working pppoe with readiness notification on ip-up

This commit is contained in:
Daniel Barlow 2022-09-25 21:12:23 +01:00
parent 47f8fa9797
commit 5d51d15b86
2 changed files with 51 additions and 39 deletions

View file

@ -4,45 +4,40 @@
, busybox , busybox
, ppp , ppp
, pppoe , pppoe
, writeShellScript , writeAshScript
} : } :
let let
inherit (liminix.services) longrun; inherit (liminix.services) longrun;
ip-up = writeShellScript "ip-up" ''
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 in
interface: { interface: {
synchronous ? false synchronous ? false
, ppp-options ? [] , ppp-options ? []
, ... , ...
} @ args: longrun { } @ args:
name = "${interface.device}.ppppoe"; let
run = "${ppp}/bin/pppd pty '${pppoe}/bin/pppoe -I ${interface.device}' ${lib.concatStringsSep " " ppp-options}" ; name = "${interface.device}.pppoe";
ip-up = writeAshScript "ip-up" {} ''
outputs=/run/service-state/${name}.service/
mkdir -p $outputs
(cd $outputs
echo $1 > ifname
echo $2 > tty
echo $3 > speed
echo $4 > address
echo $5 > peer-address
)
echo >/proc/self/fd/10
'';
ppp-options' = ppp-options ++ [
"ip-up-script" ip-up
"ipparam" name
"nodetach"
];
in
longrun {
inherit name;
run = "${ppp}/bin/pppd pty '${pppoe}/bin/pppoe -I ${interface.device}' ${lib.concatStringsSep " " ppp-options'}" ;
notification-fd = 10;
dependencies = [ interface ];
} }

View file

@ -14,33 +14,50 @@ in rec {
}; };
kernel.config = { kernel.config = {
"IKCONFIG_PROC" = "y";
"PPP" = "y"; "PPP" = "y";
"PPPOE" = "y"; "PPPOE" = "y";
"PPPOL2TP" = "y"; "PPPOL2TP" = "y";
"PPP_ASYNC" = "y";
"PPP_BSDCOMP" = "y";
"PPP_DEFLATE" = "y";
"PPP_MPPE" = "y";
"PPP_SYNC_TTY" = "y";
};
services.syslogd = longrun {
name = "syslogd";
run = "${pkgs.busybox}/bin/syslogd -n -O /run/syslog";
}; };
services.pppoe = services.pppoe =
let iface = interface { type = "hardware"; device = "eth0"; }; let iface = interface { type = "hardware"; device = "eth0"; };
in pppoe iface {}; in pppoe iface {
ppp-options = [
"debug" "+ipv6" "noauth"
"name" "db123@a.1"
"password" "NotReallyTheSecret"
];
};
services.defaultroute4 = services.defaultroute4 =
let iface = services.pppoe; let iface = services.pppoe;
in oneshot { in oneshot {
name = "defaultroute4"; name = "defaultroute4";
up = '' up = ''
ip route add default gw $(cat ${output iface "address"}) ip route add default via $(cat ${output iface "address"})
echo "1" > /sys/net/ipv4/$(cat ${output iface "ifname"}) echo "1" > /proc/sys/net/ipv4/conf/$(cat ${output iface "ifname"}/forwarding)
''; '';
down = '' down = ''
ip route del default gw $(cat ${output iface "address"}) ip route del default via $(cat ${output iface "address"})
echo "0" > /sys/net/ipv4/$(cat ${output iface "ifname"}) echo "0" > /proc/sys/net/ipv4/conf/$(cat ${output iface "ifname"}/forwarding)
''; '';
dependencies = [iface]; dependencies = [iface];
}; };
services.default = target { services.default = target {
name = "default"; name = "default";
contents = with services; [ loopback defaultroute4 ]; contents = with services; [ loopback defaultroute4 syslogd ];
}; };
systemPackages = [ pkgs.hello ] ; systemPackages = [ pkgs.hello ] ;