1 /*- 2 * Copyright (c) 2001 Charles Mott <cm@linktel.net> 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$ 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 76 extern int packetAliasMode; 77 78 /* Prototypes */ 79 80 /* General utilities */ 81 u_short IpChecksum(struct ip *_pip); 82 u_short TcpChecksum(struct ip *_pip); 83 void DifferentialChecksum(u_short *_cksum, u_short *_new, u_short *_old, 84 int _n); 85 86 /* Internal data access */ 87 struct alias_link * 88 FindIcmpIn(struct in_addr _dst_addr, struct in_addr _alias_addr, 89 u_short _id_alias, int _create); 90 struct alias_link * 91 FindIcmpOut(struct in_addr _src_addr, struct in_addr _dst_addr, 92 u_short _id, int _create); 93 struct alias_link * 94 FindFragmentIn1(struct in_addr _dst_addr, struct in_addr _alias_addr, 95 u_short _ip_id); 96 struct alias_link * 97 FindFragmentIn2(struct in_addr _dst_addr, struct in_addr _alias_addr, 98 u_short _ip_id); 99 struct alias_link * 100 AddFragmentPtrLink(struct in_addr _dst_addr, u_short _ip_id); 101 struct alias_link * 102 FindFragmentPtr(struct in_addr _dst_addr, u_short _ip_id); 103 struct alias_link * 104 FindProtoIn(struct in_addr _dst_addr, struct in_addr _alias_addr, 105 u_char _proto); 106 struct alias_link * 107 FindProtoOut(struct in_addr _src_addr, struct in_addr _dst_addr, 108 u_char _proto); 109 struct 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); 112 struct 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); 115 struct 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); 118 struct alias_link * 119 FindPptpOutByCallId(struct in_addr _src_addr, 120 struct in_addr _dst_addr, u_int16_t _src_call_id); 121 struct alias_link * 122 FindPptpInByCallId(struct in_addr _dst_addr, 123 struct in_addr _alias_addr, u_int16_t _dst_call_id); 124 struct alias_link * 125 FindPptpOutByPeerCallId(struct in_addr _src_addr, 126 struct in_addr _dst_addr, u_int16_t _dst_call_id); 127 struct alias_link * 128 FindPptpInByPeerCallId(struct in_addr _dst_addr, 129 struct in_addr _alias_addr, u_int16_t _alias_call_id); 130 struct 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); 133 struct in_addr 134 FindOriginalAddress(struct in_addr _alias_addr); 135 struct in_addr 136 FindAliasAddress(struct in_addr _original_addr); 137 138 /* External data access/modification */ 139 int 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); 142 void GetFragmentAddr(struct alias_link *_link, struct in_addr *_src_addr); 143 void SetFragmentAddr(struct alias_link *_link, struct in_addr _src_addr); 144 void GetFragmentPtr(struct alias_link *_link, char **_fptr); 145 void SetFragmentPtr(struct alias_link *_link, char *fptr); 146 void SetStateIn(struct alias_link *_link, int _state); 147 void SetStateOut(struct alias_link *_link, int _state); 148 int GetStateIn(struct alias_link *_link); 149 int GetStateOut(struct alias_link *_link); 150 struct in_addr 151 GetOriginalAddress(struct alias_link *_link); 152 struct in_addr 153 GetDestAddress(struct alias_link *_link); 154 struct in_addr 155 GetAliasAddress(struct alias_link *_link); 156 struct in_addr 157 GetDefaultAliasAddress(void); 158 void SetDefaultAliasAddress(struct in_addr _alias_addr); 159 u_short GetOriginalPort(struct alias_link *_link); 160 u_short GetAliasPort(struct alias_link *_link); 161 struct in_addr 162 GetProxyAddress(struct alias_link *_link); 163 void SetProxyAddress(struct alias_link *_link, struct in_addr _addr); 164 u_short GetProxyPort(struct alias_link *_link); 165 void SetProxyPort(struct alias_link *_link, u_short _port); 166 void SetAckModified(struct alias_link *_link); 167 int GetAckModified(struct alias_link *_link); 168 int GetDeltaAckIn(struct ip *_pip, struct alias_link *_link); 169 int GetDeltaSeqOut(struct ip *_pip, struct alias_link *_link); 170 void AddSeq(struct ip *_pip, struct alias_link *_link, int _delta); 171 void SetExpire(struct alias_link *_link, int _expire); 172 void ClearCheckNewLink(void); 173 void SetProtocolFlags(struct alias_link *_link, int _pflags); 174 int GetProtocolFlags(struct alias_link *_link); 175 void SetDestCallId(struct alias_link *_link, u_int16_t _cid); 176 #ifndef NO_FW_PUNCH 177 void PunchFWHole(struct alias_link *_link); 178 #endif 179 180 /* Housekeeping function */ 181 void HouseKeeping(void); 182 183 /* Tcp specfic routines */ 184 /* lint -save -library Suppress flexelint warnings */ 185 186 /* FTP routines */ 187 void AliasHandleFtpOut(struct ip *_pip, struct alias_link *_link, 188 int _maxpacketsize); 189 190 /* IRC routines */ 191 void AliasHandleIrcOut(struct ip *_pip, struct alias_link *_link, 192 int _maxsize); 193 194 /* RTSP routines */ 195 void AliasHandleRtspOut(struct ip *_pip, struct alias_link *_link, 196 int _maxpacketsize); 197 198 /* PPTP routines */ 199 void AliasHandlePptpOut(struct ip *_pip, struct alias_link *_link); 200 void AliasHandlePptpIn(struct ip *_pip, struct alias_link *_link); 201 int AliasHandlePptpGreOut(struct ip *_pip); 202 int AliasHandlePptpGreIn(struct ip *_pip); 203 204 /* NetBIOS routines */ 205 int AliasHandleUdpNbt(struct ip *_pip, struct alias_link *_link, 206 struct in_addr *_alias_address, u_short _alias_port); 207 int 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 */ 212 void AliasHandleCUSeeMeOut(struct ip *_pip, struct alias_link *_link); 213 void AliasHandleCUSeeMeIn(struct ip *_pip, struct in_addr _original_addr); 214 215 /* Transparent proxy routines */ 216 int ProxyCheck(struct ip *_pip, struct in_addr *_proxy_server_addr, 217 u_short *_proxy_server_port); 218 void ProxyModify(struct alias_link *_link, struct ip *_pip, 219 int _maxpacketsize, int _proxy_type); 220 221 enum 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