lwdclient.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004, 2005, 2007, 2009  Internet Systems Consortium, Inc. ("ISC")
00003  * Copyright (C) 2000, 2001  Internet Software Consortium.
00004  *
00005  * Permission to use, copy, modify, and/or distribute this software for any
00006  * purpose with or without fee is hereby granted, provided that the above
00007  * copyright notice and this permission notice appear in all copies.
00008  *
00009  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
00010  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
00011  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
00012  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
00013  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
00014  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00015  * PERFORMANCE OF THIS SOFTWARE.
00016  */
00017 
00018 /* $Id: lwdclient.h,v 1.20 2009/01/17 23:47:42 tbox Exp $ */
00019 
00020 #ifndef NAMED_LWDCLIENT_H
00021 #define NAMED_LWDCLIENT_H 1
00022 
00023 /*! \file */
00024 
00025 #include <isc/event.h>
00026 #include <isc/eventclass.h>
00027 #include <isc/netaddr.h>
00028 #include <isc/sockaddr.h>
00029 #include <isc/types.h>
00030 
00031 #include <dns/fixedname.h>
00032 #include <dns/types.h>
00033 
00034 #include <lwres/lwres.h>
00035 
00036 #include <named/lwsearch.h>
00037 
00038 #define LWRD_EVENTCLASS         ISC_EVENTCLASS(4242)
00039 
00040 #define LWRD_SHUTDOWN           (LWRD_EVENTCLASS + 0x0001)
00041 
00042 /*% Lightweight Resolver Daemon Client */
00043 struct ns_lwdclient {
00044         isc_sockaddr_t          address;        /*%< where to reply */
00045         struct in6_pktinfo      pktinfo;
00046         isc_boolean_t           pktinfo_valid;
00047         ns_lwdclientmgr_t       *clientmgr;     /*%< our parent */
00048         ISC_LINK(ns_lwdclient_t) link;
00049         unsigned int            state;
00050         void                    *arg;           /*%< packet processing state */
00051 
00052         /*
00053          * Received data info.
00054          */
00055         unsigned char           buffer[LWRES_RECVLENGTH]; /*%< receive buffer */
00056         isc_uint32_t            recvlength;     /*%< length recv'd */
00057         lwres_lwpacket_t        pkt;
00058 
00059         /*%
00060          * Send data state.  If sendbuf != buffer (that is, the send buffer
00061          * isn't our receive buffer) it will be freed to the lwres_context_t.
00062          */
00063         unsigned char          *sendbuf;
00064         isc_uint32_t            sendlength;
00065         isc_buffer_t            recv_buffer;
00066 
00067         /*%
00068          * gabn (get address by name) state info.
00069          */
00070         dns_adbfind_t           *find;
00071         dns_adbfind_t           *v4find;
00072         dns_adbfind_t           *v6find;
00073         unsigned int            find_wanted;    /*%< Addresses we want */
00074         dns_fixedname_t         query_name;
00075         dns_fixedname_t         target_name;
00076         ns_lwsearchctx_t        searchctx;
00077         lwres_gabnresponse_t    gabn;
00078 
00079         /*%
00080          * gnba (get name by address) state info.
00081          */
00082         lwres_gnbaresponse_t    gnba;
00083         dns_byaddr_t           *byaddr;
00084         unsigned int            options;
00085         isc_netaddr_t           na;
00086 
00087         /*%
00088          * grbn (get rrset by name) state info.
00089          *
00090          * Note: this also uses target_name and searchctx.
00091          */
00092         lwres_grbnresponse_t    grbn;
00093         dns_lookup_t           *lookup;
00094         dns_rdatatype_t         rdtype;
00095 
00096         /*%
00097          * Alias and address info.  This is copied up to the gabn/gnba
00098          * structures eventually.
00099          *
00100          * XXXMLG We can keep all of this in a client since we only service
00101          * three packet types right now.  If we started handling more,
00102          * we'd need to use "arg" above and allocate/destroy things.
00103          */
00104         char                   *aliases[LWRES_MAX_ALIASES];
00105         isc_uint16_t            aliaslen[LWRES_MAX_ALIASES];
00106         lwres_addr_t            addrs[LWRES_MAX_ADDRS];
00107 };
00108 
00109 /*%
00110  * Client states.
00111  *
00112  * _IDLE        The client is not doing anything at all.
00113  *
00114  * _RECV        The client is waiting for data after issuing a socket recv().
00115  *
00116  * _RECVDONE    Data has been received, and is being processed.
00117  *
00118  * _FINDWAIT    An adb (or other) request was made that cannot be satisfied
00119  *              immediately.  An event will wake the client up.
00120  *
00121  * _SEND        All data for a response has completed, and a reply was
00122  *              sent via a socket send() call.
00123  *
00124  * Badly formatted state table:
00125  *
00126  *      IDLE -> RECV when client has a recv() queued.
00127  *
00128  *      RECV -> RECVDONE when recvdone event received.
00129  *
00130  *      RECVDONE -> SEND if the data for a reply is at hand.
00131  *      RECVDONE -> FINDWAIT if more searching is needed, and events will
00132  *              eventually wake us up again.
00133  *
00134  *      FINDWAIT -> SEND when enough data was received to reply.
00135  *
00136  *      SEND -> IDLE when a senddone event was received.
00137  *
00138  *      At any time -> IDLE on error.  Sometimes this will be -> SEND
00139  *      instead, if enough data is on hand to reply with a meaningful
00140  *      error.
00141  *
00142  *      Packets which are badly formatted may or may not get error returns.
00143  */
00144 #define NS_LWDCLIENT_STATEIDLE          1
00145 #define NS_LWDCLIENT_STATERECV          2
00146 #define NS_LWDCLIENT_STATERECVDONE      3
00147 #define NS_LWDCLIENT_STATEFINDWAIT      4
00148 #define NS_LWDCLIENT_STATESEND          5
00149 #define NS_LWDCLIENT_STATESENDDONE      6
00150 
00151 #define NS_LWDCLIENT_ISIDLE(c)          \
00152                         ((c)->state == NS_LWDCLIENT_STATEIDLE)
00153 #define NS_LWDCLIENT_ISRECV(c)          \
00154                         ((c)->state == NS_LWDCLIENT_STATERECV)
00155 #define NS_LWDCLIENT_ISRECVDONE(c)      \
00156                         ((c)->state == NS_LWDCLIENT_STATERECVDONE)
00157 #define NS_LWDCLIENT_ISFINDWAIT(c)      \
00158                         ((c)->state == NS_LWDCLIENT_STATEFINDWAIT)
00159 #define NS_LWDCLIENT_ISSEND(c)          \
00160                         ((c)->state == NS_LWDCLIENT_STATESEND)
00161 
00162 /*%
00163  * Overall magic test that means we're not idle.
00164  */
00165 #define NS_LWDCLIENT_ISRUNNING(c)       (!NS_LWDCLIENT_ISIDLE(c))
00166 
00167 #define NS_LWDCLIENT_SETIDLE(c)         \
00168                         ((c)->state = NS_LWDCLIENT_STATEIDLE)
00169 #define NS_LWDCLIENT_SETRECV(c)         \
00170                         ((c)->state = NS_LWDCLIENT_STATERECV)
00171 #define NS_LWDCLIENT_SETRECVDONE(c)     \
00172                         ((c)->state = NS_LWDCLIENT_STATERECVDONE)
00173 #define NS_LWDCLIENT_SETFINDWAIT(c)     \
00174                         ((c)->state = NS_LWDCLIENT_STATEFINDWAIT)
00175 #define NS_LWDCLIENT_SETSEND(c)         \
00176                         ((c)->state = NS_LWDCLIENT_STATESEND)
00177 #define NS_LWDCLIENT_SETSENDDONE(c)     \
00178                         ((c)->state = NS_LWDCLIENT_STATESENDDONE)
00179 
00180 /*% lightweight daemon client manager */
00181 struct ns_lwdclientmgr {
00182         ns_lwreslistener_t     *listener;
00183         isc_mem_t              *mctx;
00184         isc_socket_t           *sock;           /*%< socket to use */
00185         dns_view_t             *view;
00186         lwres_context_t        *lwctx;          /*%< lightweight proto context */
00187         isc_task_t             *task;           /*%< owning task */
00188         unsigned int            flags;
00189         ISC_LINK(ns_lwdclientmgr_t)     link;
00190         ISC_LIST(ns_lwdclient_t)        idle;           /*%< idle client slots */
00191         ISC_LIST(ns_lwdclient_t)        running;        /*%< running clients */
00192 };
00193 
00194 #define NS_LWDCLIENTMGR_FLAGRECVPENDING         0x00000001
00195 #define NS_LWDCLIENTMGR_FLAGSHUTTINGDOWN        0x00000002
00196 
00197 isc_result_t
00198 ns_lwdclientmgr_create(ns_lwreslistener_t *, unsigned int, isc_taskmgr_t *);
00199 
00200 void
00201 ns_lwdclient_initialize(ns_lwdclient_t *, ns_lwdclientmgr_t *);
00202 
00203 isc_result_t
00204 ns_lwdclient_startrecv(ns_lwdclientmgr_t *);
00205 
00206 void
00207 ns_lwdclient_stateidle(ns_lwdclient_t *);
00208 
00209 void
00210 ns_lwdclient_recv(isc_task_t *, isc_event_t *);
00211 
00212 void
00213 ns_lwdclient_shutdown(isc_task_t *, isc_event_t *);
00214 
00215 void
00216 ns_lwdclient_send(isc_task_t *, isc_event_t *);
00217 
00218 isc_result_t
00219 ns_lwdclient_sendreply(ns_lwdclient_t *client, isc_region_t *r);
00220 
00221 /*
00222  * Processing functions of various types.
00223  */
00224 void ns_lwdclient_processgabn(ns_lwdclient_t *, lwres_buffer_t *);
00225 void ns_lwdclient_processgnba(ns_lwdclient_t *, lwres_buffer_t *);
00226 void ns_lwdclient_processgrbn(ns_lwdclient_t *, lwres_buffer_t *);
00227 void ns_lwdclient_processnoop(ns_lwdclient_t *, lwres_buffer_t *);
00228 
00229 void ns_lwdclient_errorpktsend(ns_lwdclient_t *, isc_uint32_t);
00230 
00231 void ns_lwdclient_log(int level, const char *format, ...)
00232      ISC_FORMAT_PRINTF(2, 3);
00233 
00234 #endif /* NAMED_LWDCLIENT_H */

Generated on Tue Apr 28 17:40:54 2015 by Doxygen 1.5.4 for BIND9 Internals 9.11.0pre-alpha