shithub: riscv

Download patch

ref: 827020f6863490c649470087008ab5ca8138afc0
parent: a1fceabd5ba5f54d7a54a8bfa9138230f2372267
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sun Mar 3 22:08:27 EST 2019

devip: zero fragment offset after reassembly, remove tos magic, cleanup

--- a/sys/src/9/ip/ip.c
+++ b/sys/src/9/ip/ip.c
@@ -250,7 +250,7 @@
 void
 ipiput4(Fs *f, Ipifc *ifc, Block *bp)
 {
-	int hl, len, hop, tos, proto;
+	int hl, len, hop, tos;
 	uchar v6dst[IPaddrlen];
 	ushort frag;
 	Ip4hdr *h;
@@ -334,9 +334,6 @@
 		if(nifc->reassemble){
 			frag = nhgets(h->frag);
 			if(frag & ~IP_DF) {
-				h->tos = 0;
-				if(frag & IP_MF)
-					h->tos = 1;
 				bp = ip4reassemble(ip, frag, bp);
 				if(bp == nil)
 					return;
@@ -364,9 +361,6 @@
 
 	frag = nhgets(h->frag);
 	if(frag & ~IP_DF) {
-		h->tos = 0;
-		if(frag & IP_MF)
-			h->tos = 1;
 		bp = ip4reassemble(ip, frag, bp);
 		if(bp == nil)
 			return;
@@ -373,12 +367,7 @@
 		h = (Ip4hdr*)bp->rp;
 	}
 
-	/* don't let any frag info go up the stack */
-	h->frag[0] = 0;
-	h->frag[1] = 0;
-
-	proto = h->proto;
-	p = Fsrcvpcol(f, proto);
+	p = Fsrcvpcol(f, h->proto);
 	if(p != nil && p->rcv != nil) {
 		ip->stats[InDelivers]++;
 		(*p->rcv)(p, ifc, bp);
@@ -434,7 +423,7 @@
 	 */
 	for(f = ip->flisthead4; f != nil; f = fnext){
 		fnext = f->next;	/* because ipfragfree4 changes the list */
-		if(f->src == src && f->dst == dst && f->id == id)
+		if(f->id == id && f->src == src && f->dst == dst)
 			break;
 		if(f->age < NOW){
 			ip->stats[ReasmTimeout]++;
@@ -447,7 +436,7 @@
 	 *  and get rid of any fragments that might go
 	 *  with it.
 	 */
-	if(ih->tos == 0 && (offset & ~(IP_MF|IP_DF)) == 0) {
+	if((offset & ~IP_DF) == 0) {
 		if(f != nil) {
 			ip->stats[ReasmFails]++;
 			ipfragfree4(ip, f);
@@ -574,6 +563,8 @@
 		ipfragfree4(ip, f);
 
 		ih = (Ip4hdr*)bl->rp;
+		ih->frag[0] = 0;
+		ih->frag[1] = 0;
 		hnputs(ih->length, len);
 
 		ip->stats[ReasmOKs]++;
@@ -595,10 +586,10 @@
 
 	if(frag->blist != nil)
 		freeblist(frag->blist);
-
-	frag->src = 0;
-	frag->id = 0;
 	frag->blist = nil;
+	frag->id = 0;
+	frag->src = 0;
+	frag->dst = 0;
 
 	l = &ip->flisthead4;
 	for(fl = *l; fl != nil; fl = fl->next) {