alias.h revision 145931
1/* lint -save -library Flexelint comment for external headers */ 2 3/*- 4 * Copyright (c) 2001 Charles Mott <cm@linktel.net> 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 * 28 * $FreeBSD: head/sys/netinet/libalias/alias.h 145931 2005-05-05 21:53:17Z glebius $ 29 */ 30 31/*- 32 * Alias.h defines the outside world interfaces for the packet aliasing 33 * software. 34 * 35 * This software is placed into the public domain with no restrictions on its 36 * distribution. 37 */ 38 39#ifndef _ALIAS_H_ 40#define _ALIAS_H_ 41 42#ifdef _KERNEL 43/* 44 * The kernel version of libalias does not support these features. 45 */ 46#define NO_FW_PUNCH 47#define NO_LOGGING 48#define NO_USE_SOCKETS 49#endif 50 51/* 52 * The external interface to libalias, the packet aliasing engine. 53 * 54 * There are two sets of functions: 55 * 56 * PacketAlias*() the old API which doesn't take an instance pointer 57 * and therefore can only have one packet engine at a time. 58 * 59 * LibAlias*() the new API which takes as first argument a pointer to 60 * the instance of the packet aliasing engine. 61 * 62 * The functions otherwise correspond to each other one for one, except 63 * for the LibAliasUnaliasOut()/PacketUnaliasOut() function which were 64 * were misnamed in the old API. 65 */ 66 67/* 68 * The instance structure 69 */ 70struct libalias; 71 72/* 73 * An anonymous structure, a pointer to which is returned from 74 * PacketAliasRedirectAddr(), PacketAliasRedirectPort() or 75 * PacketAliasRedirectProto(), passed to PacketAliasAddServer(), 76 * and freed by PacketAliasRedirectDelete(). 77 */ 78struct alias_link; 79 80 81/* OLD API */ 82 83/* Initialization and control functions. */ 84void PacketAliasInit(void); 85void PacketAliasSetAddress(struct in_addr _addr); 86void PacketAliasSetFWBase(unsigned int _base, unsigned int _num); 87void PacketAliasSetSkinnyPort(unsigned int _port); 88unsigned int 89 PacketAliasSetMode(unsigned int _flags, unsigned int _mask); 90void PacketAliasUninit(void); 91 92/* Packet Handling functions. */ 93int PacketAliasIn(char *_ptr, int _maxpacketsize); 94int PacketAliasOut(char *_ptr, int _maxpacketsize); 95int PacketUnaliasOut(char *_ptr, int _maxpacketsize); 96 97/* Port and address redirection functions. */ 98 99 100int 101PacketAliasAddServer(struct alias_link *_lnk, 102 struct in_addr _addr, unsigned short _port); 103struct alias_link * 104PacketAliasRedirectAddr(struct in_addr _src_addr, 105 struct in_addr _alias_addr); 106int PacketAliasRedirectDynamic(struct alias_link *_lnk); 107void PacketAliasRedirectDelete(struct alias_link *_lnk); 108struct alias_link * 109PacketAliasRedirectPort(struct in_addr _src_addr, 110 unsigned short _src_port, struct in_addr _dst_addr, 111 unsigned short _dst_port, struct in_addr _alias_addr, 112 unsigned short _alias_port, unsigned char _proto); 113struct alias_link * 114PacketAliasRedirectProto(struct in_addr _src_addr, 115 struct in_addr _dst_addr, struct in_addr _alias_addr, 116 unsigned char _proto); 117 118/* Fragment Handling functions. */ 119void PacketAliasFragmentIn(char *_ptr, char *_ptr_fragment); 120char *PacketAliasGetFragment(char *_ptr); 121int PacketAliasSaveFragment(char *_ptr); 122 123/* Miscellaneous functions. */ 124int PacketAliasCheckNewLink(void); 125unsigned short 126 PacketAliasInternetChecksum(unsigned short *_ptr, int _nbytes); 127void PacketAliasSetTarget(struct in_addr _target_addr); 128 129/* Transparent proxying routines. */ 130int PacketAliasProxyRule(const char *_cmd); 131 132/* NEW API */ 133 134/* Initialization and control functions. */ 135struct libalias *LibAliasInit(struct libalias *); 136void LibAliasSetAddress(struct libalias *, struct in_addr _addr); 137void LibAliasSetFWBase(struct libalias *, unsigned int _base, unsigned int _num); 138void LibAliasSetSkinnyPort(struct libalias *, unsigned int _port); 139unsigned int 140 LibAliasSetMode(struct libalias *, unsigned int _flags, unsigned int _mask); 141void LibAliasUninit(struct libalias *); 142 143/* Packet Handling functions. */ 144int LibAliasIn (struct libalias *, char *_ptr, int _maxpacketsize); 145int LibAliasOut(struct libalias *, char *_ptr, int _maxpacketsize); 146int LibAliasOutTry(struct libalias *, char *_ptr, int _maxpacketsize, int _create); 147int LibAliasUnaliasOut(struct libalias *, char *_ptr, int _maxpacketsize); 148 149/* Port and address redirection functions. */ 150 151int 152LibAliasAddServer(struct libalias *, struct alias_link *_lnk, 153 struct in_addr _addr, unsigned short _port); 154struct alias_link * 155LibAliasRedirectAddr(struct libalias *, struct in_addr _src_addr, 156 struct in_addr _alias_addr); 157int LibAliasRedirectDynamic(struct libalias *, struct alias_link *_lnk); 158void LibAliasRedirectDelete(struct libalias *, struct alias_link *_lnk); 159struct alias_link * 160LibAliasRedirectPort(struct libalias *, struct in_addr _src_addr, 161 unsigned short _src_port, struct in_addr _dst_addr, 162 unsigned short _dst_port, struct in_addr _alias_addr, 163 unsigned short _alias_port, unsigned char _proto); 164struct alias_link * 165LibAliasRedirectProto(struct libalias *, struct in_addr _src_addr, 166 struct in_addr _dst_addr, struct in_addr _alias_addr, 167 unsigned char _proto); 168 169/* Fragment Handling functions. */ 170void LibAliasFragmentIn(struct libalias *, char *_ptr, char *_ptr_fragment); 171char *LibAliasGetFragment(struct libalias *, char *_ptr); 172int LibAliasSaveFragment(struct libalias *, char *_ptr); 173 174/* Miscellaneous functions. */ 175int LibAliasCheckNewLink(struct libalias *); 176unsigned short 177 LibAliasInternetChecksum(struct libalias *, unsigned short *_ptr, int _nbytes); 178void LibAliasSetTarget(struct libalias *, struct in_addr _target_addr); 179 180/* Transparent proxying routines. */ 181int LibAliasProxyRule(struct libalias *, const char *_cmd); 182 183 184/* 185 * Mode flags and other constants. 186 */ 187 188 189/* Mode flags, set using PacketAliasSetMode() */ 190 191/* 192 * If PKT_ALIAS_LOG is set, a message will be printed to /var/log/alias.log 193 * every time a link is created or deleted. This is useful for debugging. 194 */ 195#ifndef NO_LOGGING 196#define PKT_ALIAS_LOG 0x01 197#endif 198 199/* 200 * If PKT_ALIAS_DENY_INCOMING is set, then incoming connections (e.g. to ftp, 201 * telnet or web servers will be prevented by the aliasing mechanism. 202 */ 203#define PKT_ALIAS_DENY_INCOMING 0x02 204 205/* 206 * If PKT_ALIAS_SAME_PORTS is set, packets will be attempted sent from the 207 * same port as they originated on. This allows e.g. rsh to work *99% of the 208 * time*, but _not_ 100% (it will be slightly flakey instead of not working 209 * at all). This mode bit is set by PacketAliasInit(), so it is a default 210 * mode of operation. 211 */ 212#define PKT_ALIAS_SAME_PORTS 0x04 213 214/* 215 * If PKT_ALIAS_USE_SOCKETS is set, then when partially specified links (e.g. 216 * destination port and/or address is zero), the packet aliasing engine will 217 * attempt to allocate a socket for the aliasing port it chooses. This will 218 * avoid interference with the host machine. Fully specified links do not 219 * require this. This bit is set after a call to PacketAliasInit(), so it is 220 * a default mode of operation. 221 */ 222#ifndef NO_USE_SOCKETS 223#define PKT_ALIAS_USE_SOCKETS 0x08 224#endif 225/*- 226 * If PKT_ALIAS_UNREGISTERED_ONLY is set, then only packets with 227 * unregistered source addresses will be aliased. Private 228 * addresses are those in the following ranges: 229 * 230 * 10.0.0.0 -> 10.255.255.255 231 * 172.16.0.0 -> 172.31.255.255 232 * 192.168.0.0 -> 192.168.255.255 233 */ 234#define PKT_ALIAS_UNREGISTERED_ONLY 0x10 235 236/* 237 * If PKT_ALIAS_RESET_ON_ADDR_CHANGE is set, then the table of dynamic 238 * aliasing links will be reset whenever PacketAliasSetAddress() changes the 239 * default aliasing address. If the default aliasing address is left 240 * unchanged by this function call, then the table of dynamic aliasing links 241 * will be left intact. This bit is set after a call to PacketAliasInit(). 242 */ 243#define PKT_ALIAS_RESET_ON_ADDR_CHANGE 0x20 244 245#ifndef NO_FW_PUNCH 246/* 247 * If PKT_ALIAS_PUNCH_FW is set, active FTP and IRC DCC connections will 248 * create a 'hole' in the firewall to allow the transfers to work. The 249 * ipfw rule number that the hole is created with is controlled by 250 * PacketAliasSetFWBase(). The hole will be attached to that 251 * particular alias_link, so when the link goes away the hole is deleted. 252 */ 253#define PKT_ALIAS_PUNCH_FW 0x100 254#endif 255 256/* 257 * If PKT_ALIAS_PROXY_ONLY is set, then NAT will be disabled and only 258 * transparent proxying is performed. 259 */ 260#define PKT_ALIAS_PROXY_ONLY 0x40 261 262/* 263 * If PKT_ALIAS_REVERSE is set, the actions of PacketAliasIn() and 264 * PacketAliasOut() are reversed. 265 */ 266#define PKT_ALIAS_REVERSE 0x80 267 268/* Function return codes. */ 269#define PKT_ALIAS_ERROR -1 270#define PKT_ALIAS_OK 1 271#define PKT_ALIAS_IGNORED 2 272#define PKT_ALIAS_UNRESOLVED_FRAGMENT 3 273#define PKT_ALIAS_FOUND_HEADER_FRAGMENT 4 274 275#endif /* !_ALIAS_H_ */ 276 277/* lint -restore */ 278