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 # include <sys/sysmacros.h>
77 # define MTYPE(m) ((m)->b_datap->db_type)
78 # include <sys/ioccom.h>
79 # include <sys/sysmacros.h>
80 # include <sys/kmem.h>
82 * because Solaris 2 defines these in two places :-/
92 # include <inet/common.h>
94 # include <inet/ip_ire.h>
97 # include <inet/common.h>
99 # include <inet/ip_ire.h>
100 # endif /* _KERNEL */
102 #define IPMINLEN(i, h) ((i)->ip_len >= ((i)->ip_hl * 4 + sizeof(struct h)))
105 #define IP_OFFMASK 0x1fff
110 # define U_QUAD_T u_quad_t
111 # define QUAD_T quad_t
112 #else /* BSD > 199306 */
113 # define U_QUAD_T u_long
115 #endif /* BSD > 199306 */
118 * These operating systems already take care of the problem for us.
120 #if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) || \
122 typedef u_int32_t u_32_t
;
125 * Really, any arch where sizeof(long) != sizeof(int).
127 # if defined(__alpha__) || defined(__alpha)
128 typedef unsigned int u_32_t
;
130 typedef unsigned long u_32_t
;
132 #endif /* __NetBSD__ || __OpenBSD__ || __FreeBSD__ || __sgi */
135 #define MAX(a,b) (((a) > (b)) ? (a) : (b))
139 * Security Options for Intenet Protocol (IPSO) as defined in RFC 1108.
143 * 00000001 - (Reserved 4)
144 * 00111101 - Top Secret
146 * 10010110 - Confidential
147 * 01100110 - (Reserved 3)
148 * 11001100 - (Reserved 2)
149 * 10101011 - Unclassified
150 * 11110001 - (Reserved 1)
152 #define IPSO_CLASS_RES4 0x01
153 #define IPSO_CLASS_TOPS 0x3d
154 #define IPSO_CLASS_SECR 0x5a
155 #define IPSO_CLASS_CONF 0x96
156 #define IPSO_CLASS_RES3 0x66
157 #define IPSO_CLASS_RES2 0xcc
158 #define IPSO_CLASS_UNCL 0xab
159 #define IPSO_CLASS_RES1 0xf1
161 #define IPSO_AUTH_GENSER 0x80
162 #define IPSO_AUTH_ESI 0x40
163 #define IPSO_AUTH_SCI 0x20
164 #define IPSO_AUTH_NSA 0x10
165 #define IPSO_AUTH_DOE 0x08
166 #define IPSO_AUTH_UN 0x06
167 #define IPSO_AUTH_FTE 0x01
172 /*#define IPOPT_RR 7 */
173 #define IPOPT_ZSU 10 /* ZSU */
174 #define IPOPT_MTUP 11 /* MTUP */
175 #define IPOPT_MTUR 12 /* MTUR */
176 #define IPOPT_ENCODE 15 /* ENCODE */
177 /*#define IPOPT_TS 68 */
178 #define IPOPT_TR 82 /* TR */
179 /*#define IPOPT_SECURITY 130 */
180 /*#define IPOPT_LSRR 131 */
181 #define IPOPT_E_SEC 133 /* E-SEC */
182 #define IPOPT_CIPSO 134 /* CIPSO */
183 /*#define IPOPT_SATID 136 */
185 # define IPOPT_SID IPOPT_SATID
187 /*#define IPOPT_SSRR 137 */
188 #define IPOPT_ADDEXT 147 /* ADDEXT */
189 #define IPOPT_VISA 142 /* VISA */
190 #define IPOPT_IMITD 144 /* IMITD */
191 #define IPOPT_EIP 145 /* EIP */
192 #define IPOPT_FINN 205 /* FINN */
195 #if defined(__FreeBSD__) && defined(KERNEL)
197 # include <machine/spl.h>
199 #endif /* __FreeBSD__ && KERNEL */
202 * Build some macros and #defines to enable the same code to compile anywhere
203 * Well, that's the idea, anyway :-)
207 # define MUTEX_ENTER(x) mutex_enter(x)
208 # define MUTEX_EXIT(x) mutex_exit(x)
209 # define MTOD(m,t) (t)((m)->b_rptr)
210 # define IRCOPY(a,b,c) copyin((a), (b), (c))
211 # define IWCOPY(a,b,c) copyout((a), (b), (c))
212 # define FREE_MB_T(m) freemsg(m)
213 # define SPL_NET(x) ;
214 # define SPL_IMP(x) ;
218 # define ntohs(x) (x)
219 # define ntohl(x) (x)
220 # define htons(x) (x)
221 # define htonl(x) (x)
223 # define KMALLOC(a,b,c) (a) = (b)kmem_alloc((c), KM_NOSLEEP)
224 # define GET_MINOR(x) getminor(x)
233 struct qinit
*qf_wqinfo
;
234 struct qinit
*qf_rqinfo
;
235 struct qinit qf_wqinit
;
236 struct qinit qf_rqinit
;
237 mblk_t
*qf_m
; /* These three fields are for passing data up from */
238 queue_t
*qf_q
; /* fr_qin and fr_qout to the packet processing. */
240 int qf_len
; /* this field is used for in ipfr_fastroute */
243 * in case the ILL has disappeared...
245 int qf_hl
; /* header length */
247 extern ill_t
*get_unit
__P((char *));
248 # define GETUNIT(n) get_unit((n))
251 # include <sys/ksynch.h>
252 # define IPF_LOCK_PL plhi
253 # include <sys/sema.h>
259 # define MUTEX_ENTER(x) (x)->pl = LOCK((x)->l, IPF_LOCK_PL);
260 # define MUTEX_EXIT(x) UNLOCK((x)->l, (x)->pl);
262 # define MUTEX_ENTER(x) ;
263 # define MUTEX_EXIT(x) ;
266 # define FREE_MB_T(m) m_freem(m)
267 # define MTOD(m,t) mtod(m,t)
268 # define IRCOPY(a,b,c) bcopy((a), (b), (c))
269 # define IWCOPY(a,b,c) bcopy((a), (b), (c))
271 # endif /* SOLARIS */
275 # include <sys/kmem_alloc.h>
276 # define GETUNIT(n) ifunit((n), IFNAMSIZ)
280 # define GETUNIT(n) ifunit((n))
284 # if defined(sun) && !defined(linux) || defined(__sgi)
285 # define UIOMOVE(a,b,c,d) uiomove((caddr_t)a,b,c,d)
286 # define SLEEP(id, n) sleep((id), PZERO+1)
287 # define WAKEUP(id) wakeup(id)
288 # define KFREE(x) kmem_free((char *)(x), sizeof(*(x)))
289 # define KFREES(x,s) kmem_free((char *)(x), (s))
291 extern void m_copydata
__P((struct mbuf
*, int, int, caddr_t
));
292 extern void m_copyback
__P((struct mbuf
*, int, int, caddr_t
));
295 # include <sys/kmem.h>
296 # include <sys/ddi.h>
297 # define KMALLOC(a,b,c) (a) = (b)kmem_alloc((c), KM_NOSLEEP)
298 # define GET_MINOR(x) getminor(x)
301 # define KMALLOC(a,b,c) (a) = (b)new_kmem_alloc((c), KMEM_NOSLEEP)
302 # endif /* SOLARIS */
304 # endif /* sun && !linux */
306 # define GET_MINOR(x) minor(x)
308 # if (BSD >= 199306) || defined(__FreeBSD__)
310 # if !defined(__FreeBSD__) || (defined (__FreeBSD__) && __FreeBSD__>=3)
311 # include <vm/vm_extern.h>
312 # include <sys/proc.h>
313 extern vm_map_t kmem_map
;
314 # else /* !__FreeBSD__ || (__FreeBSD__ && __FreeBSD__>=3) */
315 # include <vm/vm_kern.h>
316 # endif /* !__FreeBSD__ || (__FreeBSD__ && __FreeBSD__>=3) */
318 # define KMALLOC(a, b, c) MALLOC((a), b, (c), M_PFIL, M_NOWAIT)
319 # define KFREE(x) FREE((x), M_PFIL)
320 # define KFREES(x,s) FREE((x), M_PFIL)
322 # define KMALLOC(a, b, c) MALLOC((a), b, (c), M_TEMP, M_NOWAIT)
323 # define KFREE(x) FREE((x), M_TEMP)
324 # define KFREES(x,s) FREE((x), M_TEMP)
326 # define UIOMOVE(a,b,c,d) uiomove(a,b,d)
327 # define SLEEP(id, n) tsleep((id), PPAUSE|PCATCH, n, 0)
328 # define WAKEUP(id) wakeup(id)
330 # if defined(NetBSD) && NetBSD <= 1991011 && NetBSD >= 199407
331 # define SPL_NET(x) x = splsoftnet()
332 # define SPL_X(x) (void) splx(x)
334 # if !SOLARIS && !defined(linux)
335 # define SPL_IMP(x) x = splimp()
336 # define SPL_NET(x) x = splnet()
337 # define SPL_X(x) (void) splx(x)
339 # endif /* NetBSD && NetBSD <= 1991011 && NetBSD >= 199407 */
340 # define PANIC(x,y) if (x) panic y
342 # define SLEEP(x,y) ;
344 # define PANIC(x,y) ;
345 # define MUTEX_ENTER(x) ;
346 # define MUTEX_EXIT(x) ;
347 # define SPL_NET(x) ;
348 # define SPL_IMP(x) ;
351 /*# define KMALLOC(a,b,c) (a) = (b)malloc(c) */
352 # define KFREE(x) FREE(x)
353 # define KFREES(x,s) FREE(x)
354 # define GETUNIT(x) get_unit(x)
355 # define IRCOPY(a,b,c) bcopy((a), (b), (c))
356 # define IWCOPY(a,b,c) bcopy((a), (b), (c))
363 typedef struct sk_buff mb_t
;
365 typedef struct mbuf mb_t
;
369 #if defined(linux) || defined(__sgi)
371 * These #ifdef's are here mainly for linux, but who knows, they may
372 * not be in other places or maybe one day linux will grow up and some
373 * of these will turn up there too.
376 # define ICMP_MINLEN 8
379 # define ICMP_UNREACH ICMP_DEST_UNREACH
381 #ifndef ICMP_SOURCEQUENCH
382 # define ICMP_SOURCEQUENCH ICMP_SOURCE_QUENCH
384 #ifndef ICMP_TIMXCEED
385 # define ICMP_TIMXCEED ICMP_TIME_EXCEEDED
387 #ifndef ICMP_PARAMPROB
388 # define ICMP_PARAMPROB ICMP_PARAMETERPROB
391 # define ICMP_TSTAMP ICMP_TIMESTAMP
393 #ifndef ICMP_TSTAMPREPLY
394 # define ICMP_TSTAMPREPLY ICMP_TIMESTAMPREPLY
397 # define ICMP_IREQ ICMP_INFO_REQUEST
399 #ifndef ICMP_IREQREPLY
400 # define ICMP_IREQREPLY ICMP_INFO_REPLY
403 # define ICMP_MASKREQ ICMP_ADDRESS
405 #ifndef ICMP_MASKREPLY
406 # define ICMP_MASKREPLY ICMP_ADDRESSREPLY
412 # define IPOPT_MINOFF 4
415 # define IPOPT_COPIED(x) ((x)&0x80)
424 # define IP_MF ((u_short)0x2000)
427 # define ETHERTYPE_IP ((u_short)0x0800)
439 # define TH_PUSH 0x08
459 #ifndef IPOPT_SECURITY
460 # define IPOPT_SECURITY 130
463 # define IPOPT_LSRR 131
466 # define IPOPT_SATID 136
469 # define IPOPT_SSRR 137
471 #ifndef IPOPT_SECUR_UNCLASS
472 # define IPOPT_SECUR_UNCLASS ((u_short)0x0000)
474 #ifndef IPOPT_SECUR_CONFID
475 # define IPOPT_SECUR_CONFID ((u_short)0xf135)
477 #ifndef IPOPT_SECUR_EFTO
478 # define IPOPT_SECUR_EFTO ((u_short)0x789a)
480 #ifndef IPOPT_SECUR_MMMM
481 # define IPOPT_SECUR_MMMM ((u_short)0xbc4d)
483 #ifndef IPOPT_SECUR_RESTR
484 # define IPOPT_SECUR_RESTR ((u_short)0xaf13)
486 #ifndef IPOPT_SECUR_SECRET
487 # define IPOPT_SECUR_SECRET ((u_short)0xd788)
489 #ifndef IPOPT_SECUR_TOPSECRET
490 # define IPOPT_SECUR_TOPSECRET ((u_short)0x6bc5)
493 # define IPOPT_OLEN 1
495 #endif /* linux || __sgi */
501 #define TCPS_CLOSED 0 /* closed */
502 #define TCPS_LISTEN 1 /* listening for connection */
503 #define TCPS_SYN_SENT 2 /* active, have sent syn */
504 #define TCPS_SYN_RECEIVED 3 /* have send and received syn */
505 /* states < TCPS_ESTABLISHED are those where connections not established */
506 #define TCPS_ESTABLISHED 4 /* established */
507 #define TCPS_CLOSE_WAIT 5 /* rcvd fin, waiting for close */
508 /* states > TCPS_CLOSE_WAIT are those where user has closed */
509 #define TCPS_FIN_WAIT_1 6 /* have closed, sent fin */
510 #define TCPS_CLOSING 7 /* closed xchd FIN; await FIN ACK */
511 #define TCPS_LAST_ACK 8 /* had fin and close; await FIN ACK */
512 /* states > TCPS_CLOSE_WAIT && < TCPS_FIN_WAIT_2 await ACK of FIN */
513 #define TCPS_FIN_WAIT_2 9 /* have closed, fin is acked */
514 #define TCPS_TIME_WAIT 10 /* in 2*msl quiet wait after close */
522 * mbuf related problems.
524 #define mtod(m,t) (t)((m)->data)
535 # if defined(__i386__) || defined(__MIPSEL__) || defined(__alpha__) ||\
557 # if defined(__i386__) || defined(__MIPSEL__) || defined(__alpha__) ||\
572 struct in_addr ip_src
;
573 struct in_addr ip_dst
;
577 * Structure of an icmp header.
579 typedef struct icmp
{
580 u_char icmp_type
; /* type of message, see below */
581 u_char icmp_code
; /* type sub code */
582 u_short icmp_cksum
; /* ones complement cksum of struct */
584 u_char ih_pptr
; /* ICMP_PARAMPROB */
585 struct in_addr ih_gwaddr
; /* ICMP_REDIRECT */
592 # define icmp_pptr icmp_hun.ih_pptr
593 # define icmp_gwaddr icmp_hun.ih_gwaddr
594 # define icmp_id icmp_hun.ih_idseq.icd_id
595 # define icmp_seq icmp_hun.ih_idseq.icd_seq
596 # define icmp_void icmp_hun.ih_void
605 /* options and then 64 bits of data */
610 # define icmp_otime icmp_dun.id_ts.its_otime
611 # define icmp_rtime icmp_dun.id_ts.its_rtime
612 # define icmp_ttime icmp_dun.id_ts.its_ttime
613 # define icmp_ip icmp_dun.id_ip.idi_ip
614 # define icmp_mask icmp_dun.id_mask
615 # define icmp_data icmp_dun.id_data
618 # ifndef LINUX_IPOVLY
619 # define LINUX_IPOVLY
621 caddr_t ih_next
, ih_prev
; /* for protocol sequence q's */
622 u_char ih_x1
; /* (unused) */
623 u_char ih_pr
; /* protocol */
624 short ih_len
; /* protocol length */
625 struct in_addr ih_src
; /* source internet address */
626 struct in_addr ih_dst
; /* destination internet address */
644 # define UIOMOVE(a, b, c, d) uiomove(a,b,c,d)
647 * For masking struct ifnet onto struct device
649 # define if_name name
652 # define GETUNIT(x) dev_get(x)
653 # define FREE_MB_T(m) kfree_skb(m, FREE_WRITE)
654 # define uniqtime do_gettimeofday
659 # include <linux/netdevice.h>
664 # define bcmp(a,b,c) memcmp(a,b,c)
665 # define bcopy(a,b,c) memcpy(b,a,c)
666 # define bzero(a,c) memset(a,0,c)
668 # define UNITNAME(n) dev_get((n))
670 # define KMALLOC(a,b,c) (a) = (b)kmalloc((c), GFP_ATOMIC)
671 # define KFREE(x) kfree_s((x), sizeof(*(x)))
672 # define KFREES(x,s) kfree_s((x), (s))
673 # define IRCOPY(a,b,c) { \
674 error = verify_area(VERIFY_READ, (a) ,(c)); \
676 memcpy_fromfs((b), (a), (c)); \
678 # define IWCOPY(a,b,c) { \
679 error = verify_area(VERIFY_WRITE, (b), (c)); \
681 memcpy_tofs((b), (a), (c)); \
695 # include <linux/netdevice.h>
698 # define ifnet device
700 typedef struct tcphdr tcphdr_t
;
701 typedef struct udphdr udphdr_t
;
702 typedef struct icmp icmphdr_t
;
703 typedef struct ip ip_t
;
704 typedef struct ether_header ether_header_t
;
706 typedef struct tcpiphdr tcpiphdr_t
;
708 #if defined(hpux) || defined(linux)
710 char ether_addr_octet
[6];
715 * XXX - This is one of those *awful* hacks which nobody likes
723 #ifndef ICMP_ROUTERADVERT
724 # define ICMP_ROUTERADVERT 9
726 #ifndef ICMP_ROUTERSOLICIT
727 # define ICMP_ROUTERSOLICIT 10
730 #endif /* __IP_COMPAT_H__ */