ipfw2 - Final whitespace cleanup
[dragonfly.git] / sys / net / libalias / alias.h
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: src/sys/netinet/libalias/alias.h,v 1.34.6.1 2008/11/25 02:59:29 kensmith Exp $
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 #include <netinet/in_systm.h>
43 #include <netinet/in.h>
44 #include <netinet/ip.h>
45
46 #define LIBALIAS_BUF_SIZE 128
47 #ifdef  _KERNEL
48 /*
49  * The kernel version of libalias does not support these features.
50  */
51 #define NO_FW_PUNCH
52 #define NO_USE_SOCKETS
53
54 MALLOC_DECLARE(M_ALIAS);
55
56 #endif
57
58 /*
59  * The external interface to libalias, the packet aliasing engine.
60  *
61  * There are two sets of functions:
62  *
63  * PacketAlias*() the old API which doesn't take an instance pointer
64  * and therefore can only have one packet engine at a time.
65  *
66  * LibAlias*() the new API which takes as first argument a pointer to
67  * the instance of the packet aliasing engine.
68  *
69  * The functions otherwise correspond to each other one for one, except
70  * for the LibAliasUnaliasOut()/PacketUnaliasOut() function which were
71  * were misnamed in the old API.
72  */
73
74 /*
75  * The instance structure
76  */
77 struct libalias;
78
79 /*
80  * An anonymous structure, a pointer to which is returned from
81  * PacketAliasRedirectAddr(), PacketAliasRedirectPort() or
82  * PacketAliasRedirectProto(), passed to PacketAliasAddServer(),
83  * and freed by PacketAliasRedirectDelete().
84  */
85 struct alias_link;
86
87
88 /* OLD API */
89
90 /* Initialization and control functions. */
91 void            PacketAliasInit(void);
92 void            PacketAliasSetAddress(struct in_addr _addr);
93 void            PacketAliasSetFWBase(unsigned int _base, unsigned int _num);
94 void            PacketAliasSetSkinnyPort(unsigned int _port);
95 unsigned int
96                 PacketAliasSetMode(unsigned int _flags, unsigned int _mask);
97 void            PacketAliasUninit(void);
98
99 /* Packet Handling functions. */
100 int             PacketAliasIn(char *_ptr, int _maxpacketsize);
101 int             PacketAliasOut(char *_ptr, int _maxpacketsize);
102 int             PacketUnaliasOut(char *_ptr, int _maxpacketsize);
103
104 /* Port and address redirection functions. */
105
106
107 int
108 PacketAliasAddServer(struct alias_link *_lnk,
109         struct in_addr _addr, unsigned short _port);
110 struct alias_link *
111 PacketAliasRedirectAddr(struct in_addr _src_addr,
112         struct in_addr _alias_addr);
113 int             PacketAliasRedirectDynamic(struct alias_link *_lnk);
114 void            PacketAliasRedirectDelete(struct alias_link *_lnk);
115 struct alias_link *
116 PacketAliasRedirectPort(struct in_addr _src_addr,
117         unsigned short _src_port, struct in_addr _dst_addr,
118         unsigned short _dst_port, struct in_addr _alias_addr,
119         unsigned short _alias_port, unsigned char _proto);
120 struct alias_link *
121 PacketAliasRedirectProto(struct in_addr _src_addr,
122         struct in_addr _dst_addr, struct in_addr _alias_addr,
123         unsigned char _proto);
124
125 /* Fragment Handling functions. */
126 void            PacketAliasFragmentIn(char *_ptr, char *_ptr_fragment);
127 char               *PacketAliasGetFragment(char *_ptr);
128 int             PacketAliasSaveFragment(char *_ptr);
129
130 /* Miscellaneous functions. */
131 int             PacketAliasCheckNewLink(void);
132 unsigned short
133                 PacketAliasInternetChecksum(unsigned short *_ptr, int _nbytes);
134 void            PacketAliasSetTarget(struct in_addr _target_addr);
135
136 /* Transparent proxying routines. */
137 int             PacketAliasProxyRule(const char *_cmd);
138
139 /* NEW API */
140
141 /* Initialization and control functions. */
142 struct libalias *LibAliasInit(struct libalias *);
143 void            LibAliasSetAddress(struct libalias *, struct in_addr _addr);
144 void            LibAliasSetFWBase(struct libalias *, unsigned int _base, unsigned int _num);
145 void            LibAliasSetSkinnyPort(struct libalias *, unsigned int _port);
146 unsigned int
147                 LibAliasSetMode(struct libalias *, unsigned int _flags, unsigned int _mask);
148 void            LibAliasUninit(struct libalias *);
149
150 /* Packet Handling functions. */
151 int             LibAliasIn (struct libalias *, char *_ptr, int _maxpacketsize);
152 int             LibAliasOut(struct libalias *, char *_ptr, int _maxpacketsize);
153 int             LibAliasOutTry(struct libalias *, char *_ptr, int _maxpacketsize, int _create);
154 int             LibAliasUnaliasOut(struct libalias *, char *_ptr, int _maxpacketsize);
155
156 /* Port and address redirection functions. */
157
158 int
159 LibAliasAddServer(struct libalias *, struct alias_link *_lnk,
160         struct in_addr _addr, unsigned short _port);
161 struct alias_link *
162 LibAliasRedirectAddr(struct libalias *, struct in_addr _src_addr,
163         struct in_addr _alias_addr);
164 int             LibAliasRedirectDynamic(struct libalias *, struct alias_link *_lnk);
165 void            LibAliasRedirectDelete(struct libalias *, struct alias_link *_lnk);
166 struct alias_link *
167 LibAliasRedirectPort(struct libalias *, struct in_addr _src_addr,
168         unsigned short _src_port, struct in_addr _dst_addr,
169         unsigned short _dst_port, struct in_addr _alias_addr,
170         unsigned short _alias_port, unsigned char _proto);
171 struct alias_link *
172 LibAliasRedirectProto(struct libalias *, struct in_addr _src_addr,
173         struct in_addr _dst_addr, struct in_addr _alias_addr,
174         unsigned char _proto);
175
176 /* Fragment Handling functions. */
177 void            LibAliasFragmentIn(struct libalias *, char *_ptr, char *_ptr_fragment);
178 char               *LibAliasGetFragment(struct libalias *, char *_ptr);
179 int             LibAliasSaveFragment(struct libalias *, char *_ptr);
180
181 /* Miscellaneous functions. */
182 int             LibAliasCheckNewLink(struct libalias *);
183 unsigned short
184                 LibAliasInternetChecksum(struct libalias *, unsigned short *_ptr, int _nbytes);
185 void            LibAliasSetTarget(struct libalias *, struct in_addr _target_addr);
186
187 /* Transparent proxying routines. */
188 int             LibAliasProxyRule(struct libalias *, const char *_cmd);
189
190 /* Module handling API */
191 int                      LibAliasLoadModule(char *);
192 int                      LibAliasUnLoadAllModule(void);
193 int                      LibAliasRefreshModules(void);
194
195 /* Mbuf helper function. */
196 struct mbuf     *m_megapullup(struct mbuf *, int);
197
198 /*
199  * Mode flags and other constants.
200  */
201
202
203 /* Mode flags, set using PacketAliasSetMode() */
204
205 /*
206  * If PKT_ALIAS_LOG is set, a message will be printed to /var/log/alias.log
207  * every time a link is created or deleted.  This is useful for debugging.
208  */
209 #define PKT_ALIAS_LOG                   0x01
210
211 /*
212  * If PKT_ALIAS_DENY_INCOMING is set, then incoming connections (e.g. to ftp,
213  * telnet or web servers will be prevented by the aliasing mechanism.
214  */
215 #define PKT_ALIAS_DENY_INCOMING         0x02
216
217 /*
218  * If PKT_ALIAS_SAME_PORTS is set, packets will be attempted sent from the
219  * same port as they originated on.  This allows e.g. rsh to work *99% of the
220  * time*, but _not_ 100% (it will be slightly flakey instead of not working
221  * at all).  This mode bit is set by PacketAliasInit(), so it is a default
222  * mode of operation.
223  */
224 #define PKT_ALIAS_SAME_PORTS            0x04
225
226 /*
227  * If PKT_ALIAS_USE_SOCKETS is set, then when partially specified links (e.g.
228  * destination port and/or address is zero), the packet aliasing engine will
229  * attempt to allocate a socket for the aliasing port it chooses.  This will
230  * avoid interference with the host machine.  Fully specified links do not
231  * require this.  This bit is set after a call to PacketAliasInit(), so it is
232  * a default mode of operation.
233  */
234 #ifndef NO_USE_SOCKETS
235 #define PKT_ALIAS_USE_SOCKETS           0x08
236 #endif
237 /*-
238  * If PKT_ALIAS_UNREGISTERED_ONLY is set, then only packets with
239  * unregistered source addresses will be aliased.  Private
240  * addresses are those in the following ranges:
241  *
242  *              10.0.0.0         ->   10.255.255.255
243  *              172.16.0.0   ->   172.31.255.255
244  *              192.168.0.0  ->   192.168.255.255
245  */
246 #define PKT_ALIAS_UNREGISTERED_ONLY     0x10
247
248 /*
249  * If PKT_ALIAS_RESET_ON_ADDR_CHANGE is set, then the table of dynamic
250  * aliasing links will be reset whenever PacketAliasSetAddress() changes the
251  * default aliasing address.  If the default aliasing address is left
252  * unchanged by this function call, then the table of dynamic aliasing links
253  * will be left intact.  This bit is set after a call to PacketAliasInit().
254  */
255 #define PKT_ALIAS_RESET_ON_ADDR_CHANGE  0x20
256
257 #ifndef NO_FW_PUNCH
258 /*
259  * If PKT_ALIAS_PUNCH_FW is set, active FTP and IRC DCC connections will
260  * create a 'hole' in the firewall to allow the transfers to work.  The
261  * ipfw rule number that the hole is created with is controlled by
262  * PacketAliasSetFWBase().  The hole will be attached to that
263  * particular alias_link, so when the link goes away the hole is deleted.
264  */
265 #define PKT_ALIAS_PUNCH_FW              0x100
266 #endif
267
268 /*
269  * If PKT_ALIAS_PROXY_ONLY is set, then NAT will be disabled and only
270  * transparent proxying is performed.
271  */
272 #define PKT_ALIAS_PROXY_ONLY            0x40
273
274 /*
275  * If PKT_ALIAS_REVERSE is set, the actions of PacketAliasIn() and
276  * PacketAliasOut() are reversed.
277  */
278 #define PKT_ALIAS_REVERSE               0x80
279
280 /* Function return codes. */
281 #define PKT_ALIAS_ERROR                 -1
282 #define PKT_ALIAS_OK                    1
283 #define PKT_ALIAS_IGNORED               2
284 #define PKT_ALIAS_UNRESOLVED_FRAGMENT   3
285 #define PKT_ALIAS_FOUND_HEADER_FRAGMENT 4
286
287
288
289 #endif                          /* !_ALIAS_H_ */
290
291 /* lint -restore */