]> git.ipfire.org Git - thirdparty/squid.git/blob - src/dns.cc
Cleanup: zap CVS Id tags
[thirdparty/squid.git] / src / dns.cc
1
2 /*
3 * $Id$
4 *
5 * DEBUG: section 34 Dnsserver interface
6 * AUTHOR: Harvest Derived
7 *
8 * SQUID Web Proxy Cache http://www.squid-cache.org/
9 * ----------------------------------------------------------
10 *
11 * Squid is the result of efforts by numerous individuals from
12 * the Internet community; see the CONTRIBUTORS file for full
13 * details. Many organizations have provided support for Squid's
14 * development; see the SPONSORS file for full details. Squid is
15 * Copyrighted (C) 2001 by the Regents of the University of
16 * California; see the COPYRIGHT file for full details. Squid
17 * incorporates software developed and/or copyrighted by other
18 * sources; see 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 #include "Store.h"
38 #include "wordlist.h"
39 #include "SquidTime.h"
40 #include "CacheManager.h"
41 #include "helper.h"
42
43 /* MS VisualStudio Projects are monolitich, so we need the following
44 #if to include the external DNS code in compile process when
45 using external DNS.
46 */
47 #if USE_DNSSERVERS
48
49 static helper *dnsservers = NULL;
50
51 static void
52 dnsStats(StoreEntry * sentry)
53 {
54 storeAppendPrintf(sentry, "Dnsserver Statistics:\n");
55 helperStats(sentry, dnsservers);
56 }
57
58 static void
59 dnsRegisterWithCacheManager(void)
60 {
61 CacheManager::GetInstance()->
62 registerAction("dns", "Dnsserver Statistics", dnsStats, 0, 1);
63 }
64
65 void
66 dnsInit(void)
67 {
68 wordlist *w;
69
70 dnsRegisterWithCacheManager();
71
72 if (!Config.Program.dnsserver)
73 return;
74
75 if (dnsservers == NULL)
76 dnsservers = helperCreate("dnsserver");
77
78 dnsservers->n_to_start = Config.dnsChildren;
79
80 dnsservers->ipc_type = IPC_STREAM;
81
82 assert(dnsservers->cmdline == NULL);
83
84 wordlistAdd(&dnsservers->cmdline, Config.Program.dnsserver);
85
86 if (Config.onoff.res_defnames)
87 wordlistAdd(&dnsservers->cmdline, "-D");
88
89 for (w = Config.dns_nameservers; w != NULL; w = w->next) {
90 wordlistAdd(&dnsservers->cmdline, "-s");
91 wordlistAdd(&dnsservers->cmdline, w->key);
92 }
93
94 helperOpenServers(dnsservers);
95 }
96
97 void
98 dnsShutdown(void)
99 {
100 if (!dnsservers)
101 return;
102
103 helperShutdown(dnsservers);
104
105 wordlistDestroy(&dnsservers->cmdline);
106
107 if (!shutting_down)
108 return;
109
110 helperFree(dnsservers);
111
112 dnsservers = NULL;
113 }
114
115 void
116 dnsSubmit(const char *lookup, HLPCB * callback, void *data)
117 {
118 char buf[256];
119 static time_t first_warn = 0;
120 snprintf(buf, 256, "%s\n", lookup);
121
122 if (dnsservers->stats.queue_size >= dnsservers->n_running * 2) {
123 if (first_warn == 0)
124 first_warn = squid_curtime;
125
126 if (squid_curtime - first_warn > 3 * 60)
127 fatal("DNS servers not responding for 3 minutes");
128
129 debugs(34, 1, "dnsSubmit: queue overload, rejecting " << lookup);
130
131 callback(data, (char *)"$fail Temporary network problem, please retry later");
132
133 return;
134 }
135
136 first_warn = 0;
137 helperSubmit(dnsservers, buf, callback, data);
138 }
139
140 #ifdef SQUID_SNMP
141 /*
142 * The function to return the DNS via SNMP
143 */
144 variable_list *
145 snmp_netDnsFn(variable_list * Var, snint * ErrP)
146 {
147 variable_list *Answer = NULL;
148 debugs(49, 5, "snmp_netDnsFn: Processing request: " << Var->name[LEN_SQ_NET + 1]);
149 snmpDebugOid(5, Var->name, Var->name_length);
150 *ErrP = SNMP_ERR_NOERROR;
151
152 switch (Var->name[LEN_SQ_NET + 1]) {
153
154 case DNS_REQ:
155 Answer = snmp_var_new_integer(Var->name, Var->name_length,
156 dnsservers->stats.requests,
157 SMI_COUNTER32);
158 break;
159
160 case DNS_REP:
161 Answer = snmp_var_new_integer(Var->name, Var->name_length,
162 dnsservers->stats.replies,
163 SMI_COUNTER32);
164 break;
165
166 case DNS_SERVERS:
167 Answer = snmp_var_new_integer(Var->name, Var->name_length,
168 dnsservers->n_running,
169 SMI_COUNTER32);
170 break;
171
172 default:
173 *ErrP = SNMP_ERR_NOSUCHNAME;
174 break;
175 }
176
177 return Answer;
178 }
179
180 #endif /*SQUID_SNMP */
181 #endif /* USE_DNSSERVERS */