]> git.saurik.com Git - apple/network_cmds.git/blob - alias/alias.h
f6df7fcf5a2f5320711ae63e6c18f71f3b71c4ff
[apple/network_cmds.git] / alias / alias.h
1 /*
2 * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /*-
26 * Copyright (c) 2001 Charles Mott <cmott@scientech.com>
27 * All rights reserved.
28 *
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
31 * are met:
32 * 1. Redistributions of source code must retain the above copyright
33 * notice, this list of conditions and the following disclaimer.
34 * 2. Redistributions in binary form must reproduce the above copyright
35 * notice, this list of conditions and the following disclaimer in the
36 * documentation and/or other materials provided with the distribution.
37 *
38 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
39 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
41 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
42 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
43 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
44 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
45 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
46 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
47 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
48 * SUCH DAMAGE.
49 *
50 * Based upon:
51 * $FreeBSD: src/lib/libalias/alias.h,v 1.12.2.4 2001/08/01 09:36:40 obrien Exp $
52 */
53
54 /*-
55 * Alias.h defines the outside world interfaces for the packet aliasing
56 * software.
57 *
58 * This software is placed into the public domain with no restrictions on its
59 * distribution.
60 */
61
62 #ifndef _ALIAS_H_
63 #define _ALIAS_H_
64
65 /* Alias link representative (incomplete struct) */
66 struct alias_link;
67
68 /* External interfaces (API) to packet aliasing engine */
69
70 /* Initialization and Control */
71 extern void
72 PacketAliasInit(void);
73
74 extern void
75 PacketAliasUninit(void);
76
77 extern void
78 PacketAliasSetAddress(struct in_addr);
79
80 extern unsigned int
81 PacketAliasSetMode(unsigned int, unsigned int);
82
83 #ifndef NO_FW_PUNCH
84 extern void
85 PacketAliasSetFWBase(unsigned int, unsigned int);
86 #endif
87
88 extern void
89 PacketAliasClampMSS(u_short mss);
90
91 /* Packet Handling */
92 extern int
93 PacketAliasIn(char *, int maxpacketsize);
94
95 extern int
96 PacketAliasOut(char *, int maxpacketsize);
97
98 extern int
99 PacketUnaliasOut(char *, int maxpacketsize);
100
101 /* Port and Address Redirection */
102 extern struct alias_link *
103 PacketAliasRedirectPort(struct in_addr, u_short,
104 struct in_addr, u_short,
105 struct in_addr, u_short,
106 u_char);
107
108 extern int
109 PacketAliasAddServer(struct alias_link *link,
110 struct in_addr addr,
111 u_short port);
112
113 extern struct alias_link *
114 PacketAliasRedirectProto(struct in_addr,
115 struct in_addr,
116 struct in_addr,
117 u_char);
118
119 extern struct alias_link *
120 PacketAliasRedirectAddr(struct in_addr,
121 struct in_addr);
122
123 extern void
124 PacketAliasRedirectDelete(struct alias_link *);
125
126 /* Fragment Handling */
127 extern int
128 PacketAliasSaveFragment(char *);
129
130 extern char *
131 PacketAliasGetFragment(char *);
132
133 extern void
134 PacketAliasFragmentIn(char *, char *);
135
136 /* Miscellaneous Functions */
137 extern void
138 PacketAliasSetTarget(struct in_addr addr);
139
140 extern int
141 PacketAliasCheckNewLink(void);
142
143 extern u_short
144 PacketAliasInternetChecksum(u_short *, int);
145
146 /* Transparent Proxying */
147 extern int
148 PacketAliasProxyRule(const char *);
149
150
151 /********************** Mode flags ********************/
152 /* Set these flags using PacketAliasSetMode() */
153
154 /* If PKT_ALIAS_LOG is set, a message will be printed to
155 /var/log/alias.log every time a link is created or deleted. This
156 is useful for debugging */
157 #define PKT_ALIAS_LOG 0x01
158
159 /* If PKT_ALIAS_DENY_INCOMING is set, then incoming connections (e.g.
160 to ftp, telnet or web servers will be prevented by the aliasing
161 mechanism. */
162 #define PKT_ALIAS_DENY_INCOMING 0x02
163
164 /* If PKT_ALIAS_SAME_PORTS is set, packets will be attempted sent from
165 the same port as they originated on. This allows e.g. rsh to work
166 *99% of the time*, but _not_ 100%. (It will be slightly flakey
167 instead of not working at all.) This mode bit is set by
168 PacketAliasInit(), so it is a default mode of operation. */
169 #define PKT_ALIAS_SAME_PORTS 0x04
170
171 /* If PKT_ALIAS_USE_SOCKETS is set, then when partially specified
172 links (e.g. destination port and/or address is zero), the packet
173 aliasing engine will attempt to allocate a socket for the aliasing
174 port it chooses. This will avoid interference with the host
175 machine. Fully specified links do not require this. This bit
176 is set after a call to PacketAliasInit(), so it is a default
177 mode of operation. */
178 #define PKT_ALIAS_USE_SOCKETS 0x08
179
180 /* If PKT_ALIAS_UNREGISTERED_ONLY is set, then only packets with
181 unregistered source addresses will be aliased. Private
182 addresses are those in the following ranges:
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 #define PKT_ALIAS_UNREGISTERED_ONLY 0x10
187
188 /* If PKT_ALIAS_RESET_ON_ADDR_CHANGE is set, then the table of dynamic
189 aliasing links will be reset whenever PacketAliasSetAddress()
190 changes the default aliasing address. If the default aliasing
191 address is left unchanged by this function call, then the
192 table of dynamic aliasing links will be left intact. This
193 bit is set after a call to PacketAliasInit(). */
194 #define PKT_ALIAS_RESET_ON_ADDR_CHANGE 0x20
195
196 #ifndef NO_FW_PUNCH
197 /* If PKT_ALIAS_PUNCH_FW is set, active FTP and IRC DCC connections
198 will create a 'hole' in the firewall to allow the transfers to
199 work. Where (IPFW "line-numbers") the hole is created is
200 controlled by PacketAliasSetFWBase(base, size). The hole will be
201 attached to that particular alias_link, so when the link goes away
202 so do the hole. */
203 #define PKT_ALIAS_PUNCH_FW 0x100
204 #endif
205
206 /* If PKT_ALIAS_PROXY_ONLY is set, then NAT will be disabled and only
207 transparent proxying performed */
208 #define PKT_ALIAS_PROXY_ONLY 0x40
209
210 /* If PKT_ALIAS_REVERSE is set, the actions of PacketAliasIn()
211 and PacketAliasOut() are reversed */
212 #define PKT_ALIAS_REVERSE 0x80
213
214 /* Return Codes */
215 #define PKT_ALIAS_ERROR -1
216 #define PKT_ALIAS_OK 1
217 #define PKT_ALIAS_IGNORED 2
218 #define PKT_ALIAS_UNRESOLVED_FRAGMENT 3
219 #define PKT_ALIAS_FOUND_HEADER_FRAGMENT 4
220
221 #endif
222 /* lint -restore */