From patchwork Fri Feb 16 23:43:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Iurman X-Patchwork-Id: 202432 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp57900dyc; Fri, 16 Feb 2024 15:50:58 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU2khqwLoc6FMNcE3NVpC7FwuRdKqoXl/kRtO/rfwn9LV7IPHWL9wXfR/R9zD2mWDbziNTQWgREy0L+s0RKqrQP31XNvQ== X-Google-Smtp-Source: AGHT+IGT3REHxUe6QmxXR0gQzsCYqdqPoXh+lBTSxLHiupC/Gnp7W8cEzDh9N7lztEKuI1fNKCiO X-Received: by 2002:a92:d94a:0:b0:363:b8fb:fcb7 with SMTP id l10-20020a92d94a000000b00363b8fbfcb7mr3511409ilq.16.1708127458182; Fri, 16 Feb 2024 15:50:58 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708127458; cv=pass; d=google.com; s=arc-20160816; b=d+d46IowEz5wh4iQSpvH01XAy5QgvTP5mzfgOz3M1WsI3ccz0hMdtGo49JnebyZbU3 e+h6KD3sFbaiH0fk8W/R9jjnlH3TGtr9OWPgUY+a1u5nF7lvdnnKEmUrJrYNMuPp6/kA EtjGoZWlr2mFT70wqmhDFUJ661nyhVQwW3R9OK7brTfoWGVe6sQ/kn99OJnlfB5qSh+6 wWxHg8NNf1f7nUDOOmcfbe8acdVxhfPW8J2aIHuS9dFqAX4iyfbL22AG7tXTlKyIO3BE 48IE3jDGtlbwpC8WVdCBEqKfKdBHCw5X6UOYgWZJzVvoVZfdeGbL2Bu6v1UMthRSjzOh HqHA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature:dkim-filter; bh=KBT5QiCYF+jW6KQjYqqpLSpV8B1JmQ2uuG5tyIxcSu0=; fh=wKA1yLAaxZXTggjEsc7ekQegiUD1yMj/fZjOnZZQ/2U=; b=o/RAnzUXB3HxL+9aAOP+D+Z8W0eeZSWxZ1OkiY4otfVHKrL3j6lXgn04M5kpZmQ0Uf Kif0kOHsq+PBB/gUKwj1ejiXQosodS0rLPFEYpL9tuXnbGE7O7Z3Wp9y/AjhGO+n/DKw ySWHk8uxwFX8H+JF4kWhqSCn4hYnUqX+K5B8Ma1rAT80MYCGRVLoyXgEjogyEZV2PzA+ vQtbLCKmEmw0C33qCb7fMnbU+/JOaRcX1AOJdZl6KkISAOYcpAlhVwgUeQQowsPOnieL 92/m78r9kw4fsG1fuBPQwnx50/hyxc0hljMfNkiWAGZGxWqfmA87D9zUhGKcpj3qO5HB dfVw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@uliege.be header.s=ulg20190529 header.b=OBkwBK7b; arc=pass (i=1 spf=pass spfdomain=uliege.be dkim=pass dkdomain=uliege.be dmarc=pass fromdomain=uliege.be); spf=pass (google.com: domain of linux-kernel+bounces-69491-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69491-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=uliege.be Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id e22-20020a656896000000b005cf0309e41bsi566673pgt.823.2024.02.16.15.50.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 15:50:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69491-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@uliege.be header.s=ulg20190529 header.b=OBkwBK7b; arc=pass (i=1 spf=pass spfdomain=uliege.be dkim=pass dkdomain=uliege.be dmarc=pass fromdomain=uliege.be); spf=pass (google.com: domain of linux-kernel+bounces-69491-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69491-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=uliege.be Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 00A8F2897D9 for ; Fri, 16 Feb 2024 23:50:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1079714A4E2; Fri, 16 Feb 2024 23:50:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=uliege.be header.i=@uliege.be header.b="OBkwBK7b" Received: from serv108.segi.ulg.ac.be (serv108.segi.ulg.ac.be [139.165.32.111]) (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 5A884148FE9; Fri, 16 Feb 2024 23:50:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=139.165.32.111 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708127414; cv=none; b=Rqp6ChPHPhltJpjksdCznJNS77TCQgspWfzFCc/Zm9tcKwdtodkuGOb4AJrHaeXMInzaz/jXHlIvhUXvEXOcZ8r8uiJCErm/QokawlohU+8BEWEWXGXQqVBuoQAGLZ5BPCgbx8XIf1hilBTozWqMi4qez4nZlHOwhAlFXTYutZo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708127414; c=relaxed/simple; bh=SUlpKvijFULBhu+onKj0KJkGrequq3NY9IlyDbpNHsc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=GtORZfEeiLvzOWWl6kx+fUQ8pmWUAc+uDFOg7Bj4sfL/OeeR7p885uyXtTVDIAwmbv8mlDax+kyf65ww6gTzfMk3A9PevqTgsCemy9tzIpofNawIaHWBlC/ReA93j1eBtBW5NRrMNJuBtm2wLgRXpmEOAhGjaQGax22qyc50jVs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=uliege.be; spf=pass smtp.mailfrom=uliege.be; dkim=pass (2048-bit key) header.d=uliege.be header.i=@uliege.be header.b=OBkwBK7b; arc=none smtp.client-ip=139.165.32.111 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=uliege.be Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=uliege.be Received: from localhost.localdomain (125.179-65-87.adsl-dyn.isp.belgacom.be [87.65.179.125]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by serv108.segi.ulg.ac.be (Postfix) with ESMTPSA id 86162200C99A; Sat, 17 Feb 2024 00:44:26 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 serv108.segi.ulg.ac.be 86162200C99A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uliege.be; s=ulg20190529; t=1708127066; bh=KBT5QiCYF+jW6KQjYqqpLSpV8B1JmQ2uuG5tyIxcSu0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OBkwBK7bv651mHZOpD6QhZyzeYarcjkiZici4n8srVvFYAlZfKsBwVFHYnAPWOi8m a7YleW/tQUHWUSaNLLBqNq0JIO0CjGV802Za7FmmlyDmOvIc0waX08uefRzPAirUNs /ctZQi7LcszxAHJaaBfWHyX2OG0Lx4xjLtYvoqeSPYK6fh7celuenNDoc/GXyOr/Oi ZmDSKM1ozAuxeTMHKaavo36EICuh4nlR0tI9q0EcZ+7Q3H5qrM8VQD8sHLiTZCXrWK TyKGQA5EVMjm5PtXFce6IreT3NxvygjvuBrWA3vHk9GC5uqBeoCdI1rfNsi/HiEZ0a O2aiS7FdFH2xg== From: Justin Iurman To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, shuah@kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, justin.iurman@uliege.be Subject: [PATCH net 1/2] ioam6: fix write to cloned skb in ipv6_hop_ioam() Date: Sat, 17 Feb 2024 00:43:55 +0100 Message-Id: <20240216234356.32243-2-justin.iurman@uliege.be> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240216234356.32243-1-justin.iurman@uliege.be> References: <20240216234356.32243-1-justin.iurman@uliege.be> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791101457473459294 X-GMAIL-MSGID: 1791101457473459294 ioam6_fill_trace_data() writes inside the skb payload without ensuring it's writeable (e.g., not cloned). This function is called both from the input and output path. The output path (ioam6_iptunnel) already does the check. This commit provides a fix for the input path, inside ipv6_hop_ioam(). Fixes: 9ee11f0fff20 ("ipv6: ioam: Data plane support for Pre-allocated Trace ") Reported-by: Paolo Abeni Signed-off-by: Justin Iurman --- net/ipv6/exthdrs.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/net/ipv6/exthdrs.c b/net/ipv6/exthdrs.c index 4952ae792450..f68e5faab3aa 100644 --- a/net/ipv6/exthdrs.c +++ b/net/ipv6/exthdrs.c @@ -943,6 +943,14 @@ static bool ipv6_hop_ioam(struct sk_buff *skb, int optoff) if (!skb_valid_dst(skb)) ip6_route_input(skb); + if (skb_cloned(skb)) { + if (pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) + goto drop; + + hdr = (struct ioam6_hdr *)(skb_network_header(skb) + optoff); + trace = (struct ioam6_trace_hdr *)((u8 *)hdr + sizeof(*hdr)); + } + ioam6_fill_trace_data(skb, ns, trace, true); break; default: From patchwork Fri Feb 16 23:43:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Iurman X-Patchwork-Id: 202433 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp57966dyc; Fri, 16 Feb 2024 15:51:09 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWc5Z2TNTS36YZQhTW7bE7XWOvUCzOkPO8R6hW4YE+PLfqZkAqhtJJsStbrZMwF36BM6ih837qSZw2fIsM57U6AgdRS3A== X-Google-Smtp-Source: AGHT+IFRt2OivoGgZtvpTIpj9uH3QhomcHY2EYxrhL1yEtrKXSDer6N2E5H5Fs3rJNIeOxVHttcy X-Received: by 2002:ac8:5904:0:b0:42d:ca01:b34b with SMTP id 4-20020ac85904000000b0042dca01b34bmr6488110qty.63.1708127469300; Fri, 16 Feb 2024 15:51:09 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708127469; cv=pass; d=google.com; s=arc-20160816; b=QBoAmXaYAUO/bNc6V/GIxeFm/fSHXcQKKQtHf+qOZZ3Pg+twZmKk01dX28DzfcMXzR HVUFQRDd7y5WP5hkD+Pk9ks1f3EM30gtY4nNoDTcqiOkOla9nGxiykJaf/sfxNwdzPJt Irv4gp/M3cehzbmToxlF/6bqSfHfc5AdqiY/pMRV3IqB7okz9wpTQvfuYFGO6yD+HVEd 0dVgXJUhygK2jfqk6a/Wr7lwq3zB3rv+Ethh1CGXQXkUV4NJUCrJeNytAntNOrH/Hstr xOH5JWEz9yWjS3+mGqBM6MD2lHd0PLK/O7S8AqeR2jqCZEa/wb15oD3G8ZvjusbXpCqB S4BQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature:dkim-filter; bh=9j5eVpiBwzw5ltDCPFe2hsyvQP/Xgv6qbYI20MohXf8=; fh=wKA1yLAaxZXTggjEsc7ekQegiUD1yMj/fZjOnZZQ/2U=; b=Nw2Yg1roReOkcKmv48fX3LTHLRSOau/gfBqZ4XY+Bu6SfLbsPeIVHPdg+hMLxhkr9O YCFItThFpEZ28WXmLO97VDlc0fli5VkoKiq00vOolfy/IhgjjJZdkNDouyxIPX2s2hKA jDb7lzj7jBP2Fn0HAHdmChHJqDbRwgSi0oRbqq0LRhIQoNFLw0CEFQLzu1wUnhzLNgfe KgIYXqZVLx7CAA8QPFU33lpiqYa55h7nD2L9Hu6pvygFILua4/7InAeMjS6NXeuA9K5a FGnHWflvusY/4D09GqCZzITrP9UbFnRvjlrdx2WtzkcnVyvYUhjV4unaZBH6Cz5e0SV9 dJdQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@uliege.be header.s=ulg20190529 header.b=U8q5O9Nj; arc=pass (i=1 spf=pass spfdomain=uliege.be dkim=pass dkdomain=uliege.be dmarc=pass fromdomain=uliege.be); spf=pass (google.com: domain of linux-kernel+bounces-69492-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69492-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=uliege.be Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id 14-20020ac8574e000000b0042dc85eeda8si1174832qtx.121.2024.02.16.15.51.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 15:51:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69492-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@uliege.be header.s=ulg20190529 header.b=U8q5O9Nj; arc=pass (i=1 spf=pass spfdomain=uliege.be dkim=pass dkdomain=uliege.be dmarc=pass fromdomain=uliege.be); spf=pass (google.com: domain of linux-kernel+bounces-69492-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69492-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=uliege.be Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 0F23B1C21CC5 for ; Fri, 16 Feb 2024 23:51:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 37E5114AD05; Fri, 16 Feb 2024 23:50:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=uliege.be header.i=@uliege.be header.b="U8q5O9Nj" Received: from serv108.segi.ulg.ac.be (serv108.segi.ulg.ac.be [139.165.32.111]) (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 335DA1DFFD; Fri, 16 Feb 2024 23:50:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=139.165.32.111 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708127415; cv=none; b=brLhDCk8giyKpWX1yjduOCP3dhNgemCpoHX/mvTc1VDGqPZ56w2jBXMT0/vckE1nc8TNQcgxw+rEdUzHm1s+mSNCoJcdmiFY3LEgMuDtvjz59d7GLRSKNXqz4fUgCXwpfeakZycgayJDSaKHR0dvejpCFIf8sutaFt8OVDAl17A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708127415; c=relaxed/simple; bh=J8FXU7aHYZuODWspt2kUR8S1w28W8VmvUfgLuCM8cWA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nRURKYdqKzyF71Qn2uUDRREZMF3jIFR9IIQYXhMsKjt4TkvBf8KS5aGY5/KIkr0VFS5UrbOdoGfPsrH+hNtXvqN9kk4H2GDH+CD0We8xhM7Feheafx1Aim4/Kv/y9UXc8pagHCsXHaq7p4vdJmehSJFFOI8S71qMECXMOjJApcA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=uliege.be; spf=pass smtp.mailfrom=uliege.be; dkim=pass (2048-bit key) header.d=uliege.be header.i=@uliege.be header.b=U8q5O9Nj; arc=none smtp.client-ip=139.165.32.111 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=uliege.be Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=uliege.be Received: from localhost.localdomain (125.179-65-87.adsl-dyn.isp.belgacom.be [87.65.179.125]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by serv108.segi.ulg.ac.be (Postfix) with ESMTPSA id BF415200C992; Sat, 17 Feb 2024 00:44:26 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 serv108.segi.ulg.ac.be BF415200C992 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uliege.be; s=ulg20190529; t=1708127066; bh=9j5eVpiBwzw5ltDCPFe2hsyvQP/Xgv6qbYI20MohXf8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U8q5O9Nj59vvVIzHuQFzN6OH7r3zRtBcokHLHAk+64iTZhAE6Wiz0fjNTOddW/08f 9r0E4ZzyNbnjPQG/4LfgnSbUD+6fJt92s7Rjm1tYU35KQ4MJI3g3rI/1Cmug9SVyTZ 4kNIO1UyGNnLTiL5VoIO6f90asrlslLJ3RPFtL6Ztzv0Nrls6KOAno/PcC76TjNRJq gQCPgyvxxKh6GCceCbDVIu6sCKjAh3iDqqCOngJyALFaPc3AhJLaTb5L2Qj7w/WaoW bTnhAkNlKZSzrK7Xd3J97T7aXa1/akCwDp6Ztd2FeXc/6MGgN4G0s7sql9pcyPXJa0 fAOUjAkzxvU+Q== From: Justin Iurman To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, shuah@kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, justin.iurman@uliege.be Subject: [PATCH net 2/2] selftests: ioam6: refactoring to align with the fix Date: Sat, 17 Feb 2024 00:43:56 +0100 Message-Id: <20240216234356.32243-3-justin.iurman@uliege.be> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240216234356.32243-1-justin.iurman@uliege.be> References: <20240216234356.32243-1-justin.iurman@uliege.be> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791101469504181305 X-GMAIL-MSGID: 1791101469504181305 ioam6_parser uses a packet socket. After the fix to prevent writing to cloned skb's, the receiver does not see its IOAM data anymore, which makes input/forward ioam-selftests to fail. As a workaround, ioam6_parser now uses an IPv6 raw socket and leverages ancillary data to get hop-by-hop options. As a consequence, the hook is "after" the IOAM data insertion by the receiver and all tests are working again. Signed-off-by: Justin Iurman --- tools/testing/selftests/net/ioam6.sh | 38 ++++---- tools/testing/selftests/net/ioam6_parser.c | 101 +++++++++++---------- 2 files changed, 73 insertions(+), 66 deletions(-) diff --git a/tools/testing/selftests/net/ioam6.sh b/tools/testing/selftests/net/ioam6.sh index fe59ca3e5596..12491850ae98 100755 --- a/tools/testing/selftests/net/ioam6.sh +++ b/tools/testing/selftests/net/ioam6.sh @@ -367,14 +367,12 @@ run_test() local desc=$2 local node_src=$3 local node_dst=$4 - local ip6_src=$5 - local ip6_dst=$6 - local if_dst=$7 - local trace_type=$8 - local ioam_ns=$9 - - ip netns exec $node_dst ./ioam6_parser $if_dst $name $ip6_src $ip6_dst \ - $trace_type $ioam_ns & + local ip6_dst=$5 + local trace_type=$6 + local ioam_ns=$7 + local type=$8 + + ip netns exec $node_dst ./ioam6_parser $name $trace_type $ioam_ns $type & local spid=$! sleep 0.1 @@ -489,7 +487,7 @@ out_undef_ns() trace prealloc type 0x800000 ns 0 size 4 dev veth0 run_test ${FUNCNAME[0]} "${desc} ($1 mode)" $ioam_node_alpha $ioam_node_beta \ - db01::2 db01::1 veth0 0x800000 0 + db01::1 0x800000 0 $1 [ "$1" = "encap" ] && ip -netns $ioam_node_beta link set ip6tnl0 down } @@ -509,7 +507,7 @@ out_no_room() trace prealloc type 0xc00000 ns 123 size 4 dev veth0 run_test ${FUNCNAME[0]} "${desc} ($1 mode)" $ioam_node_alpha $ioam_node_beta \ - db01::2 db01::1 veth0 0xc00000 123 + db01::1 0xc00000 123 $1 [ "$1" = "encap" ] && ip -netns $ioam_node_beta link set ip6tnl0 down } @@ -543,14 +541,14 @@ out_bits() if [ $cmd_res != 0 ] then npassed=$((npassed+1)) - log_test_passed "$descr" + log_test_passed "$descr ($1 mode)" else nfailed=$((nfailed+1)) - log_test_failed "$descr" + log_test_failed "$descr ($1 mode)" fi else run_test "out_bit$i" "$descr ($1 mode)" $ioam_node_alpha \ - $ioam_node_beta db01::2 db01::1 veth0 ${bit2type[$i]} 123 + $ioam_node_beta db01::1 ${bit2type[$i]} 123 $1 fi done @@ -574,7 +572,7 @@ out_full_supp_trace() trace prealloc type 0xfff002 ns 123 size 100 dev veth0 run_test ${FUNCNAME[0]} "${desc} ($1 mode)" $ioam_node_alpha $ioam_node_beta \ - db01::2 db01::1 veth0 0xfff002 123 + db01::1 0xfff002 123 $1 [ "$1" = "encap" ] && ip -netns $ioam_node_beta link set ip6tnl0 down } @@ -604,7 +602,7 @@ in_undef_ns() trace prealloc type 0x800000 ns 0 size 4 dev veth0 run_test ${FUNCNAME[0]} "${desc} ($1 mode)" $ioam_node_alpha $ioam_node_beta \ - db01::2 db01::1 veth0 0x800000 0 + db01::1 0x800000 0 $1 [ "$1" = "encap" ] && ip -netns $ioam_node_beta link set ip6tnl0 down } @@ -624,7 +622,7 @@ in_no_room() trace prealloc type 0xc00000 ns 123 size 4 dev veth0 run_test ${FUNCNAME[0]} "${desc} ($1 mode)" $ioam_node_alpha $ioam_node_beta \ - db01::2 db01::1 veth0 0xc00000 123 + db01::1 0xc00000 123 $1 [ "$1" = "encap" ] && ip -netns $ioam_node_beta link set ip6tnl0 down } @@ -651,7 +649,7 @@ in_bits() dev veth0 run_test "in_bit$i" "${desc//$i} ($1 mode)" $ioam_node_alpha \ - $ioam_node_beta db01::2 db01::1 veth0 ${bit2type[$i]} 123 + $ioam_node_beta db01::1 ${bit2type[$i]} 123 $1 done [ "$1" = "encap" ] && ip -netns $ioam_node_beta link set ip6tnl0 down @@ -679,7 +677,7 @@ in_oflag() trace prealloc type 0xc00000 ns 123 size 4 dev veth0 run_test ${FUNCNAME[0]} "${desc} ($1 mode)" $ioam_node_alpha $ioam_node_beta \ - db01::2 db01::1 veth0 0xc00000 123 + db01::1 0xc00000 123 $1 [ "$1" = "encap" ] && ip -netns $ioam_node_beta link set ip6tnl0 down @@ -703,7 +701,7 @@ in_full_supp_trace() trace prealloc type 0xfff002 ns 123 size 80 dev veth0 run_test ${FUNCNAME[0]} "${desc} ($1 mode)" $ioam_node_alpha $ioam_node_beta \ - db01::2 db01::1 veth0 0xfff002 123 + db01::1 0xfff002 123 $1 [ "$1" = "encap" ] && ip -netns $ioam_node_beta link set ip6tnl0 down } @@ -731,7 +729,7 @@ fwd_full_supp_trace() trace prealloc type 0xfff002 ns 123 size 244 via db01::1 dev veth0 run_test ${FUNCNAME[0]} "${desc} ($1 mode)" $ioam_node_alpha $ioam_node_gamma \ - db01::2 db02::2 veth0 0xfff002 123 + db02::2 0xfff002 123 $1 [ "$1" = "encap" ] && ip -netns $ioam_node_gamma link set ip6tnl0 down } diff --git a/tools/testing/selftests/net/ioam6_parser.c b/tools/testing/selftests/net/ioam6_parser.c index d9d1d4190126..14b354e14d25 100644 --- a/tools/testing/selftests/net/ioam6_parser.c +++ b/tools/testing/selftests/net/ioam6_parser.c @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include @@ -512,14 +511,6 @@ static int str2id(const char *tname) return -1; } -static int ipv6_addr_equal(const struct in6_addr *a1, const struct in6_addr *a2) -{ - return ((a1->s6_addr32[0] ^ a2->s6_addr32[0]) | - (a1->s6_addr32[1] ^ a2->s6_addr32[1]) | - (a1->s6_addr32[2] ^ a2->s6_addr32[2]) | - (a1->s6_addr32[3] ^ a2->s6_addr32[3])) == 0; -} - static int get_u32(__u32 *val, const char *arg, int base) { unsigned long res; @@ -603,70 +594,88 @@ static int (*func[__TEST_MAX])(int, struct ioam6_trace_hdr *, __u32, __u16) = { int main(int argc, char **argv) { - int fd, size, hoplen, tid, ret = 1; - struct in6_addr src, dst; + int fd, size, hoplen, tid, ret = 1, on = 1; + __u8 buffer[512], is_encap; struct ioam6_hdr *opt; - struct ipv6hdr *ip6h; - __u8 buffer[400], *p; - __u16 ioam_ns; + struct cmsghdr *cmsg; + struct msghdr msg; + struct iovec iov; __u32 tr_type; + __u16 ioam_ns; + __u8 *ptr; - if (argc != 7) + if (argc != 5) goto out; - tid = str2id(argv[2]); + tid = str2id(argv[1]); if (tid < 0 || !func[tid]) goto out; - if (inet_pton(AF_INET6, argv[3], &src) != 1 || - inet_pton(AF_INET6, argv[4], &dst) != 1) + if (get_u32(&tr_type, argv[2], 16) || + get_u16(&ioam_ns, argv[3], 0)) goto out; - if (get_u32(&tr_type, argv[5], 16) || - get_u16(&ioam_ns, argv[6], 0)) + if (!strcmp(argv[4], "inline")) + is_encap = 0; + else if (!strcmp(argv[4], "encap")) + is_encap = 1; + else goto out; - fd = socket(AF_PACKET, SOCK_DGRAM, __cpu_to_be16(ETH_P_IPV6)); - if (!fd) + fd = socket(PF_INET6, SOCK_RAW, + is_encap ? IPPROTO_IPV6 : IPPROTO_ICMPV6); + if (fd < 0) goto out; - if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, - argv[1], strlen(argv[1]))) - goto close; + setsockopt(fd, IPPROTO_IPV6, IPV6_RECVHOPOPTS, &on, sizeof(on)); + iov.iov_len = 1; + iov.iov_base = malloc(CMSG_SPACE(sizeof(buffer))); + if (!iov.iov_base) + goto close; recv: - size = recv(fd, buffer, sizeof(buffer), 0); + memset(&msg, 0, sizeof(msg)); + msg.msg_iov = &iov; + msg.msg_iovlen = 1; + msg.msg_control = buffer; + msg.msg_controllen = CMSG_SPACE(sizeof(buffer)); + + size = recvmsg(fd, &msg, 0); if (size <= 0) goto close; - ip6h = (struct ipv6hdr *)buffer; + for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL; + cmsg = CMSG_NXTHDR(&msg, cmsg)) { + if (cmsg->cmsg_level != IPPROTO_IPV6 || + cmsg->cmsg_type != IPV6_HOPOPTS || + cmsg->cmsg_len < sizeof(struct ipv6_hopopt_hdr)) + continue; - if (!ipv6_addr_equal(&ip6h->saddr, &src) || - !ipv6_addr_equal(&ip6h->daddr, &dst)) - goto recv; + ptr = (__u8 *)CMSG_DATA(cmsg); - if (ip6h->nexthdr != IPPROTO_HOPOPTS) - goto close; + hoplen = (ptr[1] + 1) << 3; + ptr += sizeof(struct ipv6_hopopt_hdr); - p = buffer + sizeof(*ip6h); - hoplen = (p[1] + 1) << 3; - p += sizeof(struct ipv6_hopopt_hdr); + while (hoplen > 0) { + opt = (struct ioam6_hdr *)ptr; - while (hoplen > 0) { - opt = (struct ioam6_hdr *)p; + if (opt->opt_type == IPV6_TLV_IOAM && + opt->type == IOAM6_TYPE_PREALLOC) { + ptr += sizeof(*opt); + ret = func[tid](tid, + (struct ioam6_trace_hdr *)ptr, + tr_type, ioam_ns); + goto close; + } - if (opt->opt_type == IPV6_TLV_IOAM && - opt->type == IOAM6_TYPE_PREALLOC) { - p += sizeof(*opt); - ret = func[tid](tid, (struct ioam6_trace_hdr *)p, - tr_type, ioam_ns); - break; + ptr += opt->opt_len + 2; + hoplen -= opt->opt_len + 2; } - - p += opt->opt_len + 2; - hoplen -= opt->opt_len + 2; } + + goto recv; close: + free(iov.iov_base); close(fd); out: return ret;