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