ipdadm.c revision fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi/*
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi * This file and its contents are supplied under the terms of the
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi * Common Development and Distribution License ("CDDL"), version 1.0.
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi * You may only use this file in accordance with the terms of version
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi * 1.0 of the CDDL.
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi *
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi * A full copy of the text of the CDDL should have accompanied this
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi * source. A copy of the CDDL is also available via the Internet at
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi * http://www.illumos.org/license/CDDL.
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi */
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi/*
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi * Copyright (c) 2012 Joyent, Inc. All rights reserved.
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi * Use is subject to license terms.
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi */
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi#include <sys/types.h>
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi#include <sys/stat.h>
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi#include <values.h>
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi#include <fcntl.h>
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi#include <errno.h>
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi#include <string.h>
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi#include <strings.h>
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi#include <stdio.h>
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi#include <stdlib.h>
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi#include <unistd.h>
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi#include <stropts.h>
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi#include <zone.h>
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi#include <libgen.h>
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi#include <assert.h>
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi#include <libipd.h>
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchistatic char *g_pname;
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchistatic char g_zonename[ZONENAME_MAX];
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchistatic zoneid_t g_zid;
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi#define E_SUCCESS 0
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi#define E_ERROR 1
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi#define E_USAGE 2
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchitypedef int (*idc_cmd_func_t)(int, char *[]);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchitypedef struct ipdadm_cmd {
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi const char *idc_name; /* subcommand name */
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi idc_cmd_func_t idc_func; /* subcommand function */
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi const char *idc_usage; /* subcommand help */
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi} ipdadm_cmd_t;
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchistatic int ipdadm_list(int, char *[]);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchistatic int ipdadm_info(int, char *[]);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchistatic int ipdadm_corrupt(int, char *[]);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchistatic int ipdadm_delay(int, char *[]);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchistatic int ipdadm_drop(int, char *[]);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchistatic int ipdadm_remove(int, char *[]);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi#define IPDADM_NCMDS 6
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchistatic ipdadm_cmd_t ipdadm_cmds[] = {
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi { "list", ipdadm_list, "list [-v]" },
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi { "info", ipdadm_info, "info" },
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi { "corrupt", ipdadm_corrupt, "corrupt <percentage>" },
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi { "delay", ipdadm_delay, "delay <microseconds>" },
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi { "drop", ipdadm_drop, "drop <percentage>" },
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi { "remove", ipdadm_remove, "remove [corrupt|delay|drop]" }
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi};
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchistatic int
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchiusage(FILE *fp)
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi{
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi int ii;
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi ipdadm_cmd_t *cmd;
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) fprintf(fp, "Usage: %s [-z zonename] subcommand "
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi "[subcommand opts]\n\n", g_pname);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) fprintf(fp, "Subcommands:\n");
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi for (ii = 0; ii < IPDADM_NCMDS; ii++) {
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi cmd = &ipdadm_cmds[ii];
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) fprintf(fp, "\t%s\n", cmd->idc_usage);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi }
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi return (E_USAGE);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi}
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchistatic void
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchiipdadm_list_one(zoneid_t z, const ipd_config_t *icp, void *arg)
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi{
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi char zonename[ZONENAME_MAX];
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi int opt_v = (int)(intptr_t)arg;
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi if (getzonenamebyid(z, zonename, sizeof (zonename)) < 0)
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) printf("%ld", z);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi else
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) printf("%s", zonename);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi if (!opt_v) {
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) printf("\n");
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi return;
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi }
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) printf("\t%u\t%u\t%u\n", icp->ic_corrupt, icp->ic_drop,
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi icp->ic_delay);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi}
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchistatic int
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchiipdadm_list(int argc, char *argv[])
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi{
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi int opt_v = 0;
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi int fd, rval;
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi ipd_stathdl_t hdl;
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi if (argc > 1)
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi return (usage(stderr));
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi if (argc == 1) {
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi if (strcmp(argv[0], "-v") == 0)
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi ++opt_v;
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi else
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi return (usage(stderr));
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi }
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi fd = ipd_open(NULL);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi rval = ipd_status_read(fd, &hdl);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) ipd_close(fd);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi if (rval != 0) {
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) fprintf(stderr, "%s: failed to get list info: %s\n",
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi g_pname, ipd_errmsg);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi return (E_ERROR);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi }
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi ipd_status_foreach_zone(hdl, ipdadm_list_one, (void *)(intptr_t)opt_v);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi ipd_status_free(hdl);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi return (E_SUCCESS);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi}
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi/*ARGSUSED*/
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchistatic int
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchiipdadm_info(int argc, char *argv[])
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi{
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi int rval, fd;
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi ipd_stathdl_t hdl;
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi ipd_config_t *icp;
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi if (argc != 0)
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi return (usage(stderr));
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi fd = ipd_open(NULL);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi rval = ipd_status_read(fd, &hdl);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) ipd_close(fd);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi if (rval != 0) {
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) fprintf(stderr, "%s: failed to get info: %s\n",
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi g_pname, ipd_errmsg);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi return (E_ERROR);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi }
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi if (ipd_status_get_config(hdl, g_zid, &icp) != 0) {
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi if (ipd_errno == EIPD_ZC_NOENT) {
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) printf("zone %s does not exist or has no "
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi "ipd actions enabled\n", g_zonename);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi return (E_SUCCESS);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi }
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) fprintf(stderr, "%s: failed to get info: %s\n",
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi g_pname, ipd_errmsg);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi return (E_ERROR);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi }
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) printf("ipd information for zone %s:\n",
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi g_zonename);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) printf("\tcorrupt:\t%u%% chance of packet corruption\n",
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi icp->ic_corrupt);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) printf("\tdrop:\t\t%u%% chance of packet drop\n",
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi icp->ic_drop);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) printf("\tdelay:\t\t%u microsecond delay per packet\n",
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi icp->ic_delay);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi ipd_status_free(hdl);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi return (E_SUCCESS);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi}
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchistatic long
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchiipdadm_parse_long(const char *str, const char *name, long min, long max)
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi{
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi long val;
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi char *end;
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi errno = 0;
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi val = strtol(str, &end, 10);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi if (errno != 0) {
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) fprintf(stderr, "%s: invalid value for %s: %s\n",
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi g_pname, name, str);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi exit(E_ERROR);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi }
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi /*
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi * We want to make sure that we got the whole string. If not that's an
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi * error. e.g. 23.42 should not be valid.
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi */
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi if (*end != '\0') {
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) fprintf(stderr, "%s: %s value must be an integer\n",
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi g_pname, name);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi exit(E_ERROR);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi }
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi if (val < min || val > max) {
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) fprintf(stderr, "%s: %s value must be between %ld and "
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi "%ld inclusive\n", g_pname, name, min, max);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi exit(E_ERROR);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi }
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi return (val);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi}
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchistatic int
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchiipdadm_corrupt(int argc, char *argv[])
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi{
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi int rval, fd;
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi long val;
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi ipd_config_t ic;
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi if (argc != 1) {
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) fprintf(stderr, "%s: corrupt <percentage>\n",
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi g_pname);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi return (usage(stderr));
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi }
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi val = ipdadm_parse_long(argv[0], "corrupt", 0, 100);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi bzero(&ic, sizeof (ic));
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi ic.ic_mask = IPDM_CORRUPT;
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi ic.ic_corrupt = val;
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi fd = ipd_open(NULL);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi rval = ipd_ctl(fd, g_zid, &ic);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) ipd_close(fd);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi if (rval != 0) {
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) fprintf(stderr, "%s: failed to change corrupt "
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi "value: %s\n", g_pname, ipd_errmsg);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi return (E_ERROR);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi }
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi return (E_SUCCESS);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi}
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchistatic int
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchiipdadm_delay(int argc, char *argv[])
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi{
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi long val;
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi int fd, rval;
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi ipd_config_t ic;
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi if (argc != 1) {
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) fprintf(stderr, "%s: delay <microseconds>\n",
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi g_pname);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi return (usage(stderr));
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi }
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi val = ipdadm_parse_long(argv[0], "delay", 0, MAXLONG);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi bzero(&ic, sizeof (ic));
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi ic.ic_mask = IPDM_DELAY;
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi ic.ic_delay = val;
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi fd = ipd_open(NULL);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi rval = ipd_ctl(fd, g_zid, &ic);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) ipd_close(fd);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi if (rval != 0) {
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) fprintf(stderr, "%s: failed to change delay value: %s\n",
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi g_pname, ipd_errmsg);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi return (E_ERROR);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi }
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi return (E_SUCCESS);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi}
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchistatic int
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchiipdadm_drop(int argc, char *argv[])
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi{
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi long val;
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi int fd, rval;
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi ipd_config_t ic;
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi if (argc != 1) {
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) fprintf(stderr, "%s: drop <percentage>\n",
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi g_pname);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi return (usage(stderr));
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi }
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi val = ipdadm_parse_long(argv[0], "drop", 0, 100);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi bzero(&ic, sizeof (ic));
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi ic.ic_mask = IPDM_DROP;
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi ic.ic_drop = val;
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi fd = ipd_open(NULL);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi rval = ipd_ctl(fd, g_zid, &ic);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) ipd_close(fd);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi if (rval != 0) {
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) fprintf(stderr, "%s: failed to change drop value: %s\n",
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi g_pname, ipd_errmsg);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi return (E_ERROR);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi }
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi return (E_SUCCESS);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi}
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchistatic int
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchiipdadm_remove_valid(const char *str)
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi{
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi if (strcmp(str, "corrupt") == 0) {
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi return (IPDM_CORRUPT);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi } else if (strcmp(str, "drop") == 0) {
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi return (IPDM_DROP);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi } else if (strcmp(str, "delay") == 0) {
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi return (IPDM_DELAY);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi }
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi return (0);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi}
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchistatic int
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchiipdadm_remove(int argc, char *argv[])
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi{
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi ipd_config_t ic;
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi char *cur, *res;
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi int rval, fd;
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi if (argc < 1) {
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) fprintf(stderr, "%s: remove <arguments>\n",
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi g_pname);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi return (usage(stderr));
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi }
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi if (argc > 1) {
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) fprintf(stderr, "%s: remove's arguments must be "
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi "comma seperated\n", g_pname);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi return (E_ERROR);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi }
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi bzero(&ic, sizeof (ic));
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi cur = argv[0];
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi while ((res = strchr(cur, ',')) != NULL) {
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi *res = '\0';
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi if ((rval = ipdadm_remove_valid(cur)) == 0) {
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) fprintf(stderr, "%s: unknown remove "
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi "argument: %s\n", g_pname, cur);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi return (E_ERROR);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi }
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi ic.ic_mask |= rval;
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi cur = res + 1;
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi }
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi if ((rval = ipdadm_remove_valid(cur)) == 0) {
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) fprintf(stderr, "%s: unknown remove argument: %s\n",
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi g_pname, cur);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi return (E_ERROR);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi }
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi ic.ic_mask |= rval;
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi fd = ipd_open(NULL);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi rval = ipd_ctl(fd, g_zid, &ic);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) ipd_close(fd);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi if (rval == -1) {
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) fprintf(stderr, "%s: failed to remove instances: %s\n",
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi g_pname, ipd_errmsg);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi return (E_ERROR);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi }
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi return (E_SUCCESS);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi}
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchiint
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchimain(int argc, char *argv[])
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi{
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi int ii;
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi ipdadm_cmd_t *cmd;
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi g_pname = basename(argv[0]);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi if (argc < 2)
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi return (usage(stderr));
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi argc--;
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi argv++;
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi g_zid = getzoneid();
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi if (strcmp("-z", argv[0]) == 0) {
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi argc--;
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi argv++;
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi if (argc < 1) {
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) fprintf(stderr, "%s: -z requires an argument\n",
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi g_pname);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi return (usage(stderr));
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi }
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi if (g_zid != GLOBAL_ZONEID) {
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) fprintf(stderr, "%s: -z option only permitted "
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi "in global zone\n", g_pname);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi return (usage(stderr));
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi }
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi g_zid = getzoneidbyname(argv[0]);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi if (g_zid == -1) {
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) fprintf(stderr, "%s: %s: invalid zone\n",
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi g_pname, argv[0]);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi return (E_ERROR);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi }
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi argc--;
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi argv++;
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi }
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi if (getzonenamebyid(g_zid, g_zonename, sizeof (g_zonename)) < 0) {
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) fprintf(stderr, "%s: failed to get zonename: %s\n",
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi g_pname, strerror(errno));
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi return (E_ERROR);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi }
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi if (argc < 1)
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi return (usage(stderr));
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi for (ii = 0; ii < IPDADM_NCMDS; ii++) {
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi cmd = &ipdadm_cmds[ii];
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi if (strcmp(argv[0], cmd->idc_name) == 0) {
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi argv++;
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi argc--;
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi assert(cmd->idc_func != NULL);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi return (cmd->idc_func(argc, argv));
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi }
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi }
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) fprintf(stderr, "%s: %s: unknown command\n", g_pname, argv[0]);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi return (usage(stderr));
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi}