From 5d51d15b86ffd60759bb1965be56fc5be3b0549b Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Sun, 25 Sep 2022 21:12:23 +0100 Subject: [PATCH] working pppoe with readiness notification on ip-up --- pkgs/liminix-tools/networking/pppoe.nix | 61 ++++++++++++------------- tests/pppoe/configuration.nix | 29 +++++++++--- 2 files changed, 51 insertions(+), 39 deletions(-) diff --git a/pkgs/liminix-tools/networking/pppoe.nix b/pkgs/liminix-tools/networking/pppoe.nix index b98d9c4..69c3de6 100644 --- a/pkgs/liminix-tools/networking/pppoe.nix +++ b/pkgs/liminix-tools/networking/pppoe.nix @@ -4,45 +4,40 @@ , busybox , ppp , pppoe -, writeShellScript +, writeAshScript } : let 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 interface: { synchronous ? false , ppp-options ? [] , ... -} @ args: longrun { - name = "${interface.device}.ppppoe"; - run = "${ppp}/bin/pppd pty '${pppoe}/bin/pppoe -I ${interface.device}' ${lib.concatStringsSep " " ppp-options}" ; +} @ args: +let + 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 ]; } diff --git a/tests/pppoe/configuration.nix b/tests/pppoe/configuration.nix index c002aca..e1c53bc 100644 --- a/tests/pppoe/configuration.nix +++ b/tests/pppoe/configuration.nix @@ -14,33 +14,50 @@ in rec { }; kernel.config = { + "IKCONFIG_PROC" = "y"; "PPP" = "y"; "PPPOE" = "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 = 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 = let iface = services.pppoe; in oneshot { name = "defaultroute4"; up = '' - ip route add default gw $(cat ${output iface "address"}) - echo "1" > /sys/net/ipv4/$(cat ${output iface "ifname"}) + ip route add default via $(cat ${output iface "address"}) + echo "1" > /proc/sys/net/ipv4/conf/$(cat ${output iface "ifname"}/forwarding) ''; down = '' - ip route del default gw $(cat ${output iface "address"}) - echo "0" > /sys/net/ipv4/$(cat ${output iface "ifname"}) + ip route del default via $(cat ${output iface "address"}) + echo "0" > /proc/sys/net/ipv4/conf/$(cat ${output iface "ifname"}/forwarding) ''; dependencies = [iface]; }; services.default = target { name = "default"; - contents = with services; [ loopback defaultroute4 ]; + contents = with services; [ loopback defaultroute4 syslogd ]; }; systemPackages = [ pkgs.hello ] ;