diff --git a/Makefile b/Makefile index ea2f797c..b7488add 100644 --- a/Makefile +++ b/Makefile @@ -71,6 +71,19 @@ 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 " check - run tests" + @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) @@ -106,6 +119,9 @@ clobber: distclean: clobber +check: + cd testsuite && $(MAKE) && $(MAKE) alltests + cscope: cscope -b -q -R -Iinclude -sip -slib -smisc -snetem -stc 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)) 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) 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) { diff --git a/testsuite/Makefile b/testsuite/Makefile index d1ac997d..b3aebec1 100644 --- a/testsuite/Makefile +++ b/testsuite/Makefile @@ -28,20 +28,24 @@ endif configure: echo "Entering iproute2" && cd iproute2 && $(MAKE) configure && cd ..; -compile: configure +compile: configure generate_nlmsg echo "Entering iproute2" && cd iproute2 && $(MAKE) && cd ..; - $(MAKE) -C tools listtests: @for t in $(TESTS); do \ echo "$$t"; \ done -alltests: $(TESTS) +generate_nlmsg: + $(MAKE) -C tools -clean: +alltests: generate_nlmsg $(TESTS) + +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 +53,21 @@ clean: distclean: clean echo "Entering iproute2" && cd iproute2 && $(MAKE) distclean && cd ..; -$(TESTS): clean +$(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 @./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 \ 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