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