interface: fix regression on adding hotplug devices to interfaces
[project/netifd.git] / iprule.c
index b9e16a5f082c4451f6bac85273c9e83cb423a4ee..e851e2d1bdbaff58552ba7cec89c4c386bd94fd6 100644 (file)
--- a/iprule.c
+++ b/iprule.c
@@ -44,6 +44,7 @@ enum {
        RULE_ACTION,
        RULE_GOTO,
        RULE_SUP_PREFIXLEN,
+       RULE_UIDRANGE,
        RULE_DISABLED,
        __RULE_MAX
 };
@@ -59,6 +60,7 @@ static const struct blobmsg_policy rule_attr[__RULE_MAX] = {
        [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_UIDRANGE] = { .name = "uidrange", .type = BLOBMSG_TYPE_STRING },
        [RULE_ACTION] = { .name = "action", .type = BLOBMSG_TYPE_STRING },
        [RULE_GOTO]   = { .name = "goto", .type = BLOBMSG_TYPE_INT32 },
        [RULE_DISABLED] = { .name = "disabled", .type = BLOBMSG_TYPE_BOOL },
@@ -234,7 +236,7 @@ iprule_add(struct blob_attr *attr, bool v6)
 
        if ((cur = tb[RULE_SRC]) != NULL) {
                if (!parse_ip_and_netmask(af, blobmsg_data(cur), &rule->src_addr, &rule->src_mask)) {
-                       DPRINTF("Failed to parse rule source: %s\n", (char *) blobmsg_data(cur));
+                       D(INTERFACE, "Failed to parse rule source: %s", (char *) blobmsg_data(cur));
                        goto error;
                }
                rule->flags |= IPRULE_SRC;
@@ -242,7 +244,7 @@ iprule_add(struct blob_attr *attr, bool v6)
 
        if ((cur = tb[RULE_DEST]) != NULL) {
                if (!parse_ip_and_netmask(af, blobmsg_data(cur), &rule->dest_addr, &rule->dest_mask)) {
-                       DPRINTF("Failed to parse rule destination: %s\n", (char *) blobmsg_data(cur));
+                       D(INTERFACE, "Failed to parse rule destination: %s", (char *) blobmsg_data(cur));
                        goto error;
                }
                rule->flags |= IPRULE_DEST;
@@ -255,7 +257,7 @@ iprule_add(struct blob_attr *attr, bool v6)
 
        if ((cur = tb[RULE_TOS]) != NULL) {
                if ((rule->tos = blobmsg_get_u32(cur)) > 255) {
-                       DPRINTF("Invalid TOS value: %u\n", blobmsg_get_u32(cur));
+                       D(INTERFACE, "Invalid TOS value: %u", blobmsg_get_u32(cur));
                        goto error;
                }
                rule->flags |= IPRULE_TOS;
@@ -263,7 +265,7 @@ iprule_add(struct blob_attr *attr, bool v6)
 
        if ((cur = tb[RULE_FWMARK]) != NULL) {
                if (!iprule_parse_mark(blobmsg_data(cur), rule)) {
-                       DPRINTF("Failed to parse rule fwmark: %s\n", (char *) blobmsg_data(cur));
+                       D(INTERFACE, "Failed to parse rule fwmark: %s", (char *) blobmsg_data(cur));
                        goto error;
                }
                /* flags set by iprule_parse_mark() */
@@ -271,7 +273,7 @@ iprule_add(struct blob_attr *attr, bool v6)
 
        if ((cur = tb[RULE_LOOKUP]) != NULL) {
                if (!system_resolve_rt_table(blobmsg_data(cur), &rule->lookup)) {
-                       DPRINTF("Failed to parse rule lookup table: %s\n", (char *) blobmsg_data(cur));
+                       D(INTERFACE, "Failed to parse rule lookup table: %s", (char *) blobmsg_data(cur));
                        goto error;
                }
                rule->flags |= IPRULE_LOOKUP;
@@ -282,9 +284,21 @@ iprule_add(struct blob_attr *attr, bool v6)
                rule->flags |= IPRULE_SUP_PREFIXLEN;
        }
 
+       if ((cur = tb[RULE_UIDRANGE]) != NULL) {
+               int ret = sscanf(blobmsg_get_string(cur), "%u-%u", &rule->uidrange_start, &rule->uidrange_end);
+
+               if (ret == 1)
+                       rule->uidrange_end = rule->uidrange_start;
+               else if (ret != 2) {
+                       D(INTERFACE, "Failed to parse UID range: %s", (char *) blobmsg_data(cur));
+                       goto error;
+               }
+               rule->flags |= IPRULE_UIDRANGE;
+       }
+
        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));
+                       D(INTERFACE, "Failed to parse rule action: %s", (char *) blobmsg_data(cur));
                        goto error;
                }
                rule->flags |= IPRULE_ACTION;