All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH iproute2] bridge/mdb: fix missing new line when show bridge mdb
@ 2018-09-05  3:33 Hangbin Liu
  2018-09-06 13:00 ` Stephen Hemminger
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Hangbin Liu @ 2018-09-05  3:33 UTC (permalink / raw)
  To: netdev; +Cc: Stephen Hemminger, David Ahern, Hangbin Liu

The bridge mdb show is broken on current iproute2. e.g.
]# bridge mdb show
34: br0  veth0_br  224.1.1.2  temp 34: br0  veth0_br  224.1.1.1  temp

After fix:
]# bridge mdb show
34: br0  veth0_br  224.1.1.2  temp
34: br0  veth0_br  224.1.1.1  temp

Reported-by: Ying Xu <yinxu@redhat.com>
Fixes: c7c1a1ef51aea ("bridge: colorize output and use JSON print library")
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
---
 bridge/mdb.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/bridge/mdb.c b/bridge/mdb.c
index f38dc67..d89c065 100644
--- a/bridge/mdb.c
+++ b/bridge/mdb.c
@@ -107,6 +107,10 @@ static void br_print_router_ports(FILE *f, struct rtattr *attr,
 			fprintf(f, "%s ", port_ifname);
 		}
 	}
+
+	if (!is_json_context() && !show_stats)
+		fprintf(f, "\n");
+
 	close_json_array(PRINT_JSON, NULL);
 }
 
@@ -164,6 +168,10 @@ static void print_mdb_entry(FILE *f, int ifindex, const struct br_mdb_entry *e,
 		print_string(PRINT_ANY, "timer", " %s",
 			     format_timer(timer));
 	}
+
+	if (!is_json_context())
+		fprintf(f, "\n");
+
 	close_json_object();
 }
 
-- 
2.5.5

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH iproute2] bridge/mdb: fix missing new line when show bridge mdb
  2018-09-05  3:33 [PATCH iproute2] bridge/mdb: fix missing new line when show bridge mdb Hangbin Liu
@ 2018-09-06 13:00 ` Stephen Hemminger
  2018-09-07  0:14   ` Hangbin Liu
  2018-09-11  1:26 ` [PATCHv2 " Hangbin Liu
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 9+ messages in thread
From: Stephen Hemminger @ 2018-09-06 13:00 UTC (permalink / raw)
  To: Hangbin Liu; +Cc: netdev, David Ahern

On Wed,  5 Sep 2018 11:33:43 +0800
Hangbin Liu <liuhangbin@gmail.com> wrote:

> The bridge mdb show is broken on current iproute2. e.g.
> ]# bridge mdb show
> 34: br0  veth0_br  224.1.1.2  temp 34: br0  veth0_br  224.1.1.1  temp
> 
> After fix:
> ]# bridge mdb show
> 34: br0  veth0_br  224.1.1.2  temp
> 34: br0  veth0_br  224.1.1.1  temp
> 
> Reported-by: Ying Xu <yinxu@redhat.com>
> Fixes: c7c1a1ef51aea ("bridge: colorize output and use JSON print library")
> Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
> ---
>  bridge/mdb.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/bridge/mdb.c b/bridge/mdb.c
> index f38dc67..d89c065 100644
> --- a/bridge/mdb.c
> +++ b/bridge/mdb.c
> @@ -107,6 +107,10 @@ static void br_print_router_ports(FILE *f, struct rtattr *attr,
>  			fprintf(f, "%s ", port_ifname);
>  		}
>  	}
> +
> +	if (!is_json_context() && !show_stats)
> +		fprintf(f, "\n");
> +
>  	close_json_array(PRINT_JSON, NULL);
>  }
>  
> @@ -164,6 +168,10 @@ static void print_mdb_entry(FILE *f, int ifindex, const struct br_mdb_entry *e,
>  		print_string(PRINT_ANY, "timer", " %s",
>  			     format_timer(timer));
>  	}
> +
> +	if (!is_json_context())
> +		fprintf(f, "\n");
> +
>  	close_json_object();
>  }
>  

Thanks for catching this.

Now that there is a json print library, the preferred pattern for
this is:
	print_string(PRINT_FP, NULL, "\n", NULL);

I plan to introduce a helper
	print_fp(...)

and it would be easier if all places were consistent.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH iproute2] bridge/mdb: fix missing new line when show bridge mdb
  2018-09-06 13:00 ` Stephen Hemminger
@ 2018-09-07  0:14   ` Hangbin Liu
  0 siblings, 0 replies; 9+ messages in thread
From: Hangbin Liu @ 2018-09-07  0:14 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: netdev, David Ahern

Hi Stephen,
On Thu, Sep 06, 2018 at 02:00:53PM +0100, Stephen Hemminger wrote:
> > @@ -164,6 +168,10 @@ static void print_mdb_entry(FILE *f, int ifindex, const struct br_mdb_entry *e,
> >  		print_string(PRINT_ANY, "timer", " %s",
> >  			     format_timer(timer));
> >  	}
> > +
> > +	if (!is_json_context())
> > +		fprintf(f, "\n");
> > +
> >  	close_json_object();
> >  }
> >  
> 
> Thanks for catching this.
> 
> Now that there is a json print library, the preferred pattern for
> this is:
> 	print_string(PRINT_FP, NULL, "\n", NULL);

Are we going to replace all printf() by json print library, even not in
json context? If yes, I can post a v2 patch. Becuase there are still a
lot fprintf() in mdb.c.

> 
> I plan to introduce a helper
> 	print_fp(...)
> 
> and it would be easier if all places were consistent.

cool, that would be more clear.

Thanks
Hangbin

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCHv2 iproute2] bridge/mdb: fix missing new line when show bridge mdb
  2018-09-05  3:33 [PATCH iproute2] bridge/mdb: fix missing new line when show bridge mdb Hangbin Liu
  2018-09-06 13:00 ` Stephen Hemminger
@ 2018-09-11  1:26 ` Hangbin Liu
  2018-09-11 11:01   ` Phil Sutter
  2018-09-11 15:30   ` Stephen Hemminger
  2018-09-11 14:04 ` [PATCHv3 " Hangbin Liu
  2018-09-12  1:39 ` [PATCHv4 " Hangbin Liu
  3 siblings, 2 replies; 9+ messages in thread
From: Hangbin Liu @ 2018-09-11  1:26 UTC (permalink / raw)
  To: netdev; +Cc: Stephen Hemminger, David Ahern, Phil Sutter, Hangbin Liu

The bridge mdb show is broken on current iproute2. e.g.
]# bridge mdb show
34: br0  veth0_br  224.1.1.2  temp 34: br0  veth0_br  224.1.1.1  temp

After fix:
]# bridge mdb show
34: br0  veth0_br  224.1.1.2  temp
34: br0  veth0_br  224.1.1.1  temp

v2: use json print lib as Stephen suggested.

Reported-by: Ying Xu <yinxu@redhat.com>
Fixes: c7c1a1ef51aea ("bridge: colorize output and use JSON print library")
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
---
 bridge/mdb.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/bridge/mdb.c b/bridge/mdb.c
index f38dc67..408117d 100644
--- a/bridge/mdb.c
+++ b/bridge/mdb.c
@@ -107,6 +107,10 @@ static void br_print_router_ports(FILE *f, struct rtattr *attr,
 			fprintf(f, "%s ", port_ifname);
 		}
 	}
+
+	if (!is_json_context() && !show_stats)
+		print_string(PRINT_FP, NULL, "\n", NULL);
+
 	close_json_array(PRINT_JSON, NULL);
 }
 
@@ -164,6 +168,10 @@ static void print_mdb_entry(FILE *f, int ifindex, const struct br_mdb_entry *e,
 		print_string(PRINT_ANY, "timer", " %s",
 			     format_timer(timer));
 	}
+
+	if (!is_json_context())
+		print_string(PRINT_FP, NULL, "\n", NULL);
+
 	close_json_object();
 }
 
-- 
2.5.5

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCHv2 iproute2] bridge/mdb: fix missing new line when show bridge mdb
  2018-09-11  1:26 ` [PATCHv2 " Hangbin Liu
@ 2018-09-11 11:01   ` Phil Sutter
  2018-09-11 15:30   ` Stephen Hemminger
  1 sibling, 0 replies; 9+ messages in thread
From: Phil Sutter @ 2018-09-11 11:01 UTC (permalink / raw)
  To: Hangbin Liu; +Cc: netdev, Stephen Hemminger, David Ahern

Hi Hangbin,

On Tue, Sep 11, 2018 at 09:26:35AM +0800, Hangbin Liu wrote:
[...]
> +	if (!is_json_context() && !show_stats)
> +		print_string(PRINT_FP, NULL, "\n", NULL);

There is no need to check for !is_json_context() here. You give a type
of PRINT_FP which won't lead to output if JSON is active. For reference,
check print_color_string() in lib/json_print.c and _IS_JSON_CONTEXT
macro.

Cheers, Phil

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCHv3 iproute2] bridge/mdb: fix missing new line when show bridge mdb
  2018-09-05  3:33 [PATCH iproute2] bridge/mdb: fix missing new line when show bridge mdb Hangbin Liu
  2018-09-06 13:00 ` Stephen Hemminger
  2018-09-11  1:26 ` [PATCHv2 " Hangbin Liu
@ 2018-09-11 14:04 ` Hangbin Liu
  2018-09-11 15:31   ` Stephen Hemminger
  2018-09-12  1:39 ` [PATCHv4 " Hangbin Liu
  3 siblings, 1 reply; 9+ messages in thread
From: Hangbin Liu @ 2018-09-11 14:04 UTC (permalink / raw)
  To: netdev; +Cc: Phil Sutter, Stephen Hemminger, David Ahern, Hangbin Liu

The bridge mdb show is broken on current iproute2. e.g.
]# bridge mdb show
34: br0  veth0_br  224.1.1.2  temp 34: br0  veth0_br  224.1.1.1  temp

After fix:
]# bridge mdb show
34: br0  veth0_br  224.1.1.2  temp
34: br0  veth0_br  224.1.1.1  temp

v2: Use json print lib as Stephen suggested.
v3: No need to use is_json_context() as Phil pointed out.

Reported-by: Ying Xu <yinxu@redhat.com>
Fixes: c7c1a1ef51aea ("bridge: colorize output and use JSON print library")
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
---
 bridge/mdb.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/bridge/mdb.c b/bridge/mdb.c
index f38dc67..2f24b01 100644
--- a/bridge/mdb.c
+++ b/bridge/mdb.c
@@ -107,6 +107,10 @@ static void br_print_router_ports(FILE *f, struct rtattr *attr,
 			fprintf(f, "%s ", port_ifname);
 		}
 	}
+
+	if (!show_stats)
+		print_string(PRINT_FP, NULL, "\n", NULL);
+
 	close_json_array(PRINT_JSON, NULL);
 }
 
@@ -164,6 +168,8 @@ static void print_mdb_entry(FILE *f, int ifindex, const struct br_mdb_entry *e,
 		print_string(PRINT_ANY, "timer", " %s",
 			     format_timer(timer));
 	}
+
+	print_string(PRINT_FP, NULL, "\n", NULL);
 	close_json_object();
 }
 
-- 
2.5.5

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCHv2 iproute2] bridge/mdb: fix missing new line when show bridge mdb
  2018-09-11  1:26 ` [PATCHv2 " Hangbin Liu
  2018-09-11 11:01   ` Phil Sutter
@ 2018-09-11 15:30   ` Stephen Hemminger
  1 sibling, 0 replies; 9+ messages in thread
From: Stephen Hemminger @ 2018-09-11 15:30 UTC (permalink / raw)
  To: Hangbin Liu; +Cc: netdev, David Ahern, Phil Sutter

On Tue, 11 Sep 2018 09:26:35 +0800
Hangbin Liu <liuhangbin@gmail.com> wrote:

> +	if (!is_json_context() && !show_stats)
> +		print_string(PRINT_FP, NULL, "\n", NULL);

I just added print_nl to json_print which does what you want.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCHv3 iproute2] bridge/mdb: fix missing new line when show bridge mdb
  2018-09-11 14:04 ` [PATCHv3 " Hangbin Liu
@ 2018-09-11 15:31   ` Stephen Hemminger
  0 siblings, 0 replies; 9+ messages in thread
From: Stephen Hemminger @ 2018-09-11 15:31 UTC (permalink / raw)
  To: Hangbin Liu; +Cc: netdev, Phil Sutter, David Ahern

On Tue, 11 Sep 2018 22:04:50 +0800
Hangbin Liu <liuhangbin@gmail.com> wrote:

> The bridge mdb show is broken on current iproute2. e.g.
> ]# bridge mdb show
> 34: br0  veth0_br  224.1.1.2  temp 34: br0  veth0_br  224.1.1.1  temp
> 
> After fix:
> ]# bridge mdb show
> 34: br0  veth0_br  224.1.1.2  temp
> 34: br0  veth0_br  224.1.1.1  temp
> 
> v2: Use json print lib as Stephen suggested.
> v3: No need to use is_json_context() as Phil pointed out.
> 
> Reported-by: Ying Xu <yinxu@redhat.com>
> Fixes: c7c1a1ef51aea ("bridge: colorize output and use JSON print library")
> Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
> ---
>  bridge/mdb.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/bridge/mdb.c b/bridge/mdb.c
> index f38dc67..2f24b01 100644
> --- a/bridge/mdb.c
> +++ b/bridge/mdb.c
> @@ -107,6 +107,10 @@ static void br_print_router_ports(FILE *f, struct rtattr *attr,
>  			fprintf(f, "%s ", port_ifname);
>  		}
>  	}
> +
> +	if (!show_stats)
> +		print_string(PRINT_FP, NULL, "\n", NULL);
> +
>  	close_json_array(PRINT_JSON, NULL);
>  }
>  
> @@ -164,6 +168,8 @@ static void print_mdb_entry(FILE *f, int ifindex, const struct br_mdb_entry *e,
>  		print_string(PRINT_ANY, "timer", " %s",
>  			     format_timer(timer));
>  	}
> +
> +	print_string(PRINT_FP, NULL, "\n", NULL);

This can now just be:
	print_nl();

The problem with print_string(PRINT_FP, NULL, "\n", NULL) is that it doesn't handle oneline
mode correctly.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCHv4 iproute2] bridge/mdb: fix missing new line when show bridge mdb
  2018-09-05  3:33 [PATCH iproute2] bridge/mdb: fix missing new line when show bridge mdb Hangbin Liu
                   ` (2 preceding siblings ...)
  2018-09-11 14:04 ` [PATCHv3 " Hangbin Liu
@ 2018-09-12  1:39 ` Hangbin Liu
  3 siblings, 0 replies; 9+ messages in thread
From: Hangbin Liu @ 2018-09-12  1:39 UTC (permalink / raw)
  To: netdev; +Cc: Phil Sutter, Stephen Hemminger, David Ahern, Hangbin Liu

The bridge mdb show is broken on current iproute2. e.g.
]# bridge mdb show
34: br0  veth0_br  224.1.1.2  temp 34: br0  veth0_br  224.1.1.1  temp

After fix:
]# bridge mdb show
34: br0  veth0_br  224.1.1.2  temp
34: br0  veth0_br  224.1.1.1  temp

v2: Use json print lib as Stephen suggested.
v3: No need to use is_json_context() as print_string() could handle both cases.
v4: use new function print_nl() to print new line in non-json mode.

Reported-by: Ying Xu <yinxu@redhat.com>
Fixes: c7c1a1ef51aea ("bridge: colorize output and use JSON print library")
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
---
 bridge/mdb.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/bridge/mdb.c b/bridge/mdb.c
index cc1b454..841a361 100644
--- a/bridge/mdb.c
+++ b/bridge/mdb.c
@@ -107,6 +107,10 @@ static void br_print_router_ports(FILE *f, struct rtattr *attr,
 			fprintf(f, "%s ", port_ifname);
 		}
 	}
+
+	if (!show_stats)
+		print_nl();
+
 	close_json_array(PRINT_JSON, NULL);
 }
 
@@ -157,6 +161,8 @@ static void print_mdb_entry(FILE *f, int ifindex, const struct br_mdb_entry *e,
 		print_string(PRINT_ANY, "timer", " %s",
 			     format_timer(timer));
 	}
+
+	print_nl();
 	close_json_object();
 }
 
-- 
2.5.5

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2018-09-12  6:42 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-05  3:33 [PATCH iproute2] bridge/mdb: fix missing new line when show bridge mdb Hangbin Liu
2018-09-06 13:00 ` Stephen Hemminger
2018-09-07  0:14   ` Hangbin Liu
2018-09-11  1:26 ` [PATCHv2 " Hangbin Liu
2018-09-11 11:01   ` Phil Sutter
2018-09-11 15:30   ` Stephen Hemminger
2018-09-11 14:04 ` [PATCHv3 " Hangbin Liu
2018-09-11 15:31   ` Stephen Hemminger
2018-09-12  1:39 ` [PATCHv4 " Hangbin Liu

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.