]> git.ipfire.org Git - thirdparty/iproute2.git/commit
tc: nat: Fix mask calculation
authorTorben Nielsen <t8927095@gmail.com>
Thu, 6 Mar 2025 11:25:19 +0000 (12:25 +0100)
committerStephen Hemminger <stephen@networkplumber.org>
Wed, 12 Mar 2025 18:19:53 +0000 (11:19 -0700)
commit667817b4c34944175deaf6ca9aa3afdf5b668fc5
treec7cf09dd80d1b5d31b1e99a3be526793ba683801
parente3f9681d4a777fb2595a322b421abf0036ab1aae
tc: nat: Fix mask calculation

In parse_nat_args the network mask is calculated as

        sel->mask = htonl(~0u << (32 - addr.bitlen));

According to  ISO/IEC 9899:TC3 6.5.7 Bitwise shift operators:
The integer promotions are performed on each of the operands.
The type of the result is that of the promoted left operand.
If the value of the right operand is negative or is greater
than or equal to the width of the promoted left operand,
the behavior is undefined

Specifically this means that the mask is undefined for
addr.bitlen = 0
On x86_64 the result is 0xffffffff, on armv7l it is 0.

Promoting the left operand of the shift operator solves this issue.

Signed-off-by: Torben Nielsen <torben.nielsen@prevas.dk>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
tc/m_nat.c