forked from DGNum/liminix
add a "route" service
This commit is contained in:
parent
676c94782b
commit
7803eebfd4
3 changed files with 48 additions and 25 deletions
|
@ -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;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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 ] ;
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue