odhcp-script: unique subdirectory names for each parsed address

This commit is contained in:
Daniel Barlow 2023-09-10 12:15:34 +01:00
parent 22275f311c
commit 3ff55d3aad
2 changed files with 25 additions and 16 deletions

View file

@ -1,20 +1,20 @@
./address/2001-8b0-1111-1111-0-ffff-1234-5678/address:2001:8b0:1111:1111:0:ffff:1234:5678 ./address/2001-8b0-1111-1111-0-ffff-1234-5678_BVG8Gro50UM/address:2001:8b0:1111:1111:0:ffff:1234:5678
./address/2001-8b0-1111-1111-0-ffff-1234-5678/len:128 ./address/2001-8b0-1111-1111-0-ffff-1234-5678_BVG8Gro50UM/len:128
./address/2001-8b0-1111-1111-0-ffff-1234-5678/preferred:3600 ./address/2001-8b0-1111-1111-0-ffff-1234-5678_BVG8Gro50UM/preferred:3600
./address/2001-8b0-1111-1111-0-ffff-1234-5678/valid:7200 ./address/2001-8b0-1111-1111-0-ffff-1234-5678_BVG8Gro50UM/valid:7200
./addresses:2001:8b0:1111:1111:0:ffff:1234:5678/128,3600,7200 ./addresses:2001:8b0:1111:1111:0:ffff:1234:5678/128,3600,7200
./ifname:ppp0 ./ifname:ppp0
./option_1:000300018cfdf02420eb ./option_1:000300018cfdf02420eb
./option_2:000300010df0feca0df0 ./option_2:000300010df0feca0df0
./passthru:00170020200108b0000000000000000000002020200108b0000000000000000000002021 ./passthru:00170020200108b0000000000000000000002020200108b0000000000000000000002021
./prefix/2001-8b0-de3a-22/address:2001:8b0:de3a:22:: ./prefix/2001-8b0-de3a-22_hiaEztRS00M/address:2001:8b0:de3a:22::
./prefix/2001-8b0-de3a-22/len:64 ./prefix/2001-8b0-de3a-22_hiaEztRS00M/len:64
./prefix/2001-8b0-de3a-22/preferred:7200 ./prefix/2001-8b0-de3a-22_hiaEztRS00M/preferred:7200
./prefix/2001-8b0-de3a-22/valid:7200 ./prefix/2001-8b0-de3a-22_hiaEztRS00M/valid:7200
./prefix/2001-8b0-de3a-abcd/address:2001:8b0:de3a:abcd:: ./prefix/2001-8b0-de3a-abcd_HmTdEWrIMEM/address:2001:8b0:de3a:abcd::
./prefix/2001-8b0-de3a-abcd/len:64 ./prefix/2001-8b0-de3a-abcd_HmTdEWrIMEM/len:64
./prefix/2001-8b0-de3a-abcd/preferred:7200 ./prefix/2001-8b0-de3a-abcd_HmTdEWrIMEM/preferred:7200
./prefix/2001-8b0-de3a-abcd/valid:7200 ./prefix/2001-8b0-de3a-abcd_HmTdEWrIMEM/valid:7200
./prefixes:2001:8b0:de3a:abcd::/64,7200,7200 2001:8b0:de3a:22::/64,7200,7200 ./prefixes:2001:8b0:de3a:abcd::/64,7200,7200 2001:8b0:de3a:22::/64,7200,7200
./ra_hoplimit:64 ./ra_hoplimit:64
./ra_mtu:0 ./ra_mtu:0

View file

@ -1,4 +1,4 @@
(local { : split : merge } (require :anoia)) (local { : split : merge : hash : base64url } (require :anoia))
(local { : view } (require :fennel)) (local { : view } (require :fennel))
(local { : mktree : rmtree } (require :anoia.fs)) (local { : mktree : rmtree } (require :anoia.fs))
@ -26,9 +26,18 @@
(fn write-addresses [prefix addresses] (fn write-addresses [prefix addresses]
(each [_ a (ipairs (split " " addresses))] (each [_ a (ipairs (split " " addresses))]
(let [address (parse-address a) (let [address (parse-address a)
keydir (.. prefix (-> address.address suffix (base64url (string.pack "n" (hash a)))
(: :gsub "::$" "") ;; keydir should be a function of all the address
(: :gsub ":" "-")))] ;; attributes: we want it to change whenever anything changes
;; so that clients can see which addresses are new without
;; deep table comparisons
keydir (..
prefix
(-> address.address
(: :gsub "::$" "")
(: :gsub ":" "-"))
"_"
suffix)]
(mktree (.. state-directory "/" keydir)) (mktree (.. state-directory "/" keydir))
(each [k v (pairs address)] (each [k v (pairs address)]
(write-value (.. keydir "/" k) v))))) (write-value (.. keydir "/" k) v)))))