X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fnetifd.git;a=blobdiff_plain;f=interface.c;h=5649324d44bc50a57c4acfffdc2ed69f9ad7ca1a;hp=76f8c7038ac6b1c8c3bb86ac13705f002d9d22b8;hb=98ffa1331519ed3dd84bd351652ae0fde3df8c93;hpb=da279866a33682e590428b740b4564a4b2e6f780 diff --git a/interface.c b/interface.c index 76f8c70..5649324 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,14 +62,15 @@ 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 union config_param_info iface_attr_info[IFACE_ATTR_MAX] = { +static const struct uci_blob_param_info iface_attr_info[IFACE_ATTR_MAX] = { [IFACE_ATTR_DNS] = { .type = BLOBMSG_TYPE_STRING }, [IFACE_ATTR_IP6CLASS] = { .type = BLOBMSG_TYPE_STRING }, }; -const struct config_param_list interface_attr_list = { +const struct uci_blob_param_list interface_attr_list = { .n_params = IFACE_ATTR_MAX, .params = iface_attrs, .info = iface_attr_info, @@ -151,7 +153,7 @@ interface_add_data(struct interface *iface, const struct blob_attr *data) n = calloc(1, sizeof(*n) + blob_pad_len(data)); memcpy(n->data, data, blob_pad_len(data)); - n->node.key = blobmsg_name(data); + n->node.key = blobmsg_name(n->data); o = avl_find_element(&iface->data, n->node.key, o, node); if (o) @@ -220,6 +222,9 @@ __interface_set_down(struct interface *iface, bool force) interface_proto_event(iface->proto, PROTO_CMD_TEARDOWN, force); if (force) interface_flush_state(iface); + + if (iface->dynamic) + vlist_delete(&interfaces, &iface->node); } static void @@ -375,6 +380,7 @@ interface_alias_cb(struct interface_user *dep, struct interface *iface, enum int interface_remove_user(dep); break; case IFEV_RELOAD: + case IFEV_UPDATE: break; } } @@ -480,8 +486,10 @@ interface_proto_cb(struct interface_proto_state *state, enum interface_proto_eve switch (ev) { case IFPEV_UP: - if (iface->state != IFS_SETUP) + if (iface->state != IFS_SETUP) { + interface_event(iface, IFEV_UPDATE); return; + } interface_ip_set_enabled(&iface->config_ip, true); system_flush_routes(); @@ -528,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); @@ -588,14 +598,27 @@ interface_init(struct interface *iface, const char *name, } // Set a default exteranl routing table for IPv6 to do source-based-filtering + struct interface *iface_old = vlist_find(&interfaces, name, iface_old, node); + if (iface_old && iface_old->ip6table > 1000 && iface_old->ip6table < 2000) + iface->ip6table = iface_old->ip6table; + else + iface->ip6table = 1000 + ++interface_serial; - iface->ip6table = 1000 + ++interface_serial; if ((cur = tb[IFACE_ATTR_IP6TABLE])) { if (!system_resolve_rt_table(blobmsg_data(cur), &iface->ip6table)) 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; + return iface; +} + +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) @@ -671,6 +694,9 @@ interface_set_main_dev(struct interface *iface, struct device *dev) interface_set_l3_dev(iface, dev); device_add_user(&iface->main_dev, dev); + if (!dev) + return; + if (claimed) device_claim(&iface->l3_dev); @@ -829,8 +855,8 @@ interface_change_config(struct interface *if_old, struct interface *if_new) if (!if_old->proto_handler->config_params) D(INTERFACE, "No config parameters for interface '%s'\n", if_old->name); - else if (!config_check_equal(if_old->config, if_new->config, - if_old->proto_handler->config_params)) + else if (!uci_blob_check_equal(if_old->config, if_new->config, + if_old->proto_handler->config_params)) reload = true; #define UPDATE(field, __var) ({ \ @@ -854,6 +880,8 @@ interface_change_config(struct interface *if_old, struct interface *if_new) UPDATE(metric, reload_ip); UPDATE(proto_ip.no_defaultroute, reload_ip); + UPDATE(ip4table, reload_ip); + UPDATE(ip6table, reload_ip); interface_merge_assignment_data(if_old, if_new); #undef UPDATE @@ -868,9 +896,9 @@ interface_change_config(struct interface *if_old, struct interface *if_new) if (reload_ip) { interface_ip_set_enabled(&if_old->config_ip, false); - interface_ip_set_enabled(&if_old->config_ip, if_new->config_ip.enabled); interface_ip_set_enabled(&if_old->proto_ip, false); interface_ip_set_enabled(&if_old->proto_ip, if_new->proto_ip.enabled); + interface_ip_set_enabled(&if_old->config_ip, if_new->config_ip.enabled); } interface_write_resolv_conf();