alias_local.h revision 77701
1/*-
2 * Copyright (c) 2001 Charles Mott <cmott@scientech.com>
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: head/sys/netinet/libalias/alias_local.h 77701 2001-06-04 15:09:51Z brian $
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/* Macros */
50
51/*
52 * The following macro is used to update an
53 * internet checksum.  "delta" is a 32-bit
54 * accumulation of all the changes to the
55 * checksum (adding in new 16-bit words and
56 * subtracting out old words), and "cksum"
57 * is the checksum value to be updated.
58 */
59#define	ADJUST_CHECKSUM(acc, cksum) \
60	do { \
61		acc += cksum; \
62		if (acc < 0) { \
63			acc = -acc; \
64			acc = (acc >> 16) + (acc & 0xffff); \
65			acc += acc >> 16; \
66			cksum = (u_short) ~acc; \
67		} else { \
68			acc = (acc >> 16) + (acc & 0xffff); \
69			acc += acc >> 16; \
70			cksum = (u_short) acc; \
71		} \
72	} while (0)
73
74/* Globals */
75
76extern int packetAliasMode;
77
78/* Prototypes */
79
80/* General utilities */
81u_short	 IpChecksum(struct ip *_pip);
82u_short	 TcpChecksum(struct ip *_pip);
83void	 DifferentialChecksum(u_short *_cksum, u_short *_new, u_short *_old,
84	    int _n);
85
86/* Internal data access */
87struct alias_link *
88	 FindIcmpIn(struct in_addr _dst_addr, struct in_addr _alias_addr,
89	    u_short _id_alias, int _create);
90struct alias_link *
91	 FindIcmpOut(struct in_addr _src_addr, struct in_addr _dst_addr,
92	    u_short _id, int _create);
93struct alias_link *
94	 FindFragmentIn1(struct in_addr _dst_addr, struct in_addr _alias_addr,
95	    u_short _ip_id);
96struct alias_link *
97	 FindFragmentIn2(struct in_addr _dst_addr, struct in_addr _alias_addr,
98	    u_short _ip_id);
99struct alias_link *
100	 AddFragmentPtrLink(struct in_addr _dst_addr, u_short _ip_id);
101struct alias_link *
102	 FindFragmentPtr(struct in_addr _dst_addr, u_short _ip_id);
103struct alias_link *
104	 FindProtoIn(struct in_addr _dst_addr, struct in_addr _alias_addr,
105	    u_char _proto);
106struct alias_link *
107	 FindProtoOut(struct in_addr _src_addr, struct in_addr _dst_addr,
108	    u_char _proto);
109struct alias_link *
110	 FindUdpTcpIn(struct in_addr _dst_addr, struct in_addr _alias_addr,
111	    u_short _dst_port, u_short _alias_port, u_char _proto, int _create);
112struct alias_link *
113	 FindUdpTcpOut(struct in_addr _src_addr, struct in_addr _dst_addr,
114	    u_short _src_port, u_short _dst_port, u_char _proto, int _create);
115struct alias_link *
116	 AddPptp(struct in_addr _src_addr, struct in_addr _dst_addr,
117	    struct in_addr _alias_addr, u_int16_t _src_call_id);
118struct alias_link *
119	 FindPptpOutByCallId(struct in_addr _src_addr,
120	    struct in_addr _dst_addr, u_int16_t _src_call_id);
121struct alias_link *
122	 FindPptpInByCallId(struct in_addr _dst_addr,
123	    struct in_addr _alias_addr, u_int16_t _dst_call_id);
124struct alias_link *
125	 FindPptpOutByPeerCallId(struct in_addr _src_addr,
126	    struct in_addr _dst_addr, u_int16_t _dst_call_id);
127struct alias_link *
128	 FindPptpInByPeerCallId(struct in_addr _dst_addr,
129	    struct in_addr _alias_addr, u_int16_t _alias_call_id);
130struct alias_link *
131	 FindRtspOut(struct in_addr _src_addr, struct in_addr _dst_addr,
132	    u_short _src_port, u_short _alias_port, u_char _proto);
133struct in_addr
134	 FindOriginalAddress(struct in_addr _alias_addr);
135struct in_addr
136	 FindAliasAddress(struct in_addr _original_addr);
137
138/* External data access/modification */
139int	 FindNewPortGroup(struct in_addr _dst_addr, struct in_addr _alias_addr,
140                     u_short _src_port, u_short _dst_port, u_short _port_count,
141		     u_char _proto, u_char _align);
142void	 GetFragmentAddr(struct alias_link *_link, struct in_addr *_src_addr);
143void	 SetFragmentAddr(struct alias_link *_link, struct in_addr _src_addr);
144void	 GetFragmentPtr(struct alias_link *_link, char **_fptr);
145void	 SetFragmentPtr(struct alias_link *_link, char *fptr);
146void	 SetStateIn(struct alias_link *_link, int _state);
147void	 SetStateOut(struct alias_link *_link, int _state);
148int	 GetStateIn(struct alias_link *_link);
149int	 GetStateOut(struct alias_link *_link);
150struct in_addr
151	 GetOriginalAddress(struct alias_link *_link);
152struct in_addr
153	 GetDestAddress(struct alias_link *_link);
154struct in_addr
155	 GetAliasAddress(struct alias_link *_link);
156struct in_addr
157	 GetDefaultAliasAddress(void);
158void	 SetDefaultAliasAddress(struct in_addr _alias_addr);
159u_short	 GetOriginalPort(struct alias_link *_link);
160u_short	 GetAliasPort(struct alias_link *_link);
161struct in_addr
162	 GetProxyAddress(struct alias_link *_link);
163void	 SetProxyAddress(struct alias_link *_link, struct in_addr _addr);
164u_short	 GetProxyPort(struct alias_link *_link);
165void	 SetProxyPort(struct alias_link *_link, u_short _port);
166void	 SetAckModified(struct alias_link *_link);
167int	 GetAckModified(struct alias_link *_link);
168int	 GetDeltaAckIn(struct ip *_pip, struct alias_link *_link);
169int	 GetDeltaSeqOut(struct ip *_pip, struct alias_link *_link);
170void	 AddSeq(struct ip *_pip, struct alias_link *_link, int _delta);
171void	 SetExpire(struct alias_link *_link, int _expire);
172void	 ClearCheckNewLink(void);
173void	 SetProtocolFlags(struct alias_link *_link, int _pflags);
174int	 GetProtocolFlags(struct alias_link *_link);
175void	 SetDestCallId(struct alias_link *_link, u_int16_t _cid);
176#ifndef NO_FW_PUNCH
177void	 PunchFWHole(struct alias_link *_link);
178#endif
179
180/* Housekeeping function */
181void	 HouseKeeping(void);
182
183/* Tcp specfic routines */
184/* lint -save -library Suppress flexelint warnings */
185
186/* FTP routines */
187void	 AliasHandleFtpOut(struct ip *_pip, struct alias_link *_link,
188	    int _maxpacketsize);
189
190/* IRC routines */
191void	 AliasHandleIrcOut(struct ip *_pip, struct alias_link *_link,
192	    int _maxsize);
193
194/* RTSP routines */
195void	 AliasHandleRtspOut(struct ip *_pip, struct alias_link *_link,
196	    int _maxpacketsize);
197
198/* PPTP routines */
199void	 AliasHandlePptpOut(struct ip *_pip, struct alias_link *_link);
200void	 AliasHandlePptpIn(struct ip *_pip, struct alias_link *_link);
201int	 AliasHandlePptpGreOut(struct ip *_pip);
202int	 AliasHandlePptpGreIn(struct ip *_pip);
203
204/* NetBIOS routines */
205int	 AliasHandleUdpNbt(struct ip *_pip, struct alias_link *_link,
206	    struct in_addr *_alias_address, u_short _alias_port);
207int	 AliasHandleUdpNbtNS(struct ip *_pip, struct alias_link *_link,
208	    struct in_addr *_alias_address, u_short *_alias_port,
209	    struct in_addr *_original_address, u_short *_original_port);
210
211/* CUSeeMe routines */
212void	 AliasHandleCUSeeMeOut(struct ip *_pip, struct alias_link *_link);
213void	 AliasHandleCUSeeMeIn(struct ip *_pip, struct in_addr _original_addr);
214
215/* Transparent proxy routines */
216int	 ProxyCheck(struct ip *_pip, struct in_addr *_proxy_server_addr,
217	    u_short *_proxy_server_port);
218void	 ProxyModify(struct alias_link *_link, struct ip *_pip,
219	    int _maxpacketsize, int _proxy_type);
220
221enum alias_tcp_state {
222	ALIAS_TCP_STATE_NOT_CONNECTED,
223	ALIAS_TCP_STATE_CONNECTED,
224	ALIAS_TCP_STATE_DISCONNECTED
225};
226
227/*lint -restore */
228
229#endif /* !_ALIAS_LOCAL_H_ */
230