41 static const char* dnsh_str =
"dnshandler";
43 static void dnshandler_handle_xfr(
netio_type* netio,
54 if (!interfaces || interfaces->
count <= 0) {
59 ods_log_error(
"[%s] unable to create dnshandler: " 60 "allocator_alloc() failed", dnsh_str);
72 ods_log_error(
"[%s] unable to create socklist: " 73 "allocator_alloc() failed", dnsh_str);
79 ods_log_error(
"[%s] unable to create dnshandler: " 80 "netio_create() failed", dnsh_str);
86 ods_log_error(
"[%s] unable to create dnshandler: " 87 "query_create() failed", dnsh_str);
107 ods_status status = ODS_STATUS_OK;
108 ods_log_assert(dnshandler);
110 if (status != ODS_STATUS_OK) {
111 ods_log_error(
"[%s] unable to start: sock_listen() " 112 "failed (%s)", dnsh_str, ods_status2str(status));
130 ods_log_assert(dnshandler);
131 ods_log_assert(dnshandler->
engine);
132 ods_log_debug(
"[%s] start", dnsh_str);
134 engine = dnshandler->
engine;
141 ods_log_error(
"[%s] unable to start: allocator_alloc() " 152 ods_log_error(
"[%s] unable to start: allocator_alloc() " 164 ods_log_debug(
"[%s] add udp network handler fd %u", dnsh_str,
165 (
unsigned) handler->
fd);
175 ods_log_error(
"[%s] unable to start: allocator_alloc() " 185 handler = &tcp_accept_handlers[i];
191 ods_log_debug(
"[%s] add tcp network handler fd %u", dnsh_str,
192 (
unsigned) handler->
fd);
197 ods_log_deeebug(
"[%s] netio dispatch", dnsh_str);
199 if (errno != EINTR) {
200 ods_log_error(
"[%s] unable to dispatch netio: %s", dnsh_str,
207 ods_log_debug(
"[%s] shutdown", dnsh_str);
208 free(tcp_accept_handlers);
229 if (dnshandler && dnshandler->
thread_id) {
230 ods_thread_kill(dnshandler->
thread_id, SIGHUP);
243 ods_log_assert(dnshandler);
245 nb = send(dnshandler->
xfrhandler.
fd, (
const void*) pkt, len, 0);
247 ods_log_error(
"[%s] unable to forward notify: send() failed (%s)",
248 dnsh_str, strerror(errno));
250 ods_log_debug(
"[%s] forwarded notify: %ld bytes sent", dnsh_str, (
long)nb);
260 dnshandler_handle_xfr(
netio_type* ATTR_UNUSED(netio),
265 ssize_t received = 0;
272 ods_log_debug(
"[%s] read forwarded xfr packet: %d bytes received",
273 dnsh_str, (
int) received);
274 if (received == -1) {
275 ods_log_error(
"[%s] unable to forward xfr packet: %s", dnsh_str,
query_type * query_create(void)
void query_cleanup(query_type *q)
ods_status dnshandler_listen(dnshandler_type *dnshandler)
listener_type * interfaces
enum netio_events_enum netio_events_type
void sock_handle_udp(netio_type *ATTR_UNUSED(netio), netio_handler_type *handler, netio_events_type event_types)
void sock_handle_tcp_accept(netio_type *netio, netio_handler_type *handler, netio_events_type event_types)
sock_type udp[MAX_INTERFACES]
void netio_add_handler(netio_type *netio, netio_handler_type *handler)
sock_type tcp[MAX_INTERFACES]
void dnshandler_signal(dnshandler_type *dnshandler)
netio_handler_type * tcp_accept_handlers
size_t tcp_accept_handler_count
netio_event_handler_type event_handler
ods_status sock_listen(socklist_type *sockets, listener_type *listener)
netio_handler_type xfrhandler
netio_events_type event_types
netio_type * netio_create()
dnshandler_type * dnshandler_create(listener_type *interfaces)
ods_thread_type thread_id
void dnshandler_start(dnshandler_type *dnshandler)
struct timespec * timeout
void dnshandler_fwd_notify(dnshandler_type *dnshandler, uint8_t *pkt, size_t len)
int netio_dispatch(netio_type *netio, const struct timespec *timeout, const sigset_t *sigmask)
void netio_cleanup(netio_type *netio)
void dnshandler_cleanup(dnshandler_type *dnshandler)