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