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
|
|
|
|
2024-02-16 19:47:12 +01:00
|
|
|
(fn deletions [old-addresses new-addresses]
|
|
|
|
(let [deleted {}]
|
2023-09-13 18:49:57 +02:00
|
|
|
(each [n address (pairs old-addresses)]
|
2024-02-16 19:47:12 +01:00
|
|
|
(let [now (. new-addresses n)]
|
|
|
|
(if (or (not now) (not (= now.len address.len)))
|
|
|
|
(table.insert deleted address))))
|
|
|
|
deleted))
|
2023-06-01 00:29:05 +02:00
|
|
|
|
2024-02-16 19:47:12 +01:00
|
|
|
(fn update-prefixes [wan-device addresses new-addresses exec]
|
|
|
|
(each [_ p (ipairs (deletions addresses new-addresses))]
|
|
|
|
(exec
|
|
|
|
(.. "ip address del " p.address "1/" p.len " dev " wan-device)))
|
|
|
|
(each [_ p (pairs new-addresses)]
|
|
|
|
(exec
|
|
|
|
(.. "ip address change " p.address "1/" p.len
|
|
|
|
" dev " wan-device
|
|
|
|
" valid_lft " p.valid
|
|
|
|
" preferred_lft " p.preferred
|
|
|
|
)))
|
|
|
|
new-addresses)
|
2023-09-13 18:49:57 +02:00
|
|
|
|
|
|
|
(fn run []
|
|
|
|
(let [[state-directory lan-device] arg
|
|
|
|
dir (svc.open state-directory)]
|
|
|
|
(accumulate [addresses []
|
|
|
|
v (dir:events)]
|
2024-02-16 19:47:12 +01:00
|
|
|
(update-prefixes lan-device addresses (v:output "prefix") system))))
|
2023-09-13 18:49:57 +02:00
|
|
|
|
|
|
|
{ : changes : run }
|