diff options
-rw-r--r-- | alias.c | 11 | ||||
-rw-r--r-- | bridge.c | 12 | ||||
-rw-r--r-- | config.c | 2 | ||||
-rw-r--r-- | device.c | 20 | ||||
-rw-r--r-- | device.h | 23 | ||||
-rw-r--r-- | macvlan.c | 7 | ||||
-rw-r--r-- | tunnel.c | 9 | ||||
-rw-r--r-- | ubus.c | 2 | ||||
-rw-r--r-- | vlan.c | 2 | ||||
-rw-r--r-- | vlandev.c | 7 |
10 files changed, 53 insertions, 42 deletions
@@ -30,7 +30,7 @@ struct alias_device { char name[]; }; -static const struct device_type alias_device_type; +static struct device_type alias_device_type; static void alias_set_device(struct alias_device *alias, struct device *dev) { @@ -113,7 +113,8 @@ static void alias_device_cb(struct device_user *dep, enum device_event ev) } static struct device * -alias_device_create(const char *name, struct blob_attr *attr) +alias_device_create(const char *name, struct device_type *devtype, + struct blob_attr *attr) { struct alias_device *alias; @@ -124,7 +125,7 @@ alias_device_create(const char *name, struct blob_attr *attr) strcpy(alias->name, name); alias->dev.set_state = alias_device_set_state; alias->dev.hidden = true; - device_init_virtual(&alias->dev, &alias_device_type, NULL); + device_init_virtual(&alias->dev, devtype, NULL); alias->avl.key = alias->name; avl_insert(&aliases, &alias->avl); alias->dep.alias = true; @@ -162,7 +163,7 @@ static int alias_check_state(struct device *dev) return 0; } -static const struct device_type alias_device_type = { +static struct device_type alias_device_type = { .name = "Network alias", .create = alias_device_create, .free = alias_device_free, @@ -192,7 +193,7 @@ device_alias_get(const char *name) if (alias) return &alias->dev; - return alias_device_create(name, NULL); + return alias_device_create(name, &alias_device_type, NULL); } static void __init alias_init(void) @@ -72,15 +72,16 @@ static const struct uci_blob_param_list bridge_attr_list = { .next = { &device_attr_list }, }; -static struct device *bridge_create(const char *name, struct blob_attr *attr); +static struct device *bridge_create(const char *name, struct device_type *devtype, + struct blob_attr *attr); static void bridge_config_init(struct device *dev); static void bridge_free(struct device *dev); static void bridge_dump_info(struct device *dev, struct blob_buf *b); enum dev_change_type bridge_reload(struct device *dev, struct blob_attr *attr); -const struct device_type bridge_device_type = { - .name = "Bridge", +struct device_type bridge_device_type = { + .name = "bridge", .config_params = &bridge_attr_list, .create = bridge_create, @@ -699,7 +700,8 @@ bridge_retry_members(struct uloop_timeout *timeout) } static struct device * -bridge_create(const char *name, struct blob_attr *attr) +bridge_create(const char *name, struct device_type *devtype, + struct blob_attr *attr) { struct bridge_state *bst; struct device *dev = NULL; @@ -709,7 +711,7 @@ bridge_create(const char *name, struct blob_attr *attr) return NULL; dev = &bst->dev; - device_init(dev, &bridge_device_type, name); + device_init(dev, devtype, name); dev->config_pending = true; bst->retry.cb = bridge_retry_members; @@ -157,7 +157,7 @@ config_init_devices(void) uci_foreach_element(&uci_network->sections, e) { const struct uci_blob_param_list *params = NULL; struct uci_section *s = uci_to_section(e); - const struct device_type *devtype = NULL; + struct device_type *devtype = NULL; struct device *dev; const char *type, *name; @@ -118,11 +118,15 @@ simple_device_set_state(struct device *dev, bool state) } static struct device * -simple_device_create(const char *name, struct blob_attr *attr) +simple_device_create(const char *name, struct device_type *devtype, + struct blob_attr *attr) { struct blob_attr *tb[__DEV_ATTR_MAX]; struct device *dev = NULL; + /* device type is unused for simple devices */ + devtype = NULL; + blobmsg_parse(dev_attrs, __DEV_ATTR_MAX, tb, blob_data(attr), blob_len(attr)); dev = device_get(name, true); if (!dev) @@ -141,7 +145,7 @@ static void simple_device_free(struct device *dev) free(dev); } -const struct device_type simple_device_type = { +struct device_type simple_device_type = { .name = "Network device", .config_params = &device_attr_list, @@ -417,7 +421,7 @@ int device_check_state(struct device *dev) return dev->type->check_state(dev); } -void device_init_virtual(struct device *dev, const struct device_type *type, const char *name) +void device_init_virtual(struct device *dev, struct device_type *type, const char *name) { assert(dev); assert(type); @@ -434,7 +438,7 @@ void device_init_virtual(struct device *dev, const struct device_type *type, con dev->set_state = set_device_state; } -int device_init(struct device *dev, const struct device_type *type, const char *ifname) +int device_init(struct device *dev, struct device_type *type, const char *ifname) { int ret; @@ -729,7 +733,7 @@ device_init_pending(void) } static enum dev_change_type -device_set_config(struct device *dev, const struct device_type *type, +device_set_config(struct device *dev, struct device_type *type, struct blob_attr *attr) { struct blob_attr *tb[__DEV_ATTR_MAX]; @@ -758,7 +762,7 @@ device_set_config(struct device *dev, const struct device_type *type, } enum dev_change_type -device_apply_config(struct device *dev, const struct device_type *type, +device_apply_config(struct device *dev, struct device_type *type, struct blob_attr *config) { enum dev_change_type change; @@ -883,7 +887,7 @@ device_set_default_ps(bool state) } struct device * -device_create(const char *name, const struct device_type *type, +device_create(const char *name, struct device_type *type, struct blob_attr *config) { struct device *odev = NULL, *dev; @@ -908,7 +912,7 @@ device_create(const char *name, const struct device_type *type, if (!config) return NULL; - dev = type->create(name, config); + dev = type->create(name, type, config); if (!dev) return NULL; @@ -64,7 +64,8 @@ struct device_type { const struct uci_blob_param_list *config_params; - struct device *(*create)(const char *name, struct blob_attr *attr); + struct device *(*create)(const char *name, struct device_type *devtype, + struct blob_attr *attr); void (*config_init)(struct device *); enum dev_change_type (*reload)(struct device *, struct blob_attr *); void (*dump_info)(struct device *, struct blob_buf *buf); @@ -166,7 +167,7 @@ struct device_settings { * can be used to support VLANs as well */ struct device { - const struct device_type *type; + struct device_type *type; struct avl_node avl; struct safe_list users; @@ -217,30 +218,30 @@ struct device_hotplug_ops { }; extern const struct uci_blob_param_list device_attr_list; -extern const struct device_type simple_device_type; -extern const struct device_type bridge_device_type; -extern const struct device_type tunnel_device_type; -extern const struct device_type macvlan_device_type; -extern const struct device_type vlandev_device_type; +extern struct device_type simple_device_type; +extern struct device_type bridge_device_type; +extern struct device_type tunnel_device_type; +extern struct device_type macvlan_device_type; +extern struct device_type vlandev_device_type; void device_lock(void); void device_unlock(void); -struct device *device_create(const char *name, const struct device_type *type, +struct device *device_create(const char *name, struct device_type *type, struct blob_attr *config); void device_init_settings(struct device *dev, struct blob_attr **tb); void device_init_pending(void); enum dev_change_type -device_apply_config(struct device *dev, const struct device_type *type, +device_apply_config(struct device *dev, struct device_type *type, struct blob_attr *config); void device_reset_config(void); void device_reset_old(void); void device_set_default_ps(bool state); -void device_init_virtual(struct device *dev, const struct device_type *type, const char *name); -int device_init(struct device *iface, const struct device_type *type, const char *ifname); +void device_init_virtual(struct device *dev, struct device_type *type, const char *name); +int device_init(struct device *iface, struct device_type *type, const char *ifname); void device_cleanup(struct device *dev); struct device *device_find(const char *name); struct device *device_get(const char *name, int create); @@ -228,7 +228,8 @@ macvlan_reload(struct device *dev, struct blob_attr *attr) } static struct device * -macvlan_create(const char *name, struct blob_attr *attr) +macvlan_create(const char *name, struct device_type *devtype, + struct blob_attr *attr) { struct macvlan_device *mvdev; struct device *dev = NULL; @@ -238,7 +239,7 @@ macvlan_create(const char *name, struct blob_attr *attr) return NULL; dev = &mvdev->dev; - device_init(dev, &macvlan_device_type, name); + device_init(dev, devtype, name); dev->config_pending = true; mvdev->set_state = dev->set_state; @@ -252,7 +253,7 @@ macvlan_create(const char *name, struct blob_attr *attr) return dev; } -const struct device_type macvlan_device_type = { +struct device_type macvlan_device_type = { .name = "MAC VLAN", .config_params = &macvlan_attr_list, .create = macvlan_create, @@ -61,7 +61,8 @@ tunnel_reload(struct device *dev, struct blob_attr *attr) } static struct device * -tunnel_create(const char *name, struct blob_attr *attr) +tunnel_create(const char *name, struct device_type *devtype, + struct blob_attr *attr) { struct tunnel *tun; struct device *dev; @@ -71,10 +72,10 @@ tunnel_create(const char *name, struct blob_attr *attr) return NULL; dev = &tun->dev; - device_init(dev, &tunnel_device_type, name); + device_init(dev, devtype, name); tun->set_state = dev->set_state; dev->set_state = tunnel_set_state; - device_apply_config(dev, &tunnel_device_type, attr); + device_apply_config(dev, devtype, attr); device_set_present(dev, true); return dev; @@ -88,7 +89,7 @@ tunnel_free(struct device *dev) free(tun); } -const struct device_type tunnel_device_type = { +struct device_type tunnel_device_type = { .name = "IP tunnel", .config_params = &tunnel_attr_list, .reload = tunnel_reload, @@ -685,7 +685,7 @@ netifd_dump_status(struct interface *iface) if (iface->ip4table) blobmsg_add_u32(&b, "ip4table", iface->ip4table); if (iface->ip6table) - blobmsg_add_u32(&b, "ip6table", iface->ip6table); + blobmsg_add_u32(&b, "ip6table", iface->ip6table); blobmsg_add_u32(&b, "metric", iface->metric); blobmsg_add_u8(&b, "delegation", !iface->proto_ip.no_delegation); a = blobmsg_open_array(&b, "ipv4-address"); @@ -96,7 +96,7 @@ static void vlan_dev_cb(struct device_user *dep, enum device_event ev) static struct device *get_vlan_device(struct device *dev, int id, bool create) { - static const struct device_type vlan_type = { + static struct device_type vlan_type = { .name = "VLAN", .config_params = &device_attr_list, .free = free_vlan_if, @@ -216,7 +216,8 @@ vlandev_reload(struct device *dev, struct blob_attr *attr) } static struct device * -vlandev_create(const char *name, struct blob_attr *attr) +vlandev_create(const char *name, struct device_type *devtype, + struct blob_attr *attr) { struct vlandev_device *mvdev; struct device *dev = NULL; @@ -226,7 +227,7 @@ vlandev_create(const char *name, struct blob_attr *attr) return NULL; dev = &mvdev->dev; - device_init(dev, &vlandev_device_type, name); + device_init(dev, devtype, name); dev->config_pending = true; mvdev->set_state = dev->set_state; @@ -240,7 +241,7 @@ vlandev_create(const char *name, struct blob_attr *attr) return dev; } -const struct device_type vlandev_device_type = { +struct device_type vlandev_device_type = { .name = "VLANDEV", .config_params = &vlandev_attr_list, .create = vlandev_create, |