diff --git a/pkgs/liminix-tools/networking/default.nix b/pkgs/liminix-tools/networking/default.nix index 53c649d..1592cb4 100644 --- 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 index e1c53bc..f08f05c 100644 --- 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 index 2696c8c..c92967f 100644 --- 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 {