]> git.ipfire.org Git - thirdparty/squid.git/blob - src/dns.cc
merge changes from SQUID_2_3 branch
[thirdparty/squid.git] / src / dns.cc
1
2 /*
3 * $Id: dns.cc,v 1.80 1999/12/30 17:36:30 wessels Exp $
4 *
5 * DEBUG: section 34 Dnsserver interface
6 * AUTHOR: Harvest Derived
7 *
8 * SQUID Internet Object Cache http://squid.nlanr.net/Squid/
9 * ----------------------------------------------------------
10 *
11 * Squid is the result of efforts by numerous individuals from the
12 * Internet community. Development is led by Duane Wessels of the
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.
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
32 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
33 *
34 */
35
36 #include "squid.h"
37
38 static helper *dnsservers = NULL;
39
40 #if USE_DNSSERVERS
41 static void
42 dnsStats(StoreEntry * sentry)
43 {
44 storeAppendPrintf(sentry, "Dnsserver Statistics:\n");
45 helperStats(sentry, dnsservers);
46 }
47
48 #endif
49
50 void
51 dnsInit(void)
52 {
53 #if USE_DNSSERVERS
54 static int init = 0;
55 wordlist *w;
56 if (!Config.Program.dnsserver)
57 return;
58 if (dnsservers == NULL)
59 dnsservers = helperCreate("dnsserver");
60 dnsservers->n_to_start = Config.dnsChildren;
61 dnsservers->ipc_type = IPC_TCP_SOCKET;
62 assert(dnsservers->cmdline == NULL);
63 wordlistAdd(&dnsservers->cmdline, Config.Program.dnsserver);
64 if (Config.onoff.res_defnames)
65 wordlistAdd(&dnsservers->cmdline, "-D");
66 for (w = Config.dns_nameservers; w != NULL; w = w->next) {
67 wordlistAdd(&dnsservers->cmdline, "-s");
68 wordlistAdd(&dnsservers->cmdline, w->key);
69 }
70 helperOpenServers(dnsservers);
71 if (!init) {
72 cachemgrRegister("dns",
73 "Dnsserver Statistics",
74 dnsStats, 0, 1);
75 init = 1;
76 }
77 #endif
78 }
79
80 void
81 dnsShutdown(void)
82 {
83 if (!dnsservers)
84 return;
85 helperShutdown(dnsservers);
86 wordlistDestroy(&dnsservers->cmdline);
87 if (!shutting_down)
88 return;
89 helperFree(dnsservers);
90 dnsservers = NULL;
91 }
92
93 void
94 dnsSubmit(const char *lookup, HLPCB * callback, void *data)
95 {
96 char buf[256];
97 snprintf(buf, 256, "%s\n", lookup);
98 helperSubmit(dnsservers, buf, callback, data);
99 }
100
101 #ifdef SQUID_SNMP
102 /*
103 * The function to return the DNS via SNMP
104 */
105 variable_list *
106 snmp_netDnsFn(variable_list * Var, snint * ErrP)
107 {
108 variable_list *Answer = NULL;
109 debug(49, 5) ("snmp_netDnsFn: Processing request:\n", Var->name[LEN_SQ_NET +
110 1]);
111 snmpDebugOid(5, Var->name, Var->name_length);
112 *ErrP = SNMP_ERR_NOERROR;
113 switch (Var->name[LEN_SQ_NET + 1]) {
114 case DNS_REQ:
115 Answer = snmp_var_new_integer(Var->name, Var->name_length,
116 dnsservers->stats.requests,
117 SMI_COUNTER32);
118 break;
119 case DNS_REP:
120 Answer = snmp_var_new_integer(Var->name, Var->name_length,
121 dnsservers->stats.replies,
122 SMI_COUNTER32);
123 break;
124 case DNS_SERVERS:
125 Answer = snmp_var_new_integer(Var->name, Var->name_length,
126 dnsservers->n_running,
127 SMI_COUNTER32);
128 break;
129 default:
130 *ErrP = SNMP_ERR_NOSUCHNAME;
131 break;
132 }
133 return Answer;
134 }
135 #endif /*SQUID_SNMP */