xref: /netbsd-src/external/bsd/unbound/dist/util/netevent.h (revision bdc22b2e01993381dcefeff2bc9b56ca75a4235c)
1 /*
2  * util/netevent.h - event notification
3  *
4  * Copyright (c) 2007, NLnet Labs. All rights reserved.
5  *
6  * This software is open source.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * Redistributions in binary form must reproduce the above copyright notice,
16  * this list of conditions and the following disclaimer in the documentation
17  * and/or other materials provided with the distribution.
18  *
19  * Neither the name of the NLNET LABS nor the names of its contributors may
20  * be used to endorse or promote products derived from this software without
21  * specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 /**
37  * \file
38  *
39  * This file contains event notification functions.
40  *
41  * There are three types of communication points
42  *    o UDP socket - perthread buffer.
43  *    o TCP-accept socket - array of TCP-sockets, socketcount.
44  *    o TCP socket - own buffer, parent-TCPaccept, read/write state,
45  *                   number of bytes read/written, timeout.
46  *
47  * There are sockets aimed towards our clients and towards the internet.
48  *    o frontside - aimed towards our clients, queries come in, answers back.
49  *    o behind - aimed towards internet, to the authoritative DNS servers.
50  *
51  * Several event types are available:
52  *    o comm_base - for thread safety of the comm points, one per thread.
53  *    o comm_point - udp and tcp networking, with callbacks.
54  *    o comm_timer - a timeout with callback.
55  *    o comm_signal - callbacks when signal is caught.
56  *    o comm_reply - holds reply info during networking callback.
57  *
58  */
59 
60 #ifndef NET_EVENT_H
61 #define NET_EVENT_H
62 
63 #include "dnscrypt/dnscrypt.h"
64 
65 struct sldns_buffer;
66 struct comm_point;
67 struct comm_reply;
68 struct ub_event_base;
69 
70 /* internal event notification data storage structure. */
71 struct internal_event;
72 struct internal_base;
73 struct internal_timer; /* A sub struct of the comm_timer super struct */
74 
75 /** callback from communication point function type */
76 typedef int comm_point_callback_type(struct comm_point*, void*, int,
77 	struct comm_reply*);
78 
79 /** to pass no_error to callback function */
80 #define NETEVENT_NOERROR 0
81 /** to pass closed connection to callback function */
82 #define NETEVENT_CLOSED -1
83 /** to pass timeout happened to callback function */
84 #define NETEVENT_TIMEOUT -2
85 /** to pass fallback from capsforID to callback function; 0x20 failed */
86 #define NETEVENT_CAPSFAIL -3
87 
88 /** timeout to slow accept calls when not possible, in msec. */
89 #define NETEVENT_SLOW_ACCEPT_TIME 2000
90 
91 /**
92  * A communication point dispatcher. Thread specific.
93  */
94 struct comm_base {
95 	/** behind the scenes structure. with say libevent info. alloced */
96 	struct internal_base* eb;
97 	/** callback to stop listening on accept sockets,
98 	 * performed when accept() will not function properly */
99 	void (*stop_accept)(void*);
100 	/** callback to start listening on accept sockets, performed
101 	 * after stop_accept() then a timeout has passed. */
102 	void (*start_accept)(void*);
103 	/** user argument for stop_accept and start_accept functions */
104 	void* cb_arg;
105 };
106 
107 /**
108  * Reply information for a communication point.
109  */
110 struct comm_reply {
111 	/** the comm_point with fd to send reply on to. */
112 	struct comm_point* c;
113 	/** the address (for UDP based communication) */
114 	struct sockaddr_storage addr;
115 	/** length of address */
116 	socklen_t addrlen;
117 	/** return type 0 (none), 4(IP4), 6(IP6) */
118 	int srctype;
119 	/* DnsCrypt context */
120 #ifdef USE_DNSCRYPT
121 	uint8_t client_nonce[crypto_box_HALF_NONCEBYTES];
122 	uint8_t nmkey[crypto_box_BEFORENMBYTES];
123 	const dnsccert *dnsc_cert;
124 	int is_dnscrypted;
125 #endif
126 	/** the return source interface data */
127 	union {
128 #ifdef IPV6_PKTINFO
129 		struct in6_pktinfo v6info;
130 #endif
131 #ifdef IP_PKTINFO
132 		struct in_pktinfo v4info;
133 #elif defined(IP_RECVDSTADDR)
134 		struct in_addr v4addr;
135 #endif
136 	}
137 		/** variable with return source data */
138 		pktinfo;
139 	/** max udp size for udp packets */
140 	size_t max_udp_size;
141 };
142 
143 /**
144  * Communication point to the network
145  * These behaviours can be accomplished by setting the flags
146  * and passing return values from the callback.
147  *    udp frontside: called after readdone. sendafter.
148  *    tcp frontside: called readdone, sendafter. close.
149  *    udp behind: called after readdone. No send after.
150  *    tcp behind: write done, read done, then called. No send after.
151  */
152 struct comm_point {
153 	/** behind the scenes structure, with say libevent info. alloced. */
154 	struct internal_event* ev;
155 
156 	/** file descriptor for communication point */
157 	int fd;
158 
159 	/** timeout (NULL if it does not). Malloced. */
160 	struct timeval* timeout;
161 
162 	/** buffer pointer. Either to perthread, or own buffer or NULL */
163 	struct sldns_buffer* buffer;
164 
165 	/* -------- TCP Handler -------- */
166 	/** Read/Write state for TCP */
167 	int tcp_is_reading;
168 	/** The current read/write count for TCP */
169 	size_t tcp_byte_count;
170 	/** parent communication point (for TCP sockets) */
171 	struct comm_point* tcp_parent;
172 	/** sockaddr from peer, for TCP handlers */
173 	struct comm_reply repinfo;
174 
175 	/* -------- TCP Accept -------- */
176 	/** the number of TCP handlers for this tcp-accept socket */
177 	int max_tcp_count;
178 	/** current number of tcp handler in-use for this accept socket */
179 	int cur_tcp_count;
180 	/** malloced array of tcp handlers for a tcp-accept,
181 	    of size max_tcp_count. */
182 	struct comm_point** tcp_handlers;
183 	/** linked list of free tcp_handlers to use for new queries.
184 	    For tcp_accept the first entry, for tcp_handlers the next one. */
185 	struct comm_point* tcp_free;
186 
187 	/* -------- SSL TCP DNS ------- */
188 	/** the SSL object with rw bio (owned) or for commaccept ctx ref */
189 	void* ssl;
190 	/** handshake state for init and renegotiate */
191 	enum {
192 		/** no handshake, it has been done */
193 		comm_ssl_shake_none = 0,
194 		/** ssl initial handshake wants to read */
195 		comm_ssl_shake_read,
196 		/** ssl initial handshake wants to write */
197 		comm_ssl_shake_write,
198 		/** ssl_write wants to read */
199 		comm_ssl_shake_hs_read,
200 		/** ssl_read wants to write */
201 		comm_ssl_shake_hs_write
202 	} ssl_shake_state;
203 
204 	/* -------- dnstap ------- */
205 	/** the dnstap environment */
206 	struct dt_env* dtenv;
207 
208 	/** is this a UDP, TCP-accept or TCP socket. */
209 	enum comm_point_type {
210 		/** UDP socket - handle datagrams. */
211 		comm_udp,
212 		/** TCP accept socket - only creates handlers if readable. */
213 		comm_tcp_accept,
214 		/** TCP handler socket - handle byteperbyte readwrite. */
215 		comm_tcp,
216 		/** AF_UNIX socket - for internal commands. */
217 		comm_local,
218 		/** raw - not DNS format - for pipe readers and writers */
219 		comm_raw
220 	}
221 		/** variable with type of socket, UDP,TCP-accept,TCP,pipe */
222 		type;
223 
224 	/* ---------- Behaviour ----------- */
225 	/** if set the connection is NOT closed on delete. */
226 	int do_not_close;
227 
228 	/** if set, the connection is closed on error, on timeout,
229 	    and after read/write completes. No callback is done. */
230 	int tcp_do_close;
231 
232 	/** if set, read/write completes:
233 		read/write state of tcp is toggled.
234 		buffer reset/bytecount reset.
235 		this flag cleared.
236 	    So that when that is done the callback is called. */
237 	int tcp_do_toggle_rw;
238 
239 	/** timeout in msec for TCP wait times for this connection */
240 	int tcp_timeout_msec;
241 
242 	/** if set, checks for pending error from nonblocking connect() call.*/
243 	int tcp_check_nb_connect;
244 
245 #ifdef USE_MSG_FASTOPEN
246 	/** used to track if the sendto() call should be done when using TFO. */
247 	int tcp_do_fastopen;
248 #endif
249 
250 #ifdef USE_DNSCRYPT
251 	/** Is this a dnscrypt channel */
252 	int dnscrypt;
253 	/** encrypted buffer pointer. Either to perthread, or own buffer or NULL */
254 	struct sldns_buffer* dnscrypt_buffer;
255 #endif
256 	/** number of queries outstanding on this socket, used by
257 	 * outside network for udp ports */
258 	int inuse;
259 
260 	/** callback when done.
261 	    tcp_accept does not get called back, is NULL then.
262 	    If a timeout happens, callback with timeout=1 is called.
263 	    If an error happens, callback is called with error set
264 	    nonzero. If not NETEVENT_NOERROR, it is an errno value.
265 	    If the connection is closed (by remote end) then the
266 	    callback is called with error set to NETEVENT_CLOSED=-1.
267 	    If a timeout happens on the connection, the error is set to
268 	    NETEVENT_TIMEOUT=-2.
269 	    The reply_info can be copied if the reply needs to happen at a
270 	    later time. It consists of a struct with commpoint and address.
271 	    It can be passed to a msg send routine some time later.
272 	    Note the reply information is temporary and must be copied.
273 	    NULL is passed for_reply info, in cases where error happened.
274 
275 	    declare as:
276 	    int my_callback(struct comm_point* c, void* my_arg, int error,
277 		struct comm_reply *reply_info);
278 
279 	    if the routine returns 0, nothing is done.
280 	    Notzero, the buffer will be sent back to client.
281 	    		For UDP this is done without changing the commpoint.
282 			In TCP it sets write state.
283 	*/
284 	comm_point_callback_type* callback;
285 	/** argument to pass to callback. */
286 	void *cb_arg;
287 };
288 
289 /**
290  * Structure only for making timeout events.
291  */
292 struct comm_timer {
293 	/** the internal event stuff (derived) */
294 	struct internal_timer* ev_timer;
295 
296 	/** callback function, takes user arg only */
297 	void (*callback)(void*);
298 
299 	/** callback user argument */
300 	void* cb_arg;
301 };
302 
303 /**
304  * Structure only for signal events.
305  */
306 struct comm_signal {
307 	/** the communication base */
308 	struct comm_base* base;
309 
310 	/** the internal event stuff */
311 	struct internal_signal* ev_signal;
312 
313 	/** callback function, takes signal number and user arg */
314 	void (*callback)(int, void*);
315 
316 	/** callback user argument */
317 	void* cb_arg;
318 };
319 
320 /**
321  * Create a new comm base.
322  * @param sigs: if true it attempts to create a default loop for
323  *   signal handling.
324  * @return: the new comm base. NULL on error.
325  */
326 struct comm_base* comm_base_create(int sigs);
327 
328 /**
329  * Create comm base that uses the given ub_event_base (underlying pluggable
330  * event mechanism pointer).
331  * @param base: underlying pluggable event base.
332  * @return: the new comm base. NULL on error.
333  */
334 struct comm_base* comm_base_create_event(struct ub_event_base* base);
335 
336 /**
337  * Delete comm base structure but not the underlying lib event base.
338  * All comm points must have been deleted.
339  * @param b: the base to delete.
340  */
341 void comm_base_delete_no_base(struct comm_base* b);
342 
343 /**
344  * Destroy a comm base.
345  * All comm points must have been deleted.
346  * @param b: the base to delete.
347  */
348 void comm_base_delete(struct comm_base* b);
349 
350 /**
351  * Obtain two pointers. The pointers never change (until base_delete()).
352  * The pointers point to time values that are updated regularly.
353  * @param b: the communication base that will update the time values.
354  * @param tt: pointer to time in seconds is returned.
355  * @param tv: pointer to time in microseconds is returned.
356  */
357 void comm_base_timept(struct comm_base* b, time_t** tt, struct timeval** tv);
358 
359 /**
360  * Dispatch the comm base events.
361  * @param b: the communication to perform.
362  */
363 void comm_base_dispatch(struct comm_base* b);
364 
365 /**
366  * Exit from dispatch loop.
367  * @param b: the communication base that is in dispatch().
368  */
369 void comm_base_exit(struct comm_base* b);
370 
371 /**
372  * Set the slow_accept mode handlers.  You can not provide these if you do
373  * not perform accept() calls.
374  * @param b: comm base
375  * @param stop_accept: function that stops listening to accept fds.
376  * @param start_accept: function that resumes listening to accept fds.
377  * @param arg: callback arg to pass to the functions.
378  */
379 void comm_base_set_slow_accept_handlers(struct comm_base* b,
380 	void (*stop_accept)(void*), void (*start_accept)(void*), void* arg);
381 
382 /**
383  * Access internal data structure (for util/tube.c on windows)
384  * @param b: comm base
385  * @return ub_event_base.
386  */
387 struct ub_event_base* comm_base_internal(struct comm_base* b);
388 
389 /**
390  * Create an UDP comm point. Calls malloc.
391  * setups the structure with the parameters you provide.
392  * @param base: in which base to alloc the commpoint.
393  * @param fd : file descriptor of open UDP socket.
394  * @param buffer: shared buffer by UDP sockets from this thread.
395  * @param callback: callback function pointer.
396  * @param callback_arg: will be passed to your callback function.
397  * @return: returns the allocated communication point. NULL on error.
398  * Sets timeout to NULL. Turns off TCP options.
399  */
400 struct comm_point* comm_point_create_udp(struct comm_base* base,
401 	int fd, struct sldns_buffer* buffer,
402 	comm_point_callback_type* callback, void* callback_arg);
403 
404 /**
405  * Create an UDP with ancillary data comm point. Calls malloc.
406  * Uses recvmsg instead of recv to get udp message.
407  * setups the structure with the parameters you provide.
408  * @param base: in which base to alloc the commpoint.
409  * @param fd : file descriptor of open UDP socket.
410  * @param buffer: shared buffer by UDP sockets from this thread.
411  * @param callback: callback function pointer.
412  * @param callback_arg: will be passed to your callback function.
413  * @return: returns the allocated communication point. NULL on error.
414  * Sets timeout to NULL. Turns off TCP options.
415  */
416 struct comm_point* comm_point_create_udp_ancil(struct comm_base* base,
417 	int fd, struct sldns_buffer* buffer,
418 	comm_point_callback_type* callback, void* callback_arg);
419 
420 /**
421  * Create a TCP listener comm point. Calls malloc.
422  * Setups the structure with the parameters you provide.
423  * Also Creates TCP Handlers, pre allocated for you.
424  * Uses the parameters you provide.
425  * @param base: in which base to alloc the commpoint.
426  * @param fd: file descriptor of open TCP socket set to listen nonblocking.
427  * @param num: becomes max_tcp_count, the routine allocates that
428  *	many tcp handler commpoints.
429  * @param bufsize: size of buffer to create for handlers.
430  * @param callback: callback function pointer for TCP handlers.
431  * @param callback_arg: will be passed to your callback function.
432  * @return: returns the TCP listener commpoint. You can find the
433  *  	TCP handlers in the array inside the listener commpoint.
434  *	returns NULL on error.
435  * Inits timeout to NULL. All handlers are on the free list.
436  */
437 struct comm_point* comm_point_create_tcp(struct comm_base* base,
438 	int fd, int num, size_t bufsize,
439 	comm_point_callback_type* callback, void* callback_arg);
440 
441 /**
442  * Create an outgoing TCP commpoint. No file descriptor is opened, left at -1.
443  * @param base: in which base to alloc the commpoint.
444  * @param bufsize: size of buffer to create for handlers.
445  * @param callback: callback function pointer for the handler.
446  * @param callback_arg: will be passed to your callback function.
447  * @return: the commpoint or NULL on error.
448  */
449 struct comm_point* comm_point_create_tcp_out(struct comm_base* base,
450 	size_t bufsize, comm_point_callback_type* callback, void* callback_arg);
451 
452 /**
453  * Create commpoint to listen to a local domain file descriptor.
454  * @param base: in which base to alloc the commpoint.
455  * @param fd: file descriptor of open AF_UNIX socket set to listen nonblocking.
456  * @param bufsize: size of buffer to create for handlers.
457  * @param callback: callback function pointer for the handler.
458  * @param callback_arg: will be passed to your callback function.
459  * @return: the commpoint or NULL on error.
460  */
461 struct comm_point* comm_point_create_local(struct comm_base* base,
462 	int fd, size_t bufsize,
463 	comm_point_callback_type* callback, void* callback_arg);
464 
465 /**
466  * Create commpoint to listen to a local domain pipe descriptor.
467  * @param base: in which base to alloc the commpoint.
468  * @param fd: file descriptor.
469  * @param writing: true if you want to listen to writes, false for reads.
470  * @param callback: callback function pointer for the handler.
471  * @param callback_arg: will be passed to your callback function.
472  * @return: the commpoint or NULL on error.
473  */
474 struct comm_point* comm_point_create_raw(struct comm_base* base,
475 	int fd, int writing,
476 	comm_point_callback_type* callback, void* callback_arg);
477 
478 /**
479  * Close a comm point fd.
480  * @param c: comm point to close.
481  */
482 void comm_point_close(struct comm_point* c);
483 
484 /**
485  * Close and deallocate (free) the comm point. If the comm point is
486  * a tcp-accept point, also its tcp-handler points are deleted.
487  * @param c: comm point to delete.
488  */
489 void comm_point_delete(struct comm_point* c);
490 
491 /**
492  * Send reply. Put message into commpoint buffer.
493  * @param repinfo: The reply info copied from a commpoint callback call.
494  */
495 void comm_point_send_reply(struct comm_reply* repinfo);
496 
497 /**
498  * Drop reply. Cleans up.
499  * @param repinfo: The reply info copied from a commpoint callback call.
500  */
501 void comm_point_drop_reply(struct comm_reply* repinfo);
502 
503 /**
504  * Send an udp message over a commpoint.
505  * @param c: commpoint to send it from.
506  * @param packet: what to send.
507  * @param addr: where to send it to.
508  * @param addrlen: length of addr.
509  * @return: false on a failure.
510  */
511 int comm_point_send_udp_msg(struct comm_point* c, struct sldns_buffer* packet,
512 	struct sockaddr* addr, socklen_t addrlen);
513 
514 /**
515  * Stop listening for input on the commpoint. No callbacks will happen.
516  * @param c: commpoint to disable. The fd is not closed.
517  */
518 void comm_point_stop_listening(struct comm_point* c);
519 
520 /**
521  * Start listening again for input on the comm point.
522  * @param c: commpoint to enable again.
523  * @param newfd: new fd, or -1 to leave fd be.
524  * @param msec: timeout in milliseconds, or -1 for no (change to the) timeout.
525  *	So seconds*1000.
526  */
527 void comm_point_start_listening(struct comm_point* c, int newfd, int msec);
528 
529 /**
530  * Stop listening and start listening again for reading or writing.
531  * @param c: commpoint
532  * @param rd: if true, listens for reading.
533  * @param wr: if true, listens for writing.
534  */
535 void comm_point_listen_for_rw(struct comm_point* c, int rd, int wr);
536 
537 /**
538  * Get size of memory used by comm point.
539  * For TCP handlers this includes subhandlers.
540  * For UDP handlers, this does not include the (shared) UDP buffer.
541  * @param c: commpoint.
542  * @return size in bytes.
543  */
544 size_t comm_point_get_mem(struct comm_point* c);
545 
546 /**
547  * create timer. Not active upon creation.
548  * @param base: event handling base.
549  * @param cb: callback function: void myfunc(void* myarg);
550  * @param cb_arg: user callback argument.
551  * @return: the new timer or NULL on error.
552  */
553 struct comm_timer* comm_timer_create(struct comm_base* base,
554 	void (*cb)(void*), void* cb_arg);
555 
556 /**
557  * disable timer. Stops callbacks from happening.
558  * @param timer: to disable.
559  */
560 void comm_timer_disable(struct comm_timer* timer);
561 
562 /**
563  * reset timevalue for timer.
564  * @param timer: timer to (re)set.
565  * @param tv: when the timer should activate. if NULL timer is disabled.
566  */
567 void comm_timer_set(struct comm_timer* timer, struct timeval* tv);
568 
569 /**
570  * delete timer.
571  * @param timer: to delete.
572  */
573 void comm_timer_delete(struct comm_timer* timer);
574 
575 /**
576  * see if timeout has been set to a value.
577  * @param timer: the timer to examine.
578  * @return: false if disabled or not set.
579  */
580 int comm_timer_is_set(struct comm_timer* timer);
581 
582 /**
583  * Get size of memory used by comm timer.
584  * @param timer: the timer to examine.
585  * @return size in bytes.
586  */
587 size_t comm_timer_get_mem(struct comm_timer* timer);
588 
589 /**
590  * Create a signal handler. Call signal_bind() later to bind to a signal.
591  * @param base: communication base to use.
592  * @param callback: called when signal is caught.
593  * @param cb_arg: user argument to callback
594  * @return: the signal struct or NULL on error.
595  */
596 struct comm_signal* comm_signal_create(struct comm_base* base,
597 	void (*callback)(int, void*), void* cb_arg);
598 
599 /**
600  * Bind signal struct to catch a signal. A signle comm_signal can be bound
601  * to multiple signals, calling comm_signal_bind multiple times.
602  * @param comsig: the communication point, with callback information.
603  * @param sig: signal number.
604  * @return: true on success. false on error.
605  */
606 int comm_signal_bind(struct comm_signal* comsig, int sig);
607 
608 /**
609  * Delete the signal communication point.
610  * @param comsig: to delete.
611  */
612 void comm_signal_delete(struct comm_signal* comsig);
613 
614 /**
615  * perform accept(2) with error checking.
616  * @param c: commpoint with accept fd.
617  * @param addr: remote end returned here.
618  * @param addrlen: length of remote end returned here.
619  * @return new fd, or -1 on error.
620  *	if -1, error message has been printed if necessary, simply drop
621  *	out of the reading handler.
622  */
623 int comm_point_perform_accept(struct comm_point* c,
624 	struct sockaddr_storage* addr, socklen_t* addrlen);
625 
626 /**** internal routines ****/
627 
628 /**
629  * This routine is published for checks and tests, and is only used internally.
630  * handle libevent callback for udp comm point.
631  * @param fd: file descriptor.
632  * @param event: event bits from libevent:
633  *	EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT.
634  * @param arg: the comm_point structure.
635  */
636 void comm_point_udp_callback(int fd, short event, void* arg);
637 
638 /**
639  * This routine is published for checks and tests, and is only used internally.
640  * handle libevent callback for udp ancillary data comm point.
641  * @param fd: file descriptor.
642  * @param event: event bits from libevent:
643  *	EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT.
644  * @param arg: the comm_point structure.
645  */
646 void comm_point_udp_ancil_callback(int fd, short event, void* arg);
647 
648 /**
649  * This routine is published for checks and tests, and is only used internally.
650  * handle libevent callback for tcp accept comm point
651  * @param fd: file descriptor.
652  * @param event: event bits from libevent:
653  *	EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT.
654  * @param arg: the comm_point structure.
655  */
656 void comm_point_tcp_accept_callback(int fd, short event, void* arg);
657 
658 /**
659  * This routine is published for checks and tests, and is only used internally.
660  * handle libevent callback for tcp data comm point
661  * @param fd: file descriptor.
662  * @param event: event bits from libevent:
663  *	EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT.
664  * @param arg: the comm_point structure.
665  */
666 void comm_point_tcp_handle_callback(int fd, short event, void* arg);
667 
668 /**
669  * This routine is published for checks and tests, and is only used internally.
670  * handle libevent callback for timer comm.
671  * @param fd: file descriptor (always -1).
672  * @param event: event bits from libevent:
673  *	EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT.
674  * @param arg: the comm_timer structure.
675  */
676 void comm_timer_callback(int fd, short event, void* arg);
677 
678 /**
679  * This routine is published for checks and tests, and is only used internally.
680  * handle libevent callback for signal comm.
681  * @param fd: file descriptor (used for the signal number).
682  * @param event: event bits from libevent:
683  *	EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT.
684  * @param arg: the internal commsignal structure.
685  */
686 void comm_signal_callback(int fd, short event, void* arg);
687 
688 /**
689  * This routine is published for checks and tests, and is only used internally.
690  * libevent callback for AF_UNIX fds
691  * @param fd: file descriptor.
692  * @param event: event bits from libevent:
693  *	EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT.
694  * @param arg: the comm_point structure.
695  */
696 void comm_point_local_handle_callback(int fd, short event, void* arg);
697 
698 /**
699  * This routine is published for checks and tests, and is only used internally.
700  * libevent callback for raw fd access.
701  * @param fd: file descriptor.
702  * @param event: event bits from libevent:
703  *	EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT.
704  * @param arg: the comm_point structure.
705  */
706 void comm_point_raw_handle_callback(int fd, short event, void* arg);
707 
708 /**
709  * This routine is published for checks and tests, and is only used internally.
710  * libevent callback for timeout on slow accept.
711  * @param fd: file descriptor.
712  * @param event: event bits from libevent:
713  *	EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT.
714  * @param arg: the comm_point structure.
715  */
716 void comm_base_handle_slow_accept(int fd, short event, void* arg);
717 
718 #ifdef USE_WINSOCK
719 /**
720  * Callback for openssl BIO to on windows detect WSAEWOULDBLOCK and notify
721  * the winsock_event of this for proper TCP nonblocking implementation.
722  * @param c: comm_point, fd must be set its struct event is registered.
723  * @param ssl: openssl SSL, fd must be set so it has a bio.
724  */
725 void comm_point_tcp_win_bio_cb(struct comm_point* c, void* ssl);
726 #endif
727 
728 /** see if errno for tcp connect has to be logged or not. This uses errno */
729 int tcp_connect_errno_needs_log(struct sockaddr* addr, socklen_t addrlen);
730 
731 #endif /* NET_EVENT_H */
732