server.c revision 6d9ae6b3a89de2dad5813b4f1020dbe7d78f66f2
842920c7db2db1de1a0f9571f77aee5ea92ae5bbAutomatic Updater * Copyright (C) 1999 Internet Software Consortium.
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * Permission to use, copy, modify, and distribute this software for any
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * purpose with or without fee is hereby granted, provided that the above
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * copyright notice and this permission notice appear in all copies.
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews printf("%s: %s\n", (msg), dns_result_totext(result));
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrewsmakename(isc_mem_t *mctx, char *text, dns_name_t *name, dns_name_t *origin) {
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews char b[255];
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews isc_buffer_init(&source, text, len, ISC_BUFFERTYPE_TEXT);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews isc_buffer_init(&target, b, sizeof b, ISC_BUFFERTYPE_BINARY);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews result = dns_name_fromtext(name, &source, origin, ISC_FALSE, &target);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * This is in bin/tests/wire_test.c, but should be in a debugging library.
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrewsresolve_packet(isc_mem_t *mctx, dns_db_t *, dns_message_t *, isc_buffer_t *);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrewsresolve_packet(isc_mem_t *mctx, dns_db_t *db, dns_message_t *query,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews result = dns_message_create(mctx, &message, DNS_MESSAGE_INTENT_RENDER);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews CHECKRESULT(result, "dns_message_create failed");
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * XXX This is a total and disgusting hack. We need a way to add
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * a copy of a rdataset and a name to the new message, but for now
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * I'll just steal the one from the existing query message, and
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * make certain the query is not destroyed before our message is.
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews result = dns_message_firstname(query, DNS_SECTION_QUESTION);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews dns_message_currentname(query, DNS_SECTION_QUESTION, &name);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews dns_message_addname(message, name, DNS_SECTION_QUESTION);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews INSIST(result == DNS_R_SUCCESS); /* XXX not in a real server */
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * Pull the name out of the database.
554d22d2deb8889bb16434176b5716ab79d15c50Mark Andrews if (!dns_name_issubdomain(name, dns_db_origin(db))) {
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews result = dns_db_findnode(db, &name2, ISC_FALSE, &node);
554d22d2deb8889bb16434176b5716ab79d15c50Mark Andrews result = dns_db_findrdataset(db, node, NULL, rds->type, 0, &rdataset);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews dns_message_addname(message, &name2, DNS_SECTION_ANSWER);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews result = dns_message_renderbegin(message, target);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews result = dns_message_rendersection(message, DNS_SECTION_QUESTION,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews result = dns_message_rendersection(message, DNS_SECTION_ANSWER,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews result = dns_message_rendersection(message, DNS_SECTION_AUTHORITY,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews result = dns_message_rendersection(message, DNS_SECTION_ADDITIONAL,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews result = dns_message_rendersection(message, DNS_SECTION_OPT,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews result = dns_message_rendersection(message, DNS_SECTION_TSIG,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * Process the wire format message given in r, and return a new packet to
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * Return of DNS_R_SUCCESS means r->base is a newly allocated region of
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * memory, and r->length is its length. The actual for-transmit packet
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * begins at (r->length + reslen) to reserve (reslen) bytes at the front
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * of the packet for transmission specific details.
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrewsdispatch(isc_mem_t *mctx, isc_region_t *rxr, unsigned int reslen)
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews char t[512];
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * Set up the input buffer from the contents of the region passed
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews isc_buffer_init(&source, rxr->base, rxr->length,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews result = dns_message_create(mctx, &message, DNS_MESSAGE_INTENT_PARSE);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews if (CHECKRESULT(result, "dns_message_create failed")) {
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews if (CHECKRESULT(result, "dns_message_parsed failed")) {
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews CHECKRESULT(result, "dns_message_parse failed");
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews if (CHECKRESULT(result, "printmessage failed")) {
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews isc_buffer_init(&target, t, sizeof(t), ISC_BUFFERTYPE_BINARY);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews result = resolve_packet(mctx, db, message, &target);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * Copy the reply out, adjusting for reslen
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews txr.base = isc_mem_get(mctx, txr.length + reslen);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews memcpy(txr.base + reslen, t + reslen, txr.length);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews printf("Base == %p, length == %u\n", txr.base, txr.length);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews unsigned int workers;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews unsigned int addrlen;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews#if 0 /* brister */
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews const char *conffile = "/etc/named.conf"; /* XXX hardwired */
3398334b3acda24b086957286288ca9852662b12Automatic Updater while ((ch = getopt(argc, argv, "z:t:s")) != -1) {
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews#if 0 /* brister */
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews RUNTIME_CHECK(parse_configuration(conffile, mctx, &configctx) ==
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews result = dns_db_create(mctx, "rbt", &base, ISC_FALSE, 1, 0, NULL,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews RUNTIME_CHECK(isc_taskmgr_create(mctx, workers, 0, &manager) ==
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * Open up a database.
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews RUNTIME_CHECK(isc_socketmgr_create(mctx, &socketmgr) == ISC_R_SUCCESS);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * open up a UDP socket
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews RUNTIME_CHECK(isc_socket_create(socketmgr, isc_socket_udp, &so0) ==
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews RUNTIME_CHECK(udp_listener_start(ludp, so0, manager,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * open up a TCP socket
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews RUNTIME_CHECK(isc_socket_create(socketmgr, isc_socket_tcp, &so1) ==
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews RUNTIME_CHECK(tcp_listener_start(ltcp, so1, manager,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * XXX Need to set up a condition variable here, and wait on it.
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * For now, just semi-busy loop.