xref: /freebsd/sys/netinet/libalias/alias.h (revision ff7cd805df308ccde1d28ffaa084e25925763f98)
1 /* lint -save -library Flexelint comment for external headers */
2 
3 /*-
4  * Copyright (c) 2001 Charles Mott <cm@linktel.net>
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  *
28  * $FreeBSD$
29  */
30 
31 /*-
32  * Alias.h defines the outside world interfaces for the packet aliasing
33  * software.
34  *
35  * This software is placed into the public domain with no restrictions on its
36  * distribution.
37  */
38 
39 #ifndef _ALIAS_H_
40 #define	_ALIAS_H_
41 
42 /* The external interface to libalias, the packet aliasing engine. */
43 
44 /* Initialization and control functions. */
45 void	 PacketAliasInit(void);
46 void	 PacketAliasSetAddress(struct in_addr _addr);
47 void	 PacketAliasSetFWBase(unsigned int _base, unsigned int _num);
48 void	 PacketAliasSetSkinnyPort(unsigned int _port);
49 unsigned int
50 	 PacketAliasSetMode(unsigned int _flags, unsigned int _mask);
51 void	 PacketAliasUninit(void);
52 
53 /* Packet Handling functions. */
54 int	 PacketAliasIn(char *_ptr, int _maxpacketsize);
55 int	 PacketAliasOut(char *_ptr, int _maxpacketsize);
56 int	 PacketUnaliasOut(char *_ptr, int _maxpacketsize);
57 
58 /* Port and address redirection functions. */
59 
60 /*
61  * An anonymous structure, a pointer to which is returned from
62  * PacketAliasRedirectAddr(), PacketAliasRedirectPort() or
63  * PacketAliasRedirectProto(), passed to PacketAliasAddServer(),
64  * and freed by PacketAliasRedirectDelete().
65  */
66 struct	alias_link;
67 
68 int	 PacketAliasAddServer(struct alias_link *_link,
69 	    struct in_addr _addr, unsigned short _port);
70 struct alias_link *
71 	 PacketAliasRedirectAddr(struct in_addr _src_addr,
72 	    struct in_addr _alias_addr);
73 int	 PacketAliasRedirectDynamic(struct alias_link *_link);
74 void	 PacketAliasRedirectDelete(struct alias_link *_link);
75 struct alias_link *
76 	 PacketAliasRedirectPort(struct in_addr _src_addr,
77 	    unsigned short _src_port, struct in_addr _dst_addr,
78 	    unsigned short _dst_port, struct in_addr _alias_addr,
79 	    unsigned short _alias_port, unsigned char _proto);
80 struct alias_link *
81 	 PacketAliasRedirectProto(struct in_addr _src_addr,
82 	    struct in_addr _dst_addr, struct in_addr _alias_addr,
83 	    unsigned char _proto);
84 
85 /* Fragment Handling functions. */
86 void	 PacketAliasFragmentIn(char *_ptr, char *_ptr_fragment);
87 char	*PacketAliasGetFragment(char *_ptr);
88 int	 PacketAliasSaveFragment(char *_ptr);
89 
90 /* Miscellaneous functions. */
91 int	 PacketAliasCheckNewLink(void);
92 unsigned short
93 	 PacketAliasInternetChecksum(unsigned short *_ptr, int _nbytes);
94 void	 PacketAliasSetTarget(struct in_addr _target_addr);
95 
96 /* Transparent proxying routines. */
97 int	 PacketAliasProxyRule(const char *_cmd);
98 
99 /* Mode flags, set using PacketAliasSetMode() */
100 
101 /*
102  * If PKT_ALIAS_LOG is set, a message will be printed to /var/log/alias.log
103  * every time a link is created or deleted.  This is useful for debugging.
104  */
105 #define	PKT_ALIAS_LOG			0x01
106 
107 /*
108  * If PKT_ALIAS_DENY_INCOMING is set, then incoming connections (e.g. to ftp,
109  * telnet or web servers will be prevented by the aliasing mechanism.
110  */
111 #define	PKT_ALIAS_DENY_INCOMING		0x02
112 
113 /*
114  * If PKT_ALIAS_SAME_PORTS is set, packets will be attempted sent from the
115  * same port as they originated on.  This allows e.g. rsh to work *99% of the
116  * time*, but _not_ 100% (it will be slightly flakey instead of not working
117  * at all).  This mode bit is set by PacketAliasInit(), so it is a default
118  * mode of operation.
119  */
120 #define	PKT_ALIAS_SAME_PORTS		0x04
121 
122 /*
123  * If PKT_ALIAS_USE_SOCKETS is set, then when partially specified links (e.g.
124  * destination port and/or address is zero), the packet aliasing engine will
125  * attempt to allocate a socket for the aliasing port it chooses.  This will
126  * avoid interference with the host machine.  Fully specified links do not
127  * require this.  This bit is set after a call to PacketAliasInit(), so it is
128  * a default mode of operation.
129  */
130 #define	PKT_ALIAS_USE_SOCKETS		0x08
131 
132 /*-
133  * If PKT_ALIAS_UNREGISTERED_ONLY is set, then only packets with
134  * unregistered source addresses will be aliased.  Private
135  * addresses are those in the following ranges:
136  *
137  *		10.0.0.0     ->   10.255.255.255
138  *		172.16.0.0   ->   172.31.255.255
139  *		192.168.0.0  ->   192.168.255.255
140  */
141 #define	PKT_ALIAS_UNREGISTERED_ONLY	0x10
142 
143 /*
144  * If PKT_ALIAS_RESET_ON_ADDR_CHANGE is set, then the table of dynamic
145  * aliasing links will be reset whenever PacketAliasSetAddress() changes the
146  * default aliasing address.  If the default aliasing address is left
147  * unchanged by this function call, then the table of dynamic aliasing links
148  * will be left intact.  This bit is set after a call to PacketAliasInit().
149  */
150 #define	PKT_ALIAS_RESET_ON_ADDR_CHANGE	0x20
151 
152 #ifndef NO_FW_PUNCH
153 /*
154  * If PKT_ALIAS_PUNCH_FW is set, active FTP and IRC DCC connections will
155  * create a 'hole' in the firewall to allow the transfers to work.  The
156  * ipfw rule number that the hole is created with is controlled by
157  * PacketAliasSetFWBase().  The hole will be attached to that
158  * particular alias_link, so when the link goes away the hole is deleted.
159  */
160 #define	PKT_ALIAS_PUNCH_FW		0x100
161 #endif
162 
163 /*
164  * If PKT_ALIAS_PROXY_ONLY is set, then NAT will be disabled and only
165  * transparent proxying is performed.
166  */
167 #define	PKT_ALIAS_PROXY_ONLY		0x40
168 
169 /*
170  * If PKT_ALIAS_REVERSE is set, the actions of PacketAliasIn() and
171  * PacketAliasOut() are reversed.
172  */
173 #define	PKT_ALIAS_REVERSE		0x80
174 
175 /* Function return codes. */
176 #define	PKT_ALIAS_ERROR			-1
177 #define	PKT_ALIAS_OK			1
178 #define	PKT_ALIAS_IGNORED		2
179 #define	PKT_ALIAS_UNRESOLVED_FRAGMENT	3
180 #define	PKT_ALIAS_FOUND_HEADER_FRAGMENT	4
181 
182 #endif /* !_ALIAS_H_ */
183 
184 /* lint -restore */
185