diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2021-06-30 23:03:57 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2021-07-06 21:18:26 -0700 |
commit | 02b20379584ab4467276e00fed34e879587525e5 (patch) | |
tree | 60b4ae9d6ce3b9b839b4d884a30eaf4ac483939b /src/util.lisp | |
parent | 79f5ffa705299b06e8e4848d6d4cff342e171cd9 (diff) | |
download | consfigurator-02b20379584ab4467276e00fed34e879587525e5.tar.gz |
add NETWORK:{CLEAN-/ETC/NETWORK/INTERFACES,PRESERVE-STATIC-ONCE}
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
Diffstat (limited to 'src/util.lisp')
-rw-r--r-- | src/util.lisp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/util.lisp b/src/util.lisp index 74aea8d..73810ae 100644 --- a/src/util.lisp +++ b/src/util.lisp @@ -266,6 +266,37 @@ expansion as a starting point for your own DEFPACKAGE form for your consfig." (declare (ignore ,ignore) ,@declarations) ,@forms)))) +(defun parse-cidr (address-with-suffix) + (destructuring-bind (address cidr) + (split-string address-with-suffix :separator "/") + (unless cidr + (simple-program-error "~A is not in CIDR notation." + address-with-suffix)) + (values + address + (loop with cidr = (parse-integer cidr) + with type = (if (or (> cidr 32) (find #\: address)) 6 4) + with block-digits = (if (= type 4) 8 16) + repeat (if (= type 4) 4 8) + for digits = (min cidr block-digits) + do (decf cidr digits) + collect (parse-integer + (with-output-to-string (s) + (loop repeat digits do (princ #\1 s)) + (loop repeat (- block-digits digits) do (princ #\0 s))) + :radix 2) + into accum + finally (return (if (= type 4) + (format nil "~{~D~^.~}" accum) + (with-output-to-string (s) + (loop for blocks on accum + if (> (car blocks) 0) + do (format s "~X" (car blocks)) + and if (cdr blocks) do (princ #\: s) + end + else do (princ #\: s) + (loop-finish))))))))) + ;;;; Progress & debug printing |