resolver: the system's name servers and hosts file by default

Without nserver (or fakeresolve) names were resolved by the C library.
3proxy's own resolver is now the default, with the system's name
servers: up to 3 from /etc/resolv.conf, on Windows from the registry
(set for the system, set for an interface with an address, Tcpip6
interfaces, then those DHCP gave). With none found, the C library as
before. nserver takes up to 3 as well (MAXNSERVERS), a fourth is
warned about.

The name servers in force belong to the process, not a configuration:
nserver lines are kept aside while a configuration is read and replace
them only once it is committed, so a reload resolves with those in
force until then. Resolutions and dnspr read a copy of them.

The system's are read at start, before the configuration and a chroot
in it, and are in force while it is read, so its host names resolve
with them; read again at a commit, and checked every 5 seconds from
the main loop while the default is in force. What cannot be read then
(within a chroot) stays as last read.

The hosts file, read with them, is imported into tables of its own
while the default is in force: its first address of a family for a
name. A name is looked up as one nsrecord made first, then the hosts
file, then the name cache, then name servers. A changed file replaces
what was imported. No name cache is made for it: without nscache
nothing is cached, as before.

The name cache's keys are host names of any case now: DNS names are.

Tests: sysdns, a name of the hosts file answered by dnspr without
nserver, in any case, and not with one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Vladimir DubrovinandClaude Opus 5.5 committed 2026-10-20 18:49:21 +03:00
1 parent 8517a5675b
commit d5e78a0900
11 files changed
+589 -45

No files matched your search

+32 -9
View File
@@ -251,6 +251,8 @@ static int startservice(void *service){
return 0;
}
static int noresolver(void);
static int h_proxy(int argc, unsigned char ** argv){
struct child ch;
@@ -267,7 +269,7 @@ static int h_proxy(int argc, unsigned char ** argv){
childdef.helpmessage = " -Xftp - fetch ftp:// URLs\n";
#endif
#ifdef NOIPV6
if(!conf->resolvfunc || (conf->resolvfunc == myresolver && !dns_table.poolsize)){
if(noresolver()){
fprintf(stderr, "[line %d] Warning: no nserver/nscache configured, proxy may run very slow\n", linenum);
}
#endif
@@ -306,7 +308,7 @@ static int h_proxy(int argc, unsigned char ** argv){
childdef.isudp = 0;
childdef.service = S_SOCKS;
#ifdef NOIPV6
if(!conf->resolvfunc || (conf->resolvfunc == myresolver && !dns_table.poolsize)){
if(noresolver()){
fprintf(stderr, "[line %d] Warning: no nserver/nscache configured, socks may run very slow\n", linenum);
}
#endif
@@ -374,7 +376,7 @@ static int h_proxy(int argc, unsigned char ** argv){
childdef.service = S_DNSPR;
childdef.helpmessage = " -s - simple DNS forwarding - do not use 3proxy resolver / name cache\n -Fip - fake: answer all A queries with this IP\n";
#ifndef NOIPV6
if(!conf->resolvfunc || (conf->resolvfunc == myresolver && !dns_table.poolsize) || conf->resolvfunc == fakeresolver){
if(noresolver() || conf->resolvfunc == fakeresolver){
fprintf(stderr, "[line %d] Warning: no nserver/nscache configured, dnspr will not work as expected\n", linenum);
}
#endif
@@ -735,25 +737,43 @@ static int h_flushusers(int argc, unsigned char **argv){
}
*/
/* The name servers of the configuration being read: they replace those in
force (the process has one list) once it is committed */
static struct nserver cfgns[MAXNSERVERS];
static int cfgnsn = 0;
static int h_nserver(int argc, unsigned char **argv){
char *str;
if(conf->numservers < MAXNSERVERS) {
if(cfgnsn < MAXNSERVERS) {
memset(cfgns + cfgnsn, 0, sizeof(*cfgns));
if((str = strchr((char *)argv[1], '/')))
*str = 0;
*SAPORT(&conf->nservers[conf->numservers].addr) = htons(53);
if(parsehost(46, argv[1], (struct sockaddr *)&conf->nservers[conf->numservers].addr)) return 1;
*SAPORT(&cfgns[cfgnsn].addr) = htons(53);
if(parsehost(46, argv[1], (struct sockaddr *)&cfgns[cfgnsn].addr)) return 1;
if(str) {
conf->nservers[conf->numservers].usetcp = strstr(str + 1, "tcp")? 1:0;
cfgns[cfgnsn].usetcp = strstr(str + 1, "tcp")? 1:0;
*str = '/';
}
conf->numservers++;
cfgnsn++;
}
else fprintf(stderr, "[line %d] Warning: only %d name servers are used, nserver ignored\n", linenum, MAXNSERVERS);
conf->resolvfunc = myresolver;
return 0;
}
/* The configuration's name servers, or the system's in their place */
void confdnscommit(struct extparam *c){
sysdnsapply(c, cfgns, cfgnsn);
}
/* Whether names would be resolved slowly: by the C library, or by name
servers, the system's taken by default, without a cache */
static int noresolver(void){
if(!conf->resolvfunc && !sysdnscount()) return 1;
return (!conf->resolvfunc || conf->resolvfunc == myresolver) && !dns_table.poolsize;
}
static int h_authnserver(int argc, unsigned char **argv){
char *str;
@@ -2513,6 +2533,8 @@ void freeconf(struct extparam *confp){
void confbegin(void){
char * args[] = {"auth", "iponly", NULL};
cfgnsn = 0;
h_auth(2, (unsigned char **)args);
}
@@ -2643,6 +2665,7 @@ int reload (void){
_3proxy_mutex_lock(&confref_mutex);
runconf = new;
_3proxy_mutex_unlock(&confref_mutex);
confdnscommit(new);
resolvfunc = new->resolvfunc;
/* the new services take over the listening sockets of the old ones on
the same addresses, which then stop accepting, and start */