Electroneum
Loading...
Searching...
No Matches
netevent.h
Go to the documentation of this file.
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
59
60#ifndef NET_EVENT_H
61#define NET_EVENT_H
62
63#include "dnscrypt/dnscrypt.h"
64
65struct sldns_buffer;
66struct comm_point;
67struct comm_reply;
68struct ub_event_base;
69
70/* internal event notification data storage structure. */
71struct internal_event;
72struct internal_base;
73struct internal_timer; /* A sub struct of the comm_timer super struct */
74
76typedef int comm_point_callback_type(struct comm_point*, void*, int,
77 struct comm_reply*);
78
80#define NETEVENT_NOERROR 0
82#define NETEVENT_CLOSED -1
84#define NETEVENT_TIMEOUT -2
86#define NETEVENT_CAPSFAIL -3
88#define NETEVENT_DONE -4
89
91#define NETEVENT_SLOW_ACCEPT_TIME 2000
92
96struct comm_base {
98 struct internal_base* eb;
101 void (*stop_accept)(void*);
104 void (*start_accept)(void*);
106 void* cb_arg;
107};
108
114 struct comm_point* c;
118 socklen_t addrlen;
121 /* DnsCrypt context */
122#ifdef USE_DNSCRYPT
123 uint8_t client_nonce[crypto_box_HALF_NONCEBYTES];
124 uint8_t nmkey[crypto_box_BEFORENMBYTES];
125 const dnsccert *dnsc_cert;
126 int is_dnscrypted;
127#endif
129 union {
130#ifdef IPV6_PKTINFO
131 struct in6_pktinfo v6info;
132#endif
133#ifdef IP_PKTINFO
134 struct in_pktinfo v4info;
135#elif defined(IP_RECVDSTADDR)
136 struct in_addr v4addr;
137#endif
138 }
143};
144
156 struct internal_event* ev;
157
159 int fd;
160
162 struct timeval* timeout;
163
166
167 /* -------- TCP Handler -------- */
176
177 /* -------- TCP Accept -------- */
188
189 /* -------- SSL TCP DNS ------- */
191 void* ssl;
193 enum {
205
206 /* -------- HTTP ------- */
218
219 /* -------- dnstap ------- */
221 struct dt_env* dtenv;
222
238
240
241 /* ---------- Behaviour ----------- */
244
248
255
258
261
262#ifdef USE_MSG_FASTOPEN
264 int tcp_do_fastopen;
265#endif
266
267#ifdef USE_DNSCRYPT
269 int dnscrypt;
271 struct sldns_buffer* dnscrypt_buffer;
272#endif
275 int inuse;
276
303 void *cb_arg;
304};
305
311 struct internal_timer* ev_timer;
312
314 void (*callback)(void*);
315
317 void* cb_arg;
318};
319
326
328 struct internal_signal* ev_signal;
329
331 void (*callback)(int, void*);
332
334 void* cb_arg;
335};
336
343struct comm_base* comm_base_create(int sigs);
344
352
359
366
374void comm_base_timept(struct comm_base* b, time_t** tt, struct timeval** tv);
375
381
386void comm_base_exit(struct comm_base* b);
387
397 void (*stop_accept)(void*), void (*start_accept)(void*), void* arg);
398
405
418 int fd, struct sldns_buffer* buffer,
419 comm_point_callback_type* callback, void* callback_arg);
420
434 int fd, struct sldns_buffer* buffer,
435 comm_point_callback_type* callback, void* callback_arg);
436
455 int fd, int num, size_t bufsize,
456 comm_point_callback_type* callback, void* callback_arg);
457
467 size_t bufsize, comm_point_callback_type* callback, void* callback_arg);
468
480 size_t bufsize, comm_point_callback_type* callback,
481 void* callback_arg, struct sldns_buffer* temp);
482
493 int fd, size_t bufsize,
494 comm_point_callback_type* callback, void* callback_arg);
495
506 int fd, int writing,
507 comm_point_callback_type* callback, void* callback_arg);
508
514
521
527
533
542int comm_point_send_udp_msg(struct comm_point* c, struct sldns_buffer* packet,
543 struct sockaddr* addr, socklen_t addrlen);
544
550
558void comm_point_start_listening(struct comm_point* c, int newfd, int msec);
559
566void comm_point_listen_for_rw(struct comm_point* c, int rd, int wr);
567
576
585 void (*cb)(void*), void* cb_arg);
586
591void comm_timer_disable(struct comm_timer* timer);
592
598void comm_timer_set(struct comm_timer* timer, struct timeval* tv);
599
604void comm_timer_delete(struct comm_timer* timer);
605
611int comm_timer_is_set(struct comm_timer* timer);
612
618size_t comm_timer_get_mem(struct comm_timer* timer);
619
628 void (*callback)(int, void*), void* cb_arg);
629
637int comm_signal_bind(struct comm_signal* comsig, int sig);
638
643void comm_signal_delete(struct comm_signal* comsig);
644
655 struct sockaddr_storage* addr, socklen_t* addrlen);
656
657/**** internal routines ****/
658
667void comm_point_udp_callback(int fd, short event, void* arg);
668
677void comm_point_udp_ancil_callback(int fd, short event, void* arg);
678
687void comm_point_tcp_accept_callback(int fd, short event, void* arg);
688
697void comm_point_tcp_handle_callback(int fd, short event, void* arg);
698
707void comm_point_http_handle_callback(int fd, short event, void* arg);
708
717void comm_timer_callback(int fd, short event, void* arg);
718
727void comm_signal_callback(int fd, short event, void* arg);
728
737void comm_point_local_handle_callback(int fd, short event, void* arg);
738
747void comm_point_raw_handle_callback(int fd, short event, void* arg);
748
757void comm_base_handle_slow_accept(int fd, short event, void* arg);
758
759#ifdef USE_WINSOCK
766void comm_point_tcp_win_bio_cb(struct comm_point* c, void* ssl);
767#endif
768
770int tcp_connect_errno_needs_log(struct sockaddr* addr, socklen_t addrlen);
771
772#endif /* NET_EVENT_H */
void comm_point_udp_ancil_callback(int fd, short event, void *arg)
void comm_point_send_reply(struct comm_reply *repinfo)
struct comm_base * comm_base_create_event(struct ub_event_base *base)
int comm_point_send_udp_msg(struct comm_point *c, struct sldns_buffer *packet, struct sockaddr *addr, socklen_t addrlen)
struct comm_point * comm_point_create_udp_ancil(struct comm_base *base, int fd, struct sldns_buffer *buffer, comm_point_callback_type *callback, void *callback_arg)
struct comm_point * comm_point_create_http_out(struct comm_base *base, size_t bufsize, comm_point_callback_type *callback, void *callback_arg, struct sldns_buffer *temp)
void comm_base_delete(struct comm_base *b)
struct comm_point * comm_point_create_raw(struct comm_base *base, int fd, int writing, comm_point_callback_type *callback, void *callback_arg)
void comm_point_tcp_handle_callback(int fd, short event, void *arg)
int tcp_connect_errno_needs_log(struct sockaddr *addr, socklen_t addrlen)
void comm_point_stop_listening(struct comm_point *c)
void comm_base_dispatch(struct comm_base *b)
void comm_signal_callback(int fd, short event, void *arg)
void comm_base_delete_no_base(struct comm_base *b)
struct comm_point * comm_point_create_tcp(struct comm_base *base, int fd, int num, size_t bufsize, comm_point_callback_type *callback, void *callback_arg)
struct comm_point * comm_point_create_udp(struct comm_base *base, int fd, struct sldns_buffer *buffer, comm_point_callback_type *callback, void *callback_arg)
void comm_timer_set(struct comm_timer *timer, struct timeval *tv)
struct comm_point * comm_point_create_tcp_out(struct comm_base *base, size_t bufsize, comm_point_callback_type *callback, void *callback_arg)
struct comm_point * comm_point_create_local(struct comm_base *base, int fd, size_t bufsize, comm_point_callback_type *callback, void *callback_arg)
void comm_base_set_slow_accept_handlers(struct comm_base *b, void(*stop_accept)(void *), void(*start_accept)(void *), void *arg)
void comm_base_exit(struct comm_base *b)
void comm_point_close(struct comm_point *c)
void comm_point_drop_reply(struct comm_reply *repinfo)
void comm_point_http_handle_callback(int fd, short event, void *arg)
struct comm_signal * comm_signal_create(struct comm_base *base, void(*callback)(int, void *), void *cb_arg)
int comm_signal_bind(struct comm_signal *comsig, int sig)
int comm_timer_is_set(struct comm_timer *timer)
void comm_point_tcp_accept_callback(int fd, short event, void *arg)
size_t comm_point_get_mem(struct comm_point *c)
size_t comm_timer_get_mem(struct comm_timer *timer)
void comm_base_timept(struct comm_base *b, time_t **tt, struct timeval **tv)
int comm_point_perform_accept(struct comm_point *c, struct sockaddr_storage *addr, socklen_t *addrlen)
void comm_point_udp_callback(int fd, short event, void *arg)
void comm_point_delete(struct comm_point *c)
void comm_point_listen_for_rw(struct comm_point *c, int rd, int wr)
void comm_timer_callback(int fd, short event, void *arg)
void comm_base_handle_slow_accept(int fd, short event, void *arg)
void comm_point_start_listening(struct comm_point *c, int newfd, int msec)
void comm_timer_delete(struct comm_timer *timer)
struct comm_timer * comm_timer_create(struct comm_base *base, void(*cb)(void *), void *cb_arg)
void comm_signal_delete(struct comm_signal *comsig)
void comm_point_local_handle_callback(int fd, short event, void *arg)
void comm_timer_disable(struct comm_timer *timer)
struct ub_event_base * comm_base_internal(struct comm_base *b)
struct comm_base * comm_base_create(int sigs)
int comm_point_callback_type(struct comm_point *, void *, int, struct comm_reply *)
Definition netevent.h:76
void comm_point_raw_handle_callback(int fd, short event, void *arg)
unsigned char uint8_t
Definition stdint.h:124
void * cb_arg
Definition netevent.h:106
struct internal_base * eb
Definition netevent.h:98
void(* stop_accept)(void *)
Definition netevent.h:101
void(* start_accept)(void *)
Definition netevent.h:104
struct dt_env * dtenv
Definition netevent.h:221
int tcp_is_reading
Definition netevent.h:169
enum comm_point::comm_point_type type
int tcp_do_toggle_rw
Definition netevent.h:254
int http_in_chunk_headers
Definition netevent.h:211
@ comm_tcp_accept
Definition netevent.h:228
struct comm_point * tcp_parent
Definition netevent.h:173
void * ssl
Definition netevent.h:191
size_t http_stored
Definition netevent.h:217
struct internal_event * ev
Definition netevent.h:156
struct comm_point * tcp_free
Definition netevent.h:187
struct sldns_buffer * buffer
Definition netevent.h:165
struct comm_reply repinfo
Definition netevent.h:175
comm_point_callback_type * callback
Definition netevent.h:301
int tcp_timeout_msec
Definition netevent.h:257
@ comm_ssl_shake_hs_read
Definition netevent.h:201
@ comm_ssl_shake_hs_write
Definition netevent.h:203
@ comm_ssl_shake_write
Definition netevent.h:199
@ comm_ssl_shake_none
Definition netevent.h:195
@ comm_ssl_shake_read
Definition netevent.h:197
int do_not_close
Definition netevent.h:243
int http_in_headers
Definition netevent.h:208
int max_tcp_count
Definition netevent.h:179
struct comm_point ** tcp_handlers
Definition netevent.h:184
int http_is_chunked
Definition netevent.h:213
int tcp_do_close
Definition netevent.h:247
int tcp_check_nb_connect
Definition netevent.h:260
size_t tcp_byte_count
Definition netevent.h:171
enum comm_point::@032366052243257054373201124345267221037176053226 ssl_shake_state
int cur_tcp_count
Definition netevent.h:181
void * cb_arg
Definition netevent.h:303
struct timeval * timeout
Definition netevent.h:162
struct sldns_buffer * http_temp
Definition netevent.h:215
struct sockaddr_storage addr
Definition netevent.h:116
union comm_reply::@373044044211123335325344221147267262177051357253 pktinfo
size_t max_udp_size
Definition netevent.h:142
int srctype
Definition netevent.h:120
socklen_t addrlen
Definition netevent.h:118
struct comm_point * c
Definition netevent.h:114
struct comm_base * base
Definition netevent.h:325
void(* callback)(int, void *)
Definition netevent.h:331
void * cb_arg
Definition netevent.h:334
struct internal_signal * ev_signal
Definition netevent.h:328
struct internal_timer * ev_timer
Definition netevent.h:311
void(* callback)(void *)
Definition netevent.h:314
void * cb_arg
Definition netevent.h:317