alias.h revision 120372
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 120372 2003-09-23 07:41:55Z marcus $ 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 4274778Sbrian/* The external interface to libalias, the packet aliasing engine. */ 4326026Sbrian 4474778Sbrian/* Initialization and control functions. */ 4574778Sbrianvoid PacketAliasInit(void); 4674778Sbrianvoid PacketAliasSetAddress(struct in_addr _addr); 4774778Sbrianvoid PacketAliasSetFWBase(unsigned int _base, unsigned int _num); 48120372Smarcusvoid PacketAliasSetSkinnyPort(unsigned int _port); 4974778Sbrianunsigned int 5074778Sbrian PacketAliasSetMode(unsigned int _flags, unsigned int _mask); 5174778Sbrianvoid PacketAliasUninit(void); 5227864Sbrian 5374778Sbrian/* Packet Handling functions. */ 5474778Sbrianint PacketAliasIn(char *_ptr, int _maxpacketsize); 5574778Sbrianint PacketAliasOut(char *_ptr, int _maxpacketsize); 5674778Sbrianint PacketUnaliasOut(char *_ptr, int _maxpacketsize); 5727864Sbrian 5874778Sbrian/* Port and address redirection functions. */ 5932377Seivind 6074778Sbrian/* 6174778Sbrian * An anonymous structure, a pointer to which is returned from 6274778Sbrian * PacketAliasRedirectAddr(), PacketAliasRedirectPort() or 6374778Sbrian * PacketAliasRedirectProto(), passed to PacketAliasAddServer(), 6474778Sbrian * and freed by PacketAliasRedirectDelete(). 6574778Sbrian */ 6674778Sbrianstruct alias_link; 6727864Sbrian 6874778Sbrianint PacketAliasAddServer(struct alias_link *_link, 6974778Sbrian struct in_addr _addr, unsigned short _port); 7074778Sbrianstruct alias_link * 7174778Sbrian PacketAliasRedirectAddr(struct in_addr _src_addr, 7274778Sbrian struct in_addr _alias_addr); 73115650Sruint PacketAliasRedirectDynamic(struct alias_link *_link); 7474778Sbrianvoid PacketAliasRedirectDelete(struct alias_link *_link); 7574778Sbrianstruct alias_link * 7674778Sbrian PacketAliasRedirectPort(struct in_addr _src_addr, 7774778Sbrian unsigned short _src_port, struct in_addr _dst_addr, 7874778Sbrian unsigned short _dst_port, struct in_addr _alias_addr, 7974778Sbrian unsigned short _alias_port, unsigned char _proto); 8074778Sbrianstruct alias_link * 8174778Sbrian PacketAliasRedirectProto(struct in_addr _src_addr, 8274778Sbrian struct in_addr _dst_addr, struct in_addr _alias_addr, 8374778Sbrian unsigned char _proto); 8427864Sbrian 8574778Sbrian/* Fragment Handling functions. */ 8674778Sbrianvoid PacketAliasFragmentIn(char *_ptr, char *_ptr_fragment); 8774778Sbrianchar *PacketAliasGetFragment(char *_ptr); 8874778Sbrianint PacketAliasSaveFragment(char *_ptr); 8932377Seivind 9074778Sbrian/* Miscellaneous functions. */ 9174778Sbrianint PacketAliasCheckNewLink(void); 9274778Sbrianunsigned short 9374778Sbrian PacketAliasInternetChecksum(unsigned short *_ptr, int _nbytes); 9474778Sbrianvoid PacketAliasSetTarget(struct in_addr _target_addr); 9527864Sbrian 9674778Sbrian/* Transparent proxying routines. */ 9774778Sbrianint PacketAliasProxyRule(const char *_cmd); 9827864Sbrian 9974778Sbrian/* Mode flags, set using PacketAliasSetMode() */ 10063899Sarchie 10174778Sbrian/* 10274778Sbrian * If PKT_ALIAS_LOG is set, a message will be printed to /var/log/alias.log 10374778Sbrian * every time a link is created or deleted. This is useful for debugging. 10474778Sbrian */ 10574778Sbrian#define PKT_ALIAS_LOG 0x01 10627864Sbrian 10774778Sbrian/* 10874778Sbrian * If PKT_ALIAS_DENY_INCOMING is set, then incoming connections (e.g. to ftp, 10974778Sbrian * telnet or web servers will be prevented by the aliasing mechanism. 11074778Sbrian */ 11174778Sbrian#define PKT_ALIAS_DENY_INCOMING 0x02 11259702Sru 11374778Sbrian/* 11474778Sbrian * If PKT_ALIAS_SAME_PORTS is set, packets will be attempted sent from the 11574778Sbrian * same port as they originated on. This allows e.g. rsh to work *99% of the 11674778Sbrian * time*, but _not_ 100% (it will be slightly flakey instead of not working 11774778Sbrian * at all). This mode bit is set by PacketAliasInit(), so it is a default 11874778Sbrian * mode of operation. 11974778Sbrian */ 12074778Sbrian#define PKT_ALIAS_SAME_PORTS 0x04 12144307Sbrian 12274778Sbrian/* 12374778Sbrian * If PKT_ALIAS_USE_SOCKETS is set, then when partially specified links (e.g. 12474778Sbrian * destination port and/or address is zero), the packet aliasing engine will 12574778Sbrian * attempt to allocate a socket for the aliasing port it chooses. This will 12674778Sbrian * avoid interference with the host machine. Fully specified links do not 12774778Sbrian * require this. This bit is set after a call to PacketAliasInit(), so it is 12874778Sbrian * a default mode of operation. 12974778Sbrian */ 13074778Sbrian#define PKT_ALIAS_USE_SOCKETS 0x08 13127864Sbrian 13274778Sbrian/*- 13374778Sbrian * If PKT_ALIAS_UNREGISTERED_ONLY is set, then only packets with 13474778Sbrian * unregistered source addresses will be aliased. Private 13574778Sbrian * addresses are those in the following ranges: 13674778Sbrian * 13774778Sbrian * 10.0.0.0 -> 10.255.255.255 13874778Sbrian * 172.16.0.0 -> 172.31.255.255 13974778Sbrian * 192.168.0.0 -> 192.168.255.255 14074778Sbrian */ 14174778Sbrian#define PKT_ALIAS_UNREGISTERED_ONLY 0x10 14227864Sbrian 14374778Sbrian/* 14474778Sbrian * If PKT_ALIAS_RESET_ON_ADDR_CHANGE is set, then the table of dynamic 14574778Sbrian * aliasing links will be reset whenever PacketAliasSetAddress() changes the 14674778Sbrian * default aliasing address. If the default aliasing address is left 14774778Sbrian * unchanged by this function call, then the table of dynamic aliasing links 14874778Sbrian * will be left intact. This bit is set after a call to PacketAliasInit(). 14974778Sbrian */ 15074778Sbrian#define PKT_ALIAS_RESET_ON_ADDR_CHANGE 0x20 15127864Sbrian 15235314Sbrian#ifndef NO_FW_PUNCH 15374778Sbrian/* 15474778Sbrian * If PKT_ALIAS_PUNCH_FW is set, active FTP and IRC DCC connections will 15574778Sbrian * create a 'hole' in the firewall to allow the transfers to work. The 15674778Sbrian * ipfw rule number that the hole is created with is controlled by 15774778Sbrian * PacketAliasSetFWBase(). The hole will be attached to that 15874778Sbrian * particular alias_link, so when the link goes away the hole is deleted. 15974778Sbrian */ 16074778Sbrian#define PKT_ALIAS_PUNCH_FW 0x100 16135314Sbrian#endif 16232377Seivind 16374778Sbrian/* 16474778Sbrian * If PKT_ALIAS_PROXY_ONLY is set, then NAT will be disabled and only 16574778Sbrian * transparent proxying is performed. 16674778Sbrian */ 16774778Sbrian#define PKT_ALIAS_PROXY_ONLY 0x40 16844307Sbrian 16974778Sbrian/* 17074778Sbrian * If PKT_ALIAS_REVERSE is set, the actions of PacketAliasIn() and 17174778Sbrian * PacketAliasOut() are reversed. 17274778Sbrian */ 17374778Sbrian#define PKT_ALIAS_REVERSE 0x80 17444307Sbrian 17574778Sbrian/* Function return codes. */ 17674778Sbrian#define PKT_ALIAS_ERROR -1 17774778Sbrian#define PKT_ALIAS_OK 1 17874778Sbrian#define PKT_ALIAS_IGNORED 2 17974778Sbrian#define PKT_ALIAS_UNRESOLVED_FRAGMENT 3 18074778Sbrian#define PKT_ALIAS_FOUND_HEADER_FRAGMENT 4 18126026Sbrian 18274778Sbrian#endif /* !_ALIAS_H_ */ 18374778Sbrian 18474778Sbrian/* lint -restore */ 185