From: Roy Marples Date: Fri, 3 Jul 2009 23:32:30 +0000 (+0000) Subject: Save the MTU when changing it. X-Git-Tag: v5.0.6~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=62009c79586ff8465dfe6d91258aa0af527b0421;p=thirdparty%2Fdhcpcd.git Save the MTU when changing it. If we enter a state without a new MTU then restore the old one. --- diff --git a/configure.c b/configure.c index 11ea58a5..a74074c6 100644 --- a/configure.c +++ b/configure.c @@ -170,7 +170,7 @@ make_env(const struct interface *iface, char ***argv) 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 @@ make_env(const struct interface *iface, char ***argv) 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; diff --git a/dhcpcd-hooks/10-mtu b/dhcpcd-hooks/10-mtu index e4bb651c..a9f874d8 100644 --- a/dhcpcd-hooks/10-mtu +++ b/dhcpcd-hooks/10-mtu @@ -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