Message ID | 20191009124947.27175-3-jiri@resnulli.us |
---|---|
State | Changes Requested |
Delegated to: | David Ahern |
Headers | show |
Series | [iproute2-next,v3,1/2] ip: add support for alternative name addition/deletion/list | expand |
On 10/9/19 8:49 AM, Jiri Pirko wrote: > From: Jiri Pirko <jiri@mellanox.com> > > Extend ll_name_to_index() to get the index of a netdevice using > alternative interface name. Allow alternative long names to pass checks > in couple of ip link/addr commands. you don't add altnames to the name_hash, so the lookup can not find a match based on altname.
Tue, Oct 15, 2019 at 08:34:56PM CEST, dsahern@gmail.com wrote: >On 10/9/19 8:49 AM, Jiri Pirko wrote: >> From: Jiri Pirko <jiri@mellanox.com> >> >> Extend ll_name_to_index() to get the index of a netdevice using >> alternative interface name. Allow alternative long names to pass checks >> in couple of ip link/addr commands. > >you don't add altnames to the name_hash, so the lookup can not find a >match based on altname. you are right, it is always going to fall back to ll_link_get(). I will do another patch to add the altnames to name_hash. It can go in separatelly or I can add that to this patchset. Up to you. >
On 10/16/19 7:28 AM, Jiri Pirko wrote: > Tue, Oct 15, 2019 at 08:34:56PM CEST, dsahern@gmail.com wrote: >> On 10/9/19 8:49 AM, Jiri Pirko wrote: >>> From: Jiri Pirko <jiri@mellanox.com> >>> >>> Extend ll_name_to_index() to get the index of a netdevice using >>> alternative interface name. Allow alternative long names to pass checks >>> in couple of ip link/addr commands. >> >> you don't add altnames to the name_hash, so the lookup can not find a >> match based on altname. > > you are right, it is always going to fall back to ll_link_get(). I will > do another patch to add the altnames to name_hash. It can go in > separatelly or I can add that to this patchset. Up to you. this patch claims to do the lookup, so it should actually be able to do a lookup.
Thu, Oct 17, 2019 at 05:34:54PM CEST, dsahern@gmail.com wrote: >On 10/16/19 7:28 AM, Jiri Pirko wrote: >> Tue, Oct 15, 2019 at 08:34:56PM CEST, dsahern@gmail.com wrote: >>> On 10/9/19 8:49 AM, Jiri Pirko wrote: >>>> From: Jiri Pirko <jiri@mellanox.com> >>>> >>>> Extend ll_name_to_index() to get the index of a netdevice using >>>> alternative interface name. Allow alternative long names to pass checks >>>> in couple of ip link/addr commands. >>> >>> you don't add altnames to the name_hash, so the lookup can not find a >>> match based on altname. >> >> you are right, it is always going to fall back to ll_link_get(). I will >> do another patch to add the altnames to name_hash. It can go in >> separatelly or I can add that to this patchset. Up to you. > >this patch claims to do the lookup, so it should actually be able to do >a lookup. Allright.
diff --git a/ip/iplink.c b/ip/iplink.c index bf90fad1b3ea..47f73988c2d5 100644 --- a/ip/iplink.c +++ b/ip/iplink.c @@ -931,7 +931,7 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req, char **type) NEXT_ARG(); if (dev != name) duparg2("dev", *argv); - if (check_ifname(*argv)) + if (check_altifname(*argv)) invarg("\"dev\" not a valid ifname", *argv); dev = *argv; } @@ -1106,7 +1106,8 @@ int iplink_get(char *name, __u32 filt_mask) if (name) { addattr_l(&req.n, sizeof(req), - IFLA_IFNAME, name, strlen(name) + 1); + !check_ifname(name) ? IFLA_IFNAME : IFLA_ALT_IFNAME, + name, strlen(name) + 1); } addattr32(&req.n, sizeof(req), IFLA_EXT_MASK, filt_mask); diff --git a/lib/ll_map.c b/lib/ll_map.c index e0ed54bf77c9..5c612f952be4 100644 --- a/lib/ll_map.c +++ b/lib/ll_map.c @@ -22,6 +22,7 @@ #include "libnetlink.h" #include "ll_map.h" #include "list.h" +#include "utils.h" struct ll_cache { struct hlist_node idx_hash; @@ -70,7 +71,7 @@ static struct ll_cache *ll_get_by_name(const char *name) struct ll_cache *im = container_of(n, struct ll_cache, name_hash); - if (strncmp(im->name, name, IFNAMSIZ) == 0) + if (strcmp(im->name, name) == 0) return im; } @@ -174,8 +175,9 @@ static int ll_link_get(const char *name, int index) addattr32(&req.n, sizeof(req), IFLA_EXT_MASK, filt_mask); if (name) - addattr_l(&req.n, sizeof(req), IFLA_IFNAME, name, - strlen(name) + 1); + addattr_l(&req.n, sizeof(req), + !check_ifname(name) ? IFLA_IFNAME : IFLA_ALT_IFNAME, + name, strlen(name) + 1); if (rtnl_talk_suppress_rtnl_errmsg(&rth, &req.n, &answer) < 0) goto out;