From 2bfff07ebdb20a94d83087950e125cc65c5757a6 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Wed, 9 Dec 1998 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1998-12-09 --- ip/ip.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/ip/ip.c b/ip/ip.c index 64085e1747200b6d3311170276ae7183d5261815..321419d5bdf6d64f14d1d90b445b0930c6366325 100644 --- a/ip/ip.c +++ b/ip/ip.c @@ -318,6 +318,7 @@ ipiput(Fs *f, uchar *ia, Block *bp) int notforme; uchar *dp, v6dst[IPaddrlen]; IP *ip; + Route *r, *sr; ip = f->ip; ip->istats.ipInReceives++; @@ -375,18 +376,31 @@ ipiput(Fs *f, uchar *ia, Block *bp) /* route */ if(notforme) { - if(ip->iprouting) { - /* gate */ - if(h->ttl <= 1){ - ip->istats.ipInHdrErrors++; - icmpttlexceeded(f, ia, bp); - freeblist(bp); - } else { - ip->istats.ipForwDatagrams++; - ipoput(f, bp, 1, h->ttl - 1); - } - } else + if(!ip->iprouting){ useriprouter(f, ia, bp); + return; + } + + /* don't forward to source's network */ + sr = v4lookup(f, h->src); + r = v4lookup(f, h->dst); + if(r == nil || sr == r){ + ip->istats.ipOutDiscards++; + freeblist(bp); + return; + } + + /* don't forward if packet has timed out */ + if(h->ttl <= 1){ + ip->istats.ipInHdrErrors++; + icmpttlexceeded(f, ia, bp); + freeblist(bp); + return; + } + + ip->istats.ipForwDatagrams++; + ipoput(f, bp, 1, h->ttl - 1); + return; }