From 4b8f7a2110d80fdad0f09f376dbfd2204e2e8f8e Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Thu, 7 Mar 2019 22:39:50 +0100 Subject: [PATCH] devip: ignore the evil bit in fragment info field using ~IP_DF mask to select offset and "more fragments" bits includes the evil bit 15. so instead define a constant IP_FO for the fragment offset bits and use (IP_MF|IP_FO). that way the evil bit gets ignored and doesnt cause any useless calls to ipreassemble(). --- sys/src/9/ip/icmp.c | 2 +- sys/src/9/ip/ip.c | 8 ++++---- sys/src/9/ip/ip.h | 1 + 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/sys/src/9/ip/icmp.c b/sys/src/9/ip/icmp.c index 90c289f4b..5a2a810e8 100644 --- a/sys/src/9/ip/icmp.c +++ b/sys/src/9/ip/icmp.c @@ -401,7 +401,7 @@ icmpiput(Proto *icmp, Ipifc*, Block *bp) goto raise; } p = (Icmp *)bp->rp; - if((nhgets(p->frag) & ~(IP_DF|IP_MF)) == 0){ + if((nhgets(p->frag) & IP_FO) == 0){ pr = Fsrcvpcolx(icmp->f, p->proto); if(pr != nil && pr->advise != nil) { (*pr->advise)(pr, bp, msg); diff --git a/sys/src/9/ip/ip.c b/sys/src/9/ip/ip.c index ace707632..0752cb6f0 100644 --- a/sys/src/9/ip/ip.c +++ b/sys/src/9/ip/ip.c @@ -333,7 +333,7 @@ ipiput4(Fs *f, Ipifc *ifc, Block *bp) /* reassemble if the interface expects it */ if(nifc->reassemble){ frag = nhgets(h->frag); - if(frag & ~IP_DF) { + if(frag & (IP_MF|IP_FO)) { bp = ip4reassemble(ip, frag, bp); if(bp == nil) return; @@ -360,7 +360,7 @@ ipiput4(Fs *f, Ipifc *ifc, Block *bp) } frag = nhgets(h->frag); - if(frag & ~IP_DF) { + if(frag & (IP_MF|IP_FO)) { bp = ip4reassemble(ip, frag, bp); if(bp == nil) return; @@ -436,7 +436,7 @@ ip4reassemble(IP *ip, int offset, Block *bp) * and get rid of any fragments that might go * with it. */ - if((offset & ~IP_DF) == 0) { + if((offset & (IP_MF|IP_FO)) == 0) { if(f != nil) { ip->stats[ReasmFails]++; ipfragfree4(ip, f); @@ -451,7 +451,7 @@ ip4reassemble(IP *ip, int offset, Block *bp) } fp = (Ipfrag*)bp->base; - fp->foff = (offset & 0x1fff)<<3; + fp->foff = (offset & IP_FO)<<3; fp->flen = fragsize; /* First fragment allocates a reassembly queue */ diff --git a/sys/src/9/ip/ip.h b/sys/src/9/ip/ip.h index 1d7b369d9..8354abbe8 100644 --- a/sys/src/9/ip/ip.h +++ b/sys/src/9/ip/ip.h @@ -57,6 +57,7 @@ enum IP_HLEN4= 5, /* v4: Header length in words */ IP_DF= 0x4000, /* v4: Don't fragment */ IP_MF= 0x2000, /* v4: More fragments */ + IP_FO= 0x1fff, /* v4: Fragment offset */ IP4HDR= IP_HLEN4<<2, /* sizeof(Ip4hdr) */ IP_MAX= 64*1024, /* Max. Internet packet size, v4 & v6 */