1303 files changed, 32187 insertions, 57138 deletions
diff --git a/networking/libiproute/ipaddress.c b/networking/libiproute/ipaddress.c index 1058b5a..21465dc 100644 --- a/networking/libiproute/ipaddress.c +++ b/networking/libiproute/ipaddress.c @@ -13,6 +13,7 @@ #include <net/if_arp.h> #include "ip_common.h" /* #include "libbb.h" is inside */ +#include "common_bufsiz.h" #include "rt_names.h" #include "utils.h" @@ -39,8 +40,8 @@ struct filter_t { } FIX_ALIASING; typedef struct filter_t filter_t; -#define G_filter (*(filter_t*)&bb_common_bufsiz1) - +#define G_filter (*(filter_t*)bb_common_bufsiz1) +#define INIT_G() do { setup_common_bufsiz(); } while (0) static void print_link_flags(unsigned flags, unsigned mdown) { @@ -137,12 +138,11 @@ static NOINLINE int print_linkinfo(const struct nlmsghdr *n) { unsigned m_flag = 0; if (tb[IFLA_LINK]) { - SPRINT_BUF(b1); int iflink = *(int*)RTA_DATA(tb[IFLA_LINK]); if (iflink == 0) printf("@NONE: "); else { - printf("@%s: ", ll_idx_n2a(iflink, b1)); + printf("@%s: ", ll_index_to_name(iflink)); m_flag = ll_index_to_flags(iflink); m_flag = !(m_flag & IFF_UP); } @@ -158,8 +158,7 @@ static NOINLINE int print_linkinfo(const struct nlmsghdr *n) printf("qdisc %s ", (char*)RTA_DATA(tb[IFLA_QDISC])); #ifdef IFLA_MASTER if (tb[IFLA_MASTER]) { - SPRINT_BUF(b1); - printf("master %s ", ll_idx_n2a(*(int*)RTA_DATA(tb[IFLA_MASTER]), b1)); + printf("master %s ", ll_index_to_name(*(int*)RTA_DATA(tb[IFLA_MASTER]))); } #endif /* IFLA_OPERSTATE was added to kernel with the same commit as IFF_DORMANT */ @@ -216,9 +215,7 @@ static int FAST_FUNC print_addrinfo(const struct sockaddr_nl *who UNUSED_PARAM, { struct ifaddrmsg *ifa = NLMSG_DATA(n); int len = n->nlmsg_len; - struct rtattr * rta_tb[IFA_MAX+1]; - char abuf[256]; - SPRINT_BUF(b1); + struct rtattr *rta_tb[IFA_MAX+1]; if (n->nlmsg_type != RTM_NEWADDR && n->nlmsg_type != RTM_DELADDR) return 0; @@ -250,7 +247,7 @@ static int FAST_FUNC print_addrinfo(const struct sockaddr_nl *who UNUSED_PARAM, if (rta_tb[IFA_LABEL]) label = RTA_DATA(rta_tb[IFA_LABEL]); else - label = ll_idx_n2a(ifa->ifa_index, b1); + label = ll_index_to_name(ifa->ifa_index); if (fnmatch(G_filter.label, label, 0) != 0) return 0; } @@ -294,9 +291,9 @@ static int FAST_FUNC print_addrinfo(const struct sockaddr_nl *who UNUSED_PARAM, printf(" family %d ", ifa->ifa_family); if (rta_tb[IFA_LOCAL]) { - fputs(rt_addr_n2a(ifa->ifa_family, - RTA_DATA(rta_tb[IFA_LOCAL]), - abuf, sizeof(abuf)), stdout); + fputs(rt_addr_n2a(ifa->ifa_family, RTA_DATA(rta_tb[IFA_LOCAL])), + stdout + ); if (rta_tb[IFA_ADDRESS] == NULL || memcmp(RTA_DATA(rta_tb[IFA_ADDRESS]), RTA_DATA(rta_tb[IFA_LOCAL]), 4) == 0 @@ -304,28 +301,25 @@ static int FAST_FUNC print_addrinfo(const struct sockaddr_nl *who UNUSED_PARAM, printf("/%d ", ifa->ifa_prefixlen); } else { printf(" peer %s/%d ", - rt_addr_n2a(ifa->ifa_family, - RTA_DATA(rta_tb[IFA_ADDRESS]), - abuf, sizeof(abuf)), - ifa->ifa_prefixlen); + rt_addr_n2a(ifa->ifa_family, RTA_DATA(rta_tb[IFA_ADDRESS])), + ifa->ifa_prefixlen + ); } } if (rta_tb[IFA_BROADCAST]) { printf("brd %s ", rt_addr_n2a(ifa->ifa_family, - RTA_DATA(rta_tb[IFA_BROADCAST]), - abuf, sizeof(abuf)) + RTA_DATA(rta_tb[IFA_BROADCAST])) ); } if (rta_tb[IFA_ANYCAST]) { printf("any %s ", rt_addr_n2a(ifa->ifa_family, - RTA_DATA(rta_tb[IFA_ANYCAST]), - abuf, sizeof(abuf)) + RTA_DATA(rta_tb[IFA_ANYCAST])) ); } - printf("scope %s ", rtnl_rtscope_n2a(ifa->ifa_scope, b1)); + printf("scope %s ", rtnl_rtscope_n2a(ifa->ifa_scope)); if (ifa->ifa_flags & IFA_F_SECONDARY) { ifa->ifa_flags &= ~IFA_F_SECONDARY; printf("secondary "); @@ -458,7 +452,7 @@ int FAST_FUNC ipaddr_list_or_flush(char **argv, int flush) G_filter.scopemask = -1; if (rtnl_rtscope_a2n(&scope, *argv)) { if (strcmp(*argv, "all") != 0) { - invarg(*argv, "scope"); + invarg_1_to_2(*argv, "scope"); } scope = RT_SCOPE_NOWHERE; G_filter.scopemask = 0; @@ -556,12 +550,11 @@ int FAST_FUNC ipaddr_list_or_flush(char **argv, int flush) continue; } if (G_filter.label) { - SPRINT_BUF(b1); const char *label; if (tb[IFA_LABEL]) label = RTA_DATA(tb[IFA_LABEL]); else - label = ll_idx_n2a(ifa->ifa_index, b1); + label = ll_index_to_name(ifa->ifa_index); if (fnmatch(G_filter.label, label, 0) != 0) continue; } @@ -598,7 +591,7 @@ static int default_scope(inet_prefix *lcl) } /* Return value becomes exitcode. It's okay to not return at all */ -static int ipaddr_modify(int cmd, char **argv) +static int ipaddr_modify(int cmd, int flags, char **argv) { static const char option[] ALIGN1 = "peer\0""remote\0""broadcast\0""brd\0" @@ -622,7 +615,7 @@ static int ipaddr_modify(int cmd, char **argv) memset(&req, 0, sizeof(req)); req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg)); - req.n.nlmsg_flags = NLM_F_REQUEST; + req.n.nlmsg_flags = NLM_F_REQUEST | flags; req.n.nlmsg_type = cmd; req.ifa.ifa_family = preferred_family; @@ -673,7 +666,7 @@ static int ipaddr_modify(int cmd, char **argv) } else if (arg == 5) { /* scope */ uint32_t scope = 0; if (rtnl_rtscope_a2n(&scope, *argv)) { - invarg(*argv, "scope"); + invarg_1_to_2(*argv, "scope"); } req.ifa.ifa_scope = scope; scoped = 1; @@ -701,7 +694,7 @@ static int ipaddr_modify(int cmd, char **argv) /* There was no "dev IFACE", but we need that */ bb_error_msg_and_die("need \"dev IFACE\""); } - if (l && strncmp(d, l, strlen(d)) != 0) { + if (l && !is_prefixed_with(l, d)) { bb_error_msg_and_die("\"dev\" (%s) must match \"label\" (%s)", d, l); } @@ -749,16 +742,27 @@ static int ipaddr_modify(int cmd, char **argv) int FAST_FUNC do_ipaddr(char **argv) { static const char commands[] ALIGN1 = - "add\0""delete\0""list\0""show\0""lst\0""flush\0"; + /* 0 1 2 3 4 5 6 7 8 */ + "add\0""change\0""chg\0""replace\0""delete\0""list\0""show\0""lst\0""flush\0"; int cmd = 2; + + INIT_G(); + if (*argv) { cmd = index_in_substrings(commands, *argv); if (cmd < 0) - invarg(*argv, applet_name); + invarg_1_to_2(*argv, applet_name); argv++; - if (cmd <= 1) - return ipaddr_modify((cmd == 0) ? RTM_NEWADDR : RTM_DELADDR, argv); + if (cmd <= 4) { + return ipaddr_modify( + /*cmd:*/ cmd == 4 ? RTM_DELADDR : RTM_NEWADDR, + /*flags:*/ + cmd == 0 ? NLM_F_CREATE|NLM_F_EXCL : /* add */ + cmd == 1 || cmd == 2 ? NLM_F_REPLACE : /* change */ + cmd == 3 ? NLM_F_CREATE|NLM_F_REPLACE : /* replace */ + 0 /* delete */ + , argv); + } } - /* 2 == list, 3 == show, 4 == lst */ - return ipaddr_list_or_flush(argv, cmd == 5); + return ipaddr_list_or_flush(argv, cmd == 8); } |