2023-10-07 22:45:51 +02:00
|
|
|
{
|
2024-02-09 20:03:02 +01:00
|
|
|
secret,
|
|
|
|
inputs',
|
|
|
|
pkgs,
|
|
|
|
lib,
|
|
|
|
...
|
|
|
|
}: {
|
2024-01-18 14:09:59 +01:00
|
|
|
networking.notnft.postStop = ''
|
2024-03-02 23:09:25 +01:00
|
|
|
if systemctl status podman ; then
|
|
|
|
${lib.getExe' pkgs.podman "podman"} network reload -a
|
|
|
|
fi
|
2024-01-18 14:09:59 +01:00
|
|
|
'';
|
|
|
|
|
|
|
|
networking.notnft.postStart = ''
|
2024-03-02 23:09:25 +01:00
|
|
|
if systemctl status podman ; then
|
|
|
|
${lib.getExe' pkgs.podman "podman"} network reload -a
|
|
|
|
fi
|
2024-01-18 14:09:59 +01:00
|
|
|
'';
|
2024-02-09 20:03:02 +01:00
|
|
|
|
|
|
|
networking.notnft.rules = let
|
|
|
|
notnft = inputs'.notnft.lib.${pkgs.stdenv.system};
|
|
|
|
logRule = with notnft.dsl;
|
|
|
|
with payload;
|
|
|
|
prefix: [
|
|
|
|
(log {
|
|
|
|
prefix = "${prefix} dropped: ";
|
|
|
|
flags = f: [f.all];
|
|
|
|
})
|
|
|
|
];
|
|
|
|
traceChain = with notnft.dsl;
|
|
|
|
with payload;
|
|
|
|
add chain
|
|
|
|
[(is.eq th.dport 53) (mangle meta.nftrace 1)]
|
|
|
|
[(is.eq th.dport 53) (mangle meta.nftrace 1)]
|
|
|
|
[(is.eq th.dport 22) (mangle meta.nftrace 1)]
|
|
|
|
[(is.eq th.sport 22) (mangle meta.nftrace 1)]
|
2024-03-02 22:00:09 +01:00
|
|
|
[(is.eq meta.oifname "uk3s0") (mangle meta.nftrace 1)]
|
|
|
|
[(is.eq meta.iifname "uk3s0") (mangle meta.nftrace 1)];
|
2024-02-09 20:03:02 +01:00
|
|
|
in
|
|
|
|
with notnft.dsl;
|
|
|
|
with payload;
|
|
|
|
ruleset {
|
|
|
|
filter = add table {family = f: f.inet;} {
|
2023-10-07 22:45:51 +02:00
|
|
|
trace = traceChain;
|
|
|
|
|
|
|
|
### lo
|
2024-02-09 20:03:02 +01:00
|
|
|
input-lo =
|
|
|
|
add chain
|
|
|
|
[accept];
|
2023-10-07 22:45:51 +02:00
|
|
|
|
2024-02-09 20:03:02 +01:00
|
|
|
output-lo =
|
|
|
|
add chain
|
|
|
|
[accept];
|
2023-10-07 22:45:51 +02:00
|
|
|
###
|
|
|
|
|
|
|
|
### mvm
|
2024-02-09 20:03:02 +01:00
|
|
|
input-mvm =
|
2024-03-02 22:00:09 +01:00
|
|
|
add chain;
|
2024-02-09 20:03:02 +01:00
|
|
|
|
|
|
|
output-mvm =
|
|
|
|
add chain
|
|
|
|
[(is.eq ip.protocol (f: f.icmp)) (is.eq ip.saddr "10.80.1.1") (is.eq ip.daddr "10.80.1.2") accept]
|
|
|
|
[(is.eq ip.protocol (f: f.icmp)) (is.eq ip.saddr "10.80.1.2") (is.eq ip.daddr "10.80.1.1") accept]
|
|
|
|
[(is.eq ip.protocol (f: with f; set [tcp])) (is.eq th.dport 22) (is.eq ip.saddr "10.80.1.1") (is.eq ip.daddr "10.80.1.2") accept]
|
|
|
|
[(is.eq ip.protocol (f: with f; set [tcp])) (is.eq th.dport 80) (is.eq ip.saddr "10.80.1.1") (is.eq ip.daddr "10.80.1.2") accept];
|
2023-10-07 22:45:51 +02:00
|
|
|
###
|
|
|
|
|
2024-03-02 22:00:09 +01:00
|
|
|
###
|
|
|
|
input-uk3s =
|
|
|
|
add chain;
|
|
|
|
|
|
|
|
output-uk3s =
|
|
|
|
add chain
|
|
|
|
[(is.eq ip.daddr (cidr "10.50.0.0/22")) accept];
|
|
|
|
|
2024-03-23 08:31:33 +01:00
|
|
|
input-arma3 =
|
|
|
|
add chain;
|
|
|
|
|
|
|
|
output-arma3 =
|
|
|
|
add chain
|
|
|
|
[(is.eq ip.daddr (cidr "10.99.99.0/24")) accept];
|
|
|
|
|
2023-10-07 22:45:51 +02:00
|
|
|
### wlan0
|
2024-02-09 20:03:02 +01:00
|
|
|
input-wlan0 =
|
|
|
|
add chain
|
|
|
|
[(is.eq ip.protocol (f: f.tcp)) (is.eq th.dport "8080") accept]
|
|
|
|
[(is.eq ip.protocol (f: f.udp)) (is.eq th.dport "20111") accept]
|
|
|
|
[(is.eq ip.protocol (f: f.tcp)) (is.eq th.dport "27036") accept]
|
|
|
|
[(is.eq ip.protocol (f: f.udp)) (is.eq th.dport (set [27031 27032 27033 27034 27035 27036])) accept];
|
|
|
|
|
|
|
|
output-wlan0 =
|
|
|
|
add chain
|
|
|
|
[(is.ne ip.daddr (secret.network.ips.blowhole.ip or "")) (is.eq ip.protocol (f: with f; set [tcp udp])) (is.eq th.dport 53) drop]
|
|
|
|
[accept];
|
2023-10-07 22:45:51 +02:00
|
|
|
###
|
|
|
|
|
|
|
|
### wlan0
|
2024-02-09 20:03:02 +01:00
|
|
|
input-eth0 =
|
|
|
|
add chain;
|
2023-10-07 22:45:51 +02:00
|
|
|
|
2024-02-09 20:03:02 +01:00
|
|
|
output-eth0 =
|
|
|
|
add chain
|
|
|
|
[(is.ne ip.daddr (secret.network.ips.blowhole.ip or "")) (is.eq ip.protocol (f: with f; set [tcp udp])) (is.eq th.dport 53) drop]
|
|
|
|
[accept];
|
2023-10-07 22:45:51 +02:00
|
|
|
###
|
|
|
|
|
|
|
|
### wg0
|
2024-02-09 20:03:02 +01:00
|
|
|
input-wg0 =
|
|
|
|
add chain
|
2023-10-07 22:45:51 +02:00
|
|
|
# accept syncthing sharing
|
2024-02-09 20:03:02 +01:00
|
|
|
[(is.eq ip.protocol (f: f.udp)) (is.eq th.sport "22000") (is.eq th.dport "22000") accept]
|
|
|
|
[(is.eq ip.protocol (f: f.tcp)) (is.eq th.dport "22000") accept]
|
|
|
|
[(is.eq ip.protocol (f: f.icmp)) accept];
|
2023-10-07 22:45:51 +02:00
|
|
|
|
2024-02-09 20:03:02 +01:00
|
|
|
output-wg0 =
|
|
|
|
add chain
|
2023-10-07 22:45:51 +02:00
|
|
|
# TCP, UDP 53 to blowhole
|
2024-02-09 20:03:02 +01:00
|
|
|
[(is.eq ip.protocol (f: with f; set [udp tcp])) (is.eq th.dport 53) (is.eq ip.saddr (secret.network.ips.omen.vpn or "")) (is.eq ip.daddr (secret.network.ips.blowhole.ip or "")) accept]
|
2023-10-07 22:45:51 +02:00
|
|
|
# TCP 22, 80, 4646, 8200, 8500, 2049 to blowhole
|
2024-02-09 20:03:02 +01:00
|
|
|
[(is.eq ip.protocol (f: with f; set [tcp])) (is.eq th.dport (set [22 80 4646 8200 8500 2049])) (is.eq ip.saddr (secret.network.ips.omen.vpn or "")) (is.eq ip.daddr (secret.network.ips.blowhole.ip or "")) accept]
|
|
|
|
# NFS services to blowhole
|
|
|
|
[(is.eq ip.protocol (f: with f; set [tcp udp])) (is.eq th.dport (set [111 2049 4000 4002 20048])) (is.eq ip.saddr (secret.network.ips.omen.vpn or "")) (is.eq ip.daddr (secret.network.ips.blowhole.ip or "")) accept]
|
2024-03-02 22:00:09 +01:00
|
|
|
# TCP 22, 4646, 8200 toothpick
|
|
|
|
[(is.eq ip.protocol (f: with f; set [tcp])) (is.eq th.dport (set [22 4646 8200])) (is.eq ip.saddr (secret.network.ips.omen.vpn or "")) (is.eq ip.daddr (secret.network.ips.toothpick or "")) accept]
|
2023-10-07 22:45:51 +02:00
|
|
|
# TCP 22 altra
|
2024-02-09 20:03:02 +01:00
|
|
|
[(is.eq ip.protocol (f: with f; set [tcp])) (is.eq th.dport (set [22])) (is.eq ip.saddr (secret.network.ips.omen.vpn or "")) (is.eq ip.daddr (secret.network.ips.altra.ip or "")) accept]
|
2024-03-30 14:52:58 +01:00
|
|
|
# TCP 22 heater
|
|
|
|
[(is.eq ip.protocol (f: with f; set [tcp])) (is.eq th.dport (set [22])) (is.eq ip.saddr (secret.network.ips.omen.vpn or "")) (is.eq ip.daddr (secret.network.ips.heater or "")) accept]
|
2024-04-13 19:38:04 +02:00
|
|
|
[(is.eq ip.protocol (f: with f; set [udp])) (is.eq th.dport (set [2302 2303 2304])) (is.eq ip.saddr (secret.network.ips.omen.vpn or "")) (is.eq ip.daddr (secret.network.ips.heater or "")) accept]
|
2023-10-21 17:46:17 +02:00
|
|
|
# ICMP to blowhole, toothpick, altra
|
2024-02-09 20:03:02 +01:00
|
|
|
[(is.eq ip.protocol (f: f.icmp)) (is.eq ip.saddr (secret.network.ips.omen.vpn or "")) (is.eq ip.daddr (set [(secret.network.ips.toothpick or "") (secret.network.ips.altra.ip or "") (secret.network.ips.blowhole.ip or "")])) accept]
|
|
|
|
[(is.eq ip.protocol (f: f.tcp)) (is.eq th.dport 8883) (is.eq ip.saddr (secret.network.ips.omen.vpn or "")) (is.eq ip.daddr (secret.network.ips.altra.ip or "")) accept]
|
2023-10-07 22:45:51 +02:00
|
|
|
# accept syncthing sharing
|
2024-02-09 20:03:02 +01:00
|
|
|
[(is.eq ip.protocol (f: f.tcp)) (is.eq th.dport 554) (is.eq ip.saddr (secret.network.ips.omen.vpn or "")) (is.eq ip.daddr "10.64.2.128") accept]
|
|
|
|
[(is.eq ip.protocol (f: f.udp)) (is.eq th.sport "22000") (is.eq th.dport "22000") accept]
|
|
|
|
[(is.eq ip.protocol (f: f.tcp)) (is.eq th.dport "22000") accept];
|
2023-10-07 22:45:51 +02:00
|
|
|
###
|
|
|
|
|
2024-02-09 20:03:02 +01:00
|
|
|
input =
|
|
|
|
add chain {
|
|
|
|
type = f: f.filter;
|
|
|
|
hook = f: f.input;
|
|
|
|
prio = -300;
|
|
|
|
policy = f: f.drop;
|
|
|
|
}
|
2023-10-07 22:45:51 +02:00
|
|
|
# accept related, established and drop invalid
|
2024-02-09 20:03:02 +01:00
|
|
|
[
|
|
|
|
(vmap ct.state {
|
|
|
|
established = accept;
|
|
|
|
related = accept;
|
|
|
|
invalid = drop;
|
|
|
|
})
|
|
|
|
]
|
2023-10-07 22:45:51 +02:00
|
|
|
# # accept icmp between the same IP
|
|
|
|
# [ (is.eq ip.protocol (f: f.icmp)) (is.eq ip.daddr ip.saddr) accept ]
|
2024-02-09 20:03:02 +01:00
|
|
|
[(jump "trace")]
|
|
|
|
[(is.eq meta.iifname "wlan0") (jump "input-wlan0")]
|
|
|
|
[(is.eq meta.iifname "eth0") (jump "input-eth0")]
|
|
|
|
[(is.eq meta.iifname "mvm0") (jump "input-mvm")]
|
|
|
|
[(is.eq meta.iifname "lo") (jump "input-lo")]
|
|
|
|
[(is.eq meta.iifname "wg0") (jump "input-wg0")]
|
2024-03-02 22:00:09 +01:00
|
|
|
[(is.eq meta.iifname "uk3s0") (jump "input-uk3s")]
|
2024-03-23 08:31:33 +01:00
|
|
|
[(is.eq meta.iifname "arma3") (jump "input-arma3")]
|
2024-02-09 20:03:02 +01:00
|
|
|
[(is.eq ip.protocol (f: f.icmp)) accept]
|
2023-10-07 22:45:51 +02:00
|
|
|
(logRule "Input");
|
|
|
|
|
2024-02-09 20:03:02 +01:00
|
|
|
output =
|
|
|
|
add chain {
|
|
|
|
type = f: f.filter;
|
|
|
|
hook = f: f.output;
|
|
|
|
prio = -300;
|
|
|
|
policy = f: f.drop;
|
|
|
|
}
|
|
|
|
[(jump "trace")]
|
|
|
|
[(is.eq meta.oifname "wlan0") (jump "output-wlan0")]
|
|
|
|
[(is.eq meta.oifname "eth0") (jump "output-eth0")]
|
|
|
|
[(is.eq meta.oifname "lo") (jump "output-lo")]
|
|
|
|
[(is.eq meta.oifname "mvm0") (jump "output-mvm")]
|
|
|
|
[(is.eq meta.oifname "wg0") (jump "output-wg0")]
|
2024-03-02 22:00:09 +01:00
|
|
|
[(is.eq meta.oifname "uk3s0") (jump "output-uk3s")]
|
2024-03-23 08:31:33 +01:00
|
|
|
[(is.eq meta.oifname "arma3") (jump "output-arma3")]
|
2023-10-07 22:45:51 +02:00
|
|
|
(logRule "Output");
|
|
|
|
|
2024-02-09 20:03:02 +01:00
|
|
|
forward =
|
|
|
|
add chain {
|
|
|
|
type = f: f.filter;
|
|
|
|
hook = f: f.forward;
|
|
|
|
prio = -300;
|
|
|
|
policy = f: f.drop;
|
|
|
|
}
|
|
|
|
[(jump "trace")]
|
2023-10-07 22:45:51 +02:00
|
|
|
# accept masquaraded packets incoming from wg0
|
2024-02-09 20:03:02 +01:00
|
|
|
[
|
2024-03-02 22:00:09 +01:00
|
|
|
(is.eq meta.iifname (set ["wg0" "wlan0" "eth0"]))
|
2024-02-09 20:03:02 +01:00
|
|
|
(vmap ct.state {
|
|
|
|
established = accept;
|
|
|
|
related = accept;
|
|
|
|
})
|
|
|
|
]
|
|
|
|
# accept TCP, UDP 53 from 10.80.1.2 to blowhole
|
|
|
|
[(is.eq meta.iifname "mvm0") (is.eq meta.oifname "wg0") (is.eq ip.protocol (f: with f; set [tcp udp])) (is.eq th.dport 53) (is.eq ip.saddr "10.80.1.2") (is.eq ip.daddr (secret.network.ips.blowhole.ip or "")) accept]
|
2023-10-07 22:45:51 +02:00
|
|
|
# accept TCP, UDP 53 from 10.80.1.2 to blowhole
|
2024-02-09 20:03:02 +01:00
|
|
|
[(is.eq meta.iifname "podman0") (is.eq meta.oifname "wg0") (is.eq ip.protocol (f: with f; set [tcp udp])) (is.eq th.dport 53) (is.eq ip.daddr (secret.network.ips.blowhole.ip or "")) accept]
|
2024-03-23 08:31:33 +01:00
|
|
|
[(is.eq meta.iifname (set ["uk3s0" "arma3"])) (is.eq meta.oifname "wg0") (is.eq ip.protocol (f: with f; set [tcp udp])) (is.eq th.dport 53) (is.eq ip.daddr (secret.network.ips.blowhole.ip or "")) accept]
|
|
|
|
[(is.eq meta.iifname (set ["uk3s0" "arma3"])) (is.eq meta.oifname (set ["wlan0" "eth0"])) accept]
|
2023-10-07 22:45:51 +02:00
|
|
|
(logRule "Forward");
|
|
|
|
|
2024-03-02 22:00:09 +01:00
|
|
|
prerouting =
|
|
|
|
add chain {
|
|
|
|
type = f: f.nat;
|
|
|
|
hook = f: f.prerouting;
|
|
|
|
prio = -199;
|
|
|
|
policy = f: f.accept;
|
|
|
|
}
|
|
|
|
[(jump "trace")];
|
2024-02-09 20:03:02 +01:00
|
|
|
|
|
|
|
postrouting =
|
|
|
|
add chain {
|
|
|
|
type = f: f.nat;
|
|
|
|
hook = f: f.postrouting;
|
|
|
|
prio = -199;
|
|
|
|
policy = f: f.accept;
|
|
|
|
}
|
2024-03-02 22:00:09 +01:00
|
|
|
[(jump "trace")]
|
2023-10-07 22:45:51 +02:00
|
|
|
# masquarade from 10.80.1.2 heading to wg0
|
2024-03-02 22:00:09 +01:00
|
|
|
[(is.eq meta.iifname "mvm0") (is.eq meta.oifname "wg0") (is.eq ip.saddr (set ["10.80.1.2"])) masquerade]
|
|
|
|
[(is.eq meta.iifname "uk3s0") (is.eq meta.oifname "wg0") (is.eq ip.saddr (cidr "10.50.0.0/22")) masquerade]
|
2024-03-23 08:31:33 +01:00
|
|
|
[(is.eq meta.iifname "uk3s0") (is.eq meta.oifname (set ["wlan0" "eth0"])) (is.eq ip.saddr (cidr "10.50.0.0/22")) masquerade]
|
|
|
|
[(is.eq meta.iifname "arma3") (is.eq meta.oifname "wg0") (is.eq ip.saddr (cidr "10.99.99.0/24")) masquerade]
|
|
|
|
[(is.eq meta.iifname "arma3") (is.eq meta.oifname (set ["wlan0" "eth0"])) (is.eq ip.saddr (cidr "10.99.99.0/24")) masquerade];
|
2023-10-07 22:45:51 +02:00
|
|
|
};
|
|
|
|
|
2024-02-09 20:03:02 +01:00
|
|
|
bridge-t = add table {family = f: f.bridge;} {
|
2023-10-07 22:45:51 +02:00
|
|
|
trace = traceChain;
|
|
|
|
|
|
|
|
input-body = add chain;
|
|
|
|
|
2024-02-09 20:03:02 +01:00
|
|
|
input =
|
|
|
|
add chain {
|
|
|
|
type = f: f.filter;
|
|
|
|
hook = f: f.input;
|
|
|
|
prio = f: f.filter;
|
|
|
|
policy = f: f.drop;
|
|
|
|
}
|
|
|
|
[(jump "trace")]
|
|
|
|
[
|
|
|
|
(vmap ct.state {
|
|
|
|
established = accept;
|
|
|
|
related = accept;
|
|
|
|
invalid = drop;
|
|
|
|
})
|
|
|
|
]
|
|
|
|
[(is.eq meta.protocol (f: f.arp)) accept]
|
|
|
|
[(is.eq meta.iifname "veth0") (is.eq ip.daddr (secret.network.ips.blowhole.ip or "")) (is.eq ip.protocol (f: with f; set [tcp udp])) (is.eq th.dport 53) accept]
|
|
|
|
[(jump "input-body")]
|
2023-10-07 22:45:51 +02:00
|
|
|
(logRule "Bridge input");
|
|
|
|
|
|
|
|
output-body = add chain;
|
|
|
|
|
2024-02-09 20:03:02 +01:00
|
|
|
output =
|
|
|
|
add chain {
|
|
|
|
type = f: f.filter;
|
|
|
|
hook = f: f.output;
|
|
|
|
prio = f: f.out;
|
|
|
|
policy = f: f.drop;
|
|
|
|
}
|
|
|
|
[(jump "trace")]
|
|
|
|
[(is.eq ether.type (f: f.arp)) accept]
|
|
|
|
[(jump "output-body")]
|
|
|
|
[(is.eq ip.daddr (cidr "10.88.0.0" 16)) (is.eq ip.saddr (cidr "10.88.0.0" 16)) accept]
|
2023-10-07 22:45:51 +02:00
|
|
|
(logRule "Bridge output");
|
|
|
|
|
|
|
|
forward-body = add chain;
|
|
|
|
|
2024-02-09 20:03:02 +01:00
|
|
|
forward =
|
|
|
|
add chain {
|
|
|
|
type = f: f.filter;
|
|
|
|
hook = f: f.forward;
|
|
|
|
prio = f: f.filter;
|
|
|
|
policy = f: f.drop;
|
|
|
|
}
|
|
|
|
[(jump "trace")]
|
|
|
|
[(jump "forward-body")]
|
2023-10-07 22:45:51 +02:00
|
|
|
(logRule "Bridge forward");
|
|
|
|
|
2024-02-09 20:03:02 +01:00
|
|
|
prerouting = add chain {
|
|
|
|
type = f: f.filter;
|
|
|
|
hook = f: f.prerouting;
|
|
|
|
prio = f: f.dstnat;
|
|
|
|
policy = f: f.accept;
|
|
|
|
};
|
|
|
|
|
|
|
|
postrouting = add chain {
|
|
|
|
type = f: f.filter;
|
|
|
|
hook = f: f.postrouting;
|
|
|
|
prio = f: f.srcnat;
|
|
|
|
policy = f: f.accept;
|
|
|
|
};
|
2023-10-07 22:45:51 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|