]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/ipfilter/ipf.h
Add UPDATING entries and bump version.
[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 #  define       __P(x)  x
77 #endif
78
79 #ifndef U_32_T
80 # define        U_32_T  1
81 # if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) || \
82     defined(__sgi)
83 typedef u_int32_t       u_32_t;
84 # else
85 #  if defined(__alpha__) || defined(__alpha) || defined(_LP64)
86 typedef unsigned int    u_32_t;
87 #  else
88 #   if SOLARIS2 >= 6
89 typedef uint32_t        u_32_t;
90 #   else
91 typedef unsigned int    u_32_t;
92 #   endif
93 #  endif
94 # endif /* __NetBSD__ || __OpenBSD__ || __FreeBSD__ || __sgi */
95 #endif /* U_32_T */
96
97 #ifndef MAXHOSTNAMELEN
98 # define        MAXHOSTNAMELEN  256
99 #endif
100
101 #define MAX_ICMPCODE    16
102 #define MAX_ICMPTYPE    19
103
104 #define PRINTF  (void)printf
105 #define FPRINTF (void)fprintf
106
107
108 struct  ipopt_names     {
109         int     on_value;
110         int     on_bit;
111         int     on_siz;
112         char    *on_name;
113 };
114
115
116 typedef struct  alist_s {
117         struct  alist_s *al_next;
118         int             al_not;
119         int             al_family;
120         i6addr_t        al_i6addr;
121         i6addr_t        al_i6mask;
122 } alist_t;
123
124 #define al_addr al_i6addr.in4_addr
125 #define al_mask al_i6mask.in4_addr
126 #define al_1    al_addr
127 #define al_2    al_mask
128
129
130 typedef struct  plist_s {
131         struct  plist_s *pl_next;
132         int             pl_compare;
133         u_short         pl_port1;
134         u_short         pl_port2;
135 } plist_t;
136
137
138 typedef struct  {
139         u_short fb_c;
140         u_char  fb_t;
141         u_char  fb_f;
142         u_32_t  fb_k;
143 } fakebpf_t;
144
145
146 typedef struct  {
147         char    *it_name;
148         int     it_v4;
149         int     it_v6;
150 } icmptype_t;
151
152
153 typedef struct  wordtab {
154         char    *w_word;
155         int     w_value;
156 } wordtab_t;
157
158
159 typedef struct  namelist {
160         struct namelist *na_next;
161         char            *na_name;
162         int             na_value;
163 } namelist_t;
164
165
166 typedef struct  proxyrule {
167         struct  proxyrule       *pr_next;
168         char                    *pr_proxy;
169         char                    *pr_conf;
170         namelist_t              *pr_names;
171         int                     pr_proto;
172 } proxyrule_t;
173
174
175 #if defined(__NetBSD__) || defined(__FreeBSD__) || \
176         SOLARIS
177 # include <stdarg.h>
178 typedef int     (* ioctlfunc_t)(int, ioctlcmd_t, ...);
179 #else
180 typedef int     (* ioctlfunc_t)(dev_t, ioctlcmd_t, void *);
181 #endif
182 typedef int     (* addfunc_t)(int, ioctlfunc_t, void *);
183 typedef int     (* copyfunc_t)(void *, void *, size_t);
184
185
186 extern  char    thishost[MAXHOSTNAMELEN];
187 extern  char    flagset[];
188 extern  u_char  flags[];
189 extern  struct ipopt_names ionames[];
190 extern  struct ipopt_names secclass[];
191 extern  char    *icmpcodes[MAX_ICMPCODE + 1];
192 extern  char    *icmptypes[MAX_ICMPTYPE + 1];
193 extern  int     use_inet6;
194 extern  int     lineNum;
195 extern  int     debuglevel;
196 extern  struct ipopt_names v6ionames[];
197 extern  icmptype_t icmptypelist[];
198 extern  wordtab_t statefields[];
199 extern  wordtab_t natfields[];
200 extern  wordtab_t poolfields[];
201
202
203 extern int addicmp(char ***, struct frentry *, int);
204 extern int addipopt(char *, struct ipopt_names *, int, char *);
205 extern int addkeep(char ***, struct frentry *, int);
206 extern alist_t *alist_new(int, char *);
207 extern void alist_free(alist_t *);
208 extern void assigndefined(char *);
209 extern void binprint(void *, size_t);
210 extern u_32_t buildopts(char *, char *, int);
211 extern int checkrev(char *);
212 extern int connecttcp(char *, int);
213 extern int count6bits(u_32_t *);
214 extern int count4bits(u_32_t);
215 extern char *fac_toname(int);
216 extern int fac_findname(char *);
217 extern const char *familyname(const int);
218 extern void fill6bits(int, u_int *);
219 extern wordtab_t *findword(wordtab_t *, char *);
220 extern int ftov(int);
221 extern char *ipf_geterror(int, ioctlfunc_t *);
222 extern int genmask(int, char *, i6addr_t *);
223 extern int gethost(int, char *, i6addr_t *);
224 extern int geticmptype(int, char *);
225 extern int getport(struct frentry *, char *, u_short *, char *);
226 extern int getportproto(char *, int);
227 extern int getproto(char *);
228 extern char *getnattype(struct nat *);
229 extern char *getsumd(u_32_t);
230 extern u_32_t getoptbyname(char *);
231 extern u_32_t getoptbyvalue(int);
232 extern u_32_t getv6optbyname(char *);
233 extern u_32_t getv6optbyvalue(int);
234 extern char *icmptypename(int, int);
235 extern void initparse(void);
236 extern void ipf_dotuning(int, char *, ioctlfunc_t);
237 extern int ipf_addrule(int, ioctlfunc_t, void *);
238 extern void ipf_mutex_clean(void);
239 extern int ipf_parsefile(int, addfunc_t, ioctlfunc_t *, char *);
240 extern int ipf_parsesome(int, addfunc_t, ioctlfunc_t *, FILE *);
241 extern void ipf_perror(int, char *);
242 extern int ipf_perror_fd( int, ioctlfunc_t, char *);
243 extern void ipf_rwlock_clean(void);
244 extern char *ipf_strerror(int);
245 extern void ipferror(int, char *);
246 extern int ipmon_parsefile(char *);
247 extern int ipmon_parsesome(FILE *);
248 extern int ipnat_addrule(int, ioctlfunc_t, void *);
249 extern int ipnat_parsefile(int, addfunc_t, ioctlfunc_t, char *);
250 extern int ipnat_parsesome(int, addfunc_t, ioctlfunc_t, FILE *);
251 extern int ippool_parsefile(int, char *, ioctlfunc_t);
252 extern int ippool_parsesome(int, FILE *, ioctlfunc_t);
253 extern int kmemcpywrap(void *, void *, size_t);
254 extern char *kvatoname(ipfunc_t, ioctlfunc_t);
255 extern int load_dstlist(struct ippool_dst *, ioctlfunc_t,
256                              ipf_dstnode_t *);
257 extern int load_dstlistnode(int, char *, struct ipf_dstnode *,
258                                  ioctlfunc_t);
259 extern alist_t *load_file(char *);
260 extern int load_hash(struct iphtable_s *, struct iphtent_s *,
261                           ioctlfunc_t);
262 extern int load_hashnode(int, char *, struct iphtent_s *, int,
263                               ioctlfunc_t);
264 extern alist_t *load_http(char *);
265 extern int load_pool(struct ip_pool_s *list, ioctlfunc_t);
266 extern int load_poolnode(int, char *, ip_pool_node_t *, int, ioctlfunc_t);
267 extern alist_t *load_url(char *);
268 extern alist_t *make_range(int, struct in_addr, struct in_addr);
269 extern void mb_hexdump(mb_t *, FILE *);
270 extern ipfunc_t nametokva(char *, ioctlfunc_t);
271 extern void nat_setgroupmap(struct ipnat *);
272 extern int ntomask(int, int, u_32_t *);
273 extern u_32_t optname(char ***, u_short *, int);
274 extern wordtab_t *parsefields(wordtab_t *, char *);
275 extern int *parseipfexpr(char *, char **);
276 extern int parsewhoisline(char *, addrfamily_t *, addrfamily_t *);
277 extern void pool_close(void);
278 extern int pool_fd(void);
279 extern int pool_ioctl(ioctlfunc_t, ioctlcmd_t, void *);
280 extern int pool_open(void);
281 extern char *portname(int, int);
282 extern int pri_findname(char *);
283 extern char *pri_toname(int);
284 extern void print_toif(int, char *, char *, struct frdest *);
285 extern void printaps(ap_session_t *, int, int);
286 extern void printaddr(int, int, char *, int, u_32_t *, u_32_t *);
287 extern void printbuf(char *, int, int);
288 extern void printfieldhdr(wordtab_t *, wordtab_t *);
289 extern void printfr(struct frentry *, ioctlfunc_t);
290 extern struct iphtable_s *printhash(struct iphtable_s *, copyfunc_t,
291                                          char *, int, wordtab_t *);
292 extern struct iphtable_s *printhash_live(iphtable_t *, int, char *,
293                                               int, wordtab_t *);
294 extern ippool_dst_t *printdstl_live(ippool_dst_t *, int, char *,
295                                          int, wordtab_t *);
296 extern void printhashdata(iphtable_t *, int);
297 extern struct iphtent_s *printhashnode(struct iphtable_s *,
298                                             struct iphtent_s *,
299                                             copyfunc_t, int, wordtab_t *);
300 extern void printhost(int, u_32_t *);
301 extern void printhostmask(int, u_32_t *, u_32_t *);
302 extern void printip(int, u_32_t *);
303 extern void printlog(struct frentry *);
304 extern void printlookup(char *, i6addr_t *addr, i6addr_t *mask);
305 extern void printmask(int, u_32_t *);
306 extern void printnataddr(int, char *, nat_addr_t *, int);
307 extern void printnatfield(nat_t *, int);
308 extern void printnatside(char *, nat_stat_side_t *);
309 extern void printpacket(int, mb_t *);
310 extern void printpacket6(int, mb_t *);
311 extern struct ippool_dst *printdstlist(struct ippool_dst *, copyfunc_t,
312                                             char *, int, ipf_dstnode_t *,
313                                             wordtab_t *);
314 extern void printdstlistdata(ippool_dst_t *, int);
315 extern ipf_dstnode_t *printdstlistnode(ipf_dstnode_t *, copyfunc_t,
316                                             int, wordtab_t *);
317 extern void printdstlistpolicy(ippool_policy_t);
318 extern struct ip_pool_s *printpool(struct ip_pool_s *, copyfunc_t,
319                                         char *, int, wordtab_t *);
320 extern struct ip_pool_s *printpool_live(struct ip_pool_s *, int,
321                                              char *, int, wordtab_t *);
322 extern void printpooldata(ip_pool_t *, int);
323 extern void printpoolfield(void *, int, int);
324 extern struct ip_pool_node *printpoolnode(struct ip_pool_node *,
325                                                int, wordtab_t *);
326 extern void printproto(struct protoent *, int, struct ipnat *);
327 extern void printportcmp(int, struct frpcmp *);
328 extern void printstatefield(ipstate_t *, int);
329 extern void printtqtable(ipftq_t *);
330 extern void printtunable(ipftune_t *);
331 extern void printunit(int);
332 extern void optprint(u_short *, u_long, u_long);
333 #ifdef  USE_INET6
334 extern void optprintv6(u_short *, u_long, u_long);
335 #endif
336 extern int remove_hash(struct iphtable_s *, ioctlfunc_t);
337 extern int remove_hashnode(int, char *, struct iphtent_s *, ioctlfunc_t);
338 extern int remove_pool(ip_pool_t *, ioctlfunc_t);
339 extern int remove_poolnode(int, char *, ip_pool_node_t *, ioctlfunc_t);
340 extern u_char tcpflags(char *);
341 extern void printc(struct frentry *);
342 extern void printC(int);
343 extern void emit(int, int, void *, struct frentry *);
344 extern u_char secbit(int);
345 extern u_char seclevel(char *);
346 extern void printfraginfo(char *, struct ipfr *);
347 extern void printifname(char *, char *, void *);
348 extern char *hostname(int, void *);
349 extern struct ipstate *printstate(struct ipstate *, int, u_long);
350 extern void printsbuf(char *);
351 extern void printnat(struct ipnat *, int);
352 extern void printactiveaddress(int, char *, i6addr_t *, char *);
353 extern void printactivenat(struct nat *, int, u_long);
354 extern void printhostmap(struct hostmap *, u_int);
355 extern void printtcpflags(u_32_t, u_32_t);
356 extern void printipfexpr(int *);
357 extern void printstatefield(ipstate_t *, int);
358 extern void printstatefieldhdr(int);
359 extern int sendtrap_v1_0(int, char *, char *, int, time_t);
360 extern int sendtrap_v2_0(int, char *, char *, int);
361 extern int vtof(int);
362
363 extern void set_variable(char *, char *);
364 extern char *get_variable(char *, char **, int);
365 extern void resetlexer(void);
366
367 extern void debug(int, char *, ...);
368 extern void verbose(int, char *, ...);
369 extern void ipfkdebug(char *, ...);
370 extern void ipfkverbose(char *, ...);
371
372 #if SOLARIS
373 extern int gethostname(char *, int );
374 extern void sync(void);
375 #endif
376
377 #endif /* __IPF_H__ */