X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=lib%2Fll_map.c;h=8e8a0b1e9c9d9880bcbecccffd225fe4ebe9a1c6;hb=25c6339b223f17d1603702c0c87f06b252bb4949;hp=70684b02042b6b50225104980a07ad9f3031bed2;hpb=f4745880289463b498350c72842d0029e8345b28;p=mirror_iproute2.git diff --git a/lib/ll_map.c b/lib/ll_map.c index 70684b02..8e8a0b1e 100644 --- a/lib/ll_map.c +++ b/lib/ll_map.c @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include @@ -78,8 +77,7 @@ static struct ll_cache *ll_get_by_name(const char *name) return NULL; } -int ll_remember_index(const struct sockaddr_nl *who, - struct nlmsghdr *n, void *arg) +int ll_remember_index(struct nlmsghdr *n, void *arg) { unsigned int h; const char *ifname; @@ -137,8 +135,26 @@ int ll_remember_index(const struct sockaddr_nl *who, return 0; } -const char *ll_idx_n2a(unsigned idx, char *buf) +const char *ll_idx_n2a(unsigned int idx) { + static char buf[IFNAMSIZ]; + + snprintf(buf, sizeof(buf), "if%u", idx); + return buf; +} + +static unsigned int ll_idx_a2n(const char *name) +{ + unsigned int idx; + + if (sscanf(name, "if%u", &idx) != 1) + return 0; + return idx; +} + +const char *ll_index_to_name(unsigned int idx) +{ + static char buf[IFNAMSIZ]; const struct ll_cache *im; if (idx == 0) @@ -149,18 +165,11 @@ const char *ll_idx_n2a(unsigned idx, char *buf) return im->name; if (if_indextoname(idx, buf) == NULL) - snprintf(buf, IFNAMSIZ, "if%d", idx); + snprintf(buf, IFNAMSIZ, "if%u", idx); return buf; } -const char *ll_index_to_name(unsigned idx) -{ - static char nbuf[IFNAMSIZ]; - - return ll_idx_n2a(idx, nbuf); -} - int ll_index_to_type(unsigned idx) { const struct ll_cache *im; @@ -197,10 +206,24 @@ unsigned ll_name_to_index(const char *name) idx = if_nametoindex(name); if (idx == 0) - sscanf(name, "if%u", &idx); + idx = ll_idx_a2n(name); return idx; } +void ll_drop_by_index(unsigned index) +{ + struct ll_cache *im; + + im = ll_get_by_index(index); + if (!im) + return; + + hlist_del(&im->idx_hash); + hlist_del(&im->name_hash); + + free(im); +} + void ll_init_map(struct rtnl_handle *rth) { static int initialized; @@ -208,7 +231,7 @@ void ll_init_map(struct rtnl_handle *rth) if (initialized) return; - if (rtnl_wilddump_request(rth, AF_UNSPEC, RTM_GETLINK) < 0) { + if (rtnl_linkdump_req(rth, AF_UNSPEC) < 0) { perror("Cannot send dump request"); exit(1); }