Hi,
ATM I'm still stuck with OpenWrt 21.x.x on a D-Link DIR-860L B1 and since I noticed some developments with the possibility to add a custom firewall in OpenWrt 23.x.x I considered to switch to the latter.
Reference:
Now, since I'm very comfortable with iptables, have more than 2 decades of system/network admin experience (that's accustomed with laggy remote shells/terminals, rather dumb editors like vi in which you don't really look to produce fancy accolades indentations ... and happy to parse, understand and resolve network & firewall syntax issues fast, advocating to leave the utterly inefficient love poems syntax to the poets) and not a developer/coder like oshenders - see Reflections:
I tried to use iptables-nft for my custom rules (script), knowing that it should be compatible (nftables documentation) - Section: using the nf_tables compat backend:
https://wiki.nftables.org/wiki-nftables/index.php/Moving_from_iptables_to_nftables
and failed pretty bad at it in OpenWrt 23.05.2.
I didn't want to mess up the main OpenWrt 21.x.x on a D-Link DIR-860L B1 and used a spare TP-Link TL-WR841N v13 loaded with OpenWrt 23.05.2 as guinea pig. Hooked it on WAN to the main D-Link DIR-860L B1 in a double-NAT fashion - D-Link DIR-860L B1 is on 192.168.1.0 and TP-Link TL-WR841N v13 on 192.168.2.0
To recap, all the tests were done on a TP-Link TL-WR841N v13 loaded with OpenWrt 23.05.2 and configured in a Routed AP fashion.
In this forum I learned that I would need some additional packages to make iptables-nft work and installed the following:
opkg install iptables-nft
opkg install ip6tables-nft
opkg install kmod-ipt-conntrack
opkg install kmod-ipt-nat
Before "translating" my old OpenWrt 21.x.x iptables custom ruleset into iptables-nft, I started to test some rules in a ssh console on the router. For example, I defined 2 generic rules to allow the traffic on tcp port 9999 (Kodi Remote - KORE App) originating from my phone over WiFi to access a station connected to the LAN (Kodi Player) - note that the router was configured in Routed AP mode (LAN/WiFi split and forward traffic dropped inLuCi-Firewall Settings).
The rules:
/usr/sbin/iptables-nft -I FORWARD -i phy0-ap0 -o br-lan -p tcp -s 0/0 --destination-port 9999 -j ACCEPT
/usr/sbin/iptables-nft -I FORWARD -i br-lan -o phy0-ap0 -p tcp -d 0/0 --source-port 9999 -j ACCEPT
Well, it didn't work and I started to investigate. Launched tcpdump on both OpenWRT and the Kodi station (LAN) and learned that the packets were coming over WiFi into the router, were forwarded to the LAN station, the LAN station replied and the replies were dumped by the router (didn't hit my second rule). Cool!
Furthermore, found out that iptables-nft creates its own table "ip filter" and doesn't really add/delete rules in/from the OpenWRT defined table "inet fw4". Again, just wonderful.
Now, I could see the packets (counters) coming from WiFi hitting the first rule in the ip filter table, but the second rule counters were all on 0. My guess is that the replies were dropped in the rules from within the table inet fw4.
I didn't investigate further because my eyes were hurting, zig-zaging through that rather uninspired unindented output of "nft list table inet fw4/ip filter & nft list chain * "
Also important, with just a few (less than a dozen) of these iptables-nft rules, the throughput of the router dropped from 100Mbps to ~12Mbps (both uplink/downlink) - noticed it while performing a speed test (speedtest.net) through it.
In some posts and on github (OpenWRT related) I found some additional packages that I also installed (never know what I might need in my future firewalls), apparently without any positive results.
List:
opkg install iptables-mod-filter
opkg install iptables-mod-conntrack-extra
opkg install kmod-ipt-ipset
opkg install iptables-mod-nfqueue
opkg install kmod-ipt-nat6
opkg install kmod-ipt-ipopt
opkg install kmod-ipt-compat-xtables
opkg install kmod-ipt-condition
opkg install kmod-ipt-extra
opkg install kmod-ipt-iface
opkg install kmod-ipt-ipmark
opkg install kmod-ipt-iprange
opkg install kmod-ipt-ipv4options
opkg install kmod-ipt-nat-extra
opkg install kmod-ipt-physdev
opkg install kmod-ipt-proto
opkg install kmod-ipt-raw
opkg install kmod-ipt-raw6
opkg install kmod-ipt-rpfilter
opkg install kmod-ipt-socket
opkg install kmod-ipt-sysrq
opkg install kmod-ipt-tproxy
Added a little masochism to my approach and started to consider that if I can't beat nftables, well, let's embrace that abomination. I could always use iptables-translate to please OpenWrt
iptables-translate doesn't always output 100% nft compatible/native syntax and some fine tuning is required on complex iptables statements (had a few in a ~ 200 lines ruleset).
But then, another proof that the folks behind nftables do not appear to have much sys/net admin field experience given how inconsistent and incompatible with shells the syntax is (brackets, & signs, then pipes and then curly brackets). Had to escape a lot for pleasing the ash shell - a small snippet from a block of traffic integrity check I always use (not just drop inconsistent packets but also inconsistent traffic):
# brackets and pipes for flags series
/usr/sbin/nft insert rule inet fw4 input tcp flags \& \(fin\|syn\|rst\|psh\|ack\|urg\) == fin\|syn\|rst\|psh\|ack\|urg counter drop
/usr/sbin/nft insert rule inet fw4 input tcp flags \& \(fin\|syn\|rst\|psh\|ack\|urg\) == fin\|psh\|urg counter drop
/usr/sbin/nft insert rule inet fw4 input tcp flags \& \(fin\|syn\|rst\|psh\|ack\|urg\) == fin\|syn\|rst\|ack\|urg counter drop
# and then comma separation and curly brackets for port series ..wtf
/usr/sbin/nft insert rule inet fw4 forward iifname "phy0-ap0" oifname "br-lan" ip protocol tcp ip saddr 192.168.10.101 tcp dport { 111,2049,32765,32766,32767,32768,32769} counter accept
Finally, all works (apparently) as expected with my nft ruleset and the custom script triggered from within the firewall conf file, only issue is that by adding a bunch of these nft rules (around 50 from about a total of 200) I loose around 50% of the throughput - speedtest reports ~ 52Mbps.
Commented most of the 50 rules, left with a dozen and I still lose around 30% of the throughput.
Worth noting that on this router with OpenWrt 21.x.x and the full iptables ruleset (200 lines) I lose around 3-5Mbps (speedtest result ~96Mbps).
Now, my only question is simple:
- while OpenWrt 22.x.x looks useless, there is OpenWrt 23.x.x as the latest and greatest with all these (dis) functionalities embedded, would it be possible to still maintain (security patches only) OpenWrt 21.x.x - the "Last Action Hero" for a while?
I'd be really thankful for such an effort and kindness and I really mean it. Reading many of the posts here I started to become confident that you'll also make a lot of other users happy while still supporting iptables.
Thanks!