diff options
Diffstat (limited to 'pkg/tcpip')
-rw-r--r-- | pkg/tcpip/adapters/gonet/gonet.go | 4 | ||||
-rw-r--r-- | pkg/tcpip/network/ipv4/ipv4_test.go | 2 | ||||
-rw-r--r-- | pkg/tcpip/sample/tun_tcp_connect/main.go | 2 | ||||
-rw-r--r-- | pkg/tcpip/sample/tun_tcp_echo/main.go | 2 | ||||
-rw-r--r-- | pkg/tcpip/stack/transport_test.go | 6 | ||||
-rw-r--r-- | pkg/tcpip/tcpip.go | 6 | ||||
-rw-r--r-- | pkg/tcpip/transport/icmp/endpoint.go | 17 | ||||
-rw-r--r-- | pkg/tcpip/transport/tcp/dual_stack_test.go | 24 | ||||
-rw-r--r-- | pkg/tcpip/transport/tcp/endpoint.go | 10 | ||||
-rw-r--r-- | pkg/tcpip/transport/tcp/endpoint_state.go | 2 | ||||
-rw-r--r-- | pkg/tcpip/transport/tcp/tcp_test.go | 32 | ||||
-rw-r--r-- | pkg/tcpip/transport/tcp/testing/context/context.go | 2 | ||||
-rw-r--r-- | pkg/tcpip/transport/udp/endpoint.go | 16 | ||||
-rw-r--r-- | pkg/tcpip/transport/udp/udp_test.go | 28 |
14 files changed, 63 insertions, 90 deletions
diff --git a/pkg/tcpip/adapters/gonet/gonet.go b/pkg/tcpip/adapters/gonet/gonet.go index 8b077156c..560b8ac4b 100644 --- a/pkg/tcpip/adapters/gonet/gonet.go +++ b/pkg/tcpip/adapters/gonet/gonet.go @@ -60,7 +60,7 @@ func NewListener(s *stack.Stack, addr tcpip.FullAddress, network tcpip.NetworkPr return nil, errors.New(err.String()) } - if err := ep.Bind(addr, nil); err != nil { + if err := ep.Bind(addr); err != nil { ep.Close() return nil, &net.OpError{ Op: "bind", @@ -524,7 +524,7 @@ func NewPacketConn(s *stack.Stack, addr tcpip.FullAddress, network tcpip.Network return nil, errors.New(err.String()) } - if err := ep.Bind(addr, nil); err != nil { + if err := ep.Bind(addr); err != nil { ep.Close() return nil, &net.OpError{ Op: "bind", diff --git a/pkg/tcpip/network/ipv4/ipv4_test.go b/pkg/tcpip/network/ipv4/ipv4_test.go index 190d548eb..42e85564e 100644 --- a/pkg/tcpip/network/ipv4/ipv4_test.go +++ b/pkg/tcpip/network/ipv4/ipv4_test.go @@ -69,7 +69,7 @@ func TestExcludeBroadcast(t *testing.T) { } // However, we can bind to a broadcast address to listen. - if err := ep.Bind(tcpip.FullAddress{Addr: header.IPv4Broadcast, Port: 53, NIC: 1}, nil); err != nil { + if err := ep.Bind(tcpip.FullAddress{Addr: header.IPv4Broadcast, Port: 53, NIC: 1}); err != nil { t.Errorf("Bind failed: %v", err) } }) diff --git a/pkg/tcpip/sample/tun_tcp_connect/main.go b/pkg/tcpip/sample/tun_tcp_connect/main.go index 67e8f0b9e..327a79f48 100644 --- a/pkg/tcpip/sample/tun_tcp_connect/main.go +++ b/pkg/tcpip/sample/tun_tcp_connect/main.go @@ -165,7 +165,7 @@ func main() { // Bind if a port is specified. if localPort != 0 { - if err := ep.Bind(tcpip.FullAddress{0, "", localPort}, nil); err != nil { + if err := ep.Bind(tcpip.FullAddress{0, "", localPort}); err != nil { log.Fatal("Bind failed: ", err) } } diff --git a/pkg/tcpip/sample/tun_tcp_echo/main.go b/pkg/tcpip/sample/tun_tcp_echo/main.go index ab40e9e0b..b23dc13e7 100644 --- a/pkg/tcpip/sample/tun_tcp_echo/main.go +++ b/pkg/tcpip/sample/tun_tcp_echo/main.go @@ -165,7 +165,7 @@ func main() { defer ep.Close() - if err := ep.Bind(tcpip.FullAddress{0, "", uint16(localPort)}, nil); err != nil { + if err := ep.Bind(tcpip.FullAddress{0, "", uint16(localPort)}); err != nil { log.Fatal("Bind failed: ", err) } diff --git a/pkg/tcpip/stack/transport_test.go b/pkg/tcpip/stack/transport_test.go index 3347b5599..a9e844e3d 100644 --- a/pkg/tcpip/stack/transport_test.go +++ b/pkg/tcpip/stack/transport_test.go @@ -145,7 +145,7 @@ func (f *fakeTransportEndpoint) Accept() (tcpip.Endpoint, *waiter.Queue, *tcpip. return &a, nil, nil } -func (f *fakeTransportEndpoint) Bind(a tcpip.FullAddress, commit func() *tcpip.Error) *tcpip.Error { +func (f *fakeTransportEndpoint) Bind(a tcpip.FullAddress) *tcpip.Error { if err := f.stack.RegisterTransportEndpoint( a.NIC, []tcpip.NetworkProtocolNumber{fakeNetNumber}, @@ -157,7 +157,7 @@ func (f *fakeTransportEndpoint) Bind(a tcpip.FullAddress, commit func() *tcpip.E return err } f.acceptQueue = []fakeTransportEndpoint{} - return commit() + return nil } func (*fakeTransportEndpoint) GetLocalAddress() (tcpip.FullAddress, *tcpip.Error) { @@ -483,7 +483,7 @@ func TestTransportForwarding(t *testing.T) { t.Fatalf("NewEndpoint failed: %v", err) } - if err := ep.Bind(tcpip.FullAddress{Addr: "\x01", NIC: 1}, func() *tcpip.Error { return nil }); err != nil { + if err := ep.Bind(tcpip.FullAddress{Addr: "\x01", NIC: 1}); err != nil { t.Fatalf("Bind failed: %v", err) } diff --git a/pkg/tcpip/tcpip.go b/pkg/tcpip/tcpip.go index 89e9d6741..49cc8705a 100644 --- a/pkg/tcpip/tcpip.go +++ b/pkg/tcpip/tcpip.go @@ -356,11 +356,7 @@ type Endpoint interface { // Bind binds the endpoint to a specific local address and port. // Specifying a NIC is optional. - // - // An optional commit function will be executed atomically with respect - // to binding the endpoint. If this returns an error, the bind will not - // occur and the error will be propagated back to the caller. - Bind(address FullAddress, commit func() *Error) *Error + Bind(address FullAddress) *Error // GetLocalAddress returns the address to which the endpoint is bound. GetLocalAddress() (FullAddress, *Error) diff --git a/pkg/tcpip/transport/icmp/endpoint.go b/pkg/tcpip/transport/icmp/endpoint.go index b3b7a1d0e..05c4b532a 100644 --- a/pkg/tcpip/transport/icmp/endpoint.go +++ b/pkg/tcpip/transport/icmp/endpoint.go @@ -100,7 +100,7 @@ func newEndpoint(stack *stack.Stack, netProto tcpip.NetworkProtocolNumber, trans // Raw endpoints must be immediately bound because they receive all // ICMP traffic starting from when they're created via socket(). if raw { - if err := e.bindLocked(tcpip.FullAddress{}, nil); err != nil { + if err := e.bindLocked(tcpip.FullAddress{}); err != nil { return nil, err } } @@ -202,7 +202,7 @@ func (e *endpoint) prepareForWrite(to *tcpip.FullAddress) (retry bool, err *tcpi } // The state is still 'initial', so try to bind the endpoint. - if err := e.bindLocked(tcpip.FullAddress{}, nil); err != nil { + if err := e.bindLocked(tcpip.FullAddress{}); err != nil { return false, err } @@ -576,7 +576,7 @@ func (e *endpoint) registerWithStack(nicid tcpip.NICID, netProtos []tcpip.Networ return id, err } -func (e *endpoint) bindLocked(addr tcpip.FullAddress, commit func() *tcpip.Error) *tcpip.Error { +func (e *endpoint) bindLocked(addr tcpip.FullAddress) *tcpip.Error { // Don't allow binding once endpoint is not in the initial state // anymore. if e.state != stateInitial { @@ -608,13 +608,6 @@ func (e *endpoint) bindLocked(addr tcpip.FullAddress, commit func() *tcpip.Error if err != nil { return err } - if commit != nil { - if err := commit(); err != nil { - // Unregister, the commit failed. - e.stack.UnregisterTransportEndpoint(addr.NIC, netProtos, e.transProto, id, e) - return err - } - } e.id = id e.regNICID = addr.NIC @@ -631,11 +624,11 @@ func (e *endpoint) bindLocked(addr tcpip.FullAddress, commit func() *tcpip.Error // Bind binds the endpoint to a specific local address and port. // Specifying a NIC is optional. -func (e *endpoint) Bind(addr tcpip.FullAddress, commit func() *tcpip.Error) *tcpip.Error { +func (e *endpoint) Bind(addr tcpip.FullAddress) *tcpip.Error { e.mu.Lock() defer e.mu.Unlock() - err := e.bindLocked(addr, commit) + err := e.bindLocked(addr) if err != nil { return err } diff --git a/pkg/tcpip/transport/tcp/dual_stack_test.go b/pkg/tcpip/transport/tcp/dual_stack_test.go index d3120c1d8..52f20bef1 100644 --- a/pkg/tcpip/transport/tcp/dual_stack_test.go +++ b/pkg/tcpip/transport/tcp/dual_stack_test.go @@ -113,7 +113,7 @@ func TestV4ConnectWhenBoundToWildcard(t *testing.T) { c.CreateV6Endpoint(false) // Bind to wildcard. - if err := c.EP.Bind(tcpip.FullAddress{}, nil); err != nil { + if err := c.EP.Bind(tcpip.FullAddress{}); err != nil { t.Fatalf("Bind failed: %v", err) } @@ -128,7 +128,7 @@ func TestV4ConnectWhenBoundToV4MappedWildcard(t *testing.T) { c.CreateV6Endpoint(false) // Bind to v4 mapped wildcard. - if err := c.EP.Bind(tcpip.FullAddress{Addr: context.V4MappedWildcardAddr}, nil); err != nil { + if err := c.EP.Bind(tcpip.FullAddress{Addr: context.V4MappedWildcardAddr}); err != nil { t.Fatalf("Bind failed: %v", err) } @@ -143,7 +143,7 @@ func TestV4ConnectWhenBoundToV4Mapped(t *testing.T) { c.CreateV6Endpoint(false) // Bind to v4 mapped address. - if err := c.EP.Bind(tcpip.FullAddress{Addr: context.StackV4MappedAddr}, nil); err != nil { + if err := c.EP.Bind(tcpip.FullAddress{Addr: context.StackV4MappedAddr}); err != nil { t.Fatalf("Bind failed: %v", err) } @@ -233,7 +233,7 @@ func TestV6ConnectWhenBoundToWildcard(t *testing.T) { c.CreateV6Endpoint(false) // Bind to wildcard. - if err := c.EP.Bind(tcpip.FullAddress{}, nil); err != nil { + if err := c.EP.Bind(tcpip.FullAddress{}); err != nil { t.Fatalf("Bind failed: %v", err) } @@ -248,7 +248,7 @@ func TestV6ConnectWhenBoundToLocalAddress(t *testing.T) { c.CreateV6Endpoint(false) // Bind to local address. - if err := c.EP.Bind(tcpip.FullAddress{Addr: context.StackV6Addr}, nil); err != nil { + if err := c.EP.Bind(tcpip.FullAddress{Addr: context.StackV6Addr}); err != nil { t.Fatalf("Bind failed: %v", err) } @@ -263,7 +263,7 @@ func TestV4RefuseOnV6Only(t *testing.T) { c.CreateV6Endpoint(true) // Bind to wildcard. - if err := c.EP.Bind(tcpip.FullAddress{Port: context.StackPort}, nil); err != nil { + if err := c.EP.Bind(tcpip.FullAddress{Port: context.StackPort}); err != nil { t.Fatalf("Bind failed: %v", err) } @@ -300,7 +300,7 @@ func TestV6RefuseOnBoundToV4Mapped(t *testing.T) { c.CreateV6Endpoint(false) // Bind and listen. - if err := c.EP.Bind(tcpip.FullAddress{Addr: context.V4MappedWildcardAddr, Port: context.StackPort}, nil); err != nil { + if err := c.EP.Bind(tcpip.FullAddress{Addr: context.V4MappedWildcardAddr, Port: context.StackPort}); err != nil { t.Fatalf("Bind failed: %v", err) } @@ -415,7 +415,7 @@ func TestV4AcceptOnV6(t *testing.T) { c.CreateV6Endpoint(false) // Bind to wildcard. - if err := c.EP.Bind(tcpip.FullAddress{Port: context.StackPort}, nil); err != nil { + if err := c.EP.Bind(tcpip.FullAddress{Port: context.StackPort}); err != nil { t.Fatalf("Bind failed: %v", err) } @@ -430,7 +430,7 @@ func TestV4AcceptOnBoundToV4MappedWildcard(t *testing.T) { c.CreateV6Endpoint(false) // Bind to v4 mapped wildcard. - if err := c.EP.Bind(tcpip.FullAddress{Addr: context.V4MappedWildcardAddr, Port: context.StackPort}, nil); err != nil { + if err := c.EP.Bind(tcpip.FullAddress{Addr: context.V4MappedWildcardAddr, Port: context.StackPort}); err != nil { t.Fatalf("Bind failed: %v", err) } @@ -445,7 +445,7 @@ func TestV4AcceptOnBoundToV4Mapped(t *testing.T) { c.CreateV6Endpoint(false) // Bind and listen. - if err := c.EP.Bind(tcpip.FullAddress{Addr: context.StackV4MappedAddr, Port: context.StackPort}, nil); err != nil { + if err := c.EP.Bind(tcpip.FullAddress{Addr: context.StackV4MappedAddr, Port: context.StackPort}); err != nil { t.Fatalf("Bind failed: %v", err) } @@ -460,7 +460,7 @@ func TestV6AcceptOnV6(t *testing.T) { c.CreateV6Endpoint(false) // Bind and listen. - if err := c.EP.Bind(tcpip.FullAddress{Port: context.StackPort}, nil); err != nil { + if err := c.EP.Bind(tcpip.FullAddress{Port: context.StackPort}); err != nil { t.Fatalf("Bind failed: %v", err) } @@ -551,7 +551,7 @@ func TestV4AcceptOnV4(t *testing.T) { } // Bind to wildcard. - if err := c.EP.Bind(tcpip.FullAddress{Port: context.StackPort}, nil); err != nil { + if err := c.EP.Bind(tcpip.FullAddress{Port: context.StackPort}); err != nil { t.Fatalf("Bind failed: %v", err) } diff --git a/pkg/tcpip/transport/tcp/endpoint.go b/pkg/tcpip/transport/tcp/endpoint.go index c48a27d8f..ae99f0f8e 100644 --- a/pkg/tcpip/transport/tcp/endpoint.go +++ b/pkg/tcpip/transport/tcp/endpoint.go @@ -1336,7 +1336,7 @@ func (e *endpoint) Accept() (tcpip.Endpoint, *waiter.Queue, *tcpip.Error) { } // Bind binds the endpoint to a specific local port and optionally address. -func (e *endpoint) Bind(addr tcpip.FullAddress, commit func() *tcpip.Error) (err *tcpip.Error) { +func (e *endpoint) Bind(addr tcpip.FullAddress) (err *tcpip.Error) { e.mu.Lock() defer e.mu.Unlock() @@ -1397,14 +1397,6 @@ func (e *endpoint) Bind(addr tcpip.FullAddress, commit func() *tcpip.Error) (err e.id.LocalAddress = addr.Addr } - // Check the commit function. - if commit != nil { - if err := commit(); err != nil { - // The defer takes care of unwind. - return err - } - } - // Mark endpoint as bound. e.state = stateBound diff --git a/pkg/tcpip/transport/tcp/endpoint_state.go b/pkg/tcpip/transport/tcp/endpoint_state.go index ca7852d04..87e988afa 100644 --- a/pkg/tcpip/transport/tcp/endpoint_state.go +++ b/pkg/tcpip/transport/tcp/endpoint_state.go @@ -185,7 +185,7 @@ func (e *endpoint) afterLoad() { if len(e.bindAddress) == 0 { e.bindAddress = e.id.LocalAddress } - if err := e.Bind(tcpip.FullAddress{Addr: e.bindAddress, Port: e.id.LocalPort}, nil); err != nil { + if err := e.Bind(tcpip.FullAddress{Addr: e.bindAddress, Port: e.id.LocalPort}); err != nil { panic("endpoint binding failed: " + err.String()) } } diff --git a/pkg/tcpip/transport/tcp/tcp_test.go b/pkg/tcpip/transport/tcp/tcp_test.go index 557cc258d..2011189b7 100644 --- a/pkg/tcpip/transport/tcp/tcp_test.go +++ b/pkg/tcpip/transport/tcp/tcp_test.go @@ -135,7 +135,7 @@ func TestPassiveConnectionAttemptIncrement(t *testing.T) { t.Fatalf("NewEndpoint failed: %v", err) } - if err := ep.Bind(tcpip.FullAddress{Addr: context.StackAddr, Port: context.StackPort}, nil); err != nil { + if err := ep.Bind(tcpip.FullAddress{Addr: context.StackAddr, Port: context.StackPort}); err != nil { t.Fatalf("Bind failed: %v", err) } if err := ep.Listen(1); err != nil { @@ -193,7 +193,7 @@ func TestTCPResetsSentIncrement(t *testing.T) { } want := stats.TCP.SegmentsSent.Value() + 1 - if err := ep.Bind(tcpip.FullAddress{Port: context.StackPort}, nil); err != nil { + if err := ep.Bind(tcpip.FullAddress{Port: context.StackPort}); err != nil { t.Fatalf("Bind failed: %v", err) } @@ -1042,7 +1042,7 @@ func TestScaledWindowAccept(t *testing.T) { t.Fatalf("SetSockOpt failed failed: %v", err) } - if err := ep.Bind(tcpip.FullAddress{Port: context.StackPort}, nil); err != nil { + if err := ep.Bind(tcpip.FullAddress{Port: context.StackPort}); err != nil { t.Fatalf("Bind failed: %v", err) } @@ -1115,7 +1115,7 @@ func TestNonScaledWindowAccept(t *testing.T) { t.Fatalf("SetSockOpt failed failed: %v", err) } - if err := ep.Bind(tcpip.FullAddress{Port: context.StackPort}, nil); err != nil { + if err := ep.Bind(tcpip.FullAddress{Port: context.StackPort}); err != nil { t.Fatalf("Bind failed: %v", err) } @@ -1618,7 +1618,7 @@ func TestPassiveSendMSSLessThanMTU(t *testing.T) { t.Fatalf("SetSockOpt failed failed: %v", err) } - if err := ep.Bind(tcpip.FullAddress{Port: context.StackPort}, nil); err != nil { + if err := ep.Bind(tcpip.FullAddress{Port: context.StackPort}); err != nil { t.Fatalf("Bind failed: %v", err) } @@ -1675,7 +1675,7 @@ func TestSynCookiePassiveSendMSSLessThanMTU(t *testing.T) { } defer ep.Close() - if err := ep.Bind(tcpip.FullAddress{Port: context.StackPort}, nil); err != nil { + if err := ep.Bind(tcpip.FullAddress{Port: context.StackPort}); err != nil { t.Fatalf("Bind failed: %v", err) } @@ -1840,7 +1840,7 @@ func TestCloseListener(t *testing.T) { t.Fatalf("NewEndpoint failed: %v", err) } - if err := ep.Bind(tcpip.FullAddress{}, nil); err != nil { + if err := ep.Bind(tcpip.FullAddress{}); err != nil { t.Fatalf("Bind failed: %v", err) } @@ -2824,7 +2824,7 @@ func TestUpdateListenBacklog(t *testing.T) { t.Fatalf("NewEndpoint failed: %v", err) } - if err := ep.Bind(tcpip.FullAddress{}, nil); err != nil { + if err := ep.Bind(tcpip.FullAddress{}); err != nil { t.Fatalf("Bind failed: %v", err) } @@ -3096,7 +3096,7 @@ func TestReusePort(t *testing.T) { if err != nil { t.Fatalf("NewEndpoint failed; %v", err) } - if err := c.EP.Bind(tcpip.FullAddress{Port: context.StackPort}, nil); err != nil { + if err := c.EP.Bind(tcpip.FullAddress{Port: context.StackPort}); err != nil { t.Fatalf("Bind failed: %v", err) } @@ -3105,7 +3105,7 @@ func TestReusePort(t *testing.T) { if err != nil { t.Fatalf("NewEndpoint failed; %v", err) } - if err := c.EP.Bind(tcpip.FullAddress{Port: context.StackPort}, nil); err != nil { + if err := c.EP.Bind(tcpip.FullAddress{Port: context.StackPort}); err != nil { t.Fatalf("Bind failed: %v", err) } c.EP.Close() @@ -3115,7 +3115,7 @@ func TestReusePort(t *testing.T) { if err != nil { t.Fatalf("NewEndpoint failed; %v", err) } - if err := c.EP.Bind(tcpip.FullAddress{Port: context.StackPort}, nil); err != nil { + if err := c.EP.Bind(tcpip.FullAddress{Port: context.StackPort}); err != nil { t.Fatalf("Bind failed: %v", err) } if err := c.EP.Connect(tcpip.FullAddress{Addr: context.TestAddr, Port: context.TestPort}); err != tcpip.ErrConnectStarted { @@ -3127,7 +3127,7 @@ func TestReusePort(t *testing.T) { if err != nil { t.Fatalf("NewEndpoint failed; %v", err) } - if err := c.EP.Bind(tcpip.FullAddress{Port: context.StackPort}, nil); err != nil { + if err := c.EP.Bind(tcpip.FullAddress{Port: context.StackPort}); err != nil { t.Fatalf("Bind failed: %v", err) } c.EP.Close() @@ -3137,7 +3137,7 @@ func TestReusePort(t *testing.T) { if err != nil { t.Fatalf("NewEndpoint failed; %v", err) } - if err := c.EP.Bind(tcpip.FullAddress{Port: context.StackPort}, nil); err != nil { + if err := c.EP.Bind(tcpip.FullAddress{Port: context.StackPort}); err != nil { t.Fatalf("Bind failed: %v", err) } if err := c.EP.Listen(10); err != nil { @@ -3149,7 +3149,7 @@ func TestReusePort(t *testing.T) { if err != nil { t.Fatalf("NewEndpoint failed; %v", err) } - if err := c.EP.Bind(tcpip.FullAddress{Port: context.StackPort}, nil); err != nil { + if err := c.EP.Bind(tcpip.FullAddress{Port: context.StackPort}); err != nil { t.Fatalf("Bind failed: %v", err) } if err := c.EP.Listen(10); err != nil { @@ -3337,7 +3337,7 @@ func TestSelfConnect(t *testing.T) { } defer ep.Close() - if err := ep.Bind(tcpip.FullAddress{Port: context.StackPort}, nil); err != nil { + if err := ep.Bind(tcpip.FullAddress{Port: context.StackPort}); err != nil { t.Fatalf("Bind failed: %v", err) } @@ -3508,7 +3508,7 @@ func TestConnectAvoidsBoundPorts(t *testing.T) { } for i := ports.FirstEphemeral; i <= math.MaxUint16; i++ { - if makeEP(exhaustedNetwork).Bind(tcpip.FullAddress{Addr: address(t, exhaustedAddressType, isAny), Port: uint16(i)}, nil); err != nil { + if makeEP(exhaustedNetwork).Bind(tcpip.FullAddress{Addr: address(t, exhaustedAddressType, isAny), Port: uint16(i)}); err != nil { t.Fatalf("Bind(%d) failed: %v", i, err) } } diff --git a/pkg/tcpip/transport/tcp/testing/context/context.go b/pkg/tcpip/transport/tcp/testing/context/context.go index 0695e8150..fb4ae4a1b 100644 --- a/pkg/tcpip/transport/tcp/testing/context/context.go +++ b/pkg/tcpip/transport/tcp/testing/context/context.go @@ -796,7 +796,7 @@ func (c *Context) AcceptWithOptions(wndScale int, synOptions header.TCPSynOption } defer ep.Close() - if err := ep.Bind(tcpip.FullAddress{Port: StackPort}, nil); err != nil { + if err := ep.Bind(tcpip.FullAddress{Port: StackPort}); err != nil { c.t.Fatalf("Bind failed: %v", err) } diff --git a/pkg/tcpip/transport/udp/endpoint.go b/pkg/tcpip/transport/udp/endpoint.go index 44b9cdf6a..4108cb09c 100644 --- a/pkg/tcpip/transport/udp/endpoint.go +++ b/pkg/tcpip/transport/udp/endpoint.go @@ -247,7 +247,7 @@ func (e *endpoint) prepareForWrite(to *tcpip.FullAddress) (retry bool, err *tcpi } // The state is still 'initial', so try to bind the endpoint. - if err := e.bindLocked(tcpip.FullAddress{}, nil); err != nil { + if err := e.bindLocked(tcpip.FullAddress{}); err != nil { return false, err } @@ -806,7 +806,7 @@ func (e *endpoint) registerWithStack(nicid tcpip.NICID, netProtos []tcpip.Networ return id, err } -func (e *endpoint) bindLocked(addr tcpip.FullAddress, commit func() *tcpip.Error) *tcpip.Error { +func (e *endpoint) bindLocked(addr tcpip.FullAddress) *tcpip.Error { // Don't allow binding once endpoint is not in the initial state // anymore. if e.state != stateInitial { @@ -846,14 +846,6 @@ func (e *endpoint) bindLocked(addr tcpip.FullAddress, commit func() *tcpip.Error if err != nil { return err } - if commit != nil { - if err := commit(); err != nil { - // Unregister, the commit failed. - e.stack.UnregisterTransportEndpoint(nicid, netProtos, ProtocolNumber, id, e) - e.stack.ReleasePort(netProtos, ProtocolNumber, id.LocalAddress, id.LocalPort) - return err - } - } e.id = id e.regNICID = nicid @@ -871,11 +863,11 @@ func (e *endpoint) bindLocked(addr tcpip.FullAddress, commit func() *tcpip.Error // Bind binds the endpoint to a specific local address and port. // Specifying a NIC is optional. -func (e *endpoint) Bind(addr tcpip.FullAddress, commit func() *tcpip.Error) *tcpip.Error { +func (e *endpoint) Bind(addr tcpip.FullAddress) *tcpip.Error { e.mu.Lock() defer e.mu.Unlock() - err := e.bindLocked(addr, commit) + err := e.bindLocked(addr) if err != nil { return err } diff --git a/pkg/tcpip/transport/udp/udp_test.go b/pkg/tcpip/transport/udp/udp_test.go index 2a9cf4b57..884a76b04 100644 --- a/pkg/tcpip/transport/udp/udp_test.go +++ b/pkg/tcpip/transport/udp/udp_test.go @@ -289,7 +289,7 @@ func TestBindPortReuse(t *testing.T) { if err := eps[i].SetSockOpt(reusePortOpt); err != nil { c.t.Fatalf("SetSockOpt failed failed: %v", err) } - if err := eps[i].Bind(tcpip.FullAddress{Addr: stackV6Addr, Port: stackPort}, nil); err != nil { + if err := eps[i].Bind(tcpip.FullAddress{Addr: stackV6Addr, Port: stackPort}); err != nil { t.Fatalf("ep.Bind(...) failed: %v", err) } } @@ -385,7 +385,7 @@ func TestBindEphemeralPort(t *testing.T) { c.createV6Endpoint(false) - if err := c.ep.Bind(tcpip.FullAddress{}, nil); err != nil { + if err := c.ep.Bind(tcpip.FullAddress{}); err != nil { t.Fatalf("ep.Bind(...) failed: %v", err) } } @@ -412,7 +412,7 @@ func TestBindReservedPort(t *testing.T) { t.Fatalf("NewEndpoint failed: %v", err) } defer ep.Close() - if got, want := ep.Bind(addr, nil), tcpip.ErrPortInUse; got != want { + if got, want := ep.Bind(addr), tcpip.ErrPortInUse; got != want { t.Fatalf("got ep.Bind(...) = %v, want = %v", got, want) } } @@ -425,11 +425,11 @@ func TestBindReservedPort(t *testing.T) { defer ep.Close() // We can't bind ipv4-any on the port reserved by the connected endpoint // above, since the endpoint is dual-stack. - if got, want := ep.Bind(tcpip.FullAddress{Port: addr.Port}, nil), tcpip.ErrPortInUse; got != want { + if got, want := ep.Bind(tcpip.FullAddress{Port: addr.Port}), tcpip.ErrPortInUse; got != want { t.Fatalf("got ep.Bind(...) = %v, want = %v", got, want) } // We can bind an ipv4 address on this port, though. - if err := ep.Bind(tcpip.FullAddress{Addr: stackAddr, Port: addr.Port}, nil); err != nil { + if err := ep.Bind(tcpip.FullAddress{Addr: stackAddr, Port: addr.Port}); err != nil { t.Fatalf("ep.Bind(...) failed: %v", err) } }() @@ -443,7 +443,7 @@ func TestBindReservedPort(t *testing.T) { t.Fatalf("NewEndpoint failed: %v", err) } defer ep.Close() - if err := ep.Bind(tcpip.FullAddress{Port: addr.Port}, nil); err != nil { + if err := ep.Bind(tcpip.FullAddress{Port: addr.Port}); err != nil { t.Fatalf("ep.Bind(...) failed: %v", err) } }() @@ -456,7 +456,7 @@ func TestV4ReadOnV6(t *testing.T) { c.createV6Endpoint(false) // Bind to wildcard. - if err := c.ep.Bind(tcpip.FullAddress{Port: stackPort}, nil); err != nil { + if err := c.ep.Bind(tcpip.FullAddress{Port: stackPort}); err != nil { c.t.Fatalf("Bind failed: %v", err) } @@ -471,7 +471,7 @@ func TestV4ReadOnBoundToV4MappedWildcard(t *testing.T) { c.createV6Endpoint(false) // Bind to v4 mapped wildcard. - if err := c.ep.Bind(tcpip.FullAddress{Addr: V4MappedWildcardAddr, Port: stackPort}, nil); err != nil { + if err := c.ep.Bind(tcpip.FullAddress{Addr: V4MappedWildcardAddr, Port: stackPort}); err != nil { c.t.Fatalf("Bind failed: %v", err) } @@ -486,7 +486,7 @@ func TestV4ReadOnBoundToV4Mapped(t *testing.T) { c.createV6Endpoint(false) // Bind to local address. - if err := c.ep.Bind(tcpip.FullAddress{Addr: stackV4MappedAddr, Port: stackPort}, nil); err != nil { + if err := c.ep.Bind(tcpip.FullAddress{Addr: stackV4MappedAddr, Port: stackPort}); err != nil { c.t.Fatalf("Bind failed: %v", err) } @@ -501,7 +501,7 @@ func TestV6ReadOnV6(t *testing.T) { c.createV6Endpoint(false) // Bind to wildcard. - if err := c.ep.Bind(tcpip.FullAddress{Port: stackPort}, nil); err != nil { + if err := c.ep.Bind(tcpip.FullAddress{Port: stackPort}); err != nil { c.t.Fatalf("Bind failed: %v", err) } @@ -556,7 +556,7 @@ func TestV4ReadOnV4(t *testing.T) { } // Bind to wildcard. - if err := c.ep.Bind(tcpip.FullAddress{Port: stackPort}, nil); err != nil { + if err := c.ep.Bind(tcpip.FullAddress{Port: stackPort}); err != nil { c.t.Fatalf("Bind failed: %v", err) } @@ -650,7 +650,7 @@ func TestDualWriteBoundToWildcard(t *testing.T) { c.createV6Endpoint(false) // Bind to wildcard. - if err := c.ep.Bind(tcpip.FullAddress{Port: stackPort}, nil); err != nil { + if err := c.ep.Bind(tcpip.FullAddress{Port: stackPort}); err != nil { c.t.Fatalf("Bind failed: %v", err) } @@ -729,7 +729,7 @@ func TestV6WriteOnBoundToV4Mapped(t *testing.T) { c.createV6Endpoint(false) // Bind to v4 mapped address. - if err := c.ep.Bind(tcpip.FullAddress{Addr: stackV4MappedAddr, Port: stackPort}, nil); err != nil { + if err := c.ep.Bind(tcpip.FullAddress{Addr: stackV4MappedAddr, Port: stackPort}); err != nil { c.t.Fatalf("Bind failed: %v", err) } @@ -827,7 +827,7 @@ func TestReadIncrementsPacketsReceived(t *testing.T) { } // Bind to wildcard. - if err := c.ep.Bind(tcpip.FullAddress{Port: stackPort}, nil); err != nil { + if err := c.ep.Bind(tcpip.FullAddress{Port: stackPort}); err != nil { c.t.Fatalf("Bind failed: %v", err) } |