Lines Matching refs:client

48 cleanup_gabn(ns_lwdclient_t *client) {
49 ns_lwdclient_log(50, "cleaning up client %p", client);
51 if (client->v6find != NULL) {
52 if (client->v6find == client->v4find)
53 client->v6find = NULL;
55 dns_adb_destroyfind(&client->v6find);
57 if (client->v4find != NULL)
58 dns_adb_destroyfind(&client->v4find);
62 setup_addresses(ns_lwdclient_t *client, dns_adbfind_t *find, unsigned int at) {
75 while (ai != NULL && client->gabn.naddrs < LWRES_MAX_ADDRS) {
80 addr = &client->addrs[client->gabn.naddrs];
89 client->gabn.naddrs++;
91 LWRES_LIST_APPEND(client->gabn.addrs, addr, link);
111 sort_addresses(ns_lwdclient_t *client) {
117 ns_lwresd_t *lwresd = client->clientmgr->listener->manager;
121 naddrs = client->gabn.naddrs;
130 isc_netaddr_fromsockaddr(&remote, &client->address);
140 &client->addrs[i]);
146 result = lwaddr_lwresaddr_fromnetaddr(&client->addrs[i],
155 generate_reply(ns_lwdclient_t *client) {
162 cm = client->clientmgr;
165 ns_lwdclient_log(50, "generating gabn reply for client %p", client);
168 * We must make certain the client->find is not still active.
172 if (client->find == client->v4find || client->find == client->v6find)
173 client->find = NULL;
175 if (client->find != NULL)
176 dns_adb_destroyfind(&client->find);
181 if (NEED_V6(client) && client->v4find != NULL)
182 client->v6find = client->v4find;
188 LWRES_LIST_INIT(client->gabn.addrs);
189 if (client->v4find != NULL)
190 setup_addresses(client, client->v4find, DNS_ADBFIND_INET);
191 if (client->v6find != NULL)
192 setup_addresses(client, client->v6find, DNS_ADBFIND_INET6);
199 if (client->gabn.naddrs == 0) {
201 result = ns_lwsearchctx_next(&client->searchctx);
203 cleanup_gabn(client);
204 result = start_find(client);
214 client->pkt.recvlength = LWRES_RECVLENGTH;
215 client->pkt.authtype = 0; /* XXXMLG */
216 client->pkt.authlength = 0;
221 if (client->gabn.naddrs != 0)
222 client->pkt.result = LWRES_R_SUCCESS;
224 client->pkt.result = LWRES_R_NOTFOUND;
226 sort_addresses(client);
228 lwres = lwres_gabnresponse_render(cm->lwctx, &client->gabn,
229 &client->pkt, &lwb);
235 client->sendbuf = r.base;
236 client->sendlength = r.length;
237 result = ns_lwdclient_sendreply(client, &r);
241 NS_LWDCLIENT_SETSEND(client);
246 cleanup_gabn(client);
251 cleanup_gabn(client);
254 lwres_context_freemem(client->clientmgr->lwctx,
257 ns_lwdclient_errorpktsend(client, LWRES_R_FAILURE);
268 add_alias(ns_lwdclient_t *client) {
273 b = client->recv_buffer;
278 result = dns_name_totext(dns_fixedname_name(&client->target_name),
279 ISC_TRUE, &client->recv_buffer);
286 naliases = client->gabn.naliases;
288 client->gabn.aliases[naliases] = client->gabn.realname;
289 client->gabn.aliaslen[naliases] = client->gabn.realnamelen;
290 client->gabn.naliases++;
296 client->gabn.realname = (char *)(b.base) + b.used;
297 client->gabn.realnamelen = client->recv_buffer.used - b.used;
303 store_realname(ns_lwdclient_t *client) {
308 b = client->recv_buffer;
310 tname = dns_fixedname_name(&client->target_name);
311 result = ns_lwsearchctx_current(&client->searchctx, tname);
318 result = dns_name_totext(tname, ISC_TRUE, &client->recv_buffer);
325 client->gabn.realname = (char *) b.base + b.used;
326 client->gabn.realnamelen = client->recv_buffer.used - b.used;
333 ns_lwdclient_t *client = ev->ev_arg;
337 ns_lwdclient_log(50, "find done for task %p, client %p", task, client);
348 if (NEED_V4(client)) {
349 client->v4find = client->find;
352 if (NEED_V6(client)) {
353 client->v6find = client->find;
356 if (client->find != NULL) {
358 client->find = NULL;
360 dns_adb_destroyfind(&client->find);
363 generate_reply(client);
372 if ((client->find != client->v4find)
373 && (client->find != client->v6find)) {
374 dns_adb_destroyfind(&client->find);
376 client->find = NULL;
384 restart_find(client);
391 cleanup_gabn(client);
392 ns_lwdclient_errorpktsend(client, LWRES_R_FAILURE);
396 restart_find(ns_lwdclient_t *client) {
401 ns_lwdclient_log(50, "starting find for client %p", client);
417 if (NEED_V4(client))
419 if (NEED_V6(client))
423 INSIST(client->find == NULL);
424 result = dns_adb_createfind(client->clientmgr->view->adb,
425 client->clientmgr->task,
426 process_gabn_finddone, client,
427 dns_fixedname_name(&client->target_name),
429 dns_fixedname_name(&client->target_name),
430 client->clientmgr->view->dstport,
431 &client->find);
438 dns_adb_destroyfind(&client->find);
439 cleanup_gabn(client);
440 result = add_alias(client);
444 ns_lwdclient_errorpktsend(client, LWRES_R_FAILURE);
457 if (client->find != NULL)
458 dns_adb_destroyfind(&client->find);
459 cleanup_gabn(client);
460 ns_lwdclient_errorpktsend(client, LWRES_R_FAILURE);
469 if (NEED_V4(client)
470 && ((client->find->query_pending & DNS_ADBFIND_INET) == 0)) {
471 ns_lwdclient_log(50, "client %p ipv4 satisfied by find %p",
472 client, client->find);
474 client->v4find = client->find;
480 if (NEED_V6(client)
481 && ((client->find->query_pending & DNS_ADBFIND_INET6) == 0)) {
482 ns_lwdclient_log(50, "client %p ipv6 satisfied by find %p",
483 client, client->find);
485 client->v6find = client->find;
497 if ((client->find->options & DNS_ADBFIND_WANTEVENT) != 0) {
499 INSIST(client->v4find == NULL || client->v6find == NULL);
504 client->find = NULL;
506 dns_adb_destroyfind(&client->find);
513 generate_reply(client);
517 start_find(ns_lwdclient_t *client) {
524 init_gabn(client);
526 result = store_realname(client);
529 restart_find(client);
535 init_gabn(ns_lwdclient_t *client) {
543 client->aliases[i] = NULL;
544 client->aliaslen[i] = 0;
547 client->addrs[i].family = 0;
548 client->addrs[i].length = 0;
549 memset(client->addrs[i].address, 0, LWRES_ADDR_MAXLEN);
550 LWRES_LINK_INIT(&client->addrs[i], link);
553 client->gabn.naliases = 0;
554 client->gabn.naddrs = 0;
555 client->gabn.realname = NULL;
556 client->gabn.aliases = client->aliases;
557 client->gabn.realnamelen = 0;
558 client->gabn.aliaslen = client->aliaslen;
559 LWRES_LIST_INIT(client->gabn.addrs);
560 client->gabn.base = NULL;
561 client->gabn.baselen = 0;
566 isc_buffer_init(&client->recv_buffer, client->buffer, LWRES_RECVLENGTH);
572 * client->sockaddr contains the address we need to reply to,
574 * client->pkt contains the packet header data,
589 ns_lwdclient_processgabn(ns_lwdclient_t *client, lwres_buffer_t *b) {
595 REQUIRE(NS_LWDCLIENT_ISRECVDONE(client));
597 cm = client->clientmgr;
600 result = lwres_gabnrequest_parse(client->clientmgr->lwctx,
601 b, &client->pkt, &req);
610 dns_fixedname_init(&client->target_name);
611 dns_fixedname_init(&client->query_name);
612 result = dns_name_fromtext(dns_fixedname_name(&client->query_name),
616 ns_lwsearchctx_init(&client->searchctx,
618 dns_fixedname_name(&client->query_name),
620 ns_lwsearchctx_first(&client->searchctx);
622 client->find_wanted = req->addrtypes;
623 ns_lwdclient_log(50, "client %p looking for addrtypes %08x",
624 client, client->find_wanted);
629 lwres_gabnrequest_free(client->clientmgr->lwctx, &req);
634 result = start_find(client);
645 lwres_gabnrequest_free(client->clientmgr->lwctx, &req);
647 ns_lwdclient_errorpktsend(client, LWRES_R_FAILURE);