]> git.ipfire.org Git - thirdparty/squid.git/blame - src/dns.cc
merge changes from SQUID_2_3 branch
[thirdparty/squid.git] / src / dns.cc
CommitLineData
88738790 1
f88bb09c 2/*
7e3ce7b9 3 * $Id: dns.cc,v 1.80 1999/12/30 17:36:30 wessels Exp $
f88bb09c 4 *
5 * DEBUG: section 34 Dnsserver interface
6 * AUTHOR: Harvest Derived
7 *
42c04c16 8 * SQUID Internet Object Cache http://squid.nlanr.net/Squid/
e25c139f 9 * ----------------------------------------------------------
f88bb09c 10 *
11 * Squid is the result of efforts by numerous individuals from the
12 * Internet community. Development is led by Duane Wessels of the
e25c139f 13 * National Laboratory for Applied Network Research and funded by the
14 * National Science Foundation. Squid is Copyrighted (C) 1998 by
15 * Duane Wessels and the University of California San Diego. Please
16 * see the COPYRIGHT file for full details. Squid incorporates
17 * software developed and/or copyrighted by other sources. Please see
18 * the CREDITS file for full details.
f88bb09c 19 *
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 2 of the License, or
23 * (at your option) any later version.
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * You should have received a copy of the GNU General Public License
31 * along with this program; if not, write to the Free Software
cbdec147 32 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
e25c139f 33 *
f88bb09c 34 */
35
36#include "squid.h"
37
74addf6c 38static helper *dnsservers = NULL;
6a78c18e 39
5f841119 40#if USE_DNSSERVERS
6a78c18e 41static void
74addf6c 42dnsStats(StoreEntry * sentry)
f88bb09c 43{
74addf6c 44 storeAppendPrintf(sentry, "Dnsserver Statistics:\n");
45 helperStats(sentry, dnsservers);
0a21bd84 46}
b2c141d4 47
5f841119 48#endif
0a21bd84 49
50void
74addf6c 51dnsInit(void)
0a21bd84 52{
7b724b86 53#if USE_DNSSERVERS
74addf6c 54 static int init = 0;
09c483ec 55 wordlist *w;
74addf6c 56 if (!Config.Program.dnsserver)
57 return;
838b993c 58 if (dnsservers == NULL)
7d47d8e6 59 dnsservers = helperCreate("dnsserver");
74addf6c 60 dnsservers->n_to_start = Config.dnsChildren;
b011dbb0 61 dnsservers->ipc_type = IPC_TCP_SOCKET;
838b993c 62 assert(dnsservers->cmdline == NULL);
74addf6c 63 wordlistAdd(&dnsservers->cmdline, Config.Program.dnsserver);
a7c05555 64 if (Config.onoff.res_defnames)
74addf6c 65 wordlistAdd(&dnsservers->cmdline, "-D");
c68e9c6b 66 for (w = Config.dns_nameservers; w != NULL; w = w->next) {
74addf6c 67 wordlistAdd(&dnsservers->cmdline, "-s");
c68e9c6b 68 wordlistAdd(&dnsservers->cmdline, w->key);
09c483ec 69 }
74addf6c 70 helperOpenServers(dnsservers);
71 if (!init) {
72 cachemgrRegister("dns",
73 "Dnsserver Statistics",
74 dnsStats, 0, 1);
7e3ce7b9 75 init = 1;
f88bb09c 76 }
7b724b86 77#endif
f88bb09c 78}
79
b8d8561b 80void
74addf6c 81dnsShutdown(void)
f88bb09c 82{
74addf6c 83 if (!dnsservers)
84 return;
85 helperShutdown(dnsservers);
86 wordlistDestroy(&dnsservers->cmdline);
838b993c 87 if (!shutting_down)
88 return;
1f5f60dd 89 helperFree(dnsservers);
90 dnsservers = NULL;
f88bb09c 91}
9e4ad609 92
e144eae4 93void
74addf6c 94dnsSubmit(const char *lookup, HLPCB * callback, void *data)
9e4ad609 95{
74addf6c 96 char buf[256];
97 snprintf(buf, 256, "%s\n", lookup);
98 helperSubmit(dnsservers, buf, callback, data);
9e4ad609 99}
dce0d044 100
101#ifdef SQUID_SNMP
102/*
135171fe 103 * The function to return the DNS via SNMP
104 */
dce0d044 105variable_list *
106snmp_netDnsFn(variable_list * Var, snint * ErrP)
107{
736eb6ad 108 variable_list *Answer = NULL;
dce0d044 109 debug(49, 5) ("snmp_netDnsFn: Processing request:\n", Var->name[LEN_SQ_NET +
135171fe 110 1]);
dce0d044 111 snmpDebugOid(5, Var->name, Var->name_length);
dce0d044 112 *ErrP = SNMP_ERR_NOERROR;
135171fe 113 switch (Var->name[LEN_SQ_NET + 1]) {
dce0d044 114 case DNS_REQ:
736eb6ad 115 Answer = snmp_var_new_integer(Var->name, Var->name_length,
116 dnsservers->stats.requests,
117 SMI_COUNTER32);
135171fe 118 break;
dce0d044 119 case DNS_REP:
736eb6ad 120 Answer = snmp_var_new_integer(Var->name, Var->name_length,
121 dnsservers->stats.replies,
122 SMI_COUNTER32);
135171fe 123 break;
dce0d044 124 case DNS_SERVERS:
736eb6ad 125 Answer = snmp_var_new_integer(Var->name, Var->name_length,
126 dnsservers->n_running,
127 SMI_COUNTER32);
135171fe 128 break;
dce0d044 129 default:
135171fe 130 *ErrP = SNMP_ERR_NOSUCHNAME;
736eb6ad 131 break;
dce0d044 132 }
133 return Answer;
134}
135171fe 135#endif /*SQUID_SNMP */