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
102extern int packetAliasMode;
103
104
105/* Structs */
106
107struct alias_link;    /* Incomplete structure */
108
109
110/* Prototypes */
111
112/* General utilities */
113u_short IpChecksum(struct ip *);
114u_short TcpChecksum(struct ip *);
115void DifferentialChecksum(u_short *, u_short *, u_short *, int);
116
117/* Internal data access */
118struct alias_link *
119FindIcmpIn(struct in_addr, struct in_addr, u_short, int);
120
121struct alias_link *
122FindIcmpOut(struct in_addr, struct in_addr, u_short, int);
123
124struct alias_link *
125FindFragmentIn1(struct in_addr, struct in_addr, u_short);
126
127struct alias_link *
128FindFragmentIn2(struct in_addr, struct in_addr, u_short);
129
130struct alias_link *
131AddFragmentPtrLink(struct in_addr, u_short);
132
133struct alias_link *
134FindFragmentPtr(struct in_addr, u_short);
135
136struct alias_link *
137FindProtoIn(struct in_addr, struct in_addr, u_char);
138
139struct alias_link *
140FindProtoOut(struct in_addr, struct in_addr, u_char);
141
142struct alias_link *
143FindUdpTcpIn (struct in_addr, struct in_addr, u_short, u_short, u_char, int);
144
145struct alias_link *
146FindUdpTcpOut(struct in_addr, struct in_addr, u_short, u_short, u_char, int);
147
148struct alias_link *
149AddPptp(struct in_addr, struct in_addr, struct in_addr, u_int16_t);
150
151struct alias_link *
152FindPptpOutByCallId(struct in_addr, struct in_addr, u_int16_t);
153
154struct alias_link *
155FindPptpInByCallId(struct in_addr, struct in_addr, u_int16_t);
156
157struct alias_link *
158FindPptpOutByPeerCallId(struct in_addr, struct in_addr, u_int16_t);
159
160struct alias_link *
161FindPptpInByPeerCallId(struct in_addr, struct in_addr, u_int16_t);
162
163struct alias_link *
164FindRtspOut(struct in_addr, struct in_addr, u_short, u_short, u_char);
165
166struct in_addr
167FindOriginalAddress(struct in_addr);
168
169struct in_addr
170FindAliasAddress(struct in_addr);
171
172/* External data access/modification */
173int FindNewPortGroup(struct in_addr, struct in_addr,
174                     u_short, u_short, u_short, u_char, u_char);
175void GetFragmentAddr(struct alias_link *, struct in_addr *);
176void SetFragmentAddr(struct alias_link *, struct in_addr);
177void GetFragmentPtr(struct alias_link *, char **);
178void SetFragmentPtr(struct alias_link *, char *);
179void SetStateIn(struct alias_link *, int);
180void SetStateOut(struct alias_link *, int);
181int GetStateIn(struct alias_link *);
182int GetStateOut(struct alias_link *);
183struct in_addr GetOriginalAddress(struct alias_link *);
184struct in_addr GetDestAddress(struct alias_link *);
185struct in_addr GetAliasAddress(struct alias_link *);
186struct in_addr GetDefaultAliasAddress(void);
187void SetDefaultAliasAddress(struct in_addr);
188u_short GetOriginalPort(struct alias_link *);
189u_short GetAliasPort(struct alias_link *);
190struct in_addr GetProxyAddress(struct alias_link *);
191void SetProxyAddress(struct alias_link *, struct in_addr);
192u_short GetProxyPort(struct alias_link *);
193void SetProxyPort(struct alias_link *, u_short);
194void SetAckModified(struct alias_link *);
195int GetAckModified(struct alias_link *);
196int GetDeltaAckIn(struct ip *, struct alias_link *);
197int GetDeltaSeqOut(struct ip *, struct alias_link *);
198void AddSeq(struct ip *, struct alias_link *, int);
199void SetExpire(struct alias_link *, int);
200void ClearCheckNewLink(void);
201void SetLastLineCrlfTermed(struct alias_link *, int);
202int GetLastLineCrlfTermed(struct alias_link *);
203void SetDestCallId(struct alias_link *, u_int16_t);
204#ifndef NO_FW_PUNCH
205void PunchFWHole(struct alias_link *);
206#endif
207
208
209/* Housekeeping function */
210void HouseKeeping(void);
211
212/* Tcp specfic routines */
213/*lint -save -library Suppress flexelint warnings */
214
215/* FTP routines */
216void AliasHandleFtpOut(struct ip *, struct alias_link *, int);
217
218/* IRC routines */
219void AliasHandleIrcOut(struct ip *, struct alias_link *, int);
220
221/* RTSP routines */
222void AliasHandleRtspOut(struct ip *, struct alias_link *, int);
223
224/* PPTP routines */
225void AliasHandlePptpOut(struct ip *, struct alias_link *);
226void AliasHandlePptpIn(struct ip *, struct alias_link *);
227int AliasHandlePptpGreOut(struct ip *);
228int AliasHandlePptpGreIn(struct ip *);
229
230/* NetBIOS routines */
231int AliasHandleUdpNbt(struct ip *, struct alias_link *, struct in_addr *, u_short);
232int AliasHandleUdpNbtNS(struct ip *, struct alias_link *, struct in_addr *, u_short *, struct in_addr *, u_short *);
233
234/* CUSeeMe routines */
235void AliasHandleCUSeeMeOut(struct ip *, struct alias_link *);
236void AliasHandleCUSeeMeIn(struct ip *, struct in_addr);
237
238/* Transparent proxy routines */
239int ProxyCheck(struct ip *, struct in_addr *, u_short *);
240void ProxyModify(struct alias_link *, struct ip *, int, int);
241
242
243enum 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_ */
252