alias_local.h revision 127689
160812Sps/*-
260786Sps * Copyright (c) 2001 Charles Mott <cm@linktel.net>
360786Sps * All rights reserved.
460786Sps *
560786Sps * Redistribution and use in source and binary forms, with or without
660786Sps * modification, are permitted provided that the following conditions
760786Sps * are met:
860786Sps * 1. Redistributions of source code must retain the above copyright
960786Sps *    notice, this list of conditions and the following disclaimer.
1060786Sps * 2. Redistributions in binary form must reproduce the above copyright
1160786Sps *    notice, this list of conditions and the following disclaimer in the
1260786Sps *    documentation and/or other materials provided with the distribution.
1360786Sps *
1460786Sps * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1560786Sps * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1660786Sps * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1760786Sps * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1860786Sps * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1960786Sps * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2060786Sps * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2160786Sps * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2260786Sps * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2360786Sps * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2460786Sps * SUCH DAMAGE.
2560786Sps *
2660786Sps * $FreeBSD: head/sys/netinet/libalias/alias_local.h 127689 2004-03-31 21:32:58Z des $
2760786Sps */
2860786Sps
2960786Sps/*
3060786Sps * Alias_local.h contains the function prototypes for alias.c,
3160786Sps * alias_db.c, alias_util.c and alias_ftp.c, alias_irc.c (as well
3260786Sps * as any future add-ons).  It also includes macros, globals and
3360812Sps * struct definitions shared by more than one alias*.c file.
3460786Sps *
3560786Sps * This include file is intended to be used only within the aliasing
3660786Sps * software.  Outside world interfaces are defined in alias.h
3760786Sps *
3860786Sps * This software is placed into the public domain with no restrictions
3960786Sps * on its distribution.
4060786Sps *
4160786Sps * Initial version:  August, 1996  (cjm)
4260786Sps *
4360786Sps * <updated several times by original author and Eivind Eklund>
4460786Sps */
4560786Sps
4660786Sps#ifndef _ALIAS_LOCAL_H_
4760786Sps#define	_ALIAS_LOCAL_H_
4860786Sps
4960786Sps#include <sys/queue.h>
5060786Sps
5160786Sps/* Sizes of input and output link tables */
5260786Sps#define LINK_TABLE_OUT_SIZE         101
5360786Sps#define LINK_TABLE_IN_SIZE         4001
5460786Sps
5560786Spsstruct proxy_entry;
5660786Sps
5760786Spsstruct libalias {
5860786Sps	LIST_ENTRY(libalias) instancelist;
5960786Sps
6060786Sps	int		packetAliasMode;	/* Mode flags                      */
6160786Sps	/* - documented in alias.h  */
6260786Sps
6360786Sps	struct in_addr	aliasAddress;	/* Address written onto source     */
6460786Sps	/* field of IP packet.           */
6560812Sps
6660786Sps	struct in_addr	targetAddress;	/* IP address incoming packets     */
6760786Sps	/* are sent to if no aliasing    */
6860786Sps	/* link already exists           */
6960786Sps
7060786Sps	struct in_addr	nullAddress;	/* Used as a dummy parameter for   */
7160786Sps	/* some function calls           */
7260786Sps
7360786Sps			LIST_HEAD     (, alias_link) linkTableOut[LINK_TABLE_OUT_SIZE];
7460786Sps	/* Lookup table of pointers to     */
7560786Sps	/* chains of link records. Each  */
7660786Sps
7760786Sps			LIST_HEAD     (, alias_link) linkTableIn[LINK_TABLE_IN_SIZE];
7860786Sps	/* link record is doubly indexed */
7960786Sps	/* into input and output lookup  */
8060786Sps	/* tables.                       */
8160786Sps
8260786Sps	/* Link statistics                 */
8360786Sps	int		icmpLinkCount;
8460786Sps	int		udpLinkCount;
8560786Sps	int		tcpLinkCount;
8660786Sps	int		pptpLinkCount;
8760786Sps	int		protoLinkCount;
8860786Sps	int		fragmentIdLinkCount;
8960786Sps	int		fragmentPtrLinkCount;
9060786Sps	int		sockCount;
9160786Sps
9260786Sps	int		cleanupIndex;	/* Index to chain of link table    */
9360786Sps	/* being inspected for old links   */
9460786Sps
9560786Sps	int		timeStamp;	/* System time in seconds for      */
9660786Sps	/* current packet                  */
9760786Sps
9860786Sps	int		lastCleanupTime;	/* Last time
9960786Sps						 * IncrementalCleanup()  */
10060786Sps	/* was called                      */
10160786Sps
10260786Sps	int		houseKeepingResidual;	/* used by HouseKeeping()          */
10360786Sps
10460786Sps	int		deleteAllLinks;	/* If equal to zero, DeleteLink()  */
10560812Sps	/* will not remove permanent links */
10660812Sps
10760812Sps	FILE           *monitorFile;	/* File descriptor for link        */
10860786Sps	/* statistics monitoring file      */
10960786Sps
11060786Sps	int		newDefaultLink;	/* Indicates if a new aliasing     */
11160786Sps	/* link has been created after a   */
11260786Sps	/* call to PacketAliasIn/Out().    */
11360786Sps
11460786Sps#ifndef NO_FW_PUNCH
11560812Sps	int		fireWallFD;	/* File descriptor to be able to   */
11660812Sps	/* control firewall.  Opened by    */
11760812Sps	/* PacketAliasSetMode on first     */
11860812Sps	/* setting the PKT_ALIAS_PUNCH_FW  */
11960812Sps	/* flag.                           */
12060812Sps	int		fireWallBaseNum;	/* The first firewall entry
12160812Sps						 * free for our use */
12260812Sps	int		fireWallNumNums;	/* How many entries can we
12360812Sps						 * use? */
12460812Sps	int		fireWallActiveNum;	/* Which entry did we last
12560786Sps						 * use? */
12660786Sps	char           *fireWallField;	/* bool array for entries */
12760786Sps#endif
12860786Sps
12960786Sps	unsigned int	skinnyPort;	/* TCP port used by the Skinny     */
13060786Sps	/* protocol.                       */
13160786Sps
13260786Sps	struct proxy_entry *proxyList;
13360786Sps
13460786Sps	struct in_addr	true_addr;	/* in network byte order. */
13560786Sps	u_short		true_port;	/* in host byte order. */
13660786Sps
13760786Sps};
13860786Sps
13960786Sps/* Macros */
14060786Sps
14160786Sps/*
14260786Sps * The following macro is used to update an
14360786Sps * internet checksum.  "delta" is a 32-bit
14460786Sps * accumulation of all the changes to the
14560786Sps * checksum (adding in new 16-bit words and
14660786Sps * subtracting out old words), and "cksum"
14760786Sps * is the checksum value to be updated.
14860786Sps */
14960786Sps#define	ADJUST_CHECKSUM(acc, cksum) \
15060786Sps	do { \
15160786Sps		acc += cksum; \
15260786Sps		if (acc < 0) { \
15360786Sps			acc = -acc; \
15460786Sps			acc = (acc >> 16) + (acc & 0xffff); \
15560786Sps			acc += acc >> 16; \
15660786Sps			cksum = (u_short) ~acc; \
15760786Sps		} else { \
15860786Sps			acc = (acc >> 16) + (acc & 0xffff); \
15960786Sps			acc += acc >> 16; \
16060786Sps			cksum = (u_short) acc; \
16160786Sps		} \
16260786Sps	} while (0)
16360786Sps
16460786Sps
16560786Sps/* Prototypes */
16660786Sps
16760786Sps/* General utilities */
16860786Spsu_short		IpChecksum(struct ip *_pip);
16960786Spsu_short		TcpChecksum(struct ip *_pip);
17060786Spsvoid
17160786SpsDifferentialChecksum(u_short * _cksum, void * _new, void * _old, int _n);
17260786Sps
17360786Sps/* Internal data access */
17460786Spsstruct alias_link *
17560786SpsFindIcmpIn(struct libalias *la, struct in_addr _dst_addr, struct in_addr _alias_addr,
17660786Sps    u_short _id_alias, int _create);
17760786Spsstruct alias_link *
17860786SpsFindIcmpOut(struct libalias *la, struct in_addr _src_addr, struct in_addr _dst_addr,
17960786Sps    u_short _id, int _create);
18060786Spsstruct alias_link *
18160786SpsFindFragmentIn1(struct libalias *la, struct in_addr _dst_addr, struct in_addr _alias_addr,
18260786Sps    u_short _ip_id);
18360786Spsstruct alias_link *
18460786SpsFindFragmentIn2(struct libalias *la, struct in_addr _dst_addr, struct in_addr _alias_addr,
18560786Sps    u_short _ip_id);
18660786Spsstruct alias_link *
18760786Sps		AddFragmentPtrLink(struct libalias *la, struct in_addr _dst_addr, u_short _ip_id);
18860786Spsstruct alias_link *
18960786Sps		FindFragmentPtr(struct libalias *la, struct in_addr _dst_addr, u_short _ip_id);
19060786Spsstruct alias_link *
19160786SpsFindProtoIn(struct libalias *la, struct in_addr _dst_addr, struct in_addr _alias_addr,
19260786Sps    u_char _proto);
19360786Spsstruct alias_link *
19460786SpsFindProtoOut(struct libalias *la, struct in_addr _src_addr, struct in_addr _dst_addr,
19560786Sps    u_char _proto);
19660786Spsstruct alias_link *
19760786SpsFindUdpTcpIn(struct libalias *la, struct in_addr _dst_addr, struct in_addr _alias_addr,
19860786Sps    u_short _dst_port, u_short _alias_port, u_char _proto, int _create);
19960786Spsstruct alias_link *
20060786SpsFindUdpTcpOut(struct libalias *la, struct in_addr _src_addr, struct in_addr _dst_addr,
20160786Sps    u_short _src_port, u_short _dst_port, u_char _proto, int _create);
20260786Spsstruct alias_link *
20360786SpsAddPptp(struct libalias *la, struct in_addr _src_addr, struct in_addr _dst_addr,
20460786Sps    struct in_addr _alias_addr, u_int16_t _src_call_id);
20560786Spsstruct alias_link *
20660786SpsFindPptpOutByCallId(struct libalias *la, struct in_addr _src_addr,
20760786Sps    struct in_addr _dst_addr, u_int16_t _src_call_id);
20860786Spsstruct alias_link *
20960786SpsFindPptpInByCallId(struct libalias *la, struct in_addr _dst_addr,
21060786Sps    struct in_addr _alias_addr, u_int16_t _dst_call_id);
21160786Spsstruct alias_link *
21260786SpsFindPptpOutByPeerCallId(struct libalias *la, struct in_addr _src_addr,
21360786Sps    struct in_addr _dst_addr, u_int16_t _dst_call_id);
21460786Spsstruct alias_link *
21560812SpsFindPptpInByPeerCallId(struct libalias *la, struct in_addr _dst_addr,
21660786Sps    struct in_addr _alias_addr, u_int16_t _alias_call_id);
21760786Spsstruct alias_link *
21860786SpsFindRtspOut(struct libalias *la, struct in_addr _src_addr, struct in_addr _dst_addr,
21960786Sps    u_short _src_port, u_short _alias_port, u_char _proto);
22060786Spsstruct in_addr
22160786Sps		FindOriginalAddress(struct libalias *la, struct in_addr _alias_addr);
22260786Spsstruct in_addr
22360786Sps		FindAliasAddress(struct libalias *la, struct in_addr _original_addr);
22460786Sps
22560786Sps/* External data access/modification */
22660786Spsint
22760786SpsFindNewPortGroup(struct libalias *la, struct in_addr _dst_addr, struct in_addr _alias_addr,
22860786Sps    u_short _src_port, u_short _dst_port, u_short _port_count,
22960786Sps    u_char _proto, u_char _align);
23060786Spsvoid		GetFragmentAddr(struct alias_link *_link, struct in_addr *_src_addr);
23160786Spsvoid		SetFragmentAddr(struct alias_link *_link, struct in_addr _src_addr);
23260786Spsvoid		GetFragmentPtr(struct alias_link *_link, char **_fptr);
23360786Spsvoid		SetFragmentPtr(struct alias_link *_link, char *fptr);
23460786Spsvoid		SetStateIn(struct alias_link *_link, int _state);
23560786Spsvoid		SetStateOut(struct alias_link *_link, int _state);
23660786Spsint		GetStateIn (struct alias_link *_link);
23760786Spsint		GetStateOut(struct alias_link *_link);
23860786Spsstruct in_addr
23960786Sps		GetOriginalAddress(struct alias_link *_link);
24060786Spsstruct in_addr
24160786Sps		GetDestAddress(struct alias_link *_link);
24260786Spsstruct in_addr
24360786Sps		GetAliasAddress(struct alias_link *_link);
24460786Spsstruct in_addr
24560786Sps		GetDefaultAliasAddress(struct libalias *la);
24660786Spsvoid		SetDefaultAliasAddress(struct libalias *la, struct in_addr _alias_addr);
24760786Spsu_short		GetOriginalPort(struct alias_link *_link);
24860786Spsu_short		GetAliasPort(struct alias_link *_link);
24960786Spsstruct in_addr
25060786Sps		GetProxyAddress(struct alias_link *_link);
25160786Spsvoid		SetProxyAddress(struct alias_link *_link, struct in_addr _addr);
25260786Spsu_short		GetProxyPort(struct alias_link *_link);
25360786Spsvoid		SetProxyPort(struct alias_link *_link, u_short _port);
25460786Spsvoid		SetAckModified(struct alias_link *_link);
25560786Spsint		GetAckModified(struct alias_link *_link);
25660786Spsint		GetDeltaAckIn(struct ip *_pip, struct alias_link *_link);
25760786Spsint		GetDeltaSeqOut(struct ip *_pip, struct alias_link *_link);
25860786Spsvoid		AddSeq    (struct ip *_pip, struct alias_link *_link, int _delta);
25960786Spsvoid		SetExpire (struct alias_link *_link, int _expire);
26060786Spsvoid		ClearCheckNewLink(struct libalias *la);
26160786Spsvoid		SetProtocolFlags(struct alias_link *_link, int _pflags);
26260786Spsint		GetProtocolFlags(struct alias_link *_link);
26360786Spsvoid		SetDestCallId(struct alias_link *_link, u_int16_t _cid);
26460786Sps
26560786Sps#ifndef NO_FW_PUNCH
26660786Spsvoid		PunchFWHole(struct alias_link *_link);
26760786Sps
26860786Sps#endif
26960786Sps
27060786Sps/* Housekeeping function */
27160786Spsvoid		HouseKeeping(struct libalias *);
27260786Sps
27360786Sps/* Tcp specfic routines */
27460786Sps/* lint -save -library Suppress flexelint warnings */
27560786Sps
27660786Sps/* FTP routines */
27760786Spsvoid
27860786SpsAliasHandleFtpOut(struct libalias *la, struct ip *_pip, struct alias_link *_link,
27960786Sps    int _maxpacketsize);
28060786Sps
28160786Sps/* IRC routines */
28260786Spsvoid
28360786SpsAliasHandleIrcOut(struct libalias *la, struct ip *_pip, struct alias_link *_link,
28460786Sps    int _maxsize);
28560786Sps
28660786Sps/* RTSP routines */
28760786Spsvoid
28860786SpsAliasHandleRtspOut(struct libalias *la, struct ip *_pip, struct alias_link *_link,
28960786Sps    int _maxpacketsize);
29060786Sps
29160786Sps/* PPTP routines */
29260786Spsvoid		AliasHandlePptpOut(struct libalias *la, struct ip *_pip, struct alias_link *_link);
29360786Spsvoid		AliasHandlePptpIn(struct libalias *la, struct ip *_pip, struct alias_link *_link);
29460786Spsint		AliasHandlePptpGreOut(struct libalias *la, struct ip *_pip);
29560786Spsint		AliasHandlePptpGreIn(struct libalias *la, struct ip *_pip);
29660786Sps
29760786Sps/* NetBIOS routines */
29860786Spsint
29960786SpsAliasHandleUdpNbt(struct libalias *la, struct ip *_pip, struct alias_link *_link,
30060786Sps    struct in_addr *_alias_address, u_short _alias_port);
30160786Spsint
30260786SpsAliasHandleUdpNbtNS(struct libalias *la, struct ip *_pip, struct alias_link *_link,
30360786Sps    struct in_addr *_alias_address, u_short * _alias_port,
30460786Sps    struct in_addr *_original_address, u_short * _original_port);
30560786Sps
30660786Sps/* CUSeeMe routines */
30760786Spsvoid		AliasHandleCUSeeMeOut(struct libalias *la, struct ip *_pip, struct alias_link *_link);
30860786Spsvoid		AliasHandleCUSeeMeIn(struct libalias *la, struct ip *_pip, struct in_addr _original_addr);
30960786Sps
31060786Sps/* Skinny routines */
31160786Spsvoid		AliasHandleSkinny(struct libalias *la, struct ip *_pip, struct alias_link *_link);
31260786Sps
31360786Sps/* Transparent proxy routines */
31460786Spsint
31560786SpsProxyCheck(struct libalias *la, struct ip *_pip, struct in_addr *_proxy_server_addr,
31660786Sps    u_short * _proxy_server_port);
31760786Spsvoid
31860786SpsProxyModify(struct libalias *la, struct alias_link *_link, struct ip *_pip,
31960786Sps    int _maxpacketsize, int _proxy_type);
32060786Sps
32160786Spsenum alias_tcp_state {
32260786Sps	ALIAS_TCP_STATE_NOT_CONNECTED,
32360786Sps	ALIAS_TCP_STATE_CONNECTED,
32460786Sps	ALIAS_TCP_STATE_DISCONNECTED
32560786Sps};
32660786Sps
32760786Sps/*lint -restore */
32860786Sps
32960786Sps#endif				/* !_ALIAS_LOCAL_H_ */
33060786Sps