Print this page
7388 Support DHCP Client FQDN. Allow IAID/DUID for all v4.

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/cmd-inet/usr.sbin/ipadm/ipadm.c
          +++ new/usr/src/cmd/cmd-inet/usr.sbin/ipadm/ipadm.c
↓ open down ↓ 13 lines elided ↑ open up ↑
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  /*
  22   22   * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  23   23   * Copyright 2012 Nexenta Systems, Inc. All rights reserved.
       24 + * Copyright (c) 2016, Chris Fraire <cfraire@me.com>.
  24   25   */
  25   26  #include <arpa/inet.h>
  26   27  #include <errno.h>
  27   28  #include <getopt.h>
  28   29  #include <inet/ip.h>
  29   30  #include <inet/iptun.h>
  30   31  #include <inet/tunables.h>
  31   32  #include <libdladm.h>
  32   33  #include <libdliptun.h>
  33   34  #include <libdllink.h>
↓ open down ↓ 47 lines elided ↑ open up ↑
  81   82          { "reset-ifprop", do_reset_ifprop,
  82   83              "\treset-ifprop\t[-t] -p <prop> -m <protocol> <interface>"  },
  83   84          { "show-ifprop", do_show_ifprop,
  84   85              "\tshow-ifprop\t[[-c] -o <field>,...] [-p <prop>,...]\n"
  85   86              "\t\t\t[-m <protocol>] [interface]\n"                       },
  86   87  
  87   88          /* address management related sub-commands */
  88   89          { "create-addr", do_create_addr,
  89   90              "\tcreate-addr\t[-t] -T static [-d] "
  90   91              "-a{local|remote}=addr[/prefixlen]\n\t\t\t<addrobj>\n"
  91      -            "\tcreate-addr\t[-t] -T dhcp [-w <seconds> | forever] <addrobj>\n"
       92 +            "\tcreate-addr\t[-t] -T dhcp [-w <seconds> | forever]\n"
       93 +            "\t\t\t[-1] [-h <hostname>] <addrobj>\n"
  92   94              "\tcreate-addr\t[-t] -T addrconf [-i interface-id]\n"
  93   95              "\t\t\t[-p {stateful|stateless}={yes|no}] <addrobj>" },
  94   96          { "down-addr",  do_down_addr,   "\tdown-addr\t[-t] <addrobj>"   },
  95   97          { "up-addr",    do_up_addr,     "\tup-addr\t\t[-t] <addrobj>"   },
  96   98          { "disable-addr", do_disable_addr, "\tdisable-addr\t-t <addrobj>" },
  97   99          { "enable-addr", do_enable_addr, "\tenable-addr\t-t <addrobj>"  },
  98  100          { "refresh-addr", do_refresh_addr, "\trefresh-addr\t[-i] <addrobj>" },
  99  101          { "delete-addr", do_delete_addr, "\tdelete-addr\t[-r] <addrobj>" },
 100  102          { "show-addr",  do_show_addr,
 101  103              "\tshow-addr\t[[-p] -o <field>,...] [<addrobj>]\n"          },
↓ open down ↓ 52 lines elided ↑ open up ↑
 154  156          {"inform",      no_argument,            0, 'i'  },
 155  157          {"release",     no_argument,            0, 'r'  },
 156  158          {"temporary",   no_argument,            0, 't'  },
 157  159          { 0, 0, 0, 0 }
 158  160  };
 159  161  
 160  162  static const struct option addr_longopts[] = {
 161  163          {"address",     required_argument,      0, 'a'  },
 162  164          {"down",        no_argument,            0, 'd'  },
 163  165          {"interface-id", required_argument,     0, 'i'  },
      166 +        {"primary",     no_argument,            0, '1'  },
 164  167          {"prop",        required_argument,      0, 'p'  },
      168 +        {"reqhost", required_argument,  0, 'h'  },
 165  169          {"temporary",   no_argument,            0, 't'  },
 166  170          {"type",        required_argument,      0, 'T'  },
 167  171          {"wait",        required_argument,      0, 'w'  },
 168  172          { 0, 0, 0, 0 }
 169  173  };
 170  174  
 171  175  static const struct option show_addr_longopts[] = {
 172  176          {"parsable",    no_argument,            0, 'p'  },
 173  177          {"output",      required_argument,      0, 'o'  },
 174  178          { 0, 0, 0, 0 }
↓ open down ↓ 450 lines elided ↑ open up ↑
 625  629           * stop the walker.
 626  630           */
 627  631          if (statep->sps_status == IPADM_NOTFOUND ||
 628  632              statep->sps_status == IPADM_NOTSUP)
 629  633                  return (_B_FALSE);
 630  634          return (_B_TRUE);
 631  635  }
 632  636  
 633  637  /*
 634  638   * Properties to be displayed is in `statep->sps_proplist'. If it is NULL,
 635      - * for all the properties for the specified object, relavant information, will
 636      - * be displayed. Otherwise, for the selected property set, display relevant
      639 + * for all the properties for the specified object, display relevant
      640 + * information. Otherwise, for the selected property set, display relevant
 637  641   * information
 638  642   */
 639  643  static void
 640  644  show_properties(void *arg, int prop_class)
 641  645  {
 642  646          show_prop_state_t       *statep = arg;
 643  647          nvlist_t                *nvl = statep->sps_proplist;
 644  648          uint_t                  proto = statep->sps_proto;
 645  649          nvpair_t                *curr_nvp;
 646  650          char                    *buf, *name;
↓ open down ↓ 604 lines elided ↑ open up ↑
1251 1255          ipadm_status_t  status;
1252 1256          int             option;
1253 1257          uint32_t        flags =
1254 1258              IPADM_OPT_PERSIST|IPADM_OPT_ACTIVE|IPADM_OPT_UP|IPADM_OPT_V46;
1255 1259          char            *cp;
1256 1260          char            *atype = NULL;
1257 1261          char            *static_arg = NULL;
1258 1262          char            *addrconf_arg = NULL;
1259 1263          char            *interface_id = NULL;
1260 1264          char            *wait = NULL;
     1265 +        char            *reqhost = NULL;
1261 1266          boolean_t       s_opt = _B_FALSE;       /* static addr options */
1262 1267          boolean_t       auto_opt = _B_FALSE;    /* Addrconf options */
1263 1268          boolean_t       dhcp_opt = _B_FALSE;    /* dhcp options */
     1269 +        boolean_t       primary_opt = _B_FALSE; /* dhcp primary option */
1264 1270  
1265 1271          opterr = 0;
1266      -        while ((option = getopt_long(argc, argv, ":T:a:di:p:w:t",
     1272 +        while ((option = getopt_long(argc, argv, ":1T:a:dh:i:p:w:t",
1267 1273              addr_longopts, NULL)) != -1) {
1268 1274                  switch (option) {
     1275 +                case '1':
     1276 +                        primary_opt = _B_TRUE;
     1277 +                        break;
1269 1278                  case 'T':
1270 1279                          atype = optarg;
1271 1280                          break;
1272 1281                  case 'a':
1273 1282                          static_arg = optarg;
1274 1283                          s_opt = _B_TRUE;
1275 1284                          break;
1276 1285                  case 'd':
1277 1286                          flags &= ~IPADM_OPT_UP;
1278 1287                          s_opt = _B_TRUE;
1279 1288                          break;
     1289 +                case 'h':
     1290 +                        reqhost = optarg;
     1291 +                        break;
1280 1292                  case 'i':
1281 1293                          interface_id = optarg;
1282 1294                          auto_opt = _B_TRUE;
1283 1295                          break;
1284 1296                  case 'p':
1285 1297                          addrconf_arg = optarg;
1286 1298                          auto_opt = _B_TRUE;
1287 1299                          break;
1288 1300                  case 'w':
1289 1301                          wait = optarg;
↓ open down ↓ 11 lines elided ↑ open up ↑
1301 1313          } else if ((cp = strchr(argv[optind], '/')) == NULL ||
1302 1314              strlen(++cp) == 0) {
1303 1315                  die("invalid address object name: %s\nusage: %s",
1304 1316                      argv[optind], use);
1305 1317          }
1306 1318  
1307 1319          /*
1308 1320           * Allocate and initialize the addrobj based on the address type.
1309 1321           */
1310 1322          if (strcmp(atype, "static") == 0) {
1311      -                if (static_arg == NULL || auto_opt || dhcp_opt) {
     1323 +                if (static_arg == NULL || auto_opt || dhcp_opt
     1324 +                    || reqhost != NULL || primary_opt) {
1312 1325                          die("Invalid arguments for type %s\nusage: %s",
1313 1326                              atype, use);
1314 1327                  }
1315 1328                  process_static_addrargs(use, static_arg, argv[optind]);
1316 1329          } else if (strcmp(atype, "dhcp") == 0) {
1317 1330                  if (auto_opt || s_opt) {
1318 1331                          die("Invalid arguments for type %s\nusage: %s",
1319 1332                              atype, use);
1320 1333                  }
1321 1334  
↓ open down ↓ 16 lines elided ↑ open up ↑
1338 1351                                  if (*end != '\0' || timeout < 0)
1339 1352                                          die("Invalid argument");
1340 1353                                  ipadm_wait = (int32_t)timeout;
1341 1354                          }
1342 1355                          status = ipadm_set_wait_time(ipaddr, ipadm_wait);
1343 1356                          if (status != IPADM_SUCCESS) {
1344 1357                                  die("Error in setting wait time: %s",
1345 1358                                      ipadm_status2str(status));
1346 1359                          }
1347 1360                  }
     1361 +                if (primary_opt) {
     1362 +                        status = ipadm_set_primary(ipaddr, _B_TRUE);
     1363 +                        if (status != IPADM_SUCCESS) {
     1364 +                                die("Error in setting primary flag: %s",
     1365 +                                    ipadm_status2str(status));
     1366 +                        }
     1367 +                }
     1368 +                if (reqhost != NULL) {
     1369 +                        status = ipadm_set_reqhost(ipaddr, reqhost);
     1370 +                        if (status != IPADM_SUCCESS) {
     1371 +                                die("Error in setting reqhost: %s",
     1372 +                                    ipadm_status2str(status));
     1373 +                        }
     1374 +                }
1348 1375          } else if (strcmp(atype, "addrconf") == 0) {
1349      -                if (dhcp_opt || s_opt) {
     1376 +                if (dhcp_opt || s_opt || reqhost != NULL || primary_opt) {
1350 1377                          die("Invalid arguments for type %s\nusage: %s",
1351 1378                              atype, use);
1352 1379                  }
1353 1380  
1354      -                /* Initialize the addrobj for dhcp addresses. */
     1381 +                /* Initialize the addrobj for ipv6-addrconf addresses. */
1355 1382                  status = ipadm_create_addrobj(IPADM_ADDR_IPV6_ADDRCONF,
1356 1383                      argv[optind], &ipaddr);
1357 1384                  if (status != IPADM_SUCCESS) {
1358 1385                          die("Error in creating address object: %s",
1359 1386                              ipadm_status2str(status));
1360 1387                  }
1361 1388                  if (interface_id != NULL) {
1362 1389                          status = ipadm_set_interface_id(ipaddr, interface_id);
1363 1390                          if (status != IPADM_SUCCESS) {
1364 1391                                  die("Error in setting interface ID: %s",
↓ open down ↓ 860 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX