From d6abae5a7a5d72f43ad018206e18d9fb5b891f95 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Tue, 16 Apr 2019 16:04:39 +0200 Subject: [PATCH 1/8] ip: add missing space after 'external' in detailed mode Add a missing space after the 'external' keyword in the detailed mode of tunnel links output: # ip -d link 79: geneve1: mtu 65465 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/ether da:e9:e4:2b:f9:d4 brd ff:ff:ff:ff:ff:ff promiscuity 0 minmtu 68 maxmtu 65465 geneve externaladdrgenmode eui64 numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535 80: vxlan1: mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/ether 7a:a8:19:07:da:01 brd ff:ff:ff:ff:ff:ff promiscuity 0 minmtu 68 maxmtu 65535 vxlan externaladdrgenmode eui64 numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535 84: gre1@NONE: mtu 1476 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/none 00:00:00:00 brd 00:00:00:00 promiscuity 0 minmtu 0 maxmtu 0 gre externaladdrgenmode eui64 numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535 87: ip6gre1@NONE: mtu 1448 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/gre6 :: brd :: promiscuity 0 minmtu 0 maxmtu 0 ip6gre externaladdrgenmode eui64 numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535 88: ip6tnl1@NONE: mtu 1452 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/tunnel6 :: brd :: promiscuity 0 minmtu 68 maxmtu 65407 ip6tnl externaladdrgenmode eui64 numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535 90: ipip1@NONE: mtu 1480 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/ipip 0.0.0.0 brd 0.0.0.0 promiscuity 0 minmtu 0 maxmtu 0 ipip externaladdrgenmode eui64 numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535 Fixes: 00ff4b8e31af ("ip/tunnel: Be consistent when printing tunnel collect metadata") Reviewed-and-tested-by: Andrea Claudi Signed-off-by: Beniamino Galvani Signed-off-by: Stephen Hemminger --- ip/iplink_geneve.c | 2 +- ip/iplink_vxlan.c | 2 +- ip/link_gre.c | 2 +- ip/link_gre6.c | 2 +- ip/link_ip6tnl.c | 2 +- ip/link_iptnl.c | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ip/iplink_geneve.c b/ip/iplink_geneve.c index 278a6e23..d70b1941 100644 --- a/ip/iplink_geneve.c +++ b/ip/iplink_geneve.c @@ -251,7 +251,7 @@ static void geneve_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) return; if (tb[IFLA_GENEVE_COLLECT_METADATA]) { - print_bool(PRINT_ANY, "external", "external", true); + print_bool(PRINT_ANY, "external", "external ", true); return; } diff --git a/ip/iplink_vxlan.c b/ip/iplink_vxlan.c index 497affc0..1489c009 100644 --- a/ip/iplink_vxlan.c +++ b/ip/iplink_vxlan.c @@ -418,7 +418,7 @@ static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) if (tb[IFLA_VXLAN_COLLECT_METADATA] && rta_getattr_u8(tb[IFLA_VXLAN_COLLECT_METADATA])) { - print_bool(PRINT_ANY, "external", "external", true); + print_bool(PRINT_ANY, "external", "external ", true); return; } diff --git a/ip/link_gre.c b/ip/link_gre.c index d754fa9a..842fab5c 100644 --- a/ip/link_gre.c +++ b/ip/link_gre.c @@ -436,7 +436,7 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) return; if (tb[IFLA_GRE_COLLECT_METADATA]) { - print_bool(PRINT_ANY, "external", "external", true); + print_bool(PRINT_ANY, "external", "external ", true); return; } diff --git a/ip/link_gre6.c b/ip/link_gre6.c index 6c4671e5..4710b404 100644 --- a/ip/link_gre6.c +++ b/ip/link_gre6.c @@ -465,7 +465,7 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) return; if (tb[IFLA_GRE_COLLECT_METADATA]) { - print_bool(PRINT_ANY, "external", "external", true); + print_bool(PRINT_ANY, "external", "external ", true); return; } diff --git a/ip/link_ip6tnl.c b/ip/link_ip6tnl.c index 711988a1..8d9feab1 100644 --- a/ip/link_ip6tnl.c +++ b/ip/link_ip6tnl.c @@ -354,7 +354,7 @@ static void ip6tunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb return; if (tb[IFLA_IPTUN_COLLECT_METADATA]) { - print_bool(PRINT_ANY, "external", "external", true); + print_bool(PRINT_ANY, "external", "external ", true); return; } diff --git a/ip/link_iptnl.c b/ip/link_iptnl.c index d4a56de4..2736ef89 100644 --- a/ip/link_iptnl.c +++ b/ip/link_iptnl.c @@ -374,7 +374,7 @@ static void iptunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[ return; if (tb[IFLA_IPTUN_COLLECT_METADATA]) { - print_bool(PRINT_ANY, "external", "external", true); + print_bool(PRINT_ANY, "external", "external ", true); return; } From b11b495e7c071691e6282d048ab2d1a32a8c000d Mon Sep 17 00:00:00 2001 From: Nikolay Aleksandrov Date: Fri, 12 Apr 2019 18:30:55 +0300 Subject: [PATCH 2/8] bridge: mdb: restore valid json output Since the commit below mdb's json output has been invalid and also with changed format. Restore it to a valid json like the previous format. Also takes care of a double "Deleted" print when monitoring for changes. Example bridge -p -d -j mdb show: [ { "mdb": [ { "index": 4, "dev": "virbr0", "port": "vnet2", "grp": "ff02::202", "state": "temp", "flags": [ ] },{ "index": 4, "dev": "virbr0", "port": "vnet2", "grp": "ff02::1:fffb:1939", "state": "temp", "flags": [ ] },{ "index": 6, "dev": "virbr1", "port": "vnet7", "grp": "ff02::202", "state": "temp", "flags": [ ] },{ "index": 6, "dev": "virbr1", "port": "vnet7", "grp": "ff02::1:ffd0:f61f", "state": "temp", "flags": [ ] } ], "router": { "virbr0": [ { "port": "vnet1" },{ "port": "vnet0" } ], "virbr1": [ { "port": "vnet5" } ] } } ] Fixes: c7c1a1ef51ae ("bridge: colorize output and use JSON print library") Signed-off-by: Nikolay Aleksandrov Signed-off-by: Stephen Hemminger --- bridge/br_common.h | 2 +- bridge/mdb.c | 80 +++++++++++++++++++++++++++++++++++++++------- bridge/monitor.c | 2 +- 3 files changed, 70 insertions(+), 14 deletions(-) diff --git a/bridge/br_common.h b/bridge/br_common.h index 23d653df..b5798da3 100644 --- a/bridge/br_common.h +++ b/bridge/br_common.h @@ -8,8 +8,8 @@ void print_vlan_info(struct rtattr *tb, int ifindex); int print_linkinfo(struct nlmsghdr *n, void *arg); +int print_mdb_mon(struct nlmsghdr *n, void *arg); int print_fdb(struct nlmsghdr *n, void *arg); -int print_mdb(struct nlmsghdr *n, void *arg); int do_fdb(int argc, char **argv); int do_mdb(int argc, char **argv); diff --git a/bridge/mdb.c b/bridge/mdb.c index 855a6a45..59aa1764 100644 --- a/bridge/mdb.c +++ b/bridge/mdb.c @@ -132,9 +132,6 @@ static void print_mdb_entry(FILE *f, int ifindex, const struct br_mdb_entry *e, open_json_object(NULL); - if (n->nlmsg_type == RTM_DELMDB) - print_bool(PRINT_ANY, "deleted", "Deleted ", true); - print_int(PRINT_ANY, "index", "%u: ", ifindex); print_color_string(PRINT_ANY, COLOR_IFNAME, "dev", "%s ", dev); print_string(PRINT_ANY, "port", " %s ", @@ -189,10 +186,8 @@ static void print_mdb_entries(FILE *fp, struct nlmsghdr *n, int rem = RTA_PAYLOAD(mdb); struct rtattr *i; - open_json_array(PRINT_JSON, "mdb"); for (i = RTA_DATA(mdb); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) br_print_mdb_entry(fp, ifindex, i, n); - close_json_array(PRINT_JSON, NULL); } static void print_router_entries(FILE *fp, struct nlmsghdr *n, @@ -200,7 +195,6 @@ static void print_router_entries(FILE *fp, struct nlmsghdr *n, { const char *brifname = ll_index_to_name(ifindex); - open_json_array(PRINT_JSON, "router"); if (n->nlmsg_type == RTM_GETMDB) { if (show_details) br_print_router_ports(fp, router, brifname); @@ -222,15 +216,12 @@ static void print_router_entries(FILE *fp, struct nlmsghdr *n, port_name, brifname); } } - close_json_array(PRINT_JSON, NULL); } -int print_mdb(struct nlmsghdr *n, void *arg) +static int __parse_mdb_nlmsg(struct nlmsghdr *n, struct rtattr **tb) { - FILE *fp = arg; struct br_port_msg *r = NLMSG_DATA(n); int len = n->nlmsg_len; - struct rtattr *tb[MDBA_MAX+1]; if (n->nlmsg_type != RTM_GETMDB && n->nlmsg_type != RTM_NEWMDB && @@ -253,6 +244,54 @@ int print_mdb(struct nlmsghdr *n, void *arg) parse_rtattr(tb, MDBA_MAX, MDBA_RTA(r), n->nlmsg_len - NLMSG_LENGTH(sizeof(*r))); + return 1; +} + +static int print_mdbs(struct nlmsghdr *n, void *arg) +{ + struct br_port_msg *r = NLMSG_DATA(n); + struct rtattr *tb[MDBA_MAX+1]; + FILE *fp = arg; + int ret; + + ret = __parse_mdb_nlmsg(n, tb); + if (ret != 1) + return ret; + + if (tb[MDBA_MDB]) + print_mdb_entries(fp, n, r->ifindex, tb[MDBA_MDB]); + + return 0; +} + +static int print_rtrs(struct nlmsghdr *n, void *arg) +{ + struct br_port_msg *r = NLMSG_DATA(n); + struct rtattr *tb[MDBA_MAX+1]; + FILE *fp = arg; + int ret; + + ret = __parse_mdb_nlmsg(n, tb); + if (ret != 1) + return ret; + + if (tb[MDBA_ROUTER]) + print_router_entries(fp, n, r->ifindex, tb[MDBA_ROUTER]); + + return 0; +} + +int print_mdb_mon(struct nlmsghdr *n, void *arg) +{ + struct br_port_msg *r = NLMSG_DATA(n); + struct rtattr *tb[MDBA_MAX+1]; + FILE *fp = arg; + int ret; + + ret = __parse_mdb_nlmsg(n, tb); + if (ret != 1) + return ret; + if (n->nlmsg_type == RTM_DELMDB) print_bool(PRINT_ANY, "deleted", "Deleted ", true); @@ -291,18 +330,35 @@ static int mdb_show(int argc, char **argv) } new_json_obj(json); + open_json_object(NULL); - /* get mdb entries*/ + /* get mdb entries */ if (rtnl_mdbdump_req(&rth, PF_BRIDGE) < 0) { perror("Cannot send dump request"); return -1; } - if (rtnl_dump_filter(&rth, print_mdb, stdout) < 0) { + open_json_array(PRINT_JSON, "mdb"); + if (rtnl_dump_filter(&rth, print_mdbs, stdout) < 0) { fprintf(stderr, "Dump terminated\n"); return -1; } + close_json_array(PRINT_JSON, NULL); + /* get router ports */ + if (rtnl_mdbdump_req(&rth, PF_BRIDGE) < 0) { + perror("Cannot send dump request"); + return -1; + } + + open_json_object("router"); + if (rtnl_dump_filter(&rth, print_rtrs, stdout) < 0) { + fprintf(stderr, "Dump terminated\n"); + return -1; + } + close_json_object(); + + close_json_object(); delete_json_obj(); fflush(stdout); diff --git a/bridge/monitor.c b/bridge/monitor.c index 708a1bd2..08439a60 100644 --- a/bridge/monitor.c +++ b/bridge/monitor.c @@ -61,7 +61,7 @@ static int accept_msg(struct rtnl_ctrl_data *ctrl, case RTM_DELMDB: if (prefix_banner) fprintf(fp, "[MDB]"); - return print_mdb(n, arg); + return print_mdb_mon(n, arg); case NLMSG_TSTAMP: print_nlmsg_timestamp(fp, n); From 6e982e7b9ba2a7810aeb67232bdc4697cc5721ea Mon Sep 17 00:00:00 2001 From: Nikolay Aleksandrov Date: Tue, 16 Apr 2019 18:30:12 +0300 Subject: [PATCH 3/8] bridge: vlan: fix standard stats output Each of the commits below broke the vlan stats output in a different way: - 45fca4ed9412 ("bridge: fix vlan show stats formatting") Added a second print of an interface name (e.g. eth4eth4) - c7c1a1ef51ae ("bridge: colorize output and use JSON print library") Broke normal vlan stats output by not printing a new line after them Also printed interfaces without any vlans when printing stats This fix is not pretty but it brings back the previous behaviour. Before this fix: $ bridge -s vlan show port vlan id br0br0 1 PVID Egress Untagged RX: 0 bytes 0 packets TX: 0 bytes 0 packets 4 RX: 0 bytes 0 packets TX: 0 bytes 0 packetseth4eth4 4 RX: 0 bytes 0 packets TX: 0 bytes 0 packetsroot@debian:~/ After this fix: $ bridge -s vlan show port vlan id br0 1 PVID Egress Untagged RX: 0 bytes 0 packets TX: 0 bytes 0 packets 4 RX: 0 bytes 0 packets TX: 0 bytes 0 packets eth4 4 RX: 0 bytes 0 packets TX: 0 bytes 0 packets Fixes: 45fca4ed9412 ("bridge: fix vlan show stats formatting") Fixes: c7c1a1ef51ae ("bridge: colorize output and use JSON print library") Signed-off-by: Nikolay Aleksandrov Signed-off-by: Stephen Hemminger --- bridge/vlan.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/bridge/vlan.c b/bridge/vlan.c index d075a42d..6d33b0a9 100644 --- a/bridge/vlan.c +++ b/bridge/vlan.c @@ -252,11 +252,11 @@ static int filter_vlan_check(__u16 vid, __u16 flags) return 1; } -static void open_vlan_port(int ifi_index) +static void open_vlan_port(int ifi_index, const char *fmt) { open_json_object(NULL); - print_string(PRINT_ANY, "ifname", "%s", - ll_index_to_name(ifi_index)); + print_color_string(PRINT_ANY, COLOR_IFNAME, "ifname", fmt, + ll_index_to_name(ifi_index)); open_json_array(PRINT_JSON, "vlans"); } @@ -286,7 +286,7 @@ static void print_vlan_tunnel_info(FILE *fp, struct rtattr *tb, int ifindex) __u32 last_tunid_start = 0; if (!filter_vlan) - open_vlan_port(ifindex); + open_vlan_port(ifindex, "%s"); open_json_array(PRINT_JSON, "tunnel"); for (i = RTA_DATA(list); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) { @@ -331,7 +331,7 @@ static void print_vlan_tunnel_info(FILE *fp, struct rtattr *tb, int ifindex) continue; if (filter_vlan) - open_vlan_port(ifindex); + open_vlan_port(ifindex, "%s"); open_json_object(NULL); print_range("vlan", last_vid_start, tunnel_vid); @@ -463,7 +463,7 @@ static void print_one_vlan_stats(const struct bridge_vlan_xstats *vstats) print_lluint(PRINT_ANY, "tx_bytes", " TX: %llu bytes", vstats->tx_bytes); - print_lluint(PRINT_ANY, "tx_packets", " %llu packets", + print_lluint(PRINT_ANY, "tx_packets", " %llu packets\n", vstats->tx_packets); close_json_object(); } @@ -472,7 +472,7 @@ static void print_vlan_stats_attr(struct rtattr *attr, int ifindex) { struct rtattr *brtb[LINK_XSTATS_TYPE_MAX+1]; struct rtattr *i, *list; - const char *ifname; + bool found_vlan = false; int rem; parse_rtattr(brtb, LINK_XSTATS_TYPE_MAX, RTA_DATA(attr), @@ -483,12 +483,6 @@ static void print_vlan_stats_attr(struct rtattr *attr, int ifindex) list = brtb[LINK_XSTATS_TYPE_BRIDGE]; rem = RTA_PAYLOAD(list); - ifname = ll_index_to_name(ifindex); - open_vlan_port(ifindex); - - print_color_string(PRINT_FP, COLOR_IFNAME, - NULL, "%-16s", ifname); - for (i = RTA_DATA(list); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) { const struct bridge_vlan_xstats *vstats = RTA_DATA(i); @@ -503,9 +497,19 @@ static void print_vlan_stats_attr(struct rtattr *attr, int ifindex) !(vstats->flags & BRIDGE_VLAN_INFO_BRENTRY)) continue; + /* found vlan stats, first time print the interface name */ + if (!found_vlan) { + open_vlan_port(ifindex, "%-16s"); + found_vlan = true; + } else { + print_string(PRINT_FP, NULL, "%-16s", ""); + } print_one_vlan_stats(vstats); } - close_vlan_port(); + + /* vlan_port is opened only if there are any vlan stats */ + if (found_vlan) + close_vlan_port(); } static int print_vlan_stats(struct nlmsghdr *n, void *arg) @@ -632,7 +636,7 @@ void print_vlan_info(struct rtattr *tb, int ifindex) int rem = RTA_PAYLOAD(list); __u16 last_vid_start = 0; - open_vlan_port(ifindex); + open_vlan_port(ifindex, "%s"); for (i = RTA_DATA(list); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) { struct bridge_vlan_info *vinfo; From 6f87b544ca9e632f6ed606db299e2d74b17be9b3 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 23 Apr 2019 09:16:12 +0200 Subject: [PATCH 4/8] iprule: avoid printing extra space after gateway for nat action For all other actions we avoid the trailing space, so do it here as well. Signed-off-by: Thomas Haller Signed-off-by: Stephen Hemminger --- ip/iprule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ip/iprule.c b/ip/iprule.c index 83aef38e..2479c3ab 100644 --- a/ip/iprule.c +++ b/ip/iprule.c @@ -443,7 +443,7 @@ int print_rule(struct nlmsghdr *n, void *arg) gateway = format_host_rta(frh->family, tb[RTA_GATEWAY]); print_string(PRINT_ANY, "nat_gateway", - "map-to %s ", gateway); + "map-to %s", gateway); } else { print_null(PRINT_ANY, "masquerade", "masquerade", NULL); } From 461f0405f331425069551173b127d3d0dba32315 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 23 Apr 2019 09:16:13 +0200 Subject: [PATCH 5/8] iprule: avoid trailing space in print_rule() after printing protocol It seems print_rule() tries to avoid a trailing space at the end of the line. At least, when printing details about the actions, they no longer append the space. Probably expecting to be the last attribute that will be printed. Don't let the protocol add the trailing space. The space at the end of the line should be printed consistently (or not). Signed-off-by: Thomas Haller Signed-off-by: Stephen Hemminger --- ip/iprule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ip/iprule.c b/ip/iprule.c index 2479c3ab..ce6b7cd3 100644 --- a/ip/iprule.c +++ b/ip/iprule.c @@ -468,7 +468,7 @@ int print_rule(struct nlmsghdr *n, void *arg) __u8 protocol = rta_getattr_u8(tb[FRA_PROTOCOL]); if ((protocol && protocol != RTPROT_KERNEL) || show_details > 0) { - print_string(PRINT_ANY, "protocol", " proto %s ", + print_string(PRINT_ANY, "protocol", " proto %s", rtnl_rtprot_n2a(protocol, b1, sizeof(b1))); } } From 927632d4da72bb0e2e9837975663d723082fb63e Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 23 Apr 2019 09:16:14 +0200 Subject: [PATCH 6/8] iprule: refactor print_rule() to use leading space before printing attribute When printing the actions, we avoid adding the trailing space after the attribute. Possibly because we expect the action to be the last output on the line and not end with a space. But for FR_ACT_TO_TBL nothing is printed. That means, we add double spaces if a protocol is printed as well: # ip rule add priority 10 protocol 10 type 1 will be printed as 10: from all lookup 1 proto mrt The only visible effect of the patch is to avoid the double-space and avoid a trailing space if the action is FR_ACT_TO_TBL. Signed-off-by: Thomas Haller Signed-off-by: Stephen Hemminger --- ip/iprule.c | 84 ++++++++++++++++++++++++++--------------------------- 1 file changed, 41 insertions(+), 43 deletions(-) diff --git a/ip/iprule.c b/ip/iprule.c index ce6b7cd3..b00ca7d1 100644 --- a/ip/iprule.c +++ b/ip/iprule.c @@ -273,34 +273,30 @@ int print_rule(struct nlmsghdr *n, void *arg) print_color_string(PRINT_ANY, ifa_family_color(frh->family), "src", "%s", src); if (frh->src_len != host_len) - print_uint(PRINT_ANY, "srclen", "/%u ", frh->src_len); - else - print_string(PRINT_FP, NULL, " ", NULL); + print_uint(PRINT_ANY, "srclen", "/%u", frh->src_len); } else if (frh->src_len) { print_string(PRINT_ANY, "src", "from %s", "0"); - print_uint(PRINT_ANY, "srclen", "/%u ", frh->src_len); + print_uint(PRINT_ANY, "srclen", "/%u", frh->src_len); } else { - print_string(PRINT_ANY, "src", "from %s ", "all"); + print_string(PRINT_ANY, "src", "from %s", "all"); } if (tb[FRA_DST]) { const char *dst = rt_addr_n2a_rta(frh->family, tb[FRA_DST]); - print_string(PRINT_FP, NULL, "to ", NULL); + print_string(PRINT_FP, NULL, " to ", NULL); print_color_string(PRINT_ANY, ifa_family_color(frh->family), "dst", "%s", dst); if (frh->dst_len != host_len) - print_uint(PRINT_ANY, "dstlen", "/%u ", frh->dst_len); - else - print_string(PRINT_FP, NULL, " ", NULL); + print_uint(PRINT_ANY, "dstlen", "/%u", frh->dst_len); } else if (frh->dst_len) { - print_string(PRINT_ANY, "dst", "to %s", "0"); - print_uint(PRINT_ANY, "dstlen", "/%u ", frh->dst_len); + print_string(PRINT_ANY, "dst", " to %s", "0"); + print_uint(PRINT_ANY, "dstlen", "/%u", frh->dst_len); } if (frh->tos) { print_string(PRINT_ANY, "tos", - "tos %s ", + " tos %s", rtnl_dsfield_n2a(frh->tos, b1, sizeof(b1))); } @@ -312,34 +308,34 @@ int print_rule(struct nlmsghdr *n, void *arg) if (tb[FRA_FWMASK] && (mask = rta_getattr_u32(tb[FRA_FWMASK])) != 0xFFFFFFFF) { - print_0xhex(PRINT_ANY, "fwmark", "fwmark %#llx", mark); - print_0xhex(PRINT_ANY, "fwmask", "/%#llx ", mask); + print_0xhex(PRINT_ANY, "fwmark", " fwmark %#llx", mark); + print_0xhex(PRINT_ANY, "fwmask", "/%#llx", mask); } else { - print_0xhex(PRINT_ANY, "fwmark", "fwmark %#llx ", mark); + print_0xhex(PRINT_ANY, "fwmark", " fwmark %#llx", mark); } } if (tb[FRA_IFNAME]) { if (!is_json_context()) - fprintf(fp, "iif "); + fprintf(fp, " iif "); print_color_string(PRINT_ANY, COLOR_IFNAME, - "iif", "%s ", + "iif", "%s", rta_getattr_str(tb[FRA_IFNAME])); if (frh->flags & FIB_RULE_IIF_DETACHED) - print_null(PRINT_ANY, "iif_detached", "[detached] ", + print_null(PRINT_ANY, "iif_detached", " [detached]", NULL); } if (tb[FRA_OIFNAME]) { if (!is_json_context()) - fprintf(fp, "oif "); + fprintf(fp, " oif "); - print_color_string(PRINT_ANY, COLOR_IFNAME, "oif", "%s ", + print_color_string(PRINT_ANY, COLOR_IFNAME, "oif", "%s", rta_getattr_str(tb[FRA_OIFNAME])); if (frh->flags & FIB_RULE_OIF_DETACHED) - print_null(PRINT_ANY, "oif_detached", "[detached] ", + print_null(PRINT_ANY, "oif_detached", " [detached]", NULL); } @@ -348,19 +344,19 @@ int print_rule(struct nlmsghdr *n, void *arg) if (mdev) print_null(PRINT_ANY, "l3mdev", - "lookup [l3mdev-table] ", NULL); + " lookup [l3mdev-table]", NULL); } if (tb[FRA_UID_RANGE]) { struct fib_rule_uid_range *r = RTA_DATA(tb[FRA_UID_RANGE]); - print_uint(PRINT_ANY, "uid_start", "uidrange %u", r->start); - print_uint(PRINT_ANY, "uid_end", "-%u ", r->end); + print_uint(PRINT_ANY, "uid_start", " uidrange %u", r->start); + print_uint(PRINT_ANY, "uid_end", "-%u", r->end); } if (tb[FRA_IP_PROTO]) { SPRINT_BUF(pbuf); - print_string(PRINT_ANY, "ipproto", "ipproto %s ", + print_string(PRINT_ANY, "ipproto", " ipproto %s", inet_proto_n2a(rta_getattr_u8(tb[FRA_IP_PROTO]), pbuf, sizeof(pbuf))); } @@ -369,11 +365,11 @@ int print_rule(struct nlmsghdr *n, void *arg) struct fib_rule_port_range *r = RTA_DATA(tb[FRA_SPORT_RANGE]); if (r->start == r->end) { - print_uint(PRINT_ANY, "sport", "sport %u ", r->start); + print_uint(PRINT_ANY, "sport", " sport %u", r->start); } else { - print_uint(PRINT_ANY, "sport_start", "sport %u", + print_uint(PRINT_ANY, "sport_start", " sport %u", r->start); - print_uint(PRINT_ANY, "sport_end", "-%u ", r->end); + print_uint(PRINT_ANY, "sport_end", "-%u", r->end); } } @@ -381,24 +377,24 @@ int print_rule(struct nlmsghdr *n, void *arg) struct fib_rule_port_range *r = RTA_DATA(tb[FRA_DPORT_RANGE]); if (r->start == r->end) { - print_uint(PRINT_ANY, "dport", "dport %u ", r->start); + print_uint(PRINT_ANY, "dport", " dport %u", r->start); } else { - print_uint(PRINT_ANY, "dport_start", "dport %u", + print_uint(PRINT_ANY, "dport_start", " dport %u", r->start); - print_uint(PRINT_ANY, "dport_end", "-%u ", r->end); + print_uint(PRINT_ANY, "dport_end", "-%u", r->end); } } if (tb[FRA_TUN_ID]) { __u64 tun_id = ntohll(rta_getattr_u64(tb[FRA_TUN_ID])); - print_u64(PRINT_ANY, "tun_id", "tun_id %llu ", tun_id); + print_u64(PRINT_ANY, "tun_id", " tun_id %llu", tun_id); } table = frh_get_table(frh, tb); if (table) { print_string(PRINT_ANY, "table", - "lookup %s ", + " lookup %s", rtnl_rttable_n2a(table, b1, sizeof(b1))); if (tb[FRA_SUPPRESS_PREFIXLEN]) { @@ -406,7 +402,7 @@ int print_rule(struct nlmsghdr *n, void *arg) if (pl != -1) print_int(PRINT_ANY, "suppress_prefixlen", - "suppress_prefixlength %d ", pl); + " suppress_prefixlength %d", pl); } if (tb[FRA_SUPPRESS_IFGROUP]) { @@ -417,7 +413,7 @@ int print_rule(struct nlmsghdr *n, void *arg) = rtnl_group_n2a(group, b1, sizeof(b1)); print_string(PRINT_ANY, "suppress_ifgroup", - "suppress_ifgroup %s ", grname); + " suppress_ifgroup %s", grname); } } } @@ -429,10 +425,12 @@ int print_rule(struct nlmsghdr *n, void *arg) to &= 0xFFFF; if (from) print_string(PRINT_ANY, - "flow_from", "realms %s/", + "flow_from", " realms %s/", rtnl_rtrealm_n2a(from, b1, sizeof(b1))); + else + print_string(PRINT_FP, NULL, " ", NULL); - print_string(PRINT_ANY, "flow_to", "%s ", + print_string(PRINT_ANY, "flow_to", "%s", rtnl_rtrealm_n2a(to, b1, sizeof(b1))); } @@ -443,24 +441,24 @@ int print_rule(struct nlmsghdr *n, void *arg) gateway = format_host_rta(frh->family, tb[RTA_GATEWAY]); print_string(PRINT_ANY, "nat_gateway", - "map-to %s", gateway); + " map-to %s", gateway); } else { - print_null(PRINT_ANY, "masquerade", "masquerade", NULL); + print_null(PRINT_ANY, "masquerade", " masquerade", NULL); } } else if (frh->action == FR_ACT_GOTO) { if (tb[FRA_GOTO]) - print_uint(PRINT_ANY, "goto", "goto %u", + print_uint(PRINT_ANY, "goto", " goto %u", rta_getattr_u32(tb[FRA_GOTO])); else - print_string(PRINT_ANY, "goto", "goto %s", "none"); + print_string(PRINT_ANY, "goto", " goto %s", "none"); if (frh->flags & FIB_RULE_UNRESOLVED) print_null(PRINT_ANY, "unresolved", " [unresolved]", NULL); } else if (frh->action == FR_ACT_NOP) { - print_null(PRINT_ANY, "nop", "nop", NULL); + print_null(PRINT_ANY, "nop", " nop", NULL); } else if (frh->action != FR_ACT_TO_TBL) { - print_string(PRINT_ANY, "action", "%s", + print_string(PRINT_ANY, "action", " %s", rtnl_rtntype_n2a(frh->action, b1, sizeof(b1))); } From 62de07faf7ecfbf867ce63e7e08bb624ad54137a Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 23 Apr 2019 09:16:15 +0200 Subject: [PATCH 7/8] iprule: always print realms keyword for rule # rule add priority 10 realms 1/0xF # rule add priority 10 realms 0/0xF # ip rule 10: from all lookup main 15 10: from all lookup main realms 1/15 The previous behavior was there since the beginning. Signed-off-by: Thomas Haller Signed-off-by: Stephen Hemminger --- ip/iprule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ip/iprule.c b/ip/iprule.c index b00ca7d1..9f5d998b 100644 --- a/ip/iprule.c +++ b/ip/iprule.c @@ -428,7 +428,7 @@ int print_rule(struct nlmsghdr *n, void *arg) "flow_from", " realms %s/", rtnl_rtrealm_n2a(from, b1, sizeof(b1))); else - print_string(PRINT_FP, NULL, " ", NULL); + print_string(PRINT_FP, NULL, " realms ", NULL); print_string(PRINT_ANY, "flow_to", "%s", rtnl_rtrealm_n2a(to, b1, sizeof(b1))); From 38983334f6d59318f40cda5cab771a92c2510695 Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Wed, 24 Apr 2019 15:08:31 -0700 Subject: [PATCH 8/8] tc/ematch: fix deprecated yacc warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Newer versions of Bison deprecated some directives. YACC emp_ematch.yacc.c emp_ematch.y:11.1-14: warning: deprecated directive, use ‘%define parse.error verbose’ [-Wdeprecated] %error-verbose ^~~~~~~~~~~~~~ emp_ematch.y:12.1-22: warning: deprecated directive, use ‘%define api.prefix {ematch_}’ [-Wdeprecated] %name-prefix "ematch_" Signed-off-by: Stephen Hemminger --- tc/emp_ematch.y | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tc/emp_ematch.y b/tc/emp_ematch.y index 2e6cf353..a02e831a 100644 --- a/tc/emp_ematch.y +++ b/tc/emp_ematch.y @@ -8,8 +8,8 @@ %locations %token-table -%error-verbose -%name-prefix "ematch_" +%define parse.error verbose +%define api.prefix {ematch_} %union { unsigned int i;