6
6
use ArrayAccess \DnsRecord \Abstracts \AbstractResourceRecordType ;
7
7
use ArrayAccess \DnsRecord \Interfaces \ResourceRecord \ResourceRecordMetaTypeInterface ;
8
8
use ArrayAccess \DnsRecord \Packet \Message ;
9
- use ArrayAccess \DnsRecord \Utils \Buffer ;
10
9
use ArrayAccess \DnsRecord \Utils \Lookup ;
11
10
use function pack ;
12
11
use function unpack ;
22
21
* 2: |DO| Z |
23
22
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
24
23
*
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
+ *
25
38
* @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
26
40
*/
27
41
class OPT extends AbstractResourceRecordType implements ResourceRecordMetaTypeInterface
28
42
{
29
43
const TYPE = 'OPT ' ;
30
44
31
- protected int $ extended_rcode ;
45
+ protected int $ extended_rcode = 0 ;
32
46
33
- protected int $ version ;
47
+ protected int $ version = 0 ;
34
48
35
- protected int $ do ;
49
+ protected int $ do = 0 ;
36
50
37
- protected int $ z ;
51
+ protected int $ z = 0 ;
38
52
39
53
protected int $ option_code = 0 ;
40
54
@@ -43,39 +57,40 @@ class OPT extends AbstractResourceRecordType implements ResourceRecordMetaTypeIn
43
57
protected string $ option_data = '' ;
44
58
45
59
/**
46
- * @param string $name
60
+ * @param int $extendedRcode
47
61
* @param int $do
62
+ * @param int $version
63
+ * @param int $z
64
+ * @param int $classSize
48
65
* @return OPT
49
66
* @noinspection PhpDocMissingThrowsInspection
50
67
*/
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
68
85
);
69
86
87
+ // https://datatracker.ietf.org/doc/html/rfc6891#section-6.1.2
88
+ $ message = new Message ($ data );
89
+
70
90
/** @noinspection PhpUnhandledExceptionInspection */
71
91
return new self ($ message , 0 );
72
92
}
73
93
74
- protected function generateTTL ()
75
- {
76
- return unpack ('N ' , $ this ->getQueryMessage ())[1 ];
77
- }
78
-
79
94
protected function parseRData (string $ message , int $ rdataOffset ): void
80
95
{
81
96
[
@@ -84,7 +99,7 @@ protected function parseRData(string $message, int $rdataOffset): void
84
99
'do ' => $ do ,
85
100
'z ' => $ this ->z ,
86
101
] = unpack ('Cextended/Cversion/Cdo/Cz ' , pack ('N ' , $ this ->ttl ));
87
- $ this ->do = ($ do >> 7 );
102
+ $ this ->do = ($ do >> 7 );
88
103
if ($ this ->rdLength > 0 ) {
89
104
[
90
105
'option_code ' => $ this ->option_code ,
0 commit comments