diff options
author | gVisor bot <gvisor-bot@google.com> | 2020-11-13 07:00:09 +0000 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2020-11-13 07:00:09 +0000 |
commit | f560fd07ef27eef3027f03e93e2c958375d60dd7 (patch) | |
tree | 38c9c19a5948edaa06ab43454fb38a96d9f9531d /pkg/tcpip | |
parent | f942d232b2c93d40a7af7007a8490c51d663e7f5 (diff) | |
parent | 5bb64ce1b8c42fcd96e44a5be05e17f34a83f840 (diff) |
Merge release-20201030.0-83-g5bb64ce1b (automated)
Diffstat (limited to 'pkg/tcpip')
-rw-r--r-- | pkg/tcpip/socketops.go | 45 | ||||
-rw-r--r-- | pkg/tcpip/tcpip.go | 11 | ||||
-rw-r--r-- | pkg/tcpip/tcpip_state_autogen.go | 24 | ||||
-rw-r--r-- | pkg/tcpip/transport/icmp/endpoint.go | 7 | ||||
-rw-r--r-- | pkg/tcpip/transport/icmp/icmp_state_autogen.go | 3 | ||||
-rw-r--r-- | pkg/tcpip/transport/packet/endpoint.go | 7 | ||||
-rw-r--r-- | pkg/tcpip/transport/packet/packet_state_autogen.go | 3 | ||||
-rw-r--r-- | pkg/tcpip/transport/raw/endpoint.go | 7 | ||||
-rw-r--r-- | pkg/tcpip/transport/raw/raw_state_autogen.go | 3 | ||||
-rw-r--r-- | pkg/tcpip/transport/tcp/endpoint.go | 20 | ||||
-rw-r--r-- | pkg/tcpip/transport/tcp/tcp_state_autogen.go | 194 | ||||
-rw-r--r-- | pkg/tcpip/transport/udp/endpoint.go | 22 | ||||
-rw-r--r-- | pkg/tcpip/transport/udp/udp_state_autogen.go | 58 |
13 files changed, 245 insertions, 159 deletions
diff --git a/pkg/tcpip/socketops.go b/pkg/tcpip/socketops.go new file mode 100644 index 000000000..2a6c7c7c0 --- /dev/null +++ b/pkg/tcpip/socketops.go @@ -0,0 +1,45 @@ +// Copyright 2020 The gVisor Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package tcpip + +import ( + "gvisor.dev/gvisor/pkg/sync" +) + +// SocketOptions contains all the variables which store values for socket +// level options. +// +// +stateify savable +type SocketOptions struct { + // mu protects fields below. + mu sync.Mutex `state:"nosave"` + broadcastEnabled bool +} + +// GetBroadcast gets value for SO_BROADCAST option. +func (so *SocketOptions) GetBroadcast() bool { + so.mu.Lock() + defer so.mu.Unlock() + + return so.broadcastEnabled +} + +// SetBroadcast sets value for SO_BROADCAST option. +func (so *SocketOptions) SetBroadcast(v bool) { + so.mu.Lock() + defer so.mu.Unlock() + + so.broadcastEnabled = v +} diff --git a/pkg/tcpip/tcpip.go b/pkg/tcpip/tcpip.go index 9a0c63ae4..f9e83dd1c 100644 --- a/pkg/tcpip/tcpip.go +++ b/pkg/tcpip/tcpip.go @@ -634,6 +634,10 @@ type Endpoint interface { // LastError clears and returns the last error reported by the endpoint. LastError() *Error + + // SocketOptions returns the structure which contains all the socket + // level options. + SocketOptions() *SocketOptions } // LinkPacketInfo holds Link layer information for a received packet. @@ -694,15 +698,10 @@ type WriteOptions struct { type SockOptBool int const ( - // BroadcastOption is used by SetSockOptBool/GetSockOptBool to specify - // whether datagram sockets are allowed to send packets to a broadcast - // address. - BroadcastOption SockOptBool = iota - // CorkOption is used by SetSockOptBool/GetSockOptBool to specify if // data should be held until segments are full by the TCP transport // protocol. - CorkOption + CorkOption SockOptBool = iota // DelayOption is used by SetSockOptBool/GetSockOptBool to specify if // data should be sent out immediately by the transport protocol. For diff --git a/pkg/tcpip/tcpip_state_autogen.go b/pkg/tcpip/tcpip_state_autogen.go index 638637135..09aeb0f74 100644 --- a/pkg/tcpip/tcpip_state_autogen.go +++ b/pkg/tcpip/tcpip_state_autogen.go @@ -6,6 +6,29 @@ import ( "gvisor.dev/gvisor/pkg/state" ) +func (so *SocketOptions) StateTypeName() string { + return "pkg/tcpip.SocketOptions" +} + +func (so *SocketOptions) StateFields() []string { + return []string{ + "broadcastEnabled", + } +} + +func (so *SocketOptions) beforeSave() {} + +func (so *SocketOptions) StateSave(stateSinkObject state.Sink) { + so.beforeSave() + stateSinkObject.Save(0, &so.broadcastEnabled) +} + +func (so *SocketOptions) afterLoad() {} + +func (so *SocketOptions) StateLoad(stateSourceObject state.Source) { + stateSourceObject.Load(0, &so.broadcastEnabled) +} + func (f *FullAddress) StateTypeName() string { return "pkg/tcpip.FullAddress" } @@ -167,6 +190,7 @@ func (i *IPPacketInfo) StateLoad(stateSourceObject state.Source) { } func init() { + state.Register((*SocketOptions)(nil)) state.Register((*FullAddress)(nil)) state.Register((*ControlMessages)(nil)) state.Register((*LinkPacketInfo)(nil)) diff --git a/pkg/tcpip/transport/icmp/endpoint.go b/pkg/tcpip/transport/icmp/endpoint.go index 763cd8f84..440cb0352 100644 --- a/pkg/tcpip/transport/icmp/endpoint.go +++ b/pkg/tcpip/transport/icmp/endpoint.go @@ -79,6 +79,9 @@ type endpoint struct { // owner is used to get uid and gid of the packet. owner tcpip.PacketOwner + + // ops is used to get socket level options. + ops tcpip.SocketOptions } func newEndpoint(s *stack.Stack, netProto tcpip.NetworkProtocolNumber, transProto tcpip.TransportProtocolNumber, waiterQueue *waiter.Queue) (tcpip.Endpoint, *tcpip.Error) { @@ -853,3 +856,7 @@ func (*endpoint) Wait() {} func (*endpoint) LastError() *tcpip.Error { return nil } + +func (e *endpoint) SocketOptions() *tcpip.SocketOptions { + return &e.ops +} diff --git a/pkg/tcpip/transport/icmp/icmp_state_autogen.go b/pkg/tcpip/transport/icmp/icmp_state_autogen.go index 2acf00a72..81d864da0 100644 --- a/pkg/tcpip/transport/icmp/icmp_state_autogen.go +++ b/pkg/tcpip/transport/icmp/icmp_state_autogen.go @@ -60,6 +60,7 @@ func (e *endpoint) StateFields() []string { "ttl", "linger", "owner", + "ops", } } @@ -80,6 +81,7 @@ func (e *endpoint) StateSave(stateSinkObject state.Sink) { stateSinkObject.Save(11, &e.ttl) stateSinkObject.Save(12, &e.linger) stateSinkObject.Save(13, &e.owner) + stateSinkObject.Save(14, &e.ops) } func (e *endpoint) StateLoad(stateSourceObject state.Source) { @@ -96,6 +98,7 @@ func (e *endpoint) StateLoad(stateSourceObject state.Source) { stateSourceObject.Load(11, &e.ttl) stateSourceObject.Load(12, &e.linger) stateSourceObject.Load(13, &e.owner) + stateSourceObject.Load(14, &e.ops) stateSourceObject.LoadValue(5, new(int), func(y interface{}) { e.loadRcvBufSizeMax(y.(int)) }) stateSourceObject.AfterLoad(e.afterLoad) } diff --git a/pkg/tcpip/transport/packet/endpoint.go b/pkg/tcpip/transport/packet/endpoint.go index 31831a6d8..3bff3755a 100644 --- a/pkg/tcpip/transport/packet/endpoint.go +++ b/pkg/tcpip/transport/packet/endpoint.go @@ -89,6 +89,9 @@ type endpoint struct { // lastErrorMu protects lastError. lastErrorMu sync.Mutex `state:"nosave"` lastError *tcpip.Error `state:".(string)"` + + // ops is used to get socket level options. + ops tcpip.SocketOptions } // NewEndpoint returns a new packet endpoint. @@ -549,3 +552,7 @@ func (ep *endpoint) Stats() tcpip.EndpointStats { } func (ep *endpoint) SetOwner(owner tcpip.PacketOwner) {} + +func (ep *endpoint) SocketOptions() *tcpip.SocketOptions { + return &ep.ops +} diff --git a/pkg/tcpip/transport/packet/packet_state_autogen.go b/pkg/tcpip/transport/packet/packet_state_autogen.go index 66b6a4cc2..2ce71eb84 100644 --- a/pkg/tcpip/transport/packet/packet_state_autogen.go +++ b/pkg/tcpip/transport/packet/packet_state_autogen.go @@ -64,6 +64,7 @@ func (ep *endpoint) StateFields() []string { "boundNIC", "linger", "lastError", + "ops", } } @@ -86,6 +87,7 @@ func (ep *endpoint) StateSave(stateSinkObject state.Sink) { stateSinkObject.Save(11, &ep.bound) stateSinkObject.Save(12, &ep.boundNIC) stateSinkObject.Save(13, &ep.linger) + stateSinkObject.Save(15, &ep.ops) } func (ep *endpoint) StateLoad(stateSourceObject state.Source) { @@ -102,6 +104,7 @@ func (ep *endpoint) StateLoad(stateSourceObject state.Source) { stateSourceObject.Load(11, &ep.bound) stateSourceObject.Load(12, &ep.boundNIC) stateSourceObject.Load(13, &ep.linger) + stateSourceObject.Load(15, &ep.ops) stateSourceObject.LoadValue(5, new(int), func(y interface{}) { ep.loadRcvBufSizeMax(y.(int)) }) stateSourceObject.LoadValue(14, new(string), func(y interface{}) { ep.loadLastError(y.(string)) }) stateSourceObject.AfterLoad(ep.afterLoad) diff --git a/pkg/tcpip/transport/raw/endpoint.go b/pkg/tcpip/transport/raw/endpoint.go index 7b6a87ba9..4ae1f92ab 100644 --- a/pkg/tcpip/transport/raw/endpoint.go +++ b/pkg/tcpip/transport/raw/endpoint.go @@ -89,6 +89,9 @@ type endpoint struct { // owner is used to get uid and gid of the packet. owner tcpip.PacketOwner + + // ops is used to get socket level options. + ops tcpip.SocketOptions } // NewEndpoint returns a raw endpoint for the given protocols. @@ -756,3 +759,7 @@ func (*endpoint) Wait() {} func (*endpoint) LastError() *tcpip.Error { return nil } + +func (e *endpoint) SocketOptions() *tcpip.SocketOptions { + return &e.ops +} diff --git a/pkg/tcpip/transport/raw/raw_state_autogen.go b/pkg/tcpip/transport/raw/raw_state_autogen.go index 7a5831bf3..26fc86a27 100644 --- a/pkg/tcpip/transport/raw/raw_state_autogen.go +++ b/pkg/tcpip/transport/raw/raw_state_autogen.go @@ -61,6 +61,7 @@ func (e *endpoint) StateFields() []string { "bound", "linger", "owner", + "ops", } } @@ -82,6 +83,7 @@ func (e *endpoint) StateSave(stateSinkObject state.Sink) { stateSinkObject.Save(12, &e.bound) stateSinkObject.Save(13, &e.linger) stateSinkObject.Save(14, &e.owner) + stateSinkObject.Save(15, &e.ops) } func (e *endpoint) StateLoad(stateSourceObject state.Source) { @@ -99,6 +101,7 @@ func (e *endpoint) StateLoad(stateSourceObject state.Source) { stateSourceObject.Load(12, &e.bound) stateSourceObject.Load(13, &e.linger) stateSourceObject.Load(14, &e.owner) + stateSourceObject.Load(15, &e.ops) stateSourceObject.LoadValue(6, new(int), func(y interface{}) { e.loadRcvBufSizeMax(y.(int)) }) stateSourceObject.AfterLoad(e.afterLoad) } 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 +} diff --git a/pkg/tcpip/transport/tcp/tcp_state_autogen.go b/pkg/tcpip/transport/tcp/tcp_state_autogen.go index 8782316f2..2a2960d80 100644 --- a/pkg/tcpip/transport/tcp/tcp_state_autogen.go +++ b/pkg/tcpip/transport/tcp/tcp_state_autogen.go @@ -176,7 +176,6 @@ func (e *endpoint) StateFields() []string { "ttl", "v6only", "isConnectNotified", - "broadcast", "portFlags", "boundBindToDevice", "boundPortFlags", @@ -224,6 +223,7 @@ func (e *endpoint) StateFields() []string { "txHash", "owner", "linger", + "ops", } } @@ -234,9 +234,9 @@ func (e *endpoint) StateSave(stateSinkObject state.Sink) { var stateValue EndpointState = e.saveState() stateSinkObject.SaveValue(11, stateValue) var recentTSTimeValue unixTime = e.saveRecentTSTime() - stateSinkObject.SaveValue(26, recentTSTimeValue) + stateSinkObject.SaveValue(25, recentTSTimeValue) var acceptedChanValue []*endpoint = e.saveAcceptedChan() - stateSinkObject.SaveValue(52, acceptedChanValue) + stateSinkObject.SaveValue(51, acceptedChanValue) stateSinkObject.Save(0, &e.EndpointInfo) stateSinkObject.Save(1, &e.waiterQueue) stateSinkObject.Save(2, &e.uniqueID) @@ -251,52 +251,52 @@ func (e *endpoint) StateSave(stateSinkObject state.Sink) { stateSinkObject.Save(13, &e.ttl) stateSinkObject.Save(14, &e.v6only) stateSinkObject.Save(15, &e.isConnectNotified) - stateSinkObject.Save(16, &e.broadcast) - stateSinkObject.Save(17, &e.portFlags) - stateSinkObject.Save(18, &e.boundBindToDevice) - stateSinkObject.Save(19, &e.boundPortFlags) - stateSinkObject.Save(20, &e.boundDest) - stateSinkObject.Save(21, &e.effectiveNetProtos) - stateSinkObject.Save(22, &e.workerRunning) - stateSinkObject.Save(23, &e.workerCleanup) - stateSinkObject.Save(24, &e.sendTSOk) - stateSinkObject.Save(25, &e.recentTS) - stateSinkObject.Save(27, &e.tsOffset) - stateSinkObject.Save(28, &e.shutdownFlags) - stateSinkObject.Save(29, &e.sackPermitted) - stateSinkObject.Save(30, &e.sack) - stateSinkObject.Save(31, &e.bindToDevice) - stateSinkObject.Save(32, &e.delay) - stateSinkObject.Save(33, &e.cork) - stateSinkObject.Save(34, &e.scoreboard) - stateSinkObject.Save(35, &e.slowAck) - stateSinkObject.Save(36, &e.segmentQueue) - stateSinkObject.Save(37, &e.synRcvdCount) - stateSinkObject.Save(38, &e.userMSS) - stateSinkObject.Save(39, &e.maxSynRetries) - stateSinkObject.Save(40, &e.windowClamp) - stateSinkObject.Save(41, &e.sndBufSize) - stateSinkObject.Save(42, &e.sndBufUsed) - stateSinkObject.Save(43, &e.sndClosed) - stateSinkObject.Save(44, &e.sndBufInQueue) - stateSinkObject.Save(45, &e.sndQueue) - stateSinkObject.Save(46, &e.cc) - stateSinkObject.Save(47, &e.packetTooBigCount) - stateSinkObject.Save(48, &e.sndMTU) - stateSinkObject.Save(49, &e.keepalive) - stateSinkObject.Save(50, &e.userTimeout) - stateSinkObject.Save(51, &e.deferAccept) - stateSinkObject.Save(53, &e.rcv) - stateSinkObject.Save(54, &e.snd) - stateSinkObject.Save(55, &e.connectingAddress) - stateSinkObject.Save(56, &e.amss) - stateSinkObject.Save(57, &e.sendTOS) - stateSinkObject.Save(58, &e.gso) - stateSinkObject.Save(59, &e.tcpLingerTimeout) - stateSinkObject.Save(60, &e.closed) - stateSinkObject.Save(61, &e.txHash) - stateSinkObject.Save(62, &e.owner) - stateSinkObject.Save(63, &e.linger) + stateSinkObject.Save(16, &e.portFlags) + stateSinkObject.Save(17, &e.boundBindToDevice) + stateSinkObject.Save(18, &e.boundPortFlags) + stateSinkObject.Save(19, &e.boundDest) + stateSinkObject.Save(20, &e.effectiveNetProtos) + stateSinkObject.Save(21, &e.workerRunning) + stateSinkObject.Save(22, &e.workerCleanup) + stateSinkObject.Save(23, &e.sendTSOk) + stateSinkObject.Save(24, &e.recentTS) + stateSinkObject.Save(26, &e.tsOffset) + stateSinkObject.Save(27, &e.shutdownFlags) + stateSinkObject.Save(28, &e.sackPermitted) + stateSinkObject.Save(29, &e.sack) + stateSinkObject.Save(30, &e.bindToDevice) + stateSinkObject.Save(31, &e.delay) + stateSinkObject.Save(32, &e.cork) + stateSinkObject.Save(33, &e.scoreboard) + stateSinkObject.Save(34, &e.slowAck) + stateSinkObject.Save(35, &e.segmentQueue) + stateSinkObject.Save(36, &e.synRcvdCount) + stateSinkObject.Save(37, &e.userMSS) + stateSinkObject.Save(38, &e.maxSynRetries) + stateSinkObject.Save(39, &e.windowClamp) + stateSinkObject.Save(40, &e.sndBufSize) + stateSinkObject.Save(41, &e.sndBufUsed) + stateSinkObject.Save(42, &e.sndClosed) + stateSinkObject.Save(43, &e.sndBufInQueue) + stateSinkObject.Save(44, &e.sndQueue) + stateSinkObject.Save(45, &e.cc) + stateSinkObject.Save(46, &e.packetTooBigCount) + stateSinkObject.Save(47, &e.sndMTU) + stateSinkObject.Save(48, &e.keepalive) + stateSinkObject.Save(49, &e.userTimeout) + stateSinkObject.Save(50, &e.deferAccept) + stateSinkObject.Save(52, &e.rcv) + stateSinkObject.Save(53, &e.snd) + stateSinkObject.Save(54, &e.connectingAddress) + stateSinkObject.Save(55, &e.amss) + stateSinkObject.Save(56, &e.sendTOS) + stateSinkObject.Save(57, &e.gso) + stateSinkObject.Save(58, &e.tcpLingerTimeout) + stateSinkObject.Save(59, &e.closed) + stateSinkObject.Save(60, &e.txHash) + stateSinkObject.Save(61, &e.owner) + stateSinkObject.Save(62, &e.linger) + stateSinkObject.Save(63, &e.ops) } func (e *endpoint) StateLoad(stateSourceObject state.Source) { @@ -314,56 +314,56 @@ func (e *endpoint) StateLoad(stateSourceObject state.Source) { stateSourceObject.Load(13, &e.ttl) stateSourceObject.Load(14, &e.v6only) stateSourceObject.Load(15, &e.isConnectNotified) - stateSourceObject.Load(16, &e.broadcast) - stateSourceObject.Load(17, &e.portFlags) - stateSourceObject.Load(18, &e.boundBindToDevice) - stateSourceObject.Load(19, &e.boundPortFlags) - stateSourceObject.Load(20, &e.boundDest) - stateSourceObject.Load(21, &e.effectiveNetProtos) - stateSourceObject.Load(22, &e.workerRunning) - stateSourceObject.Load(23, &e.workerCleanup) - stateSourceObject.Load(24, &e.sendTSOk) - stateSourceObject.Load(25, &e.recentTS) - stateSourceObject.Load(27, &e.tsOffset) - stateSourceObject.Load(28, &e.shutdownFlags) - stateSourceObject.Load(29, &e.sackPermitted) - stateSourceObject.Load(30, &e.sack) - stateSourceObject.Load(31, &e.bindToDevice) - stateSourceObject.Load(32, &e.delay) - stateSourceObject.Load(33, &e.cork) - stateSourceObject.Load(34, &e.scoreboard) - stateSourceObject.Load(35, &e.slowAck) - stateSourceObject.LoadWait(36, &e.segmentQueue) - stateSourceObject.Load(37, &e.synRcvdCount) - stateSourceObject.Load(38, &e.userMSS) - stateSourceObject.Load(39, &e.maxSynRetries) - stateSourceObject.Load(40, &e.windowClamp) - stateSourceObject.Load(41, &e.sndBufSize) - stateSourceObject.Load(42, &e.sndBufUsed) - stateSourceObject.Load(43, &e.sndClosed) - stateSourceObject.Load(44, &e.sndBufInQueue) - stateSourceObject.LoadWait(45, &e.sndQueue) - stateSourceObject.Load(46, &e.cc) - stateSourceObject.Load(47, &e.packetTooBigCount) - stateSourceObject.Load(48, &e.sndMTU) - stateSourceObject.Load(49, &e.keepalive) - stateSourceObject.Load(50, &e.userTimeout) - stateSourceObject.Load(51, &e.deferAccept) - stateSourceObject.LoadWait(53, &e.rcv) - stateSourceObject.LoadWait(54, &e.snd) - stateSourceObject.Load(55, &e.connectingAddress) - stateSourceObject.Load(56, &e.amss) - stateSourceObject.Load(57, &e.sendTOS) - stateSourceObject.Load(58, &e.gso) - stateSourceObject.Load(59, &e.tcpLingerTimeout) - stateSourceObject.Load(60, &e.closed) - stateSourceObject.Load(61, &e.txHash) - stateSourceObject.Load(62, &e.owner) - stateSourceObject.Load(63, &e.linger) + stateSourceObject.Load(16, &e.portFlags) + stateSourceObject.Load(17, &e.boundBindToDevice) + stateSourceObject.Load(18, &e.boundPortFlags) + stateSourceObject.Load(19, &e.boundDest) + stateSourceObject.Load(20, &e.effectiveNetProtos) + stateSourceObject.Load(21, &e.workerRunning) + stateSourceObject.Load(22, &e.workerCleanup) + stateSourceObject.Load(23, &e.sendTSOk) + stateSourceObject.Load(24, &e.recentTS) + stateSourceObject.Load(26, &e.tsOffset) + stateSourceObject.Load(27, &e.shutdownFlags) + stateSourceObject.Load(28, &e.sackPermitted) + stateSourceObject.Load(29, &e.sack) + stateSourceObject.Load(30, &e.bindToDevice) + stateSourceObject.Load(31, &e.delay) + stateSourceObject.Load(32, &e.cork) + stateSourceObject.Load(33, &e.scoreboard) + stateSourceObject.Load(34, &e.slowAck) + stateSourceObject.LoadWait(35, &e.segmentQueue) + stateSourceObject.Load(36, &e.synRcvdCount) + stateSourceObject.Load(37, &e.userMSS) + stateSourceObject.Load(38, &e.maxSynRetries) + stateSourceObject.Load(39, &e.windowClamp) + stateSourceObject.Load(40, &e.sndBufSize) + stateSourceObject.Load(41, &e.sndBufUsed) + stateSourceObject.Load(42, &e.sndClosed) + stateSourceObject.Load(43, &e.sndBufInQueue) + stateSourceObject.LoadWait(44, &e.sndQueue) + stateSourceObject.Load(45, &e.cc) + stateSourceObject.Load(46, &e.packetTooBigCount) + stateSourceObject.Load(47, &e.sndMTU) + stateSourceObject.Load(48, &e.keepalive) + stateSourceObject.Load(49, &e.userTimeout) + stateSourceObject.Load(50, &e.deferAccept) + stateSourceObject.LoadWait(52, &e.rcv) + stateSourceObject.LoadWait(53, &e.snd) + stateSourceObject.Load(54, &e.connectingAddress) + stateSourceObject.Load(55, &e.amss) + stateSourceObject.Load(56, &e.sendTOS) + stateSourceObject.Load(57, &e.gso) + stateSourceObject.Load(58, &e.tcpLingerTimeout) + stateSourceObject.Load(59, &e.closed) + stateSourceObject.Load(60, &e.txHash) + stateSourceObject.Load(61, &e.owner) + stateSourceObject.Load(62, &e.linger) + stateSourceObject.Load(63, &e.ops) stateSourceObject.LoadValue(3, new(string), func(y interface{}) { e.loadLastError(y.(string)) }) stateSourceObject.LoadValue(11, new(EndpointState), func(y interface{}) { e.loadState(y.(EndpointState)) }) - stateSourceObject.LoadValue(26, new(unixTime), func(y interface{}) { e.loadRecentTSTime(y.(unixTime)) }) - stateSourceObject.LoadValue(52, new([]*endpoint), func(y interface{}) { e.loadAcceptedChan(y.([]*endpoint)) }) + stateSourceObject.LoadValue(25, new(unixTime), func(y interface{}) { e.loadRecentTSTime(y.(unixTime)) }) + stateSourceObject.LoadValue(51, new([]*endpoint), func(y interface{}) { e.loadAcceptedChan(y.([]*endpoint)) }) stateSourceObject.AfterLoad(e.afterLoad) } diff --git a/pkg/tcpip/transport/udp/endpoint.go b/pkg/tcpip/transport/udp/endpoint.go index 9bcb918bb..57976d4e3 100644 --- a/pkg/tcpip/transport/udp/endpoint.go +++ b/pkg/tcpip/transport/udp/endpoint.go @@ -108,7 +108,6 @@ type endpoint struct { multicastLoop bool portFlags ports.Flags bindToDevice tcpip.NICID - broadcast bool noChecksum bool lastErrorMu sync.Mutex `state:"nosave"` @@ -157,6 +156,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 } // +stateify savable @@ -508,7 +510,7 @@ func (e *endpoint) write(p tcpip.Payloader, opts tcpip.WriteOptions) (int64, <-c resolve = route.Resolve } - if !e.broadcast && route.IsOutboundBroadcast() { + if !e.ops.GetBroadcast() && route.IsOutboundBroadcast() { return 0, nil, tcpip.ErrBroadcastDisabled } @@ -553,11 +555,6 @@ func (e *endpoint) Peek([][]byte) (int64, tcpip.ControlMessages, *tcpip.Error) { // SetSockOptBool implements tcpip.Endpoint.SetSockOptBool. func (e *endpoint) SetSockOptBool(opt tcpip.SockOptBool, v bool) *tcpip.Error { switch opt { - case tcpip.BroadcastOption: - e.mu.Lock() - e.broadcast = v - e.mu.Unlock() - case tcpip.MulticastLoopOption: e.mu.Lock() e.multicastLoop = v @@ -614,7 +611,6 @@ func (e *endpoint) SetSockOptBool(opt tcpip.SockOptBool, v bool) *tcpip.Error { e.v6only = v } - return nil } @@ -830,12 +826,6 @@ func (e *endpoint) SetSockOpt(opt tcpip.SettableSocketOption) *tcpip.Error { // GetSockOptBool implements tcpip.Endpoint.GetSockOptBool. func (e *endpoint) GetSockOptBool(opt tcpip.SockOptBool) (bool, *tcpip.Error) { switch opt { - case tcpip.BroadcastOption: - e.mu.RLock() - v := e.broadcast - e.mu.RUnlock() - return v, nil - case tcpip.KeepaliveEnabledOption: return false, nil @@ -1525,3 +1515,7 @@ func isBroadcastOrMulticast(a tcpip.Address) bool { func (e *endpoint) SetOwner(owner tcpip.PacketOwner) { e.owner = owner } + +func (e *endpoint) SocketOptions() *tcpip.SocketOptions { + return &e.ops +} diff --git a/pkg/tcpip/transport/udp/udp_state_autogen.go b/pkg/tcpip/transport/udp/udp_state_autogen.go index 06d025590..6a715cc10 100644 --- a/pkg/tcpip/transport/udp/udp_state_autogen.go +++ b/pkg/tcpip/transport/udp/udp_state_autogen.go @@ -72,7 +72,6 @@ func (e *endpoint) StateFields() []string { "multicastLoop", "portFlags", "bindToDevice", - "broadcast", "noChecksum", "lastError", "boundBindToDevice", @@ -86,6 +85,7 @@ func (e *endpoint) StateFields() []string { "effectiveNetProtos", "owner", "linger", + "ops", } } @@ -94,7 +94,7 @@ func (e *endpoint) StateSave(stateSinkObject state.Sink) { var rcvBufSizeMaxValue int = e.saveRcvBufSizeMax() stateSinkObject.SaveValue(5, rcvBufSizeMaxValue) var lastErrorValue string = e.saveLastError() - stateSinkObject.SaveValue(22, lastErrorValue) + stateSinkObject.SaveValue(21, lastErrorValue) stateSinkObject.Save(0, &e.TransportEndpointInfo) stateSinkObject.Save(1, &e.waiterQueue) stateSinkObject.Save(2, &e.uniqueID) @@ -114,19 +114,19 @@ func (e *endpoint) StateSave(stateSinkObject state.Sink) { stateSinkObject.Save(17, &e.multicastLoop) stateSinkObject.Save(18, &e.portFlags) stateSinkObject.Save(19, &e.bindToDevice) - stateSinkObject.Save(20, &e.broadcast) - stateSinkObject.Save(21, &e.noChecksum) - stateSinkObject.Save(23, &e.boundBindToDevice) - stateSinkObject.Save(24, &e.boundPortFlags) - stateSinkObject.Save(25, &e.sendTOS) - stateSinkObject.Save(26, &e.receiveTOS) - stateSinkObject.Save(27, &e.receiveTClass) - stateSinkObject.Save(28, &e.receiveIPPacketInfo) - stateSinkObject.Save(29, &e.shutdownFlags) - stateSinkObject.Save(30, &e.multicastMemberships) - stateSinkObject.Save(31, &e.effectiveNetProtos) - stateSinkObject.Save(32, &e.owner) - stateSinkObject.Save(33, &e.linger) + stateSinkObject.Save(20, &e.noChecksum) + stateSinkObject.Save(22, &e.boundBindToDevice) + stateSinkObject.Save(23, &e.boundPortFlags) + stateSinkObject.Save(24, &e.sendTOS) + stateSinkObject.Save(25, &e.receiveTOS) + stateSinkObject.Save(26, &e.receiveTClass) + stateSinkObject.Save(27, &e.receiveIPPacketInfo) + stateSinkObject.Save(28, &e.shutdownFlags) + stateSinkObject.Save(29, &e.multicastMemberships) + stateSinkObject.Save(30, &e.effectiveNetProtos) + stateSinkObject.Save(31, &e.owner) + stateSinkObject.Save(32, &e.linger) + stateSinkObject.Save(33, &e.ops) } func (e *endpoint) StateLoad(stateSourceObject state.Source) { @@ -149,21 +149,21 @@ func (e *endpoint) StateLoad(stateSourceObject state.Source) { stateSourceObject.Load(17, &e.multicastLoop) stateSourceObject.Load(18, &e.portFlags) stateSourceObject.Load(19, &e.bindToDevice) - stateSourceObject.Load(20, &e.broadcast) - stateSourceObject.Load(21, &e.noChecksum) - stateSourceObject.Load(23, &e.boundBindToDevice) - stateSourceObject.Load(24, &e.boundPortFlags) - stateSourceObject.Load(25, &e.sendTOS) - stateSourceObject.Load(26, &e.receiveTOS) - stateSourceObject.Load(27, &e.receiveTClass) - stateSourceObject.Load(28, &e.receiveIPPacketInfo) - stateSourceObject.Load(29, &e.shutdownFlags) - stateSourceObject.Load(30, &e.multicastMemberships) - stateSourceObject.Load(31, &e.effectiveNetProtos) - stateSourceObject.Load(32, &e.owner) - stateSourceObject.Load(33, &e.linger) + stateSourceObject.Load(20, &e.noChecksum) + stateSourceObject.Load(22, &e.boundBindToDevice) + stateSourceObject.Load(23, &e.boundPortFlags) + stateSourceObject.Load(24, &e.sendTOS) + stateSourceObject.Load(25, &e.receiveTOS) + stateSourceObject.Load(26, &e.receiveTClass) + stateSourceObject.Load(27, &e.receiveIPPacketInfo) + stateSourceObject.Load(28, &e.shutdownFlags) + stateSourceObject.Load(29, &e.multicastMemberships) + stateSourceObject.Load(30, &e.effectiveNetProtos) + stateSourceObject.Load(31, &e.owner) + stateSourceObject.Load(32, &e.linger) + stateSourceObject.Load(33, &e.ops) stateSourceObject.LoadValue(5, new(int), func(y interface{}) { e.loadRcvBufSizeMax(y.(int)) }) - stateSourceObject.LoadValue(22, new(string), func(y interface{}) { e.loadLastError(y.(string)) }) + stateSourceObject.LoadValue(21, new(string), func(y interface{}) { e.loadLastError(y.(string)) }) stateSourceObject.AfterLoad(e.afterLoad) } |