Skip to contentSkip to conversation

utils: also check AF_INET family when rtm_type is RTN_MULTICAST

PATCH In review Hangbin Liu 3 participants 5 messages Jul 27, 2017

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 utils: also check AF_INET family when rtm_type is RTN_MULTICAST

When we get a multicast route, the rtm_type is RTN_MULTICAST, but the rtm_family may be AF_INET. If we only check the type with RTNL_FAMILY_IPMR, we will get malformed address. e.g.

+ ip -4 route add multicast 172.111.1.1 dev em1 table main

Before fix:
+ ip route list type multicast table main multicast ac6f:101:800:400:400:0:3c00:0 dev em1 scope link

After fix:
+ ip route list type multicast table main
multicast 172.111.1.1 dev em1 scope link

Fixes 56e3eb4c3400 ("ip: route: fix multicast route dumps")
---
 lib/utils.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
lib/utils.c +2 -1
index e77bd30..0479e00 100644
@@ -1215,5 +1215,6 @@ int get_real_family(int rtm_type, int rtm_family)
 	if (rtm_type != RTN_MULTICAST)
 		return rtm_family;
 
-	return rtm_family == RTNL_FAMILY_IPMR ? AF_INET : AF_INET6;
+	return (rtm_family == RTNL_FAMILY_IPMR ||
+		rtm_family == AF_INET) ? AF_INET : AF_INET6;
 }
Signature · 1 line
2.5.5
#1 lore raw

Hi Hangbin,

On Thu, Jul 27, 2017 at 05:01:49PM +0800, Hangbin Liu wrote:
[...]

lib/utils.c int get_real_family(int rtm_type, int rtm_family) · line 1220

Quoted 12 lines
lib/utils.c +2 -1
index e77bd30..0479e00 100644
@@ -1215,5 +1215,6 @@ int get_real_family(int rtm_type, int rtm_family)
 	if (rtm_type != RTN_MULTICAST)
 		return rtm_family;
 
-	return rtm_family == RTNL_FAMILY_IPMR ? AF_INET : AF_INET6;
+	return (rtm_family == RTNL_FAMILY_IPMR ||
+		rtm_family == AF_INET) ? AF_INET : AF_INET6;
 }

I think this is not very readable. How about this instead:

- return rtm_family == RTNL_FAMILY_IPMR ? AF_INET : AF_INET6;
+ if (rtm_family == RTNL_FAMILY_IPMR)
+ return AF_INET;
+
+ return rtm_family;

Thanks, Phil

#2 lore raw

PATCH v2 1/1 utils: return default family when rtm_family is not RTNL_FAMILY_IPMR/IP6MR

In reply to Hangbin Liu

When we get a multicast route, the rtm_type is RTN_MULTICAST, but the rtm_family may be AF_INET. If we only check the type with RTNL_FAMILY_IPMR, we will get malformed address. e.g.

+ ip -4 route add multicast 172.111.1.1 dev em1 table main

Before fix:
+ ip route list type multicast table main multicast ac6f:101:800:400:400:0:3c00:0 dev em1 scope link

After fix:
+ ip route list type multicast table main
multicast 172.111.1.1 dev em1 scope link

Fixes 56e3eb4c3400 ("ip: route: fix multicast route dumps")
---
 lib/utils.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
lib/utils.c +7 -1
index e77bd30..9aa3219 100644
@@ -1215,5 +1215,11 @@ int get_real_family(int rtm_type, int rtm_family)
 	if (rtm_type != RTN_MULTICAST)
 		return rtm_family;
 
-	return rtm_family == RTNL_FAMILY_IPMR ? AF_INET : AF_INET6;
+	if (rtm_family == RTNL_FAMILY_IPMR)
+		return AF_INET;
+
+	if (rtm_family == RTNL_FAMILY_IP6MR)
+		return AF_INET6;
+
+	return rtm_family;
 }
Signature · 1 line
2.5.5
Acked-by on v2 1/1
#3 lore raw

Re: [PATCHv2 iproute2] utils: return default family when rtm_family is not RTNL_FAMILY_IPMR/IP6MR

Quoted 10 lines · Hangbin Liu

When we get a multicast route, the rtm_type is RTN_MULTICAST, but the rtm_family may be AF_INET. If we only check the type with RTNL_FAMILY_IPMR, we will get malformed address. e.g.

+ ip -4 route add multicast 172.111.1.1 dev em1 table main

Before fix:
+ ip route list type multicast table main multicast ac6f:101:800:400:400:0:3c00:0 dev em1 scope link

Quoted 6 lines

After fix:
+ ip route list type multicast table main
multicast 172.111.1.1 dev em1 scope link

Fixes 56e3eb4c3400 ("ip: route: fix multicast route dumps")
#4 lore raw

Re: [PATCHv2 iproute2] utils: return default family when rtm_family is not RTNL_FAMILY_IPMR/IP6MR

Quoted 11 lines · On Thu, 27 Jul 2017 12:03:02 +0200 Phil Sutter <[email protected]> wrote:
Quoted 10 lines · Hangbin Liu

When we get a multicast route, the rtm_type is RTN_MULTICAST, but the rtm_family may be AF_INET. If we only check the type with RTNL_FAMILY_IPMR, we will get malformed address. e.g.

+ ip -4 route add multicast 172.111.1.1 dev em1 table main

Before fix:
+ ip route list type multicast table main multicast ac6f:101:800:400:400:0:3c00:0 dev em1 scope link

Quoted 8 lines
Quoted 6 lines

After fix:
+ ip route list type multicast table main
multicast 172.111.1.1 dev em1 scope link

Fixes 56e3eb4c3400 ("ip: route: fix multicast route dumps")

Applied, thanks.