iplink: fix incorrect any address handling for ip tunnels
Subsystems (2)
PATCH 1/1 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 <[email protected]>
Fixes d42c7891d26e4 ("utils: Do not reset family for default, any, all addresses")
Signed-off-by Hangbin Liu <[email protected]>
--- 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(-)
ip/link_gre.c +2 -2
@@ -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)
ip/link_gre6.c +2 -2
@@ -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);
ip/link_ip6tnl.c +2 -2
@@ -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); }
ip/link_iptnl.c +2 -2
@@ -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); }
ip/link_vti.c +2 -2
@@ -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)
ip/link_vti6.c +2 -2
@@ -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)
Signature · 1 line
2.5.5