diff options
author | gVisor bot <gvisor-bot@google.com> | 2019-12-23 17:08:00 +0000 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2019-12-23 17:08:00 +0000 |
commit | 5128f604cb9f1fcf972339618d488d005d8ac25f (patch) | |
tree | ae0fe7c31375705a5fdb760a9eb3fa2ed1f808a7 /pkg/tcpip/stack/stack.go | |
parent | 4c8b622c6b83e02d1794cf3c61772a21d4bafce5 (diff) | |
parent | 5bc4ae9d5746e65909a0bdab60e7bd598d4401c7 (diff) |
Merge release-20191213.0-44-g5bc4ae9 (automated)
Diffstat (limited to 'pkg/tcpip/stack/stack.go')
-rw-r--r-- | pkg/tcpip/stack/stack.go | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/pkg/tcpip/stack/stack.go b/pkg/tcpip/stack/stack.go index 0e88643a4..7a9600679 100644 --- a/pkg/tcpip/stack/stack.go +++ b/pkg/tcpip/stack/stack.go @@ -662,11 +662,31 @@ func (s *Stack) Stats() tcpip.Stats { } // SetForwarding enables or disables the packet forwarding between NICs. +// +// When forwarding becomes enabled, any host-only state on all NICs will be +// cleaned up. func (s *Stack) SetForwarding(enable bool) { // TODO(igudger, bgeffon): Expose via /proc/sys/net/ipv4/ip_forward. s.mu.Lock() + defer s.mu.Unlock() + + // If forwarding status didn't change, do nothing further. + if s.forwarding == enable { + return + } + s.forwarding = enable - s.mu.Unlock() + + // If this stack does not support IPv6, do nothing further. + if _, ok := s.networkProtocols[header.IPv6ProtocolNumber]; !ok { + return + } + + if enable { + for _, nic := range s.nics { + nic.becomeIPv6Router() + } + } } // Forwarding returns if the packet forwarding between NICs is enabled. |