git: 9front

Download patch

ref: 907c6f96a8776582663aa4a495b3995f8ac70408
parent: baeeb6625d82f23b29ea1b588facef185011b5df
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sun Sep 29 07:41:50 EDT 2024

ip/ipconfig: make ra limiter less agressive (thanks cgnarne)

For handling route invalidations, we have to allow
short bursts of traffic. Therefore we keep track
of the number of ra's received in the ra interal
and only start dropping packets when reaching 100
packets.

--- a/sys/src/cmd/ip/ipconfig/ipv6.c
+++ b/sys/src/cmd/ip/ipconfig/ipv6.c
@@ -807,7 +807,7 @@
 static int
 recvra6(void)
 {
-	int fd, n, sendrscnt, recvracnt, sleepfor;
+	int fd, n, sendrscnt, gotra, pktcnt, sleepfor;
 	uchar buf[4096];
 
 	fd = dialicmpv6(v6allnodesL, ICMP6_RA);
@@ -829,7 +829,6 @@
 	procsetname("recvra6 on %s %I", conf.dev, conf.lladdr);
 	notify(catch);
 
-	recvracnt = 0;
 	sendrscnt = 0;
 	if(recvra6on(myifc) == IsHostRecv){
 		sendrs(fd, v6allroutersL);
@@ -836,6 +835,8 @@
 		sendrscnt = Maxv6rss;
 	}
 
+	gotra = 0;
+	pktcnt = 0;
 	sleepfor = Minv6interradelay;
 
 	for (;;) {
@@ -844,9 +845,13 @@
 		sleepfor = alarm(0);
 
 		/* wait for alarm to expire */
-		if(recvracnt >= Maxv6initras && sleepfor > 100)
-			continue;
-
+		if(sleepfor > 100){
+			if(pktcnt > 100)
+				continue;
+			pktcnt++;
+		} else {
+			pktcnt = 1;
+		}
 		sleepfor = Maxv6radelay;
 
 		myifc = readipifc(conf.mpoint, myifc, myifc->index);
@@ -853,7 +858,7 @@
 		if(myifc == nil) {
 			warning("recvra6: can't read router params on %s, quitting on %s",
 				conf.mpoint, conf.dev);
-			if(recvracnt == 0)
+			if(!gotra)
 				rendezvous(recvra6, (void*)-1);
 			exits(nil);
 		}
@@ -863,7 +868,7 @@
 			break;
 		default:
 			warning("recvra6: recvra off, quitting on %s", conf.dev);
-			if(recvracnt == 0)
+			if(!gotra)
 				rendezvous(recvra6, (void*)-1);
 			exits(nil);
 		}
@@ -873,11 +878,11 @@
 				sendrscnt--;
 				sendrs(fd, v6allroutersL);
 				sleepfor = V6rsintvl + nrand(100);
-			} else if(recvracnt == 0) {
+			} else if(!gotra) {
+				gotra = 1;
 				warning("recvra6: no router advs after %d sols on %s",
 					Maxv6rss, conf.dev);
 				rendezvous(recvra6, (void*)0);
-				recvracnt = 1;
 			}
 			continue;
 		}
@@ -886,7 +891,8 @@
 			continue;
 
 		/* got at least initial ra; no whining */
-		if(recvracnt == 0){
+		if(!gotra){
+			gotra = 1;
 			if(dodhcp && conf.mflag){
 				dhcpv6query();
 				if(noconfig || !validip(conf.laddr))
@@ -903,11 +909,6 @@
 			}
 			rendezvous(recvra6, (void*)1);
 		}
-
-		if(recvracnt < Maxv6initras)
-			recvracnt++;
-		else
-			recvracnt = 1;
 	}
 }
 
--