1 /* lint -save -library Flexelint comment for external headers */ 2 3 /*- 4 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 5 * 6 * Copyright (c) 2001 Charles Mott <cm@linktel.net> 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 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. 17 * 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 28 * SUCH DAMAGE. 29 * 30 * $FreeBSD: stable/12/sys/netinet/libalias/alias.h 369956 2021-06-07 05:53:38Z donner $ 31 */ 32 33 /* 34 * Alias.h defines the outside world interfaces for the packet aliasing 35 * software. 36 * 37 * This software is placed into the public domain with no restrictions on its 38 * distribution. 39 */ 40 41 #ifndef _ALIAS_H_ 42 #define _ALIAS_H_ 43 44 #include <netinet/in_systm.h> 45 #include <netinet/in.h> 46 #include <netinet/ip.h> 47 48 #define LIBALIAS_BUF_SIZE 128 49 #ifdef _KERNEL 50 /* 51 * The kernel version of libalias does not support these features. 52 */ 53 #define NO_FW_PUNCH 54 #define NO_USE_SOCKETS 55 #endif 56 57 /* 58 * The external interface to libalias, the packet aliasing engine. 59 * 60 * There are two sets of functions: 61 * 62 * PacketAlias*() the old API which doesn't take an instance pointer 63 * and therefore can only have one packet engine at a time. 64 * 65 * LibAlias*() the new API which takes as first argument a pointer to 66 * the instance of the packet aliasing engine. 67 * 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. 71 */ 72 73 /* 74 * The instance structure 75 */ 76 struct libalias; 77 78 /* 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(). 83 */ 84 struct alias_link; 85 86 /* Initialization and control functions. */ 87 struct libalias *LibAliasInit(struct libalias *); 88 void LibAliasSetAddress(struct libalias *, struct in_addr _addr); 89 void LibAliasSetAliasPortRange(struct libalias *la, u_short port_low, u_short port_hi); 90 void LibAliasSetFWBase(struct libalias *, unsigned int _base, unsigned int _num); 91 void LibAliasSetSkinnyPort(struct libalias *, unsigned int _port); 92 unsigned int LibAliasSetMode(struct libalias *, unsigned int _flags, unsigned int _mask); 93 void LibAliasUninit(struct libalias *); 94 95 /* Packet Handling functions. */ 96 int LibAliasIn (struct libalias *, void *_ptr, int _maxpacketsize); 97 int LibAliasOut(struct libalias *, void *_ptr, int _maxpacketsize); 98 int LibAliasOutTry(struct libalias *, void *_ptr, int _maxpacketsize, int _create); 99 int LibAliasUnaliasOut(struct libalias *, void *_ptr, int _maxpacketsize); 100 101 /* Port and address redirection functions. */ 102 103 int LibAliasAddServer(struct libalias *, struct alias_link *_lnk, 104 struct in_addr _addr, unsigned short _port); 105 struct alias_link * LibAliasRedirectAddr(struct libalias *, struct in_addr _src_addr, 106 struct in_addr _alias_addr); 107 int LibAliasRedirectDynamic(struct libalias *, struct alias_link *_lnk); 108 void LibAliasRedirectDelete(struct libalias *, struct alias_link *_lnk); 109 struct alias_link * LibAliasRedirectPort(struct libalias *, struct in_addr _src_addr, 110 unsigned short _src_port, struct in_addr _dst_addr, 111 unsigned short _dst_port, struct in_addr _alias_addr, 112 unsigned short _alias_port, unsigned char _proto); 113 struct alias_link * LibAliasRedirectProto(struct libalias *, struct in_addr _src_addr, 114 struct in_addr _dst_addr, struct in_addr _alias_addr, 115 unsigned char _proto); 116 117 /* Fragment Handling functions. */ 118 void LibAliasFragmentIn(struct libalias *, void *_ptr, void *_ptr_fragment); 119 void *LibAliasGetFragment(struct libalias *, void *_ptr); 120 int LibAliasSaveFragment(struct libalias *, void *_ptr); 121 122 /* Miscellaneous functions. */ 123 unsigned short LibAliasInternetChecksum(struct libalias *, unsigned short *_ptr, int _nbytes); 124 void LibAliasSetTarget(struct libalias *, struct in_addr _target_addr); 125 126 /* never used and never worked, to be removed in FreeBSD 14 */ 127 int LibAliasCheckNewLink(struct libalias *); 128 129 /* Transparent proxying routines. */ 130 int LibAliasProxyRule(struct libalias *, const char *_cmd); 131 132 /* Module handling API */ 133 int LibAliasLoadModule(char *); 134 int LibAliasUnLoadAllModule(void); 135 int LibAliasRefreshModules(void); 136 137 /* Mbuf helper function. */ 138 struct mbuf *m_megapullup(struct mbuf *, int); 139 140 /* 141 * Mode flags and other constants. 142 */ 143 144 /* Mode flags, set using PacketAliasSetMode() */ 145 146 /* 147 * If PKT_ALIAS_LOG is set, a message will be printed to /var/log/alias.log 148 * every time a link is created or deleted. This is useful for debugging. 149 */ 150 #define PKT_ALIAS_LOG 0x01 151 152 /* 153 * If PKT_ALIAS_DENY_INCOMING is set, then incoming connections (e.g. to ftp, 154 * telnet or web servers will be prevented by the aliasing mechanism. 155 */ 156 #define PKT_ALIAS_DENY_INCOMING 0x02 157 158 /* 159 * If PKT_ALIAS_SAME_PORTS is set, packets will be attempted sent from the 160 * same port as they originated on. This allows e.g. rsh to work *99% of the 161 * time*, but _not_ 100% (it will be slightly flakey instead of not working 162 * at all). This mode bit is set by PacketAliasInit(), so it is a default 163 * mode of operation. 164 */ 165 #define PKT_ALIAS_SAME_PORTS 0x04 166 167 /* 168 * If PKT_ALIAS_USE_SOCKETS is set, then when partially specified links (e.g. 169 * destination port and/or address is zero), the packet aliasing engine will 170 * attempt to allocate a socket for the aliasing port it chooses. This will 171 * avoid interference with the host machine. Fully specified links do not 172 * require this. This bit is set after a call to PacketAliasInit(), so it is 173 * a default mode of operation. 174 */ 175 #ifndef NO_USE_SOCKETS 176 #define PKT_ALIAS_USE_SOCKETS 0x08 177 #endif 178 /*- 179 * If PKT_ALIAS_UNREGISTERED_ONLY is set, then only packets with 180 * unregistered source addresses will be aliased. Private 181 * addresses are those in the following ranges: 182 * 183 * 10.0.0.0 -> 10.255.255.255 184 * 172.16.0.0 -> 172.31.255.255 185 * 192.168.0.0 -> 192.168.255.255 186 */ 187 #define PKT_ALIAS_UNREGISTERED_ONLY 0x10 188 189 /* 190 * If PKT_ALIAS_RESET_ON_ADDR_CHANGE is set, then the table of dynamic 191 * aliasing links will be reset whenever PacketAliasSetAddress() changes the 192 * default aliasing address. If the default aliasing address is left 193 * unchanged by this function call, then the table of dynamic aliasing links 194 * will be left intact. This bit is set after a call to PacketAliasInit(). 195 */ 196 #define PKT_ALIAS_RESET_ON_ADDR_CHANGE 0x20 197 198 /* 199 * If PKT_ALIAS_PROXY_ONLY is set, then NAT will be disabled and only 200 * transparent proxying is performed. 201 */ 202 #define PKT_ALIAS_PROXY_ONLY 0x40 203 204 /* 205 * If PKT_ALIAS_REVERSE is set, the actions of PacketAliasIn() and 206 * PacketAliasOut() are reversed. 207 */ 208 #define PKT_ALIAS_REVERSE 0x80 209 210 #ifndef NO_FW_PUNCH 211 /* 212 * If PKT_ALIAS_PUNCH_FW is set, active FTP and IRC DCC connections will 213 * create a 'hole' in the firewall to allow the transfers to work. The 214 * ipfw rule number that the hole is created with is controlled by 215 * PacketAliasSetFWBase(). The hole will be attached to that 216 * particular alias_link, so when the link goes away the hole is deleted. 217 */ 218 #define PKT_ALIAS_PUNCH_FW 0x100 219 #endif 220 221 /* 222 * If PKT_ALIAS_SKIP_GLOBAL is set, nat instance is not checked for matching 223 * states in 'ipfw nat global' rule. 224 */ 225 #define PKT_ALIAS_SKIP_GLOBAL 0x200 226 227 /* 228 * Like PKT_ALIAS_UNREGISTERED_ONLY, but includes the RFC 6598 229 * (Carrier Grade NAT) address range as follows: 230 * 231 * 100.64.0.0 -> 100.127.255.255 232 */ 233 #define PKT_ALIAS_UNREGISTERED_CGN 0x400 234 235 /* Function return codes. */ 236 #define PKT_ALIAS_ERROR -1 237 #define PKT_ALIAS_OK 1 238 #define PKT_ALIAS_IGNORED 2 239 #define PKT_ALIAS_UNRESOLVED_FRAGMENT 3 240 #define PKT_ALIAS_FOUND_HEADER_FRAGMENT 4 241 242 #endif /* !_ALIAS_H_ */ 243 244 /* lint -restore */ 245