lib/ll_map: Update name when changed
Subsystems (3)
PATCH 1/2 lib/ll_map: Update name when changed
On systems with a predictable naming scheme, our interfaces always first come up with the incremental kernel name prior to being renamed. If we have multiple links that come up at different times, they will usually use overlapping names when first seen. The predictable name is then set shorlty after. When using ip-monitor, all routes will then end up printing with this same first name (usually best seen with eth0). In these instances the routes cannot have their interfaces distinguished, as they are printed with a stale name.
Consider the following example while running ip-monitor
```
$ sudo ip link add dummy1 type dummy
$ sudo ip link set dummy1 name dummy2
$ sudo ip link set dummy2 addr 00:00:00:00:00:02
$ sudo ip link add dummy1 type dummy
$ sudo ip link set dummy1 addr 00:00:00:00:00:01
$ sudo ip link set dummy2 up
$ sudo ip link set dummy1 up
```
We currently see the following, notice the address and route lines
```
20: dummy1: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN group default
link/ether 82:49:17:d4:21:88 brd ff:ff:ff:ff:ff:ff
20: dummy1: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN group default
link/ether 86:61:a6:69:1d:7b brd ff:ff:ff:ff:ff:ff
20: dummy2: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN group default
link/ether 86:61:a6:69:1d:7b brd ff:ff:ff:ff:ff:ff
20: dummy2: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN group default
link/ether 00:00:00:00:00:02 brd ff:ff:ff:ff:ff:ff
21: dummy1: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN group default
link/ether d6:f6:da:e5:d7:7c brd ff:ff:ff:ff:ff:ff
21: dummy1: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN group default
link/ether 86:61:a6:69:1d:7b brd ff:ff:ff:ff:ff:ff
21: dummy1: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN group default
link/ether 00:00:00:00:00:01 brd ff:ff:ff:ff:ff:ff
20: dummy2: <BROADCAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default
link/ether 00:00:00:00:00:02 brd ff:ff:ff:ff:ff:ff
multicast ff00::/8 dev dummy1 table local proto kernel metric 256 pref medium
fe80::/64 dev dummy1 proto kernel metric 256 pref medium
20: dummy1 inet6 fe80::200:ff:fe00:2/64 scope link proto kernel_ll
valid_lft forever preferred_lft forever
local fe80::200:ff:fe00:2 dev dummy1 table local proto kernel metric 0 pref medium
21: dummy1: <BROADCAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default
link/ether 00:00:00:00:00:01 brd ff:ff:ff:ff:ff:ff
multicast ff00::/8 dev dummy1 table local proto kernel metric 256 pref medium
fe80::/64 dev dummy1 proto kernel metric 256 pref medium
21: dummy1 inet6 fe80::200:ff:fe00:1/64 scope link proto kernel_ll
valid_lft forever preferred_lft forever
local fe80::200:ff:fe00:1 dev dummy1 table local proto kernel metric 0 pref medium
```--- lib/ll_map.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
lib/ll_map.c +1 -2
@@ -118,9 +118,8 @@ static void ll_entry_update(struct ll_cache *im, struct ifinfomsg *ifi, {unsigned int h; +strcpy (im->name, ifname); im->flags = ifi->ifi_flags; -if (!strcmp (im->name, ifname)) -return ;hlist_del (&im->name_hash); h =namehash (ifname) & (IDXMAP_SIZE -1 );hlist_add_head (&im->name_hash, &name_head[h]);
Signature · 1 line
2.50.1.565.gc32cd1483b-goog
PATCH 2/2 ip-monitor: Always monitor links
We need to watch link changes even if we don't actively print them. Otherwise, route changes will not print the correct link name.
--- ip/ipmonitor.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
ip/ipmonitor.c +6 -2
@@ -25,6 +25,7 @@ static int prefix_banner;int listen_all_nsid;struct rtnl_ctrl_data *ctrl_data;int do_monitor; +int print_link;static void usage (void ) {
@@ -100,7 +101,8 @@ static int accept_msg(struct rtnl_ctrl_data *ctrl,case RTM_NEWLINK :case RTM_DELLINK :ll_remember_index (n,NULL ); -print_linkinfo (n, arg); +if (print_link) +print_linkinfo (n, arg);return 0 ;case RTM_NEWADDR :
@@ -263,8 +265,10 @@ int do_ipmonitor(int argc, char **argv)if (!lmask) lmask =IPMON_L_ALL ; +/* Always monitor links for renaming */ + groups |=nl_mgrp (RTNLGRP_LINK );if (lmask &IPMON_LLINK ) - groups |=nl_mgrp (RTNLGRP_LINK ); + print_link = true;if (lmask &IPMON_LADDR ) {if (!preferred_family || preferred_family ==AF_INET ) groups |=nl_mgrp (RTNLGRP_IPV4_IFADDR );
Signature · 1 line
2.50.1.565.gc32cd1483b-goog