diff options
author | gVisor bot <gvisor-bot@google.com> | 2020-02-21 19:24:01 +0000 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2020-02-21 19:24:01 +0000 |
commit | 342d41ff2a03e94dcf87e2c693b7c61e62004392 (patch) | |
tree | 8ba8f6dcd6c7c6f9da1048a70f42af2b4107e1a8 /pkg/tcpip | |
parent | 4bbbadf9be518641dd6fa62404f075a591cccfbb (diff) | |
parent | a155a23480abfafe096ff50f2c4aaf2c215b6c44 (diff) |
Merge release-20200211.0-62-ga155a23 (automated)
Diffstat (limited to 'pkg/tcpip')
-rw-r--r-- | pkg/tcpip/stack/nic.go | 25 | ||||
-rw-r--r-- | pkg/tcpip/stack/stack.go | 5 |
2 files changed, 12 insertions, 18 deletions
diff --git a/pkg/tcpip/stack/nic.go b/pkg/tcpip/stack/nic.go index b2be18e47..862954ab2 100644 --- a/pkg/tcpip/stack/nic.go +++ b/pkg/tcpip/stack/nic.go @@ -44,8 +44,7 @@ type NIC struct { linkEP LinkEndpoint context NICContext - stats NICStats - attach sync.Once + stats NICStats mu struct { sync.RWMutex @@ -141,6 +140,8 @@ func newNIC(stack *Stack, id tcpip.NICID, name string, ep LinkEndpoint, ctx NICC nic.mu.packetEPs[netProto.Number()] = []PacketEndpoint{} } + nic.linkEP.Attach(nic) + return nic } @@ -200,14 +201,16 @@ func (n *NIC) disable() *tcpip.Error { } } - // TODO(b/147015577): Should n detach from its LinkEndpoint? - n.mu.enabled = false return nil } -// enable enables n. enable will attach the nic to its LinkEndpoint and -// join the IPv6 All-Nodes Multicast address (ff02::1). +// enable enables n. +// +// If the stack has IPv6 enabled, enable will join the IPv6 All-Nodes Multicast +// address (ff02::1), start DAD for permanent addresses, and start soliciting +// routers if the stack is not operating as a router. If the stack is also +// configured to auto-generate a link-local address, one will be generated. func (n *NIC) enable() *tcpip.Error { n.mu.RLock() enabled := n.mu.enabled @@ -225,8 +228,6 @@ func (n *NIC) enable() *tcpip.Error { n.mu.enabled = true - n.attachLinkEndpoint() - // Create an endpoint to receive broadcast packets on this interface. if _, ok := n.stack.networkProtocols[header.IPv4ProtocolNumber]; ok { if _, err := n.addAddressLocked(ipv4BroadcastAddr, NeverPrimaryEndpoint, permanent, static, false /* deprecated */); err != nil { @@ -321,14 +322,6 @@ func (n *NIC) becomeIPv6Host() { n.mu.ndp.startSolicitingRouters() } -// attachLinkEndpoint attaches the NIC to the endpoint, which will enable it -// to start delivering packets. -func (n *NIC) attachLinkEndpoint() { - n.attach.Do(func() { - n.linkEP.Attach(n) - }) -} - // setPromiscuousMode enables or disables promiscuous mode. func (n *NIC) setPromiscuousMode(enable bool) { n.mu.Lock() diff --git a/pkg/tcpip/stack/stack.go b/pkg/tcpip/stack/stack.go index fabc976a7..f0ed76fbe 100644 --- a/pkg/tcpip/stack/stack.go +++ b/pkg/tcpip/stack/stack.go @@ -881,6 +881,8 @@ type NICOptions struct { // CreateNICWithOptions creates a NIC with the provided id, LinkEndpoint, and // NICOptions. See the documentation on type NICOptions for details on how // NICs can be configured. +// +// LinkEndpoint.Attach will be called to bind ep with a NetworkDispatcher. func (s *Stack) CreateNICWithOptions(id tcpip.NICID, ep LinkEndpoint, opts NICOptions) *tcpip.Error { s.mu.Lock() defer s.mu.Unlock() @@ -900,7 +902,6 @@ func (s *Stack) CreateNICWithOptions(id tcpip.NICID, ep LinkEndpoint, opts NICOp } n := newNIC(s, id, opts.Name, ep, opts.Context) - s.nics[id] = n if !opts.Disabled { return n.enable() @@ -910,7 +911,7 @@ func (s *Stack) CreateNICWithOptions(id tcpip.NICID, ep LinkEndpoint, opts NICOp } // CreateNIC creates a NIC with the provided id and LinkEndpoint and calls -// `LinkEndpoint.Attach` to start delivering packets to it. +// LinkEndpoint.Attach to bind ep with a NetworkDispatcher. func (s *Stack) CreateNIC(id tcpip.NICID, ep LinkEndpoint) *tcpip.Error { return s.CreateNICWithOptions(id, ep, NICOptions{}) } |