From: Felix Fietkau Date: Sun, 22 Jan 2012 17:43:36 +0000 (+0100) Subject: move device settings to a separate struct X-Git-Url: https://git.archive.openwrt.org/?p=project%2Fnetifd.git;a=commitdiff_plain;h=91fa29a0d17b40963f67f08e740ca0a07365db90 move device settings to a separate struct --- diff --git a/device.c b/device.c index 7253bb9..f5a719a 100644 --- a/device.c +++ b/device.c @@ -178,30 +178,31 @@ static const struct device_type alias_device_type = { void device_init_settings(struct device *dev, struct blob_attr **tb) { + struct device_settings *s = &dev->settings; struct blob_attr *cur; struct ether_addr *ea; - dev->flags = 0; + s->flags = 0; dev->disabled = false; if ((cur = tb[DEV_ATTR_ENABLED])) device_set_disabled(dev, !blobmsg_get_bool(cur)); if ((cur = tb[DEV_ATTR_MTU])) { - dev->mtu = blobmsg_get_u32(cur); - dev->flags |= DEV_OPT_MTU; + s->mtu = blobmsg_get_u32(cur); + s->flags |= DEV_OPT_MTU; } if ((cur = tb[DEV_ATTR_TXQUEUELEN])) { - dev->txqueuelen = blobmsg_get_u32(cur); - dev->flags |= DEV_OPT_TXQUEUELEN; + s->txqueuelen = blobmsg_get_u32(cur); + s->flags |= DEV_OPT_TXQUEUELEN; } if ((cur = tb[DEV_ATTR_MACADDR])) { ea = ether_aton(blob_data(cur)); if (ea) { - memcpy(dev->macaddr, ea, sizeof(dev->macaddr)); - dev->flags |= DEV_OPT_MACADDR; + memcpy(s->macaddr, ea, 6); + s->flags |= DEV_OPT_MACADDR; } } } diff --git a/device.h b/device.h index 338138f..12176ce 100644 --- a/device.h +++ b/device.h @@ -74,6 +74,13 @@ struct device_user { void (*cb)(struct device_user *, enum device_event); }; +struct device_settings { + unsigned int flags; + unsigned int mtu; + unsigned int txqueuelen; + uint8_t macaddr[6]; +}; + /* * link layer device. typically represents a linux network device. * can be used to support VLANs as well @@ -105,12 +112,7 @@ struct device { struct device_user parent; - /* settings */ - unsigned int flags; - - unsigned int mtu; - unsigned int txqueuelen; - uint8_t macaddr[6]; + struct device_settings settings; }; struct device_hotplug_ops { diff --git a/system-linux.c b/system-linux.c index 2150c44..0ff2b3b 100644 --- a/system-linux.c +++ b/system-linux.c @@ -570,31 +570,30 @@ int system_vlan_del(struct device *dev) } static void -system_if_apply_settings(struct device *dev) +system_if_apply_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 (dev->flags & DEV_OPT_MTU) { - ifr.ifr_mtu = dev->mtu; + if (s->flags & DEV_OPT_MTU) { + ifr.ifr_mtu = s->mtu; ioctl(sock_ioctl, SIOCSIFMTU, &ifr); } - if (dev->flags & DEV_OPT_TXQUEUELEN) { - ifr.ifr_qlen = dev->txqueuelen; + if (s->flags & DEV_OPT_TXQUEUELEN) { + ifr.ifr_qlen = s->txqueuelen; ioctl(sock_ioctl, SIOCSIFTXQLEN, &ifr); } - if (dev->flags & DEV_OPT_MACADDR) { - memcpy(&ifr.ifr_hwaddr, dev->macaddr, sizeof(dev->macaddr)); + if (s->flags & DEV_OPT_MACADDR) { + memcpy(&ifr.ifr_hwaddr, s->macaddr, sizeof(s->macaddr)); ioctl(sock_ioctl, SIOCSIFHWADDR, &ifr); } - - dev->ifindex = system_if_resolve(dev); } int system_if_up(struct device *dev) { - system_if_apply_settings(dev); + system_if_apply_settings(dev, &dev->settings); + dev->ifindex = system_if_resolve(dev); return system_if_flags(dev->ifname, IFF_UP, 0); }