From 9f4cd646c23a8fd511c21446ed2c4d391a21b341 Mon Sep 17 00:00:00 2001 From: xishang0128 Date: Sun, 23 Jun 2024 15:33:38 +0800 Subject: [PATCH] fix: `dhcp://` with special notation cannot be parsed --- component/process/process_linux.go | 1 - config/config.go | 14 +++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/component/process/process_linux.go b/component/process/process_linux.go index 4667104cc2..45c89e5a5a 100644 --- a/component/process/process_linux.go +++ b/component/process/process_linux.go @@ -209,7 +209,6 @@ func findPackageName(uid uint32) string { }) if sharedPackage, loaded := packageManager.SharedPackageByID(uid % 100000); loaded { - fmt.Println(loaded) return sharedPackage } if packageName, loaded := packageManager.PackageByID(uid % 100000); loaded { diff --git a/config/config.go b/config/config.go index 2166b87d70..5676f7aae4 100644 --- a/config/config.go +++ b/config/config.go @@ -1057,6 +1057,16 @@ func parseNameServer(servers []string, respectRules bool, preferH3 bool) ([]dns. var nameservers []dns.NameServer for idx, server := range servers { + if strings.HasPrefix(server, "dhcp://") { + nameservers = append( + nameservers, + dns.NameServer{ + Net: "dhcp", + Addr: server[len("dhcp://"):], + }, + ) + continue + } server = parsePureDNSServer(server) u, err := url.Parse(server) if err != nil { @@ -1099,9 +1109,6 @@ func parseNameServer(servers []string, respectRules bool, preferH3 bool) ([]dns. } } } - case "dhcp": - addr = u.Host - dnsNetType = "dhcp" // UDP from DHCP case "quic": addr, err = hostWithDefaultPort(u.Host, "853") dnsNetType = "quic" // DNS over QUIC @@ -1174,6 +1181,7 @@ func parsePureDNSServer(server string) string { } } } + func parseNameServerPolicy(nsPolicy *orderedmap.OrderedMap[string, any], ruleProviders map[string]providerTypes.RuleProvider, respectRules bool, preferH3 bool) (*orderedmap.OrderedMap[string, []dns.NameServer], error) { policy := orderedmap.New[string, []dns.NameServer]() updatedPolicy := orderedmap.New[string, any]()