Hi all,
So I have some code which generates geoip rules for nftables. This is basically the nftables-facing part of the geoip project I'm developing.
I'm just getting to know nftables, so I'd like to show you guys some samples of resulting rules and see if you think that they do what they are supposed to do, and if anyone has ideas for improvement.
First, a short description, for the uninitiated.
The code works in either whitelist mode or blacklist mode.
Rules are created based on user-specified parameters.
One of these parameters is defining the device the code runs on as a router or as a host.
(the project aims to support both options and to work on OpenWRT and non-OpenWRT devices)
For a router, rules are applied to connections arriving from the WAN interfaces.
For a host, rules are applied to all incoming connections. For a host, when in whitelist mode, exceptions are added for trusted LAN subnets.
Here are the resulting rules:
router: whitelist
Summary
table inet geoip-shell {
set NL_ipv4_2024-02-04_geoip-shell {
type ipv4_addr
policy memory
flags interval
auto-merge
}
set NL_ipv6_2024-02-04_geoip-shell {
type ipv6_addr
policy memory
flags interval
auto-merge
}
chain GEOIP-BASE {
type filter hook prerouting priority mangle; policy accept;
jump GEOIP-SHELL comment "geoip-shell_main"
}
chain GEOIP-SHELL {
iifname { "eth1", "eth2" } ip saddr @NL_ipv4_2024-02-04_geoip-shell accept
iifname { "eth1", "eth2" } ip6 saddr @NL_ipv6_2024-02-04_geoip-shell accept
iifname { "eth1", "eth2" } ct state established,related accept comment "geoip-shell_aux-rel-est"
iifname { "eth1", "eth2" } drop comment "geoip-shell_whitelist_block"
}
}
router: blacklist
Summary
table inet geoip-shell {
set NL_ipv4_2024-02-04_geoip-shell {
type ipv4_addr
policy memory
flags interval
auto-merge
}
set NL_ipv6_2024-02-04_geoip-shell {
type ipv6_addr
policy memory
flags interval
auto-merge
}
chain GEOIP-BASE {
type filter hook prerouting priority mangle; policy accept;
jump GEOIP-SHELL comment "geoip-shell_main"
}
chain GEOIP-SHELL {
iifname { "eth1", "eth2" } ip saddr @NL_ipv4_2024-02-04_geoip-shell drop
iifname { "eth1", "eth2" } ip6 saddr @NL_ipv6_2024-02-04_geoip-shell drop
iifname { "eth1", "eth2" } ct state established,related accept comment "geoip-shell_aux-rel-est"
}
}
host: whitelist
Summary
table inet geoip-shell {
set NL_ipv4_2024-02-04_geoip-shell {
type ipv4_addr
policy memory
flags interval
auto-merge
}
set NL_ipv6_2024-02-04_geoip-shell {
type ipv6_addr
policy memory
flags interval
auto-merge
}
set geoip-shell_lansubnets_ipv4 {
type ipv4_addr
flags interval
auto-merge
}
set geoip-shell_lansubnets_ipv6 {
type ipv6_addr
flags interval
auto-merge
}
chain GEOIP-BASE {
type filter hook prerouting priority mangle; policy accept;
jump GEOIP-SHELL comment "geoip-shell_main"
}
chain GEOIP-SHELL {
iifname "lo" accept comment "geoip-shell_aux-loopback"
ip saddr @geoip-shell_lansubnets_ipv4 accept comment "geoip-shell_aux-lansubnet"
ip6 saddr @geoip-shell_lansubnets_ipv6 accept comment "geoip-shell_aux-lansubnet"
ip saddr @NL_ipv4_2024-02-04_geoip-shell accept
ip6 saddr @NL_ipv6_2024-02-04_geoip-shell accept
ct state established,related accept comment "geoip-shell_aux-rel-est"
drop comment "geoip-shell_whitelist_block"
}
}
host: blacklist
Summary
table inet geoip-shell {
set NL_ipv4_2024-02-04_geoip-shell {
type ipv4_addr
policy memory
flags interval
auto-merge
}
set NL_ipv6_2024-02-04_geoip-shell {
type ipv6_addr
policy memory
flags interval
auto-merge
}
chain GEOIP-BASE {
type filter hook prerouting priority mangle; policy accept;
jump GEOIP-SHELL comment "geoip-shell_main"
}
chain GEOIP-SHELL {
ip saddr @NL_ipv4_2024-02-04_geoip-shell drop
ip6 saddr @NL_ipv6_2024-02-04_geoip-shell drop
ct state established,related accept comment "geoip-shell_aux-rel-est"
}
}
Bonus question: which rules do you think is worth having a counter on?
