PERFORCE change 74083 for review

Sam Leffler sam at FreeBSD.org
Tue Mar 29 21:23:14 PST 2005


http://perforce.freebsd.org/chv.cgi?CH=74083

Change 74083 by sam at sam_ebb on 2005/03/30 05:23:04

	save ip_next_mtu rewrite

Affected files ...

.. //depot/projects/wifi/sys/netinet/ip_icmp.c#3 edit

Differences ...

==== //depot/projects/wifi/sys/netinet/ip_icmp.c#3 (text+ko) ====

@@ -832,36 +832,34 @@
  * is returned; otherwise, a smaller value is returned.
  */
 static int
-ip_next_mtu(mtu, dir)
-	int mtu;
-	int dir;
+ip_next_mtu(int mtu, int dir)
 {
-	static int mtutab[] = {
+	static const int mtutab[] = {
 		65535, 32000, 17914, 8166, 4352, 2002, 1492, 1006, 508, 296,
 		68, 0
 	};
+#define	NMTU	(sizeof(mtutab) / sizeof(mtutab[0]))
 	int i;
 
-	for (i = 0; i < (sizeof mtutab) / (sizeof mtutab[0]); i++) {
-		if (mtu >= mtutab[i])
-			break;
+	if (mtu < 0) {
+#ifdef ICMPPRINTFS
+		if (icmpprintfs)
+			printf("%s: bogus mtu %d\n", mtu);
+#endif
+		return 0;
 	}
-
-	if (dir < 0) {
-		if (i == 0) {
-			return 0;
-		} else {
-			return mtutab[i - 1];
-		}
-	} else {
-		if (mtutab[i] == 0) {
-			return 0;
-		} else if(mtu > mtutab[i]) {
-			return mtutab[i];
-		} else {
-			return mtutab[i + 1];
-		}
+	if (dir < 0) {			/* next larger mtu */
+		for (i = 0; i < NMTU; i++)
+			if (mtu >= mtutab[i])
+				break;
+		return (i > 0 ? mtutab[i-1] : mtutab[0]);
+	} else {			/* next smaller mtu */
+		for (i = 0; i < NMTU; i++)
+			if (mtutab[i] < mtu)
+				break;
+		return (i < NMTU ? mtutab[i] : mtutab[NMTU-1]);
 	}
+#undef NMTU
 }
 
 


More information about the p4-projects mailing list