Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/networking/libiproute
- Timestamp:
- Dec 20, 2016, 4:07:32 PM (7 years ago)
- Location:
- branches/3.3
- Files:
-
- 1 added
- 1 deleted
- 19 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3/mindi-busybox/networking/libiproute/Kbuild.src
r2725 r3621 65 65 rt_names.o \ 66 66 utils.o 67 68 lib-$(CONFIG_FEATURE_IP_NEIGH) += \ 69 ip_parse_common_args.o \ 70 ipneigh.o \ 71 libnetlink.o \ 72 ll_map.o \ 73 rt_names.o \ 74 utils.o -
branches/3.3/mindi-busybox/networking/libiproute/ip_common.h
r2725 r3621 25 25 int FAST_FUNC do_iproute(char **argv); 26 26 int FAST_FUNC do_iprule(char **argv); 27 //int FAST_FUNC do_ipneigh(char **argv);27 int FAST_FUNC do_ipneigh(char **argv); 28 28 int FAST_FUNC do_iptunnel(char **argv); 29 29 int FAST_FUNC do_iplink(char **argv); -
branches/3.3/mindi-busybox/networking/libiproute/ip_parse_common_args.c
r2725 r3621 68 68 arg = index_in_strings(families, *argv); 69 69 if (arg < 0) 70 invarg (*argv, "protocolfamily");70 invarg_1_to_2(*argv, "family"); 71 71 /* now arg == 0, 1 or 2 */ 72 72 } else { -
branches/3.3/mindi-busybox/networking/libiproute/ipaddress.c
r3232 r3621 14 14 15 15 #include "ip_common.h" /* #include "libbb.h" is inside */ 16 #include "common_bufsiz.h" 16 17 #include "rt_names.h" 17 18 #include "utils.h" … … 40 41 typedef struct filter_t filter_t; 41 42 42 #define G_filter (*(filter_t*) &bb_common_bufsiz1)43 43 #define G_filter (*(filter_t*)bb_common_bufsiz1) 44 #define INIT_G() do { setup_common_bufsiz(); } while (0) 44 45 45 46 static void print_link_flags(unsigned flags, unsigned mdown) … … 138 139 unsigned m_flag = 0; 139 140 if (tb[IFLA_LINK]) { 140 SPRINT_BUF(b1);141 141 int iflink = *(int*)RTA_DATA(tb[IFLA_LINK]); 142 142 if (iflink == 0) 143 143 printf("@NONE: "); 144 144 else { 145 printf("@%s: ", ll_i dx_n2a(iflink, b1));145 printf("@%s: ", ll_index_to_name(iflink)); 146 146 m_flag = ll_index_to_flags(iflink); 147 147 m_flag = !(m_flag & IFF_UP); … … 159 159 #ifdef IFLA_MASTER 160 160 if (tb[IFLA_MASTER]) { 161 SPRINT_BUF(b1); 162 printf("master %s ", ll_idx_n2a(*(int*)RTA_DATA(tb[IFLA_MASTER]), b1)); 161 printf("master %s ", ll_index_to_name(*(int*)RTA_DATA(tb[IFLA_MASTER]))); 163 162 } 164 163 #endif … … 217 216 struct ifaddrmsg *ifa = NLMSG_DATA(n); 218 217 int len = n->nlmsg_len; 219 struct rtattr * rta_tb[IFA_MAX+1]; 220 char abuf[256]; 221 SPRINT_BUF(b1); 218 struct rtattr *rta_tb[IFA_MAX+1]; 222 219 223 220 if (n->nlmsg_type != RTM_NEWADDR && n->nlmsg_type != RTM_DELADDR) … … 251 248 label = RTA_DATA(rta_tb[IFA_LABEL]); 252 249 else 253 label = ll_i dx_n2a(ifa->ifa_index, b1);250 label = ll_index_to_name(ifa->ifa_index); 254 251 if (fnmatch(G_filter.label, label, 0) != 0) 255 252 return 0; … … 295 292 296 293 if (rta_tb[IFA_LOCAL]) { 297 fputs(rt_addr_n2a(ifa->ifa_family, 298 RTA_DATA(rta_tb[IFA_LOCAL]),299 abuf, sizeof(abuf)), stdout);294 fputs(rt_addr_n2a(ifa->ifa_family, RTA_DATA(rta_tb[IFA_LOCAL])), 295 stdout 296 ); 300 297 301 298 if (rta_tb[IFA_ADDRESS] == NULL … … 305 302 } else { 306 303 printf(" peer %s/%d ", 307 rt_addr_n2a(ifa->ifa_family, 308 RTA_DATA(rta_tb[IFA_ADDRESS]), 309 abuf, sizeof(abuf)), 310 ifa->ifa_prefixlen); 304 rt_addr_n2a(ifa->ifa_family, RTA_DATA(rta_tb[IFA_ADDRESS])), 305 ifa->ifa_prefixlen 306 ); 311 307 } 312 308 } … … 315 311 printf("brd %s ", 316 312 rt_addr_n2a(ifa->ifa_family, 317 RTA_DATA(rta_tb[IFA_BROADCAST]), 318 abuf, sizeof(abuf)) 313 RTA_DATA(rta_tb[IFA_BROADCAST])) 319 314 ); 320 315 } … … 322 317 printf("any %s ", 323 318 rt_addr_n2a(ifa->ifa_family, 324 RTA_DATA(rta_tb[IFA_ANYCAST]), 325 abuf, sizeof(abuf)) 319 RTA_DATA(rta_tb[IFA_ANYCAST])) 326 320 ); 327 321 } 328 printf("scope %s ", rtnl_rtscope_n2a(ifa->ifa_scope , b1));322 printf("scope %s ", rtnl_rtscope_n2a(ifa->ifa_scope)); 329 323 if (ifa->ifa_flags & IFA_F_SECONDARY) { 330 324 ifa->ifa_flags &= ~IFA_F_SECONDARY; … … 459 453 if (rtnl_rtscope_a2n(&scope, *argv)) { 460 454 if (strcmp(*argv, "all") != 0) { 461 invarg (*argv, "scope");455 invarg_1_to_2(*argv, "scope"); 462 456 } 463 457 scope = RT_SCOPE_NOWHERE; … … 557 551 } 558 552 if (G_filter.label) { 559 SPRINT_BUF(b1);560 553 const char *label; 561 554 if (tb[IFA_LABEL]) 562 555 label = RTA_DATA(tb[IFA_LABEL]); 563 556 else 564 label = ll_i dx_n2a(ifa->ifa_index, b1);557 label = ll_index_to_name(ifa->ifa_index); 565 558 if (fnmatch(G_filter.label, label, 0) != 0) 566 559 continue; … … 599 592 600 593 /* Return value becomes exitcode. It's okay to not return at all */ 601 static int ipaddr_modify(int cmd, char **argv)594 static int ipaddr_modify(int cmd, int flags, char **argv) 602 595 { 603 596 static const char option[] ALIGN1 = … … 623 616 624 617 req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg)); 625 req.n.nlmsg_flags = NLM_F_REQUEST ;618 req.n.nlmsg_flags = NLM_F_REQUEST | flags; 626 619 req.n.nlmsg_type = cmd; 627 620 req.ifa.ifa_family = preferred_family; 628 621 629 622 while (*argv) { 630 const smalluint arg = index_in_strings(option, *argv); 623 unsigned arg = index_in_strings(option, *argv); 624 /* if search fails, "local" is assumed */ 625 if ((int)arg >= 0) 626 NEXT_ARG(); 627 631 628 if (arg <= 1) { /* peer, remote */ 632 NEXT_ARG();633 634 629 if (peer_len) { 635 630 duparg("peer", *argv); … … 644 639 } else if (arg <= 3) { /* broadcast, brd */ 645 640 inet_prefix addr; 646 NEXT_ARG();647 641 if (brd_len) { 648 642 duparg("broadcast", *argv); … … 661 655 } else if (arg == 4) { /* anycast */ 662 656 inet_prefix addr; 663 NEXT_ARG();664 657 if (any_len) { 665 658 duparg("anycast", *argv); … … 673 666 } else if (arg == 5) { /* scope */ 674 667 uint32_t scope = 0; 675 NEXT_ARG();676 668 if (rtnl_rtscope_a2n(&scope, *argv)) { 677 invarg (*argv, "scope");669 invarg_1_to_2(*argv, "scope"); 678 670 } 679 671 req.ifa.ifa_scope = scope; 680 672 scoped = 1; 681 673 } else if (arg == 6) { /* dev */ 682 NEXT_ARG();683 674 d = *argv; 684 675 } else if (arg == 7) { /* label */ 685 NEXT_ARG();686 676 l = *argv; 687 677 addattr_l(&req.n, sizeof(req), IFA_LABEL, l, strlen(l) + 1); 688 678 } else { 689 if (arg == 8) /* local */ 690 NEXT_ARG(); 679 /* local (specified or assumed) */ 691 680 if (local_len) { 692 681 duparg2("local", *argv); … … 706 695 bb_error_msg_and_die("need \"dev IFACE\""); 707 696 } 708 if (l && strncmp(d, l, strlen(d)) != 0) {697 if (l && !is_prefixed_with(l, d)) { 709 698 bb_error_msg_and_die("\"dev\" (%s) must match \"label\" (%s)", d, l); 710 699 } … … 725 714 brd = peer; 726 715 if (brd.bitlen <= 30) { 727 for (i =31; i>=brd.bitlen; i--) {716 for (i = 31; i >= brd.bitlen; i--) { 728 717 if (brd_len == -1) 729 718 brd.data[0] |= htonl(1<<(31-i)); … … 754 743 { 755 744 static const char commands[] ALIGN1 = 756 "add\0""delete\0""list\0""show\0""lst\0""flush\0"; 757 smalluint cmd = 2; 745 /* 0 1 2 3 4 5 6 7 8 */ 746 "add\0""change\0""chg\0""replace\0""delete\0""list\0""show\0""lst\0""flush\0"; 747 int cmd = 2; 748 749 INIT_G(); 750 758 751 if (*argv) { 759 752 cmd = index_in_substrings(commands, *argv); 760 if (cmd > 5)761 bb_error_msg_and_die(bb_msg_invalid_arg,*argv, applet_name);753 if (cmd < 0) 754 invarg_1_to_2(*argv, applet_name); 762 755 argv++; 763 if (cmd <= 1) 764 return ipaddr_modify((cmd == 0) ? RTM_NEWADDR : RTM_DELADDR, argv); 765 } 766 /* 2 == list, 3 == show, 4 == lst */ 767 return ipaddr_list_or_flush(argv, cmd == 5); 768 } 756 if (cmd <= 4) { 757 return ipaddr_modify( 758 /*cmd:*/ cmd == 4 ? RTM_DELADDR : RTM_NEWADDR, 759 /*flags:*/ 760 cmd == 0 ? NLM_F_CREATE|NLM_F_EXCL : /* add */ 761 cmd == 1 || cmd == 2 ? NLM_F_REPLACE : /* change */ 762 cmd == 3 ? NLM_F_CREATE|NLM_F_REPLACE : /* replace */ 763 0 /* delete */ 764 , argv); 765 } 766 } 767 return ipaddr_list_or_flush(argv, cmd == 8); 768 } -
branches/3.3/mindi-busybox/networking/libiproute/iplink.c
r3232 r3621 2 2 /* 3 3 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> 4 * Patrick McHardy <kaber@trash.net> 4 5 * 5 6 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 6 7 */ 7 8 #include <net/if.h> 8 #include <net/if_packet.h> 9 /*#include <net/if_packet.h> - not needed? */ 9 10 #include <netpacket/packet.h> 10 11 #include <netinet/if_ether.h> 11 12 13 #include <linux/if_vlan.h> 12 14 #include "ip_common.h" /* #include "libbb.h" is inside */ 13 15 #include "rt_names.h" 14 16 #include "utils.h" 15 17 18 #undef ETH_P_8021AD 19 #define ETH_P_8021AD 0x88A8 20 #undef VLAN_FLAG_REORDER_HDR 21 #define VLAN_FLAG_REORDER_HDR 0x1 22 #undef VLAN_FLAG_GVRP 23 #define VLAN_FLAG_GVRP 0x2 24 #undef VLAN_FLAG_LOOSE_BINDING 25 #define VLAN_FLAG_LOOSE_BINDING 0x4 26 #undef VLAN_FLAG_MVRP 27 #define VLAN_FLAG_MVRP 0x8 28 #undef IFLA_VLAN_PROTOCOL 29 #define IFLA_VLAN_PROTOCOL 5 30 16 31 #ifndef IFLA_LINKINFO 17 32 # define IFLA_LINKINFO 18 18 33 # define IFLA_INFO_KIND 1 34 # define IFLA_INFO_DATA 2 35 #endif 36 37 #ifndef IFLA_VLAN_MAX 38 # define IFLA_VLAN_ID 1 39 # define IFLA_VLAN_FLAGS 2 40 struct ifla_vlan_flags { 41 uint32_t flags; 42 uint32_t mask; 43 }; 19 44 #endif 20 45 21 46 /* taken from linux/sockios.h */ 22 47 #define SIOCSIFNAME 0x8923 /* set interface name */ 48 49 #if 0 50 # define dbg(...) bb_error_msg(__VA_ARGS__) 51 #else 52 # define dbg(...) ((void)0) 53 #endif 23 54 24 55 /* Exits on error */ … … 278 309 } 279 310 311 static void vlan_parse_opt(char **argv, struct nlmsghdr *n, unsigned int size) 312 { 313 static const char keywords[] ALIGN1 = 314 "id\0" 315 "protocol\0" 316 "reorder_hdr\0" 317 "gvrp\0" 318 "mvrp\0" 319 "loose_binding\0" 320 ; 321 static const char protocols[] ALIGN1 = 322 "802.1q\0" 323 "802.1ad\0" 324 ; 325 static const char str_on_off[] ALIGN1 = 326 "on\0" 327 "off\0" 328 ; 329 enum { 330 ARG_id = 0, 331 ARG_reorder_hdr, 332 ARG_gvrp, 333 ARG_mvrp, 334 ARG_loose_binding, 335 ARG_protocol, 336 }; 337 enum { 338 PROTO_8021Q = 0, 339 PROTO_8021AD, 340 }; 341 enum { 342 PARM_on = 0, 343 PARM_off 344 }; 345 int arg; 346 uint16_t id, proto; 347 struct ifla_vlan_flags flags = {}; 348 349 while (*argv) { 350 arg = index_in_substrings(keywords, *argv); 351 if (arg < 0) 352 invarg_1_to_2(*argv, "type vlan"); 353 354 NEXT_ARG(); 355 if (arg == ARG_id) { 356 id = get_u16(*argv, "id"); 357 addattr_l(n, size, IFLA_VLAN_ID, &id, sizeof(id)); 358 } else if (arg == ARG_protocol) { 359 arg = index_in_substrings(protocols, *argv); 360 if (arg == PROTO_8021Q) 361 proto = ETH_P_8021Q; 362 else if (arg == PROTO_8021AD) 363 proto = ETH_P_8021AD; 364 else 365 bb_error_msg_and_die("unknown VLAN encapsulation protocol '%s'", 366 *argv); 367 addattr_l(n, size, IFLA_VLAN_PROTOCOL, &proto, sizeof(proto)); 368 } else { 369 int param = index_in_strings(str_on_off, *argv); 370 if (param < 0) 371 die_must_be_on_off(nth_string(keywords, arg)); 372 373 if (arg == ARG_reorder_hdr) { 374 flags.mask |= VLAN_FLAG_REORDER_HDR; 375 flags.flags &= ~VLAN_FLAG_REORDER_HDR; 376 if (param == PARM_on) 377 flags.flags |= VLAN_FLAG_REORDER_HDR; 378 } else if (arg == ARG_gvrp) { 379 flags.mask |= VLAN_FLAG_GVRP; 380 flags.flags &= ~VLAN_FLAG_GVRP; 381 if (param == PARM_on) 382 flags.flags |= VLAN_FLAG_GVRP; 383 } else if (arg == ARG_mvrp) { 384 flags.mask |= VLAN_FLAG_MVRP; 385 flags.flags &= ~VLAN_FLAG_MVRP; 386 if (param == PARM_on) 387 flags.flags |= VLAN_FLAG_MVRP; 388 } else { /*if (arg == ARG_loose_binding) */ 389 flags.mask |= VLAN_FLAG_LOOSE_BINDING; 390 flags.flags &= ~VLAN_FLAG_LOOSE_BINDING; 391 if (param == PARM_on) 392 flags.flags |= VLAN_FLAG_LOOSE_BINDING; 393 } 394 } 395 argv++; 396 } 397 398 if (flags.mask) 399 addattr_l(n, size, IFLA_VLAN_FLAGS, &flags, sizeof(flags)); 400 } 401 280 402 #ifndef NLMSG_TAIL 281 403 #define NLMSG_TAIL(nmsg) \ … … 283 405 #endif 284 406 /* Return value becomes exitcode. It's okay to not return at all */ 285 static int do_ change(char **argv, const unsigned rtm)407 static int do_add_or_delete(char **argv, const unsigned rtm) 286 408 { 287 409 static const char keywords[] ALIGN1 = 288 "link\0""name\0""type\0""dev\0" ;410 "link\0""name\0""type\0""dev\0""address\0"; 289 411 enum { 290 412 ARG_link, … … 292 414 ARG_type, 293 415 ARG_dev, 416 ARG_address, 294 417 }; 295 418 struct rtnl_handle rth; … … 300 423 } req; 301 424 smalluint arg; 302 char *name_str = NULL, *link_str = NULL, *type_str = NULL, *dev_str = NULL; 425 char *name_str = NULL; 426 char *link_str = NULL; 427 char *type_str = NULL; 428 char *dev_str = NULL; 429 char *address_str = NULL; 303 430 304 431 memset(&req, 0, sizeof(req)); … … 313 440 while (*argv) { 314 441 arg = index_in_substrings(keywords, *argv); 442 if (arg == ARG_type) { 443 NEXT_ARG(); 444 type_str = *argv++; 445 dbg("type_str:'%s'", type_str); 446 break; 447 } 315 448 if (arg == ARG_link) { 316 449 NEXT_ARG(); 317 450 link_str = *argv; 451 dbg("link_str:'%s'", link_str); 318 452 } else if (arg == ARG_name) { 319 453 NEXT_ARG(); 320 454 name_str = *argv; 321 } else if (arg == ARG_type) { 322 NEXT_ARG(); 323 type_str = *argv; 455 dbg("name_str:'%s'", name_str); 456 } else if (arg == ARG_address) { 457 NEXT_ARG(); 458 address_str = *argv; 459 dbg("address_str:'%s'", name_str); 324 460 } else { 325 461 if (arg == ARG_dev) { … … 329 465 } 330 466 dev_str = *argv; 467 dbg("dev_str:'%s'", dev_str); 331 468 } 332 469 argv++; … … 340 477 addattr_l(&req.n, sizeof(req), IFLA_INFO_KIND, type_str, 341 478 strlen(type_str)); 479 480 if (*argv) { 481 struct rtattr *data = NLMSG_TAIL(&req.n); 482 addattr_l(&req.n, sizeof(req), IFLA_INFO_DATA, NULL, 0); 483 484 if (strcmp(type_str, "vlan") == 0) 485 vlan_parse_opt(argv, &req.n, sizeof(req)); 486 487 data->rta_len = (void *)NLMSG_TAIL(&req.n) - (void *)data; 488 } 489 342 490 linkinfo->rta_len = (void *)NLMSG_TAIL(&req.n) - (void *)linkinfo; 343 491 } … … 353 501 addattr_l(&req.n, sizeof(req), IFLA_LINK, &idx, 4); 354 502 } 503 if (address_str) { 504 unsigned char abuf[32]; 505 int len = ll_addr_a2n(abuf, sizeof(abuf), address_str); 506 dbg("address len:%d", len); 507 if (len < 0) 508 return -1; 509 addattr_l(&req.n, sizeof(req), IFLA_ADDRESS, abuf, len); 510 } 355 511 } 356 512 if (name_str) { 357 513 const size_t name_len = strlen(name_str) + 1; 358 514 if (name_len < 2 || name_len > IFNAMSIZ) 359 invarg (name_str, "name");515 invarg_1_to_2(name_str, "name"); 360 516 addattr_l(&req.n, sizeof(req), IFLA_IFNAME, name_str, name_len); 361 517 } … … 365 521 } 366 522 523 /* Other keywords recognized by iproute2-3.12.0: */ 524 #if 0 525 } else if (matches(*argv, "broadcast") == 0 || 526 strcmp(*argv, "brd") == 0) { 527 NEXT_ARG(); 528 len = ll_addr_a2n(abuf, sizeof(abuf), *argv); 529 if (len < 0) 530 return -1; 531 addattr_l(&req->n, sizeof(*req), IFLA_BROADCAST, abuf, len); 532 } else if (matches(*argv, "txqueuelen") == 0 || 533 strcmp(*argv, "qlen") == 0 || 534 matches(*argv, "txqlen") == 0) { 535 NEXT_ARG(); 536 if (qlen != -1) 537 duparg("txqueuelen", *argv); 538 if (get_integer(&qlen, *argv, 0)) 539 invarg_1_to_2(*argv, "txqueuelen"); 540 addattr_l(&req->n, sizeof(*req), IFLA_TXQLEN, &qlen, 4); 541 } else if (strcmp(*argv, "mtu") == 0) { 542 NEXT_ARG(); 543 if (mtu != -1) 544 duparg("mtu", *argv); 545 if (get_integer(&mtu, *argv, 0)) 546 invarg_1_to_2(*argv, "mtu"); 547 addattr_l(&req->n, sizeof(*req), IFLA_MTU, &mtu, 4); 548 } else if (strcmp(*argv, "netns") == 0) { 549 NEXT_ARG(); 550 if (netns != -1) 551 duparg("netns", *argv); 552 if ((netns = get_netns_fd(*argv)) >= 0) 553 addattr_l(&req->n, sizeof(*req), IFLA_NET_NS_FD, &netns, 4); 554 else if (get_integer(&netns, *argv, 0) == 0) 555 addattr_l(&req->n, sizeof(*req), IFLA_NET_NS_PID, &netns, 4); 556 else 557 invarg_1_to_2(*argv, "netns"); 558 } else if (strcmp(*argv, "multicast") == 0) { 559 NEXT_ARG(); 560 req->i.ifi_change |= IFF_MULTICAST; 561 if (strcmp(*argv, "on") == 0) { 562 req->i.ifi_flags |= IFF_MULTICAST; 563 } else if (strcmp(*argv, "off") == 0) { 564 req->i.ifi_flags &= ~IFF_MULTICAST; 565 } else 566 return on_off("multicast", *argv); 567 } else if (strcmp(*argv, "allmulticast") == 0) { 568 NEXT_ARG(); 569 req->i.ifi_change |= IFF_ALLMULTI; 570 if (strcmp(*argv, "on") == 0) { 571 req->i.ifi_flags |= IFF_ALLMULTI; 572 } else if (strcmp(*argv, "off") == 0) { 573 req->i.ifi_flags &= ~IFF_ALLMULTI; 574 } else 575 return on_off("allmulticast", *argv); 576 } else if (strcmp(*argv, "promisc") == 0) { 577 NEXT_ARG(); 578 req->i.ifi_change |= IFF_PROMISC; 579 if (strcmp(*argv, "on") == 0) { 580 req->i.ifi_flags |= IFF_PROMISC; 581 } else if (strcmp(*argv, "off") == 0) { 582 req->i.ifi_flags &= ~IFF_PROMISC; 583 } else 584 return on_off("promisc", *argv); 585 } else if (strcmp(*argv, "trailers") == 0) { 586 NEXT_ARG(); 587 req->i.ifi_change |= IFF_NOTRAILERS; 588 if (strcmp(*argv, "off") == 0) { 589 req->i.ifi_flags |= IFF_NOTRAILERS; 590 } else if (strcmp(*argv, "on") == 0) { 591 req->i.ifi_flags &= ~IFF_NOTRAILERS; 592 } else 593 return on_off("trailers", *argv); 594 } else if (strcmp(*argv, "arp") == 0) { 595 NEXT_ARG(); 596 req->i.ifi_change |= IFF_NOARP; 597 if (strcmp(*argv, "on") == 0) { 598 req->i.ifi_flags &= ~IFF_NOARP; 599 } else if (strcmp(*argv, "off") == 0) { 600 req->i.ifi_flags |= IFF_NOARP; 601 } else 602 return on_off("noarp", *argv); 603 } else if (strcmp(*argv, "vf") == 0) { 604 struct rtattr *vflist; 605 NEXT_ARG(); 606 if (get_integer(&vf, *argv, 0)) { 607 invarg_1_to_2(*argv, "vf"); 608 } 609 vflist = addattr_nest(&req->n, sizeof(*req), 610 IFLA_VFINFO_LIST); 611 len = iplink_parse_vf(vf, &argc, &argv, req); 612 if (len < 0) 613 return -1; 614 addattr_nest_end(&req->n, vflist); 615 } else if (matches(*argv, "master") == 0) { 616 int ifindex; 617 NEXT_ARG(); 618 ifindex = ll_name_to_index(*argv); 619 if (!ifindex) 620 invarg_1_to_2(*argv, "master"); 621 addattr_l(&req->n, sizeof(*req), IFLA_MASTER, 622 &ifindex, 4); 623 } else if (matches(*argv, "nomaster") == 0) { 624 int ifindex = 0; 625 addattr_l(&req->n, sizeof(*req), IFLA_MASTER, 626 &ifindex, 4); 627 } else if (matches(*argv, "dynamic") == 0) { 628 NEXT_ARG(); 629 req->i.ifi_change |= IFF_DYNAMIC; 630 if (strcmp(*argv, "on") == 0) { 631 req->i.ifi_flags |= IFF_DYNAMIC; 632 } else if (strcmp(*argv, "off") == 0) { 633 req->i.ifi_flags &= ~IFF_DYNAMIC; 634 } else 635 return on_off("dynamic", *argv); 636 } else if (matches(*argv, "alias") == 0) { 637 NEXT_ARG(); 638 addattr_l(&req->n, sizeof(*req), IFLA_IFALIAS, 639 *argv, strlen(*argv)); 640 argc--; argv++; 641 break; 642 } else if (strcmp(*argv, "group") == 0) { 643 NEXT_ARG(); 644 if (*group != -1) 645 duparg("group", *argv); 646 if (rtnl_group_a2n(group, *argv)) 647 invarg_1_to_2(*argv, "group"); 648 } else if (strcmp(*argv, "mode") == 0) { 649 int mode; 650 NEXT_ARG(); 651 mode = get_link_mode(*argv); 652 if (mode < 0) 653 invarg_1_to_2(*argv, "mode"); 654 addattr8(&req->n, sizeof(*req), IFLA_LINKMODE, mode); 655 } else if (strcmp(*argv, "state") == 0) { 656 int state; 657 NEXT_ARG(); 658 state = get_operstate(*argv); 659 if (state < 0) 660 invarg_1_to_2(*argv, "state"); 661 addattr8(&req->n, sizeof(*req), IFLA_OPERSTATE, state); 662 } else if (matches(*argv, "numtxqueues") == 0) { 663 NEXT_ARG(); 664 if (numtxqueues != -1) 665 duparg("numtxqueues", *argv); 666 if (get_integer(&numtxqueues, *argv, 0)) 667 invarg_1_to_2(*argv, "numtxqueues"); 668 addattr_l(&req->n, sizeof(*req), IFLA_NUM_TX_QUEUES, 669 &numtxqueues, 4); 670 } else if (matches(*argv, "numrxqueues") == 0) { 671 NEXT_ARG(); 672 if (numrxqueues != -1) 673 duparg("numrxqueues", *argv); 674 if (get_integer(&numrxqueues, *argv, 0)) 675 invarg_1_to_2(*argv, "numrxqueues"); 676 addattr_l(&req->n, sizeof(*req), IFLA_NUM_RX_QUEUES, 677 &numrxqueues, 4); 678 } 679 #endif 680 367 681 /* Return value becomes exitcode. It's okay to not return at all */ 368 682 int FAST_FUNC do_iplink(char **argv) … … 371 685 "add\0""delete\0""set\0""show\0""lst\0""list\0"; 372 686 if (*argv) { 373 smalluint key = index_in_substrings(keywords, *argv);374 if (key > 5) /* invalid argument */375 bb_error_msg_and_die(bb_msg_invalid_arg,*argv, applet_name);687 int key = index_in_substrings(keywords, *argv); 688 if (key < 0) /* invalid argument */ 689 invarg_1_to_2(*argv, applet_name); 376 690 argv++; 377 691 if (key <= 1) /* add/delete */ 378 return do_ change(argv, key ? RTM_DELLINK : RTM_NEWLINK);379 elseif (key == 2) /* set */692 return do_add_or_delete(argv, key ? RTM_DELLINK : RTM_NEWLINK); 693 if (key == 2) /* set */ 380 694 return do_set(argv); 381 695 } -
branches/3.3/mindi-busybox/networking/libiproute/iproute.c
r3232 r3621 12 12 13 13 #include "ip_common.h" /* #include "libbb.h" is inside */ 14 #include "common_bufsiz.h" 14 15 #include "rt_names.h" 15 16 #include "utils.h" … … 44 45 typedef struct filter_t filter_t; 45 46 46 #define G_filter (*(filter_t*)&bb_common_bufsiz1) 47 #define G_filter (*(filter_t*)bb_common_bufsiz1) 48 #define INIT_G() do { setup_common_bufsiz(); } while (0) 47 49 48 50 static int flush_update(void) … … 54 56 G_filter.flushp = 0; 55 57 return 0; 56 }57 58 static unsigned get_hz(void)59 {60 static unsigned hz_internal;61 FILE *fp;62 63 if (hz_internal)64 return hz_internal;65 66 fp = fopen_for_read("/proc/net/psched");67 if (fp) {68 unsigned nom, denom;69 70 if (fscanf(fp, "%*08x%*08x%08x%08x", &nom, &denom) == 2)71 if (nom == 1000000)72 hz_internal = denom;73 fclose(fp);74 }75 if (!hz_internal)76 hz_internal = sysconf(_SC_CLK_TCK);77 return hz_internal;78 58 } 79 59 … … 84 64 int len = n->nlmsg_len; 85 65 struct rtattr *tb[RTA_MAX+1]; 86 char abuf[256];87 66 inet_prefix dst; 88 67 inet_prefix src; 89 68 int host_len = -1; 90 SPRINT_BUF(b1);91 69 92 70 if (n->nlmsg_type != RTM_NEWROUTE && n->nlmsg_type != RTM_DELROUTE) { … … 219 197 if (NLMSG_ALIGN(G_filter.flushp) + n->nlmsg_len > G_filter.flushe) { 220 198 if (flush_update()) 221 bb_error_msg_and_die("flush");199 xfunc_die(); 222 200 } 223 201 fn = (void*)(G_filter.flushb + NLMSG_ALIGN(G_filter.flushp)); … … 237 215 } 238 216 if (r->rtm_type != RTN_UNICAST /* && !G_filter.type - always 0 */) { 239 printf("%s ", rtnl_rtntype_n2a(r->rtm_type , b1));217 printf("%s ", rtnl_rtntype_n2a(r->rtm_type)); 240 218 } 241 219 242 220 if (tb[RTA_DST]) { 243 221 if (r->rtm_dst_len != host_len) { 244 printf("%s/%u ", rt_addr_n2a(r->rtm_family, 245 RTA_DATA(tb[RTA_DST]), 246 abuf, sizeof(abuf)), 247 r->rtm_dst_len 248 ); 222 printf("%s/%u ", 223 rt_addr_n2a(r->rtm_family, RTA_DATA(tb[RTA_DST])), 224 r->rtm_dst_len 225 ); 249 226 } else { 250 227 printf("%s ", format_host(r->rtm_family, 251 228 RTA_PAYLOAD(tb[RTA_DST]), 252 RTA_DATA(tb[RTA_DST]), 253 abuf, sizeof(abuf)) 254 ); 229 RTA_DATA(tb[RTA_DST])) 230 ); 255 231 } 256 232 } else if (r->rtm_dst_len) { … … 261 237 if (tb[RTA_SRC]) { 262 238 if (r->rtm_src_len != host_len) { 263 printf("from %s/%u ", rt_addr_n2a(r->rtm_family, 264 RTA_DATA(tb[RTA_SRC]), 265 abuf, sizeof(abuf)), 266 r->rtm_src_len 267 ); 239 printf("from %s/%u ", 240 rt_addr_n2a(r->rtm_family, RTA_DATA(tb[RTA_SRC])), 241 r->rtm_src_len 242 ); 268 243 } else { 269 244 printf("from %s ", format_host(r->rtm_family, 270 245 RTA_PAYLOAD(tb[RTA_SRC]), 271 RTA_DATA(tb[RTA_SRC]), 272 abuf, sizeof(abuf)) 273 ); 246 RTA_DATA(tb[RTA_SRC])) 247 ); 274 248 } 275 249 } else if (r->rtm_src_len) { … … 279 253 printf("via %s ", format_host(r->rtm_family, 280 254 RTA_PAYLOAD(tb[RTA_GATEWAY]), 281 RTA_DATA(tb[RTA_GATEWAY]) ,282 abuf, sizeof(abuf)));255 RTA_DATA(tb[RTA_GATEWAY])) 256 ); 283 257 } 284 258 if (tb[RTA_OIF]) { … … 293 267 */ 294 268 printf(" src %s ", rt_addr_n2a(r->rtm_family, 295 RTA_DATA(tb[RTA_PREFSRC]), 296 abuf, sizeof(abuf))); 269 RTA_DATA(tb[RTA_PREFSRC]))); 297 270 } 298 271 if (tb[RTA_PRIORITY]) { 299 272 printf(" metric %d ", *(uint32_t*)RTA_DATA(tb[RTA_PRIORITY])); 300 273 } 274 if (r->rtm_flags & RTNH_F_DEAD) { 275 printf("dead "); 276 } 277 if (r->rtm_flags & RTNH_F_ONLINK) { 278 printf("onlink "); 279 } 280 if (r->rtm_flags & RTNH_F_PERVASIVE) { 281 printf("pervasive "); 282 } 283 if (r->rtm_flags & RTM_F_NOTIFY) { 284 printf("notify "); 285 } 286 301 287 if (r->rtm_family == AF_INET6) { 302 288 struct rta_cacheinfo *ci = NULL; … … 330 316 { 331 317 static const char keywords[] ALIGN1 = 332 "src\0""via\0""mtu\0""lock\0"" protocol\0"IF_FEATURE_IP_RULE("table\0")333 "dev\0""oif\0""to\0""metric\0" ;318 "src\0""via\0""mtu\0""lock\0""scope\0""protocol\0"IF_FEATURE_IP_RULE("table\0") 319 "dev\0""oif\0""to\0""metric\0""onlink\0"; 334 320 enum { 335 321 ARG_src, 336 322 ARG_via, 337 323 ARG_mtu, PARM_lock, 324 ARG_scope, 338 325 ARG_protocol, 339 326 IF_FEATURE_IP_RULE(ARG_table,) … … 342 329 ARG_to, 343 330 ARG_metric, 331 ARG_onlink, 344 332 }; 345 333 enum { … … 360 348 char *d = NULL; 361 349 smalluint ok = 0; 350 smalluint scope_ok = 0; 362 351 int arg; 363 352 … … 368 357 req.n.nlmsg_type = cmd; 369 358 req.r.rtm_family = preferred_family; 370 if (RT_TABLE_MAIN ) /* if it is zero, memset already did it */359 if (RT_TABLE_MAIN != 0) /* if it is zero, memset already did it */ 371 360 req.r.rtm_table = RT_TABLE_MAIN; 372 if (RT_SCOPE_NOWHERE )361 if (RT_SCOPE_NOWHERE != 0) 373 362 req.r.rtm_scope = RT_SCOPE_NOWHERE; 374 363 375 364 if (cmd != RTM_DELROUTE) { 376 req.r.rtm_protocol = RTPROT_BOOT;377 365 req.r.rtm_scope = RT_SCOPE_UNIVERSE; 378 req.r.rtm_type = RTN_UNICAST; 366 if (RTPROT_BOOT != 0) 367 req.r.rtm_protocol = RTPROT_BOOT; 368 if (RTN_UNICAST != 0) 369 req.r.rtm_type = RTN_UNICAST; 379 370 } 380 371 … … 409 400 mtu = get_unsigned(*argv, "mtu"); 410 401 rta_addattr32(mxrta, sizeof(mxbuf), RTAX_MTU, mtu); 402 } else if (arg == ARG_scope) { 403 uint32_t scope; 404 NEXT_ARG(); 405 if (rtnl_rtscope_a2n(&scope, *argv)) 406 invarg_1_to_2(*argv, "scope"); 407 req.r.rtm_scope = scope; 408 scope_ok = 1; 411 409 } else if (arg == ARG_protocol) { 412 410 uint32_t prot; 413 411 NEXT_ARG(); 414 412 if (rtnl_rtprot_a2n(&prot, *argv)) 415 invarg (*argv, "protocol");413 invarg_1_to_2(*argv, "protocol"); 416 414 req.r.rtm_protocol = prot; 417 415 ok |= proto_ok; … … 421 419 NEXT_ARG(); 422 420 if (rtnl_rttable_a2n(&tid, *argv)) 423 invarg (*argv, "table");421 invarg_1_to_2(*argv, "table"); 424 422 req.r.rtm_table = tid; 425 423 #endif … … 432 430 metric = get_u32(*argv, "metric"); 433 431 addattr32(&req.n, sizeof(req), RTA_PRIORITY, metric); 432 } else if (arg == ARG_onlink) { 433 req.r.rtm_flags |= RTNH_F_ONLINK; 434 434 } else { 435 435 int type; … … 483 483 } 484 484 485 if (req.r.rtm_type == RTN_LOCAL || req.r.rtm_type == RTN_NAT) 486 req.r.rtm_scope = RT_SCOPE_HOST; 487 else 488 if (req.r.rtm_type == RTN_BROADCAST 489 || req.r.rtm_type == RTN_MULTICAST 490 || req.r.rtm_type == RTN_ANYCAST 491 ) { 492 req.r.rtm_scope = RT_SCOPE_LINK; 493 } 494 else if (req.r.rtm_type == RTN_UNICAST || req.r.rtm_type == RTN_UNSPEC) { 495 if (cmd == RTM_DELROUTE) 496 req.r.rtm_scope = RT_SCOPE_NOWHERE; 497 else if (!(ok & gw_ok)) 485 if (!scope_ok) { 486 if (req.r.rtm_type == RTN_LOCAL || req.r.rtm_type == RTN_NAT) 487 req.r.rtm_scope = RT_SCOPE_HOST; 488 else 489 if (req.r.rtm_type == RTN_BROADCAST 490 || req.r.rtm_type == RTN_MULTICAST 491 || req.r.rtm_type == RTN_ANYCAST 492 ) { 498 493 req.r.rtm_scope = RT_SCOPE_LINK; 494 } 495 else if (req.r.rtm_type == RTN_UNICAST || req.r.rtm_type == RTN_UNSPEC) { 496 if (cmd == RTM_DELROUTE) 497 req.r.rtm_scope = RT_SCOPE_NOWHERE; 498 else if (!(ok & gw_ok)) 499 req.r.rtm_scope = RT_SCOPE_LINK; 500 } 499 501 } 500 502 … … 605 607 if (rtnl_rtprot_a2n(&prot, *argv)) { 606 608 if (index_in_strings(keywords, *argv) != KW_all) 607 invarg (*argv, "protocol");609 invarg_1_to_2(*argv, "protocol"); 608 610 prot = 0; 609 611 //G_filter.protocolmask = 0; … … 630 632 uint32_t tid; 631 633 if (rtnl_rttable_a2n(&tid, *argv)) 632 invarg (*argv, "table");634 invarg_1_to_2(*argv, "table"); 633 635 G_filter.tb = tid; 634 636 #else 635 invarg (*argv, "table");637 invarg_1_to_2(*argv, "table"); 636 638 #endif 637 639 } … … 901 903 unsigned flags = 0; 902 904 int cmd = RTM_NEWROUTE; 905 906 INIT_G(); 903 907 904 908 if (!*argv) … … 940 944 return iproute_list_or_flush(argv+1, 1); 941 945 default: 942 bb_error_msg_and_die("unknown command %s", *argv);946 invarg_1_to_2(*argv, applet_name); 943 947 } 944 948 -
branches/3.3/mindi-busybox/networking/libiproute/iprule.c
r3232 r3621 45 45 int host_len = -1; 46 46 struct rtattr * tb[RTA_MAX+1]; 47 char abuf[256];48 SPRINT_BUF(b1);49 47 50 48 if (n->nlmsg_type != RTM_NEWRULE) … … 73 71 if (tb[RTA_SRC]) { 74 72 if (r->rtm_src_len != host_len) { 75 printf("%s/%u", rt_addr_n2a(r->rtm_family, 76 RTA_DATA(tb[RTA_SRC]), 77 abuf, sizeof(abuf)), 73 printf("%s/%u", 74 rt_addr_n2a(r->rtm_family, RTA_DATA(tb[RTA_SRC])), 78 75 r->rtm_src_len 79 76 ); … … 81 78 fputs(format_host(r->rtm_family, 82 79 RTA_PAYLOAD(tb[RTA_SRC]), 83 RTA_DATA(tb[RTA_SRC]), 84 abuf, sizeof(abuf)), 80 RTA_DATA(tb[RTA_SRC])), 85 81 stdout 86 82 ); … … 96 92 if (r->rtm_dst_len != host_len) { 97 93 printf("to %s/%u ", rt_addr_n2a(r->rtm_family, 98 RTA_DATA(tb[RTA_DST]), 99 abuf, sizeof(abuf)), 94 RTA_DATA(tb[RTA_DST])), 100 95 r->rtm_dst_len 101 96 ); … … 103 98 printf("to %s ", format_host(r->rtm_family, 104 99 RTA_PAYLOAD(tb[RTA_DST]), 105 RTA_DATA(tb[RTA_DST]), 106 abuf, sizeof(abuf))); 100 RTA_DATA(tb[RTA_DST]))); 107 101 } 108 102 } else if (r->rtm_dst_len) { … … 111 105 112 106 if (r->rtm_tos) { 113 printf("tos %s ", rtnl_dsfield_n2a(r->rtm_tos , b1));107 printf("tos %s ", rtnl_dsfield_n2a(r->rtm_tos)); 114 108 } 115 109 if (tb[RTA_PROTOINFO]) { … … 122 116 123 117 if (r->rtm_table) 124 printf("lookup %s ", rtnl_rttable_n2a(r->rtm_table , b1));118 printf("lookup %s ", rtnl_rttable_n2a(r->rtm_table)); 125 119 126 120 if (tb[RTA_FLOW]) { … … 130 124 if (from) { 131 125 printf("realms %s/", 132 rtnl_rtrealm_n2a(from , b1));126 rtnl_rtrealm_n2a(from)); 133 127 } 134 128 printf("%s ", 135 rtnl_rtrealm_n2a(to , b1));129 rtnl_rtrealm_n2a(to)); 136 130 } 137 131 … … 141 135 format_host(r->rtm_family, 142 136 RTA_PAYLOAD(tb[RTA_GATEWAY]), 143 RTA_DATA(tb[RTA_GATEWAY]) ,144 abuf, sizeof(abuf)));137 RTA_DATA(tb[RTA_GATEWAY])) 138 ); 145 139 } else 146 140 printf("masquerade"); 147 141 } else if (r->rtm_type != RTN_UNICAST) 148 fputs(rtnl_rtntype_n2a(r->rtm_type , b1), stdout);142 fputs(rtnl_rtntype_n2a(r->rtm_type), stdout); 149 143 150 144 bb_putchar('\n'); … … 216 210 key = index_in_substrings(keywords, *argv) + 1; 217 211 if (key == 0) /* no match found in keywords array, bail out. */ 218 bb_error_msg_and_die(bb_msg_invalid_arg,*argv, applet_name);212 invarg_1_to_2(*argv, applet_name); 219 213 if (key == ARG_from) { 220 214 inet_prefix dst; … … 241 235 NEXT_ARG(); 242 236 if (rtnl_dsfield_a2n(&tos, *argv)) 243 invarg (*argv, "TOS");237 invarg_1_to_2(*argv, "TOS"); 244 238 req.r.rtm_tos = tos; 245 239 } else if (key == ARG_fwmark) { … … 252 246 NEXT_ARG(); 253 247 if (get_rt_realms(&realm, *argv)) 254 invarg (*argv, "realms");248 invarg_1_to_2(*argv, "realms"); 255 249 addattr32(&req.n, sizeof(req), RTA_FLOW, realm); 256 250 } else if (key == ARG_table || … … 260 254 NEXT_ARG(); 261 255 if (rtnl_rttable_a2n(&tid, *argv)) 262 invarg (*argv, "table ID");256 invarg_1_to_2(*argv, "table ID"); 263 257 req.r.rtm_table = tid; 264 258 table_ok = 1; … … 283 277 bb_show_usage(); 284 278 if (rtnl_rtntype_a2n(&type, *argv)) 285 invarg (*argv, "type");279 invarg_1_to_2(*argv, "type"); 286 280 req.r.rtm_type = type; 287 281 } … … 309 303 "add\0""delete\0""list\0""show\0"; 310 304 if (*argv) { 311 smalluint cmd = index_in_substrings(ip_rule_commands, *argv);312 if (cmd > 3)313 bb_error_msg_and_die(bb_msg_invalid_arg,*argv, applet_name);305 int cmd = index_in_substrings(ip_rule_commands, *argv); 306 if (cmd < 0) 307 invarg_1_to_2(*argv, applet_name); 314 308 argv++; 315 309 if (cmd < 2) -
branches/3.3/mindi-busybox/networking/libiproute/iptunnel.c
r3232 r3621 295 295 uval = get_unsigned(*argv, "TTL"); 296 296 if (uval > 255) 297 invarg (*argv, "TTL must be <=255");297 invarg_1_to_2(*argv, "TTL"); 298 298 p->iph.ttl = uval; 299 299 } … … 306 306 if (key != ARG_inherit) { 307 307 if (rtnl_dsfield_a2n(&uval, *argv)) 308 invarg (*argv, "TOS");308 invarg_1_to_2(*argv, "TOS"); 309 309 p->iph.tos = uval; 310 310 } else … … 405 405 static void print_tunnel(struct ip_tunnel_parm *p) 406 406 { 407 char s1[256]; 408 char s2[256]; 409 char s3[64]; 410 char s4[64]; 411 412 format_host(AF_INET, 4, &p->iph.daddr, s1, sizeof(s1)); 413 format_host(AF_INET, 4, &p->iph.saddr, s2, sizeof(s2)); 414 inet_ntop(AF_INET, &p->i_key, s3, sizeof(s3)); 415 inet_ntop(AF_INET, &p->o_key, s4, sizeof(s4)); 407 char s3[INET_ADDRSTRLEN]; 408 char s4[INET_ADDRSTRLEN]; 416 409 417 410 printf("%s: %s/ip remote %s local %s ", 418 p->name, 419 p->iph.protocol == IPPROTO_IPIP ? "ip" : 420 (p->iph.protocol == IPPROTO_GRE ? "gre" : 421 (p->iph.protocol == IPPROTO_IPV6 ? "ipv6" : "unknown")), 422 p->iph.daddr ? s1 : "any", p->iph.saddr ? s2 : "any"); 411 p->name, 412 p->iph.protocol == IPPROTO_IPIP ? "ip" : 413 p->iph.protocol == IPPROTO_GRE ? "gre" : 414 p->iph.protocol == IPPROTO_IPV6 ? "ipv6" : 415 "unknown", 416 p->iph.daddr ? format_host(AF_INET, 4, &p->iph.daddr) : "any", 417 p->iph.saddr ? format_host(AF_INET, 4, &p->iph.saddr) : "any" 418 ); 423 419 if (p->link) { 424 420 char *n = do_ioctl_get_ifname(p->link); … … 433 429 printf(" ttl inherit "); 434 430 if (p->iph.tos) { 435 SPRINT_BUF(b1);436 431 printf(" tos"); 437 432 if (p->iph.tos & 1) … … 439 434 if (p->iph.tos & ~1) 440 435 printf("%c%s ", p->iph.tos & 1 ? '/' : ' ', 441 rtnl_dsfield_n2a(p->iph.tos & ~1 , b1));436 rtnl_dsfield_n2a(p->iph.tos & ~1)); 442 437 } 443 438 if (!(p->iph.frag_off & htons(IP_DF))) 444 439 printf(" nopmtudisc"); 445 440 441 inet_ntop(AF_INET, &p->i_key, s3, sizeof(s3)); 442 inet_ntop(AF_INET, &p->o_key, s4, sizeof(s4)); 446 443 if ((p->i_flags & GRE_KEY) && (p->o_flags & GRE_KEY) && p->o_key == p->i_key) 447 444 printf(" key %s", s3); 448 else if ((p->i_flags | p->o_flags) & GRE_KEY){445 else { 449 446 if (p->i_flags & GRE_KEY) 450 447 printf(" ikey %s ", s3); … … 562 559 563 560 if (*argv) { 564 smalluint key = index_in_substrings(keywords, *argv);565 if (key > 5)566 bb_error_msg_and_die(bb_msg_invalid_arg,*argv, applet_name);561 int key = index_in_substrings(keywords, *argv); 562 if (key < 0) 563 invarg_1_to_2(*argv, applet_name); 567 564 argv++; 568 565 if (key == ARG_add) -
branches/3.3/mindi-busybox/networking/libiproute/libnetlink.c
r3232 r3621 72 72 struct sockaddr_nl nladdr; 73 73 struct iovec iov[2] = { { &nlh, sizeof(nlh) }, { req, len } }; 74 /* Use designated initializers, struct layout is non-portable */ 74 75 struct msghdr msg = { 75 (void*)&nladdr, sizeof(nladdr), 76 iov, 2, 77 NULL, 0, 78 0 76 .msg_name = (void*)&nladdr, 77 .msg_namelen = sizeof(nladdr), 78 .msg_iov = iov, 79 .msg_iovlen = 2, 80 .msg_control = NULL, 81 .msg_controllen = 0, 82 .msg_flags = 0 79 83 }; 80 84 … … 105 109 int status; 106 110 struct nlmsghdr *h; 107 111 /* Use designated initializers, struct layout is non-portable */ 108 112 struct msghdr msg = { 109 (void*)&nladdr, sizeof(nladdr), 110 &iov, 1, 111 NULL, 0, 112 0 113 .msg_name = (void*)&nladdr, 114 .msg_namelen = sizeof(nladdr), 115 .msg_iov = &iov, 116 .msg_iovlen = 1, 117 .msg_control = NULL, 118 .msg_controllen = 0, 119 .msg_flags = 0 113 120 }; 114 121 … … 212 219 struct iovec iov = { (void*)n, n->nlmsg_len }; 213 220 char *buf = xmalloc(8*1024); /* avoid big stack buffer */ 221 /* Use designated initializers, struct layout is non-portable */ 214 222 struct msghdr msg = { 215 (void*)&nladdr, sizeof(nladdr), 216 &iov, 1, 217 NULL, 0, 218 0 223 .msg_name = (void*)&nladdr, 224 .msg_namelen = sizeof(nladdr), 225 .msg_iov = &iov, 226 .msg_iovlen = 1, 227 .msg_control = NULL, 228 .msg_controllen = 0, 229 .msg_flags = 0 219 230 }; 220 231 -
branches/3.3/mindi-busybox/networking/libiproute/ll_map.c
r2725 r3621 87 87 } 88 88 89 const char FAST_FUNC *ll_idx_n2a(int idx, char *buf) 89 static 90 const char FAST_FUNC *ll_idx_n2a(int idx/*, char *buf*/) 90 91 { 91 92 struct idxmap *im; … … 96 97 if (im) 97 98 return im->name; 98 snprintf(buf, 16, "if%d", idx); 99 return buf; 99 //snprintf(buf, 16, "if%d", idx); 100 //return buf; 101 return auto_string(xasprintf("if%d", idx)); 100 102 } 101 102 103 103 104 const char FAST_FUNC *ll_index_to_name(int idx) 104 105 { 105 static char nbuf[16]; 106 107 return ll_idx_n2a(idx, nbuf); 106 //static char nbuf[16]; 107 return ll_idx_n2a(idx/*, nbuf*/); 108 108 } 109 109 … … 137 137 { 138 138 int ret = 0; 139 int sock_fd;140 139 141 140 /* caching is not warranted - no users which repeatedly call it */ … … 165 164 } 166 165 } 167 /* We have not found the interface in our cache, but the kernel168 * may still know about it. One reason is that we may be using169 * module on-demand loading, which means that the kernel will170 * load the module and make the interface exist only when171 * we explicitely request it (check for dev_load() in net/core/dev.c).172 * I can think of other similar scenario, but they are less common...173 * Jean II */174 166 #endif 175 176 sock_fd = socket(AF_INET, SOCK_DGRAM, 0); 177 if (sock_fd >= 0) { 178 struct ifreq ifr; 179 int tmp; 180 181 strncpy_IFNAMSIZ(ifr.ifr_name, name); 182 ifr.ifr_ifindex = -1; 183 tmp = ioctl(sock_fd, SIOCGIFINDEX, &ifr); 184 close(sock_fd); 185 if (tmp >= 0) 186 /* In theory, we should redump the interface list 187 * to update our cache, this is left as an exercise 188 * to the reader... Jean II */ 189 ret = ifr.ifr_ifindex; 190 } 167 ret = if_nametoindex(name); 191 168 /* out:*/ 192 169 if (ret <= 0) -
branches/3.3/mindi-busybox/networking/libiproute/ll_map.h
r2725 r3621 8 8 int ll_init_map(struct rtnl_handle *rth) FAST_FUNC; 9 9 int xll_name_to_index(const char *name) FAST_FUNC; 10 //static: const char *ll_idx_n2a(int idx, char *buf) FAST_FUNC; 10 11 const char *ll_index_to_name(int idx) FAST_FUNC; 11 const char *ll_idx_n2a(int idx, char *buf) FAST_FUNC;12 12 /* int ll_index_to_type(int idx); */ 13 13 unsigned ll_index_to_flags(int idx) FAST_FUNC; -
branches/3.3/mindi-busybox/networking/libiproute/ll_proto.c
r3232 r3621 85 85 /* Keep declarations above and below in sync! */ 86 86 87 static const char llproto_names[] =87 static const char llproto_names[] ALIGN1 = 88 88 #define __PF(f,n) #n "\0" 89 89 __PF(LOOP,loop) -
branches/3.3/mindi-busybox/networking/libiproute/ll_types.c
r3232 r3621 17 17 const char* FAST_FUNC ll_type_n2a(int type, char *buf) 18 18 { 19 static const char arphrd_name[] =19 static const char arphrd_name[] ALIGN1 = 20 20 /* 0, */ "generic" "\0" 21 21 /* ARPHRD_LOOPBACK, */ "loopback" "\0" … … 106 106 /* Keep these arrays in sync! */ 107 107 108 static const uint16_t arphrd_type[] = {108 static const uint16_t arphrd_type[] ALIGN2 = { 109 109 0, /* "generic" "\0" */ 110 110 ARPHRD_LOOPBACK, /* "loopback" "\0" */ -
branches/3.3/mindi-busybox/networking/libiproute/rt_names.c
r2725 r3621 11 11 #include "rt_names.h" 12 12 13 #define CONFDIR CONFIG_FEATURE_IP_ROUTE_DIR 14 13 15 typedef struct rtnl_tab_t { 14 16 const char *cached_str; 15 17 unsigned cached_result; 16 const char *tab[256]; 18 /* upstream version switched to a hash table and removed 19 * id < 256 limit. For now bbox bumps this array size from 256 20 * to 1024. If you plan to change this to a hash table, 21 * consider merging several hash tables we have (for example, 22 * awk has resizable one! 23 */ 24 #define RT_TABLE_MAX 1023 25 const char *tab[RT_TABLE_MAX+1]; 17 26 } rtnl_tab_t; 18 27 … … 20 29 { 21 30 char *token[2]; 22 parser_t *parser = config_open2(file, fopen_for_read); 23 31 char fullname[sizeof(CONFDIR"/rt_dsfield") + 8]; 32 parser_t *parser; 33 34 sprintf(fullname, CONFDIR"/rt_%s", file); 35 parser = config_open2(fullname, fopen_for_read); 24 36 while (config_read(parser, token, 2, 2, "# \t", PARSE_NORMAL)) { 25 37 unsigned id = bb_strtou(token[0], NULL, 0); 26 if (id > 256) {38 if (id > RT_TABLE_MAX) { 27 39 bb_error_msg("database %s is corrupted at line %d", 28 40 file, parser->lineno); … … 43 55 } 44 56 45 for (i = 0; i < 256; i++) {57 for (i = 0; i <= RT_TABLE_MAX; i++) { 46 58 if (tab->tab[i] 47 59 && strcmp(tab->tab[i], arg) == 0 … … 55 67 56 68 i = bb_strtou(arg, NULL, base); 57 if (i > 255)69 if (i > RT_TABLE_MAX) 58 70 return -1; 59 71 *id = i; … … 86 98 rtnl_rtprot_tab = xzalloc(sizeof(*rtnl_rtprot_tab)); 87 99 memcpy(rtnl_rtprot_tab->tab, init_tab, sizeof(init_tab)); 88 rtnl_tab_initialize(" /etc/iproute2/rt_protos", rtnl_rtprot_tab->tab);89 } 90 91 const char* FAST_FUNC rtnl_rtprot_n2a(int id, char *buf) 92 { 93 if (id < 0 || id >= 256){94 sprintf(buf, "%d", id);95 return buf;100 rtnl_tab_initialize("protos", rtnl_rtprot_tab->tab); 101 } 102 103 #if 0 /* UNUSED */ 104 const char* FAST_FUNC rtnl_rtprot_n2a(int id) 105 { 106 if (id < 0 || id > RT_TABLE_MAX) { 107 return itoa(id); 96 108 } 97 109 … … 100 112 if (rtnl_rtprot_tab->tab[id]) 101 113 return rtnl_rtprot_tab->tab[id]; 102 /* buf is SPRINT_BSIZE big */ 103 sprintf(buf, "%d", id); 104 return buf; 105 } 114 return itoa(id); 115 } 116 #endif 106 117 107 118 int FAST_FUNC rtnl_rtprot_a2n(uint32_t *id, char *arg) … … 124 135 rtnl_rtscope_tab->tab[253] = "link"; 125 136 rtnl_rtscope_tab->tab[200] = "site"; 126 rtnl_tab_initialize("/etc/iproute2/rt_scopes", rtnl_rtscope_tab->tab); 127 } 128 129 const char* FAST_FUNC rtnl_rtscope_n2a(int id, char *buf) 130 { 131 if (id < 0 || id >= 256) { 132 sprintf(buf, "%d", id); 133 return buf; 137 rtnl_tab_initialize("scopes", rtnl_rtscope_tab->tab); 138 } 139 140 const char* FAST_FUNC rtnl_rtscope_n2a(int id) 141 { 142 if (id < 0 || id > RT_TABLE_MAX) { 143 return itoa(id); 134 144 } 135 145 … … 138 148 if (rtnl_rtscope_tab->tab[id]) 139 149 return rtnl_rtscope_tab->tab[id]; 140 /* buf is SPRINT_BSIZE big */ 141 sprintf(buf, "%d", id); 142 return buf; 150 return itoa(id); 143 151 } 144 152 … … 157 165 rtnl_rtrealm_tab = xzalloc(sizeof(*rtnl_rtrealm_tab)); 158 166 rtnl_rtrealm_tab->tab[0] = "unknown"; 159 rtnl_tab_initialize(" /etc/iproute2/rt_realms", rtnl_rtrealm_tab->tab);167 rtnl_tab_initialize("realms", rtnl_rtrealm_tab->tab); 160 168 } 161 169 … … 167 175 168 176 #if ENABLE_FEATURE_IP_RULE 169 const char* FAST_FUNC rtnl_rtrealm_n2a(int id, char *buf) 170 { 171 if (id < 0 || id >= 256) { 172 sprintf(buf, "%d", id); 173 return buf; 177 const char* FAST_FUNC rtnl_rtrealm_n2a(int id) 178 { 179 if (id < 0 || id > RT_TABLE_MAX) { 180 return itoa(id); 174 181 } 175 182 … … 178 185 if (rtnl_rtrealm_tab->tab[id]) 179 186 return rtnl_rtrealm_tab->tab[id]; 180 /* buf is SPRINT_BSIZE big */ 181 sprintf(buf, "%d", id); 182 return buf; 187 return itoa(id); 183 188 } 184 189 #endif … … 192 197 rtnl_rtdsfield_tab = xzalloc(sizeof(*rtnl_rtdsfield_tab)); 193 198 rtnl_rtdsfield_tab->tab[0] = "0"; 194 rtnl_tab_initialize("/etc/iproute2/rt_dsfield", rtnl_rtdsfield_tab->tab); 195 } 196 197 const char* FAST_FUNC rtnl_dsfield_n2a(int id, char *buf) 198 { 199 if (id < 0 || id >= 256) { 200 sprintf(buf, "%d", id); 201 return buf; 199 rtnl_tab_initialize("dsfield", rtnl_rtdsfield_tab->tab); 200 } 201 202 const char* FAST_FUNC rtnl_dsfield_n2a(int id) 203 { 204 if (id < 0 || id > RT_TABLE_MAX) { 205 return itoa(id); 202 206 } 203 207 … … 206 210 if (rtnl_rtdsfield_tab->tab[id]) 207 211 return rtnl_rtdsfield_tab->tab[id]; 208 /* buf is SPRINT_BSIZE big */ 209 sprintf(buf, "0x%02x", id); 210 return buf; 212 return itoa(id); 211 213 } 212 214 … … 223 225 static void rtnl_rttable_initialize(void) 224 226 { 225 if (rtnl_rtdsfield_tab) return; 227 if (rtnl_rttable_tab) 228 return; 229 226 230 rtnl_rttable_tab = xzalloc(sizeof(*rtnl_rttable_tab)); 227 231 rtnl_rttable_tab->tab[0] = "unspec"; … … 229 233 rtnl_rttable_tab->tab[254] = "main"; 230 234 rtnl_rttable_tab->tab[253] = "default"; 231 rtnl_tab_initialize("/etc/iproute2/rt_tables", rtnl_rttable_tab->tab); 232 } 233 234 const char* FAST_FUNC rtnl_rttable_n2a(int id, char *buf) 235 { 236 if (id < 0 || id >= 256) { 237 sprintf(buf, "%d", id); 238 return buf; 235 rtnl_tab_initialize("tables", rtnl_rttable_tab->tab); 236 } 237 238 const char* FAST_FUNC rtnl_rttable_n2a(int id) 239 { 240 if (id < 0 || id > RT_TABLE_MAX) { 241 return itoa(id); 239 242 } 240 243 … … 243 246 if (rtnl_rttable_tab->tab[id]) 244 247 return rtnl_rttable_tab->tab[id]; 245 /* buf is SPRINT_BSIZE big */ 246 sprintf(buf, "%d", id); 247 return buf; 248 return itoa(id); 248 249 } 249 250 -
branches/3.3/mindi-busybox/networking/libiproute/rt_names.h
r2725 r3621 5 5 PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN 6 6 7 /* buf is SPRINT_BSIZE big */ 8 extern const char* rtnl_rtprot_n2a(int id, char *buf) FAST_FUNC; 9 extern const char* rtnl_rtscope_n2a(int id, char *buf) FAST_FUNC; 10 extern const char* rtnl_rtrealm_n2a(int id, char *buf) FAST_FUNC; 11 extern const char* rtnl_dsfield_n2a(int id, char *buf) FAST_FUNC; 12 extern const char* rtnl_rttable_n2a(int id, char *buf) FAST_FUNC; 7 extern const char* rtnl_rtprot_n2a(int id) FAST_FUNC; 8 extern const char* rtnl_rtscope_n2a(int id) FAST_FUNC; 9 extern const char* rtnl_rtrealm_n2a(int id) FAST_FUNC; 10 extern const char* rtnl_dsfield_n2a(int id) FAST_FUNC; 11 extern const char* rtnl_rttable_n2a(int id) FAST_FUNC; 13 12 extern int rtnl_rtprot_a2n(uint32_t *id, char *arg) FAST_FUNC; 14 13 extern int rtnl_rtscope_a2n(uint32_t *id, char *arg) FAST_FUNC; -
branches/3.3/mindi-busybox/networking/libiproute/rtm_map.c
r2725 r3621 13 13 #include "utils.h" 14 14 15 const char* FAST_FUNC rtnl_rtntype_n2a(int id , char *buf)15 const char* FAST_FUNC rtnl_rtntype_n2a(int id) 16 16 { 17 17 switch (id) { … … 41 41 return "xresolve"; 42 42 default: 43 /* buf is SPRINT_BSIZE big */ 44 sprintf(buf, "%d", id); 45 return buf; 43 return itoa(id); 46 44 } 47 45 } -
branches/3.3/mindi-busybox/networking/libiproute/rtm_map.h
r2725 r3621 5 5 PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN 6 6 7 const char *rtnl_rtntype_n2a(int id , char *buf) FAST_FUNC;7 const char *rtnl_rtntype_n2a(int id) FAST_FUNC; 8 8 int rtnl_rtntype_a2n(int *id, char *arg) FAST_FUNC; 9 9 -
branches/3.3/mindi-busybox/networking/libiproute/utils.c
r3232 r3621 14 14 #include "inet_common.h" 15 15 16 unsigned get_hz(void) 17 { 18 static unsigned hz_internal; 19 FILE *fp; 20 21 if (hz_internal) 22 return hz_internal; 23 24 fp = fopen_for_read("/proc/net/psched"); 25 if (fp) { 26 unsigned nom, denom; 27 28 if (fscanf(fp, "%*08x%*08x%08x%08x", &nom, &denom) == 2) 29 if (nom == 1000000) 30 hz_internal = denom; 31 fclose(fp); 32 } 33 if (!hz_internal) 34 hz_internal = bb_clk_tck(); 35 return hz_internal; 36 } 37 16 38 unsigned get_unsigned(char *arg, const char *errmsg) 17 39 { … … 26 48 } 27 49 } 28 invarg (arg, errmsg); /* does not return */50 invarg_1_to_2(arg, errmsg); /* does not return */ 29 51 } 30 52 … … 41 63 } 42 64 } 43 invarg (arg, errmsg); /* does not return */65 invarg_1_to_2(arg, errmsg); /* does not return */ 44 66 } 45 67 … … 56 78 } 57 79 } 58 invarg (arg, errmsg); /* does not return */80 invarg_1_to_2(arg, errmsg); /* does not return */ 59 81 } 60 82 … … 209 231 void incomplete_command(void) 210 232 { 211 bb_error_msg_and_die("command line is not complete, try option\"help\"");212 } 213 214 void invarg (const char *arg, const char *opt)215 { 216 bb_error_msg_and_die(bb_msg_invalid_arg , arg, opt);233 bb_error_msg_and_die("command line is not complete, try \"help\""); 234 } 235 236 void invarg_1_to_2(const char *arg, const char *opt) 237 { 238 bb_error_msg_and_die(bb_msg_invalid_arg_to, arg, opt); 217 239 } 218 240 … … 255 277 } 256 278 257 const char *rt_addr_n2a(int af, 258 void *addr, char *buf, int buflen) 279 const char *rt_addr_n2a(int af, void *addr) 259 280 { 260 281 switch (af) { 261 282 case AF_INET: 262 283 case AF_INET6: 263 return inet_ntop(af, addr, buf, buflen); 284 return inet_ntop(af, addr, 285 auto_string(xzalloc(INET6_ADDRSTRLEN)), INET6_ADDRSTRLEN 286 ); 264 287 default: 265 288 return "???"; … … 268 291 269 292 #ifdef RESOLVE_HOSTNAMES 270 const char *format_host(int af, int len, void *addr , char *buf, int buflen)293 const char *format_host(int af, int len, void *addr) 271 294 { 272 295 if (resolve_hosts) { … … 287 310 h_ent = gethostbyaddr(addr, len, af); 288 311 if (h_ent != NULL) { 289 safe_strncpy(buf, h_ent->h_name, buflen); 290 return buf; 291 } 292 } 293 } 294 return rt_addr_n2a(af, addr, buf, buflen); 312 return auto_string(xstrdup(h_ent->h_name)); 313 } 314 } 315 } 316 return rt_addr_n2a(af, addr); 295 317 } 296 318 #endif -
branches/3.3/mindi-busybox/networking/libiproute/utils.h
r3232 r3621 67 67 extern uint16_t get_u16(char *arg, const char *errmsg); 68 68 69 extern const char *rt_addr_n2a(int af, void *addr , char *buf, int buflen);69 extern const char *rt_addr_n2a(int af, void *addr); 70 70 #ifdef RESOLVE_HOSTNAMES 71 extern const char *format_host(int af, int len, void *addr , char *buf, int buflen);71 extern const char *format_host(int af, int len, void *addr); 72 72 #else 73 #define format_host(af, len, addr , buf, buflen) \74 rt_addr_n2a(af, addr , buf, buflen)73 #define format_host(af, len, addr) \ 74 rt_addr_n2a(af, addr) 75 75 #endif 76 76 77 void invarg (const char *, const char *) NORETURN;77 void invarg_1_to_2(const char *, const char *) NORETURN; 78 78 void duparg(const char *, const char *) NORETURN; 79 79 void duparg2(const char *, const char *) NORETURN; … … 86 86 int ipx_pton(int af, const char *src, void *addr); 87 87 88 unsigned get_hz(void); 89 88 90 POP_SAVED_FUNCTION_VISIBILITY 89 91
Note:
See TracChangeset
for help on using the changeset viewer.