about summary refs log tree commit diff
path: root/lisp
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2020-01-26T20·29+0000
committerVincent Ambo <tazjin@google.com>2020-01-26T20·29+0000
commit4c109f66b6c1a859ca7b96954e13883e38751350 (patch)
tree93cbe515b34cc01bf03c34c6025484c755af4675 /lisp
parent72abb43577e3c80acf6dfaab4a3de080476e8803 (diff)
feat(lisp/dns): Introduce enum for DNS types & decode RDATA
Adds some of the most common DNS types in the enum (others TBD), and
starts decoding RDATA for TXT and A.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/dns/message.lisp23
1 files changed, 21 insertions, 2 deletions
diff --git a/lisp/dns/message.lisp b/lisp/dns/message.lisp
index 0eedbe6601..137532b748 100644
--- a/lisp/dns/message.lisp
+++ b/lisp/dns/message.lisp
@@ -662,6 +662,21 @@
 ;; 4.1.3. Resource record format
 
 (defbinary dns-rr (:byte-order :big-endian)
+(define-enum dns-type 2
+    (:byte-order :big-endian)
+
+    ;; http://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml
+    (A 1)
+    (NS 2)
+    (CNAME 5)
+    (SOA 6)
+    (PTR 12)
+    (MX 15)
+    (TXT 16)
+    (SRV 33)
+    (AAAA 28)
+    (ANY  255)) ;; (typically wants SOA, MX, NS and MX)
+
            (name nil :type (custom :lisp-type qname
                                    :reader #'read-qname
                                    :writer #'write-qname))
@@ -669,7 +684,7 @@
            ;; two octets containing one of the RR type codes. This
            ;; field specifies the meaning of the data in the RDATA
            ;; field.
-           (type 0 :type 16)            ; TODO(tazjin): enum?
+           (type 0 :type dns-type)
 
            ;; two octets which specify the class of the data in the
            ;; RDATA field.
@@ -691,7 +706,11 @@
            ;; according to the TYPE and CLASS of the resource record.
            ;; For example, the if the TYPE is A and the CLASS is IN,
            ;; the RDATA field is a 4 octet ARPA Internet address.
-           (rdata #() :type (simple-array (unsigned-byte 8) (rdlength))))
+           (rdata #() :type (eval (case type
+                                    ;; TODO(tazjin): Deal with multiple strings in single RRDATA
+                                    ((TXT) '(counted-string 1))
+                                    ((A) '(simple-array (unsigned-byte 8) (4)))
+                                    (otherwise `(simple-array (unsigned-byte 8) (,rdlength)))))))
 
 (defbinary dns-message (:byte-order :big-endian)
            (header nil :type dns-header)