From f15836faec6ed199624bf6d4dd055a85f88d160d Mon Sep 17 00:00:00 2001 From: Petr Vorel Date: Thu, 20 Sep 2018 01:36:22 +0200 Subject: [PATCH 1/9] testsuite: Fix missing generate_nlmsg Commit ad23e152 caused generate_nlmsg to be always missing: $ make alltests make: ./tools/generate_nlmsg: Command not found Create testclean: to remove only results directory. Fixes: ad23e152 testsuite: remove all temp files and implement make clean Signed-off-by: Petr Vorel Signed-off-by: Stephen Hemminger --- testsuite/Makefile | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/testsuite/Makefile b/testsuite/Makefile index d1ac997d..a31d4531 100644 --- a/testsuite/Makefile +++ b/testsuite/Makefile @@ -30,7 +30,6 @@ configure: compile: configure echo "Entering iproute2" && cd iproute2 && $(MAKE) && cd ..; - $(MAKE) -C tools listtests: @for t in $(TESTS); do \ @@ -39,9 +38,11 @@ listtests: alltests: $(TESTS) -clean: +testclean: @echo "Removing $(RESULTS_DIR) dir ..." @rm -rf $(RESULTS_DIR) + +clean: testclean @rm -f iproute2/iproute2-this @rm -f tests/ip/link/dev_wo_vf_rate.nl $(MAKE) -C tools clean @@ -49,18 +50,18 @@ clean: distclean: clean echo "Entering iproute2" && cd iproute2 && $(MAKE) distclean && cd ..; -$(TESTS): clean +$(TESTS): testclean ifeq (,$(HAVE_UNSHARED_UTIL)) $(error Please install util-linux tools to run tests in separated network namespace) endif @./tools/generate_nlmsg @mkdir -p $(RESULTS_DIR) - + @for d in $(TESTS_DIR); do \ mkdir -p $(RESULTS_DIR)/$$d; \ done - + @if [ "$(KCPATH)" = "/proc/config.gz" ]; then \ gunzip -c $(KCPATH) >$(KENVFN); \ elif [ "$(KCPATH)" != "" ]; then \ From 3537633dcf44dc4574e1abb8ec4cb8e25aeeb518 Mon Sep 17 00:00:00 2001 From: Petr Vorel Date: Thu, 20 Sep 2018 01:36:23 +0200 Subject: [PATCH 2/9] testsuite: Generate generate_nlmsg when needed Commit 886f2c43 added generate_nlmsg.c. Running alltests target, which uses the binary required to run 'make -C tools' before. Fixes: 886f2c43 testsuite: Generate nlmsg blob at runtime Signed-off-by: Petr Vorel Signed-off-by: Stephen Hemminger --- testsuite/Makefile | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/testsuite/Makefile b/testsuite/Makefile index a31d4531..1c2467f5 100644 --- a/testsuite/Makefile +++ b/testsuite/Makefile @@ -28,7 +28,7 @@ endif configure: echo "Entering iproute2" && cd iproute2 && $(MAKE) configure && cd ..; -compile: configure +compile: configure generate_nlmsg echo "Entering iproute2" && cd iproute2 && $(MAKE) && cd ..; listtests: @@ -36,7 +36,10 @@ listtests: echo "$$t"; \ done -alltests: $(TESTS) +generate_nlmsg: + $(MAKE) -C tools + +alltests: generate_nlmsg $(TESTS) testclean: @echo "Removing $(RESULTS_DIR) dir ..." From 133c1a6c8799d322a8a018bc49822c088bc5d5ac Mon Sep 17 00:00:00 2001 From: Petr Vorel Date: Thu, 20 Sep 2018 01:36:24 +0200 Subject: [PATCH 3/9] testsuite: Warn about empty $(IPVERS) alltests target requires having symlink created by configure target (default target). Without that there is no test being run. Signed-off-by: Petr Vorel Signed-off-by: Stephen Hemminger --- testsuite/Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/testsuite/Makefile b/testsuite/Makefile index 1c2467f5..b3aebec1 100644 --- a/testsuite/Makefile +++ b/testsuite/Makefile @@ -54,6 +54,9 @@ distclean: clean echo "Entering iproute2" && cd iproute2 && $(MAKE) distclean && cd ..; $(TESTS): testclean +ifeq (,$(IPVERS)) + $(error Please run make first) +endif ifeq (,$(HAVE_UNSHARED_UTIL)) $(error Please install util-linux tools to run tests in separated network namespace) endif From 11152f0a0dbfbeb3130e23d8ab7179f3aac58706 Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Fri, 21 Sep 2018 09:15:26 -0700 Subject: [PATCH 4/9] Makefile: add help target Add help target to Makefile Signed-off-by: Stephen Hemminger --- Makefile | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Makefile b/Makefile index ea2f797c..25de3893 100644 --- a/Makefile +++ b/Makefile @@ -71,6 +71,18 @@ all: config.mk for i in $(SUBDIRS); \ do echo; echo $$i; $(MAKE) $(MFLAGS) -C $$i; done +help: + @echo "Make Targets:" + @echo " all - build binaries" + @echo " clean - remove products of build" + @echo " distclean - remove configuration and build" + @echo " install - install binaries on local machine" + @echo " cscope - build cscope database" + @echo " snapshot - generate version number header" + @echo "" + @echo "Make Arguments:" + @echo " V=[0|1] - set build verbosity level" + config.mk: sh configure $(KERNEL_INCLUDE) From fa1e658e84ab267bb98955e44774831bb36f3861 Mon Sep 17 00:00:00 2001 From: Hangbin Liu Date: Tue, 18 Sep 2018 17:48:40 +0800 Subject: [PATCH 5/9] iplink: fix incorrect any address handling for ip tunnels After commit d42c7891d26e4 ("utils: Do not reset family for default, any, all addresses"), when call get_addr() for any/all addresses, we will set addr->flags to ADDRTYPE_INET_UNSPEC if family is AF_INET/AF_INET6, which makes is_addrtype_inet() checking passed and assigns incorrect address to kernel. The ip link cmd will return error like: ]# ip link add ipip1 type ipip local any remote 1.1.1.1 RTNETLINK answers: Numerical result out of range Fix it by using is_addrtype_inet_not_unspec() to avoid unspec addresses. geneve, vxlan are not affected as they use AF_UNSPEC family when call get_addr() Reported-by: Jianlin Shi Fixes: d42c7891d26e4 ("utils: Do not reset family for default, any, all addresses") Signed-off-by: Hangbin Liu Signed-off-by: Stephen Hemminger --- ip/link_gre.c | 4 ++-- ip/link_gre6.c | 4 ++-- ip/link_ip6tnl.c | 4 ++-- ip/link_iptnl.c | 4 ++-- ip/link_vti.c | 4 ++-- ip/link_vti6.c | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/ip/link_gre.c b/ip/link_gre.c index ede761b2..1ee7ee13 100644 --- a/ip/link_gre.c +++ b/ip/link_gre.c @@ -395,9 +395,9 @@ get_failed: addattr32(n, 1024, IFLA_GRE_OKEY, okey); addattr_l(n, 1024, IFLA_GRE_IFLAGS, &iflags, 2); addattr_l(n, 1024, IFLA_GRE_OFLAGS, &oflags, 2); - if (is_addrtype_inet(&saddr)) + if (is_addrtype_inet_not_unspec(&saddr)) addattr_l(n, 1024, IFLA_GRE_LOCAL, saddr.data, saddr.bytelen); - if (is_addrtype_inet(&daddr)) + if (is_addrtype_inet_not_unspec(&daddr)) addattr_l(n, 1024, IFLA_GRE_REMOTE, daddr.data, daddr.bytelen); addattr_l(n, 1024, IFLA_GRE_PMTUDISC, &pmtudisc, 1); if (ignore_df) diff --git a/ip/link_gre6.c b/ip/link_gre6.c index 181b2eae..20f93059 100644 --- a/ip/link_gre6.c +++ b/ip/link_gre6.c @@ -424,9 +424,9 @@ get_failed: addattr32(n, 1024, IFLA_GRE_OKEY, okey); addattr_l(n, 1024, IFLA_GRE_IFLAGS, &iflags, 2); addattr_l(n, 1024, IFLA_GRE_OFLAGS, &oflags, 2); - if (is_addrtype_inet(&saddr)) + if (is_addrtype_inet_not_unspec(&saddr)) addattr_l(n, 1024, IFLA_GRE_LOCAL, saddr.data, saddr.bytelen); - if (is_addrtype_inet(&daddr)) + if (is_addrtype_inet_not_unspec(&daddr)) addattr_l(n, 1024, IFLA_GRE_REMOTE, daddr.data, daddr.bytelen); if (link) addattr32(n, 1024, IFLA_GRE_LINK, link); diff --git a/ip/link_ip6tnl.c b/ip/link_ip6tnl.c index c7fef2e0..cfe2c5aa 100644 --- a/ip/link_ip6tnl.c +++ b/ip/link_ip6tnl.c @@ -320,11 +320,11 @@ get_failed: return 0; } - if (is_addrtype_inet(&saddr)) { + if (is_addrtype_inet_not_unspec(&saddr)) { addattr_l(n, 1024, IFLA_IPTUN_LOCAL, saddr.data, saddr.bytelen); } - if (is_addrtype_inet(&daddr)) { + if (is_addrtype_inet_not_unspec(&daddr)) { addattr_l(n, 1024, IFLA_IPTUN_REMOTE, daddr.data, daddr.bytelen); } diff --git a/ip/link_iptnl.c b/ip/link_iptnl.c index 57f4d0c7..7ec1594d 100644 --- a/ip/link_iptnl.c +++ b/ip/link_iptnl.c @@ -325,11 +325,11 @@ get_failed: return 0; } - if (is_addrtype_inet(&saddr)) { + if (is_addrtype_inet_not_unspec(&saddr)) { addattr_l(n, 1024, IFLA_IPTUN_LOCAL, saddr.data, saddr.bytelen); } - if (is_addrtype_inet(&daddr)) { + if (is_addrtype_inet_not_unspec(&daddr)) { addattr_l(n, 1024, IFLA_IPTUN_REMOTE, daddr.data, daddr.bytelen); } diff --git a/ip/link_vti.c b/ip/link_vti.c index 6196a1c9..3fff4417 100644 --- a/ip/link_vti.c +++ b/ip/link_vti.c @@ -157,9 +157,9 @@ get_failed: addattr32(n, 1024, IFLA_VTI_IKEY, ikey); addattr32(n, 1024, IFLA_VTI_OKEY, okey); - if (is_addrtype_inet(&saddr)) + if (is_addrtype_inet_not_unspec(&saddr)) addattr_l(n, 1024, IFLA_VTI_LOCAL, saddr.data, saddr.bytelen); - if (is_addrtype_inet(&daddr)) + if (is_addrtype_inet_not_unspec(&daddr)) addattr_l(n, 1024, IFLA_VTI_REMOTE, daddr.data, daddr.bytelen); addattr32(n, 1024, IFLA_VTI_FWMARK, fwmark); if (link) diff --git a/ip/link_vti6.c b/ip/link_vti6.c index 4263615b..f5a267a8 100644 --- a/ip/link_vti6.c +++ b/ip/link_vti6.c @@ -159,9 +159,9 @@ get_failed: addattr32(n, 1024, IFLA_VTI_IKEY, ikey); addattr32(n, 1024, IFLA_VTI_OKEY, okey); - if (is_addrtype_inet(&saddr)) + if (is_addrtype_inet_not_unspec(&saddr)) addattr_l(n, 1024, IFLA_VTI_LOCAL, saddr.data, saddr.bytelen); - if (is_addrtype_inet(&daddr)) + if (is_addrtype_inet_not_unspec(&daddr)) addattr_l(n, 1024, IFLA_VTI_REMOTE, daddr.data, daddr.bytelen); addattr32(n, 1024, IFLA_VTI_FWMARK, fwmark); if (link) From c1360e3b483e54a61a36bd2fdb3bfb91a4d2b32a Mon Sep 17 00:00:00 2001 From: Lorenzo Bianconi Date: Fri, 21 Sep 2018 15:34:25 +0200 Subject: [PATCH 6/9] iplink_vxlan: take into account preferred_family creating vxlan device Take into account the configured preferred_family if neither saddr or daddr are provided since otherwise vxlan kernel module will use IPv4 as default remote inet family neglecting the one provided by userspace. This behaviour was originally in commit 97d564b90ccb ("vxlan: use preferred address family when neither group or remote is specified"). The issue can be triggered with the following reproducer: $ip -6 link add vxlan1 type vxlan id 42 dev enp0s2 \ proxy nolearning l2miss l3miss $bridge fdb add 46:47:1f:a7:1c:25 dev vxlan1 dst 2000::2 RTNETLINK answers: Address family not supported by protocol Fixes: 1e9b8072de2c ("iplink_vxlan: Get rid of inet_get_addr()") Signed-off-by: Lorenzo Bianconi Signed-off-by: Stephen Hemminger --- ip/iplink_vxlan.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/ip/iplink_vxlan.c b/ip/iplink_vxlan.c index 2bc253fc..831f39a2 100644 --- a/ip/iplink_vxlan.c +++ b/ip/iplink_vxlan.c @@ -82,6 +82,7 @@ static int vxlan_parse_opt(struct link_util *lu, int argc, char **argv, __u64 attrs = 0; bool set_op = (n->nlmsg_type == RTM_NEWLINK && !(n->nlmsg_flags & NLM_F_CREATE)); + bool selected_family = false; saddr.family = daddr.family = AF_UNSPEC; @@ -356,12 +357,26 @@ static int vxlan_parse_opt(struct link_util *lu, int argc, char **argv, int type = (saddr.family == AF_INET) ? IFLA_VXLAN_LOCAL : IFLA_VXLAN_LOCAL6; addattr_l(n, 1024, type, saddr.data, saddr.bytelen); + selected_family = true; } if (is_addrtype_inet(&daddr)) { int type = (daddr.family == AF_INET) ? IFLA_VXLAN_GROUP : IFLA_VXLAN_GROUP6; addattr_l(n, 1024, type, daddr.data, daddr.bytelen); + selected_family = true; + } + + if (!selected_family) { + if (preferred_family == AF_INET) { + get_addr(&daddr, "default", AF_INET); + addattr_l(n, 1024, IFLA_VXLAN_GROUP, + daddr.data, daddr.bytelen); + } else if (preferred_family == AF_INET6) { + get_addr(&daddr, "default", AF_INET6); + addattr_l(n, 1024, IFLA_VXLAN_GROUP6, + daddr.data, daddr.bytelen); + } } if (!set_op || VXLAN_ATTRSET(attrs, IFLA_VXLAN_LEARNING)) From 8804a8c0d387c12155c5844fcc8290e1712dfbe9 Mon Sep 17 00:00:00 2001 From: Petr Vorel Date: Fri, 21 Sep 2018 22:29:16 +0200 Subject: [PATCH 7/9] Makefile: Add check target Signed-off-by: Petr Vorel Signed-off-by: Stephen Hemminger --- Makefile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Makefile b/Makefile index 25de3893..b7488add 100644 --- a/Makefile +++ b/Makefile @@ -77,6 +77,7 @@ help: @echo " clean - remove products of build" @echo " distclean - remove configuration and build" @echo " install - install binaries on local machine" + @echo " check - run tests" @echo " cscope - build cscope database" @echo " snapshot - generate version number header" @echo "" @@ -118,6 +119,9 @@ clobber: distclean: clobber +check: + cd testsuite && $(MAKE) && $(MAKE) alltests + cscope: cscope -b -q -R -Iinclude -sip -slib -smisc -snetem -stc From 5dc2204c01f566b88cdcdbfc31c826714040a31d Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Tue, 25 Sep 2018 09:59:37 +0200 Subject: [PATCH 8/9] testsuite: add libmnl Supporting external ack requires libmnl now. Signed-off-by: Stephen Hemminger --- testsuite/tools/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testsuite/tools/Makefile b/testsuite/tools/Makefile index c936af71..7d53d226 100644 --- a/testsuite/tools/Makefile +++ b/testsuite/tools/Makefile @@ -2,7 +2,7 @@ include ../../config.mk generate_nlmsg: generate_nlmsg.c ../../lib/libnetlink.c - $(CC) $(CPPFLAGS) $(CFLAGS) $(LDLIBS) $(EXTRA_CFLAGS) -I../../include -include../../include/uapi/linux/netlink.h -o $@ $^ + $(CC) $(CPPFLAGS) $(CFLAGS) $(LDLIBS) $(EXTRA_CFLAGS) -I../../include -include../../include/uapi/linux/netlink.h -o $@ $^ -lmnl clean: rm -f generate_nlmsg From b45e300024bb0936a41821ad75117dc08b65669f Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Tue, 25 Sep 2018 10:08:48 +0200 Subject: [PATCH 9/9] libnetlink: don't return error on success Change to error handling broke normal code. Fixes: c60389e4f9ea ("libnetlink: fix leak and using unused memory on error") Reported-by: David Ahern Signed-off-by: Stephen Hemminger --- lib/libnetlink.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/libnetlink.c b/lib/libnetlink.c index 58680929..f18dceac 100644 --- a/lib/libnetlink.c +++ b/lib/libnetlink.c @@ -666,17 +666,20 @@ static int __rtnl_talk_iov(struct rtnl_handle *rtnl, struct iovec *iov, if (!err->error) /* check messages from kernel */ nl_dump_ext_ack(h, errfn); + else { + errno = -err->error; - if (rtnl->proto != NETLINK_SOCK_DIAG && - show_rtnl_err) - rtnl_talk_error(h, err, errfn); + if (rtnl->proto != NETLINK_SOCK_DIAG && + show_rtnl_err) + rtnl_talk_error(h, err, errfn); + } - errno = -err->error; if (answer) *answer = (struct nlmsghdr *)buf; else free(buf); - return -i; + + return err->error ? -i : 0; } if (answer) {