Skip to contentSkip to conversation

ip-rule/trivial: add comment about json key "to_tbl" for unspecific rule action

PATCH Superseded Thomas Haller 2 participants 4 messages Feb 19, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ip-rule/trivial: add comment about json key "to_tbl" for unspecific rule action

The key should not be called "to_tbl" because it is exactly not a FR_ACT_TO_TBL action.

    # ip rule add blackhole
    # ip -j rule | python -m json.tool
    ...
    {
        "priority": 0,
        "src": "all",
        "to_tbl": "blackhole"
    },

Still, as this is already released API from v4.17.0, stick to it. Only add a comment for this oddity.

Related: 0dd4ccc56c0e ("iprule: add json support")

---
If it is still permissible to change the API, I can also send a patch to rename "to_tbl" key to "action".

 ip/iprule.c | 2 ++
 1 file changed, 2 insertions(+)
ip/iprule.c +2 -0
index 2f58d8c2..aea175aa 100644
@@ -459,6 +459,8 @@ int print_rule(struct nlmsghdr *n, void *arg)
 	} else if (frh->action == FR_ACT_NOP) {
 		print_null(PRINT_ANY, "nop", "nop", NULL);
 	} else if (frh->action != FR_ACT_TO_TBL) {
+		/* The action is not(!) to-tbl, however for historic
+		 * reasons, this JSON key is called "to_tbl". */
 		print_string(PRINT_ANY, "to_tbl", "%s",
 			     rtnl_rtntype_n2a(frh->action, b1, sizeof(b1)));
 	}
Signature · 1 line
2.20.1
#1 lore raw
Quoted 30 lines · On Tue, 19 Feb 2019 15:03:31 +0100 Thomas Haller <[email protected]> wrote:

The key should not be called "to_tbl" because it is exactly not a FR_ACT_TO_TBL action.

    # ip rule add blackhole
    # ip -j rule | python -m json.tool
    ...
    {
        "priority": 0,
        "src": "all",
        "to_tbl": "blackhole"
    },

Still, as this is already released API from v4.17.0, stick to it. Only add a comment for this oddity.

Related: 0dd4ccc56c0e ("iprule: add json support")

---
If it is still permissible to change the API, I can also send a patch to rename "to_tbl" key to "action".

 ip/iprule.c | 2 ++
 1 file changed, 2 insertions(+)
ip/iprule.c +0 -0
index 2f58d8c2..aea175aa 100644

ip/iprule.c int print_rule(struct nlmsghdr *n, void *arg) · line 466

Quoted 8 lines
ip/iprule.c +2 -0
@@ -459,6 +459,8 @@ int print_rule(struct nlmsghdr *n, void *arg)
 	} else if (frh->action == FR_ACT_NOP) {
 		print_null(PRINT_ANY, "nop", "nop", NULL);
 	} else if (frh->action != FR_ACT_TO_TBL) {
+		/* The action is not(!) to-tbl, however for historic
+		 * reasons, this JSON key is called "to_tbl". */
 		print_string(PRINT_ANY, "to_tbl", "%s",
 			     rtnl_rtntype_n2a(frh->action, b1, sizeof(b1)));
 	}

Just fix it and add fixes tag. JSON has been only added for a short time.

#2 lore raw

PATCH v2 1/1 ip-rule: fix json key "to_tbl" for unspecific rule action

The key should not be called "to_tbl" because it is exactly not a FR_ACT_TO_TBL action. Change it to "action".

    # ip rule add blackhole
    # ip -j rule | python -m json.tool
    ...
    {
        "priority": 0,
        "src": "all",
        "to_tbl": "blackhole"
    },

This is an API break of JSON output as it was added in v4.17.0. Still change it as the API is relatively new and unstable.

Fixes 0dd4ccc56c0e ("iprule: add json support")
---
 ip/iprule.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
ip/iprule.c +1 -1
index 2f58d8c2..4e9437de 100644
@@ -459,7 +459,7 @@ int print_rule(struct nlmsghdr *n, void *arg)
 	} else if (frh->action == FR_ACT_NOP) {
 		print_null(PRINT_ANY, "nop", "nop", NULL);
 	} else if (frh->action != FR_ACT_TO_TBL) {
-		print_string(PRINT_ANY, "to_tbl", "%s",
+		print_string(PRINT_ANY, "action", "%s",
 			     rtnl_rtntype_n2a(frh->action, b1, sizeof(b1)));
 	}
 
Signature · 1 line
2.20.1
#3 lore raw

Re: [PATCH iproute2, v2] ip-rule: fix json key "to_tbl" for unspecific rule action

Quoted 12 lines · On Tue, 19 Feb 2019 21:50:19 +0100 Thomas Haller <[email protected]> wrote:

The key should not be called "to_tbl" because it is exactly not a FR_ACT_TO_TBL action. Change it to "action".

    # ip rule add blackhole
    # ip -j rule | python -m json.tool
    ...
    {
        "priority": 0,
        "src": "all",
        "to_tbl": "blackhole"
    },
Quoted 6 lines

This is an API break of JSON output as it was added in v4.17.0. Still change it as the API is relatively new and unstable.

Fixes 0dd4ccc56c0e ("iprule: add json support")

Applied, thanks.