Fix bug in identification timout handling.
[fwd] / addr.h
CommitLineData
479a34d9 1/* -*-c-*-
2 *
ee599f55 3 * $Id: addr.h,v 1.4 2003/11/29 20:36:07 mdw Exp $
479a34d9 4 *
5 * Generic interface to network address handlers
6 *
7 * (c) 1999 Straylight/Edgeware
8 */
9
10/*----- Licensing notice --------------------------------------------------*
11 *
12 * This file is part of the `fw' port forwarder.
13 *
14 * `fw' is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * `fw' is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with `fw'; if not, write to the Free Software Foundation,
26 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 */
28
29/*----- Revision history --------------------------------------------------*
30 *
31 * $Log: addr.h,v $
ee599f55 32 * Revision 1.4 2003/11/29 20:36:07 mdw
33 * Privileged outgoing connections.
34 *
0ac54f22 35 * Revision 1.3 2003/11/25 14:08:23 mdw
36 * Debianization. Socket target options. Internet binding.
37 *
e0ce9d38 38 * Revision 1.2 1999/07/27 18:30:53 mdw
39 * Various minor portability fixes.
40 *
479a34d9 41 * Revision 1.1 1999/07/26 23:34:26 mdw
42 * Socket address type management.
43 *
44 */
45
46#ifndef ADDR_H
47#define ADDR_H
48
49#ifdef __cplusplus
50 extern "C" {
51#endif
52
53/*----- Header files ------------------------------------------------------*/
54
e0ce9d38 55#include <sys/types.h>
479a34d9 56#include <sys/socket.h>
57
58#include <mLib/dstr.h>
0ac54f22 59#include <mLib/conn.h>
479a34d9 60
61#ifndef REFFD_H
62# include "reffd.h"
63#endif
64
0ac54f22 65#ifndef ENDPT_H
66# include "endpt.h"
67#endif
68
479a34d9 69#ifndef SCAN_H
70# include "scan.h"
71#endif
72
73/*----- Data structures ---------------------------------------------------*/
74
75/* --- A generic socket address --- *
76 *
77 * Not all systems understand @sa_len@ fields. (In particular, Linux
78 * doesn't.) Some fairly ugly hacking is then performed on particular
79 * address types.
80 */
81
82typedef struct addr {
83 struct addr_ops *ops;
84 size_t sz;
85} addr;
86
479a34d9 87#define ADDRSZ(sz) (sizeof(addr) + (sz))
88
89/* --- Address configuration --- *
90 *
91 * An address family will want to extend this.
92 */
93
94typedef struct addr_opts {
95 unsigned f;
96} addr_opts;
97
98#define ADDRF_NOLOG 1u
99
100/* --- Address types --- *
101 *
102 * For things like Internet addresses, source and destinations look
103 * different.
104 */
105
106enum {
107 ADDR_SRC,
0ac54f22 108 ADDR_DEST,
109 ADDR_GLOBAL
479a34d9 110};
111
112/* --- Description of an address type handler --- */
113
114typedef struct addr_ops {
115 const char *name; /* Protocol's internal name */
479a34d9 116
117 /* --- @read@ --- *
118 *
119 * Arguments: @scanner *sc@ = pointer to scanner to read from
120 * @unsigned type@ = type of address to be read
121 *
122 * Returns: A filled-in socket address.
123 *
124 * Use: Parses a textual representation of a socket address.
125 */
126
127 addr *(*read)(scanner */*sc*/, unsigned /*type*/);
128
129 /* --- @destroy@ --- *
130 *
131 * Arguments: @addr *a@ = pointer to an address block
132 *
133 * Returns: ---
134 *
135 * Use: Disposes of an address block in some suitable fashion.
136 */
137
138 void (*destroy)(addr */*a*/);
139
140 /* --- @print@ --- *
141 *
142 * Arguments: @addr *a@ = pointer to socket address to read
143 * @unsigned type@ = type of address to be written
144 * @dstr *d@ = string on which to write the description
145 *
146 * Returns: ---
147 *
148 * Use: Writes a textual representation of a socket address to
149 * a string.
150 */
151
152 void (*print)(addr */*a*/, unsigned /*type*/, dstr */*d*/);
153
0ac54f22 154 /* --- @initsrcopts@ --- *
479a34d9 155 *
156 * Arguments: ---
157 *
158 * Returns: A pointer to a protocol-specific data block for a listener
159 *
160 * Use: Creates a data block for a listener. This is attached to the
161 * listener data structure. Options can then be requested, and
162 * are added to the block when necessary.
163 */
164
0ac54f22 165 addr_opts *(*initsrcopts)(void);
479a34d9 166
167 /* --- @option@ --- *
168 *
169 * Arguments: @scanner *sc@ = pointer to a scanner to read from
0ac54f22 170 * @unsigned type@ = kind of option this is
479a34d9 171 * @addr_opts *ao@ = data block to modify (from @init@), or null
172 *
173 * Returns: Nonzero to claim the option.
174 *
0ac54f22 175 * Use: Parses a source option, either global or listener-specific.
176 */
177
178 int (*option)(scanner */*sc*/, addr_opts */*ao*/, unsigned /*type*/);
179
ee599f55 180 /* --- @confirm@ --- *
181 *
182 * Arguments: @addr *a@ = pointer to an address structure
183 * @unsigned type@ = kind of address this is
184 * @addr_opts *ao@ = address options
185 *
186 * Returns: ---
187 *
188 * Use: Called during initialization when an address is fully
189 * configured.
190 */
191
192 void (*confirm)(addr */*a*/, unsigned /*type*/, addr_opts */*ao*/);
193
0ac54f22 194 /* --- @freesrcopts@ --- *
195 *
196 * Arguments: @addr_opts *ao@ = data block to remove
197 *
198 * Returns: ---
199 *
200 * Use: Throws away all the configuration data for an address type.
201 */
202
203 void (*freesrcopts)(addr_opts */*ao*/);
204
205 /* --- @bind@ --- *
206 *
207 * Arguments: @addr *a@ = the address to bind to
208 * @addr_opts *ao@ = the address options
209 *
210 * Returns: File descriptor of bound socket if OK, or @-1@ on error.
211 *
212 * Use: Binds a listening socket. The tedious stuff with @listen@
213 * isn't necessary.
214 */
215
216 int (*bind)(addr */*a*/, addr_opts */*ao*/);
217
218 /* --- @unbind@ --- *
219 *
220 * Arguments: @addr *a@ = pointer to an address
221 *
222 * Returns: ---
223 *
224 * Use: Unbinds an address. This is used when tidying up. The main
225 * purpose is to let the Unix-domain handler remove its socket
226 * node from the filesystem.
479a34d9 227 */
228
0ac54f22 229 void (*unbind)(addr */*a*/);
479a34d9 230
231 /* --- @accept@ --- *
232 *
233 * Arguments: @int fd@ = listening file descriptor
234 * @addr_opts *ao@ = data block to get configuration from
235 * @const char *desc@ = description of the listener
236 *
237 * Returns: Pointer to a reference counted file descriptor.
238 *
239 * Use: Accepts, verifies and logs an incoming connection.
240 */
241
242 reffd *(*accept)(int /*fd*/, addr_opts */*ao*/, const char */*desc*/);
243
0ac54f22 244 /* --- @inittargopts@ --- *
479a34d9 245 *
0ac54f22 246 * Arguments: ---
479a34d9 247 *
0ac54f22 248 * Returns: A pointer to a protocol-specific data block for a connecter
479a34d9 249 *
0ac54f22 250 * Use: Creates a data block for a target. This is attached to the
251 * target data structure. Options can then be requested, and
252 * are added to the block when necessary.
479a34d9 253 */
254
0ac54f22 255 addr_opts *(*inittargopts)(void);
479a34d9 256
0ac54f22 257 /* --- @freetargopts@ --- *
479a34d9 258 *
0ac54f22 259 * Arguments: @addr_opts *ao@ = data block to remove
479a34d9 260 *
261 * Returns: ---
262 *
0ac54f22 263 * Use: Throws away all the configuration data for an address type.
479a34d9 264 */
265
0ac54f22 266 void (*freetargopts)(addr_opts */*ao*/);
479a34d9 267
0ac54f22 268 /* --- @connect@ --- *
479a34d9 269 *
0ac54f22 270 * Arguments: @addr *a@ = destination address
271 * @addr_opts *ao@ = target address options
272 * @conn *c@ = connection structure
273 * @endpt *e@ = endpoint structure
479a34d9 274 *
0ac54f22 275 * Returns: Zero if OK, @-1@ on some error.
479a34d9 276 *
0ac54f22 277 * Use: Requests that a connection be made, or at least set in
278 * motion. An address may do one of these things:
279 *
280 * * Return @-1@.
281 *
282 * * Call @starget_connected@ with @-1@ or a connected file
283 * descriptor and the pointer @e@.
284 *
285 * * Call @conn_init@ or @conn_fd@, giving @starget_connected@
286 * and @e@ as the function to call.
479a34d9 287 */
288
0ac54f22 289 int (*connect)(addr */*a*/, addr_opts */*ao*/, conn */*c*/, endpt */*e*/);
479a34d9 290
291} addr_ops;
292
293/*----- That's all, folks -------------------------------------------------*/
294
295#ifdef __cplusplus
296 }
297#endif
298
299#endif