Print this page
OS-200 need a better mechanism for storing persistent zone_did
OS-511 make zonecfg device resource extensible, like the net resource
OS-224 add more zonecfg net properties
OS-216 store all net config info on zone

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/zonecfg/zonecfg.c
          +++ new/usr/src/cmd/zonecfg/zonecfg.c
↓ open down ↓ 227 lines elided ↑ open up ↑
 228  228          ALIAS_MAXSWAP,
 229  229          "scheduling-class",
 230  230          "ip-type",
 231  231          "defrouter",
 232  232          "hostid",
 233  233          "user",
 234  234          "auths",
 235  235          "fs-allowed",
 236  236          ALIAS_MAXPROCS,
 237  237          "allowed-address",
      238 +        ALIAS_ZFSPRI,
      239 +        "mac-addr",
      240 +        "vlan-id",
      241 +        "global-nic",
      242 +        "property",
 238  243          NULL
 239  244  };
 240  245  
 241  246  /* These *must* match the order of the PROP_VAL_ define's from zonecfg.h */
 242  247  static char *prop_val_types[] = {
 243  248          "simple",
 244  249          "complex",
 245  250          "list",
 246  251  };
 247  252  
↓ open down ↓ 152 lines elided ↑ open up ↑
 400  405          "clear raw",
 401  406          NULL
 402  407  };
 403  408  
 404  409  static const char *net_res_scope_cmds[] = {
 405  410          "cancel",
 406  411          "end",
 407  412          "exit",
 408  413          "help",
 409  414          "info",
      415 +        "add property ",
      416 +        "clear allowed-address",
      417 +        "clear defrouter",
      418 +        "clear global-nic",
      419 +        "clear mac-addr",
      420 +        "clear vlan-id",
      421 +        "remove property ",
 410  422          "set address=",
 411      -        "set physical=",
      423 +        "set allowed-address=",
 412  424          "set defrouter=",
      425 +        "set global-nic=",
      426 +        "set mac-addr=",
      427 +        "set physical=",
      428 +        "set vlan-id=",
 413  429          NULL
 414  430  };
 415  431  
 416  432  static const char *device_res_scope_cmds[] = {
 417  433          "cancel",
 418  434          "end",
 419  435          "exit",
 420  436          "help",
 421  437          "info",
      438 +        "add property ",
 422  439          "set match=",
 423  440          NULL
 424  441  };
 425  442  
 426  443  static const char *attr_res_scope_cmds[] = {
 427  444          "cancel",
 428  445          "end",
 429  446          "exit",
 430  447          "help",
 431  448          "info",
↓ open down ↓ 639 lines elided ↑ open up ↑
1071 1088                              /*CSTYLED*/
1072 1089                              "such as \"%s=5\".\n"), MNTOPT_RETRY);
1073 1090                          break;
1074 1091                  case RT_NET:
1075 1092                          (void) fprintf(fp, gettext("The '%s' resource scope is "
1076 1093                              "used to configure a network interface.\n"),
1077 1094                              rt_to_str(resource_scope));
1078 1095                          (void) fprintf(fp, gettext("Valid commands:\n"));
1079 1096                          (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET),
1080 1097                              pt_to_str(PT_ADDRESS), gettext("<IP-address>"));
     1098 +                        (void) fprintf(fp, "\t%s %s (%s=<value>,%s=<value>)\n",
     1099 +                            cmd_to_str(CMD_ADD), pt_to_str(PT_NPROP),
     1100 +                            pt_to_str(PT_NAME), pt_to_str(PT_VALUE));
1081 1101                          (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET),
1082 1102                              pt_to_str(PT_ALLOWED_ADDRESS),
1083 1103                              gettext("<IP-address>"));
1084 1104                          (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET),
1085 1105                              pt_to_str(PT_PHYSICAL), gettext("<interface>"));
     1106 +                        (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET),
     1107 +                            pt_to_str(PT_MAC), gettext("<mac-address>"));
     1108 +                        (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET),
     1109 +                            pt_to_str(PT_GNIC), gettext("<global zone NIC>"));
     1110 +                        (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET),
     1111 +                            pt_to_str(PT_VLANID), gettext("<vlan ID>"));
1086 1112                          (void) fprintf(fp, gettext("See ifconfig(1M) for "
1087 1113                              "details of the <interface> string.\n"));
1088 1114                          (void) fprintf(fp, gettext("%s %s is valid "
1089 1115                              "if the %s property is set to %s, otherwise it "
1090 1116                              "must not be set.\n"),
1091 1117                              cmd_to_str(CMD_SET), pt_to_str(PT_ADDRESS),
1092 1118                              pt_to_str(PT_IPTYPE), gettext("shared"));
1093      -                        (void) fprintf(fp, gettext("%s %s is valid "
1094      -                            "if the %s property is set to %s, otherwise it "
1095      -                            "must not be set.\n"),
1096      -                            cmd_to_str(CMD_SET), pt_to_str(PT_ALLOWED_ADDRESS),
     1119 +                        (void) fprintf(fp, gettext("%s (%s, %s, %s, %s) are "
     1120 +                            "valid if the %s property is set to %s, otherwise "
     1121 +                            "they must not be set.\n"),
     1122 +                            cmd_to_str(CMD_SET),
     1123 +                            pt_to_str(PT_ALLOWED_ADDRESS), pt_to_str(PT_MAC),
     1124 +                            pt_to_str(PT_VLANID), pt_to_str(PT_GNIC),
1097 1125                              pt_to_str(PT_IPTYPE), gettext("exclusive"));
1098 1126                          (void) fprintf(fp, gettext("\t%s %s=%s\n%s %s "
1099 1127                              "is valid if the %s or %s property is set, "
1100 1128                              "otherwise it must not be set\n"),
1101 1129                              cmd_to_str(CMD_SET),
1102 1130                              pt_to_str(PT_DEFROUTER), gettext("<IP-address>"),
1103 1131                              cmd_to_str(CMD_SET), pt_to_str(PT_DEFROUTER),
1104 1132                              gettext(pt_to_str(PT_ADDRESS)),
1105 1133                              gettext(pt_to_str(PT_ALLOWED_ADDRESS)));
1106 1134                          break;
1107 1135                  case RT_DEVICE:
1108 1136                          (void) fprintf(fp, gettext("The '%s' resource scope is "
1109 1137                              "used to configure a device node.\n"),
1110 1138                              rt_to_str(resource_scope));
1111 1139                          (void) fprintf(fp, gettext("Valid commands:\n"));
     1140 +                        (void) fprintf(fp, "\t%s %s (%s=<value>,%s=<value>)\n",
     1141 +                            cmd_to_str(CMD_ADD), pt_to_str(PT_NPROP),
     1142 +                            pt_to_str(PT_NAME), pt_to_str(PT_VALUE));
1112 1143                          (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET),
1113 1144                              pt_to_str(PT_MATCH), gettext("<device-path>"));
1114 1145                          break;
1115 1146                  case RT_RCTL:
1116 1147                          (void) fprintf(fp, gettext("The '%s' resource scope is "
1117 1148                              "used to configure a resource control.\n"),
1118 1149                              rt_to_str(resource_scope));
1119 1150                          (void) fprintf(fp, gettext("Valid commands:\n"));
1120 1151                          (void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET),
1121 1152                              pt_to_str(PT_NAME), gettext("<string>"));
↓ open down ↓ 207 lines elided ↑ open up ↑
1329 1360                  (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"),
1330 1361                      pt_to_str(PT_MAXMSGIDS));
1331 1362                  (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"),
1332 1363                      pt_to_str(PT_MAXSEMIDS));
1333 1364                  (void) fprintf(fp, "\t%s\t%s\n", gettext("(global)"),
1334 1365                      pt_to_str(PT_SHARES));
1335 1366                  (void) fprintf(fp, "\t%s\t\t%s, %s, %s, %s, %s\n",
1336 1367                      rt_to_str(RT_FS), pt_to_str(PT_DIR),
1337 1368                      pt_to_str(PT_SPECIAL), pt_to_str(PT_RAW),
1338 1369                      pt_to_str(PT_TYPE), pt_to_str(PT_OPTIONS));
1339      -                (void) fprintf(fp, "\t%s\t\t%s, %s, %s|%s\n", rt_to_str(RT_NET),
     1370 +                (void) fprintf(fp, "\t%s\t\t%s, %s, %s, %s, %s, %s, %s %s\n",
     1371 +                    rt_to_str(RT_NET),
1340 1372                      pt_to_str(PT_ADDRESS), pt_to_str(PT_ALLOWED_ADDRESS),
1341      -                    pt_to_str(PT_PHYSICAL), pt_to_str(PT_DEFROUTER));
1342      -                (void) fprintf(fp, "\t%s\t\t%s\n", rt_to_str(RT_DEVICE),
1343      -                    pt_to_str(PT_MATCH));
     1373 +                    pt_to_str(PT_GNIC), pt_to_str(PT_MAC),
     1374 +                    pt_to_str(PT_PHYSICAL), pt_to_str(PT_NPROP),
     1375 +                    pt_to_str(PT_VLANID), pt_to_str(PT_DEFROUTER));
     1376 +                (void) fprintf(fp, "\t%s\t\t%s, %s\n", rt_to_str(RT_DEVICE),
     1377 +                    pt_to_str(PT_MATCH), pt_to_str(PT_NPROP));
1344 1378                  (void) fprintf(fp, "\t%s\t\t%s, %s\n", rt_to_str(RT_RCTL),
1345 1379                      pt_to_str(PT_NAME), pt_to_str(PT_VALUE));
1346 1380                  (void) fprintf(fp, "\t%s\t\t%s, %s, %s\n", rt_to_str(RT_ATTR),
1347 1381                      pt_to_str(PT_NAME), pt_to_str(PT_TYPE),
1348 1382                      pt_to_str(PT_VALUE));
1349 1383                  (void) fprintf(fp, "\t%s\t\t%s\n", rt_to_str(RT_DATASET),
1350 1384                      pt_to_str(PT_NAME));
1351 1385                  (void) fprintf(fp, "\t%s\t%s, %s\n", rt_to_str(RT_DCPU),
1352 1386                      pt_to_str(PT_NCPUS), pt_to_str(PT_IMPORTANCE));
1353 1387                  (void) fprintf(fp, "\t%s\t%s\n", rt_to_str(RT_PCAP),
↓ open down ↓ 337 lines elided ↑ open up ↑
1691 1725                          (void) strlcpy(zone_template, "SUNWblank",
1692 1726                              sizeof (zone_template));
1693 1727                          break;
1694 1728                  case 'F':
1695 1729                          force = B_TRUE;
1696 1730                          break;
1697 1731                  case 't':
1698 1732                          (void) strlcpy(zone_template, optarg,
1699 1733                              sizeof (zone_template));
1700 1734                          break;
     1735 +                case 'X':
     1736 +                        (void) snprintf(zone_template, sizeof (zone_template),
     1737 +                            "%s/%s.xml", ZONE_CONFIG_ROOT, zone);
     1738 +                        err = zonecfg_get_xml_handle(zone_template, handle);
     1739 +                        if (err != Z_OK) {
     1740 +                                zone_perror(execname, err, B_TRUE);
     1741 +                                exit(Z_ERR);
     1742 +                        }
     1743 +                        got_handle = B_TRUE;
     1744 +                        need_to_commit = B_TRUE;
     1745 +                        return;
1701 1746                  default:
1702 1747                          short_usage(CMD_CREATE);
1703 1748                          arg_err = B_TRUE;
1704 1749                          break;
1705 1750                  }
1706 1751          }
1707 1752          if (arg_err)
1708 1753                  return;
1709 1754  
1710 1755          if (optind != cmd->cmd_argc) {
↓ open down ↓ 83 lines elided ↑ open up ↑
1794 1839  export_func(cmd_t *cmd)
1795 1840  {
1796 1841          struct zone_nwiftab nwiftab;
1797 1842          struct zone_fstab fstab;
1798 1843          struct zone_devtab devtab;
1799 1844          struct zone_attrtab attrtab;
1800 1845          struct zone_rctltab rctltab;
1801 1846          struct zone_dstab dstab;
1802 1847          struct zone_psettab psettab;
1803 1848          struct zone_rctlvaltab *valptr;
     1849 +        struct zone_res_attrtab *rap;
1804 1850          struct zone_admintab admintab;
1805 1851          int err, arg;
1806 1852          char zonepath[MAXPATHLEN], outfile[MAXPATHLEN], pool[MAXNAMELEN];
1807 1853          char bootargs[BOOTARGS_MAX];
1808 1854          char sched[MAXNAMELEN];
1809 1855          char brand[MAXNAMELEN];
1810 1856          char hostidp[HW_HOSTID_LEN];
1811 1857          char fsallowedp[ZONE_FS_ALLOWED_MAX];
1812 1858          char *limitpriv;
1813 1859          FILE *of;
↓ open down ↓ 149 lines elided ↑ open up ↑
1963 2009                  zone_perror(zone, err, B_FALSE);
1964 2010                  goto done;
1965 2011          }
1966 2012          while (zonecfg_getnwifent(handle, &nwiftab) == Z_OK) {
1967 2013                  (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD),
1968 2014                      rt_to_str(RT_NET));
1969 2015                  export_prop(of, PT_ADDRESS, nwiftab.zone_nwif_address);
1970 2016                  export_prop(of, PT_ALLOWED_ADDRESS,
1971 2017                      nwiftab.zone_nwif_allowed_address);
1972 2018                  export_prop(of, PT_PHYSICAL, nwiftab.zone_nwif_physical);
     2019 +                export_prop(of, PT_MAC, nwiftab.zone_nwif_mac);
     2020 +                export_prop(of, PT_VLANID, nwiftab.zone_nwif_vlan_id);
     2021 +                export_prop(of, PT_GNIC, nwiftab.zone_nwif_gnic);
1973 2022                  export_prop(of, PT_DEFROUTER, nwiftab.zone_nwif_defrouter);
     2023 +                for (rap = nwiftab.zone_nwif_attrp; rap != NULL;
     2024 +                    rap = rap->zone_res_attr_next) {
     2025 +                        fprintf(of, "%s %s (%s=%s,%s=\"%s\")\n",
     2026 +                            cmd_to_str(CMD_ADD), pt_to_str(PT_NPROP),
     2027 +                            pt_to_str(PT_NAME), rap->zone_res_attr_name,
     2028 +                            pt_to_str(PT_VALUE), rap->zone_res_attr_value);
     2029 +                }
1974 2030                  (void) fprintf(of, "%s\n", cmd_to_str(CMD_END));
1975 2031          }
1976 2032          (void) zonecfg_endnwifent(handle);
1977 2033  
1978 2034          if ((err = zonecfg_setdevent(handle)) != Z_OK) {
1979 2035                  zone_perror(zone, err, B_FALSE);
1980 2036                  goto done;
1981 2037          }
1982 2038          while (zonecfg_getdevent(handle, &devtab) == Z_OK) {
1983 2039                  (void) fprintf(of, "%s %s\n", cmd_to_str(CMD_ADD),
1984 2040                      rt_to_str(RT_DEVICE));
1985 2041                  export_prop(of, PT_MATCH, devtab.zone_dev_match);
     2042 +                for (rap = devtab.zone_dev_attrp; rap != NULL;
     2043 +                    rap = rap->zone_res_attr_next) {
     2044 +                        fprintf(of, "%s %s (%s=%s,%s=\"%s\")\n",
     2045 +                            cmd_to_str(CMD_ADD), pt_to_str(PT_NPROP),
     2046 +                            pt_to_str(PT_NAME), rap->zone_res_attr_name,
     2047 +                            pt_to_str(PT_VALUE), rap->zone_res_attr_value);
     2048 +                }
1986 2049                  (void) fprintf(of, "%s\n", cmd_to_str(CMD_END));
1987 2050          }
1988 2051          (void) zonecfg_enddevent(handle);
1989 2052  
1990 2053          if ((err = zonecfg_setrctlent(handle)) != Z_OK) {
1991 2054                  zone_perror(zone, err, B_FALSE);
1992 2055                  goto done;
1993 2056          }
1994 2057          while (zonecfg_getrctlent(handle, &rctltab) == Z_OK) {
1995 2058                  (void) fprintf(of, "%s rctl\n", cmd_to_str(CMD_ADD));
↓ open down ↓ 346 lines elided ↑ open up ↑
2342 2405          }
2343 2406          err = zonecfg_add_rctl_value(&in_progress_rctltab, rctlvaltab);
2344 2407          if (err != Z_OK)
2345 2408                  zone_perror(pt_to_str(PT_VALUE), err, B_TRUE);
2346 2409          return;
2347 2410  
2348 2411  bad:
2349 2412          zonecfg_free_rctl_value_list(rctlvaltab);
2350 2413  }
2351 2414  
     2415 +/*
     2416 + * Resource attribute ("property" resource embedded on net or dev resource)
     2417 + */
2352 2418  static void
     2419 +do_res_attr(struct zone_res_attrtab **headp, complex_property_ptr_t cpp)
     2420 +{
     2421 +        complex_property_ptr_t cp;
     2422 +        struct zone_res_attrtab *np;
     2423 +        int err;
     2424 +        boolean_t seen_name = B_FALSE, seen_value = B_FALSE;
     2425 +
     2426 +        if ((np = calloc(1, sizeof (struct zone_res_attrtab))) == NULL) {
     2427 +                zone_perror(zone, Z_NOMEM, B_TRUE);
     2428 +                exit(Z_ERR);
     2429 +        }
     2430 +
     2431 +        for (cp = cpp; cp != NULL; cp = cp->cp_next) {
     2432 +                switch (cp->cp_type) {
     2433 +                case PT_NAME:
     2434 +                        if (seen_name) {
     2435 +                                zerr(gettext("%s already specified"),
     2436 +                                    pt_to_str(PT_NAME));
     2437 +                                goto bad;
     2438 +                        }
     2439 +                        (void) strlcpy(np->zone_res_attr_name, cp->cp_value,
     2440 +                            sizeof (np->zone_res_attr_name));
     2441 +                        seen_name = B_TRUE;
     2442 +                        break;
     2443 +                case PT_VALUE:
     2444 +                        if (seen_value) {
     2445 +                                zerr(gettext("%s already specified"),
     2446 +                                    pt_to_str(PT_VALUE));
     2447 +                                goto bad;
     2448 +                        }
     2449 +                        (void) strlcpy(np->zone_res_attr_value, cp->cp_value,
     2450 +                            sizeof (np->zone_res_attr_value));
     2451 +                        seen_value = B_TRUE;
     2452 +                        break;
     2453 +                default:
     2454 +                        zone_perror(pt_to_str(PT_NPROP), Z_NO_PROPERTY_TYPE,
     2455 +                            B_TRUE);
     2456 +                        long_usage(CMD_ADD, B_TRUE);
     2457 +                        usage(B_FALSE, HELP_PROPS);
     2458 +                        zonecfg_free_res_attr_list(np);
     2459 +                        return;
     2460 +                }
     2461 +        }
     2462 +
     2463 +        if (!seen_name)
     2464 +                zerr(gettext("%s not specified"), pt_to_str(PT_NAME));
     2465 +        if (!seen_value)
     2466 +                zerr(gettext("%s not specified"), pt_to_str(PT_VALUE));
     2467 +
     2468 +        err = zonecfg_add_res_attr(headp, np);
     2469 +        if (err != Z_OK)
     2470 +                zone_perror(pt_to_str(PT_NPROP), err, B_TRUE);
     2471 +        return;
     2472 +
     2473 +bad:
     2474 +        zonecfg_free_res_attr_list(np);
     2475 +}
     2476 +
     2477 +static void
2353 2478  add_property(cmd_t *cmd)
2354 2479  {
2355 2480          char *prop_id;
2356 2481          int err, res_type, prop_type;
2357 2482          property_value_ptr_t pp;
2358 2483          list_property_ptr_t l;
2359 2484  
2360 2485          res_type = resource_scope;
2361 2486          prop_type = cmd->cmd_prop_name[0];
2362 2487          if (res_type == RT_UNKNOWN || prop_type == PT_UNKNOWN) {
↓ open down ↓ 46 lines elided ↑ open up ↑
2409 2534                                  if (prop_id == NULL)
2410 2535                                          break;
2411 2536                                  err = zonecfg_add_fs_option(
2412 2537                                      &in_progress_fstab, prop_id);
2413 2538                                  if (err != Z_OK)
2414 2539                                          zone_perror(pt_to_str(prop_type), err,
2415 2540                                              B_TRUE);
2416 2541                          }
2417 2542                  }
2418 2543                  return;
     2544 +        case RT_NET:
     2545 +                if (prop_type != PT_NPROP) {
     2546 +                        zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE,
     2547 +                            B_TRUE);
     2548 +                        long_usage(CMD_ADD, B_TRUE);
     2549 +                        usage(B_FALSE, HELP_PROPS);
     2550 +                        return;
     2551 +                }
     2552 +                pp = cmd->cmd_property_ptr[0];
     2553 +                if (pp->pv_type != PROP_VAL_COMPLEX) {
     2554 +                        zerr(gettext("A %s value was expected here."),
     2555 +                            pvt_to_str(PROP_VAL_COMPLEX));
     2556 +                        saw_error = B_TRUE;
     2557 +                        return;
     2558 +                }
     2559 +
     2560 +                do_res_attr(&(in_progress_nwiftab.zone_nwif_attrp),
     2561 +                    pp->pv_complex);
     2562 +                return;
     2563 +        case RT_DEVICE:
     2564 +                if (prop_type != PT_NPROP) {
     2565 +                        zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE,
     2566 +                            B_TRUE);
     2567 +                        long_usage(CMD_ADD, B_TRUE);
     2568 +                        usage(B_FALSE, HELP_PROPS);
     2569 +                        return;
     2570 +                }
     2571 +                pp = cmd->cmd_property_ptr[0];
     2572 +                if (pp->pv_type != PROP_VAL_COMPLEX) {
     2573 +                        zerr(gettext("A %s value was expected here."),
     2574 +                            pvt_to_str(PROP_VAL_COMPLEX));
     2575 +                        saw_error = B_TRUE;
     2576 +                        return;
     2577 +                }
     2578 +
     2579 +                do_res_attr(&(in_progress_devtab.zone_dev_attrp),
     2580 +                    pp->pv_complex);
     2581 +                return;
2419 2582          case RT_RCTL:
2420 2583                  if (prop_type != PT_VALUE) {
2421 2584                          zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE,
2422 2585                              B_TRUE);
2423 2586                          long_usage(CMD_ADD, B_TRUE);
2424 2587                          usage(B_FALSE, HELP_PROPS);
2425 2588                          return;
2426 2589                  }
2427 2590                  pp = cmd->cmd_property_ptr[0];
2428 2591                  if (pp->pv_type != PROP_VAL_COMPLEX &&
↓ open down ↓ 84 lines elided ↑ open up ↑
2513 2676                          zerr(gettext("Cannot add a %s resource to the "
2514 2677                              "global zone."), rt_to_str(cmd->cmd_res_type));
2515 2678                          saw_error = B_TRUE;
2516 2679                          return;
2517 2680                  }
2518 2681  
2519 2682                  global_scope = B_FALSE;
2520 2683                  resource_scope = cmd->cmd_res_type;
2521 2684                  end_op = CMD_ADD;
2522 2685                  add_resource(cmd);
2523      -        } else
     2686 +        } else {
2524 2687                  add_property(cmd);
     2688 +        }
2525 2689  }
2526 2690  
2527 2691  /*
2528 2692   * This routine has an unusual implementation, because it tries very
2529 2693   * hard to succeed in the face of a variety of failure modes.
2530 2694   * The most common and most vexing occurs when the index file and
2531 2695   * the /etc/zones/<zonename.xml> file are not both present.  In
2532 2696   * this case, delete must eradicate as much of the zone state as is left
2533 2697   * so that the user can later create a new zone with the same name.
2534 2698   */
↓ open down ↓ 177 lines elided ↑ open up ↑
2712 2876                  case PT_ALLOWED_ADDRESS:
2713 2877                          (void) strlcpy(nwiftab->zone_nwif_allowed_address,
2714 2878                              pp->pv_simple,
2715 2879                              sizeof (nwiftab->zone_nwif_allowed_address));
2716 2880                          break;
2717 2881                  case PT_PHYSICAL:
2718 2882                          (void) strlcpy(nwiftab->zone_nwif_physical,
2719 2883                              pp->pv_simple,
2720 2884                              sizeof (nwiftab->zone_nwif_physical));
2721 2885                          break;
     2886 +                case PT_MAC:
     2887 +                        (void) strlcpy(nwiftab->zone_nwif_mac,
     2888 +                            pp->pv_simple,
     2889 +                            sizeof (nwiftab->zone_nwif_mac));
     2890 +                        break;
     2891 +                case PT_VLANID:
     2892 +                        (void) strlcpy(nwiftab->zone_nwif_vlan_id,
     2893 +                            pp->pv_simple,
     2894 +                            sizeof (nwiftab->zone_nwif_vlan_id));
     2895 +                        break;
     2896 +                case PT_GNIC:
     2897 +                        (void) strlcpy(nwiftab->zone_nwif_gnic,
     2898 +                            pp->pv_simple,
     2899 +                            sizeof (nwiftab->zone_nwif_gnic));
     2900 +                        break;
2722 2901                  case PT_DEFROUTER:
2723 2902                          (void) strlcpy(nwiftab->zone_nwif_defrouter,
2724 2903                              pp->pv_simple,
2725 2904                              sizeof (nwiftab->zone_nwif_defrouter));
2726 2905                          break;
2727 2906                  default:
2728 2907                          zone_perror(pt_to_str(cmd->cmd_prop_name[i]),
2729 2908                              Z_NO_PROPERTY_TYPE, B_TRUE);
2730 2909                          return (Z_INSUFFICIENT_SPEC);
2731 2910                  }
↓ open down ↓ 662 lines elided ↑ open up ↑
3394 3573          }
3395 3574  }
3396 3575  
3397 3576  static void
3398 3577  remove_property(cmd_t *cmd)
3399 3578  {
3400 3579          char *prop_id;
3401 3580          int err, res_type, prop_type;
3402 3581          property_value_ptr_t pp;
3403 3582          struct zone_rctlvaltab *rctlvaltab;
     3583 +        struct zone_res_attrtab *np;
3404 3584          complex_property_ptr_t cx;
3405 3585  
3406 3586          res_type = resource_scope;
3407 3587          prop_type = cmd->cmd_prop_name[0];
3408 3588          if (res_type == RT_UNKNOWN || prop_type == PT_UNKNOWN) {
3409 3589                  long_usage(CMD_REMOVE, B_TRUE);
3410 3590                  return;
3411 3591          }
3412 3592  
3413 3593          if (cmd->cmd_prop_nv_pairs != 1) {
↓ open down ↓ 40 lines elided ↑ open up ↑
3454 3634                                  if (prop_id == NULL)
3455 3635                                          break;
3456 3636                                  err = zonecfg_remove_fs_option(
3457 3637                                      &in_progress_fstab, prop_id);
3458 3638                                  if (err != Z_OK)
3459 3639                                          zone_perror(pt_to_str(prop_type), err,
3460 3640                                              B_TRUE);
3461 3641                          }
3462 3642                  }
3463 3643                  return;
     3644 +        case RT_NET:            /* FALLTHRU */
     3645 +        case RT_DEVICE:
     3646 +                if (prop_type != PT_NPROP) {
     3647 +                        zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE,
     3648 +                            B_TRUE);
     3649 +                        long_usage(CMD_REMOVE, B_TRUE);
     3650 +                        usage(B_FALSE, HELP_PROPS);
     3651 +                        return;
     3652 +                }
     3653 +                pp = cmd->cmd_property_ptr[0];
     3654 +                if (pp->pv_type != PROP_VAL_COMPLEX) {
     3655 +                        zerr(gettext("A %s value was expected here."),
     3656 +                            pvt_to_str(PROP_VAL_COMPLEX));
     3657 +                        saw_error = B_TRUE;
     3658 +                        return;
     3659 +                }
     3660 +
     3661 +                np = alloca(sizeof (struct zone_res_attrtab));
     3662 +                for (cx = pp->pv_complex; cx != NULL; cx = cx->cp_next) {
     3663 +                        switch (cx->cp_type) {
     3664 +                        case PT_NAME:
     3665 +                                (void) strlcpy(np->zone_res_attr_name,
     3666 +                                    cx->cp_value,
     3667 +                                    sizeof (np->zone_res_attr_name));
     3668 +                                break;
     3669 +                        case PT_VALUE:
     3670 +                                (void) strlcpy(np->zone_res_attr_value,
     3671 +                                    cx->cp_value,
     3672 +                                    sizeof (np->zone_res_attr_value));
     3673 +                                break;
     3674 +                        default:
     3675 +                                zone_perror(pt_to_str(prop_type),
     3676 +                                    Z_NO_PROPERTY_TYPE, B_TRUE);
     3677 +                                long_usage(CMD_REMOVE, B_TRUE);
     3678 +                                usage(B_FALSE, HELP_PROPS);
     3679 +                                return;
     3680 +                        }
     3681 +                }
     3682 +                np->zone_res_attr_next = NULL;
     3683 +
     3684 +                if (res_type == RT_NET) {
     3685 +                        err = zonecfg_remove_res_attr(
     3686 +                            &(in_progress_nwiftab.zone_nwif_attrp), np);
     3687 +                } else {                                /* RT_DEVICE */
     3688 +                        err = zonecfg_remove_res_attr(
     3689 +                            &(in_progress_devtab.zone_dev_attrp), np);
     3690 +                }
     3691 +                if (err != Z_OK)
     3692 +                        zone_perror(pt_to_str(prop_type), err, B_TRUE);
     3693 +                return;
3464 3694          case RT_RCTL:
3465 3695                  if (prop_type != PT_VALUE) {
3466 3696                          zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE,
3467 3697                              B_TRUE);
3468 3698                          long_usage(CMD_REMOVE, B_TRUE);
3469 3699                          usage(B_FALSE, HELP_PROPS);
3470 3700                          return;
3471 3701                  }
3472 3702                  pp = cmd->cmd_property_ptr[0];
3473 3703                  if (pp->pv_type != PROP_VAL_COMPLEX) {
↓ open down ↓ 32 lines elided ↑ open up ↑
3506 3736                                  return;
3507 3737                          }
3508 3738                  }
3509 3739                  rctlvaltab->zone_rctlval_next = NULL;
3510 3740                  err = zonecfg_remove_rctl_value(&in_progress_rctltab,
3511 3741                      rctlvaltab);
3512 3742                  if (err != Z_OK)
3513 3743                          zone_perror(pt_to_str(prop_type), err, B_TRUE);
3514 3744                  zonecfg_free_rctl_value_list(rctlvaltab);
3515 3745                  return;
3516      -        case RT_NET:
3517      -                if (prop_type != PT_DEFROUTER) {
3518      -                        zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE,
3519      -                            B_TRUE);
3520      -                        long_usage(CMD_REMOVE, B_TRUE);
3521      -                        usage(B_FALSE, HELP_PROPS);
3522      -                        return;
3523      -                } else {
3524      -                        bzero(&in_progress_nwiftab.zone_nwif_defrouter,
3525      -                            sizeof (in_progress_nwiftab.zone_nwif_defrouter));
3526      -                        return;
3527      -                }
3528 3746          default:
3529 3747                  zone_perror(rt_to_str(res_type), Z_NO_RESOURCE_TYPE, B_TRUE);
3530 3748                  long_usage(CMD_REMOVE, B_TRUE);
3531 3749                  usage(B_FALSE, HELP_RESOURCES);
3532 3750                  return;
3533 3751          }
3534 3752  }
3535 3753  
3536 3754  void
3537 3755  remove_func(cmd_t *cmd)
↓ open down ↓ 52 lines elided ↑ open up ↑
3590 3808                          remove_aliased_rctl(PT_PHYSICAL, ALIAS_MAXPHYSMEM);
3591 3809                          return;
3592 3810                  case PT_SWAP:
3593 3811                          remove_aliased_rctl(PT_SWAP, ALIAS_MAXSWAP);
3594 3812                          return;
3595 3813                  case PT_LOCKED:
3596 3814                          remove_aliased_rctl(PT_LOCKED, ALIAS_MAXLOCKEDMEM);
3597 3815                          return;
3598 3816                  }
3599 3817                  break;
     3818 +        case RT_NET:
     3819 +                switch (prop_type) {
     3820 +                case PT_ALLOWED_ADDRESS:
     3821 +                        in_progress_nwiftab.zone_nwif_allowed_address[0] = '\0';
     3822 +                        need_to_commit = B_TRUE;
     3823 +                        return;
     3824 +                case PT_DEFROUTER:
     3825 +                        in_progress_nwiftab.zone_nwif_defrouter[0] = '\0';
     3826 +                        need_to_commit = B_TRUE;
     3827 +                        return;
     3828 +                case PT_GNIC:
     3829 +                        in_progress_nwiftab.zone_nwif_gnic[0] = '\0';
     3830 +                        need_to_commit = B_TRUE;
     3831 +                        return;
     3832 +                case PT_MAC:
     3833 +                        in_progress_nwiftab.zone_nwif_mac[0] = '\0';
     3834 +                        need_to_commit = B_TRUE;
     3835 +                        return;
     3836 +                case PT_VLANID:
     3837 +                        in_progress_nwiftab.zone_nwif_vlan_id[0] = '\0';
     3838 +                        need_to_commit = B_TRUE;
     3839 +                        return;
     3840 +                }
     3841 +                break;
3600 3842          default:
3601 3843                  break;
3602 3844          }
3603 3845  
3604 3846          zone_perror(pt_to_str(prop_type), Z_CLEAR_DISALLOW, B_TRUE);
3605 3847  }
3606 3848  
3607 3849  static void
3608 3850  clear_global(cmd_t *cmd)
3609 3851  {
↓ open down ↓ 586 lines elided ↑ open up ↑
4196 4438                          saw_error = B_TRUE;
4197 4439                          return;
4198 4440                  }
4199 4441          }
4200 4442  
4201 4443          pp = cmd->cmd_property_ptr[0];
4202 4444          /*
4203 4445           * A nasty expression but not that complicated:
4204 4446           * 1. fs options are simple or list (tested below)
4205 4447           * 2. rctl value's are complex or list (tested below)
     4448 +         * 3. net attr's are complex (tested below)
4206 4449           * Anything else should be simple.
4207 4450           */
4208 4451          if (!(res_type == RT_FS && prop_type == PT_OPTIONS) &&
4209 4452              !(res_type == RT_RCTL && prop_type == PT_VALUE) &&
     4453 +            !(res_type == RT_NET && prop_type == PT_NPROP) &&
4210 4454              (pp->pv_type != PROP_VAL_SIMPLE ||
4211 4455              (prop_id = pp->pv_simple) == NULL)) {
4212 4456                  zerr(gettext("A %s value was expected here."),
4213 4457                      pvt_to_str(PROP_VAL_SIMPLE));
4214 4458                  saw_error = B_TRUE;
4215 4459                  return;
4216 4460          }
4217 4461          if (prop_type == PT_UNKNOWN) {
4218 4462                  long_usage(CMD_SET, B_TRUE);
4219 4463                  return;
↓ open down ↓ 239 lines elided ↑ open up ↑
4459 4703                          break;
4460 4704                  case PT_PHYSICAL:
4461 4705                          if (validate_net_physical_syntax(prop_id) != Z_OK) {
4462 4706                                  saw_error = B_TRUE;
4463 4707                                  return;
4464 4708                          }
4465 4709                          (void) strlcpy(in_progress_nwiftab.zone_nwif_physical,
4466 4710                              prop_id,
4467 4711                              sizeof (in_progress_nwiftab.zone_nwif_physical));
4468 4712                          break;
     4713 +                case PT_MAC:
     4714 +                        (void) strlcpy(in_progress_nwiftab.zone_nwif_mac,
     4715 +                            prop_id,
     4716 +                            sizeof (in_progress_nwiftab.zone_nwif_mac));
     4717 +                        break;
     4718 +                case PT_VLANID:
     4719 +                        (void) strlcpy(in_progress_nwiftab.zone_nwif_vlan_id,
     4720 +                            prop_id,
     4721 +                            sizeof (in_progress_nwiftab.zone_nwif_vlan_id));
     4722 +                        break;
     4723 +                case PT_GNIC:
     4724 +                        (void) strlcpy(in_progress_nwiftab.zone_nwif_gnic,
     4725 +                            prop_id,
     4726 +                            sizeof (in_progress_nwiftab.zone_nwif_gnic));
     4727 +                        break;
4469 4728                  case PT_DEFROUTER:
4470 4729                          if (validate_net_address_syntax(prop_id, B_TRUE)
4471 4730                              != Z_OK) {
4472 4731                                  saw_error = B_TRUE;
4473 4732                                  return;
4474 4733                          }
4475 4734                          (void) strlcpy(in_progress_nwiftab.zone_nwif_defrouter,
4476 4735                              prop_id,
4477 4736                              sizeof (in_progress_nwiftab.zone_nwif_defrouter));
4478 4737                          break;
     4738 +                case PT_NPROP:
     4739 +                        if (pp->pv_type != PROP_VAL_COMPLEX) {
     4740 +                                zerr(gettext("A %s value was expected here."),
     4741 +                                    pvt_to_str(PROP_VAL_COMPLEX));
     4742 +                                saw_error = B_TRUE;
     4743 +                                return;
     4744 +                        }
     4745 +                        zonecfg_free_res_attr_list(
     4746 +                            in_progress_nwiftab.zone_nwif_attrp);
     4747 +                        in_progress_nwiftab.zone_nwif_attrp = NULL;
     4748 +                        if (!(pp->pv_type == PROP_VAL_LIST &&
     4749 +                            pp->pv_list == NULL))
     4750 +                                add_property(cmd);
     4751 +                        break;
4479 4752                  default:
4480 4753                          zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE,
4481 4754                              B_TRUE);
4482 4755                          long_usage(CMD_SET, B_TRUE);
4483 4756                          usage(B_FALSE, HELP_PROPS);
4484 4757                          return;
4485 4758                  }
4486 4759                  return;
4487 4760          case RT_DEVICE:
4488 4761                  switch (prop_type) {
4489 4762                  case PT_MATCH:
4490 4763                          (void) strlcpy(in_progress_devtab.zone_dev_match,
4491 4764                              prop_id,
4492 4765                              sizeof (in_progress_devtab.zone_dev_match));
4493 4766                          break;
     4767 +                case PT_NPROP:
     4768 +                        if (pp->pv_type != PROP_VAL_COMPLEX) {
     4769 +                                zerr(gettext("A %s value was expected here."),
     4770 +                                    pvt_to_str(PROP_VAL_COMPLEX));
     4771 +                                saw_error = B_TRUE;
     4772 +                                return;
     4773 +                        }
     4774 +                        zonecfg_free_res_attr_list(
     4775 +                            in_progress_devtab.zone_dev_attrp);
     4776 +                        in_progress_devtab.zone_dev_attrp = NULL;
     4777 +                        if (!(pp->pv_type == PROP_VAL_LIST &&
     4778 +                            pp->pv_list == NULL))
     4779 +                                add_property(cmd);
     4780 +                        break;
4494 4781                  default:
4495 4782                          zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE,
4496 4783                              B_TRUE);
4497 4784                          long_usage(CMD_SET, B_TRUE);
4498 4785                          usage(B_FALSE, HELP_PROPS);
4499 4786                          return;
4500 4787                  }
4501 4788                  return;
4502 4789          case RT_RCTL:
4503 4790                  switch (prop_type) {
↓ open down ↓ 519 lines elided ↑ open up ↑
5023 5310           * nothing to output.
5024 5311           */
5025 5312          if (!output && cmd->cmd_prop_nv_pairs > 0)
5026 5313                  (void) printf(gettext("No such %s resource.\n"),
5027 5314                      rt_to_str(RT_FS));
5028 5315  }
5029 5316  
5030 5317  static void
5031 5318  output_net(FILE *fp, struct zone_nwiftab *nwiftab)
5032 5319  {
     5320 +        struct zone_res_attrtab *np;
     5321 +
5033 5322          (void) fprintf(fp, "%s:\n", rt_to_str(RT_NET));
5034 5323          output_prop(fp, PT_ADDRESS, nwiftab->zone_nwif_address, B_TRUE);
5035 5324          output_prop(fp, PT_ALLOWED_ADDRESS,
5036 5325              nwiftab->zone_nwif_allowed_address, B_TRUE);
5037      -        output_prop(fp, PT_PHYSICAL, nwiftab->zone_nwif_physical, B_TRUE);
5038 5326          output_prop(fp, PT_DEFROUTER, nwiftab->zone_nwif_defrouter, B_TRUE);
     5327 +        output_prop(fp, PT_GNIC, nwiftab->zone_nwif_gnic, B_TRUE);
     5328 +        output_prop(fp, PT_MAC, nwiftab->zone_nwif_mac, B_TRUE);
     5329 +        output_prop(fp, PT_PHYSICAL, nwiftab->zone_nwif_physical, B_TRUE);
     5330 +        output_prop(fp, PT_VLANID, nwiftab->zone_nwif_vlan_id, B_TRUE);
     5331 +
     5332 +        for (np = nwiftab->zone_nwif_attrp; np != NULL;
     5333 +            np = np->zone_res_attr_next) {
     5334 +                fprintf(fp, "\t%s: (%s=%s,%s=\"%s\")\n",
     5335 +                    pt_to_str(PT_NPROP),
     5336 +                    pt_to_str(PT_NAME), np->zone_res_attr_name,
     5337 +                    pt_to_str(PT_VALUE), np->zone_res_attr_value);
     5338 +        }
5039 5339  }
5040 5340  
5041 5341  static void
5042 5342  info_net(zone_dochandle_t handle, FILE *fp, cmd_t *cmd)
5043 5343  {
5044 5344          struct zone_nwiftab lookup, user;
5045 5345          boolean_t output = B_FALSE;
5046 5346  
5047 5347          if (zonecfg_setnwifent(handle) != Z_OK)
5048 5348                  return;
↓ open down ↓ 22 lines elided ↑ open up ↑
5071 5371           * nothing to output.
5072 5372           */
5073 5373          if (!output && cmd->cmd_prop_nv_pairs > 0)
5074 5374                  (void) printf(gettext("No such %s resource.\n"),
5075 5375                      rt_to_str(RT_NET));
5076 5376  }
5077 5377  
5078 5378  static void
5079 5379  output_dev(FILE *fp, struct zone_devtab *devtab)
5080 5380  {
     5381 +        struct zone_res_attrtab *np;
     5382 +
5081 5383          (void) fprintf(fp, "%s:\n", rt_to_str(RT_DEVICE));
5082 5384          output_prop(fp, PT_MATCH, devtab->zone_dev_match, B_TRUE);
     5385 +
     5386 +        for (np = devtab->zone_dev_attrp; np != NULL;
     5387 +            np = np->zone_res_attr_next) {
     5388 +                fprintf(fp, "\t%s: (%s=%s,%s=\"%s\")\n",
     5389 +                    pt_to_str(PT_NPROP),
     5390 +                    pt_to_str(PT_NAME), np->zone_res_attr_name,
     5391 +                    pt_to_str(PT_VALUE), np->zone_res_attr_value);
     5392 +        }
5083 5393  }
5084 5394  
5085 5395  static void
5086 5396  info_dev(zone_dochandle_t handle, FILE *fp, cmd_t *cmd)
5087 5397  {
5088 5398          struct zone_devtab lookup, user;
5089 5399          boolean_t output = B_FALSE;
5090 5400  
5091 5401          if (zonecfg_setdevent(handle) != Z_OK)
5092 5402                  return;
↓ open down ↓ 1006 lines elided ↑ open up ↑
6099 6409  
6100 6410          if (!global_scope) {
6101 6411                  zerr(gettext("resource specification incomplete"));
6102 6412                  saw_error = B_TRUE;
6103 6413                  if (ret_val == Z_OK)
6104 6414                          ret_val = Z_INSUFFICIENT_SPEC;
6105 6415          }
6106 6416  
6107 6417          if (save) {
6108 6418                  if (ret_val == Z_OK) {
     6419 +                        /*
     6420 +                         * If the zone doesn't yet have a debug ID, set one now.
     6421 +                         */
     6422 +                        if (zonecfg_get_did(handle) == -1)
     6423 +                                zonecfg_set_did(handle);
     6424 +
6109 6425                          if ((ret_val = zonecfg_save(handle)) == Z_OK) {
6110 6426                                  need_to_commit = B_FALSE;
6111 6427                                  (void) strlcpy(revert_zone, zone,
6112 6428                                      sizeof (revert_zone));
6113 6429                          }
6114 6430                  } else {
6115 6431                          zerr(gettext("Zone %s failed to verify"), zone);
6116 6432                  }
6117 6433          }
6118 6434          if (ret_val != Z_OK)
↓ open down ↓ 1166 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX