Skip to content

Commit

Permalink
Merge pull request #56 from xervon/tcptls-fix
Browse files Browse the repository at this point in the history
Use network "tcp" when calling tls.DialWithDialer
  • Loading branch information
denis-tingaikin authored Aug 20, 2024
2 parents ebe17d8 + 7059326 commit 6aa8454
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func NewClient(addr, net string) Client {
// SetTLSConfig sets tls config for client
func (c *client) SetTLSConfig(cfg *tls.Config) {
if cfg != nil {
c.net = tcptlc
c.net = tcptls
}
c.transport.SetTLSConfig(cfg)
}
Expand Down
2 changes: 1 addition & 1 deletion const.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const (
defaultTimeout = 30 * time.Second
readTimeout = 2 * time.Second
attemptDelay = time.Millisecond * 100
tcptlc = "tcp-tls"
tcptls = "tcp-tls"
tcp = "tcp"
udp = "udp"
)
2 changes: 1 addition & 1 deletion setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ func parseProtocol(f *Fanout, c *caddyfile.Dispenser) error {
return c.ArgErr()
}
net := strings.ToLower(c.Val())
if net != tcp && net != udp && net != tcptlc {
if net != tcp && net != udp && net != tcptls {
return errors.New("unknown network protocol")
}
f.net = net
Expand Down
8 changes: 4 additions & 4 deletions transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ func (t *transportImpl) SetTLSConfig(c *tls.Config) {
// Dial dials the address configured in transportImpl, potentially reusing a connection or creating a new one.
func (t *transportImpl) Dial(ctx context.Context, network string) (*dns.Conn, error) {
if t.tlsConfig != nil {
network = tcptlc
network = tcptls
}
if network == tcptlc {
if network == tcptls {
return t.dial(ctx, &dns.Client{Net: network, Dialer: &net.Dialer{Timeout: maxTimeout}, TLSConfig: t.tlsConfig})
}
return t.dial(ctx, &dns.Client{Net: network, Dialer: &net.Dialer{Timeout: maxTimeout}})
Expand All @@ -78,8 +78,8 @@ func (t *transportImpl) dial(ctx context.Context, c *dns.Client) (*dns.Conn, err
}
var conn = new(dns.Conn)
var err error
if network == tcptlc {
conn.Conn, err = tls.DialWithDialer(&d, network, t.addr, c.TLSConfig)
if network == tcptls {
conn.Conn, err = tls.DialWithDialer(&d, "tcp", t.addr, c.TLSConfig)
} else {
conn.Conn, err = d.DialContext(ctx, network, t.addr)
}
Expand Down

0 comments on commit 6aa8454

Please sign in to comment.