1 /* lint -save -library Flexelint comment for external headers */
4 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
6 * Copyright (c) 2001 Charles Mott <cm@linktel.net>
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * Alias.h defines the outside world interfaces for the packet aliasing
37 * This software is placed into the public domain with no restrictions on its
44 #include <netinet/in_systm.h>
45 #include <netinet/in.h>
46 #include <netinet/ip.h>
48 #define LIBALIAS_BUF_SIZE 128
51 * The kernel version of libalias does not support these features.
54 #define NO_USE_SOCKETS
58 * The external interface to libalias, the packet aliasing engine.
60 * There are two sets of functions:
62 * PacketAlias*() the old API which doesn't take an instance pointer
63 * and therefore can only have one packet engine at a time.
65 * LibAlias*() the new API which takes as first argument a pointer to
66 * the instance of the packet aliasing engine.
68 * The functions otherwise correspond to each other one for one, except
69 * for the LibAliasUnaliasOut()/PacketUnaliasOut() function which were
70 * were misnamed in the old API.
74 * The instance structure
79 * An anonymous structure, a pointer to which is returned from
80 * PacketAliasRedirectAddr(), PacketAliasRedirectPort() or
81 * PacketAliasRedirectProto(), passed to PacketAliasAddServer(),
82 * and freed by PacketAliasRedirectDelete().
86 /* Initialization and control functions. */
87 struct libalias *LibAliasInit(struct libalias *);
88 void LibAliasSetAddress(struct libalias *, struct in_addr _addr);
89 void LibAliasSetFWBase(struct libalias *, unsigned int _base, unsigned int _num);
90 void LibAliasSetSkinnyPort(struct libalias *, unsigned int _port);
92 LibAliasSetMode(struct libalias *, unsigned int _flags, unsigned int _mask);
93 void LibAliasUninit(struct libalias *);
95 /* Packet Handling functions. */
96 int LibAliasIn (struct libalias *, char *_ptr, int _maxpacketsize);
97 int LibAliasOut(struct libalias *, char *_ptr, int _maxpacketsize);
98 int LibAliasOutTry(struct libalias *, char *_ptr, int _maxpacketsize, int _create);
99 int LibAliasUnaliasOut(struct libalias *, char *_ptr, int _maxpacketsize);
101 /* Port and address redirection functions. */
104 LibAliasAddServer(struct libalias *, struct alias_link *_lnk,
105 struct in_addr _addr, unsigned short _port);
107 LibAliasRedirectAddr(struct libalias *, struct in_addr _src_addr,
108 struct in_addr _alias_addr);
109 int LibAliasRedirectDynamic(struct libalias *, struct alias_link *_lnk);
110 void LibAliasRedirectDelete(struct libalias *, struct alias_link *_lnk);
112 LibAliasRedirectPort(struct libalias *, struct in_addr _src_addr,
113 unsigned short _src_port, struct in_addr _dst_addr,
114 unsigned short _dst_port, struct in_addr _alias_addr,
115 unsigned short _alias_port, unsigned char _proto);
117 LibAliasRedirectProto(struct libalias *, struct in_addr _src_addr,
118 struct in_addr _dst_addr, struct in_addr _alias_addr,
119 unsigned char _proto);
121 /* Fragment Handling functions. */
122 void LibAliasFragmentIn(struct libalias *, char *_ptr, char *_ptr_fragment);
123 char *LibAliasGetFragment(struct libalias *, char *_ptr);
124 int LibAliasSaveFragment(struct libalias *, char *_ptr);
126 /* Miscellaneous functions. */
127 int LibAliasCheckNewLink(struct libalias *);
129 LibAliasInternetChecksum(struct libalias *, unsigned short *_ptr, int _nbytes);
130 void LibAliasSetTarget(struct libalias *, struct in_addr _target_addr);
132 /* Transparent proxying routines. */
133 int LibAliasProxyRule(struct libalias *, const char *_cmd);
135 /* Module handling API */
136 int LibAliasLoadModule(char *);
137 int LibAliasUnLoadAllModule(void);
138 int LibAliasRefreshModules(void);
140 /* Mbuf helper function. */
141 struct mbuf *m_megapullup(struct mbuf *, int);
144 * Mode flags and other constants.
148 /* Mode flags, set using PacketAliasSetMode() */
151 * If PKT_ALIAS_LOG is set, a message will be printed to /var/log/alias.log
152 * every time a link is created or deleted. This is useful for debugging.
154 #define PKT_ALIAS_LOG 0x01
157 * If PKT_ALIAS_DENY_INCOMING is set, then incoming connections (e.g. to ftp,
158 * telnet or web servers will be prevented by the aliasing mechanism.
160 #define PKT_ALIAS_DENY_INCOMING 0x02
163 * If PKT_ALIAS_SAME_PORTS is set, packets will be attempted sent from the
164 * same port as they originated on. This allows e.g. rsh to work *99% of the
165 * time*, but _not_ 100% (it will be slightly flakey instead of not working
166 * at all). This mode bit is set by PacketAliasInit(), so it is a default
169 #define PKT_ALIAS_SAME_PORTS 0x04
172 * If PKT_ALIAS_USE_SOCKETS is set, then when partially specified links (e.g.
173 * destination port and/or address is zero), the packet aliasing engine will
174 * attempt to allocate a socket for the aliasing port it chooses. This will
175 * avoid interference with the host machine. Fully specified links do not
176 * require this. This bit is set after a call to PacketAliasInit(), so it is
177 * a default mode of operation.
179 #ifndef NO_USE_SOCKETS
180 #define PKT_ALIAS_USE_SOCKETS 0x08
183 * If PKT_ALIAS_UNREGISTERED_ONLY is set, then only packets with
184 * unregistered source addresses will be aliased. Private
185 * addresses are those in the following ranges:
187 * 10.0.0.0 -> 10.255.255.255
188 * 172.16.0.0 -> 172.31.255.255
189 * 192.168.0.0 -> 192.168.255.255
191 #define PKT_ALIAS_UNREGISTERED_ONLY 0x10
194 * If PKT_ALIAS_RESET_ON_ADDR_CHANGE is set, then the table of dynamic
195 * aliasing links will be reset whenever PacketAliasSetAddress() changes the
196 * default aliasing address. If the default aliasing address is left
197 * unchanged by this function call, then the table of dynamic aliasing links
198 * will be left intact. This bit is set after a call to PacketAliasInit().
200 #define PKT_ALIAS_RESET_ON_ADDR_CHANGE 0x20
203 * If PKT_ALIAS_PROXY_ONLY is set, then NAT will be disabled and only
204 * transparent proxying is performed.
206 #define PKT_ALIAS_PROXY_ONLY 0x40
209 * If PKT_ALIAS_REVERSE is set, the actions of PacketAliasIn() and
210 * PacketAliasOut() are reversed.
212 #define PKT_ALIAS_REVERSE 0x80
216 * If PKT_ALIAS_PUNCH_FW is set, active FTP and IRC DCC connections will
217 * create a 'hole' in the firewall to allow the transfers to work. The
218 * ipfw rule number that the hole is created with is controlled by
219 * PacketAliasSetFWBase(). The hole will be attached to that
220 * particular alias_link, so when the link goes away the hole is deleted.
222 #define PKT_ALIAS_PUNCH_FW 0x100
226 * If PKT_ALIAS_SKIP_GLOBAL is set, nat instance is not checked for matching
227 * states in 'ipfw nat global' rule.
229 #define PKT_ALIAS_SKIP_GLOBAL 0x200
231 /* Function return codes. */
232 #define PKT_ALIAS_ERROR -1
233 #define PKT_ALIAS_OK 1
234 #define PKT_ALIAS_IGNORED 2
235 #define PKT_ALIAS_UNRESOLVED_FRAGMENT 3
236 #define PKT_ALIAS_FOUND_HEADER_FRAGMENT 4
238 #endif /* !_ALIAS_H_ */