ilbadm_import.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 <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <strings.h>
#include <errno.h>
#include <fcntl.h>
#include <libilb.h>
#include "ilbadm.h"
static ilbadm_cmd_help_t create_sg_help = {
"[-s server=hostspec[:portspec...]] groupname"
};
static ilbadm_cmd_help_t create_rule_help = {
"[-e] [-p] -i vip=value,port=value[,protocol=value] \n" \
" -m lbalg=value,type=value[,proxy-src=ip-range][,pmask=mask] \n"\
" -h hc-name=value[,hc-port=value]] \n" \
" [-t [conn-drain=N][,nat-timeout=N][,persist-timeout=N]] \n" \
" -o servergroup=value name"
};
static ilbadm_cmd_help_t destroy_rule_help = {
"-a | name ..."
};
static ilbadm_cmd_help_t add_server_help = {
"-s server=value[,value ...] servergroup"
};
static ilbadm_cmd_help_t remove_server_help = {
"-s server=value[,value ...] servergroup"
};
static ilbadm_cmd_help_t disable_server_help = {
"server ... "
};
static ilbadm_cmd_help_t enable_server_help = {
"server ..."
};
static ilbadm_cmd_help_t enable_rule_help = {
"[name ... ]"
};
static ilbadm_cmd_help_t disable_rule_help = {
"[name ... ]"
};
static ilbadm_cmd_help_t show_server_help = {
"[[-p] -o field[,field...]] [rulename ... ]"
};
static ilbadm_cmd_help_t showstats_help = {
"[-p] -o field[,...]] [-tdAvi]\n" \
" [-r rulename|-s servername] [interval [count]]"
};
static ilbadm_cmd_help_t show_nat_help = {
"[count]"
};
static ilbadm_cmd_help_t show_persist_help = {
"[count]"
};
static ilbadm_cmd_help_t show_hc_help = {
"[hc-name]"
};
static ilbadm_cmd_help_t create_hc_help = {
"[-n] -h hc-test=value[,hc-timeout=value]\n" \
" [,hc-count=value][,hc-interval=value] hcname"
};
static ilbadm_cmd_help_t destroy_hc_help = {
"name ..."
};
static ilbadm_cmd_help_t show_hc_result_help = {
"[rule-name]"
};
static ilbadm_cmd_help_t show_rule_help = {
"[-e|-d] [-f |[-p] -o key[,key ...]] [name ...]"
};
static ilbadm_cmd_help_t destroy_servergroup_help = {
"groupname"
};
static ilbadm_cmd_help_t show_servergroup_help = {
"[[-p] -o field[,field]] [name]"
};
static ilbadm_cmd_help_t export_config_help = {
"[filename]"
};
static ilbadm_cmd_help_t import_config_help = {
"[-p] [filename]"
};
static ilbadm_cmd_desc_t ilbadm_cmds[] = {
};
/* ARGSUSED */
{
return (ILBADM_LIBERR);
}
static void
{
char *h;
else
cmd++;
}
}
void
{
}
#define IMPORT_FILE 0x1
static void
{
" not allowed"));
exit(1);
}
}
break;
}
}
/*
* read and parse commandline
*/
static ilbadm_status_t
{
} else {
}
return (rc);
}
#define CHUNK 10
#define LINESZ 1024
typedef struct {
int listsz;
char *arglist[1];
} arg_t;
static int
{
char delim[] = " \t\n";
int i;
return (0);
i = 0;
return (i);
/* ignore lines starting with a # character */
if (*currp == '#')
goto read_next;
/*
* if there's more than one adjacent delimiters ...
*/
if (*currp == '\0') {
i--;
continue;
}
/*
* if we find a '\' at the end of a line, treat
* it as a continuation character.
*/
goto read_next;
}
if (a == NULL) {
bzero(a, sizeof (*a));
}
if (a->listsz <= i) {
int sz;
sz = sizeof (*a) +
*ap = a;
}
}
return (i);
}
static ilbadm_status_t
{
int argcount;
exit(1);
}
if ((flags & ILBADM_IMPORT_PRESERVE) == 0) {
if (rclib == ILB_STATUS_OK)
(void) ilb_reset_config(h);
if (h != ILB_INVALID_HANDLE)
(void) ilb_close(h);
}
optind = 1;
break;
}
return (rc);
}
/*
* this is the wrapper around everything to do with importing and
* parsing either commandline or persistent storage.
* if (fd == -1), parse commandline, otherwise use the given fd as input.
*/
/* ARGSUSED */
{
if (fd == -1)
else
return (rc);
}
{
int fd;
char tmpfile[MAXPATHLEN];
if (argc < 2) {
*tmpfile = '\0';
} else {
if (fd == -1) {
exit(1);
}
}
exit(1);
}
if (rclib != ILB_STATUS_OK)
goto out;
goto out;
goto out;
goto out;
exit(1);
}
*tmpfile = '\0';
}
out:
if (h != ILB_INVALID_HANDLE)
(void) ilb_close(h);
if (*tmpfile != '\0')
return (rc);
}