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