1<?php
2
3/**
4 * DNS Library for handling lookups and updates.
5 *
6 * Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
7 *
8 * See LICENSE for more details.
9 *
10 * @category  Networking
11 * @package   Net_DNS2
12 * @author    Mike Pultz <mike@mikepultz.com>
13 * @copyright 2020 Mike Pultz <mike@mikepultz.com>
14 * @license   http://www.opensource.org/licenses/bsd-license.php  BSD License
15 * @link      https://netdns2.com/
16 * @since     File available since Release 0.6.0
17 *
18 */
19
20//
21// initalize the packet id value
22//
23Net_DNS2_Lookups::$next_packet_id   = mt_rand(0, 65535);
24
25//
26// build the reverse lookup tables; this is just so we don't have to
27// have duplicate static content laying around.
28//
29Net_DNS2_Lookups::$rr_types_by_id       = array_flip(Net_DNS2_Lookups::$rr_types_by_name);
30Net_DNS2_Lookups::$classes_by_id        = array_flip(Net_DNS2_Lookups::$classes_by_name);
31Net_DNS2_Lookups::$rr_types_class_to_id = array_flip(Net_DNS2_Lookups::$rr_types_id_to_class);
32Net_DNS2_Lookups::$algorithm_name_to_id = array_flip(Net_DNS2_Lookups::$algorithm_id_to_name);
33Net_DNS2_Lookups::$digest_name_to_id    = array_flip(Net_DNS2_Lookups::$digest_id_to_name);
34Net_DNS2_Lookups::$rr_qtypes_by_id      = array_flip(Net_DNS2_Lookups::$rr_qtypes_by_name);
35Net_DNS2_Lookups::$rr_metatypes_by_id   = array_flip(Net_DNS2_Lookups::$rr_metatypes_by_name);
36Net_DNS2_Lookups::$protocol_by_id       = array_flip(Net_DNS2_Lookups::$protocol_by_name);
37
38/**
39 * This class provides simple lookups used througout the Net_DNS2 code
40 *
41 */
42class Net_DNS2_Lookups
43{
44    /*
45     * size (in bytes) of a header in a standard DNS packet
46     */
47    const DNS_HEADER_SIZE       = 12;
48
49    /*
50     * max size of a UDP packet
51     */
52    const DNS_MAX_UDP_SIZE      = 512;
53
54    /*
55     * Query/Response flag
56     */
57    const QR_QUERY              = 0;        // RFC 1035
58    const QR_RESPONSE           = 1;        // RFC 1035
59
60    /*
61     * DNS Op Codes
62     */
63    const OPCODE_QUERY          = 0;        // RFC 1035
64    const OPCODE_IQUERY         = 1;        // RFC 1035, RFC 3425
65    const OPCODE_STATUS         = 2;        // RFC 1035
66    const OPCODE_NOTIFY         = 4;        // RFC 1996
67    const OPCODE_UPDATE         = 5;        // RFC 2136
68    const OPCODE_DSO            = 6;        // RFC 8490
69
70    /*
71     * Resource Record Classes
72     */
73    const RR_CLASS_IN           = 1;        // RFC 1035
74    const RR_CLASS_CH           = 3;        // RFC 1035
75    const RR_CLASS_HS           = 4;        // RFC 1035
76    const RR_CLASS_NONE         = 254;      // RFC 2136
77    const RR_CLASS_ANY          = 255;      // RFC 1035
78
79    /*
80     * DNS Response Codes
81     */
82    const RCODE_NOERROR         = 0;        // RFC 1035
83    const RCODE_FORMERR         = 1;        // RFC 1035
84    const RCODE_SERVFAIL        = 2;        // RFC 1035
85    const RCODE_NXDOMAIN        = 3;        // RFC 1035
86    const RCODE_NOTIMP          = 4;        // RFC 1035
87    const RCODE_REFUSED         = 5;        // RFC 1035
88    const RCODE_YXDOMAIN        = 6;        // RFC 2136
89    const RCODE_YXRRSET         = 7;        // RFC 2136
90    const RCODE_NXRRSET         = 8;        // RFC 2136
91    const RCODE_NOTAUTH         = 9;        // RFC 2136
92    const RCODE_NOTZONE         = 10;       // RFC 2136
93    const RCODE_DSOTYPENI       = 11;       // RFC 8490
94
95    // 12-15 reserved
96
97    const RCODE_BADSIG          = 16;       // RFC 2845
98    const RCODE_BADVERS         = 16;       // RFC 6891
99    const RCODE_BADKEY          = 17;       // RFC 2845
100    const RCODE_BADTIME         = 18;       // RFC 2845
101    const RCODE_BADMODE         = 19;       // RFC 2930
102    const RCODE_BADNAME         = 20;       // RFC 2930
103    const RCODE_BADALG          = 21;       // RFC 2930
104    const RCODE_BADTRUNC        = 22;       // RFC 4635
105    const RCODE_BADCOOKIE       = 23;       // RFC 7873
106
107    /*
108     * internal errors codes returned by the exceptions class
109     */
110    const E_NONE                = 0;
111    const E_DNS_FORMERR         = self::RCODE_FORMERR;
112    const E_DNS_SERVFAIL        = self::RCODE_SERVFAIL;
113    const E_DNS_NXDOMAIN        = self::RCODE_NXDOMAIN;
114    const E_DNS_NOTIMP          = self::RCODE_NOTIMP;
115    const E_DNS_REFUSED         = self::RCODE_REFUSED;
116    const E_DNS_YXDOMAIN        = self::RCODE_YXDOMAIN;
117    const E_DNS_YXRRSET         = self::RCODE_YXRRSET;
118    const E_DNS_NXRRSET         = self::RCODE_NXRRSET;
119    const E_DNS_NOTAUTH         = self::RCODE_NOTAUTH;
120    const E_DNS_NOTZONE         = self::RCODE_NOTZONE;
121
122    // 11-15 reserved
123
124    const E_DNS_BADSIG          = self::RCODE_BADSIG;
125    const E_DNS_BADKEY          = self::RCODE_BADKEY;
126    const E_DNS_BADTIME         = self::RCODE_BADTIME;
127    const E_DNS_BADMODE         = self::RCODE_BADMODE;
128    const E_DNS_BADNAME         = self::RCODE_BADNAME;
129    const E_DNS_BADALG          = self::RCODE_BADALG;
130    const E_DNS_BADTRUNC        = self::RCODE_BADTRUNC;
131    const E_DNS_BADCOOKIE       = self::RCODE_BADCOOKIE;
132
133    // other error conditions
134
135    const E_NS_INVALID_FILE     = 200;
136    const E_NS_INVALID_ENTRY    = 201;
137    const E_NS_FAILED           = 202;
138    const E_NS_SOCKET_FAILED    = 203;
139    const E_NS_INVALID_SOCKET   = 204;
140
141    const E_PACKET_INVALID      = 300;
142    const E_PARSE_ERROR         = 301;
143    const E_HEADER_INVALID      = 302;
144    const E_QUESTION_INVALID    = 303;
145    const E_RR_INVALID          = 304;
146
147    const E_OPENSSL_ERROR       = 400;
148    const E_OPENSSL_UNAVAIL     = 401;
149    const E_OPENSSL_INV_PKEY    = 402;
150    const E_OPENSSL_INV_ALGO    = 403;
151
152    const E_CACHE_UNSUPPORTED   = 500;
153    const E_CACHE_SHM_FILE      = 501;
154    const E_CACHE_SHM_UNAVAIL   = 502;
155
156    /*
157     * EDNS0 Option Codes (OPT)
158     */
159    // 0 - Reserved
160    const EDNS0_OPT_LLQ             = 1;
161    const EDNS0_OPT_UL              = 2;
162    const EDNS0_OPT_NSID            = 3;
163    // 4 - Reserved
164    const EDNS0_OPT_DAU             = 5;
165    const EDNS0_OPT_DHU             = 6;
166    const EDNS0_OPT_N3U             = 7;
167    const EDNS0_OPT_CLIENT_SUBNET   = 8;
168    const EDNS0_OPT_EXPIRE          = 9;
169    const EDNS0_OPT_COOKIE          = 10;
170    const EDNS0_OPT_TCP_KEEPALIVE   = 11;
171    const EDNS0_OPT_PADDING         = 12;
172    const EDNS0_OPT_CHAIN           = 13;
173    const EDNS0_OPT_KEY_TAG         = 14;
174    // 15 - unsassigned
175    const EDNS0_OPT_CLIENT_TAG      = 16;
176    const EDNS0_OPT_SERVER_TAG      = 17;
177    // 18-26945 - unassigned
178    const EDNS0_OPT_DEVICEID        = 26946;
179
180    /*
181     * DNSSEC Algorithms
182     */
183    const DNSSEC_ALGORITHM_RES                  = 0;
184    const DNSSEC_ALGORITHM_RSAMD5               = 1;
185    const DNSSEC_ALGORITHM_DH                   = 2;
186    const DNSSEC_ALGORITHM_DSA                  = 3;
187    const DNSSEC_ALGORITHM_ECC                  = 4;
188    const DNSSEC_ALGORITHM_RSASHA1              = 5;
189    const DNSSEC_ALGORITHM_DSANSEC3SHA1         = 6;
190    const DSNSEC_ALGORITHM_RSASHA1NSEC3SHA1     = 7;
191    const DNSSEC_ALGORITHM_RSASHA256	        = 8;
192    const DNSSEC_ALGORITHM_RSASHA512            = 10;
193    const DNSSEC_ALGORITHM_ECCGOST              = 12;
194    const DNSSEC_ALGORITHM_ECDSAP256SHA256      = 13;
195    const DNSSEC_ALGORITHM_ECDSAP384SHA384      = 14;
196    const DNSSEC_ALGORITHM_ED25519              = 15;
197    const DNSSEC_ALGORITHM_ED448                = 16;
198    const DNSSEC_ALGORITHM_INDIRECT             = 252;
199    const DNSSEC_ALGORITHM_PRIVATEDNS           = 253;
200    const DNSSEC_ALGORITHM_PRIVATEOID           = 254;
201
202    /*
203     * DNSSEC Digest Types
204     */
205    const DNSSEC_DIGEST_RES                     = 0;
206    const DNSSEC_DIGEST_SHA1                    = 1;
207    const DNSSEC_DIGEST_SHA256                  = 2;
208    const DNSSEC_DIGEST_GOST                    = 3;
209    const DNSSEC_DIGEST_SHA384                  = 4;
210
211    /*
212     * The packet id used when sending requests
213     */
214    public static $next_packet_id;
215
216    /*
217     * Used to map resource record types to their id's, and back
218     */
219    public static $rr_types_by_id   = [];
220    public static $rr_types_by_name = [
221
222        'SIG0'          => 0,       // RFC 2931 pseudo type
223        'A'             => 1,       // RFC 1035
224        'NS'            => 2,       // RFC 1035
225        'MD'            => 3,       // RFC 1035 - obsolete, Not implemented
226        'MF'            => 4,       // RFC 1035 - obsolete, Not implemented
227        'CNAME'         => 5,       // RFC 1035
228        'SOA'           => 6,       // RFC 1035
229        'MB'            => 7,       // RFC 1035 - obsolete, Not implemented
230        'MG'            => 8,       // RFC 1035 - obsolete, Not implemented
231        'MR'            => 9,       // RFC 1035 - obsolete, Not implemented
232        'NULL'          => 10,      // RFC 1035 - obsolete, Not implemented
233        'WKS'           => 11,      // RFC 1035
234        'PTR'           => 12,      // RFC 1035
235        'HINFO'         => 13,      // RFC 1035
236        'MINFO'         => 14,      // RFC 1035 - obsolete, Not implemented
237        'MX'            => 15,      // RFC 1035
238        'TXT'           => 16,      // RFC 1035
239        'RP'            => 17,      // RFC 1183
240        'AFSDB'         => 18,      // RFC 1183
241        'X25'           => 19,      // RFC 1183
242        'ISDN'          => 20,      // RFC 1183
243        'RT'            => 21,      // RFC 1183
244        'NSAP'          => 22,      // RFC 1706
245        'NSAP_PTR'      => 23,      // RFC 1348 - obsolete, Not implemented
246        'SIG'           => 24,      // RFC 2535
247        'KEY'           => 25,      // RFC 2535, RFC 2930
248        'PX'            => 26,      // RFC 2163
249        'GPOS'          => 27,      // RFC 1712 - Not implemented
250        'AAAA'          => 28,      // RFC 3596
251        'LOC'           => 29,      // RFC 1876
252        'NXT'           => 30,      // RFC 2065, obsoleted by by RFC 3755
253        'EID'           => 31,      // [Patton][Patton1995]
254        'NIMLOC'        => 32,      // [Patton][Patton1995]
255        'SRV'           => 33,      // RFC 2782
256        'ATMA'          => 34,      // Windows only
257        'NAPTR'         => 35,      // RFC 2915
258        'KX'            => 36,      // RFC 2230
259        'CERT'          => 37,      // RFC 4398
260        'A6'            => 38,      // downgraded to experimental by RFC 3363
261        'DNAME'         => 39,      // RFC 2672
262        'SINK'          => 40,      // Not implemented
263        'OPT'           => 41,      // RFC 2671
264        'APL'           => 42,      // RFC 3123
265        'DS'            => 43,      // RFC 4034
266        'SSHFP'         => 44,      // RFC 4255
267        'IPSECKEY'      => 45,      // RFC 4025
268        'RRSIG'         => 46,      // RFC 4034
269        'NSEC'          => 47,      // RFC 4034
270        'DNSKEY'        => 48,      // RFC 4034
271        'DHCID'         => 49,      // RFC 4701
272        'NSEC3'         => 50,      // RFC 5155
273        'NSEC3PARAM'    => 51,      // RFC 5155
274        'TLSA'          => 52,      // RFC 6698
275        'SMIMEA'        => 53,      // RFC 8162
276
277                                    // 54 unassigned
278
279        'HIP'           => 55,      // RFC 5205
280        'NINFO'         => 56,      // Not implemented
281        'RKEY'          => 57,      // Not implemented
282        'TALINK'        => 58,      //
283        'CDS'           => 59,      // RFC 7344
284        'CDNSKEY'       => 60,      // RFC 7344
285        'OPENPGPKEY'    => 61,      // RFC 7929
286        'CSYNC'         => 62,      // RFC 7477
287        'ZONEMD'        => 63,      // Not implemented yet
288        'SVCB'          => 64,      // Not implemented yet
289        'HTTPS'         => 65,      // Not implemented yet
290
291                                    // 66 - 98 unassigned
292
293        'SPF'           => 99,      // RFC 4408
294        'UINFO'         => 100,     // no RFC, Not implemented
295        'UID'           => 101,     // no RFC, Not implemented
296        'GID'           => 102,     // no RFC, Not implemented
297        'UNSPEC'        => 103,     // no RFC, Not implemented
298        'NID'           => 104,     // RFC 6742
299        'L32'           => 105,     // RFC 6742
300        'L64'           => 106,     // RFC 6742
301        'LP'            => 107,     // RFC 6742
302        'EUI48'         => 108,     // RFC 7043
303        'EUI64'         => 109,     // RFC 7043
304
305                                    // 110 - 248 unassigned
306
307        'TKEY'          => 249,     // RFC 2930
308        'TSIG'          => 250,     // RFC 2845
309        'IXFR'          => 251,     // RFC 1995 - only a full (AXFR) is supported
310        'AXFR'          => 252,     // RFC 1035
311        'MAILB'         => 253,     // RFC 883, Not implemented
312        'MAILA'         => 254,     // RFC 973, Not implemented
313        'ANY'           => 255,     // RFC 1035 - we support both 'ANY' and '*'
314        'URI'           => 256,     // RFC 7553
315        'CAA'           => 257,     // RFC 8659
316        'AVC'           => 258,     // Application Visibility and Control
317        'DOA'           => 259,     // Not implemented yet
318        'AMTRELAY'      => 260,     // RFC 8777
319
320                                    // 261 - 32767 unassigned
321
322        'TA'            => 32768,   // same as DS
323        'DLV'           => 32769,   // RFC 4431
324        'TYPE65534'     => 65534    // Private Bind record
325    ];
326
327    /*
328     * Qtypes and Metatypes - defined in RFC2929 section 3.1
329     */
330    public static $rr_qtypes_by_id      = [];
331    public static $rr_qtypes_by_name    = [
332
333        'IXFR'          => 251,     // RFC 1995 - only a full (AXFR) is supported
334        'AXFR'          => 252,     // RFC 1035
335        'MAILB'         => 253,     // RFC 883, Not implemented
336        'MAILA'         => 254,     // RFC 973, Not implemented
337        'ANY'           => 255      // RFC 1035 - we support both 'ANY' and '*'
338    ];
339
340    public static $rr_metatypes_by_id   = [];
341    public static $rr_metatypes_by_name = [
342
343        'OPT'           => 41,      // RFC 2671
344        'TKEY'          => 249,     // RFC 2930
345        'TSIG'          => 250      // RFC 2845
346    ];
347
348    /*
349     * used to map resource record id's to RR class names
350     */
351    public static $rr_types_class_to_id = [];
352    public static $rr_types_id_to_class = [
353
354        1           => 'Net_DNS2_RR_A',
355        2           => 'Net_DNS2_RR_NS',
356        5           => 'Net_DNS2_RR_CNAME',
357        6           => 'Net_DNS2_RR_SOA',
358        11          => 'Net_DNS2_RR_WKS',
359        12          => 'Net_DNS2_RR_PTR',
360        13          => 'Net_DNS2_RR_HINFO',
361        15          => 'Net_DNS2_RR_MX',
362        16          => 'Net_DNS2_RR_TXT',
363        17          => 'Net_DNS2_RR_RP',
364        18          => 'Net_DNS2_RR_AFSDB',
365        19          => 'Net_DNS2_RR_X25',
366        20          => 'Net_DNS2_RR_ISDN',
367        21          => 'Net_DNS2_RR_RT',
368        22          => 'Net_DNS2_RR_NSAP',
369        24          => 'Net_DNS2_RR_SIG',
370        25          => 'Net_DNS2_RR_KEY',
371        26          => 'Net_DNS2_RR_PX',
372        28          => 'Net_DNS2_RR_AAAA',
373        29          => 'Net_DNS2_RR_LOC',
374        31          => 'Net_DNS2_RR_EID',
375        32          => 'Net_DNS2_RR_NIMLOC',
376        33          => 'Net_DNS2_RR_SRV',
377        34          => 'Net_DNS2_RR_ATMA',
378        35          => 'Net_DNS2_RR_NAPTR',
379        36          => 'Net_DNS2_RR_KX',
380        37          => 'Net_DNS2_RR_CERT',
381        39          => 'Net_DNS2_RR_DNAME',
382        41          => 'Net_DNS2_RR_OPT',
383        42          => 'Net_DNS2_RR_APL',
384        43          => 'Net_DNS2_RR_DS',
385        44          => 'Net_DNS2_RR_SSHFP',
386        45          => 'Net_DNS2_RR_IPSECKEY',
387        46          => 'Net_DNS2_RR_RRSIG',
388        47          => 'Net_DNS2_RR_NSEC',
389        48          => 'Net_DNS2_RR_DNSKEY',
390        49          => 'Net_DNS2_RR_DHCID',
391        50          => 'Net_DNS2_RR_NSEC3',
392        51          => 'Net_DNS2_RR_NSEC3PARAM',
393        52          => 'Net_DNS2_RR_TLSA',
394        53          => 'Net_DNS2_RR_SMIMEA',
395        55          => 'Net_DNS2_RR_HIP',
396        58          => 'Net_DNS2_RR_TALINK',
397        59          => 'Net_DNS2_RR_CDS',
398        60          => 'Net_DNS2_RR_CDNSKEY',
399        61          => 'Net_DNS2_RR_OPENPGPKEY',
400        62          => 'Net_DNS2_RR_CSYNC',
401        99          => 'Net_DNS2_RR_SPF',
402        104         => 'Net_DNS2_RR_NID',
403        105         => 'Net_DNS2_RR_L32',
404        106         => 'Net_DNS2_RR_L64',
405        107         => 'Net_DNS2_RR_LP',
406        108         => 'Net_DNS2_RR_EUI48',
407        109         => 'Net_DNS2_RR_EUI64',
408
409        249         => 'Net_DNS2_RR_TKEY',
410        250         => 'Net_DNS2_RR_TSIG',
411
412    //    251            - IXFR - handled as a full zone transfer (252)
413    //    252            - AXFR - handled as a function call
414
415        255         => 'Net_DNS2_RR_ANY',
416        256         => 'Net_DNS2_RR_URI',
417        257         => 'Net_DNS2_RR_CAA',
418        258         => 'Net_DNS2_RR_AVC',
419        260         => 'Net_DNS2_RR_AMTRELAY',
420        32768       => 'Net_DNS2_RR_TA',
421        32769       => 'Net_DNS2_RR_DLV',
422        65534       => 'Net_DNS2_RR_TYPE65534'
423    ];
424
425    /*
426     * used to map resource record class names to their id's, and back
427     */
428    public static $classes_by_id    = [];
429    public static $classes_by_name  = [
430
431        'IN'    => self::RR_CLASS_IN,        // RFC 1035
432        'CH'    => self::RR_CLASS_CH,        // RFC 1035
433        'HS'    => self::RR_CLASS_HS,        // RFC 1035
434        'NONE'  => self::RR_CLASS_NONE,      // RFC 2136
435        'ANY'   => self::RR_CLASS_ANY        // RFC 1035
436    ];
437
438    /*
439     * maps response codes to error messages
440     */
441    public static $result_code_messages = [
442
443        self::RCODE_NOERROR     => 'The request completed successfully.',
444        self::RCODE_FORMERR     => 'The name server was unable to interpret the query.',
445        self::RCODE_SERVFAIL    => 'The name server was unable to process this query due to a problem with the name server.',
446        self::RCODE_NXDOMAIN    => 'The domain name referenced in the query does not exist.',
447        self::RCODE_NOTIMP      => 'The name server does not support the requested kind of query.',
448        self::RCODE_REFUSED     => 'The name server refuses to perform the specified operation for policy reasons.',
449        self::RCODE_YXDOMAIN    => 'Name Exists when it should not.',
450        self::RCODE_YXRRSET     => 'RR Set Exists when it should not.',
451        self::RCODE_NXRRSET     => 'RR Set that should exist does not.',
452        self::RCODE_NOTAUTH     => 'Server Not Authoritative for zone.',
453        self::RCODE_NOTZONE     => 'Name not contained in zone.',
454
455        self::RCODE_BADSIG      => 'TSIG Signature Failure.',
456        self::RCODE_BADKEY      => 'Key not recognized.',
457        self::RCODE_BADTIME     => 'Signature out of time window.',
458        self::RCODE_BADMODE     => 'Bad TKEY Mode.',
459        self::RCODE_BADNAME     => 'Duplicate key name.',
460        self::RCODE_BADALG      => 'Algorithm not supported.',
461        self::RCODE_BADTRUNC    => 'Bad truncation.'
462    ];
463
464    /*
465     * maps DNS SEC alrorithms to their mnemonics
466     */
467    public static $algorithm_name_to_id = [];
468    public static $algorithm_id_to_name = [
469
470        self::DNSSEC_ALGORITHM_RES                  => 'RES',
471        self::DNSSEC_ALGORITHM_RSAMD5               => 'RSAMD5',
472        self::DNSSEC_ALGORITHM_DH                   => 'DH',
473        self::DNSSEC_ALGORITHM_DSA                  => 'DSA',
474        self::DNSSEC_ALGORITHM_ECC                  => 'ECC',
475        self::DNSSEC_ALGORITHM_RSASHA1              => 'RSASHA1',
476        self::DNSSEC_ALGORITHM_DSANSEC3SHA1         => 'DSA-NSEC3-SHA1',
477        self::DSNSEC_ALGORITHM_RSASHA1NSEC3SHA1     => 'RSASHA1-NSEC3-SHA1',
478        self::DNSSEC_ALGORITHM_RSASHA256            => 'RSASHA256',
479        self::DNSSEC_ALGORITHM_RSASHA512            => 'RSASHA512',
480        self::DNSSEC_ALGORITHM_ECCGOST              => 'ECC-GOST',
481        self::DNSSEC_ALGORITHM_ECDSAP256SHA256      => 'ECDSAP256SHA256',
482        self::DNSSEC_ALGORITHM_ECDSAP384SHA384      => 'ECDSAP384SHA384',
483        self::DNSSEC_ALGORITHM_ED25519              => 'ED25519',
484        self::DNSSEC_ALGORITHM_ED448                => 'ED448',
485        self::DNSSEC_ALGORITHM_INDIRECT             => 'INDIRECT',
486        self::DNSSEC_ALGORITHM_PRIVATEDNS           => 'PRIVATEDNS',
487        self::DNSSEC_ALGORITHM_PRIVATEOID           => 'PRIVATEOID'
488    ];
489
490    /*
491     * maps DNSSEC digest types to their mnemonics
492     */
493    public static $digest_name_to_id = [];
494    public static $digest_id_to_name = [
495
496        self::DNSSEC_DIGEST_RES         => 'RES',
497        self::DNSSEC_DIGEST_SHA1        => 'SHA-1',
498        self::DNSSEC_DIGEST_SHA256      => 'SHA-256',
499        self::DNSSEC_DIGEST_GOST        => 'GOST-R-34.11-94',
500        self::DNSSEC_DIGEST_SHA384      => 'SHA-384'
501    ];
502
503    /*
504     * Protocols names - RFC 1010
505     */
506    public static $protocol_by_id   = [];
507    public static $protocol_by_name = [
508
509        'ICMP'          => 1,
510        'IGMP'          => 2,
511        'GGP'           => 3,
512        'ST'            => 5,
513        'TCP'           => 6,
514        'UCL'           => 7,
515        'EGP'           => 8,
516        'IGP'           => 9,
517        'BBN-RCC-MON'   => 10,
518        'NVP-II'        => 11,
519        'PUP'           => 12,
520        'ARGUS'         => 13,
521        'EMCON'         => 14,
522        'XNET'          => 15,
523        'CHAOS'         => 16,
524        'UDP'           => 17,
525        'MUX'           => 18,
526        'DCN-MEAS'      => 19,
527        'HMP'           => 20,
528        'PRM'           => 21,
529        'XNS-IDP'       => 22,
530        'TRUNK-1'       => 23,
531        'TRUNK-2'       => 24,
532        'LEAF-1'        => 25,
533        'LEAF-2'        => 26,
534        'RDP'           => 27,
535        'IRTP'          => 28,
536        'ISO-TP4'       => 29,
537        'NETBLT'        => 30,
538        'MFE-NSP'       => 31,
539        'MERIT-INP'     => 32,
540        'SEP'           => 33,
541        // 34 - 60      - Unassigned
542        // 61           - any host internal protocol
543        'CFTP'          => 62,
544        // 63           - any local network
545        'SAT-EXPAK'     => 64,
546        'MIT-SUBNET'    => 65,
547        'RVD'           => 66,
548        'IPPC'          => 67,
549        // 68           - any distributed file system
550        'SAT-MON'       => 69,
551        // 70           - Unassigned
552        'IPCV'          => 71,
553        // 72 - 75      - Unassigned
554        'BR-SAT-MON'    => 76,
555        // 77           - Unassigned
556        'WB-MON'        => 78,
557        'WB-EXPAK'      => 79
558        // 80 - 254     - Unassigned
559        // 255          - Reserved
560    ];
561}
562