2023-09-13 18:49:57 +02:00
|
|
|
(local { : system } (require :anoia))
|
2023-07-08 23:15:56 +02:00
|
|
|
(local svc (require :anoia.svc))
|
2023-07-02 01:52:18 +02:00
|
|
|
|
2023-09-13 18:49:57 +02:00
|
|
|
(fn changes [old-addresses new-addresses]
|
2023-07-02 01:52:18 +02:00
|
|
|
(let [added {}
|
2023-09-13 18:49:57 +02:00
|
|
|
deleted {}]
|
|
|
|
(each [n address (pairs new-addresses)]
|
|
|
|
(if (not (. old-addresses n))
|
|
|
|
(table.insert added address)))
|
|
|
|
(each [n address (pairs old-addresses)]
|
|
|
|
(if (not (. new-addresses n))
|
|
|
|
(table.insert deleted address)))
|
2023-07-02 01:52:18 +02:00
|
|
|
(values added deleted)))
|
2023-06-01 00:29:05 +02:00
|
|
|
|
2023-09-13 18:49:57 +02:00
|
|
|
(fn update-prefixes [device prefixes new-prefixes]
|
|
|
|
(let [(added deleted) (changes prefixes new-prefixes)]
|
|
|
|
(each [_ p (ipairs added)]
|
|
|
|
(system
|
|
|
|
(.. "ip address add " p.address "1/" p.len " dev " device)))
|
|
|
|
(each [_ p (ipairs deleted)]
|
|
|
|
(system
|
|
|
|
(.. "ip address del " p.address "1/" p.len " dev " device)))))
|
|
|
|
|
|
|
|
(fn run []
|
|
|
|
(let [[state-directory lan-device] arg
|
|
|
|
dir (svc.open state-directory)]
|
|
|
|
(accumulate [addresses []
|
|
|
|
v (dir:events)]
|
|
|
|
(update-prefixes lan-device addresses (v:output "prefix")))))
|
|
|
|
|
|
|
|
{ : changes : run }
|