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