[PATCH net-next 1/6] net: lwtunnel: change encap fill order

From: Hangbin Liu

Date: Thu Sep 17 2026 - 02:37:39 EST


From: Hangbin Liu <liuhangbin@xxxxxxxxxx>

When decoding sub‑messages, YNL tries to fetch the "selector" (encap‑type)
first. However, lwtunnel fills encap‑payload data first, which causes YNL
to fail decoding the lwtunnel encap message.

Fixing this inside YNL would be complex, so change the order in the kernel
and emit encap_type first.

Signed-off-by: Hangbin Liu <liuhangbin@xxxxxxxxxx>
---
net/core/lwtunnel.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/net/core/lwtunnel.c b/net/core/lwtunnel.c
index b01a395d9a96..f13dfa02e026 100644
--- a/net/core/lwtunnel.c
+++ b/net/core/lwtunnel.c
@@ -240,6 +240,10 @@ int lwtunnel_fill_encap(struct sk_buff *skb, struct lwtunnel_state *lwtstate,
lwtstate->type > LWTUNNEL_ENCAP_MAX)
return 0;

+ ret = nla_put_u16(skb, encap_type_attr, lwtstate->type);
+ if (ret)
+ return ret;
+
nest = nla_nest_start_noflag(skb, encap_attr);
if (!nest)
return -EMSGSIZE;
@@ -254,9 +258,6 @@ int lwtunnel_fill_encap(struct sk_buff *skb, struct lwtunnel_state *lwtstate,
if (ret)
goto nla_put_failure;
nla_nest_end(skb, nest);
- ret = nla_put_u16(skb, encap_type_attr, lwtstate->type);
- if (ret)
- goto nla_put_failure;

return 0;


--
2.55.0