#include <isc/event.h>
#include <isc/eventclass.h>
#include <isc/netaddr.h>
#include <isc/sockaddr.h>
#include <isc/types.h>
#include <dns/fixedname.h>
#include <dns/types.h>
#include <lwres/lwres.h>
#include <named/lwsearch.h>
Go to the source code of this file.
Data Structures | |
struct | ns_lwdclient |
Lightweight Resolver Daemon Client. More... | |
struct | ns_lwdclientmgr |
lightweight daemon client manager More... | |
Defines | |
#define | NAMED_LWDCLIENT_H 1 |
#define | LWRD_EVENTCLASS ISC_EVENTCLASS(4242) |
#define | LWRD_SHUTDOWN (LWRD_EVENTCLASS + 0x0001) |
#define | NS_LWDCLIENT_STATEIDLE 1 |
Client states. | |
#define | NS_LWDCLIENT_STATERECV 2 |
#define | NS_LWDCLIENT_STATERECVDONE 3 |
#define | NS_LWDCLIENT_STATEFINDWAIT 4 |
#define | NS_LWDCLIENT_STATESEND 5 |
#define | NS_LWDCLIENT_STATESENDDONE 6 |
#define | NS_LWDCLIENT_ISIDLE(c) ((c)->state == NS_LWDCLIENT_STATEIDLE) |
#define | NS_LWDCLIENT_ISRECV(c) ((c)->state == NS_LWDCLIENT_STATERECV) |
#define | NS_LWDCLIENT_ISRECVDONE(c) ((c)->state == NS_LWDCLIENT_STATERECVDONE) |
#define | NS_LWDCLIENT_ISFINDWAIT(c) ((c)->state == NS_LWDCLIENT_STATEFINDWAIT) |
#define | NS_LWDCLIENT_ISSEND(c) ((c)->state == NS_LWDCLIENT_STATESEND) |
#define | NS_LWDCLIENT_ISRUNNING(c) (!NS_LWDCLIENT_ISIDLE(c)) |
Overall magic test that means we're not idle. | |
#define | NS_LWDCLIENT_SETIDLE(c) ((c)->state = NS_LWDCLIENT_STATEIDLE) |
#define | NS_LWDCLIENT_SETRECV(c) ((c)->state = NS_LWDCLIENT_STATERECV) |
#define | NS_LWDCLIENT_SETRECVDONE(c) ((c)->state = NS_LWDCLIENT_STATERECVDONE) |
#define | NS_LWDCLIENT_SETFINDWAIT(c) ((c)->state = NS_LWDCLIENT_STATEFINDWAIT) |
#define | NS_LWDCLIENT_SETSEND(c) ((c)->state = NS_LWDCLIENT_STATESEND) |
#define | NS_LWDCLIENT_SETSENDDONE(c) ((c)->state = NS_LWDCLIENT_STATESENDDONE) |
#define | NS_LWDCLIENTMGR_FLAGRECVPENDING 0x00000001 |
#define | NS_LWDCLIENTMGR_FLAGSHUTTINGDOWN 0x00000002 |
Functions | |
isc_result_t | ns_lwdclientmgr_create (ns_lwreslistener_t *, unsigned int, isc_taskmgr_t *) |
void | ns_lwdclient_initialize (ns_lwdclient_t *, ns_lwdclientmgr_t *) |
isc_result_t | ns_lwdclient_startrecv (ns_lwdclientmgr_t *) |
void | ns_lwdclient_stateidle (ns_lwdclient_t *) |
void | ns_lwdclient_recv (isc_task_t *, isc_event_t *) |
void | ns_lwdclient_shutdown (isc_task_t *, isc_event_t *) |
void | ns_lwdclient_send (isc_task_t *, isc_event_t *) |
isc_result_t | ns_lwdclient_sendreply (ns_lwdclient_t *client, isc_region_t *r) |
void | ns_lwdclient_processgabn (ns_lwdclient_t *, lwres_buffer_t *) |
void | ns_lwdclient_processgnba (ns_lwdclient_t *, lwres_buffer_t *) |
void | ns_lwdclient_processgrbn (ns_lwdclient_t *, lwres_buffer_t *) |
void | ns_lwdclient_processnoop (ns_lwdclient_t *, lwres_buffer_t *) |
void | ns_lwdclient_errorpktsend (ns_lwdclient_t *, isc_uint32_t) |
Generate an error packet for the client, schedule a send, and put us in the SEND state. | |
void | ns_lwdclient_log (int level, const char *format,...) ISC_FORMAT_PRINTF(2 |
Definition in file lwdclient.h.
#define NAMED_LWDCLIENT_H 1 |
Definition at line 21 of file lwdclient.h.
#define LWRD_EVENTCLASS ISC_EVENTCLASS(4242) |
Definition at line 38 of file lwdclient.h.
#define LWRD_SHUTDOWN (LWRD_EVENTCLASS + 0x0001) |
Definition at line 40 of file lwdclient.h.
#define NS_LWDCLIENT_STATEIDLE 1 |
Client states.
_IDLE The client is not doing anything at all.
_RECV The client is waiting for data after issuing a socket recv().
_RECVDONE Data has been received, and is being processed.
_FINDWAIT An adb (or other) request was made that cannot be satisfied immediately. An event will wake the client up.
_SEND All data for a response has completed, and a reply was sent via a socket send() call.
Badly formatted state table:
IDLE -> RECV when client has a recv() queued.
RECV -> RECVDONE when recvdone event received.
RECVDONE -> SEND if the data for a reply is at hand. RECVDONE -> FINDWAIT if more searching is needed, and events will eventually wake us up again.
FINDWAIT -> SEND when enough data was received to reply.
SEND -> IDLE when a senddone event was received.
At any time -> IDLE on error. Sometimes this will be -> SEND instead, if enough data is on hand to reply with a meaningful error.
Packets which are badly formatted may or may not get error returns.
Definition at line 144 of file lwdclient.h.
#define NS_LWDCLIENT_STATERECV 2 |
Definition at line 145 of file lwdclient.h.
#define NS_LWDCLIENT_STATERECVDONE 3 |
Definition at line 146 of file lwdclient.h.
#define NS_LWDCLIENT_STATEFINDWAIT 4 |
Definition at line 147 of file lwdclient.h.
#define NS_LWDCLIENT_STATESEND 5 |
Definition at line 148 of file lwdclient.h.
#define NS_LWDCLIENT_STATESENDDONE 6 |
Definition at line 149 of file lwdclient.h.
#define NS_LWDCLIENT_ISIDLE | ( | c | ) | ((c)->state == NS_LWDCLIENT_STATEIDLE) |
#define NS_LWDCLIENT_ISRECV | ( | c | ) | ((c)->state == NS_LWDCLIENT_STATERECV) |
#define NS_LWDCLIENT_ISRECVDONE | ( | c | ) | ((c)->state == NS_LWDCLIENT_STATERECVDONE) |
Definition at line 155 of file lwdclient.h.
Referenced by ns_lwdclient_processgabn(), ns_lwdclient_processgnba(), ns_lwdclient_processgrbn(), and ns_lwdclient_processnoop().
#define NS_LWDCLIENT_ISFINDWAIT | ( | c | ) | ((c)->state == NS_LWDCLIENT_STATEFINDWAIT) |
Definition at line 157 of file lwdclient.h.
#define NS_LWDCLIENT_ISSEND | ( | c | ) | ((c)->state == NS_LWDCLIENT_STATESEND) |
#define NS_LWDCLIENT_ISRUNNING | ( | c | ) | (!NS_LWDCLIENT_ISIDLE(c)) |
Overall magic test that means we're not idle.
Definition at line 165 of file lwdclient.h.
Referenced by ns_lwdclient_errorpktsend().
#define NS_LWDCLIENT_SETIDLE | ( | c | ) | ((c)->state = NS_LWDCLIENT_STATEIDLE) |
Definition at line 167 of file lwdclient.h.
Referenced by ns_lwdclient_initialize(), and ns_lwdclient_stateidle().
#define NS_LWDCLIENT_SETRECV | ( | c | ) | ((c)->state = NS_LWDCLIENT_STATERECV) |
#define NS_LWDCLIENT_SETRECVDONE | ( | c | ) | ((c)->state = NS_LWDCLIENT_STATERECVDONE) |
#define NS_LWDCLIENT_SETFINDWAIT | ( | c | ) | ((c)->state = NS_LWDCLIENT_STATEFINDWAIT) |
Definition at line 173 of file lwdclient.h.
#define NS_LWDCLIENT_SETSEND | ( | c | ) | ((c)->state = NS_LWDCLIENT_STATESEND) |
Definition at line 175 of file lwdclient.h.
Referenced by byaddr_done(), generate_reply(), lookup_done(), ns_lwdclient_errorpktsend(), and ns_lwdclient_processnoop().
#define NS_LWDCLIENT_SETSENDDONE | ( | c | ) | ((c)->state = NS_LWDCLIENT_STATESENDDONE) |
Definition at line 177 of file lwdclient.h.
#define NS_LWDCLIENTMGR_FLAGRECVPENDING 0x00000001 |
Definition at line 194 of file lwdclient.h.
Referenced by ns_lwdclient_recv(), and ns_lwdclient_startrecv().
#define NS_LWDCLIENTMGR_FLAGSHUTTINGDOWN 0x00000002 |
isc_result_t ns_lwdclientmgr_create | ( | ns_lwreslistener_t * | , | |
unsigned | int, | |||
isc_taskmgr_t * | ||||
) |
Definition at line 55 of file lwdclient.c.
References ns_lwdclientmgr::flags, ISC_LINK_INIT, ISC_LIST_EMPTY, ISC_LIST_HEAD, ISC_LIST_INIT, ISC_LIST_UNLINK, isc_mem_get, isc_mem_put, ISC_R_FAILURE, ISC_R_NOMEMORY, ISC_R_SUCCESS, isc_socket_attach(), isc_task_create(), isc_task_detach(), isc_task_onshutdown(), isc_task_setname(), ns_lwdclientmgr::listener, ns_lwdclientmgr::lwctx, lwdclientmgr_shutdown_callback(), ns_lwreslistener::manager, ns_lwdclientmgr::mctx, ns_lwresd::mctx, ns__lwresd_memalloc(), ns__lwresd_memfree(), ns_lwdclient_initialize(), ns_lwdclient_log(), ns_lwreslistener_attach(), ns_lwreslistener_linkcm(), ns_lwreslistener::sock, ns_lwdclientmgr::sock, ns_lwdclientmgr::task, ns_lwresd::view, and ns_lwdclientmgr::view.
Referenced by listener_startclients().
void ns_lwdclient_initialize | ( | ns_lwdclient_t * | , | |
ns_lwdclientmgr_t * | ||||
) |
Definition at line 444 of file lwdclient.c.
References ns_lwdclient::arg, ns_lwdclient::byaddr, ns_lwdclient::clientmgr, ns_lwdclient::find, ns_lwdclient::find_wanted, ISC_FALSE, ISC_LINK_INIT, ISC_LIST_APPEND, ns_lwdclient::lookup, NS_LWDCLIENT_SETIDLE, ns_lwdclient::options, ns_lwdclient::pktinfo_valid, ns_lwdclient::recvlength, ns_lwdclient::sendbuf, ns_lwdclient::sendlength, ns_lwdclient::v4find, and ns_lwdclient::v6find.
Referenced by ns_lwdclientmgr_create().
isc_result_t ns_lwdclient_startrecv | ( | ns_lwdclientmgr_t * | ) |
Definition at line 273 of file lwdclient.c.
References isc_region::base, ns_lwdclient::buffer, ns_lwdclientmgr::flags, INSIST, ISC_LIST_APPEND, ISC_LIST_HEAD, ISC_LIST_UNLINK, ISC_R_SUCCESS, isc_socket_recv(), isc_region::length, lwdclientmgr_destroy(), NS_LWDCLIENT_ISIDLE, ns_lwdclient_recv(), NS_LWDCLIENT_SETRECV, NS_LWDCLIENTMGR_FLAGRECVPENDING, r, SHUTTINGDOWN, ns_lwdclientmgr::sock, and ns_lwdclientmgr::task.
Referenced by listener_startclients(), ns_lwdclient_recv(), and ns_lwdclient_stateidle().
void ns_lwdclient_stateidle | ( | ns_lwdclient_t * | ) |
Definition at line 378 of file lwdclient.c.
References ns_lwdclient::arg, ns_lwdclient::clientmgr, INSIST, ISC_LIST_PREPEND, ISC_LIST_UNLINK, ISC_LOG_ERROR, isc_log_write(), ISC_R_SUCCESS, isc_result_totext(), NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_LWRESD, NS_LWDCLIENT_SETIDLE, ns_lwdclient_startrecv(), ns_lwdclient::sendbuf, ns_lwdclient::sendlength, ns_lwdclient::v4find, and ns_lwdclient::v6find.
Referenced by ns_lwdclient_errorpktsend(), ns_lwdclient_recv(), ns_lwdclient_send(), and process_request().
void ns_lwdclient_recv | ( | isc_task_t * | , | |
isc_event_t * | ||||
) |
Definition at line 217 of file lwdclient.c.
References isc_socketevent::address, ns_lwdclient::address, isc_socketevent::attributes, isc_region::base, ns_lwdclient::buffer, ns_lwdclient::clientmgr, ns_lwdclientmgr::flags, INSIST, isc_event_free(), ISC_FALSE, ISC_LOG_ERROR, isc_log_write(), ISC_R_SUCCESS, isc_result_totext(), ISC_SOCKEVENTATTR_PKTINFO, ISC_TRUE, isc_socketevent::n, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_LWRESD, NS_LWDCLIENT_ISRECV, ns_lwdclient_log(), NS_LWDCLIENT_SETRECVDONE, ns_lwdclient_startrecv(), ns_lwdclient_stateidle(), NS_LWDCLIENTMGR_FLAGRECVPENDING, isc_socketevent::pktinfo, ns_lwdclient::pktinfo, ns_lwdclient::pktinfo_valid, process_request(), ns_lwdclient::recvlength, isc_socketevent::region, and isc_socketevent::result.
Referenced by ns_lwdclient_startrecv().
void ns_lwdclient_shutdown | ( | isc_task_t * | , | |
isc_event_t * | ||||
) |
void ns_lwdclient_send | ( | isc_task_t * | , | |
isc_event_t * | ||||
) |
Definition at line 405 of file lwdclient.c.
References isc_region::base, ns_lwdclient::buffer, ns_lwdclient::clientmgr, INSIST, isc_event_free(), ns_lwdclientmgr::lwctx, NS_LWDCLIENT_ISSEND, ns_lwdclient_log(), ns_lwdclient_stateidle(), isc_socketevent::region, ns_lwdclient::sendbuf, ns_lwdclient::sendlength, and UNUSED.
Referenced by ns_lwdclient_sendreply().
isc_result_t ns_lwdclient_sendreply | ( | ns_lwdclient_t * | client, | |
isc_region_t * | r | |||
) |
Definition at line 431 of file lwdclient.c.
References ns_lwdclient::address, ns_lwdclient::clientmgr, isc_socket_sendto(), ns_lwdclient_send(), ns_lwdclient::pktinfo, ns_lwdclient::pktinfo_valid, ns_lwdclientmgr::sock, and ns_lwdclientmgr::task.
Referenced by byaddr_done(), generate_reply(), lookup_done(), ns_lwdclient_errorpktsend(), and ns_lwdclient_processnoop().
void ns_lwdclient_processgabn | ( | ns_lwdclient_t * | , | |
lwres_buffer_t * | ||||
) |
Definition at line 598 of file lwdgabn.c.
References ns_lwdclient::clientmgr, dns_fixedname_init, dns_fixedname_name, dns_name_fromtext(), ns_lwdclient::find_wanted, isc_buffer_add, isc_buffer_init, ISC_R_SUCCESS, ns_lwdclientmgr::listener, ns_lwdclientmgr::lwctx, ns_lwreslistener::manager, namebuf, ns_lwresd::ndots, ns_lwdclient_errorpktsend(), NS_LWDCLIENT_ISRECVDONE, ns_lwdclient_log(), ns_lwsearchctx_first(), ns_lwsearchctx_init(), ns_lwdclient::pkt, ns_lwdclient::query_name, REQUIRE, ns_lwresd::search, ns_lwdclient::searchctx, start_find(), and ns_lwdclient::target_name.
Referenced by process_request().
void ns_lwdclient_processgnba | ( | ns_lwdclient_t * | , | |
lwres_buffer_t * | ||||
) |
Definition at line 207 of file lwdgnba.c.
References AF_INET6, ns_lwdclient::byaddr, ns_lwdclient::clientmgr, isc_netaddr::family, isc_netaddr::in, isc_netaddr::in6, init_gnba(), INSIST, isc_sockaddr_fromnetaddr(), ns_lwdclientmgr::lwctx, ns_lwdclient::na, ns_lwdclient_errorpktsend(), NS_LWDCLIENT_ISRECVDONE, ns_lwdclient_log(), ns_lwdclient::options, ns_lwdclient::pkt, REQUIRE, start_byaddr(), and isc_netaddr::type.
Referenced by process_request().
void ns_lwdclient_processgrbn | ( | ns_lwdclient_t * | , | |
lwres_buffer_t * | ||||
) |
Definition at line 442 of file lwdgrbn.c.
References ns_lwdclient::byaddr, ns_lwdclient::clientmgr, dns_fixedname_init, dns_fixedname_name, dns_name_fromtext(), init_grbn(), INSIST, isc_buffer_add, isc_buffer_init, ISC_R_SUCCESS, ns_lwdclientmgr::listener, ns_lwdclientmgr::lwctx, ns_lwreslistener::manager, namebuf, ns_lwresd::ndots, ns_lwdclient_errorpktsend(), NS_LWDCLIENT_ISRECVDONE, ns_lwdclient_log(), ns_lwsearchctx_first(), ns_lwsearchctx_init(), ns_lwdclient::options, ns_lwdclient::pkt, ns_lwdclient::query_name, dns_view::rdclass, ns_lwdclient::rdtype, REQUIRE, ns_lwresd::search, ns_lwdclient::searchctx, start_lookup(), and ns_lwdclientmgr::view.
Referenced by process_request().
void ns_lwdclient_processnoop | ( | ns_lwdclient_t * | , | |
lwres_buffer_t * | ||||
) |
Definition at line 31 of file lwdnoop.c.
References isc_region::base, ns_lwdclient::byaddr, ns_lwdclient::clientmgr, INSIST, ISC_R_SUCCESS, isc_region::length, ns_lwdclientmgr::lwctx, ns_lwdclient_errorpktsend(), NS_LWDCLIENT_ISRECVDONE, ns_lwdclient_sendreply(), NS_LWDCLIENT_SETSEND, ns_lwdclient::pkt, r, REQUIRE, ns_lwdclient::sendbuf, and ns_lwdclient::sendlength.
Referenced by process_request().
void ns_lwdclient_errorpktsend | ( | ns_lwdclient_t * | client, | |
isc_uint32_t | _result | |||
) |
Generate an error packet for the client, schedule a send, and put us in the SEND state.
The client->pkt structure will be modified to form an error return. The receiver needs to verify that it is in fact an error, and do the right thing with it. The opcode will be unchanged. The result needs to be set before calling this function.
The only change this code makes is to set the receive buffer size to the size we use, set the reply bit, and recompute any security information.
Definition at line 43 of file lwderror.c.
References isc_region::base, ns_lwdclient::buffer, ISC_R_SUCCESS, isc_region::length, NS_LWDCLIENT_ISRUNNING, ns_lwdclient_sendreply(), NS_LWDCLIENT_SETSEND, ns_lwdclient_stateidle(), ns_lwdclient::pkt, r, REQUIRE, and ns_lwdclient::sendbuf.
Referenced by byaddr_done(), generate_reply(), lookup_done(), ns_lwdclient_processgabn(), ns_lwdclient_processgnba(), ns_lwdclient_processgrbn(), ns_lwdclient_processnoop(), process_gabn_finddone(), restart_find(), start_byaddr(), and start_lookup().
void ns_lwdclient_log | ( | int | level, | |
const char * | format, | |||
... | ||||
) |
Referenced by byaddr_done(), cleanup_gabn(), generate_reply(), lookup_done(), lwdclientmgr_destroy(), lwdclientmgr_shutdown_callback(), ns_lwdclient_processgabn(), ns_lwdclient_processgnba(), ns_lwdclient_processgrbn(), ns_lwdclient_recv(), ns_lwdclient_send(), ns_lwdclientmgr_create(), process_gabn_finddone(), process_request(), restart_find(), and setup_addresses().