Netdev List
 help / color / mirror / Atom feed
* [PATCH iproute2] ip route: check return value of addraw_l() when adding encap
@ 2026-11-02  9:05 Fang Jiabao
  2026-11-09  2:54 ` Stephen Hemminger
  0 siblings, 1 reply; 2+ messages in thread
From: Fang Jiabao @ 2026-11-02  9:05 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: netdev, Fang Jiabao

iproute_modify() ignores the return value of addraw_l() when it adds
the encap attribute. If the attribute does not fit into the request,
for example a seg6 encap with 60 segments, addraw_l() prints
"addraw_l ERROR: message exceeded bound of 1024" and returns -1, but
ip sends the request without the encap attribute and exits with
status 0. A route without encap is then installed silently.

Return an error instead of sending the incomplete request.

Fixes: 1e5293056a02 ("lwtunnel: Add encapsulation support to ip route")
Assisted-by: Claude:claude-sonnet-5-5
Signed-off-by: Fang Jiabao <kaquoin@163.com>
---
Tested on current main (e4cd9f1d, "json_writer: fix pretty printing of
arrays"), in a network namespace with a dummy device:

  ip -6 route add fc00:ff::60/128 encap seg6 mode encap segs <60 SIDs> dev d0

Before: "addraw_l ERROR: message exceeded bound of 1024", exit status 0,
and a route without encap was installed.
After: same message, exit status 1, no route installed.
With 59 segments the route is still added with encap, exit status 0.

With 63 or more segments the failure happens earlier, in the encap
parsing, with a different error. That is not addressed here. The same
addraw_l() pattern exists in ip/ipnexthop.c and is not changed here.

 ip/iproute.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/ip/iproute.c b/ip/iproute.c
index 1ce71f78..35c23801 100644
--- a/ip/iproute.c
+++ b/ip/iproute.c
@@ -1525,9 +1525,10 @@ static int iproute_modify(int cmd, unsigned int flags, int argc, char **argv)
 			lwt_parse_encap(rta, sizeof(buf), &argc, &argv,
 					RTA_ENCAP, RTA_ENCAP_TYPE);
 
-			if (rta->rta_len > RTA_LENGTH(0))
-				addraw_l(&req.n, 1024
-					 , RTA_DATA(rta), RTA_PAYLOAD(rta));
+			if (rta->rta_len > RTA_LENGTH(0) &&
+			    addraw_l(&req.n, 1024, RTA_DATA(rta),
+				     RTA_PAYLOAD(rta)) < 0)
+				return -1;
 		} else if (strcmp(*argv, "ttl-propagate") == 0) {
 			__u8 ttl_prop;
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-09  2:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-02  9:05 [PATCH iproute2] ip route: check return value of addraw_l() when adding encap Fang Jiabao
2026-11-09  2:54 ` Stephen Hemminger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox