X-Git-Url: http://git.archive.openwrt.org/?a=blobdiff_plain;f=interface.c;h=23c70326131dc6a5e0d2e45700178d04d95fb6e9;hb=2eaffc0ed137595784d19edf17e517c320cbf264;hp=06206170e990cff8cada328d359d9873a73445ff;hpb=ddbd2cc51b3db14f6a8bd46ceebaee9097a50b78;p=project%2Fnetifd.git diff --git a/interface.c b/interface.c index 0620617..23c7032 100644 --- a/interface.c +++ b/interface.c @@ -43,6 +43,7 @@ enum { IFACE_ATTR_IP4TABLE, IFACE_ATTR_IP6TABLE, IFACE_ATTR_IP6CLASS, + IFACE_ATTR_DELEGATE, IFACE_ATTR_MAX }; @@ -61,6 +62,7 @@ static const struct blobmsg_policy iface_attrs[IFACE_ATTR_MAX] = { [IFACE_ATTR_IP4TABLE] = { .name = "ip4table", .type = BLOBMSG_TYPE_STRING }, [IFACE_ATTR_IP6TABLE] = { .name = "ip6table", .type = BLOBMSG_TYPE_STRING }, [IFACE_ATTR_IP6CLASS] = { .name = "ip6class", .type = BLOBMSG_TYPE_ARRAY }, + [IFACE_ATTR_DELEGATE] = { .name = "delegate", .type = BLOBMSG_TYPE_BOOL }, }; static const struct uci_blob_param_info iface_attr_info[IFACE_ATTR_MAX] = { @@ -534,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, bool dynamic) +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); @@ -605,11 +609,16 @@ interface_init(struct interface *iface, const char *name, DPRINTF("Failed to resolve routing table: %s\n", (char *) blobmsg_data(cur)); } + iface->proto_ip.no_delegation = !blobmsg_get_bool_default(tb[IFACE_ATTR_DELEGATE], true); + iface->config_autostart = iface->autostart; - iface->dynamic = dynamic; + return iface; +} - if (iface->dynamic) - iface->node.version = -1; // Don't delete on reload +void interface_set_dynamic(struct interface *iface) +{ + iface->dynamic = true; + iface->node.version = -1; // Don't delete on reload } static bool __interface_add(struct interface *iface, struct blob_attr *config, bool alias) @@ -737,6 +746,37 @@ interface_add_link(struct interface *iface, struct device *dev) } int +interface_handle_link(struct interface *iface, const char *name, bool add) +{ + struct device *dev; + int ret; + + device_lock(); + + dev = device_get(name, add ? 2 : 0); + if (!dev) { + ret = UBUS_STATUS_NOT_FOUND; + goto out; + } + + if (add) { + device_set_present(dev, true); + if (iface->device_config) + device_set_config(dev, &simple_device_type, iface->config); + + system_if_apply_settings(dev, &dev->settings); + ret = interface_add_link(iface, dev); + } else { + ret = interface_remove_link(iface, dev); + } + +out: + device_unlock(); + + return ret; +} + +int interface_set_up(struct interface *iface) { int ret;