alias.h revision 6de922ee8158732706074aacb20c2a5dc6d4d7a3
af062818b47340eef15700d2f0211576ba3506eevboxsync/* lint -save -library Flexelint comment for external headers */
af062818b47340eef15700d2f0211576ba3506eevboxsync * Copyright (c) 2001 Charles Mott <cm@linktel.net>
af062818b47340eef15700d2f0211576ba3506eevboxsync * All rights reserved.
af062818b47340eef15700d2f0211576ba3506eevboxsync * Redistribution and use in source and binary forms, with or without
af062818b47340eef15700d2f0211576ba3506eevboxsync * modification, are permitted provided that the following conditions
af062818b47340eef15700d2f0211576ba3506eevboxsync * 1. Redistributions of source code must retain the above copyright
af062818b47340eef15700d2f0211576ba3506eevboxsync * notice, this list of conditions and the following disclaimer.
af062818b47340eef15700d2f0211576ba3506eevboxsync * 2. Redistributions in binary form must reproduce the above copyright
af062818b47340eef15700d2f0211576ba3506eevboxsync * notice, this list of conditions and the following disclaimer in the
af062818b47340eef15700d2f0211576ba3506eevboxsync * documentation and/or other materials provided with the distribution.
af062818b47340eef15700d2f0211576ba3506eevboxsync * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
af062818b47340eef15700d2f0211576ba3506eevboxsync * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
af062818b47340eef15700d2f0211576ba3506eevboxsync * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
af062818b47340eef15700d2f0211576ba3506eevboxsync * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
af062818b47340eef15700d2f0211576ba3506eevboxsync * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
b955672b950093ff7416d1269dd4d3b69983bd8fvboxsync * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
b955672b950093ff7416d1269dd4d3b69983bd8fvboxsync * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
b955672b950093ff7416d1269dd4d3b69983bd8fvboxsync * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
b955672b950093ff7416d1269dd4d3b69983bd8fvboxsync * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
b955672b950093ff7416d1269dd4d3b69983bd8fvboxsync * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
b955672b950093ff7416d1269dd4d3b69983bd8fvboxsync * SUCH DAMAGE.
b955672b950093ff7416d1269dd4d3b69983bd8fvboxsync * $FreeBSD: src/sys/netinet/libalias/alias.h,v 1.34.8.1 2009/04/15 03:14:26 kensmith Exp $
af062818b47340eef15700d2f0211576ba3506eevboxsync * Alias.h defines the outside world interfaces for the packet aliasing
af062818b47340eef15700d2f0211576ba3506eevboxsync * software.
af062818b47340eef15700d2f0211576ba3506eevboxsync * This software is placed into the public domain with no restrictions on its
af062818b47340eef15700d2f0211576ba3506eevboxsync * distribution.
af062818b47340eef15700d2f0211576ba3506eevboxsync * The kernel version of libalias does not support these features.
af062818b47340eef15700d2f0211576ba3506eevboxsync * The external interface to libalias, the packet aliasing engine.
af062818b47340eef15700d2f0211576ba3506eevboxsync * There are two sets of functions:
af062818b47340eef15700d2f0211576ba3506eevboxsync * PacketAlias*() the old API which doesn't take an instance pointer
af062818b47340eef15700d2f0211576ba3506eevboxsync * and therefore can only have one packet engine at a time.
af062818b47340eef15700d2f0211576ba3506eevboxsync * LibAlias*() the new API which takes as first argument a pointer to
af062818b47340eef15700d2f0211576ba3506eevboxsync * the instance of the packet aliasing engine.
af062818b47340eef15700d2f0211576ba3506eevboxsync * The functions otherwise correspond to each other one for one, except
af062818b47340eef15700d2f0211576ba3506eevboxsync * for the LibAliasUnaliasOut()/PacketUnaliasOut() function which were
af062818b47340eef15700d2f0211576ba3506eevboxsync * were misnamed in the old API.
af062818b47340eef15700d2f0211576ba3506eevboxsync * The instance structure
af062818b47340eef15700d2f0211576ba3506eevboxsync/* XXX: used only for browsing */
af062818b47340eef15700d2f0211576ba3506eevboxsync * An anonymous structure, a pointer to which is returned from
af062818b47340eef15700d2f0211576ba3506eevboxsync * PacketAliasRedirectAddr(), PacketAliasRedirectPort() or
af062818b47340eef15700d2f0211576ba3506eevboxsync * PacketAliasRedirectProto(), passed to PacketAliasAddServer(),
af062818b47340eef15700d2f0211576ba3506eevboxsync * and freed by PacketAliasRedirectDelete().
af062818b47340eef15700d2f0211576ba3506eevboxsync/* OLD API */
af062818b47340eef15700d2f0211576ba3506eevboxsync/* Initialization and control functions. */
af062818b47340eef15700d2f0211576ba3506eevboxsyncvoid PacketAliasSetFWBase(unsigned int _base, unsigned int _num);
af062818b47340eef15700d2f0211576ba3506eevboxsyncunsigned int
af062818b47340eef15700d2f0211576ba3506eevboxsync PacketAliasSetMode(unsigned int _flags, unsigned int _mask);
af062818b47340eef15700d2f0211576ba3506eevboxsync/* Packet Handling functions. */
af062818b47340eef15700d2f0211576ba3506eevboxsyncint PacketUnaliasOut(char *_ptr, int _maxpacketsize);
af062818b47340eef15700d2f0211576ba3506eevboxsync/* Port and address redirection functions. */
af062818b47340eef15700d2f0211576ba3506eevboxsyncint PacketAliasRedirectDynamic(struct alias_link *_lnk);
af062818b47340eef15700d2f0211576ba3506eevboxsyncvoid PacketAliasRedirectDelete(struct alias_link *_lnk);
af062818b47340eef15700d2f0211576ba3506eevboxsync unsigned short _src_port, struct in_addr _dst_addr,
af062818b47340eef15700d2f0211576ba3506eevboxsync unsigned short _dst_port, struct in_addr _alias_addr,
af062818b47340eef15700d2f0211576ba3506eevboxsync struct in_addr _dst_addr, struct in_addr _alias_addr,
af062818b47340eef15700d2f0211576ba3506eevboxsync unsigned char _proto);
af062818b47340eef15700d2f0211576ba3506eevboxsync/* Fragment Handling functions. */
af062818b47340eef15700d2f0211576ba3506eevboxsyncvoid PacketAliasFragmentIn(char *_ptr, char *_ptr_fragment);
af062818b47340eef15700d2f0211576ba3506eevboxsync/* Miscellaneous functions. */
af062818b47340eef15700d2f0211576ba3506eevboxsyncunsigned short
af062818b47340eef15700d2f0211576ba3506eevboxsync PacketAliasInternetChecksum(unsigned short *_ptr, int _nbytes);
af062818b47340eef15700d2f0211576ba3506eevboxsyncvoid PacketAliasSetTarget(struct in_addr _target_addr);
af062818b47340eef15700d2f0211576ba3506eevboxsync/* Transparent proxying routines. */
af062818b47340eef15700d2f0211576ba3506eevboxsync/* NEW API */
af062818b47340eef15700d2f0211576ba3506eevboxsync/* Initialization and control functions. */
af062818b47340eef15700d2f0211576ba3506eevboxsyncstruct libalias *LibAliasInit(PNATState, struct libalias *);
af062818b47340eef15700d2f0211576ba3506eevboxsyncvoid LibAliasSetAddress(struct libalias *, struct in_addr _addr);
af062818b47340eef15700d2f0211576ba3506eevboxsyncvoid LibAliasSetFWBase(struct libalias *, unsigned int _base, unsigned int _num);
af062818b47340eef15700d2f0211576ba3506eevboxsyncvoid LibAliasSetSkinnyPort(struct libalias *, unsigned int _port);
af062818b47340eef15700d2f0211576ba3506eevboxsyncunsigned int
af062818b47340eef15700d2f0211576ba3506eevboxsync LibAliasSetMode(struct libalias *, unsigned int _flags, unsigned int _mask);
af062818b47340eef15700d2f0211576ba3506eevboxsync/* Packet Handling functions. */
af062818b47340eef15700d2f0211576ba3506eevboxsyncint LibAliasIn (struct libalias *, char *_ptr, int _maxpacketsize);
af062818b47340eef15700d2f0211576ba3506eevboxsyncint LibAliasOut(struct libalias *, char *_ptr, int _maxpacketsize);
af062818b47340eef15700d2f0211576ba3506eevboxsyncint LibAliasOutTry(struct libalias *, char *_ptr, int _maxpacketsize, int _create);
af062818b47340eef15700d2f0211576ba3506eevboxsyncint LibAliasUnaliasOut(struct libalias *, char *_ptr, int _maxpacketsize);
af062818b47340eef15700d2f0211576ba3506eevboxsync/* Port and address redirection functions. */
af062818b47340eef15700d2f0211576ba3506eevboxsyncLibAliasAddServer(struct libalias *, struct alias_link *_lnk,
af062818b47340eef15700d2f0211576ba3506eevboxsyncLibAliasRedirectAddr(struct libalias *, struct in_addr _src_addr,
af062818b47340eef15700d2f0211576ba3506eevboxsyncint LibAliasRedirectDynamic(struct libalias *, struct alias_link *_lnk);
af062818b47340eef15700d2f0211576ba3506eevboxsyncvoid LibAliasRedirectDelete(struct libalias *, struct alias_link *_lnk);
af062818b47340eef15700d2f0211576ba3506eevboxsyncLibAliasRedirectPort(struct libalias *, struct in_addr _src_addr,
af062818b47340eef15700d2f0211576ba3506eevboxsync unsigned short _src_port, struct in_addr _dst_addr,
af062818b47340eef15700d2f0211576ba3506eevboxsync unsigned short _dst_port, struct in_addr _alias_addr,
af062818b47340eef15700d2f0211576ba3506eevboxsyncLibAliasRedirectProto(struct libalias *, struct in_addr _src_addr,
af062818b47340eef15700d2f0211576ba3506eevboxsync struct in_addr _dst_addr, struct in_addr _alias_addr,
af062818b47340eef15700d2f0211576ba3506eevboxsync unsigned char _proto);
af062818b47340eef15700d2f0211576ba3506eevboxsync/* Fragment Handling functions. */
af062818b47340eef15700d2f0211576ba3506eevboxsyncvoid LibAliasFragmentIn(struct libalias *, char *_ptr, char *_ptr_fragment);
af062818b47340eef15700d2f0211576ba3506eevboxsyncchar *LibAliasGetFragment(struct libalias *, char *_ptr);
af062818b47340eef15700d2f0211576ba3506eevboxsyncint LibAliasSaveFragment(struct libalias *, char *_ptr);
af062818b47340eef15700d2f0211576ba3506eevboxsync/* Miscellaneous functions. */
af062818b47340eef15700d2f0211576ba3506eevboxsyncunsigned short
af062818b47340eef15700d2f0211576ba3506eevboxsync LibAliasInternetChecksum(struct libalias *, unsigned short *_ptr, int _nbytes);
af062818b47340eef15700d2f0211576ba3506eevboxsyncvoid LibAliasSetTarget(struct libalias *, struct in_addr _target_addr);
af062818b47340eef15700d2f0211576ba3506eevboxsync/* Transparent proxying routines. */
af062818b47340eef15700d2f0211576ba3506eevboxsyncint LibAliasProxyRule(struct libalias *, const char *_cmd);
af062818b47340eef15700d2f0211576ba3506eevboxsync/* Module handling API */
af062818b47340eef15700d2f0211576ba3506eevboxsync/* Mbuf helper function. */
af062818b47340eef15700d2f0211576ba3506eevboxsyncstruct mbuf *m_megapullup(PNATState, struct mbuf *, int);
af062818b47340eef15700d2f0211576ba3506eevboxsync * Mode flags and other constants.
af062818b47340eef15700d2f0211576ba3506eevboxsync/* Mode flags, set using PacketAliasSetMode() */
af062818b47340eef15700d2f0211576ba3506eevboxsync * If PKT_ALIAS_LOG is set, a message will be printed to /var/log/alias.log
af062818b47340eef15700d2f0211576ba3506eevboxsync * every time a link is created or deleted. This is useful for debugging.
af062818b47340eef15700d2f0211576ba3506eevboxsync * If PKT_ALIAS_DENY_INCOMING is set, then incoming connections (e.g. to ftp,
af062818b47340eef15700d2f0211576ba3506eevboxsync * telnet or web servers will be prevented by the aliasing mechanism.
af062818b47340eef15700d2f0211576ba3506eevboxsync * If PKT_ALIAS_SAME_PORTS is set, packets will be attempted sent from the
af062818b47340eef15700d2f0211576ba3506eevboxsync * same port as they originated on. This allows e.g. rsh to work *99% of the
af062818b47340eef15700d2f0211576ba3506eevboxsync * time*, but _not_ 100% (it will be slightly flakey instead of not working
af062818b47340eef15700d2f0211576ba3506eevboxsync * at all). This mode bit is set by PacketAliasInit(), so it is a default
af062818b47340eef15700d2f0211576ba3506eevboxsync * mode of operation.
af062818b47340eef15700d2f0211576ba3506eevboxsync * If PKT_ALIAS_USE_SOCKETS is set, then when partially specified links (e.g.
af062818b47340eef15700d2f0211576ba3506eevboxsync * destination port and/or address is zero), the packet aliasing engine will
af062818b47340eef15700d2f0211576ba3506eevboxsync * attempt to allocate a socket for the aliasing port it chooses. This will
af062818b47340eef15700d2f0211576ba3506eevboxsync * avoid interference with the host machine. Fully specified links do not
af062818b47340eef15700d2f0211576ba3506eevboxsync * require this. This bit is set after a call to PacketAliasInit(), so it is
af062818b47340eef15700d2f0211576ba3506eevboxsync * a default mode of operation.
af062818b47340eef15700d2f0211576ba3506eevboxsync * If PKT_ALIAS_UNREGISTERED_ONLY is set, then only packets with
af062818b47340eef15700d2f0211576ba3506eevboxsync * unregistered source addresses will be aliased. Private
af062818b47340eef15700d2f0211576ba3506eevboxsync * addresses are those in the following ranges:
af062818b47340eef15700d2f0211576ba3506eevboxsync * 10.0.0.0 -> 10.255.255.255
af062818b47340eef15700d2f0211576ba3506eevboxsync * 172.16.0.0 -> 172.31.255.255
af062818b47340eef15700d2f0211576ba3506eevboxsync * 192.168.0.0 -> 192.168.255.255
af062818b47340eef15700d2f0211576ba3506eevboxsync * If PKT_ALIAS_RESET_ON_ADDR_CHANGE is set, then the table of dynamic
af062818b47340eef15700d2f0211576ba3506eevboxsync * aliasing links will be reset whenever PacketAliasSetAddress() changes the
af062818b47340eef15700d2f0211576ba3506eevboxsync * default aliasing address. If the default aliasing address is left
af062818b47340eef15700d2f0211576ba3506eevboxsync * unchanged by this function call, then the table of dynamic aliasing links
af062818b47340eef15700d2f0211576ba3506eevboxsync * will be left intact. This bit is set after a call to PacketAliasInit().
af062818b47340eef15700d2f0211576ba3506eevboxsync * If PKT_ALIAS_PUNCH_FW is set, active FTP and IRC DCC connections will
af062818b47340eef15700d2f0211576ba3506eevboxsync * create a 'hole' in the firewall to allow the transfers to work. The
af062818b47340eef15700d2f0211576ba3506eevboxsync * ipfw rule number that the hole is created with is controlled by
af062818b47340eef15700d2f0211576ba3506eevboxsync * PacketAliasSetFWBase(). The hole will be attached to that
af062818b47340eef15700d2f0211576ba3506eevboxsync * particular alias_link, so when the link goes away the hole is deleted.
af062818b47340eef15700d2f0211576ba3506eevboxsync * If PKT_ALIAS_PROXY_ONLY is set, then NAT will be disabled and only
af062818b47340eef15700d2f0211576ba3506eevboxsync * transparent proxying is performed.
af062818b47340eef15700d2f0211576ba3506eevboxsync * If PKT_ALIAS_REVERSE is set, the actions of PacketAliasIn() and
af062818b47340eef15700d2f0211576ba3506eevboxsync * PacketAliasOut() are reversed.
af062818b47340eef15700d2f0211576ba3506eevboxsync/* Function return codes. */
af062818b47340eef15700d2f0211576ba3506eevboxsync#endif /* !_ALIAS_H_ */
af062818b47340eef15700d2f0211576ba3506eevboxsync/* lint -restore */