Re: [PATCH net v3 5/8] net: resolve uncommon partial checksums at ingress

From
Michael S. Tsirkin <mst@redhat.com>
Date
2026-10-20 21:49:41
Also in
lkml, netdev
Reply to
Willem de Bruijn, 2026-10-20
On Tue, Oct 20, 2026 at 03:44:35PM -0400, Willem de Bruijn wrote:
quoted
+/* Walk the L3 header at @nhoff: where does its transport header
+ * start, and which protocol is it?  Returns false if the header
+ * is truncated, malformed or fragmented.
+ */
+static inline bool
+virtio_net_l4_start(struct sk_buff *skb, unsigned int nhoff, __be16 proto,
+		    unsigned int *thoff, int *ip_proto)
+{
+	if (proto == htons(ETH_P_IP)) {
+		const struct iphdr *iph = virtio_net_ip4_parse(skb, nhoff, thoff);
+
+		if (!iph || ip_is_fragment(iph))
+			return false;
+		*ip_proto = iph->protocol;
+		return true;
+	}
+
+	if (proto == htons(ETH_P_IPV6)) {
+		const struct ipv6hdr *iph;
+		int flags = 0;
+
+		if (!pskb_may_pull(skb, nhoff + sizeof(*iph)))
+			return false;
+		iph = (const void *)(skb->data + nhoff);
+		if (iph->version != 6)
+			return false;
+		*thoff = nhoff + sizeof(*iph);
+		*ip_proto = iph->nexthdr;
+		if (*ip_proto != IPPROTO_TCP && *ip_proto != IPPROTO_UDP) {
+			*thoff = nhoff;
+			*ip_proto = ipv6_find_hdr(skb, thoff, -1, NULL,
+						  &flags);
+			if (*ip_proto < 0 || flags & IP6_FH_F_FRAG)
+				return false;
+		}
+		return true;
+	}
+
+	return false;
+}
for all this parsing: could we use flow dissection, like the
!VIRTIO_NET_HDR_F_NEEDS_CSUM case?
Hmm I don't see how.  That one trusts the caller's protocol and network
header. We could parse L2 ourselves and use the dissector for L3+. But
it stops at whatever it does not know, and every miss would turn into a
drop or a software checksum for a packet the stack delivers fine.  Our
parser deliberately covers everything the stack can deliver.

-- 
MST
Thread (43 messages) 43 messages, 7 authors, last reply 2026-10-21
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help