sqm: Replace iptables marking with nftables#190
Conversation
|
Thank you for the patch. Did you test these changes, and if so, how? On OpenWrt, I presume? :) |
|
Yes, on openwrt. I tested |
|
this would break things for everyone who uses iptables. |
| if [ "$ZERO_DSCP_INGRESS" = "1" ]; then | ||
| sqm_debug "Squashing differentiated services code points (DSCP) from ingress." | ||
| ipt -t mangle -I PREROUTING -i $IFACE -m dscp ! --dscp 0 -j DSCP --set-dscp-class be | ||
| nft_rule " iifname \"${IFACE}\" ip dscp != cs0 ip dscp set cs0" |
There was a problem hiding this comment.
use iif ipo iifname, tc interface is totally fixed, no need to strlen() + strcmp() for each packet.
probably pre-pend meta nfproto ipv[4|6] , not visible in read-back but entered in kernel to skip unnecessary "heavy lifting" before ipX dscp for "other" protocol....
| nft_rule " }" | ||
| nft_rule " chain output {" | ||
| nft_rule " type filter hook output priority mangle; policy accept;" | ||
| nft_rule " udp dport { 123, 53 } ip dscp set af42" |
There was a problem hiding this comment.
skip payload expression by using conntrack meta 16-bits
meta nfproto ipv4 meta l4proto udp ct original proto-dst { 123 , 53 } ip dscp ...
There was a problem hiding this comment.
Thanks. I’ll update the fixed interface matches to use iif/oif, keep iifname only for the wildcard case, and add the explicit nfproto guards around the DSCP rules.
I’ll also the conntrack form for the udp output rule and retest it.
There was a problem hiding this comment.
Proposed
family 1 __set%d t 0
element 00007b00 : 0 [end] element 00003500 : 0 [end]
inet t c
[ meta load nfproto => reg 1 ]
[ cmp eq reg 1 0x00000002 ]
[ meta load l4proto => reg 1 ]
[ cmp eq reg 1 0x00000011 ]
[ ct load proto_dst => reg 1 , dir original ]
[ lookup reg 1 set __set%d ]
[ payload load 1b @ network header + 1 => reg 1 ]
[ bitwise reg 1 = ( reg 1 & 0x000000fc ) ^ 0x00000000 ]
[ cmp eq reg 1 0x00000000 ]
Current
family 1 __set%d t 0
element 00007b00 : 0 [end] element 00003500 : 0 [end]
inet t c
[ meta load l4proto => reg 1 ]
[ cmp eq reg 1 0x00000011 ]
[ payload load 2b @ transport header + 2 => reg 1 ]
[ lookup reg 1 set __set%d ]
[ meta load nfproto => reg 1 ] ^^^ till here unnecessary payload expression
[ cmp eq reg 1 0x00000002 ]
[ payload load 1b @ network header + 1 => reg 1 ]
[ bitwise reg 1 = ( reg 1 & 0x000000fc ) ^ 0x00000000 ]
[ cmp eq reg 1 0x00000000 ]
There was a problem hiding this comment.
Oh nice, I didn’t know about nft -c -d netlink -f. Thanks for pointing that out.
I checked the generated form and updated the output rules so meta nfproto comes before the UDP/ct match.
62b4b09 to
781d74d
Compare
@yhaenggi Fair point. I originally leaned toward adding nftables while keeping iptables as fallback. I made this version nft-only based on the earlier discussion here: openwrt/packages#29830 (comment) |
|
@yhaenggi addressing undefined ordering (set priority after default mangle hoks) nftables script can coexist with legacy tables, hope adding of nftables requirement is not a huge weight to carry. |
|
@tohojo question about porting tos 4 - should it be 8 ranges or X known dscp codepoints falling in them? |
|
@dhrm1k ill check back later when you get around my first sweep |
wait, your comment makes me think, you are under the impression we have kept legacy iptables intact in the code. is that the case? no, i ported it entirely to nft. |
|
Got it, I misunderstood your point. You mean even with the script fully nft-based, the hook priority should be explicit so it does not race fw4 or legacy hooks. |
Yes, exactly. There is no problem under normal usage, but 2 days into uptime some hotplug event reloads one or other firewall table and packets start running into matrix unexplainably. |
781d74d to
b9a4757
Compare
|
As much as fixed so far - perfect.
|
Replace the iptables-based marking setup with native nftables rules. This keeps the existing tc fw filter model, but uses nftables to install packet marks. Signed-off-by: dharmik <dharmikparmar2004@yahoo.com>
b9a4757 to
cc5c10e
Compare
|
@tohojo what’s your take? |
|
this is still pending.
|
Replace the iptables-based marking setup with native nftables rules.
This keeps the existing tc fw filter model, but uses nftables to install packet marks.