diff options
author | Felix Fietkau <nbd@openwrt.org> | 2012-01-22 19:00:04 +0100 |
---|---|---|
committer | Felix Fietkau <nbd@openwrt.org> | 2012-01-22 19:00:04 +0100 |
commit | 677f9754526a7923417fb70f9a8a38adaeb251a6 (patch) | |
tree | 77367d773a2ad733de771deb935b587904f1335f /system-linux.c | |
parent | 91fa29a0d17b40963f67f08e740ca0a07365db90 (diff) |
save and restore previous device settings when overriding them via config
Diffstat (limited to 'system-linux.c')
-rw-r--r-- | system-linux.c | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/system-linux.c b/system-linux.c index 0ff2b3b..4fa0ead 100644 --- a/system-linux.c +++ b/system-linux.c @@ -570,6 +570,30 @@ int system_vlan_del(struct device *dev) } 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) { struct ifreq ifr; @@ -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) |