-
Notifications
You must be signed in to change notification settings - Fork 244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proxy: add support for HTTP-only listeners for DoH #302
Open
gdm85
wants to merge
1
commit into
AdguardTeam:master
Choose a base branch
from
gdm85:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,6 +57,9 @@ type Options struct { | |
// Server listen ports | ||
ListenPorts []int `yaml:"listen-ports" short:"p" long:"port" description:"Listening ports. Zero value disables TCP and UDP listeners"` | ||
|
||
// HTTP listen ports | ||
HTTPListenPorts []int `yaml:"http-port" short:"i" long:"http-port" description:"Listening ports for DNS-over-HTTP"` | ||
|
||
// HTTPS listen ports | ||
HTTPSListenPorts []int `yaml:"https-port" short:"s" long:"https-port" description:"Listening ports for DNS-over-HTTPS"` | ||
|
||
|
@@ -245,9 +248,9 @@ func main() { | |
if err != nil { | ||
if flagsErr, ok := err.(*goFlags.Error); ok && flagsErr.Type == goFlags.ErrHelp { | ||
os.Exit(0) | ||
} else { | ||
log.Fatalf("failed to parse args: %v", err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an unrelated fix but handy to have. |
||
} | ||
|
||
os.Exit(1) | ||
} | ||
|
||
run(options) | ||
|
@@ -621,6 +624,13 @@ func initListenAddrs(config *proxy.Config, options *Options) { | |
} | ||
} | ||
|
||
for _, port := range options.HTTPListenPorts { | ||
for _, ip := range listenIPs { | ||
a := net.TCPAddrFromAddrPort(netip.AddrPortFrom(ip, uint16(port))) | ||
config.HTTPListenAddr = append(config.HTTPSListenAddr, a) | ||
} | ||
} | ||
|
||
if config.DNSCryptResolverCert != nil && config.DNSCryptProviderName != "" { | ||
for _, port := range options.DNSCryptListenPorts { | ||
for _, ip := range listenIPs { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,10 +19,10 @@ import ( | |
"golang.org/x/net/http2" | ||
) | ||
|
||
// listenHTTP creates instances of TLS listeners that will be used to run an | ||
// listenHTTPS creates instances of TLS listeners that will be used to run an | ||
// H1/H2 server. Returns the address the listener actually listens to (useful | ||
// in the case if port 0 is specified). | ||
func (p *Proxy) listenHTTP(addr *net.TCPAddr) (laddr *net.TCPAddr, err error) { | ||
func (p *Proxy) listenHTTPS(addr *net.TCPAddr) (laddr *net.TCPAddr, err error) { | ||
tcpListen, err := net.ListenTCP("tcp", addr) | ||
if err != nil { | ||
return nil, fmt.Errorf("tcp listener: %w", err) | ||
|
@@ -38,6 +38,21 @@ func (p *Proxy) listenHTTP(addr *net.TCPAddr) (laddr *net.TCPAddr, err error) { | |
return tcpListen.Addr().(*net.TCPAddr), nil | ||
} | ||
|
||
// listenHTTP creates instances of TCP listeners that will be used to run an | ||
// H1 server. Returns the address the listener actually listens to (useful | ||
// in the case if port 0 is specified). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The result is not really used, since there is no H3 support. |
||
func (p *Proxy) listenHTTP(addr *net.TCPAddr) (laddr *net.TCPAddr, err error) { | ||
tcpListen, err := net.ListenTCP("tcp", addr) | ||
if err != nil { | ||
return nil, fmt.Errorf("tcp listener: %w", err) | ||
} | ||
log.Info("Listening to http://%s", tcpListen.Addr()) | ||
|
||
p.httpListen = append(p.httpListen, tcpListen) | ||
|
||
return tcpListen.Addr().(*net.TCPAddr), nil | ||
} | ||
|
||
// listenH3 creates instances of QUIC listeners that will be used for running | ||
// an HTTP/3 server. | ||
func (p *Proxy) listenH3(addr *net.UDPAddr) (err error) { | ||
|
@@ -70,10 +85,9 @@ func (p *Proxy) createHTTPSListeners() (err error) { | |
|
||
for _, addr := range p.HTTPSListenAddr { | ||
log.Info("Creating an HTTPS server") | ||
|
||
tcpAddr, lErr := p.listenHTTP(addr) | ||
if lErr != nil { | ||
return fmt.Errorf("failed to start HTTPS server on %s: %w", addr, lErr) | ||
tcpAddr, err := p.listenHTTPS(addr) | ||
if err != nil { | ||
return fmt.Errorf("failed to start HTTPS server on %s: %w", addr, err) | ||
} | ||
|
||
if p.HTTP3 { | ||
|
@@ -90,6 +104,26 @@ func (p *Proxy) createHTTPSListeners() (err error) { | |
return nil | ||
} | ||
|
||
// createHTTPListeners creates the cleartext HTTP listener for DNS-over-HTTPS (behind a proxy doing TLS termination). | ||
func (p *Proxy) createHTTPListeners() (err error) { | ||
p.httpServer = &http.Server{ | ||
Handler: p, | ||
ReadHeaderTimeout: defaultTimeout, | ||
WriteTimeout: defaultTimeout, | ||
} | ||
|
||
for _, addr := range p.HTTPListenAddr { | ||
log.Info("Creating an HTTP server") | ||
|
||
_, err := p.listenHTTP(addr) | ||
if err != nil { | ||
return fmt.Errorf("failed to start HTTP server on %s: %w", addr, err) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// ServeHTTP is the http.Handler implementation that handles DoH queries. | ||
// Here is what it returns: | ||
// | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't find a better letter here,
-i
.