aboutsummaryrefslogtreecommitdiff
path: root/networking/libiproute/ll_map.c
diff options
context:
space:
mode:
Diffstat (limited to 'networking/libiproute/ll_map.c')
-rw-r--r--networking/libiproute/ll_map.c31
1 files changed, 18 insertions, 13 deletions
diff --git a/networking/libiproute/ll_map.c b/networking/libiproute/ll_map.c
index 62528cc83..3c4ef2c32 100644
--- a/networking/libiproute/ll_map.c
+++ b/networking/libiproute/ll_map.c
@@ -27,15 +27,16 @@ struct idxmap {
27 char name[16]; 27 char name[16];
28}; 28};
29 29
30static struct idxmap *idxmap[16]; 30static struct idxmap **idxmap; /* treat as *idxmap[16] */
31 31
32static struct idxmap *find_by_index(int idx) 32static struct idxmap *find_by_index(int idx)
33{ 33{
34 struct idxmap *im; 34 struct idxmap *im;
35 35
36 for (im = idxmap[idx & 0xF]; im; im = im->next) 36 if (idxmap)
37 if (im->index == idx) 37 for (im = idxmap[idx & 0xF]; im; im = im->next)
38 return im; 38 if (im->index == idx)
39 return im;
39 return NULL; 40 return NULL;
40} 41}
41 42
@@ -59,8 +60,10 @@ int FAST_FUNC ll_remember_index(const struct sockaddr_nl *who UNUSED_PARAM,
59 if (tb[IFLA_IFNAME] == NULL) 60 if (tb[IFLA_IFNAME] == NULL)
60 return 0; 61 return 0;
61 62
62 h = ifi->ifi_index & 0xF; 63 if (!idxmap)
64 idxmap = xzalloc(sizeof(idxmap[0]) * 16);
63 65
66 h = ifi->ifi_index & 0xF;
64 for (imp = &idxmap[h]; (im = *imp) != NULL; imp = &im->next) 67 for (imp = &idxmap[h]; (im = *imp) != NULL; imp = &im->next)
65 if (im->index == ifi->ifi_index) 68 if (im->index == ifi->ifi_index)
66 goto found; 69 goto found;
@@ -152,13 +155,15 @@ int FAST_FUNC xll_name_to_index(const char *name)
152 ret = icache; 155 ret = icache;
153 goto out; 156 goto out;
154 } 157 }
155 for (i = 0; i < 16; i++) { 158 if (idxmap) {
156 for (im = idxmap[i]; im; im = im->next) { 159 for (i = 0; i < 16; i++) {
157 if (strcmp(im->name, name) == 0) { 160 for (im = idxmap[i]; im; im = im->next) {
158 icache = im->index; 161 if (strcmp(im->name, name) == 0) {
159 strcpy(ncache, name); 162 icache = im->index;
160 ret = im->index; 163 strcpy(ncache, name);
161 goto out; 164 ret = im->index;
165 goto out;
166 }
162 } 167 }
163 } 168 }
164 } 169 }
@@ -195,6 +200,6 @@ int FAST_FUNC xll_name_to_index(const char *name)
195int FAST_FUNC ll_init_map(struct rtnl_handle *rth) 200int FAST_FUNC ll_init_map(struct rtnl_handle *rth)
196{ 201{
197 xrtnl_wilddump_request(rth, AF_UNSPEC, RTM_GETLINK); 202 xrtnl_wilddump_request(rth, AF_UNSPEC, RTM_GETLINK);
198 xrtnl_dump_filter(rth, ll_remember_index, &idxmap); 203 xrtnl_dump_filter(rth, ll_remember_index, NULL);
199 return 0; 204 return 0;
200} 205}