Skip to content

Commit dbea502

Browse files
committed
patch bug
1 parent 6d0ff4e commit dbea502

File tree

3 files changed

+48
-30
lines changed

3 files changed

+48
-30
lines changed

src/ResourceRecord/Definitions/QClass/Unassigned.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,11 @@ class Unassigned extends AbstractResourceRecordClass implements ResourceRecordQC
4141
public static function inRange(int $value) : bool
4242
{
4343
foreach (self::RANGES as $ranges) {
44-
if ($value >= $ranges[0] && $value <= $ranges[0]) {
44+
if ($value >= $ranges[0] && $value <= $ranges[1]) {
4545
return true;
4646
}
4747
}
48+
4849
return false;
4950
}
5051

src/ResourceRecord/RRTypes/OPT.php

Lines changed: 44 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use ArrayAccess\DnsRecord\Abstracts\AbstractResourceRecordType;
77
use ArrayAccess\DnsRecord\Interfaces\ResourceRecord\ResourceRecordMetaTypeInterface;
88
use ArrayAccess\DnsRecord\Packet\Message;
9-
use ArrayAccess\DnsRecord\Utils\Buffer;
109
use ArrayAccess\DnsRecord\Utils\Lookup;
1110
use function pack;
1211
use function unpack;
@@ -22,19 +21,34 @@
2221
* 2: |DO| Z |
2322
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
2423
*
24+
* Wire Format - RFC6891
25+
* The type is payload size
26+
*
27+
* +------------+--------------+------------------------------+
28+
* | Field Name | Field Type | Description |
29+
* +------------+--------------+------------------------------+
30+
* | NAME | domain name | MUST be 0 (root domain) |
31+
* | TYPE | u_int16_t | OPT (41) |
32+
* | CLASS | u_int16_t | requestor's UDP payload size |
33+
* | TTL | u_int32_t | extended RCODE and flags |
34+
* | RDLEN | u_int16_t | length of all RDATA |
35+
* | RDATA | octet stream | {attribute,value} pairs |
36+
* +------------+--------------+------------------------------+
37+
*
2538
* @link https://datatracker.ietf.org/doc/html/rfc1035#section-3.4.1
39+
* @link https://datatracker.ietf.org/doc/html/rfc6891#section-6.1.2
2640
*/
2741
class OPT extends AbstractResourceRecordType implements ResourceRecordMetaTypeInterface
2842
{
2943
const TYPE = 'OPT';
3044

31-
protected int $extended_rcode;
45+
protected int $extended_rcode = 0;
3246

33-
protected int $version;
47+
protected int $version = 0;
3448

35-
protected int $do;
49+
protected int $do = 0;
3650

37-
protected int $z;
51+
protected int $z = 0;
3852

3953
protected int $option_code = 0;
4054

@@ -43,39 +57,40 @@ class OPT extends AbstractResourceRecordType implements ResourceRecordMetaTypeIn
4357
protected string $option_data = '';
4458

4559
/**
46-
* @param string $name
60+
* @param int $extendedRcode
4761
* @param int $do
62+
* @param int $version
63+
* @param int $z
64+
* @param int $classSize
4865
* @return OPT
4966
* @noinspection PhpDocMissingThrowsInspection
5067
*/
51-
public static function create(string $name = '', int $do = 1): OPT
52-
{
53-
$name = $name ? Buffer::compressLabel($name) : "\0";
54-
$message = new Message(
55-
$name . pack(
56-
"nnNn",
57-
Lookup::resourceType('OPT')->getValue(),
58-
Lookup::QCLASS_LIST['IN'],
59-
pack(
60-
'CCCC',
61-
0,
62-
0,
63-
($do << 7),
64-
0
65-
),
66-
0
67-
)
68+
public static function create(
69+
int $extendedRcode = 0,
70+
int $do = 1,
71+
int $version = 0,
72+
int $z = 0,
73+
int $classSize = Lookup::MAX_TCP_SIZE
74+
): OPT {
75+
$data = pack(
76+
"cnnCCCCn",
77+
0, // empty
78+
Lookup::resourceType('OPT')->getValue(),
79+
$classSize,
80+
$extendedRcode, // extended_rcode
81+
$version, // version
82+
($do << 7), // DO
83+
$z, // z
84+
0 // end
6885
);
6986

87+
// https://datatracker.ietf.org/doc/html/rfc6891#section-6.1.2
88+
$message = new Message($data);
89+
7090
/** @noinspection PhpUnhandledExceptionInspection */
7191
return new self($message, 0);
7292
}
7393

74-
protected function generateTTL()
75-
{
76-
return unpack('N', $this->getQueryMessage())[1];
77-
}
78-
7994
protected function parseRData(string $message, int $rdataOffset): void
8095
{
8196
[
@@ -84,7 +99,7 @@ protected function parseRData(string $message, int $rdataOffset): void
8499
'do' => $do,
85100
'z' => $this->z,
86101
] = unpack('Cextended/Cversion/Cdo/Cz', pack('N', $this->ttl));
87-
$this->do = ($do >> 7);
102+
$this->do = ($do >> 7);
88103
if ($this->rdLength > 0) {
89104
[
90105
'option_code' => $this->option_code,

src/Utils/Lookup.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,11 @@ public static function resourceClass(ResourceRecordClassInterface|string|int $cl
391391
if (PrivateUse::RANGE_START <= $class && PrivateUse::RANGE_END >= $class) {
392392
return new PrivateUse($class);
393393
}
394+
394395
if (Unassigned::inRange($class)) {
395396
return new Unassigned($class);
396397
}
398+
397399
throw new InvalidArgumentException(
398400
sprintf(
399401
'QCLASS value "%d" is not valid',

0 commit comments

Comments
 (0)