1a9643ea8Slogwang /*-
2*22ce4affSfengbojiang  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3*22ce4affSfengbojiang  *
4a9643ea8Slogwang  * Copyright (c) 2001 Charles Mott <[email protected]>
5a9643ea8Slogwang  * All rights reserved.
6a9643ea8Slogwang  *
7a9643ea8Slogwang  * Redistribution and use in source and binary forms, with or without
8a9643ea8Slogwang  * modification, are permitted provided that the following conditions
9a9643ea8Slogwang  * are met:
10a9643ea8Slogwang  * 1. Redistributions of source code must retain the above copyright
11a9643ea8Slogwang  *    notice, this list of conditions and the following disclaimer.
12a9643ea8Slogwang  * 2. Redistributions in binary form must reproduce the above copyright
13a9643ea8Slogwang  *    notice, this list of conditions and the following disclaimer in the
14a9643ea8Slogwang  *    documentation and/or other materials provided with the distribution.
15a9643ea8Slogwang  *
16a9643ea8Slogwang  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17a9643ea8Slogwang  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18a9643ea8Slogwang  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19a9643ea8Slogwang  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20a9643ea8Slogwang  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21a9643ea8Slogwang  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22a9643ea8Slogwang  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23a9643ea8Slogwang  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24a9643ea8Slogwang  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25a9643ea8Slogwang  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26a9643ea8Slogwang  * SUCH DAMAGE.
27a9643ea8Slogwang  *
28a9643ea8Slogwang  * $FreeBSD$
29a9643ea8Slogwang  */
30a9643ea8Slogwang 
31a9643ea8Slogwang /*
32a9643ea8Slogwang  * Alias_local.h contains the function prototypes for alias.c,
33a9643ea8Slogwang  * alias_db.c, alias_util.c and alias_ftp.c, alias_irc.c (as well
34a9643ea8Slogwang  * as any future add-ons).  It also includes macros, globals and
35a9643ea8Slogwang  * struct definitions shared by more than one alias*.c file.
36a9643ea8Slogwang  *
37a9643ea8Slogwang  * This include file is intended to be used only within the aliasing
38a9643ea8Slogwang  * software.  Outside world interfaces are defined in alias.h
39a9643ea8Slogwang  *
40a9643ea8Slogwang  * This software is placed into the public domain with no restrictions
41a9643ea8Slogwang  * on its distribution.
42a9643ea8Slogwang  *
43a9643ea8Slogwang  * Initial version:  August, 1996  (cjm)
44a9643ea8Slogwang  *
45a9643ea8Slogwang  * <updated several times by original author and Eivind Eklund>
46a9643ea8Slogwang  */
47a9643ea8Slogwang 
48a9643ea8Slogwang #ifndef _ALIAS_LOCAL_H_
49a9643ea8Slogwang #define	_ALIAS_LOCAL_H_
50a9643ea8Slogwang 
51a9643ea8Slogwang #include <sys/types.h>
52a9643ea8Slogwang #include <sys/sysctl.h>
53a9643ea8Slogwang 
54a9643ea8Slogwang #ifdef _KERNEL
55a9643ea8Slogwang #include <sys/malloc.h>
56a9643ea8Slogwang #include <sys/param.h>
57a9643ea8Slogwang #include <sys/lock.h>
58a9643ea8Slogwang #include <sys/mutex.h>
59a9643ea8Slogwang 
60a9643ea8Slogwang /* XXX: LibAliasSetTarget() uses this constant. */
61a9643ea8Slogwang #define	INADDR_NONE	0xffffffff
62a9643ea8Slogwang 
63a9643ea8Slogwang #include <netinet/libalias/alias_sctp.h>
64a9643ea8Slogwang #else
65a9643ea8Slogwang #include "alias_sctp.h"
66a9643ea8Slogwang #endif
67a9643ea8Slogwang 
68a9643ea8Slogwang /* Sizes of input and output link tables */
69a9643ea8Slogwang #define LINK_TABLE_OUT_SIZE        4001
70a9643ea8Slogwang #define LINK_TABLE_IN_SIZE         4001
71a9643ea8Slogwang 
72a9643ea8Slogwang #define	GET_ALIAS_PORT		-1
73a9643ea8Slogwang #define	GET_ALIAS_ID		GET_ALIAS_PORT
74a9643ea8Slogwang 
75*22ce4affSfengbojiang #ifdef _KERNEL
76*22ce4affSfengbojiang #define INET_NTOA_BUF(buf) (buf)
77*22ce4affSfengbojiang #else
78*22ce4affSfengbojiang #define INET_NTOA_BUF(buf) (buf), sizeof(buf)
79*22ce4affSfengbojiang #endif
80*22ce4affSfengbojiang 
81a9643ea8Slogwang struct proxy_entry;
82a9643ea8Slogwang 
83a9643ea8Slogwang struct libalias {
84a9643ea8Slogwang 	LIST_ENTRY(libalias) instancelist;
85a9643ea8Slogwang 
86a9643ea8Slogwang 	int		packetAliasMode;	/* Mode flags                      */
87a9643ea8Slogwang 	/* - documented in alias.h  */
88a9643ea8Slogwang 
89a9643ea8Slogwang 	struct in_addr	aliasAddress;	/* Address written onto source     */
90a9643ea8Slogwang 	/* field of IP packet.           */
91a9643ea8Slogwang 
92a9643ea8Slogwang 	struct in_addr	targetAddress;	/* IP address incoming packets     */
93a9643ea8Slogwang 	/* are sent to if no aliasing    */
94a9643ea8Slogwang 	/* link already exists           */
95a9643ea8Slogwang 
96a9643ea8Slogwang 	struct in_addr	nullAddress;	/* Used as a dummy parameter for   */
97a9643ea8Slogwang 	/* some function calls           */
98a9643ea8Slogwang 
99a9643ea8Slogwang 			LIST_HEAD     (, alias_link) linkTableOut[LINK_TABLE_OUT_SIZE];
100a9643ea8Slogwang 	/* Lookup table of pointers to     */
101a9643ea8Slogwang 	/* chains of link records. Each  */
102a9643ea8Slogwang 
103a9643ea8Slogwang 			LIST_HEAD     (, alias_link) linkTableIn[LINK_TABLE_IN_SIZE];
104a9643ea8Slogwang 	/* link record is doubly indexed */
105a9643ea8Slogwang 	/* into input and output lookup  */
106a9643ea8Slogwang 	/* tables.                       */
107a9643ea8Slogwang 
108a9643ea8Slogwang 	/* Link statistics                 */
109a9643ea8Slogwang 	int		icmpLinkCount;
110a9643ea8Slogwang 	int		udpLinkCount;
111a9643ea8Slogwang 	int		tcpLinkCount;
112a9643ea8Slogwang 	int		pptpLinkCount;
113a9643ea8Slogwang 	int		protoLinkCount;
114a9643ea8Slogwang 	int		fragmentIdLinkCount;
115a9643ea8Slogwang 	int		fragmentPtrLinkCount;
116a9643ea8Slogwang 	int		sockCount;
117a9643ea8Slogwang 
118a9643ea8Slogwang 	int		cleanupIndex;	/* Index to chain of link table    */
119a9643ea8Slogwang 	/* being inspected for old links   */
120a9643ea8Slogwang 
121a9643ea8Slogwang 	int		timeStamp;	/* System time in seconds for      */
122a9643ea8Slogwang 	/* current packet                  */
123a9643ea8Slogwang 
124a9643ea8Slogwang 	int		lastCleanupTime;	/* Last time
125a9643ea8Slogwang 						 * IncrementalCleanup()  */
126a9643ea8Slogwang 	/* was called                      */
127a9643ea8Slogwang 
128a9643ea8Slogwang 	int		deleteAllLinks;	/* If equal to zero, DeleteLink()  */
129a9643ea8Slogwang 	/* will not remove permanent links */
130a9643ea8Slogwang 
131a9643ea8Slogwang 	/* log descriptor        */
132a9643ea8Slogwang #ifdef  _KERNEL
133a9643ea8Slogwang 	char           *logDesc;
134a9643ea8Slogwang #else
135a9643ea8Slogwang 	FILE           *logDesc;
136a9643ea8Slogwang #endif
137a9643ea8Slogwang 	/* statistics monitoring */
138a9643ea8Slogwang 
139a9643ea8Slogwang 	int		newDefaultLink;	/* Indicates if a new aliasing     */
140a9643ea8Slogwang 	/* link has been created after a   */
141a9643ea8Slogwang 	/* call to PacketAliasIn/Out().    */
142a9643ea8Slogwang 
143a9643ea8Slogwang #ifndef NO_FW_PUNCH
144a9643ea8Slogwang 	int		fireWallFD;	/* File descriptor to be able to   */
145a9643ea8Slogwang 	/* control firewall.  Opened by    */
146a9643ea8Slogwang 	/* PacketAliasSetMode on first     */
147a9643ea8Slogwang 	/* setting the PKT_ALIAS_PUNCH_FW  */
148a9643ea8Slogwang 	/* flag.                           */
149a9643ea8Slogwang 	int		fireWallBaseNum;	/* The first firewall entry
150a9643ea8Slogwang 						 * free for our use */
151a9643ea8Slogwang 	int		fireWallNumNums;	/* How many entries can we
152a9643ea8Slogwang 						 * use? */
153a9643ea8Slogwang 	int		fireWallActiveNum;	/* Which entry did we last
154a9643ea8Slogwang 						 * use? */
155a9643ea8Slogwang 	char           *fireWallField;	/* bool array for entries */
156a9643ea8Slogwang #endif
157a9643ea8Slogwang 
158a9643ea8Slogwang 	unsigned int	skinnyPort;	/* TCP port used by the Skinny     */
159a9643ea8Slogwang 	/* protocol.                       */
160a9643ea8Slogwang 
161a9643ea8Slogwang 	struct proxy_entry *proxyList;
162a9643ea8Slogwang 
163a9643ea8Slogwang 	struct in_addr	true_addr;	/* in network byte order. */
164a9643ea8Slogwang 	u_short		true_port;	/* in host byte order. */
165a9643ea8Slogwang 
166a9643ea8Slogwang 	/*
167a9643ea8Slogwang 	 * sctp code support
168a9643ea8Slogwang 	 */
169a9643ea8Slogwang 
170a9643ea8Slogwang 	/* counts associations that have progressed to UP and not yet removed */
171a9643ea8Slogwang 	int		sctpLinkCount;
172a9643ea8Slogwang #ifdef  _KERNEL
173a9643ea8Slogwang 	/* timing queue for keeping track of association timeouts */
174a9643ea8Slogwang 	struct sctp_nat_timer sctpNatTimer;
175a9643ea8Slogwang 
176a9643ea8Slogwang 	/* size of hash table used in this instance */
177a9643ea8Slogwang 	u_int sctpNatTableSize;
178a9643ea8Slogwang 
179a9643ea8Slogwang /*
180a9643ea8Slogwang  * local look up table sorted by l_vtag/l_port
181a9643ea8Slogwang  */
182a9643ea8Slogwang 	LIST_HEAD(sctpNatTableL, sctp_nat_assoc) *sctpTableLocal;
183a9643ea8Slogwang /*
184a9643ea8Slogwang  * global look up table sorted by g_vtag/g_port
185a9643ea8Slogwang  */
186a9643ea8Slogwang 	LIST_HEAD(sctpNatTableG, sctp_nat_assoc) *sctpTableGlobal;
187a9643ea8Slogwang 
188a9643ea8Slogwang 	/*
189a9643ea8Slogwang 	 * avoid races in libalias: every public function has to use it.
190a9643ea8Slogwang 	 */
191a9643ea8Slogwang 	struct mtx mutex;
192a9643ea8Slogwang #endif
193a9643ea8Slogwang };
194a9643ea8Slogwang 
195a9643ea8Slogwang /* Macros */
196a9643ea8Slogwang 
197a9643ea8Slogwang #ifdef _KERNEL
198a9643ea8Slogwang #define LIBALIAS_LOCK_INIT(l) \
199a9643ea8Slogwang         mtx_init(&l->mutex, "per-instance libalias mutex", NULL, MTX_DEF)
200a9643ea8Slogwang #define LIBALIAS_LOCK_ASSERT(l) mtx_assert(&l->mutex, MA_OWNED)
201a9643ea8Slogwang #define LIBALIAS_LOCK(l) mtx_lock(&l->mutex)
202a9643ea8Slogwang #define LIBALIAS_UNLOCK(l) mtx_unlock(&l->mutex)
203a9643ea8Slogwang #define LIBALIAS_LOCK_DESTROY(l)	mtx_destroy(&l->mutex)
204a9643ea8Slogwang #else
205a9643ea8Slogwang #define LIBALIAS_LOCK_INIT(l)
206a9643ea8Slogwang #define LIBALIAS_LOCK_ASSERT(l)
207a9643ea8Slogwang #define LIBALIAS_LOCK(l)
208a9643ea8Slogwang #define LIBALIAS_UNLOCK(l)
209a9643ea8Slogwang #define LIBALIAS_LOCK_DESTROY(l)
210a9643ea8Slogwang #endif
211a9643ea8Slogwang 
212a9643ea8Slogwang /*
213a9643ea8Slogwang  * The following macro is used to update an
214a9643ea8Slogwang  * internet checksum.  "delta" is a 32-bit
215a9643ea8Slogwang  * accumulation of all the changes to the
216a9643ea8Slogwang  * checksum (adding in new 16-bit words and
217a9643ea8Slogwang  * subtracting out old words), and "cksum"
218a9643ea8Slogwang  * is the checksum value to be updated.
219a9643ea8Slogwang  */
220a9643ea8Slogwang #define	ADJUST_CHECKSUM(acc, cksum) \
221a9643ea8Slogwang 	do { \
222a9643ea8Slogwang 		acc += cksum; \
223a9643ea8Slogwang 		if (acc < 0) { \
224a9643ea8Slogwang 			acc = -acc; \
225a9643ea8Slogwang 			acc = (acc >> 16) + (acc & 0xffff); \
226a9643ea8Slogwang 			acc += acc >> 16; \
227a9643ea8Slogwang 			cksum = (u_short) ~acc; \
228a9643ea8Slogwang 		} else { \
229a9643ea8Slogwang 			acc = (acc >> 16) + (acc & 0xffff); \
230a9643ea8Slogwang 			acc += acc >> 16; \
231a9643ea8Slogwang 			cksum = (u_short) acc; \
232a9643ea8Slogwang 		} \
233a9643ea8Slogwang 	} while (0)
234a9643ea8Slogwang 
235a9643ea8Slogwang /* Prototypes */
236a9643ea8Slogwang 
237a9643ea8Slogwang /*
238a9643ea8Slogwang  * SctpFunction prototypes
239a9643ea8Slogwang  *
240a9643ea8Slogwang  */
241a9643ea8Slogwang void AliasSctpInit(struct libalias *la);
242a9643ea8Slogwang void AliasSctpTerm(struct libalias *la);
243a9643ea8Slogwang int SctpAlias(struct libalias *la, struct ip *ip, int direction);
244a9643ea8Slogwang 
245a9643ea8Slogwang /*
246a9643ea8Slogwang  * We do not calculate TCP checksums when libalias is a kernel
247a9643ea8Slogwang  * module, since it has no idea about checksum offloading.
248a9643ea8Slogwang  * If TCP data has changed, then we just set checksum to zero,
249a9643ea8Slogwang  * and caller must recalculate it himself.
250a9643ea8Slogwang  * In case if libalias will edit UDP data, the same approach
251a9643ea8Slogwang  * should be used.
252a9643ea8Slogwang  */
253a9643ea8Slogwang #ifndef _KERNEL
254a9643ea8Slogwang u_short		IpChecksum(struct ip *_pip);
255a9643ea8Slogwang u_short		TcpChecksum(struct ip *_pip);
256a9643ea8Slogwang #endif
257a9643ea8Slogwang void
258a9643ea8Slogwang DifferentialChecksum(u_short * _cksum, void * _new, void * _old, int _n);
259a9643ea8Slogwang 
260a9643ea8Slogwang /* Internal data access */
261a9643ea8Slogwang struct alias_link *
262a9643ea8Slogwang AddLink(struct libalias *la, struct in_addr src_addr, struct in_addr dst_addr,
263a9643ea8Slogwang     struct in_addr alias_addr, u_short src_port, u_short dst_port,
264a9643ea8Slogwang     int alias_param, int link_type);
265a9643ea8Slogwang struct alias_link *
266a9643ea8Slogwang FindIcmpIn(struct libalias *la, struct in_addr _dst_addr, struct in_addr _alias_addr,
267a9643ea8Slogwang     u_short _id_alias, int _create);
268a9643ea8Slogwang struct alias_link *
269a9643ea8Slogwang FindIcmpOut(struct libalias *la, struct in_addr _src_addr, struct in_addr _dst_addr,
270a9643ea8Slogwang     u_short _id, int _create);
271a9643ea8Slogwang struct alias_link *
272a9643ea8Slogwang FindFragmentIn1(struct libalias *la, struct in_addr _dst_addr, struct in_addr _alias_addr,
273a9643ea8Slogwang     u_short _ip_id);
274a9643ea8Slogwang struct alias_link *
275a9643ea8Slogwang FindFragmentIn2(struct libalias *la, struct in_addr _dst_addr, struct in_addr _alias_addr,
276a9643ea8Slogwang     u_short _ip_id);
277a9643ea8Slogwang struct alias_link *
278a9643ea8Slogwang 		AddFragmentPtrLink(struct libalias *la, struct in_addr _dst_addr, u_short _ip_id);
279a9643ea8Slogwang struct alias_link *
280a9643ea8Slogwang 		FindFragmentPtr(struct libalias *la, struct in_addr _dst_addr, u_short _ip_id);
281a9643ea8Slogwang struct alias_link *
282a9643ea8Slogwang FindProtoIn(struct libalias *la, struct in_addr _dst_addr, struct in_addr _alias_addr,
283a9643ea8Slogwang     u_char _proto);
284a9643ea8Slogwang struct alias_link *
285a9643ea8Slogwang FindProtoOut(struct libalias *la, struct in_addr _src_addr, struct in_addr _dst_addr,
286a9643ea8Slogwang     u_char _proto);
287a9643ea8Slogwang struct alias_link *
288a9643ea8Slogwang FindUdpTcpIn(struct libalias *la, struct in_addr _dst_addr, struct in_addr _alias_addr,
289a9643ea8Slogwang     u_short _dst_port, u_short _alias_port, u_char _proto, int _create);
290a9643ea8Slogwang struct alias_link *
291a9643ea8Slogwang FindUdpTcpOut(struct libalias *la, struct in_addr _src_addr, struct in_addr _dst_addr,
292a9643ea8Slogwang     u_short _src_port, u_short _dst_port, u_char _proto, int _create);
293a9643ea8Slogwang struct alias_link *
294a9643ea8Slogwang AddPptp(struct libalias *la, struct in_addr _src_addr, struct in_addr _dst_addr,
295a9643ea8Slogwang     struct in_addr _alias_addr, u_int16_t _src_call_id);
296a9643ea8Slogwang struct alias_link *
297a9643ea8Slogwang FindPptpOutByCallId(struct libalias *la, struct in_addr _src_addr,
298a9643ea8Slogwang     struct in_addr _dst_addr, u_int16_t _src_call_id);
299a9643ea8Slogwang struct alias_link *
300a9643ea8Slogwang FindPptpInByCallId(struct libalias *la, struct in_addr _dst_addr,
301a9643ea8Slogwang     struct in_addr _alias_addr, u_int16_t _dst_call_id);
302a9643ea8Slogwang struct alias_link *
303a9643ea8Slogwang FindPptpOutByPeerCallId(struct libalias *la, struct in_addr _src_addr,
304a9643ea8Slogwang     struct in_addr _dst_addr, u_int16_t _dst_call_id);
305a9643ea8Slogwang struct alias_link *
306a9643ea8Slogwang FindPptpInByPeerCallId(struct libalias *la, struct in_addr _dst_addr,
307a9643ea8Slogwang     struct in_addr _alias_addr, u_int16_t _alias_call_id);
308a9643ea8Slogwang struct alias_link *
309a9643ea8Slogwang FindRtspOut(struct libalias *la, struct in_addr _src_addr, struct in_addr _dst_addr,
310a9643ea8Slogwang     u_short _src_port, u_short _alias_port, u_char _proto);
311a9643ea8Slogwang struct in_addr
312a9643ea8Slogwang 		FindOriginalAddress(struct libalias *la, struct in_addr _alias_addr);
313a9643ea8Slogwang struct in_addr
314a9643ea8Slogwang 		FindAliasAddress(struct libalias *la, struct in_addr _original_addr);
315a9643ea8Slogwang struct in_addr
316a9643ea8Slogwang FindSctpRedirectAddress(struct libalias *la,  struct sctp_nat_msg *sm);
317a9643ea8Slogwang 
318a9643ea8Slogwang /* External data access/modification */
319a9643ea8Slogwang int
320a9643ea8Slogwang FindNewPortGroup(struct libalias *la, struct in_addr _dst_addr, struct in_addr _alias_addr,
321a9643ea8Slogwang     u_short _src_port, u_short _dst_port, u_short _port_count,
322a9643ea8Slogwang     u_char _proto, u_char _align);
323a9643ea8Slogwang void		GetFragmentAddr(struct alias_link *_lnk, struct in_addr *_src_addr);
324a9643ea8Slogwang void		SetFragmentAddr(struct alias_link *_lnk, struct in_addr _src_addr);
325*22ce4affSfengbojiang void		GetFragmentPtr(struct alias_link *_lnk, void **_fptr);
326*22ce4affSfengbojiang void		SetFragmentPtr(struct alias_link *_lnk, void *fptr);
327a9643ea8Slogwang void		SetStateIn(struct alias_link *_lnk, int _state);
328a9643ea8Slogwang void		SetStateOut(struct alias_link *_lnk, int _state);
329a9643ea8Slogwang int		GetStateIn (struct alias_link *_lnk);
330a9643ea8Slogwang int		GetStateOut(struct alias_link *_lnk);
331a9643ea8Slogwang struct in_addr
332a9643ea8Slogwang 		GetOriginalAddress(struct alias_link *_lnk);
333a9643ea8Slogwang struct in_addr
334a9643ea8Slogwang 		GetDestAddress(struct alias_link *_lnk);
335a9643ea8Slogwang struct in_addr
336a9643ea8Slogwang 		GetAliasAddress(struct alias_link *_lnk);
337a9643ea8Slogwang struct in_addr
338a9643ea8Slogwang 		GetDefaultAliasAddress(struct libalias *la);
339a9643ea8Slogwang void		SetDefaultAliasAddress(struct libalias *la, struct in_addr _alias_addr);
340a9643ea8Slogwang u_short		GetOriginalPort(struct alias_link *_lnk);
341a9643ea8Slogwang u_short		GetAliasPort(struct alias_link *_lnk);
342a9643ea8Slogwang struct in_addr
343a9643ea8Slogwang 		GetProxyAddress(struct alias_link *_lnk);
344a9643ea8Slogwang void		SetProxyAddress(struct alias_link *_lnk, struct in_addr _addr);
345a9643ea8Slogwang u_short		GetProxyPort(struct alias_link *_lnk);
346a9643ea8Slogwang void		SetProxyPort(struct alias_link *_lnk, u_short _port);
347a9643ea8Slogwang void		SetAckModified(struct alias_link *_lnk);
348a9643ea8Slogwang int		GetAckModified(struct alias_link *_lnk);
349a9643ea8Slogwang int		GetDeltaAckIn(u_long, struct alias_link *_lnk);
350a9643ea8Slogwang int             GetDeltaSeqOut(u_long, struct alias_link *lnk);
351a9643ea8Slogwang void            AddSeq(struct alias_link *lnk, int delta, u_int ip_hl,
352a9643ea8Slogwang 		    u_short ip_len, u_long th_seq, u_int th_off);
353a9643ea8Slogwang void		SetExpire (struct alias_link *_lnk, int _expire);
354a9643ea8Slogwang void		ClearCheckNewLink(struct libalias *la);
355a9643ea8Slogwang void		SetProtocolFlags(struct alias_link *_lnk, int _pflags);
356a9643ea8Slogwang int		GetProtocolFlags(struct alias_link *_lnk);
357a9643ea8Slogwang void		SetDestCallId(struct alias_link *_lnk, u_int16_t _cid);
358a9643ea8Slogwang 
359a9643ea8Slogwang #ifndef NO_FW_PUNCH
360a9643ea8Slogwang void		PunchFWHole(struct alias_link *_lnk);
361a9643ea8Slogwang 
362a9643ea8Slogwang #endif
363a9643ea8Slogwang 
364a9643ea8Slogwang /* Housekeeping function */
365a9643ea8Slogwang void		HouseKeeping(struct libalias *);
366a9643ea8Slogwang 
367a9643ea8Slogwang /* Tcp specific routines */
368a9643ea8Slogwang /* lint -save -library Suppress flexelint warnings */
369a9643ea8Slogwang 
370a9643ea8Slogwang /* Transparent proxy routines */
371a9643ea8Slogwang int
372a9643ea8Slogwang ProxyCheck(struct libalias *la, struct in_addr *proxy_server_addr,
373a9643ea8Slogwang     u_short * proxy_server_port, struct in_addr src_addr,
374a9643ea8Slogwang     struct in_addr dst_addr, u_short dst_port, u_char ip_p);
375a9643ea8Slogwang void
376a9643ea8Slogwang ProxyModify(struct libalias *la, struct alias_link *_lnk, struct ip *_pip,
377a9643ea8Slogwang     int _maxpacketsize, int _proxy_type);
378a9643ea8Slogwang 
379a9643ea8Slogwang enum alias_tcp_state {
380a9643ea8Slogwang 	ALIAS_TCP_STATE_NOT_CONNECTED,
381a9643ea8Slogwang 	ALIAS_TCP_STATE_CONNECTED,
382a9643ea8Slogwang 	ALIAS_TCP_STATE_DISCONNECTED
383a9643ea8Slogwang };
384a9643ea8Slogwang 
385a9643ea8Slogwang #if defined(_NETINET_IP_H_)
386a9643ea8Slogwang static __inline void *
ip_next(struct ip * iphdr)387a9643ea8Slogwang ip_next(struct ip *iphdr)
388a9643ea8Slogwang {
389a9643ea8Slogwang 	char *p = (char *)iphdr;
390a9643ea8Slogwang 	return (&p[iphdr->ip_hl * 4]);
391a9643ea8Slogwang }
392a9643ea8Slogwang #endif
393a9643ea8Slogwang 
394a9643ea8Slogwang #if defined(_NETINET_TCP_H_)
395a9643ea8Slogwang static __inline void *
tcp_next(struct tcphdr * tcphdr)396a9643ea8Slogwang tcp_next(struct tcphdr *tcphdr)
397a9643ea8Slogwang {
398a9643ea8Slogwang 	char *p = (char *)tcphdr;
399a9643ea8Slogwang 	return (&p[tcphdr->th_off * 4]);
400a9643ea8Slogwang }
401a9643ea8Slogwang #endif
402a9643ea8Slogwang 
403a9643ea8Slogwang #if defined(_NETINET_UDP_H_)
404a9643ea8Slogwang static __inline void *
udp_next(struct udphdr * udphdr)405a9643ea8Slogwang udp_next(struct udphdr *udphdr)
406a9643ea8Slogwang {
407a9643ea8Slogwang 	return ((void *)(udphdr + 1));
408a9643ea8Slogwang }
409a9643ea8Slogwang #endif
410a9643ea8Slogwang 
411a9643ea8Slogwang #endif				/* !_ALIAS_LOCAL_H_ */
412