alias_local.h revision 120372
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 120372 2003-09-23 07:41:55Z marcus $
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/* Macros */
5060786Sps
5160786Sps/*
5260786Sps * The following macro is used to update an
5360786Sps * internet checksum.  "delta" is a 32-bit
5460786Sps * accumulation of all the changes to the
5560786Sps * checksum (adding in new 16-bit words and
5660786Sps * subtracting out old words), and "cksum"
5760786Sps * is the checksum value to be updated.
5860786Sps */
5960786Sps#define	ADJUST_CHECKSUM(acc, cksum) \
6060786Sps	do { \
6160786Sps		acc += cksum; \
6260786Sps		if (acc < 0) { \
6360786Sps			acc = -acc; \
6460786Sps			acc = (acc >> 16) + (acc & 0xffff); \
6560812Sps			acc += acc >> 16; \
6660786Sps			cksum = (u_short) ~acc; \
6760786Sps		} else { \
6860786Sps			acc = (acc >> 16) + (acc & 0xffff); \
6960786Sps			acc += acc >> 16; \
7060786Sps			cksum = (u_short) acc; \
7160786Sps		} \
7260786Sps	} while (0)
7360786Sps
7460786Sps/* Globals */
7560786Sps
7660786Spsextern int packetAliasMode;
7760786Spsextern unsigned int skinnyPort;
7860786Sps
7960786Sps/* Prototypes */
8060786Sps
8160786Sps/* General utilities */
8260786Spsu_short	 IpChecksum(struct ip *_pip);
8360786Spsu_short	 TcpChecksum(struct ip *_pip);
8460786Spsvoid	 DifferentialChecksum(u_short *_cksum, u_short *_new, u_short *_old,
8560786Sps	    int _n);
8660786Sps
8760786Sps/* Internal data access */
8860786Spsstruct alias_link *
8960786Sps	 FindIcmpIn(struct in_addr _dst_addr, struct in_addr _alias_addr,
9060786Sps	    u_short _id_alias, int _create);
9160786Spsstruct alias_link *
9260786Sps	 FindIcmpOut(struct in_addr _src_addr, struct in_addr _dst_addr,
9360786Sps	    u_short _id, int _create);
9460786Spsstruct alias_link *
9560786Sps	 FindFragmentIn1(struct in_addr _dst_addr, struct in_addr _alias_addr,
9660786Sps	    u_short _ip_id);
9760786Spsstruct alias_link *
9860786Sps	 FindFragmentIn2(struct in_addr _dst_addr, struct in_addr _alias_addr,
9960786Sps	    u_short _ip_id);
10060786Spsstruct alias_link *
10160786Sps	 AddFragmentPtrLink(struct in_addr _dst_addr, u_short _ip_id);
10260786Spsstruct alias_link *
10360786Sps	 FindFragmentPtr(struct in_addr _dst_addr, u_short _ip_id);
10460786Spsstruct alias_link *
10560812Sps	 FindProtoIn(struct in_addr _dst_addr, struct in_addr _alias_addr,
10660812Sps	    u_char _proto);
10760812Spsstruct alias_link *
10860786Sps	 FindProtoOut(struct in_addr _src_addr, struct in_addr _dst_addr,
10960786Sps	    u_char _proto);
11060786Spsstruct alias_link *
11160786Sps	 FindUdpTcpIn(struct in_addr _dst_addr, struct in_addr _alias_addr,
11260786Sps	    u_short _dst_port, u_short _alias_port, u_char _proto, int _create);
11360786Spsstruct alias_link *
11460786Sps	 FindUdpTcpOut(struct in_addr _src_addr, struct in_addr _dst_addr,
11560812Sps	    u_short _src_port, u_short _dst_port, u_char _proto, int _create);
11660812Spsstruct alias_link *
11760812Sps	 AddPptp(struct in_addr _src_addr, struct in_addr _dst_addr,
11860812Sps	    struct in_addr _alias_addr, u_int16_t _src_call_id);
11960812Spsstruct alias_link *
12060812Sps	 FindPptpOutByCallId(struct in_addr _src_addr,
12160812Sps	    struct in_addr _dst_addr, u_int16_t _src_call_id);
12260812Spsstruct alias_link *
12360812Sps	 FindPptpInByCallId(struct in_addr _dst_addr,
12460812Sps	    struct in_addr _alias_addr, u_int16_t _dst_call_id);
12560786Spsstruct alias_link *
12660786Sps	 FindPptpOutByPeerCallId(struct in_addr _src_addr,
12760786Sps	    struct in_addr _dst_addr, u_int16_t _dst_call_id);
12860786Spsstruct alias_link *
12960786Sps	 FindPptpInByPeerCallId(struct in_addr _dst_addr,
13060786Sps	    struct in_addr _alias_addr, u_int16_t _alias_call_id);
13160786Spsstruct alias_link *
13260786Sps	 FindRtspOut(struct in_addr _src_addr, struct in_addr _dst_addr,
13360786Sps	    u_short _src_port, u_short _alias_port, u_char _proto);
13460786Spsstruct in_addr
13560786Sps	 FindOriginalAddress(struct in_addr _alias_addr);
13660786Spsstruct in_addr
13760786Sps	 FindAliasAddress(struct in_addr _original_addr);
13860786Sps
13960786Sps/* External data access/modification */
14060786Spsint	 FindNewPortGroup(struct in_addr _dst_addr, struct in_addr _alias_addr,
14160786Sps                     u_short _src_port, u_short _dst_port, u_short _port_count,
14260786Sps		     u_char _proto, u_char _align);
14360786Spsvoid	 GetFragmentAddr(struct alias_link *_link, struct in_addr *_src_addr);
14460786Spsvoid	 SetFragmentAddr(struct alias_link *_link, struct in_addr _src_addr);
14560786Spsvoid	 GetFragmentPtr(struct alias_link *_link, char **_fptr);
14660786Spsvoid	 SetFragmentPtr(struct alias_link *_link, char *fptr);
14760786Spsvoid	 SetStateIn(struct alias_link *_link, int _state);
14860786Spsvoid	 SetStateOut(struct alias_link *_link, int _state);
14960786Spsint	 GetStateIn(struct alias_link *_link);
15060786Spsint	 GetStateOut(struct alias_link *_link);
15160786Spsstruct in_addr
15260786Sps	 GetOriginalAddress(struct alias_link *_link);
15360786Spsstruct in_addr
15460786Sps	 GetDestAddress(struct alias_link *_link);
15560786Spsstruct in_addr
15660786Sps	 GetAliasAddress(struct alias_link *_link);
15760786Spsstruct in_addr
15860786Sps	 GetDefaultAliasAddress(void);
15960786Spsvoid	 SetDefaultAliasAddress(struct in_addr _alias_addr);
16060786Spsu_short	 GetOriginalPort(struct alias_link *_link);
16160786Spsu_short	 GetAliasPort(struct alias_link *_link);
16260786Spsstruct in_addr
16360786Sps	 GetProxyAddress(struct alias_link *_link);
16460786Spsvoid	 SetProxyAddress(struct alias_link *_link, struct in_addr _addr);
16560786Spsu_short	 GetProxyPort(struct alias_link *_link);
16660786Spsvoid	 SetProxyPort(struct alias_link *_link, u_short _port);
16760786Spsvoid	 SetAckModified(struct alias_link *_link);
16860786Spsint	 GetAckModified(struct alias_link *_link);
16960786Spsint	 GetDeltaAckIn(struct ip *_pip, struct alias_link *_link);
17060786Spsint	 GetDeltaSeqOut(struct ip *_pip, struct alias_link *_link);
17160786Spsvoid	 AddSeq(struct ip *_pip, struct alias_link *_link, int _delta);
17260786Spsvoid	 SetExpire(struct alias_link *_link, int _expire);
17360786Spsvoid	 ClearCheckNewLink(void);
17460786Spsvoid	 SetProtocolFlags(struct alias_link *_link, int _pflags);
17560786Spsint	 GetProtocolFlags(struct alias_link *_link);
17660786Spsvoid	 SetDestCallId(struct alias_link *_link, u_int16_t _cid);
17760786Sps#ifndef NO_FW_PUNCH
17860786Spsvoid	 PunchFWHole(struct alias_link *_link);
17960786Sps#endif
18060786Sps
18160786Sps/* Housekeeping function */
18260786Spsvoid	 HouseKeeping(void);
18360786Sps
18460786Sps/* Tcp specfic routines */
18560786Sps/* lint -save -library Suppress flexelint warnings */
18660786Sps
18760786Sps/* FTP routines */
18860786Spsvoid	 AliasHandleFtpOut(struct ip *_pip, struct alias_link *_link,
18960786Sps	    int _maxpacketsize);
19060786Sps
19160786Sps/* IRC routines */
19260786Spsvoid	 AliasHandleIrcOut(struct ip *_pip, struct alias_link *_link,
19360786Sps	    int _maxsize);
19460786Sps
19560786Sps/* RTSP routines */
19660786Spsvoid	 AliasHandleRtspOut(struct ip *_pip, struct alias_link *_link,
19760786Sps	    int _maxpacketsize);
19860786Sps
19960786Sps/* PPTP routines */
20060786Spsvoid	 AliasHandlePptpOut(struct ip *_pip, struct alias_link *_link);
20160786Spsvoid	 AliasHandlePptpIn(struct ip *_pip, struct alias_link *_link);
20260786Spsint	 AliasHandlePptpGreOut(struct ip *_pip);
20360786Spsint	 AliasHandlePptpGreIn(struct ip *_pip);
20460786Sps
20560786Sps/* NetBIOS routines */
20660786Spsint	 AliasHandleUdpNbt(struct ip *_pip, struct alias_link *_link,
20760786Sps	    struct in_addr *_alias_address, u_short _alias_port);
20860786Spsint	 AliasHandleUdpNbtNS(struct ip *_pip, struct alias_link *_link,
20960786Sps	    struct in_addr *_alias_address, u_short *_alias_port,
21060786Sps	    struct in_addr *_original_address, u_short *_original_port);
21160786Sps
21260786Sps/* CUSeeMe routines */
21360786Spsvoid	 AliasHandleCUSeeMeOut(struct ip *_pip, struct alias_link *_link);
21460786Spsvoid	 AliasHandleCUSeeMeIn(struct ip *_pip, struct in_addr _original_addr);
21560812Sps
21660786Sps/* Skinny routines */
21760786Spsvoid	 AliasHandleSkinny(struct ip *_pip, struct alias_link *_link);
21860786Sps
21960786Sps/* Transparent proxy routines */
22060786Spsint	 ProxyCheck(struct ip *_pip, struct in_addr *_proxy_server_addr,
22160786Sps	    u_short *_proxy_server_port);
22260786Spsvoid	 ProxyModify(struct alias_link *_link, struct ip *_pip,
22360786Sps	    int _maxpacketsize, int _proxy_type);
22460786Sps
22560786Spsenum alias_tcp_state {
22660786Sps	ALIAS_TCP_STATE_NOT_CONNECTED,
22760786Sps	ALIAS_TCP_STATE_CONNECTED,
22860786Sps	ALIAS_TCP_STATE_DISCONNECTED
22960786Sps};
23060786Sps
23160786Sps/*lint -restore */
23260786Sps
23360786Sps#endif /* !_ALIAS_LOCAL_H_ */
23460786Sps