diff options
Diffstat (limited to 'networking/libiproute/iproute.c')
-rw-r--r-- | networking/libiproute/iproute.c | 72 |
1 files changed, 22 insertions, 50 deletions
diff --git a/networking/libiproute/iproute.c b/networking/libiproute/iproute.c index 6ecd5f719..d232ee6fd 100644 --- a/networking/libiproute/iproute.c +++ b/networking/libiproute/iproute.c | |||
@@ -55,35 +55,12 @@ static int flush_update(void) | |||
55 | return 0; | 55 | return 0; |
56 | } | 56 | } |
57 | 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 = bb_clk_tck(); | ||
77 | return hz_internal; | ||
78 | } | ||
79 | |||
80 | static int FAST_FUNC print_route(const struct sockaddr_nl *who UNUSED_PARAM, | 58 | static int FAST_FUNC print_route(const struct sockaddr_nl *who UNUSED_PARAM, |
81 | struct nlmsghdr *n, void *arg UNUSED_PARAM) | 59 | struct nlmsghdr *n, void *arg UNUSED_PARAM) |
82 | { | 60 | { |
83 | struct rtmsg *r = NLMSG_DATA(n); | 61 | struct rtmsg *r = NLMSG_DATA(n); |
84 | int len = n->nlmsg_len; | 62 | int len = n->nlmsg_len; |
85 | struct rtattr *tb[RTA_MAX+1]; | 63 | struct rtattr *tb[RTA_MAX+1]; |
86 | char abuf[256]; | ||
87 | inet_prefix dst; | 64 | inet_prefix dst; |
88 | inet_prefix src; | 65 | inet_prefix src; |
89 | int host_len = -1; | 66 | int host_len = -1; |
@@ -217,7 +194,7 @@ static int FAST_FUNC print_route(const struct sockaddr_nl *who UNUSED_PARAM, | |||
217 | 194 | ||
218 | if (NLMSG_ALIGN(G_filter.flushp) + n->nlmsg_len > G_filter.flushe) { | 195 | if (NLMSG_ALIGN(G_filter.flushp) + n->nlmsg_len > G_filter.flushe) { |
219 | if (flush_update()) | 196 | if (flush_update()) |
220 | bb_error_msg_and_die("flush"); | 197 | xfunc_die(); |
221 | } | 198 | } |
222 | fn = (void*)(G_filter.flushb + NLMSG_ALIGN(G_filter.flushp)); | 199 | fn = (void*)(G_filter.flushb + NLMSG_ALIGN(G_filter.flushp)); |
223 | memcpy(fn, n, n->nlmsg_len); | 200 | memcpy(fn, n, n->nlmsg_len); |
@@ -240,17 +217,15 @@ static int FAST_FUNC print_route(const struct sockaddr_nl *who UNUSED_PARAM, | |||
240 | 217 | ||
241 | if (tb[RTA_DST]) { | 218 | if (tb[RTA_DST]) { |
242 | if (r->rtm_dst_len != host_len) { | 219 | if (r->rtm_dst_len != host_len) { |
243 | printf("%s/%u ", rt_addr_n2a(r->rtm_family, | 220 | printf("%s/%u ", |
244 | RTA_DATA(tb[RTA_DST]), | 221 | rt_addr_n2a(r->rtm_family, RTA_DATA(tb[RTA_DST])), |
245 | abuf, sizeof(abuf)), | 222 | r->rtm_dst_len |
246 | r->rtm_dst_len | 223 | ); |
247 | ); | ||
248 | } else { | 224 | } else { |
249 | printf("%s ", format_host(r->rtm_family, | 225 | printf("%s ", format_host(r->rtm_family, |
250 | RTA_PAYLOAD(tb[RTA_DST]), | 226 | RTA_PAYLOAD(tb[RTA_DST]), |
251 | RTA_DATA(tb[RTA_DST]), | 227 | RTA_DATA(tb[RTA_DST])) |
252 | abuf, sizeof(abuf)) | 228 | ); |
253 | ); | ||
254 | } | 229 | } |
255 | } else if (r->rtm_dst_len) { | 230 | } else if (r->rtm_dst_len) { |
256 | printf("0/%d ", r->rtm_dst_len); | 231 | printf("0/%d ", r->rtm_dst_len); |
@@ -259,17 +234,15 @@ static int FAST_FUNC print_route(const struct sockaddr_nl *who UNUSED_PARAM, | |||
259 | } | 234 | } |
260 | if (tb[RTA_SRC]) { | 235 | if (tb[RTA_SRC]) { |
261 | if (r->rtm_src_len != host_len) { | 236 | if (r->rtm_src_len != host_len) { |
262 | printf("from %s/%u ", rt_addr_n2a(r->rtm_family, | 237 | printf("from %s/%u ", |
263 | RTA_DATA(tb[RTA_SRC]), | 238 | rt_addr_n2a(r->rtm_family, RTA_DATA(tb[RTA_SRC])), |
264 | abuf, sizeof(abuf)), | 239 | r->rtm_src_len |
265 | r->rtm_src_len | 240 | ); |
266 | ); | ||
267 | } else { | 241 | } else { |
268 | printf("from %s ", format_host(r->rtm_family, | 242 | printf("from %s ", format_host(r->rtm_family, |
269 | RTA_PAYLOAD(tb[RTA_SRC]), | 243 | RTA_PAYLOAD(tb[RTA_SRC]), |
270 | RTA_DATA(tb[RTA_SRC]), | 244 | RTA_DATA(tb[RTA_SRC])) |
271 | abuf, sizeof(abuf)) | 245 | ); |
272 | ); | ||
273 | } | 246 | } |
274 | } else if (r->rtm_src_len) { | 247 | } else if (r->rtm_src_len) { |
275 | printf("from 0/%u ", r->rtm_src_len); | 248 | printf("from 0/%u ", r->rtm_src_len); |
@@ -277,8 +250,8 @@ static int FAST_FUNC print_route(const struct sockaddr_nl *who UNUSED_PARAM, | |||
277 | if (tb[RTA_GATEWAY] && G_filter.rvia.bitlen != host_len) { | 250 | if (tb[RTA_GATEWAY] && G_filter.rvia.bitlen != host_len) { |
278 | printf("via %s ", format_host(r->rtm_family, | 251 | printf("via %s ", format_host(r->rtm_family, |
279 | RTA_PAYLOAD(tb[RTA_GATEWAY]), | 252 | RTA_PAYLOAD(tb[RTA_GATEWAY]), |
280 | RTA_DATA(tb[RTA_GATEWAY]), | 253 | RTA_DATA(tb[RTA_GATEWAY])) |
281 | abuf, sizeof(abuf))); | 254 | ); |
282 | } | 255 | } |
283 | if (tb[RTA_OIF]) { | 256 | if (tb[RTA_OIF]) { |
284 | printf("dev %s ", ll_index_to_name(*(int*)RTA_DATA(tb[RTA_OIF]))); | 257 | printf("dev %s ", ll_index_to_name(*(int*)RTA_DATA(tb[RTA_OIF]))); |
@@ -291,8 +264,7 @@ static int FAST_FUNC print_route(const struct sockaddr_nl *who UNUSED_PARAM, | |||
291 | and symbolic name will not be useful. | 264 | and symbolic name will not be useful. |
292 | */ | 265 | */ |
293 | printf(" src %s ", rt_addr_n2a(r->rtm_family, | 266 | printf(" src %s ", rt_addr_n2a(r->rtm_family, |
294 | RTA_DATA(tb[RTA_PREFSRC]), | 267 | RTA_DATA(tb[RTA_PREFSRC]))); |
295 | abuf, sizeof(abuf))); | ||
296 | } | 268 | } |
297 | if (tb[RTA_PRIORITY]) { | 269 | if (tb[RTA_PRIORITY]) { |
298 | printf(" metric %d ", *(uint32_t*)RTA_DATA(tb[RTA_PRIORITY])); | 270 | printf(" metric %d ", *(uint32_t*)RTA_DATA(tb[RTA_PRIORITY])); |
@@ -425,7 +397,7 @@ IF_FEATURE_IP_RULE(ARG_table,) | |||
425 | uint32_t prot; | 397 | uint32_t prot; |
426 | NEXT_ARG(); | 398 | NEXT_ARG(); |
427 | if (rtnl_rtprot_a2n(&prot, *argv)) | 399 | if (rtnl_rtprot_a2n(&prot, *argv)) |
428 | invarg(*argv, "protocol"); | 400 | invarg_1_to_2(*argv, "protocol"); |
429 | req.r.rtm_protocol = prot; | 401 | req.r.rtm_protocol = prot; |
430 | ok |= proto_ok; | 402 | ok |= proto_ok; |
431 | #if ENABLE_FEATURE_IP_RULE | 403 | #if ENABLE_FEATURE_IP_RULE |
@@ -433,7 +405,7 @@ IF_FEATURE_IP_RULE(ARG_table,) | |||
433 | uint32_t tid; | 405 | uint32_t tid; |
434 | NEXT_ARG(); | 406 | NEXT_ARG(); |
435 | if (rtnl_rttable_a2n(&tid, *argv)) | 407 | if (rtnl_rttable_a2n(&tid, *argv)) |
436 | invarg(*argv, "table"); | 408 | invarg_1_to_2(*argv, "table"); |
437 | req.r.rtm_table = tid; | 409 | req.r.rtm_table = tid; |
438 | #endif | 410 | #endif |
439 | } else if (arg == ARG_dev || arg == ARG_oif) { | 411 | } else if (arg == ARG_dev || arg == ARG_oif) { |
@@ -619,7 +591,7 @@ static int iproute_list_or_flush(char **argv, int flush) | |||
619 | //G_filter.protocolmask = -1; | 591 | //G_filter.protocolmask = -1; |
620 | if (rtnl_rtprot_a2n(&prot, *argv)) { | 592 | if (rtnl_rtprot_a2n(&prot, *argv)) { |
621 | if (index_in_strings(keywords, *argv) != KW_all) | 593 | if (index_in_strings(keywords, *argv) != KW_all) |
622 | invarg(*argv, "protocol"); | 594 | invarg_1_to_2(*argv, "protocol"); |
623 | prot = 0; | 595 | prot = 0; |
624 | //G_filter.protocolmask = 0; | 596 | //G_filter.protocolmask = 0; |
625 | } | 597 | } |
@@ -644,10 +616,10 @@ static int iproute_list_or_flush(char **argv, int flush) | |||
644 | #if ENABLE_FEATURE_IP_RULE | 616 | #if ENABLE_FEATURE_IP_RULE |
645 | uint32_t tid; | 617 | uint32_t tid; |
646 | if (rtnl_rttable_a2n(&tid, *argv)) | 618 | if (rtnl_rttable_a2n(&tid, *argv)) |
647 | invarg(*argv, "table"); | 619 | invarg_1_to_2(*argv, "table"); |
648 | G_filter.tb = tid; | 620 | G_filter.tb = tid; |
649 | #else | 621 | #else |
650 | invarg(*argv, "table"); | 622 | invarg_1_to_2(*argv, "table"); |
651 | #endif | 623 | #endif |
652 | } | 624 | } |
653 | } else if (arg == KW_cache) { | 625 | } else if (arg == KW_cache) { |
@@ -954,7 +926,7 @@ int FAST_FUNC do_iproute(char **argv) | |||
954 | case 11: /* flush */ | 926 | case 11: /* flush */ |
955 | return iproute_list_or_flush(argv+1, 1); | 927 | return iproute_list_or_flush(argv+1, 1); |
956 | default: | 928 | default: |
957 | bb_error_msg_and_die("unknown command %s", *argv); | 929 | invarg_1_to_2(*argv, applet_name); |
958 | } | 930 | } |
959 | 931 | ||
960 | return iproute_modify(cmd, flags, argv+1); | 932 | return iproute_modify(cmd, flags, argv+1); |