From 32c18f443f567dac21465b3999d1a18b886891d1 Mon Sep 17 00:00:00 2001 From: Kevin Krakauer Date: Fri, 16 Apr 2021 16:26:31 -0700 Subject: Enlarge port range and fix integer overflow Also count failed TCP port allocations PiperOrigin-RevId: 368939619 --- pkg/tcpip/transport/tcp/accept.go | 1 + pkg/tcpip/transport/tcp/endpoint.go | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'pkg/tcpip/transport/tcp') diff --git a/pkg/tcpip/transport/tcp/accept.go b/pkg/tcpip/transport/tcp/accept.go index 63c46b1be..4be306434 100644 --- a/pkg/tcpip/transport/tcp/accept.go +++ b/pkg/tcpip/transport/tcp/accept.go @@ -455,6 +455,7 @@ func (e *endpoint) reserveTupleLocked() bool { Dest: dest, } if !e.stack.ReserveTuple(portRes) { + e.stack.Stats().TCP.FailedPortReservations.Increment() return false } diff --git a/pkg/tcpip/transport/tcp/endpoint.go b/pkg/tcpip/transport/tcp/endpoint.go index 9afd2bb7f..bc88e48e9 100644 --- a/pkg/tcpip/transport/tcp/endpoint.go +++ b/pkg/tcpip/transport/tcp/endpoint.go @@ -2251,7 +2251,7 @@ func (e *endpoint) connect(addr tcpip.FullAddress, handshake bool, run bool) tcp panic(err) } } - portOffset := uint16(h.Sum32()) + portOffset := h.Sum32() var twReuse tcpip.TCPTimeWaitReuseOption if err := e.stack.TransportProtocolOption(ProtocolNumber, &twReuse); err != nil { @@ -2362,6 +2362,7 @@ func (e *endpoint) connect(addr tcpip.FullAddress, handshake bool, run bool) tcp e.boundDest = addr return true, nil }); err != nil { + e.stack.Stats().TCP.FailedPortReservations.Increment() return err } } @@ -2685,6 +2686,7 @@ func (e *endpoint) bindLocked(addr tcpip.FullAddress) (err tcpip.Error) { return true, nil }) if err != nil { + e.stack.Stats().TCP.FailedPortReservations.Increment() return err } -- cgit v1.2.3