netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH iproute2] ip/iptoken: fix dump error when ipv6 disabled
@ 2019-06-25  9:35 Hangbin Liu
  2019-06-25 20:11 ` Stephen Hemminger
  2019-06-26  1:44 ` [PATCHv2 " Hangbin Liu
  0 siblings, 2 replies; 3+ messages in thread
From: Hangbin Liu @ 2019-06-25  9:35 UTC (permalink / raw)
  To: netdev
  Cc: Daniel Borkmann, Phil Sutter, Stephen Hemminger, David Ahern,
	Andrea Claudi, Hangbin Liu

When we disable IPv6 from the start up (ipv6.disable=1), there will be
no IPv6 route info in the dump message. If we return -1 when
ifi->ifi_family != AF_INET6, we will get error like

$ ip token list
Dump terminated

which will make user feel confused. There is no need to return -1 if the
dump message not match. Return 0 is enough.

Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
---
 ip/iptoken.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/ip/iptoken.c b/ip/iptoken.c
index f1194c3e..dfd22734 100644
--- a/ip/iptoken.c
+++ b/ip/iptoken.c
@@ -59,13 +59,9 @@ static int print_token(struct nlmsghdr *n, void *arg)
 	if (len < 0)
 		return -1;
 
-	if (ifi->ifi_family != AF_INET6)
-		return -1;
-	if (ifi->ifi_index == 0)
-		return -1;
-	if (ifindex > 0 && ifi->ifi_index != ifindex)
-		return 0;
-	if (ifi->ifi_flags & (IFF_LOOPBACK | IFF_NOARP))
+	if (ifi->ifi_family != AF_INET6 || ifi->ifi_index == 0 ||
+	    (ifindex > 0 && ifi->ifi_index != ifindex) ||
+	    (ifi->ifi_flags & (IFF_LOOPBACK | IFF_NOARP)))
 		return 0;
 
 	parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), len);
-- 
2.19.2


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

* Re: [PATCH iproute2] ip/iptoken: fix dump error when ipv6 disabled
  2019-06-25  9:35 [PATCH iproute2] ip/iptoken: fix dump error when ipv6 disabled Hangbin Liu
@ 2019-06-25 20:11 ` Stephen Hemminger
  2019-06-26  1:44 ` [PATCHv2 " Hangbin Liu
  1 sibling, 0 replies; 3+ messages in thread
From: Stephen Hemminger @ 2019-06-25 20:11 UTC (permalink / raw)
  To: Hangbin Liu
  Cc: netdev, Daniel Borkmann, Phil Sutter, David Ahern, Andrea Claudi

On Tue, 25 Jun 2019 17:35:50 +0800
Hangbin Liu <liuhangbin@gmail.com> wrote:

> When we disable IPv6 from the start up (ipv6.disable=1), there will be
> no IPv6 route info in the dump message. If we return -1 when
> ifi->ifi_family != AF_INET6, we will get error like
> 
> $ ip token list
> Dump terminated
> 
> which will make user feel confused. There is no need to return -1 if the
> dump message not match. Return 0 is enough.
> 
> Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
> ---
>  ip/iptoken.c | 10 +++-------
>  1 file changed, 3 insertions(+), 7 deletions(-)
> 
> diff --git a/ip/iptoken.c b/ip/iptoken.c
> index f1194c3e..dfd22734 100644
> --- a/ip/iptoken.c
> +++ b/ip/iptoken.c
> @@ -59,13 +59,9 @@ static int print_token(struct nlmsghdr *n, void *arg)
>  	if (len < 0)
>  		return -1;
>  
> -	if (ifi->ifi_family != AF_INET6)
> -		return -1;
> -	if (ifi->ifi_index == 0)
> -		return -1;
> -	if (ifindex > 0 && ifi->ifi_index != ifindex)
> -		return 0;
> -	if (ifi->ifi_flags & (IFF_LOOPBACK | IFF_NOARP))
> +	if (ifi->ifi_family != AF_INET6 || ifi->ifi_index == 0 ||
> +	    (ifindex > 0 && ifi->ifi_index != ifindex) ||
> +	    (ifi->ifi_flags & (IFF_LOOPBACK | IFF_NOARP)))
>  		return 0;

Please don't combine all the conditions, it is simpler as:

	if (ifi->ifi_family != AF_INET6)
		return 0;

	

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

* [PATCHv2 iproute2] ip/iptoken: fix dump error when ipv6 disabled
  2019-06-25  9:35 [PATCH iproute2] ip/iptoken: fix dump error when ipv6 disabled Hangbin Liu
  2019-06-25 20:11 ` Stephen Hemminger
@ 2019-06-26  1:44 ` Hangbin Liu
  1 sibling, 0 replies; 3+ messages in thread
From: Hangbin Liu @ 2019-06-26  1:44 UTC (permalink / raw)
  To: netdev
  Cc: Daniel Borkmann, Phil Sutter, Stephen Hemminger, David Ahern,
	Andrea Claudi, Hangbin Liu

When we disable IPv6 from the start up (ipv6.disable=1), there will be
no IPv6 route info in the dump message. If we return -1 when
ifi->ifi_family != AF_INET6, we will get error like

$ ip token list
Dump terminated

which will make user feel confused. There is no need to return -1 if the
dump message not match. Return 0 is enough.

v2: do not combine all the conditions together.

Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
---
 ip/iptoken.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/ip/iptoken.c b/ip/iptoken.c
index f1194c3e..9f356890 100644
--- a/ip/iptoken.c
+++ b/ip/iptoken.c
@@ -60,9 +60,9 @@ static int print_token(struct nlmsghdr *n, void *arg)
 		return -1;
 
 	if (ifi->ifi_family != AF_INET6)
-		return -1;
+		return 0;
 	if (ifi->ifi_index == 0)
-		return -1;
+		return 0;
 	if (ifindex > 0 && ifi->ifi_index != ifindex)
 		return 0;
 	if (ifi->ifi_flags & (IFF_LOOPBACK | IFF_NOARP))
-- 
2.19.2


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

end of thread, other threads:[~2019-06-26  1:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-25  9:35 [PATCH iproute2] ip/iptoken: fix dump error when ipv6 disabled Hangbin Liu
2019-06-25 20:11 ` Stephen Hemminger
2019-06-26  1:44 ` [PATCHv2 " Hangbin Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).