aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--networking/libiproute/libnetlink.c128
-rw-r--r--networking/libiproute/libnetlink.h4
-rw-r--r--networking/libiproute/rt_names.c81
-rw-r--r--networking/libiproute/rt_names.h3
4 files changed, 0 insertions, 216 deletions
diff --git a/networking/libiproute/libnetlink.c b/networking/libiproute/libnetlink.c
index efbb6f104..ad5bcd70f 100644
--- a/networking/libiproute/libnetlink.c
+++ b/networking/libiproute/libnetlink.c
@@ -319,134 +319,6 @@ int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer,
319 } 319 }
320} 320}
321 321
322int rtnl_listen(struct rtnl_handle *rtnl,
323 int (*handler)(struct sockaddr_nl *,struct nlmsghdr *n, void *),
324 void *jarg)
325{
326 int status;
327 struct nlmsghdr *h;
328 struct sockaddr_nl nladdr;
329 struct iovec iov;
330 char buf[8192];
331 struct msghdr msg = {
332 (void*)&nladdr, sizeof(nladdr),
333 &iov, 1,
334 NULL, 0,
335 0
336 };
337
338 memset(&nladdr, 0, sizeof(nladdr));
339 nladdr.nl_family = AF_NETLINK;
340 nladdr.nl_pid = 0;
341 nladdr.nl_groups = 0;
342
343
344 iov.iov_base = buf;
345
346 while (1) {
347 iov.iov_len = sizeof(buf);
348 status = recvmsg(rtnl->fd, &msg, 0);
349
350 if (status < 0) {
351 if (errno == EINTR)
352 continue;
353 bb_perror_msg("OVERRUN");
354 continue;
355 }
356 if (status == 0) {
357 bb_error_msg("EOF on netlink");
358 return -1;
359 }
360 if (msg.msg_namelen != sizeof(nladdr)) {
361 bb_error_msg_and_die("Sender address length == %d", msg.msg_namelen);
362 }
363 for (h = (struct nlmsghdr*)buf; status >= sizeof(*h); ) {
364 int err;
365 int len = h->nlmsg_len;
366 int l = len - sizeof(*h);
367
368 if (l<0 || len>status) {
369 if (msg.msg_flags & MSG_TRUNC) {
370 bb_error_msg("Truncated message");
371 return -1;
372 }
373 bb_error_msg_and_die("!!!malformed message: len=%d", len);
374 }
375
376 err = handler(&nladdr, h, jarg);
377 if (err < 0) {
378 return err;
379 }
380
381 status -= NLMSG_ALIGN(len);
382 h = (struct nlmsghdr*)((char*)h + NLMSG_ALIGN(len));
383 }
384 if (msg.msg_flags & MSG_TRUNC) {
385 bb_error_msg("Message truncated");
386 continue;
387 }
388 if (status) {
389 bb_error_msg_and_die("!!!Remnant of size %d", status);
390 }
391 }
392}
393
394int rtnl_from_file(FILE *rtnl,
395 int (*handler)(struct sockaddr_nl *,struct nlmsghdr *n, void *),
396 void *jarg)
397{
398 int status;
399 struct sockaddr_nl nladdr;
400 char buf[8192];
401 struct nlmsghdr *h = (void*)buf;
402
403 memset(&nladdr, 0, sizeof(nladdr));
404 nladdr.nl_family = AF_NETLINK;
405 nladdr.nl_pid = 0;
406 nladdr.nl_groups = 0;
407
408 while (1) {
409 int err, len, type;
410 int l;
411
412 status = fread(&buf, 1, sizeof(*h), rtnl);
413
414 if (status < 0) {
415 if (errno == EINTR)
416 continue;
417 bb_perror_msg("rtnl_from_file: fread");
418 return -1;
419 }
420 if (status == 0)
421 return 0;
422
423 len = h->nlmsg_len;
424 type= h->nlmsg_type;
425 l = len - sizeof(*h);
426
427 if (l<0 || len>sizeof(buf)) {
428 bb_error_msg("!!!malformed message: len=%d @%lu",
429 len, ftell(rtnl));
430 return -1;
431 }
432
433 status = fread(NLMSG_DATA(h), 1, NLMSG_ALIGN(l), rtnl);
434
435 if (status < 0) {
436 bb_perror_msg("rtnl_from_file: fread");
437 return -1;
438 }
439 if (status < l) {
440 bb_error_msg("rtnl-from_file: truncated message");
441 return -1;
442 }
443
444 err = handler(&nladdr, h, jarg);
445 if (err < 0)
446 return err;
447 }
448}
449
450int addattr32(struct nlmsghdr *n, int maxlen, int type, __u32 data) 322int addattr32(struct nlmsghdr *n, int maxlen, int type, __u32 data)
451{ 323{
452 int len = RTA_LENGTH(4); 324 int len = RTA_LENGTH(4);
diff --git a/networking/libiproute/libnetlink.h b/networking/libiproute/libnetlink.h
index 45d3ad2bc..c8a8b783c 100644
--- a/networking/libiproute/libnetlink.h
+++ b/networking/libiproute/libnetlink.h
@@ -37,10 +37,6 @@ extern int rta_addattr_l(struct rtattr *rta, int maxlen, int type, void *data, i
37 37
38extern int parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta, int len); 38extern int parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta, int len);
39 39
40extern int rtnl_listen(struct rtnl_handle *, int (*handler)(struct sockaddr_nl *,struct nlmsghdr *n, void *),
41 void *jarg);
42extern int rtnl_from_file(FILE *, int (*handler)(struct sockaddr_nl *,struct nlmsghdr *n, void *),
43 void *jarg);
44 40
45#endif /* __LIBNETLINK_H__ */ 41#endif /* __LIBNETLINK_H__ */
46 42
diff --git a/networking/libiproute/rt_names.c b/networking/libiproute/rt_names.c
index 5206c4b40..9d47491bc 100644
--- a/networking/libiproute/rt_names.c
+++ b/networking/libiproute/rt_names.c
@@ -207,23 +207,6 @@ static void rtnl_rtrealm_initialize(void)
207 rtnl_rtrealm_tab, 256); 207 rtnl_rtrealm_tab, 256);
208} 208}
209 209
210const char * rtnl_rtrealm_n2a(int id, char *buf, int len)
211{
212 if (id<0 || id>=256) {
213 snprintf(buf, len, "%d", id);
214 return buf;
215 }
216 if (!rtnl_rtrealm_tab[id]) {
217 if (!rtnl_rtrealm_init)
218 rtnl_rtrealm_initialize();
219 }
220 if (rtnl_rtrealm_tab[id])
221 return rtnl_rtrealm_tab[id];
222 snprintf(buf, len, "%d", id);
223 return buf;
224}
225
226
227int rtnl_rtrealm_a2n(uint32_t *id, char *arg) 210int rtnl_rtrealm_a2n(uint32_t *id, char *arg)
228{ 211{
229 static char *cache = NULL; 212 static char *cache = NULL;
@@ -258,70 +241,6 @@ int rtnl_rtrealm_a2n(uint32_t *id, char *arg)
258 241
259 242
260 243
261static char * rtnl_rttable_tab[256] = {
262 "unspec",
263};
264
265static int rtnl_rttable_init;
266
267static void rtnl_rttable_initialize(void)
268{
269 rtnl_rttable_init = 1;
270 rtnl_rttable_tab[255] = "local";
271 rtnl_rttable_tab[254] = "main";
272 rtnl_tab_initialize("/etc/iproute2/rt_tables",
273 rtnl_rttable_tab, 256);
274}
275
276const char * rtnl_rttable_n2a(int id, char *buf, int len)
277{
278 if (id<0 || id>=256) {
279 snprintf(buf, len, "%d", id);
280 return buf;
281 }
282 if (!rtnl_rttable_tab[id]) {
283 if (!rtnl_rttable_init)
284 rtnl_rttable_initialize();
285 }
286 if (rtnl_rttable_tab[id])
287 return rtnl_rttable_tab[id];
288 snprintf(buf, len, "%d", id);
289 return buf;
290}
291
292int rtnl_rttable_a2n(uint32_t *id, char *arg)
293{
294 static char *cache = NULL;
295 static unsigned long res;
296 char *end;
297 int i;
298
299 if (cache && strcmp(cache, arg) == 0) {
300 *id = res;
301 return 0;
302 }
303
304 if (!rtnl_rttable_init)
305 rtnl_rttable_initialize();
306
307 for (i=0; i<256; i++) {
308 if (rtnl_rttable_tab[i] &&
309 strcmp(rtnl_rttable_tab[i], arg) == 0) {
310 cache = rtnl_rttable_tab[i];
311 res = i;
312 *id = res;
313 return 0;
314 }
315 }
316
317 i = strtoul(arg, &end, 0);
318 if (!end || end == arg || *end || i > 255)
319 return -1;
320 *id = i;
321 return 0;
322}
323
324
325static char * rtnl_rtdsfield_tab[256] = { 244static char * rtnl_rtdsfield_tab[256] = {
326 "0", 245 "0",
327}; 246};
diff --git a/networking/libiproute/rt_names.h b/networking/libiproute/rt_names.h
index ed090a13b..deb5aa6f4 100644
--- a/networking/libiproute/rt_names.h
+++ b/networking/libiproute/rt_names.h
@@ -5,12 +5,9 @@
5 5
6extern const char* rtnl_rtprot_n2a(int id, char *buf, int len); 6extern const char* rtnl_rtprot_n2a(int id, char *buf, int len);
7extern const char* rtnl_rtscope_n2a(int id, char *buf, int len); 7extern const char* rtnl_rtscope_n2a(int id, char *buf, int len);
8extern const char* rtnl_rttable_n2a(int id, char *buf, int len);
9extern const char* rtnl_rtrealm_n2a(int id, char *buf, int len);
10extern const char* rtnl_dsfield_n2a(int id, char *buf, int len); 8extern const char* rtnl_dsfield_n2a(int id, char *buf, int len);
11extern int rtnl_rtprot_a2n(uint32_t *id, char *arg); 9extern int rtnl_rtprot_a2n(uint32_t *id, char *arg);
12extern int rtnl_rtscope_a2n(uint32_t *id, char *arg); 10extern int rtnl_rtscope_a2n(uint32_t *id, char *arg);
13extern int rtnl_rttable_a2n(uint32_t *id, char *arg);
14extern int rtnl_rtrealm_a2n(uint32_t *id, char *arg); 11extern int rtnl_rtrealm_a2n(uint32_t *id, char *arg);
15extern int rtnl_dsfield_a2n(uint32_t *id, char *arg); 12extern int rtnl_dsfield_a2n(uint32_t *id, char *arg);
16 13