nterface-ip: remove superfluous iface check in interface_ip_set_enabled()
[project/netifd.git] / iprule.c
index 7172f29..7cf7422 100644 (file)
--- a/iprule.c
+++ b/iprule.c
@@ -15,7 +15,6 @@
 #include <string.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
 #include <stdio.h>
-#include <unistd.h>
 
 #include <arpa/inet.h>
 
 
 #include <arpa/inet.h>
 
@@ -29,6 +28,7 @@
 
 struct vlist_tree iprules;
 static bool iprules_flushed = false;
 
 struct vlist_tree iprules;
 static bool iprules_flushed = false;
+static unsigned int iprules_counter[2];
 
 enum {
        RULE_INTERFACE_IN,
 
 enum {
        RULE_INTERFACE_IN,
@@ -42,6 +42,7 @@ enum {
        RULE_LOOKUP,
        RULE_ACTION,
        RULE_GOTO,
        RULE_LOOKUP,
        RULE_ACTION,
        RULE_GOTO,
+       RULE_SUP_PREFIXLEN,
        __RULE_MAX
 };
 
        __RULE_MAX
 };
 
@@ -55,11 +56,12 @@ static const struct blobmsg_policy rule_attr[__RULE_MAX] = {
        [RULE_TOS] = { .name = "tos", .type = BLOBMSG_TYPE_INT32 },
        [RULE_FWMARK] = { .name = "mark", .type = BLOBMSG_TYPE_STRING },
        [RULE_LOOKUP] = { .name = "lookup", .type = BLOBMSG_TYPE_STRING },
        [RULE_TOS] = { .name = "tos", .type = BLOBMSG_TYPE_INT32 },
        [RULE_FWMARK] = { .name = "mark", .type = BLOBMSG_TYPE_STRING },
        [RULE_LOOKUP] = { .name = "lookup", .type = BLOBMSG_TYPE_STRING },
+       [RULE_SUP_PREFIXLEN] = { .name = "suppress_prefixlength", .type = BLOBMSG_TYPE_INT32 },
        [RULE_ACTION] = { .name = "action", .type = BLOBMSG_TYPE_STRING },
        [RULE_GOTO]   = { .name = "goto", .type = BLOBMSG_TYPE_INT32 },
 };
 
        [RULE_ACTION] = { .name = "action", .type = BLOBMSG_TYPE_STRING },
        [RULE_GOTO]   = { .name = "goto", .type = BLOBMSG_TYPE_INT32 },
 };
 
-const struct config_param_list rule_attr_list = {
+const struct uci_blob_param_list rule_attr_list = {
        .n_params = __RULE_MAX,
        .params = rule_attr,
 };
        .n_params = __RULE_MAX,
        .params = rule_attr,
 };
@@ -111,6 +113,7 @@ iprule_add(struct blob_attr *attr, bool v6)
                return;
 
        rule->flags = v6 ? IPRULE_INET6 : IPRULE_INET4;
                return;
 
        rule->flags = v6 ? IPRULE_INET6 : IPRULE_INET4;
+       rule->order = iprules_counter[rule->flags]++;
 
        if ((cur = tb[RULE_INVERT]) != NULL)
                rule->invert = blobmsg_get_bool(cur);
 
        if ((cur = tb[RULE_INVERT]) != NULL)
                rule->invert = blobmsg_get_bool(cur);
@@ -184,6 +187,11 @@ iprule_add(struct blob_attr *attr, bool v6)
                rule->flags |= IPRULE_LOOKUP;
        }
 
                rule->flags |= IPRULE_LOOKUP;
        }
 
+       if ((cur = tb[RULE_SUP_PREFIXLEN]) != NULL) {
+               rule->sup_prefixlen = blobmsg_get_u32(cur);
+               rule->flags |= IPRULE_SUP_PREFIXLEN;
+       }
+
        if ((cur = tb[RULE_ACTION]) != NULL) {
                if (!system_resolve_iprule_action(blobmsg_data(cur), &rule->action)) {
                        DPRINTF("Failed to parse rule action: %s\n", (char *) blobmsg_data(cur));
        if ((cur = tb[RULE_ACTION]) != NULL) {
                if (!system_resolve_iprule_action(blobmsg_data(cur), &rule->action)) {
                        DPRINTF("Failed to parse rule action: %s\n", (char *) blobmsg_data(cur));
@@ -197,13 +205,6 @@ iprule_add(struct blob_attr *attr, bool v6)
                rule->flags |= IPRULE_GOTO;
        }
 
                rule->flags |= IPRULE_GOTO;
        }
 
-       /* trigger flush of existing rules when adding first uci rule the first time */
-       if (!iprules_flushed)
-       {
-               system_flush_iprules();
-               iprules_flushed = true;
-       }
-
        vlist_add(&iprules, &rule->node, &rule->flags);
        return;
 
        vlist_add(&iprules, &rule->node, &rule->flags);
        return;
 
@@ -214,6 +215,13 @@ error:
 void
 iprule_update_start(void)
 {
 void
 iprule_update_start(void)
 {
+       if (!iprules_flushed) {
+               system_flush_iprules();
+               iprules_flushed = true;
+       }
+
+       iprules_counter[0] = 1;
+       iprules_counter[1] = 1;
        vlist_update(&iprules);
 }
 
        vlist_update(&iprules);
 }
 
@@ -232,7 +240,7 @@ rule_cmp(const void *k1, const void *k2, void *ptr)
 
 static void
 iprule_update_rule(struct vlist_tree *tree,
 
 static void
 iprule_update_rule(struct vlist_tree *tree,
-                   struct vlist_node *node_new, struct vlist_node *node_old)
+                       struct vlist_node *node_new, struct vlist_node *node_old)
 {
        struct iprule *rule_old, *rule_new;
 
 {
        struct iprule *rule_old, *rule_new;