~clint-fewbar/ubuntu/precise/squid3/ignore-sighup-early

« back to all changes in this revision

Viewing changes to src/dns.cc

  • Committer: Bazaar Package Importer
  • Author(s): Luigi Gangitano
  • Date: 2006-11-11 10:32:06 UTC
  • Revision ID: james.westby@ubuntu.com-20061111103206-f3p0r9g0vq44rp3r
Tags: upstream-3.0.PRE5
ImportĀ upstreamĀ versionĀ 3.0.PRE5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/*
 
3
 * $Id: dns.cc,v 1.99 2006/10/20 05:34:20 wessels Exp $
 
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
void
 
59
dnsInit(void)
 
60
{
 
61
    wordlist *w;
 
62
 
 
63
    if (!Config.Program.dnsserver)
 
64
        return;
 
65
 
 
66
    if (dnsservers == NULL)
 
67
        dnsservers = helperCreate("dnsserver");
 
68
 
 
69
    dnsservers->n_to_start = Config.dnsChildren;
 
70
 
 
71
    dnsservers->ipc_type = IPC_STREAM;
 
72
 
 
73
    assert(dnsservers->cmdline == NULL);
 
74
 
 
75
    wordlistAdd(&dnsservers->cmdline, Config.Program.dnsserver);
 
76
 
 
77
    if (Config.onoff.res_defnames)
 
78
        wordlistAdd(&dnsservers->cmdline, "-D");
 
79
 
 
80
    for (w = Config.dns_nameservers; w != NULL; w = w->next) {
 
81
        wordlistAdd(&dnsservers->cmdline, "-s");
 
82
        wordlistAdd(&dnsservers->cmdline, w->key);
 
83
    }
 
84
 
 
85
    helperOpenServers(dnsservers);
 
86
}
 
87
 
 
88
void
 
89
dnsRegisterWithCacheManager(CacheManager & manager)
 
90
{
 
91
    manager.registerAction("dns",
 
92
                           "Dnsserver Statistics",
 
93
                           dnsStats, 0, 1);
 
94
}
 
95
 
 
96
void
 
97
dnsShutdown(void)
 
98
{
 
99
    if (!dnsservers)
 
100
        return;
 
101
 
 
102
    helperShutdown(dnsservers);
 
103
 
 
104
    wordlistDestroy(&dnsservers->cmdline);
 
105
 
 
106
    if (!shutting_down)
 
107
        return;
 
108
 
 
109
    helperFree(dnsservers);
 
110
 
 
111
    dnsservers = NULL;
 
112
}
 
113
 
 
114
void
 
115
dnsSubmit(const char *lookup, HLPCB * callback, void *data)
 
116
{
 
117
    char buf[256];
 
118
    static time_t first_warn = 0;
 
119
    snprintf(buf, 256, "%s\n", lookup);
 
120
 
 
121
    if (dnsservers->stats.queue_size >= dnsservers->n_running * 2) {
 
122
        if (first_warn == 0)
 
123
            first_warn = squid_curtime;
 
124
 
 
125
        if (squid_curtime - first_warn > 3 * 60)
 
126
            fatal("DNS servers not responding for 3 minutes");
 
127
 
 
128
        debug(34, 1) ("dnsSubmit: queue overload, rejecting %s\n", lookup);
 
129
 
 
130
        callback(data, (char *)"$fail Temporary network problem, please retry later");
 
131
 
 
132
        return;
 
133
    }
 
134
 
 
135
    first_warn = 0;
 
136
    helperSubmit(dnsservers, buf, callback, data);
 
137
}
 
138
 
 
139
#ifdef SQUID_SNMP
 
140
/*
 
141
 * The function to return the DNS via SNMP
 
142
 */
 
143
variable_list *
 
144
snmp_netDnsFn(variable_list * Var, snint * ErrP)
 
145
{
 
146
    variable_list *Answer = NULL;
 
147
    debug(49, 5) ("snmp_netDnsFn: Processing request: %d\n", Var->name[LEN_SQ_NET + 1]);
 
148
    snmpDebugOid(5, Var->name, Var->name_length);
 
149
    *ErrP = SNMP_ERR_NOERROR;
 
150
 
 
151
    switch (Var->name[LEN_SQ_NET + 1]) {
 
152
 
 
153
    case DNS_REQ:
 
154
        Answer = snmp_var_new_integer(Var->name, Var->name_length,
 
155
                                      dnsservers->stats.requests,
 
156
                                      SMI_COUNTER32);
 
157
        break;
 
158
 
 
159
    case DNS_REP:
 
160
        Answer = snmp_var_new_integer(Var->name, Var->name_length,
 
161
                                      dnsservers->stats.replies,
 
162
                                      SMI_COUNTER32);
 
163
        break;
 
164
 
 
165
    case DNS_SERVERS:
 
166
        Answer = snmp_var_new_integer(Var->name, Var->name_length,
 
167
                                      dnsservers->n_running,
 
168
                                      SMI_COUNTER32);
 
169
        break;
 
170
 
 
171
    default:
 
172
        *ErrP = SNMP_ERR_NOSUCHNAME;
 
173
        break;
 
174
    }
 
175
 
 
176
    return Answer;
 
177
}
 
178
 
 
179
#endif /*SQUID_SNMP */
 
180
#endif /* USE_DNSSERVERS */