summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2009-07-03 23:32:30 +0000
committerRoy Marples <roy@marples.name>2009-07-03 23:32:30 +0000
commit62009c79586ff8465dfe6d91258aa0af527b0421 (patch)
tree8245b7a31e61ad94a60ed137897000d18c1a256c
parent3e87456b9a7be1824e0346d973d6f76776b5ef1e (diff)
downloaddhcpcd-62009c79586ff8465dfe6d91258aa0af527b0421.tar.xz
Save the MTU when changing it.
If we enter a state without a new MTU then restore the old one.
-rw-r--r--configure.c6
-rw-r--r--dhcpcd-hooks/10-mtu18
2 files changed, 20 insertions, 4 deletions
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