Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add SRV record support

  • Loading branch information...
commit b3358f46976ed067e01431733e75a43c4d167548 1 parent 4d1c573
Pixie authored committed
2  src/sockets/dns/common.lisp
View
@@ -14,7 +14,7 @@
(defconstant (+query-type-map+ :test 'equal)
'((:a . 1) (:ns . 2) (:cname . 5) (:soa . 6)
(:wks . 11) (:ptr . 12) (:hinfo . 13) (:mx . 15)
- (:txt . 16) (:aaaa . 28) (:any . 255)))
+ (:txt . 16) (:aaaa . 28) (:srv . 33) (:any . 255)))
(defun query-type-number (id)
(cdr (assoc id +query-type-map+)))
9 src/sockets/dns/message.lisp
View
@@ -379,6 +379,15 @@
(read-ub32 buffer))) ; MINIMUM
(defmethod read-rr-data ((buffer dynamic-buffer)
+ (type (eql :srv)) (class (eql :in))
+ resource-length)
+ (declare (ignore resource-length))
+ (list (read-ub16 buffer) ; PRIORITY
+ (read-ub16 buffer) ; WEIGHT
+ (read-ub16 buffer) ; PORT
+ (read-domain-name buffer))) ; TARGET
+
+(defmethod read-rr-data ((buffer dynamic-buffer)
(type (eql :txt)) (class (eql :in))
resource-length)
(declare (ignore type class))
15 src/sockets/dns/query.lisp
View
@@ -106,6 +106,15 @@
(cons preference
(subseq name 0 (1- (length name)))))))
+(defmethod %decode-rr ((rr dns-rr) (type (eql :srv)) class)
+ (declare (ignore class))
+ (destructuring-bind (priority weight port target) (dns-rr-data rr)
+ (list* (dns-rr-ttl rr)
+ priority
+ weight
+ port
+ (subseq target 0 (1- (length target))))))
+
(defun decode-rr (rr)
(%decode-rr rr (dns-record-type rr) (dns-record-class rr)))
@@ -186,6 +195,12 @@
(let ((rr (aref (dns-message-answer msg) 0)))
(decode-rr rr)))
+;; TODO: randomly choose between same priority by weight
+(defmethod %decode-response ((msg dns-message) (question-type (eql :srv)))
+ (declare (ignore question-type))
+ (let* ((decoded-rrs (map 'vector #'decode-rr (dns-message-answer msg))))
+ (aref (sort decoded-rrs #'< :key #'second) 0)))
+
(defmethod %decode-response ((msg dns-message) (question-type (eql :txt)))
(declare (ignore question-type))
(decode-rr (aref (dns-message-answer msg) 0)))
Please sign in to comment.
Something went wrong with that request. Please try again.