Subject: [PATCH v1 2/2] ipv6: always accept routing headers with 0 segments left

From: Mathis Marion <[email-masked]>
Date: Mon, 24 Jun 2024 16:15:33 +0200

From: Mathis Marion <[email-masked]>

Routing headers of type 3 and 4 would be rejected even if segments left
was 0, in the case that they were disabled through system configuration.

RFC 8200 section 4.4 specifies:

      If Segments Left is zero, the node must ignore the Routing header
      and proceed to process the next header in the packet, whose type
      is identified by the Next Header field in the Routing header.

Signed-off-by: Mathis Marion <[email-masked]>
---
 net/ipv6/exthdrs.c | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/net/ipv6/exthdrs.c b/net/ipv6/exthdrs.c
index 083dbbafb166..913160b0fe13 100644
--- a/net/ipv6/exthdrs.c
+++ b/net/ipv6/exthdrs.c
@@ -662,17 +662,6 @@ static int ipv6_rthdr_rcv(struct sk_buff *skb)
 		return -1;
 	}
 
-	switch (hdr->type) {
-	case IPV6_SRCRT_TYPE_4:
-		/* segment routing */
-		return ipv6_srh_rcv(skb);
-	case IPV6_SRCRT_TYPE_3:
-		/* rpl segment routing */
-		return ipv6_rpl_srh_rcv(skb);
-	default:
-		break;
-	}
-
 looped_back:
 	if (hdr->segments_left == 0) {
 		switch (hdr->type) {
@@ -708,6 +697,12 @@ static int ipv6_rthdr_rcv(struct sk_buff *skb)
 		}
 		break;
 #endif
+	case IPV6_SRCRT_TYPE_3:
+		/* rpl segment routing */
+		return ipv6_rpl_srh_rcv(skb);
+	case IPV6_SRCRT_TYPE_4:
+		/* segment routing */
+		return ipv6_srh_rcv(skb);
 	default:
 		goto unknown_rh;
 	}
-- 
2.43.0