From patchwork Thu Mar 21 12:20:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark X-Patchwork-Id: 13598683 X-Patchwork-Delegate: kuba@kernel.org Received: from fhigh3-smtp.messagingengine.com (fhigh3-smtp.messagingengine.com [103.168.172.154]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 740B5224F2; Thu, 21 Mar 2024 12:21:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711023689; cv=none; b=nEsYoQMdi/pXww+ooGL1hDAqjXiTG+hYHkZEWuj58ISsJ6mrSb1CW54HPLdKYIM2m28tcHiN3QS7H1QDG/sVmn5Yge5cxJLgIIEZc8OcJ/192ysVuUEgwno8SGaQHz2fuaZ0hfpjlCTnYpN45ZebKkDrU3uEjMOCpwwM2WTxJlw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711023689; c=relaxed/simple; bh=tJHhyKzMBGPlvqUYLPyAq4LJdsUc0ArOyr39DcHjHFE=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=j8tE45m7ED561fB7m+8tcN87ERI9PIT2FMam7XcP05TNSvboePNtDEP3wBUhXpfzTP8QWpsMThudQoEOBUubzI62JWfOHtg2NweuNXdpqakDSJLjTIk1O9f7MZ5AHbzgQt29d8Ywbw1Zb3Vi7F15ttfW8plDP9VjaTPl0lZcTfY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=yotsuba.nl; spf=pass smtp.mailfrom=yotsuba.nl; dkim=pass (2048-bit key) header.d=yotsuba.nl header.i=@yotsuba.nl header.b=Nj7pM8Km; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=cx1XgYkr; arc=none smtp.client-ip=103.168.172.154 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=yotsuba.nl Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=yotsuba.nl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=yotsuba.nl header.i=@yotsuba.nl header.b="Nj7pM8Km"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="cx1XgYkr" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 4F69B1140113; Thu, 21 Mar 2024 08:21:25 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Thu, 21 Mar 2024 08:21:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yotsuba.nl; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:message-id:mime-version:reply-to:subject:subject:to :to; s=fm1; t=1711023685; x=1711110085; bh=zl2DkJ9v924tdl+ckZdhY C/P/YNrKbev6EVT/FWNrpk=; b=Nj7pM8Km98RJRF+HloMaLqvDVCJ7HX9HuwlaO WR4dWGD9wbcaazY7TNObtfO2om2d2luwvYucpxunx5JAZ9LH8LKwv6qMMsS2rpyG JkPSWpzek1+B5U45T2Tde3nsPajBduYaWYET4WCO2ZorBqUMDL9jsVyUwdGQucoS HXmxM0H3xM3WLLkT8JvN2CFYSNHJswdGikXmHXRjx7Ci3DFEWmiM04kV8YpuOzes Dveo7h63G5vInDtMO8qUSkw5ZrqAS5WTrhXjD0RCr9lxEJXBsEsjXitxyHmC2dSt YRWUTqNh4c9X7XXDIrjPm0Hznap8PP9CpN3wivg32JmiMRYRQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:message-id:mime-version:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1711023685; x=1711110085; bh=zl2DkJ9v924tdl+ckZdhYC/P/YNr Kbev6EVT/FWNrpk=; b=cx1XgYkrsFzFHlzAh7MDr0ZOdZrc8+ofZIQAjquc08K6 MVh3c9iN/YISpCtFmK+Pqr252fARl+5WTV1EEyA9JIurGqVtnNku9IoljEpZSASe 0/0GUlt8faETp6OBypsbgUhgPo+53TGqqwfo3LKbeTEzmZDwEUM4IXc9xX2S+D5z NmV34+dZc5ftU6Mvdk5xFnzrkJb6Qkb+KgY3j0eS1+C6KmG7XH4dF8EF3MsORd37 14POAQpQGIhZQsanKRqgRWT/vfmWJTSYEL3q/eA0dKm2YHSXBNt815mhkwlJN7hV 387EAPh9sXwUp4kpPoATjzjaduUpMhi9ztX7NVQsOw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrleeigdeflecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvfevufffkffoggfgsedtkeertdertddtnecuhfhrohhmpeforghrkhcuvehi lhhishhsvghnuceomhgrrhhkseihohhtshhusggrrdhnlheqnecuggftrfgrthhtvghrnh ephfeuleeijefgffejheduteeigfefhedvjeeggfffhefgkedthfefjefftefgvedvnecu ffhomhgrihhnpehkvghrnhgvlhdrohhrghenucevlhhushhtvghrufhiiigvpedtnecurf grrhgrmhepmhgrihhlfhhrohhmpehmrghrkheshihothhsuhgsrgdrnhhl X-ME-Proxy: Feedback-ID: i85e1472c:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 21 Mar 2024 08:21:24 -0400 (EDT) From: Mark Cilissen To: netdev@vger.kernel.org Cc: Mark Cilissen , Jakub Kicinski , Hans de Goede , Paolo Abeni , Ratheesh Kannoth , Eric Dumazet , Breno Leitao , Ingo Molnar , "David S. Miller" , linux-kernel@vger.kernel.org Subject: [RFC net-next v2 1/2] netpoll: support sending over raw IP interfaces Date: Thu, 21 Mar 2024 13:20:00 +0100 Message-ID: <20240321122003.20089-1-mark@yotsuba.nl> X-Mailer: git-send-email 2.44.0 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Currently, netpoll only supports interfaces with an ethernet-compatible link layer. Certain interfaces like SLIP do not have a link layer on the network interface level at all and expect raw IP packets, and could benefit from being supported by netpoll. This commit adds support for such interfaces by checking if a link layer header is present using `dev_has_header()`. If that is not the case, it simply skips adding the ethernet header, causing a raw IP packet to be sent over the interface. This has been confirmed to add netconsole support to at least SLIP and WireGuard interfaces. Signed-off-by: Mark Cilissen --- v2: - Use dev_has_header(netdev) to detect existence of link layer header instead of netdev->hard_header_len, restore prior skb allocation sizes by always using LL_RESERVED_SPACE() as before - Add selftest for netconsole v1: https://lore.kernel.org/netdev/20240313124613.51399-1-mark@yotsuba.nl/T/ --- Documentation/networking/netconsole.rst | 3 ++- net/core/netpoll.c | 15 ++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Documentation/networking/netconsole.rst b/Documentation/networking/netconsole.rst index d55c2a22ec7a..434ce0366027 100644 --- a/Documentation/networking/netconsole.rst +++ b/Documentation/networking/netconsole.rst @@ -327,4 +327,5 @@ enable the logging of even the most critical kernel bugs. It works from IRQ contexts as well, and does not enable interrupts while sending packets. Due to these unique needs, configuration cannot be more automatic, and some fundamental limitations will remain: -only IP networks, UDP packets and ethernet devices are supported. +only UDP packets over IP networks, over ethernet links if a +hardware layer is required, are supported. diff --git a/net/core/netpoll.c b/net/core/netpoll.c index 543007f159f9..d12aa1b7d79e 100644 --- a/net/core/netpoll.c +++ b/net/core/netpoll.c @@ -458,9 +458,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len) ip6h->saddr = np->local_ip.in6; ip6h->daddr = np->remote_ip.in6; - eth = skb_push(skb, ETH_HLEN); - skb_reset_mac_header(skb); - skb->protocol = eth->h_proto = htons(ETH_P_IPV6); + skb->protocol = htons(ETH_P_IPV6); } else { udph->check = 0; udph->check = csum_tcpudp_magic(np->local_ip.ip, @@ -487,14 +485,17 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len) put_unaligned(np->remote_ip.ip, &(iph->daddr)); iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl); + skb->protocol = htons(ETH_P_IP); + } + + if (dev_has_header(np->dev)) { eth = skb_push(skb, ETH_HLEN); skb_reset_mac_header(skb); - skb->protocol = eth->h_proto = htons(ETH_P_IP); + eth->h_proto = skb->protocol; + ether_addr_copy(eth->h_source, np->dev->dev_addr); + ether_addr_copy(eth->h_dest, np->remote_mac); } - ether_addr_copy(eth->h_source, np->dev->dev_addr); - ether_addr_copy(eth->h_dest, np->remote_mac); - skb->dev = np->dev; netpoll_send_skb(np, skb); From patchwork Thu Mar 21 12:20:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark X-Patchwork-Id: 13598684 X-Patchwork-Delegate: kuba@kernel.org Received: from fout8-smtp.messagingengine.com (fout8-smtp.messagingengine.com [103.168.172.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 82196762F3; Thu, 21 Mar 2024 12:21:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711023694; cv=none; b=NJTLEp5XC/9Qf7A5r+Dt/+o2BBWWDxIsj9vA1rqphncTDokmA8YDEmEFwTbiAlBzhq0ei4wSfkBLtVkMFp9fzeabgqlooj331okjfClHmDI+lRLF77bgQNEWqpWt4MSXowgpCnzFl8ZFdC6BRJefJwsSMNDJw9NkajpxmF19pPw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711023694; c=relaxed/simple; bh=h0OCYhTLwuSwPnc4GUkrDtFpzmlCkF3n8K6eXs2ulvA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HgjAqWq5x4XiNFC8pUjuVPI338KxxoeEIWeQDw1d4aPI2hakoYc+YUErC0HFHfc6DQrFMjFeM0VeAxDk/b+IkSXN2QzhyYqR4vP6QCsm+Oij3dUEBPp/b52xetZ/rqlVblDXcshsiSllD5RYVcSantYk3owKaf6cHaNR4gfaV9U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=yotsuba.nl; spf=pass smtp.mailfrom=yotsuba.nl; dkim=pass (2048-bit key) header.d=yotsuba.nl header.i=@yotsuba.nl header.b=a1LXpSUC; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=k9ORNhDb; arc=none smtp.client-ip=103.168.172.151 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=yotsuba.nl Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=yotsuba.nl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=yotsuba.nl header.i=@yotsuba.nl header.b="a1LXpSUC"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="k9ORNhDb" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfout.nyi.internal (Postfix) with ESMTP id 633951380147; Thu, 21 Mar 2024 08:21:31 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Thu, 21 Mar 2024 08:21:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yotsuba.nl; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm1; t=1711023691; x= 1711110091; bh=W9wJZQJR63Wvk/JDbjxC6995wg9TQBOr281LOEXEo7w=; b=a 1LXpSUCdbfC3JZbq2LxJaNrdOnmcwGXM3cuUZk/w5d5jonJ3IZg+sl3SsSzKZXas W7WWVG1mDL9lbJ4Ozq6LQ0BLmHObJY7v2t0/LDqpHcFF55rWmkgf2SlZw9XJ135d D3F+jdEB03csO8pVBW+GOf32nnIJKcMQX20SmVX/latDMl/jDisZbqLM3Spm/U3s Gb+ugjfW1wY7+dzZtq8UWkjCMtQR1cfqyWTVotQbMGAwRD3RTsMWVtlRs6LwJs0m yLqUKqpK51bMG6DwcMB3SdzPBhFPla3GK3owft/eurVOpOKnW9AWjwHiiZo9s11c nSZX2CkXRLQfz8dIDUo1A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1711023691; x= 1711110091; bh=W9wJZQJR63Wvk/JDbjxC6995wg9TQBOr281LOEXEo7w=; b=k 9ORNhDbuzqeRIUjjb1hevH7JcSKpa5jn1oMxYsXXBemKjBokugpDpWNHj5FHG9F8 ciezCVeh1mO019diLL1CzlAE2+p3kOCSJRLc0DQcwiGB/8tEKkaU0Q/yeMJobJW5 L8N3UPpjaTJCH873581GWH15gZk61Ki315kCqbsN4AK2VsHHk92eGxJIJqmKKk3B WcAdc7obJ3IqxjMndFjPpuqN1uW7PMifTumCedhHKATKUDnSC72gxSzMiRW3gM7a cFG//7fnB1tIu+AJA8uYK0Gsh+HGUbbFcJ2765vXfQ/lbPkyGLsqFBMc93N0BuD5 i4pzxPqLN9HvqpvAabcbw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrleeigdeflecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeforghrkhcu vehilhhishhsvghnuceomhgrrhhkseihohhtshhusggrrdhnlheqnecuggftrfgrthhtvg hrnhepueejkeffteeiueeiveevtdeftefgffdtfedtheeikeeukeegffeukeduhfeiveef necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepmhgrrh hkseihohhtshhusggrrdhnlh X-ME-Proxy: Feedback-ID: i85e1472c:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 21 Mar 2024 08:21:30 -0400 (EDT) From: Mark Cilissen To: netdev@vger.kernel.org Cc: Mark Cilissen , Jakub Kicinski , Hans de Goede , Paolo Abeni , Ratheesh Kannoth , Eric Dumazet , Breno Leitao , Ingo Molnar , "David S. Miller" , linux-kernel@vger.kernel.org Subject: [RFC net-next v2 2/2] selftests: add netpoll selftest Date: Thu, 21 Mar 2024 13:20:01 +0100 Message-ID: <20240321122003.20089-2-mark@yotsuba.nl> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240321122003.20089-1-mark@yotsuba.nl> References: <20240321122003.20089-1-mark@yotsuba.nl> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Now that netpoll supports more kinds of network interfaces it benefits extra from being tested to monitor regressions. This test runs entirely in userspace, adding a netconsole for the interface-under-test using configfs and sending a kernel log message that is verified using socat. To cover a mix of circumstances while keeping host tooling dependences fairly minimal, the following interface scenarios are tested: - Ethernet link layer, IPv4 and IPv6 (veth) - No exposed link layer, IPv4 (gre, ipip, ip6tnl) - No exposed link layer, IPv6 (gre, sit, ip6tnl) As a sanity check the test was run on kernel release 6.7.9-200.fc39, which does not include the expanded netpoll interface support, and yielded the expected failures: PASS: netconsole (eth/ipv4) PASS: netconsole (eth/ipv6) FAIL: netconsole (ipv4/gre/ipv4): message did not arrive in time (124) FAIL: netconsole (ipv4/gre/ipv6): message did not arrive in time (124) FAIL: netconsole (ipv6/ip6gre/ipv4): message did not arrive in time (124) FAIL: netconsole (ipv6/ip6gre/ipv6): message did not arrive in time (124) FAIL: netconsole (ipv4/ipip/ipv4): message did not arrive in time (124) FAIL: netconsole (ipv4/sit/ipv6): message did not arrive in time (124) FAIL: netconsole (ipv6/ip6tnl/ipv4): message did not arrive in time (124) FAIL: netconsole (ipv6/ip6tnl/ipv6): message did not arrive in time (124) Signed-off-by: Mark Cilissen --- tools/testing/selftests/net/Makefile | 1 + tools/testing/selftests/net/config | 1 + tools/testing/selftests/net/netpoll.sh | 226 +++++++++++++++++++++++++ 3 files changed, 228 insertions(+) create mode 100755 tools/testing/selftests/net/netpoll.sh diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile index 7b6918d5f4af..e9908a976f5e 100644 --- a/tools/testing/selftests/net/Makefile +++ b/tools/testing/selftests/net/Makefile @@ -93,6 +93,7 @@ TEST_PROGS += test_bridge_backup_port.sh TEST_PROGS += fdb_flush.sh TEST_PROGS += fq_band_pktlimit.sh TEST_PROGS += vlan_hw_filter.sh +TEST_PROGS += netpoll.sh TEST_FILES := settings TEST_FILES += in_netns.sh lib.sh net_helper.sh setup_loopback.sh setup_veth.sh diff --git a/tools/testing/selftests/net/config b/tools/testing/selftests/net/config index 5e4390cac17e..bc3b6991b1aa 100644 --- a/tools/testing/selftests/net/config +++ b/tools/testing/selftests/net/config @@ -100,3 +100,4 @@ CONFIG_NETFILTER_XT_MATCH_POLICY=m CONFIG_CRYPTO_ARIA=y CONFIG_XFRM_INTERFACE=m CONFIG_XFRM_USER=m +CONFIG_NETCONSOLE=m diff --git a/tools/testing/selftests/net/netpoll.sh b/tools/testing/selftests/net/netpoll.sh new file mode 100755 index 000000000000..ab4acd756ca1 --- /dev/null +++ b/tools/testing/selftests/net/netpoll.sh @@ -0,0 +1,226 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 +# +# Test netpoll and netconsole in various interface scenarios: +# ethernet (veth), raw IPv4 (gre, ipip, ip6tnl), raw IPv6 (gre, sit, ip6tnl) +# +# +-----------------------------------------+ +# | $NS1 | +# | $H1 +---+ $T1 | +# | 192.0.2.1/30 | 192.0.2.65/30 | +# | 2001:db8:1::1/64 | 2001:db8:2::1/64 | +# +------------------|----------------------+ +# | +# +------------------|----------------------+ +# | $NS2 | | +# | $H2 +---+ $T2 | +# | 192.0.2.2/30 192.0.2.66/30 | +# | 2001:db8:1::2/64 2001:db8:2::2/64 | +# +-----------------------------------------+ +# shellcheck disable=SC3043 # allow 'local' keyword +set -e + +readonly ksft_skip=4 +readonly H1A4=192.0.2.1/30 +readonly H1A6=2001:db8:1::1/64 +readonly H2A4=192.0.2.2/30 +readonly H2A6=2001:db8:1::2/64 +readonly T1A4=192.0.2.65/30 +readonly T1A6=2001:db8:2::1/64 +readonly T2A4=192.0.2.66/30 +readonly T2A6=2001:db8:2::2/64 + +# shellcheck disable=SC2155 # declare and assign separately +readonly BASE="ksft-$(mktemp -u XXXXXX)" +readonly NS1="$BASE-n1" +readonly NS2="$BASE-n2" +readonly H1="$BASE-h1" +readonly H2="$BASE-h2" +readonly T1="$BASE-i1" +readonly T2="$BASE-i2" + + +# Utilities + +setup() { + ip netns add "$NS1" + ip netns exec "$NS1" sysctl -wq net.ipv4.ip_forward=1 + ip netns exec "$NS1" sysctl -wq net.ipv6.conf.all.forwarding=1 + ip netns exec "$NS1" sysctl -wq net.ipv6.conf.default.forwarding=1 + + ip netns add "$NS2" + ip netns exec "$NS2" sysctl -wq net.ipv4.ip_forward=1 + ip netns exec "$NS2" sysctl -wq net.ipv6.conf.all.forwarding=1 + ip netns exec "$NS2" sysctl -wq net.ipv6.conf.default.forwarding=1 + + ip link add "$H1" type veth peer name "$H2" + + ip link set dev "$H1" netns "$NS1" + ip -n "$NS1" link set dev "$H1" up + ip -n "$NS1" addr add "$H1A4" dev "$H1" + ip -n "$NS1" addr add "$H1A6" dev "$H1" nodad + + ip link set dev "$H2" netns "$NS2" + ip -n "$NS2" link set dev "$H2" up + ip -n "$NS2" addr add "$H2A4" dev "$H2" + ip -n "$NS2" addr add "$H2A6" dev "$H2" nodad + + grep -q '^netcon' /proc/consoles || modprobe netconsole +} + +cleanup() { + set +e + for d in /sys/kernel/config/netconsole/"$BASE"*; do + [ -d "$d" ] || continue + rmdir "$d" + done + for ns in "$NS1" "$NS2"; do + if ip -n "$ns" link show >/dev/null 2>&1; then + ip netns del "$ns" + fi + done + # In case we exit before the veth got moved into its namespace + if [ -e /sys/class/net/"$H1" ]; then + ip link del dev "$H1" + fi +} + +trap cleanup EXIT + +if ! command -v socat >/dev/null 2>&1; then + echo "SKIP: netconsole tests need socat" + exit $ksft_skip +fi + + +test_netconsole() { + local name="$1"; shift + local outif="$1"; shift + local outip="$1"; shift + local inif="$1"; shift + local inip="$1"; shift + local ret=0 + + local msg="kselftest/net/netpoll: netconsole test message for $name" + # Setup logger and background it, it will exit when it receives the message + timeout 3s ip netns exec "$NS2" socat -u -S 0 \ + udp6-recv:6666,reuseaddr,so-bindtodevice="$inif",ipv6only=0 \ + system:"grep -m 1 -q \'$(printf '%s' "$msg" | sed -e 's/:/\\:/g')\$\'" & + # Setup netconsole + ip netns exec "$NS1" sh -s < dev_name +echo "${outip%%/*}" > local_ip +echo "${inip%%/*}" > remote_ip +echo 6666 > remote_port +echo 1 > enabled +EOF + + # Send message and wait for it to arrive or timeout + echo "<1>$msg" > /dev/kmsg + if wait %+; then + echo "PASS: netconsole ($name)" + else + ret=$? + echo "FAIL: netconsole ($name): message did not arrive in time ($err)" + fi + rmdir /sys/kernel/config/netconsole/"$outif" + return $ret +} + + +# Test starts here + +ret=0 +mark_failed() { + # Make sure failure isn't overwritten by skip + if [ "$ret" = 0 ] || [ "$ret" = $ksft_skip ]; then + ret="$1" + fi +} + +setup + +# Test ethernet interfaces + +test_netconsole eth/ipv4 "$H1" "$H1A4" "$H2" "$H2A4" || mark_failed $? +test_netconsole eth/ipv6 "$H1" "$H1A6" "$H2" "$H2A6" || mark_failed $? + +# Test tunnel interfaces + +setup_tunnel() { + local type="$1"; shift + local h1a="${1%%/*}"; shift + local h2a="${1%%/*}"; shift + local t1a="$1"; shift + local t2a="$1"; shift + + ip -n "$NS1" link add "$T1" type "$type" local "$h1a" remote "$h2a" "$@" \ + || return $ksft_skip # Skip test if tunnel type is not available + ip -n "$NS1" addr add "$t1a" dev "$T1" + ip -n "$NS1" link set "$T1" up + + ip -n "$NS2" link add "$T2" type "$type" local "$h2a" remote "$h1a" "$@" \ + || return $ksft_skip # Skip test if tunnel type is not available + ip -n "$NS2" addr add "$t2a" dev "$T2" + ip -n "$NS2" link set "$T2" up +} + +teardown_tunnel() { + ip -n "$NS1" link del dev "$T1" + ip -n "$NS2" link del dev "$T2" +} + +test_tunnel_4in4() { + local type="$1"; shift + local ret=0 + setup_tunnel "$type" "$H1A4" "$H2A4" "$T1A4" "$T2A4" "$@" + test_netconsole "ipv4/$type/ipv4" "$T1" "$T1A4" "$T2" "$T2A4" || ret=$? + teardown_tunnel + return $ret +} + +test_tunnel_4in6() { + local type="$1"; shift + local ret=0 + setup_tunnel "$type" "$H1A6" "$H2A6" "$T1A4" "$T2A4" "$@" + test_netconsole "ipv6/$type/ipv4" "$T1" "$T1A4" "$T2" "$T2A4" || ret=$? + teardown_tunnel + return $ret +} + +test_tunnel_6in4() { + local type="$1"; shift + local ret=0 + setup_tunnel "$type" "$H1A4" "$H2A4" "$T1A6" "$T2A6" "$@" + test_netconsole "ipv4/$type/ipv6" "$T1" "$T1A6" "$T2" "$T2A6" || ret=$? + teardown_tunnel + return $ret +} + +test_tunnel_6in6() { + local type="$1"; shift + local ret=0 + setup_tunnel "$type" "$H1A6" "$H2A6" "$T1A6" "$T2A6" "$@" + test_netconsole "ipv6/$type/ipv6" "$T1" "$T1A6" "$T2" "$T2A6" || ret=$? + teardown_tunnel + return $ret +} + +test_tunnel_4in4 gre || mark_failed $? +test_tunnel_6in4 gre || mark_failed $? +test_tunnel_4in6 ip6gre || mark_failed $? +test_tunnel_6in6 ip6gre || mark_failed $? +test_tunnel_4in4 ipip || mark_failed $? +test_tunnel_6in4 sit || mark_failed $? +test_tunnel_4in6 ip6tnl mode ipip6 || mark_failed $? +test_tunnel_6in6 ip6tnl mode ip6ip6 || mark_failed $? + + +# Test done + +cleanup +exit "$ret"