Print this page
4585 dladm(1m) needs a 'help' subcommand
3755 dladm show-aggr documentation
3374 usage of 'dladm' does not match to its man page

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/dladm/dladm.c
          +++ new/usr/src/cmd/dladm/dladm.c
↓ open down ↓ 75 lines elided ↑ open up ↑
  76   76  #include <ofmt.h>
  77   77  
  78   78  #define MAXPORT                 256
  79   79  #define MAXVNIC                 256
  80   80  #define BUFLEN(lim, ptr)        (((lim) > (ptr)) ? ((lim) - (ptr)) : 0)
  81   81  #define MAXLINELEN              1024
  82   82  #define SMF_UPGRADE_FILE                "/var/svc/profile/upgrade"
  83   83  #define SMF_UPGRADEDATALINK_FILE        "/var/svc/profile/upgrade_datalink"
  84   84  #define SMF_DLADM_UPGRADE_MSG           " # added by dladm(1M)"
  85   85  #define DLADM_DEFAULT_COL       80
       86 +#define DLADM_DEFAULT_CMD       "show-link"
  86   87  
  87   88  /*
  88   89   * used by the wifi show-* commands to set up ofmt_field_t structures.
  89   90   */
  90   91  #define WIFI_CMD_SCAN           0x00000001
  91   92  #define WIFI_CMD_SHOW           0x00000002
  92   93  #define WIFI_CMD_ALL            (WIFI_CMD_SCAN | WIFI_CMD_SHOW)
  93   94  
  94   95  /* No larger than pktsum_t */
  95   96  typedef struct brsum_s {
↓ open down ↓ 116 lines elided ↑ open up ↑
 212  213  static cmdfunc_t do_create_part, do_delete_part, do_show_part, do_show_ib;
 213  214  static cmdfunc_t do_up_part;
 214  215  static cmdfunc_t do_create_etherstub, do_delete_etherstub, do_show_etherstub;
 215  216  static cmdfunc_t do_create_simnet, do_modify_simnet;
 216  217  static cmdfunc_t do_delete_simnet, do_show_simnet, do_up_simnet;
 217  218  static cmdfunc_t do_show_usage;
 218  219  static cmdfunc_t do_create_bridge, do_modify_bridge, do_delete_bridge;
 219  220  static cmdfunc_t do_add_bridge, do_remove_bridge, do_show_bridge;
 220  221  static cmdfunc_t do_create_iptun, do_modify_iptun, do_delete_iptun;
 221  222  static cmdfunc_t do_show_iptun, do_up_iptun, do_down_iptun;
      223 +static cmdfunc_t do_help;
 222  224  
 223  225  static void     do_up_vnic_common(int, char **, const char *, boolean_t);
 224  226  
 225  227  static int show_part(dladm_handle_t, datalink_id_t, void *);
 226  228  
 227  229  static void     altroot_cmd(char *, int, char **);
 228  230  static int      show_linkprop_onelink(dladm_handle_t, datalink_id_t, void *);
 229  231  
 230  232  static void     link_stats(datalink_id_t, uint_t, char *, show_state_t *);
 231  233  static void     aggr_stats(datalink_id_t, show_grp_state_t *, uint_t);
↓ open down ↓ 28 lines elided ↑ open up ↑
 260  262  typedef struct  cmd {
 261  263          char            *c_name;
 262  264          cmdfunc_t       *c_fn;
 263  265          const char      *c_usage;
 264  266  } cmd_t;
 265  267  
 266  268  static cmd_t    cmds[] = {
 267  269          { "rename-link",        do_rename_link,
 268  270              "    rename-link      <oldlink> <newlink>"                  },
 269  271          { "show-link",          do_show_link,
 270      -            "    show-link        [-pP] [-o <field>,..] [-s [-i <interval>]] "
 271      -            "[<link>]\n"                                                },
      272 +            "    show-link        [-P] [[-p] -o <field>,..] "
      273 +            "[-s [-i <interval>]] [<link>]"                             },
 272  274          { "create-aggr",        do_create_aggr,
 273  275              "    create-aggr      [-t] [-P <policy>] [-L <mode>] [-T <time>] "
 274  276              "[-u <address>]\n"
 275  277              "\t\t     -l <link> [-l <link>...] <link>"                  },
 276  278          { "delete-aggr",        do_delete_aggr,
 277  279              "    delete-aggr      [-t] <link>"                          },
 278  280          { "add-aggr",           do_add_aggr,
 279  281              "    add-aggr         [-t] -l <link> [-l <link>...] <link>" },
 280  282          { "remove-aggr",        do_remove_aggr,
 281  283              "    remove-aggr      [-t] -l <link> [-l <link>...] <link>" },
 282  284          { "modify-aggr",        do_modify_aggr,
 283  285              "    modify-aggr      [-t] [-P <policy>] [-L <mode>] [-T <time>] "
 284  286              "[-u <address>]\n"
 285  287              "\t\t     <link>"                                           },
 286  288          { "show-aggr",          do_show_aggr,
 287      -            "    show-aggr        [-pPLx] [-o <field>,..] [-s [-i <interval>]] "
 288      -            "[<link>]\n"                                                },
      289 +            "    show-aggr        [-PLx] [[-p] -o <field>,..] "
      290 +            "[-s [-i <interval>]] [<link>]"                             },
 289  291          { "up-aggr",            do_up_aggr,     NULL                    },
 290  292          { "scan-wifi",          do_scan_wifi,
 291      -            "    scan-wifi        [-p] [-o <field>,...] [<link>]"       },
      293 +            "    scan-wifi        [[-p] -o <field>,...] [<link>]"       },
 292  294          { "connect-wifi",       do_connect_wifi,
 293  295              "    connect-wifi     [-e <essid>] [-i <bssid>] [-k <key>,...] "
 294  296              "[-s wep|wpa]\n"
 295  297              "\t\t     [-a open|shared] [-b bss|ibss] [-c] [-m a|b|g] "
 296  298              "[-T <time>]\n"
 297  299              "\t\t     [<link>]"                                         },
 298  300          { "disconnect-wifi",    do_disconnect_wifi,
 299  301              "    disconnect-wifi  [-a] [<link>]"                        },
 300  302          { "show-wifi",          do_show_wifi,
 301      -            "    show-wifi        [-p] [-o <field>,...] [<link>]\n"     },
      303 +            "    show-wifi        [[-p] -o <field>,...] [<link>]"       },
 302  304          { "set-linkprop",       do_set_linkprop,
 303  305              "    set-linkprop     [-t] -p <prop>=<value>[,...] <name>"  },
 304  306          { "reset-linkprop",     do_reset_linkprop,
 305  307              "    reset-linkprop   [-t] [-p <prop>,...] <name>"          },
 306  308          { "show-linkprop",      do_show_linkprop,
 307  309              "    show-linkprop    [-cP] [-o <field>,...] [-p <prop>,...] "
 308      -            "<name>\n"                                                  },
      310 +            "<name>"                                                    },
 309  311          { "show-ether",         do_show_ether,
 310      -            "    show-ether       [-px][-o <field>,...] <link>\n"       },
      312 +            "    show-ether       [-x] [[-p] -o <field>,...] <link>"    },
 311  313          { "create-secobj",      do_create_secobj,
 312  314              "    create-secobj    [-t] [-f <file>] -c <class> <secobj>" },
 313  315          { "delete-secobj",      do_delete_secobj,
 314  316              "    delete-secobj    [-t] <secobj>[,...]"                  },
 315  317          { "show-secobj",        do_show_secobj,
 316      -            "    show-secobj      [-pP] [-o <field>,...] [<secobj>,...]\n" },
      318 +            "    show-secobj      [-P] [[-p] -o <field>,...] [<secobj>,...]" },
 317  319          { "init-linkprop",      do_init_linkprop,       NULL            },
 318  320          { "init-secobj",        do_init_secobj,         NULL            },
 319  321          { "create-vlan",        do_create_vlan,
 320  322              "    create-vlan      [-ft] -l <link> -v <vid> [link]"      },
 321  323          { "delete-vlan",        do_delete_vlan,
 322  324              "    delete-vlan      [-t] <link>"                          },
 323  325          { "show-vlan",          do_show_vlan,
 324      -            "    show-vlan        [-pP] [-o <field>,..] [<link>]\n"     },
      326 +            "    show-vlan        [-P] [[-p] -o <field>,...] [<link>]"  },
 325  327          { "up-vlan",            do_up_vlan,             NULL            },
 326  328          { "create-iptun",       do_create_iptun,
 327  329              "    create-iptun     [-t] -T <type> "
 328  330              "[-a {local|remote}=<addr>,...] <link>]" },
 329  331          { "delete-iptun",       do_delete_iptun,
 330  332              "    delete-iptun     [-t] <link>"                          },
 331  333          { "modify-iptun",       do_modify_iptun,
 332  334              "    modify-iptun     [-t] -a {local|remote}=<addr>,... <link>" },
 333  335          { "show-iptun",         do_show_iptun,
 334      -            "    show-iptun       [-pP] [-o <field>,..] [<link>]\n"     },
      336 +            "    show-iptun       [-P] [[-p] -o <field>,...] [<link>]"  },
 335  337          { "up-iptun",           do_up_iptun,            NULL            },
 336  338          { "down-iptun",         do_down_iptun,          NULL            },
 337  339          { "delete-phys",        do_delete_phys,
 338  340              "    delete-phys      <link>"                               },
 339  341          { "show-phys",          do_show_phys,
 340      -            "    show-phys        [-pP] [-o <field>,..] [-H] [<link>]\n"},
      342 +            "    show-phys        [-P] [[-p] -o <field>,...] [-H] [<link>]" },
 341  343          { "init-phys",          do_init_phys,           NULL            },
 342  344          { "show-linkmap",       do_show_linkmap,        NULL            },
 343  345          { "create-vnic",        do_create_vnic,
 344  346              "    create-vnic      [-t] -l <link> [-m <value> | auto |\n"
 345  347              "\t\t     {factory [-n <slot-id>]} | {random [-r <prefix>]} |\n"
 346  348              "\t\t     {vrrp -V <vrid> -A {inet | inet6}} [-v <vid> [-f]]\n"
 347      -            "\t\t     [-p <prop>=<value>[,...]] <vnic-link>"    },
      349 +            "\t\t     [-p <prop>=<value>[,...]] [-R root-dir] <vnic-link>" },
 348  350          { "delete-vnic",        do_delete_vnic,
 349  351              "    delete-vnic      [-t] <vnic-link>"                     },
 350  352          { "show-vnic",          do_show_vnic,
 351      -            "    show-vnic        [-pP] [-l <link>] [-s [-i <interval>]] "
 352      -            "[<link>]\n"                                                },
      353 +            "    show-vnic        [-P] [[-p] -o <field>,...] [-l <link>] "
      354 +            "[-s [-i <interval>]] [<link>]"                             },
 353  355          { "up-vnic",            do_up_vnic,             NULL            },
 354  356          { "create-part",        do_create_part,
 355  357              "    create-part      [-t] [-f] -l <link> [-P <pkey>]\n"
 356  358              "\t\t     [-R <root-dir>] <part-link>"                      },
 357  359          { "delete-part",        do_delete_part,
 358  360              "    delete-part      [-t] [-R <root-dir>] <part-link>"},
 359  361          { "show-part",          do_show_part,
 360      -            "    show-part        [-pP] [-o <field>,...][-l <linkover>]\n"
      362 +            "    show-part        [-P] [[-p] -o <field>,...] [-l <linkover>]\n"
 361  363              "\t\t     [<part-link>]"            },
 362  364          { "show-ib",            do_show_ib,
 363      -            "    show-ib          [-p] [-o <field>,...] [<link>]\n"     },
      365 +            "    show-ib          [[-p] -o <field>,...] [<link>]"       },
 364  366          { "up-part",            do_up_part,             NULL            },
 365  367          { "create-etherstub",   do_create_etherstub,
 366  368              "    create-etherstub [-t] <link>"                          },
 367  369          { "delete-etherstub",   do_delete_etherstub,
 368  370              "    delete-etherstub [-t] <link>"                          },
 369  371          { "show-etherstub",     do_show_etherstub,
 370  372              "    show-etherstub   [-t] [<link>]\n"                      },
 371  373          { "create-simnet",      do_create_simnet,       NULL            },
 372  374          { "modify-simnet",      do_modify_simnet,       NULL            },
 373  375          { "delete-simnet",      do_delete_simnet,       NULL            },
↓ open down ↓ 11 lines elided ↑ open up ↑
 385  387              "\t\t     [-f <force-protocol>] <bridge>"                   },
 386  388          { "delete-bridge",      do_delete_bridge,
 387  389              "    delete-bridge    [-R <root-dir>] <bridge>"             },
 388  390          { "add-bridge",         do_add_bridge,
 389  391              "    add-bridge       [-R <root-dir>] -l <link> [-l <link>]... "
 390  392              "<bridge>"                                                  },
 391  393          { "remove-bridge",      do_remove_bridge,
 392  394              "    remove-bridge    [-R <root-dir>] -l <link> [-l <link>]... "
 393  395              "<bridge>"                                                  },
 394  396          { "show-bridge",        do_show_bridge,
 395      -            "    show-bridge      [-p] [-o <field>,...] [-s [-i <interval>]] "
      397 +            "    show-bridge      [[-p] -o <field>,...] [-s [-i <interval>]] "
 396  398              "[<bridge>]\n"
 397      -            "    show-bridge      -l [-p] [-o <field>,...] [-s [-i <interval>]]"
      399 +            "    show-bridge      -l [[-p] -o <field>,...] [-s [-i <interval>]]"
 398  400              " <bridge>\n"
 399      -            "    show-bridge      -f [-p] [-o <field>,...] [-s [-i <interval>]]"
      401 +            "    show-bridge      -f [[-p] -o <field>,...] [-s [-i <interval>]]"
 400  402              " <bridge>\n"
 401      -            "    show-bridge      -t [-p] [-o <field>,...] [-s [-i <interval>]]"
 402      -            " <bridge>\n"                                               },
      403 +            "    show-bridge      -t [[-p] -o <field>,...] [-s [-i <interval>]]"
      404 +            " <bridge>"                                                 },
 403  405          { "show-usage",         do_show_usage,
 404  406              "    show-usage       [-a] [-d | -F <format>] "
 405  407              "[-s <DD/MM/YYYY,HH:MM:SS>]\n"
 406      -            "\t\t     [-e <DD/MM/YYYY,HH:MM:SS>] -f <logfile> [<link>]" }
      408 +            "\t\t     [-e <DD/MM/YYYY,HH:MM:SS>] -f <logfile> [<link>]" },
      409 +        { "help",               do_help,
      410 +            "    help             [<subcommand>]"                       }
 407  411  };
 408  412  
 409  413  static const struct option lopts[] = {
 410  414          {"vlan-id",     required_argument,      0, 'v'},
 411  415          {"output",      required_argument,      0, 'o'},
 412  416          {"dev",         required_argument,      0, 'd'},
 413  417          {"policy",      required_argument,      0, 'P'},
 414  418          {"lacp-mode",   required_argument,      0, 'L'},
 415  419          {"lacp-timer",  required_argument,      0, 'T'},
 416  420          {"unicast",     required_argument,      0, 'u'},
↓ open down ↓ 712 lines elided ↑ open up ↑
1129 1133          offsetof(usage_fields_buf_t, usage_rbytes), print_default_cb},
1130 1134  { "OPACKETS",   10,
1131 1135          offsetof(usage_fields_buf_t, usage_opackets), print_default_cb},
1132 1136  { "OBYTES",     11,
1133 1137          offsetof(usage_fields_buf_t, usage_obytes), print_default_cb},
1134 1138  { "BANDWIDTH",  15,
1135 1139          offsetof(usage_fields_buf_t, usage_bandwidth), print_default_cb},
1136 1140  { NULL,         0, 0, NULL}}
1137 1141  ;
1138 1142  
1139      -
1140 1143  /*
1141 1144   * structures for 'dladm show-usage link'
1142 1145   */
1143 1146  
1144 1147  typedef struct  usage_l_fields_buf_s {
1145 1148          char    usage_l_link[12];
1146 1149          char    usage_l_stime[13];
1147 1150          char    usage_l_etime[13];
1148 1151          char    usage_l_rbytes[8];
1149 1152          char    usage_l_obytes[8];
↓ open down ↓ 282 lines elided ↑ open up ↑
1432 1435   * specific function is called.
1433 1436   */
1434 1437  static dladm_handle_t handle = NULL;
1435 1438  
1436 1439  #define DLADM_ETHERSTUB_NAME    "etherstub"
1437 1440  #define DLADM_IS_ETHERSTUB(id)  (id == DATALINK_INVALID_LINKID)
1438 1441  
1439 1442  static void
1440 1443  usage(void)
1441 1444  {
1442      -        int     i;
1443      -        cmd_t   *cmdp;
1444      -        (void) fprintf(stderr, gettext("usage:  dladm <subcommand> <args> ..."
1445      -            "\n"));
1446      -        for (i = 0; i < sizeof (cmds) / sizeof (cmds[0]); i++) {
1447      -                cmdp = &cmds[i];
1448      -                if (cmdp->c_usage != NULL)
1449      -                        (void) fprintf(stderr, "%s\n", gettext(cmdp->c_usage));
1450      -        }
     1445 +        (void) fprintf(stderr, gettext("For more information, run: %s help\n"),
     1446 +            progname);
1451 1447  
1452 1448          /* close dladm handle if it was opened */
1453 1449          if (handle != NULL)
1454 1450                  dladm_close(handle);
1455 1451  
1456 1452          exit(EXIT_FAILURE);
1457 1453  }
1458 1454  
1459 1455  int
1460 1456  main(int argc, char *argv[])
↓ open down ↓ 3 lines elided ↑ open up ↑
1464 1460          dladm_status_t status;
1465 1461  
1466 1462          (void) setlocale(LC_ALL, "");
1467 1463  #if !defined(TEXT_DOMAIN)
1468 1464  #define TEXT_DOMAIN "SYS_TEST"
1469 1465  #endif
1470 1466          (void) textdomain(TEXT_DOMAIN);
1471 1467  
1472 1468          progname = argv[0];
1473 1469  
1474      -        if (argc < 2)
1475      -                usage();
     1470 +        if (argc < 2) {
     1471 +                argv[1] = DLADM_DEFAULT_CMD;
     1472 +                argc++;
     1473 +        }
1476 1474  
1477 1475          for (i = 0; i < sizeof (cmds) / sizeof (cmds[0]); i++) {
1478 1476                  cmdp = &cmds[i];
1479 1477                  if (strcmp(argv[1], cmdp->c_name) == 0) {
1480 1478                          /* Open the libdladm handle */
1481 1479                          if ((status = dladm_open(&handle)) != DLADM_STATUS_OK) {
1482 1480                                  die_dlerr(status,
1483 1481                                      "could not open /dev/dld");
1484 1482                          }
1485 1483  
↓ open down ↓ 3 lines elided ↑ open up ↑
1489 1487                          return (EXIT_SUCCESS);
1490 1488                  }
1491 1489          }
1492 1490  
1493 1491          (void) fprintf(stderr, gettext("%s: unknown subcommand '%s'\n"),
1494 1492              progname, argv[1]);
1495 1493          usage();
1496 1494          return (EXIT_FAILURE);
1497 1495  }
1498 1496  
     1497 +static int
     1498 +help_compare(const void *cmd1, const void *cmd2)
     1499 +{
     1500 +        cmd_t   *cmd1p = (cmd_t *)cmd1;
     1501 +        cmd_t   *cmd2p = (cmd_t *)cmd2;
     1502 +
     1503 +        return (strcmp(cmd1p->c_name, cmd2p->c_name));
     1504 +}
     1505 +
     1506 +static void
     1507 +do_help(int argc, char *argv[], const char *use)
     1508 +{
     1509 +        size_t          nelems;
     1510 +        int             i, j, ncols = 3;
     1511 +        boolean_t       found = B_FALSE;
     1512 +
     1513 +        _NOTE(ARGUNUSED(use));
     1514 +
     1515 +        nelems = sizeof (cmds) / sizeof (cmd_t);
     1516 +
     1517 +        if (argc < 2) {
     1518 +                qsort(cmds, nelems, sizeof (cmd_t), help_compare);
     1519 +
     1520 +                (void) fprintf(stderr, gettext(
     1521 +                    "usage: dladm help <subcommand>\n"
     1522 +                    "Subcommands are:\n"));
     1523 +
     1524 +                for (i = 0, j = 0; i < nelems; i++) {
     1525 +                        if (cmds[i].c_usage == NULL)
     1526 +                                continue;
     1527 +
     1528 +                        (void) fprintf(stderr, "%-20s", cmds[i].c_name);
     1529 +
     1530 +                        if (++j % ncols == 0)
     1531 +                                (void) putc('\n', stderr);
     1532 +                }
     1533 +
     1534 +                if (j % ncols != 0)
     1535 +                        (void) putc('\n', stderr);
     1536 +        } else {
     1537 +                for (i = 0; i < nelems; i++) {
     1538 +                        if (strcmp(argv[1], cmds[i].c_name) == 0) {
     1539 +                                (void) fprintf(stderr, "usage:\n%s\n",
     1540 +                                    gettext(cmds[i].c_usage));
     1541 +                                found = B_TRUE;
     1542 +                                break;
     1543 +                        }
     1544 +                }
     1545 +
     1546 +                if (!found) {
     1547 +                        (void) fprintf(stderr, gettext(
     1548 +                            "%s: unknown subcommand '%s'\n"),
     1549 +                            progname, argv[1]);
     1550 +                        usage();
     1551 +                }
     1552 +        }
     1553 +}
     1554 +
1499 1555  /*ARGSUSED*/
1500 1556  static int
1501 1557  show_usage_date(dladm_usage_t *usage, void *arg)
1502 1558  {
1503 1559          show_usage_state_t      *state = (show_usage_state_t *)arg;
1504 1560          time_t                  stime;
1505 1561          char                    timebuf[20];
1506 1562          dladm_status_t          status;
1507 1563          uint32_t                flags;
1508 1564  
↓ open down ↓ 8182 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX