Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / dist / ipf / netinet / ip_fil.h
blobaf48a6fbd4b2b0795741bf7b35782744b4ab51a5
1 /* $NetBSD$ */
3 /*
4 * Copyright (C) 1993-2001, 2003 by Darren Reed.
6 * See the IPFILTER.LICENCE file for details on licencing.
8 * @(#)ip_fil.h 1.35 6/5/96
9 * Id: ip_fil.h,v 2.170.2.62 2009/07/22 01:46:42 darrenr Exp
12 #ifndef _NETINET_IP_FIL_H_
13 #define _NETINET_IP_FIL_H_
15 #include "netinet/ip_compat.h"
17 #ifndef SOLARIS
18 # define SOLARIS (defined(sun) && (defined(__svr4__) || defined(__SVR4)))
19 #endif
21 #ifndef __P
22 # ifdef __STDC__
23 # define __P(x) x
24 # else
25 # define __P(x) ()
26 # endif
27 #endif
29 #if defined(__STDC__) || defined(__GNUC__) || defined(_AIX51)
30 # define SIOCADAFR _IOW('r', 60, struct ipfobj)
31 # define SIOCRMAFR _IOW('r', 61, struct ipfobj)
32 # define SIOCSETFF _IOW('r', 62, u_int)
33 # define SIOCGETFF _IOR('r', 63, u_int)
34 # define SIOCGETFS _IOWR('r', 64, struct ipfobj)
35 # define SIOCIPFFL _IOWR('r', 65, int)
36 # define SIOCIPFFB _IOR('r', 66, int)
37 # define SIOCADIFR _IOW('r', 67, struct ipfobj)
38 # define SIOCRMIFR _IOW('r', 68, struct ipfobj)
39 # define SIOCSWAPA _IOR('r', 69, u_int)
40 # define SIOCINAFR _IOW('r', 70, struct ipfobj)
41 # define SIOCINIFR _IOW('r', 71, struct ipfobj)
42 # define SIOCFRENB _IOW('r', 72, u_int)
43 # define SIOCFRSYN _IOW('r', 73, u_int)
44 # define SIOCFRZST _IOWR('r', 74, struct ipfobj)
45 # define SIOCZRLST _IOWR('r', 75, struct ipfobj)
46 # define SIOCAUTHW _IOWR('r', 76, struct ipfobj)
47 # define SIOCAUTHR _IOWR('r', 77, struct ipfobj)
48 # define SIOCSTAT1 _IOWR('r', 78, struct ipfobj)
49 # define SIOCSTLCK _IOWR('r', 79, u_int)
50 # define SIOCSTPUT _IOWR('r', 80, struct ipfobj)
51 # define SIOCSTGET _IOWR('r', 81, struct ipfobj)
52 # define SIOCSTGSZ _IOWR('r', 82, struct ipfobj)
53 # define SIOCSTAT2 _IOWR('r', 83, struct ipfobj)
54 # define SIOCSETLG _IOWR('r', 84, int)
55 # define SIOCGETLG _IOWR('r', 85, int)
56 # define SIOCFUNCL _IOWR('r', 86, struct ipfunc_resolve)
57 # define SIOCIPFGETNEXT _IOWR('r', 87, struct ipfobj)
58 # define SIOCIPFGET _IOWR('r', 88, struct ipfobj)
59 # define SIOCIPFSET _IOWR('r', 89, struct ipfobj)
60 # define SIOCIPFL6 _IOWR('r', 90, int)
61 # define SIOCIPFITER _IOWR('r', 91, struct ipfobj)
62 # define SIOCGENITER _IOWR('r', 92, struct ipfobj)
63 # define SIOCGTABL _IOWR('r', 93, struct ipfobj)
64 # define SIOCIPFDELTOK _IOWR('r', 94, int)
65 # define SIOCLOOKUPITER _IOWR('r', 95, struct ipfobj)
66 # define SIOCGTQTAB _IOWR('r', 96, struct ipfobj)
67 #else
68 # define SIOCADAFR _IOW(r, 60, struct ipfobj)
69 # define SIOCRMAFR _IOW(r, 61, struct ipfobj)
70 # define SIOCSETFF _IOW(r, 62, u_int)
71 # define SIOCGETFF _IOR(r, 63, u_int)
72 # define SIOCGETFS _IOWR(r, 64, struct ipfobj)
73 # define SIOCIPFFL _IOWR(r, 65, int)
74 # define SIOCIPFFB _IOR(r, 66, int)
75 # define SIOCADIFR _IOW(r, 67, struct ipfobj)
76 # define SIOCRMIFR _IOW(r, 68, struct ipfobj)
77 # define SIOCSWAPA _IOR(r, 69, u_int)
78 # define SIOCINAFR _IOW(r, 70, struct ipfobj)
79 # define SIOCINIFR _IOW(r, 71, struct ipfobj)
80 # define SIOCFRENB _IOW(r, 72, u_int)
81 # define SIOCFRSYN _IOW(r, 73, u_int)
82 # define SIOCFRZST _IOWR(r, 74, struct ipfobj)
83 # define SIOCZRLST _IOWR(r, 75, struct ipfobj)
84 # define SIOCAUTHW _IOWR(r, 76, struct ipfobj)
85 # define SIOCAUTHR _IOWR(r, 77, struct ipfobj)
86 # define SIOCSTAT1 _IOWR(r, 78, struct ipfobj)
87 # define SIOCSTLCK _IOWR(r, 79, u_int)
88 # define SIOCSTPUT _IOWR(r, 80, struct ipfobj)
89 # define SIOCSTGET _IOWR(r, 81, struct ipfobj)
90 # define SIOCSTGSZ _IOWR(r, 82, struct ipfobj)
91 # define SIOCSTAT2 _IOWR(r, 83, struct ipfobj)
92 # define SIOCSETLG _IOWR(r, 84, int)
93 # define SIOCGETLG _IOWR(r, 85, int)
94 # define SIOCFUNCL _IOWR(r, 86, struct ipfunc_resolve)
95 # define SIOCIPFGETNEXT _IOWR(r, 87, struct ipfobj)
96 # define SIOCIPFGET _IOWR(r, 88, struct ipfobj)
97 # define SIOCIPFSET _IOWR(r, 89, struct ipfobj)
98 # define SIOCIPFL6 _IOWR(r, 90, int)
99 # define SIOCIPFITER _IOWR(r, 91, struct ipfobj)
100 # define SIOCGENITER _IOWR(r, 92, struct ipfobj)
101 # define SIOCGTABL _IOWR(r, 93, struct ipfobj)
102 # define SIOCIPFDELTOK _IOWR(r, 94, int)
103 # define SIOCLOOKUPITER _IOWR(r, 95, struct ipfobj)
104 # define SIOCGTQTAB _IOWR(r, 96, struct ipfobj)
105 #endif
106 #define SIOCADDFR SIOCADAFR
107 #define SIOCDELFR SIOCRMAFR
108 #define SIOCINSFR SIOCINAFR
109 #define SIOCATHST SIOCSTAT1
110 #define SIOCGFRST SIOCSTAT2
113 struct ipscan;
114 struct ifnet;
117 typedef int (* lookupfunc_t) __P((void *, int, void *));
120 * i6addr is used as a container for both IPv4 and IPv6 addresses, as well
121 * as other types of objects, depending on its qualifier.
123 #ifdef USE_INET6
124 typedef union i6addr {
125 u_32_t i6[4];
126 struct in_addr in4;
127 struct in6_addr in6;
128 void *vptr[2];
129 lookupfunc_t lptr[2];
130 struct {
131 u_short type;
132 u_short subtype;
133 char label[12];
134 } i6un;
135 } i6addr_t;
136 #else
137 typedef union i6addr {
138 u_32_t i6[4];
139 struct in_addr in4;
140 void *vptr[2];
141 lookupfunc_t lptr[2];
142 struct {
143 u_short type;
144 u_short subtype;
145 char label[12];
146 } i6un;
147 } i6addr_t;
148 #endif
150 #define in4_addr in4.s_addr
151 #define iplookupnum i6[1]
152 #define iplookupname i6un.label
153 #define iplookuptype i6un.type
154 #define iplookupsubtype i6un.subtype
156 * NOTE: These DO overlap the above on 64bit systems and this IS recognised.
158 #define iplookupptr vptr[0]
159 #define iplookupfunc lptr[1]
161 /* Avoid casting to a type presuming 64-bit alignment. */
162 #define I60(x) (((u_32_t *)(x))[0])
163 #define I61(x) (((u_32_t *)(x))[1])
164 #define I62(x) (((u_32_t *)(x))[2])
165 #define I63(x) (((u_32_t *)(x))[3])
166 #define HI60(x) ntohl(((u_32_t *)(x))[0])
167 #define HI61(x) ntohl(((u_32_t *)(x))[1])
168 #define HI62(x) ntohl(((u_32_t *)(x))[2])
169 #define HI63(x) ntohl(((u_32_t *)(x))[3])
171 #define IP6_EQ(a,b) ((I63(a) == I63(b)) && (I62(a) == I62(b)) && \
172 (I61(a) == I61(b)) && (I60(a) == I60(b)))
173 #define IP6_NEQ(a,b) ((I63(a) != I63(b)) || (I62(a) != I62(b)) || \
174 (I61(a) != I61(b)) || (I60(a) != I60(b)))
175 #define IP6_ISZERO(a) ((I60(a) | I61(a) | I62(a) | I63(a)) == 0)
176 #define IP6_NOTZERO(a) ((I60(a) | I61(a) | I62(a) | I63(a)) != 0)
177 #define IP6_GT(a,b) (HI60(a) > HI60(b) || (HI60(a) == HI60(b) && \
178 (HI61(a) > HI61(b) || (HI61(a) == HI61(b) && \
179 (HI62(a) > HI62(b) || (HI62(a) == HI62(b) && \
180 HI63(a) > HI63(b)))))))
181 #define IP6_LT(a,b) (HI60(a) < HI60(b) || (HI60(a) == HI60(b) && \
182 (HI61(a) < HI61(b) || (HI61(a) == HI61(b) && \
183 (HI62(a) < HI62(b) || (HI62(a) == HI62(b) && \
184 HI63(a) < HI63(b)))))))
185 #define NLADD(n,x) htonl(ntohl(n) + (x))
186 #define IP6_INC(a) \
187 { u_32_t *_i6 = (u_32_t *)(a); \
188 _i6[3] = NLADD(_i6[3], 1); \
189 if (_i6[3] == 0) { \
190 _i6[2] = NLADD(_i6[2], 1); \
191 if (_i6[2] == 0) { \
192 _i6[1] = NLADD(_i6[1], 1); \
193 if (_i6[1] == 0) { \
194 _i6[0] = NLADD(_i6[0], 1); \
199 #define IP6_ADD(a,x,d) \
200 { i6addr_t *_s = (i6addr_t *)(a); \
201 i6addr_t *_d = (i6addr_t *)(d); \
202 _d->i6[0] = NLADD(_s->i6[0], x); \
203 if (ntohl(_d->i6[0]) < ntohl(_s->i6[0])) { \
204 _d->i6[1] = NLADD(_d->i6[1], 1); \
205 if (ntohl(_d->i6[1]) < ntohl(_s->i6[1])) { \
206 _d->i6[2] = NLADD(_d->i6[2], 1); \
207 if (ntohl(_d->i6[2]) < ntohl(_s->i6[2])) { \
208 _d->i6[3] = NLADD(_d->i6[3], 1); \
213 #define IP6_AND(a,b,d) { i6addr_t *_s1 = (i6addr_t *)(a); \
214 i6addr_t *_s2 = (i6addr_t *)(b); \
215 i6addr_t *_d = (i6addr_t *)(d); \
216 _d->i6[0] = _s1->i6[0] & _s2->i6[0]; \
217 _d->i6[1] = _s1->i6[1] & _s2->i6[1]; \
218 _d->i6[2] = _s1->i6[2] & _s2->i6[2]; \
219 _d->i6[3] = _s1->i6[3] & _s2->i6[3]; \
221 #define IP6_MERGE(a,b,c) \
222 { i6addr_t *_d, *_s1, *_s2; \
223 _d = (i6addr_t *)(a); \
224 _s1 = (i6addr_t *)(b); \
225 _s2 = (i6addr_t *)(c); \
226 _d->i6[0] |= _s1->i6[0] & ~_s2->i6[0]; \
227 _d->i6[1] |= _s1->i6[1] & ~_s2->i6[1]; \
228 _d->i6[2] |= _s1->i6[2] & ~_s2->i6[2]; \
229 _d->i6[2] |= _s1->i6[3] & ~_s2->i6[3]; \
233 typedef struct fr_ip {
234 u_32_t fi_v:4; /* IP version */
235 u_32_t fi_xx:4; /* spare */
236 u_32_t fi_tos:8; /* IP packet TOS */
237 u_32_t fi_ttl:8; /* IP packet TTL */
238 u_32_t fi_p:8; /* IP packet protocol */
239 u_32_t fi_optmsk; /* bitmask composed from IP options */
240 i6addr_t fi_src; /* source address from packet */
241 i6addr_t fi_dst; /* destination address from packet */
242 u_short fi_secmsk; /* bitmask composed from IP security options */
243 u_short fi_auth; /* authentication code from IP sec. options */
244 u_32_t fi_flx; /* packet flags */
245 u_32_t fi_tcpmsk; /* TCP options set/reset */
246 u_32_t fi_res1; /* RESERVED */
247 } fr_ip_t;
250 * For use in fi_flx
252 #define FI_TCPUDP 0x0001 /* TCP/UCP implied comparison*/
253 #define FI_OPTIONS 0x0002
254 #define FI_FRAG 0x0004
255 #define FI_SHORT 0x0008
256 #define FI_NATED 0x0010
257 #define FI_MULTICAST 0x0020
258 #define FI_BROADCAST 0x0040
259 #define FI_MBCAST 0x0080
260 #define FI_STATE 0x0100
261 #define FI_BADNAT 0x0200
262 #define FI_BAD 0x0400
263 #define FI_OOW 0x0800 /* Out of state window, else match */
264 #define FI_ICMPERR 0x1000
265 #define FI_FRAGBODY 0x2000
266 #define FI_BADSRC 0x4000
267 #define FI_LOWTTL 0x8000
268 #define FI_CMP 0xcf03 /* Not FI_FRAG,FI_NATED,FI_FRAGTAIL,broadcast */
269 #define FI_ICMPCMP 0x0003 /* Flags we can check for ICMP error packets */
270 #define FI_WITH 0xeffe /* Not FI_TCPUDP */
271 #define FI_V6EXTHDR 0x10000
272 #define FI_COALESCE 0x20000
273 #define FI_NEWNAT 0x40000
274 #define FI_MOREFRAG 0x80000
275 #define FI_NOCKSUM 0x20000000 /* don't do a L4 checksum validation */
276 #define FI_DONTCACHE 0x40000000 /* don't cache the result */
277 #define FI_IGNORE 0x80000000
279 #define fi_saddr fi_src.in4.s_addr
280 #define fi_daddr fi_dst.in4.s_addr
281 #define fi_srcnum fi_src.iplookupnum
282 #define fi_dstnum fi_dst.iplookupnum
283 #define fi_srcname fi_src.iplookupname
284 #define fi_dstname fi_dst.iplookupname
285 #define fi_srctype fi_src.iplookuptype
286 #define fi_dsttype fi_dst.iplookuptype
287 #define fi_srcsubtype fi_src.iplookupsubtype
288 #define fi_dstsubtype fi_dst.iplookupsubtype
289 #define fi_srcptr fi_src.iplookupptr
290 #define fi_dstptr fi_dst.iplookupptr
291 #define fi_srcfunc fi_src.iplookupfunc
292 #define fi_dstfunc fi_dst.iplookupfunc
296 * These are both used by the state and NAT code to indicate that one port or
297 * the other should be treated as a wildcard.
298 * NOTE: When updating, check bit masks in ip_state.h and update there too.
300 #define SI_W_SPORT 0x00000100
301 #define SI_W_DPORT 0x00000200
302 #define SI_WILDP (SI_W_SPORT|SI_W_DPORT)
303 #define SI_W_SADDR 0x00000400
304 #define SI_W_DADDR 0x00000800
305 #define SI_WILDA (SI_W_SADDR|SI_W_DADDR)
306 #define SI_NEWFR 0x00001000
307 #define SI_CLONE 0x00002000
308 #define SI_CLONED 0x00004000
311 typedef struct fr_info {
312 void *fin_ifp; /* interface packet is `on' */
313 fr_ip_t fin_fi; /* IP Packet summary */
314 union {
315 u_short fid_16[2]; /* TCP/UDP ports, ICMP code/type */
316 u_32_t fid_32;
317 } fin_dat;
318 int fin_out; /* in or out ? 1 == out, 0 == in */
319 int fin_rev; /* state only: 1 = reverse */
320 u_short fin_hlen; /* length of IP header in bytes */
321 u_char fin_tcpf; /* TCP header flags (SYN, ACK, etc) */
322 u_char fin_icode; /* ICMP error to return */
323 u_32_t fin_rule; /* rule # last matched */
324 char fin_group[FR_GROUPLEN]; /* group number, -1 for none */
325 struct frentry *fin_fr; /* last matching rule */
326 void *fin_dp; /* start of data past IP header */
327 int fin_dlen; /* length of data portion of packet */
328 int fin_plen;
329 int fin_ipoff; /* # bytes from buffer start to hdr */
330 u_short fin_id; /* IP packet id field */
331 u_short fin_off;
332 int fin_depth; /* Group nesting depth */
333 int fin_error; /* Error code to return */
334 int fin_cksum; /* -1 bad, 1 good, 0 not done */
335 u_int fin_pktnum;
336 void *fin_nattag;
337 void *fin_exthdr;
338 ip_t *fin_ip;
339 mb_t **fin_mp; /* pointer to pointer to mbuf */
340 mb_t *fin_m; /* pointer to mbuf */
341 #ifdef MENTAT
342 mb_t *fin_qfm; /* pointer to mblk where pkt starts */
343 void *fin_qpi;
344 char fin_ifname[LIFNAMSIZ];
345 #endif
346 #ifdef __sgi
347 void *fin_hbuf;
348 #endif
349 } fr_info_t;
351 #define fin_v fin_fi.fi_v
352 #define fin_p fin_fi.fi_p
353 #define fin_flx fin_fi.fi_flx
354 #define fin_optmsk fin_fi.fi_optmsk
355 #define fin_secmsk fin_fi.fi_secmsk
356 #define fin_auth fin_fi.fi_auth
357 #define fin_src fin_fi.fi_src.in4
358 #define fin_src6 fin_fi.fi_src.in6
359 #define fin_saddr fin_fi.fi_saddr
360 #define fin_dst fin_fi.fi_dst.in4
361 #define fin_dst6 fin_fi.fi_dst.in6
362 #define fin_daddr fin_fi.fi_daddr
363 #define fin_data fin_dat.fid_16
364 #define fin_sport fin_dat.fid_16[0]
365 #define fin_dport fin_dat.fid_16[1]
366 #define fin_ports fin_dat.fid_32
368 #define IPF_IN 0
369 #define IPF_OUT 1
371 typedef struct frentry *(*ipfunc_t) __P((fr_info_t *, u_32_t *));
372 typedef int (*ipfuncinit_t) __P((struct frentry *));
374 typedef struct ipfunc_resolve {
375 char ipfu_name[32];
376 ipfunc_t ipfu_addr;
377 ipfuncinit_t ipfu_init;
378 } ipfunc_resolve_t;
381 * Size for compares on fr_info structures
383 #define FI_CSIZE offsetof(fr_info_t, fin_icode)
384 #define FI_LCSIZE offsetof(fr_info_t, fin_dp)
387 * Size for copying cache fr_info structure
389 #define FI_COPYSIZE offsetof(fr_info_t, fin_dp)
392 * Structure for holding IPFilter's tag information
394 #define IPFTAG_LEN 16
395 typedef struct {
396 union {
397 u_32_t iptu_num[4];
398 char iptu_tag[IPFTAG_LEN];
399 } ipt_un;
400 int ipt_not;
401 } ipftag_t;
403 #define ipt_tag ipt_un.iptu_tag
404 #define ipt_num ipt_un.iptu_num
408 * This structure is used to hold information about the next hop for where
409 * to forward a packet.
411 typedef struct frdest {
412 void *fd_ifp;
413 i6addr_t fd_ip6;
414 char fd_ifname[LIFNAMSIZ];
415 } frdest_t;
417 #define fd_ip fd_ip6.in4
421 * This structure holds information about a port comparison.
423 typedef struct frpcmp {
424 int frp_cmp; /* data for port comparisons */
425 u_short frp_port; /* top port for <> and >< */
426 u_short frp_top; /* top port for <> and >< */
427 } frpcmp_t;
429 #define FR_NONE 0
430 #define FR_EQUAL 1
431 #define FR_NEQUAL 2
432 #define FR_LESST 3
433 #define FR_GREATERT 4
434 #define FR_LESSTE 5
435 #define FR_GREATERTE 6
436 #define FR_OUTRANGE 7
437 #define FR_INRANGE 8
438 #define FR_INCRANGE 9
441 * Structure containing all the relevant TCP things that can be checked in
442 * a filter rule.
444 typedef struct frtuc {
445 u_char ftu_tcpfm; /* tcp flags mask */
446 u_char ftu_tcpf; /* tcp flags */
447 frpcmp_t ftu_src;
448 frpcmp_t ftu_dst;
449 } frtuc_t;
451 #define ftu_scmp ftu_src.frp_cmp
452 #define ftu_dcmp ftu_dst.frp_cmp
453 #define ftu_sport ftu_src.frp_port
454 #define ftu_dport ftu_dst.frp_port
455 #define ftu_stop ftu_src.frp_top
456 #define ftu_dtop ftu_dst.frp_top
458 #define FR_TCPFMAX 0x3f
461 * This structure makes up what is considered to be the IPFilter specific
462 * matching components of a filter rule, as opposed to the data structures
463 * used to define the result which are in frentry_t and not here.
465 typedef struct fripf {
466 fr_ip_t fri_ip;
467 fr_ip_t fri_mip; /* mask structure */
469 u_short fri_icmpm; /* data for ICMP packets (mask) */
470 u_short fri_icmp;
472 frtuc_t fri_tuc;
473 int fri_satype; /* addres type */
474 int fri_datype; /* addres type */
475 int fri_sifpidx; /* doing dynamic addressing */
476 int fri_difpidx; /* index into fr_ifps[] to use when */
477 } fripf_t;
479 #define fri_dlookup fri_mip.fi_dst
480 #define fri_slookup fri_mip.fi_src
481 #define fri_dstnum fri_mip.fi_dstnum
482 #define fri_srcnum fri_mip.fi_srcnum
483 #define fri_dstname fri_mip.fi_dstname
484 #define fri_srcname fri_mip.fi_srcname
485 #define fri_dstptr fri_mip.fi_dstptr
486 #define fri_srcptr fri_mip.fi_srcptr
488 #define FRI_NORMAL 0 /* Normal address */
489 #define FRI_DYNAMIC 1 /* dynamic address */
490 #define FRI_LOOKUP 2 /* address is a pool # */
491 #define FRI_RANGE 3 /* address/mask is a range */
492 #define FRI_NETWORK 4 /* network address from if */
493 #define FRI_BROADCAST 5 /* broadcast address from if */
494 #define FRI_PEERADDR 6 /* Peer address for P-to-P */
495 #define FRI_NETMASKED 7 /* network address with netmask from if */
498 typedef struct frentry * (* frentfunc_t) __P((fr_info_t *));
500 typedef struct frentry {
501 ipfmutex_t fr_lock;
502 struct frentry *fr_next;
503 struct frentry **fr_grp;
504 struct ipscan *fr_isc;
505 void *fr_ifas[4];
506 void *fr_ptr; /* for use with fr_arg */
507 char *fr_comment; /* text comment for rule */
508 int fr_ref; /* reference count - for grouping */
509 int fr_statecnt; /* state count - for limit rules */
511 * The line number from a file is here because we need to be able to
512 * match the rule generated with ``grep rule ipf.conf | ipf -rf -''
513 * with the rule loaded using ``ipf -f ipf.conf'' - thus it can't be
514 * on the other side of fr_func.
516 int fr_flineno; /* line number from conf file */
518 * These are only incremented when a packet matches this rule and
519 * it is the last match
521 U_QUAD_T fr_hits;
522 U_QUAD_T fr_bytes;
525 * For PPS rate limiting
527 struct timeval fr_lastpkt;
528 int fr_curpps;
530 union {
531 void *fru_data;
532 void * fru_caddr;
533 fripf_t *fru_ipf;
534 frentfunc_t fru_func;
535 } fr_dun;
538 * Fields after this may not change whilst in the kernel.
540 ipfunc_t fr_func; /* call this function */
541 int fr_dsize;
542 int fr_pps;
543 int fr_statemax; /* max reference count */
544 u_32_t fr_type;
545 u_32_t fr_flags; /* per-rule flags && options (see below) */
546 u_32_t fr_logtag; /* user defined log tag # */
547 u_32_t fr_collect; /* collection number */
548 u_int fr_arg; /* misc. numeric arg for rule */
549 u_int fr_loglevel; /* syslog log facility + priority */
550 u_int fr_age[2]; /* non-TCP timeouts */
551 u_char fr_v;
552 u_char fr_icode; /* return ICMP code */
553 char fr_group[FR_GROUPLEN]; /* group to which this rule belongs */
554 char fr_grhead[FR_GROUPLEN]; /* group # which this rule starts */
555 ipftag_t fr_nattag;
556 char fr_ifnames[4][LIFNAMSIZ];
557 char fr_isctag[16];
558 frdest_t fr_tifs[2]; /* "to"/"reply-to" interface */
559 frdest_t fr_dif; /* duplicate packet interface */
561 * This must be last and will change after loaded into the kernel.
563 u_int fr_cksum; /* checksum on filter rules for performance */
564 } frentry_t;
566 #define fr_caddr fr_dun.fru_caddr
567 #define fr_data fr_dun.fru_data
568 #define fr_dfunc fr_dun.fru_func
569 #define fr_ipf fr_dun.fru_ipf
570 #define fr_ip fr_ipf->fri_ip
571 #define fr_mip fr_ipf->fri_mip
572 #define fr_icmpm fr_ipf->fri_icmpm
573 #define fr_icmp fr_ipf->fri_icmp
574 #define fr_tuc fr_ipf->fri_tuc
575 #define fr_satype fr_ipf->fri_satype
576 #define fr_datype fr_ipf->fri_datype
577 #define fr_sifpidx fr_ipf->fri_sifpidx
578 #define fr_difpidx fr_ipf->fri_difpidx
579 #define fr_proto fr_ip.fi_p
580 #define fr_mproto fr_mip.fi_p
581 #define fr_ttl fr_ip.fi_ttl
582 #define fr_mttl fr_mip.fi_ttl
583 #define fr_tos fr_ip.fi_tos
584 #define fr_mtos fr_mip.fi_tos
585 #define fr_tcpfm fr_tuc.ftu_tcpfm
586 #define fr_tcpf fr_tuc.ftu_tcpf
587 #define fr_scmp fr_tuc.ftu_scmp
588 #define fr_dcmp fr_tuc.ftu_dcmp
589 #define fr_dport fr_tuc.ftu_dport
590 #define fr_sport fr_tuc.ftu_sport
591 #define fr_stop fr_tuc.ftu_stop
592 #define fr_dtop fr_tuc.ftu_dtop
593 #define fr_dst fr_ip.fi_dst.in4
594 #define fr_daddr fr_ip.fi_dst.in4.s_addr
595 #define fr_src fr_ip.fi_src.in4
596 #define fr_saddr fr_ip.fi_src.in4.s_addr
597 #define fr_dmsk fr_mip.fi_dst.in4
598 #define fr_dmask fr_mip.fi_dst.in4.s_addr
599 #define fr_smsk fr_mip.fi_src.in4
600 #define fr_smask fr_mip.fi_src.in4.s_addr
601 #define fr_dstnum fr_ip.fi_dstnum
602 #define fr_srcnum fr_ip.fi_srcnum
603 #define fr_dlookup fr_ip.fi_dst
604 #define fr_slookup fr_ip.fi_src
605 #define fr_dstname fr_ip.fi_dstname
606 #define fr_srcname fr_ip.fi_srcname
607 #define fr_dsttype fr_ip.fi_dsttype
608 #define fr_srctype fr_ip.fi_srctype
609 #define fr_dstsubtype fr_ip.fi_dstsubtype
610 #define fr_srcsubtype fr_ip.fi_srcsubtype
611 #define fr_dstptr fr_mip.fi_dstptr
612 #define fr_srcptr fr_mip.fi_srcptr
613 #define fr_dstfunc fr_mip.fi_dstfunc
614 #define fr_srcfunc fr_mip.fi_srcfunc
615 #define fr_optbits fr_ip.fi_optmsk
616 #define fr_optmask fr_mip.fi_optmsk
617 #define fr_secbits fr_ip.fi_secmsk
618 #define fr_secmask fr_mip.fi_secmsk
619 #define fr_authbits fr_ip.fi_auth
620 #define fr_authmask fr_mip.fi_auth
621 #define fr_flx fr_ip.fi_flx
622 #define fr_mflx fr_mip.fi_flx
623 #define fr_ifname fr_ifnames[0]
624 #define fr_oifname fr_ifnames[2]
625 #define fr_ifa fr_ifas[0]
626 #define fr_oifa fr_ifas[2]
627 #define fr_tif fr_tifs[0]
628 #define fr_rif fr_tifs[1]
630 #define FR_NOLOGTAG 0
632 #define FR_CMPSIZ (sizeof(struct frentry) - \
633 offsetof(struct frentry, fr_func))
636 * fr_type
638 #define FR_T_NONE 0
639 #define FR_T_IPF 1 /* IPF structures */
640 #define FR_T_BPFOPC 2 /* BPF opcode */
641 #define FR_T_CALLFUNC 3 /* callout to function in fr_func only */
642 #define FR_T_COMPIPF 4 /* compiled C code */
643 #define FR_T_BUILTIN 0x80000000 /* rule is in kernel space */
646 * fr_flags
648 #define FR_CALL 0x00000 /* call rule */
649 #define FR_BLOCK 0x00001 /* do not allow packet to pass */
650 #define FR_PASS 0x00002 /* allow packet to pass */
651 #define FR_AUTH 0x00003 /* use authentication */
652 #define FR_PREAUTH 0x00004 /* require preauthentication */
653 #define FR_ACCOUNT 0x00005 /* Accounting rule */
654 #define FR_SKIP 0x00006 /* skip rule */
655 #define FR_DIVERT 0x00007 /* divert rule */
656 #define FR_CMDMASK 0x0000f
657 #define FR_LOG 0x00010 /* Log */
658 #define FR_LOGB 0x00011 /* Log-fail */
659 #define FR_LOGP 0x00012 /* Log-pass */
660 #define FR_LOGMASK (FR_LOG|FR_CMDMASK)
661 #define FR_CALLNOW 0x00020 /* call another function (fr_func) if matches */
662 #define FR_NOTSRCIP 0x00040
663 #define FR_NOTDSTIP 0x00080
664 #define FR_QUICK 0x00100 /* match & stop processing list */
665 #define FR_KEEPFRAG 0x00200 /* keep fragment information */
666 #define FR_KEEPSTATE 0x00400 /* keep `connection' state information */
667 #define FR_FASTROUTE 0x00800 /* bypass normal routing */
668 #define FR_RETRST 0x01000 /* Return TCP RST packet - reset connection */
669 #define FR_RETICMP 0x02000 /* Return ICMP unreachable packet */
670 #define FR_FAKEICMP 0x03000 /* Return ICMP unreachable with fake source */
671 #define FR_OUTQUE 0x04000 /* outgoing packets */
672 #define FR_INQUE 0x08000 /* ingoing packets */
673 #define FR_LOGBODY 0x10000 /* Log the body */
674 #define FR_LOGFIRST 0x20000 /* Log the first byte if state held */
675 #define FR_LOGORBLOCK 0x40000 /* block the packet if it can't be logged */
676 #define FR_DUP 0x80000 /* duplicate packet */
677 #define FR_FRSTRICT 0x100000 /* strict frag. cache */
678 #define FR_STSTRICT 0x200000 /* strict keep state */
679 #define FR_NEWISN 0x400000 /* new ISN for outgoing TCP */
680 #define FR_NOICMPERR 0x800000 /* do not match ICMP errors in state */
681 #define FR_STATESYNC 0x1000000 /* synchronize state to slave */
682 #define FR_NOMATCH 0x8000000 /* no match occured */
683 /* 0x10000000 FF_LOGPASS */
684 /* 0x20000000 FF_LOGBLOCK */
685 /* 0x40000000 FF_LOGNOMATCH */
686 /* 0x80000000 FF_BLOCKNONIP */
687 #define FR_COPIED 0x40000000 /* copied from user space */
688 #define FR_INACTIVE 0x80000000 /* only used when flush'ing rules */
690 #define FR_RETMASK (FR_RETICMP|FR_RETRST|FR_FAKEICMP)
691 #define FR_ISBLOCK(x) (((x) & FR_CMDMASK) == FR_BLOCK)
692 #define FR_ISPASS(x) (((x) & FR_CMDMASK) == FR_PASS)
693 #define FR_ISAUTH(x) (((x) & FR_CMDMASK) == FR_AUTH)
694 #define FR_ISPREAUTH(x) (((x) & FR_CMDMASK) == FR_PREAUTH)
695 #define FR_ISACCOUNT(x) (((x) & FR_CMDMASK) == FR_ACCOUNT)
696 #define FR_ISSKIP(x) (((x) & FR_CMDMASK) == FR_SKIP)
697 #define FR_ISNOMATCH(x) ((x) & FR_NOMATCH)
698 #define FR_INOUT (FR_INQUE|FR_OUTQUE)
701 * recognized flags for SIOCGETFF and SIOCSETFF, and get put in fr_flags
703 #define FF_LOGPASS 0x10000000
704 #define FF_LOGBLOCK 0x20000000
705 #define FF_LOGNOMATCH 0x40000000
706 #define FF_LOGGING (FF_LOGPASS|FF_LOGBLOCK|FF_LOGNOMATCH)
707 #define FF_BLOCKNONIP 0x80000000 /* Solaris2 Only */
711 * Structure that passes information on what/how to flush to the kernel.
713 typedef struct ipfflush {
714 int ipflu_how;
715 int ipflu_arg;
716 } ipfflush_t;
722 typedef struct ipfgetctl {
723 u_int ipfg_min; /* min value */
724 u_int ipfg_current; /* current value */
725 u_int ipfg_max; /* max value */
726 u_int ipfg_default; /* default value */
727 u_int ipfg_steps; /* value increments */
728 char ipfg_name[40]; /* tag name for this control */
729 } ipfgetctl_t;
731 typedef struct ipfsetctl {
732 int ipfs_which; /* 0 = min 1 = current 2 = max 3 = default */
733 u_int ipfs_value; /* min value */
734 char ipfs_name[40]; /* tag name for this control */
735 } ipfsetctl_t;
739 * Some of the statistics below are in their own counters, but most are kept
740 * in this single structure so that they can all easily be collected and
741 * copied back as required.
743 typedef struct filterstats {
744 u_long fr_pass; /* packets allowed */
745 u_long fr_block; /* packets denied */
746 u_long fr_nom; /* packets which don't match any rule */
747 u_long fr_short; /* packets which are short */
748 u_long fr_ppkl; /* packets allowed and logged */
749 u_long fr_bpkl; /* packets denied and logged */
750 u_long fr_npkl; /* packets unmatched and logged */
751 u_long fr_pkl; /* packets logged */
752 u_long fr_skip; /* packets to be logged but buffer full */
753 u_long fr_ret; /* packets for which a return is sent */
754 u_long fr_acct; /* packets for which counting was performed */
755 u_long fr_bnfr; /* bad attempts to allocate fragment state */
756 u_long fr_nfr; /* new fragment state kept */
757 u_long fr_cfr; /* add new fragment state but complete pkt */
758 u_long fr_bads; /* bad attempts to allocate packet state */
759 u_long fr_ads; /* new packet state kept */
760 u_long fr_chit; /* cached hit */
761 u_long fr_tcpbad; /* TCP checksum check failures */
762 u_long fr_pull[2]; /* good and bad pullup attempts */
763 u_long fr_badsrc; /* source received doesn't match route */
764 u_long fr_badttl; /* TTL in packet doesn't reach minimum */
765 u_long fr_bad; /* bad IP packets to the filter */
766 u_long fr_ipv6; /* IPv6 packets in/out */
767 u_long fr_ppshit; /* dropped because of pps ceiling */
768 u_long fr_ipud; /* IP id update failures */
769 } filterstats_t;
772 * Log structure. Each packet header logged is prepended by one of these.
773 * Following this in the log records read from the device will be an ipflog
774 * structure which is then followed by any packet data.
776 typedef struct iplog {
777 u_32_t ipl_magic;
778 u_int ipl_count;
779 struct timeval ipl_time;
780 size_t ipl_dsize;
781 struct iplog *ipl_next;
782 } iplog_t;
784 #define ipl_sec ipl_time.tv_sec
785 #define ipl_usec ipl_time.tv_usec
787 #define IPL_MAGIC 0x49504c4d /* 'IPLM' */
788 #define IPL_MAGIC_NAT 0x49504c4e /* 'IPLN' */
789 #define IPL_MAGIC_STATE 0x49504c53 /* 'IPLS' */
790 #define IPLOG_SIZE sizeof(iplog_t)
792 typedef struct ipflog {
793 #if (defined(NetBSD) && (NetBSD <= 1991011) && (NetBSD >= 199603)) || \
794 (defined(OpenBSD) && (OpenBSD >= 199603))
795 #else
796 u_int fl_unit;
797 #endif
798 u_32_t fl_rule;
799 u_32_t fl_flags;
800 u_32_t fl_lflags;
801 u_32_t fl_logtag;
802 ipftag_t fl_nattag;
803 u_short fl_plen; /* extra data after hlen */
804 u_short fl_loglevel; /* syslog log level */
805 char fl_group[FR_GROUPLEN];
806 u_char fl_hlen; /* length of IP headers saved */
807 u_char fl_dir;
808 u_char fl_xxx[2]; /* pad */
809 char fl_ifname[LIFNAMSIZ];
810 } ipflog_t;
812 #ifndef IPF_LOGGING
813 # define IPF_LOGGING 0
814 #endif
815 #ifndef IPF_DEFAULT_PASS
816 # define IPF_DEFAULT_PASS FR_PASS
817 #endif
819 #define DEFAULT_IPFLOGSIZE 8192
820 #ifndef IPFILTER_LOGSIZE
821 # define IPFILTER_LOGSIZE DEFAULT_IPFLOGSIZE
822 #else
823 # if IPFILTER_LOGSIZE < DEFAULT_IPFLOGSIZE
824 # error IPFILTER_LOGSIZE too small. Must be >= DEFAULT_IPFLOGSIZE
825 # endif
826 #endif
828 #define IPF_OPTCOPY 0x07ff00 /* bit mask of copied options */
831 * Device filenames for reading log information. Use ipf on Solaris2 because
832 * ipl is already a name used by something else.
834 #ifndef IPL_NAME
835 # if SOLARIS
836 # define IPL_NAME "/dev/ipf"
837 # else
838 # define IPL_NAME "/dev/ipl"
839 # endif
840 #endif
842 * Pathnames for various IP Filter control devices. Used by LKM
843 * and userland, so defined here.
845 #define IPNAT_NAME "/dev/ipnat"
846 #define IPSTATE_NAME "/dev/ipstate"
847 #define IPAUTH_NAME "/dev/ipauth"
848 #define IPSYNC_NAME "/dev/ipsync"
849 #define IPSCAN_NAME "/dev/ipscan"
850 #define IPLOOKUP_NAME "/dev/iplookup"
852 #define IPL_LOGIPF 0 /* Minor device #'s for accessing logs */
853 #define IPL_LOGNAT 1
854 #define IPL_LOGSTATE 2
855 #define IPL_LOGAUTH 3
856 #define IPL_LOGSYNC 4
857 #define IPL_LOGSCAN 5
858 #define IPL_LOGLOOKUP 6
859 #define IPL_LOGCOUNT 7
860 #define IPL_LOGMAX 7
861 #define IPL_LOGSIZE IPL_LOGMAX + 1
862 #define IPL_LOGALL -1
863 #define IPL_LOGNONE -2
866 * For SIOCGETFS
868 typedef struct friostat {
869 struct filterstats f_st[2];
870 struct frentry *f_ipf[2][2];
871 struct frentry *f_acct[2][2];
872 struct frentry *f_ipf6[2][2];
873 struct frentry *f_acct6[2][2];
874 struct frentry *f_auth;
875 struct frgroup *f_groups[IPL_LOGSIZE][2];
876 u_long f_froute[2];
877 u_long f_ticks;
878 int f_locks[IPL_LOGSIZE];
879 size_t f_kmutex_sz;
880 size_t f_krwlock_sz;
881 int f_defpass; /* default pass - from fr_pass */
882 int f_active; /* 1 or 0 - active rule set */
883 int f_running; /* 1 if running, else 0 */
884 int f_logging; /* 1 if enabled, else 0 */
885 int f_features;
886 char f_version[32]; /* version string */
887 } friostat_t;
889 #define f_fin f_ipf[0]
890 #define f_fin6 f_ipf6[0]
891 #define f_fout f_ipf[1]
892 #define f_fout6 f_ipf6[1]
893 #define f_acctin f_acct[0]
894 #define f_acctin6 f_acct6[0]
895 #define f_acctout f_acct[1]
896 #define f_acctout6 f_acct6[1]
898 #define IPF_FEAT_LKM 0x001
899 #define IPF_FEAT_LOG 0x002
900 #define IPF_FEAT_LOOKUP 0x004
901 #define IPF_FEAT_BPF 0x008
902 #define IPF_FEAT_COMPILED 0x010
903 #define IPF_FEAT_CKSUM 0x020
904 #define IPF_FEAT_SYNC 0x040
905 #define IPF_FEAT_SCAN 0x080
906 #define IPF_FEAT_IPV6 0x100
908 typedef struct optlist {
909 u_short ol_val;
910 int ol_bit;
911 } optlist_t;
915 * Group list structure.
917 typedef struct frgroup {
918 struct frgroup *fg_next;
919 struct frentry *fg_head;
920 struct frentry *fg_start;
921 u_32_t fg_flags;
922 int fg_ref;
923 char fg_name[FR_GROUPLEN];
924 } frgroup_t;
926 #define FG_NAME(g) (*(g)->fg_name == '\0' ? "" : (g)->fg_name)
930 * Used by state and NAT tables
932 typedef struct icmpinfo {
933 u_short ici_id;
934 u_short ici_seq;
935 u_char ici_type;
936 } icmpinfo_t;
938 typedef struct udpinfo {
939 u_short us_sport;
940 u_short us_dport;
941 } udpinfo_t;
944 typedef struct tcpdata {
945 u_32_t td_end;
946 u_32_t td_maxend;
947 u_32_t td_maxwin;
948 u_32_t td_winscale;
949 u_32_t td_maxseg;
950 int td_winflags;
951 } tcpdata_t;
953 #define TCP_WSCALE_MAX 14
955 #define TCP_WSCALE_SEEN 0x00000001
956 #define TCP_WSCALE_FIRST 0x00000002
957 #define TCP_SACK_PERMIT 0x00000004
960 typedef struct tcpinfo {
961 u_short ts_sport;
962 u_short ts_dport;
963 tcpdata_t ts_data[2];
964 } tcpinfo_t;
968 * Structures to define a GRE header as seen in a packet.
970 struct grebits {
971 u_32_t grb_C:1;
972 u_32_t grb_R:1;
973 u_32_t grb_K:1;
974 u_32_t grb_S:1;
975 u_32_t grb_s:1;
976 u_32_t grb_recur:1;
977 u_32_t grb_A:1;
978 u_32_t grb_flags:3;
979 u_32_t grb_ver:3;
980 u_short grb_ptype;
983 typedef struct grehdr {
984 union {
985 struct grebits gru_bits;
986 u_short gru_flags;
987 } gr_un;
988 u_short gr_len;
989 u_short gr_call;
990 } grehdr_t;
992 #define gr_flags gr_un.gru_flags
993 #define gr_bits gr_un.gru_bits
994 #define gr_ptype gr_bits.grb_ptype
995 #define gr_C gr_bits.grb_C
996 #define gr_R gr_bits.grb_R
997 #define gr_K gr_bits.grb_K
998 #define gr_S gr_bits.grb_S
999 #define gr_s gr_bits.grb_s
1000 #define gr_recur gr_bits.grb_recur
1001 #define gr_A gr_bits.grb_A
1002 #define gr_ver gr_bits.grb_ver
1005 * GRE information tracked by "keep state"
1007 typedef struct greinfo {
1008 u_short gs_call[2];
1009 u_short gs_flags;
1010 u_short gs_ptype;
1011 } greinfo_t;
1013 #define GRE_REV(x) ((ntohs(x) >> 13) & 7)
1017 * Format of an Authentication header
1019 typedef struct authhdr {
1020 u_char ah_next;
1021 u_char ah_plen;
1022 u_short ah_reserved;
1023 u_32_t ah_spi;
1024 u_32_t ah_seq;
1025 /* Following the sequence number field is 0 or more bytes of */
1026 /* authentication data, as specified by ah_plen - RFC 2402. */
1027 } authhdr_t;
1031 * Timeout tail queue list member
1033 typedef struct ipftqent {
1034 struct ipftqent **tqe_pnext;
1035 struct ipftqent *tqe_next;
1036 struct ipftq *tqe_ifq;
1037 void *tqe_parent; /* pointer back to NAT/state struct */
1038 u_long tqe_die; /* when this entriy is to die */
1039 u_long tqe_touched;
1040 int tqe_flags;
1041 int tqe_state[2]; /* current state of this entry */
1042 } ipftqent_t;
1044 #define TQE_RULEBASED 0x00000001
1048 * Timeout tail queue head for IPFilter
1050 typedef struct ipftq {
1051 ipfmutex_t ifq_lock;
1052 u_int ifq_ttl;
1053 ipftqent_t *ifq_head;
1054 ipftqent_t **ifq_tail;
1055 struct ipftq *ifq_next;
1056 struct ipftq **ifq_pnext;
1057 int ifq_ref;
1058 u_int ifq_flags;
1059 } ipftq_t;
1061 #define IFQF_USER 0x01 /* User defined aging */
1062 #define IFQF_DELETE 0x02 /* Marked for deletion */
1063 #define IFQF_PROXY 0x04 /* Timeout queue in use by a proxy */
1065 #define IPF_HZ_MULT 1
1066 #define IPF_HZ_DIVIDE 2 /* How many times a second ipfilter */
1067 /* checks its timeout queues. */
1068 #define IPF_TTLVAL(x) (((x) / IPF_HZ_MULT) * IPF_HZ_DIVIDE)
1070 typedef int (*ipftq_delete_fn_t)(void *);
1073 * Structure to define address for pool lookups.
1075 typedef struct {
1076 u_char adf_len;
1077 i6addr_t adf_addr;
1078 } addrfamily_t;
1082 * Object structure description. For passing through in ioctls.
1084 typedef struct ipfobj {
1085 u_32_t ipfo_rev; /* IPFilter version number */
1086 u_32_t ipfo_size; /* size of object at ipfo_ptr */
1087 void *ipfo_ptr; /* pointer to object */
1088 int ipfo_type; /* type of object being pointed to */
1089 int ipfo_offset; /* bytes from ipfo_ptr where to start */
1090 u_char ipfo_xxxpad[32]; /* reserved for future use */
1091 } ipfobj_t;
1093 #define IPFOBJ_FRENTRY 0 /* struct frentry */
1094 #define IPFOBJ_IPFSTAT 1 /* struct friostat */
1095 #define IPFOBJ_IPFINFO 2 /* struct fr_info */
1096 #define IPFOBJ_AUTHSTAT 3 /* struct fr_authstat */
1097 #define IPFOBJ_FRAGSTAT 4 /* struct ipfrstat */
1098 #define IPFOBJ_IPNAT 5 /* struct ipnat */
1099 #define IPFOBJ_NATSTAT 6 /* struct natstat */
1100 #define IPFOBJ_STATESAVE 7 /* struct ipstate_save */
1101 #define IPFOBJ_NATSAVE 8 /* struct nat_save */
1102 #define IPFOBJ_NATLOOKUP 9 /* struct natlookup */
1103 #define IPFOBJ_IPSTATE 10 /* struct ipstate */
1104 #define IPFOBJ_STATESTAT 11 /* struct ips_stat */
1105 #define IPFOBJ_FRAUTH 12 /* struct frauth */
1106 #define IPFOBJ_TUNEABLE 13 /* struct ipftune */
1107 #define IPFOBJ_NAT 14 /* struct nat */
1108 #define IPFOBJ_IPFITER 15 /* struct ipfruleiter */
1109 #define IPFOBJ_GENITER 16 /* struct ipfgeniter */
1110 #define IPFOBJ_GTABLE 17 /* struct ipftable */
1111 #define IPFOBJ_LOOKUPITER 18 /* struct ipflookupiter */
1112 #define IPFOBJ_STATETQTAB 19 /* struct ipftq [NSTATES] */
1113 #define IPFOBJ_COUNT 20 /* How many #defines are above this? */
1116 typedef union ipftunevalptr {
1117 void *ipftp_void;
1118 u_long *ipftp_long;
1119 u_int *ipftp_int;
1120 u_short *ipftp_short;
1121 u_char *ipftp_char;
1122 } ipftunevalptr_t;
1124 typedef struct ipftuneable {
1125 ipftunevalptr_t ipft_una;
1126 const char *ipft_name;
1127 u_long ipft_min;
1128 u_long ipft_max;
1129 int ipft_sz;
1130 int ipft_flags;
1131 struct ipftuneable *ipft_next;
1132 } ipftuneable_t;
1134 #define ipft_addr ipft_una.ipftp_void
1135 #define ipft_plong ipft_una.ipftp_long
1136 #define ipft_pint ipft_una.ipftp_int
1137 #define ipft_pshort ipft_una.ipftp_short
1138 #define ipft_pchar ipft_una.ipftp_char
1140 #define IPFT_RDONLY 1 /* read-only */
1141 #define IPFT_WRDISABLED 2 /* write when disabled only */
1143 typedef union ipftuneval {
1144 u_long ipftu_long;
1145 u_int ipftu_int;
1146 u_short ipftu_short;
1147 u_char ipftu_char;
1148 } ipftuneval_t;
1150 typedef struct ipftune {
1151 void *ipft_cookie;
1152 ipftuneval_t ipft_un;
1153 u_long ipft_min;
1154 u_long ipft_max;
1155 int ipft_sz;
1156 int ipft_flags;
1157 char ipft_name[80];
1158 } ipftune_t;
1160 #define ipft_vlong ipft_un.ipftu_long
1161 #define ipft_vint ipft_un.ipftu_int
1162 #define ipft_vshort ipft_un.ipftu_short
1163 #define ipft_vchar ipft_un.ipftu_char
1168 typedef struct ipfruleiter {
1169 int iri_inout;
1170 char iri_group[FR_GROUPLEN];
1171 int iri_active;
1172 int iri_nrules;
1173 int iri_v;
1174 frentry_t *iri_rule;
1175 } ipfruleiter_t;
1178 * Values for iri_inout
1180 #define F_IN 0
1181 #define F_OUT 1
1182 #define F_ACIN 2
1183 #define F_ACOUT 3
1186 typedef struct ipfgeniter {
1187 int igi_type;
1188 int igi_nitems;
1189 void *igi_data;
1190 } ipfgeniter_t;
1192 #define IPFGENITER_IPF 0
1193 #define IPFGENITER_NAT 1
1194 #define IPFGENITER_IPNAT 2
1195 #define IPFGENITER_FRAG 3
1196 #define IPFGENITER_AUTH 4
1197 #define IPFGENITER_STATE 5
1198 #define IPFGENITER_NATFRAG 6
1199 #define IPFGENITER_HOSTMAP 7
1200 #define IPFGENITER_LOOKUP 8
1202 typedef struct ipftable {
1203 int ita_type;
1204 void *ita_table;
1205 } ipftable_t;
1207 #define IPFTABLE_BUCKETS 1
1208 #define IPFTABLE_BUCKETS_NATIN 2
1209 #define IPFTABLE_BUCKETS_NATOUT 3
1215 typedef struct ipftoken {
1216 struct ipftoken *ipt_next;
1217 struct ipftoken **ipt_pnext;
1218 void *ipt_ctx;
1219 void *ipt_data;
1220 u_long ipt_die;
1221 int ipt_type;
1222 int ipt_uid;
1223 int ipt_subtype;
1224 int ipt_ref;
1225 } ipftoken_t;
1229 ** HPUX Port
1231 #ifdef __hpux
1232 /* HP-UX locking sequence deadlock detection module lock MAJOR ID */
1233 # define IPF_SMAJ 0 /* temp assignment XXX, not critical */
1234 #endif
1236 #if !defined(CDEV_MAJOR) && defined (__FreeBSD_version) && \
1237 (__FreeBSD_version >= 220000)
1238 # define CDEV_MAJOR 79
1239 #endif
1242 * Post NetBSD 1.2 has the PFIL interface for packet filters. This turns
1243 * on those hooks. We don't need any special mods in non-IP Filter code
1244 * with this!
1246 #if (defined(NetBSD) && (NetBSD > 199609) && (NetBSD <= 1991011)) || \
1247 (defined(NetBSD1_2) && NetBSD1_2 > 1) || \
1248 (defined(__FreeBSD__) && (__FreeBSD_version >= 500043))
1249 # if (NetBSD >= 199905)
1250 # define PFIL_HOOKS
1251 # endif
1252 # ifdef PFIL_HOOKS
1253 # define NETBSD_PF
1254 # endif
1255 #endif
1257 #ifdef _KERNEL
1258 # define FR_VERBOSE(verb_pr)
1259 # define FR_DEBUG(verb_pr)
1260 #else
1261 extern void debug __P((char *, ...));
1262 extern void verbose __P((char *, ...));
1263 # define FR_VERBOSE(verb_pr) verbose verb_pr
1264 # define FR_DEBUG(verb_pr) debug verb_pr
1265 #endif
1268 #ifndef _KERNEL
1269 extern int fr_check __P((struct ip *, int, void *, int, mb_t **));
1270 extern int (*fr_checkp) __P((ip_t *, int, void *, int, mb_t **));
1271 extern int ipf_log __P((void));
1272 extern struct ifnet *get_unit __P((char *, int));
1273 extern char *get_ifname __P((struct ifnet *));
1274 # if defined(__NetBSD__) || defined(__OpenBSD__) || \
1275 (_BSDI_VERSION >= 199701) || (__FreeBSD_version >= 300000)
1276 extern int iplioctl __P((int, ioctlcmd_t, void *, int));
1277 # else
1278 extern int iplioctl __P((int, ioctlcmd_t, void *, int));
1279 # endif
1280 extern int iplopen __P((dev_t, int));
1281 extern int iplclose __P((dev_t, int));
1282 extern void m_freem __P((mb_t *));
1283 extern int bcopywrap __P((void *, void *, size_t));
1284 #else /* #ifndef _KERNEL */
1285 # ifdef BSD
1286 # if (defined(__NetBSD__) && (__NetBSD_Version__ < 399000000)) || \
1287 defined(__osf__) || \
1288 (defined(__FreeBSD_version) && (__FreeBSD_version < 500043))
1289 # include <sys/select.h>
1290 # else
1291 # include <sys/selinfo.h>
1292 # endif
1293 extern struct selinfo ipfselwait[IPL_LOGSIZE];
1294 # endif
1295 # if defined(__NetBSD__) && defined(PFIL_HOOKS)
1296 extern void ipfilterattach __P((int));
1297 # endif
1298 extern int ipl_enable __P((void));
1299 extern int ipl_disable __P((void));
1300 extern int ipf_inject __P((fr_info_t *, mb_t *));
1301 # ifdef MENTAT
1302 extern int fr_check __P((struct ip *, int, void *, int, void *,
1303 mblk_t **));
1304 # if SOLARIS
1305 # if SOLARIS2 >= 7
1306 extern int iplioctl __P((dev_t, int, intptr_t, int, cred_t *, int *));
1307 # else
1308 extern int iplioctl __P((dev_t, int, int *, int, cred_t *, int *));
1309 # endif
1310 extern int iplopen __P((dev_t *, int, int, cred_t *));
1311 extern int iplclose __P((dev_t, int, int, cred_t *));
1312 extern int iplread __P((dev_t, uio_t *, cred_t *));
1313 extern int iplwrite __P((dev_t, uio_t *, cred_t *));
1314 # endif
1315 # ifdef __hpux
1316 extern int iplopen __P((dev_t, int, intptr_t, int));
1317 extern int iplclose __P((dev_t, int, int));
1318 extern int iplioctl __P((dev_t, int, void *, int));
1319 extern int iplread __P((dev_t, uio_t *));
1320 extern int iplwrite __P((dev_t, uio_t *));
1321 extern int iplselect __P((dev_t, int));
1322 # endif
1323 extern int fr_qout __P((queue_t *, mblk_t *));
1324 # else /* MENTAT */
1325 extern int fr_check __P((struct ip *, int, void *, int, mb_t **));
1326 extern int (*fr_checkp) __P((ip_t *, int, void *, int, mb_t **));
1327 extern size_t mbufchainlen __P((mb_t *));
1328 # ifdef __sgi
1329 # include <sys/cred.h>
1330 extern int iplioctl __P((dev_t, int, void *, int, cred_t *, int *));
1331 extern int iplopen __P((dev_t *, int, int, cred_t *));
1332 extern int iplclose __P((dev_t, int, int, cred_t *));
1333 extern int iplread __P((dev_t, uio_t *, cred_t *));
1334 extern int iplwrite __P((dev_t, uio_t *, cred_t *));
1335 extern int ipfilter_sgi_attach __P((void));
1336 extern void ipfilter_sgi_detach __P((void));
1337 extern void ipfilter_sgi_intfsync __P((void));
1338 # else
1339 # ifdef IPFILTER_LKM
1340 extern int iplidentify __P((char *));
1341 # endif
1342 # if (defined(_BSDI_VERSION) && (_BSDI_VERSION >= 199510)) || \
1343 (defined(__FreeBSD_version) && (__FreeBSD_version >= 220000)) || \
1344 (defined(NetBSD) && (NetBSD >= 199511)) || defined(__OpenBSD__)
1345 # if defined(__NetBSD__) || (_BSDI_VERSION >= 199701) || \
1346 defined(__OpenBSD__) || (__FreeBSD_version >= 300000)
1347 # if (__FreeBSD_version >= 500024)
1348 # if (__FreeBSD_version >= 502116)
1349 extern int iplioctl __P((struct cdev*, u_long, void *, int, struct thread *));
1350 # else
1351 extern int iplioctl __P((dev_t, u_long, void *, int, struct thread *));
1352 # endif /* __FreeBSD_version >= 502116 */
1353 # else
1354 # if (__NetBSD_Version__ >= 499001000)
1355 extern int iplioctl __P((dev_t, u_long, void *, int, struct lwp *));
1356 # else
1357 # if (__NetBSD_Version__ >= 399001400)
1358 extern int iplioctl __P((dev_t, u_long, caddr_t, int, struct lwp *));
1359 # else
1360 extern int iplioctl __P((dev_t, u_long, caddr_t, int, struct proc *));
1361 # endif
1362 # endif
1363 # endif /* __FreeBSD_version >= 500024 */
1364 # else
1365 extern int iplioctl __P((dev_t, int, void *, int, struct lwp *));
1366 # endif
1367 # if (__FreeBSD_version >= 500024)
1368 # if (__FreeBSD_version >= 502116)
1369 extern int iplopen __P((struct cdev*, int, int, struct thread *));
1370 extern int iplclose __P((struct cdev*, int, int, struct thread *));
1371 # else
1372 extern int iplopen __P((dev_t, int, int, struct thread *));
1373 extern int iplclose __P((dev_t, int, int, struct thread *));
1374 # endif /* __FreeBSD_version >= 502116 */
1375 # else
1376 # if (__NetBSD_Version__ >= 399001400)
1377 extern int iplopen __P((dev_t, int, int, struct lwp *));
1378 extern int iplclose __P((dev_t, int, int, struct lwp *));
1379 # else
1380 extern int iplopen __P((dev_t, int, int, struct proc *));
1381 extern int iplclose __P((dev_t, int, int, struct proc *));
1382 # endif /* __NetBSD_Version__ >= 399001400 */
1383 # endif /* __FreeBSD_version >= 500024 */
1384 # else
1385 # ifdef linux
1386 extern int iplioctl __P((struct inode *, struct file *, u_int, u_long));
1387 # else
1388 extern int iplopen __P((dev_t, int));
1389 extern int iplclose __P((dev_t, int));
1390 extern int iplioctl __P((dev_t, int, void *, int));
1391 # endif
1392 # endif /* (_BSDI_VERSION >= 199510) */
1393 # if defined(BSD) && (BSD >= 199306)
1394 # if (__FreeBSD_version >= 502116)
1395 extern int iplread __P((struct cdev*, struct uio *, int));
1396 extern int iplwrite __P((struct cdev*, struct uio *, int));
1397 # else
1398 extern int iplread __P((dev_t, struct uio *, int));
1399 extern int iplwrite __P((dev_t, struct uio *, int));
1400 # endif /* __FreeBSD_version >= 502116 */
1401 # else
1402 # ifndef linux
1403 extern int iplread __P((dev_t, struct uio *));
1404 extern int iplwrite __P((dev_t, struct uio *));
1405 # endif
1406 # endif /* BSD >= 199306 */
1407 # endif /* __ sgi */
1408 # endif /* MENTAT */
1410 # if defined(__FreeBSD_version)
1411 extern int ipf_pfil_hook __P((void));
1412 extern int ipf_pfil_unhook __P((void));
1413 extern void ipf_event_reg __P((void));
1414 extern void ipf_event_dereg __P((void));
1415 # endif
1417 #endif /* #ifndef _KERNEL */
1419 extern ipfmutex_t ipl_mutex, ipf_authmx, ipf_rw, ipf_hostmap;
1420 extern ipfmutex_t ipf_timeoutlock, ipf_stinsert, ipf_natio, ipf_nat_new;
1421 extern ipfrwlock_t ipf_mutex, ipf_global, ip_poolrw, ipf_ipidfrag;
1422 extern ipfrwlock_t ipf_frag, ipf_state, ipf_nat, ipf_natfrag, ipf_auth;
1423 extern ipfrwlock_t ipf_frcache, ipf_tokens;
1425 extern char *memstr __P((const char *, char *, size_t, size_t));
1426 extern int count4bits __P((u_32_t));
1427 extern int frrequest __P((int, ioctlcmd_t, void *, int, int));
1428 extern char *getifname __P((struct ifnet *));
1429 extern int ipfattach __P((void));
1430 extern int ipfdetach __P((void));
1431 extern u_short ipf_cksum __P((u_short *, int));
1432 extern int copyinptr __P((void *, void *, size_t));
1433 extern int copyoutptr __P((void *, void *, size_t));
1434 extern int fr_fastroute __P((mb_t *, mb_t **, fr_info_t *, frdest_t *));
1435 extern int fr_inobj __P((void *, void *, int));
1436 extern int fr_inobjsz __P((void *, void *, int, int));
1437 extern int fr_ioctlswitch __P((int, void *, ioctlcmd_t, int, int, void *));
1438 extern int fr_ipf_ioctl __P((void *, ioctlcmd_t, int, int, void *));
1439 extern int fr_ipftune __P((ioctlcmd_t, void *));
1440 extern int fr_outobj __P((void *, void *, int));
1441 extern int fr_outobjsz __P((void *, void *, int, int));
1442 extern void *fr_pullup __P((mb_t *, fr_info_t *, int));
1443 extern void fr_resolvedest __P((struct frdest *, int));
1444 extern int fr_resolvefunc __P((void *));
1445 extern void *fr_resolvenic __P((char *, int));
1446 extern int fr_send_icmp_err __P((int, fr_info_t *, int));
1447 extern int fr_send_reset __P((fr_info_t *));
1448 #if (defined(__FreeBSD_version) && (__FreeBSD_version < 501000)) || \
1449 !defined(_KERNEL) || defined(linux)
1450 extern int ppsratecheck __P((struct timeval *, int *, int));
1451 #endif
1452 extern ipftq_t *fr_addtimeoutqueue __P((ipftq_t **, u_int));
1453 extern void fr_deletequeueentry __P((ipftqent_t *));
1454 extern int fr_deletetimeoutqueue __P((ipftq_t *));
1455 extern void fr_freetimeoutqueue __P((ipftq_t *));
1456 extern void fr_movequeue __P((ipftqent_t *, ipftq_t *, ipftq_t *));
1457 extern void fr_queueappend __P((ipftqent_t *, ipftq_t *, void *));
1458 extern void fr_queueback __P((ipftqent_t *));
1459 extern void fr_queuefront __P((ipftqent_t *));
1460 extern void fr_checkv4sum __P((fr_info_t *));
1461 extern int fr_checkl4sum __P((fr_info_t *));
1462 extern int fr_ifpfillv4addr __P((int, struct sockaddr_in *,
1463 struct sockaddr_in *, struct in_addr *,
1464 struct in_addr *));
1465 extern int fr_coalesce __P((fr_info_t *));
1466 #ifdef USE_INET6
1467 extern void fr_checkv6sum __P((fr_info_t *));
1468 extern int fr_ifpfillv6addr __P((int, struct sockaddr_in6 *,
1469 struct sockaddr_in6 *, struct in_addr *,
1470 struct in_addr *));
1471 #endif
1473 extern int fr_addipftune __P((ipftuneable_t *));
1474 extern int fr_delipftune __P((ipftuneable_t *));
1476 extern int frflush __P((minor_t, int, int));
1477 extern void frsync __P((void *));
1478 extern frgroup_t *fr_addgroup __P((char *, void *, u_32_t, minor_t, int));
1479 extern int fr_derefrule __P((frentry_t **));
1480 extern void fr_delgroup __P((char *, minor_t, int));
1481 extern frgroup_t *fr_findgroup __P((char *, minor_t, int, frgroup_t ***));
1483 extern int fr_loginit __P((void));
1484 extern int ipflog_canread __P((int));
1485 extern int ipflog_clear __P((minor_t));
1486 extern int ipflog_read __P((minor_t, uio_t *));
1487 extern int ipflog __P((fr_info_t *, u_int));
1488 extern int ipllog __P((int, fr_info_t *, void **, size_t *, int *, int));
1489 extern void fr_logunload __P((void));
1491 extern frentry_t *fr_acctpkt __P((fr_info_t *, u_32_t *));
1492 extern int fr_copytolog __P((int, char *, int));
1493 extern u_short fr_cksum __P((mb_t *, ip_t *, int, void *, int));
1494 extern void fr_deinitialise __P((void));
1495 extern frentry_t *fr_dolog __P((fr_info_t *, u_32_t *));
1496 extern frentry_t *fr_dstgrpmap __P((fr_info_t *, u_32_t *));
1497 extern void fr_fixskip __P((frentry_t **, frentry_t *, int));
1498 extern void fr_forgetifp __P((void *));
1499 extern frentry_t *fr_getrulen __P((int, char *, u_32_t));
1500 extern void fr_getstat __P((struct friostat *));
1501 extern int fr_ifpaddr __P((int, int, void *,
1502 struct in_addr *, struct in_addr *));
1503 extern int fr_initialise __P((void));
1504 extern int fr_lock __P((void *, int *));
1505 extern int fr_makefrip __P((int, ip_t *, fr_info_t *));
1506 extern int fr_matchtag __P((ipftag_t *, ipftag_t *));
1507 extern int fr_matchicmpqueryreply __P((int, icmpinfo_t *,
1508 struct icmp *, int));
1509 extern u_32_t fr_newisn __P((fr_info_t *));
1510 extern u_short fr_nextipid __P((fr_info_t *));
1511 extern int ipf_queueflush __P((ipftq_delete_fn_t, ipftq_t *, ipftq_t *));
1512 extern int fr_scanlist __P((fr_info_t *, u_32_t));
1513 extern frentry_t *fr_srcgrpmap __P((fr_info_t *, u_32_t *));
1514 extern int fr_tcpudpchk __P((fr_info_t *, frtuc_t *));
1515 extern int fr_verifysrc __P((fr_info_t *fin));
1516 extern int fr_zerostats __P((void *));
1517 extern ipftoken_t *ipf_findtoken __P((int, int, void *));
1518 extern void ipf_dereftoken __P((ipftoken_t *));
1519 extern int ipf_getnextrule __P((ipftoken_t *, void *));
1520 extern void ipf_expiretokens __P((void));
1521 extern void ipf_freetoken __P((ipftoken_t *));
1522 extern int ipf_deltoken __P((int,int, void *));
1523 extern int ipfsync __P((void));
1524 extern int ipf_genericiter __P((void *, int, void *));
1525 #ifndef ipf_random
1526 extern u_32_t ipf_random __P((void));
1527 #endif
1528 #ifdef NEED_LOCAL_RAND
1529 extern void ipf_rand_push __P((void *, int));
1530 #endif
1532 extern int fr_running;
1533 extern u_long fr_frouteok[2];
1534 extern int fr_pass;
1535 extern int fr_flags;
1536 extern int fr_active;
1537 extern int fr_chksrc;
1538 extern int fr_minttl;
1539 extern int fr_refcnt;
1540 extern int fr_control_forwarding;
1541 extern int fr_update_ipid;
1542 extern int nat_logging;
1543 extern int ipstate_logging;
1544 extern int ipl_suppress;
1545 extern int ipl_logmax;
1546 extern int ipl_logall;
1547 extern int ipl_logsize;
1548 extern u_long fr_ticks;
1549 extern fr_info_t frcache[2][8];
1550 extern char ipfilter_version[];
1551 extern iplog_t **iplh[IPL_LOGSIZE], *iplt[IPL_LOGSIZE];
1552 extern int iplused[IPL_LOGMAX + 1];
1553 extern struct frentry *ipfilter[2][2], *ipacct[2][2];
1554 #ifdef USE_INET6
1555 extern struct frentry *ipfilter6[2][2], *ipacct6[2][2];
1556 extern int icmptoicmp6types[ICMP_MAXTYPE+1];
1557 extern int icmptoicmp6unreach[ICMP_MAX_UNREACH];
1558 extern int icmpreplytype6[ICMP6_MAXTYPE + 1];
1559 #endif
1560 extern int icmpreplytype4[ICMP_MAXTYPE + 1];
1561 extern struct frgroup *ipfgroups[IPL_LOGSIZE][2];
1562 extern struct filterstats frstats[];
1563 extern frentry_t *ipfrule_match __P((fr_info_t *));
1564 extern u_char ipf_iss_secret[32];
1565 extern ipftuneable_t ipf_tuneables[];
1567 #endif /* _NETINET_IP_FIL_H_ */