1 /* lint -save -library Flexelint comment for external headers */
4 * Copyright (c) 2001 Charles Mott <cm@linktel.net>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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
32 * Alias.h defines the outside world interfaces for the packet aliasing
35 * This software is placed into the public domain with no restrictions on its
43 * The external interface to libalias, the packet aliasing engine.
45 * There are two sets of functions:
47 * PacketAlias*() the old API which doesn't take an instance pointer
48 * and therefore can only have one packet engine at a time.
50 * LibAlias*() the new API which takes as first argument a pointer to
51 * the instance of the packet aliasing engine.
53 * The functions otherwise correspond to each other one for one, except
54 * for the LibAliasUnaliasOut()/PacketUnaliasOut() function which were
55 * were misnamed in the old API.
59 * The instance structure
64 * An anonymous structure, a pointer to which is returned from
65 * PacketAliasRedirectAddr(), PacketAliasRedirectPort() or
66 * PacketAliasRedirectProto(), passed to PacketAliasAddServer(),
67 * and freed by PacketAliasRedirectDelete().
74 /* Initialization and control functions. */
75 void PacketAliasInit(void);
76 void PacketAliasSetAddress(struct in_addr _addr);
77 void PacketAliasSetFWBase(unsigned int _base, unsigned int _num);
78 void PacketAliasSetSkinnyPort(unsigned int _port);
80 PacketAliasSetMode(unsigned int _flags, unsigned int _mask);
81 void PacketAliasUninit(void);
83 /* Packet Handling functions. */
84 int PacketAliasIn(char *_ptr, int _maxpacketsize);
85 int PacketAliasOut(char *_ptr, int _maxpacketsize);
86 int PacketUnaliasOut(char *_ptr, int _maxpacketsize);
88 /* Port and address redirection functions. */
92 PacketAliasAddServer(struct alias_link *_lnk,
93 struct in_addr _addr, unsigned short _port);
95 PacketAliasRedirectAddr(struct in_addr _src_addr,
96 struct in_addr _alias_addr);
97 int PacketAliasRedirectDynamic(struct alias_link *_lnk);
98 void PacketAliasRedirectDelete(struct alias_link *_lnk);
100 PacketAliasRedirectPort(struct in_addr _src_addr,
101 unsigned short _src_port, struct in_addr _dst_addr,
102 unsigned short _dst_port, struct in_addr _alias_addr,
103 unsigned short _alias_port, unsigned char _proto);
105 PacketAliasRedirectProto(struct in_addr _src_addr,
106 struct in_addr _dst_addr, struct in_addr _alias_addr,
107 unsigned char _proto);
109 /* Fragment Handling functions. */
110 void PacketAliasFragmentIn(char *_ptr, char *_ptr_fragment);
111 char *PacketAliasGetFragment(char *_ptr);
112 int PacketAliasSaveFragment(char *_ptr);
114 /* Miscellaneous functions. */
115 int PacketAliasCheckNewLink(void);
117 PacketAliasInternetChecksum(unsigned short *_ptr, int _nbytes);
118 void PacketAliasSetTarget(struct in_addr _target_addr);
120 /* Transparent proxying routines. */
121 int PacketAliasProxyRule(const char *_cmd);
125 /* Initialization and control functions. */
126 struct libalias *LibAliasInit(struct libalias *);
127 void LibAliasSetAddress(struct libalias *, struct in_addr _addr);
128 void LibAliasSetFWBase(struct libalias *, unsigned int _base, unsigned int _num);
129 void LibAliasSetSkinnyPort(struct libalias *, unsigned int _port);
131 LibAliasSetMode(struct libalias *, unsigned int _flags, unsigned int _mask);
132 void LibAliasUninit(struct libalias *);
134 /* Packet Handling functions. */
135 int LibAliasIn (struct libalias *, char *_ptr, int _maxpacketsize);
136 int LibAliasOut(struct libalias *, char *_ptr, int _maxpacketsize);
137 int LibAliasOutTry(struct libalias *, char *_ptr, int _maxpacketsize, int _create);
138 int LibAliasUnaliasOut(struct libalias *, char *_ptr, int _maxpacketsize);
140 /* Port and address redirection functions. */
143 LibAliasAddServer(struct libalias *, struct alias_link *_lnk,
144 struct in_addr _addr, unsigned short _port);
146 LibAliasRedirectAddr(struct libalias *, struct in_addr _src_addr,
147 struct in_addr _alias_addr);
148 int LibAliasRedirectDynamic(struct libalias *, struct alias_link *_lnk);
149 void LibAliasRedirectDelete(struct libalias *, struct alias_link *_lnk);
151 LibAliasRedirectPort(struct libalias *, struct in_addr _src_addr,
152 unsigned short _src_port, struct in_addr _dst_addr,
153 unsigned short _dst_port, struct in_addr _alias_addr,
154 unsigned short _alias_port, unsigned char _proto);
156 LibAliasRedirectProto(struct libalias *, struct in_addr _src_addr,
157 struct in_addr _dst_addr, struct in_addr _alias_addr,
158 unsigned char _proto);
160 /* Fragment Handling functions. */
161 void LibAliasFragmentIn(struct libalias *, char *_ptr, char *_ptr_fragment);
162 char *LibAliasGetFragment(struct libalias *, char *_ptr);
163 int LibAliasSaveFragment(struct libalias *, char *_ptr);
165 /* Miscellaneous functions. */
166 int LibAliasCheckNewLink(struct libalias *);
168 LibAliasInternetChecksum(struct libalias *, unsigned short *_ptr, int _nbytes);
169 void LibAliasSetTarget(struct libalias *, struct in_addr _target_addr);
171 /* Transparent proxying routines. */
172 int LibAliasProxyRule(struct libalias *, const char *_cmd);
176 * Mode flags and other constants.
180 /* Mode flags, set using PacketAliasSetMode() */
183 * If PKT_ALIAS_LOG is set, a message will be printed to /var/log/alias.log
184 * every time a link is created or deleted. This is useful for debugging.
186 #define PKT_ALIAS_LOG 0x01
189 * If PKT_ALIAS_DENY_INCOMING is set, then incoming connections (e.g. to ftp,
190 * telnet or web servers will be prevented by the aliasing mechanism.
192 #define PKT_ALIAS_DENY_INCOMING 0x02
195 * If PKT_ALIAS_SAME_PORTS is set, packets will be attempted sent from the
196 * same port as they originated on. This allows e.g. rsh to work *99% of the
197 * time*, but _not_ 100% (it will be slightly flakey instead of not working
198 * at all). This mode bit is set by PacketAliasInit(), so it is a default
201 #define PKT_ALIAS_SAME_PORTS 0x04
204 * If PKT_ALIAS_USE_SOCKETS is set, then when partially specified links (e.g.
205 * destination port and/or address is zero), the packet aliasing engine will
206 * attempt to allocate a socket for the aliasing port it chooses. This will
207 * avoid interference with the host machine. Fully specified links do not
208 * require this. This bit is set after a call to PacketAliasInit(), so it is
209 * a default mode of operation.
211 #define PKT_ALIAS_USE_SOCKETS 0x08
214 * If PKT_ALIAS_UNREGISTERED_ONLY is set, then only packets with
215 * unregistered source addresses will be aliased. Private
216 * addresses are those in the following ranges:
218 * 10.0.0.0 -> 10.255.255.255
219 * 172.16.0.0 -> 172.31.255.255
220 * 192.168.0.0 -> 192.168.255.255
222 #define PKT_ALIAS_UNREGISTERED_ONLY 0x10
225 * If PKT_ALIAS_RESET_ON_ADDR_CHANGE is set, then the table of dynamic
226 * aliasing links will be reset whenever PacketAliasSetAddress() changes the
227 * default aliasing address. If the default aliasing address is left
228 * unchanged by this function call, then the table of dynamic aliasing links
229 * will be left intact. This bit is set after a call to PacketAliasInit().
231 #define PKT_ALIAS_RESET_ON_ADDR_CHANGE 0x20
235 * If PKT_ALIAS_PUNCH_FW is set, active FTP and IRC DCC connections will
236 * create a 'hole' in the firewall to allow the transfers to work. The
237 * ipfw rule number that the hole is created with is controlled by
238 * PacketAliasSetFWBase(). The hole will be attached to that
239 * particular alias_link, so when the link goes away the hole is deleted.
241 #define PKT_ALIAS_PUNCH_FW 0x100
245 * If PKT_ALIAS_PROXY_ONLY is set, then NAT will be disabled and only
246 * transparent proxying is performed.
248 #define PKT_ALIAS_PROXY_ONLY 0x40
251 * If PKT_ALIAS_REVERSE is set, the actions of PacketAliasIn() and
252 * PacketAliasOut() are reversed.
254 #define PKT_ALIAS_REVERSE 0x80
256 /* Function return codes. */
257 #define PKT_ALIAS_ERROR -1
258 #define PKT_ALIAS_OK 1
259 #define PKT_ALIAS_IGNORED 2
260 #define PKT_ALIAS_UNRESOLVED_FRAGMENT 3
261 #define PKT_ALIAS_FOUND_HEADER_FRAGMENT 4
263 #endif /* !_ALIAS_H_ */