Skip to contentSkip to conversation

netpoll: support sending over raw IP interfaces

RFC New Mark Cilissen 1 participant 2 messages Mar 21, 2024

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

RFC v2 1/2 netpoll: support sending over raw IP interfaces

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.

---
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/[email protected]/T/

---
 Documentation/networking/netconsole.rst |  3 ++-
 net/core/netpoll.c                      | 15 ++++++++-------
 2 files changed, 10 insertions(+), 8 deletions(-)
Documentation/networking/netconsole.rst +2 -1
index d55c2a22ec7a..434ce0366027 100644
@@ -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.
net/core/netpoll.c +8 -7
index 543007f159f9..d12aa1b7d79e 100644
@@ -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);
Signature · 1 line
2.44.0
#1 lore raw

RFC v2 2/2 selftests: add netpoll selftest

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)

---
 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
tools/testing/selftests/net/Makefile +1 -0
index 7b6918d5f4af..e9908a976f5e 100644
@@ -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
tools/testing/selftests/net/config +1 -0
index 5e4390cac17e..bc3b6991b1aa 100644
@@ -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
tools/testing/selftests/net/netpoll.sh new file +226 -0

226 lines not on this page · raw message

Signature · 1 line
2.44.0