diff --git a/iface/bind/bind.go b/iface/bind/bind.go index 846028c53..2a2e0d8bb 100644 --- a/iface/bind/bind.go +++ b/iface/bind/bind.go @@ -54,8 +54,7 @@ func (b *ICEBind) Open(uport uint16) ([]conn.ReceiveFunc, uint16, error) { return nil, 0, conn.ErrBindAlreadyOpen } - port := int(uport) - ipv4Conn, port, err := listenNet("udp4", port) + ipv4Conn, _, err := listenNet("udp4", int(uport)) if err != nil && !errors.Is(err, syscall.EAFNOSUPPORT) { return nil, 0, err } @@ -168,6 +167,7 @@ func (b *ICEBind) SetMark(mark uint32) error { return nil } +// Send bytes to the remote endpoint (peer) func (b *ICEBind) Send(buff []byte, endpoint conn.Endpoint) error { nend, ok := endpoint.(conn.StdNetEndpoint) diff --git a/iface/bind/udp_mux.go b/iface/bind/udp_mux.go index 3cf3753d0..c34331fb0 100644 --- a/iface/bind/udp_mux.go +++ b/iface/bind/udp_mux.go @@ -15,6 +15,10 @@ import ( "github.com/pion/transport/v2" ) +/* + Most of this code was copied from https://github.com/pion/ice and modified to fulfill NetBird's requirements +*/ + const receiveMTU = 8192 // UDPMuxDefault is an implementation of the interface @@ -37,8 +41,6 @@ type UDPMuxDefault struct { // for UDP connection listen at unspecified address localAddrsForUnspecified []net.Addr - - used bool } const maxAddrSize = 512 @@ -374,9 +376,7 @@ func (m *UDPMuxDefault) HandleSTUNMessage(msg *stun.Message, addr net.Addr) erro m.addressMapMu.Lock() var destinationConnList []*udpMuxedConn if storedConns, ok := m.addressMap[addr.String()]; ok { - for _, conn := range storedConns { - destinationConnList = append(destinationConnList, conn) - } + destinationConnList = append(destinationConnList, storedConns...) } m.addressMapMu.Unlock() diff --git a/iface/bind/udp_mux_universal.go b/iface/bind/udp_mux_universal.go index 8417c2a5e..b6939b200 100644 --- a/iface/bind/udp_mux_universal.go +++ b/iface/bind/udp_mux_universal.go @@ -1,5 +1,9 @@ package bind +/* + Most of this code was copied from https://github.com/pion/ice and modified to fulfill NetBird's requirements. +*/ + import ( "fmt" log "github.com/sirupsen/logrus" @@ -70,7 +74,7 @@ type udpConn struct { logger logging.LeveledLogger } -// GetListenAddresses returns the listen addr of this UDPMux +// GetListenAddresses returns the listen addr of this UDP func (m *UniversalUDPMuxDefault) GetListenAddresses() []net.Addr { return []net.Addr{m.LocalAddr()} } diff --git a/iface/bind/udp_muxed_conn.go b/iface/bind/udp_muxed_conn.go index 6706ff07d..f5390032b 100644 --- a/iface/bind/udp_muxed_conn.go +++ b/iface/bind/udp_muxed_conn.go @@ -1,5 +1,9 @@ package bind +/* + Most of this code was copied from https://github.com/pion/ice and modified to fulfill NetBird's requirements +*/ + import ( "encoding/binary" "io" @@ -141,20 +145,6 @@ func (c *udpMuxedConn) addAddress(addr string) { c.params.Mux.registerConnForAddress(c, addr) } -func (c *udpMuxedConn) removeAddress(addr string) { - c.mu.Lock() - defer c.mu.Unlock() - - newAddresses := make([]string, 0, len(c.addresses)) - for _, a := range c.addresses { - if a != addr { - newAddresses = append(newAddresses, a) - } - } - - c.addresses = newAddresses -} - func (c *udpMuxedConn) containsAddress(addr string) bool { c.mu.Lock() defer c.mu.Unlock()