summaryrefslogtreecommitdiff
path: root/sys/src/9/ip/ip.c
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2018-04-19 01:08:51 +0200
committercinap_lenrek <cinap_lenrek@felloff.net>2018-04-19 01:08:51 +0200
commit638b4a1ec113adebdd6a85d647574a46e0b7feab (patch)
treea7f73ff337561664e71c95124a37179e20299310 /sys/src/9/ip/ip.c
parent691370a08dbfda305f0302023618211ffbfbce7a (diff)
devip: add "reflect" ctl message, fix memory leaks in icmpv6, fix source address for icmpttlexceeded, cleanup
Diffstat (limited to 'sys/src/9/ip/ip.c')
-rw-r--r--sys/src/9/ip/ip.c28
1 files changed, 12 insertions, 16 deletions
diff --git a/sys/src/9/ip/ip.c b/sys/src/9/ip/ip.c
index d296c2ed0..948125737 100644
--- a/sys/src/9/ip/ip.c
+++ b/sys/src/9/ip/ip.c
@@ -333,8 +333,7 @@ ipiput4(Fs *f, Ipifc *ifc, Block *bp)
if((bp->flag & Bipck) == 0 && ipcsum(&h->vihl)) {
ip->stats[InHdrErrors]++;
netlog(f, Logip, "ip: checksum error %V\n", h->src);
- freeblist(bp);
- return;
+ goto drop;
}
v4tov6(v6dst, h->dst);
notforme = ipforme(f, v6dst) == 0;
@@ -345,8 +344,7 @@ ipiput4(Fs *f, Ipifc *ifc, Block *bp)
if(hl < (IP_HLEN4<<2)) {
ip->stats[InHdrErrors]++;
netlog(f, Logip, "ip: %V bad hivl %ux\n", h->src, h->vihl);
- freeblist(bp);
- return;
+ goto drop;
}
/* If this is not routed strip off the options */
if(notforme == 0) {
@@ -364,33 +362,30 @@ ipiput4(Fs *f, Ipifc *ifc, Block *bp)
if(notforme) {
Route *r;
Routehint rh;
+ Ipifc *toifc;
- if(!ip->iprouting){
- freeblist(bp);
- return;
- }
+ if(!ip->iprouting)
+ goto drop;
/* don't forward to source's network */
rh.r = nil;
r = v4lookup(f, h->dst, h->src, &rh);
- if(r == nil || r->ifc == ifc){
+ if(r == nil || (toifc = r->ifc) == nil
+ || (toifc == ifc && !ifc->reflect)){
ip->stats[OutDiscards]++;
- freeblist(bp);
- return;
+ goto drop;
}
/* don't forward if packet has timed out */
hop = h->ttl;
if(hop < 1) {
ip->stats[InHdrErrors]++;
- icmpttlexceeded(f, ifc->lifc->local, bp);
- freeblist(bp);
- return;
+ icmpttlexceeded(f, ifc, bp);
+ goto drop;
}
/* reassemble if the interface expects it */
-if(r->ifc == nil) panic("nil route ifc");
- if(r->ifc->reassemble){
+ if(toifc->reassemble){
frag = nhgets(h->frag);
if(frag & ~IP_DF) {
h->tos = 0;
@@ -434,6 +429,7 @@ if(r->ifc == nil) panic("nil route ifc");
}
ip->stats[InDiscards]++;
ip->stats[InUnknownProtos]++;
+drop:
freeblist(bp);
}