fix: dns truncate not work

This commit is contained in:
wwqgtxx 2024-03-23 22:30:19 +08:00
parent 9c08e936f9
commit d56a439a74

View File

@ -78,7 +78,9 @@ func (c *client) ExchangeContext(ctx context.Context, m *D.Msg) (*D.Msg, error)
options = append(options, dialer.WithInterface(c.iface)) 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 { if err != nil {
return nil, err return nil, err
} }
@ -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 == "" { if msg != nil && msg.Truncated && c.Client.Net == "" {
tcpClient := *c.Client // copy a client tcpClient := *c.Client // copy a client
tcpClient.Net = "tcp" 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()) 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) msg, _, err = tcpClient.ExchangeWithConn(m, dConn)
} }