From f900a21611c03e6d83104f2a862cd4c5f160d35f Mon Sep 17 00:00:00 2001 From: Peter Korsgaard Date: Sat, 27 Oct 2018 17:31:02 +0200 Subject: [PATCH 1/7] utils.h: provide fallback CLOCK_TAI definition q_{etf,taprio}.c uses CLOCK_TAI, which isn't exposed by glibc < 2.21 or uClibc, breaking the build. Provide a fallback definition like it is done for IPPROTO_MPLS and others. Signed-off-by: Peter Korsgaard Signed-off-by: Stephen Hemminger --- include/utils.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/utils.h b/include/utils.h index 258d630e..685d2c1d 100644 --- a/include/utils.h +++ b/include/utils.h @@ -126,6 +126,10 @@ struct ipx_addr { #define IPPROTO_MPLS 137 #endif +#ifndef CLOCK_TAI +# define CLOCK_TAI 11 +#endif + __u32 get_addr32(const char *name); int get_addr_1(inet_prefix *dst, const char *arg, int family); int get_prefix_1(inet_prefix *dst, char *arg, int family); From 45fca4ed94120a480cef70e8199083565f82bd51 Mon Sep 17 00:00:00 2001 From: Tobias Jungel Date: Fri, 26 Oct 2018 23:51:03 +0200 Subject: [PATCH 2/7] bridge: fix vlan show stats formatting The output of -statistics vlan show was broken previous change for json output. This aligns the format to vlan show. v2: fixed too greedy deletion that caused a -Wmaybe-uninitialized Signed-off-by: Tobias Jungel Signed-off-by: Stephen Hemminger --- bridge/vlan.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/bridge/vlan.c b/bridge/vlan.c index a111d5e6..d075a42d 100644 --- a/bridge/vlan.c +++ b/bridge/vlan.c @@ -484,7 +484,7 @@ static void print_vlan_stats_attr(struct rtattr *attr, int ifindex) rem = RTA_PAYLOAD(list); ifname = ll_index_to_name(ifindex); - open_json_object(ifname); + open_vlan_port(ifindex); print_color_string(PRINT_FP, COLOR_IFNAME, NULL, "%-16s", ifname); @@ -505,8 +505,7 @@ static void print_vlan_stats_attr(struct rtattr *attr, int ifindex) print_one_vlan_stats(vstats); } - close_json_object(); - + close_vlan_port(); } static int print_vlan_stats(struct nlmsghdr *n, void *arg) From 00240899ec0b0bb296ee54860802adec3be0d26e Mon Sep 17 00:00:00 2001 From: Stefano Brivio Date: Mon, 29 Oct 2018 23:04:25 +0100 Subject: [PATCH 3/7] ss: Actually print left delimiter for columns While rendering columns, we use a local variable to keep track of the field currently being printed, without touching current_field, which is used for buffering. Use the right pointer to access the left delimiter for the current column, instead of always printing the left delimiter for the last buffered field, which is usually an empty string. This fixes an issue especially visible on narrow terminals, where some columns might be displayed without separation. Reported-by: YoyPa Fixes: 691bd854bf4a ("ss: Buffer raw fields first, then render them as a table") Signed-off-by: Stefano Brivio Tested-by: YoyPa Signed-off-by: Stephen Hemminger --- misc/ss.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/misc/ss.c b/misc/ss.c index c8970438..4d12fb5d 100644 --- a/misc/ss.c +++ b/misc/ss.c @@ -1260,7 +1260,7 @@ static void render(void) while (token) { /* Print left delimiter only if we already started a line */ if (line_started++) - printed = printf("%s", current_field->ldelim); + printed = printf("%s", f->ldelim); else printed = 0; From 7a04dd84a7f938f72fcef9efe8383314b0a66274 Mon Sep 17 00:00:00 2001 From: Yonghong Song Date: Mon, 29 Oct 2018 15:32:03 -0700 Subject: [PATCH 4/7] bpf: check map symbol type properly with newer llvm compiler With llvm 7.0 or earlier, the map symbol type is STT_NOTYPE. -bash-4.4$ cat t.c __attribute__((section("maps"))) int g; -bash-4.4$ clang -target bpf -O2 -c t.c -bash-4.4$ readelf -s t.o Symbol table '.symtab' contains 2 entries: Num: Value Size Type Bind Vis Ndx Name 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND 1: 0000000000000000 0 NOTYPE GLOBAL DEFAULT 3 g The following llvm commit enables BPF target to generate proper symbol type and size. commit bf6ec206615b9718869d48b4e5400d0c6e3638dd Author: Yonghong Song Date: Wed Sep 19 16:04:13 2018 +0000 [bpf] Symbol sizes and types in object file Clang-compiled object files currently don't include the symbol sizes and types. Some tools however need that information. For example, ctfconvert uses that information to generate FreeBSD's CTF representation from ELF files. With this patch, symbol sizes and types are included in object files. Signed-off-by: Paul Chaignon Reported-by: Yutaro Hayakawa Hence, for llvm 8.0.0 (currently trunk), symbol type will be not NOTYPE, but OBJECT. -bash-4.4$ clang -target bpf -O2 -c t.c -bash-4.4$ readelf -s t.o Symbol table '.symtab' contains 3 entries: Num: Value Size Type Bind Vis Ndx Name 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND 1: 0000000000000000 0 FILE LOCAL DEFAULT ABS t.c 2: 0000000000000000 4 OBJECT GLOBAL DEFAULT 3 g This patch makes sure bpf library accepts both NOTYPE and OBJECT types of global map symbols. Signed-off-by: Yonghong Song Acked-by: Daniel Borkmann Signed-off-by: Stephen Hemminger --- lib/bpf.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/bpf.c b/lib/bpf.c index d093d0bd..45f279fa 100644 --- a/lib/bpf.c +++ b/lib/bpf.c @@ -1758,11 +1758,13 @@ static const char *bpf_map_fetch_name(struct bpf_elf_ctx *ctx, int which) int i; for (i = 0; i < ctx->sym_num; i++) { + int type = GELF_ST_TYPE(sym.st_info); + if (gelf_getsym(ctx->sym_tab, i, &sym) != &sym) continue; if (GELF_ST_BIND(sym.st_info) != STB_GLOBAL || - GELF_ST_TYPE(sym.st_info) != STT_NOTYPE || + (type != STT_NOTYPE && type != STT_OBJECT) || sym.st_shndx != ctx->sec_maps || sym.st_value / ctx->map_len != which) continue; @@ -1849,11 +1851,13 @@ static int bpf_map_num_sym(struct bpf_elf_ctx *ctx) GElf_Sym sym; for (i = 0; i < ctx->sym_num; i++) { + int type = GELF_ST_TYPE(sym.st_info); + if (gelf_getsym(ctx->sym_tab, i, &sym) != &sym) continue; if (GELF_ST_BIND(sym.st_info) != STB_GLOBAL || - GELF_ST_TYPE(sym.st_info) != STT_NOTYPE || + (type != STT_NOTYPE && type != STT_OBJECT) || sym.st_shndx != ctx->sec_maps) continue; num++; @@ -1927,10 +1931,12 @@ static int bpf_map_verify_all_offs(struct bpf_elf_ctx *ctx, int end) * the table again. */ for (i = 0; i < ctx->sym_num; i++) { + int type = GELF_ST_TYPE(sym.st_info); + if (gelf_getsym(ctx->sym_tab, i, &sym) != &sym) continue; if (GELF_ST_BIND(sym.st_info) != STB_GLOBAL || - GELF_ST_TYPE(sym.st_info) != STT_NOTYPE || + (type != STT_NOTYPE && type != STT_OBJECT) || sym.st_shndx != ctx->sec_maps) continue; if (sym.st_value == off) From 508f3c231efb179fb842d222e8151b395937b136 Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Wed, 31 Oct 2018 18:00:11 +0000 Subject: [PATCH 5/7] Use libbsd for strlcpy if available If libc does not provide strlcpy check for libbsd with pkg-config to avoid relying on inline version. Signed-off-by: Luca Boccassi Signed-off-by: Stephen Hemminger --- configure | 11 +++++++++-- genl/ctrl.c | 3 +++ ip/iplink.c | 3 +++ ip/ipnetns.c | 3 +++ ip/iproute_lwtunnel.c | 3 +++ ip/ipvrf.c | 3 +++ ip/ipxfrm.c | 3 +++ ip/tunnel.c | 3 +++ ip/xfrm_state.c | 3 +++ lib/bpf.c | 3 +++ lib/fs.c | 3 +++ lib/inet_proto.c | 3 +++ misc/ss.c | 3 +++ tc/em_ipset.c | 3 +++ tc/m_pedit.c | 3 +++ 15 files changed, 51 insertions(+), 2 deletions(-) diff --git a/configure b/configure index 744d6282..c5655978 100755 --- a/configure +++ b/configure @@ -330,8 +330,15 @@ EOF then echo "no" else - echo 'CFLAGS += -DNEED_STRLCPY' >>$CONFIG - echo "yes" + if ${PKG_CONFIG} libbsd --exists + then + echo 'CFLAGS += -DHAVE_LIBBSD' `${PKG_CONFIG} libbsd --cflags` >>$CONFIG + echo 'LDLIBS +=' `${PKG_CONFIG} libbsd --libs` >> $CONFIG + echo "no" + else + echo 'CFLAGS += -DNEED_STRLCPY' >>$CONFIG + echo "yes" + fi fi rm -f $TMPDIR/strtest.c $TMPDIR/strtest } diff --git a/genl/ctrl.c b/genl/ctrl.c index 6133336a..fef6aaa9 100644 --- a/genl/ctrl.c +++ b/genl/ctrl.c @@ -18,6 +18,9 @@ #include #include #include +#ifdef HAVE_LIBBSD +#include +#endif #include "utils.h" #include "genl_utils.h" diff --git a/ip/iplink.c b/ip/iplink.c index b5519201..067f5409 100644 --- a/ip/iplink.c +++ b/ip/iplink.c @@ -24,6 +24,9 @@ #include #include #include +#ifdef HAVE_LIBBSD +#include +#endif #include #include #include diff --git a/ip/ipnetns.c b/ip/ipnetns.c index 0eac18cf..da019d76 100644 --- a/ip/ipnetns.c +++ b/ip/ipnetns.c @@ -8,6 +8,9 @@ #include #include #include +#ifdef HAVE_LIBBSD +#include +#endif #include #include #include diff --git a/ip/iproute_lwtunnel.c b/ip/iproute_lwtunnel.c index 8f497015..2285bc1d 100644 --- a/ip/iproute_lwtunnel.c +++ b/ip/iproute_lwtunnel.c @@ -16,6 +16,9 @@ #include #include #include +#ifdef HAVE_LIBBSD +#include +#endif #include #include #include diff --git a/ip/ipvrf.c b/ip/ipvrf.c index 8a6b7f97..8572b4f2 100644 --- a/ip/ipvrf.c +++ b/ip/ipvrf.c @@ -21,6 +21,9 @@ #include #include #include +#ifdef HAVE_LIBBSD +#include +#endif #include #include #include diff --git a/ip/ipxfrm.c b/ip/ipxfrm.c index 17ab4abe..b02f30a6 100644 --- a/ip/ipxfrm.c +++ b/ip/ipxfrm.c @@ -28,6 +28,9 @@ #include #include #include +#ifdef HAVE_LIBBSD +#include +#endif #include #include #include diff --git a/ip/tunnel.c b/ip/tunnel.c index d0d55f37..73abb2e2 100644 --- a/ip/tunnel.c +++ b/ip/tunnel.c @@ -24,6 +24,9 @@ #include #include +#ifdef HAVE_LIBBSD +#include +#endif #include #include #include diff --git a/ip/xfrm_state.c b/ip/xfrm_state.c index e8c01746..18e0c6fa 100644 --- a/ip/xfrm_state.c +++ b/ip/xfrm_state.c @@ -27,6 +27,9 @@ #include #include #include +#ifdef HAVE_LIBBSD +#include +#endif #include #include "utils.h" #include "xfrm.h" diff --git a/lib/bpf.c b/lib/bpf.c index 45f279fa..35d7c45a 100644 --- a/lib/bpf.c +++ b/lib/bpf.c @@ -15,6 +15,9 @@ #include #include #include +#ifdef HAVE_LIBBSD +#include +#endif #include #include #include diff --git a/lib/fs.c b/lib/fs.c index 86efd4ed..af36bea0 100644 --- a/lib/fs.c +++ b/lib/fs.c @@ -20,6 +20,9 @@ #include #include #include +#ifdef HAVE_LIBBSD +#include +#endif #include #include diff --git a/lib/inet_proto.c b/lib/inet_proto.c index 0836a4c9..b379d8f8 100644 --- a/lib/inet_proto.c +++ b/lib/inet_proto.c @@ -18,6 +18,9 @@ #include #include #include +#ifdef HAVE_LIBBSD +#include +#endif #include "rt_names.h" #include "utils.h" diff --git a/misc/ss.c b/misc/ss.c index 4d12fb5d..c472fbd9 100644 --- a/misc/ss.c +++ b/misc/ss.c @@ -19,6 +19,9 @@ #include #include #include +#ifdef HAVE_LIBBSD +#include +#endif #include #include #include diff --git a/tc/em_ipset.c b/tc/em_ipset.c index 48b287f5..550b2101 100644 --- a/tc/em_ipset.c +++ b/tc/em_ipset.c @@ -20,6 +20,9 @@ #include #include #include +#ifdef HAVE_LIBBSD +#include +#endif #include #include diff --git a/tc/m_pedit.c b/tc/m_pedit.c index 2aeb56d9..baacc80d 100644 --- a/tc/m_pedit.c +++ b/tc/m_pedit.c @@ -23,6 +23,9 @@ #include #include #include +#ifdef HAVE_LIBBSD +#include +#endif #include #include "utils.h" #include "tc_util.h" From b65b4c0870ffc0ce0c110fea636b6267d098245b Mon Sep 17 00:00:00 2001 From: David Ahern Date: Tue, 30 Oct 2018 13:58:56 -0700 Subject: [PATCH 6/7] ip rule: Honor filter arguments on flush 'ip ru flush' currently removes all rules with priority > 0 regardless of any other command line arguments passed in. Update flush_rule to call filter_nlmsg to determine if the rule should be flushed or not. This enables rule flushing such as 'ip ru flush table 1001' and 'ip ru flush pref 99'. Signed-off-by: David Ahern Signed-off-by: Stephen Hemminger --- ip/iprule.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ip/iprule.c b/ip/iprule.c index d89d808d..74805b6c 100644 --- a/ip/iprule.c +++ b/ip/iprule.c @@ -461,6 +461,7 @@ static int flush_rule(struct nlmsghdr *n, void *arg) struct fib_rule_hdr *frh = NLMSG_DATA(n); int len = n->nlmsg_len; struct rtattr *tb[FRA_MAX+1]; + int host_len = -1; len -= NLMSG_LENGTH(sizeof(*frh)); if (len < 0) @@ -468,6 +469,10 @@ static int flush_rule(struct nlmsghdr *n, void *arg) parse_rtattr(tb, FRA_MAX, RTM_RTA(frh), len); + host_len = af_bit_len(frh->family); + if (!filter_nlmsg(n, tb, host_len)) + return 0; + if (tb[FRA_PROTOCOL]) { __u8 protocol = rta_getattr_u8(tb[FRA_PROTOCOL]); From 23801209261b92ce12c960f54ffbaa90d16a617f Mon Sep 17 00:00:00 2001 From: David Ahern Date: Tue, 30 Oct 2018 13:59:05 -0700 Subject: [PATCH 7/7] ip rule: Require at least one argument for add 'ip rule add' with no additional arguments just adds another rule for the main table - which exists by default. Require at least 1 argument similar to delete. Signed-off-by: David Ahern Signed-off-by: Stephen Hemminger --- ip/iprule.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ip/iprule.c b/ip/iprule.c index 74805b6c..a85a4390 100644 --- a/ip/iprule.c +++ b/ip/iprule.c @@ -696,6 +696,11 @@ static int iprule_modify(int cmd, int argc, char **argv) }; if (cmd == RTM_NEWRULE) { + if (argc == 0) { + fprintf(stderr, + "\"ip rule add\" requires arguments.\n"); + return -1; + } req.n.nlmsg_flags |= NLM_F_CREATE|NLM_F_EXCL; req.frh.action = FR_ACT_TO_TBL; }