From nobody Thu Jul 25 21:02:07 2024 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 4WVNcJ3K0Lz5RJSP; Thu, 25 Jul 2024 21:02:08 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4WVNcH5cS0z4FLS; Thu, 25 Jul 2024 21:02:07 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1721941327; 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=6kSzcgKWAPeimVnkmkf8OLlGsijFlXN9TKTsQ45Jc4o=; b=mPTrVjxv4g3KUxKvUuL+MREOvpcZjugPQO7OlEbDeKLaUxc/NpNKduTYvG/hy9XGBm6CIB xx90h1X/9/7xEX0Ls6utLHq1Xp/BhxZulyS4ubQN3gCWwJs3F3Jv/sUeS+DgR9Br8xMXmK zlIxul7X/vYpGjp/AqrD0drTWhCJe0iBwc25xS35BKlW1G0MCLDZncnlsw5DLwOYGyNfOb 05ipnMPNQP4a0d5EkRTH02sD1guWSxePCuKE9yxXP7zB0pSAKbqLNOiv7jZT1nAryvaIer cRfrR3m27Zfg+hv+WCaaIVRq8ui3CH1p/5HZNMwi4hY/8tZO/Mlkkp+dpQu7ZA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1721941327; a=rsa-sha256; cv=none; b=YbUxG2CfEDMEtPhPfbVngY9dG1wYqN+lzEL9qyaUkPA8PVP7KDg1vuIbYnnIt06tStZ15c YI6UHBL7YEU0fNV2TaZG5gz5Sr3sqdD2Xk0F7xR8hsR+5NJFOS36aEDqlzAYnPOyj4Y9yj H4e5DEXIs+C+0L6ZBsxVdCDZtO65st6lLwasJ4180bKA2mdHgcuzSOcgFpBUFbdghvgQT1 pCuMmubGxPTXDIHGBqz06oWZIwfK8OaabQRAIwLj65eeFdmRJKhrmLXTFmne04McUWAHg5 IjggwaAPnDSOMBtOFz08tl6jm3z0jIjj9uBaIg0pOIn6lFuDLqh3zZNCIcFXsg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1721941327; 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=6kSzcgKWAPeimVnkmkf8OLlGsijFlXN9TKTsQ45Jc4o=; b=vlE5Ir9fXJG/5OoB1ii0UddadhUhW9GIAKWdw8+y6zzGmwqy+vvTZl8CsRZ3QvRgQqRYu+ hPgc4swBrx8YvMRt7IXt7wK4G9n6tNgzbBr/0/z9rmlofoEIeG+5DN/zJ9GAGBdIfSmlSr stn4fly4xlk2UEQ0S63opKy1ErqNouvfndJXZKg/l6yZgiRR0EQnkbdzGGVu0988ei1jlH Zi/mRewAjm3I2XH4w7k96v1PqrflQQvwvSGrxHRWjPCGbovehRAnZJFpmemZ6MIUfiuztg CihIYWyvJ+tfdb2m3sQQvT5ONzTZ2f76kuLYiqM1jgDmAhQqhVSXGGscQod61A== 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 4WVNcH56kwz19LF; Thu, 25 Jul 2024 21:02:07 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 46PL27cA095003; Thu, 25 Jul 2024 21:02:07 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 46PL27rq095000; Thu, 25 Jul 2024 21:02:07 GMT (envelope-from git) Date: Thu, 25 Jul 2024 21:02:07 GMT Message-Id: <202407252102.46PL27rq095000@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: feda329622bc - main - netinet6 tests: Add a regression test for default router handling 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: feda329622bc77ab64ae5f0bf852743f4a037616 Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=feda329622bc77ab64ae5f0bf852743f4a037616 commit feda329622bc77ab64ae5f0bf852743f4a037616 Author: Mark Johnston AuthorDate: 2024-07-25 21:01:11 +0000 Commit: Mark Johnston CommitDate: 2024-07-25 21:01:11 +0000 netinet6 tests: Add a regression test for default router handling This serves as a regression test for commit a48df53e4249. Reviewed by: bz, allanjude MFC after: 2 weeks Sponsored by: Klara, Inc. Sponsored by: Bell Tower Integration Differential Revision: https://reviews.freebsd.org/D46136 --- tests/sys/netinet6/Makefile | 34 +++++++++-------- tests/sys/netinet6/ndp.sh | 92 ++++++++++++++++++++++++++++++++++++++++++--- tests/sys/netinet6/ra.py | 38 +++++++++++++++++++ 3 files changed, 143 insertions(+), 21 deletions(-) diff --git a/tests/sys/netinet6/Makefile b/tests/sys/netinet6/Makefile index 78df34af46dd..45e88b50164b 100644 --- a/tests/sys/netinet6/Makefile +++ b/tests/sys/netinet6/Makefile @@ -4,28 +4,30 @@ TESTSDIR= ${TESTSBASE}/sys/netinet6 FILESDIR= ${TESTSDIR} ATF_TESTS_PYTEST= test_ip6_output.py -ATF_TESTS_SH= \ - exthdr \ - mld \ - scapyi386 \ - redirect \ - divert \ - forward6 \ - output6 \ - lpm6 \ - fibs6 \ - ndp \ - proxy_ndp +ATF_TESTS_SH= exthdr \ + mld \ + scapyi386 \ + redirect \ + divert \ + forward6 \ + output6 \ + lpm6 \ + fibs6 \ + ndp \ + proxy_ndp + TEST_METADATA.output6+= required_programs="python" -${PACKAGE}FILES+= exthdr.py -${PACKAGE}FILES+= mld.py -${PACKAGE}FILES+= scapyi386.py -${PACKAGE}FILES+= redirect.py +${PACKAGE}FILES+= exthdr.py \ + mld.py \ + scapyi386.py \ + ra.py \ + redirect.py ${PACKAGE}FILESMODE_exthdr.py= 0555 ${PACKAGE}FILESMODE_mld.py= 0555 ${PACKAGE}FILESMODE_scapyi386.py=0555 +${PACKAGE}FILESMODE_ra.py=0555 ${PACKAGE}FILESMODE_redirect.py=0555 TESTS_SUBDIRS+= frag6 diff --git a/tests/sys/netinet6/ndp.sh b/tests/sys/netinet6/ndp.sh index eddd49112421..038a640f331e 100755 --- a/tests/sys/netinet6/ndp.sh +++ b/tests/sys/netinet6/ndp.sh @@ -25,7 +25,6 @@ # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # -# . $(atf_get_srcdir)/../common/vnet.subr @@ -36,6 +35,7 @@ ndp_add_gu_success_head() { } ndp_add_gu_success_body() { + local epair0 jname vnet_init @@ -74,6 +74,7 @@ ndp_del_gu_success_head() { } ndp_del_gu_success_body() { + local epair0 jname vnet_init @@ -102,13 +103,94 @@ ndp_del_gu_success_cleanup() { vnet_cleanup } +ndp_if_up() +{ + local ifname=$1 + local jname=$2 -atf_init_test_cases() + if [ -n "$jname" ]; then + jname="jexec ${jname}" + fi + atf_check ${jname} ifconfig ${ifname} up + atf_check ${jname} ifconfig ${ifname} inet6 -ifdisabled + while ${jname} ifconfig ${ifname} inet6 | grep tentative; do + sleep 0.1 + done +} + +ndp_if_lladdr() { + local ifname=$1 + local jname=$2 - atf_add_test_case "ndp_add_gu_success" - atf_add_test_case "ndp_del_gu_success" + if [ -n "$jname" ]; then + jname="jexec ${jname}" + fi + ${jname} ifconfig ${ifname} inet6 | \ + awk '/inet6 fe80:/{split($2, addr, "%"); print addr[1]}' } -# end +atf_test_case "ndp_slaac_default_route" "cleanup" +ndp_slaac_default_route_head() { + atf_set descr 'Test default route installation via SLAAC' + atf_set require.user root + atf_set require.progs "python" +} + +ndp_slaac_default_route_body() { + local epair0 jname lladdr + + vnet_init + + jname="v6t-ndp_slaac_default_route" + + epair0=$(vnet_mkepair) + vnet_mkjail ${jname} ${epair0}a + + ndp_if_up ${epair0}a ${jname} + ndp_if_up ${epair0}b + atf_check jexec ${jname} ifconfig ${epair0}a inet6 accept_rtadv + + # Send an RA advertising a prefix. + atf_check -e ignore python $(atf_get_srcdir)/ra.py \ + --sendif ${epair0}b \ + --dst $(ndp_if_lladdr ${epair0}a ${jname}) \ + --src $(ndp_if_lladdr ${epair0}b) \ + --prefix "2001:db8:ffff:1000::" --prefixlen 64 + + # Wait for a default router to appear. + while [ -z "$(jexec ${jname} ndp -r)" ]; do + sleep 0.1 + done + atf_check -o match:"^default[[:space:]]+fe80:" \ + jexec ${jname} netstat -rn -6 + + # Get rid of the default route. + jexec ${jname} route -6 flush + atf_check -o not-match:"^default[[:space:]]+fe80:" \ + jexec ${jname} netstat -rn -6 + + # Send another RA, make sure that the default route is installed again. + atf_check -e ignore python $(atf_get_srcdir)/ra.py \ + --sendif ${epair0}b \ + --dst $(ndp_if_lladdr ${epair0}a ${jname}) \ + --src $(ndp_if_lladdr ${epair0}b) \ + --prefix "2001:db8:ffff:1000::" --prefixlen 64 + while [ -z "$(jexec ${jname} ndp -r)" ]; do + sleep 0.1 + done + atf_check -o match:"^default[[:space:]]+fe80:" \ + jexec ${jname} netstat -rn -6 +} + +ndp_slaac_default_route_cleanup() { + vnet_cleanup +} + +atf_init_test_cases() +{ + atf_add_test_case "ndp_add_gu_success" + atf_add_test_case "ndp_del_gu_success" + atf_add_test_case "ndp_slaac_default_route" +} diff --git a/tests/sys/netinet6/ra.py b/tests/sys/netinet6/ra.py new file mode 100644 index 000000000000..44814418da48 --- /dev/null +++ b/tests/sys/netinet6/ra.py @@ -0,0 +1,38 @@ +#- +# SPDX-License-Identifier: BSD-2-Clause +# +# Copyright (c) 2024 Klara, Inc. +# + +import argparse +import scapy.all as sp +import sys + +# +# Emit a router advertisement with the specified prefix. +# +def main(): + parser = argparse.ArgumentParser("ra.py", + description="Emits Router Advertisement packets") + parser.add_argument('--sendif', nargs=1, required=True, + help='The interface through which the packet will be sent') + parser.add_argument('--src', nargs=1, required=True, + help='The source IP address') + parser.add_argument('--dst', nargs=1, required=True, + help='The destination IP address') + parser.add_argument('--prefix', nargs=1, required=True, + help='The prefix to be advertised') + parser.add_argument('--prefixlen', nargs=1, required=True, type=int, + help='The prefix length to be advertised') + + args = parser.parse_args() + pkt = sp.Ether() / \ + sp.IPv6(src=args.src, dst=args.dst) / \ + sp.ICMPv6ND_RA(chlim=64) / \ + sp.ICMPv6NDOptPrefixInfo(prefix=args.prefix, prefixlen=args.prefixlen) + + sp.sendp(pkt, iface=args.sendif[0], verbose=False) + sys.exit(0) + +if __name__ == '__main__': + main()