netifd: allow disabling rule/rule6 config sections
authorVladislav Grigoryev <vg.aetera@gmail.com>
Thu, 2 Dec 2021 11:26:49 +0000 (14:26 +0300)
committerHans Dedecker <dedeckeh@gmail.com>
Sun, 12 Dec 2021 20:16:18 +0000 (21:16 +0100)
Allow disabling IP rules similar to routes:
https://git.openwrt.org/?p=project/netifd.git;a=commitdiff;h=327da9895327bc56b23413ee91a6e6b6e0e4329d

Signed-off-by: Vladislav Grigoryev <vg.aetera@gmail.com>
iprule.c

index c3a629f6103624e6cb8578959ecd3ed4c814bf7a..b9e16a5f082c4451f6bac85273c9e83cb423a4ee 100644 (file)
--- a/iprule.c
+++ b/iprule.c
@@ -44,6 +44,7 @@ enum {
        RULE_ACTION,
        RULE_GOTO,
        RULE_SUP_PREFIXLEN,
+       RULE_DISABLED,
        __RULE_MAX
 };
 
@@ -60,6 +61,7 @@ static const struct blobmsg_policy rule_attr[__RULE_MAX] = {
        [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_DISABLED] = { .name = "disabled", .type = BLOBMSG_TYPE_BOOL },
 };
 
 const struct uci_blob_param_list rule_attr_list = {
@@ -203,6 +205,9 @@ iprule_add(struct blob_attr *attr, bool v6)
 
        blobmsg_parse(rule_attr, __RULE_MAX, tb, blobmsg_data(attr), blobmsg_data_len(attr));
 
+       if ((cur = tb[RULE_DISABLED]) != NULL && blobmsg_get_bool(cur))
+               return;
+
        rule = calloc(1, sizeof(*rule));
        if (!rule)
                return;