shithub: riscv

Download patch

ref: c5c613357e45af55b9cca2ae90cfc89895a2bd48
parent: 26aca332bb74cf8ee6f27ee7f826413a19182ca9
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sun Apr 22 14:48:08 EDT 2018

devip: cleanup udp.c

--- a/sys/src/9/ip/udp.c
+++ b/sys/src/9/ip/udp.c
@@ -474,13 +474,11 @@
 	}
 
 	if(qfull(c->rq)){
-		netlog(f, Logudp, "udp: qfull %I.%d -> %I.%d\n", raddr, rport,
-		       laddr, lport);
+		netlog(f, Logudp, "udp: qfull %I.%d -> %I.%d\n",
+			raddr, rport, laddr, lport);
 		freeblist(bp);
 	} else {
-		if(bp->next)
-			bp = concatblock(bp);
-		qpass(c->rq, bp);
+		qpass(c->rq, concatblock(bp));
 	}
 	qunlock(c);
 
@@ -514,34 +512,25 @@
 	uchar source[IPaddrlen], dest[IPaddrlen];
 	ushort psource, pdest;
 	Conv *s, **p;
-	int version;
 
 	h4 = (Udp4hdr*)(bp->rp);
-	version = ((h4->vihl&0xF0)==IP_VER6) ? V6 : V4;
+	h6 = (Udp6hdr*)(bp->rp);
 
-	switch(version) {
-	case V4:
+	if((h4->vihl&0xF0)==IP_VER4) {
 		v4tov6(dest, h4->udpdst);
 		v4tov6(source, h4->udpsrc);
 		psource = nhgets(h4->udpsport);
 		pdest = nhgets(h4->udpdport);
-		break;
-	case V6:
-		h6 = (Udp6hdr*)(bp->rp);
+	} else {
 		ipmove(dest, h6->udpdst);
 		ipmove(source, h6->udpsrc);
 		psource = nhgets(h6->udpsport);
 		pdest = nhgets(h6->udpdport);
-		break;
-	default:
-		panic("udpadvise: version %d", version);
-		return;  /* to avoid a warning */
 	}
 
 	/* Look for a connection */
 	qlock(udp);
-	for(p = udp->conv; *p; p++) {
-		s = *p;
+	for(p = udp->conv; (s = *p) != nil; p++) {
 		if(s->rport == pdest)
 		if(s->lport == psource)
 		if(ipcmp(s->raddr, dest) == 0)