-
Notifications
You must be signed in to change notification settings - Fork 610
Update Runner managing DNS components #2378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,7 +27,9 @@ | |
| #include "event.h" | ||
| #include "fd.h" | ||
| #include "fde.h" | ||
| #include "fqdncache.h" | ||
| #include "ip/tools.h" | ||
| #include "ipcache.h" | ||
| #include "MemBuf.h" | ||
| #include "mgr/Registration.h" | ||
| #include "snmp_agent.h" | ||
|
|
@@ -199,22 +201,6 @@ class ns | |
| nsvc *vc = nullptr; | ||
| }; | ||
|
|
||
| namespace Dns | ||
| { | ||
|
|
||
| /// manage DNS internal component | ||
| class ConfigRr : public RegisteredRunner | ||
| { | ||
| public: | ||
| /* RegisteredRunner API */ | ||
| void startReconfigure() override; | ||
| void endingShutdown() override; | ||
| }; | ||
|
|
||
| } // namespace Dns | ||
|
|
||
| DefineRunnerRegistratorIn(Dns, ConfigRr); | ||
|
|
||
| struct _sp { | ||
| char domain[NS_MAXDNAME]; | ||
| int queries; | ||
|
|
@@ -397,6 +383,86 @@ idnsParseNameservers(void) | |
| return result; | ||
| } | ||
|
|
||
| static void | ||
| idnsParseEtcHosts() | ||
| { | ||
| char buf[1024]; | ||
| char buf2[512]; | ||
|
|
||
| if (!Config.etcHostsPath) | ||
| return; | ||
|
|
||
| if (strcmp(Config.etcHostsPath, "none") == 0) | ||
| return; | ||
|
|
||
| FILE *fp = fopen(Config.etcHostsPath, "r"); | ||
| if (!fp) { | ||
| int xerrno = errno; | ||
| debugs(78, DBG_IMPORTANT, "'" << Config.etcHostsPath << "' : " << xstrerr(xerrno)); | ||
| return; | ||
| } | ||
|
|
||
| #if _SQUID_WINDOWS_ | ||
| setmode(fileno(fp), O_TEXT); | ||
| #endif | ||
|
|
||
| while (fgets(buf, 1024, fp)) { /* for each line */ | ||
|
|
||
| if (buf[0] == '#') /* MS-windows likes to add comments */ | ||
| continue; | ||
| strtok(buf, "#"); /* chop everything following a comment marker */ | ||
|
|
||
| auto lt = buf; | ||
| char *addr = buf; | ||
| debugs(78, 5, "etc_hosts: line is '" << buf << "'"); | ||
|
|
||
| auto nt = strpbrk(lt, w_space); | ||
| if (!nt) /* empty line */ | ||
| continue; | ||
| *nt = '\0'; /* null-terminate the address */ | ||
| debugs(78, 5, "etc_hosts: address is '" << addr << "'"); | ||
|
|
||
| lt = nt + 1; | ||
| SBufList hosts; | ||
| while ((nt = strpbrk(lt, w_space))) { | ||
| char *host = nullptr; | ||
|
|
||
| if (nt == lt) { /* multiple spaces */ | ||
| debugs(78, 5, "etc_hosts: multiple spaces, skipping"); | ||
| lt = nt + 1; | ||
| continue; | ||
| } | ||
| *nt = '\0'; | ||
| debugs(78, 5, "etc_hosts: got hostname '" << lt << "'"); | ||
|
|
||
| /* For IPV6 addresses also check for a colon */ | ||
| if (Config.appendDomain && !strchr(lt, '.') && !strchr(lt, ':')) { | ||
| /* I know it's ugly, but it's only at reconfig */ | ||
| strncpy(buf2, lt, sizeof(buf2)-1); | ||
| strncat(buf2, Config.appendDomain, sizeof(buf2) - strlen(lt) - 1); | ||
| buf2[sizeof(buf2)-1] = '\0'; | ||
| host = buf2; | ||
| } else { | ||
| host = lt; | ||
| } | ||
|
|
||
| if (ipcacheAddEntryFromHosts(host, addr) != 0) { | ||
| /* invalid address, continuing is useless */ | ||
| hosts.clear(); | ||
| break; | ||
| } | ||
| hosts.emplace_back(SBuf(host)); | ||
|
|
||
| lt = nt + 1; | ||
| } | ||
|
|
||
| if (!hosts.empty()) | ||
| fqdncacheAddEntryFromHosts(addr, hosts); | ||
| } | ||
|
|
||
| fclose(fp); | ||
| } | ||
|
|
||
| static bool | ||
| idnsParseResolvConf(void) | ||
| { | ||
|
|
@@ -1545,10 +1611,10 @@ idnsRcodeCount(int rcode, int attempt) | |
| ++ RcodeMatrix[rcode][attempt]; | ||
| } | ||
|
|
||
| void | ||
| Dns::Init(void) | ||
| static void | ||
| idnsInitialize() | ||
| { | ||
| static int init = 0; | ||
| idnsParseEtcHosts(); | ||
|
|
||
| if (DnsSocketA < 0 && DnsSocketB < 0) { | ||
| Ip::Address addrV6; // since we do not want to alter Config.Addrs.udp_* and do not have one of our own. | ||
|
|
@@ -1623,12 +1689,6 @@ Dns::Init(void) | |
| idnsAddNameserver("127.0.0.1"); | ||
| } | ||
|
|
||
| if (!init) { | ||
| memset(RcodeMatrix, '\0', sizeof(RcodeMatrix)); | ||
| idns_lookup_hash = hash_create((HASHCMP *) strcmp, 103, hash_string); | ||
| ++init; | ||
| } | ||
|
|
||
| #if WHEN_EDNS_RESPONSES_ARE_PARSED | ||
| if (Config.onoff.ignore_unknown_nameservers && max_shared_edns > 0) { | ||
| debugs(0, DBG_IMPORTANT, "ERROR: cannot negotiate EDNS with unknown nameservers. Disabling"); | ||
|
|
@@ -1669,18 +1729,6 @@ idnsShutdownAndFreeState(const char *reason) | |
| idnsFreeSearchpath(); | ||
| } | ||
|
|
||
| void | ||
| Dns::ConfigRr::endingShutdown() | ||
| { | ||
| idnsShutdownAndFreeState("Shutdown"); | ||
| } | ||
|
|
||
| void | ||
| Dns::ConfigRr::startReconfigure() | ||
| { | ||
| idnsShutdownAndFreeState("Reconfigure"); | ||
| } | ||
|
|
||
| static int | ||
| idnsCachedLookup(const char *key, IDNSCB * callback, void *data) | ||
| { | ||
|
|
@@ -1900,3 +1948,41 @@ snmp_netDnsFn(variable_list * Var, snint * ErrP) | |
|
|
||
| #endif /*SQUID_SNMP */ | ||
|
|
||
| static void | ||
| idnsStartupSequence() | ||
| { | ||
| ipcache_init(); | ||
| fqdncache_init(); | ||
| idnsInitialize(); | ||
| } | ||
|
|
||
| static void | ||
| idnsReconfigureSequence() | ||
| { | ||
| idnsInitialize(); | ||
| ipcache_restart(); /* clear stuck entries */ | ||
| fqdncache_restart(); /* sigh, fqdncache too */ | ||
| } | ||
|
|
||
| namespace Dns | ||
| { | ||
|
|
||
| /// manage DNS internal component | ||
| class ConfigRr : public RegisteredRunner | ||
| { | ||
| public: | ||
| /* RegisteredRunner API */ | ||
| void bootstrapConfig() override { | ||
| // XXX: replace globals | ||
| memset(RcodeMatrix, '\0', sizeof(RcodeMatrix)); | ||
| idns_lookup_hash = hash_create((HASHCMP *) strcmp, 103, hash_string); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These initialization steps are not necessary for configuration parsing and, hence, do not belong to |
||
| } | ||
| void useConfig() override { idnsStartupSequence(); } | ||
| void startReconfigure() override { idnsShutdownAndFreeState("Reconfigure"); } | ||
| void syncConfig() override { idnsReconfigureSequence(); } | ||
| void endingShutdown() override { idnsShutdownAndFreeState("Shutdown"); } | ||
| }; | ||
|
|
||
| } // namespace Dns | ||
|
|
||
| DefineRunnerRegistratorIn(Dns, ConfigRr); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -349,7 +349,7 @@ ipcacheExpiredEntry(ipcache_entry * i) | |
| } | ||
|
|
||
| /// \ingroup IPCacheAPI | ||
| void | ||
| static void | ||
| ipcache_purgelru(void *) | ||
| { | ||
| dlink_node *m; | ||
|
|
@@ -695,7 +695,6 @@ ipcacheRegisterWithCacheManager(void) | |
| void | ||
| ipcache_init(void) | ||
| { | ||
| int n; | ||
| debugs(14, Important(24), "Initializing IP Cache..."); | ||
| memset(&IpcacheStats, '\0', sizeof(IpcacheStats)); | ||
| lru_list = dlink_list(); | ||
|
|
@@ -704,10 +703,11 @@ ipcache_init(void) | |
| (float) Config.ipcache.high) / (float) 100); | ||
| ipcache_low = (long) (((float) Config.ipcache.size * | ||
| (float) Config.ipcache.low) / (float) 100); | ||
| n = hashPrime(ipcache_high / 4); | ||
| auto n = hashPrime(ipcache_high / 4); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you are polishing how |
||
| ip_table = hash_create((HASHCMP *) strcmp, n, hash4); | ||
|
|
||
| ipcacheRegisterWithCacheManager(); | ||
| ipcache_purgelru(nullptr); | ||
| } | ||
|
|
||
| /** | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When working on improving this code, please do not add more configuration parsing steps into socket opening code. Squid should parse/validate configuration and then (if validation is successful) apply it (e.g., by closing and opening configuration-dependent sockets).