Deleted Added
full compact
netevent.h (307729) netevent.h (356345)
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

--- 46 unchanged lines hidden (view full) ---

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
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

--- 46 unchanged lines hidden (view full) ---

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
63struct sldns_buffer;
64struct comm_point;
65struct comm_reply;
65struct sldns_buffer;
66struct comm_point;
67struct comm_reply;
68struct tcl_list;
66struct ub_event_base;
67
68/* internal event notification data storage structure. */
69struct internal_event;
70struct internal_base;
71struct internal_timer; /* A sub struct of the comm_timer super struct */
72
73/** callback from communication point function type */
69struct ub_event_base;
70
71/* internal event notification data storage structure. */
72struct internal_event;
73struct internal_base;
74struct internal_timer; /* A sub struct of the comm_timer super struct */
75
76/** callback from communication point function type */
74typedef int comm_point_callback_t(struct comm_point*, void*, int,
77typedef int comm_point_callback_type(struct comm_point*, void*, int,
75 struct comm_reply*);
76
77/** to pass no_error to callback function */
78#define NETEVENT_NOERROR 0
79/** to pass closed connection to callback function */
80#define NETEVENT_CLOSED -1
81/** to pass timeout happened to callback function */
82#define NETEVENT_TIMEOUT -2
83/** to pass fallback from capsforID to callback function; 0x20 failed */
84#define NETEVENT_CAPSFAIL -3
78 struct comm_reply*);
79
80/** to pass no_error to callback function */
81#define NETEVENT_NOERROR 0
82/** to pass closed connection to callback function */
83#define NETEVENT_CLOSED -1
84/** to pass timeout happened to callback function */
85#define NETEVENT_TIMEOUT -2
86/** to pass fallback from capsforID to callback function; 0x20 failed */
87#define NETEVENT_CAPSFAIL -3
88/** to pass done transfer to callback function; http file is complete */
89#define NETEVENT_DONE -4
85
86/** timeout to slow accept calls when not possible, in msec. */
87#define NETEVENT_SLOW_ACCEPT_TIME 2000
88
89/**
90 * A communication point dispatcher. Thread specific.
91 */
92struct comm_base {

--- 16 unchanged lines hidden (view full) ---

109 /** the comm_point with fd to send reply on to. */
110 struct comm_point* c;
111 /** the address (for UDP based communication) */
112 struct sockaddr_storage addr;
113 /** length of address */
114 socklen_t addrlen;
115 /** return type 0 (none), 4(IP4), 6(IP6) */
116 int srctype;
90
91/** timeout to slow accept calls when not possible, in msec. */
92#define NETEVENT_SLOW_ACCEPT_TIME 2000
93
94/**
95 * A communication point dispatcher. Thread specific.
96 */
97struct comm_base {

--- 16 unchanged lines hidden (view full) ---

114 /** the comm_point with fd to send reply on to. */
115 struct comm_point* c;
116 /** the address (for UDP based communication) */
117 struct sockaddr_storage addr;
118 /** length of address */
119 socklen_t addrlen;
120 /** return type 0 (none), 4(IP4), 6(IP6) */
121 int srctype;
122 /* DnsCrypt context */
123#ifdef USE_DNSCRYPT
124 uint8_t client_nonce[crypto_box_HALF_NONCEBYTES];
125 uint8_t nmkey[crypto_box_BEFORENMBYTES];
126 const dnsccert *dnsc_cert;
127 int is_dnscrypted;
128#endif
117 /** the return source interface data */
118 union {
119#ifdef IPV6_PKTINFO
120 struct in6_pktinfo v6info;
121#endif
122#ifdef IP_PKTINFO
123 struct in_pktinfo v4info;
124#elif defined(IP_RECVDSTADDR)
125 struct in_addr v4addr;
126#endif
129 /** the return source interface data */
130 union {
131#ifdef IPV6_PKTINFO
132 struct in6_pktinfo v6info;
133#endif
134#ifdef IP_PKTINFO
135 struct in_pktinfo v4info;
136#elif defined(IP_RECVDSTADDR)
137 struct in_addr v4addr;
138#endif
127 }
139 }
128 /** variable with return source data */
129 pktinfo;
140 /** variable with return source data */
141 pktinfo;
142 /** max udp size for udp packets */
143 size_t max_udp_size;
130};
131
132/**
133 * Communication point to the network
134 * These behaviours can be accomplished by setting the flags
135 * and passing return values from the callback.
136 * udp frontside: called after readdone. sendafter.
137 * tcp frontside: called readdone, sendafter. close.

--- 47 unchanged lines hidden (view full) ---

185 /** ssl initial handshake wants to write */
186 comm_ssl_shake_write,
187 /** ssl_write wants to read */
188 comm_ssl_shake_hs_read,
189 /** ssl_read wants to write */
190 comm_ssl_shake_hs_write
191 } ssl_shake_state;
192
144};
145
146/**
147 * Communication point to the network
148 * These behaviours can be accomplished by setting the flags
149 * and passing return values from the callback.
150 * udp frontside: called after readdone. sendafter.
151 * tcp frontside: called readdone, sendafter. close.

--- 47 unchanged lines hidden (view full) ---

199 /** ssl initial handshake wants to write */
200 comm_ssl_shake_write,
201 /** ssl_write wants to read */
202 comm_ssl_shake_hs_read,
203 /** ssl_read wants to write */
204 comm_ssl_shake_hs_write
205 } ssl_shake_state;
206
207 /* -------- HTTP ------- */
208 /** Currently reading in http headers */
209 int http_in_headers;
210 /** Currently reading in chunk headers, 0=not, 1=firstline, 2=unused
211 * (more lines), 3=trailer headers after chunk */
212 int http_in_chunk_headers;
213 /** chunked transfer */
214 int http_is_chunked;
215 /** http temp buffer (shared buffer for temporary work) */
216 struct sldns_buffer* http_temp;
217 /** http stored content in buffer */
218 size_t http_stored;
219
193 /* -------- dnstap ------- */
194 /** the dnstap environment */
195 struct dt_env* dtenv;
196
197 /** is this a UDP, TCP-accept or TCP socket. */
198 enum comm_point_type {
199 /** UDP socket - handle datagrams. */
200 comm_udp,
201 /** TCP accept socket - only creates handlers if readable. */
202 comm_tcp_accept,
203 /** TCP handler socket - handle byteperbyte readwrite. */
204 comm_tcp,
220 /* -------- dnstap ------- */
221 /** the dnstap environment */
222 struct dt_env* dtenv;
223
224 /** is this a UDP, TCP-accept or TCP socket. */
225 enum comm_point_type {
226 /** UDP socket - handle datagrams. */
227 comm_udp,
228 /** TCP accept socket - only creates handlers if readable. */
229 comm_tcp_accept,
230 /** TCP handler socket - handle byteperbyte readwrite. */
231 comm_tcp,
232 /** HTTP handler socket */
233 comm_http,
205 /** AF_UNIX socket - for internal commands. */
206 comm_local,
207 /** raw - not DNS format - for pipe readers and writers */
208 comm_raw
209 }
210 /** variable with type of socket, UDP,TCP-accept,TCP,pipe */
211 type;
212

--- 10 unchanged lines hidden (view full) ---

223 buffer reset/bytecount reset.
224 this flag cleared.
225 So that when that is done the callback is called. */
226 int tcp_do_toggle_rw;
227
228 /** timeout in msec for TCP wait times for this connection */
229 int tcp_timeout_msec;
230
234 /** AF_UNIX socket - for internal commands. */
235 comm_local,
236 /** raw - not DNS format - for pipe readers and writers */
237 comm_raw
238 }
239 /** variable with type of socket, UDP,TCP-accept,TCP,pipe */
240 type;
241

--- 10 unchanged lines hidden (view full) ---

252 buffer reset/bytecount reset.
253 this flag cleared.
254 So that when that is done the callback is called. */
255 int tcp_do_toggle_rw;
256
257 /** timeout in msec for TCP wait times for this connection */
258 int tcp_timeout_msec;
259
260 /** if set, tcp keepalive is enabled on this connection */
261 int tcp_keepalive;
262
231 /** if set, checks for pending error from nonblocking connect() call.*/
232 int tcp_check_nb_connect;
233
263 /** if set, checks for pending error from nonblocking connect() call.*/
264 int tcp_check_nb_connect;
265
266 /** if set, check for connection limit on tcp accept. */
267 struct tcl_list* tcp_conn_limit;
268 /** the entry for the connection. */
269 struct tcl_addr* tcl_addr;
270
271 /** the structure to keep track of open requests on this channel */
272 struct tcp_req_info* tcp_req_info;
273
234#ifdef USE_MSG_FASTOPEN
235 /** used to track if the sendto() call should be done when using TFO. */
236 int tcp_do_fastopen;
237#endif
238
274#ifdef USE_MSG_FASTOPEN
275 /** used to track if the sendto() call should be done when using TFO. */
276 int tcp_do_fastopen;
277#endif
278
279#ifdef USE_DNSCRYPT
280 /** Is this a dnscrypt channel */
281 int dnscrypt;
282 /** encrypted buffer pointer. Either to perthread, or own buffer or NULL */
283 struct sldns_buffer* dnscrypt_buffer;
284#endif
239 /** number of queries outstanding on this socket, used by
240 * outside network for udp ports */
241 int inuse;
242
243 /** callback when done.
244 tcp_accept does not get called back, is NULL then.
245 If a timeout happens, callback with timeout=1 is called.
246 If an error happens, callback is called with error set

--- 12 unchanged lines hidden (view full) ---

259 int my_callback(struct comm_point* c, void* my_arg, int error,
260 struct comm_reply *reply_info);
261
262 if the routine returns 0, nothing is done.
263 Notzero, the buffer will be sent back to client.
264 For UDP this is done without changing the commpoint.
265 In TCP it sets write state.
266 */
285 /** number of queries outstanding on this socket, used by
286 * outside network for udp ports */
287 int inuse;
288
289 /** callback when done.
290 tcp_accept does not get called back, is NULL then.
291 If a timeout happens, callback with timeout=1 is called.
292 If an error happens, callback is called with error set

--- 12 unchanged lines hidden (view full) ---

305 int my_callback(struct comm_point* c, void* my_arg, int error,
306 struct comm_reply *reply_info);
307
308 if the routine returns 0, nothing is done.
309 Notzero, the buffer will be sent back to client.
310 For UDP this is done without changing the commpoint.
311 In TCP it sets write state.
312 */
267 comm_point_callback_t* callback;
313 comm_point_callback_type* callback;
268 /** argument to pass to callback. */
269 void *cb_arg;
270};
271
272/**
273 * Structure only for making timeout events.
274 */
275struct comm_timer {

--- 101 unchanged lines hidden (view full) ---

377 * @param buffer: shared buffer by UDP sockets from this thread.
378 * @param callback: callback function pointer.
379 * @param callback_arg: will be passed to your callback function.
380 * @return: returns the allocated communication point. NULL on error.
381 * Sets timeout to NULL. Turns off TCP options.
382 */
383struct comm_point* comm_point_create_udp(struct comm_base* base,
384 int fd, struct sldns_buffer* buffer,
314 /** argument to pass to callback. */
315 void *cb_arg;
316};
317
318/**
319 * Structure only for making timeout events.
320 */
321struct comm_timer {

--- 101 unchanged lines hidden (view full) ---

423 * @param buffer: shared buffer by UDP sockets from this thread.
424 * @param callback: callback function pointer.
425 * @param callback_arg: will be passed to your callback function.
426 * @return: returns the allocated communication point. NULL on error.
427 * Sets timeout to NULL. Turns off TCP options.
428 */
429struct comm_point* comm_point_create_udp(struct comm_base* base,
430 int fd, struct sldns_buffer* buffer,
385 comm_point_callback_t* callback, void* callback_arg);
431 comm_point_callback_type* callback, void* callback_arg);
386
387/**
388 * Create an UDP with ancillary data comm point. Calls malloc.
389 * Uses recvmsg instead of recv to get udp message.
390 * setups the structure with the parameters you provide.
391 * @param base: in which base to alloc the commpoint.
392 * @param fd : file descriptor of open UDP socket.
393 * @param buffer: shared buffer by UDP sockets from this thread.
394 * @param callback: callback function pointer.
395 * @param callback_arg: will be passed to your callback function.
396 * @return: returns the allocated communication point. NULL on error.
397 * Sets timeout to NULL. Turns off TCP options.
398 */
399struct comm_point* comm_point_create_udp_ancil(struct comm_base* base,
400 int fd, struct sldns_buffer* buffer,
432
433/**
434 * Create an UDP with ancillary data comm point. Calls malloc.
435 * Uses recvmsg instead of recv to get udp message.
436 * setups the structure with the parameters you provide.
437 * @param base: in which base to alloc the commpoint.
438 * @param fd : file descriptor of open UDP socket.
439 * @param buffer: shared buffer by UDP sockets from this thread.
440 * @param callback: callback function pointer.
441 * @param callback_arg: will be passed to your callback function.
442 * @return: returns the allocated communication point. NULL on error.
443 * Sets timeout to NULL. Turns off TCP options.
444 */
445struct comm_point* comm_point_create_udp_ancil(struct comm_base* base,
446 int fd, struct sldns_buffer* buffer,
401 comm_point_callback_t* callback, void* callback_arg);
447 comm_point_callback_type* callback, void* callback_arg);
402
403/**
404 * Create a TCP listener comm point. Calls malloc.
405 * Setups the structure with the parameters you provide.
406 * Also Creates TCP Handlers, pre allocated for you.
407 * Uses the parameters you provide.
408 * @param base: in which base to alloc the commpoint.
409 * @param fd: file descriptor of open TCP socket set to listen nonblocking.
410 * @param num: becomes max_tcp_count, the routine allocates that
411 * many tcp handler commpoints.
448
449/**
450 * Create a TCP listener comm point. Calls malloc.
451 * Setups the structure with the parameters you provide.
452 * Also Creates TCP Handlers, pre allocated for you.
453 * Uses the parameters you provide.
454 * @param base: in which base to alloc the commpoint.
455 * @param fd: file descriptor of open TCP socket set to listen nonblocking.
456 * @param num: becomes max_tcp_count, the routine allocates that
457 * many tcp handler commpoints.
458 * @param idle_timeout: TCP idle timeout in ms.
459 * @param tcp_conn_limit: TCP connection limit info.
412 * @param bufsize: size of buffer to create for handlers.
460 * @param bufsize: size of buffer to create for handlers.
461 * @param spoolbuf: shared spool buffer for tcp_req_info structures.
462 * or NULL to not create those structures in the tcp handlers.
413 * @param callback: callback function pointer for TCP handlers.
414 * @param callback_arg: will be passed to your callback function.
415 * @return: returns the TCP listener commpoint. You can find the
416 * TCP handlers in the array inside the listener commpoint.
417 * returns NULL on error.
418 * Inits timeout to NULL. All handlers are on the free list.
419 */
420struct comm_point* comm_point_create_tcp(struct comm_base* base,
463 * @param callback: callback function pointer for TCP handlers.
464 * @param callback_arg: will be passed to your callback function.
465 * @return: returns the TCP listener commpoint. You can find the
466 * TCP handlers in the array inside the listener commpoint.
467 * returns NULL on error.
468 * Inits timeout to NULL. All handlers are on the free list.
469 */
470struct comm_point* comm_point_create_tcp(struct comm_base* base,
421 int fd, int num, size_t bufsize,
422 comm_point_callback_t* callback, void* callback_arg);
471 int fd, int num, int idle_timeout, struct tcl_list* tcp_conn_limit,
472 size_t bufsize, struct sldns_buffer* spoolbuf,
473 comm_point_callback_type* callback, void* callback_arg);
423
424/**
425 * Create an outgoing TCP commpoint. No file descriptor is opened, left at -1.
426 * @param base: in which base to alloc the commpoint.
427 * @param bufsize: size of buffer to create for handlers.
428 * @param callback: callback function pointer for the handler.
429 * @param callback_arg: will be passed to your callback function.
430 * @return: the commpoint or NULL on error.
431 */
432struct comm_point* comm_point_create_tcp_out(struct comm_base* base,
474
475/**
476 * Create an outgoing TCP commpoint. No file descriptor is opened, left at -1.
477 * @param base: in which base to alloc the commpoint.
478 * @param bufsize: size of buffer to create for handlers.
479 * @param callback: callback function pointer for the handler.
480 * @param callback_arg: will be passed to your callback function.
481 * @return: the commpoint or NULL on error.
482 */
483struct comm_point* comm_point_create_tcp_out(struct comm_base* base,
433 size_t bufsize, comm_point_callback_t* callback, void* callback_arg);
484 size_t bufsize, comm_point_callback_type* callback, void* callback_arg);
434
435/**
485
486/**
487 * Create an outgoing HTTP commpoint. No file descriptor is opened, left at -1.
488 * @param base: in which base to alloc the commpoint.
489 * @param bufsize: size of buffer to create for handlers.
490 * @param callback: callback function pointer for the handler.
491 * @param callback_arg: will be passed to your callback function.
492 * @param temp: sldns buffer, shared between other http_out commpoints, for
493 * temporary data when performing callbacks.
494 * @return: the commpoint or NULL on error.
495 */
496struct comm_point* comm_point_create_http_out(struct comm_base* base,
497 size_t bufsize, comm_point_callback_type* callback,
498 void* callback_arg, struct sldns_buffer* temp);
499
500/**
436 * Create commpoint to listen to a local domain file descriptor.
437 * @param base: in which base to alloc the commpoint.
438 * @param fd: file descriptor of open AF_UNIX socket set to listen nonblocking.
439 * @param bufsize: size of buffer to create for handlers.
440 * @param callback: callback function pointer for the handler.
441 * @param callback_arg: will be passed to your callback function.
442 * @return: the commpoint or NULL on error.
443 */
444struct comm_point* comm_point_create_local(struct comm_base* base,
445 int fd, size_t bufsize,
501 * Create commpoint to listen to a local domain file descriptor.
502 * @param base: in which base to alloc the commpoint.
503 * @param fd: file descriptor of open AF_UNIX socket set to listen nonblocking.
504 * @param bufsize: size of buffer to create for handlers.
505 * @param callback: callback function pointer for the handler.
506 * @param callback_arg: will be passed to your callback function.
507 * @return: the commpoint or NULL on error.
508 */
509struct comm_point* comm_point_create_local(struct comm_base* base,
510 int fd, size_t bufsize,
446 comm_point_callback_t* callback, void* callback_arg);
511 comm_point_callback_type* callback, void* callback_arg);
447
448/**
449 * Create commpoint to listen to a local domain pipe descriptor.
450 * @param base: in which base to alloc the commpoint.
451 * @param fd: file descriptor.
452 * @param writing: true if you want to listen to writes, false for reads.
453 * @param callback: callback function pointer for the handler.
454 * @param callback_arg: will be passed to your callback function.
455 * @return: the commpoint or NULL on error.
456 */
457struct comm_point* comm_point_create_raw(struct comm_base* base,
458 int fd, int writing,
512
513/**
514 * Create commpoint to listen to a local domain pipe descriptor.
515 * @param base: in which base to alloc the commpoint.
516 * @param fd: file descriptor.
517 * @param writing: true if you want to listen to writes, false for reads.
518 * @param callback: callback function pointer for the handler.
519 * @param callback_arg: will be passed to your callback function.
520 * @return: the commpoint or NULL on error.
521 */
522struct comm_point* comm_point_create_raw(struct comm_base* base,
523 int fd, int writing,
459 comm_point_callback_t* callback, void* callback_arg);
524 comm_point_callback_type* callback, void* callback_arg);
460
461/**
462 * Close a comm point fd.
463 * @param c: comm point to close.
464 */
465void comm_point_close(struct comm_point* c);
466
467/**

--- 177 unchanged lines hidden (view full) ---

645 * @param event: event bits from libevent:
646 * EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT.
647 * @param arg: the comm_point structure.
648 */
649void comm_point_tcp_handle_callback(int fd, short event, void* arg);
650
651/**
652 * This routine is published for checks and tests, and is only used internally.
525
526/**
527 * Close a comm point fd.
528 * @param c: comm point to close.
529 */
530void comm_point_close(struct comm_point* c);
531
532/**

--- 177 unchanged lines hidden (view full) ---

710 * @param event: event bits from libevent:
711 * EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT.
712 * @param arg: the comm_point structure.
713 */
714void comm_point_tcp_handle_callback(int fd, short event, void* arg);
715
716/**
717 * This routine is published for checks and tests, and is only used internally.
718 * handle libevent callback for tcp data comm point
719 * @param fd: file descriptor.
720 * @param event: event bits from libevent:
721 * EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT.
722 * @param arg: the comm_point structure.
723 */
724void comm_point_http_handle_callback(int fd, short event, void* arg);
725
726/**
727 * This routine is published for checks and tests, and is only used internally.
653 * handle libevent callback for timer comm.
654 * @param fd: file descriptor (always -1).
655 * @param event: event bits from libevent:
656 * EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT.
657 * @param arg: the comm_timer structure.
658 */
659void comm_timer_callback(int fd, short event, void* arg);
660

--- 54 unchanged lines hidden ---
728 * handle libevent callback for timer comm.
729 * @param fd: file descriptor (always -1).
730 * @param event: event bits from libevent:
731 * EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT.
732 * @param arg: the comm_timer structure.
733 */
734void comm_timer_callback(int fd, short event, void* arg);
735

--- 54 unchanged lines hidden ---