mirror of
https://github.com/torvalds/linux.git
synced 2026-06-02 03:24:19 +02:00
selftests: net: add a test case for nsid in all nsid notifications
The test subscribes to link events from all namespaces and makes sure that local events do not carry NSID in their ancillary data (even if there is a self-referential NSID allocated for the local namespace), and remote events do. Signed-off-by: Ilya Maximets <i.maximets@ovn.org> Acked-by: Nicolas Dichtel <nicolas.dichtel@6wind.com> Link: https://patch.msgid.link/20260520172317.175168-5-i.maximets@ovn.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
parent
88b126b39f
commit
2e43b64248
|
|
@ -3,13 +3,14 @@
|
|||
|
||||
import time
|
||||
|
||||
from lib.py import ksft_run, ksft_exit, ksft_true
|
||||
from lib.py import ksft_run, ksft_exit, ksft_eq, ksft_true
|
||||
from lib.py import ip
|
||||
from lib.py import NetNS, NetNSEnter
|
||||
from lib.py import RtnlFamily
|
||||
|
||||
|
||||
LINK_NETNSID = 100
|
||||
LINK_NETNSID2 = 200
|
||||
|
||||
|
||||
def test_event() -> None:
|
||||
|
|
@ -32,6 +33,57 @@ def test_event() -> None:
|
|||
"Received unexpected link notification")
|
||||
|
||||
|
||||
def test_event_all_nsid() -> None:
|
||||
"""NETLINK_LISTEN_ALL_NSID notifications: local events must not
|
||||
carry nsid even with a self-referential mapping. Remote events
|
||||
must carry the correct nsid."""
|
||||
|
||||
with NetNS() as ns1, NetNS() as ns2:
|
||||
net1, net2 = str(ns1), str(ns2)
|
||||
|
||||
with NetNSEnter(net1):
|
||||
rtnl = RtnlFamily()
|
||||
rtnl.ntf_listen_all_nsid()
|
||||
rtnl.ntf_subscribe("rtnlgrp-link")
|
||||
|
||||
# Case 1: no nsid assigned, local event, no nsid expected.
|
||||
ip("link add dummy-lo type dummy", ns=net1)
|
||||
|
||||
# Case 2: self-referential nsid, local event, still no nsid.
|
||||
ip(f"netns set {net1} {LINK_NETNSID}", ns=net1)
|
||||
ip("link add dummy-sr type dummy", ns=net1)
|
||||
|
||||
# Case 3: remote event, nsid present.
|
||||
ip(f"netns set {net2} {LINK_NETNSID2}", ns=net1)
|
||||
ip("link add dummy-re type dummy", ns=net2)
|
||||
|
||||
# Collect the three newlink events, ignoring unrelated noise.
|
||||
events = {}
|
||||
for msg in rtnl.poll_ntf(duration=1):
|
||||
if msg['name'] == 'getlink':
|
||||
ifname = msg['msg'].get('ifname')
|
||||
if ifname in ('dummy-lo', 'dummy-sr', 'dummy-re'):
|
||||
events[ifname] = msg
|
||||
if len(events) == 3:
|
||||
break
|
||||
|
||||
ksft_true('dummy-lo' in events, "missing local event")
|
||||
ksft_true(events['dummy-lo'].get('nsid') is None,
|
||||
"local event without nsid should not carry nsid")
|
||||
|
||||
ksft_true('dummy-sr' in events, "missing self-ref event")
|
||||
ksft_true(events['dummy-sr'].get('nsid') is None,
|
||||
"local event with self-ref nsid should not carry nsid")
|
||||
|
||||
ksft_true('dummy-re' in events, "missing remote event")
|
||||
ksft_eq(events['dummy-re'].get('nsid'), LINK_NETNSID2,
|
||||
"remote event should carry nsid")
|
||||
|
||||
ip("link del dummy-lo", ns=net1)
|
||||
ip("link del dummy-sr", ns=net1)
|
||||
ip("link del dummy-re", ns=net2)
|
||||
|
||||
|
||||
def validate_link_netns(netns, ifname, link_netnsid) -> bool:
|
||||
link_info = ip(f"-d link show dev {ifname}", ns=netns, json=True)
|
||||
if not link_info:
|
||||
|
|
@ -133,7 +185,12 @@ def test_peer_net() -> None:
|
|||
|
||||
|
||||
def main() -> None:
|
||||
ksft_run([test_event, test_link_net, test_peer_net])
|
||||
ksft_run([
|
||||
test_event,
|
||||
test_event_all_nsid,
|
||||
test_link_net,
|
||||
test_peer_net,
|
||||
])
|
||||
ksft_exit()
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user