00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef NAMED_LWDCLIENT_H
00021 #define NAMED_LWDCLIENT_H 1
00022
00023
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
00043 struct ns_lwdclient {
00044 isc_sockaddr_t address;
00045 struct in6_pktinfo pktinfo;
00046 isc_boolean_t pktinfo_valid;
00047 ns_lwdclientmgr_t *clientmgr;
00048 ISC_LINK(ns_lwdclient_t) link;
00049 unsigned int state;
00050 void *arg;
00051
00052
00053
00054
00055 unsigned char buffer[LWRES_RECVLENGTH];
00056 isc_uint32_t recvlength;
00057 lwres_lwpacket_t pkt;
00058
00059
00060
00061
00062
00063 unsigned char *sendbuf;
00064 isc_uint32_t sendlength;
00065 isc_buffer_t recv_buffer;
00066
00067
00068
00069
00070 dns_adbfind_t *find;
00071 dns_adbfind_t *v4find;
00072 dns_adbfind_t *v6find;
00073 unsigned int find_wanted;
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
00081
00082 lwres_gnbaresponse_t gnba;
00083 dns_byaddr_t *byaddr;
00084 unsigned int options;
00085 isc_netaddr_t na;
00086
00087
00088
00089
00090
00091
00092 lwres_grbnresponse_t grbn;
00093 dns_lookup_t *lookup;
00094 dns_rdatatype_t rdtype;
00095
00096
00097
00098
00099
00100
00101
00102
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
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
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
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
00181 struct ns_lwdclientmgr {
00182 ns_lwreslistener_t *listener;
00183 isc_mem_t *mctx;
00184 isc_socket_t *sock;
00185 dns_view_t *view;
00186 lwres_context_t *lwctx;
00187 isc_task_t *task;
00188 unsigned int flags;
00189 ISC_LINK(ns_lwdclientmgr_t) link;
00190 ISC_LIST(ns_lwdclient_t) idle;
00191 ISC_LIST(ns_lwdclient_t) running;
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
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