All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH iproute2] utils: also check AF_INET family when rtm_type is RTN_MULTICAST
@ 2017-07-27  9:01 Hangbin Liu
  2017-07-27  9:11 ` Phil Sutter
  2017-07-27  9:44 ` [PATCHv2 iproute2] utils: return default family when rtm_family is not RTNL_FAMILY_IPMR/IP6MR Hangbin Liu
  0 siblings, 2 replies; 5+ messages in thread
From: Hangbin Liu @ 2017-07-27  9:01 UTC (permalink / raw)
  To: netdev; +Cc: Nikolay Aleksandrov, Stephen Hemminger, 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")
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
---
 lib/utils.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/utils.c b/lib/utils.c
index e77bd30..0479e00 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -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;
 }
-- 
2.5.5

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH iproute2] utils: also check AF_INET family when rtm_type is RTN_MULTICAST
  2017-07-27  9:01 [PATCH iproute2] utils: also check AF_INET family when rtm_type is RTN_MULTICAST Hangbin Liu
@ 2017-07-27  9:11 ` Phil Sutter
  2017-07-27  9:44 ` [PATCHv2 iproute2] utils: return default family when rtm_family is not RTNL_FAMILY_IPMR/IP6MR Hangbin Liu
  1 sibling, 0 replies; 5+ messages in thread
From: Phil Sutter @ 2017-07-27  9:11 UTC (permalink / raw)
  To: Hangbin Liu; +Cc: netdev, Nikolay Aleksandrov, Stephen Hemminger

Hi Hangbin,

On Thu, Jul 27, 2017 at 05:01:49PM +0800, Hangbin Liu wrote:
[...]
> diff --git a/lib/utils.c b/lib/utils.c
> index e77bd30..0479e00 100644
> --- a/lib/utils.c
> +++ b/lib/utils.c
> @@ -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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCHv2 iproute2] utils: return default family when rtm_family is not RTNL_FAMILY_IPMR/IP6MR
  2017-07-27  9:01 [PATCH iproute2] utils: also check AF_INET family when rtm_type is RTN_MULTICAST Hangbin Liu
  2017-07-27  9:11 ` Phil Sutter
@ 2017-07-27  9:44 ` Hangbin Liu
  2017-07-27 10:03   ` Phil Sutter
  1 sibling, 1 reply; 5+ messages in thread
From: Hangbin Liu @ 2017-07-27  9:44 UTC (permalink / raw)
  To: netdev; +Cc: Nikolay Aleksandrov, Stephen Hemminger, Phil Sutter, 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")
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
---
 lib/utils.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/lib/utils.c b/lib/utils.c
index e77bd30..9aa3219 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -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;
 }
-- 
2.5.5

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCHv2 iproute2] utils: return default family when rtm_family is not RTNL_FAMILY_IPMR/IP6MR
  2017-07-27  9:44 ` [PATCHv2 iproute2] utils: return default family when rtm_family is not RTNL_FAMILY_IPMR/IP6MR Hangbin Liu
@ 2017-07-27 10:03   ` Phil Sutter
  2017-07-27 18:28     ` Stephen Hemminger
  0 siblings, 1 reply; 5+ messages in thread
From: Phil Sutter @ 2017-07-27 10:03 UTC (permalink / raw)
  To: Hangbin Liu; +Cc: netdev, Nikolay Aleksandrov, Stephen Hemminger

On Thu, Jul 27, 2017 at 05:44:15PM +0800, Hangbin Liu wrote:
> 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")
> Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>

Acked-by: Phil Sutter <phil@nwl.cc>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCHv2 iproute2] utils: return default family when rtm_family is not RTNL_FAMILY_IPMR/IP6MR
  2017-07-27 10:03   ` Phil Sutter
@ 2017-07-27 18:28     ` Stephen Hemminger
  0 siblings, 0 replies; 5+ messages in thread
From: Stephen Hemminger @ 2017-07-27 18:28 UTC (permalink / raw)
  To: Phil Sutter; +Cc: Hangbin Liu, netdev, Nikolay Aleksandrov

On Thu, 27 Jul 2017 12:03:02 +0200
Phil Sutter <phil@nwl.cc> wrote:

> On Thu, Jul 27, 2017 at 05:44:15PM +0800, Hangbin Liu wrote:
> > 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")
> > Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>  
> 
> Acked-by: Phil Sutter <phil@nwl.cc>

Applied, thanks.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-07-27 18:28 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-27  9:01 [PATCH iproute2] utils: also check AF_INET family when rtm_type is RTN_MULTICAST Hangbin Liu
2017-07-27  9:11 ` Phil Sutter
2017-07-27  9:44 ` [PATCHv2 iproute2] utils: return default family when rtm_family is not RTNL_FAMILY_IPMR/IP6MR Hangbin Liu
2017-07-27 10:03   ` Phil Sutter
2017-07-27 18:28     ` Stephen Hemminger

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.