Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/networking/libiproute/ipaddress.c
- Timestamp:
- Dec 20, 2016, 4:07:32 PM (7 years ago)
- Location:
- branches/3.3
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note:
See TracChangeset
for help on using the changeset viewer.