Pr 586 tweaks (#594)
* add proxy tcp * add truncated for tcp to udp response * move truncation to scrubbing * add test that executes upstream over tcp * middleware/proxy: some tweaks rename force-tcp to force_tcp to be inline with the rest and use a dnsOptions struct to put the options in to allow it to be extended. Add some parse tests as well. * Fix test and rename dnsOptions Options
This commit is contained in:
parent
5b32a07ae6
commit
5ac6020f45
6 changed files with 94 additions and 7 deletions
|
@ -14,10 +14,19 @@ import (
|
|||
type dnsEx struct {
|
||||
Timeout time.Duration
|
||||
group *singleflight.Group
|
||||
Options
|
||||
}
|
||||
|
||||
type Options struct {
|
||||
ForceTCP bool // If true use TCP for upstream no matter what
|
||||
}
|
||||
|
||||
func newDNSEx() *dnsEx {
|
||||
return &dnsEx{group: new(singleflight.Group), Timeout: defaultTimeout * time.Second}
|
||||
return newDNSExWithOption(Options{})
|
||||
}
|
||||
|
||||
func newDNSExWithOption(opt Options) *dnsEx {
|
||||
return &dnsEx{group: new(singleflight.Group), Timeout: defaultTimeout * time.Second, Options: opt}
|
||||
}
|
||||
|
||||
func (d *dnsEx) Protocol() string { return "dns" }
|
||||
|
@ -26,7 +35,11 @@ func (d *dnsEx) OnStartup(p *Proxy) error { return nil }
|
|||
|
||||
// Exchange implements the Exchanger interface.
|
||||
func (d *dnsEx) Exchange(ctx context.Context, addr string, state request.Request) (*dns.Msg, error) {
|
||||
co, err := net.DialTimeout(state.Proto(), addr, d.Timeout)
|
||||
proto := state.Proto()
|
||||
if d.Options.ForceTCP {
|
||||
proto = "tcp"
|
||||
}
|
||||
co, err := net.DialTimeout(proto, addr, d.Timeout)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -43,7 +56,8 @@ func (d *dnsEx) Exchange(ctx context.Context, addr string, state request.Request
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Make sure it fits in the DNS response.
|
||||
reply, _ = state.Scrub(reply)
|
||||
reply.Compress = true
|
||||
reply.Id = state.Req.Id
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue