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

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: 56e3eb4c34 ("ip: route: fix multicast route dumps")
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
Acked-by: Phil Sutter <phil@nwl.cc>
This commit is contained in:
Hangbin Liu 2017-07-27 17:44:15 +08:00 committed by Stephen Hemminger
parent d3f0b09197
commit 5ce897a03b

View File

@ -1215,5 +1215,11 @@ int get_real_family(int rtm_type, int rtm_family)
if (rtm_type != RTN_MULTICAST) if (rtm_type != RTN_MULTICAST)
return rtm_family; 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;
} }