1
0

Compare commits

...

12 Commits

Author SHA1 Message Date
9dd3cf23b4 anoia.fs.mktree replaces mkdir
This uses lfs to make the tree in-process instead of
shelling out to the mkdir command
2023-09-08 21:17:42 +01:00
4e9227dff3 move rmtree to anoia library 2023-09-08 21:03:18 +01:00
eaa45906ff fennelrepl runs with --correlate
this is so that error message line numbers match up
2023-09-08 21:02:26 +01:00
7fc5d2934d set FENNEL_PATH using absolute paths 2023-09-08 21:01:39 +01:00
12e25722fa odhcp-script: delete stale dirs from previous runs
This requires adding LFS as a dependency because native Lua has
no way to iterate a directory, but it seems to be Not Huge and
hopefully we'll have other uses for it
2023-09-08 20:48:01 +01:00
09fe21260e rename fn 2023-09-08 20:48:01 +01:00
4bd3ccc8fd inline write-{addresses,prefixes} 2023-09-08 20:48:01 +01:00
3e163d4253 remove unused fn 2023-09-08 20:47:55 +01:00
9487cb2567 DRY near-duplicate code between parse-{addresses,prefixces} 2023-09-08 20:47:55 +01:00
907a9de773 update 2023-09-08 20:47:55 +01:00
b25103be2e test script for odhcp6-script 2023-09-08 20:47:55 +01:00
353a199ab2 odhcpc script: parse ADDRESSES and PREFIXES
so downstream doesn't have to
2023-09-05 22:42:25 +01:00
8 changed files with 184 additions and 6 deletions

View File

@ -2137,10 +2137,11 @@ Thu Aug 31 23:53:54 BST 2023
[done] - packet forwarding
- dhcp6 client
- what to do with acquire-{wan,lan} scripts?
- resolvconf
- [done] anything in vanilla-configuration ditto
- packet forwarding
- and arhcive
- rsync
- [not doing] rsync
- [done] watchdog
- [done] mount
- nftables syntax error
@ -2149,7 +2150,7 @@ Thu Aug 31 23:53:54 BST 2023
- [done] services for liminix.networking
- [done] write a blog entry
- [done] ntp is not setting the time
- static dhcp(6) lease support reqd for dogfooding
- [done] static dhcp(6) lease support reqd for dogfooding
Sat Sep 2 21:35:41 BST 2023
@ -2247,3 +2248,40 @@ I think we might rename wlan_24 to wlan and wlan_5 to wlan1.
This is on the assumption that almost no device is 5GHz only, so
would make it easier to write a basic wlan example that works
both on 2.4GHz boards and dual radio boards
Mon Sep 4 23:15:26 BST 2023
If dhcpcd parsed the update-script output into separate files, half
the complexity of acquire-lan-prefix would go away. The other half is
because it subscribes to changes in the outputs instead of just
running once. Perhaps there's a better way to do that?
Could separate prefixes and addresses something like this...
outputs/prefix/2001\:8b0\:de3a\:40dc\:\:/prefix
outputs/prefix/2001\:8b0\:de3a\:40dc\:\:/length
outputs/prefix/2001\:8b0\:de3a\:40dc\:\:/preferred
outputs/prefix/2001\:8b0\:de3a\:40dc\:\:/valid
outputs/prefix/2001\:8b0\:de3a\:80\:\:/prefix
outputs/prefix/2001\:8b0\:de3a\:80\:\:/length
outputs/prefix/2001\:8b0\:de3a\:80\:\:/preferred
outputs/prefix/2001\:8b0\:de3a\:80\:\:/valid
the directory name is arbitrary as long as it's unique. Might even be better to
remove the colons
outputs/prefix/200108b0de3a40dc/valid
or we could adopt the MS convention and replace with hyphens
outputs/prefix/2001-8b0-de3a-40dc--/prefix
Also: we should write some kind of test for this...
Tue Sep 5 21:36:39 BST 2023
How do we set the cpu governor?

32
pkgs/anoia/fs.fnl Normal file
View File

@ -0,0 +1,32 @@
(local lfs (require :lfs))
(fn directory? [pathname]
(= (lfs.symlinkattributes pathname :mode) "directory"))
(fn mktree [pathname]
(if (or (= pathname "") (= pathname "/"))
(error (.. "can't mkdir " pathname)))
(or (directory? pathname)
(let [parent (string.gsub pathname "/[^/]+/?$" "")]
(or (directory? parent) (mktree parent))
(assert (lfs.mkdir pathname)))))
(fn rmtree [pathname]
(case (lfs.symlinkattributes pathname)
nil true
{:mode "directory"}
(do
(each [f (lfs.dir pathname)]
(when (not (or (= f ".") (= f "..")))
(rmtree ( .. pathname "/" f)))
(lfs.rmdir pathname)))
{:mode "file"}
(os.remove pathname)
{:mode "link"}
(os.remove pathname)
unknown
(error (.. "can't remove " pathname " of kind \"" unknown.mode "\""))))
{ : mktree : rmtree }

View File

@ -14,6 +14,7 @@ let packages = [
linotify
anoia
fennel
lua.pkgs.luafilesystem
];
join = ps: builtins.concatStringsSep ";" ps;
luapath = join (builtins.map (f:
@ -34,7 +35,7 @@ in writeScriptBin "fennelrepl" ''
end
if #arg > 0 then
script = table.remove(arg, 1)
fennel.dofile(script, {}, arg)
fennel.dofile(script, {correlate = true}, arg)
else
fennel.repl()
end

View File

@ -0,0 +1,26 @@
./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/len:128
./address/2001-8b0-1111-1111-0-ffff-1234-5678/preferred:3600
./address/2001-8b0-1111-1111-0-ffff-1234-5678/valid:7200
./addresses:2001:8b0:1111:1111:0:ffff:1234:5678/128,3600,7200
./ifname:ppp0
./option_1:000300018cfdf02420eb
./option_2:000300010df0feca0df0
./passthru:00170020200108b0000000000000000000002020200108b0000000000000000000002021
./prefix/2001-8b0-de3a-22/address:2001:8b0:de3a:22::
./prefix/2001-8b0-de3a-22/len:64
./prefix/2001-8b0-de3a-22/preferred:7200
./prefix/2001-8b0-de3a-22/valid:7200
./prefix/2001-8b0-de3a-abcd/address:2001:8b0:de3a:abcd::
./prefix/2001-8b0-de3a-abcd/len:64
./prefix/2001-8b0-de3a-abcd/preferred:7200
./prefix/2001-8b0-de3a-abcd/valid:7200
./prefixes:2001:8b0:de3a:abcd::/64,7200,7200 2001:8b0:de3a:22::/64,7200,7200
./ra_hoplimit:64
./ra_mtu:0
./ra_reachable:0
./ra_retransmit:0
./ra_routes:::/0,fe80::203:97ff:fed6:0,65533,512
./rdnss:2001:8b0::2020 2001:8b0::2021
./server:fe80::203:97ff:fed6:0
./state:bound

View File

@ -1,6 +1,9 @@
(local { : split : merge } (require :anoia))
(local { : view } (require :fennel))
(local { : mktree : rmtree } (require :anoia.fs))
(local state-directory (assert (os.getenv "SERVICE_STATE")))
(os.execute (.. "mkdir -p " state-directory))
(mktree state-directory)
(fn write-value [name value]
(let [path (.. state-directory "/" name)]
@ -10,10 +13,34 @@
(fn write-value-from-env [name]
(write-value name (os.getenv (string.upper name))))
(fn parse-address [str]
(fn parse-extra [s]
(let [out {}]
(each [name val (string.gmatch s ",(.-)=([^,]+)")]
(tset out name val))
out))
(let [(address len preferred valid extra)
(string.match str "(.-)/(%d+),(%d+),(%d+)(.*)$")]
(merge {: address : len : preferred : valid} (parse-extra extra))))
(fn write-addresses [prefix addresses]
(each [_ a (ipairs (split " " addresses))]
(let [address (parse-address a)
keydir (.. prefix (-> address.address
(: :gsub "::$" "")
(: :gsub ":" "-")))]
(mktree (.. state-directory "/" keydir))
(each [k v (pairs address)]
(write-value (.. keydir "/" k) v)))))
;; we remove state before updating to ensure that consumers don't get
;; a half-updated snapshot
(os.remove (.. state-directory "/state"))
;; remove parsed addresses/prefixes from any previous run
(rmtree (.. state-directory "/prefix"))
(rmtree (.. state-directory "/address"))
(let [wanted
[
:addresses
@ -48,7 +75,10 @@
:sntp_fqdn
]]
(each [_ n (ipairs wanted)]
(write-value-from-env n)))
(write-value-from-env n))
(write-addresses "address/" (os.getenv :ADDRESSES))
(write-addresses "prefix/" (os.getenv :PREFIXES)))
(let [[ifname state] arg
ready (match state

View File

@ -0,0 +1,29 @@
RA_ADDRESSES=
RA_REACHABLE=0
USER=root
CER=
PASSTHRU=00170020200108b0000000000000000000002020200108b0000000000000000000002021
SHLVL=2
SERVER=fe80::203:97ff:fed6:0
HOME=/home/root/
RA_MTU=0
RA_ROUTES=::/0,fe80::203:97ff:fed6:0,65533,512
OPTION_1=000300018cfdf02420eb
NTP_FQDN=
OPTION_2=000300010df0feca0df0
RA_DOMAINS=
DOMAINS=
LOGNAME=root
AFTR=
SIP_IP=
NTP_IP=
PREFIXES="2001:8b0:de3a:abcd::/64,7200,7200 2001:8b0:de3a:22::/64,7200,7200"
RA_HOPLIMIT=64
SHELL=/bin/sh
RA_DNS=
RDNSS="2001:8b0::2020 2001:8b0::2021"
SNTP_IP=
RA_RETRANSMIT=0
SIP_DOMAIN=
PWD=/home/root
ADDRESSES=2001:8b0:1111:1111:0:ffff:1234:5678/128,3600,7200

21
pkgs/odhcp-script/test.sh Executable file
View File

@ -0,0 +1,21 @@
#!/usr/bin/env sh
set -e
statedir=$(mktemp -d)
cleanup(){
test -n "$statedir" && test -d $statedir && rm -rf $statedir
}
trap 'exit 1' INT HUP QUIT TERM ALRM USR1
trap 'cleanup' EXIT
# call the script twice with different state, to test that it cleans
# out old values when it runs again
(set -a; . ./test.env ; ADDRESSES=2001:80:111:111:0:fff:123:567/128,3600,7200 SERVICE_STATE=$statedir fennelrepl odhcp6-script.fnl ppp0 bound) 10>&1
(set -a; . ./test.env ; SERVICE_STATE=$statedir fennelrepl odhcp6-script.fnl ppp0 bound) 10>&1
(cd $statedir && find . -type f | xargs grep '' | sort) > actual
diff -u expected actual
cmp expected actual

View File

@ -5,10 +5,11 @@ let
liminix-config = ./vanilla-configuration.nix;
inherit nixpkgs;
});
here = builtins.toString ./.;
in liminix.buildEnv.overrideAttrs (o: {
nativeBuildInputs = o.nativeBuildInputs ++ [ (import nixpkgs {}).sphinx ] ;
shellHook = ''
publish(){ make -C doc html && rsync -azv doc/_build/html/ myhtic.telent.net:/var/www/blogs/www.liminix.org/_site/doc; }
'';
FENNEL_PATH = "pkgs/?/init.fnl;pkgs/?.fnl";
FENNEL_PATH = "${here}/pkgs/?/init.fnl;${here}/pkgs/?.fnl";
})