Plan 9 from Bell Labs’s /usr/web/sources/contrib/yk/dist/9legacy/applied/ip-ipconfig-mtu.diff

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


--- /n/sources/plan9/sys/src/cmd/ip/ipconfig/main.c	Mon Jun 24 22:35:14 2013
+++ /sys/src/cmd/ip/ipconfig/main.c	Fri Apr 15 00:00:00 2016
@@ -36,6 +36,7 @@
 	Taddrs,
 	Tstr,
 	Tbyte,
+	Tushort,
 	Tulong,
 	Tvec,
 };
@@ -79,7 +80,7 @@
 [OBttl]			{ "ttl",		Tulong },
 [OBpathtimeout]		{ "pathtimeout",	Taddrs },
 [OBpathplateau]		{ "pathplateau",	Taddrs },
-[OBmtu]			{ "mtu",		Tulong },
+[OBmtu]			{ "mtu",		Tushort },
 [OBsubnetslocal]	{ "subnetslocal",	Taddrs },
 [OBbaddr]		{ "baddr",		Taddrs },
 [OBdiscovermask]	{ "discovermask",	Taddrs },
@@ -208,6 +209,7 @@
 int	optgetbyte(uchar*, int);
 int	optgetstr(uchar*, int, char*, int);
 uchar*	optget(uchar*, int, int*);
+ushort	optgetushort(uchar*, int);
 ulong	optgetulong(uchar*, int);
 int	optgetvec(uchar*, int, uchar*, int);
 char*	optgetx(uchar*, uchar);
@@ -842,6 +844,15 @@
 		return -1;
 	}
 
+	if(!validip(conf.raddr) && conf.mtu != 0){
+		n = snprint(buf, sizeof buf, " mtu %d", conf.mtu);
+
+		if(write(conf.cfd, buf, n) < 0){
+			warning("write(%s): %r", buf);
+			return -1;
+		}
+	}
+
 	if(beprimary==1 && validip(conf.gaddr))
 		adddefroute(conf.mpoint, conf.gaddr);
 
@@ -1263,6 +1276,14 @@
 		optgetstr(bp->optdata, OBdomainname,
 			conf.domainname, sizeof conf.domainname);
 
+		/* get mtu */
+		if(conf.mtu == 0){
+			conf.mtu = optgetushort(bp->optdata, OBmtu);
+			if(conf.mtu != 0)
+				conf.mtu += 14; /* size of ethernet header */
+			DEBUG("mtu=%d ", conf.mtu);
+		}
+
 		/* get anything else we asked for */
 		getoptions(bp->optdata);
 
@@ -1459,6 +1480,18 @@
 	if(p == nil)
 		return 0;
 	return *p;
+}
+
+ushort
+optgetushort(uchar *p, int op)
+{
+	int len;
+
+	len = 2;
+	p = optget(p, op, &len);
+	if(p == nil)
+		return 0;
+	return nhgets(p);
 }
 
 ulong

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].