Commit 2f7ef7dc authored by Hans Dedecker's avatar Hans Dedecker

interface: rework code to get rid of interface_set_dynamic

Integrate dynamic interface creation code into interface_alloc and
__interface_add so we can get rid of interface_set_dynamic
Signed-off-by: default avatarHans Dedecker <dedeckeh@gmail.com>
parent 841b5d15
......@@ -102,7 +102,7 @@ config_parse_interface(struct uci_section *s, bool alias)
uci_to_blob(&b, s, &interface_attr_list);
iface = interface_alloc(s->e.name, b.head);
iface = interface_alloc(s->e.name, b.head, false);
if (!iface)
return;
......
......@@ -768,7 +768,7 @@ void interface_set_proto_state(struct interface *iface, struct interface_proto_s
}
struct interface *
interface_alloc(const char *name, struct blob_attr *config)
interface_alloc(const char *name, struct blob_attr *config, bool dynamic)
{
struct interface *iface;
struct blob_attr *tb[IFACE_ATTR_MAX];
......@@ -803,6 +803,7 @@ interface_alloc(const char *name, struct blob_attr *config)
iface->autostart = blobmsg_get_bool_default(tb[IFACE_ATTR_AUTO], true);
iface->force_link = blobmsg_get_bool_default(tb[IFACE_ATTR_FORCE_LINK], force_link);
iface->dynamic = dynamic;
iface->proto_ip.no_defaultroute =
!blobmsg_get_bool_default(tb[IFACE_ATTR_DEFAULTROUTE], true);
iface->proto_ip.no_dns =
......@@ -877,17 +878,11 @@ interface_alloc(const char *name, struct blob_attr *config)
return iface;
}
void interface_set_dynamic(struct interface *iface)
{
iface->dynamic = true;
iface->autostart = true;
iface->node.version = -1; // Don't delete on reload
}
static bool __interface_add(struct interface *iface, struct blob_attr *config, bool alias)
{
struct blob_attr *tb[IFACE_ATTR_MAX];
struct blob_attr *cur;
char *name = iface->dynamic ? strdup(iface->name) : NULL;
blobmsg_parse(iface_attrs, IFACE_ATTR_MAX, tb,
blob_data(config), blob_len(config));
......@@ -905,13 +900,25 @@ static bool __interface_add(struct interface *iface, struct blob_attr *config, b
iface->config = config;
vlist_add(&interfaces, &iface->node, iface->name);
if (name) {
iface = vlist_find(&interfaces, name, iface, node);
free(name);
if (!iface)
return false;
/* Don't delete dynamic interface on reload */
iface->node.version = -1;
}
return true;
}
void
bool
interface_add(struct interface *iface, struct blob_attr *config)
{
__interface_add(iface, config, false);
return __interface_add(iface, config, false);
}
bool
......@@ -1220,6 +1227,7 @@ interface_change_config(struct interface *if_old, struct interface *if_new)
if_old->config_autostart = if_new->config_autostart;
if_old->ifname = if_new->ifname;
if_old->parent_ifname = if_new->parent_ifname;
if_old->dynamic = if_new->dynamic;
if_old->proto_handler = if_new->proto_handler;
if_old->force_link = if_new->force_link;
if_old->dns_metric = if_new->dns_metric;
......
......@@ -174,11 +174,9 @@ struct interface {
extern struct vlist_tree interfaces;
extern const struct uci_blob_param_list interface_attr_list;
struct interface *interface_alloc(const char *name, struct blob_attr *config);
struct interface *interface_alloc(const char *name, struct blob_attr *config, bool dynamic);
void interface_set_dynamic(struct interface *iface);
void interface_add(struct interface *iface, struct blob_attr *config);
bool interface_add(struct interface *iface, struct blob_attr *config);
bool interface_add_alias(struct interface *iface, struct blob_attr *config);
void interface_set_proto_state(struct interface *iface, struct interface_proto_state *state);
......
......@@ -137,29 +137,22 @@ netifd_add_dynamic(struct ubus_context *ctx, struct ubus_object *obj,
const char *name = blobmsg_get_string(tb[DI_NAME]);
iface = interface_alloc(name, msg);
iface = interface_alloc(name, msg, true);
if (!iface)
return UBUS_STATUS_UNKNOWN_ERROR;
config = blob_memdup(msg);
if (!config)
goto error;
interface_add(iface, config);
// need to look up the interface name again, in case of config update
// the pointer will have changed
iface = vlist_find(&interfaces, name, iface, node);
if (!iface)
return UBUS_STATUS_UNKNOWN_ERROR;
goto error_free;
// Set interface as dynamic
interface_set_dynamic(iface);
if (!interface_add(iface, config))
goto error;
return UBUS_STATUS_OK;
error:
error_free:
free(iface);
error:
return UBUS_STATUS_UNKNOWN_ERROR;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment