From: Gabriel Goller <g.goller@proxmox.com>
To: Andrea Mayer <andrea.mayer@uniroma2.it>,
"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>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v4] net: ipv6: seg6: report lwtunnel setup errors via extack
Date: Mon, 5 Oct 2026 16:06:34 +0200 [thread overview]
Message-ID: <20261005140637.644840-1-g.goller@proxmox.com> (raw)
seg6_build_state() rejected invalid configurations with a generic -EINVAL,
so "ip route add ... encap seg6 ..." always reported "Invalid argument".
Attach an extack message to each of them. The checks themselves and their
return values are unchanged.
Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
---
v4 (https://lore.kernel.org/all/20260923120228.172643-1-g.goller@proxmox.com/):
* use NL_SET_ERR_MSG when the SRH attr is missing
* use NL_SET_ERR_MSG_ATTR when we have an invalid attr
v3 (https://lore.kernel.org/all/20260922090851.38978-1-g.goller@proxmox.com/):
* format fix
* use NL_SET_ERR_MSG_ATTR
v2 (https://lore.kernel.org/all/20260918153544.1178884-1-g.goller@proxmox.com/):
* dropped tests
net/ipv6/seg6_iptunnel.c | 27 ++++++++++++++++++++++-----
1 file changed, 22 insertions(+), 5 deletions(-)
diff --git a/net/ipv6/seg6_iptunnel.c b/net/ipv6/seg6_iptunnel.c
index 69a6ef5c5317..73160179a545 100644
--- a/net/ipv6/seg6_iptunnel.c
+++ b/net/ipv6/seg6_iptunnel.c
@@ -762,8 +762,11 @@ static int seg6_build_state(struct net *net, struct nlattr *nla,
struct seg6_lwt *slwt;
int err;
- if (family != AF_INET && family != AF_INET6)
+ if (family != AF_INET && family != AF_INET6) {
+ NL_SET_ERR_MSG(extack,
+ "unsupported address family for SRv6 encapsulation");
return -EINVAL;
+ }
err = nla_parse_nested_deprecated(tb, SEG6_IPTUNNEL_MAX, nla,
seg6_iptunnel_policy, extack);
@@ -771,8 +774,10 @@ static int seg6_build_state(struct net *net, struct nlattr *nla,
if (err < 0)
return err;
- if (!tb[SEG6_IPTUNNEL_SRH])
+ if (!tb[SEG6_IPTUNNEL_SRH]) {
+ NL_SET_ERR_MSG(extack, "missing SRv6 SRH attribute");
return -EINVAL;
+ }
tuninfo = nla_data(tb[SEG6_IPTUNNEL_SRH]);
tuninfo_len = nla_len(tb[SEG6_IPTUNNEL_SRH]);
@@ -782,13 +787,19 @@ static int seg6_build_state(struct net *net, struct nlattr *nla,
*/
min_size = sizeof(*tuninfo) + sizeof(struct ipv6_sr_hdr) +
sizeof(struct in6_addr);
- if (tuninfo_len < min_size)
+ if (tuninfo_len < min_size) {
+ NL_SET_ERR_MSG_ATTR(extack, tb[SEG6_IPTUNNEL_SRH],
+ "truncated SRv6 SRH attribute");
return -EINVAL;
+ }
switch (tuninfo->mode) {
case SEG6_IPTUN_MODE_INLINE:
- if (family != AF_INET6)
+ if (family != AF_INET6) {
+ NL_SET_ERR_MSG_ATTR(extack, tb[SEG6_IPTUNNEL_SRH],
+ "inline mode requires an IPv6 route");
return -EINVAL;
+ }
if (tb[SEG6_IPTUNNEL_SRC]) {
NL_SET_ERR_MSG(extack, "incompatible mode for tunsrc");
@@ -804,12 +815,18 @@ static int seg6_build_state(struct net *net, struct nlattr *nla,
case SEG6_IPTUN_MODE_L2ENCAP_RED:
break;
default:
+ NL_SET_ERR_MSG_ATTR(extack, tb[SEG6_IPTUNNEL_SRH],
+ "invalid SRv6 encapsulation mode");
return -EINVAL;
}
/* verify that SRH is consistent */
- if (!seg6_validate_srh(tuninfo->srh, tuninfo_len - sizeof(*tuninfo), false))
+ if (!seg6_validate_srh(tuninfo->srh, tuninfo_len - sizeof(*tuninfo),
+ false)) {
+ NL_SET_ERR_MSG_ATTR(extack, tb[SEG6_IPTUNNEL_SRH],
+ "invalid SRv6 segment routing header");
return -EINVAL;
+ }
newts = lwtunnel_state_alloc(tuninfo_len + sizeof(*slwt));
if (!newts)
--
2.47.3
next reply other threads:[~2026-10-05 14:06 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-05 14:06 Gabriel Goller [this message]
2026-10-05 21:18 ` Jakub Kicinski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261005140637.644840-1-g.goller@proxmox.com \
--to=g.goller@proxmox.com \
--cc=andrea.mayer@uniroma2.it \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®