Repository navigation
Conversation
Add the blank line after a declaration that nxstyle asks for. No code change. The next commit changes this file, and the CI runs nxstyle on the whole file. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
|
Thanks! The layout of the two new entry structs matches what 1.
2. TCP flag names ( Linux iptables accepts flag names in any case ( 3. Limit after a UDP or ICMP match (
4. Small things
5. Merge order This PR needs |
The kernel filter can match TCP flags and a packet rate, but the iptables and ip6tables commands cannot make such a rule. Add these options of Linux iptables: - --tcp-flags mask comp: the TCP flags to examine and the value that they must have. --syn is "--tcp-flags SYN,RST,ACK,FIN SYN". Both set flg_mask and flg_cmp of struct xt_tcp. A rule with TCP flags and no port now also gets a TCP match. As in Linux, the flag names can be in upper or lower case, and ALL and NONE can be items of the list. - -m limit, --limit rate[/unit], --limit-burst number: a limit match (struct xt_rateinfo), with the defaults of Linux (3/hour, burst 5). The layout of an entry is fixed when it is allocated, so netlib gets netlib_ipt_filter_entry_limit() and netlib_ip6t_filter_entry_limit(). They make a limit alone or a limit after a TCP, UDP or ICMP match. As in Linux, "!" before -m, --limit or --limit-burst gives an error. iptables -L and ip6tables -L now show all matches of a rule, with the TCP flags and the rate. netlib now starts each match and the target of an entry at an offset that is a multiple of XT_ALIGN(), as Linux iptables does. So each match_size is a multiple of XT_ALIGN(), which the kernel checks. Before, a TCP or UDP match had a match_size of 52 on 64-bit targets. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
7b46c3a to
f015bfa
Compare
|
Done. |
Summary
apache/nuttx#22367 adds the TCP flags match and the
limitmatch of iptables to the kernel filter. Theiptablesandip6tablescommands cannot make such a rule: they ignore--synand-m limit, soiptables -A INPUT -p tcp --syn -m limit --limit 5/s -j ACCEPTbecomes a rule that accepts all TCP packets.This PR adds the options of Linux iptables:
[!] --tcp-flags mask compand[!] --syn(--tcp-flags SYN,RST,ACK,FIN SYN). They setflg_maskandflg_cmpofstruct xt_tcp. A rule with TCP flags and no port also gets a TCP match. As in Linux, the flag names can be in upper or lower case, andALLandNONEcan be items of the list. The tool defines the six flag values itself (no kernel header).-m limit,--limit rate[/second|minute|hour|day],--limit-burst number, with the defaults of Linux (3/hour, burst 5). netlib getsnetlib_ipt_filter_entry_limit()andnetlib_ip6t_filter_entry_limit(): a limit alone, or a limit after a TCP, UDP or ICMP match.--limitwithout-m limitgives an error message. As in Linux,!before-m,--limitor--limit-burstgives an error message.XT_ALIGN(), as Linux iptables does. So eachmatch_sizeandtarget_sizeis a multiple ofXT_ALIGN(), which net/ipfilter: Match TCP flags and a packet rate. nuttx#22367 checks. Before, a TCP or UDP match had 52 bytes on 64-bit targets (now 56).iptables -Landip6tables -Lshow all matches of a rule, with the TCP flags and the rate (in the unit that Linux iptables would print).iptables_utils.c(no code change; the CI checks the whole file).Impact
Only
system/iptablesand the iptables part of netlib (withCONFIG_NET_IPFILTER). The existing options and rules do not change.Testing
With apache/nuttx#22367, on qemu-armv8a:nsh (flat, QEMU TCG, TUN device), Arm GNU 13.2.Rel1,
-Werror:--limit 150/s --limit-burst 10, 1521 SYNs pass; without the rule 2000 pass. With nuttx-apps master the same commands make a rule that accepts all TCP packets, and all 2000 SYNs pass. Details in net/ipfilter: Match TCP flags and a packet rate. nuttx#22367.--tcp-flags SYN,ACK SYN,ACK,--tcp-flags syn,ack SYN,--tcp-flags Syn,ALL none,--dport 5025 --syn,! --syn,! --tcp-flags ALL NONE,-p udp -m limit --limit 7/hour,-p udp --dport 53 -m limit --limit 3/s,-p icmp --icmp-type 8 -m limit --limit 1/s,-m limitalone (3/hour, burst 5),ip6tables ... --syn -m limit --limit 2/s,ip6tables -p icmp6 --icmpv6-type 128 -m limit --limit 1/s,ip6tables -p udp --dport 53 -m limit, and-Dwith the same rule: the expected rules in-L.-p tcp ! --tcp-flags NONE NONE -j DROPmakes the ruleflags:!0x00/0x00, and a TCP connection over the loopback still works (the rule matches no packet, as in Linux).! -m limit,-m limit ! --limit 5/s,-m limit ! --limit-burst 5,--limitwithout-m limit,-p udp --syn,--limit-burst 0,--limit 20000/s, an unknown TCP flag.match_size,target_offset,target_sizeandnext_offsetthat are multiples ofXT_ALIGN()(8) on qemu-armv8a, qemu-armv7a and rv-virt (64-bit).-Werror: qemu-armv8a:netnsh (IPv4 + IPv6, and IPv4 only), qemu-armv8a:knsh (apps imported), qemu-armv7a:nsh (Arm GNU 13.2.Rel1); rv-virt:netnsh64, rv-virt:knetnsh64 (apps imported) and qemu-armv8a:netnsh (NuttX CI image).tools/checkpatch.sh -c -u -m -g: pass.