mirror of
https://github.com/3proxy/3proxy.git
synced 2026-11-22 23:59:41 +08:00
resolver: per service, defaultresolve, fakeresolve or sysresolve
C/C++ CI Linux / ${{ matrix.target }} (ubuntu-24.04-arm) (push) Waiting to run
C/C++ CI Linux / ${{ matrix.target }} (ubuntu-latest) (push) Waiting to run
C/C++ CI MacOS / ${{ matrix.target }} (macos-15) (push) Waiting to run
C/C++ CI Windows / ${{ matrix.target }} (windows-2022) (push) Waiting to run
C/C++ CI cmake / ${{ matrix.target }} (macos-15) (push) Waiting to run
C/C++ CI cmake / ${{ matrix.target }} (ubuntu-24.04-arm) (push) Waiting to run
C/C++ CI cmake / ${{ matrix.target }} (ubuntu-latest) (push) Waiting to run
C/C++ CI cmake / ${{ matrix.target }} (windows-2022) (push) Waiting to run
C/C++ CI cmake / ubuntu-latest (wolfSSL) (push) Waiting to run
C/C++ CI Linux / ${{ matrix.target }} (ubuntu-24.04-arm) (push) Waiting to run
C/C++ CI Linux / ${{ matrix.target }} (ubuntu-latest) (push) Waiting to run
C/C++ CI MacOS / ${{ matrix.target }} (macos-15) (push) Waiting to run
C/C++ CI Windows / ${{ matrix.target }} (windows-2022) (push) Waiting to run
C/C++ CI cmake / ${{ matrix.target }} (macos-15) (push) Waiting to run
C/C++ CI cmake / ${{ matrix.target }} (ubuntu-24.04-arm) (push) Waiting to run
C/C++ CI cmake / ${{ matrix.target }} (ubuntu-latest) (push) Waiting to run
C/C++ CI cmake / ${{ matrix.target }} (windows-2022) (push) Waiting to run
C/C++ CI cmake / ubuntu-latest (wolfSSL) (push) Waiting to run
Each service resolves names the way the last of defaultresolve (the name servers in force, configured or the system's with the hosts file), fakeresolve (127.0.0.2) and sysresolve (the C library) read before it says; the last one in the configuration also applies outside services. defaultresolve is the new command, and the default. The name servers and the hosts file no longer depend on the mode: nserver lines, or the system's, are always in force, so dnspr keeps forwarding; with fakeresolve it does not, as before. fakeresolver moves to common.c, which the standalone services link without resolve.c. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
994526dbc4
commit
3d20e1104e
14 files changed
+181
-101
No files matched your search
+44
-6
@@ -570,7 +570,7 @@ int parsehostname(char *hostname, struct clientparam *param, uint16_t port){
|
||||
if(sp){
|
||||
port = atoi(sp+1);
|
||||
}
|
||||
ret = !getip46(param->srv->family, param->hostname, (struct sockaddr *)¶m->req);
|
||||
ret = !getip46m(param->srv->resolvmode, param->srv->family, param->hostname, (struct sockaddr *)¶m->req);
|
||||
if(se) *se = ']';
|
||||
if(sp) *sp = ':';
|
||||
*SAPORT(¶m->req) = htons(port);
|
||||
@@ -863,7 +863,36 @@ int scanaddr(const unsigned char *s, uint32_t * ip, uint32_t * mask) {
|
||||
return res;
|
||||
}
|
||||
|
||||
/* The default resolver: name servers, configured or the system's, or NULL
|
||||
for the system routines. resolvmode is the configuration's, for names
|
||||
resolved outside a service; each service has its own. */
|
||||
RESOLVFUNC resolvfunc = NULL;
|
||||
int resolvmode = RESOLVE_DEFAULT;
|
||||
|
||||
uint32_t fakeresolver (int af, unsigned char *name, unsigned char * value){
|
||||
if(af == AF_INET6){
|
||||
memset(value, 0, 16);
|
||||
value[15] = 2;
|
||||
}
|
||||
else {
|
||||
value[0] = 127;
|
||||
value[1] = 0;
|
||||
value[2] = 0;
|
||||
value[3] = 2;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* The resolver of a mode, NULL for the system routines */
|
||||
static RESOLVFUNC moderesolver(int mode){
|
||||
switch(mode){
|
||||
case RESOLVE_FAKE:
|
||||
return fakeresolver;
|
||||
case RESOLVE_SYSTEM:
|
||||
return NULL;
|
||||
}
|
||||
return resolvfunc;
|
||||
}
|
||||
#ifndef _WIN32
|
||||
_3proxy_mutex_t gethostbyname_mutex;
|
||||
int ghbn_init = 0;
|
||||
@@ -887,7 +916,7 @@ struct hostent * my_gethostbyname(char *name, char *buf, struct hostent *hp){
|
||||
#endif
|
||||
|
||||
#ifdef NOIPV6
|
||||
uint32_t getip(unsigned char *name){
|
||||
static uint32_t getipm(int mode, unsigned char *name){
|
||||
uint32_t retval;
|
||||
int i;
|
||||
int ndots = 0;
|
||||
@@ -913,7 +942,7 @@ uint32_t getip(unsigned char *name){
|
||||
return retval;
|
||||
}
|
||||
}
|
||||
if((tmpresolv=resolvfunc)){
|
||||
if((tmpresolv=moderesolver(mode))){
|
||||
return (*tmpresolv)(AF_INET, name, (unsigned char *)&retval)?retval:0;
|
||||
}
|
||||
#ifndef NOSTDRESOLVE
|
||||
@@ -937,6 +966,10 @@ uint32_t getip(unsigned char *name){
|
||||
#endif
|
||||
return retval;
|
||||
}
|
||||
|
||||
uint32_t getip(unsigned char *name){
|
||||
return getipm(resolvmode, name);
|
||||
}
|
||||
#endif
|
||||
|
||||
int afdetect(unsigned char *name){
|
||||
@@ -971,7 +1004,8 @@ int afdetect(unsigned char *name){
|
||||
|
||||
}
|
||||
|
||||
uint32_t getip46(int family, unsigned char *name, struct sockaddr *sa){
|
||||
/* A name resolved the way a mode says: a service's names with its own */
|
||||
uint32_t getip46m(int mode, int family, unsigned char *name, struct sockaddr *sa){
|
||||
#ifndef NOIPV6
|
||||
int detect;
|
||||
#ifndef NOSTDRESOLVE
|
||||
@@ -984,7 +1018,7 @@ uint32_t getip46(int family, unsigned char *name, struct sockaddr *sa){
|
||||
family = 4;
|
||||
#else
|
||||
((struct sockaddr_in *)sa)->sin_family = AF_INET;
|
||||
return (((struct sockaddr_in *)sa)->sin_addr.s_addr = getip(name))? AF_INET:0;
|
||||
return (((struct sockaddr_in *)sa)->sin_addr.s_addr = getipm(mode, name))? AF_INET:0;
|
||||
#endif
|
||||
#ifndef NOIPV6
|
||||
}
|
||||
@@ -996,7 +1030,7 @@ uint32_t getip46(int family, unsigned char *name, struct sockaddr *sa){
|
||||
return inet_pton(*SAFAMILY(sa), (char *)name, SAADDR(sa))>0? *SAFAMILY(sa) : 0;
|
||||
}
|
||||
|
||||
if((tmpresolv = resolvfunc)){
|
||||
if((tmpresolv = moderesolver(mode))){
|
||||
int f = (family == 6 || family == 64)?AF_INET6:AF_INET;
|
||||
*SAFAMILY(sa) = f;
|
||||
if(tmpresolv(f, name, SAADDR(sa))) return f;
|
||||
@@ -1030,6 +1064,10 @@ uint32_t getip46(int family, unsigned char *name, struct sockaddr *sa){
|
||||
#endif
|
||||
}
|
||||
|
||||
uint32_t getip46(int family, unsigned char *name, struct sockaddr *sa){
|
||||
return getip46m(resolvmode, family, name, sa);
|
||||
}
|
||||
|
||||
int hascap(const unsigned char *line, const char *cap){
|
||||
int len = (int)strlen(cap);
|
||||
for(; *line; line++) if(!strncasecmp((char *)line, cap, len)) return 1;
|
||||
|
||||
Reference in new issue
Block a user