From dd124e49dd203f300b4ae4b8074755dbe1735e4e Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Thu, 22 Sep 2022 12:42:20 +0100 Subject: [PATCH] udhcp: write service responses as outputs --- pkgs/liminix-tools/default.nix | 2 +- pkgs/liminix-tools/networking/udhcpc.nix | 51 +++++++++++++++++++++++- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/pkgs/liminix-tools/default.nix b/pkgs/liminix-tools/default.nix index 0b7d30e..1d0ba90 100644 --- a/pkgs/liminix-tools/default.nix +++ b/pkgs/liminix-tools/default.nix @@ -80,6 +80,6 @@ in { }; services = { inherit longrun oneshot bundle target; - output = service: name: "/run/services/outputs/${service.name}/${name}"; + output = service: name: "/run/s6-rc/scandir/${service.name}/data/outputs/${name}"; }; } diff --git a/pkgs/liminix-tools/networking/udhcpc.nix b/pkgs/liminix-tools/networking/udhcpc.nix index ffdecb8..5ce05a6 100644 --- a/pkgs/liminix-tools/networking/udhcpc.nix +++ b/pkgs/liminix-tools/networking/udhcpc.nix @@ -1,10 +1,57 @@ { liminix , busybox +, writeShellScript } : -let inherit (liminix.services) longrun; +let + inherit (liminix.services) longrun; + script = writeShellScript "udhcp-notify" '' +action=$1 +env > /run/udhcp.values + +set_address() { + ip address replace $ip/$mask dev $interface + mkdir -p data/outputs + for i in lease mask ip router siaddr dns serverid subnet opt53 interface ; do + echo ''${!i} > data/outputs/$i + done +} +case $action in + deconfig) + ip address flush $interface + ip link set up dev $interface + ;; + bound) + # this doesn't actually replace, it adds a new address. + set_address + ;; + renew) + set_address + ;; + nak) + echo "received NAK on $interface" + ;; +esac +''; + in interface: { ... } @ args: longrun { name = "${interface.device}.udhcp"; - run = "${busybox}/bin/udhcpc -f -i ${interface.device}"; + run = "${busybox}/bin/udhcpc -f -i ${interface.device} -s ${script}"; } + +# lease=86400 +# mask=24 +# ip=10.0.2.15 +# router=10.0.2.2 +# siaddr=10.0.2.2 +# dns=10.0.2.3 +# serverid=10.0.2.2 +# subnet=255.255.255.0 +# SHLVL=2 +# opt53=05 +# interface=eth0 +# PATH=/nix/store/npy692wik809z3vdwrkrj2wixjkr33kp-busybox-mips-unknown-linux-musl-1.35.0/bin:/nix/store/ +# pj0b27l5728cypa5mmagz0q8ibzpik0h-execline-mips-unknown-linux-musl-2.9.0.1-bin/bin:/nix/store/rfjiw4dnv29daqc9971qmica1h86l0s0-s6-linux-init-mips-unknown-linux-musl-1.0.8.0-bin/bin:/nix/store/4wn3jm7yy2gfi0is0yy75lifbq5zjwz7-s6-rc-mips-unknown-linux-musl-0.5.3.2-bin/bin:/usr/bin:/bin +# _=/nix/store/npy692wik809z3vdwrkrj2wixjkr33kp-busybox-mips-unknown-linux-musl-1.35.0/bin/env +# /