From c4dc4fd856e6a6344aea08adab30dd8a1b0fb32a Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Tue, 26 Aug 2003 04:34:17 +0000 Subject: [PATCH] 1417. [func] ID.SERVER/CHAOS is now a built in zone. See "server-id" for how to configure. --- CHANGES | 3 ++ bin/named/builtin.c | 25 ++++++++++++++-- bin/named/config.c | 47 ++++++++++++++++-------------- bin/named/include/named/server.h | 5 +++- bin/named/server.c | 18 +++++++++++- doc/arm/Bv9ARM-book.xml | 17 ++++++++++- lib/isccfg/namedconf.c | 49 +++++++++++++++++++++++++++++++- 7 files changed, 137 insertions(+), 27 deletions(-) diff --git a/CHANGES b/CHANGES index 7a8df3c3f1..16f5371c98 100644 --- a/CHANGES +++ b/CHANGES @@ -6,6 +6,9 @@ 1500. [bug] host failed to lookup MX records. Also look up AAAA records. +1417. [func] ID.SERVER/CHAOS is now a built in zone. + See "server-id" for how to configure. + 1412. [func] You can now specify servers to be tried if a nameserver has IPv6 address and you only support IPv4 or the reverse. See dual-stack-servers. diff --git a/bin/named/builtin.c b/bin/named/builtin.c index b3f5d11f6a..76bf136919 100644 --- a/bin/named/builtin.c +++ b/bin/named/builtin.c @@ -15,10 +15,10 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: builtin.c,v 1.4.106.1 2003/08/13 03:58:09 marka Exp $ */ +/* $Id: builtin.c,v 1.4.106.2 2003/08/26 04:34:14 marka Exp $ */ /* - * The built-in "version", "hostname", and "authors" databases. + * The built-in "version", "hostname", "id" and "authors" databases. */ #include @@ -43,6 +43,7 @@ typedef struct builtin builtin_t; static isc_result_t do_version_lookup(dns_sdblookup_t *lookup); static isc_result_t do_hostname_lookup(dns_sdblookup_t *lookup); static isc_result_t do_authors_lookup(dns_sdblookup_t *lookup); +static isc_result_t do_id_lookup(dns_sdblookup_t *lookup); /* * We can't use function pointers as the db_data directly @@ -57,6 +58,7 @@ struct builtin { static builtin_t version_builtin = { do_version_lookup }; static builtin_t hostname_builtin = { do_hostname_lookup }; static builtin_t authors_builtin = { do_authors_lookup }; +static builtin_t id_builtin = { do_id_lookup }; static dns_sdbimplementation_t *builtin_impl; @@ -147,6 +149,23 @@ do_authors_lookup(dns_sdblookup_t *lookup) { return (ISC_R_SUCCESS); } +static isc_result_t +do_id_lookup(dns_sdblookup_t *lookup) { + + if (ns_g_server->server_usehostname) { + char buf[256]; + isc_result_t result = ns_os_gethostname(buf, sizeof(buf)); + if (result != ISC_R_SUCCESS) + return (result); + return (put_txt(lookup, buf)); + } + + if (ns_g_server->server_id == NULL) + return (ISC_R_SUCCESS); + else + return (put_txt(lookup, ns_g_server->server_id)); +} + static isc_result_t builtin_authority(const char *zone, void *dbdata, dns_sdblookup_t *lookup) { isc_result_t result; @@ -178,6 +197,8 @@ builtin_create(const char *zone, int argc, char **argv, *dbdata = &hostname_builtin; else if (strcmp(argv[0], "authors") == 0) *dbdata = &authors_builtin; + else if (strcmp(argv[0], "id") == 0) + *dbdata = &id_builtin; else return (ISC_R_NOTIMPLEMENTED); return (ISC_R_SUCCESS); diff --git a/bin/named/config.c b/bin/named/config.c index 76f593a461..2a15a80c97 100644 --- a/bin/named/config.c +++ b/bin/named/config.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: config.c,v 1.11.2.4.8.11 2003/08/25 04:16:16 marka Exp $ */ +/* $Id: config.c,v 1.11.2.4.8.12 2003/08/26 04:34:14 marka Exp $ */ #include @@ -76,6 +76,7 @@ options {\n\ rrset-order {order cyclic;};\n\ serial-queries 20;\n\ serial-query-rate 20;\n\ + server-id none;\n\ stacksize default;\n\ statistics-file \"named.stats\";\n\ statistics-interval 60;\n\ @@ -148,26 +149,30 @@ options {\n\ zone-statistics false;\n\ max-journal-size unlimited;\n\ ixfr-from-differences false;\n\ -}; - -view \"_bind\" chaos { - recursion no; - - zone \"version.bind\" chaos { - type master; - database \"_builtin version\"; - }; - - zone \"hostname.bind\" chaos { - type master; - database \"_builtin hostname\"; - }; - - zone \"authors.bind\" chaos { - type master; - database \"_builtin authors\"; - }; -}; +};\n\ +\n\ +view \"_bind\" chaos {\n\ + recursion no;\n\ +\n\ + zone \"version.bind\" chaos {\n\ + type master;\n\ + database \"_builtin version\";\n\ + };\n\ +\n\ + zone \"hostname.bind\" chaos {\n\ + type master;\n\ + database \"_builtin hostname\";\n\ + };\n\ +\n\ + zone \"authors.bind\" chaos {\n\ + type master;\n\ + database \"_builtin authors\";\n\ + };\n\ + zone \"id.server\" chaos {\n\ + type master;\n\ + database \"_builtin id\";\n\ + };\n\ +};\n\ "; isc_result_t diff --git a/bin/named/include/named/server.h b/bin/named/include/named/server.h index 80bc3807d4..83fee2ed6c 100644 --- a/bin/named/include/named/server.h +++ b/bin/named/include/named/server.h @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: server.h,v 1.58.2.1.10.7 2003/08/21 06:17:57 marka Exp $ */ +/* $Id: server.h,v 1.58.2.1.10.8 2003/08/26 04:34:15 marka Exp $ */ #ifndef NAMED_SERVER_H #define NAMED_SERVER_H 1 @@ -56,6 +56,9 @@ struct ns_server { char * version; /* User-specified version */ isc_boolean_t hostname_set; /* User has set hostname */ char * hostname; /* User-specified hostname */ + /* Use hostname for server id */ + isc_boolean_t server_usehostname; + char * server_id; /* User-specified server id */ /* * Current ACL environment. This defines the diff --git a/bin/named/server.c b/bin/named/server.c index 5a398ac9a5..e345d67ca1 100644 --- a/bin/named/server.c +++ b/bin/named/server.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: server.c,v 1.339.2.15.2.26 2003/08/26 03:24:07 marka Exp $ */ +/* $Id: server.c,v 1.339.2.15.2.27 2003/08/26 04:34:14 marka Exp $ */ #include @@ -2301,6 +2301,18 @@ load_configuration(const char *filename, ns_server_t *server, server->hostname_set = ISC_FALSE; } + obj = NULL; + result = ns_config_get(maps, "server-id", &obj); + server->server_usehostname = ISC_FALSE; + if (result == ISC_R_SUCCESS && cfg_obj_isboolean(obj)) { + server->server_usehostname = ISC_TRUE; + } else if (result == ISC_R_SUCCESS) { + CHECKM(setoptstring(server, &server->server_id, obj), "strdup"); + } else { + result = setoptstring(server, &server->server_id, NULL); + RUNTIME_CHECK(result == ISC_R_SUCCESS); + } + obj = NULL; result = ns_config_get(maps, "flush-zones-on-shutdown", &obj); if (result == ISC_R_SUCCESS) { @@ -2621,6 +2633,8 @@ ns_server_create(isc_mem_t *mctx, ns_server_t **serverp) { server->hostname = NULL; server->version_set = ISC_FALSE; server->version = NULL; + server->server_usehostname = ISC_FALSE; + server->server_id = NULL; CHECKFATAL(dns_stats_alloccounters(ns_g_mctx, &server->querystats), "dns_stats_alloccounters"); @@ -2653,6 +2667,8 @@ ns_server_destroy(ns_server_t **serverp) { isc_mem_free(server->mctx, server->version); if (server->hostname != NULL) isc_mem_free(server->mctx, server->hostname); + if (server->server_id != NULL) + isc_mem_free(server->mctx, server->server_id); dns_zonemgr_detach(&server->zonemgr); diff --git a/doc/arm/Bv9ARM-book.xml b/doc/arm/Bv9ARM-book.xml index dd5bf0ce84..1e5b20180f 100644 --- a/doc/arm/Bv9ARM-book.xml +++ b/doc/arm/Bv9ARM-book.xml @@ -2,7 +2,7 @@ - + BIND 9 Administrator Reference Manual @@ -2657,6 +2657,7 @@ statement in the named.conf file: options { version version_string; hostname hostname_string; + server-id server_id_string; directory path_name; key-directory path_name; named-xfer path_name; @@ -2783,6 +2784,20 @@ answering your queries. Specifying hostname none; disables processing of the queries. +server-id +The ID of the server should report via a query of +the name ID.SERVER +with type TXT, class CHAOS. +The primary purpose of such queries is to +identify which of a group of anycast servers is actually +answering your queries. Specifying server-id none; +disables processing of the queries. +Specifying server-id hostname; will cause named to +use the hostname as found by gethostname(). +The default server-id is none. + + + directory The working directory of the server. Any non-absolute pathnames in the configuration file will be taken diff --git a/lib/isccfg/namedconf.c b/lib/isccfg/namedconf.c index 1ad8a9b843..8f4fd0f1cc 100644 --- a/lib/isccfg/namedconf.c +++ b/lib/isccfg/namedconf.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: namedconf.c,v 1.21.44.10 2003/08/26 03:24:14 marka Exp $ */ +/* $Id: namedconf.c,v 1.21.44.11 2003/08/26 04:34:17 marka Exp $ */ #include @@ -442,6 +442,52 @@ doc_qstringornone(cfg_printer_t *pctx, const cfg_type_t *type) { static cfg_type_t cfg_type_qstringornone = { "qstringornone", parse_qstringornone, NULL, doc_qstringornone, NULL, NULL }; +/* + * keyword hostname + */ + +static void +print_hostname(cfg_printer_t *pctx, cfg_obj_t *obj) { + UNUSED(obj); + cfg_print_chars(pctx, "hostname", 4); +} + +static cfg_type_t cfg_type_hostname = { + "hostname", NULL, print_hostname, NULL, &cfg_rep_boolean, NULL +}; + +/* + * "server-id" arguement. + */ + +static isc_result_t +parse_serverid(cfg_parser_t *pctx, const cfg_type_t *type, + cfg_obj_t **ret) +{ + isc_result_t result; + CHECK(cfg_gettoken(pctx, CFG_LEXOPT_QSTRING)); + if (pctx->token.type == isc_tokentype_string && + strcasecmp(TOKEN_STRING(pctx), "none") == 0) + return (cfg_create_obj(pctx, &cfg_type_none, ret)); + if (pctx->token.type == isc_tokentype_string && + strcasecmp(TOKEN_STRING(pctx), "hostname") == 0) { + return (cfg_create_obj(pctx, &cfg_type_hostname, ret)); + } + cfg_ungettoken(pctx); + return (cfg_parse_qstring(pctx, type, ret)); + cleanup: + return (result); +} + +static void +doc_serverid(cfg_printer_t *pctx, const cfg_type_t *type) { + UNUSED(type); + cfg_print_chars(pctx, "( | none | hostname )", 26); +} + +static cfg_type_t cfg_type_serverid = { + "serverid", parse_serverid, NULL, doc_serverid, NULL, NULL }; + /* * Clauses that can be found within the top level of the named.conf * file only. @@ -507,6 +553,7 @@ options_clauses[] = { { "recursive-clients", &cfg_type_uint32, 0 }, { "serial-queries", &cfg_type_uint32, CFG_CLAUSEFLAG_OBSOLETE }, { "serial-query-rate", &cfg_type_uint32, 0 }, + { "server-id", &cfg_type_serverid, 0 }, { "stacksize", &cfg_type_size, 0 }, { "statistics-file", &cfg_type_qstring, 0 }, { "statistics-interval", &cfg_type_uint32, CFG_CLAUSEFLAG_NYI },