From 6843870670b8a68c98528faf638c6b3938cab55d Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Sat, 5 Oct 2013 21:41:52 +0200 Subject: [PATCH] interface: rework code to get rid of arbitrary IFNAMSIZ limitation for interface names Signed-off-by: Felix Fietkau --- config.c | 5 ++--- interface.c | 11 +++++++---- interface.h | 5 ++--- ubus.c | 3 +-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/config.c b/config.c index 682db54..49bae15 100644 --- a/config.c +++ b/config.c @@ -71,12 +71,11 @@ config_parse_interface(struct uci_section *s, bool alias) } 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); diff --git a/interface.c b/interface.c index 18322d7..5649324 100644 --- a/interface.c +++ b/interface.c @@ -536,15 +536,17 @@ void interface_set_proto_state(struct interface *iface, struct interface_proto_s 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); @@ -610,6 +612,7 @@ interface_init(struct interface *iface, const char *name, 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) diff --git a/interface.h b/interface.h index 5b04102..b845c9b 100644 --- a/interface.h +++ b/interface.h @@ -88,7 +88,7 @@ struct interface { struct list_head hotplug_list; enum interface_event hotplug_ev; - char name[IFNAMSIZ]; + const char *name; const char *ifname; bool available; @@ -145,8 +145,7 @@ struct interface { 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); diff --git a/ubus.c b/ubus.c index cfdfcf3..31a83a9 100644 --- a/ubus.c +++ b/ubus.c @@ -135,11 +135,10 @@ netifd_add_dynamic(struct ubus_context *ctx, struct ubus_object *obj, 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; -- 2.30.2