nexmon – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | /* source: xio.h */ |
2 | /* Copyright Gerhard Rieger */ |
||
3 | /* Published under the GNU General Public License V.2, see file COPYING */ |
||
4 | |||
5 | #ifndef __xio_h_included |
||
6 | #define __xio_h_included 1 |
||
7 | |||
8 | #if 1 /*!*/ |
||
9 | #include "mytypes.h" |
||
10 | #include "sysutils.h" |
||
11 | #endif |
||
12 | |||
13 | #define XIO_MAXSOCK 2 |
||
14 | |||
15 | /* Linux 2.2.10 */ |
||
16 | #define HAVE_STRUCT_LINGER 1 |
||
17 | |||
18 | #define LINETERM_RAW 0 |
||
19 | #define LINETERM_CR 1 |
||
20 | #define LINETERM_CRNL 2 |
||
21 | |||
22 | union xioaddr_desc; |
||
23 | struct opt; |
||
24 | |||
25 | /* the flags argument of xioopen */ |
||
26 | #define XIO_RDONLY O_RDONLY /* asserted to be 0 */ |
||
27 | #define XIO_WRONLY O_WRONLY /* asserted to be 1 */ |
||
28 | #define XIO_RDWR O_RDWR /* asserted to be 2 */ |
||
29 | #define XIO_ACCMODE O_ACCMODE /* must be 3 */ |
||
30 | /* 3 is undefined */ |
||
31 | #define XIO_MAYFORK 4 /* address is allowed to fork the program (fork), |
||
32 | especially with listen and connect addresses */ |
||
33 | #define XIO_MAYCHILD 8 /* address is allowed to fork off a child that |
||
34 | exec's another program or calls system() */ |
||
35 | #define XIO_MAYEXEC 16 /* address is allowed to exec a prog (exec+nofork) */ |
||
36 | #define XIO_MAYCONVERT 32 /* address is allowed to perform modifications on the |
||
37 | stream data, e.g. SSL, READLINE; CRLF */ |
||
38 | #define XIO_MAYCHAIN 64 /* address is allowed to consist of a chain of |
||
39 | subaddresses that are handled by socat |
||
40 | subprocesses */ |
||
41 | #define XIO_EMBEDDED 256 /* address is nonterminal */ |
||
42 | #define XIO_MAYALL INT_MAX /* all features enabled */ |
||
43 | |||
44 | /* the status flags of xiofile_t */ |
||
45 | #define XIO_DOESFORK XIO_MAYFORK |
||
46 | #define XIO_DOESCHILD XIO_MAYCHILD |
||
47 | #define XIO_DOESEXEC XIO_MAYEXEC |
||
48 | #define XIO_DOESCONVERT XIO_MAYCONVERT |
||
49 | #define XIO_DOESCHAIN XIO_MAYCHAIN |
||
50 | |||
51 | /* sometimes we use a set of allowed direction(s), a bit pattern */ |
||
52 | #define XIOBIT_RDONLY (1<<XIO_RDONLY) |
||
53 | #define XIOBIT_WRONLY (1<<XIO_WRONLY) |
||
54 | #define XIOBIT_RDWR (1<<XIO_RDWR) |
||
55 | #define XIOBIT_ALL (XIOBIT_RDONLY|XIOBIT_WRONLY|XIOBIT_RDWR) |
||
56 | #define XIOBIT_ALLRD (XIOBIT_RDONLY|XIOBIT_RDWR) |
||
57 | #define XIOBIT_ALLWR (XIOBIT_WRONLY|XIOBIT_RDWR) |
||
58 | #define XIOBIT_ONE (XIOBIT_RDONLY|XIOBIT_WRONLY) |
||
59 | /* reverse the direction pattern */ |
||
60 | #define XIOBIT_REVERSE(x) (((x)&XIOBIT_RDWR)|(((x)&XIOBIT_RDONLY)?XIOBIT_WRONLY:0)|(((x)&XIOBIT_WRONLY)?XIOBIT_RDONLY:0)) |
||
61 | |||
62 | #define XIOWITHRD(rw) ((rw+1)&(XIO_RDONLY+1)) |
||
63 | #define XIOWITHWR(rw) ((rw+1)&(XIO_WRONLY+1)) |
||
64 | |||
65 | /* methods for reading and writing, and for related checks */ |
||
66 | #define XIODATA_READMASK 0xf000 /* mask for basic r/w method */ |
||
67 | #define XIOREAD_STREAM 0x1000 /* read() (default) */ |
||
68 | #define XIOREAD_RECV 0x2000 /* recvfrom() */ |
||
69 | #define XIOREAD_PTY 0x4000 /* handle EIO */ |
||
70 | #define XIOREAD_READLINE 0x5000 /* ... */ |
||
71 | #define XIOREAD_OPENSSL 0x6000 /* SSL_read() */ |
||
72 | #define XIOREAD_TEST 0x7000 /* xioread_test() */ |
||
73 | #define XIODATA_WRITEMASK 0x0f00 /* mask for basic r/w method */ |
||
74 | #define XIOWRITE_STREAM 0x0100 /* write() (default) */ |
||
75 | #define XIOWRITE_SENDTO 0x0200 /* sendto() */ |
||
76 | #define XIOWRITE_PIPE 0x0300 /* write() to alternate (pipe) Fd */ |
||
77 | #define XIOWRITE_2PIPE 0x0400 /* write() to alternate (2pipe) Fd */ |
||
78 | #define XIOWRITE_READLINE 0x0500 /* check for prompt */ |
||
79 | #define XIOWRITE_OPENSSL 0x0600 /* SSL_write() */ |
||
80 | #define XIOWRITE_TEST 0x0700 /* xiowrite_test() */ |
||
81 | #define XIOWRITE_TESTREV 0x0800 /* xiowrite_testrev() */ |
||
82 | /* modifiers to XIODATA_READ_RECV */ |
||
83 | #define XIOREAD_RECV_CHECKPORT 0x0001 /* recv, check peer port */ |
||
84 | #define XIOREAD_RECV_CHECKADDR 0x0002 /* recv, check peer address */ |
||
85 | #define XIOREAD_RECV_CHECKRANGE 0x0004 /* recv, check if peer addr in range */ |
||
86 | #define XIOREAD_RECV_ONESHOT 0x0008 /* give EOF after first packet */ |
||
87 | #define XIOREAD_RECV_SKIPIP 0x0010 /* recv, skip IPv4 header */ |
||
88 | #define XIOREAD_RECV_FROM 0x0020 /* remember peer for replying */ |
||
89 | |||
90 | /* combinations */ |
||
91 | #define XIODATA_MASK (XIODATA_READMASK|XIODATA_WRITEMASK) |
||
92 | #define XIODATA_STREAM (XIOREAD_STREAM|XIOWRITE_STREAM) |
||
93 | #define XIODATA_RECVFROM (XIOREAD_RECV|XIOWRITE_SENDTO|XIOREAD_RECV_CHECKPORT|XIOREAD_RECV_CHECKADDR|XIOREAD_RECV_FROM) |
||
94 | #define XIODATA_RECVFROM_SKIPIP (XIODATA_RECVFROM|XIOREAD_RECV_SKIPIP) |
||
95 | #define XIODATA_RECVFROM_ONE (XIODATA_RECVFROM|XIOREAD_RECV_ONESHOT) |
||
96 | #define XIODATA_RECVFROM_SKIPIP_ONE (XIODATA_RECVFROM_SKIPIP|XIOREAD_RECV_ONESHOT) |
||
97 | #define XIODATA_RECV (XIOREAD_RECV|XIOWRITE_SENDTO|XIOREAD_RECV_CHECKRANGE) |
||
98 | #define XIODATA_RECV_SKIPIP (XIODATA_RECV|XIOREAD_RECV_SKIPIP) |
||
99 | #define XIODATA_PIPE (XIOREAD_STREAM|XIOWRITE_PIPE) |
||
100 | #define XIODATA_2PIPE (XIOREAD_STREAM|XIOWRITE_2PIPE) |
||
101 | #define XIODATA_PTY (XIOREAD_PTY|XIOWRITE_STREAM) |
||
102 | #define XIODATA_READLINE (XIOREAD_READLINE|XIOWRITE_STREAM) |
||
103 | #define XIODATA_OPENSSL (XIOREAD_OPENSSL|XIOWRITE_OPENSSL) |
||
104 | #define XIODATA_TEST (XIOREAD_TEST|XIOWRITE_TEST) |
||
105 | #define XIODATA_TESTUNI XIOWRITE_TEST |
||
106 | #define XIODATA_TESTREV XIOWRITE_TESTREV |
||
107 | |||
108 | /* XIOSHUT_* define the actions on shutdown of the address */ |
||
109 | /* */ |
||
110 | #define XIOSHUTRD_MASK 0x00f0 |
||
111 | #define XIOSHUTWR_MASK 0x000f |
||
112 | #define XIOSHUTSPEC_MASK 0xff00 /* specific action */ |
||
113 | #define XIOSHUTRD_UNSPEC 0x0000 |
||
114 | #define XIOSHUTWR_UNSPEC 0x0000 |
||
115 | #define XIOSHUTRD_NONE 0x0010 /* no action - e.g. stdin */ |
||
116 | #define XIOSHUTWR_NONE 0x0001 /* no action - e.g. stdout */ |
||
117 | #define XIOSHUTRD_CLOSE 0x0020 /* close() */ |
||
118 | #define XIOSHUTWR_CLOSE 0x0002 /* close() */ |
||
119 | #define XIOSHUTRD_DOWN 0x0030 /* shutdown(, SHUT_RD) */ |
||
120 | #define XIOSHUTWR_DOWN 0x0003 /* shutdown(, SHUT_WR) */ |
||
121 | #define XIOSHUTRD_SIGHUP 0x0040 /* kill sub process */ |
||
122 | #define XIOSHUTWR_SIGHUP 0x0004 /* flush sub process with SIGHPUP */ |
||
123 | #define XIOSHUTRD_SIGTERM 0x0050 /* kill sub process with SIGTERM */ |
||
124 | #define XIOSHUTWR_SIGTERM 0x0005 /* kill sub process with SIGTERM */ |
||
125 | #define XIOSHUTWR_SIGKILL 0x0006 /* kill sub process with SIGKILL */ |
||
126 | #define XIOSHUTWR_NULL 0x0007 /* send empty packet (dgram socket) */ |
||
127 | #define XIOSHUT_UNSPEC (XIOSHUTRD_UNSPEC|XIOSHUTWR_UNSPEC) |
||
128 | #define XIOSHUT_NONE (XIOSHUTRD_NONE|XIOSHUTWR_NONE) |
||
129 | #define XIOSHUT_CLOSE (XIOSHUTRD_CLOSE|XIOSHUTWR_CLOSE) |
||
130 | #define XIOSHUT_DOWN (XIOSHUTRD_DOWN|XIOSHUTWR_DOWN) |
||
131 | #define XIOSHUT_KILL (XIOSHUTRD_KILL|XIOSHUTWR_KILL) |
||
132 | #define XIOSHUT_NULL (XIOSHUTRD_DOWN|XIOSHUTWR_NULL) |
||
133 | #define XIOSHUT_PTYEOF 0x0100 /* change pty to icanon and write VEOF */ |
||
134 | #define XIOSHUT_OPENSSL 0x0101 /* specific action on openssl */ |
||
135 | /*!!!*/ |
||
136 | |||
137 | #define XIOCLOSE_UNSPEC 0x0000 /* after init, when no end-close... option */ |
||
138 | #define XIOCLOSE_NONE 0x0001 /* no action */ |
||
139 | #define XIOCLOSE_CLOSE 0x0002 /* close() */ |
||
140 | #define XIOCLOSE_SIGTERM 0x0003 /* send SIGTERM to sub process */ |
||
141 | #define XIOCLOSE_SIGKILL 0x0004 /* send SIGKILL to sub process */ |
||
142 | #define XIOCLOSE_CLOSE_SIGTERM 0x0005 /* close fd, then send SIGTERM */ |
||
143 | #define XIOCLOSE_CLOSE_SIGKILL 0x0006 /* close fd, then send SIGKILL */ |
||
144 | #define XIOCLOSE_SLEEP_SIGTERM 0x0007 /* short sleep, then SIGTERM */ |
||
145 | #define XIOCLOSE_OPENSSL 0x0101 |
||
146 | #define XIOCLOSE_READLINE 0x0102 |
||
147 | |||
148 | /* these are the values allowed for the "enum xiotag tag" flag of the "struct |
||
149 | single" and "union bipipe" (xiofile_t) structures. */ |
||
150 | enum xiotag { |
||
151 | XIO_TAG_INVALID, /* the record is not in use */ |
||
152 | XIO_TAG_RDONLY, /* this is a single read-only stream */ |
||
153 | XIO_TAG_WRONLY, /* this is a single write-only stream */ |
||
154 | XIO_TAG_RDWR, /* this is a single read-write stream */ |
||
155 | XIO_TAG_DUAL /* this is a dual stream, consisting of two single |
||
156 | streams */ |
||
157 | } ; |
||
158 | |||
159 | /* inter address communication types */ |
||
160 | enum xiocomm { |
||
161 | XIOCOMM_SOCKETPAIRS, /* two unix (local) socket pairs */ |
||
162 | XIOCOMM_PIPES, /* two unnamed pipes (fifos) */ |
||
163 | XIOCOMM_SOCKETPAIR, /* one unix (local) socket pairs */ |
||
164 | XIOCOMM_PTYS, /* two pseudo terminals, each from master to slave */ |
||
165 | XIOCOMM_PTY, /* one pseudo terminal, master on left side */ |
||
166 | XIOCOMM_TCP, /* one TCP socket pair */ |
||
167 | XIOCOMM_TCP4, /* one TCP/IPv4 socket pair */ |
||
168 | XIOCOMM_TCP4_LISTEN, /* right side listens for TCP/IPv4, left connects */ |
||
169 | } ; |
||
170 | |||
171 | union bipipe; |
||
172 | |||
173 | |||
174 | #define XIOADDR_ENDPOINT 0 /* endpoint address */ |
||
175 | #define XIOADDR_INTER 1 /* inter address */ |
||
176 | #define XIOADDR_SYS XIOADDR_ENDPOINT |
||
177 | #define XIOADDR_PROT XIOADDR_INTER |
||
178 | |||
179 | /* one side of an "extended socketpair" */ |
||
180 | typedef struct fddesc { |
||
181 | int rfd; /* used for reading */ |
||
182 | int wfd; /* used for writing */ |
||
183 | bool single; /* rfd and wfd refer to the same "file" */ |
||
184 | int dtype; /* specifies methods for reading and writing */ |
||
185 | int howtoshut; /* specifies method for shutting down wfd */ |
||
186 | int howtoclose; /* specifies method for closing rfd and wfd */ |
||
187 | } xiofd_t; |
||
188 | |||
189 | struct xioaddr_inter_desc { |
||
190 | int tag; /* 0: endpoint addr; 1: inter addr */ |
||
191 | const char *defname; /* main (canonical) name of address */ |
||
192 | int numparams; /* number of required parameters */ |
||
193 | int leftdirs; /* set of data directions supported on left side: |
||
194 | e.g. XIOBIT_RDONLY|XIOBIT_WRONLY|XIOBIT_RDWR */ |
||
195 | unsigned groups; |
||
196 | int howtoshut; |
||
197 | int howtoclose; |
||
198 | int (*func)(int argc, const char *argv[], struct opt *opts, int rw, union bipipe *fd, unsigned groups, |
||
199 | int arg1, int arg2, int arg3); |
||
200 | int arg1; |
||
201 | int arg2; |
||
202 | int arg3; |
||
203 | int rightdirs; |
||
204 | #if WITH_HELP |
||
205 | const char *syntax; |
||
206 | #endif |
||
207 | } ; |
||
208 | |||
209 | struct xioaddr_endpoint_desc { |
||
210 | int tag; /* XIOADDR_ENDPOINT, XIOADDR_INTER */ |
||
211 | const char *defname; /* main (canonical) name of address */ |
||
212 | int numparams; /* number of required parameters */ |
||
213 | int leftdirs; /* XIOBIT_* */ |
||
214 | unsigned groups; |
||
215 | int howtoshut; |
||
216 | int howtoclose; |
||
217 | int (*func)(int argc, const char *argv[], struct opt *opts, int rw, union bipipe *fd, unsigned groups, |
||
218 | int arg1, int arg2, int arg3); |
||
219 | int arg1; |
||
220 | int arg2; |
||
221 | int arg3; |
||
222 | #if WITH_HELP |
||
223 | const char *syntax; |
||
224 | #endif |
||
225 | } ; |
||
226 | |||
227 | |||
228 | struct xioaddr_common_desc { |
||
229 | int tag; /* 0: endpoint addr; 1: inter addr */ |
||
230 | const char *defname; /* main (canonical) name of address */ |
||
231 | int numparams; /* number of required parameters */ |
||
232 | int leftdirs; |
||
233 | unsigned groups; |
||
234 | int howtoshut; |
||
235 | int howtoclose; |
||
236 | } ; |
||
237 | |||
238 | |||
239 | union xioaddr_desc { |
||
240 | int tag; /* 0: endpoint addr; 1: inter addr */ |
||
241 | struct xioaddr_common_desc common_desc; |
||
242 | struct xioaddr_inter_desc inter_desc; |
||
243 | struct xioaddr_endpoint_desc endpoint_desc; |
||
244 | } ; |
||
245 | |||
246 | union xioaddr_descp { |
||
247 | struct xioaddr_common_desc * |
||
248 | common_desc; |
||
249 | int *tag; /* 0: endpoint addr; 1: inter addr */ |
||
250 | struct xioaddr_inter_desc *inter_desc; |
||
251 | struct xioaddr_endpoint_desc *endpoint_desc; |
||
252 | } ; |
||
253 | |||
254 | |||
255 | /*!!! this to xio-sockd4.h */ |
||
256 | struct socks4head { |
||
257 | uint8_t version; |
||
258 | uint8_t action; |
||
259 | uint16_t port; |
||
260 | uint32_t dest; |
||
261 | } ; |
||
262 | |||
263 | /* global XIO options/parameters */ |
||
264 | typedef struct { |
||
265 | bool strictopts; |
||
266 | const char *pipesep; |
||
267 | const char *paramsep; |
||
268 | const char *optionsep; |
||
269 | char ip4portsep; |
||
270 | char ip6portsep; /* do not change, might be hardcoded somewhere! */ |
||
271 | const char *syslogfac; /* syslog facility (only with mixed mode) */ |
||
272 | char default_ip; /* default prot.fam for IP based listen ('4' or '6') */ |
||
273 | char preferred_ip; /* preferred prot.fam. for name resolution ('0' for |
||
274 | unspecified, '4', or '6') */ |
||
275 | char *reversechar; |
||
276 | char *chainsep; |
||
277 | size_t bufsiz; |
||
278 | bool verbose; |
||
279 | bool verbhex; |
||
280 | bool debug; |
||
281 | char logopt; /* y..syslog; s..stderr; f..file; m..mixed */ |
||
282 | struct timeval total_timeout;/* when nothing happens, die after seconds */ |
||
283 | struct timeval pollintv; /* with ignoreeof, reread after seconds */ |
||
284 | struct timeval closwait; /* after close of x, die after seconds */ |
||
285 | bool lefttoright; /* first addr ro, second addr wo */ |
||
286 | bool righttoleft; /* first addr wo, second addr ro */ |
||
287 | int pipetype; /* communication (pipe) type; 0: 2 unidirectional |
||
288 | socketpairs; 1: 2 pipes; 2: 1 socketpair */ |
||
289 | } xioopts_t; |
||
290 | |||
291 | /* pack the description of a lock file */ |
||
292 | typedef struct { |
||
293 | const char *lockfile; /* name of lockfile; NULL if no locking */ |
||
294 | bool waitlock; /* dont't exit when already locked */ |
||
295 | struct timespec intervall; /* polling intervall */ |
||
296 | } xiolock_t; |
||
297 | |||
298 | #define MAXARGV 8 |
||
299 | |||
300 | /* a non-dual file descriptor */ |
||
301 | typedef struct single { |
||
302 | enum xiotag tag; /* see enum xiotag */ |
||
303 | const union xioaddr_desc *addrdesc; |
||
304 | int flags; |
||
305 | /* until here, keep consistent with bipipe.common !!! */ |
||
306 | #if WITH_RETRY |
||
307 | unsigned int retry; /* retry opening this many times */ |
||
308 | bool forever; /* retry opening forever */ |
||
309 | struct timespec intervall; /* wait so long between retries */ |
||
310 | #endif /* WITH_RETRY */ |
||
311 | bool ignoreeof; /* option ignoreeof; do not pass eof condition to app*/ |
||
312 | int eof; /* 1..exec'd child has died, but no explicit eof |
||
313 | occurred |
||
314 | 2..fd0 has reached EOF (definitely; never with |
||
315 | ignoreeof! */ |
||
316 | size_t wsize; /* write always this size; 0..all available */ |
||
317 | size_t readbytes; /* read only so many bytes; 0...unlimited */ |
||
318 | size_t actbytes; /* so many bytes still to be read (when readbytes!=0)*/ |
||
319 | xiolock_t lock; /* parameters of lockfile */ |
||
320 | bool havelock; /* we are happy owner of the above lock */ |
||
321 | /* until here, keep consistent with bipipe.dual ! */ |
||
322 | int reverse; /* valid during parse and overload, before open: |
||
323 | will this (inter) address be integrated forward or |
||
324 | reverse? */ |
||
325 | const union xioaddr_desc **addrdescs; |
||
326 | /* valid after parse, before overload: |
||
327 | the list of possible address descriptors derived |
||
328 | from addr keyword, one of which will be selected by |
||
329 | context and num of parameters */ |
||
330 | int closing; /* 0..write channel is up, 1..just shutdown write ch., |
||
331 | 2..counting down closing timeout, 3..no more write |
||
332 | possible */ |
||
333 | bool cool_write; /* downlevel EPIPE, ECONNRESET to notice */ |
||
334 | int argc; /* number of fields in argv */ |
||
335 | const char *argv[MAXARGV]; /* address keyword, required args */ |
||
336 | struct opt *opts; /* the options of this address */ |
||
337 | int lineterm; /* 0..dont touch; 1..CR; 2..CRNL on extern data */ |
||
338 | int rfd; /* was fd1 */ |
||
339 | int wfd; /* was fd2 */ |
||
340 | pid_t subaddrpid; /* pid of subaddress (process handling next addr in |
||
341 | chain) */ |
||
342 | int subaddrstat; /* state of subaddress process |
||
343 | 0...no sub address process |
||
344 | 1...running |
||
345 | -1...ended (aborted?) */ |
||
346 | int subaddrexit; /* if subaddstat==-1: exit code of sub process */ |
||
347 | bool opt_unlink_close; /* option unlink_close */ |
||
348 | char *unlink_close; /* name of a symlink or unix socket to be removed */ |
||
349 | int dtype; |
||
350 | int howtoshut; /* method for shutting down xfds */ |
||
351 | int howtoclose; /* method for closing xfds */ |
||
352 | #if _WITH_SOCKET |
||
353 | union sockaddr_union peersa; |
||
354 | socklen_t salen; |
||
355 | #endif /* _WITH_SOCKET */ |
||
356 | #if WITH_TERMIOS |
||
357 | bool ttyvalid; /* the following struct is valid */ |
||
358 | struct termios savetty; /* save orig tty settings for later restore */ |
||
359 | #endif /* WITH_TERMIOS */ |
||
360 | /*0 const char *name;*/ /* only with END_UNLINK */ |
||
361 | struct { /* this was for exec only, now for embedded */ |
||
362 | pid_t pid; /* child PID, with EXEC: */ |
||
363 | int (*sigchild)(struct single *); /* callback after sigchild */ |
||
364 | } child; |
||
365 | pid_t ppid; /* parent pid, only if we send it signals */ |
||
366 | int escape; /* escape character; -1 for no escape */ |
||
367 | bool actescape; /* escape character found in input data */ |
||
368 | pthread_t subthread; /* thread handling next inter-addr in chain */ |
||
369 | union { |
||
370 | #if 0 |
||
371 | struct { |
||
372 | int fdout; /* use fd for output */ |
||
373 | } bipipe; |
||
374 | #endif |
||
375 | #if _WITH_SOCKET |
||
376 | struct { |
||
377 | struct timeval connect_timeout; /* how long to hang in connect() */ |
||
378 | union sockaddr_union la; /* local socket address */ |
||
379 | bool null_eof; /* with dgram: empty packet means EOF */ |
||
380 | bool dorange; |
||
381 | struct xiorange range; /* restrictions for peer address */ |
||
382 | #if _WITH_IP4 || _WITH_IP6 |
||
383 | struct { |
||
384 | unsigned int res_opts[2]; /* bits to be set in _res.options are |
||
385 | at [0], bits to be cleared are at [1] */ |
||
386 | bool dosourceport; |
||
387 | uint16_t sourceport; /* host byte order */ |
||
388 | bool lowport; |
||
389 | #if (WITH_TCP || WITH_UDP) && WITH_LIBWRAP |
||
390 | bool dolibwrap; |
||
391 | char *libwrapname; |
||
392 | char *tcpwrap_etc; |
||
393 | char *hosts_allow_table; |
||
394 | char *hosts_deny_table; |
||
395 | #endif |
||
396 | } ip; |
||
397 | #endif /* _WITH_IP4 || _WITH_IP6 */ |
||
398 | #if WITH_UNIX |
||
399 | struct { |
||
400 | bool tight; |
||
401 | } un; |
||
402 | #endif /* WITH_UNIX */ |
||
403 | } socket; |
||
404 | #endif /* _WITH_SOCKET */ |
||
405 | struct { |
||
406 | pid_t pid; /* child PID, with EXEC: */ |
||
407 | int fdout; /* use fd for output if two pipes */ |
||
408 | } exec; |
||
409 | #if WITH_READLINE |
||
410 | struct { |
||
411 | char *history_file; |
||
412 | char *prompt; /* static prompt, passed to readline() */ |
||
413 | size_t dynbytes; /* length of buffer for dynamic prompt */ |
||
414 | char *dynprompt; /* the dynamic prompt */ |
||
415 | char *dynend; /* current end of dynamic prompt */ |
||
416 | #if HAVE_REGEX_H |
||
417 | bool hasnoecho; /* following regex is set */ |
||
418 | regex_t noecho; /* if it matches the prompt, input is silent */ |
||
419 | #endif |
||
420 | } readline; |
||
421 | #endif /* WITH_READLINE */ |
||
422 | #if WITH_SOCKS4_SERVER |
||
423 | struct { |
||
424 | int state; /* state of socks4 protocol negotiation */ |
||
425 | /* we cannot rely on all request data arriving at once */ |
||
426 | struct socks4head head; |
||
427 | char *userid; |
||
428 | char *hostname; /* socks4a only */ |
||
429 | /* the following structs are an experiment for future synchronization |
||
430 | mechanisms */ |
||
431 | struct { |
||
432 | size_t canrecv; |
||
433 | size_t wantwrite; |
||
434 | void *inbuff; |
||
435 | size_t inbuflen; /* length of buffer */ |
||
436 | size_t bytes; /* current bytes in buffer */ |
||
437 | } proto; |
||
438 | struct { |
||
439 | size_t canrecv; |
||
440 | size_t wantwrite; |
||
441 | } peer_proto; |
||
442 | struct { |
||
443 | size_t canrecv; |
||
444 | size_t wantwrite; |
||
445 | int _errno; |
||
446 | } data; |
||
447 | struct { |
||
448 | size_t canrecv; |
||
449 | size_t wantwrite; |
||
450 | } peer_data; |
||
451 | } socks4d; |
||
452 | #endif /* WITH_SOCKS4_SERVER */ |
||
453 | #if WITH_OPENSSL |
||
454 | struct { |
||
455 | struct timeval connect_timeout; /* how long to hang in connect() */ |
||
456 | SSL *ssl; |
||
457 | SSL_CTX* ctx; |
||
458 | } openssl; |
||
459 | #endif /* WITH_OPENSSL */ |
||
460 | #if WITH_TUN |
||
461 | struct { |
||
462 | short iff_opts[2]; /* ifr flags, using OFUNC_OFFSET_MASKS */ |
||
463 | } tun; |
||
464 | #endif /* WITH_TUN */ |
||
465 | #if _WITH_GZIP |
||
466 | struct { |
||
467 | gzFile in; /* for reading (uncompressing from stream to API) */ |
||
468 | gzFile out; /* for writing (compressing from API to stream) */ |
||
469 | int level; |
||
470 | } gzip; |
||
471 | #endif /* _WITH_GZIP */ |
||
472 | } para; |
||
473 | } xiosingle_t; |
||
474 | |||
475 | /* rw: 0..read, 1..write, 2..r/w */ |
||
476 | /* when implementing a new address type take care of following topics: |
||
477 | . be aware that xioopen_single is used for O_RDONLY, O_WRONLY, and O_RDWR data |
||
478 | . which options are allowed (option groups) |
||
479 | . implement application of all these options |
||
480 | . set FD_CLOEXEC on new file descriptors BEFORE the cloexec option might be |
||
481 | applied |
||
482 | . |
||
483 | */ |
||
484 | |||
485 | typedef union bipipe { |
||
486 | enum xiotag tag; |
||
487 | struct { |
||
488 | enum xiotag tag; |
||
489 | const union xioaddr_desc *addrdesc; |
||
490 | int flags; |
||
491 | } common; |
||
492 | struct single stream; |
||
493 | struct { |
||
494 | enum xiotag tag; |
||
495 | const union xioaddr_desc *addrdesc; |
||
496 | int flags; /* compatible to fcntl(.., F_GETFL, ..) */ |
||
497 | #if WITH_RETRY |
||
498 | unsigned retry; /* retry opening this many times */ |
||
499 | bool forever; /* retry opening forever */ |
||
500 | struct timespec intervall; /* wait so long between retries */ |
||
501 | #endif /* WITH_RETRY */ |
||
502 | bool ignoreeof; |
||
503 | int eof; /* fd0 has reached EOF */ |
||
504 | size_t wsize; /* write always this size; 0..all available */ |
||
505 | size_t readbytes; /* read only so many bytes; 0...unlimited */ |
||
506 | size_t actbytes; /* so many bytes still to be read */ |
||
507 | xiolock_t lock; /* parameters of lockfile */ |
||
508 | bool havelock; /* we are happy owner of the above lock */ |
||
509 | /* until here, keep consistent with struct single ! */ |
||
510 | xiosingle_t *stream[2]; /* input stream, output stream */ |
||
511 | } dual; |
||
512 | } xiofile_t; |
||
513 | |||
514 | |||
515 | #define XIO_WRITABLE(s) (((s)->common.flags+1)&2) |
||
516 | #define XIO_READABLE(s) (((s)->common.flags+1)&1) |
||
517 | #define XIO_RDSTREAM(s) (((s)->tag==XIO_TAG_DUAL)?(s)->dual.stream[0]:&(s)->stream) |
||
518 | #define XIO_WRSTREAM(s) (((s)->tag==XIO_TAG_DUAL)?(s)->dual.stream[1]:&(s)->stream) |
||
519 | #define XIO_GETRDFD(s) (((s)->tag==XIO_TAG_DUAL)?(s)->dual.stream[0]->rfd:(s)->stream.rfd) |
||
520 | #define _XIO_GETWRFD(s) ((s)->wfd) |
||
521 | #define XIO_GETWRFD(s) (((s)->tag==XIO_TAG_DUAL)?_XIO_GETWRFD((s)->dual.stream[1]):_XIO_GETWRFD(&(s)->stream)) |
||
522 | #define XIO_EOF(s) (XIO_RDSTREAM(s)->eof && !XIO_RDSTREAM(s)->ignoreeof) |
||
523 | |||
524 | typedef unsigned long flags_t; |
||
525 | |||
526 | union integral { |
||
527 | int u_bool; |
||
528 | uint8_t u_byte; |
||
529 | gid_t u_gidt; |
||
530 | int u_int; |
||
531 | long u_long; |
||
532 | #if HAVE_TYPE_LONGLONG |
||
533 | long long u_longlong; |
||
534 | #endif |
||
535 | double u_double; |
||
536 | mode_t u_modet; |
||
537 | short u_short; |
||
538 | size_t u_sizet; |
||
539 | char *u_string; |
||
540 | uid_t u_uidt; |
||
541 | unsigned int u_uint; |
||
542 | unsigned long u_ulong; |
||
543 | unsigned short u_ushort; |
||
544 | uint16_t u_2bytes; |
||
545 | void *u_ptr; |
||
546 | flags_t u_flag; |
||
547 | struct { |
||
548 | uint8_t *b_data; |
||
549 | size_t b_len; |
||
550 | } u_bin; |
||
551 | struct timeval u_timeval; |
||
552 | #if HAVE_STRUCT_LINGER |
||
553 | struct linger u_linger; |
||
554 | #endif /* HAVE_STRUCT_LINGER */ |
||
555 | #if HAVE_STRUCT_TIMESPEC |
||
556 | struct timespec u_timespec; |
||
557 | #endif /* HAVE_STRUCT_TIMESPEC */ |
||
558 | #if HAVE_STRUCT_IP_MREQ || HAVE_STRUCT_IP_MREQN |
||
559 | struct { |
||
560 | char *multiaddr; |
||
561 | char *param2; /* address, interface */ |
||
562 | #if HAVE_STRUCT_IP_MREQN |
||
563 | char ifindex[IF_NAMESIZE+1]; |
||
564 | #endif |
||
565 | } u_ip_mreq; |
||
566 | #endif |
||
567 | #if WITH_IP4 |
||
568 | struct in_addr u_ip4addr; |
||
569 | #endif |
||
570 | } ; |
||
571 | |||
572 | /* some aliases */ |
||
573 | |||
574 | #if HAVE_BASIC_OFF_T==3 |
||
575 | # define u_off u_int |
||
576 | #elif HAVE_BASIC_OFF_T==5 |
||
577 | # define u_off u_long |
||
578 | #elif HAVE_BASIC_OFF_T==7 |
||
579 | # define u_off u_longlong |
||
580 | #else |
||
581 | # error "unexpected size of off_t, please report this as bug" |
||
582 | #endif |
||
583 | |||
584 | #if defined(HAVE_BASIC_OFF64_T) && HAVE_BASIC_OFF64_T |
||
585 | # if HAVE_BASIC_OFF64_T==5 |
||
586 | # define u_off64 u_long |
||
587 | # elif HAVE_BASIC_OFF64_T==7 |
||
588 | # define u_off64 u_longlong |
||
589 | # else |
||
590 | # error "unexpected size of off64_t, please report this as bug" |
||
591 | # endif |
||
592 | #endif /* defined(HAVE_BASIC_OFF64_T) && HAVE_BASIC_OFF64_T */ |
||
593 | |||
594 | |||
595 | /* this handles option instances, for communication between subroutines */ |
||
596 | struct opt { |
||
597 | const struct optdesc *desc; |
||
598 | union integral value; |
||
599 | union integral value2; |
||
600 | union integral value3; |
||
601 | } ; |
||
602 | |||
603 | /* with threading, the arguments indirectly passed to xioengine() */ |
||
604 | struct threadarg_struct { |
||
605 | int rw; /* one of XIO_RDONLY, ... */ |
||
606 | xiofile_t *xfd1; |
||
607 | xiofile_t *xfd2; |
||
608 | } ; |
||
609 | |||
610 | extern const char *PIPESEP; |
||
611 | extern xiofile_t *sock[XIO_MAXSOCK]; /*!!!*/ |
||
612 | |||
613 | extern int num_child; |
||
614 | |||
615 | /* return values of xioopensingle */ |
||
616 | #define STAT_OK 0 |
||
617 | #define STAT_WARNING 1 |
||
618 | #define STAT_EXIT 2 |
||
619 | #define STAT_NOACTION 3 /* by retropt_* when option not applied */ |
||
620 | #define STAT_RETRYNOW -1 /* only after timeouts useful ? */ |
||
621 | #define STAT_RETRYLATER -2 /* address cannot be opened, but user might |
||
622 | change something in the filesystem etc. to |
||
623 | make this process succeed later. */ |
||
624 | #define STAT_NORETRY -3 /* address syntax error, not implemented etc; |
||
625 | not even by external changes correctable */ |
||
626 | |||
627 | extern int xioinitialize(int xioflags); |
||
628 | extern int xioinitialize2(void); |
||
629 | extern pid_t xio_fork(bool subchild, int level); |
||
630 | extern int xio_forked_inchild(void); |
||
631 | extern int xiosetopt(char what, const char *arg); |
||
632 | extern int xioinqopt(char what, char *arg, size_t n); |
||
633 | extern xiofile_t *xioopen(const char *args, int xioflags); |
||
634 | extern xiofile_t *xioopenx(const char *addr, int xioflags, int infd, int outfd); |
||
635 | extern int xiosocketpair2(int pf, int socktype, int protocol, int sv[2]); |
||
636 | extern int xiosocketpair3(xiofile_t **xfd1p, xiofile_t **xfd2p, int how, ...); |
||
637 | extern int xiopty(int useptmx, int *ttyfdp, int *ptyfdp); |
||
638 | extern int xiocommpair(int commtype, bool lefttoright, bool righttoleft, |
||
639 | int dual, xiofd_t *left, xiofd_t *right, ...); |
||
640 | |||
641 | extern int xioopensingle(char *addr, xiosingle_t *fd, int xioflags); |
||
642 | extern int xioopenhelp(FILE *of, int level); |
||
643 | |||
644 | /* must be outside function for use by childdied handler */ |
||
645 | extern xiofile_t *xioallocfd(void); |
||
646 | extern void xiofreefd(xiofile_t *xfd); |
||
647 | |||
648 | extern int xiosetsigchild(xiofile_t *xfd, int (*callback)(struct single *)); |
||
649 | extern int xiosetchilddied(void); |
||
650 | extern int xio_opt_signal(pid_t pid, int signum); |
||
651 | |||
652 | extern void *xioengine(void *thread_arg); |
||
653 | extern int _socat(xiofile_t *xfd1, xiofile_t *xfd2); |
||
654 | extern ssize_t xioread(xiofile_t *sock1, void *buff, size_t bufsiz); |
||
655 | extern ssize_t xiopending(xiofile_t *sock1); |
||
656 | extern ssize_t xiowrite(xiofile_t *sock1, const void *buff, size_t bufsiz); |
||
657 | extern int xiotransfer(xiofile_t *inpipe, xiofile_t *outpipe, |
||
658 | unsigned char **buff, size_t bufsiz, bool righttoleft); |
||
659 | extern int xioshutdown(xiofile_t *sock, int how); |
||
660 | |||
661 | extern int xioclose(xiofile_t *sock); |
||
662 | extern void xioexit(void); |
||
663 | |||
664 | extern int (*xiohook_newchild)(void); /* xio calls this function from a new child process */ |
||
665 | extern int socat_sigchild(struct single *file); |
||
666 | |||
667 | |||
668 | extern xioopts_t xioopts, *xioparams; |
||
669 | |||
670 | |||
671 | #endif /* !defined(__xio_h_included) */ |