Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/networking/libiproute/iproute.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/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
Note:
See TracChangeset
for help on using the changeset viewer.