alias.h revision 145931
174778Sbrian/* lint -save -library Flexelint comment for external headers */ 226026Sbrian 374778Sbrian/*- 485964Sbrian * Copyright (c) 2001 Charles Mott <cm@linktel.net> 577701Sbrian * All rights reserved. 677701Sbrian * 777701Sbrian * Redistribution and use in source and binary forms, with or without 877701Sbrian * modification, are permitted provided that the following conditions 977701Sbrian * are met: 1077701Sbrian * 1. Redistributions of source code must retain the above copyright 1177701Sbrian * notice, this list of conditions and the following disclaimer. 1277701Sbrian * 2. Redistributions in binary form must reproduce the above copyright 1377701Sbrian * notice, this list of conditions and the following disclaimer in the 1477701Sbrian * documentation and/or other materials provided with the distribution. 1577701Sbrian * 1677701Sbrian * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1777701Sbrian * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1877701Sbrian * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1977701Sbrian * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2077701Sbrian * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2177701Sbrian * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2277701Sbrian * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2377701Sbrian * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2477701Sbrian * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2577701Sbrian * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2677701Sbrian * SUCH DAMAGE. 2777701Sbrian * 2877701Sbrian * $FreeBSD: head/sys/netinet/libalias/alias.h 145931 2005-05-05 21:53:17Z glebius $ 2977701Sbrian */ 3077701Sbrian 3177701Sbrian/*- 3274778Sbrian * Alias.h defines the outside world interfaces for the packet aliasing 3374778Sbrian * software. 3499207Sbrian * 3574778Sbrian * This software is placed into the public domain with no restrictions on its 3674778Sbrian * distribution. 3774778Sbrian */ 3826026Sbrian 3926026Sbrian#ifndef _ALIAS_H_ 4074778Sbrian#define _ALIAS_H_ 4126026Sbrian 42145931Sglebius#ifdef _KERNEL 43124621Sphk/* 44145931Sglebius * The kernel version of libalias does not support these features. 45145931Sglebius */ 46145931Sglebius#define NO_FW_PUNCH 47145931Sglebius#define NO_LOGGING 48145931Sglebius#define NO_USE_SOCKETS 49145931Sglebius#endif 50145931Sglebius 51145931Sglebius/* 52124621Sphk * The external interface to libalias, the packet aliasing engine. 53124621Sphk * 54124621Sphk * There are two sets of functions: 55124621Sphk * 56124621Sphk * PacketAlias*() the old API which doesn't take an instance pointer 57124621Sphk * and therefore can only have one packet engine at a time. 58124621Sphk * 59127094Sdes * LibAlias*() the new API which takes as first argument a pointer to 60124621Sphk * the instance of the packet aliasing engine. 61124621Sphk * 62124621Sphk * The functions otherwise correspond to each other one for one, except 63127094Sdes * for the LibAliasUnaliasOut()/PacketUnaliasOut() function which were 64124621Sphk * were misnamed in the old API. 65124621Sphk */ 6626026Sbrian 67124621Sphk/* 68124621Sphk * The instance structure 69124621Sphk */ 70124621Sphkstruct libalias; 71124621Sphk 72124621Sphk/* 73124621Sphk * An anonymous structure, a pointer to which is returned from 74124621Sphk * PacketAliasRedirectAddr(), PacketAliasRedirectPort() or 75124621Sphk * PacketAliasRedirectProto(), passed to PacketAliasAddServer(), 76124621Sphk * and freed by PacketAliasRedirectDelete(). 77124621Sphk */ 78127094Sdesstruct alias_link; 79124621Sphk 80124621Sphk 81124621Sphk/* OLD API */ 82124621Sphk 8374778Sbrian/* Initialization and control functions. */ 84127094Sdesvoid PacketAliasInit(void); 85127094Sdesvoid PacketAliasSetAddress(struct in_addr _addr); 86127094Sdesvoid PacketAliasSetFWBase(unsigned int _base, unsigned int _num); 87127094Sdesvoid PacketAliasSetSkinnyPort(unsigned int _port); 8874778Sbrianunsigned int 89127094Sdes PacketAliasSetMode(unsigned int _flags, unsigned int _mask); 90127094Sdesvoid PacketAliasUninit(void); 9127864Sbrian 9274778Sbrian/* Packet Handling functions. */ 93127094Sdesint PacketAliasIn(char *_ptr, int _maxpacketsize); 94127094Sdesint PacketAliasOut(char *_ptr, int _maxpacketsize); 95127094Sdesint PacketUnaliasOut(char *_ptr, int _maxpacketsize); 9627864Sbrian 9774778Sbrian/* Port and address redirection functions. */ 9832377Seivind 9927864Sbrian 100127094Sdesint 101131614SdesPacketAliasAddServer(struct alias_link *_lnk, 102127094Sdes struct in_addr _addr, unsigned short _port); 10374778Sbrianstruct alias_link * 104127094SdesPacketAliasRedirectAddr(struct in_addr _src_addr, 105127094Sdes struct in_addr _alias_addr); 106131614Sdesint PacketAliasRedirectDynamic(struct alias_link *_lnk); 107131614Sdesvoid PacketAliasRedirectDelete(struct alias_link *_lnk); 10874778Sbrianstruct alias_link * 109127094SdesPacketAliasRedirectPort(struct in_addr _src_addr, 110127094Sdes unsigned short _src_port, struct in_addr _dst_addr, 111127094Sdes unsigned short _dst_port, struct in_addr _alias_addr, 112127094Sdes unsigned short _alias_port, unsigned char _proto); 11374778Sbrianstruct alias_link * 114127094SdesPacketAliasRedirectProto(struct in_addr _src_addr, 115127094Sdes struct in_addr _dst_addr, struct in_addr _alias_addr, 116127094Sdes unsigned char _proto); 11727864Sbrian 11874778Sbrian/* Fragment Handling functions. */ 119127094Sdesvoid PacketAliasFragmentIn(char *_ptr, char *_ptr_fragment); 120127094Sdeschar *PacketAliasGetFragment(char *_ptr); 121127094Sdesint PacketAliasSaveFragment(char *_ptr); 12232377Seivind 12374778Sbrian/* Miscellaneous functions. */ 124127094Sdesint PacketAliasCheckNewLink(void); 12574778Sbrianunsigned short 126127094Sdes PacketAliasInternetChecksum(unsigned short *_ptr, int _nbytes); 127127094Sdesvoid PacketAliasSetTarget(struct in_addr _target_addr); 12827864Sbrian 12974778Sbrian/* Transparent proxying routines. */ 130127094Sdesint PacketAliasProxyRule(const char *_cmd); 13127864Sbrian 132124621Sphk/* NEW API */ 133124621Sphk 134124621Sphk/* Initialization and control functions. */ 135127094Sdesstruct libalias *LibAliasInit(struct libalias *); 136127094Sdesvoid LibAliasSetAddress(struct libalias *, struct in_addr _addr); 137127094Sdesvoid LibAliasSetFWBase(struct libalias *, unsigned int _base, unsigned int _num); 138127094Sdesvoid LibAliasSetSkinnyPort(struct libalias *, unsigned int _port); 139124621Sphkunsigned int 140127094Sdes LibAliasSetMode(struct libalias *, unsigned int _flags, unsigned int _mask); 141127094Sdesvoid LibAliasUninit(struct libalias *); 142124621Sphk 143124621Sphk/* Packet Handling functions. */ 144127094Sdesint LibAliasIn (struct libalias *, char *_ptr, int _maxpacketsize); 145127094Sdesint LibAliasOut(struct libalias *, char *_ptr, int _maxpacketsize); 146131566Sphkint LibAliasOutTry(struct libalias *, char *_ptr, int _maxpacketsize, int _create); 147127094Sdesint LibAliasUnaliasOut(struct libalias *, char *_ptr, int _maxpacketsize); 148124621Sphk 149124621Sphk/* Port and address redirection functions. */ 150124621Sphk 151127094Sdesint 152131614SdesLibAliasAddServer(struct libalias *, struct alias_link *_lnk, 153127094Sdes struct in_addr _addr, unsigned short _port); 154124621Sphkstruct alias_link * 155127094SdesLibAliasRedirectAddr(struct libalias *, struct in_addr _src_addr, 156127094Sdes struct in_addr _alias_addr); 157131614Sdesint LibAliasRedirectDynamic(struct libalias *, struct alias_link *_lnk); 158131614Sdesvoid LibAliasRedirectDelete(struct libalias *, struct alias_link *_lnk); 159124621Sphkstruct alias_link * 160127094SdesLibAliasRedirectPort(struct libalias *, struct in_addr _src_addr, 161127094Sdes unsigned short _src_port, struct in_addr _dst_addr, 162127094Sdes unsigned short _dst_port, struct in_addr _alias_addr, 163127094Sdes unsigned short _alias_port, unsigned char _proto); 164124621Sphkstruct alias_link * 165127094SdesLibAliasRedirectProto(struct libalias *, struct in_addr _src_addr, 166127094Sdes struct in_addr _dst_addr, struct in_addr _alias_addr, 167127094Sdes unsigned char _proto); 168124621Sphk 169124621Sphk/* Fragment Handling functions. */ 170127094Sdesvoid LibAliasFragmentIn(struct libalias *, char *_ptr, char *_ptr_fragment); 171127094Sdeschar *LibAliasGetFragment(struct libalias *, char *_ptr); 172127094Sdesint LibAliasSaveFragment(struct libalias *, char *_ptr); 173124621Sphk 174124621Sphk/* Miscellaneous functions. */ 175127094Sdesint LibAliasCheckNewLink(struct libalias *); 176124621Sphkunsigned short 177127094Sdes LibAliasInternetChecksum(struct libalias *, unsigned short *_ptr, int _nbytes); 178127094Sdesvoid LibAliasSetTarget(struct libalias *, struct in_addr _target_addr); 179124621Sphk 180124621Sphk/* Transparent proxying routines. */ 181127094Sdesint LibAliasProxyRule(struct libalias *, const char *_cmd); 182124621Sphk 183124621Sphk 184124621Sphk/* 185124621Sphk * Mode flags and other constants. 186124621Sphk */ 187124621Sphk 188124621Sphk 18974778Sbrian/* Mode flags, set using PacketAliasSetMode() */ 19063899Sarchie 19174778Sbrian/* 19274778Sbrian * If PKT_ALIAS_LOG is set, a message will be printed to /var/log/alias.log 19374778Sbrian * every time a link is created or deleted. This is useful for debugging. 19474778Sbrian */ 195145925Sglebius#ifndef NO_LOGGING 19674778Sbrian#define PKT_ALIAS_LOG 0x01 197145925Sglebius#endif 19827864Sbrian 19974778Sbrian/* 20074778Sbrian * If PKT_ALIAS_DENY_INCOMING is set, then incoming connections (e.g. to ftp, 20174778Sbrian * telnet or web servers will be prevented by the aliasing mechanism. 20274778Sbrian */ 20374778Sbrian#define PKT_ALIAS_DENY_INCOMING 0x02 20459702Sru 20574778Sbrian/* 20674778Sbrian * If PKT_ALIAS_SAME_PORTS is set, packets will be attempted sent from the 20774778Sbrian * same port as they originated on. This allows e.g. rsh to work *99% of the 20874778Sbrian * time*, but _not_ 100% (it will be slightly flakey instead of not working 20974778Sbrian * at all). This mode bit is set by PacketAliasInit(), so it is a default 21074778Sbrian * mode of operation. 21174778Sbrian */ 21274778Sbrian#define PKT_ALIAS_SAME_PORTS 0x04 21344307Sbrian 21474778Sbrian/* 21574778Sbrian * If PKT_ALIAS_USE_SOCKETS is set, then when partially specified links (e.g. 21674778Sbrian * destination port and/or address is zero), the packet aliasing engine will 21774778Sbrian * attempt to allocate a socket for the aliasing port it chooses. This will 21874778Sbrian * avoid interference with the host machine. Fully specified links do not 21974778Sbrian * require this. This bit is set after a call to PacketAliasInit(), so it is 22074778Sbrian * a default mode of operation. 22174778Sbrian */ 222145926Sglebius#ifndef NO_USE_SOCKETS 22374778Sbrian#define PKT_ALIAS_USE_SOCKETS 0x08 224145926Sglebius#endif 22574778Sbrian/*- 22674778Sbrian * If PKT_ALIAS_UNREGISTERED_ONLY is set, then only packets with 22774778Sbrian * unregistered source addresses will be aliased. Private 22874778Sbrian * addresses are those in the following ranges: 22974778Sbrian * 23074778Sbrian * 10.0.0.0 -> 10.255.255.255 23174778Sbrian * 172.16.0.0 -> 172.31.255.255 23274778Sbrian * 192.168.0.0 -> 192.168.255.255 23374778Sbrian */ 23474778Sbrian#define PKT_ALIAS_UNREGISTERED_ONLY 0x10 23527864Sbrian 23674778Sbrian/* 23774778Sbrian * If PKT_ALIAS_RESET_ON_ADDR_CHANGE is set, then the table of dynamic 23874778Sbrian * aliasing links will be reset whenever PacketAliasSetAddress() changes the 23974778Sbrian * default aliasing address. If the default aliasing address is left 24074778Sbrian * unchanged by this function call, then the table of dynamic aliasing links 24174778Sbrian * will be left intact. This bit is set after a call to PacketAliasInit(). 24274778Sbrian */ 24374778Sbrian#define PKT_ALIAS_RESET_ON_ADDR_CHANGE 0x20 24427864Sbrian 24535314Sbrian#ifndef NO_FW_PUNCH 24674778Sbrian/* 24774778Sbrian * If PKT_ALIAS_PUNCH_FW is set, active FTP and IRC DCC connections will 24874778Sbrian * create a 'hole' in the firewall to allow the transfers to work. The 24974778Sbrian * ipfw rule number that the hole is created with is controlled by 25074778Sbrian * PacketAliasSetFWBase(). The hole will be attached to that 25174778Sbrian * particular alias_link, so when the link goes away the hole is deleted. 25274778Sbrian */ 25374778Sbrian#define PKT_ALIAS_PUNCH_FW 0x100 25435314Sbrian#endif 25532377Seivind 25674778Sbrian/* 25774778Sbrian * If PKT_ALIAS_PROXY_ONLY is set, then NAT will be disabled and only 25874778Sbrian * transparent proxying is performed. 25974778Sbrian */ 26074778Sbrian#define PKT_ALIAS_PROXY_ONLY 0x40 26144307Sbrian 26274778Sbrian/* 26374778Sbrian * If PKT_ALIAS_REVERSE is set, the actions of PacketAliasIn() and 26474778Sbrian * PacketAliasOut() are reversed. 26574778Sbrian */ 26674778Sbrian#define PKT_ALIAS_REVERSE 0x80 26744307Sbrian 26874778Sbrian/* Function return codes. */ 26974778Sbrian#define PKT_ALIAS_ERROR -1 27074778Sbrian#define PKT_ALIAS_OK 1 27174778Sbrian#define PKT_ALIAS_IGNORED 2 27274778Sbrian#define PKT_ALIAS_UNRESOLVED_FRAGMENT 3 27374778Sbrian#define PKT_ALIAS_FOUND_HEADER_FRAGMENT 4 27426026Sbrian 275127094Sdes#endif /* !_ALIAS_H_ */ 27674778Sbrian 27774778Sbrian/* lint -restore */ 278