liminix

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 7803eebfd48f256d81154808ebe5b3aff1a3656f
parent 676c94782bb1590baeaf74e4415e488a2ad2b763
Author: Daniel Barlow <dan@telent.net>
Date:   Mon, 26 Sep 2022 12:55:10 +0100

add a "route" service

Diffstat:
Mpkgs/liminix-tools/networking/default.nix | 11+++++++++++
Mtests/pppoe/configuration.nix | 34+++++++++++++++++++++-------------
Mtests/smoke/configuration.nix | 28++++++++++++++++------------
3 files changed, 48 insertions(+), 25 deletions(-)

diff --git a/pkgs/liminix-tools/networking/default.nix b/pkgs/liminix-tools/networking/default.nix @@ -25,4 +25,15 @@ in { run = "odhcpcd ${interface.device}"; }; pppoe = callPackage ./pppoe.nix {}; + route = { name, target, via, dependencies }: + oneshot { + inherit name; + up = '' + ip route add ${target} via ${via} + ''; + down = '' + ip route del ${target} via ${via} + ''; + inherit dependencies; + }; } diff --git a/tests/pppoe/configuration.nix b/tests/pppoe/configuration.nix @@ -1,6 +1,6 @@ { config, pkgs, ... } : let - inherit (pkgs.liminix.networking) interface address pppoe; + inherit (pkgs.liminix.networking) interface address pppoe route; inherit (pkgs.liminix.services) oneshot longrun bundle target output; in rec { services.loopback = @@ -40,24 +40,32 @@ in rec { ]; }; - services.defaultroute4 = - let iface = services.pppoe; + services.defaultroute4 = route { + name = "defautlrote"; + via = "$(cat ${output services.pppoe "address"})"; + target = "default"; + dependencies = [ services.pppoe ]; + }; + + services.packet_forwarding = + let + iface = services.pppoe; + filename = "/proc/sys/net/ipv4/conf/$(cat ${output iface "ifname"})/forwarding"; in oneshot { - name = "defaultroute4"; - up = '' - 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 via $(cat ${output iface "address"}) - echo "0" > /proc/sys/net/ipv4/conf/$(cat ${output iface "ifname"}/forwarding) - ''; + name = "let-the-ip-flow"; + up = "echo 1 > ${filename}"; + down = "echo 0 > ${filename}"; dependencies = [iface]; }; services.default = target { name = "default"; - contents = with services; [ loopback defaultroute4 syslogd ]; + contents = with services; [ + loopback + defaultroute4 + packet_forwarding + syslogd + ]; }; systemPackages = [ pkgs.hello ] ; diff --git a/tests/smoke/configuration.nix b/tests/smoke/configuration.nix @@ -1,6 +1,6 @@ { config, pkgs, ... } : let - inherit (pkgs.liminix.networking) interface address udhcpc odhcpc; + inherit (pkgs.liminix.networking) interface address udhcpc odhcpc route; inherit (pkgs.liminix.services) oneshot longrun bundle target output; in rec { services.loopback = @@ -40,18 +40,22 @@ in rec { dependencies = [services.dhcpv4]; }; - services.defaultroute4 = - let inherit (services) dhcpv4; + services.defaultroute4 = route { + name = "defautlrote"; + via = "$(cat ${output services.dhcpv4 "address"})"; + target = "default"; + dependencies = [ services.dhcpv4 ]; + }; + + services.packet_forwarding = + let + iface = services.dhcpv4; + filename = "/proc/sys/net/ipv4/conf/$(cat ${output iface "ifname"})/forwarding"; in oneshot { - name = "defaultroute4"; - up = '' - ip route add default gw $(cat ${output dhcpv4 "address"}) - echo "1" > /sys/net/ipv4/$(cat ${output dhcpv4 "ifname"}) - ''; - down = '' - ip route del default gw $(cat ${output dhcpv4 "address"}) - echo "0" > /sys/net/ipv4/$(cat ${output dhcpv4 "ifname"}) - ''; + name = "let-the-ip-flow"; + up = "echo 1 > ${filename}"; + down = "echo 0 > ${filename}"; + dependencies = [iface]; }; services.default = target {