Refactor to have a local dns request type

This commit is contained in:
Niten 2020-12-02 16:07:06 -08:00
parent 84ab618b6c
commit 3aad2b6a87
1 changed files with 33 additions and 30 deletions

View File

@ -12,6 +12,24 @@
(defun symbolize (str) (-> str string-upcase (intern :KEYWORD)))
(defclass dns-request ()
((hostname :initarg :hostname)
(domain :initarg :domain)
(sender :initarg :sender)
(msg-id :initarg :msg-id)))
(defclass request-change-ipv4 (dns-request)
((ip-address :initarg :ip-address)))
(defclass request-change-ipv6 (dns-request)
((ip-address :initarg :ip-address)))
(defclass request-change-sshfp (dns-request)
((sshfp :initarg :sshfp)))
(defclass unknown-dns-request (dns-request)
((request-type :initarg :request-type)))
(defclass dns-record ()
((id :col-type integer
:col-identity t
@ -50,21 +68,6 @@
(:table-name domains)
(:keys id))
(defclass change-request-ipv4 (request)
((hostname :initarg :hostname)
(domain :initarg :domain)
(ip-address :initarg :ip-address)))
(defclass change-request-ipv6 (request)
((hostname :initarg :hostname)
(domain :initarg :domain)
(ip-address :initarg :ip-address)))
(defclass change-request-sshfp (request)
((hostname :initarg :hostname)
(domain :initarg :domain)
(sshfp :initarg :sshfp)))
(defparameter *hostname-rx*
"(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])")
@ -170,7 +173,7 @@
(hostname-extractor-rx sender)
hostname)))
(defmethod handle-message ((message change-request-sshfp))
(defmethod backplane-server:handle-message ((message request-change-sshfp))
(with-slots (hostname domain sshfp msg-id) message
(if (not (listp sshfp))
(make-error :msg (format nil "expected list of sshfp records, got: ~A" sshfp)
@ -193,7 +196,7 @@
text)
:msg-id msg-id))))))
(defmethod handle-message ((message change-request-ipv4))
(defmethod backplane-server:handle-message ((message request-change-ipv4))
(with-slots (hostname domain ip-address msg-id) message
(handler-case
(progn (set-host-v4ip hostname domain ip-address)
@ -213,7 +216,7 @@
text)
:msg-id msg-id)))))
(defmethod handle-message ((message change-request-ipv6))
(defmethod backplane-server:handle-message ((message request-change-ipv6))
(with-slots (hostname domain ip-address msg-id) message
(handler-case
(progn (set-host-v6ip hostname domain ip-address)
@ -237,34 +240,34 @@
(:documentation "Parse a DNS service message of type REQUEST"))
(defmethod parse-dns-message (sender (request (eql :CHANGE_IPV4)) message msg-id)
(make-instance 'change-request-ipv4
:msg-id msg-id
(make-instance 'request-change-ipv4
:sender sender
:hostname (sender-hostname sender)
:domain (cdr (assoc :DOMAIN message))
:ip-address (cdr (assoc :IP message))))
:ip-address (cdr (assoc :IP message))
:msg-id msg-id))
(defmethod parse-dns-message (sender (request (eql :CHANGE_IPV6)) message msg-id)
(make-instance 'change-request-ipv6
:msg-id msg-id
(make-instance 'request-change-ipv6
:sender sender
:hostname (sender-hostname sender)
:domain (cdr (assoc :DOMAIN message))
:ip-address (cdr (assoc :IP message))))
:ip-address (cdr (assoc :IP message))
:msg-id msg-id))
(defmethod parse-dns-message (sender (request (eql :CHANGE_SSHFP)) message msg-id)
(make-instance 'change-request-sshfp
:msg-id msg-id
(make-instance 'request-change-sshfp
:sender sender
:hostname (sender-hostname sender)
:domain (cdr (assoc :DOMAIN message))
:sshfp (cdr (assoc :SSHFP message))))
:sshfp (cdr (assoc :SSHFP message))
:msg-id msg-id))
(defmethod parse-dns-message (sender request message msg-id)
(make-instance 'unknown-request
:msg-id msg-id
:sender sender
:request request))
:sender sender
:request-type request
:msg-id msg-id))
(defmethod backplane-server:parse-message (sender (service (eql :DNS)) api-version message msg-id)
(parse-dns-message sender (symbolize (cdr (assoc :REQUEST message))) message msg-id))