From 0ccd4e6a171519ec811e96ff6efc4c2eedb090a8 Mon Sep 17 00:00:00 2001 From: YX Hao Date: Wed, 2 Oct 2024 07:01:11 +0800 Subject: [PATCH] Add `*` to stand for any protocol for `GroupFile` --- default.config | 6 ++++++ default.en.config | 6 ++++++ mmgr.c | 28 +++++++++++++++++++++++++--- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/default.config b/default.config index 2b90b87..90f88fc 100755 --- a/default.config +++ b/default.config @@ -153,6 +153,12 @@ GroupFile # PROXY 192.168.1.1:8080,192.168.1.1:8081 # # example.com +# +# # file 4 +# # UDP and TCP use the same servers +# PROTOCOL * +# SERVER 1.2.4.8,127.0.0.1 +# # PARALLEL default: on, TCP PROXY default: no # 注意: # 1.对于没有指定服务器的域名,会随机选择一个服务器组进行查询。 diff --git a/default.en.config b/default.en.config index bcab16f..5d226c0 100755 --- a/default.en.config +++ b/default.en.config @@ -182,6 +182,12 @@ GroupFile # PROXY 192.168.1.1:8080,192.168.1.1:8081 # # example.com +# +# # file 4 +# # UDP and TCP use the same servers +# PROTOCOL * +# SERVER 1.2.4.8,127.0.0.1 +# # PARALLEL default: on, TCP PROXY default: no # Notes: # 1.For domains that aren't explicitly specified, a random server group will be chosen. diff --git a/mmgr.c b/mmgr.c index 116d569..6d93aa3 100755 --- a/mmgr.c +++ b/mmgr.c @@ -280,6 +280,7 @@ static int Tcp_Init(ModuleMap *ModuleMap, StringListIterator *i) } /* +############################# # UDP PROTOCOL UDP SERVER 1.2.4.8,127.0.0.1 @@ -309,6 +310,10 @@ PROXY 192.168.1.1:8080,192.168.1.1:8081 example.com +############################# +# UDP and TCP use the same servers +PROTOCOL * +SERVER 1.2.4.8,127.0.0.1 */ static int Modules_InitFromFile(ModuleMap *ModuleMap, StringListIterator *i) { @@ -326,6 +331,10 @@ static int Modules_InitFromFile(ModuleMap *ModuleMap, StringListIterator *i) const char *Protocol = NULL; const char *List = NULL; + BOOL UseUDP = FALSE; + BOOL UseTCP = FALSE; + BOOL UseANY = FALSE; + int ret = 0; FileOri = i->Next(i); @@ -458,7 +467,16 @@ static int Modules_InitFromFile(ModuleMap *ModuleMap, StringListIterator *i) goto EXIT_2; } - if( strcmp(Protocol, "udp") == 0 ) + UseANY = strcmp(Protocol, "*") == 0; + if( UseANY ) + { + UseUDP = TRUE; + UseTCP = TRUE; + } else { + UseUDP = strcmp(Protocol, "udp") == 0; + } + + if( UseUDP ) { const char *Services = NULL; const char *Parallel = "on"; @@ -472,7 +490,11 @@ static int Modules_InitFromFile(ModuleMap *ModuleMap, StringListIterator *i) ret = -337; } - } else if( strcmp(Protocol, "tcp") == 0 ) + } else { + UseTCP = strcmp(Protocol, "tcp") == 0; + } + + if( UseTCP ) { const char *Services = NULL; const char *Parallel = "on"; @@ -488,7 +510,7 @@ static int Modules_InitFromFile(ModuleMap *ModuleMap, StringListIterator *i) ret = -233; } - } else { + } else if( !UseUDP ) { ERRORMSG("Unknown protocol %s, file \"%s\".\n", Protocol, File); ret = -281; }