Merge from vendor branch AWK:
[dragonfly.git] / contrib / ipfilter / ip_fil.h
1 /*
2  * Copyright (C) 1993-2002 by Darren Reed.
3  *
4  * See the IPFILTER.LICENCE file for details on licencing.
5  *
6  * @(#)ip_fil.h 1.35 6/5/96
7  * $Id: ip_fil.h,v 2.29.2.34 2002/10/01 15:23:37 darrenr Exp $
8  */
9
10 #ifndef __IP_FIL_H__
11 #define __IP_FIL_H__
12
13 /*
14  * Pathnames for various IP Filter control devices.  Used by LKM
15  * and userland, so defined here.
16  */
17 #define IPNAT_NAME      "/dev/ipnat"
18 #define IPSTATE_NAME    "/dev/ipstate"
19 #define IPAUTH_NAME     "/dev/ipauth"
20
21 #ifndef SOLARIS
22 # define SOLARIS (defined(sun) && (defined(__svr4__) || defined(__SVR4)))
23 #endif
24
25 #if defined(KERNEL) && !defined(_KERNEL)
26 # define        _KERNEL
27 #endif
28
29 #ifndef __P
30 # ifdef __STDC__
31 #  define       __P(x)  x
32 # else
33 #  define       __P(x)  ()
34 # endif
35 #endif
36
37 #ifndef offsetof
38 # define        offsetof(t,m)   (int)((&((t *)0L)->m))
39 #endif
40
41 #if defined(__STDC__) || defined(__GNUC__)
42 # define        SIOCADAFR       _IOW('r', 60, struct frentry *)
43 # define        SIOCRMAFR       _IOW('r', 61, struct frentry *)
44 # define        SIOCSETFF       _IOW('r', 62, u_int)
45 # define        SIOCGETFF       _IOR('r', 63, u_int)
46 # define        SIOCGETFS       _IOWR('r', 64, struct friostat *)
47 # define        SIOCIPFFL       _IOWR('r', 65, int)
48 # define        SIOCIPFFB       _IOR('r', 66, int)
49 # define        SIOCADIFR       _IOW('r', 67, struct frentry *)
50 # define        SIOCRMIFR       _IOW('r', 68, struct frentry *)
51 # define        SIOCSWAPA       _IOR('r', 69, u_int)
52 # define        SIOCINAFR       _IOW('r', 70, struct frentry *)
53 # define        SIOCINIFR       _IOW('r', 71, struct frentry *)
54 # define        SIOCFRENB       _IOW('r', 72, u_int)
55 # define        SIOCFRSYN       _IOW('r', 73, u_int)
56 # define        SIOCFRZST       _IOWR('r', 74, struct friostat *)
57 # define        SIOCZRLST       _IOWR('r', 75, struct frentry *)
58 # define        SIOCAUTHW       _IOWR('r', 76, struct frauth *)
59 # define        SIOCAUTHR       _IOWR('r', 77, struct frauth *)
60 # define        SIOCATHST       _IOWR('r', 78, struct fr_authstat *)
61 # define        SIOCSTLCK       _IOWR('r', 79, u_int)
62 # define        SIOCSTPUT       _IOWR('r', 80, struct ipstate_save *)
63 # define        SIOCSTGET       _IOWR('r', 81, struct ipstate_save *)
64 # define        SIOCSTGSZ       _IOWR('r', 82, struct natget)
65 # define        SIOCGFRST       _IOWR('r', 83, struct ipfrstat *)
66 # define        SIOCIPFL6       _IOWR('r', 84, int)
67 #else
68 # define        SIOCADAFR       _IOW(r, 60, struct frentry *)
69 # define        SIOCRMAFR       _IOW(r, 61, struct frentry *)
70 # define        SIOCSETFF       _IOW(r, 62, u_int)
71 # define        SIOCGETFF       _IOR(r, 63, u_int)
72 # define        SIOCGETFS       _IOWR(r, 64, struct friostat *)
73 # define        SIOCIPFFL       _IOWR(r, 65, int)
74 # define        SIOCIPFFB       _IOR(r, 66, int)
75 # define        SIOCADIFR       _IOW(r, 67, struct frentry *)
76 # define        SIOCRMIFR       _IOW(r, 68, struct frentry *)
77 # define        SIOCSWAPA       _IOR(r, 69, u_int)
78 # define        SIOCINAFR       _IOW(r, 70, struct frentry *)
79 # define        SIOCINIFR       _IOW(r, 71, struct frentry *)
80 # define        SIOCFRENB       _IOW(r, 72, u_int)
81 # define        SIOCFRSYN       _IOW(r, 73, u_int)
82 # define        SIOCFRZST       _IOWR(r, 74, struct friostat *)
83 # define        SIOCZRLST       _IOWR(r, 75, struct frentry *)
84 # define        SIOCAUTHW       _IOWR(r, 76, struct frauth *)
85 # define        SIOCAUTHR       _IOWR(r, 77, struct frauth *)
86 # define        SIOCATHST       _IOWR(r, 78, struct fr_authstat *)
87 # define        SIOCSTLCK       _IOWR(r, 79, u_int)
88 # define        SIOCSTPUT       _IOWR(r, 80, struct ipstate_save *)
89 # define        SIOCSTGET       _IOWR(r, 81, struct ipstate_save *)
90 # define        SIOCSTGSZ       _IOWR(r, 82, struct natget)
91 # define        SIOCGFRST       _IOWR(r, 83, struct ipfrstat *)
92 # define        SIOCIPFL6       _IOWR(r, 84, int)
93 #endif
94 #define SIOCADDFR       SIOCADAFR
95 #define SIOCDELFR       SIOCRMAFR
96 #define SIOCINSFR       SIOCINAFR
97
98
99 typedef struct  fr_ip   {
100         u_32_t  fi_v:4;         /* IP version */
101         u_32_t  fi_fl:4;        /* packet flags */
102         u_32_t  fi_tos:8;       /* IP packet TOS */
103         u_32_t  fi_ttl:8;       /* IP packet TTL */
104         u_32_t  fi_p:8;         /* IP packet protocol */
105         union   i6addr fi_src;  /* source address from packet */
106         union   i6addr fi_dst;  /* destination address from packet */
107         u_32_t  fi_optmsk;      /* bitmask composed from IP options */
108         u_short fi_secmsk;      /* bitmask composed from IP security options */
109         u_short fi_auth;        /* authentication code from IP sec. options */
110 } fr_ip_t;
111
112 #define FI_OPTIONS      (FF_OPTIONS >> 24)
113 #define FI_TCPUDP       (FF_TCPUDP >> 24)       /* TCP/UCP implied comparison*/
114 #define FI_FRAG         (FF_FRAG >> 24)
115 #define FI_SHORT        (FF_SHORT >> 24)
116 #define FI_CMP          (FI_OPTIONS|FI_TCPUDP|FI_SHORT)
117
118 #define fi_saddr        fi_src.in4.s_addr
119 #define fi_daddr        fi_dst.in4.s_addr
120
121
122 /*
123  * These are both used by the state and NAT code to indicate that one port or
124  * the other should be treated as a wildcard.
125  */
126 #define FI_W_SPORT      0x00000100
127 #define FI_W_DPORT      0x00000200
128 #define FI_WILDP        (FI_W_SPORT|FI_W_DPORT)
129 #define FI_W_SADDR      0x00000400
130 #define FI_W_DADDR      0x00000800
131 #define FI_WILDA        (FI_W_SADDR|FI_W_DADDR)
132 #define FI_NEWFR        0x00001000      /* Create a filter rule */
133 #define FI_IGNOREPKT    0x00002000      /* Do not treat as a real packet */
134 #define FI_NORULE       0x00004000      /* Not direct a result of a rule */
135
136 typedef struct  fr_info {
137         void    *fin_ifp;               /* interface packet is `on' */
138         struct  fr_ip   fin_fi;         /* IP Packet summary */
139         u_short fin_data[2];            /* TCP/UDP ports, ICMP code/type */
140         u_int   fin_out;                /* in or out ? 1 == out, 0 == in */
141         u_short fin_hlen;               /* length of IP header in bytes */
142         u_char  fin_rev;                /* state only: 1 = reverse */
143         u_char  fin_tcpf;               /* TCP header flags (SYN, ACK, etc) */
144         u_int   fin_icode;              /* ICMP error to return */
145         u_32_t  fin_rule;               /* rule # last matched */
146         u_32_t  fin_group;              /* group number, -1 for none */
147         struct  frentry *fin_fr;        /* last matching rule */
148         char    *fin_dp;                /* start of data past IP header */
149         u_short fin_plen;
150         u_short fin_off;
151         u_short fin_dlen;               /* length of data portion of packet */
152         u_short fin_id;                 /* IP packet id field */
153         u_int   fin_misc;
154         void    *fin_mp;                /* pointer to pointer to mbuf */
155 #if SOLARIS
156         void    *fin_qfm;               /* pointer to mblk where pkt starts */
157         void    *fin_qif;
158 #endif
159 } fr_info_t;
160
161 #define fin_v           fin_fi.fi_v
162 #define fin_p           fin_fi.fi_p
163 #define fin_saddr       fin_fi.fi_saddr
164 #define fin_src         fin_fi.fi_src.in4
165 #define fin_daddr       fin_fi.fi_daddr
166 #define fin_dst         fin_fi.fi_dst.in4
167 #define fin_fl          fin_fi.fi_fl
168
169 /*
170  * Size for compares on fr_info structures
171  */
172 #define FI_CSIZE        offsetof(fr_info_t, fin_icode)
173 #define FI_LCSIZE       offsetof(fr_info_t, fin_dp)
174
175 /*
176  * For fin_misc
177  */
178 #define FM_BADSTATE     0x00000001
179
180 /*
181  * Size for copying cache fr_info structure
182  */
183 #define FI_COPYSIZE     offsetof(fr_info_t, fin_dp)
184
185 typedef struct  frdest  {
186         void    *fd_ifp;
187         union   i6addr  fd_ip6;
188         char    fd_ifname[LIFNAMSIZ];
189 #if SOLARIS
190         mb_t    *fd_mp;                 /* cache resolver for to/dup-to */
191 #endif
192 } frdest_t;
193
194 #define fd_ip   fd_ip6.in4
195
196
197 typedef struct  frpcmp  {
198         int     frp_cmp;        /* data for port comparisons */
199         u_short frp_port;       /* top port for <> and >< */
200         u_short frp_top;        /* top port for <> and >< */
201 } frpcmp_t;
202
203 typedef struct  frtuc   {
204         u_char  ftu_tcpfm;      /* tcp flags mask */
205         u_char  ftu_tcpf;       /* tcp flags */
206         frpcmp_t        ftu_src;
207         frpcmp_t        ftu_dst;
208 } frtuc_t;
209
210 #define ftu_scmp        ftu_src.frp_cmp
211 #define ftu_dcmp        ftu_dst.frp_cmp
212 #define ftu_sport       ftu_src.frp_port
213 #define ftu_dport       ftu_dst.frp_port
214 #define ftu_stop        ftu_src.frp_top
215 #define ftu_dtop        ftu_dst.frp_top
216
217 typedef struct  frentry {
218         struct  frentry *fr_next;
219         struct  frentry *fr_grp;
220         int     fr_ref;         /* reference count - for grouping */
221         void    *fr_ifas[4];
222         /*
223          * These are only incremented when a packet  matches this rule and
224          * it is the last match
225          */
226         U_QUAD_T        fr_hits;
227         U_QUAD_T        fr_bytes;
228         /*
229          * Fields after this may not change whilst in the kernel.
230          */
231         struct  fr_ip   fr_ip;
232         struct  fr_ip   fr_mip; /* mask structure */
233
234
235         u_short fr_icmpm;       /* data for ICMP packets (mask) */
236         u_short fr_icmp;
237
238         u_int   fr_age[2];      /* aging for state */
239         frtuc_t fr_tuc;
240         u_32_t  fr_group;       /* group to which this rule belongs */
241         u_32_t  fr_grhead;      /* group # which this rule starts */
242         u_32_t  fr_flags;       /* per-rule flags && options (see below) */
243         u_int   fr_skip;        /* # of rules to skip */
244         u_int   fr_loglevel;    /* syslog log facility + priority */
245         int     (*fr_func) __P((int, ip_t *, fr_info_t *));     /* call this function */
246         int     fr_sap;         /* For solaris only */
247         u_char  fr_icode;       /* return ICMP code */
248         char    fr_ifnames[4][LIFNAMSIZ];
249         struct  frdest  fr_tif; /* "to" interface */
250         struct  frdest  fr_dif; /* duplicate packet interfaces */
251         u_int   fr_cksum;       /* checksum on filter rules for performance */
252 } frentry_t;
253
254 #define fr_v            fr_ip.fi_v
255 #define fr_proto        fr_ip.fi_p
256 #define fr_ttl          fr_ip.fi_ttl
257 #define fr_tos          fr_ip.fi_tos
258 #define fr_tcpfm        fr_tuc.ftu_tcpfm
259 #define fr_tcpf         fr_tuc.ftu_tcpf
260 #define fr_scmp         fr_tuc.ftu_scmp
261 #define fr_dcmp         fr_tuc.ftu_dcmp
262 #define fr_dport        fr_tuc.ftu_dport
263 #define fr_sport        fr_tuc.ftu_sport
264 #define fr_stop         fr_tuc.ftu_stop
265 #define fr_dtop         fr_tuc.ftu_dtop
266 #define fr_dst          fr_ip.fi_dst.in4
267 #define fr_src          fr_ip.fi_src.in4
268 #define fr_dmsk         fr_mip.fi_dst.in4
269 #define fr_smsk         fr_mip.fi_src.in4
270 #define fr_ifname       fr_ifnames[0]
271 #define fr_oifname      fr_ifnames[2]
272 #define fr_ifa          fr_ifas[0]
273 #define fr_oifa         fr_ifas[2]
274
275 #define FR_CMPSIZ       (sizeof(struct frentry) - offsetof(frentry_t, fr_ip))
276
277 /*
278  * fr_flags
279  */
280 #define FR_BLOCK        0x00001 /* do not allow packet to pass */
281 #define FR_PASS         0x00002 /* allow packet to pass */
282 #define FR_OUTQUE       0x00004 /* outgoing packets */
283 #define FR_INQUE        0x00008 /* ingoing packets */
284 #define FR_LOG          0x00010 /* Log */
285 #define FR_LOGB         0x00011 /* Log-fail */
286 #define FR_LOGP         0x00012 /* Log-pass */
287 #define FR_NOTSRCIP     0x00020 /* not the src IP# */
288 #define FR_NOTDSTIP     0x00040 /* not the dst IP# */
289 #define FR_RETRST       0x00080 /* Return TCP RST packet - reset connection */
290 #define FR_RETICMP      0x00100 /* Return ICMP unreachable packet */
291 #define FR_FAKEICMP     0x00180 /* Return ICMP unreachable with fake source */
292 #define FR_NOMATCH      0x00200 /* no match occured */
293 #define FR_ACCOUNT      0x00400 /* count packet bytes */
294 #define FR_KEEPFRAG     0x00800 /* keep fragment information */
295 #define FR_KEEPSTATE    0x01000 /* keep `connection' state information */
296 #define FR_INACTIVE     0x02000
297 #define FR_QUICK        0x04000 /* match & stop processing list */
298 #define FR_FASTROUTE    0x08000 /* bypass normal routing */
299 #define FR_CALLNOW      0x10000 /* call another function (fr_func) if matches */
300 #define FR_DUP          0x20000 /* duplicate packet */
301 #define FR_LOGORBLOCK   0x40000 /* block the packet if it can't be logged */
302 #define FR_LOGBODY      0x80000 /* Log the body */
303 #define FR_LOGFIRST     0x100000        /* Log the first byte if state held */
304 #define FR_AUTH         0x200000        /* use authentication */
305 #define FR_PREAUTH      0x400000        /* require preauthentication */
306 #define FR_DONTCACHE    0x800000        /* don't cache the result */
307
308 #define FR_LOGMASK      (FR_LOG|FR_LOGP|FR_LOGB)
309 #define FR_RETMASK      (FR_RETICMP|FR_RETRST|FR_FAKEICMP)
310
311 /*
312  * These correspond to #define's for FI_* and are stored in fr_flags
313  */
314 #define FF_OPTIONS      0x01000000
315 #define FF_TCPUDP       0x02000000
316 #define FF_FRAG         0x04000000
317 #define FF_SHORT        0x08000000
318 /*
319  * recognized flags for SIOCGETFF and SIOCSETFF, and get put in fr_flags
320  */
321 #define FF_LOGPASS      0x10000000
322 #define FF_LOGBLOCK     0x20000000
323 #define FF_LOGNOMATCH   0x40000000
324 #define FF_LOGGING      (FF_LOGPASS|FF_LOGBLOCK|FF_LOGNOMATCH)
325 #define FF_BLOCKNONIP   0x80000000      /* Solaris2 Only */
326
327 #define FR_NONE 0
328 #define FR_EQUAL 1
329 #define FR_NEQUAL 2
330 #define FR_LESST 3
331 #define FR_GREATERT 4
332 #define FR_LESSTE 5
333 #define FR_GREATERTE 6
334 #define FR_OUTRANGE 7
335 #define FR_INRANGE 8
336
337 typedef struct  filterstats {
338         u_long  fr_pass;        /* packets allowed */
339         u_long  fr_block;       /* packets denied */
340         u_long  fr_nom;         /* packets which don't match any rule */
341         u_long  fr_short;       /* packets which are short */
342         u_long  fr_ppkl;        /* packets allowed and logged */
343         u_long  fr_bpkl;        /* packets denied and logged */
344         u_long  fr_npkl;        /* packets unmatched and logged */
345         u_long  fr_pkl;         /* packets logged */
346         u_long  fr_skip;        /* packets to be logged but buffer full */
347         u_long  fr_ret;         /* packets for which a return is sent */
348         u_long  fr_acct;        /* packets for which counting was performed */
349         u_long  fr_bnfr;        /* bad attempts to allocate fragment state */
350         u_long  fr_nfr;         /* new fragment state kept */
351         u_long  fr_cfr;         /* add new fragment state but complete pkt */
352         u_long  fr_bads;        /* bad attempts to allocate packet state */
353         u_long  fr_ads;         /* new packet state kept */
354         u_long  fr_chit;        /* cached hit */
355         u_long  fr_tcpbad;      /* TCP checksum check failures */
356         u_long  fr_pull[2];     /* good and bad pullup attempts */
357         u_long  fr_badsrc;      /* source received doesn't match route */
358         u_long  fr_badttl;      /* TTL in packet doesn't reach minimum */
359 #if SOLARIS
360         u_long  fr_notdata;     /* PROTO/PCPROTO that have no data */
361         u_long  fr_nodata;      /* mblks that have no data */
362         u_long  fr_bad;         /* bad IP packets to the filter */
363         u_long  fr_notip;       /* packets passed through no on ip queue */
364         u_long  fr_drop;        /* packets dropped - no info for them! */
365         u_long  fr_copy;        /* messages copied due to db_ref > 1 */
366 #endif
367         u_long  fr_ipv6[2];     /* IPv6 packets in/out */
368 } filterstats_t;
369
370 /*
371  * For SIOCGETFS
372  */
373 typedef struct  friostat        {
374         struct  filterstats     f_st[2];
375         struct  frentry         *f_fin[2];
376         struct  frentry         *f_fout[2];
377         struct  frentry         *f_acctin[2];
378         struct  frentry         *f_acctout[2];
379         struct  frentry         *f_fin6[2];
380         struct  frentry         *f_fout6[2];
381         struct  frentry         *f_acctin6[2];
382         struct  frentry         *f_acctout6[2];
383         struct  frentry         *f_auth;
384         struct  frgroup         *f_groups[3][2];
385         u_long  f_froute[2];
386         int     f_defpass;      /* default pass - from fr_pass */
387         char    f_active;       /* 1 or 0 - active rule set */
388         char    f_running;      /* 1 if running, else 0 */
389         char    f_logging;      /* 1 if enabled, else 0 */
390         char    f_version[32];  /* version string */
391         int     f_locks[4];
392 } friostat_t;
393
394 typedef struct  optlist {
395         u_short ol_val;
396         int     ol_bit;
397 } optlist_t;
398
399
400 /*
401  * Group list structure.
402  */
403 typedef struct frgroup {
404         u_32_t  fg_num;
405         struct  frgroup *fg_next;
406         struct  frentry *fg_head;
407         struct  frentry **fg_start;
408 } frgroup_t;
409
410
411 /*
412  * Log structure.  Each packet header logged is prepended by one of these.
413  * Following this in the log records read from the device will be an ipflog
414  * structure which is then followed by any packet data.
415  */
416 typedef struct  iplog   {
417         u_32_t          ipl_magic;
418         u_int           ipl_count;
419         struct  timeval ipl_tv;
420         size_t          ipl_dsize;
421         struct  iplog   *ipl_next;
422 } iplog_t;
423
424 #define ipl_sec         ipl_tv.tv_sec
425 #define ipl_usec        ipl_tv.tv_usec
426
427 #define IPL_MAGIC       0x49504c4d /* 'IPLM' */
428 #define IPLOG_SIZE      sizeof(iplog_t)
429
430 typedef struct  ipflog  {
431 #if (defined(NetBSD) && (NetBSD <= 1991011) && (NetBSD >= 199603)) || \
432         (defined(OpenBSD) && (OpenBSD >= 199603))
433         char    fl_ifname[LIFNAMSIZ];
434 #else
435         u_int   fl_unit;
436         char    fl_ifname[LIFNAMSIZ];
437 #endif
438         u_char  fl_plen;        /* extra data after hlen */
439         u_char  fl_hlen;        /* length of IP headers saved */
440         u_short fl_loglevel;    /* syslog log level */
441         u_32_t  fl_rule;
442         u_32_t  fl_group;
443         u_32_t  fl_flags;
444         u_char  fl_dir;
445         u_char  fl_pad[3];
446 } ipflog_t;
447
448
449 #ifndef ICMP_UNREACH_FILTER
450 # define        ICMP_UNREACH_FILTER     13
451 #endif
452
453 #ifndef IPF_LOGGING
454 # define        IPF_LOGGING     0
455 #endif
456 #ifndef IPF_DEFAULT_PASS
457 # define        IPF_DEFAULT_PASS        FR_PASS
458 #endif
459
460 #define IPMINLEN(i, h)  ((i)->ip_len >= ((i)->ip_hl * 4 + sizeof(struct h)))
461 #define IPLLOGSIZE      8192
462
463 #define IPF_OPTCOPY     0x07ff00        /* bit mask of copied options */
464
465 /*
466  * Device filenames for reading log information.  Use ipf on Solaris2 because
467  * ipl is already a name used by something else.
468  */
469 #ifndef IPL_NAME
470 # if    SOLARIS
471 #  define       IPL_NAME        "/dev/ipf"
472 # else
473 #  define       IPL_NAME        "/dev/ipl"
474 # endif
475 #endif
476 #define IPL_NAT         IPNAT_NAME
477 #define IPL_STATE       IPSTATE_NAME
478 #define IPL_AUTH        IPAUTH_NAME
479
480 #define IPL_LOGIPF      0       /* Minor device #'s for accessing logs */
481 #define IPL_LOGNAT      1
482 #define IPL_LOGSTATE    2
483 #define IPL_LOGAUTH     3
484 #define IPL_LOGMAX      3
485
486 #if !defined(CDEV_MAJOR) && defined (__FreeBSD_version) && \
487     (__FreeBSD_version >= 220000)
488 # define        CDEV_MAJOR      79
489 #endif
490
491 /*
492  * Post NetBSD 1.2 has the PFIL interface for packet filters.  This turns
493  * on those hooks.  We don't need any special mods in non-IP Filter code
494  * with this!
495  */
496 #if (defined(NetBSD) && (NetBSD > 199609) && (NetBSD <= 1991011)) || \
497     (defined(NetBSD1_2) && NetBSD1_2 > 1)
498 # if (NetBSD >= 199905)
499 #  define PFIL_HOOKS
500 # endif
501 # ifdef PFIL_HOOKS
502 #  define NETBSD_PF
503 # endif
504 #endif
505
506
507 #ifndef _KERNEL
508 extern  char    *get_ifname __P((struct ifnet *));
509 extern  int     fr_check __P((ip_t *, int, void *, int, mb_t **));
510 extern  int     (*fr_checkp) __P((ip_t *, int, void *, int, mb_t **));
511 extern  int     send_reset __P((ip_t *, fr_info_t *));
512 extern  int     send_icmp_err __P((ip_t *, int, fr_info_t *, int));
513 extern  int     ipf_log __P((void));
514 extern  struct  ifnet *get_unit __P((char *, int));
515 extern  int     mbuflen __P((mb_t *));
516 # if defined(__NetBSD__) || defined(__OpenBSD__) || \
517           (_BSDI_VERSION >= 199701) || (__FreeBSD_version >= 300000)
518 extern  int     iplioctl __P((dev_t, u_long, caddr_t, int));
519 # else
520 extern  int     iplioctl __P((dev_t, int, caddr_t, int));
521 # endif
522 extern  int     iplopen __P((dev_t, int));
523 extern  int     iplclose __P((dev_t, int));
524 #else /* #ifndef _KERNEL */
525 # if defined(__NetBSD__) && defined(PFIL_HOOKS)
526 extern  void    ipfilterattach __P((int));
527 # endif
528 extern  int     iplattach __P((void));
529 extern  int     ipl_enable __P((void));
530 extern  int     ipl_disable __P((void));
531 extern  int     send_icmp_err __P((ip_t *, int, fr_info_t *, int));
532 extern  int     send_reset __P((ip_t *, fr_info_t *));
533 # if    SOLARIS
534 extern  int     fr_check __P((ip_t *, int, void *, int, qif_t *, mb_t **));
535 extern  int     (*fr_checkp) __P((ip_t *, int, void *,
536                                   int, qif_t *, mb_t **));
537 #  if SOLARIS2 >= 7
538 extern  int     iplioctl __P((dev_t, int, intptr_t, int, cred_t *, int *));
539 #  else
540 extern  int     iplioctl __P((dev_t, int, int *, int, cred_t *, int *));
541 #  endif
542 extern  int     iplopen __P((dev_t *, int, int, cred_t *));
543 extern  int     iplclose __P((dev_t, int, int, cred_t *));
544 extern  int     ipfsync __P((void));
545 extern  int     ipfr_fastroute __P((ip_t *, mblk_t *, mblk_t **,
546                                     fr_info_t *, frdest_t *));
547 extern  void    copyin_mblk __P((mblk_t *, size_t, size_t, char *));
548 extern  void    copyout_mblk __P((mblk_t *, size_t, size_t, char *));
549 extern  int     fr_qin __P((queue_t *, mblk_t *));
550 extern  int     fr_qout __P((queue_t *, mblk_t *));
551 extern  int     iplread __P((dev_t, struct uio *, cred_t *));
552 # else /* SOLARIS */
553 extern  int     fr_check __P((ip_t *, int, void *, int, mb_t **));
554 extern  int     (*fr_checkp) __P((ip_t *, int, void *, int, mb_t **));
555 extern  int     ipfr_fastroute __P((mb_t *, mb_t **, fr_info_t *, frdest_t *));
556 extern  size_t  mbufchainlen __P((mb_t *));
557 #  ifdef        __sgi
558 #   include <sys/cred.h>
559 extern  int     iplioctl __P((dev_t, int, caddr_t, int, cred_t *, int *));
560 extern  int     iplopen __P((dev_t *, int, int, cred_t *));
561 extern  int     iplclose __P((dev_t, int, int, cred_t *));
562 extern  int     iplread __P((dev_t, struct uio *, cred_t *));
563 extern  int     ipfsync __P((void));
564 extern  int     ipfilter_sgi_attach __P((void));
565 extern  void    ipfilter_sgi_detach __P((void));
566 extern  void    ipfilter_sgi_intfsync __P((void));
567 #  else
568 #   ifdef       IPFILTER_LKM
569 extern  int     iplidentify __P((char *));
570 #   endif
571 #   if (_BSDI_VERSION >= 199510) || (__FreeBSD_version >= 220000) || \
572       (NetBSD >= 199511) || defined(__OpenBSD__)
573 #    if defined(__NetBSD__) || (_BSDI_VERSION >= 199701) || \
574        defined(__OpenBSD__) || (__FreeBSD_version >= 300000)
575 extern  int     iplioctl __P((dev_t, u_long, caddr_t, int, struct proc *));
576 #    else
577 extern  int     iplioctl __P((dev_t, int, caddr_t, int, struct proc *));
578 #    endif
579 extern  int     iplopen __P((dev_t, int, int, struct proc *));
580 extern  int     iplclose __P((dev_t, int, int, struct proc *));
581 #   else
582 #    ifndef     linux
583 extern  int     iplopen __P((dev_t, int));
584 extern  int     iplclose __P((dev_t, int));
585 extern  int     iplioctl __P((dev_t, int, caddr_t, int));
586 #    else
587 extern  int     iplioctl(struct inode *, struct file *, u_int, u_long);
588 extern  int     iplopen __P((struct inode *, struct file *));
589 extern  void    iplclose __P((struct inode *, struct file *));
590 #    endif /* !linux */
591 #   endif /* (_BSDI_VERSION >= 199510) */
592 #   if  BSD >= 199306
593 extern  int     iplread __P((dev_t, struct uio *, int));
594 #   else
595 #    ifndef linux
596 extern  int     iplread __P((dev_t, struct uio *));
597 #    else
598 extern  int     iplread(struct inode *, struct file *, char *, int);
599 #    endif /* !linux */
600 #   endif /* BSD >= 199306 */
601 #  endif /* __ sgi */
602 # endif /* SOLARIS */
603 #endif /* #ifndef _KERNEL */
604
605 extern  char    *memstr __P((char *, char *, int, int));
606 extern  void    fixskip __P((frentry_t **, frentry_t *, int));
607 extern  int     countbits __P((u_32_t));
608 extern  int     ipldetach __P((void));
609 extern  u_short ipf_cksum __P((u_short *, int));
610 extern  int     ircopyptr __P((void *, void *, size_t));
611 extern  int     iwcopyptr __P((void *, void *, size_t));
612
613 extern  void    ipflog_init __P((void));
614 extern  int     ipflog_clear __P((minor_t));
615 extern  int     ipflog __P((u_int, ip_t *, fr_info_t *, mb_t *));
616 extern  int     ipllog __P((int, fr_info_t *, void **, size_t *, int *, int));
617 extern  int     ipflog_read __P((minor_t, struct uio *));
618
619 extern  int     frflush __P((minor_t, int, int));
620 extern  void    frsync __P((void));
621 extern  frgroup_t *fr_addgroup __P((u_32_t, frentry_t *, minor_t, int));
622 extern  void    fr_delgroup __P((u_32_t, u_32_t, minor_t, int));
623 extern  frgroup_t *fr_findgroup __P((u_32_t, u_32_t, minor_t, int,
624                                     frgroup_t ***));
625
626 extern  int     fr_copytolog __P((int, char *, int));
627 extern  void    fr_forgetifp __P((void *));
628 extern  void    fr_getstat __P((struct friostat *));
629 extern  int     fr_ifpaddr __P((int, void *, struct in_addr *));
630 extern  int     fr_lock __P((caddr_t, int *));
631 extern  void    fr_makefrip __P((int, ip_t *, fr_info_t *));
632 extern  u_short fr_tcpsum __P((mb_t *, ip_t *, tcphdr_t *));
633 extern  int     fr_scanlist __P((u_32_t, ip_t *, fr_info_t *, void *));
634 extern  int     fr_tcpudpchk __P((frtuc_t *, fr_info_t *));
635 extern  int     fr_verifysrc __P((struct in_addr, void *));
636
637 extern  int     ipl_unreach;
638 extern  int     fr_running;
639 extern  u_long  ipl_frouteok[2];
640 extern  int     fr_pass;
641 extern  int     fr_flags;
642 extern  int     fr_active;
643 extern  int     fr_chksrc;
644 extern  int     fr_minttl;
645 extern  int     fr_minttllog;
646 extern  fr_info_t       frcache[2];
647 extern  char    ipfilter_version[];
648 extern  iplog_t **iplh[IPL_LOGMAX+1], *iplt[IPL_LOGMAX+1];
649 extern  size_t  iplused[IPL_LOGMAX + 1];
650 extern  struct frentry *ipfilter[2][2], *ipacct[2][2];
651 #ifdef  USE_INET6
652 extern  struct frentry *ipfilter6[2][2], *ipacct6[2][2];
653 extern  int     icmptoicmp6types[ICMP_MAXTYPE+1];
654 extern  int     icmptoicmp6unreach[ICMP_MAX_UNREACH];
655 #endif
656 extern  struct frgroup *ipfgroups[3][2];
657 extern  struct filterstats frstats[];
658
659 #endif  /* __IP_FIL_H__ */