| 3 |
liveuser |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
namespace React\Dns\Model;
|
|
|
4 |
|
|
|
5 |
/**
|
|
|
6 |
* This class represents a single resulting record in a response message
|
|
|
7 |
*
|
|
|
8 |
* It uses a structure similar to `\React\Dns\Query\Query`, but does include
|
|
|
9 |
* fields for resulting TTL and resulting record data (IPs etc.).
|
|
|
10 |
*
|
|
|
11 |
* @link https://tools.ietf.org/html/rfc1035#section-4.1.3
|
|
|
12 |
* @see \React\Dns\Query\Query
|
|
|
13 |
*/
|
|
|
14 |
final class Record
|
|
|
15 |
{
|
|
|
16 |
/**
|
|
|
17 |
* @var string hostname without trailing dot, for example "reactphp.org"
|
|
|
18 |
*/
|
|
|
19 |
public $name;
|
|
|
20 |
|
|
|
21 |
/**
|
|
|
22 |
* @var int see Message::TYPE_* constants (UINT16)
|
|
|
23 |
*/
|
|
|
24 |
public $type;
|
|
|
25 |
|
|
|
26 |
/**
|
|
|
27 |
* Defines the network class, usually `Message::CLASS_IN`.
|
|
|
28 |
*
|
|
|
29 |
* For `OPT` records (EDNS0), this defines the maximum message size instead.
|
|
|
30 |
*
|
|
|
31 |
* @var int see Message::CLASS_IN constant (UINT16)
|
|
|
32 |
* @see Message::CLASS_IN
|
|
|
33 |
*/
|
|
|
34 |
public $class;
|
|
|
35 |
|
|
|
36 |
/**
|
|
|
37 |
* Defines the maximum time-to-live (TTL) in seconds
|
|
|
38 |
*
|
|
|
39 |
* For `OPT` records (EDNS0), this defines additional flags instead.
|
|
|
40 |
*
|
|
|
41 |
* @var int maximum TTL in seconds (UINT32, most significant bit always unset)
|
|
|
42 |
* @link https://tools.ietf.org/html/rfc2181#section-8
|
|
|
43 |
* @link https://tools.ietf.org/html/rfc6891#section-6.1.3 for `OPT` records (EDNS0)
|
|
|
44 |
*/
|
|
|
45 |
public $ttl;
|
|
|
46 |
|
|
|
47 |
/**
|
|
|
48 |
* The payload data for this record
|
|
|
49 |
*
|
|
|
50 |
* The payload data format depends on the record type. As a rule of thumb,
|
|
|
51 |
* this library will try to express this in a way that can be consumed
|
|
|
52 |
* easily without having to worry about DNS internals and its binary transport:
|
|
|
53 |
*
|
|
|
54 |
* - A:
|
|
|
55 |
* IPv4 address string, for example "192.168.1.1".
|
|
|
56 |
*
|
|
|
57 |
* - AAAA:
|
|
|
58 |
* IPv6 address string, for example "::1".
|
|
|
59 |
*
|
|
|
60 |
* - CNAME / PTR / NS:
|
|
|
61 |
* The hostname without trailing dot, for example "reactphp.org".
|
|
|
62 |
*
|
|
|
63 |
* - TXT:
|
|
|
64 |
* List of string values, for example `["v=spf1 include:example.com"]`.
|
|
|
65 |
* This is commonly a list with only a single string value, but this
|
|
|
66 |
* technically allows multiple strings (0-255 bytes each) in a single
|
|
|
67 |
* record. This is rarely used and depending on application you may want
|
|
|
68 |
* to join these together or handle them separately. Each string can
|
|
|
69 |
* transport any binary data, its character encoding is not defined (often
|
|
|
70 |
* ASCII/UTF-8 in practice). [RFC 1464](https://tools.ietf.org/html/rfc1464)
|
|
|
71 |
* suggests using key-value pairs such as `["name=test","version=1"]`, but
|
|
|
72 |
* interpretation of this is not enforced and left up to consumers of this
|
|
|
73 |
* library (used for DNS-SD/Zeroconf and others).
|
|
|
74 |
*
|
|
|
75 |
* - MX:
|
|
|
76 |
* Mail server priority (UINT16) and target hostname without trailing dot,
|
|
|
77 |
* for example `{"priority":10,"target":"mx.example.com"}`.
|
|
|
78 |
* The payload data uses an associative array with fixed keys "priority"
|
|
|
79 |
* (also commonly referred to as weight or preference) and "target" (also
|
|
|
80 |
* referred to as exchange). If a response message contains multiple
|
|
|
81 |
* records of this type, targets should be sorted by priority (lowest
|
|
|
82 |
* first) - this is left up to consumers of this library (used for SMTP).
|
|
|
83 |
*
|
|
|
84 |
* - SRV:
|
|
|
85 |
* Service priority (UINT16), service weight (UINT16), service port (UINT16)
|
|
|
86 |
* and target hostname without trailing dot, for example
|
|
|
87 |
* `{"priority":10,"weight":50,"port":8080,"target":"example.com"}`.
|
|
|
88 |
* The payload data uses an associative array with fixed keys "priority",
|
|
|
89 |
* "weight", "port" and "target" (also referred to as name).
|
|
|
90 |
* The target may be an empty host name string if the service is decidedly
|
|
|
91 |
* not available. If a response message contains multiple records of this
|
|
|
92 |
* type, targets should be sorted by priority (lowest first) and selected
|
|
|
93 |
* randomly according to their weight - this is left up to consumers of
|
|
|
94 |
* this library, see also [RFC 2782](https://tools.ietf.org/html/rfc2782)
|
|
|
95 |
* for more details.
|
|
|
96 |
*
|
|
|
97 |
* - SSHFP:
|
|
|
98 |
* Includes algorithm (UNIT8), fingerprint type (UNIT8) and fingerprint
|
|
|
99 |
* value as lower case hex string, for example:
|
|
|
100 |
* `{"algorithm":1,"type":1,"fingerprint":"0123456789abcdef..."}`
|
|
|
101 |
* See also https://www.iana.org/assignments/dns-sshfp-rr-parameters/dns-sshfp-rr-parameters.xhtml
|
|
|
102 |
* for algorithm and fingerprint type assignments.
|
|
|
103 |
*
|
|
|
104 |
* - SOA:
|
|
|
105 |
* Includes master hostname without trailing dot, responsible person email
|
|
|
106 |
* as hostname without trailing dot and serial, refresh, retry, expire and
|
|
|
107 |
* minimum times in seconds (UINT32 each), for example:
|
|
|
108 |
* `{"mname":"ns.example.com","rname":"hostmaster.example.com","serial":
|
|
|
109 |
* 2018082601,"refresh":3600,"retry":1800,"expire":60000,"minimum":3600}`.
|
|
|
110 |
*
|
|
|
111 |
* - CAA:
|
|
|
112 |
* Includes flag (UNIT8), tag string and value string, for example:
|
|
|
113 |
* `{"flag":128,"tag":"issue","value":"letsencrypt.org"}`
|
|
|
114 |
*
|
|
|
115 |
* - OPT:
|
|
|
116 |
* Special pseudo-type for EDNS0. Includes an array of additional opt codes
|
|
|
117 |
* with a value according to the respective OPT code. See `Message::OPT_*`
|
|
|
118 |
* for list of supported OPT codes. Any other OPT code not currently
|
|
|
119 |
* supported will be an opaque binary string containing the raw data
|
|
|
120 |
* as transported in the DNS record. For forwards compatibility, you should
|
|
|
121 |
* not rely on this format for unknown types. Future versions may add
|
|
|
122 |
* support for new types and this may then parse the payload data
|
|
|
123 |
* appropriately - this will not be considered a BC break. See also
|
|
|
124 |
* [RFC 6891](https://tools.ietf.org/html/rfc6891) for more details.
|
|
|
125 |
*
|
|
|
126 |
* - Any other unknown type:
|
|
|
127 |
* An opaque binary string containing the RDATA as transported in the DNS
|
|
|
128 |
* record. For forwards compatibility, you should not rely on this format
|
|
|
129 |
* for unknown types. Future versions may add support for new types and
|
|
|
130 |
* this may then parse the payload data appropriately - this will not be
|
|
|
131 |
* considered a BC break. See the format definition of known types above
|
|
|
132 |
* for more details.
|
|
|
133 |
*
|
|
|
134 |
* @var string|string[]|array
|
|
|
135 |
*/
|
|
|
136 |
public $data;
|
|
|
137 |
|
|
|
138 |
/**
|
|
|
139 |
* @param string $name
|
|
|
140 |
* @param int $type
|
|
|
141 |
* @param int $class
|
|
|
142 |
* @param int $ttl
|
|
|
143 |
* @param string|string[]|array $data
|
|
|
144 |
*/
|
|
|
145 |
public function __construct($name, $type, $class, $ttl, $data)
|
|
|
146 |
{
|
|
|
147 |
$this->name = $name;
|
|
|
148 |
$this->type = $type;
|
|
|
149 |
$this->class = $class;
|
|
|
150 |
$this->ttl = $ttl;
|
|
|
151 |
$this->data = $data;
|
|
|
152 |
}
|
|
|
153 |
}
|