VirtualBox

source: vbox/trunk/src/VBox/Devices/Network/slirp/libalias/alias_local.h@ 21664

Last change on this file since 21664 was 20958, checked in by vboxsync, 16 years ago

NAT: export of libalias

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.8 KB
Line 
1/*-
2 * Copyright (c) 2001 Charles Mott <[email protected]>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD: src/sys/netinet/libalias/alias_local.h,v 1.34.2.1.4.1 2009/04/15 03:14:26 kensmith Exp $
27 */
28
29/*
30 * Alias_local.h contains the function prototypes for alias.c,
31 * alias_db.c, alias_util.c and alias_ftp.c, alias_irc.c (as well
32 * as any future add-ons). It also includes macros, globals and
33 * struct definitions shared by more than one alias*.c file.
34 *
35 * This include file is intended to be used only within the aliasing
36 * software. Outside world interfaces are defined in alias.h
37 *
38 * This software is placed into the public domain with no restrictions
39 * on its distribution.
40 *
41 * Initial version: August, 1996 (cjm)
42 *
43 * <updated several times by original author and Eivind Eklund>
44 */
45
46#ifndef _ALIAS_LOCAL_H_
47#define _ALIAS_LOCAL_H_
48
49#ifndef VBOX
50#include <sys/types.h>
51#include <sys/sysctl.h>
52
53#ifdef _KERNEL
54#include <sys/malloc.h>
55#include <sys/param.h>
56#include <sys/lock.h>
57#include <sys/mutex.h>
58
59/* XXX: LibAliasSetTarget() uses this constant. */
60#define INADDR_NONE 0xffffffff
61#endif
62#else /* !VBOX */
63# include <slirp.h>
64#endif /* VBOX */
65
66/* Sizes of input and output link tables */
67#define LINK_TABLE_OUT_SIZE 4001
68#define LINK_TABLE_IN_SIZE 4001
69
70struct proxy_entry;
71
72struct libalias {
73 LIST_ENTRY(libalias) instancelist;
74
75 int packetAliasMode; /* Mode flags */
76 /* - documented in alias.h */
77
78 struct in_addr aliasAddress; /* Address written onto source */
79 /* field of IP packet. */
80
81 struct in_addr targetAddress; /* IP address incoming packets */
82 /* are sent to if no aliasing */
83 /* link already exists */
84
85 struct in_addr nullAddress; /* Used as a dummy parameter for */
86 /* some function calls */
87
88 LIST_HEAD (RT_NOTHING, alias_link) linkTableOut[LINK_TABLE_OUT_SIZE];
89 /* Lookup table of pointers to */
90 /* chains of link records. Each */
91
92 LIST_HEAD (RT_NOTHING, alias_link) linkTableIn[LINK_TABLE_IN_SIZE];
93 /* link record is doubly indexed */
94 /* into input and output lookup */
95 /* tables. */
96
97 /* Link statistics */
98 int icmpLinkCount;
99 int udpLinkCount;
100 int tcpLinkCount;
101 int pptpLinkCount;
102 int protoLinkCount;
103 int fragmentIdLinkCount;
104 int fragmentPtrLinkCount;
105 int sockCount;
106
107 int cleanupIndex; /* Index to chain of link table */
108 /* being inspected for old links */
109
110 int timeStamp; /* System time in seconds for */
111 /* current packet */
112
113 int lastCleanupTime; /* Last time
114 * IncrementalCleanup() */
115 /* was called */
116
117 int deleteAllLinks; /* If equal to zero, DeleteLink() */
118 /* will not remove permanent links */
119
120 /* log descriptor */
121#ifdef _KERNEL
122 char *logDesc;
123#else
124 FILE *logDesc;
125#endif
126 /* statistics monitoring */
127
128 int newDefaultLink; /* Indicates if a new aliasing */
129 /* link has been created after a */
130 /* call to PacketAliasIn/Out(). */
131
132#ifndef NO_FW_PUNCH
133 int fireWallFD; /* File descriptor to be able to */
134 /* control firewall. Opened by */
135 /* PacketAliasSetMode on first */
136 /* setting the PKT_ALIAS_PUNCH_FW */
137 /* flag. */
138 int fireWallBaseNum; /* The first firewall entry
139 * free for our use */
140 int fireWallNumNums; /* How many entries can we
141 * use? */
142 int fireWallActiveNum; /* Which entry did we last
143 * use? */
144 char *fireWallField; /* bool array for entries */
145#endif
146
147 unsigned int skinnyPort; /* TCP port used by the Skinny */
148 /* protocol. */
149
150 struct proxy_entry *proxyList;
151
152 struct in_addr true_addr; /* in network byte order. */
153 u_short true_port; /* in host byte order. */
154#if defined(_KERNEL) && !defined(VBOX)
155 /*
156 * avoid races in libalias: every public function has to use it.
157 */
158 struct mtx mutex;
159#endif
160#ifdef VBOX
161 PNATState pData;
162#endif
163};
164
165/* Macros */
166
167#if defined(_KERNEL) && !defined(VBOX)
168#define LIBALIAS_LOCK_INIT(l) \
169 mtx_init(&l->mutex, "per-instance libalias mutex", NULL, MTX_DEF)
170#define LIBALIAS_LOCK_ASSERT(l) mtx_assert(&l->mutex, MA_OWNED)
171#define LIBALIAS_LOCK(l) mtx_lock(&l->mutex)
172#define LIBALIAS_UNLOCK(l) mtx_unlock(&l->mutex)
173#define LIBALIAS_LOCK_DESTROY(l) mtx_destroy(&l->mutex)
174#else
175#define LIBALIAS_LOCK_INIT(l)
176#define LIBALIAS_LOCK_ASSERT(l)
177#define LIBALIAS_LOCK(l)
178#define LIBALIAS_UNLOCK(l)
179#define LIBALIAS_LOCK_DESTROY(l)
180#endif
181
182/*
183 * The following macro is used to update an
184 * internet checksum. "delta" is a 32-bit
185 * accumulation of all the changes to the
186 * checksum (adding in new 16-bit words and
187 * subtracting out old words), and "cksum"
188 * is the checksum value to be updated.
189 */
190#define ADJUST_CHECKSUM(acc, cksum) \
191 do { \
192 acc += cksum; \
193 if (acc < 0) { \
194 acc = -acc; \
195 acc = (acc >> 16) + (acc & 0xffff); \
196 acc += acc >> 16; \
197 cksum = (u_short) ~acc; \
198 } else { \
199 acc = (acc >> 16) + (acc & 0xffff); \
200 acc += acc >> 16; \
201 cksum = (u_short) acc; \
202 } \
203 } while (0)
204
205
206/* Prototypes */
207
208/*
209 * We do not calculate TCP checksums when libalias is a kernel
210 * module, since it has no idea about checksum offloading.
211 * If TCP data has changed, then we just set checksum to zero,
212 * and caller must recalculate it himself.
213 * In case if libalias will edit UDP data, the same approach
214 * should be used.
215 */
216#ifndef _KERNEL
217u_short IpChecksum(struct ip *_pip);
218u_short TcpChecksum(struct ip *_pip);
219#endif
220void
221DifferentialChecksum(u_short * _cksum, void * _new, void * _old, int _n);
222
223/* Internal data access */
224struct alias_link *
225FindIcmpIn(struct libalias *la, struct in_addr _dst_addr, struct in_addr _alias_addr,
226 u_short _id_alias, int _create);
227struct alias_link *
228FindIcmpOut(struct libalias *la, struct in_addr _src_addr, struct in_addr _dst_addr,
229 u_short _id, int _create);
230struct alias_link *
231FindFragmentIn1(struct libalias *la, struct in_addr _dst_addr, struct in_addr _alias_addr,
232 u_short _ip_id);
233struct alias_link *
234FindFragmentIn2(struct libalias *la, struct in_addr _dst_addr, struct in_addr _alias_addr,
235 u_short _ip_id);
236struct alias_link *
237 AddFragmentPtrLink(struct libalias *la, struct in_addr _dst_addr, u_short _ip_id);
238struct alias_link *
239 FindFragmentPtr(struct libalias *la, struct in_addr _dst_addr, u_short _ip_id);
240struct alias_link *
241FindProtoIn(struct libalias *la, struct in_addr _dst_addr, struct in_addr _alias_addr,
242 u_char _proto);
243struct alias_link *
244FindProtoOut(struct libalias *la, struct in_addr _src_addr, struct in_addr _dst_addr,
245 u_char _proto);
246struct alias_link *
247FindUdpTcpIn(struct libalias *la, struct in_addr _dst_addr, struct in_addr _alias_addr,
248 u_short _dst_port, u_short _alias_port, u_char _proto, int _create);
249struct alias_link *
250FindUdpTcpOut(struct libalias *la, struct in_addr _src_addr, struct in_addr _dst_addr,
251 u_short _src_port, u_short _dst_port, u_char _proto, int _create);
252struct alias_link *
253AddPptp(struct libalias *la, struct in_addr _src_addr, struct in_addr _dst_addr,
254 struct in_addr _alias_addr, u_int16_t _src_call_id);
255struct alias_link *
256FindPptpOutByCallId(struct libalias *la, struct in_addr _src_addr,
257 struct in_addr _dst_addr, u_int16_t _src_call_id);
258struct alias_link *
259FindPptpInByCallId(struct libalias *la, struct in_addr _dst_addr,
260 struct in_addr _alias_addr, u_int16_t _dst_call_id);
261struct alias_link *
262FindPptpOutByPeerCallId(struct libalias *la, struct in_addr _src_addr,
263 struct in_addr _dst_addr, u_int16_t _dst_call_id);
264struct alias_link *
265FindPptpInByPeerCallId(struct libalias *la, struct in_addr _dst_addr,
266 struct in_addr _alias_addr, u_int16_t _alias_call_id);
267struct alias_link *
268FindRtspOut(struct libalias *la, struct in_addr _src_addr, struct in_addr _dst_addr,
269 u_short _src_port, u_short _alias_port, u_char _proto);
270struct in_addr
271 FindOriginalAddress(struct libalias *la, struct in_addr _alias_addr);
272struct in_addr
273 FindAliasAddress(struct libalias *la, struct in_addr _original_addr);
274
275/* External data access/modification */
276int
277FindNewPortGroup(struct libalias *la, struct in_addr _dst_addr, struct in_addr _alias_addr,
278 u_short _src_port, u_short _dst_port, u_short _port_count,
279 u_char _proto, u_char _align);
280void GetFragmentAddr(struct alias_link *_lnk, struct in_addr *_src_addr);
281void SetFragmentAddr(struct alias_link *_lnk, struct in_addr _src_addr);
282void GetFragmentPtr(struct alias_link *_lnk, char **_fptr);
283void SetFragmentPtr(struct alias_link *_lnk, char *fptr);
284void SetStateIn(struct alias_link *_lnk, int _state);
285void SetStateOut(struct alias_link *_lnk, int _state);
286int GetStateIn (struct alias_link *_lnk);
287int GetStateOut(struct alias_link *_lnk);
288struct in_addr
289 GetOriginalAddress(struct alias_link *_lnk);
290struct in_addr
291 GetDestAddress(struct alias_link *_lnk);
292struct in_addr
293 GetAliasAddress(struct alias_link *_lnk);
294struct in_addr
295 GetDefaultAliasAddress(struct libalias *la);
296void SetDefaultAliasAddress(struct libalias *la, struct in_addr _alias_addr);
297u_short GetOriginalPort(struct alias_link *_lnk);
298u_short GetAliasPort(struct alias_link *_lnk);
299struct in_addr
300 GetProxyAddress(struct alias_link *_lnk);
301void SetProxyAddress(struct alias_link *_lnk, struct in_addr _addr);
302u_short GetProxyPort(struct alias_link *_lnk);
303void SetProxyPort(struct alias_link *_lnk, u_short _port);
304void SetAckModified(struct alias_link *_lnk);
305int GetAckModified(struct alias_link *_lnk);
306int GetDeltaAckIn(struct ip *_pip, struct alias_link *_lnk);
307int GetDeltaSeqOut(struct ip *_pip, struct alias_link *_lnk);
308void AddSeq (struct ip *_pip, struct alias_link *_lnk, int _delta);
309void SetExpire (struct alias_link *_lnk, int _expire);
310void ClearCheckNewLink(struct libalias *la);
311void SetProtocolFlags(struct alias_link *_lnk, int _pflags);
312int GetProtocolFlags(struct alias_link *_lnk);
313void SetDestCallId(struct alias_link *_lnk, u_int16_t _cid);
314
315#ifndef NO_FW_PUNCH
316void PunchFWHole(struct alias_link *_lnk);
317
318#endif
319
320/* Housekeeping function */
321void HouseKeeping(struct libalias *);
322
323/* Tcp specfic routines */
324/* lint -save -library Suppress flexelint warnings */
325
326/* Transparent proxy routines */
327int
328ProxyCheck(struct libalias *la, struct ip *_pip, struct in_addr *_proxy_server_addr,
329 u_short * _proxy_server_port);
330void
331ProxyModify(struct libalias *la, struct alias_link *_lnk, struct ip *_pip,
332 int _maxpacketsize, int _proxy_type);
333
334enum alias_tcp_state {
335 ALIAS_TCP_STATE_NOT_CONNECTED,
336 ALIAS_TCP_STATE_CONNECTED,
337 ALIAS_TCP_STATE_DISCONNECTED
338};
339
340#if defined(_NETINET_IP_H_)
341static __inline void *
342ip_next(struct ip *iphdr)
343{
344 char *p = (char *)iphdr;
345 return (&p[iphdr->ip_hl * 4]);
346}
347#endif
348
349#if defined(_NETINET_TCP_H_)
350static __inline void *
351tcp_next(struct tcphdr *tcphdr)
352{
353 char *p = (char *)tcphdr;
354 return (&p[tcphdr->th_off * 4]);
355}
356#endif
357
358#if defined(_NETINET_UDP_H_)
359static __inline void *
360udp_next(struct udphdr *udphdr)
361{
362 return ((void *)(udphdr + 1));
363}
364#endif
365
366#endif /* !_ALIAS_LOCAL_H_ */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette