168 lines
4.7 KiB
C
168 lines
4.7 KiB
C
/*
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
|
*
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
|
|
*
|
|
* See the COPYRIGHT file distributed with this work for additional
|
|
* information regarding copyright ownership.
|
|
*/
|
|
|
|
#include <ns/hooks.h>
|
|
#include <dns/view.h>
|
|
#include <dns/rdatalist.h>
|
|
#include <dns/byaddr.h>
|
|
|
|
typedef struct dynptrr dynptrr_t;
|
|
struct dynptrr {
|
|
isc_mem_t *mctx;
|
|
};
|
|
|
|
static ns_hookresult_t
|
|
dynptrr_nxdomain_begin(void *arg, void *cbdata, isc_result_t *resp) {
|
|
query_ctx_t *qctx = (query_ctx_t *)arg;
|
|
isc_mem_t *mctx = qctx->client->view->mctx;
|
|
dynptrr_t *inst = (dynptrr_t *)cbdata;
|
|
UNUSED(inst);
|
|
|
|
*resp = ISC_R_UNSET;
|
|
if (qctx->type != dns_rdatatype_ptr) {
|
|
return NS_HOOK_CONTINUE;
|
|
}
|
|
isc_log_write(NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_HOOKS,
|
|
ISC_LOG_DEBUG(1), "dynptrr nxdomain begin");
|
|
|
|
dns_message_t *message = qctx->client->message;
|
|
|
|
dns_name_t *name = isc_mem_get(mctx, sizeof(*name));
|
|
dns_rdataset_t *synth = NULL;
|
|
dns_rdatalist_t *synthlist = NULL;
|
|
dns_rdata_t *synthdata = NULL;
|
|
|
|
dns_name_init(name);
|
|
dns_name_dup(qctx->client->query.qname, mctx, name);
|
|
char n[512];
|
|
dns_name_format(name, n, 512);
|
|
isc_log_write(NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_HOOKS,
|
|
ISC_LOG_DEBUG(1), "dynptrr %s", n);
|
|
|
|
dns_message_gettemprdataset(message, &synth);
|
|
dns_rdataset_init(synth);
|
|
synth->ttl = 60;
|
|
synth->rdclass = dns_rdataclass_in;
|
|
synth->type = dns_rdatatype_ptr;
|
|
|
|
dns_message_gettemprdatalist(message, &synthlist);
|
|
dns_rdatalist_init(synthlist);
|
|
synthlist->ttl = 60;
|
|
synthlist->rdclass = dns_rdataclass_in;
|
|
synthlist->type = dns_rdatatype_ptr;
|
|
|
|
dns_message_gettemprdata(message, &synthdata);
|
|
dns_rdata_init(synthdata);
|
|
synthdata->rdclass = dns_rdataclass_in;
|
|
synthdata->type = dns_rdatatype_ptr;
|
|
|
|
/*
|
|
* It seems that for a ptr type, the data must be the ndata pointer of a
|
|
* dns_name_t. (I attempted putting a raw string instead, and it was a
|
|
* crash)
|
|
*/
|
|
synthdata->data = name->ndata;
|
|
synthdata->length = name->length;
|
|
|
|
ISC_LIST_APPEND(synthlist->rdata, synthdata, link);
|
|
|
|
dns_rdatalist_tordataset(synthlist, synth);
|
|
dns_rdataset_setownercase(synth, name);
|
|
dns_message_addname(message, name, DNS_SECTION_ANSWER);
|
|
ISC_LIST_APPEND(name->list, synth, link);
|
|
|
|
isc_result_t result = ns_query_done(qctx);
|
|
*resp = result;
|
|
|
|
/* ------------------------------------------------- */
|
|
|
|
// isc_netaddr_t peeraddr;
|
|
// isc_netaddr_fromsockaddr(&peeraddr, &qctx->client->peeraddr);
|
|
//
|
|
// char createdptrnamed[512];
|
|
// isc_buffer_t createdptrnameb;
|
|
// isc_buffer_init(&createdptrnameb, createdptrnamed, 512);
|
|
//
|
|
// dns_name_t *createdptrname = isc_mem_get(mctx, sizeof(*createdptrname));
|
|
// dns_name_init(createdptrname);
|
|
// dns_name_setbuffer(createdptrname, &createdptrnameb);
|
|
// isc_result_t r = dns_byaddr_createptrname(&peeraddr, createdptrname);
|
|
// isc_log_write(NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_HOOKS,
|
|
// ISC_LOG_DEBUG(1), "dynptrr %s", isc_result_totext(r));
|
|
// dns_name_format(createdptrname, n, 512);
|
|
// isc_log_write(NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_HOOKS,
|
|
// ISC_LOG_DEBUG(1), "dynptrr ptr %s", n);
|
|
// isc_mem_put(mctx, createdptrname, sizeof(*createdptrname));
|
|
//
|
|
/* ------------------------------------------------- */
|
|
|
|
return NS_HOOK_RETURN;
|
|
}
|
|
|
|
|
|
void
|
|
plugin_destroy(void **instp) {
|
|
REQUIRE(instp && *instp);
|
|
|
|
dynptrr_t *inst = *instp;
|
|
isc_mem_t *mctx = inst->mctx;
|
|
isc_mem_put(mctx, inst, sizeof(*inst));
|
|
*instp = NULL;
|
|
|
|
printf("dynptrr plugin_destroy\n");
|
|
}
|
|
|
|
int
|
|
plugin_version(void) {
|
|
printf("dynptrr plugin_version\n");
|
|
return NS_PLUGIN_VERSION;
|
|
}
|
|
|
|
isc_result_t
|
|
plugin_register(const char *parameters, const void *cfg, const char *cfg_file,
|
|
unsigned long cfg_line, isc_mem_t *mctx, void *actx,
|
|
ns_hooktable_t *hooktable, void **instp) {
|
|
REQUIRE(cfg);
|
|
REQUIRE(mctx);
|
|
REQUIRE(actx);
|
|
REQUIRE(hooktable);
|
|
REQUIRE(instp && *instp == NULL);
|
|
|
|
printf("dynptrr plugin_register %s %s %ld\n", parameters, cfg_file,
|
|
cfg_line);
|
|
|
|
dynptrr_t *inst = isc_mem_get(mctx, sizeof(*inst));
|
|
*inst = (dynptrr_t){ .mctx = mctx };
|
|
*instp = inst;
|
|
|
|
const ns_hook_t testhook = {
|
|
.action = dynptrr_nxdomain_begin,
|
|
.action_data = inst
|
|
};
|
|
ns_hook_add(hooktable, mctx, NS_QUERY_NXDOMAIN_BEGIN, &testhook);
|
|
|
|
return ISC_R_SUCCESS;
|
|
}
|
|
|
|
isc_result_t
|
|
plugin_check(const char *parameters, const void *cfg, const char *cfg_file,
|
|
unsigned long cfg_line, isc_mem_t *mctx, void *actx) {
|
|
REQUIRE(cfg);
|
|
REQUIRE(mctx);
|
|
REQUIRE(actx);
|
|
|
|
printf("dynptrr plugin_check %s %s %ld\n", parameters, cfg_file,
|
|
cfg_line);
|
|
return ISC_R_SUCCESS;
|
|
}
|