changeset 1327:207f58dad37a draft

Save the MTU when changing it. If we enter a state without a new MTU then restore the old one.
author Roy Marples <roy@marples.name>
date Fri, 03 Jul 2009 23:32:30 +0000
parents 1feeadf14c9d
children 697a7a94565b
files configure.c dhcpcd-hooks/10-mtu
diffstat 2 files changed, 20 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/configure.c	Fri Jul 03 19:13:26 2009 +0000
+++ b/configure.c	Fri Jul 03 23:32:30 2009 +0000
@@ -170,7 +170,7 @@
 	const struct interface *ifp;
 
 	/* Make our env */
-	elen = 7;
+	elen = 8;
 	env = xmalloc(sizeof(char *) * (elen + 1));
 	e = strlen("interface") + strlen(iface->name) + 2;
 	env[0] = xmalloc(e);
@@ -187,10 +187,12 @@
 	snprintf(env[4], e, "ifwireless=%d", iface->wireless);
 	env[5] = xmalloc(e);
 	snprintf(env[5], e, "ifflags=%u", iface->flags);
+	env[6] = xmalloc(e);
+	snprintf(env[6], e, "ifmtu=%d", get_mtu(iface->name));
 	l = e = strlen("interface_order=");
 	for (ifp = ifaces; ifp; ifp = ifp->next)
 		e += strlen(ifp->name) + 1;
-	p = env[6] = xmalloc(e);
+	p = env[7] = xmalloc(e);
 	strlcpy(p, "interface_order=", e);
 	e -= l;
 	p += l;
--- a/dhcpcd-hooks/10-mtu	Fri Jul 03 19:13:26 2009 +0000
+++ b/dhcpcd-hooks/10-mtu	Fri Jul 03 23:32:30 2009 +0000
@@ -1,8 +1,22 @@
 # Configure the MTU for the interface
 
-if [ -n "$new_interface_mtu" ]; then
+mtu_dir="$state_dir/mtu"
+
+if [ "$reason" = PREINIT -a -e "$mtu_dir/$interface" ]; then
+	rm "$mtu_dir/$interface"
+elif [ -n "$new_interface_mtu" ]; then
 	# The smalled MTU dhcpcd can work with is 576
 	if [ "$new_interface_mtu" -ge 576 ]; then
-		ifconfig "$interface" mtu "$new_interface_mtu"
+		if ifconfig "$interface" mtu "$new_interface_mtu"; then
+			# Save the MTU so we can restore it later
+			if [ ! -e "$mtu_dir/$interface" ]; then
+				mkdir -p "$mtu_dir"
+				echo "$ifmtu" > "$mtu_dir/$interface"
+			fi
+		fi
 	fi
+elif [ -e "$mtu_dir/$interface" ]; then
+	# No MTU in this state, so restore the prior MTU
+	ifconfig "$interface" mtu $(cat "$mtu_dir/$interface")
+	rm "$mtu_dir/$interface"
 fi