This is an automated email from the ASF dual-hosted git repository. acassis pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 67dcf1209b409e7bb656e53ea340077ce7bf7f18 Author: Marco Casaroli <[email protected]> AuthorDate: Thu Nov 26 05:13:46 2026 +0100 Documentation: Describe the TCP flags and limit matches of iptables. The IP packet filter page and the iptables and ip6tables pages now describe --tcp-flags, --syn, -m limit, --limit and --limit-burst, with an example that limits new TCP connections. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]> --- .../applications/system/ip6tables/index.rst | 41 ++++++++++++++++++++++ .../applications/system/iptables/index.rst | 40 +++++++++++++++++++++ Documentation/os/networking/ipfilter.rst | 24 ++++++++++++- 3 files changed, 104 insertions(+), 1 deletion(-) diff --git a/Documentation/applications/system/ip6tables/index.rst b/Documentation/applications/system/ip6tables/index.rst index cb928751ea8..57de193bcb6 100644 --- a/Documentation/applications/system/ip6tables/index.rst +++ b/Documentation/applications/system/ip6tables/index.rst @@ -106,6 +106,36 @@ Options valid with ``-p icmp6`` (or ``-p icmpv6``, ``-p ipv6-icmp``). The ``!`` argument inverts the match. +``[!] --tcp-flags mask comp`` + TCP flags specification. ``mask`` is a comma separated list of the + flags to examine. ``comp`` is the list of the flags of ``mask`` that + must be set; the other flags of ``mask`` must be clear. The flags + are ``SYN``, ``ACK``, ``FIN``, ``RST``, ``URG`` and ``PSH``, in upper + or lower case; ``ALL`` and ``NONE`` are also accepted. Only valid + with ``-p tcp``. The ``!`` argument inverts the match. + +``[!] --syn`` + Match only TCP packets with SYN set and ACK, RST and FIN clear (the + first packet of a connection). The same as + ``--tcp-flags SYN,RST,ACK,FIN SYN``. + +``-m, --match limit`` + Add a rate limit to the rule: the rule matches at most ``--limit`` + packets on average, with bursts of up to ``--limit-burst`` packets. + Over the rate, the rule does not match and the next rule applies. + The limit can be used alone or with a TCP, UDP or ICMP match. Each + rule has its own count, which starts again when the table changes. + The ``!`` argument is not accepted before ``-m``, ``--limit`` and + ``--limit-burst``. + +``--limit rate[/second|/minute|/hour|/day]`` + Average rate of the limit match (default: ``3/hour``). The unit can + be abbreviated (``5/s``); without a unit, the rate is per second. + +``--limit-burst number`` + Number of packets that can match at once, from 1 to 10000 (default: + ``5``). + ``!`` Inverts the following match criterion. @@ -154,6 +184,17 @@ Use negation to match all protocols except TCP: nsh> ip6tables -A INPUT ! -p tcp -j ACCEPT +Accept at most 5 new TCP connections per second (bursts of 10), and drop +the other SYN packets: + +.. code-block:: text + + nsh> ip6tables -A INPUT -p tcp --syn -m limit --limit 5/s --limit-burst 10 -j ACCEPT + nsh> ip6tables -A INPUT -p tcp --syn -j DROP + +A rule with a limit is long: set ``CONFIG_NSH_LINELEN`` and +``CONFIG_NSH_MAXARGUMENTS`` large enough for it. + See Also ======== diff --git a/Documentation/applications/system/iptables/index.rst b/Documentation/applications/system/iptables/index.rst index 7f92715340d..7ee809cba15 100644 --- a/Documentation/applications/system/iptables/index.rst +++ b/Documentation/applications/system/iptables/index.rst @@ -112,6 +112,36 @@ Options ICMP type specification. Can be a numeric type (0-255). Only valid with ``-p icmp``. The ``!`` argument inverts the match. +``[!] --tcp-flags mask comp`` + TCP flags specification. ``mask`` is a comma separated list of the + flags to examine. ``comp`` is the list of the flags of ``mask`` that + must be set; the other flags of ``mask`` must be clear. The flags + are ``SYN``, ``ACK``, ``FIN``, ``RST``, ``URG`` and ``PSH``, in upper + or lower case; ``ALL`` and ``NONE`` are also accepted. Only valid + with ``-p tcp``. The ``!`` argument inverts the match. + +``[!] --syn`` + Match only TCP packets with SYN set and ACK, RST and FIN clear (the + first packet of a connection). The same as + ``--tcp-flags SYN,RST,ACK,FIN SYN``. + +``-m, --match limit`` + Add a rate limit to the rule: the rule matches at most ``--limit`` + packets on average, with bursts of up to ``--limit-burst`` packets. + Over the rate, the rule does not match and the next rule applies. + The limit can be used alone or with a TCP, UDP or ICMP match. Each + rule has its own count, which starts again when the table changes. + The ``!`` argument is not accepted before ``-m``, ``--limit`` and + ``--limit-burst``. + +``--limit rate[/second|/minute|/hour|/day]`` + Average rate of the limit match (default: ``3/hour``). The unit can + be abbreviated (``5/s``); without a unit, the rate is per second. + +``--limit-burst number`` + Number of packets that can match at once, from 1 to 10000 (default: + ``5``). + ``!`` Inverts the following match criterion. @@ -166,3 +196,13 @@ Use negation to match all protocols except TCP: nsh> iptables -A INPUT ! -p tcp -j ACCEPT +Accept at most 5 new TCP connections per second (bursts of 10), and drop +the other SYN packets: + +.. code-block:: text + + 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 + +A rule with a limit is long: set ``CONFIG_NSH_LINELEN`` and +``CONFIG_NSH_MAXARGUMENTS`` large enough for it. diff --git a/Documentation/os/networking/ipfilter.rst b/Documentation/os/networking/ipfilter.rst index a69bcb99eab..73746d7fe06 100644 --- a/Documentation/os/networking/ipfilter.rst +++ b/Documentation/os/networking/ipfilter.rst @@ -5,7 +5,7 @@ IP Packet Filter NuttX supports IP packet filter (firewall) compatible with Linux's iptables and netfilter. It is a stateless packet filter that can be used to filter packets based on source and destination IP addresses, source and destination ports, -protocol, and interface. +protocol, TCP flags, and interface. A rule can also have a rate limit. Workflow ======== @@ -79,6 +79,11 @@ The following examples show the commands we support: port[:port] Destination port [!] --icmp-type type ICMP type [!] --icmpv6-type type ICMPv6 type + [!] --tcp-flags mask comp TCP flags (SYN,ACK,FIN,RST,URG,PSH,ALL,NONE) + [!] --syn TCP SYN (--tcp-flags SYN,RST,ACK,FIN SYN) + --match -m limit Match a packet rate + --limit rate[/unit] Packets per s, m, h or d (default: 3/hour) + --limit-burst number Packets that can come at once (default: 5) .. code-block:: shell @@ -123,3 +128,20 @@ The following examples show the commands we support: Chain OUTPUT (policy ACCEPT) target prot idev odev source destination + +A rule can match TCP flags (``--tcp-flags``, ``--syn``) and can have a rate +limit (``-m limit``). The filter keeps one token bucket per rule: the rule +matches at most ``--limit`` packets on average, and up to ``--limit-burst`` +packets at once. A packet over the rate does not match the rule, and the next +rule of the chain applies. The bucket is full again after each change of the +table. The limit works alone or after a TCP, UDP or ICMP match. + +.. code-block:: shell + + > iptables -A INPUT -p tcp --syn -m limit --limit 5/s --limit-burst 10 -j ACCEPT + > iptables -A INPUT -p tcp --syn -j DROP + > 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
