summaryrefslogtreecommitdiffhomepage
path: root/pkg/tcpip/stack/stack.go
diff options
context:
space:
mode:
authorIan Gudger <igudger@google.com>2019-03-12 14:36:58 -0700
committerShentubot <shentubot@google.com>2019-03-12 14:37:56 -0700
commita16f6e50c5a6465b94f367d62c7a46b34ef15f66 (patch)
tree6ad6ab66e1ed0c8da218f3db0afe47fc74452e06 /pkg/tcpip/stack/stack.go
parent8930e79ebf72a0cc69e9b81af37bcbb57b115543 (diff)
Make HandleLocal apply to all non-loopback interfaces.
HandleLocal is very similar conceptually to MULTICAST_LOOP, so we can unify the implementations. This has the benefit of making HandleLocal apply even when the fdbased link endpoint isn't in use. In addition, move looping logic to route creation so that it doesn't need to be run for each packet. This should improve performance. PiperOrigin-RevId: 238099480 Change-Id: I72839f16f25310471453bc9d3fb8544815b25c23
Diffstat (limited to 'pkg/tcpip/stack/stack.go')
-rw-r--r--pkg/tcpip/stack/stack.go13
1 files changed, 11 insertions, 2 deletions
diff --git a/pkg/tcpip/stack/stack.go b/pkg/tcpip/stack/stack.go
index 047b704e0..cbfe5c3c7 100644
--- a/pkg/tcpip/stack/stack.go
+++ b/pkg/tcpip/stack/stack.go
@@ -308,6 +308,9 @@ type Stack struct {
// clock is used to generate user-visible times.
clock tcpip.Clock
+
+ // handleLocal allows non-loopback interfaces to loop packets.
+ handleLocal bool
}
// Options contains optional Stack configuration.
@@ -319,6 +322,11 @@ type Options struct {
// Stats are optional statistic counters.
Stats tcpip.Stats
+
+ // HandleLocal indicates whether packets destined to their source
+ // should be handled by the stack internally (true) or outside the
+ // stack (false).
+ HandleLocal bool
}
// New allocates a new networking stack with only the requested networking and
@@ -343,6 +351,7 @@ func New(network []string, transport []string, opts Options) *Stack {
PortManager: ports.NewPortManager(),
clock: clock,
stats: opts.Stats.FillIn(),
+ handleLocal: opts.HandleLocal,
}
// Add specified network protocols.
@@ -764,7 +773,7 @@ func (s *Stack) FindRoute(id tcpip.NICID, localAddr, remoteAddr tcpip.Address, n
if id != 0 && !needRoute {
if nic, ok := s.nics[id]; ok {
if ref := s.getRefEP(nic, localAddr, netProto); ref != nil {
- return makeRoute(netProto, ref.ep.ID().LocalAddress, remoteAddr, nic.linkEP.LinkAddress(), ref, multicastLoop && !nic.loopback), nil
+ return makeRoute(netProto, ref.ep.ID().LocalAddress, remoteAddr, nic.linkEP.LinkAddress(), ref, s.handleLocal && !nic.loopback, multicastLoop && !nic.loopback), nil
}
}
} else {
@@ -780,7 +789,7 @@ func (s *Stack) FindRoute(id tcpip.NICID, localAddr, remoteAddr tcpip.Address, n
remoteAddr = ref.ep.ID().LocalAddress
}
- r := makeRoute(netProto, ref.ep.ID().LocalAddress, remoteAddr, nic.linkEP.LinkAddress(), ref, multicastLoop && !nic.loopback)
+ r := makeRoute(netProto, ref.ep.ID().LocalAddress, remoteAddr, nic.linkEP.LinkAddress(), ref, s.handleLocal && !nic.loopback, multicastLoop && !nic.loopback)
if needRoute {
r.NextHop = route.Gateway
}