Add option "delegate" to toggle prefix delegation
authorSteven Barth <steven@midlink.org>
Fri, 18 Oct 2013 12:18:32 +0000 (14:18 +0200)
committerSteven Barth <steven@midlink.org>
Fri, 18 Oct 2013 12:18:32 +0000 (14:18 +0200)
interface-ip.c
interface.c
interface.h

index 60902f994e41cdb4191f6c5640a4c5527072fdc7..2280266552b3d527e2d80993c0fd33b600e99944 100644 (file)
@@ -920,7 +920,9 @@ interface_update_prefix(struct vlist_tree *tree,
        } else if (node_new) {
                // Set null-route to avoid routing loops
                system_add_route(NULL, &route);
-               interface_update_prefix_assignments(prefix_new, true);
+
+               if (!prefix_new->iface || !prefix_new->iface->proto_ip.no_delegation)
+                       interface_update_prefix_assignments(prefix_new, true);
        } else if (node_old) {
                // Remove null-route
                interface_update_prefix_assignments(prefix_old, false);
@@ -928,11 +930,12 @@ interface_update_prefix(struct vlist_tree *tree,
        }
 
        if (node_old) {
-               list_del(&prefix_old->head);
+               if (prefix_old->head.next)
+                       list_del(&prefix_old->head);
                free(prefix_old);
        }
 
-       if (node_new)
+       if (node_new && (!prefix_new->iface || !prefix_new->iface->proto_ip.no_delegation))
                list_add(&prefix_new->head, &prefixes);
 
 }
index 06206170e990cff8cada328d359d9873a73445ff..698fedb645761116641a017fc3db50fc4a50429f 100644 (file)
@@ -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] = {
@@ -605,6 +607,8 @@ 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;
 
index 8c69958fa8edc78df18cb1a66476122843f385bf..ca5d3761ffa61356867a29b48c4e136519af4bbb 100644 (file)
@@ -60,6 +60,7 @@ struct interface_ip_settings {
        bool enabled;
        bool no_defaultroute;
        bool no_dns;
+       bool no_delegation;
 
        struct vlist_tree addr;
        struct vlist_tree route;