bridge/mdb: fix missing new line when show bridge mdb
Subsystems (2)
PATCH 1/1 bridge/mdb: fix missing new line when show bridge mdb
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
--- bridge/mdb.c | 8 ++++++++ 1 file changed, 8 insertions(+)
bridge/mdb.c +8 -0
@@ -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 (); }
Signature · 1 line
2.5.5
Quoted 32 lines · On Wed, 5 Sep 2018 11:33:43 +0800 Hangbin Liu <[email protected]> wrote:
The bridge mdb show is broken on current iproute2. e.g.
]# bridge mdb show
34: br0veth0_br224.1.1.2 temp 34: br0veth0_br224.1.1.1 tempAfter fix:
]# bridge mdb show34: br0 veth0_br 224.1.1.2 temp 34: br0 veth0_br 224.1.1.1 tempReported-by Ying Xu <[email protected]>Fixes c7c1a1ef51aea ("bridge: colorize output and use JSON print library")Signed-off-by Hangbin Liu <[email protected]>--- bridge/mdb.c | 8 ++++++++ 1 file changed, 8 insertions(+)bridge/mdb.c +4
-0@@ -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 ); }
bridge/mdb.c static void print_mdb_entry(FILE *f, int ifindex, const struct br_mdb_entry *e, · line 177
Quoted 10 lines
bridge/mdb.c +4
-0@@ -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.
Hi Stephen,
Quoted 14 lines · Stephen Hemminger
bridge/mdb.c static void print_mdb_entry(FILE *f, int ifindex, const struct br_mdb_entry *e, · line 177
Quoted 11 lines
bridge/mdb.c +4
-0@@ -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.
Quoted 3 lines
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.
Quoted 5 lines
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
PATCH v2 1/1 bridge/mdb: fix missing new line when show bridge mdb
In reply to Hangbin LiuThe 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.
--- bridge/mdb.c | 8 ++++++++ 1 file changed, 8 insertions(+)
bridge/mdb.c +8 -0
@@ -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 (); }
Signature · 1 line
2.5.5
Hi Hangbin,
On Tue, Sep 11, 2018 at 09:26:35AM +0800, Hangbin Liu wrote:
[...]
bridge/mdb.c static void br_print_router_ports(FILE *f, struct rtattr *attr, · line 112
Quoted 2 lines
bridge/mdb.c +2
-0+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
bridge/mdb.c static void br_print_router_ports(FILE *f, struct rtattr *attr, · line 112
Quoted 2 lines · On Tue, 11 Sep 2018 09:26:35 +0800 Hangbin Liu <[email protected]> wrote:
bridge/mdb.c +2
-0+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.
PATCH v3 1/1 bridge/mdb: fix missing new line when show bridge mdb
In reply to Hangbin LiuThe 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.
--- bridge/mdb.c | 6 ++++++ 1 file changed, 6 insertions(+)
bridge/mdb.c +6 -0
@@ -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 (); }
Signature · 1 line
2.5.5
Quoted 35 lines · On Tue, 11 Sep 2018 22:04:50 +0800 Hangbin Liu <[email protected]> wrote:
The bridge mdb show is broken on current iproute2. e.g.
]# bridge mdb show
34: br0veth0_br224.1.1.2 temp 34: br0veth0_br224.1.1.1 tempAfter fix:
]# bridge mdb show34: br0 veth0_br 224.1.1.2 temp 34: br0 veth0_br 224.1.1.1 tempv2: Use json print lib as Stephen suggested.
v3: No need to useis_json_context()as Phil pointed out.Reported-by Ying Xu <[email protected]>Fixes c7c1a1ef51aea ("bridge: colorize output and use JSON print library")Signed-off-by Hangbin Liu <[email protected]>--- bridge/mdb.c | 6 ++++++ 1 file changed, 6 insertions(+)bridge/mdb.c +4
-0@@ -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 ); }
bridge/mdb.c static void print_mdb_entry(FILE *f, int ifindex, const struct br_mdb_entry *e, · line 172
Quoted 5 lines
bridge/mdb.c +2
-0@@ -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.
PATCH v4 1/1 bridge/mdb: fix missing new line when show bridge mdb
In reply to Hangbin LiuThe 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.
--- bridge/mdb.c | 6 ++++++ 1 file changed, 6 insertions(+)
bridge/mdb.c +6 -0
@@ -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 (); }
Signature · 1 line
2.5.5