Changeset 4437573 in rtems-libbsd
- Timestamp:
- 04/27/17 03:57:28 (7 years ago)
- Branches:
- 5, 5-freebsd-12, 6-freebsd-12, master
- Children:
- 53914f2
- Parents:
- 43c65f5
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
rtemsbsd/rtems/rtems-bsd-rc-conf-net.c
r43c65f5 r4437573 222 222 223 223 /* 224 * ifconfig_show 225 226 */ 227 static int 228 ifconfig_show(const char* ifname) 229 { 230 const char const* ifconfig_show[] = { "ifconfig", ifname, NULL }; 231 return rtems_bsd_command_ifconfig(2, (char**) ifconfig_show); 232 } 233 234 /* 224 235 * ifconfig_'interface' 225 236 * 226 237 * eg ifconfig_em0="inet 10.10.5.33 netmask 255.255.255.0" 238 * ifconfig_em0_alias0="ether 10:22:33:44:55:66" 239 * ifconfig_em0_alias1="inet 10.1.1.111 netmask 0xffffffff" 227 240 * 228 241 * See 'man rc.conf(5)' on FreeBSD. … … 232 245 const char* ifname, 233 246 int argc, 234 const char** argv) 247 const char** argv, 248 int opt_argc, 249 const char** opt_argv, 250 bool add_up) 235 251 { 236 252 const char** args; 237 253 int arg; 238 254 int ifconfig_argc = 0; 239 bool add_up = true;240 255 int r; 241 const char const* ifconfig_show[] = { "ifconfig", ifname, NULL };242 256 243 257 for (arg = 1; arg < argc; ++arg) { … … 246 260 } 247 261 248 args = calloc(argc + 3, sizeof(char*));262 args = calloc(argc + opt_argc + 3, sizeof(char*)); 249 263 if (args == NULL) { 250 264 errno = ENOMEM; … … 257 271 for (arg = 1; arg < argc; ++arg) { 258 272 if (strcasecmp("DHCP", argv[arg]) == 0 || 259 strcasecmp("SYNCDHCP", argv[arg]) == 0) { 273 strcasecmp("SYNCDHCP", argv[arg]) == 0 || 274 strcasecmp("UP", argv[arg]) == 0) { 260 275 add_up = false; 261 276 } … … 265 280 } 266 281 282 if (opt_argv != NULL) { 283 for (arg = 0; arg < opt_argc; ++arg) { 284 args[ifconfig_argc++] = opt_argv[arg]; 285 } 286 } 287 267 288 if (add_up) 268 289 args[ifconfig_argc++] = "up"; … … 278 299 return -1; 279 300 } 280 281 r = rtems_bsd_command_ifconfig(2, (char**) ifconfig_show);282 301 283 302 return r; … … 354 373 355 374 static int 356 show_interfaces(const char* msg, struct ifaddrs* ifap)375 list_interfaces(const char* msg, struct ifaddrs* ifap) 357 376 { 358 377 struct ifaddrs* ifa; … … 378 397 379 398 fprintf(stdout, "\b.\n"); 399 400 return 0; 401 } 402 403 static int 404 show_interfaces(struct ifaddrs* ifap) 405 { 406 struct ifaddrs* ifa; 407 408 for (ifa = ifap; ifa; ifa = ifa->ifa_next) { 409 ifconfig_show(ifa->ifa_name); 410 } 380 411 381 412 return 0; … … 404 435 "ifconfig_lo0", "inet", "127.0.0.1", "netmask", "255.0.0.0", NULL 405 436 }; 406 show_result("lo0", ifconfig_(rc_conf, "lo0", 5, lo0_argv)); 437 show_result("lo0", 438 ifconfig_(rc_conf, "lo0", 439 5, lo0_argv, 440 0, NULL, 441 true)); 407 442 return 0; 408 443 } … … 436 471 * interface. 437 472 */ 438 show_result(iface, ifconfig_(rc_conf, ifa->ifa_name, aa->argc, aa->argv)); 473 show_result(iface, ifconfig_(rc_conf, ifa->ifa_name, 474 aa->argc, aa->argv, 475 0, NULL, 476 true)); 477 } 478 snprintf(iface, sizeof(iface), "ifconfig_%s_alias[0-9]+", ifa->ifa_name); 479 if (r == 0) { 480 r = rtems_bsd_rc_conf_find(rc_conf, iface, aa); 481 while (r == 0) { 482 const char* alias_argv[] = { "alias", NULL }; 483 show_result(iface, 484 ifconfig_(rc_conf, ifa->ifa_name, 485 aa->argc, aa->argv, 486 1, alias_argv, 487 false)); 488 r = rtems_bsd_rc_conf_find_next(rc_conf, aa); 489 } 439 490 } 440 491 } … … 494 545 } 495 546 else { 496 show_result(vlan_name, ifconfig_(rc_conf, vlan_name, 497 vaa->argc, vaa->argv)); 547 show_result(vlan_name, 548 ifconfig_(rc_conf, vlan_name, 549 vaa->argc, vaa->argv, 550 0, NULL, 551 true)); 498 552 } 499 553 } … … 700 754 } 701 755 702 show_interfaces("Starting network: ", ifap);756 list_interfaces("Starting network: ", ifap); 703 757 show_result("cloned_interfaces", cloned_interfaces(rc_conf, aa)); 704 758 show_result("lo0", setup_lo0(rc_conf, ifap)); … … 706 760 show_result("vlans", setup_vlans(rc_conf, aa, ifap, &dhcp)); 707 761 show_result("defaultrouter", defaultrouter(rc_conf, aa)); 762 show_interfaces(ifap); 708 763 if (dhcp) 709 764 show_result("dhcp", run_dhcp(rc_conf, aa)); -
testsuite/rcconf01/test_main.c
r43c65f5 r4437573 70 70 test_service_last_num = 1; 71 71 72 /* 73 * Fill match of anything. 74 */ 75 puts("test_service regex: 'test_regex_.*'"); 76 test_regex_last_num = 0; 77 72 78 assert((aa = rtems_bsd_rc_conf_argc_argv_create()) != NULL); 73 79 r = rtems_bsd_rc_conf_find(rc_conf, "test_regex_.*", aa); … … 79 85 int num; 80 86 int arg; 81 rtems_bsd_rc_conf_print_cmd(rc_conf, "test_service ", aa->argc, aa->argv);87 rtems_bsd_rc_conf_print_cmd(rc_conf, "test_service[1]", aa->argc, aa->argv); 82 88 assert(strncasecmp(aa->argv[0], "test_regex_", strlen("test_regex_")) == 0); 83 89 num = atoi(aa->argv[0] + strlen("test_regex_")); … … 99 105 assert(r == 0 || (r < 0 && errno == ENOENT)); 100 106 } 107 108 /* 109 * Specific match of only numbers. 110 */ 111 puts("test_service regex: 'test_regex_[0-9]+'"); 112 test_regex_last_num = 0; 113 114 assert((aa = rtems_bsd_rc_conf_argc_argv_create()) != NULL); 115 r = rtems_bsd_rc_conf_find(rc_conf, "test_regex_[0-9]+", aa); 116 assert(r == 0 || (r < 0 && errno == ENOENT)); 117 if (r < 0 && errno == ENOENT) 118 return -1; 119 120 while (r == 0) { 121 int num; 122 int arg; 123 rtems_bsd_rc_conf_print_cmd(rc_conf, "test_service[2]", aa->argc, aa->argv); 124 assert(strncasecmp(aa->argv[0], "test_regex_", strlen("test_regex_")) == 0); 125 num = atoi(aa->argv[0] + strlen("test_regex_")); 126 assert(num == (test_regex_last_num + 1)); 127 assert((num - 1) < NUM_OF_TEST_REGEX_); 128 for (arg = 0; arg < aa->argc; ++arg) { 129 const char* a = aa->argv[arg]; 130 size_t l = strlen(a); 131 if (l > 0) { 132 assert(!isspace(a[0])); 133 assert(!isspace(a[l - 1])); 134 assert(a[0] != '"'); 135 assert(a[l - 1] != '"'); 136 } 137 } 138 test_regex_results[num - 1] = true; 139 ++test_regex_last_num; 140 r = rtems_bsd_rc_conf_find_next(rc_conf, aa); 141 assert(r == 0 || (r < 0 && errno == ENOENT)); 142 } 143 101 144 rtems_bsd_rc_conf_argc_argv_destroy(aa); 102 145 puts("test_service done"); -
testsuite/rcconf02/test_main.c
r43c65f5 r4437573 76 76 "ifconfig_" # iface "=\"inet " NET_CFG_SELF_IP " netmask " NET_CFG_NETMASK "\"\n" 77 77 78 79 #define RC_CONF_IFACES \ 78 #define IFACE_ALIAS(iface) \ 79 "ifconfig_" # iface "_alias0=\"ether 10:22:33:44:55:66\"\n" \ 80 "ifconfig_" # iface "_alias1=\"inet 10.1.1.111 netmask 0xffffffff\"\n" 81 82 #define RC_CONF_IFACES_IPV4 \ 80 83 IFACE_IPV4(dmc0) \ 81 84 IFACE_IPV4(sm0) \ … … 84 87 IFACE_IPV4(em0) \ 85 88 IFACE_IPV4(re0) 89 90 #define RC_CONF_IFACES_ALIAS \ 91 IFACE_ALIAS(dmc0) \ 92 IFACE_ALIAS(sm0) \ 93 IFACE_ALIAS(cgem0) \ 94 IFACE_ALIAS(fec0) \ 95 IFACE_ALIAS(em0) \ 96 IFACE_ALIAS(re0) 97 98 #define RC_CONF_IFACES \ 99 RC_CONF_IFACES_IPV4 \ 100 RC_CONF_IFACES_ALIAS 86 101 87 102 #define IFACE_VLAN(iface) \
Note: See TracChangeset
for help on using the changeset viewer.