4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
31 #include <sys/types.h>
32 #include <sys/socket.h>
40 * Error strings for error values returned by ilbadm functions
43 ilbadm_errstr(ilbadm_status_t rc
)
47 return (gettext("no error"));
49 return (gettext("processing of command failed"));
51 return (gettext("memory allocation failure"));
53 return (gettext("invalid value - refer to ilbadm(1M)"));
55 return (gettext("failed to print healthcheck values"));
57 return (gettext("address family is invalid"));
58 case ILBADM_INVAL_PORT
:
59 return (gettext("port value is invalid"));
60 case ILBADM_INVAL_SRVID
:
61 return (gettext("server ID is invalid"));
62 case ILBADM_INVAL_ADDR
:
63 return (gettext("address is invalid"));
64 case ILBADM_INVAL_ARGS
:
65 return (gettext("invalid/incompatible keywords - refer to"
67 case ILBADM_ENOSGNAME
:
68 return (gettext("servergroup name missing"));
70 return (gettext("rule name missing or specified"
72 case ILBADM_ENOSERVER
:
73 return (gettext("server name missing or specified"
74 " server not found"));
75 case ILBADM_INVAL_ALG
:
76 return (gettext("LB algorithm is invalid"));
78 return (gettext("protocol does not exist in"
79 " protocol database"));
80 case ILBADM_ENOSERVICE
:
81 return (gettext("servicename does not exist in nameservices"));
82 case ILBADM_INVAL_OPER
:
83 return (gettext("operation type is invalid"));
84 case ILBADM_INVAL_KEYWORD
:
85 return (gettext("keyword is invalid - please refer"
87 case ILBADM_ASSIGNREQ
:
88 return (gettext("assignment '=' missing"));
89 case ILBADM_NORECURSIVE
:
90 return (gettext("recursive import not allowed"));
91 case ILBADM_INVAL_COMMAND
:
92 return (gettext("subcommand is invalid - please refer"
95 return (gettext("proxy-src is missing"));
96 case ILBADM_INVAL_PROXY
:
97 return (gettext("proxy-src not allowed"));
98 case ILBADM_ENOOPTION
:
99 return (gettext("mandatory argument(s) missing - refer"
101 case ILBADM_TOOMANYIPADDR
:
102 return (gettext("address range contains more than 255"
104 case ILBADM_EXPORTFAIL
:
105 return (gettext("could not export servergroup because"
106 " of lack of space"));
107 case ILBADM_INVAL_SYNTAX
:
108 return (gettext("syntax failure - refer to ilbadm(1M)"));
109 case ILBADM_NOKEYWORD_VAL
:
110 return (gettext("missing value"));
112 return (gettext("library error"));
114 return (gettext("unknown error"));
122 ilbadm_err(const char *format
, ...)
124 /* similar to warn() of dladm.c */
127 (void) fprintf(stderr
, "ilbadm: ");
129 va_start(alist
, format
);
130 (void) vfprintf(stderr
, format
, alist
);
133 (void) fprintf(stderr
, "\n");
139 (void) fprintf(stderr
, gettext("Usage:\n"));
140 print_cmdlist_short(basename(name
), stderr
);
145 print_version(char *name
)
147 (void) printf("%s %s\n", basename(name
), ILBADM_VERSION
);
148 (void) printf(gettext(ILBADM_COPYRIGHT
));
153 unknown_opt(char **argv
, int optind
)
155 ilbadm_err(gettext("bad or misplaced option %s"), argv
[optind
]);
160 incomplete_cmdline(char *name
)
162 ilbadm_err(gettext("the command line is incomplete "
163 "(more arguments expected)"));
168 bad_importfile(char *name
, char *filename
)
170 ilbadm_err(gettext("file %s cannot be opened for reading"), filename
);
175 main(int argc
, char *argv
[])
182 (void) setlocale(LC_ALL
, "");
184 #if !defined(TEXT_DOMAIN)
185 #define TEXT_DOMAIN "SYS_TEST"
187 (void) textdomain(TEXT_DOMAIN
);
189 /* handle global options (-?, -V) first */
190 while ((c
= getopt(argc
, argv
, ":V:?")) != -1) {
192 case 'V': print_version(argv
[0]);
199 default: unknown_opt(argv
, optind
- 1);
206 incomplete_cmdline(argv
[0]);
209 * we can import from a given file (argv[2]) or from
210 * stdin (if no file given)
212 if (strcasecmp(argv
[1], "import-config") == 0 ||
213 strcasecmp(argv
[1], "import-cf") == 0) {
216 if (argc
> 2 && strcmp(argv
[2], "-p") == 0) {
218 flags
|= ILBADM_IMPORT_PRESERVE
;
221 if (argc
- shift
< 3)
224 if ((fd
= open(argv
[2+shift
], O_RDONLY
)) == -1)
225 bad_importfile(argv
[0], argv
[2+shift
]);
232 * re-set optind for next callers of getopt() - they all believe they're
238 rc
= ilbadm_import(fd
, argc
, argv
, flags
);
241 * The error messages have been printed out, using
242 * ilbadm_errstr() and ilb_errstr(), before we get here.
243 * So just set the exit value