From 5bb64ce1b8c42fcd96e44a5be05e17f34a83f840 Mon Sep 17 00:00:00 2001 From: Nayana Bidari Date: Thu, 12 Nov 2020 22:55:09 -0800 Subject: Refactor SOL_SOCKET options Store all the socket level options in a struct and call {Get/Set}SockOpt on this struct. This will avoid implementing socket level options on all endpoints. This CL contains implementing one socket level option for tcp and udp endpoints. PiperOrigin-RevId: 342203981 --- pkg/tcpip/transport/tcp/endpoint.go | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'pkg/tcpip/transport/tcp/endpoint.go') diff --git a/pkg/tcpip/transport/tcp/endpoint.go b/pkg/tcpip/transport/tcp/endpoint.go index 23b9de8c5..194d3a8a4 100644 --- a/pkg/tcpip/transport/tcp/endpoint.go +++ b/pkg/tcpip/transport/tcp/endpoint.go @@ -440,9 +440,6 @@ type endpoint struct { ttl uint8 v6only bool isConnectNotified bool - // TCP should never broadcast but Linux nevertheless supports enabling/ - // disabling SO_BROADCAST, albeit as a NOOP. - broadcast bool // portFlags stores the current values of port related flags. portFlags ports.Flags @@ -685,6 +682,9 @@ type endpoint struct { // linger is used for SO_LINGER socket option. linger tcpip.LingerOption + + // ops is used to get socket level options. + ops tcpip.SocketOptions } // UniqueID implements stack.TransportEndpoint.UniqueID. @@ -1599,11 +1599,6 @@ func (e *endpoint) windowCrossedACKThresholdLocked(deltaBefore int) (crossed boo func (e *endpoint) SetSockOptBool(opt tcpip.SockOptBool, v bool) *tcpip.Error { switch opt { - case tcpip.BroadcastOption: - e.LockUser() - e.broadcast = v - e.UnlockUser() - case tcpip.CorkOption: e.LockUser() if !v { @@ -1950,11 +1945,6 @@ func (e *endpoint) readyReceiveSize() (int, *tcpip.Error) { // GetSockOptBool implements tcpip.Endpoint.GetSockOptBool. func (e *endpoint) GetSockOptBool(opt tcpip.SockOptBool) (bool, *tcpip.Error) { switch opt { - case tcpip.BroadcastOption: - e.LockUser() - v := e.broadcast - e.UnlockUser() - return v, nil case tcpip.CorkOption: return atomic.LoadUint32(&e.cork) != 0, nil @@ -3130,3 +3120,7 @@ func (e *endpoint) Wait() { <-notifyCh } } + +func (e *endpoint) SocketOptions() *tcpip.SocketOptions { + return &e.ops +} -- cgit v1.2.3