2023-08-28 16:10:53 +02:00
|
|
|
{
|
|
|
|
liminix
|
|
|
|
, writeAshScript
|
|
|
|
, serviceFns
|
|
|
|
, lib
|
|
|
|
} :
|
|
|
|
{ interface }:
|
|
|
|
let
|
|
|
|
inherit (liminix.services) longrun;
|
|
|
|
name = "${interface.name}.dhcpc";
|
|
|
|
script = writeAshScript "dhcp-notify" { } ''
|
|
|
|
. ${serviceFns}
|
|
|
|
exec 2>&1
|
|
|
|
action=$1
|
|
|
|
|
|
|
|
set_address() {
|
|
|
|
ip address replace $ip/$mask dev $interface
|
|
|
|
(in_outputs ${name}
|
|
|
|
for i in lease mask ip router siaddr dns serverid subnet opt53 interface ; do
|
2024-06-15 16:34:49 +02:00
|
|
|
(printenv $i || true) > $i
|
2023-08-28 16:10:53 +02: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
|
|
|
|
echo >/proc/self/fd/10
|
|
|
|
;;
|
|
|
|
renew)
|
|
|
|
set_address
|
|
|
|
;;
|
|
|
|
nak)
|
|
|
|
echo "received NAK on $interface"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
'';
|
|
|
|
in longrun {
|
|
|
|
inherit name;
|
2024-06-15 16:34:49 +02:00
|
|
|
run = "exec /bin/udhcpc -f -i $(output ${interface} ifname) -x hostname:$(cat /proc/sys/kernel/hostname) -s ${script}";
|
2023-08-28 16:10:53 +02:00
|
|
|
notification-fd = 10;
|
|
|
|
dependencies = [ interface ];
|
|
|
|
}
|