]> git.saurik.com Git - apple/network_cmds.git/blob - alias/alias_local.h
2ff5b64597d66aaba37e776b078709083bef44e5
[apple/network_cmds.git] / alias / alias_local.h
1 /*
2 * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /*-
26 * Copyright (c) 2001 Charles Mott <cmott@scientech.com>
27 * All rights reserved.
28 *
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
31 * are met:
32 * 1. Redistributions of source code must retain the above copyright
33 * notice, this list of conditions and the following disclaimer.
34 * 2. Redistributions in binary form must reproduce the above copyright
35 * notice, this list of conditions and the following disclaimer in the
36 * documentation and/or other materials provided with the distribution.
37 *
38 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
39 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
41 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
42 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
43 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
44 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
45 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
46 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
47 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
48 * SUCH DAMAGE.
49 *
50 * Based upon:
51 * $FreeBSD: src/lib/libalias/alias_local.h,v 1.10.2.5 2001/08/01 09:52:26 obrien Exp $
52 */
53
54 /*
55 * Alias_local.h contains the function prototypes for alias.c,
56 * alias_db.c, alias_util.c and alias_ftp.c, alias_irc.c (as well
57 * as any future add-ons). It also includes macros, globals and
58 * struct definitions shared by more than one alias*.c file.
59 *
60 * This include file is intended to be used only within the aliasing
61 * software. Outside world interfaces are defined in alias.h
62 *
63 * This software is placed into the public domain with no restrictions
64 * on its distribution.
65 *
66 * Initial version: August, 1996 (cjm)
67 *
68 * <updated several times by original author and Eivind Eklund>
69 */
70
71 #ifndef _ALIAS_LOCAL_H_
72 #define _ALIAS_LOCAL_H_
73
74 #ifndef NULL
75 #define NULL 0
76 #endif
77
78 /* Macros */
79
80 /*
81 * The following macro is used to update an
82 * internet checksum. "delta" is a 32-bit
83 * accumulation of all the changes to the
84 * checksum (adding in new 16-bit words and
85 * subtracting out old words), and "cksum"
86 * is the checksum value to be updated.
87 */
88 #define ADJUST_CHECKSUM(acc, cksum) \
89 do { \
90 acc += cksum; \
91 if (acc < 0) { \
92 acc = -acc; \
93 acc = (acc >> 16) + (acc & 0xffff); \
94 acc += acc >> 16; \
95 cksum = (u_short) ~acc; \
96 } else { \
97 acc = (acc >> 16) + (acc & 0xffff); \
98 acc += acc >> 16; \
99 cksum = (u_short) acc; \
100 } \
101 } while (0)
102
103 /* Globals */
104
105 extern int packetAliasMode;
106
107
108 /* Structs */
109
110 struct alias_link; /* Incomplete structure */
111
112
113 /* Prototypes */
114
115 /* General utilities */
116 u_short IpChecksum(struct ip *);
117 u_short TcpChecksum(struct ip *);
118 void DifferentialChecksum(u_short *, u_short *, u_short *, int);
119
120 /* Internal data access */
121 struct alias_link *
122 FindIcmpIn(struct in_addr, struct in_addr, u_short, int);
123
124 struct alias_link *
125 FindIcmpOut(struct in_addr, struct in_addr, u_short, int);
126
127 struct alias_link *
128 FindFragmentIn1(struct in_addr, struct in_addr, u_short);
129
130 struct alias_link *
131 FindFragmentIn2(struct in_addr, struct in_addr, u_short);
132
133 struct alias_link *
134 AddFragmentPtrLink(struct in_addr, u_short);
135
136 struct alias_link *
137 FindFragmentPtr(struct in_addr, u_short);
138
139 struct alias_link *
140 FindProtoIn(struct in_addr, struct in_addr, u_char);
141
142 struct alias_link *
143 FindProtoOut(struct in_addr, struct in_addr, u_char);
144
145 struct alias_link *
146 FindUdpTcpIn (struct in_addr, struct in_addr, u_short, u_short, u_char, int);
147
148 struct alias_link *
149 FindUdpTcpOut(struct in_addr, struct in_addr, u_short, u_short, u_char, int);
150
151 struct alias_link *
152 AddPptp(struct in_addr, struct in_addr, struct in_addr, u_int16_t);
153
154 struct alias_link *
155 FindPptpOutByCallId(struct in_addr, struct in_addr, u_int16_t);
156
157 struct alias_link *
158 FindPptpInByCallId(struct in_addr, struct in_addr, u_int16_t);
159
160 struct alias_link *
161 FindPptpOutByPeerCallId(struct in_addr, struct in_addr, u_int16_t);
162
163 struct alias_link *
164 FindPptpInByPeerCallId(struct in_addr, struct in_addr, u_int16_t);
165
166 struct alias_link *
167 FindRtspOut(struct in_addr, struct in_addr, u_short, u_short, u_char);
168
169 struct in_addr
170 FindOriginalAddress(struct in_addr);
171
172 struct in_addr
173 FindAliasAddress(struct in_addr);
174
175 /* External data access/modification */
176 int FindNewPortGroup(struct in_addr, struct in_addr,
177 u_short, u_short, u_short, u_char, u_char);
178 void GetFragmentAddr(struct alias_link *, struct in_addr *);
179 void SetFragmentAddr(struct alias_link *, struct in_addr);
180 void GetFragmentPtr(struct alias_link *, char **);
181 void SetFragmentPtr(struct alias_link *, char *);
182 void SetStateIn(struct alias_link *, int);
183 void SetStateOut(struct alias_link *, int);
184 int GetStateIn(struct alias_link *);
185 int GetStateOut(struct alias_link *);
186 struct in_addr GetOriginalAddress(struct alias_link *);
187 struct in_addr GetDestAddress(struct alias_link *);
188 struct in_addr GetAliasAddress(struct alias_link *);
189 struct in_addr GetDefaultAliasAddress(void);
190 void SetDefaultAliasAddress(struct in_addr);
191 u_short GetOriginalPort(struct alias_link *);
192 u_short GetAliasPort(struct alias_link *);
193 struct in_addr GetProxyAddress(struct alias_link *);
194 void SetProxyAddress(struct alias_link *, struct in_addr);
195 u_short GetProxyPort(struct alias_link *);
196 void SetProxyPort(struct alias_link *, u_short);
197 void SetAckModified(struct alias_link *);
198 int GetAckModified(struct alias_link *);
199 int GetDeltaAckIn(struct ip *, struct alias_link *);
200 int GetDeltaSeqOut(struct ip *, struct alias_link *);
201 void AddSeq(struct ip *, struct alias_link *, int);
202 void SetExpire(struct alias_link *, int);
203 void ClearCheckNewLink(void);
204 void SetLastLineCrlfTermed(struct alias_link *, int);
205 int GetLastLineCrlfTermed(struct alias_link *);
206 void SetDestCallId(struct alias_link *, u_int16_t);
207 #ifndef NO_FW_PUNCH
208 void PunchFWHole(struct alias_link *);
209 #endif
210
211
212 /* Housekeeping function */
213 void HouseKeeping(void);
214
215 /* Tcp specfic routines */
216 /*lint -save -library Suppress flexelint warnings */
217
218 /* FTP routines */
219 void AliasHandleFtpOut(struct ip *, struct alias_link *, int);
220
221 /* IRC routines */
222 void AliasHandleIrcOut(struct ip *, struct alias_link *, int);
223
224 /* RTSP routines */
225 void AliasHandleRtspOut(struct ip *, struct alias_link *, int);
226
227 /* PPTP routines */
228 void AliasHandlePptpOut(struct ip *, struct alias_link *);
229 void AliasHandlePptpIn(struct ip *, struct alias_link *);
230 int AliasHandlePptpGreOut(struct ip *);
231 int AliasHandlePptpGreIn(struct ip *);
232
233 /* NetBIOS routines */
234 int AliasHandleUdpNbt(struct ip *, struct alias_link *, struct in_addr *, u_short);
235 int AliasHandleUdpNbtNS(struct ip *, struct alias_link *, struct in_addr *, u_short *, struct in_addr *, u_short *);
236
237 /* CUSeeMe routines */
238 void AliasHandleCUSeeMeOut(struct ip *, struct alias_link *);
239 void AliasHandleCUSeeMeIn(struct ip *, struct in_addr);
240
241 /* Transparent proxy routines */
242 int ProxyCheck(struct ip *, struct in_addr *, u_short *);
243 void ProxyModify(struct alias_link *, struct ip *, int, int);
244
245
246 enum alias_tcp_state {
247 ALIAS_TCP_STATE_NOT_CONNECTED,
248 ALIAS_TCP_STATE_CONNECTED,
249 ALIAS_TCP_STATE_DISCONNECTED
250 };
251
252 /*lint -restore */
253
254 #endif /* !_ALIAS_LOCAL_H_ */