27 |
char name[16]; |
char name[16]; |
28 |
}; |
}; |
29 |
|
|
30 |
static struct idxmap *idxmap[16]; |
static struct idxmap **idxmap; /* treat as *idxmap[16] */ |
31 |
|
|
32 |
static struct idxmap *find_by_index(int idx) |
static struct idxmap *find_by_index(int idx) |
33 |
{ |
{ |
34 |
struct idxmap *im; |
struct idxmap *im; |
35 |
|
|
36 |
for (im = idxmap[idx & 0xF]; im; im = im->next) |
if (idxmap) |
37 |
if (im->index == idx) |
for (im = idxmap[idx & 0xF]; im; im = im->next) |
38 |
return im; |
if (im->index == idx) |
39 |
|
return im; |
40 |
return NULL; |
return NULL; |
41 |
} |
} |
42 |
|
|
43 |
int ll_remember_index(const struct sockaddr_nl *who UNUSED_PARAM, |
int FAST_FUNC ll_remember_index(const struct sockaddr_nl *who UNUSED_PARAM, |
44 |
struct nlmsghdr *n, |
struct nlmsghdr *n, |
45 |
void *arg UNUSED_PARAM) |
void *arg UNUSED_PARAM) |
46 |
{ |
{ |
60 |
if (tb[IFLA_IFNAME] == NULL) |
if (tb[IFLA_IFNAME] == NULL) |
61 |
return 0; |
return 0; |
62 |
|
|
63 |
h = ifi->ifi_index & 0xF; |
if (!idxmap) |
64 |
|
idxmap = xzalloc(sizeof(idxmap[0]) * 16); |
65 |
|
|
66 |
|
h = ifi->ifi_index & 0xF; |
67 |
for (imp = &idxmap[h]; (im = *imp) != NULL; imp = &im->next) |
for (imp = &idxmap[h]; (im = *imp) != NULL; imp = &im->next) |
68 |
if (im->index == ifi->ifi_index) |
if (im->index == ifi->ifi_index) |
69 |
goto found; |
goto found; |
89 |
return 0; |
return 0; |
90 |
} |
} |
91 |
|
|
92 |
const char *ll_idx_n2a(int idx, char *buf) |
const char FAST_FUNC *ll_idx_n2a(int idx, char *buf) |
93 |
{ |
{ |
94 |
struct idxmap *im; |
struct idxmap *im; |
95 |
|
|
103 |
} |
} |
104 |
|
|
105 |
|
|
106 |
const char *ll_index_to_name(int idx) |
const char FAST_FUNC *ll_index_to_name(int idx) |
107 |
{ |
{ |
108 |
static char nbuf[16]; |
static char nbuf[16]; |
109 |
|
|
124 |
} |
} |
125 |
#endif |
#endif |
126 |
|
|
127 |
unsigned ll_index_to_flags(int idx) |
unsigned FAST_FUNC ll_index_to_flags(int idx) |
128 |
{ |
{ |
129 |
struct idxmap *im; |
struct idxmap *im; |
130 |
|
|
136 |
return 0; |
return 0; |
137 |
} |
} |
138 |
|
|
139 |
int xll_name_to_index(const char *const name) |
int FAST_FUNC xll_name_to_index(const char *name) |
140 |
{ |
{ |
141 |
int ret = 0; |
int ret = 0; |
142 |
int sock_fd; |
int sock_fd; |
155 |
ret = icache; |
ret = icache; |
156 |
goto out; |
goto out; |
157 |
} |
} |
158 |
for (i = 0; i < 16; i++) { |
if (idxmap) { |
159 |
for (im = idxmap[i]; im; im = im->next) { |
for (i = 0; i < 16; i++) { |
160 |
if (strcmp(im->name, name) == 0) { |
for (im = idxmap[i]; im; im = im->next) { |
161 |
icache = im->index; |
if (strcmp(im->name, name) == 0) { |
162 |
strcpy(ncache, name); |
icache = im->index; |
163 |
ret = im->index; |
strcpy(ncache, name); |
164 |
goto out; |
ret = im->index; |
165 |
|
goto out; |
166 |
|
} |
167 |
} |
} |
168 |
} |
} |
169 |
} |
} |
177 |
#endif |
#endif |
178 |
|
|
179 |
sock_fd = socket(AF_INET, SOCK_DGRAM, 0); |
sock_fd = socket(AF_INET, SOCK_DGRAM, 0); |
180 |
if (sock_fd) { |
if (sock_fd >= 0) { |
181 |
struct ifreq ifr; |
struct ifreq ifr; |
182 |
int tmp; |
int tmp; |
183 |
|
|
184 |
strncpy(ifr.ifr_name, name, IFNAMSIZ); |
strncpy_IFNAMSIZ(ifr.ifr_name, name); |
185 |
ifr.ifr_ifindex = -1; |
ifr.ifr_ifindex = -1; |
186 |
tmp = ioctl(sock_fd, SIOCGIFINDEX, &ifr); |
tmp = ioctl(sock_fd, SIOCGIFINDEX, &ifr); |
187 |
close(sock_fd); |
close(sock_fd); |
193 |
} |
} |
194 |
/* out:*/ |
/* out:*/ |
195 |
if (ret <= 0) |
if (ret <= 0) |
196 |
bb_error_msg_and_die("cannot find device \"%s\"", name); |
bb_error_msg_and_die("can't find device '%s'", name); |
197 |
return ret; |
return ret; |
198 |
} |
} |
199 |
|
|
200 |
int ll_init_map(struct rtnl_handle *rth) |
int FAST_FUNC ll_init_map(struct rtnl_handle *rth) |
201 |
{ |
{ |
202 |
xrtnl_wilddump_request(rth, AF_UNSPEC, RTM_GETLINK); |
xrtnl_wilddump_request(rth, AF_UNSPEC, RTM_GETLINK); |
203 |
xrtnl_dump_filter(rth, ll_remember_index, &idxmap); |
xrtnl_dump_filter(rth, ll_remember_index, NULL); |
204 |
return 0; |
return 0; |
205 |
} |
} |