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;
}
}
}
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
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 {
}
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);
}