X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fnetifd.git;a=blobdiff_plain;f=interface.c;h=3dceef07797f4e473d67f327c9643fb03ec1713c;hp=ca641aeb1bec9c5602211d25780a739bd55ae209;hb=70d48250e7d25e7df13032eb69e30f0022e4e556;hpb=d76dbcf653fc15719cd9d6bb2ab258b94eada46a;ds=sidebyside diff --git a/interface.c b/interface.c index ca641ae..3dceef0 100644 --- a/interface.c +++ b/interface.c @@ -17,6 +17,7 @@ enum { IFACE_ATTR_IFNAME, IFACE_ATTR_PROTO, IFACE_ATTR_AUTO, + IFACE_ATTR_DEFAULTROUTE, IFACE_ATTR_MAX }; @@ -24,6 +25,7 @@ static const struct blobmsg_policy iface_attrs[IFACE_ATTR_MAX] = { [IFACE_ATTR_PROTO] = { .name = "proto", .type = BLOBMSG_TYPE_STRING }, [IFACE_ATTR_IFNAME] = { .name = "ifname", .type = BLOBMSG_TYPE_STRING }, [IFACE_ATTR_AUTO] = { .name = "auto", .type = BLOBMSG_TYPE_BOOL }, + [IFACE_ATTR_DEFAULTROUTE] = { .name = "defaultroute", .type = BLOBMSG_TYPE_BOOL }, }; const struct config_param_list interface_attr_list = { @@ -100,34 +102,12 @@ interface_flush_state(struct interface *iface) static void mark_interface_down(struct interface *iface) { + if (iface->state == IFS_UP) + interface_event(iface, IFEV_DOWN); interface_flush_state(iface); iface->state = IFS_DOWN; } -static int -__interface_set_up(struct interface *iface) -{ - int ret; - - if (iface->state != IFS_DOWN) - return 0; - - if (iface->main_dev.dev) { - ret = device_claim(&iface->main_dev); - if (ret) - return ret; - } - - iface->state = IFS_SETUP; - ret = interface_proto_event(iface->proto, PROTO_CMD_SETUP, false); - if (ret) { - mark_interface_down(iface); - return ret; - } - - return 0; -} - void __interface_set_down(struct interface *iface, bool force) { @@ -137,8 +117,9 @@ __interface_set_down(struct interface *iface, bool force) iface->state == IFS_TEARDOWN) return; + if (iface->state == IFS_UP) + interface_event(iface, IFEV_DOWN); iface->state = IFS_TEARDOWN; - interface_event(iface, IFEV_DOWN); interface_proto_event(iface->proto, PROTO_CMD_TEARDOWN, force); if (force) interface_flush_state(iface); @@ -202,12 +183,14 @@ interface_claim_device(struct interface *iface) { struct device *dev; - if (iface->ifname && iface->proto_handler && + if (iface->ifname && !(iface->proto_handler->flags & PROTO_FLAG_NODEV)) { dev = device_get(iface->ifname, true); if (dev) device_add_user(&iface->main_dev, dev); } + if (iface->proto_handler->flags & PROTO_FLAG_INIT_AVAILABLE) + interface_set_available(iface, true); } @@ -242,9 +225,8 @@ static void interface_do_reload(struct interface *iface) { interface_cleanup(iface); - - interface_claim_device(iface); proto_init_interface(iface, iface->config); + interface_claim_device(iface); } static void @@ -297,8 +279,9 @@ interface_proto_cb(struct interface_proto_state *state, enum interface_proto_eve return; netifd_log_message(L_NOTICE, "Interface '%s' has lost the connection\n", iface->name); + if (iface->state == IFS_UP) + interface_event(iface, IFEV_DOWN); iface->state = IFS_SETUP; - interface_event(iface, IFEV_DOWN); break; } } @@ -345,10 +328,10 @@ interface_init(struct interface *iface, const char *name, proto_attach_interface(iface, proto_name); - if ((cur = tb[IFACE_ATTR_AUTO])) - iface->autostart = blobmsg_get_bool(cur); - else - iface->autostart = true; + iface->autostart = blobmsg_get_bool_default(tb[IFACE_ATTR_AUTO], true); + iface->proto_ip.no_defaultroute = + !blobmsg_get_bool_default(tb[IFACE_ATTR_DEFAULTROUTE], true); + iface->config_autostart = iface->autostart; } @@ -400,6 +383,8 @@ interface_add_link(struct interface *iface, struct device *dev) int interface_set_up(struct interface *iface) { + int ret; + iface->autostart = true; if (iface->state != IFS_DOWN) @@ -411,7 +396,20 @@ interface_set_up(struct interface *iface) return -1; } - return __interface_set_up(iface); + if (iface->main_dev.dev) { + ret = device_claim(&iface->main_dev); + if (ret) + return ret; + } + + iface->state = IFS_SETUP; + ret = interface_proto_event(iface->proto, PROTO_CMD_SETUP, false); + if (ret) { + mark_interface_down(iface); + return ret; + } + + return 0; } int @@ -485,8 +483,9 @@ interface_change_config(struct interface *if_old, struct interface *if_new) if_old->ifname = if_new->ifname; if_old->proto_handler = if_new->proto_handler; - if (strcmp(old_ifname, if_new->ifname) != 0 || - proto != if_new->proto_handler) { + if ((!!old_ifname != !!if_new->ifname) || + (old_ifname && strcmp(old_ifname, if_new->ifname) != 0) || + proto != if_new->proto_handler) { D(INTERFACE, "Reload interface '%s' because of ifname/proto change\n", if_old->name); goto reload; @@ -502,6 +501,11 @@ interface_change_config(struct interface *if_old, struct interface *if_new) goto reload; } + if (if_old->proto_ip.no_defaultroute != if_new->proto_ip.no_defaultroute) { + if_old->proto_ip.no_defaultroute = if_new->proto_ip.no_defaultroute; + interface_ip_set_enabled(&if_old->proto_ip, if_old->proto_ip.enabled); + } + goto out; reload: @@ -526,8 +530,8 @@ interface_update(struct vlist_tree *tree, struct vlist_node *node_new, set_config_state(if_old, IFC_REMOVE); } else if (node_new) { D(INTERFACE, "Create interface '%s'\n", if_new->name); - interface_claim_device(if_new); proto_init_interface(if_new, if_new->config); + interface_claim_device(if_new); netifd_ubus_add_interface(if_new); } }