From nobody Mon Feb 20 10:21:18 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4PKz3L43M5z3sKwx; Mon, 20 Feb 2023 10:21:18 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4PKz3L3YDhz4Mxf; Mon, 20 Feb 2023 10:21:18 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1676888478; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=4NdIL2ajb9JSnYwyPHABLYmm59dzL0LvdNPSgb5Bz78=; b=QzyqZTiJzUzIts8Q1sUXrveXWHWaJ50ckkckTk6XCeZ3gv3+tiTSez8Q4vzIjdslhQO0Wb Mj9yh3l+eKLzk5PY2fX+1TuWj+yYf6OUCWOF5wNmZ5BHt4a9HvXYLRD1FhHjZOgArLtPS2 VOeh0/y9YAH5CGDTVyo3PQcFWKn7V22TAkdQFr/cgWgMatHWvf6Ctj8F0xDz6AW9y++8qQ T1BZ7knqHVS1+/F04ASXuxtaREd8YXmu50YtdtAzdnE91i4R491ggA46O3BNg5GihjxWNC L1su5t/47Zmi6ygWLq4nn8uy9sfN04fkZ3biMWDpZfgWlF5T7H3divJA0uJ2tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1676888478; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=4NdIL2ajb9JSnYwyPHABLYmm59dzL0LvdNPSgb5Bz78=; b=r50SxLoasQg9x5+uC+Oih9fAjB7914RGKg2W+ytq3Ja+wcj7V4KC0uBz/iuRSkWL/VO/tA jLW3jiDxVsB8EIRzOo8aQMzC9D5ZuMz8dhopzq1qbB/XigErI22v1xqrlULU9OmYwtPH9P DPCyZRkXf1VYcWL6+GxEBQs0poWbUGfX6FL0QfMWYvl4v9mSwTpcL9JeKpGuxjNryBClSP uV0UgqkejXYynFEc8J88lM209wyhFMptXU/aNEdUlC3cg10XLFxSQ1ETz+qJZPW+vhqzDH uZjnsqXxCrQ2o9jExypo1U5jM0tn2HisM/4x7Jx3ncEAhJwV9mpdRAoEvV8fhQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1676888478; a=rsa-sha256; cv=none; b=p3LzRjVFgnpeqQVqFigyUE5JjTpYDSnrH6Q9DZyALcxNCW3FNkyN2JslWlZYZyFpDJUdIi Z+3Dnk53+Dkjl1/XWm/qEC68NthCIsGCI0LF2tjeURBSQeVisI1e4IDJukAwKEAufBUOJW wje90tMzYdWjhmfQV6HJYkSTeqcGfx7EyfG+3lECHvspmha69lZckVctkMinwRQOt9m28Y /UtdOLUU8M29hYxNPw7s9IKgesIkmhM4JkvEV14jWnmldD8QVYfukiHbseBXX+lug4oHmg QZnRRRGSuMQwb2Qi+aBPby976vWZGswqRQKfRH6ODsZtv8isjM7gXO+Mb7fnbA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4PKz3L2JT3zdLj; Mon, 20 Feb 2023 10:21:18 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 31KALI3P044528; Mon, 20 Feb 2023 10:21:18 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 31KALIIp044527; Mon, 20 Feb 2023 10:21:18 GMT (envelope-from git) Date: Mon, 20 Feb 2023 10:21:18 GMT Message-Id: <202302201021.31KALIIp044527@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: "Alexander V. Chernikov" Subject: git: 828d3c6c4cc0 - main - tests: add netlink large dump buffer check List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: melifaro X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 828d3c6c4cc0b782e16abb1ae18023734a0b710f Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=828d3c6c4cc0b782e16abb1ae18023734a0b710f commit 828d3c6c4cc0b782e16abb1ae18023734a0b710f Author: Alexander V. Chernikov AuthorDate: 2023-02-20 10:20:23 +0000 Commit: Alexander V. Chernikov CommitDate: 2023-02-20 10:20:54 +0000 tests: add netlink large dump buffer check Differential Revision: https://reviews.freebsd.org/D38665 MFC after: 2 weeks --- tests/atf_python/sys/net/netlink.py | 20 +++++----- tests/sys/netlink/Makefile | 1 + tests/sys/netlink/test_rtnl_route.py | 76 ++++++++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+), 9 deletions(-) diff --git a/tests/atf_python/sys/net/netlink.py b/tests/atf_python/sys/net/netlink.py index 16cb746157cc..ec5a7feef317 100644 --- a/tests/atf_python/sys/net/netlink.py +++ b/tests/atf_python/sys/net/netlink.py @@ -1609,18 +1609,20 @@ class NetlinkTestTemplate(object): self.helper = NlHelper() self.nlsock = Nlsock(netlink_family, self.helper) - def write_message(self, msg): - print("") - print("============= >> TX MESSAGE =============") - msg.print_message() + def write_message(self, msg, silent=False): + if not silent: + print("") + print("============= >> TX MESSAGE =============") + msg.print_message() + msg.print_as_bytes(bytes(msg), "-- DATA --") self.nlsock.write_data(bytes(msg)) - msg.print_as_bytes(bytes(msg), "-- DATA --") - def read_message(self): + def read_message(self, silent=False): msg = self.nlsock.read_message() - print("") - print("============= << RX MESSAGE =============") - msg.print_message() + if not silent: + print("") + print("============= << RX MESSAGE =============") + msg.print_message() return msg def get_reply(self, tx_msg): diff --git a/tests/sys/netlink/Makefile b/tests/sys/netlink/Makefile index 880e5e6e4007..b6b35d195726 100644 --- a/tests/sys/netlink/Makefile +++ b/tests/sys/netlink/Makefile @@ -9,6 +9,7 @@ ATF_TESTS_C += test_snl ATF_TESTS_PYTEST += test_nl_core.py ATF_TESTS_PYTEST += test_rtnl_iface.py ATF_TESTS_PYTEST += test_rtnl_ifaddr.py +ATF_TESTS_PYTEST += test_rtnl_route.py CFLAGS+= -I${.CURDIR:H:H:H} diff --git a/tests/sys/netlink/test_rtnl_route.py b/tests/sys/netlink/test_rtnl_route.py new file mode 100644 index 000000000000..71125343166a --- /dev/null +++ b/tests/sys/netlink/test_rtnl_route.py @@ -0,0 +1,76 @@ +import ipaddress +import socket + +import pytest +from atf_python.sys.net.netlink import NetlinkRtMessage +from atf_python.sys.net.netlink import NetlinkTestTemplate +from atf_python.sys.net.netlink import NlAttrIp +from atf_python.sys.net.netlink import NlConst +from atf_python.sys.net.netlink import NlmBaseFlags +from atf_python.sys.net.netlink import NlmGetFlags +from atf_python.sys.net.netlink import NlmNewFlags +from atf_python.sys.net.netlink import NlMsgType +from atf_python.sys.net.netlink import NlRtMsgType +from atf_python.sys.net.netlink import RtattrType +from atf_python.sys.net.vnet import SingleVnetTestTemplate + + +class TestRtNlRoute(NetlinkTestTemplate, SingleVnetTestTemplate): + IPV6_PREFIXES = ["2001:db8::1/64"] + + def setup_method(self, method): + super().setup_method(method) + self.setup_netlink(NlConst.NETLINK_ROUTE) + + @pytest.mark.timeout(20) + def test_buffer_override(self): + msg_flags = ( + NlmBaseFlags.NLM_F_ACK.value + | NlmBaseFlags.NLM_F_REQUEST.value + | NlmNewFlags.NLM_F_CREATE.value + ) + + num_routes = 1000 + base_address = bytearray(ipaddress.ip_address("2001:db8:ffff::").packed) + for i in range(num_routes): + base_address[7] = i % 256 + base_address[6] = i // 256 + prefix_address = ipaddress.IPv6Address(bytes(base_address)) + + msg = NetlinkRtMessage(self.helper, NlRtMsgType.RTM_NEWROUTE.value) + msg.nl_hdr.nlmsg_flags = msg_flags + msg.base_hdr.rtm_family = socket.AF_INET6 + msg.base_hdr.rtm_dst_len = 65 + msg.add_nla(NlAttrIp(RtattrType.RTA_DST, str(prefix_address))) + msg.add_nla(NlAttrIp(RtattrType.RTA_GATEWAY, "2001:db8::2")) + + self.write_message(msg, silent=True) + rx_msg = self.read_message(silent=True) + assert rx_msg.is_type(NlMsgType.NLMSG_ERROR) + assert msg.nl_hdr.nlmsg_seq == rx_msg.nl_hdr.nlmsg_seq + assert rx_msg.error_code == 0 + # Now, dump + msg = NetlinkRtMessage(self.helper, NlRtMsgType.RTM_GETROUTE.value) + msg.nl_hdr.nlmsg_flags = ( + NlmBaseFlags.NLM_F_ACK.value + | NlmBaseFlags.NLM_F_REQUEST.value + | NlmGetFlags.NLM_F_ROOT.value + | NlmGetFlags.NLM_F_MATCH.value + ) + msg.base_hdr.rtm_family = socket.AF_INET6 + self.write_message(msg) + num_received = 0 + while True: + rx_msg = self.read_message(silent=True) + if msg.nl_hdr.nlmsg_seq == rx_msg.nl_hdr.nlmsg_seq: + if rx_msg.is_type(NlMsgType.NLMSG_ERROR): + if rx_msg.error_code != 0: + raise ValueError( + "unable to dump routes: error {}".format(rx_msg.error_code) + ) + if rx_msg.is_type(NlMsgType.NLMSG_DONE): + break + if rx_msg.is_type(NlRtMsgType.RTM_NEWROUTE): + if rx_msg.base_hdr.rtm_dst_len == 65: + num_received += 1 + assert num_routes == num_received