]> git.saurik.com Git - apple/xnu.git/blob - bsd/netinet6/natpt_defs.h
xnu-201.tar.gz
[apple/xnu.git] / bsd / netinet6 / natpt_defs.h
1 /* $KAME: natpt_defs.h,v 1.7 2000/03/25 07:23:54 sumikawa Exp $ */
2
3 /*
4 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the project nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32 #define SAME (0)
33
34 #define NATPT_MAXHASH (397)
35 #define MAXTSLOTENTRY (4096)
36
37 #define SZSIN6 sizeof(struct sockaddr_in6)
38 #define SZSIN sizeof(struct sockaddr_in)
39
40 #define CAR(p) ((p)->car)
41 #define CDR(p) ((p)->cdr)
42 #define CAAR(p) (CAR(CAR(p)))
43 #define CADR(p) (CAR(CDR(p)))
44 #define CDAR(p) (CDR(CAR(p)))
45 #define CDDR(p) (CDR(CDR(p)))
46
47 #ifndef TCP6
48 #define tcp6hdr tcphdr
49 #endif
50
51
52 #if defined(NATPT_ASSERT) && (NATPT_ASSERT != 0)
53 # if defined(__STDC__)
54 # define ASSERT(e) ((e) ? (void)0 : natpt_assert(__FILE__, __LINE__, #e))
55 # else /* PCC */
56 # define ASSERT(e) ((e) ? (void)0 : natpt_assert(__FILE__, __LINE__, "e"))
57 # endif
58 #else
59 # undef NATPT_ASSERT
60 # define ASSERT(e) ((void)0)
61 #endif
62
63
64 #define IN4_ARE_ADDR_EQUAL(a, b) \
65 ((a)->s_addr == (b)->s_addr)
66
67
68 #define ReturnEnobufs(m) if (m == NULL) { errno = ENOBUFS; return (NULL); }
69
70
71 #if (defined(KERNEL)) || (defined(_KERNEL))
72
73 #define isDebug(d) (natpt_debug & (d))
74 #define isDump(d) (natpt_dump & (d))
75
76 #define D_DIVEIN4 0x00000001
77 #define D_PEEKOUTGOINGV4 0x00000002
78 #define D_TRANSLATINGIPV4 0x00000010
79 #define D_TRANSLATEDIPV4 0x00001000
80
81 #define D_DIVEIN6 0x00010000
82 #define D_IN6REJECT 0x00020000
83 #define D_IN6ACCEPT 0x00040000
84 #define D_PEEKOUTGOINGV6 0x00080000
85 #define D_TRANSLATINGIPV6 0x00100000
86 #define D_TRANSLATEDIPV6 0x01000000
87
88 #define fixSuMiReICMPBug (1)
89
90 #ifdef fixSuMiReICMPBug
91 #define IPDST (0xc48db2cb) /* == 203.178.141.196 XXX */
92 #define ICMPSRC (0x02c410ac) /* == 172.16.196.2 XXX */
93 #endif
94
95 #endif /* defined(KERNEL) */
96
97 /*
98 * OS dependencies
99 */
100
101 #ifdef KERNEL
102
103 #if defined(__FreeBSD__) && __FreeBSD__ >= 3 || defined (__APPLE__)
104 #define rcb_list list
105 #endif
106
107 #ifdef __NetBSD__
108 /*
109 * Macros for type conversion
110 * dtom(x) - convert data pointer within mbuf to mbuf pointer (XXX)
111 */
112 #define dtom(x) ((struct mbuf *)((long)(x) & ~(MSIZE-1)))
113 #endif
114
115 #endif /* _KERNEL */
116
117
118 /*
119 * Structure definitions.
120 */
121
122 typedef struct _cell
123 {
124 struct _cell *car;
125 struct _cell *cdr;
126 } Cell;
127
128
129 /* Interface Box structure */
130
131 struct ifBox
132 {
133 int side;
134 #define noSide (0)
135 #define inSide (1)
136 #define outSide (2)
137 char ifName[IFNAMSIZ];
138 struct ifnet *ifnet;
139 };
140
141
142 /* IP ... */
143
144 struct _cv /* 28[byte] */
145 {
146 u_char ip_p; /* IPPROTO_(ICMP[46]|TCP|UDP) */
147 u_char ip_payload; /* IPPROTO_(ICMP|TCP|UDP) */
148
149 u_char inout;
150 /* #define NATPT_UNSPEC (0) */
151 /* #define NATPT_INBOUND (1) */
152 /* #define NATPT_OUTBOUND (2) */
153
154 u_char flags;
155 #define NATPT_TRACEROUTE (0x01)
156 #define NATPT_NEEDFRAGMENT (0x02)
157
158 int poff; /* payload offset */
159 int plen; /* payload length */
160
161 struct mbuf *m;
162 struct _tSlot *ats;
163 union
164 {
165 struct ip *_ip4;
166 struct ip6_hdr *_ip6;
167 } _ip;
168 union
169 {
170 caddr_t _caddr;
171 struct icmp *_icmp4;
172 struct icmp6_hdr *_icmp6;
173 struct tcphdr *_tcp4;
174 struct tcp6hdr *_tcp6;
175 struct udphdr *_udp;
176 } _payload;
177 };
178
179
180 /* IP address structure */
181
182 union inaddr /* sizeof(): 16[byte] */
183 {
184 struct in_addr in4;
185 struct in6_addr in6;
186 };
187
188
189 struct pAddr /* sizeof(): 44[byte] */
190 {
191 u_char ip_p; /* protocol family (within struct _tSlot) */
192 u_char sa_family; /* address family (within struct _cSlot) */
193
194 u_short port[2];
195 #define _port0 port[0]
196 #define _port1 port[1]
197
198 #define _sport port[0]
199 #define _dport port[1]
200 #define _eport port[1]
201
202 union inaddr addr[2];
203
204 #define in4src addr[0].in4
205 #define in4dst addr[1].in4
206 #define in4Addr addr[0].in4
207 #define in4Mask addr[1].in4
208 #define in4RangeStart addr[0].in4
209 #define in4RangeEnd addr[1].in4
210
211 #define in6src addr[0].in6
212 #define in6dst addr[1].in6
213 #define in6Addr addr[0].in6
214 #define in6Mask addr[1].in6
215
216 struct
217 {
218 u_char type;
219 #define ADDR_ANY (0)
220 #define ADDR_SINGLE (1)
221 #define ADDR_MASK (2)
222 #define ADDR_RANGE (3)
223 #define ADDR_FAITH (4)
224
225 u_char prefix;
226 } ad;
227 };
228
229
230 /* Configuration slot entry */
231
232 struct _cSlot /* sizeof(): 100[byte] */
233 {
234 u_char flags;
235 #define NATPT_STATIC (1) /* Rule was set statically */
236 #define NATPT_DYNAMIC (2) /* Rule was set dynamically */
237 #define NATPT_FAITH (3)
238
239 u_char dir;
240 #define NATPT_UNSPEC (0)
241 #define NATPT_INBOUND (1)
242 #define NATPT_OUTBOUND (2)
243
244 u_char map;
245 #define NATPT_PORT_MAP (0x01) /* Mapping dest port */
246 #define NATPT_PORT_MAP_DYNAMIC (0x02) /* Mapping dest port dynamically */
247 #define NATPT_ADDR_MAP (0x04) /* Mapping dest addr */
248 #define NATPT_ADDR_MAP_DYNAMIC (0x08) /* Mapping dest addr dynamically */
249
250 u_char proto;
251
252 u_short prefix;
253 u_short cport; /* current port */
254
255 struct pAddr local, remote;
256 struct _cSlotAux *aux; /* place holder */
257 };
258
259
260 #if 0
261 /* Configuration slot auxiliary entry */
262 /* currently not used */
263
264 struct _cSlotAux /* sizeof(): 0[byte] */
265 {
266 };
267 #endif
268
269
270 /* Translation slot entry */
271
272 struct _tSlot /* sizeof(): 104[byte] */
273 {
274 u_char ip_payload;
275
276 u_char session;
277 /* #define NATPT_UNSPEC (0) */
278 /* #define NATPT_INBOUND (1) */
279 /* #define NATPT_OUTBOUND (2) */
280
281 u_char remap;
282 /* #define NATPT_PORT_REMAP (0x01) */
283 /* #define NATPT_ADDR_REMAP (0x02) */
284
285 /* #define NATPT_STATIC (0x1) */
286 /* #define NATPT_DYNAMIC (0x2) */
287 /* #define NATPT_FAITH (0x3) */
288
289 struct pAddr local;
290 struct pAddr remote;
291 time_t tstamp;
292 int lcount;
293
294 union
295 {
296 struct _idseq
297 {
298 n_short icd_id;
299 n_short icd_seq;
300 } ih_idseq;
301 struct _tcpstate *tcp;
302 } suit;
303 };
304
305
306 struct _tcpstate /* sizeof(): 28[byte] */
307 {
308 short _state;
309 short _session;
310 u_long _ip_id[2]; /* IP packet Identification */
311 /* [0]: current packet */
312 /* [1]: just before packet */
313 u_short _port[2]; /* [0]:outGoing srcPort, [1]:inComing dstPort */
314 /* u_long _iss; initial send sequence number */
315 u_long _delta[3]; /* Sequence delta */
316 /* [0]: current (cumulative) */
317 /* [1]: just before (cumulative) */
318 /* [2]: (this time) */
319 };