move device settings to a separate struct
authorFelix Fietkau <nbd@openwrt.org>
Sun, 22 Jan 2012 17:43:36 +0000 (18:43 +0100)
committerFelix Fietkau <nbd@openwrt.org>
Sun, 22 Jan 2012 17:43:36 +0000 (18:43 +0100)
device.c
device.h
system-linux.c

index 7253bb9..f5a719a 100644 (file)
--- 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)
 {
 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;
 
        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->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])) {
        }
 
        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) {
        }
 
        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;
                }
        }
 }
                }
        }
 }
index 338138f..12176ce 100644 (file)
--- a/device.h
+++ b/device.h
@@ -74,6 +74,13 @@ struct device_user {
        void (*cb)(struct device_user *, enum device_event);
 };
 
        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
 /* 
  * 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;
 
 
        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 {
 };
 
 struct device_hotplug_ops {
index 2150c44..0ff2b3b 100644 (file)
@@ -570,31 +570,30 @@ int system_vlan_del(struct device *dev)
 }
 
 static void
 }
 
 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));
 {
        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);
        }
                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);
        }
                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);
        }
                ioctl(sock_ioctl, SIOCSIFHWADDR, &ifr);
        }
-
-       dev->ifindex = system_if_resolve(dev);
 }
 
 int system_if_up(struct device *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);
 }
 
        return system_if_flags(dev->ifname, IFF_UP, 0);
 }