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}";
|
run = "odhcpcd ${interface.device}";
|
||||||
};
|
};
|
||||||
pppoe = callPackage ./pppoe.nix {};
|
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, ... } :
|
{ config, pkgs, ... } :
|
||||||
let
|
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;
|
inherit (pkgs.liminix.services) oneshot longrun bundle target output;
|
||||||
in rec {
|
in rec {
|
||||||
services.loopback =
|
services.loopback =
|
||||||
|
@ -40,24 +40,32 @@ in rec {
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
services.defaultroute4 =
|
services.defaultroute4 = route {
|
||||||
let iface = services.pppoe;
|
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 {
|
in oneshot {
|
||||||
name = "defaultroute4";
|
name = "let-the-ip-flow";
|
||||||
up = ''
|
up = "echo 1 > ${filename}";
|
||||||
ip route add default via $(cat ${output iface "address"})
|
down = "echo 0 > ${filename}";
|
||||||
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)
|
|
||||||
'';
|
|
||||||
dependencies = [iface];
|
dependencies = [iface];
|
||||||
};
|
};
|
||||||
|
|
||||||
services.default = target {
|
services.default = target {
|
||||||
name = "default";
|
name = "default";
|
||||||
contents = with services; [ loopback defaultroute4 syslogd ];
|
contents = with services; [
|
||||||
|
loopback
|
||||||
|
defaultroute4
|
||||||
|
packet_forwarding
|
||||||
|
syslogd
|
||||||
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
systemPackages = [ pkgs.hello ] ;
|
systemPackages = [ pkgs.hello ] ;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{ config, pkgs, ... } :
|
{ config, pkgs, ... } :
|
||||||
let
|
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;
|
inherit (pkgs.liminix.services) oneshot longrun bundle target output;
|
||||||
in rec {
|
in rec {
|
||||||
services.loopback =
|
services.loopback =
|
||||||
|
@ -40,18 +40,22 @@ in rec {
|
||||||
dependencies = [services.dhcpv4];
|
dependencies = [services.dhcpv4];
|
||||||
};
|
};
|
||||||
|
|
||||||
services.defaultroute4 =
|
services.defaultroute4 = route {
|
||||||
let inherit (services) dhcpv4;
|
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 {
|
in oneshot {
|
||||||
name = "defaultroute4";
|
name = "let-the-ip-flow";
|
||||||
up = ''
|
up = "echo 1 > ${filename}";
|
||||||
ip route add default gw $(cat ${output dhcpv4 "address"})
|
down = "echo 0 > ${filename}";
|
||||||
echo "1" > /sys/net/ipv4/$(cat ${output dhcpv4 "ifname"})
|
dependencies = [iface];
|
||||||
'';
|
|
||||||
down = ''
|
|
||||||
ip route del default gw $(cat ${output dhcpv4 "address"})
|
|
||||||
echo "0" > /sys/net/ipv4/$(cat ${output dhcpv4 "ifname"})
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
services.default = target {
|
services.default = target {
|
||||||
|
|
Loading…
Reference in a new issue