casaroli opened a new pull request, #4149: URL: https://github.com/apache/nuttx-apps/pull/4149
depends-on: apache/nuttx#22367 ## Summary apache/nuttx#22367 adds the TCP flags match and the `limit` match of iptables to the kernel filter. The `iptables` and `ip6tables` commands cannot make such a rule: they ignore `--syn` and `-m limit`, so `iptables -A INPUT -p tcp --syn -m limit --limit 5/s -j ACCEPT` becomes a rule that accepts all TCP packets. This PR adds the options of Linux iptables: - `[!] --tcp-flags mask comp` and `[!] --syn` (`--tcp-flags SYN,RST,ACK,FIN SYN`). They set `flg_mask` and `flg_cmp` of `struct xt_tcp`. A rule with TCP flags and no port also gets a TCP match. - `-m limit`, `--limit rate[/second|minute|hour|day]`, `--limit-burst number`, with the defaults of Linux (3/hour, burst 5). netlib gets `netlib_ipt_filter_entry_limit()` and `netlib_ip6t_filter_entry_limit()`: a limit alone, or a limit after a TCP match. A limit after a UDP or ICMP match gives an error message. `--limit` without `-m limit` gives an error message. - `iptables -L` and `ip6tables -L` show all matches of a rule, with the TCP flags and the rate (in the unit that Linux iptables would print). - A first commit adds a blank line that nxstyle asks for in `iptables_utils.c` (no code change; the CI checks the whole file). ## Impact Only `system/iptables` and the iptables part of netlib (with `CONFIG_NET_IPFILTER`). The existing options and rules do not change. ## Testing With apache/nuttx#22367, on qemu-armv8a:nsh (flat, QEMU TCG, TUN device), NuttX CI image, `-Werror`: ``` nsh> iptables -A INPUT -p tcp --syn -m limit --limit 5/s --limit-burst 10 -j ACCEPT nsh> iptables -A INPUT -p tcp --syn -j DROP nsh> iptables -L INPUT Chain INPUT (policy ACCEPT) target prot idev odev source destination ACCEPT tcp any any anywhere anywhere tcp spts:0:65535 dpts:0:65535 flags:0x17/0x02 limit: avg 5/second burst 10 DROP tcp any any anywhere anywhere tcp spts:0:65535 dpts:0:65535 flags:0x17/0x02 ``` - 2000 SYNs from spoofed sources, written to the TUN device: with `--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 apache/nuttx#22367. - `--tcp-flags SYN,ACK SYN,ACK`, `--dport 5025 --syn`, `! --syn`, `! --tcp-flags ALL NONE`, `-p udp -m limit --limit 3/minute`, `-m limit` alone (3/hour, burst 5), `ip6tables ... --syn -m limit --limit 2/s`, and `-D` with the same rule: the expected rules in `-L`. - Errors: `-p udp --dport 53 -m limit`, `--limit` without `-m limit`, `-p udp --syn`, `--limit-burst 0`, `--limit 20000/s`, an unknown TCP flag. - Builds with `-Werror`: qemu-armv8a:netnsh (IPv4 + IPv6, and IPv4 only), qemu-armv8a:knsh and rv-virt:knetnsh64 (apps imported into the kernel builds), rv-virt:netnsh64. - `tools/checkpatch.sh -c -u -m -g`: pass. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
