From 5a370d545ad8287025c223a8aceff9fe46274200 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Mon, 27 Jul 2020 15:53:31 +0000 Subject: [PATCH] tstest/natlab: drop packets that can't be routed in a LAN. LANs are authoritative for their prefixes, so we should not bounce packets back and forth to the default gateway in that case. Signed-off-by: David Anderson --- tstest/natlab/natlab.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tstest/natlab/natlab.go b/tstest/natlab/natlab.go index 230039564..72716dce1 100644 --- a/tstest/natlab/natlab.go +++ b/tstest/natlab/natlab.go @@ -184,6 +184,17 @@ func (n *Network) write(p *Packet) (num int, err error) { defer n.mu.Unlock() iface, ok := n.machine[p.Dst.IP] if !ok { + // If the destination is within the network's authoritative + // range, no route to host. + if p.Dst.IP.Is4() && n.Prefix4.Contains(p.Dst.IP) { + p.Trace("no route to %v", p.Dst.IP) + return len(p.Payload), nil + } + if p.Dst.IP.Is6() && n.Prefix6.Contains(p.Dst.IP) { + p.Trace("no route to %v", p.Dst.IP) + return len(p.Payload), nil + } + if n.defaultGW == nil { p.Trace("no route to %v", p.Dst.IP) return len(p.Payload), nil