From b53835de386174a3423bd34b24a19ef01fa8a127 Mon Sep 17 00:00:00 2001 From: Serhey Popovych Date: Fri, 19 Jan 2018 18:44:00 +0200 Subject: [PATCH 1/5] tunnel: Add space between encap-dport and encap-sport in non-JSON output Fixes: bad76e6b1f44 ("ip/tunnel: Abstract tunnel encapsulation options printing") Fixes: e2d4588331fc ("ip: link_gre.c: add json output support") Signed-off-by: Serhey Popovych Signed-off-by: Stephen Hemminger --- ip/tunnel.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ip/tunnel.c b/ip/tunnel.c index 04148046..46c91024 100644 --- a/ip/tunnel.c +++ b/ip/tunnel.c @@ -201,11 +201,11 @@ static const char *tnl_encap_str(const char *name, int enabled, int port) const char *val; if (!port) { - val = "auto"; + val = "auto "; } else if (port < 0) { val = ""; } else { - snprintf(b1, sizeof(b1), "%u", port - 1); + snprintf(b1, sizeof(b1), "%u ", port - 1); val = b1; } From c4743c4d9b73a1d2f4253d27ea6ef20fe7c53a6d Mon Sep 17 00:00:00 2001 From: Serhey Popovych Date: Fri, 19 Jan 2018 18:44:01 +0200 Subject: [PATCH 2/5] iptnl/ip6tnl: Unify ttl/hoplimit parsing routines Handle "inherit" case properly for gre6 and ip6tnl. Use get_u8() in gre to parse ttl/hoplimit. Be consistent about "hlim" alias to ttl/hoplimit support. Signed-off-by: Serhey Popovych Signed-off-by: Stephen Hemminger --- ip/link_gre.c | 10 +++------- ip/link_gre6.c | 13 +++++++------ ip/link_ip6tnl.c | 14 +++++++------- ip/link_iptnl.c | 3 ++- 4 files changed, 19 insertions(+), 21 deletions(-) diff --git a/ip/link_gre.c b/ip/link_gre.c index 6254e887..009ddfc7 100644 --- a/ip/link_gre.c +++ b/ip/link_gre.c @@ -229,16 +229,12 @@ get_failed: exit(-1); } } else if (!matches(*argv, "ttl") || - !matches(*argv, "hoplimit")) { - unsigned int uval; - + !matches(*argv, "hoplimit") || + !matches(*argv, "hlim")) { NEXT_ARG(); if (strcmp(*argv, "inherit") != 0) { - if (get_unsigned(&uval, *argv, 0)) + if (get_u8(&ttl, *argv, 0)) invarg("invalid TTL\n", *argv); - if (uval > 255) - invarg("TTL must be <= 255\n", *argv); - ttl = uval; } else ttl = 0; } else if (!matches(*argv, "tos") || diff --git a/ip/link_gre6.c b/ip/link_gre6.c index 29ca3d13..3d02e167 100644 --- a/ip/link_gre6.c +++ b/ip/link_gre6.c @@ -238,13 +238,14 @@ get_failed: exit(-1); } } else if (!matches(*argv, "ttl") || - !matches(*argv, "hoplimit")) { - __u8 uval; - + !matches(*argv, "hoplimit") || + !matches(*argv, "hlim")) { NEXT_ARG(); - if (get_u8(&uval, *argv, 0)) - invarg("invalid TTL", *argv); - hop_limit = uval; + if (strcmp(*argv, "inherit") != 0) { + if (get_u8(&hop_limit, *argv, 0)) + invarg("invalid HLIM\n", *argv); + } else + hop_limit = 0; } else if (!matches(*argv, "tos") || !matches(*argv, "tclass") || !matches(*argv, "dsfield")) { diff --git a/ip/link_ip6tnl.c b/ip/link_ip6tnl.c index 8f5c9bd7..f6c52acc 100644 --- a/ip/link_ip6tnl.c +++ b/ip/link_ip6tnl.c @@ -196,15 +196,15 @@ get_failed: link = if_nametoindex(*argv); if (link == 0) invarg("\"dev\" is invalid", *argv); - } else if (strcmp(*argv, "hoplimit") == 0 || - strcmp(*argv, "ttl") == 0 || + } else if (strcmp(*argv, "ttl") == 0 || + strcmp(*argv, "hoplimit") == 0 || strcmp(*argv, "hlim") == 0) { - __u8 uval; - NEXT_ARG(); - if (get_u8(&uval, *argv, 0)) - invarg("invalid HLIM", *argv); - hop_limit = uval; + if (strcmp(*argv, "inherit") != 0) { + if (get_u8(&hop_limit, *argv, 0)) + invarg("invalid HLIM\n", *argv); + } else + hop_limit = 0; } else if (strcmp(*argv, "encaplimit") == 0) { NEXT_ARG(); if (strcmp(*argv, "none") == 0) { diff --git a/ip/link_iptnl.c b/ip/link_iptnl.c index ce3855c1..a6213d28 100644 --- a/ip/link_iptnl.c +++ b/ip/link_iptnl.c @@ -204,7 +204,8 @@ get_failed: if (link == 0) invarg("\"dev\" is invalid", *argv); } else if (strcmp(*argv, "ttl") == 0 || - strcmp(*argv, "hoplimit") == 0) { + strcmp(*argv, "hoplimit") == 0 || + strcmp(*argv, "hlim") == 0) { NEXT_ARG(); if (strcmp(*argv, "inherit") != 0) { if (get_u8(&ttl, *argv, 0)) From 9dc04a4fd2f950908db48bf1f39cd9c581c46443 Mon Sep 17 00:00:00 2001 From: Serhey Popovych Date: Fri, 19 Jan 2018 18:44:02 +0200 Subject: [PATCH 3/5] vti/vti6: Minor improvements In prepare of link_vti.c and link_vti6.c merge: 1) Make @fwmark of __u32 type instead of unsigned int in vti to match with rest tunneling code. 2) Report when unable to translate @link network device name to index instead of silently exiting in vti6. 3) Remove newline separating local/remote attributes from the ikey/okey in vti6 to match vti module. Signed-off-by: Serhey Popovych Signed-off-by: Stephen Hemminger --- ip/link_vti.c | 2 +- ip/link_vti6.c | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/ip/link_vti.c b/ip/link_vti.c index 1439e53c..6a088c6f 100644 --- a/ip/link_vti.c +++ b/ip/link_vti.c @@ -69,7 +69,7 @@ static int vti_parse_opt(struct link_util *lu, int argc, char **argv, unsigned int saddr = 0; unsigned int daddr = 0; unsigned int link = 0; - unsigned int fwmark = 0; + __u32 fwmark = 0; int len; if (!(n->nlmsg_flags & NLM_F_CREATE)) { diff --git a/ip/link_vti6.c b/ip/link_vti6.c index 2a86d592..a11f389c 100644 --- a/ip/link_vti6.c +++ b/ip/link_vti6.c @@ -144,8 +144,11 @@ get_failed: } else if (!matches(*argv, "dev")) { NEXT_ARG(); link = if_nametoindex(*argv); - if (link == 0) + if (link == 0) { + fprintf(stderr, "Cannot find device \"%s\"\n", + *argv); exit(-1); + } } else if (strcmp(*argv, "fwmark") == 0) { NEXT_ARG(); if (get_u32(&fwmark, *argv, 0)) @@ -157,7 +160,6 @@ get_failed: addattr32(n, 1024, IFLA_VTI_IKEY, ikey); addattr32(n, 1024, IFLA_VTI_OKEY, okey); - addattr_l(n, 1024, IFLA_VTI_LOCAL, &saddr, sizeof(saddr)); addattr_l(n, 1024, IFLA_VTI_REMOTE, &daddr, sizeof(daddr)); addattr32(n, 1024, IFLA_VTI_FWMARK, fwmark); From 7a14358b16992d4923464ca43056d68bf6a496b8 Mon Sep 17 00:00:00 2001 From: Serhey Popovych Date: Fri, 19 Jan 2018 18:44:03 +0200 Subject: [PATCH 4/5] iplink: Use ll_name_to_index() instead of if_nametoindex() While benefit from using ll_name_to_index() with populated cache can potentially be exploited only in few places (e.g. bridge fdb/mdb/vlan show routines) there is another advantage of ll_name_to_index() over plain if_nametoindex(): in case of if_nametoindex() failure ll_name_to_index() will attempt to get index from common name in form "if%d" that may be returned from ll_index_to_name(). This makes output from ip(8) coherent with it's input. Note that most of the code already switched from plain if_nametoindex() to ll_name_to_index() to cached variant. Signed-off-by: Serhey Popovych Signed-off-by: Stephen Hemminger --- bridge/fdb.c | 4 ++-- bridge/mdb.c | 2 +- bridge/vlan.c | 2 +- ip/iplink_bond.c | 4 ++-- ip/iplink_bridge.c | 2 +- ip/iplink_vxlan.c | 2 +- ip/iproute_lwtunnel.c | 4 ++-- ip/link_gre.c | 2 +- ip/link_gre6.c | 2 +- ip/link_ip6tnl.c | 2 +- ip/link_iptnl.c | 2 +- ip/link_vti.c | 2 +- ip/link_vti6.c | 2 +- 13 files changed, 16 insertions(+), 16 deletions(-) diff --git a/bridge/fdb.c b/bridge/fdb.c index 4d55fb04..8b133f9c 100644 --- a/bridge/fdb.c +++ b/bridge/fdb.c @@ -374,7 +374,7 @@ static int fdb_show(int argc, char **argv) /*we'll keep around filter_dev for older kernels */ if (filter_dev) { - filter_index = if_nametoindex(filter_dev); + filter_index = ll_name_to_index(filter_dev); if (filter_index == 0) { fprintf(stderr, "Cannot find device \"%s\"\n", filter_dev); @@ -463,7 +463,7 @@ static int fdb_modify(int cmd, int flags, int argc, char **argv) invarg("invalid VNI\n", *argv); } else if (strcmp(*argv, "via") == 0) { NEXT_ARG(); - via = if_nametoindex(*argv); + via = ll_name_to_index(*argv); if (via == 0) invarg("invalid device\n", *argv); } else if (strcmp(*argv, "self") == 0) { diff --git a/bridge/mdb.c b/bridge/mdb.c index 7b7b81f4..62dc8a0c 100644 --- a/bridge/mdb.c +++ b/bridge/mdb.c @@ -311,7 +311,7 @@ static int mdb_show(int argc, char **argv) } if (filter_dev) { - filter_index = if_nametoindex(filter_dev); + filter_index = ll_name_to_index(filter_dev); if (filter_index == 0) { fprintf(stderr, "Cannot find device \"%s\"\n", filter_dev); diff --git a/bridge/vlan.c b/bridge/vlan.c index 69fb5425..f42d7e6b 100644 --- a/bridge/vlan.c +++ b/bridge/vlan.c @@ -567,7 +567,7 @@ static int vlan_show(int argc, char **argv) } if (filter_dev) { - filter_index = if_nametoindex(filter_dev); + filter_index = ll_name_to_index(filter_dev); if (filter_index == 0) { fprintf(stderr, "Cannot find device \"%s\"\n", filter_dev); diff --git a/ip/iplink_bond.c b/ip/iplink_bond.c index f01fd8da..8e8723a9 100644 --- a/ip/iplink_bond.c +++ b/ip/iplink_bond.c @@ -177,7 +177,7 @@ static int bond_parse_opt(struct link_util *lu, int argc, char **argv, addattr8(n, 1024, IFLA_BOND_MODE, mode); } else if (matches(*argv, "active_slave") == 0) { NEXT_ARG(); - ifindex = if_nametoindex(*argv); + ifindex = ll_name_to_index(*argv); if (!ifindex) return -1; addattr32(n, 1024, IFLA_BOND_ACTIVE_SLAVE, ifindex); @@ -240,7 +240,7 @@ static int bond_parse_opt(struct link_util *lu, int argc, char **argv, addattr32(n, 1024, IFLA_BOND_ARP_ALL_TARGETS, arp_all_targets); } else if (matches(*argv, "primary") == 0) { NEXT_ARG(); - ifindex = if_nametoindex(*argv); + ifindex = ll_name_to_index(*argv); if (!ifindex) return -1; addattr32(n, 1024, IFLA_BOND_PRIMARY, ifindex); diff --git a/ip/iplink_bridge.c b/ip/iplink_bridge.c index d3250980..06ec092f 100644 --- a/ip/iplink_bridge.c +++ b/ip/iplink_bridge.c @@ -792,7 +792,7 @@ int bridge_parse_xstats(struct link_util *lu, int argc, char **argv) xstats_print_attr = BRIDGE_XSTATS_MCAST; } else if (strcmp(*argv, "dev") == 0) { NEXT_ARG(); - filter_index = if_nametoindex(*argv); + filter_index = ll_name_to_index(*argv); if (filter_index == 0) { fprintf(stderr, "Cannot find device \"%s\"\n", *argv); diff --git a/ip/iplink_vxlan.c b/ip/iplink_vxlan.c index 88b56625..7ea908e6 100644 --- a/ip/iplink_vxlan.c +++ b/ip/iplink_vxlan.c @@ -151,7 +151,7 @@ static int vxlan_parse_opt(struct link_util *lu, int argc, char **argv, NEXT_ARG(); check_duparg(&attrs, IFLA_VXLAN_LINK, "dev", *argv); - link = if_nametoindex(*argv); + link = ll_name_to_index(*argv); if (link == 0) { fprintf(stderr, "Cannot find device \"%s\"\n", *argv); diff --git a/ip/iproute_lwtunnel.c b/ip/iproute_lwtunnel.c index a1d36ba2..da6ebb8e 100644 --- a/ip/iproute_lwtunnel.c +++ b/ip/iproute_lwtunnel.c @@ -556,7 +556,7 @@ static int parse_encap_seg6local(struct rtattr *rta, size_t len, int *argcp, NEXT_ARG(); if (iif_ok++) duparg2("iif", *argv); - iif = if_nametoindex(*argv); + iif = ll_name_to_index(*argv); if (!iif) invarg("\"iif\" interface not found\n", *argv); rta_addattr32(rta, len, SEG6_LOCAL_IIF, iif); @@ -564,7 +564,7 @@ static int parse_encap_seg6local(struct rtattr *rta, size_t len, int *argcp, NEXT_ARG(); if (oif_ok++) duparg2("oif", *argv); - oif = if_nametoindex(*argv); + oif = ll_name_to_index(*argv); if (!oif) invarg("\"oif\" interface not found\n", *argv); rta_addattr32(rta, len, SEG6_LOCAL_OIF, oif); diff --git a/ip/link_gre.c b/ip/link_gre.c index 009ddfc7..512695d8 100644 --- a/ip/link_gre.c +++ b/ip/link_gre.c @@ -222,7 +222,7 @@ get_failed: saddr = get_addr32(*argv); } else if (!matches(*argv, "dev")) { NEXT_ARG(); - link = if_nametoindex(*argv); + link = ll_name_to_index(*argv); if (link == 0) { fprintf(stderr, "Cannot find device \"%s\"\n", *argv); diff --git a/ip/link_gre6.c b/ip/link_gre6.c index 3d02e167..29846cf1 100644 --- a/ip/link_gre6.c +++ b/ip/link_gre6.c @@ -231,7 +231,7 @@ get_failed: memcpy(&laddr, &addr.data, sizeof(laddr)); } else if (!matches(*argv, "dev")) { NEXT_ARG(); - link = if_nametoindex(*argv); + link = ll_name_to_index(*argv); if (link == 0) { fprintf(stderr, "Cannot find device \"%s\"\n", *argv); diff --git a/ip/link_ip6tnl.c b/ip/link_ip6tnl.c index f6c52acc..fdf113e0 100644 --- a/ip/link_ip6tnl.c +++ b/ip/link_ip6tnl.c @@ -193,7 +193,7 @@ get_failed: memcpy(&laddr, addr.data, sizeof(laddr)); } else if (matches(*argv, "dev") == 0) { NEXT_ARG(); - link = if_nametoindex(*argv); + link = ll_name_to_index(*argv); if (link == 0) invarg("\"dev\" is invalid", *argv); } else if (strcmp(*argv, "ttl") == 0 || diff --git a/ip/link_iptnl.c b/ip/link_iptnl.c index a6213d28..96048e2e 100644 --- a/ip/link_iptnl.c +++ b/ip/link_iptnl.c @@ -200,7 +200,7 @@ get_failed: laddr = get_addr32(*argv); } else if (matches(*argv, "dev") == 0) { NEXT_ARG(); - link = if_nametoindex(*argv); + link = ll_name_to_index(*argv); if (link == 0) invarg("\"dev\" is invalid", *argv); } else if (strcmp(*argv, "ttl") == 0 || diff --git a/ip/link_vti.c b/ip/link_vti.c index 6a088c6f..f1a11234 100644 --- a/ip/link_vti.c +++ b/ip/link_vti.c @@ -137,7 +137,7 @@ get_failed: saddr = get_addr32(*argv); } else if (!matches(*argv, "dev")) { NEXT_ARG(); - link = if_nametoindex(*argv); + link = ll_name_to_index(*argv); if (link == 0) { fprintf(stderr, "Cannot find device \"%s\"\n", *argv); diff --git a/ip/link_vti6.c b/ip/link_vti6.c index a11f389c..c394dbca 100644 --- a/ip/link_vti6.c +++ b/ip/link_vti6.c @@ -143,7 +143,7 @@ get_failed: memcpy(&saddr, addr.data, sizeof(saddr)); } else if (!matches(*argv, "dev")) { NEXT_ARG(); - link = if_nametoindex(*argv); + link = ll_name_to_index(*argv); if (link == 0) { fprintf(stderr, "Cannot find device \"%s\"\n", *argv); From 7ac29190dbbc03ee2e60406ba8c584ac3c18c6c9 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Mon, 22 Jan 2018 11:53:46 +0100 Subject: [PATCH 5/5] tc/lexer: let quotes actually start strings The lexer will go with the longest match, so previously the starting double quotes of a string would be swallowed by the [^ \t\r\n()]+ pattern leaving the user no way to actually use strings with escape sequences. Fix this by not allowing this case to start with double quotes. Signed-off-by: Wolfgang Bumiller --- tc/emp_ematch.l | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tc/emp_ematch.l b/tc/emp_ematch.l index dc106759..d7a99304 100644 --- a/tc/emp_ematch.l +++ b/tc/emp_ematch.l @@ -137,7 +137,7 @@ ")" { return yylval.i = *yytext; } -[^ \t\r\n()]+ { +[^" \t\r\n()][^ \t\r\n()]* { yylval.b = bstr_alloc(yytext); if (yylval.b == NULL) return ERROR;