Netdev List
 help / color / mirror / Atom feed
From: Hangbin Liu <liuhangbin@gmail.com>
To: netdev@vger.kernel.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
	David Ahern <dsahern@gmail.com>, Phil Sutter <phil@nwl.cc>,
	Serhey Popovych <serhe.popovych@gmail.com>,
	Hangbin Liu <liuhangbin@gmail.com>
Subject: [PATCH iproute2] iplink: fix incorrect any address handling for ip tunnels
Date: Tue, 18 Sep 2018 17:48:40 +0800	[thread overview]
Message-ID: <1537264120-31626-1-git-send-email-liuhangbin@gmail.com> (raw)

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 <jishi@redhat.com>
Fixes: d42c7891d26e4 ("utils: Do not reset family for default, any, all addresses")
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
---
 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 ede761b..1ee7ee1 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 181b2ea..20f9305 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 c7fef2e..cfe2c5a 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 57f4d0c..7ec1594 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 6196a1c..3fff441 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 4263615..f5a267a 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)
-- 
2.5.5

                 reply	other threads:[~2018-09-18 15:20 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1537264120-31626-1-git-send-email-liuhangbin@gmail.com \
    --to=liuhangbin@gmail.com \
    --cc=dsahern@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=phil@nwl.cc \
    --cc=serhe.popovych@gmail.com \
    --cc=stephen@networkplumber.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox