From: Michael Sawyer Date: Thu, 12 Oct 2000 21:52:00 +0000 (+0000) Subject: Add zone-specific reload and refresh capability to server and rndc X-Git-Tag: v9.0.1^4~54 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=94b50bce2b5deeac93734457d5474736d7b76af1;p=thirdparty%2Fbind9.git Add zone-specific reload and refresh capability to server and rndc --- diff --git a/bin/named/client.c b/bin/named/client.c index 1b054633def..f3af301228f 100644 --- a/bin/named/client.c +++ b/bin/named/client.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: client.c,v 1.118 2000/10/11 17:44:04 mws Exp $ */ +/* $Id: client.c,v 1.119 2000/10/12 21:51:42 mws Exp $ */ #include @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include diff --git a/bin/named/include/named/client.h b/bin/named/include/named/client.h index 51b78a6669b..5e15f6ae5aa 100644 --- a/bin/named/include/named/client.h +++ b/bin/named/include/named/client.h @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: client.h,v 1.44 2000/10/11 17:44:07 mws Exp $ */ +/* $Id: client.h,v 1.45 2000/10/12 21:51:48 mws Exp $ */ #ifndef NAMED_CLIENT_H #define NAMED_CLIENT_H 1 @@ -69,10 +69,8 @@ #include #include #include -#ifdef DNS_OPT_NEWCODES #include #include -#endif /* DNS_OPT_NEWCODES */ #include #include diff --git a/bin/named/include/named/omapi.h b/bin/named/include/named/omapi.h index 3408fd65b79..3c4c1c1d58a 100644 --- a/bin/named/include/named/omapi.h +++ b/bin/named/include/named/omapi.h @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: omapi.h,v 1.11 2000/10/05 10:42:38 marka Exp $ */ +/* $Id: omapi.h,v 1.12 2000/10/12 21:51:49 mws Exp $ */ #ifndef NAMED_OMAPI_H #define NAMED_OMAPI_H 1 @@ -38,6 +38,7 @@ #define NS_OMAPI_COMMAND_RELOAD "reload" #define NS_OMAPI_COMMAND_RELOADCONFIG "reload-config" #define NS_OMAPI_COMMAND_RELOADZONES "reload-zones" +#define NS_OMAPI_COMMAND_REFRESH "refresh" isc_result_t ns_omapi_init(void); diff --git a/bin/named/include/named/server.h b/bin/named/include/named/server.h index 1ea52d91b8c..12f8f70a835 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.39 2000/10/05 23:48:49 marka Exp $ */ +/* $Id: server.h,v 1.40 2000/10/12 21:51:50 mws Exp $ */ #ifndef NAMED_SERVER_H #define NAMED_SERVER_H 1 @@ -100,4 +100,10 @@ ns_server_flushonshutdown(ns_server_t *server, isc_boolean_t flush); * Inform the server that the zones should be flushed to disk on shutdown. */ +isc_result_t +ns_server_reloadzone(ns_server_t *server, char *args); + +isc_result_t +ns_server_refreshzone(ns_server_t *server, char *args); + #endif /* NAMED_SERVER_H */ diff --git a/bin/named/omapi.c b/bin/named/omapi.c index 31ffeebe21e..4873fc18ae0 100644 --- a/bin/named/omapi.c +++ b/bin/named/omapi.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: omapi.c,v 1.19 2000/10/11 21:21:46 marka Exp $ */ +/* $Id: omapi.c,v 1.20 2000/10/12 21:51:43 mws Exp $ */ /* * Principal Author: DCL @@ -78,16 +78,33 @@ control_setvalue(omapi_object_t *handle, omapi_string_t *name, */ if (omapi_string_strcmp(name, NS_OMAPI_COMMAND_RELOAD) == 0) { result = ISC_R_SUCCESS; - args = omapi_data_strdup(ns_g_mctx, value); - if (args == NULL) - result = ISC_R_NOMEMORY; - else if (strcmp(args, NS_OMAPI_COMMAND_RELOAD) == 0) + if (value != NULL) { + args = omapi_data_strdup(ns_g_mctx, value); + if (args == NULL) + result = ISC_R_NOMEMORY; + else if (strcmp(args, NS_OMAPI_COMMAND_RELOAD) == 0) + ns_server_reloadwanted(ns_g_server); + /* XXX Can the previous case ever happen??? */ + else + result = ns_server_reloadzone(ns_g_server, + args); + if (args != NULL) + isc_mem_free(ns_g_mctx, args); + } else { ns_server_reloadwanted(ns_g_server); - else - ns_server_reloadzone(ns_g_server, args); - if (args != NULL) - isc_mem_free(ns_g_mctx, args); - + } + } else if (omapi_string_strcmp(name, NS_OMAPI_COMMAND_REFRESH) == 0) { + result = ISC_R_SUCCESS; + if (value != NULL) { + args = omapi_data_strdup(ns_g_mctx, value); + if (args == NULL) + result = ISC_R_NOMEMORY; + else if (strcmp(args, NS_OMAPI_COMMAND_RELOAD) != 0) + result = ns_server_refreshzone(ns_g_server, + args); + if (args != NULL) + isc_mem_free(ns_g_mctx, args); + } } else if (omapi_string_strcmp(name,NS_OMAPI_COMMAND_HALT) == 0) { ns_server_flushonshutdown(ns_g_server, ISC_FALSE); isc_app_shutdown(); @@ -105,7 +122,6 @@ control_setvalue(omapi_object_t *handle, omapi_string_t *name, "control_setvalue: '%.*s' not yet implemented", REGION_FMT(®ion)); result = ISC_R_NOTIMPLEMENTED; - } else { isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_OMAPI, ISC_LOG_WARNING, diff --git a/bin/named/query.c b/bin/named/query.c index 68b98c3cf44..22541ef8db1 100644 --- a/bin/named/query.c +++ b/bin/named/query.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: query.c,v 1.136 2000/10/11 18:00:08 mws Exp $ */ +/* $Id: query.c,v 1.137 2000/10/12 21:51:45 mws Exp $ */ #include @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -2102,7 +2103,6 @@ query_find(ns_client_t *client, dns_fetchevent_t *event) { dns_namereln_t namereln; int order; isc_buffer_t *dbuf; - isc_region_t r; isc_buffer_t b; isc_result_t result, eresult; dns_fixedname_t fixed; diff --git a/bin/named/server.c b/bin/named/server.c index 0e615933bec..5c27400b8b0 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.227 2000/10/11 21:21:47 marka Exp $ */ +/* $Id: server.c,v 1.228 2000/10/12 21:51:46 mws Exp $ */ #include @@ -50,6 +50,7 @@ #include #include #include +#include #include @@ -705,6 +706,7 @@ create_bind_view(dns_view_t **viewp) } + /* * Create the zone that handles queries for * "version.bind. CH". The version string returned is that @@ -1877,11 +1879,98 @@ ns_server_reloadwanted(ns_server_t *server) { UNLOCK(&server->reload_event_lock); } -void -ns_server_reloadzone(ns_server_t *server, char *args) { +static char * +next_token(char **stringp, const char *delim) { + char *res; + do { + res = strsep(stringp, delim); + if (res == NULL) + break; + } while (*res == '\0'); + return (res); +} + +static isc_result_t +zone_from_args(char *args, dns_zone_t **zone) { + char *input, *ptr; + const char *zonetxt = NULL, *viewtxt = NULL; + dns_fixedname_t name; + isc_result_t result; + isc_buffer_t buf; + dns_view_t *view; + + input = args; + ptr = next_token(&input, " \t"); + while (ptr != NULL) { + switch (ptr[0]) { + case 'Z': + zonetxt = ptr+1; + break; + case 'V': + viewtxt = ptr+1; + break; + } + ptr = next_token(&input, " \t"); + } + if (zonetxt == NULL) + return DNS_R_BADZONE; /* Nothing to do! */ + isc_buffer_init(&buf, zonetxt, strlen(zonetxt)); + isc_buffer_add(&buf, strlen(zonetxt)); + dns_fixedname_init(&name); + result = dns_name_fromtext(&(name.name), &buf, dns_rootname, + ISC_FALSE, NULL); + if (result != ISC_R_SUCCESS) + goto fail1; + if (viewtxt == NULL) + viewtxt = "_default"; + result = dns_viewlist_find(&ns_g_server->viewlist, viewtxt, + dns_rdataclass_in, &view); + if (result != ISC_R_SUCCESS) + goto fail1; + result = dns_zt_find(view->zonetable, &(name.name), 0, NULL, + zone); + if (result != ISC_R_SUCCESS) + goto fail2; + fail2: + dns_view_detach(&view); + fail1: + isc_buffer_invalidate(&buf); + return (result); } +isc_result_t +ns_server_reloadzone(ns_server_t *server, char *args) { + isc_result_t result; + dns_zone_t *zone = NULL; + + UNUSED(server); + result = zone_from_args(args, &zone); + if (result != ISC_R_SUCCESS) + return (result); + if (zone != NULL) { + dns_zone_forcereload(zone); + dns_zone_detach(&zone); + } + return (ISC_R_SUCCESS); +} + +isc_result_t +ns_server_refreshzone(ns_server_t *server, char *args) { + isc_result_t result; + dns_zone_t *zone = NULL; + + UNUSED(server); + result = zone_from_args(args, &zone); + if (result != ISC_R_SUCCESS) + return (result); + if (zone != NULL) { + dns_zone_refresh(zone); + dns_zone_detach(&zone); + } + return (ISC_R_SUCCESS); +} + static isc_result_t ns_listenlist_fromconfig(dns_c_lstnlist_t *clist, dns_c_ctx_t *cctx, dns_aclconfctx_t *actx, diff --git a/bin/rndc/rndc.c b/bin/rndc/rndc.c index 813c177a401..ae96fce0df7 100644 --- a/bin/rndc/rndc.c +++ b/bin/rndc/rndc.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: rndc.c,v 1.26 2000/10/11 21:22:29 marka Exp $ */ +/* $Id: rndc.c,v 1.27 2000/10/12 21:51:51 mws Exp $ */ /* * Principal Author: DCL @@ -237,6 +237,7 @@ ndc_setvalue(omapi_object_t *handle, omapi_string_t *name, isc_result_t result; char *message; */ + UNUSED(value); INSIST(handle == (omapi_object_t *)&ndc_g_ndc); @@ -303,6 +304,8 @@ main(int argc, char **argv) { unsigned int algorithm; int ch; int len; + char *zonename = NULL; + char *viewname = NULL; progname = strrchr(*argv, '/'); if (progname != NULL) @@ -310,7 +313,8 @@ main(int argc, char **argv) { else progname = *argv; - while ((ch = isc_commandline_parse(argc, argv, "c:Mmp:s:vy:")) != -1) { + while ((ch = isc_commandline_parse(argc, argv, "c:Mmp:s:Vv:y:z:")) + != -1) { switch (ch) { case 'c': conffile = isc_commandline_argument; @@ -336,18 +340,18 @@ main(int argc, char **argv) { case 's': servername = isc_commandline_argument; break; - - case 'v': - /* - * Undocumented, for testing. - */ + case 'V': verbose = ISC_TRUE; break; - + case 'v': + viewname = isc_commandline_argument; + break; case 'y': keyname = isc_commandline_argument; break; - + case 'z': + zonename = isc_commandline_argument; + break; case '?': usage(); exit(1); @@ -504,8 +508,51 @@ main(int argc, char **argv) { result = ISC_R_NOTIMPLEMENTED; } else if (strcmp(command, "reload") == 0) { - result = send_command(omapimgr, command, args); - + char omapiargs[DNS_NAME_MAXTEXT]; + omapiargs[0]=0; + if (zonename != NULL) { + strncat(omapiargs, "Z", 1); + omapiargs[DNS_NAME_MAXTEXT-1] = 0; + strncat(omapiargs, zonename, + DNS_NAME_MAXTEXT); + omapiargs[DNS_NAME_MAXTEXT-1] = 0; + } + if (zonename != NULL && viewname != NULL) { + strncat(omapiargs, " ", + DNS_NAME_MAXTEXT); + omapiargs[DNS_NAME_MAXTEXT-1] = 0; + } + if (viewname != NULL) { + strncat(omapiargs, "V", 1); + omapiargs[DNS_NAME_MAXTEXT-1] = 0; + strncat(omapiargs, viewname, + DNS_NAME_MAXTEXT); + omapiargs[DNS_NAME_MAXTEXT-1] = 0; + } + result = send_command(omapimgr, command, omapiargs); + } else if (strcmp(command, "refresh") == 0) { + char omapiargs[DNS_NAME_MAXTEXT]; + omapiargs[0]=0; + if (zonename != NULL) { + strncat(omapiargs, "Z", 1); + omapiargs[DNS_NAME_MAXTEXT-1] = 0; + strncat(omapiargs, zonename, + DNS_NAME_MAXTEXT); + omapiargs[DNS_NAME_MAXTEXT-1] = 0; + } + if (zonename != NULL && viewname != NULL) { + strncat(omapiargs, " ", + DNS_NAME_MAXTEXT); + omapiargs[DNS_NAME_MAXTEXT-1] = 0; + } + if (viewname != NULL) { + strncat(omapiargs, "V", 1); + omapiargs[DNS_NAME_MAXTEXT-1] = 0; + strncat(omapiargs, viewname, + DNS_NAME_MAXTEXT); + omapiargs[DNS_NAME_MAXTEXT-1] = 0; + } + result = send_command(omapimgr, command, omapiargs); } else if (strcmp(command, "restart") == 0) { result = ISC_R_NOTIMPLEMENTED; diff --git a/lib/dns/include/dns/opt.h b/lib/dns/include/dns/opt.h index 3c358752429..2ec69a519cc 100644 --- a/lib/dns/include/dns/opt.h +++ b/lib/dns/include/dns/opt.h @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: opt.h,v 1.1 2000/10/11 17:44:18 mws Exp $ */ +/* $Id: opt.h,v 1.2 2000/10/12 21:51:57 mws Exp $ */ #ifndef DNS_OPT_H #define DNS_OPT_H 1 @@ -29,6 +29,14 @@ #include #include +#ifndef NOMINUM_PUBLIC +/* + * XXX For GNS, We're enabling the new option codes. This is + * internal use only. + */ +#define DNS_OPT_NEWCODES +#endif /* NOMINUM_PUBLIC */ + /* * XXX WARNING XXX These codes have not yet been assigned by IANA. * These are here as placekeepers ONLY. diff --git a/lib/dns/include/dns/zone.h b/lib/dns/include/dns/zone.h index 466eca51e0a..7b945979502 100644 --- a/lib/dns/include/dns/zone.h +++ b/lib/dns/include/dns/zone.h @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: zone.h,v 1.78 2000/10/05 06:39:25 marka Exp $ */ +/* $Id: zone.h,v 1.79 2000/10/12 21:51:58 mws Exp $ */ #ifndef DNS_ZONE_H #define DNS_ZONE_H 1 @@ -1156,6 +1156,23 @@ dns_zonemgr_getiolimit(dns_zonemgr_t *zmgr); * 'zmgr' to be a valid zone manager. */ +void +dns_zone_forcereload(dns_zone_t *zone); +/* + * Force a reload of specified zone. + * + * Requires: + * 'zone' to be a valid zone. + */ + +isc_boolean_t +dns_zone_isforced(dns_zone_t *zone); +/* + * Check if the zone is waiting a forced reload. + * + * Requires: + * 'zone' to be a valid zone. + */ ISC_LANG_ENDDECLS diff --git a/lib/dns/xfrin.c b/lib/dns/xfrin.c index b2fc23e6106..7aecd075847 100644 --- a/lib/dns/xfrin.c +++ b/lib/dns/xfrin.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: xfrin.c,v 1.100 2000/10/12 03:32:14 marka Exp $ */ +/* $Id: xfrin.c,v 1.101 2000/10/12 21:51:53 mws Exp $ */ #include @@ -409,7 +409,8 @@ xfr_rr(dns_xfrin_ctx_t *xfr, dns_name_t *name, isc_uint32_t ttl, case XFRST_SOAQUERY: xfr->end_serial = dns_soa_getserial(rdata); if (!DNS_SERIAL_GT(xfr->end_serial, - xfr->ixfr.request_serial)) { + xfr->ixfr.request_serial) && + !dns_zone_isforced(xfr->zone)) { xfrin_log(xfr, ISC_LOG_DEBUG(3), "requested serial %u, " "master has %u, not updating", @@ -437,7 +438,8 @@ xfr_rr(dns_xfrin_ctx_t *xfr, dns_name_t *name, isc_uint32_t ttl, */ xfr->end_serial = dns_soa_getserial(rdata); if (xfr->reqtype == dns_rdatatype_ixfr && - ! DNS_SERIAL_GT(xfr->end_serial, xfr->ixfr.request_serial)) + ! DNS_SERIAL_GT(xfr->end_serial, xfr->ixfr.request_serial) + && !dns_zone_isforced(xfr->zone)) { /* * This must be the single SOA record that is diff --git a/lib/dns/zone.c b/lib/dns/zone.c index 269c8b33d75..7cb40c41bb4 100644 --- a/lib/dns/zone.c +++ b/lib/dns/zone.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: zone.c,v 1.229 2000/10/10 22:00:12 bwelling Exp $ */ +/* $Id: zone.c,v 1.230 2000/10/12 21:51:55 mws Exp $ */ #include @@ -208,10 +208,12 @@ struct dns_zone { #define DNS_ZONEFLG_NOMASTERS 0x00001000U /* an attempt to refresh a * zone with no masters * occured */ -#define DNS_ZONEFLG_LOADING 0x00002000U /* load from disk in progress */ -#define DNS_ZONEFLG_HAVETIMERS 0x00004000U /* timer values have been set from - SOA (if not set, we are still using - default timer values) */ +#define DNS_ZONEFLG_LOADING 0x00002000U /* load from disk in progress*/ +#define DNS_ZONEFLG_HAVETIMERS 0x00004000U /* timer values have been set + * from SOA (if not set, we + * are still using + * default timer values) */ +#define DNS_ZONEFLG_FORCELOAD 0x00008000U /* Force a reload */ #define DNS_ZONE_OPTION(z,o) (((z)->options & (o)) != 0) @@ -2967,6 +2969,9 @@ refresh_callback(isc_task_t *task, isc_event_t *event) { zone_log(zone, me, ISC_LOG_DEBUG(1), "Serial: new %u, old %u", serial, zone->serial); if (!DNS_ZONE_FLAG(zone, DNS_ZONEFLG_LOADED) || +#ifndef NOMINUM_PUBLIC + DNS_ZONE_FLAG(zone, DNS_ZONEFLG_FORCELOAD) || +#endif /* NOMINUM_PUBLIC */ isc_serial_gt(serial, zone->serial)) { tcp_transfer: isc_event_free(&event); @@ -4283,6 +4288,7 @@ zone_xfrdone(dns_zone_t *zone, isc_result_t result) { zone->flags |= DNS_ZONEFLG_NEEDNOTIFY; /*FALLTHROUGH*/ case DNS_R_UPTODATE: + zone->flags &= ~DNS_ZONEFLG_FORCELOAD; /* * Has the zone expired underneath us? */ @@ -4535,6 +4541,11 @@ got_transfer_quota(isc_task_t *task, isc_event_t *event) { "no database exists yet, requesting AXFR of " "initial version from %s", mastertext); xfrtype = dns_rdatatype_axfr; + } else if (dns_zone_isforced(zone)) { + zone_log(zone, me, ISC_LOG_DEBUG(3), + "forced reload, requesting AXFR of " + "initial version from %s", mastertext); + xfrtype = dns_rdatatype_axfr; } else { isc_boolean_t use_ixfr = ISC_TRUE; if (peer != NULL && @@ -5410,3 +5421,18 @@ dns_zonemgr_dbdestroyed(isc_task_t *task, isc_event_t *event) { "database (%p) destroyed", (void*) db); } #endif + +void +dns_zone_forcereload(dns_zone_t *zone) { + REQUIRE(DNS_ZONE_VALID(zone)); + + zone->flags |= DNS_ZONEFLG_FORCELOAD; + dns_zone_refresh(zone); +} + +isc_boolean_t +dns_zone_isforced(dns_zone_t *zone) { + REQUIRE(DNS_ZONE_VALID(zone)); + + return (DNS_ZONE_FLAG(zone,DNS_ZONEFLG_FORCELOAD)); +} diff --git a/util/sanitize_all.sh b/util/sanitize_all.sh index a67828cde10..566a90570c8 100755 --- a/util/sanitize_all.sh +++ b/util/sanitize_all.sh @@ -15,7 +15,7 @@ # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -# $Id: sanitize_all.sh,v 1.7 2000/09/29 21:31:02 mws Exp $ +# $Id: sanitize_all.sh,v 1.8 2000/10/12 21:52:00 mws Exp $ PERL=perl5 @@ -23,9 +23,9 @@ PERL=perl5 # sanitize all of the files in that tree. find . -name '*.[ch]' | xargs $PERL util/sanitize.pl -kNOMINUM_PUBLIC \ - -kISC_PLATFORM_USETHREADS $* + -kISC_PLATFORM_USETHREADS -iNOMINUM_GNS $* find . -name '*.in' | xargs $PERL util/sanitize.pl -kNOMINUM_PUBLIC \ - -kISC_PLATFORM_USETHREADS $* + -kISC_PLATFORM_USETHREADS -iNOMINUM_GNS $* for file in `find . -name '*.dirty'` do clean=`echo $file | sed 's/\.dirty$//'`