aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Enderlin <ivan.enderlin@hoa-project.net>2012-11-28 16:09:31 +0100
committerIvan Enderlin <ivan.enderlin@hoa-project.net>2012-11-28 16:09:31 +0100
commitfee96cab01cbd8edf3de70e0210e8963ddac5655 (patch)
treede698494793837190ff885abb90cea075fc07336
parente05f89dd2e45c3af0147c782a078b346d9cea671 (diff)
downloadDns-fee96cab01cbd8edf3de70e0210e8963ddac5655.zip
Dns-fee96cab01cbd8edf3de70e0210e8963ddac5655.tar.gz
Dns-fee96cab01cbd8edf3de70e0210e8963ddac5655.tar.bz2
Add RFC references and CLASS support.
The CLASS is now accessible in event through the 'class' key.
-rw-r--r--Dns.php108
1 files changed, 74 insertions, 34 deletions
diff --git a/Dns.php b/Dns.php
index ad6f03f..490f776 100644
--- a/Dns.php
+++ b/Dns.php
@@ -51,7 +51,7 @@ namespace Hoa\Dns {
* Class \Hoa\Dns.
*
* Provide a tiny and very simple DNS server.
- * Please, see RFC6195.
+ * Please, see RFC6195, RFC1035 and RFC1034 for an overview.
*
* @author Ivan Enderlin <ivan.enderlin@hoa-project.net>
* @copyright Copyright © 2007-2012 Ivan Enderlin.
@@ -65,87 +65,117 @@ class Dns implements \Hoa\Core\Event\Listenable {
*
* @var \Hoa\Core\Event\Listener object
*/
- protected $_on = null;
+ protected $_on = null;
/**
* Socket.
*
* @var \Hoa\Socket object
*/
- protected $_server = null;
+ protected $_server = null;
/**
* Type values for resources and queries.
*
* @var \Hoa\Dns\Light array
*/
- protected static $_types = array(
- 'invalid' => 0, // Cookie.
+ protected static $_types = array(
+ 'invalid' => 0, // Invalid.
+ // <RFC1035>
'a' => 1, // Host address.
- 'ns' => 2, // Authorative server.
- 'md' => 3, // Mail destinaion.
- 'mf' => 4, // Mail forwarder.
- 'cname' => 5, // Canonical name.
- 'soa' => 6, // Start of authority zone.
+ 'ns' => 2, // Authorative name server.
+ 'md' => 3, // Mail destination (obsolete, use MX).
+ 'mf' => 4, // Mail forwarder (obsolete, use MX).
+ 'cname' => 5, // Canonical name for an alias.
+ 'soa' => 6, // Start of a zone of authority.
'mb' => 7, // Mailbox domain name.
'mg' => 8, // Mail group member.
'mr' => 9, // Mail rename name.
'null' => 10, // Null resource record.
- 'wks' => 11, // Well known service.
+ 'wks' => 11, // Well known service description.
'ptr' => 12, // Domain name pointer.
'hinfo' => 13, // Host information.
- 'minfo' => 14, // Mailbox information.
- 'mx' => 15, // Mail routing information.
+ 'minfo' => 14, // Mailbox or mail list information.
+ 'mx' => 15, // Mail exchange.
'txt' => 16, // Text strings.
+ // </RFC1035>
+ // <RFC1183>
'rp' => 17, // Responsible person.
'afsdb' => 18, // AFS cell database.
'x25' => 19, // X_25 calling address.
'isdn' => 20, // ISDN calling address.
- 'rt' => 21, // Router.
+ 'rt' => 21, // Route through resource record.
+ // </RFC1183>
+ // <RFC1348>
'nsap' => 22, // NSAP address.
- 'ns_nsap_ptr' => 23, // Reverse NSAP lookup (deprecated)
+ 'ns_nsap_ptr' => 23, // Reverse NSAP lookup (deprecated).
+ // </RFC1348>
+ // <RFC2065>
'sig' => 24, // Security signature.
- 'key' => 25, // Security key.
+ 'key' => 25, // Security key resource record.
+ // </RFC2065>
'px' => 26, // X.400 mail mapping.
'gpos' => 27, // Geographical position (withdrawn).
'aaaa' => 28, // IPv6 Address.
'loc' => 29, // Location Information.
- 'nxt' => 30, // Next domain (security)
+ // <RFC2065>
+ 'nxt' => 30, // Next domain.
+ // </RFC2065>
'eid' => 31, // Endpoint identifier.
'nimloc' => 32, // Nimrod Locator.
'srv' => 33, // Server Selection.
- 'atma' => 34, // ATM Address
- 'naptr' => 35, // Naming Authority PoinTeR
- 'kx' => 36, // Key Exchange
- 'cert' => 37, // Certification Record
- 'a6' => 38, // IPv6 Address (deprecated, use aaaa)
- 'dname' => 39, // Non-terminal DNAME (for IPv6)
- 'sink' => 40, // Kitchen sink (experimental)
- 'opt' => 41, // EDNS0 option (meta-RR)
- 'apl' => 42, // Address prefix list (RFC3123)
+ 'atma' => 34, // ATM Address.
+ 'naptr' => 35, // Naming Authority pointer.
+ 'kx' => 36, // Key Exchange.
+ 'cert' => 37, // Certification Record.
+ 'a6' => 38, // IPv6 Address (obsolete, use aaaa).
+ 'dname' => 39, // Non-terminal DNAME (for IPv6).
+ 'sink' => 40, // Kitchen sink.
+ 'opt' => 41, // EDNS0 option (meta-RR).
+ // <RFC3123>
+ 'apl' => 42, // Address prefix list.
+ // </RFC3123>
'ds' => 43, // Delegation Signer
'sshfp' => 44, // SSH Fingerprint
'ipseckey' => 45, // IPSEC Key
'rrsig' => 46, // RRSet Signature
'nsec' => 47, // Negative Security
'dnskey' => 48, // DNS Key
- 'dhcid' => 49, // Dynamic host configuartion identifier
+ 'dhcid' => 49, // Dynamic host configuration identifier
'nsec3' => 50, // Negative security type 3
'nsec3param' => 51, // Negative security type 3 parameters
'hip' => 55, // Host Identity Protocol
'spf' => 99, // Sender Policy Framework
'tkey' => 249, // Transaction key
+ // <RFC2845>
'tsig' => 250, // Transaction signature.
+ // </RFC2845>
'ixfr' => 251, // Incremental zone transfer.
+ // <RFC5936>
'axfr' => 252, // Transfer zone of authority.
'mailb' => 253, // Transfer mailbox records.
'maila' => 254, // Transfer mail agent records.
+ // </RFC5936>
'any' => 255, // Wildcard match.
'zxfr' => 256, // BIND-specific, nonstandard.
'dlv' => 32769, // DNSSEC look-aside validation.
'max' => 65536
);
+ /**
+ * Class values for resources and queries.
+ *
+ * @var \Hoa\Dns\Light array
+ */
+ protected static $_classes = array(
+ 'in' => 1, // Internet.
+ 'dc' => 2, // Data class.
+ 'ch' => 3, // Chaos.
+ 'hs' => 4, // Hesiod.
+ 'qnone' => 254, // QClass none.
+ 'qany' => 255 // QClass any.
+ );
+
/**
@@ -212,19 +242,29 @@ class Dns implements \Hoa\Core\Event\Listenable {
if(0 === $length = ord($handle[$i]))
break;
- $domain .= substr($handle, $i + 1, $length) . '.';
+ if(null !== $domain)
+ $domain .= '.';
+
+ $domain .= substr($handle, $i + 1, $length);
$i += $length;
}
+ $i += 2;
+ $type = array_search(
+ $_ = (int) (string) ord($handle[$i] + $handle[$i + 1]),
+ static::$_types
+ ) ?: $_;
+
$i += 2;
- $type = array_search(
- (int) (string) ord($handle[$i]),
- self::$_types
- );
- $domain = substr($domain, 0, -1);
+ $class = array_search(
+ $_ = (int) (string) ord($handle[$i]),
+ static::$_classes
+ ) ?: $_;
+
$ips = $this->_on->fire('query', new \Hoa\Core\Event\Bucket(array(
'domain' => $domain,
- 'type' => $type
+ 'type' => $type,
+ 'class' => $class
)));
$ip = null;