"Fossies" - the Fresh Open Source Software Archive

Member "bind-9.17.5/lib/ns/server.c" (4 Sep 2020, 5535 Bytes) of package /linux/misc/dns/bind9/9.17.5/bind-9.17.5.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "server.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
    3  *
    4  * This Source Code Form is subject to the terms of the Mozilla Public
    5  * License, v. 2.0. If a copy of the MPL was not distributed with this
    6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
    7  *
    8  * See the COPYRIGHT file distributed with this work for additional
    9  * information regarding copyright ownership.
   10  */
   11 
   12 /*! \file */
   13 
   14 #include <stdbool.h>
   15 
   16 #include <isc/mem.h>
   17 #include <isc/stats.h>
   18 #include <isc/util.h>
   19 
   20 #include <dns/stats.h>
   21 #include <dns/tkey.h>
   22 
   23 #include <ns/query.h>
   24 #include <ns/server.h>
   25 #include <ns/stats.h>
   26 
   27 #define SCTX_MAGIC    ISC_MAGIC('S', 'c', 't', 'x')
   28 #define SCTX_VALID(s) ISC_MAGIC_VALID(s, SCTX_MAGIC)
   29 
   30 #define CHECKFATAL(op)                                  \
   31     do {                                            \
   32         result = (op);                          \
   33         RUNTIME_CHECK(result == ISC_R_SUCCESS); \
   34     } while (0)
   35 
   36 isc_result_t
   37 ns_server_create(isc_mem_t *mctx, ns_matchview_t matchingview,
   38          ns_server_t **sctxp) {
   39     ns_server_t *sctx;
   40     isc_result_t result;
   41 
   42     REQUIRE(sctxp != NULL && *sctxp == NULL);
   43 
   44     sctx = isc_mem_get(mctx, sizeof(*sctx));
   45 
   46     memset(sctx, 0, sizeof(*sctx));
   47 
   48     isc_mem_attach(mctx, &sctx->mctx);
   49 
   50     isc_refcount_init(&sctx->references, 1);
   51 
   52     isc_quota_init(&sctx->xfroutquota, 10);
   53     isc_quota_init(&sctx->tcpquota, 10);
   54     isc_quota_init(&sctx->recursionquota, 100);
   55 
   56     CHECKFATAL(dns_tkeyctx_create(mctx, &sctx->tkeyctx));
   57 
   58     CHECKFATAL(ns_stats_create(mctx, ns_statscounter_max, &sctx->nsstats));
   59 
   60     CHECKFATAL(dns_rdatatypestats_create(mctx, &sctx->rcvquerystats));
   61 
   62     CHECKFATAL(dns_opcodestats_create(mctx, &sctx->opcodestats));
   63 
   64     CHECKFATAL(dns_rcodestats_create(mctx, &sctx->rcodestats));
   65 
   66     CHECKFATAL(isc_stats_create(mctx, &sctx->udpinstats4,
   67                     dns_sizecounter_in_max));
   68 
   69     CHECKFATAL(isc_stats_create(mctx, &sctx->udpoutstats4,
   70                     dns_sizecounter_out_max));
   71 
   72     CHECKFATAL(isc_stats_create(mctx, &sctx->udpinstats6,
   73                     dns_sizecounter_in_max));
   74 
   75     CHECKFATAL(isc_stats_create(mctx, &sctx->udpoutstats6,
   76                     dns_sizecounter_out_max));
   77 
   78     CHECKFATAL(isc_stats_create(mctx, &sctx->tcpinstats4,
   79                     dns_sizecounter_in_max));
   80 
   81     CHECKFATAL(isc_stats_create(mctx, &sctx->tcpoutstats4,
   82                     dns_sizecounter_out_max));
   83 
   84     CHECKFATAL(isc_stats_create(mctx, &sctx->tcpinstats6,
   85                     dns_sizecounter_in_max));
   86 
   87     CHECKFATAL(isc_stats_create(mctx, &sctx->tcpoutstats6,
   88                     dns_sizecounter_out_max));
   89 
   90     sctx->udpsize = 4096;
   91     sctx->transfer_tcp_message_size = 20480;
   92 
   93     sctx->fuzztype = isc_fuzz_none;
   94     sctx->fuzznotify = NULL;
   95     sctx->gethostname = NULL;
   96 
   97     sctx->matchingview = matchingview;
   98     sctx->answercookie = true;
   99 
  100     ISC_LIST_INIT(sctx->altsecrets);
  101 
  102     sctx->magic = SCTX_MAGIC;
  103     *sctxp = sctx;
  104 
  105     return (ISC_R_SUCCESS);
  106 }
  107 
  108 void
  109 ns_server_attach(ns_server_t *src, ns_server_t **dest) {
  110     REQUIRE(SCTX_VALID(src));
  111     REQUIRE(dest != NULL && *dest == NULL);
  112 
  113     isc_refcount_increment(&src->references);
  114 
  115     *dest = src;
  116 }
  117 
  118 void
  119 ns_server_detach(ns_server_t **sctxp) {
  120     ns_server_t *sctx;
  121 
  122     REQUIRE(sctxp != NULL && SCTX_VALID(*sctxp));
  123     sctx = *sctxp;
  124     *sctxp = NULL;
  125 
  126     if (isc_refcount_decrement(&sctx->references) == 1) {
  127         ns_altsecret_t *altsecret;
  128 
  129         while ((altsecret = ISC_LIST_HEAD(sctx->altsecrets)) != NULL) {
  130             ISC_LIST_UNLINK(sctx->altsecrets, altsecret, link);
  131             isc_mem_put(sctx->mctx, altsecret, sizeof(*altsecret));
  132         }
  133 
  134         isc_quota_destroy(&sctx->recursionquota);
  135         isc_quota_destroy(&sctx->tcpquota);
  136         isc_quota_destroy(&sctx->xfroutquota);
  137 
  138         if (sctx->server_id != NULL) {
  139             isc_mem_free(sctx->mctx, sctx->server_id);
  140         }
  141 
  142         if (sctx->blackholeacl != NULL) {
  143             dns_acl_detach(&sctx->blackholeacl);
  144         }
  145         if (sctx->keepresporder != NULL) {
  146             dns_acl_detach(&sctx->keepresporder);
  147         }
  148         if (sctx->tkeyctx != NULL) {
  149             dns_tkeyctx_destroy(&sctx->tkeyctx);
  150         }
  151 
  152         if (sctx->nsstats != NULL) {
  153             ns_stats_detach(&sctx->nsstats);
  154         }
  155 
  156         if (sctx->rcvquerystats != NULL) {
  157             dns_stats_detach(&sctx->rcvquerystats);
  158         }
  159         if (sctx->opcodestats != NULL) {
  160             dns_stats_detach(&sctx->opcodestats);
  161         }
  162         if (sctx->rcodestats != NULL) {
  163             dns_stats_detach(&sctx->rcodestats);
  164         }
  165 
  166         if (sctx->udpinstats4 != NULL) {
  167             isc_stats_detach(&sctx->udpinstats4);
  168         }
  169         if (sctx->tcpinstats4 != NULL) {
  170             isc_stats_detach(&sctx->tcpinstats4);
  171         }
  172         if (sctx->udpoutstats4 != NULL) {
  173             isc_stats_detach(&sctx->udpoutstats4);
  174         }
  175         if (sctx->tcpoutstats4 != NULL) {
  176             isc_stats_detach(&sctx->tcpoutstats4);
  177         }
  178 
  179         if (sctx->udpinstats6 != NULL) {
  180             isc_stats_detach(&sctx->udpinstats6);
  181         }
  182         if (sctx->tcpinstats6 != NULL) {
  183             isc_stats_detach(&sctx->tcpinstats6);
  184         }
  185         if (sctx->udpoutstats6 != NULL) {
  186             isc_stats_detach(&sctx->udpoutstats6);
  187         }
  188         if (sctx->tcpoutstats6 != NULL) {
  189             isc_stats_detach(&sctx->tcpoutstats6);
  190         }
  191 
  192         sctx->magic = 0;
  193 
  194         isc_mem_putanddetach(&sctx->mctx, sctx, sizeof(*sctx));
  195     }
  196 }
  197 
  198 isc_result_t
  199 ns_server_setserverid(ns_server_t *sctx, const char *serverid) {
  200     REQUIRE(SCTX_VALID(sctx));
  201 
  202     if (sctx->server_id != NULL) {
  203         isc_mem_free(sctx->mctx, sctx->server_id);
  204         sctx->server_id = NULL;
  205     }
  206 
  207     if (serverid != NULL) {
  208         sctx->server_id = isc_mem_strdup(sctx->mctx, serverid);
  209     }
  210 
  211     return (ISC_R_SUCCESS);
  212 }
  213 
  214 void
  215 ns_server_setoption(ns_server_t *sctx, unsigned int option, bool value) {
  216     REQUIRE(SCTX_VALID(sctx));
  217     if (value) {
  218         sctx->options |= option;
  219     } else {
  220         sctx->options &= ~option;
  221     }
  222 }
  223 
  224 bool
  225 ns_server_getoption(ns_server_t *sctx, unsigned int option) {
  226     REQUIRE(SCTX_VALID(sctx));
  227 
  228     return ((sctx->options & option) != 0);
  229 }