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.c37
1 files changed, 19 insertions, 18 deletions
diff --git a/networking/libiproute/ll_map.c b/networking/libiproute/ll_map.c
index a8fcd7f88..e9a1616cc 100644
--- a/networking/libiproute/ll_map.c
+++ b/networking/libiproute/ll_map.c
@@ -128,7 +128,7 @@ unsigned ll_index_to_flags(int idx)
128} 128}
129 129
130// TODO: caching is not warranted - no users which repeatedly call it 130// TODO: caching is not warranted - no users which repeatedly call it
131int ll_name_to_index(char *name) 131int xll_name_to_index(const char * const name)
132{ 132{
133 static char ncache[16]; 133 static char ncache[16];
134 static int icache; 134 static int icache;
@@ -136,17 +136,21 @@ int ll_name_to_index(char *name)
136 struct idxmap *im; 136 struct idxmap *im;
137 int sock_fd; 137 int sock_fd;
138 int i; 138 int i;
139 int ret = 0;
139 140
140 if (name == NULL) 141 if (name == NULL)
141 return 0; 142 goto out;
142 if (icache && strcmp(name, ncache) == 0) 143 if (icache && strcmp(name, ncache) == 0) {
143 return icache; 144 ret = icache;
145 goto out;
146 }
144 for (i = 0; i < 16; i++) { 147 for (i = 0; i < 16; i++) {
145 for (im = idxmap[i]; im; im = im->next) { 148 for (im = idxmap[i]; im; im = im->next) {
146 if (strcmp(im->name, name) == 0) { 149 if (strcmp(im->name, name) == 0) {
147 icache = im->index; 150 icache = im->index;
148 strcpy(ncache, name); 151 strcpy(ncache, name);
149 return im->index; 152 ret = im->index;
153 goto out;
150 } 154 }
151 } 155 }
152 } 156 }
@@ -160,29 +164,26 @@ int ll_name_to_index(char *name)
160 sock_fd = socket(AF_INET, SOCK_DGRAM, 0); 164 sock_fd = socket(AF_INET, SOCK_DGRAM, 0);
161 if (sock_fd) { 165 if (sock_fd) {
162 struct ifreq ifr; 166 struct ifreq ifr;
163 int ret; 167 int tmp;
164 strncpy(ifr.ifr_name, name, IFNAMSIZ); 168 strncpy(ifr.ifr_name, name, IFNAMSIZ);
165 ifr.ifr_ifindex = -1; 169 ifr.ifr_ifindex = -1;
166 ret = ioctl(sock_fd, SIOCGIFINDEX, &ifr); 170 tmp = ioctl(sock_fd, SIOCGIFINDEX, &ifr);
167 close(sock_fd); 171 close(sock_fd);
168 if (ret >= 0) 172 if (tmp >= 0)
169 /* In theory, we should redump the interface list 173 /* In theory, we should redump the interface list
170 * to update our cache, this is left as an exercise 174 * to update our cache, this is left as an exercise
171 * to the reader... Jean II */ 175 * to the reader... Jean II */
172 return ifr.ifr_ifindex; 176 ret = ifr.ifr_ifindex;
173 } 177 }
174 178out:
175 return 0; 179 if (ret <= 0)
180 bb_error_msg_and_die("cannot find device \"%s\"", name);
181 return ret;
176} 182}
177 183
178int ll_init_map(struct rtnl_handle *rth) 184int ll_init_map(struct rtnl_handle *rth)
179{ 185{
180 if (rtnl_wilddump_request(rth, AF_UNSPEC, RTM_GETLINK) < 0) { 186 xrtnl_wilddump_request(rth, AF_UNSPEC, RTM_GETLINK);
181 bb_perror_msg_and_die("cannot send dump request"); 187 xrtnl_dump_filter(rth, ll_remember_index, &idxmap);
182 }
183
184 if (rtnl_dump_filter(rth, ll_remember_index, &idxmap, NULL, NULL) < 0) {
185 bb_error_msg_and_die("dump terminated");
186 }
187 return 0; 188 return 0;
188} 189}