Exemplo n.º 1
0
static void
done(isc_task_t *task, isc_event_t *event) {
	dns_byaddrevent_t *bevent;
	dns_byaddr_t *byaddr;
	dns_name_t *name;

	REQUIRE(event->ev_type == DNS_EVENT_BYADDRDONE);
	bevent = (dns_byaddrevent_t *)event;

	UNUSED(task);

	printf("byaddr event result = %s\n",
	       isc_result_totext(bevent->result));

	if (bevent->result == ISC_R_SUCCESS) {
		for (name = ISC_LIST_HEAD(bevent->names);
		     name != NULL;
		     name = ISC_LIST_NEXT(name, link)) {
			char text[DNS_NAME_FORMATSIZE];
			dns_name_format(name, text, sizeof(text));
			printf("%s\n", text);
		}
	}

	byaddr = event->ev_sender;
	dns_byaddr_destroy(&byaddr);
	isc_event_free(&event);

	isc_app_shutdown();
}
Exemplo n.º 2
0
static void
byaddr_done(isc_task_t *task, isc_event_t *event) {
    ns_lwdclient_t *client;
    ns_lwdclientmgr_t *cm;
    dns_byaddrevent_t *bevent;
    int lwres;
    lwres_buffer_t lwb;
    dns_name_t *name;
    isc_result_t result;
    lwres_result_t lwresult;
    isc_region_t r;
    isc_buffer_t b;
    lwres_gnbaresponse_t *gnba;
    isc_uint16_t naliases;

    UNUSED(task);

    lwb.base = NULL;
    client = event->ev_arg;
    cm = client->clientmgr;
    INSIST(client->byaddr == (dns_byaddr_t *)event->ev_sender);

    bevent = (dns_byaddrevent_t *)event;
    gnba = &client->gnba;

    ns_lwdclient_log(50, "byaddr event result = %s",
                     isc_result_totext(bevent->result));

    result = bevent->result;
    if (result != ISC_R_SUCCESS) {
        dns_byaddr_destroy(&client->byaddr);
        isc_event_free(&event);
        bevent = NULL;

        if (client->na.family != AF_INET6 ||
                (client->options & DNS_BYADDROPT_IPV6INT) != 0) {
            if (result == DNS_R_NCACHENXDOMAIN ||
                    result == DNS_R_NCACHENXRRSET ||
                    result == DNS_R_NXDOMAIN ||
                    result == DNS_R_NXRRSET)
                lwresult = LWRES_R_NOTFOUND;
            else
                lwresult = LWRES_R_FAILURE;
            ns_lwdclient_errorpktsend(client, lwresult);
            return;
        }

        /*
         * Fall back to ip6.int reverse if the default ip6.arpa
         * fails.
         */
        client->options |= DNS_BYADDROPT_IPV6INT;

        start_byaddr(client);
        return;
    }

    for (name = ISC_LIST_HEAD(bevent->names);
            name != NULL;
            name = ISC_LIST_NEXT(name, link))
    {
        b = client->recv_buffer;

        result = dns_name_totext(name, ISC_TRUE, &client->recv_buffer);
        if (result != ISC_R_SUCCESS)
            goto out;
        ns_lwdclient_log(50, "found name '%.*s'",
                         (int)(client->recv_buffer.used - b.used),
                         (char *)(b.base) + b.used);
        if (gnba->realname == NULL) {
            gnba->realname = (char *)(b.base) + b.used;
            gnba->realnamelen = client->recv_buffer.used - b.used;
        } else {
            naliases = gnba->naliases;
            if (naliases >= LWRES_MAX_ALIASES)
                break;
            gnba->aliases[naliases] = (char *)(b.base) + b.used;
            gnba->aliaslen[naliases] =
                client->recv_buffer.used - b.used;
            gnba->naliases++;
        }
    }

    dns_byaddr_destroy(&client->byaddr);
    isc_event_free(&event);

    /*
     * Render the packet.
     */
    client->pkt.recvlength = LWRES_RECVLENGTH;
    client->pkt.authtype = 0; /* XXXMLG */
    client->pkt.authlength = 0;
    client->pkt.result = LWRES_R_SUCCESS;

    lwres = lwres_gnbaresponse_render(cm->lwctx,
                                      gnba, &client->pkt, &lwb);
    if (lwres != LWRES_R_SUCCESS)
        goto out;

    r.base = lwb.base;
    r.length = lwb.used;
    client->sendbuf = r.base;
    client->sendlength = r.length;
    result = ns_lwdclient_sendreply(client, &r);
    if (result != ISC_R_SUCCESS)
        goto out;

    NS_LWDCLIENT_SETSEND(client);

    return;

out:
    if (client->byaddr != NULL)
        dns_byaddr_destroy(&client->byaddr);
    if (lwb.base != NULL)
        lwres_context_freemem(cm->lwctx,
                              lwb.base, lwb.length);

    if (event != NULL)
        isc_event_free(&event);
}