@@ -30,6 +30,11 @@ const (
30
30
UpstreamScheme_UDP UpstreamScheme = "udp"
31
31
UpstreamScheme_TCP_UDP UpstreamScheme = "tcp+udp"
32
32
upstreamScheme_TCP_UDP_Alias UpstreamScheme = "udp+tcp"
33
+ UpstreamScheme_TLS UpstreamScheme = "tls"
34
+ UpstreamScheme_QUIC UpstreamScheme = "quic"
35
+ UpstreamScheme_HTTPS UpstreamScheme = "https"
36
+ upstreamScheme_H3_Alias UpstreamScheme = "http3"
37
+ UpstreamScheme_H3 UpstreamScheme = "h3"
33
38
)
34
39
35
40
func (s UpstreamScheme ) ContainsTcp () bool {
@@ -42,8 +47,9 @@ func (s UpstreamScheme) ContainsTcp() bool {
42
47
}
43
48
}
44
49
45
- func ParseRawUpstream (raw * url.URL ) (scheme UpstreamScheme , hostname string , port uint16 , err error ) {
50
+ func ParseRawUpstream (raw * url.URL ) (scheme UpstreamScheme , hostname string , port uint16 , path string , err error ) {
46
51
var __port string
52
+ var __path string
47
53
switch scheme = UpstreamScheme (raw .Scheme ); scheme {
48
54
case upstreamScheme_TCP_UDP_Alias :
49
55
scheme = UpstreamScheme_TCP_UDP
@@ -53,27 +59,45 @@ func ParseRawUpstream(raw *url.URL) (scheme UpstreamScheme, hostname string, por
53
59
if __port == "" {
54
60
__port = "53"
55
61
}
62
+ case upstreamScheme_H3_Alias :
63
+ scheme = UpstreamScheme_H3
64
+ fallthrough
65
+ case UpstreamScheme_HTTPS , UpstreamScheme_H3 :
66
+ __port = raw .Port ()
67
+ if __port == "" {
68
+ __port = "443"
69
+ }
70
+ __path = raw .Path
71
+ if __path == "" {
72
+ __path = "/dns-query"
73
+ }
74
+ case UpstreamScheme_QUIC , UpstreamScheme_TLS :
75
+ __port = raw .Port ()
76
+ if __port == "" {
77
+ __port = "853"
78
+ }
56
79
default :
57
- return "" , "" , 0 , fmt .Errorf ("unexpected scheme: %v" , raw .Scheme )
80
+ return "" , "" , 0 , "" , fmt .Errorf ("unexpected scheme: %v" , raw .Scheme )
58
81
}
59
82
_port , err := strconv .ParseUint (__port , 10 , 16 )
60
83
if err != nil {
61
- return "" , "" , 0 , fmt .Errorf ("failed to parse dns_upstream port: %v" , err )
84
+ return "" , "" , 0 , "" , fmt .Errorf ("failed to parse dns_upstream port: %v" , err )
62
85
}
63
86
port = uint16 (_port )
64
87
hostname = raw .Hostname ()
65
- return scheme , hostname , port , nil
88
+ return scheme , hostname , port , __path , nil
66
89
}
67
90
68
91
type Upstream struct {
69
92
Scheme UpstreamScheme
70
93
Hostname string
71
94
Port uint16
95
+ Path string
72
96
* netutils.Ip46
73
97
}
74
98
75
99
func NewUpstream (ctx context.Context , upstream * url.URL , resolverNetwork string ) (up * Upstream , err error ) {
76
- scheme , hostname , port , err := ParseRawUpstream (upstream )
100
+ scheme , hostname , port , path , err := ParseRawUpstream (upstream )
77
101
if err != nil {
78
102
return nil , fmt .Errorf ("%w: %v" , ErrFormat , err )
79
103
}
@@ -100,6 +124,7 @@ func NewUpstream(ctx context.Context, upstream *url.URL, resolverNetwork string)
100
124
Scheme : scheme ,
101
125
Hostname : hostname ,
102
126
Port : port ,
127
+ Path : path ,
103
128
Ip46 : ip46 ,
104
129
}, nil
105
130
}
@@ -115,9 +140,9 @@ func (u *Upstream) SupportedNetworks() (ipversions []consts.IpVersionStr, l4prot
115
140
}
116
141
}
117
142
switch u .Scheme {
118
- case UpstreamScheme_TCP :
143
+ case UpstreamScheme_TCP , UpstreamScheme_HTTPS , UpstreamScheme_TLS :
119
144
l4protos = []consts.L4ProtoStr {consts .L4ProtoStr_TCP }
120
- case UpstreamScheme_UDP :
145
+ case UpstreamScheme_UDP , UpstreamScheme_QUIC , UpstreamScheme_H3 :
121
146
l4protos = []consts.L4ProtoStr {consts .L4ProtoStr_UDP }
122
147
case UpstreamScheme_TCP_UDP :
123
148
// UDP first.
@@ -127,7 +152,7 @@ func (u *Upstream) SupportedNetworks() (ipversions []consts.IpVersionStr, l4prot
127
152
}
128
153
129
154
func (u * Upstream ) String () string {
130
- return string (u .Scheme ) + "://" + net .JoinHostPort (u .Hostname , strconv .Itoa (int (u .Port )))
155
+ return string (u .Scheme ) + "://" + net .JoinHostPort (u .Hostname , strconv .Itoa (int (u .Port ))) + u . Path
131
156
}
132
157
133
158
type UpstreamResolver struct {
0 commit comments