};
static struct device *bridge_create(struct blob_attr *attr);
+static void bridge_config_init(struct device *dev);
static void bridge_free(struct device *dev);
static void bridge_dump_status(struct device *dev, struct blob_buf *b);
.config_params = &bridge_attr_list,
.create = bridge_create,
+ .config_init = bridge_config_init,
.free = bridge_free,
.dump_status = bridge_dump_status,
};
struct device dev;
device_state_cb set_state;
+ struct blob_attr *ifnames;
bool active;
struct list_head members;
blobmsg_close_array(b, list);
}
+static void
+bridge_config_init(struct device *dev)
+{
+ struct bridge_state *bst;
+ struct blob_attr *cur;
+ int rem;
+
+ bst = container_of(dev, struct bridge_state, dev);
+ blobmsg_for_each_attr(cur, bst->ifnames, rem) {
+ bridge_add_member(bst, blobmsg_data(cur));
+ }
+}
+
static struct device *
bridge_create(struct blob_attr *attr)
{
struct blob_attr *tb_dev[__DEV_ATTR_MAX];
struct blob_attr *tb_br[__BRIDGE_ATTR_MAX];
- struct blob_attr *cur;
struct bridge_state *bst;
struct device *dev = NULL;
const char *name;
- int rem;
blobmsg_parse(device_attr_list.params, __DEV_ATTR_MAX, tb_dev,
blob_data(attr), blob_len(attr));
dev = &bst->dev;
device_init(dev, &bridge_device_type, name);
device_init_settings(dev, tb_dev);
+ dev->config_pending = true;
+ bst->ifnames = tb_br[BRIDGE_ATTR_IFNAME];
bst->set_state = dev->set_state;
dev->set_state = bridge_set_state;
INIT_LIST_HEAD(&bst->members);
- blobmsg_for_each_attr(cur, tb_br[BRIDGE_ATTR_IFNAME], rem) {
- bridge_add_member(bst, blobmsg_data(cur));
- }
-
return dev;
}
device_free_unused(NULL);
config_init = false;
+ device_init_pending();
interface_start_pending();
}
__device_free_unused(dev);
}
+void
+device_init_pending(void)
+{
+ struct device *dev, *tmp;
+
+ avl_for_each_element_safe(&devices, dev, avl, tmp) {
+ if (!dev->config_pending)
+ continue;
+
+ dev->type->config_init(dev);
+ dev->config_pending = false;
+ }
+}
+
enum dev_change_type
device_reload_config(struct device *dev, struct blob_attr *attr)
{
}
dev = type->create(config);
+ if (!dev)
+ return NULL;
+
dev->config = config;
if (odev)
device_replace(dev, odev);
+ if (!config_init && dev->config_pending)
+ type->config_init(dev);
+
return dev;
}
const struct config_param_list *config_params;
struct device *(*create)(struct blob_attr *attr);
+ void (*config_init)(struct device *);
enum dev_change_type (*reload)(struct device *, struct blob_attr *);
void (*dump_status)(struct device *, struct blob_buf *buf);
int (*check_state)(struct device *);
int ifindex;
struct blob_attr *config;
+ bool config_pending;
bool present;
int active;
struct device *device_create(const char *name, const struct device_type *type,
struct blob_attr *config);
void device_init_settings(struct device *dev, struct blob_attr **tb);
+void device_init_pending(void);
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);
struct device *get_vlan_device_chain(const char *ifname, bool create)
{
- struct device *iface = NULL;
+ struct device *dev = NULL;
char *buf, *s, *next, *err = NULL;
int id;
return NULL;
s = split_vlan(buf);
- iface = device_get(buf, create);
- if (!iface && !create)
+ dev = device_get(buf, create);
+ if (!dev && !create)
goto error;
do {
if (err && *err)
goto error;
- iface = get_vlan_device(iface, id, create);
- if (!iface)
+ dev = get_vlan_device(dev, id, create);
+ if (!dev)
goto error;
s = next;
} while (1);
error:
- iface = NULL;
+ dev = NULL;
out:
free(buf);
- return iface;
+ return dev;
}