Feature: can set custom interface for dns nameserver (#2126)

This commit is contained in:
Hongqi Yu
2022-06-01 10:50:54 +08:00
committed by GitHub
parent 9d2fc976e2
commit c1285adbf8
3 changed files with 15 additions and 5 deletions

View File

@ -79,7 +79,7 @@ func (dc *dohClient) doRequest(req *http.Request) (msg *D.Msg, err error) {
return msg, err
}
func newDoHClient(url string, r *Resolver) *dohClient {
func newDoHClient(url, iface string, r *Resolver) *dohClient {
return &dohClient{
url: url,
transport: &http.Transport{
@ -95,7 +95,12 @@ func newDoHClient(url string, r *Resolver) *dohClient {
return nil, err
}
return dialer.DialContext(ctx, "tcp", net.JoinHostPort(ip.String(), port))
options := []dialer.Option{}
if iface != "" {
options = append(options, dialer.WithInterface(iface))
}
return dialer.DialContext(ctx, "tcp", net.JoinHostPort(ip.String(), port), options...)
},
},
}