[GH-ISSUE #51] DNS Nameserver not available over TCP #21

Closed
opened 2026-03-04 23:23:47 +03:00 by kerem · 3 comments
Owner

Originally created by @Thiritin on GitHub (Jul 11, 2018).
Original GitHub issue: https://github.com/yswery/PHP-DNS-SERVER/issues/51

Reachability via TCP should be guaranteed [if not, output of WARNING message].
Explanation: RFC 1034 and 1035 specify for DNSs the use of UDP as well as of TCP
transport, with UDP having priority and being used for the major share of the data
traffic. Under certain circumstances (e.g. response size) a resolver may have to switch
to TCP, which is expressly supported by RFC 1123.

Due to this not matching DENICS terms the Nameserver cannot be used with .de TLDs.

https://www.denic.de/fileadmin/public/documentation/DENIC-23p_EN.pdf
(Chapter 2.1.6, paragraph 3)

Originally created by @Thiritin on GitHub (Jul 11, 2018). Original GitHub issue: https://github.com/yswery/PHP-DNS-SERVER/issues/51 Reachability via TCP should be guaranteed **[if not, output of WARNING message].** Explanation: RFC 1034 and 1035 specify for DNSs the use of UDP as well as of TCP transport, with UDP having priority and being used for the major share of the data traffic. Under certain circumstances (e.g. response size) a resolver may have to switch to TCP, which is expressly supported by RFC 1123. Due to this not matching DENICS terms the Nameserver cannot be used with .de TLDs. https://www.denic.de/fileadmin/public/documentation/DENIC-23p_EN.pdf (Chapter 2.1.6, paragraph 3)
kerem closed this issue 2026-03-04 23:23:47 +03:00
Author
Owner

@linkec commented on GitHub (Jul 16, 2018):

I found the same problem,And rewrite my own code, but have some problem.
`$data = unpack('npacksize/npacket_id/nflags/nqdcount/nancount/nnscount/narcount', $buffer);
$flags = ds_decode_flags($data['flags']);
$offset = 14;
$question = ds_decode_question_rr($buffer, $offset, $data['qdcount']);
$authority = ds_decode_rr($buffer, $offset, $data['nscount']);
$additional = ds_decode_rr($buffer, $offset, $data['arcount']);

if(isset($additional[0]['data']['value']['ip'])){
	$userip = $additional[0]['data']['value']['ip'];
}else{
	$userip = $connection->getRemoteIp();
}
$answer = get_answer($userip,$question);

$flags['qr'] = 1;
$flags['aa'] = 1;
$flags['ra'] = 0;

$qdcount = count($question);
$ancount = count($answer);
$nscount = count($authority);
$arcount = count($additional);

$response = pack('nnnnnn', $data['packet_id'], ds_encode_flags($flags), $qdcount, $ancount, $nscount, $arcount);
$response .= ($p = ds_encode_question_rr($question, strlen($response)));
$response .= ($p = ds_encode_rr($answer, strlen($response)));
$response .= ds_encode_rr($authority, strlen($response));
$response .= ds_encode_rr($additional, strlen($response));
$packsize = strlen($response);
$response = pack('N',$packsize).$response;
return $response;`
<!-- gh-comment-id:405350003 --> @linkec commented on GitHub (Jul 16, 2018): I found the same problem,And rewrite my own code, but have some problem. `$data = unpack('npacksize/npacket_id/nflags/nqdcount/nancount/nnscount/narcount', $buffer); $flags = ds_decode_flags($data['flags']); $offset = 14; $question = ds_decode_question_rr($buffer, $offset, $data['qdcount']); $authority = ds_decode_rr($buffer, $offset, $data['nscount']); $additional = ds_decode_rr($buffer, $offset, $data['arcount']); if(isset($additional[0]['data']['value']['ip'])){ $userip = $additional[0]['data']['value']['ip']; }else{ $userip = $connection->getRemoteIp(); } $answer = get_answer($userip,$question); $flags['qr'] = 1; $flags['aa'] = 1; $flags['ra'] = 0; $qdcount = count($question); $ancount = count($answer); $nscount = count($authority); $arcount = count($additional); $response = pack('nnnnnn', $data['packet_id'], ds_encode_flags($flags), $qdcount, $ancount, $nscount, $arcount); $response .= ($p = ds_encode_question_rr($question, strlen($response))); $response .= ($p = ds_encode_rr($answer, strlen($response))); $response .= ds_encode_rr($authority, strlen($response)); $response .= ds_encode_rr($additional, strlen($response)); $packsize = strlen($response); $response = pack('N',$packsize).$response; return $response;`
Author
Owner

@linkec commented on GitHub (Jul 16, 2018):

BTW, I have added the EDNS extension, still on experimental.

<!-- gh-comment-id:405351886 --> @linkec commented on GitHub (Jul 16, 2018): BTW, I have added the EDNS extension, still on experimental.
Author
Owner

@samuelwilliams commented on GitHub (Sep 11, 2018):

@linkec Did you want to build a test case and make a pull request? That would help demonstrate your point.

<!-- gh-comment-id:420235307 --> @samuelwilliams commented on GitHub (Sep 11, 2018): @linkec Did you want to build a test case and make a pull request? That would help demonstrate your point.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/PHP-DNS-SERVER#21
No description provided.