Changeset 4437573 in rtems-libbsd


Ignore:
Timestamp:
04/27/17 03:57:28 (7 years ago)
Author:
Chris Johns <chrisj@…>
Branches:
5, 5-freebsd-12, 6-freebsd-12, master
Children:
53914f2
Parents:
43c65f5
Message:

rc_conf: Add support for ifconfig_<interface>_alias[0-9]+.

The interface alias allows extra IP addresses to be set on and
interface and it also allows the MAC address to be set.

Examples:

ifconfig_em0="inet 10.10.5.33 netmask 255.255.255.0"
ifconfig_em0_alias0="ether 10:22:33:44:55:66"
ifconfig_em0_alias1="inet 10.1.1.111 netmask 0xffffffff"

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • rtemsbsd/rtems/rtems-bsd-rc-conf-net.c

    r43c65f5 r4437573  
    222222
    223223/*
     224 * ifconfig_show
     225
     226 */
     227static int
     228ifconfig_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/*
    224235 * ifconfig_'interface'
    225236 *
    226237 * 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"
    227240 *
    228241 * See 'man rc.conf(5)' on FreeBSD.
     
    232245          const char*        ifname,
    233246          int                argc,
    234           const char**       argv)
     247          const char**       argv,
     248          int                opt_argc,
     249          const char**       opt_argv,
     250          bool               add_up)
    235251{
    236252  const char**      args;
    237253  int               arg;
    238254  int               ifconfig_argc = 0;
    239   bool              add_up = true;
    240255  int               r;
    241   const char const* ifconfig_show[] = { "ifconfig", ifname, NULL };
    242256
    243257  for (arg = 1; arg < argc; ++arg) {
     
    246260  }
    247261
    248   args = calloc(argc + 3, sizeof(char*));
     262  args = calloc(argc + opt_argc + 3, sizeof(char*));
    249263  if (args == NULL) {
    250264    errno = ENOMEM;
     
    257271  for (arg = 1; arg < argc; ++arg) {
    258272    if (strcasecmp("DHCP",     argv[arg]) == 0 ||
    259         strcasecmp("SYNCDHCP", argv[arg]) == 0) {
     273        strcasecmp("SYNCDHCP", argv[arg]) == 0 ||
     274        strcasecmp("UP",       argv[arg]) == 0) {
    260275      add_up = false;
    261276    }
     
    265280  }
    266281
     282  if (opt_argv != NULL) {
     283    for (arg = 0; arg < opt_argc; ++arg) {
     284      args[ifconfig_argc++] = opt_argv[arg];
     285    }
     286  }
     287
    267288  if (add_up)
    268289    args[ifconfig_argc++] = "up";
     
    278299    return -1;
    279300  }
    280 
    281   r = rtems_bsd_command_ifconfig(2, (char**) ifconfig_show);
    282301
    283302  return r;
     
    354373
    355374static int
    356 show_interfaces(const char* msg, struct ifaddrs* ifap)
     375list_interfaces(const char* msg, struct ifaddrs* ifap)
    357376{
    358377  struct ifaddrs* ifa;
     
    378397
    379398  fprintf(stdout, "\b.\n");
     399
     400  return 0;
     401}
     402
     403static int
     404show_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  }
    380411
    381412  return 0;
     
    404435        "ifconfig_lo0", "inet", "127.0.0.1", "netmask", "255.0.0.0", NULL
    405436      };
    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));
    407442      return 0;
    408443    }
     
    436471         * interface.
    437472         */
    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        }
    439490      }
    440491    }
     
    494545              }
    495546              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));
    498552              }
    499553            }
     
    700754  }
    701755
    702   show_interfaces("Starting network: ", ifap);
     756  list_interfaces("Starting network: ", ifap);
    703757  show_result("cloned_interfaces", cloned_interfaces(rc_conf, aa));
    704758  show_result("lo0", setup_lo0(rc_conf, ifap));
     
    706760  show_result("vlans", setup_vlans(rc_conf, aa, ifap, &dhcp));
    707761  show_result("defaultrouter", defaultrouter(rc_conf, aa));
     762  show_interfaces(ifap);
    708763  if (dhcp)
    709764    show_result("dhcp", run_dhcp(rc_conf, aa));
  • testsuite/rcconf01/test_main.c

    r43c65f5 r4437573  
    7070  test_service_last_num = 1;
    7171
     72  /*
     73   * Fill match of anything.
     74   */
     75  puts("test_service regex: 'test_regex_.*'");
     76  test_regex_last_num = 0;
     77
    7278  assert((aa = rtems_bsd_rc_conf_argc_argv_create()) != NULL);
    7379  r = rtems_bsd_rc_conf_find(rc_conf, "test_regex_.*", aa);
     
    7985    int num;
    8086    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);
    8288    assert(strncasecmp(aa->argv[0], "test_regex_", strlen("test_regex_")) == 0);
    8389    num = atoi(aa->argv[0] + strlen("test_regex_"));
     
    99105    assert(r == 0 || (r < 0 && errno == ENOENT));
    100106  }
     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
    101144  rtems_bsd_rc_conf_argc_argv_destroy(aa);
    102145  puts("test_service done");
  • testsuite/rcconf02/test_main.c

    r43c65f5 r4437573  
    7676  "ifconfig_" # iface "=\"inet " NET_CFG_SELF_IP " netmask " NET_CFG_NETMASK "\"\n"
    7777
    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 \
    8083  IFACE_IPV4(dmc0)  \
    8184  IFACE_IPV4(sm0)   \
     
    8487  IFACE_IPV4(em0)   \
    8588  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
    86101
    87102#define IFACE_VLAN(iface) \
Note: See TracChangeset for help on using the changeset viewer.