All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mohsin Bashir <mohsin.bashr@gmail.com>
To: netdev@vger.kernel.org
Cc: andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org,
	kuba@kernel.org, pabeni@redhat.com, shuah@kernel.org,
	linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH net-next 05/11] selftests: drv-net: tc_flower_police: Test destination prefix rules
Date: Thu,  3 Dec 2026 16:05:15 -0800	[thread overview]
Message-ID: <20261204000521.3396802-6-mohsin.bashr@gmail.com> (raw)
In-Reply-To: <20261204000521.3396802-1-mohsin.bashr@gmail.com>

From: Mohsin Bashir <hmohsin@meta.com>

Flower can also match on a destination prefix. A device that ignores
the mask, or applies a longer one, polices only part of the prefix. Add
police_dst_prefix to verify that a /120 rule limits traffic to an address
in the upper half of the prefix and leaves traffic outside it alone.

The test skips if LOCAL_PREFIX_V6 is longer than /120 or the device
rejects the rule.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Mohsin Bashir <hmohsin@meta.com>
---
 .../drivers/net/hw/tc_flower_police.py        | 35 ++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/drivers/net/hw/tc_flower_police.py b/tools/testing/selftests/drivers/net/hw/tc_flower_police.py
index b42ed22419ad..cdff5cb6b6a3 100755
--- a/tools/testing/selftests/drivers/net/hw/tc_flower_police.py
+++ b/tools/testing/selftests/drivers/net/hw/tc_flower_police.py
@@ -298,6 +298,38 @@ def police_isolation(cfg):
     _check_unpoliced(got, RATE_MBIT, "other address")
 
 
+def police_dst_prefix(cfg):
+    """
+    Check that a destination prefix rule polices traffic to an address in
+    the prefix and leaves traffic to an address outside it alone.
+    """
+    _setup_clsact(cfg)
+    if _local_prefix(cfg).prefixlen > 120:
+        raise KsftSkipEx("LOCAL_PREFIX_V6 longer than /120")
+    dst = _add_secondary_addr(cfg,
+                              lambda a: int(ipaddress.IPv6Address(a)) & 0x80)
+    rule = f"protocol ipv6 flower dst_ip {dst}/120"
+
+    _check_baseline_rate(cfg)
+    _add_filter(cfg, rule, _police(RATE_MBIT), pref=10)
+    _check_in_hw(cfg, 10)
+
+    got = _iperf3(cfg, dst, OFFERED_MBIT)
+    _check_rate(got, RATE_MBIT, "matching flow")
+    got = _iperf3(cfg, cfg.addr_v["6"], OFFERED_MBIT)
+    _check_unpoliced(got, RATE_MBIT, "address outside the prefix")
+    if _local_prefix(cfg).prefixlen < 120:
+        # Just outside the /120, for a device that uses a shorter mask
+        near = ipaddress.IPv6Address(int(ipaddress.IPv6Address(dst)) ^ 0x100)
+        if str(near) not in _dev_addrs(cfg):
+            ip(f"-6 addr add {near}/128 dev {cfg.ifname} nodad")
+            defer(ip, f"-6 addr del {near}/128 dev {cfg.ifname}")
+        got = _iperf3(cfg, near, OFFERED_MBIT)
+        _check_unpoliced(got, RATE_MBIT, "address next to the prefix")
+    else:
+        ksft_pr("LOCAL_PREFIX_V6 is a /120, shorter masks not checked")
+
+
 def main() -> None:
     """Ksft boilerplate main."""
     with NetDrvEpEnv(__file__, nsim_test=False) as cfg:
@@ -306,7 +338,8 @@ def main() -> None:
                   police_no_leak,
                   link_baseline,
                   police_rate,
-                  police_isolation],
+                  police_isolation,
+                  police_dst_prefix],
                  args=(cfg,))
     ksft_exit()
 
-- 
2.53.1-Meta


  parent reply	other threads:[~2026-12-04  0:05 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04  0:05 [PATCH net-next 00/11] selftests: drv-net: Test tc-flower police offload Mohsin Bashir
2026-12-04  0:05 ` [PATCH net-next 01/11] selftests: drv-net: Iperf3Runner: Support UDP and server side results Mohsin Bashir
2026-12-05  0:15   ` netdev-bot+sashiko
2026-12-04  0:05 ` [PATCH net-next 02/11] selftests: drv-net: Add tc-flower police offload test Mohsin Bashir
2026-12-05  0:15   ` netdev-bot+sashiko
2026-12-04  0:05 ` [PATCH net-next 03/11] selftests: drv-net: tc_flower_police: Test that rules do not leak Mohsin Bashir
2026-12-05  0:15   ` netdev-bot+sashiko
2026-12-04  0:05 ` [PATCH net-next 04/11] selftests: drv-net: tc_flower_police: Test the policed rate and its scope Mohsin Bashir
2026-12-05  0:15   ` netdev-bot+sashiko
2026-12-04  0:05 ` Mohsin Bashir [this message]
2026-12-05  0:15   ` [PATCH net-next 05/11] selftests: drv-net: tc_flower_police: Test destination prefix rules netdev-bot+sashiko
2026-12-04  0:05 ` [PATCH net-next 06/11] selftests: drv-net: tc_flower_police: Test police parameters Mohsin Bashir
2026-12-05  0:15   ` netdev-bot+sashiko
2026-12-04  0:05 ` [PATCH net-next 07/11] selftests: drv-net: tc_flower_police: Test multiple policers Mohsin Bashir
2026-12-05  0:15   ` netdev-bot+sashiko
2026-12-04  0:05 ` [PATCH net-next 08/11] selftests: drv-net: tc_flower_police: Test rule removal Mohsin Bashir
2026-12-05  0:15   ` netdev-bot+sashiko
2026-12-04  0:05 ` [PATCH net-next 09/11] selftests: drv-net: tc_flower_police: Test policing across reconfiguration Mohsin Bashir
2026-12-05  0:15   ` netdev-bot+sashiko
2026-12-04  0:05 ` [PATCH net-next 10/11] selftests: drv-net: tc_flower_police: Test policing with ntuple steering Mohsin Bashir
2026-12-05  0:15   ` netdev-bot+sashiko
2026-12-04  0:05 ` [PATCH net-next 11/11] selftests: drv-net: tc_flower_police: Test policing with RSS contexts Mohsin Bashir
2026-12-05  0:15   ` netdev-bot+sashiko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261204000521.3396802-6-mohsin.bashr@gmail.com \
    --to=mohsin.bashr@gmail.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=shuah@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.