Add support for internal DNS system

This commit is contained in:
风扇滑翔翼 2025-03-09 18:55:37 +00:00 committed by GitHub
parent 4999fd5b7b
commit 5f504888b6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 206 additions and 0 deletions

View file

@ -106,6 +106,14 @@ func lookupIP(domain string, strategy DomainStrategy, localAddr net.Address) ([]
return ips, err
}
func LookupHTTPS(domain string) (map[string]string, error) {
if dnsClient == nil {
return nil, nil
}
HTTPSRecord, err := dnsClient.(dns.EnhancedClient).LookupHTTPS(domain)
return HTTPSRecord, err
}
func canLookupIP(ctx context.Context, dst net.Destination, sockopt *SocketConfig) bool {
if dst.Address.Family().IsIP() || dnsClient == nil {
return false

View file

@ -138,6 +138,22 @@ func QueryRecord(domain string, server string) ([]byte, error) {
// dnsQuery is the real func for sending type65 query for given domain to given DNS server.
// return ECH config, TTL and error
func dnsQuery(server string, domain string) ([]byte, uint32, error) {
if server == "xray" {
HTTPSRecord, err := internet.LookupHTTPS(domain)
if err !=nil {
return []byte{}, 0, errors.New("failed to lookup HTTPS record with xray internal DNS: ", err)
}
ECH := HTTPSRecord["ech"]
if ECH == "" {
return []byte{}, 0, errors.New("no ech record found")
}
Base64echConfigList, err := goech.ECHConfigListFromBase64(ECH)
if err != nil {
return []byte{}, 0, errors.New("failed to unmarshal ECHConfigList: ", err)
}
echConfigList, _ := Base64echConfigList.MarshalBinary()
return echConfigList, 600, nil
}
m := new(dns.Msg)
var dnsResolve []byte
m.SetQuestion(dns.Fqdn(domain), dns.TypeHTTPS)