bridge: fdb show: fix fdb entry state output (+ add json support)
Subsystems (2)
PATCH v2 1/1 bridge: fdb show: fix fdb entry state output (+ add json support)
From: Julien Fortin <[email protected]>
bridge json fdb show is printing an incorrect / non-machine readable value, when using -j (json output) we are expecting machine readable data that shouldn't require special handling/parsing.
$ bridge -j fdb show | \
python -c \
'import sys,json;print(json.dumps(json.loads(sys.stdin.read()),indent=4))'
[
{
"master": "br0",
"mac": "56:23:28:4f:4f:e5",
"flags": [],
"ifname": "vx0",
"state": "state=0x80" <<<<<<<<< with the patch: "state": "0x80"
}
]This patch also fixes the non-json output, from:
state=0x42
to:
state 0x42This will only be displayed if the FDB entry has an unknown value.
--- bridge/fdb.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
bridge/fdb.c +4 -1
@@ -62,7 +62,10 @@ static const char *state_n2a(unsigned int s)if (s &NUD_REACHABLE )return "" ; -sprintf (buf,"state=%#x" , s); +if (is_json_context ()) +sprintf (buf,"%#x" , s); +else +sprintf (buf,"state %#x" , s);return buf; }
Signature · 1 line
2.27.0
bridge/fdb.c static const char *state_n2a(unsigned int s) · line 68
Quoted 13 lines · On Mon, 27 Jul 2020 18:20:09 +0200 Julien Fortin <[email protected]>…
bridge/fdb.c +4
-1@@ -62,7 +62,10 @@ static const char *state_n2a(unsigned int s)if (s &NUD_REACHABLE )return "" ; -sprintf (buf,"state=%#x" , s); +if (is_json_context ()) +sprintf (buf,"%#x" , s); +else +sprintf (buf,"state %#x" , s)
Please keep the "state=%#x" for the non JSON case. No need to change output format.
Quoted 12 lines · Stephen Hemminger
Quoted 8 lines · On Mon, 27 Jul 2020 18:20:09 +0200 Julien Fortin <[email protected]>…
bridge/fdb.c +0
-0@@ -62,7 +62,10 @@ static const char *state_n2a(unsigned int s)if (s &NUD_REACHABLE )return "" ;
Quoted 8 lines
bridge/fdb.c static const char *state_n2a(unsigned int s) · line 68
Quoted 5 lines
bridge/fdb.c +4
-1-sprintf (buf,"state=%#x" , s); +if (is_json_context ()) +sprintf (buf,"%#x" , s); +else +sprintf (buf,"state %#x" , s)Please keep the "state=%#x" for the non JSON case. No need to change output format.
My v1 patch (see below) kept the "state=" but you asked me to remove it and re-submit.
bridge/fdb.c +4 -1
@@ -62,7 +62,10 @@ static const char *state_n2a(unsigned int s)if (s &NUD_REACHABLE )return "" ; -sprintf (buf,"state=%#x" , s); +if (is_json_context ()) +sprintf (buf,"%#x" , s); +else +sprintf (buf,"state=%#x" , s);return buf; }
Quoted 32 lines · Julien Fortin
Quoted 12 lines · Stephen Hemminger
Quoted 8 lines · On Mon, 27 Jul 2020 18:20:09 +0200 Julien Fortin <[email protected]>…
bridge/fdb.c +0
-0@@ -62,7 +62,10 @@ static const char *state_n2a(unsigned int s)if (s &NUD_REACHABLE )return "" ;Quoted 8 lines
bridge/fdb.c static const char *state_n2a(unsigned int s)
Quoted 5 lines
bridge/fdb.c +4
-1-sprintf (buf,"state=%#x" , s); +if (is_json_context ()) +sprintf (buf,"%#x" , s); +else +sprintf (buf,"state %#x" , s)Please keep the "state=%#x" for the non JSON case. No need to change output format.
My v1 patch (see below) kept the "state=" but you asked me to remove it and re-submit.
bridge/fdb.c +0
-0@@ -62,7 +62,10 @@ static const char *state_n2a(unsigned int s)if (s &NUD_REACHABLE )
bridge/fdb.c static const char *state_n2a(unsigned int s) · line 71
Quoted 10 lines
bridge/fdb.c +4
-1return "" ; -sprintf (buf,"state=%#x" , s); +if (is_json_context ()) +sprintf (buf,"%#x" , s); +else +sprintf (buf,"state=%#x" , s);return buf; }
the v1 patch looks correct to me. Resubmit, but this should go to main branch since it is a bug fix.