forked from DGNum/liminix
set ipv6 wan address to that provided by dhcpv6
This commit is contained in:
parent
c7ead8559b
commit
7c06f30675
3 changed files with 77 additions and 10 deletions
60
examples/acquire-wan-address.fnl
Normal file
60
examples/acquire-wan-address.fnl
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
(local { : merge : split : file-exists? : system } (require :anoia))
|
||||||
|
(local svc (require :anoia.svc))
|
||||||
|
|
||||||
|
;; structurally this is remarkably similar to
|
||||||
|
;; acquire-lan-prefix.fnl. maybe they should be merged: if not then
|
||||||
|
;; we could at least extract some common code
|
||||||
|
|
||||||
|
;; (alternatively we could move all the parsing code into the thing in
|
||||||
|
;; the odhcp service that *writes* this stuff)
|
||||||
|
|
||||||
|
; (parse-address "2001:8b0:1111:1111:0:ffff:51bb:4cf2/128,3600,7200")
|
||||||
|
|
||||||
|
|
||||||
|
(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))))
|
||||||
|
|
||||||
|
(local bound-states
|
||||||
|
{ :bound true
|
||||||
|
:rebound true
|
||||||
|
:informed true
|
||||||
|
:updated true
|
||||||
|
:ra-updated true
|
||||||
|
})
|
||||||
|
|
||||||
|
(fn changes [old-addresses new-addresses]
|
||||||
|
(let [added {}
|
||||||
|
deleted {}
|
||||||
|
old-set (collect [_ v (ipairs old-addresses)] (values v true))
|
||||||
|
new-set (collect [_ v (ipairs new-addresses)] (values v true))]
|
||||||
|
(each [_ address (ipairs new-addresses)]
|
||||||
|
(if (not (. old-set address))
|
||||||
|
(table.insert added (parse-address address))))
|
||||||
|
(each [_ address (ipairs old-addresses)]
|
||||||
|
(if (not (. new-set address))
|
||||||
|
(table.insert deleted (parse-address address))))
|
||||||
|
(values added deleted)))
|
||||||
|
|
||||||
|
(let [[state-directory wan-device] arg
|
||||||
|
dir (svc.open state-directory)]
|
||||||
|
(var addresses [])
|
||||||
|
(while true
|
||||||
|
(while (not (dir:ready?)) (dir:wait))
|
||||||
|
(if (. bound-states (dir:output "state"))
|
||||||
|
(let [new-addresses (split " " (dir:output "/addresses"))
|
||||||
|
(added deleted) (changes addresses new-addresses)]
|
||||||
|
(each [_ p (ipairs added)]
|
||||||
|
(system
|
||||||
|
(.. "ip address add " p.address "/" p.len " dev " wan-device)))
|
||||||
|
(each [_ p (ipairs deleted)]
|
||||||
|
(system
|
||||||
|
(.. "ip address del " p.address "/" p.len " dev " wan-device)))
|
||||||
|
(set addresses new-addresses)))
|
||||||
|
(dir:wait)))
|
8
examples/acquire-wan-address.nix
Normal file
8
examples/acquire-wan-address.nix
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
writeFennelScript
|
||||||
|
, linotify
|
||||||
|
, anoia
|
||||||
|
}:
|
||||||
|
writeFennelScript "acquire-wan-address"
|
||||||
|
[ linotify anoia ]
|
||||||
|
./acquire-wan-address.fnl
|
|
@ -295,15 +295,6 @@ in rec {
|
||||||
dependencies = [ services.wan ];
|
dependencies = [ services.wan ];
|
||||||
};
|
};
|
||||||
|
|
||||||
# services.set-wan-address =
|
|
||||||
# oneshot {
|
|
||||||
# name = "set-wan-address";
|
|
||||||
# # FIXME nasty bit of hardcoding - should get this from dhcp6c
|
|
||||||
# up = "ip address add 2001:8b0:1111:1111:0:ffff:51bb:4cf2/128 dev ppp0";
|
|
||||||
# down = "ip address del 2001:8b0:1111:1111:0:ffff:51bb:4cf2/128 dev ppp0";
|
|
||||||
# dependencies = [ services.dhcp6 ];
|
|
||||||
# };
|
|
||||||
|
|
||||||
services.acquire-lan-prefix =
|
services.acquire-lan-prefix =
|
||||||
let script = pkgs.callPackage ./acquire-delegated-prefix.nix { };
|
let script = pkgs.callPackage ./acquire-delegated-prefix.nix { };
|
||||||
in longrun {
|
in longrun {
|
||||||
|
@ -312,6 +303,14 @@ in rec {
|
||||||
dependencies = [ services.dhcp6 ];
|
dependencies = [ services.dhcp6 ];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
services.acquire-wan-address =
|
||||||
|
let script = pkgs.callPackage ./acquire-wan-address.nix { };
|
||||||
|
in longrun {
|
||||||
|
name = "acquire-wan-address";
|
||||||
|
run = "${script} /run/service-state/dhcp6c.wan $(output ${services.wan} ifname)";
|
||||||
|
dependencies = [ services.dhcp6 ];
|
||||||
|
};
|
||||||
|
|
||||||
services.default = target {
|
services.default = target {
|
||||||
name = "default";
|
name = "default";
|
||||||
contents = with config.services; [
|
contents = with config.services; [
|
||||||
|
@ -331,7 +330,7 @@ in rec {
|
||||||
config.services.hostname
|
config.services.hostname
|
||||||
dhcp6
|
dhcp6
|
||||||
acquire-lan-prefix
|
acquire-lan-prefix
|
||||||
# set-wan-address
|
acquire-wan-address
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
defaultProfile.packages = with pkgs; [
|
defaultProfile.packages = with pkgs; [
|
||||||
|
|
Loading…
Reference in a new issue