xref: /freebsd/sys/netinet/libalias/alias.h (revision 71593f95e03a410b45bacf77ac8ab5932a952894)
13b160b8bSBrian Somers /* lint -save -library Flexelint comment for external headers */
23b160b8bSBrian Somers 
371593f95SBrian Somers /*-
471593f95SBrian Somers  * Alias.h defines the outside world interfaces for the packet aliasing
571593f95SBrian Somers  * software.
671593f95SBrian Somers  *
771593f95SBrian Somers  * This software is placed into the public domain with no restrictions on its
871593f95SBrian Somers  * distribution.
971593f95SBrian Somers  *
1071593f95SBrian Somers  * $FreeBSD$
113b160b8bSBrian Somers  */
123b160b8bSBrian Somers 
133b160b8bSBrian Somers #ifndef _ALIAS_H_
143b160b8bSBrian Somers #define	_ALIAS_H_
153b160b8bSBrian Somers 
1671593f95SBrian Somers /* The external interface to libalias, the packet aliasing engine. */
1771593f95SBrian Somers 
1871593f95SBrian Somers /* Initialization and control functions. */
1971593f95SBrian Somers void	 PacketAliasInit(void);
2071593f95SBrian Somers void	 PacketAliasSetAddress(struct in_addr _addr);
2171593f95SBrian Somers void	 PacketAliasSetFWBase(unsigned int _base, unsigned int _num);
2271593f95SBrian Somers unsigned int
2371593f95SBrian Somers 	 PacketAliasSetMode(unsigned int _flags, unsigned int _mask);
2471593f95SBrian Somers void	 PacketAliasUninit(void);
2571593f95SBrian Somers 
2671593f95SBrian Somers /* Packet Handling functions. */
2771593f95SBrian Somers int	 PacketAliasIn(char *_ptr, int _maxpacketsize);
2871593f95SBrian Somers int	 PacketAliasOut(char *_ptr, int _maxpacketsize);
2971593f95SBrian Somers int	 PacketUnaliasOut(char *_ptr, int _maxpacketsize);
3071593f95SBrian Somers 
3171593f95SBrian Somers /* Port and address redirection functions. */
3271593f95SBrian Somers 
3371593f95SBrian Somers /*
3471593f95SBrian Somers  * An anonymous structure, a pointer to which is returned from
3571593f95SBrian Somers  * PacketAliasRedirectAddr(), PacketAliasRedirectPort() or
3671593f95SBrian Somers  * PacketAliasRedirectProto(), passed to PacketAliasAddServer(),
3771593f95SBrian Somers  * and freed by PacketAliasRedirectDelete().
3871593f95SBrian Somers  */
393b160b8bSBrian Somers struct	alias_link;
403b160b8bSBrian Somers 
4171593f95SBrian Somers int	 PacketAliasAddServer(struct alias_link *_link,
4271593f95SBrian Somers 	    struct in_addr _addr, unsigned short _port);
4371593f95SBrian Somers struct alias_link *
4471593f95SBrian Somers 	 PacketAliasRedirectAddr(struct in_addr _src_addr,
4571593f95SBrian Somers 	    struct in_addr _alias_addr);
4671593f95SBrian Somers void	 PacketAliasRedirectDelete(struct alias_link *_link);
4771593f95SBrian Somers struct alias_link *
4871593f95SBrian Somers 	 PacketAliasRedirectPort(struct in_addr _src_addr,
4971593f95SBrian Somers 	    unsigned short _src_port, struct in_addr _dst_addr,
5071593f95SBrian Somers 	    unsigned short _dst_port, struct in_addr _alias_addr,
5171593f95SBrian Somers 	    unsigned short _alias_port, unsigned char _proto);
5271593f95SBrian Somers struct alias_link *
5371593f95SBrian Somers 	 PacketAliasRedirectProto(struct in_addr _src_addr,
5471593f95SBrian Somers 	    struct in_addr _dst_addr, struct in_addr _alias_addr,
5571593f95SBrian Somers 	    unsigned char _proto);
563efa11bbSBrian Somers 
5771593f95SBrian Somers /* Fragment Handling functions. */
5871593f95SBrian Somers void	 PacketAliasFragmentIn(char *_ptr, char *_ptr_fragment);
5971593f95SBrian Somers char	*PacketAliasGetFragment(char *_ptr);
6071593f95SBrian Somers int	 PacketAliasSaveFragment(char *_ptr);
613efa11bbSBrian Somers 
6271593f95SBrian Somers /* Miscellaneous functions. */
6371593f95SBrian Somers int	 PacketAliasCheckNewLink(void);
6471593f95SBrian Somers unsigned short
6571593f95SBrian Somers 	 PacketAliasInternetChecksum(unsigned short *_ptr, int _nbytes);
6671593f95SBrian Somers void	 PacketAliasSetTarget(struct in_addr _target_addr);
678ddc51bcSEivind Eklund 
6871593f95SBrian Somers /* Transparent proxying routines. */
6971593f95SBrian Somers int	 PacketAliasProxyRule(const char *_cmd);
703efa11bbSBrian Somers 
7171593f95SBrian Somers /* Mode flags, set using PacketAliasSetMode() */
723efa11bbSBrian Somers 
7371593f95SBrian Somers /*
7471593f95SBrian Somers  * If PKT_ALIAS_LOG is set, a message will be printed to /var/log/alias.log
7571593f95SBrian Somers  * every time a link is created or deleted.  This is useful for debugging.
7671593f95SBrian Somers  */
773efa11bbSBrian Somers #define	PKT_ALIAS_LOG			0x01
783b160b8bSBrian Somers 
7971593f95SBrian Somers /*
8071593f95SBrian Somers  * If PKT_ALIAS_DENY_INCOMING is set, then incoming connections (e.g. to ftp,
8171593f95SBrian Somers  * telnet or web servers will be prevented by the aliasing mechanism.
8271593f95SBrian Somers  */
833efa11bbSBrian Somers #define	PKT_ALIAS_DENY_INCOMING		0x02
843b160b8bSBrian Somers 
8571593f95SBrian Somers /*
8671593f95SBrian Somers  * If PKT_ALIAS_SAME_PORTS is set, packets will be attempted sent from the
8771593f95SBrian Somers  * same port as they originated on.  This allows e.g. rsh to work *99% of the
8871593f95SBrian Somers  * time*, but _not_ 100% (it will be slightly flakey instead of not working
8971593f95SBrian Somers  * at all).  This mode bit is set by PacketAliasInit(), so it is a default
9071593f95SBrian Somers  * mode of operation.
9171593f95SBrian Somers  */
923efa11bbSBrian Somers #define	PKT_ALIAS_SAME_PORTS		0x04
933b160b8bSBrian Somers 
9471593f95SBrian Somers /*
9571593f95SBrian Somers  * If PKT_ALIAS_USE_SOCKETS is set, then when partially specified links (e.g.
9671593f95SBrian Somers  * destination port and/or address is zero), the packet aliasing engine will
9771593f95SBrian Somers  * attempt to allocate a socket for the aliasing port it chooses.  This will
9871593f95SBrian Somers  * avoid interference with the host machine.  Fully specified links do not
9971593f95SBrian Somers  * require this.  This bit is set after a call to PacketAliasInit(), so it is
10071593f95SBrian Somers  * a default mode of operation.
10171593f95SBrian Somers  */
1023efa11bbSBrian Somers #define	PKT_ALIAS_USE_SOCKETS		0x08
1033b160b8bSBrian Somers 
10471593f95SBrian Somers /*-
10571593f95SBrian Somers  * If PKT_ALIAS_UNREGISTERED_ONLY is set, then only packets with
10671593f95SBrian Somers  * unregistered source addresses will be aliased.  Private
10771593f95SBrian Somers  * addresses are those in the following ranges:
10871593f95SBrian Somers  *
10971593f95SBrian Somers  *		10.0.0.0     ->   10.255.255.255
11071593f95SBrian Somers  *		172.16.0.0   ->   172.31.255.255
11171593f95SBrian Somers  *		192.168.0.0  ->   192.168.255.255
11271593f95SBrian Somers  */
1133efa11bbSBrian Somers #define	PKT_ALIAS_UNREGISTERED_ONLY	0x10
1143b160b8bSBrian Somers 
11571593f95SBrian Somers /*
11671593f95SBrian Somers  * If PKT_ALIAS_RESET_ON_ADDR_CHANGE is set, then the table of dynamic
11771593f95SBrian Somers  * aliasing links will be reset whenever PacketAliasSetAddress() changes the
11871593f95SBrian Somers  * default aliasing address.  If the default aliasing address is left
11971593f95SBrian Somers  * unchanged by this function call, then the table of dynamic aliasing links
12071593f95SBrian Somers  * will be left intact.  This bit is set after a call to PacketAliasInit().
12171593f95SBrian Somers  */
1223efa11bbSBrian Somers #define	PKT_ALIAS_RESET_ON_ADDR_CHANGE	0x20
1233b160b8bSBrian Somers 
1249feab75aSBrian Somers #ifndef NO_FW_PUNCH
12571593f95SBrian Somers /*
12671593f95SBrian Somers  * If PKT_ALIAS_PUNCH_FW is set, active FTP and IRC DCC connections will
12771593f95SBrian Somers  * create a 'hole' in the firewall to allow the transfers to work.  The
12871593f95SBrian Somers  * ipfw rule number that the hole is created with is controlled by
12971593f95SBrian Somers  * PacketAliasSetFWBase().  The hole will be attached to that
13071593f95SBrian Somers  * particular alias_link, so when the link goes away the hole is deleted.
13171593f95SBrian Somers  */
132b12cbc34SArchie Cobbs #define	PKT_ALIAS_PUNCH_FW		0x100
1339feab75aSBrian Somers #endif
1348ddc51bcSEivind Eklund 
13571593f95SBrian Somers /*
13671593f95SBrian Somers  * If PKT_ALIAS_PROXY_ONLY is set, then NAT will be disabled and only
13771593f95SBrian Somers  * transparent proxying is performed.
13871593f95SBrian Somers  */
1397d96f4efSBrian Somers #define	PKT_ALIAS_PROXY_ONLY		0x40
1407d96f4efSBrian Somers 
14171593f95SBrian Somers /*
14271593f95SBrian Somers  * If PKT_ALIAS_REVERSE is set, the actions of PacketAliasIn() and
14371593f95SBrian Somers  * PacketAliasOut() are reversed.
14471593f95SBrian Somers  */
1457d96f4efSBrian Somers #define	PKT_ALIAS_REVERSE		0x80
1467d96f4efSBrian Somers 
14771593f95SBrian Somers /* Function return codes. */
1483b160b8bSBrian Somers #define	PKT_ALIAS_ERROR			-1
1493b160b8bSBrian Somers #define	PKT_ALIAS_OK			1
1503b160b8bSBrian Somers #define	PKT_ALIAS_IGNORED		2
1513b160b8bSBrian Somers #define	PKT_ALIAS_UNRESOLVED_FRAGMENT	3
1523b160b8bSBrian Somers #define	PKT_ALIAS_FOUND_HEADER_FRAGMENT	4
1533b160b8bSBrian Somers 
15471593f95SBrian Somers #endif /* !_ALIAS_H_ */
15571593f95SBrian Somers 
1563b160b8bSBrian Somers /* lint -restore */
157