* [PATCH iproute2-next master v2] bridge: fdb show: fix fdb entry state output (+ add json support)
@ 2020-07-27 16:20 Julien Fortin
2020-07-27 16:30 ` Stephen Hemminger
0 siblings, 1 reply; 4+ messages in thread
From: Julien Fortin @ 2020-07-27 16:20 UTC (permalink / raw)
To: netdev; +Cc: roopa, dsahern, Julien Fortin
From: Julien Fortin <julien@cumulusnetworks.com>
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 0x42
This will only be displayed if the FDB entry has an unknown value.
Fixes: c7c1a1ef51aea7c ("bridge: colorize output and use JSON print library")
Signed-off-by: Julien Fortin <julien@cumulusnetworks.com>
---
bridge/fdb.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/bridge/fdb.c b/bridge/fdb.c
index d1f8afbe..765f4e51 100644
--- a/bridge/fdb.c
+++ b/bridge/fdb.c
@@ -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;
}
--
2.27.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH iproute2-next master v2] bridge: fdb show: fix fdb entry state output (+ add json support)
2020-07-27 16:20 [PATCH iproute2-next master v2] bridge: fdb show: fix fdb entry state output (+ add json support) Julien Fortin
@ 2020-07-27 16:30 ` Stephen Hemminger
2020-07-27 23:25 ` Julien Fortin
0 siblings, 1 reply; 4+ messages in thread
From: Stephen Hemminger @ 2020-07-27 16:30 UTC (permalink / raw)
To: Julien Fortin; +Cc: netdev, roopa, dsahern
On Mon, 27 Jul 2020 18:20:09 +0200
Julien Fortin <julien@cumulusnetworks.com> wrote:
> diff --git a/bridge/fdb.c b/bridge/fdb.c
> index d1f8afbe..765f4e51 100644
> --- a/bridge/fdb.c
> +++ b/bridge/fdb.c
> @@ -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.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH iproute2-next master v2] bridge: fdb show: fix fdb entry state output (+ add json support)
2020-07-27 16:30 ` Stephen Hemminger
@ 2020-07-27 23:25 ` Julien Fortin
2020-07-28 21:08 ` David Ahern
0 siblings, 1 reply; 4+ messages in thread
From: Julien Fortin @ 2020-07-27 23:25 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: netdev, Roopa Prabhu, David Ahern
On Mon, Jul 27, 2020 at 6:30 PM Stephen Hemminger
<stephen@networkplumber.org> wrote:
>
> On Mon, 27 Jul 2020 18:20:09 +0200
> Julien Fortin <julien@cumulusnetworks.com> wrote:
>
> > diff --git a/bridge/fdb.c b/bridge/fdb.c
> > index d1f8afbe..765f4e51 100644
> > --- a/bridge/fdb.c
> > +++ b/bridge/fdb.c
> > @@ -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.
My v1 patch (see below) kept the "state=" but you asked me to remove
it and re-submit.
diff --git a/bridge/fdb.c b/bridge/fdb.c
index d2247e80..198c51d1 100644
--- a/bridge/fdb.c
+++ b/bridge/fdb.c
@@ -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;
}
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH iproute2-next master v2] bridge: fdb show: fix fdb entry state output (+ add json support)
2020-07-27 23:25 ` Julien Fortin
@ 2020-07-28 21:08 ` David Ahern
0 siblings, 0 replies; 4+ messages in thread
From: David Ahern @ 2020-07-28 21:08 UTC (permalink / raw)
To: Julien Fortin, Stephen Hemminger; +Cc: netdev, Roopa Prabhu
On 7/27/20 5:25 PM, Julien Fortin wrote:
> On Mon, Jul 27, 2020 at 6:30 PM Stephen Hemminger
> <stephen@networkplumber.org> wrote:
>>
>> On Mon, 27 Jul 2020 18:20:09 +0200
>> Julien Fortin <julien@cumulusnetworks.com> wrote:
>>
>>> diff --git a/bridge/fdb.c b/bridge/fdb.c
>>> index d1f8afbe..765f4e51 100644
>>> --- a/bridge/fdb.c
>>> +++ b/bridge/fdb.c
>>> @@ -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.
>
> My v1 patch (see below) kept the "state=" but you asked me to remove
> it and re-submit.
>
> diff --git a/bridge/fdb.c b/bridge/fdb.c
> index d2247e80..198c51d1 100644
> --- a/bridge/fdb.c
> +++ b/bridge/fdb.c
> @@ -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;
> }
>
the v1 patch looks correct to me. Resubmit, but this should go to main
branch since it is a bug fix.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-07-28 21:08 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-27 16:20 [PATCH iproute2-next master v2] bridge: fdb show: fix fdb entry state output (+ add json support) Julien Fortin
2020-07-27 16:30 ` Stephen Hemminger
2020-07-27 23:25 ` Julien Fortin
2020-07-28 21:08 ` David Ahern
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.