ipdadm.c revision fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1
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 * 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 * Copyright (c) 2012 Joyent, Inc. All rights reserved.
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi * Use is subject to license terms.
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 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 { "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 (void) fprintf(fp, "Usage: %s [-z zonename] subcommand "
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) fprintf(fp, "\t%s\n", cmd->idc_usage);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchiipdadm_list_one(zoneid_t z, const ipd_config_t *icp, void *arg)
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi if (getzonenamebyid(z, zonename, sizeof (zonename)) < 0)
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) printf("\t%u\t%u\t%u\n", icp->ic_corrupt, icp->ic_drop,
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) fprintf(stderr, "%s: failed to get list info: %s\n",
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi ipd_status_foreach_zone(hdl, ipdadm_list_one, (void *)(intptr_t)opt_v);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) fprintf(stderr, "%s: failed to get info: %s\n",
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi if (ipd_status_get_config(hdl, g_zid, &icp) != 0) {
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) printf("zone %s does not exist or has no "
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) fprintf(stderr, "%s: failed to get info: %s\n",
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) printf("ipd information for zone %s:\n",
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) printf("\tcorrupt:\t%u%% chance of packet corruption\n",
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) printf("\tdrop:\t\t%u%% chance of packet drop\n",
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) printf("\tdelay:\t\t%u microsecond delay per packet\n",
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchiipdadm_parse_long(const char *str, const char *name, long min, long max)
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) fprintf(stderr, "%s: invalid value for %s: %s\n",
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 (void) fprintf(stderr, "%s: %s value must be an integer\n",
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 (void) fprintf(stderr, "%s: corrupt <percentage>\n",
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi val = ipdadm_parse_long(argv[0], "corrupt", 0, 100);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) fprintf(stderr, "%s: failed to change corrupt "
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) fprintf(stderr, "%s: delay <microseconds>\n",
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi val = ipdadm_parse_long(argv[0], "delay", 0, MAXLONG);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) fprintf(stderr, "%s: failed to change delay value: %s\n",
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) fprintf(stderr, "%s: drop <percentage>\n",
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi val = ipdadm_parse_long(argv[0], "drop", 0, 100);
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) fprintf(stderr, "%s: failed to change drop value: %s\n",
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) fprintf(stderr, "%s: remove <arguments>\n",
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) fprintf(stderr, "%s: remove's arguments must be "
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi if ((rval = ipdadm_remove_valid(cur)) == 0) {
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) fprintf(stderr, "%s: unknown remove "
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi if ((rval = ipdadm_remove_valid(cur)) == 0) {
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) fprintf(stderr, "%s: unknown remove argument: %s\n",
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) fprintf(stderr, "%s: failed to remove instances: %s\n",
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) fprintf(stderr, "%s: -z requires an argument\n",
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) fprintf(stderr, "%s: -z option only permitted "
fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1Robert Mustacchi (void) fprintf(stderr, "%s: %s: invalid zone\n",
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 (void) fprintf(stderr, "%s: %s: unknown command\n", g_pname, argv[0]);