]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/ipfilter/ipf.h
bhyvectl(8): Normalize the man page date
[FreeBSD/FreeBSD.git] / contrib / ipfilter / ipf.h
1 /*      $FreeBSD$       */
2
3 /*
4  * Copyright (C) 2012 by Darren Reed.
5  *
6  * See the IPFILTER.LICENCE file for details on licencing.
7  *
8  * @(#)ipf.h    1.12 6/5/96
9  * $Id$
10  */
11
12 #ifndef __IPF_H__
13 #define __IPF_H__
14
15
16 #include <sys/param.h>
17 #include <sys/types.h>
18 #include <sys/file.h>
19 /*
20  * This is a workaround for <sys/uio.h> troubles on FreeBSD, HPUX, OpenBSD.
21  * Needed here because on some systems <sys/uio.h> gets included by things
22  * like <sys/socket.h>
23  */
24 #ifndef _KERNEL
25 # define ADD_KERNEL
26 # define _KERNEL
27 # define KERNEL
28 #endif
29 #include <sys/uio.h>
30 #ifdef ADD_KERNEL
31 # undef _KERNEL
32 # undef KERNEL
33 #endif
34 #include <sys/time.h>
35 #include <sys/socket.h>
36 #include <net/if.h>
37
38 #include <netinet/in.h>
39 #include <netinet/in_systm.h>
40 #include <netinet/ip.h>
41 #include <netinet/ip_icmp.h>
42 # include <netinet/tcp.h>
43 #include <netinet/udp.h>
44
45 #include <arpa/inet.h>
46
47 #include <errno.h>
48 #include <limits.h>
49 #include <netdb.h>
50 #include <stdlib.h>
51 #include <stddef.h>
52 #include <stdio.h>
53 #if !defined(__SVR4) && !defined(__svr4__) && defined(sun)
54 # include <strings.h>
55 #endif
56 #include <string.h>
57 #include <unistd.h>
58
59 #include "netinet/ip_compat.h"
60 #include "netinet/ip_fil.h"
61 #include "netinet/ip_nat.h"
62 #include "netinet/ip_frag.h"
63 #include "netinet/ip_state.h"
64 #include "netinet/ip_proxy.h"
65 #include "netinet/ip_auth.h"
66 #include "netinet/ip_lookup.h"
67 #include "netinet/ip_pool.h"
68 #include "netinet/ip_scan.h"
69 #include "netinet/ip_htable.h"
70 #include "netinet/ip_sync.h"
71 #include "netinet/ip_dstlist.h"
72
73 #include "opts.h"
74
75 #ifndef __P
76 # ifdef __STDC__
77 #  define       __P(x)  x
78 # else
79 #  define       __P(x)  ()
80 # endif
81 #endif
82 #ifndef __STDC__
83 # undef         const
84 # define        const
85 #endif
86
87 #ifndef U_32_T
88 # define        U_32_T  1
89 # if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) || \
90     defined(__sgi)
91 typedef u_int32_t       u_32_t;
92 # else
93 #  if defined(__alpha__) || defined(__alpha) || defined(_LP64)
94 typedef unsigned int    u_32_t;
95 #  else
96 #   if SOLARIS2 >= 6
97 typedef uint32_t        u_32_t;
98 #   else
99 typedef unsigned int    u_32_t;
100 #   endif
101 #  endif
102 # endif /* __NetBSD__ || __OpenBSD__ || __FreeBSD__ || __sgi */
103 #endif /* U_32_T */
104
105 #ifndef MAXHOSTNAMELEN
106 # define        MAXHOSTNAMELEN  256
107 #endif
108
109 #define MAX_ICMPCODE    16
110 #define MAX_ICMPTYPE    19
111
112 #define PRINTF  (void)printf
113 #define FPRINTF (void)fprintf
114
115
116 struct  ipopt_names     {
117         int     on_value;
118         int     on_bit;
119         int     on_siz;
120         char    *on_name;
121 };
122
123
124 typedef struct  alist_s {
125         struct  alist_s *al_next;
126         int             al_not;
127         int             al_family;
128         i6addr_t        al_i6addr;
129         i6addr_t        al_i6mask;
130 } alist_t;
131
132 #define al_addr al_i6addr.in4_addr
133 #define al_mask al_i6mask.in4_addr
134 #define al_1    al_addr
135 #define al_2    al_mask
136
137
138 typedef struct  plist_s {
139         struct  plist_s *pl_next;
140         int             pl_compare;
141         u_short         pl_port1;
142         u_short         pl_port2;
143 } plist_t;
144
145
146 typedef struct  {
147         u_short fb_c;
148         u_char  fb_t;
149         u_char  fb_f;
150         u_32_t  fb_k;
151 } fakebpf_t;
152
153
154 typedef struct  {
155         char    *it_name;
156         int     it_v4;
157         int     it_v6;
158 } icmptype_t;
159
160
161 typedef struct  wordtab {
162         char    *w_word;
163         int     w_value;
164 } wordtab_t;
165
166
167 typedef struct  namelist {
168         struct namelist *na_next;
169         char            *na_name;
170         int             na_value;
171 } namelist_t;
172
173
174 typedef struct  proxyrule {
175         struct  proxyrule       *pr_next;
176         char                    *pr_proxy;
177         char                    *pr_conf;
178         namelist_t              *pr_names;
179         int                     pr_proto;
180 } proxyrule_t;
181
182
183 #if defined(__NetBSD__) || defined(__FreeBSD_version) || \
184         SOLARIS
185 # include <stdarg.h>
186 typedef int     (* ioctlfunc_t) __P((int, ioctlcmd_t, ...));
187 #else
188 typedef int     (* ioctlfunc_t) __P((dev_t, ioctlcmd_t, void *));
189 #endif
190 typedef int     (* addfunc_t) __P((int, ioctlfunc_t, void *));
191 typedef int     (* copyfunc_t) __P((void *, void *, size_t));
192
193
194 extern  char    thishost[MAXHOSTNAMELEN];
195 extern  char    flagset[];
196 extern  u_char  flags[];
197 extern  struct ipopt_names ionames[];
198 extern  struct ipopt_names secclass[];
199 extern  char    *icmpcodes[MAX_ICMPCODE + 1];
200 extern  char    *icmptypes[MAX_ICMPTYPE + 1];
201 extern  int     use_inet6;
202 extern  int     lineNum;
203 extern  int     debuglevel;
204 extern  struct ipopt_names v6ionames[];
205 extern  icmptype_t icmptypelist[];
206 extern  wordtab_t statefields[];
207 extern  wordtab_t natfields[];
208 extern  wordtab_t poolfields[];
209
210
211 extern int addicmp __P((char ***, struct frentry *, int));
212 extern int addipopt __P((char *, struct ipopt_names *, int, char *));
213 extern int addkeep __P((char ***, struct frentry *, int));
214 extern alist_t *alist_new __P((int, char *));
215 extern void alist_free __P((alist_t *));
216 extern void assigndefined __P((char *));
217 extern void binprint __P((void *, size_t));
218 extern u_32_t buildopts __P((char *, char *, int));
219 extern int checkrev __P((char *));
220 extern int connecttcp __P((char *, int));
221 extern int count6bits __P((u_32_t *));
222 extern int count4bits __P((u_32_t));
223 extern char *fac_toname __P((int));
224 extern int fac_findname __P((char *));
225 extern const char *familyname __P((const int));
226 extern void fill6bits __P((int, u_int *));
227 extern wordtab_t *findword __P((wordtab_t *, char *));
228 extern int ftov __P((int));
229 extern char *ipf_geterror __P((int, ioctlfunc_t *));
230 extern int genmask __P((int, char *, i6addr_t *));
231 extern int gethost __P((int, char *, i6addr_t *));
232 extern int geticmptype __P((int, char *));
233 extern int getport __P((struct frentry *, char *, u_short *, char *));
234 extern int getportproto __P((char *, int));
235 extern int getproto __P((char *));
236 extern char *getnattype __P((struct nat *));
237 extern char *getsumd __P((u_32_t));
238 extern u_32_t getoptbyname __P((char *));
239 extern u_32_t getoptbyvalue __P((int));
240 extern u_32_t getv6optbyname __P((char *));
241 extern u_32_t getv6optbyvalue __P((int));
242 extern char *icmptypename __P((int, int));
243 extern void initparse __P((void));
244 extern void ipf_dotuning __P((int, char *, ioctlfunc_t));
245 extern int ipf_addrule __P((int, ioctlfunc_t, void *));
246 extern void ipf_mutex_clean __P((void));
247 extern int ipf_parsefile __P((int, addfunc_t, ioctlfunc_t *, char *));
248 extern int ipf_parsesome __P((int, addfunc_t, ioctlfunc_t *, FILE *));
249 extern void ipf_perror __P((int, char *));
250 extern int ipf_perror_fd __P(( int, ioctlfunc_t, char *));
251 extern void ipf_rwlock_clean __P((void));
252 extern char *ipf_strerror __P((int));
253 extern void ipferror __P((int, char *));
254 extern int ipmon_parsefile __P((char *));
255 extern int ipmon_parsesome __P((FILE *));
256 extern int ipnat_addrule __P((int, ioctlfunc_t, void *));
257 extern int ipnat_parsefile __P((int, addfunc_t, ioctlfunc_t, char *));
258 extern int ipnat_parsesome __P((int, addfunc_t, ioctlfunc_t, FILE *));
259 extern int ippool_parsefile __P((int, char *, ioctlfunc_t));
260 extern int ippool_parsesome __P((int, FILE *, ioctlfunc_t));
261 extern int kmemcpywrap __P((void *, void *, size_t));
262 extern char *kvatoname __P((ipfunc_t, ioctlfunc_t));
263 extern int load_dstlist __P((struct ippool_dst *, ioctlfunc_t,
264                              ipf_dstnode_t *));
265 extern int load_dstlistnode __P((int, char *, struct ipf_dstnode *,
266                                  ioctlfunc_t));
267 extern alist_t *load_file __P((char *));
268 extern int load_hash __P((struct iphtable_s *, struct iphtent_s *,
269                           ioctlfunc_t));
270 extern int load_hashnode __P((int, char *, struct iphtent_s *, int,
271                               ioctlfunc_t));
272 extern alist_t *load_http __P((char *));
273 extern int load_pool __P((struct ip_pool_s *list, ioctlfunc_t));
274 extern int load_poolnode __P((int, char *, ip_pool_node_t *, int, ioctlfunc_t));
275 extern alist_t *load_url __P((char *));
276 extern alist_t *make_range __P((int, struct in_addr, struct in_addr));
277 extern void mb_hexdump __P((mb_t *, FILE *));
278 extern ipfunc_t nametokva __P((char *, ioctlfunc_t));
279 extern void nat_setgroupmap __P((struct ipnat *));
280 extern int ntomask __P((int, int, u_32_t *));
281 extern u_32_t optname __P((char ***, u_short *, int));
282 extern wordtab_t *parsefields __P((wordtab_t *, char *));
283 extern int *parseipfexpr __P((char *, char **));
284 extern int parsewhoisline __P((char *, addrfamily_t *, addrfamily_t *));
285 extern void pool_close __P((void));
286 extern int pool_fd __P((void));
287 extern int pool_ioctl __P((ioctlfunc_t, ioctlcmd_t, void *));
288 extern int pool_open __P((void));
289 extern char *portname __P((int, int));
290 extern int pri_findname __P((char *));
291 extern char *pri_toname __P((int));
292 extern void print_toif __P((int, char *, char *, struct frdest *));
293 extern void printaps __P((ap_session_t *, int, int));
294 extern void printaddr __P((int, int, char *, int, u_32_t *, u_32_t *));
295 extern void printbuf __P((char *, int, int));
296 extern void printfieldhdr __P((wordtab_t *, wordtab_t *));
297 extern void printfr __P((struct frentry *, ioctlfunc_t));
298 extern struct iphtable_s *printhash __P((struct iphtable_s *, copyfunc_t,
299                                          char *, int, wordtab_t *));
300 extern struct iphtable_s *printhash_live __P((iphtable_t *, int, char *,
301                                               int, wordtab_t *));
302 extern ippool_dst_t *printdstl_live __P((ippool_dst_t *, int, char *,
303                                          int, wordtab_t *));
304 extern void printhashdata __P((iphtable_t *, int));
305 extern struct iphtent_s *printhashnode __P((struct iphtable_s *,
306                                             struct iphtent_s *,
307                                             copyfunc_t, int, wordtab_t *));
308 extern void printhost __P((int, u_32_t *));
309 extern void printhostmask __P((int, u_32_t *, u_32_t *));
310 extern void printip __P((int, u_32_t *));
311 extern void printlog __P((struct frentry *));
312 extern void printlookup __P((char *, i6addr_t *addr, i6addr_t *mask));
313 extern void printmask __P((int, u_32_t *));
314 extern void printnataddr __P((int, char *, nat_addr_t *, int));
315 extern void printnatfield __P((nat_t *, int));
316 extern void printnatside __P((char *, nat_stat_side_t *));
317 extern void printpacket __P((int, mb_t *));
318 extern void printpacket6 __P((int, mb_t *));
319 extern struct ippool_dst *printdstlist __P((struct ippool_dst *, copyfunc_t,
320                                             char *, int, ipf_dstnode_t *,
321                                             wordtab_t *));
322 extern void printdstlistdata __P((ippool_dst_t *, int));
323 extern ipf_dstnode_t *printdstlistnode __P((ipf_dstnode_t *, copyfunc_t,
324                                             int, wordtab_t *));
325 extern void printdstlistpolicy __P((ippool_policy_t));
326 extern struct ip_pool_s *printpool __P((struct ip_pool_s *, copyfunc_t,
327                                         char *, int, wordtab_t *));
328 extern struct ip_pool_s *printpool_live __P((struct ip_pool_s *, int,
329                                              char *, int, wordtab_t *));
330 extern void printpooldata __P((ip_pool_t *, int));
331 extern void printpoolfield __P((void *, int, int));
332 extern struct ip_pool_node *printpoolnode __P((struct ip_pool_node *,
333                                                int, wordtab_t *));
334 extern void printproto __P((struct protoent *, int, struct ipnat *));
335 extern void printportcmp __P((int, struct frpcmp *));
336 extern void printstatefield __P((ipstate_t *, int));
337 extern void printtqtable __P((ipftq_t *));
338 extern void printtunable __P((ipftune_t *));
339 extern void printunit __P((int));
340 extern void optprint __P((u_short *, u_long, u_long));
341 #ifdef  USE_INET6
342 extern void optprintv6 __P((u_short *, u_long, u_long));
343 #endif
344 extern int remove_hash __P((struct iphtable_s *, ioctlfunc_t));
345 extern int remove_hashnode __P((int, char *, struct iphtent_s *, ioctlfunc_t));
346 extern int remove_pool __P((ip_pool_t *, ioctlfunc_t));
347 extern int remove_poolnode __P((int, char *, ip_pool_node_t *, ioctlfunc_t));
348 extern u_char tcpflags __P((char *));
349 extern void printc __P((struct frentry *));
350 extern void printC __P((int));
351 extern void emit __P((int, int, void *, struct frentry *));
352 extern u_char secbit __P((int));
353 extern u_char seclevel __P((char *));
354 extern void printfraginfo __P((char *, struct ipfr *));
355 extern void printifname __P((char *, char *, void *));
356 extern char *hostname __P((int, void *));
357 extern struct ipstate *printstate __P((struct ipstate *, int, u_long));
358 extern void printsbuf __P((char *));
359 extern void printnat __P((struct ipnat *, int));
360 extern void printactiveaddress __P((int, char *, i6addr_t *, char *));
361 extern void printactivenat __P((struct nat *, int, u_long));
362 extern void printhostmap __P((struct hostmap *, u_int));
363 extern void printtcpflags __P((u_32_t, u_32_t));
364 extern void printipfexpr __P((int *));
365 extern void printstatefield __P((ipstate_t *, int));
366 extern void printstatefieldhdr __P((int));
367 extern int sendtrap_v1_0 __P((int, char *, char *, int, time_t));
368 extern int sendtrap_v2_0 __P((int, char *, char *, int));
369 extern int vtof __P((int));
370
371 extern void set_variable __P((char *, char *));
372 extern char *get_variable __P((char *, char **, int));
373 extern void resetlexer __P((void));
374
375 extern void debug __P((int, char *, ...));
376 extern void verbose __P((int, char *, ...));
377 extern void ipfkdebug __P((char *, ...));
378 extern void ipfkverbose __P((char *, ...));
379
380 #if SOLARIS
381 extern int gethostname __P((char *, int ));
382 extern void sync __P((void));
383 #endif
384
385 #endif /* __IPF_H__ */