xref: /titanic_44/usr/src/uts/common/inet/ipf/ipf.h (revision 60972f37b111e11c7b4abcfc08e54c7839fe5e63)
1 /*
2  * Copyright (C) 1993-2001, 2003 by Darren Reed.
3  *
4  * See the IPFILTER.LICENCE file for details on licencing.
5  *
6  * @(#)ipf.h	1.12 6/5/96
7  * $Id: ipf.h,v 2.71.2.7 2005/06/12 07:18:31 darrenr Exp $
8  *
9  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
10  * Use is subject to license terms.
11  */
12 
13 #ifndef	__IPF_H__
14 #define	__IPF_H__
15 
16 #pragma ident	"%Z%%M%	%I%	%E% SMI"
17 
18 #if defined(__osf__)
19 # define radix_mask ipf_radix_mask
20 # define radix_node ipf_radix_node
21 # define radix_node_head ipf_radix_node_head
22 #endif
23 
24 #include <sys/param.h>
25 #include <sys/types.h>
26 #include <sys/file.h>
27 /*
28  * This is a workaround for <sys/uio.h> troubles on FreeBSD, HPUX, OpenBSD.
29  * Needed here because on some systems <sys/uio.h> gets included by things
30  * like <sys/socket.h>
31  */
32 #ifndef _KERNEL
33 # define ADD_KERNEL
34 # define _KERNEL
35 # define KERNEL
36 #endif
37 #ifdef __OpenBSD__
38 struct file;
39 #endif
40 #include <sys/uio.h>
41 #ifdef ADD_KERNEL
42 # undef _KERNEL
43 # undef KERNEL
44 #endif
45 #include <sys/time.h>
46 #include <sys/socket.h>
47 #include <net/if.h>
48 #if __FreeBSD_version >= 300000
49 # include <net/if_var.h>
50 #endif
51 #include <netinet/in.h>
52 #include <netinet/in_systm.h>
53 #include <netinet/ip.h>
54 #include <netinet/ip_icmp.h>
55 #ifndef	TCP_PAWS_IDLE	/* IRIX */
56 # include <netinet/tcp.h>
57 #endif
58 #include <netinet/udp.h>
59 
60 #include <arpa/inet.h>
61 
62 #include <errno.h>
63 #include <limits.h>
64 #include <netdb.h>
65 #include <stdlib.h>
66 #include <stddef.h>
67 #include <stdio.h>
68 #if !defined(__SVR4) && !defined(__svr4__) && defined(sun)
69 # include <strings.h>
70 #endif
71 #include <string.h>
72 #include <unistd.h>
73 
74 #include "netinet/ipf_stack.h"
75 #include "netinet/ip_compat.h"
76 #include "netinet/ip_fil.h"
77 #include "netinet/ip_nat.h"
78 #include "netinet/ip_frag.h"
79 #include "netinet/ip_state.h"
80 #include "netinet/ip_proxy.h"
81 #include "netinet/ip_auth.h"
82 #include "netinet/ip_lookup.h"
83 #include "netinet/ip_pool.h"
84 #ifdef IPFILTER_SCAN
85 #include "netinet/ip_scan.h"
86 #endif
87 #include "netinet/ip_htable.h"
88 #ifdef IPFILTER_SYNC
89 #include "netinet/ip_sync.h"
90 #endif
91 
92 #include "opts.h"
93 
94 #ifndef __P
95 # ifdef __STDC__
96 #  define	__P(x)	x
97 # else
98 #  define	__P(x)	()
99 # endif
100 #endif
101 #ifndef __STDC__
102 # undef		const
103 # define	const
104 #endif
105 
106 #ifndef	U_32_T
107 # define	U_32_T	1
108 # if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) || \
109     defined(__sgi)
110 typedef	u_int32_t	u_32_t;
111 # else
112 #  if defined(__alpha__) || defined(__alpha) || defined(_LP64)
113 typedef unsigned int	u_32_t;
114 #  else
115 #   if SOLARIS2 >= 6
116 typedef uint32_t	u_32_t;
117 #   else
118 typedef unsigned int	u_32_t;
119 #   endif
120 #  endif
121 # endif /* __NetBSD__ || __OpenBSD__ || __FreeBSD__ || __sgi */
122 #endif /* U_32_T */
123 
124 #ifndef	MAXHOSTNAMELEN
125 # define	MAXHOSTNAMELEN	256
126 #endif
127 
128 #define	MAX_ICMPCODE	16
129 #define	MAX_ICMPTYPE	19
130 
131 
132 struct	ipopt_names	{
133 	int	on_value;
134 	int	on_bit;
135 	int	on_siz;
136 	char	*on_name;
137 };
138 
139 
140 typedef struct  alist_s {
141 	struct	alist_s	*al_next;
142 	int		al_not;
143 	sa_family_t	al_family;
144 	i6addr_t	al_i6addr;
145 	i6addr_t	al_i6mask;
146 } alist_t;
147 
148 #define	al_addr	al_i6addr.in4_addr
149 #define	al_mask	al_i6mask.in4_addr
150 #define	al_1	al_addr
151 #define	al_2	al_mask
152 
153 
154 typedef	struct	{
155 	u_short	fb_c;
156 	u_char	fb_t;
157 	u_char	fb_f;
158 	u_32_t	fb_k;
159 } fakebpf_t;
160 
161 
162 #if defined(__NetBSD__) || defined(__OpenBSD__) || \
163         (_BSDI_VERSION >= 199701) || (__FreeBSD_version >= 300000) || \
164 	SOLARIS || defined(__sgi) || defined(__osf__) || defined(linux)
165 # include <stdarg.h>
166 typedef	int	(* ioctlfunc_t) __P((int, ioctlcmd_t, ...));
167 #else
168 typedef	int	(* ioctlfunc_t) __P((dev_t, ioctlcmd_t, void *));
169 #endif
170 typedef	void	(* addfunc_t) __P((int, ioctlfunc_t, void *));
171 typedef	int	(* copyfunc_t) __P((void *, void *, size_t));
172 
173 
174 /*
175  * SunOS4
176  */
177 #if defined(sun) && !defined(__SVR4) && !defined(__svr4__)
178 extern	int	ioctl __P((int, int, void *));
179 #endif
180 
181 extern	char	thishost[];
182 extern	char	flagset[];
183 extern	u_char	flags[];
184 extern	struct ipopt_names ionames[];
185 extern	struct ipopt_names secclass[];
186 extern	char	*icmpcodes[MAX_ICMPCODE + 1];
187 extern	char	*icmptypes[MAX_ICMPTYPE + 1];
188 extern	int	use_inet6;
189 extern	int	lineNum;
190 extern	struct ipopt_names v6ionames[];
191 
192 
193 extern int addicmp __P((char ***, struct frentry *, int));
194 extern int addipopt __P((char *, struct ipopt_names *, int, char *));
195 extern int addkeep __P((char ***, struct frentry *, int));
196 extern int bcopywrap __P((void *, void *, size_t));
197 extern void binprint __P((void *, size_t));
198 extern void initparse __P((void));
199 extern u_32_t buildopts __P((char *, char *, int));
200 extern int checkrev __P((char *));
201 extern int count6bits __P((u_32_t *));
202 extern int count4bits __P((u_32_t));
203 extern int extras __P((char ***, struct frentry *, int));
204 extern char *fac_toname __P((int));
205 extern int fac_findname __P((char *));
206 extern void fill6bits __P((int, u_int *));
207 extern int gethost __P((char *, i6addr_t *, int));
208 extern int getport __P((struct frentry *, char *, u_short *));
209 extern int getportproto __P((char *, int));
210 extern int getproto __P((char *));
211 extern char *getline __P((char *, size_t, FILE *, int *));
212 extern int genmask __P((char *, u_32_t *));
213 extern char *getnattype __P((struct nat *, int));
214 extern char *getsumd __P((u_32_t));
215 extern u_32_t getoptbyname __P((char *));
216 extern u_32_t getoptbyvalue __P((int));
217 extern u_32_t getv6optbyname __P((char *));
218 extern u_32_t getv6optbyvalue __P((int));
219 extern void hexdump __P((FILE *, void *, int, int));
220 extern int icmpcode __P((char *));
221 extern void initparse __P((void));
222 extern void ipf_dotuning __P((int, char *, ioctlfunc_t));
223 extern void ipf_addrule __P((int, ioctlfunc_t, void *));
224 extern int ipf_parsefile __P((int, addfunc_t, ioctlfunc_t *, char *));
225 extern int ipf_parsesome __P((int, addfunc_t, ioctlfunc_t *, FILE *));
226 extern int ipmon_parsefile __P((char *));
227 extern int ipmon_parsesome __P((FILE *));
228 extern void ipnat_addrule __P((int, ioctlfunc_t, void *));
229 extern int ipnat_parsefile __P((int, addfunc_t, ioctlfunc_t, char *));
230 extern int ipnat_parsesome __P((int, addfunc_t, ioctlfunc_t, FILE *));
231 extern int ippool_parsefile __P((int, char *, ioctlfunc_t));
232 extern int ippool_parsesome __P((int, FILE *, ioctlfunc_t));
233 extern int kmemcpywrap __P((void *, void *, size_t));
234 extern char *kvatoname __P((ipfunc_t, ioctlfunc_t));
235 extern int load_hash __P((struct iphtable_s *, struct iphtent_s *,
236 			  ioctlfunc_t));
237 extern int load_hashnode __P((int, char *, struct iphtent_s *, ioctlfunc_t));
238 extern int load_pool __P((struct ip_pool_s *list, ioctlfunc_t));
239 extern int load_poolnode __P((int, char *, ip_pool_node_t *, ioctlfunc_t));
240 extern int loglevel __P((char **, u_int *, int));
241 extern alist_t *make_range __P((int, struct in_addr, struct in_addr));
242 extern ipfunc_t nametokva __P((char *, ioctlfunc_t));
243 extern void nat_setgroupmap __P((struct ipnat *));
244 extern int ntomask __P((int, int, u_32_t *));
245 extern u_32_t optname __P((char ***, u_short *, int));
246 extern struct frentry *parse __P((char *, int));
247 extern char *portname __P((int, int));
248 extern int portnum __P((char *, char *, u_short *, int));
249 extern int ports __P((char ***, char *, u_short *, int *, u_short *, int));
250 extern int pri_findname __P((char *));
251 extern char *pri_toname __P((int));
252 extern void print_toif __P((char *, struct frdest *));
253 extern void printaps __P((ap_session_t *, int));
254 extern void printbuf __P((char *, int, int));
255 extern void printfr __P((struct frentry *, ioctlfunc_t));
256 extern struct iphtable_s *printhash_live __P((struct iphtable_s *, int, char*, int));
257 extern void printhashdata __P((struct iphtable_s *, int));
258 extern void printtunable __P((ipftune_t *));
259 extern struct iphtable_s *printhash __P((struct iphtable_s *, copyfunc_t,
260 					 char *, int));
261 extern struct iphtent_s *printhashnode __P((struct iphtable_s *,
262 					    struct iphtent_s *,
263 					    copyfunc_t, int));
264 extern void printhostmask __P((int, u_32_t *, u_32_t *));
265 extern void printip __P((u_32_t *));
266 extern void printlog __P((struct frentry *));
267 extern void printlookup __P((i6addr_t *addr, i6addr_t *mask));
268 extern void printmask __P((int, u_32_t *));
269 extern void printpacket __P((struct ip *));
270 extern void printpacket6 __P((struct ip *));
271 extern struct ip_pool_s *printpool __P((struct ip_pool_s *, copyfunc_t,
272 					char *, int));
273 extern struct ip_pool_s *printpool_live __P((struct ip_pool_s *, int, char*, int));
274 extern void printpooldata __P((struct ip_pool_s *, int));
275 extern struct ip_pool_node *printpoolnode __P((struct ip_pool_node *, int));
276 extern void printproto __P((struct protoent *, int, struct ipnat *));
277 extern void printportcmp __P((int, struct frpcmp *));
278 extern void optprint __P((u_short *, u_long, u_long));
279 #ifdef	USE_INET6
280 extern void optprintv6 __P((u_short *, u_long, u_long));
281 #endif
282 extern int ratoi __P((char *, int *, int, int));
283 extern int ratoui __P((char *, u_int *, u_int, u_int));
284 extern int remove_hash __P((struct iphtable_s *, ioctlfunc_t));
285 extern int remove_hashnode __P((int, char *, struct iphtent_s *, ioctlfunc_t));
286 extern int remove_pool __P((ip_pool_t *, ioctlfunc_t));
287 extern int remove_poolnode __P((int, char *, ip_pool_node_t *, ioctlfunc_t));
288 extern u_char tcp_flags __P((char *, u_char *, int));
289 extern u_char tcpflags __P((char *));
290 extern void printc __P((struct frentry *));
291 extern void printC __P((int));
292 extern void emit __P((int, int, void *, struct frentry *));
293 extern u_char secbit __P((int));
294 extern u_char seclevel __P((char *));
295 extern void printfraginfo __P((char *, struct ipfr *));
296 extern void printifname __P((char *, char *, void *));
297 extern char *hostname __P((int, void *));
298 extern struct ipstate *printstate __P((struct ipstate *, int, u_long));
299 extern void printsbuf __P((char *));
300 extern void printnat __P((struct ipnat *, int));
301 extern void printactivenat __P((struct nat *, int, int));
302 extern void printhostmap __P((struct hostmap *, u_int));
303 extern void printpacket __P((struct ip *));
304 
305 extern void set_variable __P((char *, char *));
306 extern char *get_variable __P((char *, char **, int));
307 extern void resetlexer __P((void));
308 
309 #if SOLARIS
310 extern int gethostname __P((char *, int ));
311 extern void sync __P((void));
312 #endif
313 
314 #endif /* __IPF_H__ */
315