diff options
author | Nayana Bidari <nybidari@google.com> | 2020-12-14 12:00:46 -0800 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2020-12-14 12:03:27 -0800 |
commit | 2e191cb3f72858c61943168a69b0aff0fda6ee45 (patch) | |
tree | 89897cc33d764636b0478170cb6622144c25238b /pkg/tcpip/socketops.go | |
parent | 65e4ed8fbe15e3a8ebf96fdacf439d30d8a0e491 (diff) |
Move SO_LINGER option to socketops.
PiperOrigin-RevId: 347437786
Diffstat (limited to 'pkg/tcpip/socketops.go')
-rw-r--r-- | pkg/tcpip/socketops.go | 40 |
1 files changed, 32 insertions, 8 deletions
diff --git a/pkg/tcpip/socketops.go b/pkg/tcpip/socketops.go index 3d29b31ee..b60a5fd76 100644 --- a/pkg/tcpip/socketops.go +++ b/pkg/tcpip/socketops.go @@ -16,6 +16,8 @@ package tcpip import ( "sync/atomic" + + "gvisor.dev/gvisor/pkg/sync" ) // SocketOptionsHandler holds methods that help define endpoint specific @@ -77,24 +79,24 @@ type SocketOptions struct { // These fields are accessed and modified using atomic operations. - // broadcastEnabled determines whether datagram sockets are allowed to send - // packets to a broadcast address. + // broadcastEnabled determines whether datagram sockets are allowed to + // send packets to a broadcast address. broadcastEnabled uint32 - // passCredEnabled determines whether SCM_CREDENTIALS socket control messages - // are enabled. + // passCredEnabled determines whether SCM_CREDENTIALS socket control + // messages are enabled. passCredEnabled uint32 // noChecksumEnabled determines whether UDP checksum is disabled while // transmitting for this socket. noChecksumEnabled uint32 - // reuseAddressEnabled determines whether Bind() should allow reuse of local - // address. + // reuseAddressEnabled determines whether Bind() should allow reuse of + // local address. reuseAddressEnabled uint32 - // reusePortEnabled determines whether to permit multiple sockets to be bound - // to an identical socket address. + // reusePortEnabled determines whether to permit multiple sockets to be + // bound to an identical socket address. reusePortEnabled uint32 // keepAliveEnabled determines whether TCP keepalive is enabled for this @@ -142,6 +144,13 @@ type SocketOptions struct { // receiveOriginalDstAddress is used to specify if the original destination of // the incoming packet should be returned as an ancillary message. receiveOriginalDstAddress uint32 + + // mu protects the access to the below fields. + mu sync.Mutex `state:"nosave"` + + // linger determines the amount of time the socket should linger before + // close. We currently implement this option for TCP socket only. + linger LingerOption } // InitHandler initializes the handler. This must be called before using the @@ -338,3 +347,18 @@ func (*SocketOptions) GetOutOfBandInline() bool { // SetOutOfBandInline sets value for SO_OOBINLINE option. We currently do not // support disabling this option. func (*SocketOptions) SetOutOfBandInline(bool) {} + +// GetLinger gets value for SO_LINGER option. +func (so *SocketOptions) GetLinger() LingerOption { + so.mu.Lock() + linger := so.linger + so.mu.Unlock() + return linger +} + +// SetLinger sets value for SO_LINGER option. +func (so *SocketOptions) SetLinger(linger LingerOption) { + so.mu.Lock() + so.linger = linger + so.mu.Unlock() +} |