ilbadm_hc.c revision dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9
/*
* 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 <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <strings.h>
#include <errno.h>
#include <ofmt.h>
#include <libilb.h>
#include "ilbadm.h"
extern char *optarg;
typedef struct hc_export_arg {
/* Maximum columns for printing hc output. */
#define SHOW_HC_COLS 80
/* OFMT call back to print out a hc server result field. */
/* ID to indicate which field to be printed. */
enum hc_print_id {
};
/*
* Fields of a hc server result. The sum of all fields' width is SHOW_HC_COLS.
*/
static ofmt_field_t hc_results[] = {
};
/* OFMT call back to print out a hc info field. */
/*
* Fields of a hc info. The sume of all fields' width is SHOW_HC_COLS.
*/
static ofmt_field_t hc_fields[] = {
};
static boolean_t
{
switch (id) {
case hc_of_name:
break;
case hc_of_timeout:
break;
case hc_of_count:
break;
case hc_of_interval:
break;
case hc_of_def_ping:
break;
case hc_of_test:
break;
}
return (B_TRUE);
}
/* Call back to ilb_walk_hc(). */
/* ARGSUSED */
static ilb_status_t
{
return (ILB_STATUS_OK);
}
/*
* Print out health check objects given their name.
* Or print out all health check objects if no name given.
*/
/* ARGSUSED */
{
&ofmt_h)) != OFMT_SUCCESS) {
char err_buf[SHOW_HC_COLS];
return (ILBADM_LIBERR);
}
if (rclib != ILB_STATUS_OK)
goto out;
if (argc == 1) {
} else {
int i;
for (i = 1; i < argc; i++) {
if (rclib == ILB_STATUS_OK)
else
break;
}
}
out:
if (h != ILB_INVALID_HANDLE)
(void) ilb_close(h);
if (rclib != ILB_STATUS_OK) {
return (ILBADM_LIBERR);
}
return (ILBADM_OK);
}
static boolean_t
{
switch (id) {
case hc_of_rname:
break;
case hc_of_hname:
break;
case hc_of_sname:
break;
case hc_of_status:
switch (srv->hcs_status) {
case ILB_HCS_UNINIT:
break;
case ILB_HCS_UNREACH:
break;
case ILB_HCS_ALIVE:
break;
case ILB_HCS_DEAD:
break;
case ILB_HCS_DISABLED:
break;
}
break;
case hc_of_fail_cnt:
break;
case hc_of_lasttime:
return (B_FALSE);
break;
case hc_of_nexttime:
break;
return (B_FALSE);
break;
case hc_of_rtt:
break;
}
return (B_TRUE);
}
/* Call back to ilbd_walk_hc_srvs(). */
/* ARGSUSED */
static ilb_status_t
{
return (ILB_STATUS_OK);
}
/*
* Output hc result of a specified rule or all rules.
*/
{
int i;
/* ilbadm show-hc-result [rule-name] */
if (argc < 1) {
" [rule-name]"));
return (ILBADM_LIBERR);
}
&ofmt_h)) != OFMT_SUCCESS) {
char err_buf[SHOW_HC_COLS];
return (ILBADM_LIBERR);
}
if (rclib != ILB_STATUS_OK)
goto out;
/* If no rule name is given, show results for all rules. */
if (argc == 1) {
ofmt_h);
} else {
for (i = 1; i < argc; i++) {
if (rclib != ILB_STATUS_OK)
break;
}
}
out:
if (h != ILB_INVALID_HANDLE)
(void) ilb_close(h);
if (rclib != ILB_STATUS_OK) {
return (ILBADM_LIBERR);
}
return (ILBADM_OK);
}
#define ILBADM_DEF_HC_COUNT 3
static ilbadm_key_name_t hc_parse_keys[] = {
};
static ilbadm_status_t
{
/* set default value for count, interval, timeout */
return (ILBADM_LIBERR);
}
ilbadm_err("hc-test: missing");
return (ILBADM_LIBERR);
}
return (ret);
}
/* ARGSUSED */
{
char c;
if (c == 'h') {
return (ret);
} else if (c == 'n') {
} else {
return (ILBADM_LIBERR);
}
}
" create-healthcheck [-n] -h"
" hc-test=val[,hc-timeout=val][,hc-count=va]"
"[,hc-interval=val] hc-name"));
return (ILBADM_FAIL);
}
ILBD_NAMESZ - 1);
return (ILBADM_FAIL);
}
!(hc_info.hci_def_ping)) {
" for this test"));
return (ILBADM_LIBERR);
}
if (rclib != ILB_STATUS_OK)
goto out;
out:
if (h != ILB_INVALID_HANDLE)
(void) ilb_close(h);
if (rclib != ILB_STATUS_OK) {
ret = ILBADM_LIBERR;
}
return (ret);
}
{
int i;
if (argc < 2) {
" delete-healthcheck hc-name ..."));
return (ILBADM_LIBERR);
}
if (rclib != ILB_STATUS_OK)
goto out;
for (i = 1; i < argc; i++) {
if (rclib != ILB_STATUS_OK)
break;
}
out:
if (h != ILB_INVALID_HANDLE)
(void) ilb_close(h);
if (rclib != ILB_STATUS_OK) {
ret = ILBADM_LIBERR;
}
return (ret);
}
/*
* Since this function is used by libilb function, it
* must return libilb errors
*/
/* ARGSUSED */
{
int count = 0;
int ret;
/*
* a test name "PING" implies "no default ping", so we only
* print -n if the test is NOT "PING"
*/
else
count++;
}
if (hc_info->hci_timeout != 0) {
if (count++ > 0)
}
if (count++ > 0)
}
if (hc_info->hci_interval != 0) {
if (count > 0)
}
/*
* if any of the above writes fails, then, we assume, so will
* this one; so it's sufficient to test once
*/
if (ret < 0)
goto out_fail;
if (ret < 0)
return (ILB_STATUS_WRITE);
return (ILB_STATUS_OK);
}
{
if (rclib != ILB_STATUS_OK) {
ret = ILBADM_LIBERR;
}
return (ret);
}