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