proto: move the dns search option handling to the core
[project/netifd.git] / interface.c
index 257eaca..3dceef0 100644 (file)
@@ -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 = {
@@ -181,7 +183,7 @@ 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)
@@ -326,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;
 }
 
@@ -499,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: