From 447f0685697adea38be8a0128547d03afaac8c6a Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Wed, 24 May 2023 23:01:50 +0100 Subject: [PATCH] partly support getting IPv6 addresses - gets interface id from ppp - runs odhcpc to get RA and prefix delegation - doesn't do anything useful with the data yet --- examples/rotuer.nix | 20 +++++++++++ examples/udhcp6-script.fnl | 47 +++++++++++++++++++++++++ modules/busybox.nix | 2 +- pkgs/default.nix | 1 + pkgs/liminix-tools/networking/pppoe.nix | 9 +++++ pkgs/odhcp6c/default.nix | 20 +++++++++++ 6 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 examples/udhcp6-script.fnl create mode 100644 pkgs/odhcp6c/default.nix diff --git a/examples/rotuer.nix b/examples/rotuer.nix index 85ae0ae..b715da6 100644 --- a/examples/rotuer.nix +++ b/examples/rotuer.nix @@ -232,6 +232,25 @@ in rec { down = "echo 0 > ${filename}"; }; + services.dhcp6 = + let + name = "dhcp6c.wan"; + luafile = pkgs.runCommand "udhcpc-script" {} '' + ${pkgs.luaSmall.pkgs.fennel}/bin/fennel --compile ${./udhcp6-script.fnl} > $out + ''; + script = pkgs.writeAshScript "dhcp6-notify" {} '' + . ${serviceFns} + (in_outputs ${name}; ${pkgs.luaSmall}/bin/lua ${luafile} "$@") + ''; + in longrun { + inherit name; + run = '' + ${pkgs.odhcp6c}/bin/odhcp6c -s ${script} -e -v -p /run/${name}.pid -P 48 $(output ${services.wan} ifname) + ) + ''; + dependencies = [ services.wan ]; + }; + services.default = target { name = "default"; contents = with config.services; [ @@ -248,6 +267,7 @@ in rec { resolvconf sshd config.services.hostname + dhcp6 ]; }; defaultProfile.packages = with pkgs; [min-collect-garbage nftables tcpdump] ; diff --git a/examples/udhcp6-script.fnl b/examples/udhcp6-script.fnl new file mode 100644 index 0000000..f7d2b37 --- /dev/null +++ b/examples/udhcp6-script.fnl @@ -0,0 +1,47 @@ + + +(fn write-value [name value] + (with-open [fout (io.open name :w)] + (when value (fout:write value)))) + +(write-value "state" (. arg 2)) +(write-value "ifname" (. arg 1)) + +(fn write-value-from-env [name] + (write-value name (os.getenv (string.upper name)))) + +(let [wanted + [ + :addresses + :aftr + :cer + :domains + :lw406 + :mape + :mapt + :ntp_fqdn + :ntp_ip + :option_1 + :option_2 + :option_3 + :option_4 + :option_5 + :passthru + :prefixes + :ra_addresses + :ra_dns + :ra_domains + :ra_hoplimit + :ra_mtu + :ra_reachable + :ra_retransmit + :ra_routes + :rdnss + :server + :sip_domain + :sip_ip + :sntp_ip + :sntp_fqdn + ]] + (each [_ n (ipairs wanted)] + (write-value-from-env n))) diff --git a/modules/busybox.nix b/modules/busybox.nix index 5bb95ca..aeaa0a8 100644 --- a/modules/busybox.nix +++ b/modules/busybox.nix @@ -38,7 +38,7 @@ let "seq" "setsid" "sha1sum" "sha256sum" "sha512sum" "sleep" "sort" "stat" "strings" "stty" "su" "sum" "swapoff" "swapon" "sync" "tail" "tee" "test" "time" "touch" "tr" "traceroute" "traceroute6" - "true" "truncate" "tty" "udhcpc" "udhcpc6" "umount" "uname" + "true" "truncate" "tty" "udhcpc" "umount" "uname" "unexpand" "uniq" "unlink" "unlzma" "unxz" "unzip" "uptime" "watch" "wc" "whoami" "xargs" "xxd" "xz" "xzcat" "yes" "zcat" ]; diff --git a/pkgs/default.nix b/pkgs/default.nix index dd2520c..df3985d 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -43,6 +43,7 @@ preinit = callPackage ./preinit {}; swconfig = callPackage ./swconfig {}; + odhcp6c = callPackage ./odhcp6c {}; openwrt = callPackage ./openwrt {}; diff --git a/pkgs/liminix-tools/networking/pppoe.nix b/pkgs/liminix-tools/networking/pppoe.nix index 402a416..1fbf776 100644 --- a/pkgs/liminix-tools/networking/pppoe.nix +++ b/pkgs/liminix-tools/networking/pppoe.nix @@ -29,8 +29,17 @@ let ) echo >/proc/self/fd/10 ''; + ip6-up = writeAshScript "ip6-up" {} '' + . ${serviceFns} + (in_outputs ${name} + echo $4 > ipv6-address + echo $5 > ipv6-peer-address + ) + echo >/proc/self/fd/10 + ''; ppp-options' = ppp-options ++ [ "ip-up-script" ip-up + "ipv6-up-script" ip6-up "ipparam" name "nodetach" "usepeerdns" diff --git a/pkgs/odhcp6c/default.nix b/pkgs/odhcp6c/default.nix new file mode 100644 index 0000000..df8f954 --- /dev/null +++ b/pkgs/odhcp6c/default.nix @@ -0,0 +1,20 @@ +{ stdenv +, buildPackages +, cmake +, fetchFromGitHub +, ...} : +# let switchDotH = buildPackages.fetchurl { +# url = "https://git.openwrt.org/?p=openwrt/openwrt.git;a=blob_plain;f=target/linux/generic/files/include/uapi/linux/switch.h;hb=99a188828713d6ff9c541590b08d4e63ef52f6d7"; +# sha256 = "15kmhhcpd84y4f45rf8zai98c61jyvkc37p90pcxirna01x33wi8"; +# name="switch.h"; +# }; +stdenv.mkDerivation { + src = fetchFromGitHub { + owner = "openwrt"; + repo = "odhcp6c"; + rev = "bcd283632ac13391aac3ebdd074d1fd832d76fa3"; + hash = "sha256-jqxr+N1PffWYmF0F6hJKxRLMN5Ht5WpehK1K2HjL+do="; + }; + name = "odhcp6c"; + nativeBuildInputs = [ cmake ]; +}