From 677f9754526a7923417fb70f9a8a38adaeb251a6 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Sun, 22 Jan 2012 19:00:04 +0100 Subject: [PATCH] save and restore previous device settings when overriding them via config --- device.h | 1 + system-linux.c | 29 ++++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/device.h b/device.h index 12176ce..2b7fb13 100644 --- a/device.h +++ b/device.h @@ -112,6 +112,7 @@ struct device { struct device_user parent; + struct device_settings orig_settings; struct device_settings settings; }; diff --git a/system-linux.c b/system-linux.c index 0ff2b3b..4fa0ead 100644 --- a/system-linux.c +++ b/system-linux.c @@ -569,6 +569,30 @@ int system_vlan_del(struct device *dev) return system_vlan(dev, -1); } +static void +system_if_get_settings(struct device *dev, struct device_settings *s) +{ + struct ifreq ifr; + + memset(&ifr, 0, sizeof(ifr)); + strncpy(ifr.ifr_name, dev->ifname, sizeof(ifr.ifr_name)); + + if (ioctl(sock_ioctl, SIOCGIFMTU, &ifr) == 0) { + s->mtu = ifr.ifr_mtu; + s->flags |= DEV_OPT_MTU; + } + + if (ioctl(sock_ioctl, SIOCGIFTXQLEN, &ifr) == 0) { + s->txqueuelen = ifr.ifr_qlen; + s->flags |= DEV_OPT_TXQUEUELEN; + } + + if (ioctl(sock_ioctl, SIOCGIFHWADDR, &ifr) == 0) { + memcpy(s->macaddr, &ifr.ifr_hwaddr, sizeof(s->macaddr)); + s->flags |= DEV_OPT_MACADDR; + } +} + static void system_if_apply_settings(struct device *dev, struct device_settings *s) { @@ -592,6 +616,7 @@ system_if_apply_settings(struct device *dev, struct device_settings *s) int system_if_up(struct device *dev) { + system_if_get_settings(dev, &dev->orig_settings); system_if_apply_settings(dev, &dev->settings); dev->ifindex = system_if_resolve(dev); return system_if_flags(dev->ifname, IFF_UP, 0); @@ -599,7 +624,9 @@ int system_if_up(struct device *dev) int system_if_down(struct device *dev) { - return system_if_flags(dev->ifname, 0, IFF_UP); + int ret = system_if_flags(dev->ifname, 0, IFF_UP); + system_if_apply_settings(dev, &dev->orig_settings); + return ret; } int system_if_check(struct device *dev) -- 2.25.1