diff options
-rw-r--r-- | networking/libiproute/ipaddress.c | 139 | ||||
-rw-r--r-- | networking/libiproute/iproute.c | 182 |
2 files changed, 168 insertions, 153 deletions
diff --git a/networking/libiproute/ipaddress.c b/networking/libiproute/ipaddress.c index 03f5073fb..f2e340a42 100644 --- a/networking/libiproute/ipaddress.c +++ b/networking/libiproute/ipaddress.c | |||
@@ -40,7 +40,7 @@ typedef struct filter_t { | |||
40 | inet_prefix pfx; | 40 | inet_prefix pfx; |
41 | } filter_t; | 41 | } filter_t; |
42 | 42 | ||
43 | #define filter (*(filter_t*)&bb_common_bufsiz1) | 43 | #define G_filter (*(filter_t*)&bb_common_bufsiz1) |
44 | 44 | ||
45 | 45 | ||
46 | static void print_link_flags(unsigned flags, unsigned mdown) | 46 | static void print_link_flags(unsigned flags, unsigned mdown) |
@@ -107,9 +107,9 @@ static NOINLINE int print_linkinfo(const struct nlmsghdr *n) | |||
107 | if (len < 0) | 107 | if (len < 0) |
108 | return -1; | 108 | return -1; |
109 | 109 | ||
110 | if (filter.ifindex && ifi->ifi_index != filter.ifindex) | 110 | if (G_filter.ifindex && ifi->ifi_index != G_filter.ifindex) |
111 | return 0; | 111 | return 0; |
112 | if (filter.up && !(ifi->ifi_flags & IFF_UP)) | 112 | if (G_filter.up && !(ifi->ifi_flags & IFF_UP)) |
113 | return 0; | 113 | return 0; |
114 | 114 | ||
115 | memset(tb, 0, sizeof(tb)); | 115 | memset(tb, 0, sizeof(tb)); |
@@ -118,9 +118,9 @@ static NOINLINE int print_linkinfo(const struct nlmsghdr *n) | |||
118 | bb_error_msg("nil ifname"); | 118 | bb_error_msg("nil ifname"); |
119 | return -1; | 119 | return -1; |
120 | } | 120 | } |
121 | if (filter.label | 121 | if (G_filter.label |
122 | && (!filter.family || filter.family == AF_PACKET) | 122 | && (!G_filter.family || G_filter.family == AF_PACKET) |
123 | && fnmatch(filter.label, RTA_DATA(tb[IFLA_IFNAME]), 0) | 123 | && fnmatch(G_filter.label, RTA_DATA(tb[IFLA_IFNAME]), 0) |
124 | ) { | 124 | ) { |
125 | return 0; | 125 | return 0; |
126 | } | 126 | } |
@@ -161,10 +161,10 @@ static NOINLINE int print_linkinfo(const struct nlmsghdr *n) | |||
161 | printf("master %s ", ll_idx_n2a(*(int*)RTA_DATA(tb[IFLA_MASTER]), b1)); | 161 | printf("master %s ", ll_idx_n2a(*(int*)RTA_DATA(tb[IFLA_MASTER]), b1)); |
162 | } | 162 | } |
163 | #endif | 163 | #endif |
164 | if (filter.showqueue) | 164 | if (G_filter.showqueue) |
165 | print_queuelen((char*)RTA_DATA(tb[IFLA_IFNAME])); | 165 | print_queuelen((char*)RTA_DATA(tb[IFLA_IFNAME])); |
166 | 166 | ||
167 | if (!filter.family || filter.family == AF_PACKET) { | 167 | if (!G_filter.family || G_filter.family == AF_PACKET) { |
168 | SPRINT_BUF(b1); | 168 | SPRINT_BUF(b1); |
169 | printf("%c link/%s ", _SL_, ll_type_n2a(ifi->ifi_type, b1)); | 169 | printf("%c link/%s ", _SL_, ll_type_n2a(ifi->ifi_type, b1)); |
170 | 170 | ||
@@ -192,11 +192,11 @@ static NOINLINE int print_linkinfo(const struct nlmsghdr *n) | |||
192 | 192 | ||
193 | static int flush_update(void) | 193 | static int flush_update(void) |
194 | { | 194 | { |
195 | if (rtnl_send(filter.rth, filter.flushb, filter.flushp) < 0) { | 195 | if (rtnl_send(G_filter.rth, G_filter.flushb, G_filter.flushp) < 0) { |
196 | bb_perror_msg("failed to send flush request"); | 196 | bb_perror_msg("failed to send flush request"); |
197 | return -1; | 197 | return -1; |
198 | } | 198 | } |
199 | filter.flushp = 0; | 199 | G_filter.flushp = 0; |
200 | return 0; | 200 | return 0; |
201 | } | 201 | } |
202 | 202 | ||
@@ -217,7 +217,7 @@ static int FAST_FUNC print_addrinfo(const struct sockaddr_nl *who UNUSED_PARAM, | |||
217 | return -1; | 217 | return -1; |
218 | } | 218 | } |
219 | 219 | ||
220 | if (filter.flushb && n->nlmsg_type != RTM_NEWADDR) | 220 | if (G_filter.flushb && n->nlmsg_type != RTM_NEWADDR) |
221 | return 0; | 221 | return 0; |
222 | 222 | ||
223 | memset(rta_tb, 0, sizeof(rta_tb)); | 223 | memset(rta_tb, 0, sizeof(rta_tb)); |
@@ -228,52 +228,52 @@ static int FAST_FUNC print_addrinfo(const struct sockaddr_nl *who UNUSED_PARAM, | |||
228 | if (!rta_tb[IFA_ADDRESS]) | 228 | if (!rta_tb[IFA_ADDRESS]) |
229 | rta_tb[IFA_ADDRESS] = rta_tb[IFA_LOCAL]; | 229 | rta_tb[IFA_ADDRESS] = rta_tb[IFA_LOCAL]; |
230 | 230 | ||
231 | if (filter.ifindex && filter.ifindex != ifa->ifa_index) | 231 | if (G_filter.ifindex && G_filter.ifindex != ifa->ifa_index) |
232 | return 0; | 232 | return 0; |
233 | if ((filter.scope ^ ifa->ifa_scope) & filter.scopemask) | 233 | if ((G_filter.scope ^ ifa->ifa_scope) & G_filter.scopemask) |
234 | return 0; | 234 | return 0; |
235 | if ((filter.flags ^ ifa->ifa_flags) & filter.flagmask) | 235 | if ((G_filter.flags ^ ifa->ifa_flags) & G_filter.flagmask) |
236 | return 0; | 236 | return 0; |
237 | if (filter.label) { | 237 | if (G_filter.label) { |
238 | const char *label; | 238 | const char *label; |
239 | if (rta_tb[IFA_LABEL]) | 239 | if (rta_tb[IFA_LABEL]) |
240 | label = RTA_DATA(rta_tb[IFA_LABEL]); | 240 | label = RTA_DATA(rta_tb[IFA_LABEL]); |
241 | else | 241 | else |
242 | label = ll_idx_n2a(ifa->ifa_index, b1); | 242 | label = ll_idx_n2a(ifa->ifa_index, b1); |
243 | if (fnmatch(filter.label, label, 0) != 0) | 243 | if (fnmatch(G_filter.label, label, 0) != 0) |
244 | return 0; | 244 | return 0; |
245 | } | 245 | } |
246 | if (filter.pfx.family) { | 246 | if (G_filter.pfx.family) { |
247 | if (rta_tb[IFA_LOCAL]) { | 247 | if (rta_tb[IFA_LOCAL]) { |
248 | inet_prefix dst; | 248 | inet_prefix dst; |
249 | memset(&dst, 0, sizeof(dst)); | 249 | memset(&dst, 0, sizeof(dst)); |
250 | dst.family = ifa->ifa_family; | 250 | dst.family = ifa->ifa_family; |
251 | memcpy(&dst.data, RTA_DATA(rta_tb[IFA_LOCAL]), RTA_PAYLOAD(rta_tb[IFA_LOCAL])); | 251 | memcpy(&dst.data, RTA_DATA(rta_tb[IFA_LOCAL]), RTA_PAYLOAD(rta_tb[IFA_LOCAL])); |
252 | if (inet_addr_match(&dst, &filter.pfx, filter.pfx.bitlen)) | 252 | if (inet_addr_match(&dst, &G_filter.pfx, G_filter.pfx.bitlen)) |
253 | return 0; | 253 | return 0; |
254 | } | 254 | } |
255 | } | 255 | } |
256 | 256 | ||
257 | if (filter.flushb) { | 257 | if (G_filter.flushb) { |
258 | struct nlmsghdr *fn; | 258 | struct nlmsghdr *fn; |
259 | if (NLMSG_ALIGN(filter.flushp) + n->nlmsg_len > filter.flushe) { | 259 | if (NLMSG_ALIGN(G_filter.flushp) + n->nlmsg_len > G_filter.flushe) { |
260 | if (flush_update()) | 260 | if (flush_update()) |
261 | return -1; | 261 | return -1; |
262 | } | 262 | } |
263 | fn = (struct nlmsghdr*)(filter.flushb + NLMSG_ALIGN(filter.flushp)); | 263 | fn = (struct nlmsghdr*)(G_filter.flushb + NLMSG_ALIGN(G_filter.flushp)); |
264 | memcpy(fn, n, n->nlmsg_len); | 264 | memcpy(fn, n, n->nlmsg_len); |
265 | fn->nlmsg_type = RTM_DELADDR; | 265 | fn->nlmsg_type = RTM_DELADDR; |
266 | fn->nlmsg_flags = NLM_F_REQUEST; | 266 | fn->nlmsg_flags = NLM_F_REQUEST; |
267 | fn->nlmsg_seq = ++filter.rth->seq; | 267 | fn->nlmsg_seq = ++G_filter.rth->seq; |
268 | filter.flushp = (((char*)fn) + n->nlmsg_len) - filter.flushb; | 268 | G_filter.flushp = (((char*)fn) + n->nlmsg_len) - G_filter.flushb; |
269 | filter.flushed = 1; | 269 | G_filter.flushed = 1; |
270 | return 0; | 270 | return 0; |
271 | } | 271 | } |
272 | 272 | ||
273 | if (n->nlmsg_type == RTM_DELADDR) | 273 | if (n->nlmsg_type == RTM_DELADDR) |
274 | printf("Deleted "); | 274 | printf("Deleted "); |
275 | 275 | ||
276 | if (filter.oneline) | 276 | if (G_filter.oneline) |
277 | printf("%u: %s", ifa->ifa_index, ll_index_to_name(ifa->ifa_index)); | 277 | printf("%u: %s", ifa->ifa_index, ll_index_to_name(ifa->ifa_index)); |
278 | if (ifa->ifa_family == AF_INET) | 278 | if (ifa->ifa_family == AF_INET) |
279 | printf(" inet "); | 279 | printf(" inet "); |
@@ -366,14 +366,13 @@ static int print_selected_addrinfo(int ifindex, struct nlmsg_list *ainfo) | |||
366 | 366 | ||
367 | if (n->nlmsg_type != RTM_NEWADDR) | 367 | if (n->nlmsg_type != RTM_NEWADDR) |
368 | continue; | 368 | continue; |
369 | |||
370 | if (n->nlmsg_len < NLMSG_LENGTH(sizeof(ifa))) | 369 | if (n->nlmsg_len < NLMSG_LENGTH(sizeof(ifa))) |
371 | return -1; | 370 | return -1; |
372 | 371 | if (ifa->ifa_index != ifindex | |
373 | if (ifa->ifa_index != ifindex || | 372 | || (G_filter.family && G_filter.family != ifa->ifa_family) |
374 | (filter.family && filter.family != ifa->ifa_family)) | 373 | ) { |
375 | continue; | 374 | continue; |
376 | 375 | } | |
377 | print_addrinfo(NULL, n, NULL); | 376 | print_addrinfo(NULL, n, NULL); |
378 | } | 377 | } |
379 | return 0; | 378 | return 0; |
@@ -401,8 +400,8 @@ static int FAST_FUNC store_nlmsg(const struct sockaddr_nl *who, struct nlmsghdr | |||
401 | 400 | ||
402 | static void ipaddr_reset_filter(int _oneline) | 401 | static void ipaddr_reset_filter(int _oneline) |
403 | { | 402 | { |
404 | memset(&filter, 0, sizeof(filter)); | 403 | memset(&G_filter, 0, sizeof(G_filter)); |
405 | filter.oneline = _oneline; | 404 | G_filter.oneline = _oneline; |
406 | } | 405 | } |
407 | 406 | ||
408 | /* Return value becomes exitcode. It's okay to not return at all */ | 407 | /* Return value becomes exitcode. It's okay to not return at all */ |
@@ -418,16 +417,16 @@ int ipaddr_list_or_flush(char **argv, int flush) | |||
418 | int no_link = 0; | 417 | int no_link = 0; |
419 | 418 | ||
420 | ipaddr_reset_filter(oneline); | 419 | ipaddr_reset_filter(oneline); |
421 | filter.showqueue = 1; | 420 | G_filter.showqueue = 1; |
422 | 421 | ||
423 | if (filter.family == AF_UNSPEC) | 422 | if (G_filter.family == AF_UNSPEC) |
424 | filter.family = preferred_family; | 423 | G_filter.family = preferred_family; |
425 | 424 | ||
426 | if (flush) { | 425 | if (flush) { |
427 | if (!*argv) { | 426 | if (!*argv) { |
428 | bb_error_msg_and_die(bb_msg_requires_arg, "flush"); | 427 | bb_error_msg_and_die(bb_msg_requires_arg, "flush"); |
429 | } | 428 | } |
430 | if (filter.family == AF_PACKET) { | 429 | if (G_filter.family == AF_PACKET) { |
431 | bb_error_msg_and_die("can't flush link addresses"); | 430 | bb_error_msg_and_die("can't flush link addresses"); |
432 | } | 431 | } |
433 | } | 432 | } |
@@ -437,32 +436,31 @@ int ipaddr_list_or_flush(char **argv, int flush) | |||
437 | switch (option_num) { | 436 | switch (option_num) { |
438 | case 0: /* to */ | 437 | case 0: /* to */ |
439 | NEXT_ARG(); | 438 | NEXT_ARG(); |
440 | get_prefix(&filter.pfx, *argv, filter.family); | 439 | get_prefix(&G_filter.pfx, *argv, G_filter.family); |
441 | if (filter.family == AF_UNSPEC) { | 440 | if (G_filter.family == AF_UNSPEC) { |
442 | filter.family = filter.pfx.family; | 441 | G_filter.family = G_filter.pfx.family; |
443 | } | 442 | } |
444 | break; | 443 | break; |
445 | case 1: /* scope */ | 444 | case 1: { /* scope */ |
446 | { | ||
447 | uint32_t scope = 0; | 445 | uint32_t scope = 0; |
448 | NEXT_ARG(); | 446 | NEXT_ARG(); |
449 | filter.scopemask = -1; | 447 | G_filter.scopemask = -1; |
450 | if (rtnl_rtscope_a2n(&scope, *argv)) { | 448 | if (rtnl_rtscope_a2n(&scope, *argv)) { |
451 | if (strcmp(*argv, "all") != 0) { | 449 | if (strcmp(*argv, "all") != 0) { |
452 | invarg(*argv, "scope"); | 450 | invarg(*argv, "scope"); |
453 | } | 451 | } |
454 | scope = RT_SCOPE_NOWHERE; | 452 | scope = RT_SCOPE_NOWHERE; |
455 | filter.scopemask = 0; | 453 | G_filter.scopemask = 0; |
456 | } | 454 | } |
457 | filter.scope = scope; | 455 | G_filter.scope = scope; |
458 | break; | 456 | break; |
459 | } | 457 | } |
460 | case 2: /* up */ | 458 | case 2: /* up */ |
461 | filter.up = 1; | 459 | G_filter.up = 1; |
462 | break; | 460 | break; |
463 | case 3: /* label */ | 461 | case 3: /* label */ |
464 | NEXT_ARG(); | 462 | NEXT_ARG(); |
465 | filter.label = *argv; | 463 | G_filter.label = *argv; |
466 | break; | 464 | break; |
467 | case 4: /* dev */ | 465 | case 4: /* dev */ |
468 | NEXT_ARG(); | 466 | NEXT_ARG(); |
@@ -481,40 +479,41 @@ int ipaddr_list_or_flush(char **argv, int flush) | |||
481 | xrtnl_dump_filter(&rth, store_nlmsg, &linfo); | 479 | xrtnl_dump_filter(&rth, store_nlmsg, &linfo); |
482 | 480 | ||
483 | if (filter_dev) { | 481 | if (filter_dev) { |
484 | filter.ifindex = xll_name_to_index(filter_dev); | 482 | G_filter.ifindex = xll_name_to_index(filter_dev); |
485 | } | 483 | } |
486 | 484 | ||
487 | if (flush) { | 485 | if (flush) { |
488 | char flushb[4096-512]; | 486 | char flushb[4096-512]; |
489 | 487 | ||
490 | filter.flushb = flushb; | 488 | G_filter.flushb = flushb; |
491 | filter.flushp = 0; | 489 | G_filter.flushp = 0; |
492 | filter.flushe = sizeof(flushb); | 490 | G_filter.flushe = sizeof(flushb); |
493 | filter.rth = &rth; | 491 | G_filter.rth = &rth; |
494 | 492 | ||
495 | for (;;) { | 493 | for (;;) { |
496 | xrtnl_wilddump_request(&rth, filter.family, RTM_GETADDR); | 494 | xrtnl_wilddump_request(&rth, G_filter.family, RTM_GETADDR); |
497 | filter.flushed = 0; | 495 | G_filter.flushed = 0; |
498 | xrtnl_dump_filter(&rth, print_addrinfo, NULL); | 496 | xrtnl_dump_filter(&rth, print_addrinfo, NULL); |
499 | if (filter.flushed == 0) { | 497 | if (G_filter.flushed == 0) { |
500 | return 0; | 498 | return 0; |
501 | } | 499 | } |
502 | if (flush_update() < 0) | 500 | if (flush_update() < 0) { |
503 | return 1; | 501 | return 1; |
502 | } | ||
504 | } | 503 | } |
505 | } | 504 | } |
506 | 505 | ||
507 | if (filter.family != AF_PACKET) { | 506 | if (G_filter.family != AF_PACKET) { |
508 | xrtnl_wilddump_request(&rth, filter.family, RTM_GETADDR); | 507 | xrtnl_wilddump_request(&rth, G_filter.family, RTM_GETADDR); |
509 | xrtnl_dump_filter(&rth, store_nlmsg, &ainfo); | 508 | xrtnl_dump_filter(&rth, store_nlmsg, &ainfo); |
510 | } | 509 | } |
511 | 510 | ||
512 | 511 | ||
513 | if (filter.family && filter.family != AF_PACKET) { | 512 | if (G_filter.family && G_filter.family != AF_PACKET) { |
514 | struct nlmsg_list **lp; | 513 | struct nlmsg_list **lp; |
515 | lp = &linfo; | 514 | lp = &linfo; |
516 | 515 | ||
517 | if (filter.oneline) | 516 | if (G_filter.oneline) |
518 | no_link = 1; | 517 | no_link = 1; |
519 | 518 | ||
520 | while ((l = *lp) != NULL) { | 519 | while ((l = *lp) != NULL) { |
@@ -526,36 +525,38 @@ int ipaddr_list_or_flush(char **argv, int flush) | |||
526 | struct nlmsghdr *n = &a->h; | 525 | struct nlmsghdr *n = &a->h; |
527 | struct ifaddrmsg *ifa = NLMSG_DATA(n); | 526 | struct ifaddrmsg *ifa = NLMSG_DATA(n); |
528 | 527 | ||
529 | if (ifa->ifa_index != ifi->ifi_index || | 528 | if (ifa->ifa_index != ifi->ifi_index |
530 | (filter.family && filter.family != ifa->ifa_family)) | 529 | || (G_filter.family && G_filter.family != ifa->ifa_family) |
530 | ) { | ||
531 | continue; | 531 | continue; |
532 | if ((filter.scope ^ ifa->ifa_scope) & filter.scopemask) | 532 | } |
533 | if ((G_filter.scope ^ ifa->ifa_scope) & G_filter.scopemask) | ||
533 | continue; | 534 | continue; |
534 | if ((filter.flags ^ ifa->ifa_flags) & filter.flagmask) | 535 | if ((G_filter.flags ^ ifa->ifa_flags) & G_filter.flagmask) |
535 | continue; | 536 | continue; |
536 | if (filter.pfx.family || filter.label) { | 537 | if (G_filter.pfx.family || G_filter.label) { |
537 | struct rtattr *tb[IFA_MAX+1]; | 538 | struct rtattr *tb[IFA_MAX+1]; |
538 | memset(tb, 0, sizeof(tb)); | 539 | memset(tb, 0, sizeof(tb)); |
539 | parse_rtattr(tb, IFA_MAX, IFA_RTA(ifa), IFA_PAYLOAD(n)); | 540 | parse_rtattr(tb, IFA_MAX, IFA_RTA(ifa), IFA_PAYLOAD(n)); |
540 | if (!tb[IFA_LOCAL]) | 541 | if (!tb[IFA_LOCAL]) |
541 | tb[IFA_LOCAL] = tb[IFA_ADDRESS]; | 542 | tb[IFA_LOCAL] = tb[IFA_ADDRESS]; |
542 | 543 | ||
543 | if (filter.pfx.family && tb[IFA_LOCAL]) { | 544 | if (G_filter.pfx.family && tb[IFA_LOCAL]) { |
544 | inet_prefix dst; | 545 | inet_prefix dst; |
545 | memset(&dst, 0, sizeof(dst)); | 546 | memset(&dst, 0, sizeof(dst)); |
546 | dst.family = ifa->ifa_family; | 547 | dst.family = ifa->ifa_family; |
547 | memcpy(&dst.data, RTA_DATA(tb[IFA_LOCAL]), RTA_PAYLOAD(tb[IFA_LOCAL])); | 548 | memcpy(&dst.data, RTA_DATA(tb[IFA_LOCAL]), RTA_PAYLOAD(tb[IFA_LOCAL])); |
548 | if (inet_addr_match(&dst, &filter.pfx, filter.pfx.bitlen)) | 549 | if (inet_addr_match(&dst, &G_filter.pfx, G_filter.pfx.bitlen)) |
549 | continue; | 550 | continue; |
550 | } | 551 | } |
551 | if (filter.label) { | 552 | if (G_filter.label) { |
552 | SPRINT_BUF(b1); | 553 | SPRINT_BUF(b1); |
553 | const char *label; | 554 | const char *label; |
554 | if (tb[IFA_LABEL]) | 555 | if (tb[IFA_LABEL]) |
555 | label = RTA_DATA(tb[IFA_LABEL]); | 556 | label = RTA_DATA(tb[IFA_LABEL]); |
556 | else | 557 | else |
557 | label = ll_idx_n2a(ifa->ifa_index, b1); | 558 | label = ll_idx_n2a(ifa->ifa_index, b1); |
558 | if (fnmatch(filter.label, label, 0) != 0) | 559 | if (fnmatch(G_filter.label, label, 0) != 0) |
559 | continue; | 560 | continue; |
560 | } | 561 | } |
561 | } | 562 | } |
@@ -573,7 +574,7 @@ int ipaddr_list_or_flush(char **argv, int flush) | |||
573 | for (l = linfo; l; l = l->next) { | 574 | for (l = linfo; l; l = l->next) { |
574 | if (no_link || print_linkinfo(&l->h) == 0) { | 575 | if (no_link || print_linkinfo(&l->h) == 0) { |
575 | struct ifinfomsg *ifi = NLMSG_DATA(&l->h); | 576 | struct ifinfomsg *ifi = NLMSG_DATA(&l->h); |
576 | if (filter.family != AF_PACKET) | 577 | if (G_filter.family != AF_PACKET) |
577 | print_selected_addrinfo(ifi->ifi_index, ainfo); | 578 | print_selected_addrinfo(ifi->ifi_index, ainfo); |
578 | } | 579 | } |
579 | } | 580 | } |
diff --git a/networking/libiproute/iproute.c b/networking/libiproute/iproute.c index 67eb90b84..c4b3450dd 100644 --- a/networking/libiproute/iproute.c +++ b/networking/libiproute/iproute.c | |||
@@ -29,14 +29,15 @@ typedef struct filter_t { | |||
29 | int flushp; | 29 | int flushp; |
30 | int flushe; | 30 | int flushe; |
31 | struct rtnl_handle *rth; | 31 | struct rtnl_handle *rth; |
32 | int protocol, protocolmask; | 32 | //int protocol, protocolmask; - write-only fields?! |
33 | int scope, scopemask; | 33 | //int scope, scopemask; - unused |
34 | int type, typemask; | 34 | //int type; - read-only |
35 | int tos, tosmask; | 35 | //int typemask; - unused |
36 | //int tos, tosmask; - unused | ||
36 | int iif, iifmask; | 37 | int iif, iifmask; |
37 | int oif, oifmask; | 38 | int oif, oifmask; |
38 | int realm, realmmask; | 39 | //int realm, realmmask; - unused |
39 | inet_prefix rprefsrc; | 40 | //inet_prefix rprefsrc; - read-only |
40 | inet_prefix rvia; | 41 | inet_prefix rvia; |
41 | inet_prefix rdst; | 42 | inet_prefix rdst; |
42 | inet_prefix mdst; | 43 | inet_prefix mdst; |
@@ -44,15 +45,15 @@ typedef struct filter_t { | |||
44 | inet_prefix msrc; | 45 | inet_prefix msrc; |
45 | } filter_t; | 46 | } filter_t; |
46 | 47 | ||
47 | #define filter (*(filter_t*)&bb_common_bufsiz1) | 48 | #define G_filter (*(filter_t*)&bb_common_bufsiz1) |
48 | 49 | ||
49 | static int flush_update(void) | 50 | static int flush_update(void) |
50 | { | 51 | { |
51 | if (rtnl_send(filter.rth, filter.flushb, filter.flushp) < 0) { | 52 | if (rtnl_send(G_filter.rth, G_filter.flushb, G_filter.flushp) < 0) { |
52 | bb_perror_msg("failed to send flush request"); | 53 | bb_perror_msg("failed to send flush request"); |
53 | return -1; | 54 | return -1; |
54 | } | 55 | } |
55 | filter.flushp = 0; | 56 | G_filter.flushp = 0; |
56 | return 0; | 57 | return 0; |
57 | } | 58 | } |
58 | 59 | ||
@@ -95,7 +96,7 @@ static int FAST_FUNC print_route(const struct sockaddr_nl *who UNUSED_PARAM, | |||
95 | n->nlmsg_len, n->nlmsg_type, n->nlmsg_flags); | 96 | n->nlmsg_len, n->nlmsg_type, n->nlmsg_flags); |
96 | return 0; | 97 | return 0; |
97 | } | 98 | } |
98 | if (filter.flushb && n->nlmsg_type != RTM_NEWROUTE) | 99 | if (G_filter.flushb && n->nlmsg_type != RTM_NEWROUTE) |
99 | return 0; | 100 | return 0; |
100 | len -= NLMSG_LENGTH(sizeof(*r)); | 101 | len -= NLMSG_LENGTH(sizeof(*r)); |
101 | if (len < 0) | 102 | if (len < 0) |
@@ -107,8 +108,8 @@ static int FAST_FUNC print_route(const struct sockaddr_nl *who UNUSED_PARAM, | |||
107 | host_len = 32; | 108 | host_len = 32; |
108 | 109 | ||
109 | if (r->rtm_family == AF_INET6) { | 110 | if (r->rtm_family == AF_INET6) { |
110 | if (filter.tb) { | 111 | if (G_filter.tb) { |
111 | if (filter.tb < 0) { | 112 | if (G_filter.tb < 0) { |
112 | if (!(r->rtm_flags & RTM_F_CLONED)) { | 113 | if (!(r->rtm_flags & RTM_F_CLONED)) { |
113 | return 0; | 114 | return 0; |
114 | } | 115 | } |
@@ -116,11 +117,11 @@ static int FAST_FUNC print_route(const struct sockaddr_nl *who UNUSED_PARAM, | |||
116 | if (r->rtm_flags & RTM_F_CLONED) { | 117 | if (r->rtm_flags & RTM_F_CLONED) { |
117 | return 0; | 118 | return 0; |
118 | } | 119 | } |
119 | if (filter.tb == RT_TABLE_LOCAL) { | 120 | if (G_filter.tb == RT_TABLE_LOCAL) { |
120 | if (r->rtm_type != RTN_LOCAL) { | 121 | if (r->rtm_type != RTN_LOCAL) { |
121 | return 0; | 122 | return 0; |
122 | } | 123 | } |
123 | } else if (filter.tb == RT_TABLE_MAIN) { | 124 | } else if (G_filter.tb == RT_TABLE_MAIN) { |
124 | if (r->rtm_type == RTN_LOCAL) { | 125 | if (r->rtm_type == RTN_LOCAL) { |
125 | return 0; | 126 | return 0; |
126 | } | 127 | } |
@@ -130,72 +131,82 @@ static int FAST_FUNC print_route(const struct sockaddr_nl *who UNUSED_PARAM, | |||
130 | } | 131 | } |
131 | } | 132 | } |
132 | } else { | 133 | } else { |
133 | if (filter.tb > 0 && filter.tb != r->rtm_table) { | 134 | if (G_filter.tb > 0 && G_filter.tb != r->rtm_table) { |
134 | return 0; | 135 | return 0; |
135 | } | 136 | } |
136 | } | 137 | } |
137 | if (filter.rdst.family && | 138 | if (G_filter.rdst.family |
138 | (r->rtm_family != filter.rdst.family || filter.rdst.bitlen > r->rtm_dst_len)) { | 139 | && (r->rtm_family != G_filter.rdst.family || G_filter.rdst.bitlen > r->rtm_dst_len) |
140 | ) { | ||
139 | return 0; | 141 | return 0; |
140 | } | 142 | } |
141 | if (filter.mdst.family && | 143 | if (G_filter.mdst.family |
142 | (r->rtm_family != filter.mdst.family || | 144 | && (r->rtm_family != G_filter.mdst.family |
143 | (filter.mdst.bitlen >= 0 && filter.mdst.bitlen < r->rtm_dst_len))) { | 145 | || (G_filter.mdst.bitlen >= 0 && G_filter.mdst.bitlen < r->rtm_dst_len) |
146 | ) | ||
147 | ) { | ||
144 | return 0; | 148 | return 0; |
145 | } | 149 | } |
146 | if (filter.rsrc.family && | 150 | if (G_filter.rsrc.family |
147 | (r->rtm_family != filter.rsrc.family || filter.rsrc.bitlen > r->rtm_src_len)) { | 151 | && (r->rtm_family != G_filter.rsrc.family || G_filter.rsrc.bitlen > r->rtm_src_len) |
152 | ) { | ||
148 | return 0; | 153 | return 0; |
149 | } | 154 | } |
150 | if (filter.msrc.family && | 155 | if (G_filter.msrc.family |
151 | (r->rtm_family != filter.msrc.family || | 156 | && (r->rtm_family != G_filter.msrc.family |
152 | (filter.msrc.bitlen >= 0 && filter.msrc.bitlen < r->rtm_src_len))) { | 157 | || (G_filter.msrc.bitlen >= 0 && G_filter.msrc.bitlen < r->rtm_src_len) |
158 | ) | ||
159 | ) { | ||
153 | return 0; | 160 | return 0; |
154 | } | 161 | } |
155 | 162 | ||
156 | memset(tb, 0, sizeof(tb)); | 163 | memset(tb, 0, sizeof(tb)); |
157 | parse_rtattr(tb, RTA_MAX, RTM_RTA(r), len); | 164 | parse_rtattr(tb, RTA_MAX, RTM_RTA(r), len); |
158 | 165 | ||
159 | if (filter.rdst.family && inet_addr_match(&dst, &filter.rdst, filter.rdst.bitlen)) | 166 | if (G_filter.rdst.family && inet_addr_match(&dst, &G_filter.rdst, G_filter.rdst.bitlen)) |
160 | return 0; | 167 | return 0; |
161 | if (filter.mdst.family && filter.mdst.bitlen >= 0 && | 168 | if (G_filter.mdst.family && G_filter.mdst.bitlen >= 0 && |
162 | inet_addr_match(&dst, &filter.mdst, r->rtm_dst_len)) | 169 | inet_addr_match(&dst, &G_filter.mdst, r->rtm_dst_len)) |
163 | return 0; | 170 | return 0; |
164 | 171 | ||
165 | if (filter.rsrc.family && inet_addr_match(&src, &filter.rsrc, filter.rsrc.bitlen)) | 172 | if (G_filter.rsrc.family && inet_addr_match(&src, &G_filter.rsrc, G_filter.rsrc.bitlen)) |
166 | return 0; | 173 | return 0; |
167 | if (filter.msrc.family && filter.msrc.bitlen >= 0 && | 174 | if (G_filter.msrc.family && G_filter.msrc.bitlen >= 0 |
168 | inet_addr_match(&src, &filter.msrc, r->rtm_src_len)) | 175 | && inet_addr_match(&src, &G_filter.msrc, r->rtm_src_len) |
176 | ) { | ||
169 | return 0; | 177 | return 0; |
178 | } | ||
170 | 179 | ||
171 | if (filter.flushb && | 180 | if (G_filter.flushb |
172 | r->rtm_family == AF_INET6 && | 181 | && r->rtm_family == AF_INET6 |
173 | r->rtm_dst_len == 0 && | 182 | && r->rtm_dst_len == 0 |
174 | r->rtm_type == RTN_UNREACHABLE && | 183 | && r->rtm_type == RTN_UNREACHABLE |
175 | tb[RTA_PRIORITY] && | 184 | && tb[RTA_PRIORITY] |
176 | *(int*)RTA_DATA(tb[RTA_PRIORITY]) == -1) | 185 | && *(int*)RTA_DATA(tb[RTA_PRIORITY]) == -1 |
186 | ) { | ||
177 | return 0; | 187 | return 0; |
188 | } | ||
178 | 189 | ||
179 | if (filter.flushb) { | 190 | if (G_filter.flushb) { |
180 | struct nlmsghdr *fn; | 191 | struct nlmsghdr *fn; |
181 | if (NLMSG_ALIGN(filter.flushp) + n->nlmsg_len > filter.flushe) { | 192 | if (NLMSG_ALIGN(G_filter.flushp) + n->nlmsg_len > G_filter.flushe) { |
182 | if (flush_update()) | 193 | if (flush_update()) |
183 | bb_error_msg_and_die("flush"); | 194 | bb_error_msg_and_die("flush"); |
184 | } | 195 | } |
185 | fn = (struct nlmsghdr*)(filter.flushb + NLMSG_ALIGN(filter.flushp)); | 196 | fn = (struct nlmsghdr*)(G_filter.flushb + NLMSG_ALIGN(G_filter.flushp)); |
186 | memcpy(fn, n, n->nlmsg_len); | 197 | memcpy(fn, n, n->nlmsg_len); |
187 | fn->nlmsg_type = RTM_DELROUTE; | 198 | fn->nlmsg_type = RTM_DELROUTE; |
188 | fn->nlmsg_flags = NLM_F_REQUEST; | 199 | fn->nlmsg_flags = NLM_F_REQUEST; |
189 | fn->nlmsg_seq = ++filter.rth->seq; | 200 | fn->nlmsg_seq = ++G_filter.rth->seq; |
190 | filter.flushp = (((char*)fn) + n->nlmsg_len) - filter.flushb; | 201 | G_filter.flushp = (((char*)fn) + n->nlmsg_len) - G_filter.flushb; |
191 | filter.flushed = 1; | 202 | G_filter.flushed = 1; |
192 | return 0; | 203 | return 0; |
193 | } | 204 | } |
194 | 205 | ||
195 | if (n->nlmsg_type == RTM_DELROUTE) { | 206 | if (n->nlmsg_type == RTM_DELROUTE) { |
196 | printf("Deleted "); | 207 | printf("Deleted "); |
197 | } | 208 | } |
198 | if (r->rtm_type != RTN_UNICAST && !filter.type) { | 209 | if (r->rtm_type != RTN_UNICAST /* && !G_filter.type - always 0 */) { |
199 | printf("%s ", rtnl_rtntype_n2a(r->rtm_type, b1)); | 210 | printf("%s ", rtnl_rtntype_n2a(r->rtm_type, b1)); |
200 | } | 211 | } |
201 | 212 | ||
@@ -235,17 +246,17 @@ static int FAST_FUNC print_route(const struct sockaddr_nl *who UNUSED_PARAM, | |||
235 | } else if (r->rtm_src_len) { | 246 | } else if (r->rtm_src_len) { |
236 | printf("from 0/%u ", r->rtm_src_len); | 247 | printf("from 0/%u ", r->rtm_src_len); |
237 | } | 248 | } |
238 | if (tb[RTA_GATEWAY] && filter.rvia.bitlen != host_len) { | 249 | if (tb[RTA_GATEWAY] && G_filter.rvia.bitlen != host_len) { |
239 | printf("via %s ", format_host(r->rtm_family, | 250 | printf("via %s ", format_host(r->rtm_family, |
240 | RTA_PAYLOAD(tb[RTA_GATEWAY]), | 251 | RTA_PAYLOAD(tb[RTA_GATEWAY]), |
241 | RTA_DATA(tb[RTA_GATEWAY]), | 252 | RTA_DATA(tb[RTA_GATEWAY]), |
242 | abuf, sizeof(abuf))); | 253 | abuf, sizeof(abuf))); |
243 | } | 254 | } |
244 | if (tb[RTA_OIF] && filter.oifmask != -1) { | 255 | if (tb[RTA_OIF] && G_filter.oifmask != -1) { |
245 | printf("dev %s ", ll_index_to_name(*(int*)RTA_DATA(tb[RTA_OIF]))); | 256 | printf("dev %s ", ll_index_to_name(*(int*)RTA_DATA(tb[RTA_OIF]))); |
246 | } | 257 | } |
247 | 258 | ||
248 | if (tb[RTA_PREFSRC] && filter.rprefsrc.bitlen != host_len) { | 259 | if (tb[RTA_PREFSRC] && /*G_filter.rprefsrc.bitlen - always 0*/ 0 != host_len) { |
249 | /* Do not use format_host(). It is our local addr | 260 | /* Do not use format_host(). It is our local addr |
250 | and symbolic name will not be useful. | 261 | and symbolic name will not be useful. |
251 | */ | 262 | */ |
@@ -276,7 +287,7 @@ static int FAST_FUNC print_route(const struct sockaddr_nl *who UNUSED_PARAM, | |||
276 | printf(" error %d", ci->rta_error); | 287 | printf(" error %d", ci->rta_error); |
277 | } | 288 | } |
278 | } | 289 | } |
279 | if (tb[RTA_IIF] && filter.iifmask != -1) { | 290 | if (tb[RTA_IIF] && G_filter.iifmask != -1) { |
280 | printf(" iif %s", ll_index_to_name(*(int*)RTA_DATA(tb[RTA_IIF]))); | 291 | printf(" iif %s", ll_index_to_name(*(int*)RTA_DATA(tb[RTA_IIF]))); |
281 | } | 292 | } |
282 | bb_putchar('\n'); | 293 | bb_putchar('\n'); |
@@ -441,10 +452,13 @@ IF_FEATURE_IP_RULE(ARG_table,) | |||
441 | 452 | ||
442 | if (req.r.rtm_type == RTN_LOCAL || req.r.rtm_type == RTN_NAT) | 453 | if (req.r.rtm_type == RTN_LOCAL || req.r.rtm_type == RTN_NAT) |
443 | req.r.rtm_scope = RT_SCOPE_HOST; | 454 | req.r.rtm_scope = RT_SCOPE_HOST; |
444 | else if (req.r.rtm_type == RTN_BROADCAST || | 455 | else |
445 | req.r.rtm_type == RTN_MULTICAST || | 456 | if (req.r.rtm_type == RTN_BROADCAST |
446 | req.r.rtm_type == RTN_ANYCAST) | 457 | || req.r.rtm_type == RTN_MULTICAST |
458 | || req.r.rtm_type == RTN_ANYCAST | ||
459 | ) { | ||
447 | req.r.rtm_scope = RT_SCOPE_LINK; | 460 | req.r.rtm_scope = RT_SCOPE_LINK; |
461 | } | ||
448 | else if (req.r.rtm_type == RTN_UNICAST || req.r.rtm_type == RTN_UNSPEC) { | 462 | else if (req.r.rtm_type == RTN_UNICAST || req.r.rtm_type == RTN_UNSPEC) { |
449 | if (cmd == RTM_DELROUTE) | 463 | if (cmd == RTM_DELROUTE) |
450 | req.r.rtm_scope = RT_SCOPE_NOWHERE; | 464 | req.r.rtm_scope = RT_SCOPE_NOWHERE; |
@@ -507,9 +521,9 @@ static void iproute_flush_cache(void) | |||
507 | 521 | ||
508 | static void iproute_reset_filter(void) | 522 | static void iproute_reset_filter(void) |
509 | { | 523 | { |
510 | memset(&filter, 0, sizeof(filter)); | 524 | memset(&G_filter, 0, sizeof(G_filter)); |
511 | filter.mdst.bitlen = -1; | 525 | G_filter.mdst.bitlen = -1; |
512 | filter.msrc.bitlen = -1; | 526 | G_filter.msrc.bitlen = -1; |
513 | } | 527 | } |
514 | 528 | ||
515 | /* Return value becomes exitcode. It's okay to not return at all */ | 529 | /* Return value becomes exitcode. It's okay to not return at all */ |
@@ -545,7 +559,7 @@ static int iproute_list_or_flush(char **argv, int flush) | |||
545 | int arg, parm; | 559 | int arg, parm; |
546 | 560 | ||
547 | iproute_reset_filter(); | 561 | iproute_reset_filter(); |
548 | filter.tb = RT_TABLE_MAIN; | 562 | G_filter.tb = RT_TABLE_MAIN; |
549 | 563 | ||
550 | if (flush && !*argv) | 564 | if (flush && !*argv) |
551 | bb_error_msg_and_die(bb_msg_requires_arg, "\"ip route flush\""); | 565 | bb_error_msg_and_die(bb_msg_requires_arg, "\"ip route flush\""); |
@@ -555,14 +569,14 @@ static int iproute_list_or_flush(char **argv, int flush) | |||
555 | if (arg == KW_proto) { | 569 | if (arg == KW_proto) { |
556 | uint32_t prot = 0; | 570 | uint32_t prot = 0; |
557 | NEXT_ARG(); | 571 | NEXT_ARG(); |
558 | filter.protocolmask = -1; | 572 | //G_filter.protocolmask = -1; |
559 | if (rtnl_rtprot_a2n(&prot, *argv)) { | 573 | if (rtnl_rtprot_a2n(&prot, *argv)) { |
560 | if (index_in_strings(keywords, *argv) != KW_all) | 574 | if (index_in_strings(keywords, *argv) != KW_all) |
561 | invarg(*argv, "protocol"); | 575 | invarg(*argv, "protocol"); |
562 | prot = 0; | 576 | prot = 0; |
563 | filter.protocolmask = 0; | 577 | //G_filter.protocolmask = 0; |
564 | } | 578 | } |
565 | filter.protocol = prot; | 579 | //G_filter.protocol = prot; |
566 | } else if (arg == KW_dev || arg == KW_oif) { | 580 | } else if (arg == KW_dev || arg == KW_oif) { |
567 | NEXT_ARG(); | 581 | NEXT_ARG(); |
568 | od = *argv; | 582 | od = *argv; |
@@ -571,20 +585,20 @@ static int iproute_list_or_flush(char **argv, int flush) | |||
571 | id = *argv; | 585 | id = *argv; |
572 | } else if (arg == KW_via) { | 586 | } else if (arg == KW_via) { |
573 | NEXT_ARG(); | 587 | NEXT_ARG(); |
574 | get_prefix(&filter.rvia, *argv, do_ipv6); | 588 | get_prefix(&G_filter.rvia, *argv, do_ipv6); |
575 | } else if (arg == KW_table) { /* table all/cache/main */ | 589 | } else if (arg == KW_table) { /* table all/cache/main */ |
576 | NEXT_ARG(); | 590 | NEXT_ARG(); |
577 | parm = index_in_substrings(keywords, *argv); | 591 | parm = index_in_substrings(keywords, *argv); |
578 | if (parm == KW_cache) | 592 | if (parm == KW_cache) |
579 | filter.tb = -1; | 593 | G_filter.tb = -1; |
580 | else if (parm == KW_all) | 594 | else if (parm == KW_all) |
581 | filter.tb = 0; | 595 | G_filter.tb = 0; |
582 | else if (parm != KW_main) { | 596 | else if (parm != KW_main) { |
583 | #if ENABLE_FEATURE_IP_RULE | 597 | #if ENABLE_FEATURE_IP_RULE |
584 | uint32_t tid; | 598 | uint32_t tid; |
585 | if (rtnl_rttable_a2n(&tid, *argv)) | 599 | if (rtnl_rttable_a2n(&tid, *argv)) |
586 | invarg(*argv, "table"); | 600 | invarg(*argv, "table"); |
587 | filter.tb = tid; | 601 | G_filter.tb = tid; |
588 | #else | 602 | #else |
589 | invarg(*argv, "table"); | 603 | invarg(*argv, "table"); |
590 | #endif | 604 | #endif |
@@ -592,21 +606,21 @@ static int iproute_list_or_flush(char **argv, int flush) | |||
592 | } else if (arg == KW_cache) { | 606 | } else if (arg == KW_cache) { |
593 | /* The command 'ip route flush cache' is used by OpenSWAN. | 607 | /* The command 'ip route flush cache' is used by OpenSWAN. |
594 | * Assuming it's a synonym for 'ip route flush table cache' */ | 608 | * Assuming it's a synonym for 'ip route flush table cache' */ |
595 | filter.tb = -1; | 609 | G_filter.tb = -1; |
596 | } else if (arg == KW_from) { | 610 | } else if (arg == KW_from) { |
597 | NEXT_ARG(); | 611 | NEXT_ARG(); |
598 | parm = index_in_substrings(keywords, *argv); | 612 | parm = index_in_substrings(keywords, *argv); |
599 | if (parm == KW_root) { | 613 | if (parm == KW_root) { |
600 | NEXT_ARG(); | 614 | NEXT_ARG(); |
601 | get_prefix(&filter.rsrc, *argv, do_ipv6); | 615 | get_prefix(&G_filter.rsrc, *argv, do_ipv6); |
602 | } else if (parm == KW_match) { | 616 | } else if (parm == KW_match) { |
603 | NEXT_ARG(); | 617 | NEXT_ARG(); |
604 | get_prefix(&filter.msrc, *argv, do_ipv6); | 618 | get_prefix(&G_filter.msrc, *argv, do_ipv6); |
605 | } else { | 619 | } else { |
606 | if (parm == KW_exact) | 620 | if (parm == KW_exact) |
607 | NEXT_ARG(); | 621 | NEXT_ARG(); |
608 | get_prefix(&filter.msrc, *argv, do_ipv6); | 622 | get_prefix(&G_filter.msrc, *argv, do_ipv6); |
609 | filter.rsrc = filter.msrc; | 623 | G_filter.rsrc = G_filter.msrc; |
610 | } | 624 | } |
611 | } else { /* "to" is the default parameter */ | 625 | } else { /* "to" is the default parameter */ |
612 | if (arg == KW_to) { | 626 | if (arg == KW_to) { |
@@ -616,21 +630,21 @@ static int iproute_list_or_flush(char **argv, int flush) | |||
616 | /* parm = arg; - would be more plausible, but we reuse 'arg' here */ | 630 | /* parm = arg; - would be more plausible, but we reuse 'arg' here */ |
617 | if (arg == KW_root) { | 631 | if (arg == KW_root) { |
618 | NEXT_ARG(); | 632 | NEXT_ARG(); |
619 | get_prefix(&filter.rdst, *argv, do_ipv6); | 633 | get_prefix(&G_filter.rdst, *argv, do_ipv6); |
620 | } else if (arg == KW_match) { | 634 | } else if (arg == KW_match) { |
621 | NEXT_ARG(); | 635 | NEXT_ARG(); |
622 | get_prefix(&filter.mdst, *argv, do_ipv6); | 636 | get_prefix(&G_filter.mdst, *argv, do_ipv6); |
623 | } else { /* "to exact" is the default */ | 637 | } else { /* "to exact" is the default */ |
624 | if (arg == KW_exact) | 638 | if (arg == KW_exact) |
625 | NEXT_ARG(); | 639 | NEXT_ARG(); |
626 | get_prefix(&filter.mdst, *argv, do_ipv6); | 640 | get_prefix(&G_filter.mdst, *argv, do_ipv6); |
627 | filter.rdst = filter.mdst; | 641 | G_filter.rdst = G_filter.mdst; |
628 | } | 642 | } |
629 | } | 643 | } |
630 | argv++; | 644 | argv++; |
631 | } | 645 | } |
632 | 646 | ||
633 | if (do_ipv6 == AF_UNSPEC && filter.tb) { | 647 | if (do_ipv6 == AF_UNSPEC && G_filter.tb) { |
634 | do_ipv6 = AF_INET; | 648 | do_ipv6 = AF_INET; |
635 | } | 649 | } |
636 | 650 | ||
@@ -642,43 +656,43 @@ static int iproute_list_or_flush(char **argv, int flush) | |||
642 | 656 | ||
643 | if (id) { | 657 | if (id) { |
644 | idx = xll_name_to_index(id); | 658 | idx = xll_name_to_index(id); |
645 | filter.iif = idx; | 659 | G_filter.iif = idx; |
646 | filter.iifmask = -1; | 660 | G_filter.iifmask = -1; |
647 | } | 661 | } |
648 | if (od) { | 662 | if (od) { |
649 | idx = xll_name_to_index(od); | 663 | idx = xll_name_to_index(od); |
650 | filter.oif = idx; | 664 | G_filter.oif = idx; |
651 | filter.oifmask = -1; | 665 | G_filter.oifmask = -1; |
652 | } | 666 | } |
653 | } | 667 | } |
654 | 668 | ||
655 | if (flush) { | 669 | if (flush) { |
656 | char flushb[4096-512]; | 670 | char flushb[4096-512]; |
657 | 671 | ||
658 | if (filter.tb == -1) { /* "flush table cache" */ | 672 | if (G_filter.tb == -1) { /* "flush table cache" */ |
659 | if (do_ipv6 != AF_INET6) | 673 | if (do_ipv6 != AF_INET6) |
660 | iproute_flush_cache(); | 674 | iproute_flush_cache(); |
661 | if (do_ipv6 == AF_INET) | 675 | if (do_ipv6 == AF_INET) |
662 | return 0; | 676 | return 0; |
663 | } | 677 | } |
664 | 678 | ||
665 | filter.flushb = flushb; | 679 | G_filter.flushb = flushb; |
666 | filter.flushp = 0; | 680 | G_filter.flushp = 0; |
667 | filter.flushe = sizeof(flushb); | 681 | G_filter.flushe = sizeof(flushb); |
668 | filter.rth = &rth; | 682 | G_filter.rth = &rth; |
669 | 683 | ||
670 | for (;;) { | 684 | for (;;) { |
671 | xrtnl_wilddump_request(&rth, do_ipv6, RTM_GETROUTE); | 685 | xrtnl_wilddump_request(&rth, do_ipv6, RTM_GETROUTE); |
672 | filter.flushed = 0; | 686 | G_filter.flushed = 0; |
673 | xrtnl_dump_filter(&rth, print_route, NULL); | 687 | xrtnl_dump_filter(&rth, print_route, NULL); |
674 | if (filter.flushed == 0) | 688 | if (G_filter.flushed == 0) |
675 | return 0; | 689 | return 0; |
676 | if (flush_update()) | 690 | if (flush_update()) |
677 | return 1; | 691 | return 1; |
678 | } | 692 | } |
679 | } | 693 | } |
680 | 694 | ||
681 | if (filter.tb != -1) { | 695 | if (G_filter.tb != -1) { |
682 | xrtnl_wilddump_request(&rth, do_ipv6, RTM_GETROUTE); | 696 | xrtnl_wilddump_request(&rth, do_ipv6, RTM_GETROUTE); |
683 | } else if (rtnl_rtcache_request(&rth, do_ipv6) < 0) { | 697 | } else if (rtnl_rtcache_request(&rth, do_ipv6) < 0) { |
684 | bb_perror_msg_and_die("can't send dump request"); | 698 | bb_perror_msg_and_die("can't send dump request"); |