2022-09-22 12:10:41 +02:00
|
|
|
{
|
|
|
|
liminix
|
|
|
|
, busybox
|
2023-03-06 18:48:17 +01:00
|
|
|
, writeAshScript
|
2023-02-26 18:54:58 +01:00
|
|
|
, serviceFns
|
2022-09-22 12:10:41 +02:00
|
|
|
} :
|
2022-09-22 13:42:20 +02:00
|
|
|
let
|
|
|
|
inherit (liminix.services) longrun;
|
2022-09-25 22:10:04 +02:00
|
|
|
in
|
|
|
|
interface: { ... } @ args:
|
|
|
|
let
|
|
|
|
name = "${interface.device}.udhcp";
|
2023-03-06 18:48:17 +01:00
|
|
|
script = writeAshScript "udhcp-notify" {
|
|
|
|
# runtimeInputs = [ iproute2 ] using busybox version of ip
|
|
|
|
} ''
|
2023-02-25 23:53:06 +01:00
|
|
|
. ${serviceFns}
|
|
|
|
action=$1
|
2022-09-22 13:42:20 +02:00
|
|
|
|
2023-02-25 23:53:06 +01:00
|
|
|
set_address() {
|
|
|
|
ip address replace $ip/$mask dev $interface
|
2023-03-04 00:06:18 +01:00
|
|
|
(in_outputs ${name}
|
2023-02-25 23:53:06 +01:00
|
|
|
for i in lease mask ip router siaddr dns serverid subnet opt53 interface ; do
|
2023-03-07 20:05:58 +01:00
|
|
|
printenv $i > $i
|
2023-02-25 23:53:06 +01:00
|
|
|
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
|
|
|
|
'';
|
2022-09-25 22:10:04 +02:00
|
|
|
in longrun {
|
|
|
|
inherit name;
|
2022-09-22 13:42:20 +02:00
|
|
|
run = "${busybox}/bin/udhcpc -f -i ${interface.device} -s ${script}";
|
2022-09-25 22:10:57 +02:00
|
|
|
dependencies = [ interface ];
|
2022-09-22 12:10:41 +02:00
|
|
|
}
|
2022-09-22 13:42:20 +02:00
|
|
|
|
|
|
|
# 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
|
|
|
|
# /
|