Skip to content

Commit

Permalink
fix: dns truncate not work
Browse files Browse the repository at this point in the history
  • Loading branch information
wwqgtxx committed Mar 23, 2024
1 parent 9c08e93 commit d56a439
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion dns/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ func (c *client) ExchangeContext(ctx context.Context, m *D.Msg) (*D.Msg, error)
options = append(options, dialer.WithInterface(c.iface))
}

conn, err := getDialHandler(c.r, c.proxyAdapter, c.proxyName, options...)(ctx, network, net.JoinHostPort(ip.String(), c.port))
dialHandler := getDialHandler(c.r, c.proxyAdapter, c.proxyName, options...)
addr := net.JoinHostPort(ip.String(), c.port)
conn, err := dialHandler(ctx, network, addr)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -111,7 +113,16 @@ func (c *client) ExchangeContext(ctx context.Context, m *D.Msg) (*D.Msg, error)
if msg != nil && msg.Truncated && c.Client.Net == "" {
tcpClient := *c.Client // copy a client
tcpClient.Net = "tcp"
network = "tcp"
log.Debugln("[DNS] Truncated reply from %s:%s for %s over UDP, retrying over TCP", c.host, c.port, m.Question[0].String())
dConn.Conn, err = dialHandler(ctx, network, addr)
if err != nil {
ch <- result{msg, err}
return
}
defer func() {
_ = conn.Close()
}()
msg, _, err = tcpClient.ExchangeWithConn(m, dConn)
}

Expand Down

0 comments on commit d56a439

Please sign in to comment.