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
31 #include <sys/appleapiopts.h>
35 #ifndef __IP_COMPAT_H__
36 #define __IP_COMPAT_H__
43 #define SOLARIS (defined(sun) && (defined(__svr4__) || defined(__SVR4)))
46 #if defined(_KERNEL) && !defined(KERNEL)
49 #if defined(KERNEL) && !defined(_KERNEL)
52 #if!defined(__KERNEL__) && defined(KERNEL)
56 #if defined(__SVR4) || defined(__svr4__) || defined(__sgi)
58 # if !defined(_KERNEL)
59 # define bzero(a,b) memset(a,0,b)
61 # define bcopy(a,b,c) memmove(b,a,c)
66 u_char ether_addr_octet
[6];
70 # include <sys/sysmacros.h>
73 # define MTYPE(m) ((m)->b_datap->db_type)
74 # include <sys/ioccom.h>
75 # include <sys/sysmacros.h>
76 # include <sys/kmem.h>
78 * because Solaris 2 defines these in two places :-/
88 # include <inet/common.h>
90 # include <inet/ip_ire.h>
93 # include <inet/common.h>
95 # include <inet/ip_ire.h>
98 #define IPMINLEN(i, h) ((i)->ip_len >= ((i)->ip_hl * 4 + sizeof(struct h)))
101 #define IP_OFFMASK 0x1fff
106 # define U_QUAD_T u_quad_t
107 # define QUAD_T quad_t
108 #else /* BSD > 199306 */
109 # define U_QUAD_T u_long
111 #endif /* BSD > 199306 */
114 * These operating systems already take care of the problem for us.
116 #if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) || \
118 typedef u_int32_t u_32_t
;
121 * Really, any arch where sizeof(long) != sizeof(int).
123 # if defined(__alpha__) || defined(__alpha)
124 typedef unsigned int u_32_t
;
126 typedef unsigned long u_32_t
;
128 #endif /* __NetBSD__ || __OpenBSD__ || __FreeBSD__ || __sgi */
131 #define MAX(a,b) (((a) > (b)) ? (a) : (b))
135 * Security Options for Intenet Protocol (IPSO) as defined in RFC 1108.
139 * 00000001 - (Reserved 4)
140 * 00111101 - Top Secret
142 * 10010110 - Confidential
143 * 01100110 - (Reserved 3)
144 * 11001100 - (Reserved 2)
145 * 10101011 - Unclassified
146 * 11110001 - (Reserved 1)
148 #define IPSO_CLASS_RES4 0x01
149 #define IPSO_CLASS_TOPS 0x3d
150 #define IPSO_CLASS_SECR 0x5a
151 #define IPSO_CLASS_CONF 0x96
152 #define IPSO_CLASS_RES3 0x66
153 #define IPSO_CLASS_RES2 0xcc
154 #define IPSO_CLASS_UNCL 0xab
155 #define IPSO_CLASS_RES1 0xf1
157 #define IPSO_AUTH_GENSER 0x80
158 #define IPSO_AUTH_ESI 0x40
159 #define IPSO_AUTH_SCI 0x20
160 #define IPSO_AUTH_NSA 0x10
161 #define IPSO_AUTH_DOE 0x08
162 #define IPSO_AUTH_UN 0x06
163 #define IPSO_AUTH_FTE 0x01
168 /*#define IPOPT_RR 7 */
169 #define IPOPT_ZSU 10 /* ZSU */
170 #define IPOPT_MTUP 11 /* MTUP */
171 #define IPOPT_MTUR 12 /* MTUR */
172 #define IPOPT_ENCODE 15 /* ENCODE */
173 /*#define IPOPT_TS 68 */
174 #define IPOPT_TR 82 /* TR */
175 /*#define IPOPT_SECURITY 130 */
176 /*#define IPOPT_LSRR 131 */
177 #define IPOPT_E_SEC 133 /* E-SEC */
178 #define IPOPT_CIPSO 134 /* CIPSO */
179 /*#define IPOPT_SATID 136 */
181 # define IPOPT_SID IPOPT_SATID
183 /*#define IPOPT_SSRR 137 */
184 #define IPOPT_ADDEXT 147 /* ADDEXT */
185 #define IPOPT_VISA 142 /* VISA */
186 #define IPOPT_IMITD 144 /* IMITD */
187 #define IPOPT_EIP 145 /* EIP */
188 #define IPOPT_FINN 205 /* FINN */
191 #if defined(__FreeBSD__) && defined(KERNEL)
193 # include <machine/spl.h>
195 #endif /* __FreeBSD__ && KERNEL */
198 * Build some macros and #defines to enable the same code to compile anywhere
199 * Well, that's the idea, anyway :-)
203 # define MUTEX_ENTER(x) mutex_enter(x)
204 # define MUTEX_EXIT(x) mutex_exit(x)
205 # define MTOD(m,t) (t)((m)->b_rptr)
206 # define IRCOPY(a,b,c) copyin((a), (b), (c))
207 # define IWCOPY(a,b,c) copyout((a), (b), (c))
208 # define FREE_MB_T(m) freemsg(m)
209 # define SPL_NET(x) ;
210 # define SPL_IMP(x) ;
214 # define ntohs(x) (x)
215 # define ntohl(x) (x)
216 # define htons(x) (x)
217 # define htonl(x) (x)
219 # define KMALLOC(a,b,c) (a) = (b)kmem_alloc((c), KM_NOSLEEP)
220 # define GET_MINOR(x) getminor(x)
229 struct qinit
*qf_wqinfo
;
230 struct qinit
*qf_rqinfo
;
231 struct qinit qf_wqinit
;
232 struct qinit qf_rqinit
;
233 mblk_t
*qf_m
; /* These three fields are for passing data up from */
234 queue_t
*qf_q
; /* fr_qin and fr_qout to the packet processing. */
236 int qf_len
; /* this field is used for in ipfr_fastroute */
239 * in case the ILL has disappeared...
241 int qf_hl
; /* header length */
243 extern ill_t
*get_unit(char *);
244 # define GETUNIT(n) get_unit((n))
247 # include <sys/ksynch.h>
248 # define IPF_LOCK_PL plhi
249 # include <sys/sema.h>
255 # define MUTEX_ENTER(x) (x)->pl = LOCK((x)->l, IPF_LOCK_PL);
256 # define MUTEX_EXIT(x) UNLOCK((x)->l, (x)->pl);
258 # define MUTEX_ENTER(x) ;
259 # define MUTEX_EXIT(x) ;
262 # define FREE_MB_T(m) m_freem(m)
263 # define MTOD(m,t) mtod(m,t)
264 # define IRCOPY(a,b,c) bcopy((a), (b), (c))
265 # define IWCOPY(a,b,c) bcopy((a), (b), (c))
267 # endif /* SOLARIS */
271 # include <sys/kmem_alloc.h>
272 # define GETUNIT(n) ifunit((n), IFNAMSIZ)
276 # define GETUNIT(n) ifunit((n))
280 # if defined(sun) && !defined(linux) || defined(__sgi)
281 # define UIOMOVE(a,b,c,d) uiomove((caddr_t)a,b,c,d)
282 # define SLEEP(id, n) sleep((id), PZERO+1)
283 # define WAKEUP(id) wakeup(id)
284 # define KFREE(x) kmem_free((char *)(x), sizeof(*(x)))
285 # define KFREES(x,s) kmem_free((char *)(x), (s))
287 extern void m_copydata(struct mbuf
*, int, int, caddr_t
);
288 extern void m_copyback(struct mbuf
*, int, int, caddr_t
);
291 # include <sys/kmem.h>
292 # include <sys/ddi.h>
293 # define KMALLOC(a,b,c) (a) = (b)kmem_alloc((c), KM_NOSLEEP)
294 # define GET_MINOR(x) getminor(x)
297 # define KMALLOC(a,b,c) (a) = (b)new_kmem_alloc((c), KMEM_NOSLEEP)
298 # endif /* SOLARIS */
300 # endif /* sun && !linux */
302 # define GET_MINOR(x) minor(x)
304 # if (BSD >= 199306) || defined(__FreeBSD__)
306 # if !defined(__FreeBSD__) || (defined (__FreeBSD__) && __FreeBSD__>=3)
307 # include <vm/vm_extern.h>
308 # include <sys/proc.h>
309 extern vm_map_t kmem_map
;
310 # else /* !__FreeBSD__ || (__FreeBSD__ && __FreeBSD__>=3) */
311 # include <vm/vm_kern.h>
312 # endif /* !__FreeBSD__ || (__FreeBSD__ && __FreeBSD__>=3) */
314 # define KMALLOC(a, b, c) MALLOC((a), b, (c), M_PFIL, M_NOWAIT)
315 # define KFREE(x) FREE((x), M_PFIL)
316 # define KFREES(x,s) FREE((x), M_PFIL)
318 # define KMALLOC(a, b, c) MALLOC((a), b, (c), M_TEMP, M_NOWAIT)
319 # define KFREE(x) FREE((x), M_TEMP)
320 # define KFREES(x,s) FREE((x), M_TEMP)
322 # define UIOMOVE(a,b,c,d) uiomove(a,b,d)
323 # define SLEEP(id, n) tsleep((id), PPAUSE|PCATCH, n, 0)
324 # define WAKEUP(id) wakeup(id)
326 # if defined(NetBSD) && NetBSD <= 1991011 && NetBSD >= 199407
327 # define SPL_NET(x) x = splsoftnet()
328 # define SPL_X(x) (void) splx(x)
330 # if !SOLARIS && !defined(linux)
331 # define SPL_IMP(x) x = splimp()
332 # define SPL_NET(x) x = splnet()
333 # define SPL_X(x) (void) splx(x)
335 # endif /* NetBSD && NetBSD <= 1991011 && NetBSD >= 199407 */
336 # define PANIC(x,y) if (x) panic y
338 # define SLEEP(x,y) ;
340 # define PANIC(x,y) ;
341 # define MUTEX_ENTER(x) ;
342 # define MUTEX_EXIT(x) ;
343 # define SPL_NET(x) ;
344 # define SPL_IMP(x) ;
347 /*# define KMALLOC(a,b,c) (a) = (b)malloc(c) */
348 # define KFREE(x) FREE(x)
349 # define KFREES(x,s) FREE(x)
350 # define GETUNIT(x) get_unit(x)
351 # define IRCOPY(a,b,c) bcopy((a), (b), (c))
352 # define IWCOPY(a,b,c) bcopy((a), (b), (c))
359 typedef struct sk_buff mb_t
;
361 typedef struct mbuf mb_t
;
365 #if defined(linux) || defined(__sgi)
367 * These #ifdef's are here mainly for linux, but who knows, they may
368 * not be in other places or maybe one day linux will grow up and some
369 * of these will turn up there too.
372 # define ICMP_MINLEN 8
375 # define ICMP_UNREACH ICMP_DEST_UNREACH
377 #ifndef ICMP_SOURCEQUENCH
378 # define ICMP_SOURCEQUENCH ICMP_SOURCE_QUENCH
380 #ifndef ICMP_TIMXCEED
381 # define ICMP_TIMXCEED ICMP_TIME_EXCEEDED
383 #ifndef ICMP_PARAMPROB
384 # define ICMP_PARAMPROB ICMP_PARAMETERPROB
387 # define ICMP_TSTAMP ICMP_TIMESTAMP
389 #ifndef ICMP_TSTAMPREPLY
390 # define ICMP_TSTAMPREPLY ICMP_TIMESTAMPREPLY
393 # define ICMP_IREQ ICMP_INFO_REQUEST
395 #ifndef ICMP_IREQREPLY
396 # define ICMP_IREQREPLY ICMP_INFO_REPLY
399 # define ICMP_MASKREQ ICMP_ADDRESS
401 #ifndef ICMP_MASKREPLY
402 # define ICMP_MASKREPLY ICMP_ADDRESSREPLY
408 # define IPOPT_MINOFF 4
411 # define IPOPT_COPIED(x) ((x)&0x80)
420 # define IP_MF ((u_short)0x2000)
423 # define ETHERTYPE_IP ((u_short)0x0800)
435 # define TH_PUSH 0x08
455 #ifndef IPOPT_SECURITY
456 # define IPOPT_SECURITY 130
459 # define IPOPT_LSRR 131
462 # define IPOPT_SATID 136
465 # define IPOPT_SSRR 137
467 #ifndef IPOPT_SECUR_UNCLASS
468 # define IPOPT_SECUR_UNCLASS ((u_short)0x0000)
470 #ifndef IPOPT_SECUR_CONFID
471 # define IPOPT_SECUR_CONFID ((u_short)0xf135)
473 #ifndef IPOPT_SECUR_EFTO
474 # define IPOPT_SECUR_EFTO ((u_short)0x789a)
476 #ifndef IPOPT_SECUR_MMMM
477 # define IPOPT_SECUR_MMMM ((u_short)0xbc4d)
479 #ifndef IPOPT_SECUR_RESTR
480 # define IPOPT_SECUR_RESTR ((u_short)0xaf13)
482 #ifndef IPOPT_SECUR_SECRET
483 # define IPOPT_SECUR_SECRET ((u_short)0xd788)
485 #ifndef IPOPT_SECUR_TOPSECRET
486 # define IPOPT_SECUR_TOPSECRET ((u_short)0x6bc5)
489 # define IPOPT_OLEN 1
491 #endif /* linux || __sgi */
497 #define TCPS_CLOSED 0 /* closed */
498 #define TCPS_LISTEN 1 /* listening for connection */
499 #define TCPS_SYN_SENT 2 /* active, have sent syn */
500 #define TCPS_SYN_RECEIVED 3 /* have send and received syn */
501 /* states < TCPS_ESTABLISHED are those where connections not established */
502 #define TCPS_ESTABLISHED 4 /* established */
503 #define TCPS_CLOSE_WAIT 5 /* rcvd fin, waiting for close */
504 /* states > TCPS_CLOSE_WAIT are those where user has closed */
505 #define TCPS_FIN_WAIT_1 6 /* have closed, sent fin */
506 #define TCPS_CLOSING 7 /* closed xchd FIN; await FIN ACK */
507 #define TCPS_LAST_ACK 8 /* had fin and close; await FIN ACK */
508 /* states > TCPS_CLOSE_WAIT && < TCPS_FIN_WAIT_2 await ACK of FIN */
509 #define TCPS_FIN_WAIT_2 9 /* have closed, fin is acked */
510 #define TCPS_TIME_WAIT 10 /* in 2*msl quiet wait after close */
518 * mbuf related problems.
520 #define mtod(m,t) (t)((m)->data)
531 # if defined(__i386__) || defined(__MIPSEL__) || defined(__alpha__) ||\
553 # if defined(__i386__) || defined(__MIPSEL__) || defined(__alpha__) ||\
568 struct in_addr ip_src
;
569 struct in_addr ip_dst
;
573 * Structure of an icmp header.
575 typedef struct icmp
{
576 u_char icmp_type
; /* type of message, see below */
577 u_char icmp_code
; /* type sub code */
578 u_short icmp_cksum
; /* ones complement cksum of struct */
580 u_char ih_pptr
; /* ICMP_PARAMPROB */
581 struct in_addr ih_gwaddr
; /* ICMP_REDIRECT */
588 # define icmp_pptr icmp_hun.ih_pptr
589 # define icmp_gwaddr icmp_hun.ih_gwaddr
590 # define icmp_id icmp_hun.ih_idseq.icd_id
591 # define icmp_seq icmp_hun.ih_idseq.icd_seq
592 # define icmp_void icmp_hun.ih_void
601 /* options and then 64 bits of data */
606 # define icmp_otime icmp_dun.id_ts.its_otime
607 # define icmp_rtime icmp_dun.id_ts.its_rtime
608 # define icmp_ttime icmp_dun.id_ts.its_ttime
609 # define icmp_ip icmp_dun.id_ip.idi_ip
610 # define icmp_mask icmp_dun.id_mask
611 # define icmp_data icmp_dun.id_data
614 # ifndef LINUX_IPOVLY
615 # define LINUX_IPOVLY
617 caddr_t ih_next
, ih_prev
; /* for protocol sequence q's */
618 u_char ih_x1
; /* (unused) */
619 u_char ih_pr
; /* protocol */
620 short ih_len
; /* protocol length */
621 struct in_addr ih_src
; /* source internet address */
622 struct in_addr ih_dst
; /* destination internet address */
640 # define UIOMOVE(a, b, c, d) uiomove(a,b,c,d)
643 * For masking struct ifnet onto struct device
645 # define if_name name
648 # define GETUNIT(x) dev_get(x)
649 # define FREE_MB_T(m) kfree_skb(m, FREE_WRITE)
650 # define uniqtime do_gettimeofday
655 # include <linux/netdevice.h>
660 # define bcmp(a,b,c) memcmp(a,b,c)
661 # define bcopy(a,b,c) memcpy(b,a,c)
662 # define bzero(a,c) memset(a,0,c)
664 # define UNITNAME(n) dev_get((n))
666 # define KMALLOC(a,b,c) (a) = (b)kmalloc((c), GFP_ATOMIC)
667 # define KFREE(x) kfree_s((x), sizeof(*(x)))
668 # define KFREES(x,s) kfree_s((x), (s))
669 # define IRCOPY(a,b,c) { \
670 error = verify_area(VERIFY_READ, (a) ,(c)); \
672 memcpy_fromfs((b), (a), (c)); \
674 # define IWCOPY(a,b,c) { \
675 error = verify_area(VERIFY_WRITE, (b), (c)); \
677 memcpy_tofs((b), (a), (c)); \
691 # include <linux/netdevice.h>
694 # define ifnet device
696 typedef struct tcphdr tcphdr_t
;
697 typedef struct udphdr udphdr_t
;
698 typedef struct icmp icmphdr_t
;
699 typedef struct ip ip_t
;
700 typedef struct ether_header ether_header_t
;
702 typedef struct tcpiphdr tcpiphdr_t
;
704 #if defined(hpux) || defined(linux)
706 char ether_addr_octet
[6];
711 * XXX - This is one of those *awful* hacks which nobody likes
719 #ifndef ICMP_ROUTERADVERT
720 # define ICMP_ROUTERADVERT 9
722 #ifndef ICMP_ROUTERSOLICIT
723 # define ICMP_ROUTERSOLICIT 10
726 #endif /* __IP_COMPAT_H__ */