From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202408 header.b=Psf0v+9e; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 430415A0276 for ; Mon, 26 Aug 2024 04:09:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202408; t=1724638184; bh=PLHTiPCsJ93Rxvp+E2NWoiZtTuA6LVVZMoeSJgn3fpw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Psf0v+9e2xwRrpvVS7O5UtWhqMW/pqXn65b3vWgqkg2RQ8qwyYSfwvGh4nxo1V+zT 2uyJ6Ln+qAmgAFN1B7F7n4fd1oRa1zimD1rmPixkp5vNRWzbFq62c0yVld+LpRHVbl qmzIR1NUmL9OlzzQKewYa3Rr5i84pzbeuWpkblw8V1lz9n6GZ1SvYW+EqnAerFM39/ Y6QalwxG4ne1e7FPJBQuxOd7rsssWSwN8titBRJWw0buqmVnuYyucgLYhboJtCqPMa Lk5qiTgur1s+ohEXKSaKyprZAKg8YKB/2uDe8y9nOQaG8FPj/FuymHpb40ErEbFMce 2xRQtQ8ksqu0Q== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4WsYyw5scNz4x8s; Mon, 26 Aug 2024 12:09:44 +1000 (AEST) From: David Gibson To: Stefano Brivio , passt-dev@passt.top Subject: [PATCH v3 10/15] tasst/veth: Helpers for constructing veth devices between namespaces Date: Mon, 26 Aug 2024 12:09:37 +1000 Message-ID: <20240826020942.545155-11-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240826020942.545155-1-david@gibson.dropbear.id.au> References: <20240826020942.545155-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: RRSGF44GXYYPBILMNEBZGP37QTUEPLVH X-Message-ID-Hash: RRSGF44GXYYPBILMNEBZGP37QTUEPLVH X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Cleber Rosa , David Gibson X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Signed-off-by: David Gibson --- test/tasst/__main__.py | 1 + test/tasst/veth.py | 80 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 test/tasst/veth.py diff --git a/test/tasst/__main__.py b/test/tasst/__main__.py index e7456e8b..4eab9157 100644 --- a/test/tasst/__main__.py +++ b/test/tasst/__main__.py @@ -19,6 +19,7 @@ MODULES = [ 'cmdsite', 'ip', 'unshare', + 'veth', ] diff --git a/test/tasst/veth.py b/test/tasst/veth.py new file mode 100644 index 00000000..7fa5cbb5 --- /dev/null +++ b/test/tasst/veth.py @@ -0,0 +1,80 @@ +#! /usr/bin/env python3 + +# SPDX-License-Identifier: GPL-2.0-or-later +# +# Copyright Red Hat +# Author: David Gibson + +""" +Test A Simple Socket Transport + +selftest/veth.py - Test various veth configurations +""" + +import contextlib +from typing import Iterator, Literal +import ipaddress + +import exeter + +from . import cmdsite, ip, unshare + + +@contextlib.contextmanager +def veth(site: cmdsite.CmdSite, ifname: str, + peername: str, peer: unshare.Unshare | None = None) -> Iterator[None]: + site.fg('ip', 'link', 'add', ifname, 'type', 'veth', + 'peer', 'name', peername, privilege=True) + if peer is not None: + site.fg('ip', 'link', 'set', peername, + 'netns', f'{peer.relative_pid(site)}', privilege=True) + yield + site.fg('ip', 'link', 'del', ifname, privilege=True) + + +def selftests() -> None: + @contextlib.contextmanager + def veth_setup() -> Iterator[tuple[cmdsite.CmdSite, cmdsite.CmdSite]]: + with unshare.unshare('ns1', '-Un') as ns1: + with unshare.unshare('ns2', '-n', parent=ns1, + privilege=True) as ns2: + with veth(ns1, 'vetha', 'vethb', ns2): + yield (ns1, ns2) + + @exeter.test + def test_ifs() -> None: + with veth_setup() as (ns1, ns2): + exeter.assert_eq(set(ip.ifs(ns1)), set(['lo', 'vetha'])) + exeter.assert_eq(set(ip.ifs(ns2)), set(['lo', 'vethb'])) + + @exeter.test + def test_mtu() -> None: + with veth_setup() as (ns1, ns2): + exeter.assert_eq(ip.mtu(ns1, 'vetha'), 1500) + exeter.assert_eq(ip.mtu(ns2, 'vethb'), 1500) + + def test_slaac(dad: Literal['disable', 'optimistic', None]) -> None: + TESTMAC = '02:aa:bb:cc:dd:ee' + TESTIP = ipaddress.ip_interface('fe80::aa:bbff:fecc:ddee/64') + + with veth_setup() as (ns1, ns2): + ns1.fg('ip', 'link', 'set', 'dev', 'vetha', 'address', TESTMAC, + privilege=True) + + ip.ifup(ns1, 'vetha', dad=dad) + ip.ifup(ns2, 'vethb') + + addrs = ip.addr_wait(ns1, 'vetha', family='inet6', scope='link') + exeter.assert_eq(addrs, [TESTIP]) + + @exeter.test + def test_dad() -> None: + test_slaac(dad=None) + + @exeter.test + def test_optimistic_dad() -> None: + test_slaac(dad='optimistic') + + @exeter.test + def test_no_dad() -> None: + test_slaac(dad='disable') -- 2.46.0