🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #20902

[PATCH net-next v8 6/8] ip_tunnel: make ip_tunnel_encap() return a drop reason

#20902
From: Anton Danilov
Date: Mon, 23 Nov 2026 10:42
122 lines
15176 bytes
IPv4 tunnel transmitters need the reason why encapsulation failed.
Make ip_tunnel_encap() return NOMEM when the FOU or GUE build_header()
callback returns -ENOMEM, and TUNNEL_ENCAP for other failures. Success,
including when encapsulation is disabled, still returns zero.

Update both callers in ip_tunnel.c and the one in sit.c to test for a
nonzero result. Their old negative-error test would miss a drop reason.

Suggested-by: Ido Schimmel <idosch@nvidia.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: Anton Danilov <littlesmilingcloud@gmail.com>
---
 include/net/dropreason-core.h |  7 +++++++
 include/net/ip_tunnels.h      | 16 ++++++++++------
 net/ipv4/ip_tunnel.c          |  4 ++--
 net/ipv6/sit.c                |  2 +-
 4 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/include/net/dropreason-core.h b/include/net/dropreason-core.h
index 7150f357c1c6..767f528e099c 100644
--- a/include/net/dropreason-core.h
+++ b/include/net/dropreason-core.h
@@ -116,6 +116,7 @@
 	FN(TUNNEL_OPT_MISMATCH)		\
 	FN(TUNNEL_OLD_SEQ)		\
 	FN(GRE_CSUM)			\
+	FN(TUNNEL_ENCAP)		\
 	FN(MAC_INVALID_SOURCE)		\
 	FN(VXLAN_ENTRY_EXISTS)		\
 	FN(NO_TX_TARGET)		\
@@ -572,6 +573,12 @@ enum skb_drop_reason {
 	SKB_DROP_REASON_TUNNEL_OLD_SEQ,
 	/** @SKB_DROP_REASON_GRE_CSUM: GRE checksum error */
 	SKB_DROP_REASON_GRE_CSUM,
+	/**
+	 * @SKB_DROP_REASON_TUNNEL_ENCAP: failed to build the encapsulation
+	 * header of a tunnel, e.g. an unknown or unregistered encapsulation
+	 * type.
+	 */
+	SKB_DROP_REASON_TUNNEL_ENCAP,
 	/** @SKB_DROP_REASON_MAC_INVALID_SOURCE: source mac is invalid */
 	SKB_DROP_REASON_MAC_INVALID_SOURCE,
 	/**
diff --git a/include/net/ip_tunnels.h b/include/net/ip_tunnels.h
index 792690ae4f26..87046ba50d45 100644
--- a/include/net/ip_tunnels.h
+++ b/include/net/ip_tunnels.h
@@ -541,18 +541,18 @@ static inline int ip_encap_hlen(struct ip_tunnel_encap *e)
 	return hlen;
 }
 
-static inline int ip_tunnel_encap(struct sk_buff *skb,
-				  struct ip_tunnel_encap *e,
-				  u8 *protocol, struct flowi4 *fl4)
+static inline enum skb_drop_reason
+ip_tunnel_encap(struct sk_buff *skb, struct ip_tunnel_encap *e,
+		u8 *protocol, struct flowi4 *fl4)
 {
 	const struct ip_tunnel_encap_ops *ops;
 	int ret = -EINVAL;
 
 	if (e->type == TUNNEL_ENCAP_NONE)
-		return 0;
+		return SKB_NOT_DROPPED_YET;
 
 	if (e->type >= MAX_IPTUN_ENCAP_OPS)
-		return -EINVAL;
+		return SKB_DROP_REASON_TUNNEL_ENCAP;
 
 	rcu_read_lock();
 	ops = rcu_dereference(iptun_encaps[e->type]);
@@ -560,7 +560,11 @@ static inline int ip_tunnel_encap(struct sk_buff *skb,
 		ret = ops->build_header(skb, e, protocol, fl4);
 	rcu_read_unlock();
 
-	return ret;
+	if (!ret)
+		return SKB_NOT_DROPPED_YET;
+	if (ret == -ENOMEM)
+		return SKB_DROP_REASON_NOMEM;
+	return SKB_DROP_REASON_TUNNEL_ENCAP;
 }
 
 /* Extract dsfield from inner protocol */
diff --git a/net/ipv4/ip_tunnel.c b/net/ipv4/ip_tunnel.c
index 5137c26b9c1d..92e26464f2ee 100644
--- a/net/ipv4/ip_tunnel.c
+++ b/net/ipv4/ip_tunnel.c
@@ -619,7 +619,7 @@ void ip_md_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
 	if (!tunnel_hlen)
 		tunnel_hlen = ip_encap_hlen(&tun_info->encap);
 
-	if (ip_tunnel_encap(skb, &tun_info->encap, &proto, &fl4) < 0)
+	if (ip_tunnel_encap(skb, &tun_info->encap, &proto, &fl4))
 		goto tx_error;
 	inner_iph = (const struct iphdr *)skb_inner_network_header(skb);
 
@@ -783,7 +783,7 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
 			    tunnel->net, READ_ONCE(tunnel->parms.link),
 			    tunnel->fwmark, skb_get_hash(skb), 0);
 
-	if (ip_tunnel_encap(skb, &tunnel->encap, &protocol, &fl4) < 0)
+	if (ip_tunnel_encap(skb, &tunnel->encap, &protocol, &fl4))
 		goto tx_error;
 	inner_iph = (const struct iphdr *)skb_inner_network_header(skb);
 
diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
index a7ec800216ad..9576d146c961 100644
--- a/net/ipv6/sit.c
+++ b/net/ipv6/sit.c
@@ -1096,7 +1096,7 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb,
 		ttl = iph6->hop_limit;
 	tos = INET_ECN_encapsulate(tos, ipv6_get_dsfield(iph6));
 
-	if (ip_tunnel_encap(skb, &tunnel->encap, &protocol, &fl4) < 0) {
+	if (ip_tunnel_encap(skb, &tunnel->encap, &protocol, &fl4)) {
 		ip_rt_put(rt);
 		goto tx_error;
 	}
-- 
2.47.3
Technical Details
Message-ID: <20261123104210.199916-7-littlesmilingcloud@gmail.com>
Path: mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-369257-linux-kernel-netdev=dewy.ru
References: <20261123104210.199916-1-littlesmilingcloud@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-369257-linux-kernel-netdev=dewy.ru
From: littlesmilingcloud@gmail.com (Anton Danilov)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net-next v8 6/8] ip_tunnel: make ip_tunnel_encap() return a drop reason
Date: Mon, 23 Nov 2026 13:42:08 +0300
Organization: Usenet Network
Message-ID: <20261123104210.199916-7-littlesmilingcloud@gmail.com>
References: <20261123104210.199916-1-littlesmilingcloud@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3854153"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:2VrcqBm5sYqjXvYUOysTDKoN+qI= sha256:2e7IhHdR712GjiChQcBVTmVTSJp3JkHKlaVx6OEywMw=
	sha1:oC8qZHhub1vd4AzdTcB+nnDQNtU= sha256:YybUBQQSwYiox79QNE8OrsO4F6K22P9gT3RP9jWV/qs=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 36B27125D9D; Mon, 23 Nov 2026 13:42:50 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.149
X-Spam-Status: No, score=-3.149 tagged_above=-9999 required=6.31
	tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
	FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001,
	HEADER_FROM_DIFFERENT_DOMAINS=0.249, MAILING_LIST_MULTI=-1,
	RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001]
	autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id m9tJANH3SXJW;
	Mon, 23 Nov 2026 13:42:47 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-369257-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
	by mail.dewy.ru (Postfix) with ESMTPS id 165EF125D9C; Mon, 23 Nov 2026 13:42:38 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sto.lore.kernel.org (Postfix) with ESMTP id 909E8603812; Mon, 23 Nov 2026 10:42:38 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1795430545;
	b=tFyBY9D1mo3r/tdyACa4ok7Ihv0u0ogJ+gD/rhxtInbaKVY5f8y1OF59dgdOsNd6CO/M
	 mw1qGSrdZCNqSseytw5A3z5pfLDU+qkhTUd8Z2GI5Ci954kgwmMGT5wyfAWNIjIotZxde
	 /0XBDHj0YPYUfFlVmHjv5bm/svaImwvde5XW5b5h2Qark0i+3VxhXjPUMf4w4PVjVirh0
	 JzT7D36Voss5Al6fe0wFwqxIXDrvjWdrAp0AZ9/uBNscctzEQXu6tW1Tt9O7NI2VDbKZu
	 p5y1KPwuhYqXMv65n6S+/leKS31qMQTxNFN2Svnn5p67j7nbbrYytzuBuujo4nAca0A==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795430545;
	h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
	 X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg:X-Received:
	 Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:
	 References:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:
	 Content-Transfer-Encoding;
	bh=2Mu0HppQ36/o9RammXZiWbsYG3B69DWXDQ6ktqeYZBM=;
	b=28hCyHAh7k8yksoj83xvIKkvwgS0v7+wn0ZzjAARz+K3Zil36VLY/k24ydaJyEcG9dWI
	 7dCFQMznO4bofcDieY66esP6UuZH0PVr0F46SPEJiUJCzM3PxpM9dw99P0GPyCgT4a5IU
	 bn8zT96LACvenV94QLupumaBk1vSc9qxOYeRrzop8tTC4QCe6qcDtY9potW7199i53APr
	 Dbu/pdQ+G0eC9oToD9/iwUS/oQumh7vNpOXM3NRlXdSl9Vpl+GM6qwDvC3aMGgRND/xJe
	 j95Bl5K4EcL4n0iDznv2wulLGnVlbTWpJyjIaIVcK34PNY0GnxeRNDIFLoG1zpWLtyg==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="dimQ0d/3";
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.com;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 7E3E260A262E;
	Mon, 23 Nov 2026 10:42:25 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=dimQ0d/3
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.167.50
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795430544;
	b=mCZMnaYIVvE41ntAeveExv8/g/frhBLhA0NMLgYb9q1Ii8YEu3NnflUBmWq6NHsLH6bM
	 9o9SEz3SSsXGaEPpLzcNdXTulwx4jX2pvFMQRZqlHE39khQsUaZKd1GWn8Y3PI9c2no4f
	 88FGtZU6V0GVJ+0LTMyehmhu5ByucebZaRD+sdV8fXSq/xe+8OWj3foq4YoZPijdaN+v9
	 Sssj+tmfY67cHMquqTHnwJq5D2CC/JbgGkiEms4sQuij4Bdp1MIjtwg6hQisQqwrgSt+/
	 g0OoTy1IDmIukKvcjx2UNazxv83o63/ypH1sdV5wskgn0jQAsAC86nLPYnDZMrLk6sw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795430544;
	h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
	 X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject:
	 Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version:
	 Content-Transfer-Encoding;
	bh=2Mu0HppQ36/o9RammXZiWbsYG3B69DWXDQ6ktqeYZBM=;
	b=oJuyAf86JuAbBotmZkON1S2g6yNh+bpDFmvmfgsA2cx10jhOZCk9E6ksuVTJiTY92CEQ
	 h5OwMYcKmBFDx2HRfKhiUDglUQyhE0Pawc3p4jAbILfcjr7toIUrPG6dbCiPilpRM5MpF
	 Z99h2tnYhpdxvqRWNRoa1zQxLXaSf8etQPHWpRH4L6tUkk/GOEk/rk8TNNdPs0GaJw/Lj
	 +8v32hf3UGWU0CO0AnyN2WcMX11P9w4I9amGStJP96Usy7HjurkRczpeOevD1NHC/l6LI
	 ARlI2/accKwdHo7GACQz7r9Mspxx8KbTCy43BbQ7sybjdxn9gCZv+MXRf8FCykbSy5g==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.com;
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="dimQ0d/3";
	arc=none smtp.remote-ip=209.85.167.50
X-Received: from mail-lf1-f50.google.com (mail-lf1-f50.google.com [209.85.167.50])
	(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5310960A2623
	for <netdev@vger.kernel.org>; Mon, 23 Nov 2026 10:42:24 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5310960A2623
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-lf1-f50.google.com with SMTP id 2adb3069b0e04-5c158c4c15fso3872418e87.1
        for <netdev@vger.kernel.org>; Mon, 23 Nov 2026 02:42:24 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20260707; t=1795430542; x=1796035342; darn=vger.kernel.org;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:cc:to:from:from:to:cc:subject:date
         :message-id:reply-to:content-type;
        bh=2Mu0HppQ36/o9RammXZiWbsYG3B69DWXDQ6ktqeYZBM=;
        b=dimQ0d/3DC+owpNDEGAa1VvRlrJhu6CRvdBDtQUHcWWZwxH53T5pChSO3go8MVe88T
         jgJuXnib+XI6n6dUAmhOHf9t6D8SWR0ZIiAT8xzzA/2eOSF4qO2fFSKIDcbK5YNKleyy
         /fM8x/ObMVr+G/h3k3Wcr0Hdo9QsKourTfExUdvJCuNMKtZph+Oo8GHARzl0IgKcjA3U
         itSfj/A27ft58bzzwQCvElAQbXLFtLPgwmNE61yQvDDo2L/7YlIw6WxFjBM2Fnk8+ITk
         Do+ShqPHm1p4iH5XhePRD3yCDkgbqonFfDlYO/sNTXsbPpog3aoSCrDE4cDfCcMqtNi3
         nOWw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20260707; t=1795430542; x=1796035342;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from
         :to:cc:subject:date:message-id:reply-to:content-type;
        bh=2Mu0HppQ36/o9RammXZiWbsYG3B69DWXDQ6ktqeYZBM=;
        b=BWkQQAmoxgvtmuARhIHEW+HE7p+FS3HewXjdRd0RUZbFziiMRHwi3dcMqGnRh+BNsW
         h3yF69XrlzW+pT2HnxMal4MWYs8Qdugi20oqhmyVCmdBOgvKrLg8+cKh45ICStSTLOEy
         Z7SmsIKpdzFFs5UcYcTtFB3PbgAjsH2bNsY6X5NS2UoEERwJm+mYQp/oc9AcyG9aPAJu
         y8dkWzC/0uKjWRgq7djVdEZ0wKNM4/1Q5XFeOdb5EyrbP7A83ICMDy86KEIGj8DyihIj
         EgTMDNjnhQNOD0b/8dB8fT91IHGgGSaAkaBsIdP7d1dQp0LGmtixunx9ukgYC2c3AyIY
         POcw==
X-Gm-Message-State: APuU4Z/9LK269fU7/d4xYvNJ3PDLhaM4eWzjV6NG4PzQ+ZWWlwvPqPyq
	rvALlO3MFwfi6xkbLMLJvPurKK5+D6v5ZqvqIhXwA3Py8h8m0mia+FV0LM23nIVagrRnOg==
X-Gm-Gg: AZFdTZeUiLd5mLuOVsD44+ssABqQPxIA+6+z0rDgGaIXOF8sE+oqjAln4htCINUPkxW
	npaFTxcBQlsjIarl+P1kNMIzZ9v/45XofRAr0qyfTdW0kvcTtpn0p9BJSFOM8fr9P0MgoQRgPRZ
	gRbJounPRte3MpG2RASecCt74AUTJMDxowdg6mkkCaKGyxr/ZQZNVZOJI1XACj7k/7OuJBtHPbw
	WyyVZHHoEhEFDS+b05bE9NUkSUPCNystibFPW+sz37JtFL+nqBrM3HKH4IAwPMe/GZnsUKuVPi3
	sgokI1FaFwhF16n2WOanqqKQ9Q391f+8bGch6NALeaSLdRo8C84YN64UtMiUR4e3pFlDytCSDt2
	Aq/jdXTJcw2ecitOt/mvXt3TDyFjigf58AGz+0p+ZCJHGAKF3AKteUv6EVlJN9H1YfzezISHmYE
	Truh7z+pa2NrQ8UhVH6miKoWSYvTDvZweLbszR4jsG7OuEt9f0WGna/0tBayFhLPRSurm+hAnaN
	woNYSbNluv3bk+UyeRvRO/w5zjIMzgmVOIpsGvqQmW/H70zLmLmqFxZ7J5/2HG99aEMiOEgHZB4
	oS0ltDypWMOxhX483TQqJxAnB+bpGOBRVn0PI0zAgwQY64/iOtYv+HFP5qBoLRwcrLUwlyjEXam
	8W8ZUlWhIPElxXPvl9A==
X-Received: by 2002:a05:6512:10c7:b0:5bf:ec95:41c7 with SMTP id 2adb3069b0e04-5c1bc6f6aa8mr2515417e87.1.1795430542472;
        Mon, 23 Nov 2026 02:42:22 -0800 (PST)
X-Received: from dau-home-pc.megasoftware.org ([212.35.163.35])
        by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5c1bcf332e3sm2859535e87.1.2026.11.23.02.42.21
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Mon, 23 Nov 2026 02:42:21 -0800 (PST)
X-Cc: "David S . Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>,
	Paolo Abeni <pabeni@redhat.com>,
	Simon Horman <horms@kernel.org>,
	David Ahern <dsahern@kernel.org>,
	Ido Schimmel <idosch@nvidia.com>,
	linux-kernel@vger.kernel.org
X-Mailer: git-send-email 2.47.3
X-In-Reply-To: <20261123104210.199916-1-littlesmilingcloud@gmail.com>
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list