Skip to contentSkip to conversation

ip/iptoken: fix dump error when ipv6 disabled

PATCH Superseded Hangbin Liu 2 participants 3 messages Jun 25, 2019 – Jun 26, 2019

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

PATCH 1/1 ip/iptoken: fix dump error when ipv6 disabled

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.

---
 ip/iptoken.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
ip/iptoken.c +3 -7
index f1194c3e..dfd22734 100644
@@ -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);
Signature · 1 line
2.19.2
#1 lore raw
Quoted 24 lines · On Tue, 25 Jun 2019 17:35:50 +0800 Hangbin Liu <[email protected]> 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.

---
 ip/iptoken.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
ip/iptoken.c +0 -1
index f1194c3e..dfd22734 100644
@@ -59,13 +59,9 @@ static int print_token(struct nlmsghdr *n, void *arg)
 	if (len < 0)
 		return -1;
 
-	if (ifi->ifi_family != AF_INET6)

ip/iptoken.c static int print_token(struct nlmsghdr *n, void *arg) · line 65

Quoted 10 lines
ip/iptoken.c +3 -6
-		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;
#2 lore raw

PATCH v2 1/1 ip/iptoken: fix dump error when ipv6 disabled

In reply to 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.

---
 ip/iptoken.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
ip/iptoken.c +2 -2
index f1194c3e..9f356890 100644
@@ -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))
Signature · 1 line
2.19.2