netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [iproute2] iproute2: fix the link group name getting error
@ 2016-11-18  1:12 Zhang Shengju
  2016-11-29 20:49 ` Stephen Hemminger
  0 siblings, 1 reply; 2+ messages in thread
From: Zhang Shengju @ 2016-11-18  1:12 UTC (permalink / raw)
  To: netdev

In the situation where more than one entry live in the same hash bucket,
loop to get the correct one.

Before:
$ cat /etc/iproute2/group
0	default
256     test

$ sudo ip link set group test dummy1

$ ip link show type dummy
11: dummy0: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN mode DEFAULT group 0 qlen 1000
    link/ether 4e:3b:d3:6c:f0:e6 brd ff:ff:ff:ff:ff:ff
12: dummy1: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN mode DEFAULT group test qlen 1000
    link/ether d6:9c:a4:1f:e7:e5 brd ff:ff:ff:ff:ff:ff

After:
$ ip link show type dummy
11: dummy0: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/ether 4e:3b:d3:6c:f0:e6 brd ff:ff:ff:ff:ff:ff
12: dummy1: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN mode DEFAULT group test qlen 1000
    link/ether d6:9c:a4:1f:e7:e5 brd ff:ff:ff:ff:ff:ff

Signed-off-by: Zhang Shengju <zhangshengju@cmss.chinamobile.com>
---
 lib/rt_names.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/lib/rt_names.c b/lib/rt_names.c
index b665d3e..c66cb1e 100644
--- a/lib/rt_names.c
+++ b/lib/rt_names.c
@@ -559,8 +559,12 @@ const char *rtnl_group_n2a(int id, char *buf, int len)
 
 	for (i = 0; i < 256; i++) {
 		entry = rtnl_group_hash[i];
-		if (entry && entry->id == id)
-			return entry->name;
+
+		while (entry) {
+			if (entry->id == id)
+				return entry->name;
+			entry = entry->next;
+		}
 	}
 
 	snprintf(buf, len, "%d", id);
-- 
1.8.3.1

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

* Re: [iproute2] iproute2: fix the link group name getting error
  2016-11-18  1:12 [iproute2] iproute2: fix the link group name getting error Zhang Shengju
@ 2016-11-29 20:49 ` Stephen Hemminger
  0 siblings, 0 replies; 2+ messages in thread
From: Stephen Hemminger @ 2016-11-29 20:49 UTC (permalink / raw)
  To: Zhang Shengju; +Cc: netdev

On Fri, 18 Nov 2016 09:12:53 +0800
Zhang Shengju <zhangshengju@cmss.chinamobile.com> wrote:

> In the situation where more than one entry live in the same hash bucket,
> loop to get the correct one.
> 
> Before:
> $ cat /etc/iproute2/group
> 0	default
> 256     test
> 
> $ sudo ip link set group test dummy1
> 
> $ ip link show type dummy
> 11: dummy0: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN mode DEFAULT group 0 qlen 1000
>     link/ether 4e:3b:d3:6c:f0:e6 brd ff:ff:ff:ff:ff:ff
> 12: dummy1: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN mode DEFAULT group test qlen 1000
>     link/ether d6:9c:a4:1f:e7:e5 brd ff:ff:ff:ff:ff:ff
> 
> After:
> $ ip link show type dummy
> 11: dummy0: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
>     link/ether 4e:3b:d3:6c:f0:e6 brd ff:ff:ff:ff:ff:ff
> 12: dummy1: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN mode DEFAULT group test qlen 1000
>     link/ether d6:9c:a4:1f:e7:e5 brd ff:ff:ff:ff:ff:ff
> 
> Signed-off-by: Zhang Shengju <zhangshengju@cmss.chinamobile.com>

Applied, and queued for next push.

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

end of thread, other threads:[~2016-11-29 20:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-18  1:12 [iproute2] iproute2: fix the link group name getting error Zhang Shengju
2016-11-29 20:49 ` Stephen Hemminger

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).