🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
4 messages
4 total messages Started by Gabriel Goller Fri, 09 Oct 2026 15:20
[PATCH net-next v5] net: ipv6: seg6: report lwtunnel setup errors via extack
#1343
Author: Gabriel Goller
Date: Fri, 09 Oct 2026 15:20
107 lines
8368 bytes
seg6_build_state() rejected invalid configurations with a generic -EINVAL,
so "ip route add ... encap seg6 ..." sometimes reported "Invalid argument".

Add extack messages to the checks that lacked one, and use
NL_REQ_ATTR_CHECK() for the missing SRH attribute so that userspace can
tell which attribute is missing. The checks themselves and their return
values are unchanged.

Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
---

v5 (https://lore.kernel.org/all/20261005140637.644840-1-g.goller@proxmox.com/):
 * use NL_REQ_ATTR_CHECK() for the missing SRH attribute (Jakub)
 * reword the inline mode message to "inline mode requires the IPv6
   address family", since it also applies to IPv4 nexthop objects
   (Andrea)
 * consistently call the header "IPv6 Segment Routing Header" (RFC 8754)
   in all messages (Andrea)
 * include the offending mode value in the invalid mode message
 * reword the commit message to match

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 | 26 +++++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/net/ipv6/seg6_iptunnel.c b/net/ipv6/seg6_iptunnel.c
index 69a6ef5c5317..0d39a38a5dd2 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,7 +774,7 @@ static int seg6_build_state(struct net *net, struct nlattr *nla,
 	if (err < 0)
 		return err;
 
-	if (!tb[SEG6_IPTUNNEL_SRH])
+	if (NL_REQ_ATTR_CHECK(extack, nla, tb, SEG6_IPTUNNEL_SRH))
 		return -EINVAL;
 
 	tuninfo = nla_data(tb[SEG6_IPTUNNEL_SRH]);
@@ -782,13 +785,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 IPv6 Segment Routing Header 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 the IPv6 address family");
 			return -EINVAL;
+		}
 
 		if (tb[SEG6_IPTUNNEL_SRC]) {
 			NL_SET_ERR_MSG(extack, "incompatible mode for tunsrc");
@@ -804,12 +813,19 @@ static int seg6_build_state(struct net *net, struct nlattr *nla,
 	case SEG6_IPTUN_MODE_L2ENCAP_RED:
 		break;
 	default:
+		NL_SET_ERR_MSG_ATTR_FMT(extack, tb[SEG6_IPTUNNEL_SRH],
+					"invalid SRv6 encapsulation mode %d",
+					tuninfo->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 IPv6 Segment Routing Header");
 		return -EINVAL;
+	}
 
 	newts = lwtunnel_state_alloc(tuninfo_len + sizeof(*slwt));
 	if (!newts)
-- 
2.47.3
Re: [PATCH net-next v5] net: ipv6: seg6: report lwtunnel setup errors via extack
#2639
Author: Hangbin Liu
Date: Tue, 13 Oct 2026 06:14
115 lines
9878 bytes
Hi Gabriel,
On Fri, Oct 09, 2026 at 05:20:13PM +0200, Gabriel Goller wrote:
> seg6_build_state() rejected invalid configurations with a generic -EINVAL,
> so "ip route add ... encap seg6 ..." sometimes reported "Invalid argument".
> 
> Add extack messages to the checks that lacked one, and use
> NL_REQ_ATTR_CHECK() for the missing SRH attribute so that userspace can
> tell which attribute is missing. The checks themselves and their return
> values are unchanged.
> 
> Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
> ---
> 
> v5 (https://lore.kernel.org/all/20261005140637.644840-1-g.goller@proxmox.com/):
>  * use NL_REQ_ATTR_CHECK() for the missing SRH attribute (Jakub)
>  * reword the inline mode message to "inline mode requires the IPv6
>    address family", since it also applies to IPv4 nexthop objects
>    (Andrea)
>  * consistently call the header "IPv6 Segment Routing Header" (RFC 8754)
>    in all messages (Andrea)
>  * include the offending mode value in the invalid mode message
>  * reword the commit message to match
> 
> 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 | 26 +++++++++++++++++++++-----
>  1 file changed, 21 insertions(+), 5 deletions(-)
> 
> diff --git a/net/ipv6/seg6_iptunnel.c b/net/ipv6/seg6_iptunnel.c
> index 69a6ef5c5317..0d39a38a5dd2 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,7 +774,7 @@ static int seg6_build_state(struct net *net, struct nlattr *nla,
>  	if (err < 0)
>  		return err;
>  
> -	if (!tb[SEG6_IPTUNNEL_SRH])
> +	if (NL_REQ_ATTR_CHECK(extack, nla, tb, SEG6_IPTUNNEL_SRH))
>  		return -EINVAL;
>  
>  	tuninfo = nla_data(tb[SEG6_IPTUNNEL_SRH]);
> @@ -782,13 +785,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 IPv6 Segment Routing Header 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 the IPv6 address family");
>  			return -EINVAL;
> +		}
>  
>  		if (tb[SEG6_IPTUNNEL_SRC]) {
>  			NL_SET_ERR_MSG(extack, "incompatible mode for tunsrc");
> @@ -804,12 +813,19 @@ static int seg6_build_state(struct net *net, struct nlattr *nla,
>  	case SEG6_IPTUN_MODE_L2ENCAP_RED:
>  		break;
>  	default:
> +		NL_SET_ERR_MSG_ATTR_FMT(extack, tb[SEG6_IPTUNNEL_SRH],
> +					"invalid SRv6 encapsulation mode %d",
> +					tuninfo->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 IPv6 Segment Routing Header");
>  		return -EINVAL;
> +	}
>  
>  	newts = lwtunnel_state_alloc(tuninfo_len + sizeof(*slwt));
>  	if (!newts)
> -- 
> 2.47.3
> 
> 

Thanks for the update.

Reviewed-by: Hangbin Liu <liuhangbin@kylinos.cn>
Re: [PATCH net-next v5] net: ipv6: seg6: report lwtunnel setup errors via extack
#2840
Author: Andrea Mayer
Date: Tue, 13 Oct 2026 16:04
58 lines
9267 bytes
On Fri,  9 Oct 2026 17:20:13 +0200
Gabriel Goller <g.goller@proxmox.com> wrote:

Hi Gabriel,

thanks for the v5.

> seg6_build_state() rejected invalid configurations with a generic -EINVAL,
> so "ip route add ... encap seg6 ..." sometimes reported "Invalid argument".
> 
> Add extack messages to the checks that lacked one, and use
> NL_REQ_ATTR_CHECK() for the missing SRH attribute so that userspace can
> tell which attribute is missing. The checks themselves and their return
> values are unchanged.
> 
> Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
> ---
> 
> v5 (https://lore.kernel.org/all/20261005140637.644840-1-g.goller@proxmox.com/):
>  * use NL_REQ_ATTR_CHECK() for the missing SRH attribute (Jakub)
>  * reword the inline mode message to "inline mode requires the IPv6
>    address family", since it also applies to IPv4 nexthop objects
>    (Andrea)
>  * consistently call the header "IPv6 Segment Routing Header" (RFC 8754)
>    in all messages (Andrea)
>  * include the offending mode value in the invalid mode message
>  * reword the commit message to match
> 
> 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 | 26 +++++++++++++++++++++-----
>  1 file changed, 21 insertions(+), 5 deletions(-)
> 
> [snip]
>  	default:
> +		NL_SET_ERR_MSG_ATTR_FMT(extack, tb[SEG6_IPTUNNEL_SRH],
> +					"invalid SRv6 encapsulation mode %d",
> +					tuninfo->mode);
>  		return -EINVAL;

A small nit on this one, as it is new in v5: I would have kept the
v4 text here, "invalid SRv6 encapsulation mode". No need for a new
version just for this.

Reviewed-by: Andrea Mayer <andrea.mayer@uniroma2.it>

Thanks,
Andrea
Re: [PATCH net-next v5] net: ipv6: seg6: report lwtunnel setup errors via extack
#3543
Author: patchwork-bot+netdevbpf
Date: Thu, 15 Oct 2026 10:40
25 lines
6368 bytes
Hello:

This patch was applied to netdev/net-next.git (main)
by Paolo Abeni <pabeni@redhat.com>:

On Fri,  9 Oct 2026 17:20:13 +0200 you wrote:
> seg6_build_state() rejected invalid configurations with a generic -EINVAL,
> so "ip route add ... encap seg6 ..." sometimes reported "Invalid argument".
> 
> Add extack messages to the checks that lacked one, and use
> NL_REQ_ATTR_CHECK() for the missing SRH attribute so that userspace can
> tell which attribute is missing. The checks themselves and their return
> values are unchanged.
> 
> [...]

Here is the summary with links:
  - [net-next,v5] net: ipv6: seg6: report lwtunnel setup errors via extack
    https://git.kernel.org/netdev/net-next/c/a39a3a32785e

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads