-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathevldns.h
126 lines (104 loc) · 4.48 KB
/
evldns.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
* $Id$
*
* Copyright (c) 2009, Nominet UK.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Nominet UK nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY Nominet UK ''AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL Nominet UK BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef EVLDNS_H
#define EVLDNS_H
#ifdef __cplusplus
extern "C" {
#endif
#include <sys/queue.h>
#include <event.h>
#include <ldns/ldns.h>
/* forward declarations */
struct evldns_server;
struct evldns_server_port;
struct evldns_server_request;
/* type declarations */
struct evldns_server_request {
/* the parent server */
struct evldns_server_port *port;
/* current socket and (optional) event object */
int socket;
struct event *event;
/* the client's address */
struct sockaddr_storage addr;
socklen_t addrlen;
/* formatted DNS packets */
ldns_pkt *request;
ldns_pkt *response;
/* unformatted request data */
uint8_t *wire_request;
uint16_t wire_reqlen;
uint16_t wire_reqdone;
/* unformatted response data */
uint8_t *wire_response;
size_t wire_resplen;
size_t wire_respdone;
/* misc flags */
uint8_t wire_resphead:2;
uint8_t is_tcp:1;
uint8_t blackhole:1;
/* pending requests for UDP mode */
TAILQ_ENTRY(evldns_server_request) next;
};
typedef struct evldns_server_request evldns_server_request;
typedef void (*evldns_callback)(evldns_server_request *request, void *data, ldns_rdf *qname, ldns_rr_type qtype, ldns_rr_class qclass);
typedef int (*evldns_plugin_init)(struct evldns_server *p);
/*
* exported functions
*/
/* core evdns sort-of-clone functions */
struct evldns_server *evldns_add_server(struct event_base *);
struct evldns_server_port *evldns_add_server_port(struct evldns_server *, int socket);
void evldns_server_close(struct evldns_server_port *port);
void evldns_add_callback(struct evldns_server *server, const char *dname, ldns_rr_class rr_class, ldns_rr_type rr_type, evldns_callback callback, void *data);
ldns_pkt *evldns_response(const ldns_pkt *request, ldns_pkt_rcode rcode);
/* not-core network function - binds to a list of fds */
void evldns_add_server_ports(struct evldns_server *, const int *sockets);
/* plugin and function handling functions */
extern void evldns_init(void);
extern int evldns_load_plugin(struct evldns_server *server, const char *plugin);
extern void evldns_add_function(const char *name, evldns_callback func);
extern evldns_callback evldns_get_function(const char *name);
/* miscellaneous utility functions */
extern int bind_to_sockaddr(struct sockaddr *addr, socklen_t addrlen, int type, int backlog);
extern int bind_to_address(const char *addr, const char *port, int type, int backlog);
extern int bind_to_udp_address(const char *addr, const char *port);
extern int bind_to_tcp_address(const char *addr, const char *port, int backlog);
extern int bind_to_port(int port, int family, int type, int backlog);
extern int bind_to_udp4_port(int port);
extern int bind_to_udp6_port(int port);
extern int bind_to_tcp4_port(int port, int backlog);
extern int bind_to_tcp6_port(int port, int backlog);
extern int *bind_to_all(const char *addr, const char *port, int backlog);
extern int socket_is_tcp(int fd);
#ifdef __cplusplus
}
#endif
#endif /* EVLDNS_H */