xref: /freebsd/sys/netinet/libalias/alias.h (revision e83aaae350ee78c20d66b4f983eef6e6c48f30ed)
13b160b8bSBrian Somers /* lint -save -library Flexelint comment for external headers */
23b160b8bSBrian Somers 
371593f95SBrian Somers /*-
4e83aaae3SBrian Somers  * Copyright (c) 2001 Charles Mott <cm@linktel.net>
5f987e1bdSBrian Somers  * All rights reserved.
6f987e1bdSBrian Somers  *
7f987e1bdSBrian Somers  * Redistribution and use in source and binary forms, with or without
8f987e1bdSBrian Somers  * modification, are permitted provided that the following conditions
9f987e1bdSBrian Somers  * are met:
10f987e1bdSBrian Somers  * 1. Redistributions of source code must retain the above copyright
11f987e1bdSBrian Somers  *    notice, this list of conditions and the following disclaimer.
12f987e1bdSBrian Somers  * 2. Redistributions in binary form must reproduce the above copyright
13f987e1bdSBrian Somers  *    notice, this list of conditions and the following disclaimer in the
14f987e1bdSBrian Somers  *    documentation and/or other materials provided with the distribution.
15f987e1bdSBrian Somers  *
16f987e1bdSBrian Somers  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17f987e1bdSBrian Somers  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18f987e1bdSBrian Somers  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19f987e1bdSBrian Somers  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20f987e1bdSBrian Somers  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21f987e1bdSBrian Somers  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22f987e1bdSBrian Somers  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23f987e1bdSBrian Somers  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24f987e1bdSBrian Somers  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25f987e1bdSBrian Somers  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26f987e1bdSBrian Somers  * SUCH DAMAGE.
27f987e1bdSBrian Somers  *
28f987e1bdSBrian Somers  * $FreeBSD$
29f987e1bdSBrian Somers  */
30f987e1bdSBrian Somers 
31f987e1bdSBrian Somers /*-
3271593f95SBrian Somers  * Alias.h defines the outside world interfaces for the packet aliasing
3371593f95SBrian Somers  * software.
3471593f95SBrian Somers  *
3571593f95SBrian Somers  * This software is placed into the public domain with no restrictions on its
3671593f95SBrian Somers  * distribution.
373b160b8bSBrian Somers  */
383b160b8bSBrian Somers 
393b160b8bSBrian Somers #ifndef _ALIAS_H_
403b160b8bSBrian Somers #define	_ALIAS_H_
413b160b8bSBrian Somers 
4271593f95SBrian Somers /* The external interface to libalias, the packet aliasing engine. */
4371593f95SBrian Somers 
4471593f95SBrian Somers /* Initialization and control functions. */
4571593f95SBrian Somers void	 PacketAliasInit(void);
4671593f95SBrian Somers void	 PacketAliasSetAddress(struct in_addr _addr);
4771593f95SBrian Somers void	 PacketAliasSetFWBase(unsigned int _base, unsigned int _num);
4871593f95SBrian Somers unsigned int
4971593f95SBrian Somers 	 PacketAliasSetMode(unsigned int _flags, unsigned int _mask);
5071593f95SBrian Somers void	 PacketAliasUninit(void);
5171593f95SBrian Somers 
5271593f95SBrian Somers /* Packet Handling functions. */
5371593f95SBrian Somers int	 PacketAliasIn(char *_ptr, int _maxpacketsize);
5471593f95SBrian Somers int	 PacketAliasOut(char *_ptr, int _maxpacketsize);
5571593f95SBrian Somers int	 PacketUnaliasOut(char *_ptr, int _maxpacketsize);
5671593f95SBrian Somers 
5771593f95SBrian Somers /* Port and address redirection functions. */
5871593f95SBrian Somers 
5971593f95SBrian Somers /*
6071593f95SBrian Somers  * An anonymous structure, a pointer to which is returned from
6171593f95SBrian Somers  * PacketAliasRedirectAddr(), PacketAliasRedirectPort() or
6271593f95SBrian Somers  * PacketAliasRedirectProto(), passed to PacketAliasAddServer(),
6371593f95SBrian Somers  * and freed by PacketAliasRedirectDelete().
6471593f95SBrian Somers  */
653b160b8bSBrian Somers struct	alias_link;
663b160b8bSBrian Somers 
6771593f95SBrian Somers int	 PacketAliasAddServer(struct alias_link *_link,
6871593f95SBrian Somers 	    struct in_addr _addr, unsigned short _port);
6971593f95SBrian Somers struct alias_link *
7071593f95SBrian Somers 	 PacketAliasRedirectAddr(struct in_addr _src_addr,
7171593f95SBrian Somers 	    struct in_addr _alias_addr);
7271593f95SBrian Somers void	 PacketAliasRedirectDelete(struct alias_link *_link);
7371593f95SBrian Somers struct alias_link *
7471593f95SBrian Somers 	 PacketAliasRedirectPort(struct in_addr _src_addr,
7571593f95SBrian Somers 	    unsigned short _src_port, struct in_addr _dst_addr,
7671593f95SBrian Somers 	    unsigned short _dst_port, struct in_addr _alias_addr,
7771593f95SBrian Somers 	    unsigned short _alias_port, unsigned char _proto);
7871593f95SBrian Somers struct alias_link *
7971593f95SBrian Somers 	 PacketAliasRedirectProto(struct in_addr _src_addr,
8071593f95SBrian Somers 	    struct in_addr _dst_addr, struct in_addr _alias_addr,
8171593f95SBrian Somers 	    unsigned char _proto);
823efa11bbSBrian Somers 
8371593f95SBrian Somers /* Fragment Handling functions. */
8471593f95SBrian Somers void	 PacketAliasFragmentIn(char *_ptr, char *_ptr_fragment);
8571593f95SBrian Somers char	*PacketAliasGetFragment(char *_ptr);
8671593f95SBrian Somers int	 PacketAliasSaveFragment(char *_ptr);
873efa11bbSBrian Somers 
8871593f95SBrian Somers /* Miscellaneous functions. */
8971593f95SBrian Somers int	 PacketAliasCheckNewLink(void);
9071593f95SBrian Somers unsigned short
9171593f95SBrian Somers 	 PacketAliasInternetChecksum(unsigned short *_ptr, int _nbytes);
9271593f95SBrian Somers void	 PacketAliasSetTarget(struct in_addr _target_addr);
938ddc51bcSEivind Eklund 
9471593f95SBrian Somers /* Transparent proxying routines. */
9571593f95SBrian Somers int	 PacketAliasProxyRule(const char *_cmd);
963efa11bbSBrian Somers 
9771593f95SBrian Somers /* Mode flags, set using PacketAliasSetMode() */
983efa11bbSBrian Somers 
9971593f95SBrian Somers /*
10071593f95SBrian Somers  * If PKT_ALIAS_LOG is set, a message will be printed to /var/log/alias.log
10171593f95SBrian Somers  * every time a link is created or deleted.  This is useful for debugging.
10271593f95SBrian Somers  */
1033efa11bbSBrian Somers #define	PKT_ALIAS_LOG			0x01
1043b160b8bSBrian Somers 
10571593f95SBrian Somers /*
10671593f95SBrian Somers  * If PKT_ALIAS_DENY_INCOMING is set, then incoming connections (e.g. to ftp,
10771593f95SBrian Somers  * telnet or web servers will be prevented by the aliasing mechanism.
10871593f95SBrian Somers  */
1093efa11bbSBrian Somers #define	PKT_ALIAS_DENY_INCOMING		0x02
1103b160b8bSBrian Somers 
11171593f95SBrian Somers /*
11271593f95SBrian Somers  * If PKT_ALIAS_SAME_PORTS is set, packets will be attempted sent from the
11371593f95SBrian Somers  * same port as they originated on.  This allows e.g. rsh to work *99% of the
11471593f95SBrian Somers  * time*, but _not_ 100% (it will be slightly flakey instead of not working
11571593f95SBrian Somers  * at all).  This mode bit is set by PacketAliasInit(), so it is a default
11671593f95SBrian Somers  * mode of operation.
11771593f95SBrian Somers  */
1183efa11bbSBrian Somers #define	PKT_ALIAS_SAME_PORTS		0x04
1193b160b8bSBrian Somers 
12071593f95SBrian Somers /*
12171593f95SBrian Somers  * If PKT_ALIAS_USE_SOCKETS is set, then when partially specified links (e.g.
12271593f95SBrian Somers  * destination port and/or address is zero), the packet aliasing engine will
12371593f95SBrian Somers  * attempt to allocate a socket for the aliasing port it chooses.  This will
12471593f95SBrian Somers  * avoid interference with the host machine.  Fully specified links do not
12571593f95SBrian Somers  * require this.  This bit is set after a call to PacketAliasInit(), so it is
12671593f95SBrian Somers  * a default mode of operation.
12771593f95SBrian Somers  */
1283efa11bbSBrian Somers #define	PKT_ALIAS_USE_SOCKETS		0x08
1293b160b8bSBrian Somers 
13071593f95SBrian Somers /*-
13171593f95SBrian Somers  * If PKT_ALIAS_UNREGISTERED_ONLY is set, then only packets with
13271593f95SBrian Somers  * unregistered source addresses will be aliased.  Private
13371593f95SBrian Somers  * addresses are those in the following ranges:
13471593f95SBrian Somers  *
13571593f95SBrian Somers  *		10.0.0.0     ->   10.255.255.255
13671593f95SBrian Somers  *		172.16.0.0   ->   172.31.255.255
13771593f95SBrian Somers  *		192.168.0.0  ->   192.168.255.255
13871593f95SBrian Somers  */
1393efa11bbSBrian Somers #define	PKT_ALIAS_UNREGISTERED_ONLY	0x10
1403b160b8bSBrian Somers 
14171593f95SBrian Somers /*
14271593f95SBrian Somers  * If PKT_ALIAS_RESET_ON_ADDR_CHANGE is set, then the table of dynamic
14371593f95SBrian Somers  * aliasing links will be reset whenever PacketAliasSetAddress() changes the
14471593f95SBrian Somers  * default aliasing address.  If the default aliasing address is left
14571593f95SBrian Somers  * unchanged by this function call, then the table of dynamic aliasing links
14671593f95SBrian Somers  * will be left intact.  This bit is set after a call to PacketAliasInit().
14771593f95SBrian Somers  */
1483efa11bbSBrian Somers #define	PKT_ALIAS_RESET_ON_ADDR_CHANGE	0x20
1493b160b8bSBrian Somers 
1509feab75aSBrian Somers #ifndef NO_FW_PUNCH
15171593f95SBrian Somers /*
15271593f95SBrian Somers  * If PKT_ALIAS_PUNCH_FW is set, active FTP and IRC DCC connections will
15371593f95SBrian Somers  * create a 'hole' in the firewall to allow the transfers to work.  The
15471593f95SBrian Somers  * ipfw rule number that the hole is created with is controlled by
15571593f95SBrian Somers  * PacketAliasSetFWBase().  The hole will be attached to that
15671593f95SBrian Somers  * particular alias_link, so when the link goes away the hole is deleted.
15771593f95SBrian Somers  */
158b12cbc34SArchie Cobbs #define	PKT_ALIAS_PUNCH_FW		0x100
1599feab75aSBrian Somers #endif
1608ddc51bcSEivind Eklund 
16171593f95SBrian Somers /*
16271593f95SBrian Somers  * If PKT_ALIAS_PROXY_ONLY is set, then NAT will be disabled and only
16371593f95SBrian Somers  * transparent proxying is performed.
16471593f95SBrian Somers  */
1657d96f4efSBrian Somers #define	PKT_ALIAS_PROXY_ONLY		0x40
1667d96f4efSBrian Somers 
16771593f95SBrian Somers /*
16871593f95SBrian Somers  * If PKT_ALIAS_REVERSE is set, the actions of PacketAliasIn() and
16971593f95SBrian Somers  * PacketAliasOut() are reversed.
17071593f95SBrian Somers  */
1717d96f4efSBrian Somers #define	PKT_ALIAS_REVERSE		0x80
1727d96f4efSBrian Somers 
17371593f95SBrian Somers /* Function return codes. */
1743b160b8bSBrian Somers #define	PKT_ALIAS_ERROR			-1
1753b160b8bSBrian Somers #define	PKT_ALIAS_OK			1
1763b160b8bSBrian Somers #define	PKT_ALIAS_IGNORED		2
1773b160b8bSBrian Somers #define	PKT_ALIAS_UNRESOLVED_FRAGMENT	3
1783b160b8bSBrian Somers #define	PKT_ALIAS_FOUND_HEADER_FRAGMENT	4
1793b160b8bSBrian Somers 
18071593f95SBrian Somers #endif /* !_ALIAS_H_ */
18171593f95SBrian Somers 
1823b160b8bSBrian Somers /* lint -restore */
183