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: src/lib/libalias/alias_local.h,v 1.10.2.7 2001/11/23 13:10:15 brian Exp $ 27 * $DragonFly: src/lib/libalias/alias_local.h,v 1.2 2003/06/17 04:26:41 dillon Exp $ 28 */ 29 30 /* 31 * Alias_local.h contains the function prototypes for alias.c, 32 * alias_db.c, alias_util.c and alias_ftp.c, alias_irc.c (as well 33 * as any future add-ons). It also includes macros, globals and 34 * struct definitions shared by more than one alias*.c file. 35 * 36 * This include file is intended to be used only within the aliasing 37 * software. Outside world interfaces are defined in alias.h 38 * 39 * This software is placed into the public domain with no restrictions 40 * on its distribution. 41 * 42 * Initial version: August, 1996 (cjm) 43 * 44 * <updated several times by original author and Eivind Eklund> 45 */ 46 47 #ifndef _ALIAS_LOCAL_H_ 48 #define _ALIAS_LOCAL_H_ 49 50 /* Macros */ 51 52 /* 53 * The following macro is used to update an 54 * internet checksum. "delta" is a 32-bit 55 * accumulation of all the changes to the 56 * checksum (adding in new 16-bit words and 57 * subtracting out old words), and "cksum" 58 * is the checksum value to be updated. 59 */ 60 #define ADJUST_CHECKSUM(acc, cksum) \ 61 do { \ 62 acc += cksum; \ 63 if (acc < 0) { \ 64 acc = -acc; \ 65 acc = (acc >> 16) + (acc & 0xffff); \ 66 acc += acc >> 16; \ 67 cksum = (u_short) ~acc; \ 68 } else { \ 69 acc = (acc >> 16) + (acc & 0xffff); \ 70 acc += acc >> 16; \ 71 cksum = (u_short) acc; \ 72 } \ 73 } while (0) 74 75 /* Globals */ 76 77 extern int packetAliasMode; 78 79 /* Prototypes */ 80 81 /* General utilities */ 82 u_short IpChecksum(struct ip *_pip); 83 u_short TcpChecksum(struct ip *_pip); 84 void DifferentialChecksum(u_short *_cksum, u_short *_new, u_short *_old, 85 int _n); 86 87 /* Internal data access */ 88 struct alias_link * 89 FindIcmpIn(struct in_addr _dst_addr, struct in_addr _alias_addr, 90 u_short _id_alias, int _create); 91 struct alias_link * 92 FindIcmpOut(struct in_addr _src_addr, struct in_addr _dst_addr, 93 u_short _id, int _create); 94 struct alias_link * 95 FindFragmentIn1(struct in_addr _dst_addr, struct in_addr _alias_addr, 96 u_short _ip_id); 97 struct alias_link * 98 FindFragmentIn2(struct in_addr _dst_addr, struct in_addr _alias_addr, 99 u_short _ip_id); 100 struct alias_link * 101 AddFragmentPtrLink(struct in_addr _dst_addr, u_short _ip_id); 102 struct alias_link * 103 FindFragmentPtr(struct in_addr _dst_addr, u_short _ip_id); 104 struct alias_link * 105 FindProtoIn(struct in_addr _dst_addr, struct in_addr _alias_addr, 106 u_char _proto); 107 struct alias_link * 108 FindProtoOut(struct in_addr _src_addr, struct in_addr _dst_addr, 109 u_char _proto); 110 struct alias_link * 111 FindUdpTcpIn(struct in_addr _dst_addr, struct in_addr _alias_addr, 112 u_short _dst_port, u_short _alias_port, u_char _proto, int _create); 113 struct alias_link * 114 FindUdpTcpOut(struct in_addr _src_addr, struct in_addr _dst_addr, 115 u_short _src_port, u_short _dst_port, u_char _proto, int _create); 116 struct alias_link * 117 AddPptp(struct in_addr _src_addr, struct in_addr _dst_addr, 118 struct in_addr _alias_addr, u_int16_t _src_call_id); 119 struct alias_link * 120 FindPptpOutByCallId(struct in_addr _src_addr, 121 struct in_addr _dst_addr, u_int16_t _src_call_id); 122 struct alias_link * 123 FindPptpInByCallId(struct in_addr _dst_addr, 124 struct in_addr _alias_addr, u_int16_t _dst_call_id); 125 struct alias_link * 126 FindPptpOutByPeerCallId(struct in_addr _src_addr, 127 struct in_addr _dst_addr, u_int16_t _dst_call_id); 128 struct alias_link * 129 FindPptpInByPeerCallId(struct in_addr _dst_addr, 130 struct in_addr _alias_addr, u_int16_t _alias_call_id); 131 struct alias_link * 132 FindRtspOut(struct in_addr _src_addr, struct in_addr _dst_addr, 133 u_short _src_port, u_short _alias_port, u_char _proto); 134 struct in_addr 135 FindOriginalAddress(struct in_addr _alias_addr); 136 struct in_addr 137 FindAliasAddress(struct in_addr _original_addr); 138 139 /* External data access/modification */ 140 int FindNewPortGroup(struct in_addr _dst_addr, struct in_addr _alias_addr, 141 u_short _src_port, u_short _dst_port, u_short _port_count, 142 u_char _proto, u_char _align); 143 void GetFragmentAddr(struct alias_link *_link, struct in_addr *_src_addr); 144 void SetFragmentAddr(struct alias_link *_link, struct in_addr _src_addr); 145 void GetFragmentPtr(struct alias_link *_link, char **_fptr); 146 void SetFragmentPtr(struct alias_link *_link, char *fptr); 147 void SetStateIn(struct alias_link *_link, int _state); 148 void SetStateOut(struct alias_link *_link, int _state); 149 int GetStateIn(struct alias_link *_link); 150 int GetStateOut(struct alias_link *_link); 151 struct in_addr 152 GetOriginalAddress(struct alias_link *_link); 153 struct in_addr 154 GetDestAddress(struct alias_link *_link); 155 struct in_addr 156 GetAliasAddress(struct alias_link *_link); 157 struct in_addr 158 GetDefaultAliasAddress(void); 159 void SetDefaultAliasAddress(struct in_addr _alias_addr); 160 u_short GetOriginalPort(struct alias_link *_link); 161 u_short GetAliasPort(struct alias_link *_link); 162 struct in_addr 163 GetProxyAddress(struct alias_link *_link); 164 void SetProxyAddress(struct alias_link *_link, struct in_addr _addr); 165 u_short GetProxyPort(struct alias_link *_link); 166 void SetProxyPort(struct alias_link *_link, u_short _port); 167 void SetAckModified(struct alias_link *_link); 168 int GetAckModified(struct alias_link *_link); 169 int GetDeltaAckIn(struct ip *_pip, struct alias_link *_link); 170 int GetDeltaSeqOut(struct ip *_pip, struct alias_link *_link); 171 void AddSeq(struct ip *_pip, struct alias_link *_link, int _delta); 172 void SetExpire(struct alias_link *_link, int _expire); 173 void ClearCheckNewLink(void); 174 void SetLastLineCrlfTermed(struct alias_link *_link, int _yes); 175 int GetLastLineCrlfTermed(struct alias_link *_link); 176 void SetDestCallId(struct alias_link *_link, u_int16_t _cid); 177 #ifndef NO_FW_PUNCH 178 void PunchFWHole(struct alias_link *_link); 179 #endif 180 181 /* Housekeeping function */ 182 void HouseKeeping(void); 183 184 /* Tcp specfic routines */ 185 /* lint -save -library Suppress flexelint warnings */ 186 187 /* FTP routines */ 188 void AliasHandleFtpOut(struct ip *_pip, struct alias_link *_link, 189 int _maxpacketsize); 190 191 /* IRC routines */ 192 void AliasHandleIrcOut(struct ip *_pip, struct alias_link *_link, 193 int _maxsize); 194 195 /* RTSP routines */ 196 void AliasHandleRtspOut(struct ip *_pip, struct alias_link *_link, 197 int _maxpacketsize); 198 199 /* PPTP routines */ 200 void AliasHandlePptpOut(struct ip *_pip, struct alias_link *_link); 201 void AliasHandlePptpIn(struct ip *_pip, struct alias_link *_link); 202 int AliasHandlePptpGreOut(struct ip *_pip); 203 int AliasHandlePptpGreIn(struct ip *_pip); 204 205 /* NetBIOS routines */ 206 int AliasHandleUdpNbt(struct ip *_pip, struct alias_link *_link, 207 struct in_addr *_alias_address, u_short _alias_port); 208 int AliasHandleUdpNbtNS(struct ip *_pip, struct alias_link *_link, 209 struct in_addr *_alias_address, u_short *_alias_port, 210 struct in_addr *_original_address, u_short *_original_port); 211 212 /* CUSeeMe routines */ 213 void AliasHandleCUSeeMeOut(struct ip *_pip, struct alias_link *_link); 214 void AliasHandleCUSeeMeIn(struct ip *_pip, struct in_addr _original_addr); 215 216 /* Transparent proxy routines */ 217 int ProxyCheck(struct ip *_pip, struct in_addr *_proxy_server_addr, 218 u_short *_proxy_server_port); 219 void ProxyModify(struct alias_link *_link, struct ip *_pip, 220 int _maxpacketsize, int _proxy_type); 221 222 enum alias_tcp_state { 223 ALIAS_TCP_STATE_NOT_CONNECTED, 224 ALIAS_TCP_STATE_CONNECTED, 225 ALIAS_TCP_STATE_DISCONNECTED 226 }; 227 228 /*lint -restore */ 229 230 #endif /* !_ALIAS_LOCAL_H_ */ 231