VirtualBox

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

最後變更 在這個檔案從64572是 52683,由 vboxsync 提交於 10 年 前

NAT: Fix #else /* VBOX */ comments to reflect the condition when that
#else is selected. While here, add spaces inside cramped #endif /*VBOX*/
comments.

Same object code is generated.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 12.9 KB
 
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#ifndef VBOX
110 int timeStamp; /* System time in seconds for */
111 /* current packet */
112
113 int lastCleanupTime; /* Last time
114 * IncrementalCleanup() */
115#else
116 unsigned int timeStamp; /* System time in seconds for */
117 unsigned int lastCleanupTime; /* Last time */
118#endif
119 /* was called */
120
121 int deleteAllLinks; /* If equal to zero, DeleteLink() */
122 /* will not remove permanent links */
123
124 /* log descriptor */
125#ifdef _KERNEL
126 char *logDesc;
127#else
128 FILE *logDesc;
129#endif
130 /* statistics monitoring */
131
132 int newDefaultLink; /* Indicates if a new aliasing */
133 /* link has been created after a */
134 /* call to PacketAliasIn/Out(). */
135
136#ifndef NO_FW_PUNCH
137 int fireWallFD; /* File descriptor to be able to */
138 /* control firewall. Opened by */
139 /* PacketAliasSetMode on first */
140 /* setting the PKT_ALIAS_PUNCH_FW */
141 /* flag. */
142 int fireWallBaseNum; /* The first firewall entry
143 * free for our use */
144 int fireWallNumNums; /* How many entries can we
145 * use? */
146 int fireWallActiveNum; /* Which entry did we last
147 * use? */
148 char *fireWallField; /* bool array for entries */
149#endif
150
151 unsigned int skinnyPort; /* TCP port used by the Skinny */
152 /* protocol. */
153
154 struct proxy_entry *proxyList;
155
156 struct in_addr true_addr; /* in network byte order. */
157 u_short true_port; /* in host byte order. */
158#if defined(_KERNEL) && !defined(VBOX)
159 /*
160 * avoid races in libalias: every public function has to use it.
161 */
162 struct mtx mutex;
163#endif
164#ifdef VBOX
165 PNATState pData;
166#endif
167};
168
169/* Macros */
170
171#if defined(_KERNEL) && !defined(VBOX)
172#define LIBALIAS_LOCK_INIT(l) \
173 mtx_init(&l->mutex, "per-instance libalias mutex", NULL, MTX_DEF)
174#define LIBALIAS_LOCK_ASSERT(l) mtx_assert(&l->mutex, MA_OWNED)
175#define LIBALIAS_LOCK(l) mtx_lock(&l->mutex)
176#define LIBALIAS_UNLOCK(l) mtx_unlock(&l->mutex)
177#define LIBALIAS_LOCK_DESTROY(l) mtx_destroy(&l->mutex)
178#else
179#define LIBALIAS_LOCK_INIT(l)
180#define LIBALIAS_LOCK_ASSERT(l)
181#define LIBALIAS_LOCK(l) NOREF((l));
182#define LIBALIAS_UNLOCK(l) NOREF((l))
183#define LIBALIAS_LOCK_DESTROY(l)
184#endif
185
186/*
187 * The following macro is used to update an
188 * internet checksum. "delta" is a 32-bit
189 * accumulation of all the changes to the
190 * checksum (adding in new 16-bit words and
191 * subtracting out old words), and "cksum"
192 * is the checksum value to be updated.
193 */
194#define ADJUST_CHECKSUM(acc, cksum) \
195 do { \
196 acc += cksum; \
197 if (acc < 0) { \
198 acc = -acc; \
199 acc = (acc >> 16) + (acc & 0xffff); \
200 acc += acc >> 16; \
201 cksum = (u_short) ~acc; \
202 } else { \
203 acc = (acc >> 16) + (acc & 0xffff); \
204 acc += acc >> 16; \
205 cksum = (u_short) acc; \
206 } \
207 } while (0)
208
209
210/* Prototypes */
211
212/*
213 * We do not calculate TCP checksums when libalias is a kernel
214 * module, since it has no idea about checksum offloading.
215 * If TCP data has changed, then we just set checksum to zero,
216 * and caller must recalculate it himself.
217 * In case if libalias will edit UDP data, the same approach
218 * should be used.
219 */
220#ifndef _KERNEL
221u_short IpChecksum(struct ip *_pip);
222u_short TcpChecksum(struct ip *_pip);
223#endif
224void
225DifferentialChecksum(u_short * _cksum, void * _new, void * _old, int _n);
226
227/* Internal data access */
228struct alias_link *
229FindIcmpIn(struct libalias *la, struct in_addr _dst_addr, struct in_addr _alias_addr,
230 u_short _id_alias, int _create);
231struct alias_link *
232FindIcmpOut(struct libalias *la, struct in_addr _src_addr, struct in_addr _dst_addr,
233 u_short _id, int _create);
234struct alias_link *
235FindFragmentIn1(struct libalias *la, struct in_addr _dst_addr, struct in_addr _alias_addr,
236 u_short _ip_id);
237struct alias_link *
238FindFragmentIn2(struct libalias *la, struct in_addr _dst_addr, struct in_addr _alias_addr,
239 u_short _ip_id);
240struct alias_link *
241 AddFragmentPtrLink(struct libalias *la, struct in_addr _dst_addr, u_short _ip_id);
242struct alias_link *
243 FindFragmentPtr(struct libalias *la, struct in_addr _dst_addr, u_short _ip_id);
244struct alias_link *
245FindProtoIn(struct libalias *la, struct in_addr _dst_addr, struct in_addr _alias_addr,
246 u_char _proto);
247struct alias_link *
248FindProtoOut(struct libalias *la, struct in_addr _src_addr, struct in_addr _dst_addr,
249 u_char _proto);
250struct alias_link *
251FindUdpTcpIn(struct libalias *la, struct in_addr _dst_addr, struct in_addr _alias_addr,
252 u_short _dst_port, u_short _alias_port, u_char _proto, int _create);
253struct alias_link *
254FindUdpTcpOut(struct libalias *la, struct in_addr _src_addr, struct in_addr _dst_addr,
255 u_short _src_port, u_short _dst_port, u_char _proto, int _create);
256struct alias_link *
257AddPptp(struct libalias *la, struct in_addr _src_addr, struct in_addr _dst_addr,
258 struct in_addr _alias_addr, u_int16_t _src_call_id);
259struct alias_link *
260FindPptpOutByCallId(struct libalias *la, struct in_addr _src_addr,
261 struct in_addr _dst_addr, u_int16_t _src_call_id);
262struct alias_link *
263FindPptpInByCallId(struct libalias *la, struct in_addr _dst_addr,
264 struct in_addr _alias_addr, u_int16_t _dst_call_id);
265struct alias_link *
266FindPptpOutByPeerCallId(struct libalias *la, struct in_addr _src_addr,
267 struct in_addr _dst_addr, u_int16_t _dst_call_id);
268struct alias_link *
269FindPptpInByPeerCallId(struct libalias *la, struct in_addr _dst_addr,
270 struct in_addr _alias_addr, u_int16_t _alias_call_id);
271struct alias_link *
272FindRtspOut(struct libalias *la, struct in_addr _src_addr, struct in_addr _dst_addr,
273 u_short _src_port, u_short _alias_port, u_char _proto);
274struct in_addr
275 FindOriginalAddress(struct libalias *la, struct in_addr _alias_addr);
276struct in_addr
277 FindAliasAddress(struct libalias *la, struct in_addr _original_addr);
278
279/* External data access/modification */
280int
281FindNewPortGroup(struct libalias *la, struct in_addr _dst_addr, struct in_addr _alias_addr,
282 u_short _src_port, u_short _dst_port, u_short _port_count,
283 u_char _proto, u_char _align);
284void GetFragmentAddr(struct alias_link *_lnk, struct in_addr *_src_addr);
285void SetFragmentAddr(struct alias_link *_lnk, struct in_addr _src_addr);
286void GetFragmentPtr(struct alias_link *_lnk, char **_fptr);
287void SetFragmentPtr(struct alias_link *_lnk, char *fptr);
288void SetStateIn(struct alias_link *_lnk, int _state);
289void SetStateOut(struct alias_link *_lnk, int _state);
290int GetStateIn (struct alias_link *_lnk);
291int GetStateOut(struct alias_link *_lnk);
292struct in_addr
293 GetOriginalAddress(struct alias_link *_lnk);
294struct in_addr
295 GetDestAddress(struct alias_link *_lnk);
296struct in_addr
297 GetAliasAddress(struct alias_link *_lnk);
298struct in_addr
299 GetDefaultAliasAddress(struct libalias *la);
300void SetDefaultAliasAddress(struct libalias *la, struct in_addr _alias_addr);
301u_short GetOriginalPort(struct alias_link *_lnk);
302u_short GetAliasPort(struct alias_link *_lnk);
303struct in_addr
304 GetProxyAddress(struct alias_link *_lnk);
305void SetProxyAddress(struct alias_link *_lnk, struct in_addr _addr);
306u_short GetProxyPort(struct alias_link *_lnk);
307void SetProxyPort(struct alias_link *_lnk, u_short _port);
308void SetAckModified(struct alias_link *_lnk);
309int GetAckModified(struct alias_link *_lnk);
310int GetDeltaAckIn(struct ip *_pip, struct alias_link *_lnk);
311int GetDeltaSeqOut(struct ip *_pip, struct alias_link *_lnk);
312void AddSeq (struct ip *_pip, struct alias_link *_lnk, int _delta);
313void SetExpire (struct alias_link *_lnk, int _expire);
314void ClearCheckNewLink(struct libalias *la);
315void SetProtocolFlags(struct alias_link *_lnk, int _pflags);
316int GetProtocolFlags(struct alias_link *_lnk);
317void SetDestCallId(struct alias_link *_lnk, u_int16_t _cid);
318
319#ifndef NO_FW_PUNCH
320void PunchFWHole(struct alias_link *_lnk);
321
322#endif
323
324/* Housekeeping function */
325void HouseKeeping(struct libalias *);
326
327/* Tcp specfic routines */
328/* lint -save -library Suppress flexelint warnings */
329
330/* Transparent proxy routines */
331int
332ProxyCheck(struct libalias *la, struct ip *_pip, struct in_addr *_proxy_server_addr,
333 u_short * _proxy_server_port);
334void
335ProxyModify(struct libalias *la, struct alias_link *_lnk, struct ip *_pip,
336 int _maxpacketsize, int _proxy_type);
337
338enum alias_tcp_state {
339 ALIAS_TCP_STATE_NOT_CONNECTED,
340 ALIAS_TCP_STATE_CONNECTED,
341 ALIAS_TCP_STATE_DISCONNECTED
342};
343
344#if defined(_NETINET_IP_H_)
345static __inline void *
346ip_next(struct ip *iphdr)
347{
348 char *p = (char *)iphdr;
349 return (&p[iphdr->ip_hl * 4]);
350}
351#endif
352
353#if defined(_NETINET_TCP_H_)
354static __inline void *
355tcp_next(struct tcphdr *tcphdr)
356{
357 char *p = (char *)tcphdr;
358 return (&p[tcphdr->th_off * 4]);
359}
360#endif
361
362#if defined(_NETINET_UDP_H_)
363static __inline void *
364udp_next(struct udphdr *udphdr)
365{
366 return ((void *)(udphdr + 1));
367}
368#endif
369
370#endif /* !_ALIAS_LOCAL_H_ */
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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