summaryrefslogtreecommitdiffhomepage
path: root/pkg/tcpip/transport
diff options
context:
space:
mode:
authorgVisor bot <gvisor-bot@google.com>2020-02-27 19:04:41 +0000
committergVisor bot <gvisor-bot@google.com>2020-02-27 19:04:41 +0000
commit63dda1e49dfe377cf7e72e33a3254051b69bf1c9 (patch)
treed2ee5e8099ecc940108d74176cd7e78aeeb02e02 /pkg/tcpip/transport
parentd714e3b6098c356a2388c468ecca9f20f853f804 (diff)
parentabf7ebcd38e8c2750f4542f29115140bb2b44a9b (diff)
Merge release-20200219.0-52-gabf7ebc (automated)
Diffstat (limited to 'pkg/tcpip/transport')
-rwxr-xr-xpkg/tcpip/transport/packet/endpoint.go21
-rwxr-xr-xpkg/tcpip/transport/packet/packet_state_autogen.go2
2 files changed, 22 insertions, 1 deletions
diff --git a/pkg/tcpip/transport/packet/endpoint.go b/pkg/tcpip/transport/packet/endpoint.go
index 5722815e9..09a1cd436 100755
--- a/pkg/tcpip/transport/packet/endpoint.go
+++ b/pkg/tcpip/transport/packet/endpoint.go
@@ -76,6 +76,7 @@ type endpoint struct {
sndBufSize int
closed bool
stats tcpip.TransportEndpointStats `state:"nosave"`
+ bound bool
}
// NewEndpoint returns a new packet endpoint.
@@ -125,6 +126,7 @@ func (ep *endpoint) Close() {
}
ep.closed = true
+ ep.bound = false
ep.waiterQueue.Notify(waiter.EventHUp | waiter.EventErr | waiter.EventIn | waiter.EventOut)
}
@@ -216,7 +218,24 @@ func (ep *endpoint) Bind(addr tcpip.FullAddress) *tcpip.Error {
// sll_family (should be AF_PACKET), sll_protocol, and sll_ifindex."
// - packet(7).
- return tcpip.ErrNotSupported
+ ep.mu.Lock()
+ defer ep.mu.Unlock()
+
+ if ep.bound {
+ return tcpip.ErrAlreadyBound
+ }
+
+ // Unregister endpoint with all the nics.
+ ep.stack.UnregisterPacketEndpoint(0, ep.netProto, ep)
+
+ // Bind endpoint to receive packets from specific interface.
+ if err := ep.stack.RegisterPacketEndpoint(addr.NIC, ep.netProto, ep); err != nil {
+ return err
+ }
+
+ ep.bound = true
+
+ return nil
}
// GetLocalAddress implements tcpip.Endpoint.GetLocalAddress.
diff --git a/pkg/tcpip/transport/packet/packet_state_autogen.go b/pkg/tcpip/transport/packet/packet_state_autogen.go
index 1d90a383f..8ff339e08 100755
--- a/pkg/tcpip/transport/packet/packet_state_autogen.go
+++ b/pkg/tcpip/transport/packet/packet_state_autogen.go
@@ -38,6 +38,7 @@ func (x *endpoint) save(m state.Map) {
m.Save("rcvClosed", &x.rcvClosed)
m.Save("sndBufSize", &x.sndBufSize)
m.Save("closed", &x.closed)
+ m.Save("bound", &x.bound)
}
func (x *endpoint) load(m state.Map) {
@@ -50,6 +51,7 @@ func (x *endpoint) load(m state.Map) {
m.Load("rcvClosed", &x.rcvClosed)
m.Load("sndBufSize", &x.sndBufSize)
m.Load("closed", &x.closed)
+ m.Load("bound", &x.bound)
m.LoadValue("rcvBufSizeMax", new(int), func(y interface{}) { x.loadRcvBufSizeMax(y.(int)) })
m.AfterLoad(x.afterLoad)
}