1999-01-19 06:32:53 +00:00
|
|
|
/*
|
1999-03-06 03:55:54 +00:00
|
|
|
* Copyright (C) 1999 Internet Software Consortium.
|
1999-01-19 06:32:53 +00:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
|
|
|
|
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
|
|
|
|
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
|
|
|
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
|
|
|
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
|
|
|
* SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <isc/assertions.h>
|
|
|
|
#include <isc/error.h>
|
|
|
|
#include <isc/mem.h>
|
|
|
|
#include <isc/task.h>
|
|
|
|
#include <isc/thread.h>
|
|
|
|
#include <isc/result.h>
|
|
|
|
#include <isc/socket.h>
|
|
|
|
#include <isc/timer.h>
|
1999-05-27 01:51:31 +00:00
|
|
|
#include <isc/app.h>
|
1999-01-19 06:32:53 +00:00
|
|
|
|
|
|
|
#include <dns/types.h>
|
|
|
|
#include <dns/result.h>
|
|
|
|
#include <dns/name.h>
|
1999-05-03 19:56:23 +00:00
|
|
|
#include <dns/fixedname.h>
|
1999-01-19 06:32:53 +00:00
|
|
|
#include <dns/rdata.h>
|
|
|
|
#include <dns/rdatalist.h>
|
|
|
|
#include <dns/rdataset.h>
|
1999-05-03 19:56:23 +00:00
|
|
|
#include <dns/rdatasetiter.h>
|
1999-01-19 06:32:53 +00:00
|
|
|
#include <dns/compress.h>
|
1999-01-31 12:31:31 +00:00
|
|
|
#include <dns/db.h>
|
1999-05-03 19:56:23 +00:00
|
|
|
#include <dns/dbtable.h>
|
1999-04-30 05:42:06 +00:00
|
|
|
#include <dns/message.h>
|
1999-01-19 06:32:53 +00:00
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
|
|
|
#include <netinet/in.h>
|
|
|
|
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
1999-01-20 03:54:54 +00:00
|
|
|
#include "udpclient.h"
|
1999-01-28 05:52:20 +00:00
|
|
|
#include "tcpclient.h"
|
1999-05-26 06:48:26 +00:00
|
|
|
#include "interfacemgr.h"
|
1999-01-19 06:32:53 +00:00
|
|
|
|
1999-05-03 19:56:23 +00:00
|
|
|
typedef struct dbinfo {
|
|
|
|
dns_db_t * db;
|
|
|
|
ISC_LINK(struct dbinfo) link;
|
|
|
|
} dbinfo;
|
|
|
|
|
|
|
|
isc_mem_t * mctx;
|
|
|
|
isc_boolean_t want_stats = ISC_FALSE;
|
|
|
|
static char dbtype[128];
|
|
|
|
static dns_dbtable_t * dbtable;
|
|
|
|
static ISC_LIST(dbinfo) dbs;
|
|
|
|
static dbinfo * cache_dbi;
|
1999-01-31 12:31:31 +00:00
|
|
|
|
1999-05-02 07:03:13 +00:00
|
|
|
static inline isc_boolean_t
|
1999-04-30 05:42:06 +00:00
|
|
|
CHECKRESULT(dns_result_t result, char *msg)
|
|
|
|
{
|
|
|
|
if ((result) != DNS_R_SUCCESS) {
|
|
|
|
printf("%s: %s\n", (msg), dns_result_totext(result));
|
|
|
|
return (ISC_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (ISC_FALSE);
|
|
|
|
}
|
1999-01-31 12:31:31 +00:00
|
|
|
|
1999-02-01 20:47:58 +00:00
|
|
|
/*
|
1999-04-30 05:42:06 +00:00
|
|
|
* This is in bin/tests/wire_test.c, but should be in a debugging library.
|
1999-02-01 20:47:58 +00:00
|
|
|
*/
|
1999-04-30 05:42:06 +00:00
|
|
|
extern dns_result_t
|
|
|
|
printmessage(dns_message_t *);
|
|
|
|
|
1999-05-03 19:56:23 +00:00
|
|
|
#define MAX_RDATASETS 25
|
1999-04-30 05:42:06 +00:00
|
|
|
|
1999-05-03 19:56:23 +00:00
|
|
|
static dns_result_t
|
|
|
|
resolve_packet(isc_mem_t *mctx, dns_message_t *query, isc_buffer_t *target) {
|
1999-04-30 05:42:06 +00:00
|
|
|
dns_message_t *message;
|
1999-05-03 19:56:23 +00:00
|
|
|
dns_result_t result, dbresult;
|
1999-07-03 21:03:27 +00:00
|
|
|
dns_name_t *qname, *fname, *rqname;
|
|
|
|
dns_fixedname_t foundname, frqname;
|
|
|
|
dns_rdataset_t *rds, *rdataset, rqrds, rdatasets[MAX_RDATASETS];
|
1999-05-03 19:56:23 +00:00
|
|
|
unsigned int nrdatasets = 0;
|
1999-05-02 07:00:05 +00:00
|
|
|
dns_dbnode_t *node;
|
1999-05-03 19:56:23 +00:00
|
|
|
dns_db_t *db;
|
|
|
|
dns_rdatasetiter_t *rdsiter;
|
|
|
|
dns_rdatatype_t type;
|
|
|
|
isc_boolean_t possibly_auth = ISC_FALSE;
|
1999-05-02 07:00:05 +00:00
|
|
|
|
1999-05-03 19:56:23 +00:00
|
|
|
message = NULL;
|
1999-05-14 17:52:11 +00:00
|
|
|
result = dns_message_create(mctx, &message, DNS_MESSAGE_INTENTRENDER);
|
1999-04-30 05:42:06 +00:00
|
|
|
CHECKRESULT(result, "dns_message_create failed");
|
|
|
|
|
|
|
|
message->id = query->id;
|
1999-05-02 07:00:05 +00:00
|
|
|
message->rcode = dns_rcode_noerror;
|
1999-05-01 18:07:52 +00:00
|
|
|
message->flags = query->flags;
|
|
|
|
message->flags |= DNS_MESSAGEFLAG_QR;
|
|
|
|
|
|
|
|
result = dns_message_firstname(query, DNS_SECTION_QUESTION);
|
|
|
|
if (result != DNS_R_SUCCESS)
|
|
|
|
return (result);
|
1999-05-03 19:56:23 +00:00
|
|
|
qname = NULL;
|
1999-07-03 21:03:27 +00:00
|
|
|
dns_fixedname_init(&frqname);
|
|
|
|
rqname = dns_fixedname_name(&frqname);
|
1999-05-03 19:56:23 +00:00
|
|
|
dns_message_currentname(query, DNS_SECTION_QUESTION, &qname);
|
1999-07-03 21:03:27 +00:00
|
|
|
result = dns_name_concatenate(qname, NULL, rqname, NULL);
|
|
|
|
if (result != DNS_R_SUCCESS)
|
|
|
|
return (DNS_R_UNEXPECTED);
|
1999-05-03 19:56:23 +00:00
|
|
|
rds = ISC_LIST_HEAD(qname->list);
|
1999-05-02 07:00:05 +00:00
|
|
|
if (rds == NULL)
|
|
|
|
return (DNS_R_UNEXPECTED);
|
1999-05-03 19:56:23 +00:00
|
|
|
type = rds->type;
|
1999-07-03 21:03:27 +00:00
|
|
|
dns_rdataset_init(&rqrds);
|
|
|
|
dns_rdataset_makequestion(&rqrds, rds->rdclass, rds->type);
|
|
|
|
ISC_LIST_APPEND(rqname->list, &rqrds, link);
|
1999-05-01 18:07:52 +00:00
|
|
|
|
1999-07-03 21:03:27 +00:00
|
|
|
dns_message_addname(message, rqname, DNS_SECTION_QUESTION);
|
1999-04-30 05:42:06 +00:00
|
|
|
|
|
|
|
result = printmessage(message);
|
1999-05-01 18:07:52 +00:00
|
|
|
INSIST(result == DNS_R_SUCCESS); /* XXX not in a real server */
|
1999-05-02 07:00:05 +00:00
|
|
|
|
|
|
|
/*
|
1999-05-03 19:56:23 +00:00
|
|
|
* Find a database to answer the query from.
|
1999-05-02 07:00:05 +00:00
|
|
|
*/
|
1999-05-03 19:56:23 +00:00
|
|
|
db = NULL;
|
|
|
|
result = dns_dbtable_find(dbtable, qname, &db);
|
|
|
|
if (result != DNS_R_SUCCESS && result != DNS_R_PARTIALMATCH) {
|
|
|
|
printf("could not find a dbtable: %s\n",
|
|
|
|
dns_result_totext(result));
|
|
|
|
message->rcode = dns_rcode_servfail;
|
|
|
|
goto render;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now look for an answer in the database.
|
|
|
|
*/
|
|
|
|
dns_fixedname_init(&foundname);
|
|
|
|
fname = dns_fixedname_name(&foundname);
|
|
|
|
rdataset = &rdatasets[nrdatasets++];
|
|
|
|
dns_rdataset_init(rdataset);
|
|
|
|
node = NULL;
|
|
|
|
dbresult = dns_db_find(db, qname, NULL, type, 0, 0, &node, fname,
|
|
|
|
rdataset);
|
|
|
|
switch (dbresult) {
|
|
|
|
case DNS_R_SUCCESS:
|
|
|
|
case DNS_R_DNAME:
|
|
|
|
case DNS_R_CNAME:
|
|
|
|
possibly_auth = ISC_TRUE;
|
|
|
|
break;
|
|
|
|
case DNS_R_GLUE:
|
|
|
|
case DNS_R_ZONECUT:
|
|
|
|
case DNS_R_DELEGATION:
|
|
|
|
break;
|
|
|
|
case DNS_R_NXRDATASET:
|
|
|
|
if (dns_db_iszone(db))
|
|
|
|
message->flags |= DNS_MESSAGEFLAG_AA;
|
|
|
|
dns_db_detachnode(db, &node);
|
|
|
|
dns_db_detach(&db);
|
1999-05-02 07:00:05 +00:00
|
|
|
goto render;
|
1999-05-03 19:56:23 +00:00
|
|
|
case DNS_R_NXDOMAIN:
|
|
|
|
if (dns_db_iszone(db))
|
|
|
|
message->flags |= DNS_MESSAGEFLAG_AA;
|
|
|
|
dns_db_detach(&db);
|
1999-05-02 07:00:05 +00:00
|
|
|
message->rcode = dns_rcode_nxdomain;
|
|
|
|
goto render;
|
1999-05-03 19:56:23 +00:00
|
|
|
default:
|
|
|
|
printf("%s\n", dns_result_totext(result));
|
|
|
|
dns_db_detach(&db);
|
1999-05-02 07:00:05 +00:00
|
|
|
message->rcode = dns_rcode_servfail;
|
|
|
|
goto render;
|
1999-05-03 19:56:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (dbresult == DNS_R_DELEGATION) {
|
|
|
|
ISC_LIST_APPEND(fname->list, rdataset, link);
|
|
|
|
dns_message_addname(message, fname, DNS_SECTION_AUTHORITY);
|
|
|
|
} else if (type == dns_rdatatype_any) {
|
|
|
|
rdsiter = NULL;
|
|
|
|
result = dns_db_allrdatasets(db, node, NULL, 0, &rdsiter);
|
|
|
|
if (result == DNS_R_SUCCESS)
|
|
|
|
result = dns_rdatasetiter_first(rdsiter);
|
|
|
|
while (result == DNS_R_SUCCESS) {
|
|
|
|
dns_rdatasetiter_current(rdsiter, rdataset);
|
|
|
|
ISC_LIST_APPEND(fname->list, rdataset, link);
|
|
|
|
if (nrdatasets == MAX_RDATASETS) {
|
|
|
|
result = DNS_R_NOSPACE;
|
|
|
|
} else {
|
|
|
|
rdataset = &rdatasets[nrdatasets++];
|
|
|
|
dns_rdataset_init(rdataset);
|
|
|
|
result = dns_rdatasetiter_next(rdsiter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (result != DNS_R_NOMORE) {
|
|
|
|
dns_db_detachnode(db, &node);
|
|
|
|
dns_db_detach(&db);
|
|
|
|
message->rcode = dns_rcode_servfail;
|
|
|
|
goto render;
|
|
|
|
}
|
|
|
|
dns_message_addname(message, fname, DNS_SECTION_ANSWER);
|
|
|
|
} else {
|
|
|
|
ISC_LIST_APPEND(fname->list, rdataset, link);
|
|
|
|
dns_message_addname(message, fname, DNS_SECTION_ANSWER);
|
|
|
|
}
|
1999-05-02 07:00:05 +00:00
|
|
|
|
1999-05-03 19:56:23 +00:00
|
|
|
if (dns_db_iszone(db) && possibly_auth)
|
1999-05-02 07:00:05 +00:00
|
|
|
message->flags |= DNS_MESSAGEFLAG_AA;
|
|
|
|
|
1999-05-03 19:56:23 +00:00
|
|
|
dns_db_detachnode(db, &node);
|
|
|
|
dns_db_detach(&db);
|
1999-05-02 07:00:05 +00:00
|
|
|
|
|
|
|
render:
|
|
|
|
|
1999-05-01 18:07:52 +00:00
|
|
|
result = dns_message_renderbegin(message, target);
|
|
|
|
if (result != DNS_R_SUCCESS)
|
|
|
|
return (result);
|
1999-04-30 05:42:06 +00:00
|
|
|
|
1999-05-01 18:07:52 +00:00
|
|
|
result = dns_message_rendersection(message, DNS_SECTION_QUESTION,
|
|
|
|
0, 0);
|
|
|
|
if (result != DNS_R_SUCCESS)
|
|
|
|
return (result);
|
|
|
|
|
|
|
|
result = dns_message_rendersection(message, DNS_SECTION_ANSWER,
|
|
|
|
0, 0);
|
|
|
|
if (result != DNS_R_SUCCESS)
|
|
|
|
return (result);
|
|
|
|
|
|
|
|
result = dns_message_rendersection(message, DNS_SECTION_AUTHORITY,
|
|
|
|
0, 0);
|
|
|
|
if (result != DNS_R_SUCCESS)
|
|
|
|
return (result);
|
|
|
|
|
|
|
|
result = dns_message_rendersection(message, DNS_SECTION_ADDITIONAL,
|
|
|
|
0, 0);
|
|
|
|
if (result != DNS_R_SUCCESS)
|
|
|
|
return (result);
|
|
|
|
|
|
|
|
result = dns_message_rendersection(message, DNS_SECTION_TSIG,
|
|
|
|
0, 0);
|
|
|
|
if (result != DNS_R_SUCCESS)
|
|
|
|
return (result);
|
|
|
|
|
|
|
|
result = dns_message_renderend(message);
|
|
|
|
|
|
|
|
dns_message_destroy(&message);
|
|
|
|
|
|
|
|
return (DNS_R_SUCCESS);
|
1999-04-30 05:42:06 +00:00
|
|
|
}
|
1999-02-01 20:47:58 +00:00
|
|
|
|
1999-01-29 06:18:43 +00:00
|
|
|
/*
|
|
|
|
* Process the wire format message given in r, and return a new packet to
|
|
|
|
* transmit.
|
|
|
|
*
|
|
|
|
* Return of DNS_R_SUCCESS means r->base is a newly allocated region of
|
|
|
|
* memory, and r->length is its length. The actual for-transmit packet
|
|
|
|
* begins at (r->length + reslen) to reserve (reslen) bytes at the front
|
|
|
|
* of the packet for transmission specific details.
|
|
|
|
*/
|
|
|
|
static dns_result_t
|
|
|
|
dispatch(isc_mem_t *mctx, isc_region_t *rxr, unsigned int reslen)
|
|
|
|
{
|
1999-04-30 05:42:06 +00:00
|
|
|
char t[512];
|
1999-01-31 12:31:31 +00:00
|
|
|
isc_buffer_t source;
|
|
|
|
isc_buffer_t target;
|
|
|
|
dns_result_t result;
|
1999-01-29 06:18:43 +00:00
|
|
|
isc_region_t txr;
|
1999-05-01 18:07:52 +00:00
|
|
|
dns_message_t *message;
|
1999-01-31 12:31:31 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up the input buffer from the contents of the region passed
|
|
|
|
* to us.
|
|
|
|
*/
|
|
|
|
isc_buffer_init(&source, rxr->base, rxr->length,
|
|
|
|
ISC_BUFFERTYPE_BINARY);
|
|
|
|
isc_buffer_add(&source, rxr->length);
|
|
|
|
|
1999-05-03 19:56:23 +00:00
|
|
|
message = NULL;
|
1999-05-14 17:52:11 +00:00
|
|
|
result = dns_message_create(mctx, &message, DNS_MESSAGE_INTENTPARSE);
|
1999-04-30 05:42:06 +00:00
|
|
|
if (CHECKRESULT(result, "dns_message_create failed")) {
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
result = dns_message_parse(message, &source);
|
|
|
|
if (CHECKRESULT(result, "dns_message_parsed failed")) {
|
|
|
|
dns_message_destroy(&message);
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
CHECKRESULT(result, "dns_message_parse failed");
|
|
|
|
|
|
|
|
result = printmessage(message);
|
|
|
|
if (CHECKRESULT(result, "printmessage failed")) {
|
|
|
|
dns_message_destroy(&message);
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_buffer_init(&target, t, sizeof(t), ISC_BUFFERTYPE_BINARY);
|
1999-05-03 19:56:23 +00:00
|
|
|
result = resolve_packet(mctx, message, &target);
|
1999-04-30 05:42:06 +00:00
|
|
|
if (result != DNS_R_SUCCESS) {
|
1999-05-01 18:07:52 +00:00
|
|
|
dns_message_destroy(&message);
|
1999-01-31 12:31:31 +00:00
|
|
|
return (result);
|
1999-04-30 05:42:06 +00:00
|
|
|
}
|
1999-01-29 06:18:43 +00:00
|
|
|
|
|
|
|
/*
|
1999-01-31 12:58:16 +00:00
|
|
|
* Copy the reply out, adjusting for reslen
|
1999-01-29 06:18:43 +00:00
|
|
|
*/
|
1999-01-31 12:31:31 +00:00
|
|
|
isc_buffer_used(&target, &txr);
|
1999-01-31 12:58:16 +00:00
|
|
|
txr.base = isc_mem_get(mctx, txr.length + reslen);
|
1999-04-30 05:42:06 +00:00
|
|
|
if (txr.base == NULL) {
|
1999-05-01 18:07:52 +00:00
|
|
|
dns_message_destroy(&message);
|
1999-04-30 05:42:06 +00:00
|
|
|
|
1999-01-29 06:18:43 +00:00
|
|
|
return (DNS_R_NOMEMORY);
|
1999-04-30 05:42:06 +00:00
|
|
|
}
|
1999-01-29 06:18:43 +00:00
|
|
|
|
1999-05-21 05:43:48 +00:00
|
|
|
memcpy(txr.base + reslen, t, txr.length);
|
1999-01-29 06:18:43 +00:00
|
|
|
rxr->base = txr.base;
|
1999-01-31 12:58:16 +00:00
|
|
|
rxr->length = txr.length + reslen;
|
1999-01-29 06:18:43 +00:00
|
|
|
|
1999-01-31 12:31:31 +00:00
|
|
|
printf("Base == %p, length == %u\n", txr.base, txr.length);
|
|
|
|
fflush(stdout);
|
|
|
|
|
1999-02-01 21:11:10 +00:00
|
|
|
if (want_stats)
|
|
|
|
isc_mem_stats(mctx, stdout);
|
1999-01-29 06:18:43 +00:00
|
|
|
|
1999-05-01 18:07:52 +00:00
|
|
|
dns_message_destroy(&message);
|
1999-04-30 05:42:06 +00:00
|
|
|
|
1999-01-29 06:18:43 +00:00
|
|
|
return (DNS_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
1999-05-03 19:56:23 +00:00
|
|
|
static dns_result_t
|
|
|
|
load(char *filename, char *origintext, isc_boolean_t cache) {
|
|
|
|
dns_fixedname_t forigin;
|
|
|
|
dns_name_t *origin;
|
|
|
|
dns_result_t result;
|
|
|
|
isc_buffer_t source;
|
|
|
|
size_t len;
|
|
|
|
dbinfo *dbi;
|
|
|
|
|
|
|
|
dbi = isc_mem_get(mctx, sizeof *dbi);
|
|
|
|
if (dbi == NULL)
|
|
|
|
return (DNS_R_NOMEMORY);
|
|
|
|
dbi->db = NULL;
|
|
|
|
|
|
|
|
len = strlen(origintext);
|
|
|
|
isc_buffer_init(&source, origintext, len, ISC_BUFFERTYPE_TEXT);
|
|
|
|
isc_buffer_add(&source, len);
|
|
|
|
dns_fixedname_init(&forigin);
|
|
|
|
origin = dns_fixedname_name(&forigin);
|
|
|
|
result = dns_name_fromtext(origin, &source, dns_rootname, ISC_FALSE,
|
|
|
|
NULL);
|
|
|
|
if (result != DNS_R_SUCCESS)
|
|
|
|
return (result);
|
|
|
|
|
|
|
|
result = dns_db_create(mctx, dbtype, origin, cache, dns_rdataclass_in,
|
|
|
|
0, NULL, &dbi->db);
|
|
|
|
if (result != DNS_R_SUCCESS) {
|
|
|
|
isc_mem_put(mctx, dbi, sizeof *dbi);
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("loading %s (%s)\n", filename, origintext);
|
|
|
|
result = dns_db_load(dbi->db, filename);
|
|
|
|
if (result != DNS_R_SUCCESS) {
|
|
|
|
dns_db_detach(&dbi->db);
|
|
|
|
isc_mem_put(mctx, dbi, sizeof *dbi);
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
printf("loaded\n");
|
|
|
|
|
|
|
|
if (cache) {
|
|
|
|
INSIST(cache_dbi == NULL);
|
|
|
|
dns_dbtable_adddefault(dbtable, dbi->db);
|
|
|
|
cache_dbi = dbi;
|
|
|
|
} else {
|
|
|
|
if (dns_dbtable_add(dbtable, dbi->db) != DNS_R_SUCCESS) {
|
|
|
|
dns_db_detach(&dbi->db);
|
|
|
|
isc_mem_put(mctx, dbi, sizeof *dbi);
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ISC_LIST_APPEND(dbs, dbi, link);
|
|
|
|
|
|
|
|
return (DNS_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
unload_all(void) {
|
|
|
|
dbinfo *dbi, *dbi_next;
|
|
|
|
|
|
|
|
for (dbi = ISC_LIST_HEAD(dbs); dbi != NULL; dbi = dbi_next) {
|
|
|
|
dbi_next = ISC_LIST_NEXT(dbi, link);
|
|
|
|
if (dns_db_iszone(dbi->db))
|
|
|
|
dns_dbtable_remove(dbtable, dbi->db);
|
|
|
|
else {
|
|
|
|
INSIST(dbi == cache_dbi);
|
|
|
|
dns_dbtable_removedefault(dbtable);
|
|
|
|
cache_dbi = NULL;
|
|
|
|
}
|
|
|
|
dns_db_detach(&dbi->db);
|
|
|
|
ISC_LIST_UNLINK(dbs, dbi, link);
|
|
|
|
isc_mem_put(mctx, dbi, sizeof *dbi);
|
|
|
|
}
|
|
|
|
}
|
1999-01-29 06:18:43 +00:00
|
|
|
|
1999-01-19 06:32:53 +00:00
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
isc_taskmgr_t *manager = NULL;
|
|
|
|
unsigned int workers;
|
|
|
|
isc_socketmgr_t *socketmgr;
|
|
|
|
isc_sockaddr_t sockaddr;
|
|
|
|
unsigned int addrlen;
|
1999-01-31 12:31:31 +00:00
|
|
|
int ch;
|
1999-05-03 19:56:23 +00:00
|
|
|
char *origintext;
|
1999-01-31 12:31:31 +00:00
|
|
|
dns_result_t result;
|
1999-05-27 01:51:31 +00:00
|
|
|
isc_result_t iresult;
|
1999-05-26 06:48:26 +00:00
|
|
|
ns_interfacemgr_t *ifmgr = NULL;
|
1999-02-24 00:14:57 +00:00
|
|
|
|
1999-05-27 01:51:31 +00:00
|
|
|
RUNTIME_CHECK(isc_app_start() == ISC_R_SUCCESS);
|
|
|
|
|
1999-05-03 19:56:23 +00:00
|
|
|
RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
|
|
|
|
RUNTIME_CHECK(dns_dbtable_create(mctx, dns_rdataclass_in, &dbtable) ==
|
|
|
|
DNS_R_SUCCESS);
|
|
|
|
strcpy(dbtype, "rbt");
|
|
|
|
|
1999-01-31 12:31:31 +00:00
|
|
|
/*+ XXX */
|
1999-05-03 19:56:23 +00:00
|
|
|
while ((ch = getopt(argc, argv, "c:d:z:s")) != -1) {
|
1999-01-31 12:31:31 +00:00
|
|
|
switch (ch) {
|
1999-05-03 19:56:23 +00:00
|
|
|
case 'c':
|
|
|
|
result = load(optarg, ".", ISC_TRUE);
|
|
|
|
if (result != DNS_R_SUCCESS)
|
|
|
|
printf("%s\n", dns_result_totext(result));
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
strcpy(dbtype, optarg);
|
1999-01-31 12:31:31 +00:00
|
|
|
break;
|
1999-05-03 19:56:23 +00:00
|
|
|
case 'z':
|
|
|
|
origintext = strrchr(optarg, '/');
|
|
|
|
if (origintext == NULL)
|
|
|
|
origintext = optarg;
|
|
|
|
else
|
|
|
|
origintext++; /* Skip '/'. */
|
|
|
|
result = load(optarg, origintext, ISC_FALSE);
|
|
|
|
if (result != DNS_R_SUCCESS)
|
|
|
|
printf("%s\n", dns_result_totext(result));
|
1999-01-31 12:31:31 +00:00
|
|
|
break;
|
1999-02-01 21:11:10 +00:00
|
|
|
case 's':
|
|
|
|
want_stats = ISC_TRUE;
|
|
|
|
break;
|
1999-01-31 12:31:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
1999-05-03 19:56:23 +00:00
|
|
|
if (argc > 1)
|
|
|
|
fprintf(stderr, "ignoring extra command line arguments\n");
|
1999-01-31 12:31:31 +00:00
|
|
|
|
|
|
|
/*- XXX */
|
1999-01-19 06:32:53 +00:00
|
|
|
|
|
|
|
memset(&sockaddr, 0, sizeof(sockaddr));
|
|
|
|
sockaddr.type.sin.sin_port = htons(5544);
|
|
|
|
addrlen = sizeof(struct sockaddr_in);
|
|
|
|
|
1999-01-31 12:31:31 +00:00
|
|
|
workers = 2;
|
1999-01-19 06:32:53 +00:00
|
|
|
printf("%d workers\n", workers);
|
|
|
|
|
|
|
|
RUNTIME_CHECK(isc_taskmgr_create(mctx, workers, 0, &manager) ==
|
|
|
|
ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
socketmgr = NULL;
|
|
|
|
RUNTIME_CHECK(isc_socketmgr_create(mctx, &socketmgr) == ISC_R_SUCCESS);
|
|
|
|
|
1999-05-26 06:48:26 +00:00
|
|
|
result = ns_interfacemgr_create(mctx, manager, socketmgr, dispatch, &ifmgr);
|
1999-06-20 11:35:12 +00:00
|
|
|
RUNTIME_CHECK(result == DNS_R_SUCCESS);
|
1999-01-28 05:52:20 +00:00
|
|
|
|
1999-05-26 06:48:26 +00:00
|
|
|
result = ns_interfacemgr_scan(ifmgr);
|
1999-06-20 11:35:12 +00:00
|
|
|
RUNTIME_CHECK(result == DNS_R_SUCCESS);
|
1999-01-19 06:32:53 +00:00
|
|
|
|
1999-02-01 21:11:10 +00:00
|
|
|
if (want_stats)
|
|
|
|
isc_mem_stats(mctx, stdout);
|
1999-01-19 06:32:53 +00:00
|
|
|
|
1999-05-27 01:51:31 +00:00
|
|
|
/*
|
|
|
|
* Block until shutdown is requested.
|
1999-02-11 06:38:12 +00:00
|
|
|
*/
|
1999-05-27 01:51:31 +00:00
|
|
|
iresult = isc_app_run();
|
|
|
|
if (iresult != ISC_R_SUCCESS)
|
|
|
|
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
|
|
|
"isc_app_run(): %s",
|
|
|
|
isc_result_totext(iresult));
|
1999-05-03 19:56:23 +00:00
|
|
|
|
1999-05-26 06:48:26 +00:00
|
|
|
printf("Destroying network interface manager\n");
|
|
|
|
ns_interfacemgr_destroy(&ifmgr);
|
|
|
|
|
1999-05-27 01:51:31 +00:00
|
|
|
printf("Destroying task manager\n");
|
|
|
|
isc_taskmgr_destroy(&manager);
|
|
|
|
|
1999-01-19 06:32:53 +00:00
|
|
|
printf("Destroying socket manager\n");
|
|
|
|
isc_socketmgr_destroy(&socketmgr);
|
|
|
|
|
1999-05-27 01:51:31 +00:00
|
|
|
printf("Unloading\n");
|
|
|
|
unload_all();
|
|
|
|
dns_dbtable_detach(&dbtable);
|
1999-01-19 06:32:53 +00:00
|
|
|
|
1999-02-01 21:11:10 +00:00
|
|
|
if (want_stats)
|
|
|
|
isc_mem_stats(mctx, stdout);
|
1999-01-19 06:32:53 +00:00
|
|
|
isc_mem_destroy(&mctx);
|
|
|
|
|
1999-05-27 01:51:31 +00:00
|
|
|
isc_app_finish();
|
|
|
|
|
1999-01-19 06:32:53 +00:00
|
|
|
return (0);
|
|
|
|
}
|