修复dns客户端问题
This commit is contained in:
parent
8adbacc16e
commit
1bd5d8da95
@ -86,7 +86,7 @@ disabled_server_names = []
|
||||
## (dnscrypt-proxy will always encrypt everything even using UDP), and can
|
||||
## only increase latency.
|
||||
|
||||
force_tcp = true
|
||||
force_tcp = false
|
||||
|
||||
|
||||
## SOCKS proxy
|
||||
|
||||
@ -70,7 +70,7 @@ namespace FastGithub.Dns
|
||||
{
|
||||
try
|
||||
{
|
||||
this.ProcessDnsPacket(packetBuffer, ref packetLength);
|
||||
this.ProcessDnsPacket(packetBuffer, ref winDivertAddress, ref packetLength);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -136,7 +136,9 @@ namespace FastGithub.Dns
|
||||
/// 处理DNS数据包
|
||||
/// </summary>
|
||||
/// <param name="packetBuffer"></param>
|
||||
private void ProcessDnsPacket(byte[] packetBuffer, ref uint packetLength)
|
||||
/// <param name="winDivertAddress"></param>
|
||||
/// <param name="packetLength"></param>
|
||||
private void ProcessDnsPacket(byte[] packetBuffer, ref WinDivertAddress winDivertAddress, ref uint packetLength)
|
||||
{
|
||||
var packetData = packetBuffer.AsSpan(0, (int)packetLength).ToArray();
|
||||
var packet = Packet.ParsePacket(LinkLayers.Raw, packetData);
|
||||
@ -144,6 +146,11 @@ namespace FastGithub.Dns
|
||||
var udpPacket = (UdpPacket)ipPacket.PayloadPacket;
|
||||
|
||||
var request = Request.FromArray(udpPacket.PayloadData);
|
||||
if (request.OperationCode != OperationCode.Query)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var question = request.Questions.FirstOrDefault();
|
||||
if (question == null || question.Type != RecordType.A)
|
||||
{
|
||||
@ -175,6 +182,16 @@ namespace FastGithub.Dns
|
||||
// 修改数据内容和数据长度
|
||||
packet.Bytes.CopyTo(packetBuffer, 0);
|
||||
packetLength = (uint)packet.Bytes.Length;
|
||||
|
||||
// 反转方向
|
||||
if (winDivertAddress.Direction == WinDivertDirection.Inbound)
|
||||
{
|
||||
winDivertAddress.Direction = WinDivertDirection.Outbound;
|
||||
}
|
||||
else
|
||||
{
|
||||
winDivertAddress.Direction = WinDivertDirection.Inbound;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using DNS.Client.RequestResolver;
|
||||
using DNS.Client;
|
||||
using DNS.Client.RequestResolver;
|
||||
using DNS.Protocol;
|
||||
using DNS.Protocol.ResourceRecords;
|
||||
using FastGithub.Configuration;
|
||||
@ -178,7 +179,11 @@ namespace FastGithub.DomainResolve
|
||||
{
|
||||
try
|
||||
{
|
||||
var request = new Request();
|
||||
var request = new Request
|
||||
{
|
||||
RecursionDesired = true,
|
||||
OperationCode = OperationCode.Query
|
||||
};
|
||||
request.Questions.Add(new Question(new Domain(domain.Host), RecordType.A));
|
||||
|
||||
using var timeoutTokenSource = new CancellationTokenSource(this.lookupTimeout);
|
||||
@ -288,7 +293,8 @@ namespace FastGithub.DomainResolve
|
||||
|
||||
public Task<IResponse> Resolve(IRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return this.resolver.Resolve(request, cancellationToken);
|
||||
var clientRequest = new ClientRequest(this.resolver, request);
|
||||
return clientRequest.Resolve(cancellationToken);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user