From patchwork Mon Jun 24 14:15:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathis Marion X-Patchwork-Id: 13709582 X-Patchwork-Delegate: kuba@kernel.org Received: from mx0a-0024c301.pphosted.com (mx0a-0024c301.pphosted.com [148.163.149.154]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D780D19AA7F; Mon, 24 Jun 2024 14:32:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=148.163.149.154 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719239558; cv=fail; b=Kj1gSGUTP3JgYraRV5UzgSaARfM5Ext+kHsiwgmx506GeIAqr0vCnN4BqS7xDnFcCLQJnxvMGOhYY0pKUkXnVEQ2tOiMJI2o0/A5zfuqUvakB3LIVVe72jqpw/3e3XsAjVbRoqy+cO5sfqmqbQrBypuHdmoTiXprWs74htGiIPM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719239558; c=relaxed/simple; bh=UsHNUw7NnubdlyS+khngAJbLx9mDlzjwZUXC61i6N0s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=D+0kxg8j+iHbbQJz8hWznAhpbWopdhYnbT04hMC8HIvNd6sh5pCk9UWf1Ntd2T1yEdbSXMvnBexJatPf/RYnzyaOoZBib4D9wpQVFWj3AyHWmc2hsjoFm10VmjxYlxtfHRKlQDPtaMkh93dz+cZ3t49nsk4mt4LT1/RvMqEM4JM= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=silabs.com; spf=pass smtp.mailfrom=silabs.com; dkim=pass (2048-bit key) header.d=silabs.com header.i=@silabs.com header.b=Pw2olDuL; dkim=pass (1024-bit key) header.d=silabs.com header.i=@silabs.com header.b=S2iMAbTu; arc=fail smtp.client-ip=148.163.149.154 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=silabs.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=silabs.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=silabs.com header.i=@silabs.com header.b="Pw2olDuL"; dkim=pass (1024-bit key) header.d=silabs.com header.i=@silabs.com header.b="S2iMAbTu" Received: from pps.filterd (m0101743.ppops.net [127.0.0.1]) by mx0a-0024c301.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 45ODYZZo011774; Mon, 24 Jun 2024 09:16:57 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=silabs.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pps12202023; bh=UsHNUw7NnubdlyS+khngAJbLx9mDlzjwZUXC61i6N0s=; b=Pw2olDuL9QR7 VXVazgOsidR5uO63veGalZQoeyLRZ5AcXV5mk0CD1nanaJeNkELcd6/UKgR7BseG Y4YjwaXnVg0BiIhOsDXlXWxkWZSjYKSZhjvlm1vsZK88LbWlkAG7GLczmaInsmF/ 31P3DRr4f6iBJTnshh7sV6RoC+6/a2We0mOtWtvpM+S74B6a+sfzzzhJNxDpAzjl LuWgknocXZ17pm2a0wSDQg6ElLdjpfeUmgc684rBIdbSyROBJrj3oHFY09jpG05V x6IJcFgNa7cA3syXs+mcldKcULS5xtZRA6OSVjU6m6GdaOCfY2h1fk93Gd9+R2MZ j55MVZpXeg== Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2169.outbound.protection.outlook.com [104.47.56.169]) by mx0a-0024c301.pphosted.com (PPS) with ESMTPS id 3ywtx92e3d-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 24 Jun 2024 09:16:56 -0500 (CDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jkSvnmhQIqETa2vjAxxPVfCiRwY5KIKuwVWgikakUBdo/h6Xre4jNozaFXtZpLWNTnrgHxAQo3paakH+qksTDuZAJFiSnHcdO4fMq1hwuK2pME8jXWvNwLN8KEo7XzkCndiyI34JUvQ4So9cTJD89Oocj+rx+EaJzJwD9dWELpgify91OEgkq+bw4lfaaW0MGFjMPAA7NY6JSqATk2AMNb+uHGXbwk1U6IesLx5jZPTH6Psfvcx5JFHnRupxUMh1NQF5u3swqK3c41ydwuDjcOjWbXmM9o6t7D4NTS0iPXYq43az+Hxy/HimsGpIyF7i6pjMjAGwyPLSxUI3GVqycA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=UsHNUw7NnubdlyS+khngAJbLx9mDlzjwZUXC61i6N0s=; b=WeHYiqeefQkemGNhWRMTJXv/FckMMA2UwIyoCmoj+udyCbFQl0yxtJfvM+Am0T21/WjZa5DT/zpgGLqxY3F6OTDM4Zj7etejXb1+HF67qwcs+gjzgVW4sRaYOAPJ6jz4zz5eIV8ZoDf80svoEyutvwjQQvoK9ld6O1aQzh50Fzc/68fThMln3g93k4f6HD+83QV+839S7YD325EKjkTl2ur3rGVYC06E4wqgFZGfFmZsbaOLKhqQo6RqdzFBggZP7KG6hDsdGpRXrx8fqWESOt3SK3chyrAv9Vote73r+jV7xC66oGivlWn4MDGtNkDQS4FdJgYF2aKlONrGHe3bng== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=silabs.com; dmarc=pass action=none header.from=silabs.com; dkim=pass header.d=silabs.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=silabs.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UsHNUw7NnubdlyS+khngAJbLx9mDlzjwZUXC61i6N0s=; b=S2iMAbTuifCFSeuleEZYUAAN+C2H+B7Vf6Ap1uzES9TteW78QyzYOQah4oY7zp2NVw9jrgo+hHanN+QfK4ewhLnVhHt0PNIIopbIWBwpjTuR3unc1dSLZfwQOU2KcZQiEhRIaZ20cNixRltADV3BXmZNJYs1FJHUyDZjJykgfMg= Received: from MN2PR11MB4711.namprd11.prod.outlook.com (2603:10b6:208:24e::13) by LV3PR11MB8765.namprd11.prod.outlook.com (2603:10b6:408:21d::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7698.28; Mon, 24 Jun 2024 14:16:53 +0000 Received: from MN2PR11MB4711.namprd11.prod.outlook.com ([fe80::592e:a53b:e0b4:5da7]) by MN2PR11MB4711.namprd11.prod.outlook.com ([fe80::592e:a53b:e0b4:5da7%5]) with mapi id 15.20.7698.025; Mon, 24 Jun 2024 14:16:53 +0000 From: Mathis Marion To: "David S. Miller" , David Ahern , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?b?SsOpcsO0?= =?utf-8?b?bWUgUG91aWxsZXI=?= , Kylian Balan , Alexander Aring , Mathis Marion Subject: [PATCH v1 1/2] ipv6: introduce ipv6_rthdr_rcv_last() Date: Mon, 24 Jun 2024 16:15:32 +0200 Message-ID: <20240624141602.206398-2-Mathis.Marion@silabs.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240624141602.206398-1-Mathis.Marion@silabs.com> References: <20240624141602.206398-1-Mathis.Marion@silabs.com> X-ClientProxiedBy: LO4P265CA0273.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:37a::10) To MN2PR11MB4711.namprd11.prod.outlook.com (2603:10b6:208:24e::13) Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN2PR11MB4711:EE_|LV3PR11MB8765:EE_ X-MS-Office365-Filtering-Correlation-Id: 710ed98b-e27a-41b5-fac1-08dc94584c48 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|366013|52116011|376011|1800799021|38350700011; X-Microsoft-Antispam-Message-Info: 4j+wvJtH8Ote7fKsdYMU+xss3LYNgbL3We97QP732lKID5wwxWaxJM2g/LFObZMAzW6yyjIEW6xPLfQE5yUynJGzvN7ldsBmKvprphYdyglLhWL+vfuQT2d7yKnb+09ESqZRgmw0MsPLvTENyiBA3QIwsBLPx8qqmXSmX64iZK/LgHJRS4zQK8J0OzLwvvfqggpESnOQsohay28tJsMw1M1jy+t+rZuO/bvtrCE+8oyaAG5Gir+U3cR6NNLO0UTLp2CflgptBaVHgMJxbuYtfJGfdjds6S3Cj376pwFi66QzocRZBHBH9oDOTfQES4BUC7rZ9GIUG7YuX0P3zxJsOEY12EKVh/i88Ba3nW0XkL7MMLyYlwqJWe94AmcfnI5t14N3a6WTZM4pEjEF2AhjGQMO85WWkvJSAsMFnOrRk8EW3xz2bH4RqrgGU54Dwm6lzDWnvPHOhOJGLBEXYn9i4bnqCIzEfV14a+osh+wSWbxhN5kex3kciIoimpLfm4npXXogJF6ssRJIgV1nyGfQXPS/mC8WAAKB+YwELhKIEWXwLJAFdJlbubo7X5r9cFQo+Ds/p8Qh3oD0LzTNK9vLLoC+TlfUZeWooKvIVBZcpuayYPWssVvn/GJxkrN1ldhoraymAIXQXm1c0RktAVcHbsj5CyYT1Cqd5UweEXQxk1csjtUEQtoHETxK0RpY+4qH6eN49am/RExGw/1bgQYhWCYTVjdbxEvmZ27O0dWgruH/ADPnFpuGeNVoCYukeWOumfWSZnNMqak1+XhmL7BFjb3OrKgLA2ZfcbC5jOgj8SAi7gcyQBaCEv/YryGg25zZLq+RzjLzRP+O7sXIWlS1nPOklzVM+ae5q8NWI/YjpkumFgjMkmmH3ZdkjJ10GVZQMasewHZ3J5Su2L3EcpMKphiSoIWVmUfuBE8AbS9vFakmvQ64ZjignfUmXn2JdpUlwXL1ffW8QCNgKipLo5wuyyiDFQacfyQBzZ9GtN7Ja4vaZRs9HD/heMbZkZ/U0I1Ow9S+G1h5J09hz3/znBGFE74scjzlA+GmoBgP8X2IxuJC80AHCoVFE5c/HsE67dN5GTf2FbOgjcklSgvo8q8V6NI3aQVLUy0kGqxIYTAtpJNBdi9u322q+PHYVXRp5gPxgi/hSI3GH8/PhHJV5H3antC3R0UDHHvvgzphGB4Bgy9fhiB7qtGJbmhsVdBUacx71OQyNSMvoTwZz2qXI+fLuDopj3HcNV0d/tw17/Zj9u3PnnRlrPL1Yrda8qv2Srlf12Z6tk3QNx7Z+Bwxkj6+kJmc/ERh1PUCClBW27xSsCYouYqwQFvybP3hFhTb0j3N9LFu15OdBOgSNqNaxHKq0LRU4te+Sn+iXXlmEfLXd7A= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MN2PR11MB4711.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230037)(366013)(52116011)(376011)(1800799021)(38350700011);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Hn5I/HmvBMRHyqfOj3ZhD6EPwjTrae/6+l5j2HWlC/Le99DYWR4Tn+Vvyy4GeGDHLoFqO9yPchfWqZWTP+F0+qxEFJgMA4Hns9mnIFOTKsBZF3xty2gCnf/SCazkN9RraRUIsa9XOeJ2s2ASe6UYXU4qQzM/V1nxJxR1CP7WVO66UZhqrABIdFtpEwJZpxH+eECkAzbCAkjp0lQJ7S+EL8rTULws05VhEa0qoe1WXXcqptTz9uWGRigAa/sF9zacU1QDy+/6LE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KJSovKpjTzIoMww44n0Q3sZMYZp8norC8VD097Vf1v59skbO8WKccjHTlPd+2aR9BaDAnP2mAGLroVdZ8E27JdY6qoLCuzrf6RSLkiDTk3YZXrr5BUJU3880uQpIC2nZo9HknS9t+mnQAPKxradaZsy5J16iom/6KqpZHT4Db/Yj3XpB3gnyRcOQfYKkVjTa5fl0RIV75+cZLazlo01gndMfov9SWCuZpwmJFe1x4mUXJZDgh X-OriginatorOrg: silabs.com X-MS-Exchange-CrossTenant-Network-Message-Id: 710ed98b-e27a-41b5-fac1-08dc94584c48 X-MS-Exchange-CrossTenant-AuthSource: MN2PR11MB4711.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jun 2024 14:16:53.8726 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 54dbd822-5231-4b20-944d-6f4abcd541fb X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Y/WDuVk/IRwa/SrRV38Zqpz3xETFeRe4tQWi26nqEsGiRn03IV7Fb9kQWjF27XA8rUavPcKgIcoO2rLZJp4rzQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV3PR11MB8765 X-Proofpoint-GUID: UuVjjltVgkmlu-zlHvqjJoeYWaX6OYJG X-Proofpoint-ORIG-GUID: UuVjjltVgkmlu-zlHvqjJoeYWaX6OYJG X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-06-24_11,2024-06-24_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 clxscore=1015 priorityscore=1501 lowpriorityscore=0 mlxlogscore=980 mlxscore=0 suspectscore=0 bulkscore=0 phishscore=0 adultscore=0 malwarescore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2406140001 definitions=main-2406240114 From: Mathis Marion This factorizes some code between ipv6_srh_rcv(), ipv6_rpl_srh_rcv() and ipv6_rthdr_rcv(). Note that: - IPv4-in-IPv6 was previously only supported by ipv6_srh_rcv(). - IPv6-in-IPv6 was previously not supported in ipv6_rthdr_rcv(). Signed-off-by: Mathis Marion --- net/ipv6/exthdrs.c | 107 ++++++++++++++++++--------------------------- 1 file changed, 42 insertions(+), 65 deletions(-) diff --git a/net/ipv6/exthdrs.c b/net/ipv6/exthdrs.c index 6789623b2b0d..083dbbafb166 100644 --- a/net/ipv6/exthdrs.c +++ b/net/ipv6/exthdrs.c @@ -366,9 +366,45 @@ static void seg6_update_csum(struct sk_buff *skb) (__be32 *)addr); } -static int ipv6_srh_rcv(struct sk_buff *skb) +static int ipv6_rthdr_rcv_last(struct sk_buff *skb) { struct inet6_skb_parm *opt = IP6CB(skb); + struct net *net = dev_net(skb->dev); + const struct ipv6_rt_hdr *hdr; + + hdr = (struct ipv6_rt_hdr *)skb_transport_header(skb); + + if (hdr->nexthdr == NEXTHDR_IPV6 || hdr->nexthdr == NEXTHDR_IPV4) { + int offset = (hdr->hdrlen + 1) << 3; + + skb_postpull_rcsum(skb, skb_network_header(skb), + skb_network_header_len(skb)); + skb_pull(skb, offset); + skb_postpull_rcsum(skb, skb_transport_header(skb), offset); + + skb_reset_network_header(skb); + skb_reset_transport_header(skb); + skb->encapsulation = 0; + if (hdr->nexthdr == NEXTHDR_IPV4) + skb->protocol = htons(ETH_P_IP); + __skb_tunnel_rx(skb, skb->dev, net); + + netif_rx(skb); + return -1; + } + + opt->srcrt = skb_network_header_len(skb); + opt->lastopt = opt->srcrt; + skb->transport_header += (hdr->hdrlen + 1) << 3; + opt->dst0 = opt->dst1; + opt->dst1 = 0; + opt->nhoff = (&hdr->nexthdr) - skb_network_header(skb); + + return 1; +} + +static int ipv6_srh_rcv(struct sk_buff *skb) +{ struct net *net = dev_net(skb->dev); struct ipv6_sr_hdr *hdr; struct inet6_dev *idev; @@ -395,34 +431,8 @@ static int ipv6_srh_rcv(struct sk_buff *skb) #endif looped_back: - if (hdr->segments_left == 0) { - if (hdr->nexthdr == NEXTHDR_IPV6 || hdr->nexthdr == NEXTHDR_IPV4) { - int offset = (hdr->hdrlen + 1) << 3; - - skb_postpull_rcsum(skb, skb_network_header(skb), - skb_network_header_len(skb)); - skb_pull(skb, offset); - skb_postpull_rcsum(skb, skb_transport_header(skb), - offset); - - skb_reset_network_header(skb); - skb_reset_transport_header(skb); - skb->encapsulation = 0; - if (hdr->nexthdr == NEXTHDR_IPV4) - skb->protocol = htons(ETH_P_IP); - __skb_tunnel_rx(skb, skb->dev, net); - - netif_rx(skb); - return -1; - } - - opt->srcrt = skb_network_header_len(skb); - opt->lastopt = opt->srcrt; - skb->transport_header += (hdr->hdrlen + 1) << 3; - opt->nhoff = (&hdr->nexthdr) - skb_network_header(skb); - - return 1; - } + if (hdr->segments_left == 0) + return ipv6_rthdr_rcv_last(skb); if (hdr->segments_left >= (hdr->hdrlen >> 1)) { __IP6_INC_STATS(net, idev, IPSTATS_MIB_INHDRERRORS); @@ -482,7 +492,6 @@ static int ipv6_srh_rcv(struct sk_buff *skb) static int ipv6_rpl_srh_rcv(struct sk_buff *skb) { struct ipv6_rpl_sr_hdr *hdr, *ohdr, *chdr; - struct inet6_skb_parm *opt = IP6CB(skb); struct net *net = dev_net(skb->dev); struct inet6_dev *idev; struct ipv6hdr *oldhdr; @@ -506,33 +515,8 @@ static int ipv6_rpl_srh_rcv(struct sk_buff *skb) looped_back: hdr = (struct ipv6_rpl_sr_hdr *)skb_transport_header(skb); - if (hdr->segments_left == 0) { - if (hdr->nexthdr == NEXTHDR_IPV6) { - int offset = (hdr->hdrlen + 1) << 3; - - skb_postpull_rcsum(skb, skb_network_header(skb), - skb_network_header_len(skb)); - skb_pull(skb, offset); - skb_postpull_rcsum(skb, skb_transport_header(skb), - offset); - - skb_reset_network_header(skb); - skb_reset_transport_header(skb); - skb->encapsulation = 0; - - __skb_tunnel_rx(skb, skb->dev, net); - - netif_rx(skb); - return -1; - } - - opt->srcrt = skb_network_header_len(skb); - opt->lastopt = opt->srcrt; - skb->transport_header += (hdr->hdrlen + 1) << 3; - opt->nhoff = (&hdr->nexthdr) - skb_network_header(skb); - - return 1; - } + if (hdr->segments_left == 0) + return ipv6_rthdr_rcv_last(skb); n = (hdr->hdrlen << 3) - hdr->pad - (16 - hdr->cmpre); r = do_div(n, (16 - hdr->cmpri)); @@ -648,7 +632,6 @@ static int ipv6_rpl_srh_rcv(struct sk_buff *skb) static int ipv6_rthdr_rcv(struct sk_buff *skb) { struct inet6_dev *idev = __in6_dev_get(skb->dev); - struct inet6_skb_parm *opt = IP6CB(skb); struct in6_addr *addr = NULL; int n, i; struct ipv6_rt_hdr *hdr; @@ -709,13 +692,7 @@ static int ipv6_rthdr_rcv(struct sk_buff *skb) default: break; } - - opt->lastopt = opt->srcrt = skb_network_header_len(skb); - skb->transport_header += (hdr->hdrlen + 1) << 3; - opt->dst0 = opt->dst1; - opt->dst1 = 0; - opt->nhoff = (&hdr->nexthdr) - skb_network_header(skb); - return 1; + return ipv6_rthdr_rcv_last(skb); } switch (hdr->type) { From patchwork Mon Jun 24 14:15:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathis Marion X-Patchwork-Id: 13709581 X-Patchwork-Delegate: kuba@kernel.org Received: from mx0a-0024c301.pphosted.com (mx0a-0024c301.pphosted.com [148.163.149.154]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D77C219AA75; Mon, 24 Jun 2024 14:32:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=148.163.149.154 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719239558; cv=fail; b=M0vEabnBvqvUREy5phD8jndA61GZDjUc9H53wzjOcy6K/pmoClQK/tw+T+j/MxS2whfaziu4HqnB8P2S3TQCs4tPCmvOmFwaHbzKxVAIu4iaOZvCFl9bb8jE0/EZum5BZ32CtThfaMKWGUiuwHsFMzTn1obIdkUYLwhGfzDzctg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719239558; c=relaxed/simple; bh=QqtdTgNKDbGi8f3sjq6SGjA6IAg+4fwges695fR2Y8A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=jY1l3lzFrlkW6pfN3KLhp58XSJ80myB0YcYpXwzGTt9M09fMyqFNe1cbEW2Nuxu5GhlWlo7g8FHRFGhE735NUxXxCE0lMlOCfICXxj6GVfjos/aIVrCjUDpWBOv4CgTov4OB9WoGULc21EPwmYCOsge8DkL5/cDHxpMXqXzZbRE= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=silabs.com; spf=pass smtp.mailfrom=silabs.com; dkim=pass (2048-bit key) header.d=silabs.com header.i=@silabs.com header.b=OSTu6s6C; dkim=pass (1024-bit key) header.d=silabs.com header.i=@silabs.com header.b=eIIltfhT; arc=fail smtp.client-ip=148.163.149.154 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=silabs.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=silabs.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=silabs.com header.i=@silabs.com header.b="OSTu6s6C"; dkim=pass (1024-bit key) header.d=silabs.com header.i=@silabs.com header.b="eIIltfhT" Received: from pps.filterd (m0101743.ppops.net [127.0.0.1]) by mx0a-0024c301.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 45ODYZZr011774; Mon, 24 Jun 2024 09:16:59 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=silabs.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pps12202023; bh=QqtdTgNKDbGi8f3sjq6SGjA6IAg+4fwges695fR2Y8A=; b=OSTu6s6CTwqz mm/shboKOOxR0rY2RUYjZ3sus8a/SN2NSvhnN/g+7w8A6xhQp770lmhsdVHGw/ZR +Hsq1eteUrjQzDB+J+wJLUsSiH4lep+vIrqMpXEcrZ52xBE3T6bXwP07e5Dm9QI8 hf3sZA8EWUjKEs054x0nzX5WXcejiv7yZutX3SNghQFjNfnD3b/caKHOSTutPbK0 s/nEQBypQcspDj9jlhgUA+5T8lKyLc9AEqVKiYKvefldAxytlX7iZI5H73UlYE2n jEugDFYin6Sdd8u+NayzmkI0e9Wq0wq0igN492RA+Cm9YcGIC2irVOggFUmvckwz 70grcoiQvw== Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2169.outbound.protection.outlook.com [104.47.56.169]) by mx0a-0024c301.pphosted.com (PPS) with ESMTPS id 3ywtx92e3d-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 24 Jun 2024 09:16:58 -0500 (CDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=O/0Y9GyAT7/FGT0aGalTE0hEea3U5VFV6I0fUD66xpNEg688/6AL0BOWAbUpHNWBjSxia0i8A7ZO3XIW/irklaVmz2Go6HKxWRJQAwazJb5geyggj/oxEP9on//OpO1SFKDuEQ04WsFWrz3PPBlcv0Krg87d+Feqgx4cvlP9Zjy+sQs6fBC03jy5tJ8fuAhjVbavONDo3A3POykpF+rd6QFtLOkY1SdzibGKidrGotpM9Z+S7ZDJlrXdJGg2BxogdqlfSL1nEY0gvubRItt0zzMehzO7HV5Sk3LzxcW7d2WAMCCDLTFv+aJgFgpDfRYGwg1i+UbegNunWitNr5/Drw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=QqtdTgNKDbGi8f3sjq6SGjA6IAg+4fwges695fR2Y8A=; b=ZFwoSVsLldoeOvPkDArLLGCYoC0NDiDg+3KFOoDwbuu1t4QkFtZrpRfe0jLa+4py7zTNRWlo/Ja+k0i6FHeA7xFLUu39SvAm2pvIAeUVkRTia/NCDl7nA69O0Br2eoVwl3TVhlb7Yt1Qoq70i3KCiVxSq61HyOW8d2/aslnXZswl9uUWi0lpoAtJ+XkzbXYGSuOQ88BvNiqoI7dka/YMnxIJhsPjTdE12zTE2+WyTCQVIeeA5f3WsY9eFekS0+MM759JwHPUBIlSXRg+4q0U3s8VRwteI1iDST9Bb/ep3fpZOx4eO7n9XG4MhRHy10tGffF9jnedNR7o69JHgYNLKg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=silabs.com; dmarc=pass action=none header.from=silabs.com; dkim=pass header.d=silabs.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=silabs.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=QqtdTgNKDbGi8f3sjq6SGjA6IAg+4fwges695fR2Y8A=; b=eIIltfhTqMmIntWi+4M7Ab6ktc3p7cYuGz1ksCRlcynNE6pObBhypAM6Hl5bPO99MfeIJJnIyyIqMnXJIQLytPML/eqWAL5qY8Irt+EyRzsqOG317ZzNoF8ybPoVa1LJ7lJ2O6FjRmdUtNz+doK0PmPoUfwHeplZ+MmtConle14= Received: from MN2PR11MB4711.namprd11.prod.outlook.com (2603:10b6:208:24e::13) by LV3PR11MB8765.namprd11.prod.outlook.com (2603:10b6:408:21d::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7698.28; Mon, 24 Jun 2024 14:16:55 +0000 Received: from MN2PR11MB4711.namprd11.prod.outlook.com ([fe80::592e:a53b:e0b4:5da7]) by MN2PR11MB4711.namprd11.prod.outlook.com ([fe80::592e:a53b:e0b4:5da7%5]) with mapi id 15.20.7698.025; Mon, 24 Jun 2024 14:16:55 +0000 From: Mathis Marion To: "David S. Miller" , David Ahern , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?b?SsOpcsO0?= =?utf-8?b?bWUgUG91aWxsZXI=?= , Kylian Balan , Alexander Aring , Mathis Marion Subject: [PATCH v1 2/2] ipv6: always accept routing headers with 0 segments left Date: Mon, 24 Jun 2024 16:15:33 +0200 Message-ID: <20240624141602.206398-3-Mathis.Marion@silabs.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240624141602.206398-1-Mathis.Marion@silabs.com> References: <20240624141602.206398-1-Mathis.Marion@silabs.com> X-ClientProxiedBy: LO4P265CA0273.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:37a::10) To MN2PR11MB4711.namprd11.prod.outlook.com (2603:10b6:208:24e::13) Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN2PR11MB4711:EE_|LV3PR11MB8765:EE_ X-MS-Office365-Filtering-Correlation-Id: 284320b9-0cda-4ecc-1a9e-08dc94584d3a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|366013|52116011|376011|1800799021|38350700011; X-Microsoft-Antispam-Message-Info: 4JWu0cNAExAuYGbp0ejJX3nQmQzRfaGzilxWJiihPNgjrbHi4LrPh40a1vhbCYH5solMtsz3echFxBIpGaN354ibRIb1TEVkarcoT9FSPsUwVBuTG3/YBqN1IEVAV5m2WtTVbWsTsjdx7wl0Jta07//+yF8vNG5I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C2XBsiHWeAHIjfvkBgn3DbkrTn4h1YENt/2ZMbMT1GXM9kh4OjmBgtYWB7QkJr0XKr7iyMxQLMj2y+Zz+pXrwOcVlwc/1Sx0wanJlBzHFCxOqQEHqEtf6P7qlYIl47K/lZ93bhEETUAdWCK4rA= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MN2PR11MB4711.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230037)(366013)(52116011)(376011)(1800799021)(38350700011);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: S+VpGuHl36j4HQHPSbu8q4HbD4mgWb1geQxrMi3vt9cRFOml2Cf7Q3kQbmNRxpsBNcFRSDDQmT+fKrEnBHpjIj2GGzWhT7S0VZDDKeUDa5p0JCp2V16LpMHLLZt3UqtCsWcYo5mAU4XhcZSXMJhGQoClbFs0TV5m4ufpErLdPr7twA61bcsHs64dtEGLooXuLhEhyTrnBZSpi32UnjwF0EfLftrtI91/a/1RKm6hz+Ir4k5r0yVM9JGPw5lGr8mi51a0tJWvkBhIg9v1+1cBF+fmnLDTQQKY3I3T2XpwdLE9biyD0YpHPYlDL5A6RYtJls9ooI2PXdxy+Fa4/zLLyaWuY8c9RbWAEZFbmDftuX6Wf4JKUAaFMn5tGzZfy/P7tmNWhYQfzAYq9Dh5VD4gkM4B/PbYP1Lv5OJkXwKlnKwo2a0x02TcojKQjI0g/rs1xBjqSAlx4l93jt5dTLUIzZlDsFwB4bvqEOqlGKAG/OzMct5xwRQTllcUH1vfgB6Ult6FkyHTtZUE9AwOZo0tvhaGfEts/Fxc5YsXgVImVs1jW54CmRHA7IwzF1hQ4IBsP1BuhTaqhGBss6SDzVwwUk35GfAID0dQI6//lliD+a96hO4bxxftRU7+XbNZ+di7xCteFTlLMpnL+MGaOn1DSiAxiUZzxHTI9txMAQCfbxzZw6OjiBOqru5J9Z9nogo5pX9or0E9jAiBhPbHkgrGuHM9uSfsZYVU3IoXnVpJXrDcaShaQScDWxaEgfhTBgxICNDgDqikX04RghfuAjBXZUIPy7SRvOfNdfS1Hvy5A/GWHkvp5iDZ7pda4I7/ATEcZnM+5v0Pr2IrYxak8nih+Vpwva5MVGnXmTWxBflHTg8iKQzYo8APiBkTryrlG5Rb9MWVPaAtzZaDDbZ8sfn9SLwLGIkfGEXIlfBzYOlXXhMV6sMX+v8o28lOBj8g0NuOcaotSiZ4RuZ8AtOn7wktAiELhyHyFBd+vL425TJVz5BpH7AOQW1PG4NrMCNDV4t1lU5pzwp19qSCx+MWFXRVZ8cgCqSlPao7WYR910uW/In+73rsg/X2a58jPRYV9TKUmacpzmCoM7ccWj5IVgnaV+WQIrtg5pkLdFy1muqOQShF2vdAnEMsRgb1xj9UTPqqYPe2bm9CJZb7zSwqm3dhHz93VXqyrHcWIh9g3gBPtwtvY7tmrI0EZORnXOpXpSQaUu31VEHmSYRC21fnTV3VvmoxDLP1Cj0wzBc+zwscPi8/uSU/Agv61f/H05NhtCHj7mFxizGBlN9dehfOFGNb0nMSm08xnKukXt6MGjpP2Q7MR05LAbCryMilczMcbimBZzQfXYfKGKBn+pQmQbsKiH0P1EE5xqSWpmkW4/Se4+fNRszRoxoqFgj+205FpAcIigwMDuV8h5g836IGsNjktkZSBnTdNNRznmZ77Z7sKhVmP8+ayMYmbKIqYIfZO1vufb5kGli/I4uvmY6X6uEppk6/113RvYiZwvOvP1sJYHq4ED1JtgRNuOb0riGKSt6ZoJQJjmsKdrb+fqZ8s7W8VH+CkCDA5QHUM/50umKaKKa1H/kqj+Zt8LDgvI/Wd2Co X-OriginatorOrg: silabs.com X-MS-Exchange-CrossTenant-Network-Message-Id: 284320b9-0cda-4ecc-1a9e-08dc94584d3a X-MS-Exchange-CrossTenant-AuthSource: MN2PR11MB4711.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jun 2024 14:16:55.4769 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 54dbd822-5231-4b20-944d-6f4abcd541fb X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: nce6Jk3nMYImjMDIRfEniXSpzC5nueeX5OERQ/qIemS6aLbYtGwJds/26aeQC5RLtcDb9J/zCKZKUW8eifNR9g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV3PR11MB8765 X-Proofpoint-GUID: DGy_j0N5su2MPzWiPPzvS90sb2zP7eiO X-Proofpoint-ORIG-GUID: DGy_j0N5su2MPzWiPPzvS90sb2zP7eiO X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-06-24_11,2024-06-24_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 clxscore=1015 priorityscore=1501 lowpriorityscore=0 mlxlogscore=999 mlxscore=0 suspectscore=0 bulkscore=0 phishscore=0 adultscore=0 malwarescore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2406140001 definitions=main-2406240114 From: Mathis Marion 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 --- 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; }