working pppoe with readiness notification on ip-up

module-based-network
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
, 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 ];
}

View File

@ -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 ] ;