1 /*
2 * Copyright (C) 2012 by Darren Reed.
3 *
4 * See the IPFILTER.LICENCE file for details on licencing.
5 *
6 * @(#)ip_compat.h 1.8 1/14/96
7 * $FreeBSD$
8 * Id: ip_compat.h,v 2.142.2.57 2007/10/10 09:51:42 darrenr Exp $
9 */
10
11 #ifndef __IP_COMPAT_H__
12 #define __IP_COMPAT_H__
13
14 #if defined(_KERNEL) || defined(KERNEL) || defined(__KERNEL__)
15 # undef KERNEL
16 # undef _KERNEL
17 # undef __KERNEL__
18 # define KERNEL
19 # define _KERNEL
20 # define __KERNEL__
21 #endif
22
23 #ifndef SOLARIS
24 # if defined(sun) && defined(__SVR4)
25 # define SOLARIS 1
26 # else
27 # define SOLARIS 0
28 # endif
29 #endif
30
31
32 #if defined(__SVR4)
33 # define index strchr
34 # if !defined(_KERNEL)
35 # define bzero(a,b) memset(a,0,b)
36 # define bcmp memcmp
37 # define bcopy(a,b,c) memmove(b,a,c)
38 # endif
39 #endif
40
41 #ifndef LIFNAMSIZ
42 # ifdef IF_NAMESIZE
43 # define LIFNAMSIZ IF_NAMESIZE
44 # else
45 # ifdef IFNAMSIZ
46 # define LIFNAMSIZ IFNAMSIZ
47 # else
48 # define LIFNAMSIZ 16
49 # endif
50 # endif
51 #endif
52
53
54 # define IPL_EXTERN(ep) ipl##ep
55
56 /*
57 * This is a workaround for <sys/uio.h> troubles on FreeBSD and OpenBSD.
58 */
59 #ifndef _KERNEL
60 # define ADD_KERNEL
61 # define _KERNEL
62 # define KERNEL
63 #endif
64 #include <sys/uio.h>
65 #ifdef ADD_KERNEL
66 # undef _KERNEL
67 # undef KERNEL
68 #endif
69
70 #define NETBSD_GE_REV(x) (defined(__NetBSD_Version__) && \
71 (__NetBSD_Version__ >= (x)))
72 #define NETBSD_GT_REV(x) (defined(__NetBSD_Version__) && \
73 (__NetBSD_Version__ > (x)))
74 #define NETBSD_LT_REV(x) (defined(__NetBSD_Version__) && \
75 (__NetBSD_Version__ < (x)))
76
77
78 /* ----------------------------------------------------------------------- */
79 /* F R E E B S D */
80 /* ----------------------------------------------------------------------- */
81 #define HAS_SYS_MD5_H 1
82 #if defined(_KERNEL)
83 # include "opt_bpf.h"
84 # include "opt_inet6.h"
85 # if defined(INET6) && !defined(USE_INET6)
86 # define USE_INET6
87 # endif
88 #else
89 # if !defined(USE_INET6) && !defined(NOINET6)
90 # define USE_INET6
91 # endif
92 #endif
93
94 #if defined(_KERNEL)
95 # include <netinet/ip_var.h>
96 # define p_cred td_ucred
97 # define p_uid td_ucred->cr_ruid
98
99 /*
100 * When #define'd, the 5.2.1 kernel panics when used with the ftp proxy.
101 * There may be other, safe, kernels but this is not extensively tested yet.
102 */
103 # define HAVE_M_PULLDOWN
104 # if !defined(IPFILTER_LKM) && defined(__FreeBSD__)
105 # include "opt_ipfilter.h"
106 # endif
107 # define COPYIN(a,b,c) copyin((caddr_t)(a), (caddr_t)(b), (c))
108 # define COPYOUT(a,b,c) copyout((caddr_t)(a), (caddr_t)(b), (c))
109
110 #else
111 # include <inttypes.h>
112 #endif /* _KERNEL */
113
114 #include <sys/selinfo.h>
115 #include <sys/lock.h>
116 #include <sys/malloc.h>
117 #include <sys/mutex.h>
118 #define KRWLOCK_FILL_SZ 56
119 #define KMUTEX_FILL_SZ 56
120 #include <sys/rwlock.h>
121 #define KMUTEX_T struct mtx
122 #define KRWLOCK_T struct rwlock
123
124 #ifdef _KERNEL
125 # define READ_ENTER(x) rw_rlock(&(x)->ipf_lk)
126 # define WRITE_ENTER(x) rw_wlock(&(x)->ipf_lk)
127 # define MUTEX_DOWNGRADE(x) rw_downgrade(&(x)->ipf_lk)
128 # define MUTEX_TRY_UPGRADE(x) rw_try_upgrade(&(x)->ipf_lk)
129 # define RWLOCK_INIT(x,y) rw_init(&(x)->ipf_lk, (y))
130 # define RW_DESTROY(x) rw_destroy(&(x)->ipf_lk)
131 # define RWLOCK_EXIT(x) do { \
132 if (rw_wowned(&(x)->ipf_lk)) \
133 rw_wunlock(&(x)->ipf_lk); \
134 else \
135 rw_runlock(&(x)->ipf_lk); \
136 } while (0)
137 # include <net/if_var.h>
138 # define GETKTIME(x) microtime((struct timeval *)x)
139 # define if_addrlist if_addrhead
140
141 # include <netinet/in_systm.h>
142 # include <netinet/ip.h>
143 # include <machine/in_cksum.h>
144
145 # define USE_MUTEXES
146 # define MUTEX_ENTER(x) mtx_lock(&(x)->ipf_lk)
147 # define MUTEX_EXIT(x) mtx_unlock(&(x)->ipf_lk)
148 # define MUTEX_INIT(x,y) mtx_init(&(x)->ipf_lk, (y), NULL,\
149 MTX_DEF)
150 # define MUTEX_DESTROY(x) mtx_destroy(&(x)->ipf_lk)
151 # define MUTEX_NUKE(x) bzero((x), sizeof(*(x)))
152 /*
153 * Whilst the sx(9) locks on FreeBSD have the right semantics and interface
154 * for what we want to use them for, despite testing showing they work -
155 * with a WITNESS kernel, it generates LOR messages.
156 */
157 # include <machine/atomic.h>
158 # define ATOMIC_INC(x) { mtx_lock(&softc->ipf_rw.ipf_lk); (x)++; \
159 mtx_unlock(&softc->ipf_rw.ipf_lk); }
160 # define ATOMIC_DEC(x) { mtx_lock(&softc->ipf_rw.ipf_lk); (x)--; \
161 mtx_unlock(&softc->ipf_rw.ipf_lk); }
162 # define ATOMIC_INCL(x) atomic_add_long(&(x), 1)
163 # define ATOMIC_INC64(x) ATOMIC_INC(x)
164 # define ATOMIC_INC32(x) atomic_add_32((u_int *)&(x), 1)
165 # define ATOMIC_DECL(x) atomic_add_long(&(x), -1)
166 # define ATOMIC_DEC64(x) ATOMIC_DEC(x)
167 # define ATOMIC_DEC32(x) atomic_add_32((u_int *)&(x), -1)
168 # define SPL_X(x) ;
169 # define SPL_NET(x) ;
170 # define SPL_IMP(x) ;
171 # define SPL_SCHED(x) ;
172 # define GET_MINOR dev2unit
173 # define MSGDSIZE(m) mbufchainlen(m)
174 # define M_LEN(m) (m)->m_len
175 # define M_ADJ(m,x) m_adj(m, x)
176 # define M_COPY(x) m_copym((x), 0, M_COPYALL, M_NOWAIT)
177 # define M_DUP(m) m_dup(m, M_NOWAIT)
178 # define IPF_PANIC(x,y) if (x) { printf y; panic("ipf_panic"); }
179 typedef struct mbuf mb_t;
180
181 #else /* !_KERNEL */
182 # ifndef _NET_IF_VAR_H_
183 /*
184 * Userland emulation of struct ifnet.
185 */
186 struct route;
187 struct mbuf;
188 struct ifnet {
189 char if_xname[IFNAMSIZ];
190 STAILQ_HEAD(, ifaddr) if_addrlist;
191 int (*if_output)(struct ifnet *, struct mbuf *,
192 const struct sockaddr *, struct route *);
193 };
194 # endif /* _NET_IF_VAR_H_ */
195 #endif /* _KERNEL */
196
197 #define IFNAME(x) ((struct ifnet *)x)->if_xname
198 #define COPYIFNAME(v, x, b) \
199 (void) strncpy(b, \
200 ((struct ifnet *)x)->if_xname, \
201 LIFNAMSIZ)
202
203 typedef u_long ioctlcmd_t;
204 typedef struct uio uio_t;
205 typedef int minor_t;
206 typedef u_int32_t u_32_t;
207 # define U_32_T 1
208
209
210 /* ----------------------------------------------------------------------- */
211 /* G E N E R I C */
212 /* ----------------------------------------------------------------------- */
213
214 /*
215 * For BSD kernels, if bpf is in the kernel, enable ipfilter to use bpf in
216 * filter rules.
217 */
218 #if !defined(IPFILTER_BPF)
219 # if (defined(NBPF) && (NBPF > 0)) || (defined(DEV_BPF) && (DEV_BPF > 0)) || \
220 (defined(NBPFILTER) && (NBPFILTER > 0))
221 # define IPFILTER_BPF
222 # endif
223 #endif
224
225 /*
226 * Userland locking primitives
227 */
228 #ifndef _KERNEL
229 # if !defined(KMUTEX_FILL_SZ)
230 # define KMUTEX_FILL_SZ 1
231 # endif
232 # if !defined(KRWLOCK_FILL_SZ)
233 # define KRWLOCK_FILL_SZ 1
234 # endif
235 #endif
236
237 typedef struct {
238 char *eMm_owner;
239 char *eMm_heldin;
240 u_int eMm_magic;
241 int eMm_held;
242 int eMm_heldat;
243 } eMmutex_t;
244
245 typedef struct {
246 char *eMrw_owner;
247 char *eMrw_heldin;
248 u_int eMrw_magic;
249 short eMrw_read;
250 short eMrw_write;
251 int eMrw_heldat;
252 } eMrwlock_t;
253
254 typedef union {
255 char _fill[KMUTEX_FILL_SZ];
256 #ifdef KMUTEX_T
257 struct {
258 KMUTEX_T ipf_slk;
259 const char *ipf_lname;
260 } ipf_lkun_s;
261 #endif
262 eMmutex_t ipf_emu;
263 } ipfmutex_t;
264
265 typedef union {
266 char _fill[KRWLOCK_FILL_SZ];
267 #ifdef KRWLOCK_T
268 struct {
269 KRWLOCK_T ipf_slk;
270 const char *ipf_lname;
271 int ipf_sr;
272 int ipf_sw;
273 u_int ipf_magic;
274 } ipf_lkun_s;
275 #endif
276 eMrwlock_t ipf_emu;
277 } ipfrwlock_t;
278
279 #define ipf_lk ipf_lkun_s.ipf_slk
280 #define ipf_lname ipf_lkun_s.ipf_lname
281 #define ipf_isr ipf_lkun_s.ipf_sr
282 #define ipf_isw ipf_lkun_s.ipf_sw
283 #define ipf_magic ipf_lkun_s.ipf_magic
284
285 #if defined(__FreeBSD__) && defined(_KERNEL)
286 CTASSERT(sizeof(ipfrwlock_t) == KRWLOCK_FILL_SZ);
287 CTASSERT(sizeof(ipfmutex_t) == KMUTEX_FILL_SZ);
288 #endif
289
290
291 /*
292 * In a non-kernel environment, there are a lot of macros that need to be
293 * filled in to be null-ops or to point to some compatibility function,
294 * somewhere in userland.
295 */
296 #ifndef _KERNEL
297 typedef struct mb_s {
298 struct mb_s *mb_next;
299 char *mb_data;
300 void *mb_ifp;
301 int mb_len;
302 int mb_flags;
303 u_long mb_buf[2048];
304 } mb_t;
305 # undef m_next
306 # define m_next mb_next
307 # undef m_len
308 # define m_len mb_len
309 # undef m_flags
310 # define m_flags mb_flags
311 # undef m_data
312 # define m_data mb_data
313 # undef M_MCAST
314 # define M_MCAST 0x01
315 # undef M_BCAST
316 # define M_BCAST 0x02
317 # undef M_MBCAST
318 # define M_MBCAST 0x04
319 # define MSGDSIZE(m) msgdsize(m)
320 # define M_LEN(m) (m)->mb_len
321 # define M_ADJ(m,x) (m)->mb_len += x
322 # define M_COPY(m) dupmbt(m)
323 # define M_DUP(m) dupmbt(m)
324 # define GETKTIME(x) gettimeofday((struct timeval *)(x), NULL)
325 # define MTOD(m, t) ((t)(m)->mb_data)
326 # define FREE_MB_T(m) freembt(m)
327 # define ALLOC_MB_T(m,l) (m) = allocmbt(l)
328 # define PREP_MB_T(f, m) do { \
329 (m)->mb_next = *(f)->fin_mp; \
330 *(fin)->fin_mp = (m); \
331 (f)->fin_m = (m); \
332 } while (0)
333 # define SLEEP(x,y) 1;
334 # define WAKEUP(x,y) ;
335 # define POLLWAKEUP(y) ;
336 # define IPF_PANIC(x,y) ;
337 # define PANIC(x,y) ;
338 # define SPL_SCHED(x) ;
339 # define SPL_NET(x) ;
340 # define SPL_IMP(x) ;
341 # define SPL_X(x) ;
342 # define KMALLOC(a,b) (a) = (b)malloc(sizeof(*a))
343 # define KMALLOCS(a,b,c) (a) = (b)malloc(c)
344 # define KFREE(x) free(x)
345 # define KFREES(x,s) free(x)
346 # define GETIFP(x, v) get_unit(x,v)
347 # define GETIFMTU_4(x) 2048
348 # define GETIFMTU_6(x) 2048
349 # define COPYIN(a,b,c) bcopywrap((a), (b), (c))
350 # define COPYOUT(a,b,c) bcopywrap((a), (b), (c))
351 # define COPYDATA(m, o, l, b) bcopy(MTOD((mb_t *)m, char *) + (o), \
352 (b), (l))
353 # define COPYBACK(m, o, l, b) bcopy((b), \
354 MTOD((mb_t *)m, char *) + (o), \
355 (l))
356 # define UIOMOVE(a,b,c,d) ipfuiomove((caddr_t)a,b,c,d)
357 extern void m_copydata(mb_t *, int, int, caddr_t);
358 extern int ipfuiomove(caddr_t, int, int, struct uio *);
359 extern int bcopywrap(void *, void *, size_t);
360 extern mb_t *allocmbt(size_t);
361 extern mb_t *dupmbt(mb_t *);
362 extern void freembt(mb_t *);
363
364 # define MUTEX_DESTROY(x) eMmutex_destroy(&(x)->ipf_emu, \
365 __FILE__, __LINE__)
366 # define MUTEX_ENTER(x) eMmutex_enter(&(x)->ipf_emu, \
367 __FILE__, __LINE__)
368 # define MUTEX_EXIT(x) eMmutex_exit(&(x)->ipf_emu, \
369 __FILE__, __LINE__)
370 # define MUTEX_INIT(x,y) eMmutex_init(&(x)->ipf_emu, y, \
371 __FILE__, __LINE__)
372 # define MUTEX_NUKE(x) bzero((x), sizeof(*(x)))
373
374 # define MUTEX_DOWNGRADE(x) eMrwlock_downgrade(&(x)->ipf_emu, \
375 __FILE__, __LINE__)
376 # define MUTEX_TRY_UPGRADE(x) eMrwlock_try_upgrade(&(x)->ipf_emu, \
377 __FILE__, __LINE__)
378 # define READ_ENTER(x) eMrwlock_read_enter(&(x)->ipf_emu, \
379 __FILE__, __LINE__)
380 # define RWLOCK_INIT(x, y) eMrwlock_init(&(x)->ipf_emu, y)
381 # define RWLOCK_EXIT(x) eMrwlock_exit(&(x)->ipf_emu)
382 # define RW_DESTROY(x) eMrwlock_destroy(&(x)->ipf_emu)
383 # define WRITE_ENTER(x) eMrwlock_write_enter(&(x)->ipf_emu, \
384 __FILE__, \
385 __LINE__)
386
387 # define USE_MUTEXES 1
388
389 extern void eMmutex_destroy(eMmutex_t *, char *, int);
390 extern void eMmutex_enter(eMmutex_t *, char *, int);
391 extern void eMmutex_exit(eMmutex_t *, char *, int);
392 extern void eMmutex_init(eMmutex_t *, char *, char *, int);
393 extern void eMrwlock_destroy(eMrwlock_t *);
394 extern void eMrwlock_exit(eMrwlock_t *);
395 extern void eMrwlock_init(eMrwlock_t *, char *);
396 extern void eMrwlock_read_enter(eMrwlock_t *, char *, int);
397 extern void eMrwlock_write_enter(eMrwlock_t *, char *, int);
398 extern void eMrwlock_downgrade(eMrwlock_t *, char *, int);
399
400 #endif
401
402 extern mb_t *allocmbt(size_t);
403
404 #define MAX_IPV4HDR ((0xf << 2) + sizeof(struct icmp) + sizeof(ip_t) + 8)
405
406 #ifndef IP_OFFMASK
407 # define IP_OFFMASK 0x1fff
408 #endif
409
410
411 /*
412 * On BSD's use quad_t as a guarantee for getting at least a 64bit sized
413 * object.
414 */
415 #if !defined(__amd64__) && !SOLARIS
416 # define USE_QUAD_T
417 # define U_QUAD_T unsigned long long
418 # define QUAD_T long long
419 #else /* BSD */
420 # if !defined(U_QUAD_T)
421 # define U_QUAD_T u_long
422 # define QUAD_T long
423 # endif
424 #endif /* BSD */
425
426
427 #ifdef USE_INET6
428 # if defined(__NetBSD__) || defined(__FreeBSD__)
429 # include <netinet/ip6.h>
430 # include <netinet/icmp6.h>
431 # if defined(_KERNEL)
432 # include <netinet6/ip6_var.h>
433 # endif
434 typedef struct ip6_hdr ip6_t;
435 # endif
436 #endif
437
438 #ifndef MAX
439 # define MAX(a,b) (((a) > (b)) ? (a) : (b))
440 #endif
441
442 #if defined(_KERNEL)
443 # if SOLARIS && !defined(INSTANCES)
444 # define COPYDATA mb_copydata
445 # define COPYBACK mb_copyback
446 # else
447 # define COPYDATA m_copydata
448 # define COPYBACK m_copyback
449 # endif
450 # if (defined(__NetBSD_Version__) && (__NetBSD_Version__ < 105180000)) || \
451 defined(__FreeBSD__)
452 # include <vm/vm.h>
453 # endif
454 # if NETBSD_GE_REV(105180000)
455 # include <uvm/uvm_extern.h>
456 # else
457 # include <vm/vm_extern.h>
458 extern vm_map_t kmem_map;
459 # endif
460 # include <sys/proc.h>
461
462 # ifdef IPFILTER_M_IPFILTER
463 # include <sys/malloc.h>
464 MALLOC_DECLARE(M_IPFILTER);
465 # define _M_IPF M_IPFILTER
466 # else /* IPFILTER_M_IPFILTER */
467 # ifdef M_PFIL
468 # define _M_IPF M_PFIL
469 # else
470 # ifdef M_IPFILTER
471 # define _M_IPF M_IPFILTER
472 # else
473 # define _M_IPF M_TEMP
474 # endif /* M_IPFILTER */
475 # endif /* M_PFIL */
476 # endif /* IPFILTER_M_IPFILTER */
477 # if !defined(KMALLOC)
478 # define KMALLOC(a, b) (a) = (b)malloc(sizeof(*(a)), _M_IPF, M_NOWAIT)
479 # endif
480 # if !defined(KMALLOCS)
481 # define KMALLOCS(a, b, c) (a) = (b)malloc((c), _M_IPF, M_NOWAIT)
482 # endif
483 # if !defined(KFREE)
484 # define KFREE(x) free((x), _M_IPF)
485 # endif
486 # if !defined(KFREES)
487 # define KFREES(x,s) free((x), _M_IPF)
488 # endif
489 # define UIOMOVE(a,b,c,d) uiomove((caddr_t)a,b,d)
490 # define SLEEP(id, n) tsleep((id), PPAUSE|PCATCH, n, 0)
491 # define WAKEUP(id,x) wakeup(id+x)
492 # if !defined(POLLWAKEUP)
493 # define POLLWAKEUP(x) selwakeup(softc->ipf_selwait+x)
494 # endif
495 # define GETIFP(n, v) ifunit(n)
496 # define GETIFMTU_4(x) ((struct ifnet *)x)->if_mtu
497 # define GETIFMTU_6(x) ((struct ifnet *)x)->if_mtu
498
499 # if !defined(USE_MUTEXES) && !defined(SPL_NET)
500 # define SPL_IMP(x) x = splimp()
501 # define SPL_NET(x) x = splnet()
502 # if !defined(SPL_SCHED)
503 # define SPL_SCHED(x) x = splsched()
504 # endif
505 # define SPL_X(x) (void) splx(x)
506 # endif /* !USE_MUTEXES */
507
508 # ifndef FREE_MB_T
509 # define FREE_MB_T(m) m_freem(m)
510 # endif
511 # ifndef ALLOC_MB_T
512 # ifdef MGETHDR
513 # define ALLOC_MB_T(m,l) do { \
514 MGETHDR((m), M_NOWAIT, MT_HEADER); \
515 if ((m) != NULL) { \
516 (m)->m_len = (l); \
517 (m)->m_pkthdr.len = (l); \
518 } \
519 } while (0)
520 # else
521 # define ALLOC_MB_T(m,l) do { \
522 MGET((m), M_NOWAIT, MT_HEADER); \
523 if ((m) != NULL) { \
524 (m)->m_len = (l); \
525 (m)->m_pkthdr.len = (l); \
526 } \
527 } while (0)
528 # endif
529 # endif
530 # ifndef PREP_MB_T
531 # define PREP_MB_T(f, m) do { \
532 mb_t *_o = *(f)->fin_mp; \
533 (m)->m_next = _o; \
534 *(fin)->fin_mp = (m); \
535 if (_o->m_flags & M_PKTHDR) { \
536 (m)->m_pkthdr.len += \
537 _o->m_pkthdr.len; \
538 (m)->m_pkthdr.rcvif = \
539 _o->m_pkthdr.rcvif; \
540 } \
541 } while (0)
542 # endif
543 # ifndef M_DUP
544 # ifdef M_COPYALL
545 # define M_DUP(m) m_dup(m, 0, M_COPYALL, 0)
546 # else
547 # define M_DUP(m) m_dup(m)
548 # endif
549 # endif
550
551 # ifndef MTOD
552 # define MTOD(m,t) mtod(m,t)
553 # endif
554
555 # ifndef COPYIN
556 # define COPYIN(a,b,c) (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
557 # define COPYOUT(a,b,c) (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
558 # endif
559
560 # if SOLARIS && !defined(KMALLOC)
561 # define KMALLOC(a,b) (a) = (b)new_kmem_alloc(sizeof(*(a)), \
562 KMEM_NOSLEEP)
563 # define KMALLOCS(a,b,c) (a) = (b)new_kmem_alloc((c), KMEM_NOSLEEP)
564 # endif
565
566 # ifndef GET_MINOR
567 # define GET_MINOR(x) dev2unit(x)
568 # endif
569 # define PANIC(x,y) if (x) panic y
570 #endif /* _KERNEL */
571
572 #if !defined(IFNAME) && !defined(_KERNEL)
573 # define IFNAME(x) get_ifname((struct ifnet *)x)
574 #endif
575 #ifndef COPYIFNAME
576 # define NEED_FRGETIFNAME
577 extern char *ipf_getifname(struct ifnet *, char *);
578 # define COPYIFNAME(v, x, b) \
579 ipf_getifname((struct ifnet *)x, b)
580 #endif
581
582 #ifndef ASSERT
583 # ifdef _KERNEL
584 # define ASSERT(x)
585 # else
586 # define ASSERT(x) do { if (!(x)) abort(); } while (0)
587 # endif
588 #endif
589
590 #ifndef BCOPYIN
591 # define BCOPYIN(a,b,c) (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
592 # define BCOPYOUT(a,b,c) (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
593 #endif
594
595 /*
596 * Because the ctype(3) posix definition, if used "safely" in code everywhere,
597 * would mean all normal code that walks through strings needed casts. Yuck.
598 */
599 #define ISALNUM(x) isalnum((u_char)(x))
600 #define ISALPHA(x) isalpha((u_char)(x))
601 #define ISDIGIT(x) isdigit((u_char)(x))
602 #define ISSPACE(x) isspace((u_char)(x))
603 #define ISUPPER(x) isupper((u_char)(x))
604 #define ISXDIGIT(x) isxdigit((u_char)(x))
605 #define ISLOWER(x) islower((u_char)(x))
606 #define TOUPPER(x) toupper((u_char)(x))
607 #define TOLOWER(x) tolower((u_char)(x))
608
609 /*
610 * If mutexes aren't being used, turn all the mutex functions into null-ops.
611 */
612 #if !defined(USE_MUTEXES)
613 # define USE_SPL 1
614 # undef RW_DESTROY
615 # undef MUTEX_INIT
616 # undef MUTEX_NUKE
617 # undef MUTEX_DESTROY
618 # define MUTEX_ENTER(x) ;
619 # define READ_ENTER(x) ;
620 # define WRITE_ENTER(x) ;
621 # define MUTEX_DOWNGRADE(x) ;
622 # define MUTEX_TRY_UPGRADE(x) ;
623 # define RWLOCK_INIT(x, y) ;
624 # define RWLOCK_EXIT(x) ;
625 # define RW_DESTROY(x) ;
626 # define MUTEX_EXIT(x) ;
627 # define MUTEX_INIT(x,y) ;
628 # define MUTEX_DESTROY(x) ;
629 # define MUTEX_NUKE(x) ;
630 #endif /* !USE_MUTEXES */
631 #ifndef ATOMIC_INC
632 # define ATOMIC_INC(x) (x)++
633 # define ATOMIC_DEC(x) (x)--
634 #endif
635
636 #if defined(USE_SPL) && defined(_KERNEL)
637 # define SPL_INT(x) int x
638 #else
639 # define SPL_INT(x)
640 #endif
641
642 /*
643 * If there are no atomic operations for bit sizes defined, define them to all
644 * use a generic one that works for all sizes.
645 */
646 #ifndef ATOMIC_INCL
647 # define ATOMIC_INCL ATOMIC_INC
648 # define ATOMIC_INC64 ATOMIC_INC
649 # define ATOMIC_INC32 ATOMIC_INC
650 # define ATOMIC_DECL ATOMIC_DEC
651 # define ATOMIC_DEC64 ATOMIC_DEC
652 # define ATOMIC_DEC32 ATOMIC_DEC
653 #endif
654
655 #ifndef HDR_T_PRIVATE
656 typedef struct tcphdr tcphdr_t;
657 typedef struct udphdr udphdr_t;
658 #endif
659 typedef struct icmp icmphdr_t;
660 typedef struct ip ip_t;
661 typedef struct ether_header ether_header_t;
662 typedef struct tcpiphdr tcpiphdr_t;
663
664 #ifndef FR_GROUPLEN
665 # define FR_GROUPLEN 16
666 #endif
667
668 #ifndef offsetof
669 # define offsetof(t,m) (size_t)((&((t *)0L)->m))
670 #endif
671 #ifndef stsizeof
672 # define stsizeof(t,m) sizeof(((t *)0L)->m)
673 #endif
674
675 /*
676 * This set of macros has been brought about because on Tru64 it is not
677 * possible to easily assign or examine values in a structure that are
678 * bit fields.
679 */
680 #ifndef IP_V
681 # define IP_V(x) (x)->ip_v
682 #endif
683 #ifndef IP_V_A
684 # define IP_V_A(x,y) (x)->ip_v = (y)
685 #endif
686 #ifndef IP_HL
687 # define IP_HL(x) (x)->ip_hl
688 #endif
689 #ifndef IP_HL_A
690 # define IP_HL_A(x,y) (x)->ip_hl = ((y) & 0xf)
691 #endif
692 #ifndef TCP_X2
693 # define TCP_X2(x) (x)->th_x2
694 #endif
695 #ifndef TCP_X2_A
696 # define TCP_X2_A(x,y) (x)->th_x2 = (y)
697 #endif
698 #ifndef TCP_OFF
699 # define TCP_OFF(x) (x)->th_off
700 #endif
701 #ifndef TCP_OFF_A
702 # define TCP_OFF_A(x,y) (x)->th_off = (y)
703 #endif
704 #define IPMINLEN(i, h) ((i)->ip_len >= (IP_HL(i) * 4 + sizeof(struct h)))
705
706 #define TCPF_ALL (TH_FIN|TH_SYN|TH_RST|TH_PUSH|TH_ACK|TH_URG|\
707 TH_ECN|TH_CWR)
708
709 #if !SOLARIS && !defined(m_act)
710 # define m_act m_nextpkt
711 #endif
712
713 /*
714 * Security Options for Intenet Protocol (IPSO) as defined in RFC 1108.
715 *
716 * Basic Option
717 *
718 * 00000001 - (Reserved 4)
719 * 00111101 - Top Secret
720 * 01011010 - Secret
721 * 10010110 - Confidential
722 * 01100110 - (Reserved 3)
723 * 11001100 - (Reserved 2)
724 * 10101011 - Unclassified
725 * 11110001 - (Reserved 1)
726 */
727 #define IPSO_CLASS_RES4 0x01
728 #define IPSO_CLASS_TOPS 0x3d
729 #define IPSO_CLASS_SECR 0x5a
730 #define IPSO_CLASS_CONF 0x96
731 #define IPSO_CLASS_RES3 0x66
732 #define IPSO_CLASS_RES2 0xcc
733 #define IPSO_CLASS_UNCL 0xab
734 #define IPSO_CLASS_RES1 0xf1
735
736 #define IPSO_AUTH_GENSER 0x80
737 #define IPSO_AUTH_ESI 0x40
738 #define IPSO_AUTH_SCI 0x20
739 #define IPSO_AUTH_NSA 0x10
740 #define IPSO_AUTH_DOE 0x08
741 #define IPSO_AUTH_UN 0x06
742 #define IPSO_AUTH_FTE 0x01
743
744 /*
745 * IP option #defines
746 */
747 #undef IPOPT_RR
748 #define IPOPT_RR 7
749 #undef IPOPT_ZSU
750 #define IPOPT_ZSU 10 /* ZSU */
751 #undef IPOPT_MTUP
752 #define IPOPT_MTUP 11 /* MTUP */
753 #undef IPOPT_MTUR
754 #define IPOPT_MTUR 12 /* MTUR */
755 #undef IPOPT_ENCODE
756 #define IPOPT_ENCODE 15 /* ENCODE */
757 #undef IPOPT_TS
758 #define IPOPT_TS 68
759 #undef IPOPT_TR
760 #define IPOPT_TR 82 /* TR */
761 #undef IPOPT_SECURITY
762 #define IPOPT_SECURITY 130
763 #undef IPOPT_LSRR
764 #define IPOPT_LSRR 131
765 #undef IPOPT_E_SEC
766 #define IPOPT_E_SEC 133 /* E-SEC */
767 #undef IPOPT_CIPSO
768 #define IPOPT_CIPSO 134 /* CIPSO */
769 #undef IPOPT_SATID
770 #define IPOPT_SATID 136
771 #ifndef IPOPT_SID
772 # define IPOPT_SID IPOPT_SATID
773 #endif
774 #undef IPOPT_SSRR
775 #define IPOPT_SSRR 137
776 #undef IPOPT_ADDEXT
777 #define IPOPT_ADDEXT 147 /* ADDEXT */
778 #undef IPOPT_VISA
779 #define IPOPT_VISA 142 /* VISA */
780 #undef IPOPT_IMITD
781 #define IPOPT_IMITD 144 /* IMITD */
782 #undef IPOPT_EIP
783 #define IPOPT_EIP 145 /* EIP */
784 #undef IPOPT_RTRALRT
785 #define IPOPT_RTRALRT 148 /* RTRALRT */
786 #undef IPOPT_SDB
787 #define IPOPT_SDB 149
788 #undef IPOPT_NSAPA
789 #define IPOPT_NSAPA 150
790 #undef IPOPT_DPS
791 #define IPOPT_DPS 151
792 #undef IPOPT_UMP
793 #define IPOPT_UMP 152
794 #undef IPOPT_FINN
795 #define IPOPT_FINN 205 /* FINN */
796 #undef IPOPT_AH
797 #define IPOPT_AH 256+IPPROTO_AH
798
799 #define ICMP_UNREACH_ADMIN_PROHIBIT ICMP_UNREACH_FILTER_PROHIB
800 #define ICMP_UNREACH_FILTER ICMP_UNREACH_FILTER_PROHIB
801
802 #ifndef IPVERSION
803 # define IPVERSION 4
804 #endif
805 #ifndef IPOPT_MINOFF
806 # define IPOPT_MINOFF 4
807 #endif
808 #ifndef IPOPT_COPIED
809 # define IPOPT_COPIED(x) ((x)&0x80)
810 #endif
811 #ifndef IPOPT_EOL
812 # define IPOPT_EOL 0
813 #endif
814 #ifndef IPOPT_NOP
815 # define IPOPT_NOP 1
816 #endif
817 #ifndef IP_MF
818 # define IP_MF ((u_short)0x2000)
819 #endif
820 #ifndef ETHERTYPE_IP
821 # define ETHERTYPE_IP ((u_short)0x0800)
822 #endif
823 #ifndef TH_FIN
824 # define TH_FIN 0x01
825 #endif
826 #ifndef TH_SYN
827 # define TH_SYN 0x02
828 #endif
829 #ifndef TH_RST
830 # define TH_RST 0x04
831 #endif
832 #ifndef TH_PUSH
833 # define TH_PUSH 0x08
834 #endif
835 #ifndef TH_ACK
836 # define TH_ACK 0x10
837 #endif
838 #ifndef TH_URG
839 # define TH_URG 0x20
840 #endif
841 #undef TH_ACKMASK
842 #define TH_ACKMASK (TH_FIN|TH_SYN|TH_RST|TH_ACK)
843
844 #ifndef IPOPT_EOL
845 # define IPOPT_EOL 0
846 #endif
847 #ifndef IPOPT_NOP
848 # define IPOPT_NOP 1
849 #endif
850 #ifndef IPOPT_RR
851 # define IPOPT_RR 7
852 #endif
853 #ifndef IPOPT_TS
854 # define IPOPT_TS 68
855 #endif
856 #ifndef IPOPT_SECURITY
857 # define IPOPT_SECURITY 130
858 #endif
859 #ifndef IPOPT_LSRR
860 # define IPOPT_LSRR 131
861 #endif
862 #ifndef IPOPT_SATID
863 # define IPOPT_SATID 136
864 #endif
865 #ifndef IPOPT_SSRR
866 # define IPOPT_SSRR 137
867 #endif
868 #ifndef IPOPT_SECUR_UNCLASS
869 # define IPOPT_SECUR_UNCLASS ((u_short)0x0000)
870 #endif
871 #ifndef IPOPT_SECUR_CONFID
872 # define IPOPT_SECUR_CONFID ((u_short)0xf135)
873 #endif
874 #ifndef IPOPT_SECUR_EFTO
875 # define IPOPT_SECUR_EFTO ((u_short)0x789a)
876 #endif
877 #ifndef IPOPT_SECUR_MMMM
878 # define IPOPT_SECUR_MMMM ((u_short)0xbc4d)
879 #endif
880 #ifndef IPOPT_SECUR_RESTR
881 # define IPOPT_SECUR_RESTR ((u_short)0xaf13)
882 #endif
883 #ifndef IPOPT_SECUR_SECRET
884 # define IPOPT_SECUR_SECRET ((u_short)0xd788)
885 #endif
886 #ifndef IPOPT_SECUR_TOPSECRET
887 # define IPOPT_SECUR_TOPSECRET ((u_short)0x6bc5)
888 #endif
889 #ifndef IPOPT_OLEN
890 # define IPOPT_OLEN 1
891 #endif
892 #ifndef IPPROTO_HOPOPTS
893 # define IPPROTO_HOPOPTS 0
894 #endif
895 #ifndef IPPROTO_IPIP
896 # define IPPROTO_IPIP 4
897 #endif
898 #ifndef IPPROTO_ENCAP
899 # define IPPROTO_ENCAP 98
900 #endif
901 #ifndef IPPROTO_IPV6
902 # define IPPROTO_IPV6 41
903 #endif
904 #ifndef IPPROTO_ROUTING
905 # define IPPROTO_ROUTING 43
906 #endif
907 #ifndef IPPROTO_FRAGMENT
908 # define IPPROTO_FRAGMENT 44
909 #endif
910 #ifndef IPPROTO_GRE
911 # define IPPROTO_GRE 47 /* GRE encaps RFC 1701 */
912 #endif
913 #ifndef IPPROTO_ESP
914 # define IPPROTO_ESP 50
915 #endif
916 #ifndef IPPROTO_AH
917 # define IPPROTO_AH 51
918 #endif
919 #ifndef IPPROTO_ICMPV6
920 # define IPPROTO_ICMPV6 58
921 #endif
922 #ifndef IPPROTO_NONE
923 # define IPPROTO_NONE 59
924 #endif
925 #ifndef IPPROTO_DSTOPTS
926 # define IPPROTO_DSTOPTS 60
927 #endif
928 #ifndef IPPROTO_MOBILITY
929 # define IPPROTO_MOBILITY 135
930 #endif
931
932 #ifndef ICMP_ROUTERADVERT
933 # define ICMP_ROUTERADVERT 9
934 #endif
935 #ifndef ICMP_ROUTERSOLICIT
936 # define ICMP_ROUTERSOLICIT 10
937 #endif
938 #ifndef ICMP6_DST_UNREACH
939 # define ICMP6_DST_UNREACH 1
940 #endif
941 #ifndef ICMP6_PACKET_TOO_BIG
942 # define ICMP6_PACKET_TOO_BIG 2
943 #endif
944 #ifndef ICMP6_TIME_EXCEEDED
945 # define ICMP6_TIME_EXCEEDED 3
946 #endif
947 #ifndef ICMP6_PARAM_PROB
948 # define ICMP6_PARAM_PROB 4
949 #endif
950
951 #ifndef ICMP6_ECHO_REQUEST
952 # define ICMP6_ECHO_REQUEST 128
953 #endif
954 #ifndef ICMP6_ECHO_REPLY
955 # define ICMP6_ECHO_REPLY 129
956 #endif
957 #ifndef ICMP6_MEMBERSHIP_QUERY
958 # define ICMP6_MEMBERSHIP_QUERY 130
959 #endif
960 #ifndef MLD6_LISTENER_QUERY
961 # define MLD6_LISTENER_QUERY 130
962 #endif
963 #ifndef ICMP6_MEMBERSHIP_REPORT
964 # define ICMP6_MEMBERSHIP_REPORT 131
965 #endif
966 #ifndef MLD6_LISTENER_REPORT
967 # define MLD6_LISTENER_REPORT 131
968 #endif
969 #ifndef ICMP6_MEMBERSHIP_REDUCTION
970 # define ICMP6_MEMBERSHIP_REDUCTION 132
971 #endif
972 #ifndef MLD6_LISTENER_DONE
973 # define MLD6_LISTENER_DONE 132
974 #endif
975 #ifndef ND_ROUTER_SOLICIT
976 # define ND_ROUTER_SOLICIT 133
977 #endif
978 #ifndef ND_ROUTER_ADVERT
979 # define ND_ROUTER_ADVERT 134
980 #endif
981 #ifndef ND_NEIGHBOR_SOLICIT
982 # define ND_NEIGHBOR_SOLICIT 135
983 #endif
984 #ifndef ND_NEIGHBOR_ADVERT
985 # define ND_NEIGHBOR_ADVERT 136
986 #endif
987 #ifndef ND_REDIRECT
988 # define ND_REDIRECT 137
989 #endif
990 #ifndef ICMP6_ROUTER_RENUMBERING
991 # define ICMP6_ROUTER_RENUMBERING 138
992 #endif
993 #ifndef ICMP6_WRUREQUEST
994 # define ICMP6_WRUREQUEST 139
995 #endif
996 #ifndef ICMP6_WRUREPLY
997 # define ICMP6_WRUREPLY 140
998 #endif
999 #ifndef ICMP6_FQDN_QUERY
1000 # define ICMP6_FQDN_QUERY 139
1001 #endif
1002 #ifndef ICMP6_FQDN_REPLY
1003 # define ICMP6_FQDN_REPLY 140
1004 #endif
1005 #ifndef ICMP6_NI_QUERY
1006 # define ICMP6_NI_QUERY 139
1007 #endif
1008 #ifndef ICMP6_NI_REPLY
1009 # define ICMP6_NI_REPLY 140
1010 #endif
1011 #ifndef MLD6_MTRACE_RESP
1012 # define MLD6_MTRACE_RESP 200
1013 #endif
1014 #ifndef MLD6_MTRACE
1015 # define MLD6_MTRACE 201
1016 #endif
1017 #ifndef ICMP6_HADISCOV_REQUEST
1018 # define ICMP6_HADISCOV_REQUEST 202
1019 #endif
1020 #ifndef ICMP6_HADISCOV_REPLY
1021 # define ICMP6_HADISCOV_REPLY 203
1022 #endif
1023 #ifndef ICMP6_MOBILEPREFIX_SOLICIT
1024 # define ICMP6_MOBILEPREFIX_SOLICIT 204
1025 #endif
1026 #ifndef ICMP6_MOBILEPREFIX_ADVERT
1027 # define ICMP6_MOBILEPREFIX_ADVERT 205
1028 #endif
1029 #ifndef ICMP6_MAXTYPE
1030 # define ICMP6_MAXTYPE 205
1031 #endif
1032
1033 #ifndef ICMP6_DST_UNREACH_NOROUTE
1034 # define ICMP6_DST_UNREACH_NOROUTE 0
1035 #endif
1036 #ifndef ICMP6_DST_UNREACH_ADMIN
1037 # define ICMP6_DST_UNREACH_ADMIN 1
1038 #endif
1039 #ifndef ICMP6_DST_UNREACH_NOTNEIGHBOR
1040 # define ICMP6_DST_UNREACH_NOTNEIGHBOR 2
1041 #endif
1042 #ifndef ICMP6_DST_UNREACH_BEYONDSCOPE
1043 # define ICMP6_DST_UNREACH_BEYONDSCOPE 2
1044 #endif
1045 #ifndef ICMP6_DST_UNREACH_ADDR
1046 # define ICMP6_DST_UNREACH_ADDR 3
1047 #endif
1048 #ifndef ICMP6_DST_UNREACH_NOPORT
1049 # define ICMP6_DST_UNREACH_NOPORT 4
1050 #endif
1051 #ifndef ICMP6_TIME_EXCEED_TRANSIT
1052 # define ICMP6_TIME_EXCEED_TRANSIT 0
1053 #endif
1054 #ifndef ICMP6_TIME_EXCEED_REASSEMBLY
1055 # define ICMP6_TIME_EXCEED_REASSEMBLY 1
1056 #endif
1057
1058 #ifndef ICMP6_NI_SUCCESS
1059 # define ICMP6_NI_SUCCESS 0
1060 #endif
1061 #ifndef ICMP6_NI_REFUSED
1062 # define ICMP6_NI_REFUSED 1
1063 #endif
1064 #ifndef ICMP6_NI_UNKNOWN
1065 # define ICMP6_NI_UNKNOWN 2
1066 #endif
1067
1068 #ifndef ICMP6_ROUTER_RENUMBERING_COMMAND
1069 # define ICMP6_ROUTER_RENUMBERING_COMMAND 0
1070 #endif
1071 #ifndef ICMP6_ROUTER_RENUMBERING_RESULT
1072 # define ICMP6_ROUTER_RENUMBERING_RESULT 1
1073 #endif
1074 #ifndef ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET
1075 # define ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET 255
1076 #endif
1077
1078 #ifndef ICMP6_PARAMPROB_HEADER
1079 # define ICMP6_PARAMPROB_HEADER 0
1080 #endif
1081 #ifndef ICMP6_PARAMPROB_NEXTHEADER
1082 # define ICMP6_PARAMPROB_NEXTHEADER 1
1083 #endif
1084 #ifndef ICMP6_PARAMPROB_OPTION
1085 # define ICMP6_PARAMPROB_OPTION 2
1086 #endif
1087
1088 #ifndef ICMP6_NI_SUBJ_IPV6
1089 # define ICMP6_NI_SUBJ_IPV6 0
1090 #endif
1091 #ifndef ICMP6_NI_SUBJ_FQDN
1092 # define ICMP6_NI_SUBJ_FQDN 1
1093 #endif
1094 #ifndef ICMP6_NI_SUBJ_IPV4
1095 # define ICMP6_NI_SUBJ_IPV4 2
1096 #endif
1097
1098 #ifndef MLD_MTRACE_RESP
1099 # define MLD_MTRACE_RESP 200
1100 #endif
1101 #ifndef MLD_MTRACE
1102 # define MLD_MTRACE 201
1103 #endif
1104 #ifndef MLD6_MTRACE_RESP
1105 # define MLD6_MTRACE_RESP MLD_MTRACE_RESP
1106 #endif
1107 #ifndef MLD6_MTRACE
1108 # define MLD6_MTRACE MLD_MTRACE
1109 #endif
1110
1111 #if !defined(IPV6_FLOWINFO_MASK)
1112 # if (BYTE_ORDER == BIG_ENDIAN) || defined(_BIG_ENDIAN)
1113 # define IPV6_FLOWINFO_MASK 0x0fffffff /* flow info (28 bits) */
1114 # else
1115 # if(BYTE_ORDER == LITTLE_ENDIAN) || !defined(_BIG_ENDIAN)
1116 # define IPV6_FLOWINFO_MASK 0xffffff0f /* flow info (28 bits) */
1117 # endif /* LITTLE_ENDIAN */
1118 # endif
1119 #endif
1120 #if !defined(IPV6_FLOWLABEL_MASK)
1121 # if (BYTE_ORDER == BIG_ENDIAN) || defined(_BIG_ENDIAN)
1122 # define IPV6_FLOWLABEL_MASK 0x000fffff /* flow label (20 bits) */
1123 # else
1124 # if (BYTE_ORDER == LITTLE_ENDIAN) || !defined(_BIG_ENDIAN)
1125 # define IPV6_FLOWLABEL_MASK 0xffff0f00 /* flow label (20 bits) */
1126 # endif /* LITTLE_ENDIAN */
1127 # endif
1128 #endif
1129
1130 /*
1131 * ECN is a new addition to TCP - RFC 2481
1132 */
1133 #ifndef TH_ECN
1134 # define TH_ECN 0x40
1135 #endif
1136 #ifndef TH_CWR
1137 # define TH_CWR 0x80
1138 #endif
1139 #define TH_ECNALL (TH_ECN|TH_CWR)
1140
1141 /*
1142 * TCP States
1143 */
1144 #define IPF_TCPS_LISTEN 0 /* listening for connection */
1145 #define IPF_TCPS_SYN_SENT 1 /* active, have sent syn */
1146 #define IPF_TCPS_SYN_RECEIVED 2 /* have send and received syn */
1147 #define IPF_TCPS_HALF_ESTAB 3 /* for connections not fully "up" */
1148 /* states < IPF_TCPS_ESTABLISHED are those where connections not established */
1149 #define IPF_TCPS_ESTABLISHED 4 /* established */
1150 #define IPF_TCPS_CLOSE_WAIT 5 /* rcvd fin, waiting for close */
1151 /* states > IPF_TCPS_CLOSE_WAIT are those where user has closed */
1152 #define IPF_TCPS_FIN_WAIT_1 6 /* have closed, sent fin */
1153 #define IPF_TCPS_CLOSING 7 /* closed xchd FIN; await FIN ACK */
1154 #define IPF_TCPS_LAST_ACK 8 /* had fin and close; await FIN ACK */
1155 /* states > IPF_TCPS_CLOSE_WAIT && < IPF_TCPS_FIN_WAIT_2 await ACK of FIN */
1156 #define IPF_TCPS_FIN_WAIT_2 9 /* have closed, fin is acked */
1157 #define IPF_TCPS_TIME_WAIT 10 /* in 2*msl quiet wait after close */
1158 #define IPF_TCPS_CLOSED 11 /* closed */
1159 #define IPF_TCP_NSTATES 12
1160
1161 #define TCP_MSL 120
1162
1163 #undef ICMP_MAX_UNREACH
1164 #define ICMP_MAX_UNREACH 14
1165 #undef ICMP_MAXTYPE
1166 #define ICMP_MAXTYPE 18
1167
1168 #ifndef LOG_FTP
1169 # define LOG_FTP (11<<3)
1170 #endif
1171 #ifndef LOG_AUTHPRIV
1172 # define LOG_AUTHPRIV (10<<3)
1173 #endif
1174 #ifndef LOG_AUDIT
1175 # define LOG_AUDIT (13<<3)
1176 #endif
1177 #ifndef LOG_NTP
1178 # define LOG_NTP (12<<3)
1179 #endif
1180 #ifndef LOG_SECURITY
1181 # define LOG_SECURITY (13<<3)
1182 #endif
1183 #ifndef LOG_LFMT
1184 # define LOG_LFMT (14<<3)
1185 #endif
1186 #ifndef LOG_CONSOLE
1187 # define LOG_CONSOLE (14<<3)
1188 #endif
1189
1190 /*
1191 * ICMP error replies have an IP header (20 bytes), 8 bytes of ICMP data,
1192 * another IP header and then 64 bits of data, totalling 56. Of course,
1193 * the last 64 bits is dependent on that being available.
1194 */
1195 #define ICMPERR_ICMPHLEN 8
1196 #define ICMPERR_IPICMPHLEN (20 + 8)
1197 #define ICMPERR_MINPKTLEN (20 + 8 + 20)
1198 #define ICMPERR_MAXPKTLEN (20 + 8 + 20 + 8)
1199 #define ICMP6ERR_MINPKTLEN (40 + 8)
1200 #define ICMP6ERR_IPICMPHLEN (40 + 8 + 40)
1201
1202 #ifndef MIN
1203 # define MIN(a,b) (((a)<(b))?(a):(b))
1204 #endif
1205
1206 #ifdef RESCUE
1207 # undef IPFILTER_BPF
1208 #endif
1209
1210 #ifdef IPF_DEBUG
1211 # define DPRINT(x) printf x
1212 #else
1213 # define DPRINT(x)
1214 #endif
1215
1216 #if defined(DTRACE_PROBE) && defined(_KERNEL)
1217 # define DT(_n) DTRACE_PROBE(_n)
1218 # define DT1(_n,_a,_b) DTRACE_PROBE1(_n,_a,_b)
1219 # define DT2(_n,_a,_b,_c,_d) DTRACE_PROBE2(_n,_a,_b,_c,_d)
1220 # define DT3(_n,_a,_b,_c,_d,_e,_f) \
1221 DTRACE_PROBE3(_n,_a,_b,_c,_d,_e,_f)
1222 # define DT4(_n,_a,_b,_c,_d,_e,_f,_g,_h) \
1223 DTRACE_PROBE4(_n,_a,_b,_c,_d,_e,_f,_g,_h)
1224 # define DT5(_n,_a,_b,_c,_d,_e,_f,_g,_h,_i,_j) \
1225 DTRACE_PROBE5(_n,_a,_b,_c,_d,_e,_f,_g,_h,_i,_j)
1226 #else
1227 # define DT(_n)
1228 # define DT1(_n,_a,_b)
1229 # define DT2(_n,_a,_b,_c,_d)
1230 # define DT3(_n,_a,_b,_c,_d,_e,_f)
1231 # define DT4(_n,_a,_b,_c,_d,_e,_f,_g,_h)
1232 # define DT5(_n,_a,_b,_c,_d,_e,_f,_g,_h,_i,_j)
1233 #endif
1234
1235 struct ip6_routing {
1236 u_char ip6r_nxt; /* next header */
1237 u_char ip6r_len; /* length in units of 8 octets */
1238 u_char ip6r_type; /* always zero */
1239 u_char ip6r_segleft; /* segments left */
1240 u_32_t ip6r_reserved; /* reserved field */
1241 };
1242
1243 #endif /* __IP_COMPAT_H__ */
Cache object: 3c6a0bc6a3afef6f595259c58a5a33f2
|