xref: /titanic_44/usr/src/cmd/cmd-inet/usr.sbin/ilbadm/ilbadm.h (revision a4aeef46cda1835da2b19f8f62b4526de6521e6c)
1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_ILBADM_H
27 #define	_ILBADM_H
28 
29 #ifdef	__cplusplus
30 extern "C" {
31 #endif
32 
33 #include <stdio.h>
34 #include <sys/list.h>
35 #include <net/if.h>
36 #include <stdarg.h>
37 #include <inttypes.h>
38 #include <libilb.h>
39 #include <libintl.h>
40 #include <locale.h>
41 
42 #define	ILBADM_VERSION  "1.0"
43 #define	ILBADM_COPYRIGHT \
44 	"Copyright 2009 Sun Microsystems, Inc.  All rights reserved.\n" \
45 	"Use is subject to license terms.\n"
46 
47 /*
48  * flag values
49  */
50 #define	OPT_VALUE_LIST		0x0001
51 #define	OPT_IP_RANGE		0x0002
52 #define	OPT_PORTS		0x0004
53 #define	OPT_PORTS_ONLY		0x0008
54 #define	OPT_NAT			0x0010
55 #define	OPT_NUMERIC_ONLY	0x0020
56 
57 #define	ILBD_BAD_VAL	(-1)
58 
59 #define	ILBADM_LIST_FULL	0x0001
60 #define	ILBADM_LIST_PARSE	0x0002
61 #define	ILBADM_LIST_ENABLED	0x0004
62 #define	ILBADM_LIST_NOENABLED	(~ILBADM_LIST_ENABLED)
63 #define	ILBADM_LIST_DISABLED	0x0008
64 #define	ILBADM_LIST_NODISABLED	(~ILBADM_LIST_DISABLED)
65 
66 #define	ILBADM_IMPORT_PRESERVE	0x1000
67 
68 #define	V6_ADDRONLY	0x1	/* don't print surrounding "[]"s */
69 
70 #define	ILB_SRVID_SZ	(ILB_NAMESZ - 5)
71 #define	ILBD_NAMESZ	ILB_NAMESZ
72 
73 #define	ILB_MAX_PORT	UINT16_MAX
74 
75 typedef enum {
76 	ILBADM_OK = 0,
77 	ILBADM_ASSIGNREQ,	/* assignment '=' required */
78 	ILBADM_EINVAL,		/* invalid value */
79 	ILBADM_ENOMEM,		/* malloc failed */
80 	ILBADM_ENOOPTION,	/* mandatory option missing */
81 	ILBADM_ENOPROTO,	/* protocol not found in database */
82 	ILBADM_ENOPROXY,	/* proxy-src is missing */
83 	ILBADM_ENOSERVICE,	/* servicename not found in database */
84 	ILBADM_ENOSGNAME,	/* servergroup name missing */
85 	ILBADM_ENORULE,		/* rulename missing or no such rule */
86 	ILBADM_ENOSERVER,	/* rulename missing or no such rule */
87 	ILBADM_EXPORTFAIL,	/* too little space to do export servergroup */
88 	ILBADM_FAIL,		/* processing of command failed */
89 	ILBADM_HCPRINT,		/* failed to print healthcheck */
90 	ILBADM_INVAL_ADDR,	/* invalid address */
91 	ILBADM_INVAL_AF,	/* invalid address family */
92 	ILBADM_INVAL_ALG,	/* LB algorithm failure */
93 	ILBADM_INVAL_ARGS,	/* invalid arguments to command */
94 	ILBADM_INVAL_COMMAND,	/* invalid command */
95 	ILBADM_INVAL_KEYWORD,	/* invalid keyword */
96 	ILBADM_INVAL_OPER,	/* invalid operation type */
97 	ILBADM_INVAL_PORT,	/* invalid value specified for port */
98 	ILBADM_INVAL_PROXY,	/* proxy-src not allowed   */
99 	ILBADM_INVAL_SYNTAX,	/* syntax error */
100 	ILBADM_INVAL_SRVID,	/* server id is invalid (missing "_" ?) */
101 	ILBADM_LIBERR,		/* translation of libilb errors. We also */
102 				/* set it in ilbadm fuctions to indicate */
103 				/* printing of non-generic error messages */
104 	ILBADM_NORECURSIVE,	/* recursive import not allowed */
105 	ILBADM_TOOMANYIPADDR,	/* too many addresses */
106 	ILBADM_NOKEYWORD_VAL	/* no value specified for a keyword */
107 } ilbadm_status_t;
108 
109 
110 typedef enum {
111 	ILB_KEY_BAD = -1,
112 	ILB_KEY_SERVER,
113 	ILB_KEY_SERVRANGE,	/* pseudo-key for SG creation */
114 	ILB_KEY_SERVERID,
115 	ILB_KEY_VIP,
116 	ILB_KEY_PORT,
117 	ILB_KEY_PROTOCOL,
118 	ILB_KEY_IPVERSION,
119 	ILB_KEY_ALGORITHM,
120 	ILB_KEY_TYPE,
121 	ILB_KEY_SERVERGROUP,
122 	ILB_KEY_HEALTHCHECK,
123 	ILB_KEY_HCPORT,
124 	ILB_KEY_SRC,
125 	ILB_KEY_STICKY,
126 	ILB_KEY_CONNDRAIN,	/* otional timers ... */
127 	ILB_KEY_NAT_TO,
128 	ILB_KEY_STICKY_TO,
129 	ILB_KEY_HC_TEST,
130 	ILB_KEY_HC_COUNT,
131 	ILB_KEY_HC_INTERVAL,
132 	ILB_KEY_HC_TIMEOUT
133 } ilbadm_key_code_t;
134 
135 /*
136  * we need a few codes for commands, can't use libilb ones
137  */
138 typedef enum {
139 	cmd_create_sg,
140 	cmd_add_srv,
141 	cmd_rem_srv,
142 	cmd_enable_rule,
143 	cmd_disable_rule,
144 	cmd_enable_server,
145 	cmd_disable_server
146 } ilbadm_cmd_t;
147 
148 /* filched from snoop_ether.c */
149 typedef struct val_type {
150 	int	v_type;
151 	char	v_name[20];
152 	char 	v_alias[8];	/* undocumented */
153 } ilbadm_val_type_t;
154 
155 typedef struct key_names {
156 	ilbadm_key_code_t	k_key;
157 	char		k_name[20];
158 	char		k_alias[12];	/* undocumented */
159 } ilbadm_key_name_t;
160 
161 typedef struct servnode {
162 	list_node_t	s_link;
163 	ilb_server_data_t	s_spec;
164 } ilbadm_servnode_t;
165 
166 typedef struct sgroup {
167 	list_t		sg_serv_list;	/* list of servnode_t elements */
168 	int		sg_count;
169 	char 		*sg_name;
170 } ilbadm_sgroup_t;
171 
172 typedef	struct cmd_hlp {
173 	char	*h_help;
174 } ilbadm_cmd_help_t;
175 
176 typedef ilbadm_status_t	(* cmdfunc_t)(int, char **);
177 
178 typedef struct cmd_names {
179 	char		c_name[25];
180 	char		c_alias[20];	/* undocumented */
181 	cmdfunc_t	c_action;
182 	ilbadm_cmd_help_t	*c_help;	/* for "usage" */
183 } ilbadm_cmd_desc_t;
184 
185 ilbadm_status_t	ilbadm_add_server_to_group(int, char **);
186 ilbadm_status_t	ilbadm_create_servergroup(int, char **);
187 ilbadm_status_t	ilbadm_destroy_servergroup(int, char **);
188 ilbadm_status_t	ilbadm_rem_server_from_group(int, char **);
189 
190 ilbadm_status_t	ilbadm_create_rule(int, char **);
191 ilbadm_status_t	ilbadm_destroy_rule(int, char **);
192 ilbadm_status_t	ilbadm_enable_rule(int, char **);
193 ilbadm_status_t	ilbadm_disable_rule(int, char **);
194 ilbadm_status_t	ilbadm_show_server(int, char **);
195 ilbadm_status_t	ilbadm_enable_server(int, char **);
196 ilbadm_status_t	ilbadm_disable_server(int, char **);
197 
198 ilbadm_status_t	ilbadm_show_servergroups(int, char **);
199 ilbadm_status_t	ilbadm_show_rules(int, char **);
200 ilbadm_status_t	ilbadm_show_stats(int, char **);
201 
202 ilbadm_status_t	ilbadm_create_hc(int, char **);
203 ilbadm_status_t	ilbadm_destroy_hc(int, char **);
204 ilbadm_status_t	ilbadm_show_hc(int, char **);
205 ilbadm_status_t	ilbadm_show_hc_result(int, char **);
206 
207 ilbadm_status_t	ilbadm_noimport(int, char **);
208 
209 ilbadm_status_t	ilbadm_show_nat(int, char **);
210 ilbadm_status_t	ilbadm_show_persist(int, char **);
211 
212 ilbadm_status_t	i_parse_optstring(char *, void *, ilbadm_key_name_t *,
213     int, int *);
214 ilbadm_servnode_t	*i_new_sg_elem(ilbadm_sgroup_t *);
215 ilbadm_status_t	ilbadm_import(int, int, char *[], int);
216 ilbadm_status_t	ilbadm_export(int, char *[]);
217 ilbadm_status_t	ilbadm_export_servergroups(ilb_handle_t h, FILE *);
218 ilbadm_status_t	ilbadm_export_hc(ilb_handle_t h, FILE *);
219 ilbadm_status_t	ilbadm_export_rules(ilb_handle_t h, FILE *);
220 
221 ilbadm_status_t	i_check_rule_spec(ilb_rule_data_t *);
222 ilbadm_status_t ilbadm_set_netmask(char *, ilb_ip_addr_t *, int);
223 int		ilbadm_mask_to_prefixlen(ilb_ip_addr_t *);
224 
225 void		print_cmdlist_short(char *, FILE *);
226 extern int	ilb_cmp_ipaddr(ilb_ip_addr_t *, ilb_ip_addr_t *,
227     longlong_t *);
228 
229 void	ip2str(ilb_ip_addr_t *, char *, size_t, int);
230 char	*i_str_from_val(int, ilbadm_val_type_t *);
231 char	*ilbadm_key_to_opt(ilbadm_key_code_t);
232 
233 void	Usage(char *);
234 void	unknown_opt(char **, int);
235 const char	*ilbadm_errstr(ilbadm_status_t);
236 void	ilbadm_err(const char *format, ...);
237 
238 #ifdef	__cplusplus
239 }
240 #endif
241 
242 #endif /* _ILBADM_H */
243