/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <errno.h>
#include <locale.h>
#include <libintl.h>
#include <libvrrpadm.h>
#include <ofmt.h>
typedef void cmd_func_t(int, char *[], const char *);
typedef struct {
char *c_name;
const char *c_usage;
} cmd_t;
{ "create-router", do_create,
"-V <vrid> -l <link> -A {inet | inet6} [-p <priority>] "
"[-i <adv_interval>] [-o <flags>] <router_name>" },
{ "modify-router", do_modify,
"[-p <priority>] [-i <adv_interval>] [-o <flags>] <router_name>" },
{ "show-router", do_show,
"[-P | -x] [-o field[,...]] [-p] [<router_name>]" }
};
{ 0, 0, 0, 0 }
};
{ 0, 0, 0, 0 }
};
/*
* structures for 'dladm show-link -s' (print statistics)
*/
enum {
};
/*
* structures for 'vrrpadm show-router'
*/
/* name, field width, index, callback */
;
static char *timeval_since_str(int, char *, size_t);
static void usage();
static void warn(const char *, ...);
static void err_exit(const char *, ...);
static void opterr_exit(int, int, const char *);
int
{
int i;
(void) textdomain(TEXT_DOMAIN);
usage();
return (EXIT_SUCCESS);
}
}
usage();
return (EXIT_FAILURE);
}
static void
{
int c;
char *endp;
/*
* default value
*/
switch (c) {
case 'l':
}
break;
case 'i':
if (create_mask & VRRP_CONF_INTERVAL)
err_exit("duplicate '-i' option");
if ((*endp) != '\0' ||
err_exit("invalid advertisement interval");
}
break;
case 'p':
if (create_mask & VRRP_CONF_PRIORITY)
err_exit("duplicate '-p' option");
err_exit("invalid priority");
}
break;
case 'o':
mask = 0;
}
err_exit("duplicate '-o preempt' option");
err_exit("duplicate '-o accept' option");
create_mask |= mask;
break;
case 'V':
err_exit("duplicate '-V' option");
err_exit("invalid VRID");
}
break;
case 'A':
err_exit("duplicate '-A' option");
else
err_exit("invalid address family");
break;
default:
}
}
err_exit("VRRP name not specified");
}
err_exit("VRID not specified");
err_exit("address family not specified");
err_exit("link name not specified");
err_exit("accept_mode must be true for virtual IP owner");
done:
return;
}
static void
{
if (argc != 2)
}
static void
{
if (argc != 2)
}
static void
{
if (argc != 2)
}
static void
{
char *endp;
int c;
switch (c) {
case 'i':
if (modify_mask & VRRP_CONF_INTERVAL)
err_exit("duplicate '-i' option");
if ((*endp) != '\0' ||
err_exit("invalid advertisement interval");
}
break;
case 'o':
mask = 0;
&conf.vvc_accept) != 0) {
err_exit("Invalid options");
}
err_exit("duplicate '-o preempt' option");
err_exit("duplicate '-o accept' option");
modify_mask |= mask;
break;
case 'p':
if (modify_mask & VRRP_CONF_PRIORITY)
err_exit("duplicate '-p' option");
err_exit("invalid priority");
}
break;
default:
}
}
err_exit("VRRP name not specified.");
}
(modify_mask & VRRP_CONF_PRIORITY) &&
err_exit("accept_mode must be true for virtual IP owner");
}
if (modify_mask == 0)
usage();
if (err != VRRP_SUCCESS)
}
/*
* 'show-router' one VRRP router.
*/
static vrrp_err_t
{
return (err);
return (VRRP_SUCCESS);
}
static void
{
int c;
static char *dft_fields_str =
"NAME,VRID,LINK,AF,PRIO,ADV_INTV,MODE,STATE,VNIC";
static char *ext_fields_str =
"NAME,STATE,PRV_STAT,STAT_LAST,VNIC,PRIMARY_IP,VIRTUAL_IPS";
static char *peer_fields_str =
"NAME,PEER,P_PRIO,P_INTV,P_ADV_LAST,M_DOWN_INTV";
/*
* If parsable output is requested, add VIP_CNT into the output
* for extended output. It is not needed for human-readable
* output as it is obvious from the VIRTUAL_IPS list.
*/
static char *ext_parsable_fields_str =
"NAME,STATE,PRV_STAT,STAT_LAST,VNIC,PRIMARY_IP,VIP_CNT,"
"VIRTUAL_IPS";
switch (c) {
case 'o':
fields_str = optarg;
break;
case 'p':
break;
case 'P':
break;
case 'x':
break;
default:
}
}
err_exit("incompatible -P and -x options");
/*
* If parsable output is requested, add VIP_CNT into the output
* for extended output.
*/
0, &ofmt)) != OFMT_SUCCESS) {
/*
* If some fields were badly formed in human-friendly mode, we
* emit a warning and continue. Otherwise exit immediately.
*/
} else {
}
}
/* Show one router */
goto done;
}
/*
* Show all routers. First set in_cnt to 0 to find out the number
* of vrrp routers.
*/
err = VRRP_ENOMEM;
goto done;
}
goto done;
}
/*
* The VRRP routers has been changed between two vrrp_list()
* calls, try again.
*/
goto again;
}
/*
* Each VRRP router name is separated by '\0`
*/
for (i = 0; i < in_cnt; i++) {
}
done:
if (err != VRRP_SUCCESS)
}
/*
* Callback function to print fields of the configuration information.
*/
static boolean_t
{
switch (ofmtid) {
case ROUTER_NAME:
break;
case ROUTER_VRID:
break;
case ROUTER_LINK:
break;
case ROUTER_AF:
break;
case ROUTER_PRIO:
break;
case ROUTER_ADV_INTV:
break;
case ROUTER_MODE:
if (conf->vvc_enabled)
buf[0] = 'e';
if (conf->vvc_preempt)
if (conf->vvc_accept)
break;
case ROUTER_STATE:
break;
case ROUTER_PRV_STAT:
break;
case ROUTER_STAT_LAST:
bufsize);
break;
case ROUTER_PEER:
/* LINTED E_CONSTANT_CONDITION */
break;
case ROUTER_P_PRIO:
break;
case ROUTER_P_INTV:
break;
case ROUTER_P_ADV_LAST:
bufsize);
break;
case ROUTER_M_DOWN_INTV:
break;
case ROUTER_VNIC:
break;
case ROUTER_PRIMARY_IP:
/* LINTED E_CONSTANT_CONDITION */
break;
case ROUTER_VIRTUAL_IPS: {
uint32_t i;
/* LINTED E_CONSTANT_CONDITION */
}
break;
}
case ROUTER_VIP_CNT:
break;
default:
return (B_FALSE);
}
return (B_TRUE);
}
static void
usage()
{
int i;
gettext("usage: vrrpadm <sub-command> <args> ...\n"));
}
}
static void
{
}
static void
{
}
static void
{
switch (opterr) {
case ':':
break;
case '?':
default:
break;
}
}
static char *
{
sec %= 60;
if (min > 0)
else
return (str);
}
/*
* Parses options string. The values of the two options will be returned
* by 'preempt' and 'accept', and the mask 'modify_mask' will be updated
* accordingly.
*
* Returns 0 on success, errno on failures.
*
* Used by do_create() and do_modify().
*
* Note that "opts" could be modified internally in this function.
*/
static int
{
char *value;
int opt;
static char *myopts[] = {
"preempt",
"un_preempt",
"accept",
"no_accept",
};
while (*opts != '\0') {
case o_preempt:
case o_un_preempt:
if (mask & VRRP_CONF_PREEMPT)
return (EINVAL);
break;
case o_accept:
case o_no_accept:
if (mask & VRRP_CONF_ACCEPT)
return (EINVAL);
mask |= VRRP_CONF_ACCEPT;
break;
default:
return (EINVAL);
}
}
*modify_mask |= mask;
return (0);
}