diff mbox series

[iproute2-next] ip: ipneigh: json: print ndm_flags as boolean attributes

Message ID 20191226144415.50682-1-julien@cumulusnetworks.com
State Rejected
Delegated to: stephen hemminger
Headers show
Series [iproute2-next] ip: ipneigh: json: print ndm_flags as boolean attributes | expand

Commit Message

Julien Fortin Dec. 26, 2019, 2:44 p.m. UTC
From: Julien Fortin <julien@cumulusnetworks.com>

Today the following attributes are printed as json "null" attributes
NTF_ROUTER
NTF_PROXY
NTF_EXT_LEARNED
NTF_OFFLOADED

$ ip -j neigh show
[
  {
    "dst": "10.0.2.2",
    "dev": "enp0s3",
    "lladdr": "52:54:00:12:35:02",
    "router": null,
    "proxy": null,
    "extern_learn": null,
    "offload": null,
    "state": [
      "REACHABLE"
    ]
  }
]

The goal of this patch is to replace those null attributes with booleans

$ ip -j neigh show
[
  {
    "dst": "10.0.2.2",
    "dev": "enp0s3",
    "lladdr": "52:54:00:12:35:02",
    "router": true,
    "proxy": true,
    "extern_learn": true,
    "offload": true,
    "state": [
      "REACHABLE"
    ]
  }
]

Signed-off-by: Julien Fortin <julien@cumulusnetworks.com>
---
 ip/ipneigh.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Stephen Hemminger Dec. 26, 2019, 5:04 p.m. UTC | #1
On Thu, 26 Dec 2019 15:44:15 +0100
Julien Fortin <julien@cumulusnetworks.com> wrote:

> From: Julien Fortin <julien@cumulusnetworks.com>
> 
> Today the following attributes are printed as json "null" attributes
> NTF_ROUTER
> NTF_PROXY
> NTF_EXT_LEARNED
> NTF_OFFLOADED
> 
> $ ip -j neigh show
> [
>   {
>     "dst": "10.0.2.2",
>     "dev": "enp0s3",
>     "lladdr": "52:54:00:12:35:02",
>     "router": null,
>     "proxy": null,
>     "extern_learn": null,
>     "offload": null,
>     "state": [
>       "REACHABLE"
>     ]
>   }
> ]


No, this was intentional. Null is a standard method in JSON
to encode an option being present.
David Ahern Dec. 30, 2019, 5:38 p.m. UTC | #2
On 12/26/19 10:04 AM, Stephen Hemminger wrote:
> On Thu, 26 Dec 2019 15:44:15 +0100
> Julien Fortin <julien@cumulusnetworks.com> wrote:
> 
>> From: Julien Fortin <julien@cumulusnetworks.com>
>>
>> Today the following attributes are printed as json "null" attributes
>> NTF_ROUTER
>> NTF_PROXY
>> NTF_EXT_LEARNED
>> NTF_OFFLOADED
>>
>> $ ip -j neigh show
>> [
>>   {
>>     "dst": "10.0.2.2",
>>     "dev": "enp0s3",
>>     "lladdr": "52:54:00:12:35:02",
>>     "router": null,
>>     "proxy": null,
>>     "extern_learn": null,
>>     "offload": null,
>>     "state": [
>>       "REACHABLE"
>>     ]
>>   }
>> ]
> 
> 
> No, this was intentional. Null is a standard method in JSON
> to encode an option being present.
> 

seems weird for flags. ip mostly uses print_bool for flags; there are
only a few print_null.
diff mbox series

Patch

diff --git a/ip/ipneigh.c b/ip/ipneigh.c
index 678b4034..b1f212f4 100644
--- a/ip/ipneigh.c
+++ b/ip/ipneigh.c
@@ -380,16 +380,16 @@  int print_neigh(struct nlmsghdr *n, void *arg)
 	}
 
 	if (r->ndm_flags & NTF_ROUTER)
-		print_null(PRINT_ANY, "router", " %s", "router");
+		print_bool(PRINT_ANY, "router", " router", true);
 
 	if (r->ndm_flags & NTF_PROXY)
-		print_null(PRINT_ANY, "proxy", " %s", "proxy");
+		print_bool(PRINT_ANY, "proxy", " proxy", true);
 
 	if (r->ndm_flags & NTF_EXT_LEARNED)
-		print_null(PRINT_ANY, "extern_learn", " %s ", "extern_learn");
+		print_bool(PRINT_ANY, "extern_learn", " extern_learn ", true);
 
 	if (r->ndm_flags & NTF_OFFLOADED)
-		print_null(PRINT_ANY, "offload", " %s", "offload");
+		print_bool(PRINT_ANY, "offload", " offload", true);
 
 	if (show_stats) {
 		if (tb[NDA_CACHEINFO])