2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
24 * Copyright (C) 1993-1997 by Darren Reed.
26 * Redistribution and use in source and binary forms are permitted
27 * provided that this notice is preserved and due credit is given
28 * to the original author and the contributors.
30 * @(#)ip_compat.h 1.8 1/14/96
32 #include <sys/appleapiopts.h>
36 #ifndef __IP_COMPAT_H__
37 #define __IP_COMPAT_H__
44 #define SOLARIS (defined(sun) && (defined(__svr4__) || defined(__SVR4)))
47 #if defined(_KERNEL) && !defined(KERNEL)
50 #if defined(KERNEL) && !defined(_KERNEL)
53 #if!defined(__KERNEL__) && defined(KERNEL)
57 #if defined(__SVR4) || defined(__svr4__) || defined(__sgi)
59 # if !defined(_KERNEL)
60 # define bzero(a,b) memset(a,0,b)
62 # define bcopy(a,b,c) memmove(b,a,c)
67 u_char ether_addr_octet
[6];
71 # include <sys/sysmacros.h>
74 # define MTYPE(m) ((m)->b_datap->db_type)
75 # include <sys/ioccom.h>
76 # include <sys/sysmacros.h>
77 # include <sys/kmem.h>
79 * because Solaris 2 defines these in two places :-/
89 # include <inet/common.h>
91 # include <inet/ip_ire.h>
94 # include <inet/common.h>
96 # include <inet/ip_ire.h>
99 #define IPMINLEN(i, h) ((i)->ip_len >= ((i)->ip_hl * 4 + sizeof(struct h)))
102 #define IP_OFFMASK 0x1fff
107 # define U_QUAD_T u_quad_t
108 # define QUAD_T quad_t
109 #else /* BSD > 199306 */
110 # define U_QUAD_T u_long
112 #endif /* BSD > 199306 */
115 * These operating systems already take care of the problem for us.
117 #if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) || \
119 typedef u_int32_t u_32_t
;
122 * Really, any arch where sizeof(long) != sizeof(int).
124 # if defined(__alpha__) || defined(__alpha)
125 typedef unsigned int u_32_t
;
127 typedef unsigned long u_32_t
;
129 #endif /* __NetBSD__ || __OpenBSD__ || __FreeBSD__ || __sgi */
132 #define MAX(a,b) (((a) > (b)) ? (a) : (b))
136 * Security Options for Intenet Protocol (IPSO) as defined in RFC 1108.
140 * 00000001 - (Reserved 4)
141 * 00111101 - Top Secret
143 * 10010110 - Confidential
144 * 01100110 - (Reserved 3)
145 * 11001100 - (Reserved 2)
146 * 10101011 - Unclassified
147 * 11110001 - (Reserved 1)
149 #define IPSO_CLASS_RES4 0x01
150 #define IPSO_CLASS_TOPS 0x3d
151 #define IPSO_CLASS_SECR 0x5a
152 #define IPSO_CLASS_CONF 0x96
153 #define IPSO_CLASS_RES3 0x66
154 #define IPSO_CLASS_RES2 0xcc
155 #define IPSO_CLASS_UNCL 0xab
156 #define IPSO_CLASS_RES1 0xf1
158 #define IPSO_AUTH_GENSER 0x80
159 #define IPSO_AUTH_ESI 0x40
160 #define IPSO_AUTH_SCI 0x20
161 #define IPSO_AUTH_NSA 0x10
162 #define IPSO_AUTH_DOE 0x08
163 #define IPSO_AUTH_UN 0x06
164 #define IPSO_AUTH_FTE 0x01
169 /*#define IPOPT_RR 7 */
170 #define IPOPT_ZSU 10 /* ZSU */
171 #define IPOPT_MTUP 11 /* MTUP */
172 #define IPOPT_MTUR 12 /* MTUR */
173 #define IPOPT_ENCODE 15 /* ENCODE */
174 /*#define IPOPT_TS 68 */
175 #define IPOPT_TR 82 /* TR */
176 /*#define IPOPT_SECURITY 130 */
177 /*#define IPOPT_LSRR 131 */
178 #define IPOPT_E_SEC 133 /* E-SEC */
179 #define IPOPT_CIPSO 134 /* CIPSO */
180 /*#define IPOPT_SATID 136 */
182 # define IPOPT_SID IPOPT_SATID
184 /*#define IPOPT_SSRR 137 */
185 #define IPOPT_ADDEXT 147 /* ADDEXT */
186 #define IPOPT_VISA 142 /* VISA */
187 #define IPOPT_IMITD 144 /* IMITD */
188 #define IPOPT_EIP 145 /* EIP */
189 #define IPOPT_FINN 205 /* FINN */
192 #if defined(__FreeBSD__) && defined(KERNEL)
194 # include <machine/spl.h>
196 #endif /* __FreeBSD__ && KERNEL */
199 * Build some macros and #defines to enable the same code to compile anywhere
200 * Well, that's the idea, anyway :-)
204 # define MUTEX_ENTER(x) mutex_enter(x)
205 # define MUTEX_EXIT(x) mutex_exit(x)
206 # define MTOD(m,t) (t)((m)->b_rptr)
207 # define IRCOPY(a,b,c) copyin((a), (b), (c))
208 # define IWCOPY(a,b,c) copyout((a), (b), (c))
209 # define FREE_MB_T(m) freemsg(m)
210 # define SPL_NET(x) ;
211 # define SPL_IMP(x) ;
215 # define ntohs(x) (x)
216 # define ntohl(x) (x)
217 # define htons(x) (x)
218 # define htonl(x) (x)
220 # define KMALLOC(a,b,c) (a) = (b)kmem_alloc((c), KM_NOSLEEP)
221 # define GET_MINOR(x) getminor(x)
230 struct qinit
*qf_wqinfo
;
231 struct qinit
*qf_rqinfo
;
232 struct qinit qf_wqinit
;
233 struct qinit qf_rqinit
;
234 mblk_t
*qf_m
; /* These three fields are for passing data up from */
235 queue_t
*qf_q
; /* fr_qin and fr_qout to the packet processing. */
237 int qf_len
; /* this field is used for in ipfr_fastroute */
240 * in case the ILL has disappeared...
242 int qf_hl
; /* header length */
244 extern ill_t
*get_unit(char *);
245 # define GETUNIT(n) get_unit((n))
248 # include <sys/ksynch.h>
249 # define IPF_LOCK_PL plhi
250 # include <sys/sema.h>
256 # define MUTEX_ENTER(x) (x)->pl = LOCK((x)->l, IPF_LOCK_PL);
257 # define MUTEX_EXIT(x) UNLOCK((x)->l, (x)->pl);
259 # define MUTEX_ENTER(x) ;
260 # define MUTEX_EXIT(x) ;
263 # define FREE_MB_T(m) m_freem(m)
264 # define MTOD(m,t) mtod(m,t)
265 # define IRCOPY(a,b,c) bcopy((a), (b), (c))
266 # define IWCOPY(a,b,c) bcopy((a), (b), (c))
268 # endif /* SOLARIS */
272 # include <sys/kmem_alloc.h>
273 # define GETUNIT(n) ifunit((n), IFNAMSIZ)
277 # define GETUNIT(n) ifunit((n))
281 # if defined(sun) && !defined(linux) || defined(__sgi)
282 # define UIOMOVE(a,b,c,d) uiomove((caddr_t)a,b,c,d)
283 # define SLEEP(id, n) sleep((id), PZERO+1)
284 # define WAKEUP(id) wakeup(id)
285 # define KFREE(x) kmem_free((char *)(x), sizeof(*(x)))
286 # define KFREES(x,s) kmem_free((char *)(x), (s))
288 extern void m_copydata(struct mbuf
*, int, int, caddr_t
);
289 extern void m_copyback(struct mbuf
*, int, int, caddr_t
);
292 # include <sys/kmem.h>
293 # include <sys/ddi.h>
294 # define KMALLOC(a,b,c) (a) = (b)kmem_alloc((c), KM_NOSLEEP)
295 # define GET_MINOR(x) getminor(x)
298 # define KMALLOC(a,b,c) (a) = (b)new_kmem_alloc((c), KMEM_NOSLEEP)
299 # endif /* SOLARIS */
301 # endif /* sun && !linux */
303 # define GET_MINOR(x) minor(x)
305 # if (BSD >= 199306) || defined(__FreeBSD__)
307 # if !defined(__FreeBSD__) || (defined (__FreeBSD__) && __FreeBSD__>=3)
308 # include <vm/vm_extern.h>
309 # include <sys/proc.h>
310 extern vm_map_t kmem_map
;
311 # else /* !__FreeBSD__ || (__FreeBSD__ && __FreeBSD__>=3) */
312 # include <vm/vm_kern.h>
313 # endif /* !__FreeBSD__ || (__FreeBSD__ && __FreeBSD__>=3) */
315 # define KMALLOC(a, b, c) MALLOC((a), b, (c), M_PFIL, M_NOWAIT)
316 # define KFREE(x) FREE((x), M_PFIL)
317 # define KFREES(x,s) FREE((x), M_PFIL)
319 # define KMALLOC(a, b, c) MALLOC((a), b, (c), M_TEMP, M_NOWAIT)
320 # define KFREE(x) FREE((x), M_TEMP)
321 # define KFREES(x,s) FREE((x), M_TEMP)
323 # define UIOMOVE(a,b,c,d) uiomove(a,b,d)
324 # define SLEEP(id, n) tsleep((id), PPAUSE|PCATCH, n, 0)
325 # define WAKEUP(id) wakeup(id)
327 # if defined(NetBSD) && NetBSD <= 1991011 && NetBSD >= 199407
328 # define SPL_NET(x) x = splsoftnet()
329 # define SPL_X(x) (void) splx(x)
331 # if !SOLARIS && !defined(linux)
332 # define SPL_IMP(x) x = splimp()
333 # define SPL_NET(x) x = splnet()
334 # define SPL_X(x) (void) splx(x)
336 # endif /* NetBSD && NetBSD <= 1991011 && NetBSD >= 199407 */
337 # define PANIC(x,y) if (x) panic y
339 # define SLEEP(x,y) ;
341 # define PANIC(x,y) ;
342 # define MUTEX_ENTER(x) ;
343 # define MUTEX_EXIT(x) ;
344 # define SPL_NET(x) ;
345 # define SPL_IMP(x) ;
348 /*# define KMALLOC(a,b,c) (a) = (b)malloc(c) */
349 # define KFREE(x) FREE(x)
350 # define KFREES(x,s) FREE(x)
351 # define GETUNIT(x) get_unit(x)
352 # define IRCOPY(a,b,c) bcopy((a), (b), (c))
353 # define IWCOPY(a,b,c) bcopy((a), (b), (c))
360 typedef struct sk_buff mb_t
;
362 typedef struct mbuf mb_t
;
366 #if defined(linux) || defined(__sgi)
368 * These #ifdef's are here mainly for linux, but who knows, they may
369 * not be in other places or maybe one day linux will grow up and some
370 * of these will turn up there too.
373 # define ICMP_MINLEN 8
376 # define ICMP_UNREACH ICMP_DEST_UNREACH
378 #ifndef ICMP_SOURCEQUENCH
379 # define ICMP_SOURCEQUENCH ICMP_SOURCE_QUENCH
381 #ifndef ICMP_TIMXCEED
382 # define ICMP_TIMXCEED ICMP_TIME_EXCEEDED
384 #ifndef ICMP_PARAMPROB
385 # define ICMP_PARAMPROB ICMP_PARAMETERPROB
388 # define ICMP_TSTAMP ICMP_TIMESTAMP
390 #ifndef ICMP_TSTAMPREPLY
391 # define ICMP_TSTAMPREPLY ICMP_TIMESTAMPREPLY
394 # define ICMP_IREQ ICMP_INFO_REQUEST
396 #ifndef ICMP_IREQREPLY
397 # define ICMP_IREQREPLY ICMP_INFO_REPLY
400 # define ICMP_MASKREQ ICMP_ADDRESS
402 #ifndef ICMP_MASKREPLY
403 # define ICMP_MASKREPLY ICMP_ADDRESSREPLY
409 # define IPOPT_MINOFF 4
412 # define IPOPT_COPIED(x) ((x)&0x80)
421 # define IP_MF ((u_short)0x2000)
424 # define ETHERTYPE_IP ((u_short)0x0800)
436 # define TH_PUSH 0x08
456 #ifndef IPOPT_SECURITY
457 # define IPOPT_SECURITY 130
460 # define IPOPT_LSRR 131
463 # define IPOPT_SATID 136
466 # define IPOPT_SSRR 137
468 #ifndef IPOPT_SECUR_UNCLASS
469 # define IPOPT_SECUR_UNCLASS ((u_short)0x0000)
471 #ifndef IPOPT_SECUR_CONFID
472 # define IPOPT_SECUR_CONFID ((u_short)0xf135)
474 #ifndef IPOPT_SECUR_EFTO
475 # define IPOPT_SECUR_EFTO ((u_short)0x789a)
477 #ifndef IPOPT_SECUR_MMMM
478 # define IPOPT_SECUR_MMMM ((u_short)0xbc4d)
480 #ifndef IPOPT_SECUR_RESTR
481 # define IPOPT_SECUR_RESTR ((u_short)0xaf13)
483 #ifndef IPOPT_SECUR_SECRET
484 # define IPOPT_SECUR_SECRET ((u_short)0xd788)
486 #ifndef IPOPT_SECUR_TOPSECRET
487 # define IPOPT_SECUR_TOPSECRET ((u_short)0x6bc5)
490 # define IPOPT_OLEN 1
492 #endif /* linux || __sgi */
498 #define TCPS_CLOSED 0 /* closed */
499 #define TCPS_LISTEN 1 /* listening for connection */
500 #define TCPS_SYN_SENT 2 /* active, have sent syn */
501 #define TCPS_SYN_RECEIVED 3 /* have send and received syn */
502 /* states < TCPS_ESTABLISHED are those where connections not established */
503 #define TCPS_ESTABLISHED 4 /* established */
504 #define TCPS_CLOSE_WAIT 5 /* rcvd fin, waiting for close */
505 /* states > TCPS_CLOSE_WAIT are those where user has closed */
506 #define TCPS_FIN_WAIT_1 6 /* have closed, sent fin */
507 #define TCPS_CLOSING 7 /* closed xchd FIN; await FIN ACK */
508 #define TCPS_LAST_ACK 8 /* had fin and close; await FIN ACK */
509 /* states > TCPS_CLOSE_WAIT && < TCPS_FIN_WAIT_2 await ACK of FIN */
510 #define TCPS_FIN_WAIT_2 9 /* have closed, fin is acked */
511 #define TCPS_TIME_WAIT 10 /* in 2*msl quiet wait after close */
519 * mbuf related problems.
521 #define mtod(m,t) (t)((m)->data)
532 # if defined(__i386__) || defined(__MIPSEL__) || defined(__alpha__) ||\
554 # if defined(__i386__) || defined(__MIPSEL__) || defined(__alpha__) ||\
569 struct in_addr ip_src
;
570 struct in_addr ip_dst
;
574 * Structure of an icmp header.
576 typedef struct icmp
{
577 u_char icmp_type
; /* type of message, see below */
578 u_char icmp_code
; /* type sub code */
579 u_short icmp_cksum
; /* ones complement cksum of struct */
581 u_char ih_pptr
; /* ICMP_PARAMPROB */
582 struct in_addr ih_gwaddr
; /* ICMP_REDIRECT */
589 # define icmp_pptr icmp_hun.ih_pptr
590 # define icmp_gwaddr icmp_hun.ih_gwaddr
591 # define icmp_id icmp_hun.ih_idseq.icd_id
592 # define icmp_seq icmp_hun.ih_idseq.icd_seq
593 # define icmp_void icmp_hun.ih_void
602 /* options and then 64 bits of data */
607 # define icmp_otime icmp_dun.id_ts.its_otime
608 # define icmp_rtime icmp_dun.id_ts.its_rtime
609 # define icmp_ttime icmp_dun.id_ts.its_ttime
610 # define icmp_ip icmp_dun.id_ip.idi_ip
611 # define icmp_mask icmp_dun.id_mask
612 # define icmp_data icmp_dun.id_data
615 # ifndef LINUX_IPOVLY
616 # define LINUX_IPOVLY
618 caddr_t ih_next
, ih_prev
; /* for protocol sequence q's */
619 u_char ih_x1
; /* (unused) */
620 u_char ih_pr
; /* protocol */
621 short ih_len
; /* protocol length */
622 struct in_addr ih_src
; /* source internet address */
623 struct in_addr ih_dst
; /* destination internet address */
641 # define UIOMOVE(a, b, c, d) uiomove(a,b,c,d)
644 * For masking struct ifnet onto struct device
646 # define if_name name
649 # define GETUNIT(x) dev_get(x)
650 # define FREE_MB_T(m) kfree_skb(m, FREE_WRITE)
651 # define uniqtime do_gettimeofday
656 # include <linux/netdevice.h>
661 # define bcmp(a,b,c) memcmp(a,b,c)
662 # define bcopy(a,b,c) memcpy(b,a,c)
663 # define bzero(a,c) memset(a,0,c)
665 # define UNITNAME(n) dev_get((n))
667 # define KMALLOC(a,b,c) (a) = (b)kmalloc((c), GFP_ATOMIC)
668 # define KFREE(x) kfree_s((x), sizeof(*(x)))
669 # define KFREES(x,s) kfree_s((x), (s))
670 # define IRCOPY(a,b,c) { \
671 error = verify_area(VERIFY_READ, (a) ,(c)); \
673 memcpy_fromfs((b), (a), (c)); \
675 # define IWCOPY(a,b,c) { \
676 error = verify_area(VERIFY_WRITE, (b), (c)); \
678 memcpy_tofs((b), (a), (c)); \
692 # include <linux/netdevice.h>
695 # define ifnet device
697 typedef struct tcphdr tcphdr_t
;
698 typedef struct udphdr udphdr_t
;
699 typedef struct icmp icmphdr_t
;
700 typedef struct ip ip_t
;
701 typedef struct ether_header ether_header_t
;
703 typedef struct tcpiphdr tcpiphdr_t
;
705 #if defined(hpux) || defined(linux)
707 char ether_addr_octet
[6];
712 * XXX - This is one of those *awful* hacks which nobody likes
720 #ifndef ICMP_ROUTERADVERT
721 # define ICMP_ROUTERADVERT 9
723 #ifndef ICMP_ROUTERSOLICIT
724 # define ICMP_ROUTERSOLICIT 10
727 #endif /* __IP_COMPAT_H__ */