}
uci_to_blob(&b, s, &interface_attr_list);
- iface = calloc(1, sizeof(*iface));
+
+ iface = interface_alloc(s->e.name, b.head);
if (!iface)
return;
- interface_init(iface, s->e.name, b.head);
-
if (iface->proto_handler && iface->proto_handler->config_params)
uci_to_blob(&b, s, iface->proto_handler->config_params);
state->iface = iface;
}
-void
-interface_init(struct interface *iface, const char *name,
- struct blob_attr *config)
+struct interface *
+interface_alloc(const char *name, struct blob_attr *config)
{
+ struct interface *iface;
struct blob_attr *tb[IFACE_ATTR_MAX];
struct blob_attr *cur;
const char *proto_name = NULL;
+ char *iface_name;
- strncpy(iface->name, name, sizeof(iface->name) - 1);
+ iface = calloc_a(sizeof(*iface), &iface_name, strlen(name) + 1);
+ iface->name = strcpy(iface_name, name);
INIT_LIST_HEAD(&iface->errors);
INIT_LIST_HEAD(&iface->users);
INIT_LIST_HEAD(&iface->hotplug_list);
iface->proto_ip.no_delegation = !blobmsg_get_bool_default(tb[IFACE_ATTR_DELEGATE], true);
iface->config_autostart = iface->autostart;
+ return iface;
}
void interface_set_dynamic(struct interface *iface)
struct list_head hotplug_list;
enum interface_event hotplug_ev;
- char name[IFNAMSIZ];
+ const char *name;
const char *ifname;
bool available;
extern struct vlist_tree interfaces;
extern const struct uci_blob_param_list interface_attr_list;
-void interface_init(struct interface *iface, const char *name,
- struct blob_attr *config);
+struct interface *interface_alloc(const char *name, struct blob_attr *config);
void interface_set_dynamic(struct interface *iface);
const char *name = blobmsg_get_string(tb[DI_NAME]);
- iface = calloc(1, sizeof(*iface));
+ iface = interface_alloc(name, msg);
if (!iface)
return UBUS_STATUS_UNKNOWN_ERROR;
- interface_init(iface, name, msg);
interface_set_dynamic(iface);
iface->device_config = true;