diff --git a/modules/dhcp6c/acquire-delegated-prefix.fnl b/modules/dhcp6c/acquire-delegated-prefix.fnl index 07ff7af..d785126 100644 --- a/modules/dhcp6c/acquire-delegated-prefix.fnl +++ b/modules/dhcp6c/acquire-delegated-prefix.fnl @@ -14,9 +14,18 @@ (fn update-prefixes [device prefixes new-prefixes] (let [(added deleted) (changes prefixes new-prefixes)] + ;; if some address has changed (e.g. preferred/valid lifetime) + ;; then we don't want to delete it before re-adding it because + ;; the kernel will drop any routes that go through it. On the + ;; other hand, we can't add it _before_ deleting it as we'll + ;; get an error that it already exists. Therefore, use "change" + ;; instead of "add", it works a bit more like an upsert (each [_ p (ipairs added)] (system - (.. "ip address add " p.address "1/" p.len " dev " device))) + (.. "ip address change " p.address "1/" p.len " dev " device + " valid_lft " p.valid + " preferred_lft " p.preferred + ))) (each [_ p (ipairs deleted)] (system (.. "ip address del " p.address "1/" p.len " dev " device))))) diff --git a/modules/dhcp6c/acquire-wan-address.fnl b/modules/dhcp6c/acquire-wan-address.fnl index af6f92b..38847bc 100644 --- a/modules/dhcp6c/acquire-wan-address.fnl +++ b/modules/dhcp6c/acquire-wan-address.fnl @@ -17,9 +17,14 @@ (fn update-addresses [wan-device addresses new-addresses] (let [(added deleted) (changes addresses new-addresses)] + ;; see comment in acquire-delegated-prefix.fnl (each [_ p (ipairs added)] (system - (.. "ip address add " p.address "/" p.len " dev " wan-device))) + (.. "ip address change " p.address "/" p.len + " dev " wan-device + " valid_lft " p.valid + " preferred_lft " p.preferred + ))) (each [_ p (ipairs deleted)] (system (.. "ip address del " p.address "/" p.len " dev " wan-device))) diff --git a/pkgs/odhcp-script/odhcp6-script.fnl b/pkgs/odhcp-script/odhcp6-script.fnl index 0d16650..699f695 100644 --- a/pkgs/odhcp-script/odhcp6-script.fnl +++ b/pkgs/odhcp-script/odhcp6-script.fnl @@ -20,7 +20,11 @@ out)) (let [(address len preferred valid extra) (string.match str "(.-)/(%d+),(%d+),(%d+)(.*)$")] - (merge {: address : len : preferred : valid} (parse-extra extra)))) + (merge {: address : len + :preferred (or preferred "forever") + :valid (or valid "forever") + } + (parse-extra extra)))) (fn write-addresses [prefix addresses] (each [_ a (ipairs (split " " addresses))]