github.com/aristanetworks/goarista@v0.0.0-20240514173732-cca2755bbd44/netns/nslistener_other.go (about) 1 // Copyright (c) 2019 Arista Networks, Inc. 2 // Use of this source code is governed by the Apache License 2.0 3 // that can be found in the COPYING file. 4 5 //go:build !linux 6 // +build !linux 7 8 package netns 9 10 import ( 11 "net" 12 13 "github.com/aristanetworks/goarista/dscp" 14 "github.com/aristanetworks/goarista/logger" 15 ) 16 17 var hasMount = func(_ string, _ logger.Logger) bool { 18 return true 19 } 20 21 // NewNSListener creates a new net.Listener bound to a network namespace. The listening socket will 22 // be bound to the specified local address and will have the specified tos. 23 func NewNSListener(nsName string, addr *net.TCPAddr, tos byte, 24 l logger.Logger) (net.Listener, error) { 25 return NewNSListenerWithCustomListener(nsName, addr, l, 26 func() (net.Listener, error) { 27 return dscp.ListenTCPWithTOSLogger(addr, tos, l) 28 }) 29 } 30 31 // NewNSListenerWithCustomListener creates a new net.Listener bound to a network namespace. The 32 // listener is created using listenerCreator. listenerCreator should create a listener that 33 // binds to addr. 34 func NewNSListenerWithCustomListener(nsName string, addr *net.TCPAddr, logger logger.Logger, 35 listenerCreator ListenerCreator) (net.Listener, error) { 36 return makeListener(nsName, listenerCreator) 37 }