alias.h revision 267654
1155408Srwatson/* lint -save -library Flexelint comment for external headers */ 2155408Srwatson 3184488Srwatson/*- 4155408Srwatson * Copyright (c) 2001 Charles Mott <cm@linktel.net> 5155408Srwatson * All rights reserved. 6155408Srwatson * 7155408Srwatson * Redistribution and use in source and binary forms, with or without 8155408Srwatson * modification, are permitted provided that the following conditions 9155408Srwatson * are met: 10155408Srwatson * 1. Redistributions of source code must retain the above copyright 11155408Srwatson * notice, this list of conditions and the following disclaimer. 12155408Srwatson * 2. Redistributions in binary form must reproduce the above copyright 13155408Srwatson * notice, this list of conditions and the following disclaimer in the 14155408Srwatson * documentation and/or other materials provided with the distribution. 15155408Srwatson * 16155408Srwatson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17155408Srwatson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18155408Srwatson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19155408Srwatson * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20155408Srwatson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21155408Srwatson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22155408Srwatson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23155408Srwatson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24155408Srwatson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25155408Srwatson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26155408Srwatson * SUCH DAMAGE. 27155408Srwatson * 28155408Srwatson * $FreeBSD: releng/9.3/sys/netinet/libalias/alias.h 223080 2011-06-14 13:35:24Z ae $ 29155408Srwatson */ 30178186Srwatson 31178186Srwatson/* 32178186Srwatson * Alias.h defines the outside world interfaces for the packet aliasing 33155408Srwatson * software. 34155408Srwatson * 35155408Srwatson * This software is placed into the public domain with no restrictions on its 36155408Srwatson * distribution. 37155408Srwatson */ 38155408Srwatson 39155408Srwatson#ifndef _ALIAS_H_ 40155408Srwatson#define _ALIAS_H_ 41155408Srwatson 42155408Srwatson#include <netinet/in_systm.h> 43155408Srwatson#include <netinet/in.h> 44155408Srwatson#include <netinet/ip.h> 45184488Srwatson 46155408Srwatson#define LIBALIAS_BUF_SIZE 128 47155408Srwatson#ifdef _KERNEL 48155408Srwatson/* 49155408Srwatson * The kernel version of libalias does not support these features. 50184508Srwatson */ 51155408Srwatson#define NO_FW_PUNCH 52155408Srwatson#define NO_USE_SOCKETS 53155408Srwatson#endif 54155408Srwatson 55156880Srwatson/* 56155408Srwatson * The external interface to libalias, the packet aliasing engine. 57155408Srwatson * 58155408Srwatson * There are two sets of functions: 59155408Srwatson * 60155408Srwatson * PacketAlias*() the old API which doesn't take an instance pointer 61155408Srwatson * and therefore can only have one packet engine at a time. 62159269Srwatson * 63159269Srwatson * LibAlias*() the new API which takes as first argument a pointer to 64155408Srwatson * the instance of the packet aliasing engine. 65155408Srwatson * 66155408Srwatson * The functions otherwise correspond to each other one for one, except 67155408Srwatson * for the LibAliasUnaliasOut()/PacketUnaliasOut() function which were 68155408Srwatson * were misnamed in the old API. 69155408Srwatson */ 70155408Srwatson 71155408Srwatson/* 72174894Swkoszek * The instance structure 73159269Srwatson */ 74155408Srwatsonstruct libalias; 75155408Srwatson 76155408Srwatson/* 77155408Srwatson * An anonymous structure, a pointer to which is returned from 78156883Srwatson * PacketAliasRedirectAddr(), PacketAliasRedirectPort() or 79156880Srwatson * PacketAliasRedirectProto(), passed to PacketAliasAddServer(), 80155408Srwatson * and freed by PacketAliasRedirectDelete(). 81155408Srwatson */ 82155408Srwatsonstruct alias_link; 83155408Srwatson 84155408Srwatson/* Initialization and control functions. */ 85155408Srwatsonstruct libalias *LibAliasInit(struct libalias *); 86155408Srwatsonvoid LibAliasSetAddress(struct libalias *, struct in_addr _addr); 87155408Srwatsonvoid LibAliasSetFWBase(struct libalias *, unsigned int _base, unsigned int _num); 88155408Srwatsonvoid LibAliasSetSkinnyPort(struct libalias *, unsigned int _port); 89155408Srwatsonunsigned int 90155408Srwatson LibAliasSetMode(struct libalias *, unsigned int _flags, unsigned int _mask); 91155408Srwatsonvoid LibAliasUninit(struct libalias *); 92159269Srwatson 93159269Srwatson/* Packet Handling functions. */ 94159269Srwatsonint LibAliasIn (struct libalias *, char *_ptr, int _maxpacketsize); 95159269Srwatsonint LibAliasOut(struct libalias *, char *_ptr, int _maxpacketsize); 96159269Srwatsonint LibAliasOutTry(struct libalias *, char *_ptr, int _maxpacketsize, int _create); 97159269Srwatsonint LibAliasUnaliasOut(struct libalias *, char *_ptr, int _maxpacketsize); 98159269Srwatson 99159269Srwatson/* Port and address redirection functions. */ 100159269Srwatson 101159269Srwatsonint 102159269SrwatsonLibAliasAddServer(struct libalias *, struct alias_link *_lnk, 103159269Srwatson struct in_addr _addr, unsigned short _port); 104159269Srwatsonstruct alias_link * 105159269SrwatsonLibAliasRedirectAddr(struct libalias *, struct in_addr _src_addr, 106159269Srwatson struct in_addr _alias_addr); 107159269Srwatsonint LibAliasRedirectDynamic(struct libalias *, struct alias_link *_lnk); 108159269Srwatsonvoid LibAliasRedirectDelete(struct libalias *, struct alias_link *_lnk); 109155408Srwatsonstruct alias_link * 110155408SrwatsonLibAliasRedirectPort(struct libalias *, struct in_addr _src_addr, 111155408Srwatson unsigned short _src_port, struct in_addr _dst_addr, 112155408Srwatson unsigned short _dst_port, struct in_addr _alias_addr, 113155408Srwatson unsigned short _alias_port, unsigned char _proto); 114155408Srwatsonstruct alias_link * 115155408SrwatsonLibAliasRedirectProto(struct libalias *, struct in_addr _src_addr, 116155408Srwatson struct in_addr _dst_addr, struct in_addr _alias_addr, 117155408Srwatson unsigned char _proto); 118155408Srwatson 119155408Srwatson/* Fragment Handling functions. */ 120155408Srwatsonvoid LibAliasFragmentIn(struct libalias *, char *_ptr, char *_ptr_fragment); 121184488Srwatsonchar *LibAliasGetFragment(struct libalias *, char *_ptr); 122184488Srwatsonint LibAliasSaveFragment(struct libalias *, char *_ptr); 123184488Srwatson 124184508Srwatson/* Miscellaneous functions. */ 125184488Srwatsonint LibAliasCheckNewLink(struct libalias *); 126184488Srwatsonunsigned short 127184508Srwatson LibAliasInternetChecksum(struct libalias *, unsigned short *_ptr, int _nbytes); 128184508Srwatsonvoid LibAliasSetTarget(struct libalias *, struct in_addr _target_addr); 129184508Srwatson 130184508Srwatson/* Transparent proxying routines. */ 131184508Srwatsonint LibAliasProxyRule(struct libalias *, const char *_cmd); 132184508Srwatson 133184508Srwatson/* Module handling API */ 134184508Srwatsonint LibAliasLoadModule(char *); 135184488Srwatsonint LibAliasUnLoadAllModule(void); 136184488Srwatsonint LibAliasRefreshModules(void); 137184488Srwatson 138184488Srwatson/* Mbuf helper function. */ 139184488Srwatsonstruct mbuf *m_megapullup(struct mbuf *, int); 140184536Srwatson 141184536Srwatson/* 142184536Srwatson * Mode flags and other constants. 143184536Srwatson */ 144184536Srwatson 145184536Srwatson 146184536Srwatson/* Mode flags, set using PacketAliasSetMode() */ 147155408Srwatson 148155408Srwatson/* 149184536Srwatson * If PKT_ALIAS_LOG is set, a message will be printed to /var/log/alias.log 150184536Srwatson * every time a link is created or deleted. This is useful for debugging. 151155408Srwatson */ 152155408Srwatson#define PKT_ALIAS_LOG 0x01 153155408Srwatson 154155408Srwatson/* 155155408Srwatson * If PKT_ALIAS_DENY_INCOMING is set, then incoming connections (e.g. to ftp, 156159269Srwatson * telnet or web servers will be prevented by the aliasing mechanism. 157159269Srwatson */ 158159269Srwatson#define PKT_ALIAS_DENY_INCOMING 0x02 159159269Srwatson 160159269Srwatson/* 161159269Srwatson * If PKT_ALIAS_SAME_PORTS is set, packets will be attempted sent from the 162159269Srwatson * same port as they originated on. This allows e.g. rsh to work *99% of the 163159269Srwatson * time*, but _not_ 100% (it will be slightly flakey instead of not working 164159269Srwatson * at all). This mode bit is set by PacketAliasInit(), so it is a default 165159269Srwatson * mode of operation. 166159269Srwatson */ 167184508Srwatson#define PKT_ALIAS_SAME_PORTS 0x04 168184508Srwatson 169184508Srwatson/* 170159269Srwatson * If PKT_ALIAS_USE_SOCKETS is set, then when partially specified links (e.g. 171155408Srwatson * destination port and/or address is zero), the packet aliasing engine will 172155408Srwatson * attempt to allocate a socket for the aliasing port it chooses. This will 173159269Srwatson * avoid interference with the host machine. Fully specified links do not 174159269Srwatson * require this. This bit is set after a call to PacketAliasInit(), so it is 175159269Srwatson * a default mode of operation. 176155408Srwatson */ 177155408Srwatson#ifndef NO_USE_SOCKETS 178155408Srwatson#define PKT_ALIAS_USE_SOCKETS 0x08 179184508Srwatson#endif 180184508Srwatson/*- 181184508Srwatson * If PKT_ALIAS_UNREGISTERED_ONLY is set, then only packets with 182184508Srwatson * unregistered source addresses will be aliased. Private 183184508Srwatson * addresses are those in the following ranges: 184184508Srwatson * 185184508Srwatson * 10.0.0.0 -> 10.255.255.255 186184488Srwatson * 172.16.0.0 -> 172.31.255.255 187184508Srwatson * 192.168.0.0 -> 192.168.255.255 188184508Srwatson */ 189184508Srwatson#define PKT_ALIAS_UNREGISTERED_ONLY 0x10 190184508Srwatson 191184508Srwatson/* 192184508Srwatson * If PKT_ALIAS_RESET_ON_ADDR_CHANGE is set, then the table of dynamic 193155408Srwatson * aliasing links will be reset whenever PacketAliasSetAddress() changes the 194184488Srwatson * default aliasing address. If the default aliasing address is left 195184488Srwatson * unchanged by this function call, then the table of dynamic aliasing links 196184488Srwatson * will be left intact. This bit is set after a call to PacketAliasInit(). 197184488Srwatson */ 198155408Srwatson#define PKT_ALIAS_RESET_ON_ADDR_CHANGE 0x20 199155408Srwatson 200184488Srwatson/* 201155408Srwatson * If PKT_ALIAS_PROXY_ONLY is set, then NAT will be disabled and only 202184488Srwatson * transparent proxying is performed. 203184488Srwatson */ 204184488Srwatson#define PKT_ALIAS_PROXY_ONLY 0x40 205184488Srwatson 206184488Srwatson/* 207184488Srwatson * If PKT_ALIAS_REVERSE is set, the actions of PacketAliasIn() and 208184488Srwatson * PacketAliasOut() are reversed. 209184488Srwatson */ 210155408Srwatson#define PKT_ALIAS_REVERSE 0x80 211155408Srwatson 212155408Srwatson#ifndef NO_FW_PUNCH 213155408Srwatson/* 214155408Srwatson * If PKT_ALIAS_PUNCH_FW is set, active FTP and IRC DCC connections will 215155408Srwatson * create a 'hole' in the firewall to allow the transfers to work. The 216155408Srwatson * ipfw rule number that the hole is created with is controlled by 217155408Srwatson * PacketAliasSetFWBase(). The hole will be attached to that 218155408Srwatson * particular alias_link, so when the link goes away the hole is deleted. 219155408Srwatson */ 220155408Srwatson#define PKT_ALIAS_PUNCH_FW 0x100 221155408Srwatson#endif 222155408Srwatson 223155408Srwatson/* 224155408Srwatson * If PKT_ALIAS_SKIP_GLOBAL is set, nat instance is not checked for matching 225155408Srwatson * states in 'ipfw nat global' rule. 226161582Srwatson */ 227155408Srwatson#define PKT_ALIAS_SKIP_GLOBAL 0x200 228155408Srwatson 229155408Srwatson/* Function return codes. */ 230179726Sed#define PKT_ALIAS_ERROR -1 231155408Srwatson#define PKT_ALIAS_OK 1 232155408Srwatson#define PKT_ALIAS_IGNORED 2 233155408Srwatson#define PKT_ALIAS_UNRESOLVED_FRAGMENT 3 234155408Srwatson#define PKT_ALIAS_FOUND_HEADER_FRAGMENT 4 235155408Srwatson 236161582Srwatson#endif /* !_ALIAS_H_ */ 237155408Srwatson 238155408Srwatson/* lint -restore */ 239155408Srwatson