2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
23 * Copyright (C) 1993-1997 by Darren Reed.
25 * Redistribution and use in source and binary forms are permitted
26 * provided that this notice is preserved and due credit is given
27 * to the original author and the contributors.
29 * @(#)ip_compat.h 1.8 1/14/96
34 #ifndef __IP_COMPAT_H__
35 #define __IP_COMPAT_H__
47 #define SOLARIS (defined(sun) && (defined(__svr4__) || defined(__SVR4)))
50 #if defined(_KERNEL) && !defined(KERNEL)
53 #if defined(KERNEL) && !defined(_KERNEL)
56 #if!defined(__KERNEL__) && defined(KERNEL)
60 #if defined(__SVR4) || defined(__svr4__) || defined(__sgi)
62 # if !defined(_KERNEL)
63 # define bzero(a,b) memset(a,0,b)
65 # define bcopy(a,b,c) memmove(b,a,c)
70 u_char ether_addr_octet
[6];
74 #if defined(__sgi) && !defined(IPFILTER_LKM)
76 # define IPL_EXTERN(ep) ipfilter##ep
78 # define IPL_EXTERN(ep) ipfilter/**/ep
82 # define IPL_EXTERN(ep) ipl##ep
84 # define IPL_EXTERN(ep) ipl/**/ep
89 # include <sys/sysmacros.h>
92 # define MTYPE(m) ((m)->b_datap->db_type)
93 # include <sys/ioccom.h>
94 # include <sys/sysmacros.h>
95 # include <sys/kmem.h>
97 * because Solaris 2 defines these in two places :-/
107 # include <inet/common.h>
108 # include <inet/ip.h>
109 # include <inet/ip_ire.h>
112 # include <inet/common.h>
113 # include <inet/ip.h>
114 # include <inet/ip_ire.h>
115 # endif /* _KERNEL */
117 #define IPMINLEN(i, h) ((i)->ip_len >= ((i)->ip_hl * 4 + sizeof(struct h)))
120 #define IP_OFFMASK 0x1fff
125 # define U_QUAD_T u_quad_t
126 # define QUAD_T quad_t
127 #else /* BSD > 199306 */
128 # define U_QUAD_T u_long
130 #endif /* BSD > 199306 */
133 * These operating systems already take care of the problem for us.
135 #if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) || \
137 typedef u_int32_t u_32_t
;
140 * Really, any arch where sizeof(long) != sizeof(int).
142 # if defined(__alpha__) || defined(__alpha)
143 typedef unsigned int u_32_t
;
145 typedef unsigned long u_32_t
;
147 #endif /* __NetBSD__ || __OpenBSD__ || __FreeBSD__ || __sgi */
150 #define MAX(a,b) (((a) > (b)) ? (a) : (b))
154 * Security Options for Intenet Protocol (IPSO) as defined in RFC 1108.
158 * 00000001 - (Reserved 4)
159 * 00111101 - Top Secret
161 * 10010110 - Confidential
162 * 01100110 - (Reserved 3)
163 * 11001100 - (Reserved 2)
164 * 10101011 - Unclassified
165 * 11110001 - (Reserved 1)
167 #define IPSO_CLASS_RES4 0x01
168 #define IPSO_CLASS_TOPS 0x3d
169 #define IPSO_CLASS_SECR 0x5a
170 #define IPSO_CLASS_CONF 0x96
171 #define IPSO_CLASS_RES3 0x66
172 #define IPSO_CLASS_RES2 0xcc
173 #define IPSO_CLASS_UNCL 0xab
174 #define IPSO_CLASS_RES1 0xf1
176 #define IPSO_AUTH_GENSER 0x80
177 #define IPSO_AUTH_ESI 0x40
178 #define IPSO_AUTH_SCI 0x20
179 #define IPSO_AUTH_NSA 0x10
180 #define IPSO_AUTH_DOE 0x08
181 #define IPSO_AUTH_UN 0x06
182 #define IPSO_AUTH_FTE 0x01
187 /*#define IPOPT_RR 7 */
188 #define IPOPT_ZSU 10 /* ZSU */
189 #define IPOPT_MTUP 11 /* MTUP */
190 #define IPOPT_MTUR 12 /* MTUR */
191 #define IPOPT_ENCODE 15 /* ENCODE */
192 /*#define IPOPT_TS 68 */
193 #define IPOPT_TR 82 /* TR */
194 /*#define IPOPT_SECURITY 130 */
195 /*#define IPOPT_LSRR 131 */
196 #define IPOPT_E_SEC 133 /* E-SEC */
197 #define IPOPT_CIPSO 134 /* CIPSO */
198 /*#define IPOPT_SATID 136 */
200 # define IPOPT_SID IPOPT_SATID
202 /*#define IPOPT_SSRR 137 */
203 #define IPOPT_ADDEXT 147 /* ADDEXT */
204 #define IPOPT_VISA 142 /* VISA */
205 #define IPOPT_IMITD 144 /* IMITD */
206 #define IPOPT_EIP 145 /* EIP */
207 #define IPOPT_FINN 205 /* FINN */
210 #if defined(__FreeBSD__) && defined(KERNEL)
212 # include <machine/spl.h>
214 # if defined(IPFILTER_LKM) && !defined(ACTUALLY_LKM_NOT_KERNEL)
215 # define ACTUALLY_LKM_NOT_KERNEL
217 #endif /* __FreeBSD__ && KERNEL */
220 * Build some macros and #defines to enable the same code to compile anywhere
221 * Well, that's the idea, anyway :-)
225 # define MUTEX_ENTER(x) mutex_enter(x)
226 # define MUTEX_EXIT(x) mutex_exit(x)
227 # define MTOD(m,t) (t)((m)->b_rptr)
228 # define IRCOPY(a,b,c) copyin((a), (b), (c))
229 # define IWCOPY(a,b,c) copyout((a), (b), (c))
230 # define FREE_MB_T(m) freemsg(m)
231 # define SPL_NET(x) ;
232 # define SPL_IMP(x) ;
236 # define ntohs(x) (x)
237 # define ntohl(x) (x)
238 # define htons(x) (x)
239 # define htonl(x) (x)
241 # define KMALLOC(a,b,c) (a) = (b)kmem_alloc((c), KM_NOSLEEP)
242 # define GET_MINOR(x) getminor(x)
251 struct qinit
*qf_wqinfo
;
252 struct qinit
*qf_rqinfo
;
253 struct qinit qf_wqinit
;
254 struct qinit qf_rqinit
;
255 mblk_t
*qf_m
; /* These three fields are for passing data up from */
256 queue_t
*qf_q
; /* fr_qin and fr_qout to the packet processing. */
258 int qf_len
; /* this field is used for in ipfr_fastroute */
261 * in case the ILL has disappeared...
263 int qf_hl
; /* header length */
265 extern ill_t
*get_unit
__P((char *));
266 # define GETUNIT(n) get_unit((n))
269 # include <sys/ksynch.h>
270 # define IPF_LOCK_PL plhi
271 # include <sys/sema.h>
277 # define MUTEX_ENTER(x) (x)->pl = LOCK((x)->l, IPF_LOCK_PL);
278 # define MUTEX_EXIT(x) UNLOCK((x)->l, (x)->pl);
280 # define MUTEX_ENTER(x) ;
281 # define MUTEX_EXIT(x) ;
284 # define FREE_MB_T(m) m_freem(m)
285 # define MTOD(m,t) mtod(m,t)
286 # define IRCOPY(a,b,c) bcopy((a), (b), (c))
287 # define IWCOPY(a,b,c) bcopy((a), (b), (c))
289 # endif /* SOLARIS */
293 # include <sys/kmem_alloc.h>
294 # define GETUNIT(n) ifunit((n), IFNAMSIZ)
298 # define GETUNIT(n) ifunit((n))
302 # if defined(sun) && !defined(linux) || defined(__sgi)
303 # define UIOMOVE(a,b,c,d) uiomove((caddr_t)a,b,c,d)
304 # define SLEEP(id, n) sleep((id), PZERO+1)
305 # define WAKEUP(id) wakeup(id)
306 # define KFREE(x) kmem_free((char *)(x), sizeof(*(x)))
307 # define KFREES(x,s) kmem_free((char *)(x), (s))
309 extern void m_copydata
__P((struct mbuf
*, int, int, caddr_t
));
310 extern void m_copyback
__P((struct mbuf
*, int, int, caddr_t
));
313 # include <sys/kmem.h>
314 # include <sys/ddi.h>
315 # define KMALLOC(a,b,c) (a) = (b)kmem_alloc((c), KM_NOSLEEP)
316 # define GET_MINOR(x) getminor(x)
319 # define KMALLOC(a,b,c) (a) = (b)new_kmem_alloc((c), KMEM_NOSLEEP)
320 # endif /* SOLARIS */
322 # endif /* sun && !linux */
324 # define GET_MINOR(x) minor(x)
326 # if (BSD >= 199306) || defined(__FreeBSD__)
328 # if !defined(__FreeBSD__) || (defined (__FreeBSD__) && __FreeBSD__>=3)
329 # include <vm/vm_extern.h>
330 # include <sys/proc.h>
331 extern vm_map_t kmem_map
;
332 # else /* !__FreeBSD__ || (__FreeBSD__ && __FreeBSD__>=3) */
333 # include <vm/vm_kern.h>
334 # endif /* !__FreeBSD__ || (__FreeBSD__ && __FreeBSD__>=3) */
336 # define KMALLOC(a, b, c) MALLOC((a), b, (c), M_PFIL, M_NOWAIT)
337 # define KFREE(x) FREE((x), M_PFIL)
338 # define KFREES(x,s) FREE((x), M_PFIL)
340 # define KMALLOC(a, b, c) MALLOC((a), b, (c), M_TEMP, M_NOWAIT)
341 # define KFREE(x) FREE((x), M_TEMP)
342 # define KFREES(x,s) FREE((x), M_TEMP)
344 # define UIOMOVE(a,b,c,d) uiomove(a,b,d)
345 # define SLEEP(id, n) tsleep((id), PPAUSE|PCATCH, n, 0)
346 # define WAKEUP(id) wakeup(id)
348 # if defined(NetBSD) && NetBSD <= 1991011 && NetBSD >= 199407
349 # define SPL_NET(x) x = splsoftnet()
350 # define SPL_X(x) (void) splx(x)
352 # if !SOLARIS && !defined(linux)
353 # define SPL_IMP(x) x = splimp()
354 # define SPL_NET(x) x = splnet()
355 # define SPL_X(x) (void) splx(x)
357 # endif /* NetBSD && NetBSD <= 1991011 && NetBSD >= 199407 */
358 # define PANIC(x,y) if (x) panic y
360 # define SLEEP(x,y) ;
362 # define PANIC(x,y) ;
363 # define MUTEX_ENTER(x) ;
364 # define MUTEX_EXIT(x) ;
365 # define SPL_NET(x) ;
366 # define SPL_IMP(x) ;
369 /*# define KMALLOC(a,b,c) (a) = (b)malloc(c) */
370 # define KFREE(x) FREE(x)
371 # define KFREES(x,s) FREE(x)
372 # define GETUNIT(x) get_unit(x)
373 # define IRCOPY(a,b,c) bcopy((a), (b), (c))
374 # define IWCOPY(a,b,c) bcopy((a), (b), (c))
381 typedef struct sk_buff mb_t
;
383 typedef struct mbuf mb_t
;
387 #if defined(linux) || defined(__sgi)
389 * These #ifdef's are here mainly for linux, but who knows, they may
390 * not be in other places or maybe one day linux will grow up and some
391 * of these will turn up there too.
394 # define ICMP_MINLEN 8
397 # define ICMP_UNREACH ICMP_DEST_UNREACH
399 #ifndef ICMP_SOURCEQUENCH
400 # define ICMP_SOURCEQUENCH ICMP_SOURCE_QUENCH
402 #ifndef ICMP_TIMXCEED
403 # define ICMP_TIMXCEED ICMP_TIME_EXCEEDED
405 #ifndef ICMP_PARAMPROB
406 # define ICMP_PARAMPROB ICMP_PARAMETERPROB
409 # define ICMP_TSTAMP ICMP_TIMESTAMP
411 #ifndef ICMP_TSTAMPREPLY
412 # define ICMP_TSTAMPREPLY ICMP_TIMESTAMPREPLY
415 # define ICMP_IREQ ICMP_INFO_REQUEST
417 #ifndef ICMP_IREQREPLY
418 # define ICMP_IREQREPLY ICMP_INFO_REPLY
421 # define ICMP_MASKREQ ICMP_ADDRESS
423 #ifndef ICMP_MASKREPLY
424 # define ICMP_MASKREPLY ICMP_ADDRESSREPLY
430 # define IPOPT_MINOFF 4
433 # define IPOPT_COPIED(x) ((x)&0x80)
442 # define IP_MF ((u_short)0x2000)
445 # define ETHERTYPE_IP ((u_short)0x0800)
457 # define TH_PUSH 0x08
477 #ifndef IPOPT_SECURITY
478 # define IPOPT_SECURITY 130
481 # define IPOPT_LSRR 131
484 # define IPOPT_SATID 136
487 # define IPOPT_SSRR 137
489 #ifndef IPOPT_SECUR_UNCLASS
490 # define IPOPT_SECUR_UNCLASS ((u_short)0x0000)
492 #ifndef IPOPT_SECUR_CONFID
493 # define IPOPT_SECUR_CONFID ((u_short)0xf135)
495 #ifndef IPOPT_SECUR_EFTO
496 # define IPOPT_SECUR_EFTO ((u_short)0x789a)
498 #ifndef IPOPT_SECUR_MMMM
499 # define IPOPT_SECUR_MMMM ((u_short)0xbc4d)
501 #ifndef IPOPT_SECUR_RESTR
502 # define IPOPT_SECUR_RESTR ((u_short)0xaf13)
504 #ifndef IPOPT_SECUR_SECRET
505 # define IPOPT_SECUR_SECRET ((u_short)0xd788)
507 #ifndef IPOPT_SECUR_TOPSECRET
508 # define IPOPT_SECUR_TOPSECRET ((u_short)0x6bc5)
511 # define IPOPT_OLEN 1
513 #endif /* linux || __sgi */
519 #define TCPS_CLOSED 0 /* closed */
520 #define TCPS_LISTEN 1 /* listening for connection */
521 #define TCPS_SYN_SENT 2 /* active, have sent syn */
522 #define TCPS_SYN_RECEIVED 3 /* have send and received syn */
523 /* states < TCPS_ESTABLISHED are those where connections not established */
524 #define TCPS_ESTABLISHED 4 /* established */
525 #define TCPS_CLOSE_WAIT 5 /* rcvd fin, waiting for close */
526 /* states > TCPS_CLOSE_WAIT are those where user has closed */
527 #define TCPS_FIN_WAIT_1 6 /* have closed, sent fin */
528 #define TCPS_CLOSING 7 /* closed xchd FIN; await FIN ACK */
529 #define TCPS_LAST_ACK 8 /* had fin and close; await FIN ACK */
530 /* states > TCPS_CLOSE_WAIT && < TCPS_FIN_WAIT_2 await ACK of FIN */
531 #define TCPS_FIN_WAIT_2 9 /* have closed, fin is acked */
532 #define TCPS_TIME_WAIT 10 /* in 2*msl quiet wait after close */
540 * mbuf related problems.
542 #define mtod(m,t) (t)((m)->data)
553 # if defined(__i386__) || defined(__MIPSEL__) || defined(__alpha__) ||\
575 # if defined(__i386__) || defined(__MIPSEL__) || defined(__alpha__) ||\
590 struct in_addr ip_src
;
591 struct in_addr ip_dst
;
595 * Structure of an icmp header.
597 typedef struct icmp
{
598 u_char icmp_type
; /* type of message, see below */
599 u_char icmp_code
; /* type sub code */
600 u_short icmp_cksum
; /* ones complement cksum of struct */
602 u_char ih_pptr
; /* ICMP_PARAMPROB */
603 struct in_addr ih_gwaddr
; /* ICMP_REDIRECT */
610 # define icmp_pptr icmp_hun.ih_pptr
611 # define icmp_gwaddr icmp_hun.ih_gwaddr
612 # define icmp_id icmp_hun.ih_idseq.icd_id
613 # define icmp_seq icmp_hun.ih_idseq.icd_seq
614 # define icmp_void icmp_hun.ih_void
623 /* options and then 64 bits of data */
628 # define icmp_otime icmp_dun.id_ts.its_otime
629 # define icmp_rtime icmp_dun.id_ts.its_rtime
630 # define icmp_ttime icmp_dun.id_ts.its_ttime
631 # define icmp_ip icmp_dun.id_ip.idi_ip
632 # define icmp_mask icmp_dun.id_mask
633 # define icmp_data icmp_dun.id_data
636 # ifndef LINUX_IPOVLY
637 # define LINUX_IPOVLY
639 caddr_t ih_next
, ih_prev
; /* for protocol sequence q's */
640 u_char ih_x1
; /* (unused) */
641 u_char ih_pr
; /* protocol */
642 short ih_len
; /* protocol length */
643 struct in_addr ih_src
; /* source internet address */
644 struct in_addr ih_dst
; /* destination internet address */
662 # define UIOMOVE(a, b, c, d) uiomove(a,b,c,d)
665 * For masking struct ifnet onto struct device
667 # define if_name name
670 # define GETUNIT(x) dev_get(x)
671 # define FREE_MB_T(m) kfree_skb(m, FREE_WRITE)
672 # define uniqtime do_gettimeofday
677 # include <linux/netdevice.h>
682 # define bcmp(a,b,c) memcmp(a,b,c)
683 # define bcopy(a,b,c) memcpy(b,a,c)
684 # define bzero(a,c) memset(a,0,c)
686 # define UNITNAME(n) dev_get((n))
688 # define KMALLOC(a,b,c) (a) = (b)kmalloc((c), GFP_ATOMIC)
689 # define KFREE(x) kfree_s((x), sizeof(*(x)))
690 # define KFREES(x,s) kfree_s((x), (s))
691 # define IRCOPY(a,b,c) { \
692 error = verify_area(VERIFY_READ, (a) ,(c)); \
694 memcpy_fromfs((b), (a), (c)); \
696 # define IWCOPY(a,b,c) { \
697 error = verify_area(VERIFY_WRITE, (b), (c)); \
699 memcpy_tofs((b), (a), (c)); \
713 # include <linux/netdevice.h>
716 # define ifnet device
718 typedef struct tcphdr tcphdr_t
;
719 typedef struct udphdr udphdr_t
;
720 typedef struct icmp icmphdr_t
;
721 typedef struct ip ip_t
;
722 typedef struct ether_header ether_header_t
;
724 typedef struct tcpiphdr tcpiphdr_t
;
726 #if defined(hpux) || defined(linux)
728 char ether_addr_octet
[6];
733 * XXX - This is one of those *awful* hacks which nobody likes
741 #ifndef ICMP_ROUTERADVERT
742 # define ICMP_ROUTERADVERT 9
744 #ifndef ICMP_ROUTERSOLICIT
745 # define ICMP_ROUTERSOLICIT 10
748 #endif /* __IP_COMPAT_H__ */