From patchwork Mon Feb 19 13:52:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Iurman X-Patchwork-Id: 203093 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1294830dyc; Mon, 19 Feb 2024 05:53:55 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWRUJErobX+jY7MQnvDlUXO6xSrsKAAyuTWfL6Nt8KSG263h9xQY4mfiWnNFw9Y71ec917y8+CtB4xXUl6b7JG2dEmV/w== X-Google-Smtp-Source: AGHT+IETVm9wWsqsGd8sn0ylBXGcthfu2jMGo9r/10LG8b7+YFO3uvmUt73iRP/+TJnyIHxESl35 X-Received: by 2002:a17:906:a19a:b0:a3d:2a52:380f with SMTP id s26-20020a170906a19a00b00a3d2a52380fmr7976689ejy.72.1708350835181; Mon, 19 Feb 2024 05:53:55 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708350835; cv=pass; d=google.com; s=arc-20160816; b=ryycfy+WHTwK5bnbn+SnFn5WUvuDAD/ymF4nrxiQi+lQazJWsQkH4OFKVk5/p/4IQ1 OuzT3Co6Qh8v9hd+zsvQdBQK2/7ruEvm9pACk3lptv8Zcu9oOXtyW8uKi9VXfQfUWGfR p9LSYxHz3dJGTHMAXVqE283QV89Oc1C7aPukvIiuPjHraRMyrm5KzivYJmx84Aq2u+Dg 986yCGp7yOeGCgueME19qZITJR2ysVAtwz+WIibOgwNRjJz5ykhxSG94ScLbVuVeRK23 hzWqW13K+AIYj9pbnG6DQcwlAVOUAdI9tTbPQpBPB2wNxl4VqsuLFQG8qXqpu3/Yxqf5 gGDQ== 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=k3BbLM+W3IY++z5FItf1PQyWOHVjGz95oS2lZDTR3f4=; fh=1UEXF8WEdTRZGz3zsBPr9blJ8rxkIELeUsA6ymhnv1o=; b=cY6CXuoCp8q/nWYvUpEIROqcZAzmYiF25cXgjsvn8cj+iHWWAsWaPq+aRKlcH8/At0 yTmn5iHJ3RygE+NNz4Ye7CyRo8VSQtfqHXxjbHW8fBAFBjE6Sn9S9mi5HIF2GM48GqyJ FefLPhAdTcZVKrYkCQzCQMrcPHE8Q8kdOSCMle2igtMwLP2nOof21nThf0bqm48IKCOn RT0uRAukLnLqQLWjj83qYQYpgMLpbjVIFAfXXVY3PFb7bYNL1vII5j1hoxTqSt5VE70m Ifa34pc8jgqiPZeizzJ8Wu3a82V39NHuez12Z+3m9Z+hbbd1wNQJOSxyNKnMJm5g46oS a4JA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@uliege.be header.s=ulg20190529 header.b=LeD7FTRu; 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-71432-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71432-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=uliege.be Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id qf17-20020a1709077f1100b00a3eb3e3586csi589585ejc.347.2024.02.19.05.53.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 05:53:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-71432-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@uliege.be header.s=ulg20190529 header.b=LeD7FTRu; 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-71432-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71432-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 am.mirrors.kernel.org (Postfix) with ESMTPS id C8DF71F2194F for ; Mon, 19 Feb 2024 13:53:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A1C27381C4; Mon, 19 Feb 2024 13:53:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=uliege.be header.i=@uliege.be header.b="LeD7FTRu" 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 8FD2C364CC; Mon, 19 Feb 2024 13:53:01 +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=1708350783; cv=none; b=vCYMXKDm4e06e+JlGrXHGgI1ItTSrCQsuFc/QZZbKlpXpj9UcTt8ocQZ/Cl76xNXDEmpFC7/3uqPLJIgRvYzGiHk193RskXjVz5ndE8ciCIfaDC6ybGdE7RpMiHOhcANuF03w64x7T2QJzcjiSdHDnyN+ELfb8b0Yr1Ji/hQnrY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708350783; c=relaxed/simple; bh=pSf/6yBlnsj3efx67HWLfiYU1L7RVALqEg3khS/oWgk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=RiHqdCtICWRp7J87f+zf7Ni2tS7Q8Ht4ELtRhDxz2pdOVN2FhePDtU7Tu5NUIGSqB8mn7sJdhXLVOnI9qhDGSxkbEV5IK1X4t13SXwg1Aa9LmLWf77rv194np0ar6Dze68IWvcucNX5iJSuKFcBLGWQiUdcB82PXxsuV6iigNe0= 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=LeD7FTRu; 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 ubuntu.home (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 BBFD72012173; Mon, 19 Feb 2024 14:52:59 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 serv108.segi.ulg.ac.be BBFD72012173 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uliege.be; s=ulg20190529; t=1708350779; bh=k3BbLM+W3IY++z5FItf1PQyWOHVjGz95oS2lZDTR3f4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LeD7FTRu1UZv0Ax6scZg93ZbR/A7tXJxuEboY23KBSAQfrBM+jDp59ehXrAEnxUUu H9g6lQAGOji7i+pNJqLeHN1Lix50+M3LAgdetCDfQOBWWv7PXLGjApvcmJx4UqNFp1 cBEHDp9POX076y4L5tKQpl1PTCmBg2BkCgiD+oczKoh86wc2QKCZ+Nih2eQOO+HtQC by3IZ3OJtf6dhSdOtAEEpPssrP2FO7DVFWMwO3uAeNyfMlcjZBKJPk2H+X0u2FereO AQI2Jdh4zUScaqb9onAVI3bA6vaFIQzC30ySgu41JM++P0G+TTwCMskDrWOdBN3+3Z 9iechtlY0x5GQ== From: Justin Iurman To: netdev@vger.kernel.org Cc: davem@davemloft.net, dsahern@kernel.org, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux-kernel@vger.kernel.org, justin.iurman@uliege.be Subject: [PATCH net v3 1/2] Fix write to cloned skb in ipv6_hop_ioam() Date: Mon, 19 Feb 2024 14:52:54 +0100 Message-Id: <20240219135255.15429-2-justin.iurman@uliege.be> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240219135255.15429-1-justin.iurman@uliege.be> References: <20240219135255.15429-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: 1791335684901277740 X-GMAIL-MSGID: 1791335684901277740 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(). It also updates ip6_parse_tlv() to refresh the network header pointer ("nh") when returning from 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 | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/net/ipv6/exthdrs.c b/net/ipv6/exthdrs.c index 4952ae792450..02e9ffb63af1 100644 --- a/net/ipv6/exthdrs.c +++ b/net/ipv6/exthdrs.c @@ -177,6 +177,8 @@ static bool ip6_parse_tlv(bool hopbyhop, case IPV6_TLV_IOAM: if (!ipv6_hop_ioam(skb, off)) return false; + + nh = skb_network_header(skb); break; case IPV6_TLV_JUMBO: if (!ipv6_hop_jumbo(skb, off)) @@ -943,6 +945,14 @@ static bool ipv6_hop_ioam(struct sk_buff *skb, int optoff) if (!skb_valid_dst(skb)) ip6_route_input(skb); + /* About to mangle packet header */ + if (skb_ensure_writable(skb, optoff + 2 + hdr->opt_len)) + goto drop; + + /* Trace pointer may have changed */ + trace = (struct ioam6_trace_hdr *)(skb_network_header(skb) + + optoff + sizeof(*hdr)); + ioam6_fill_trace_data(skb, ns, trace, true); break; default: From patchwork Mon Feb 19 13:52: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: 203094 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1294898dyc; Mon, 19 Feb 2024 05:54:05 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVYWYzEwAtGmedPvPonLsqn40kxlbx7oXamZWHIvRORXRQtnwzS7OeJZP0aG4jdbQ8pUAe90tUNqF+Dc6EebP7W+4qo+Q== X-Google-Smtp-Source: AGHT+IE6GcugSzgciKJHhaapcme2rysVDRZ/Oh5CetLInZF9IEJnVOELpoZtYN5Q8KeS4b5yLcWV X-Received: by 2002:a17:906:4096:b0:a3e:66b5:d65f with SMTP id u22-20020a170906409600b00a3e66b5d65fmr2316019ejj.67.1708350845406; Mon, 19 Feb 2024 05:54:05 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708350845; cv=pass; d=google.com; s=arc-20160816; b=PX0hawEMlyiitW8JCGt2Zo5GgLubSLMu3hTEFBlHyCWmh+Hy7JmxfD5guUihYOs8yy m7L3m0YHBOqpCwIHdyo1W+m4TffM9p0fSG4cMPM4nBlwnrPlShtwz0lUS2tj8kL5Qh6x On8IwbM4UHdTCsUu69uQLh6aOIQpg+2pCWHkUr0XRLYEbMgCRKw+zKum2LTXJuWeLiaX gmkzMLMAdoz+LYYGPSM11EidzVEOj/spONCdv8IIml/iDWXE2Zvd1pd2z6HEA5U5feRm 1zRJQ0MZME7x2AiOqWFAuihezgZl6TfF3PDYjykit1HRSlClMZ7N7zjHjBENuQ8zlFSq LIFw== 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=GdqClNP24oSb21PimU1rdj3YpRVP83hpGrMM7xmTrzo=; fh=1UEXF8WEdTRZGz3zsBPr9blJ8rxkIELeUsA6ymhnv1o=; b=Nqb/JYYP/71I88NXKI+YiILlytiNaLQZsacTtynnoikzG3M6CAx1MQxRJwBFw/oQOV h2gdhalFShND40QmWeaSHP7QItXhxQcDl/KsFWDGp68w06KTt83OvPVW6BvFRqyB/w73 nJI8+WosuexsU0E9u5g87ihGe+3pxPhXGr6SufCOjEnZ5EMWotSR4TABT3tue9ZhE+B5 v/LG4Wi1wdst1hoX+u+WWH5+0LLa1VA+IupCX0H3DdMaTKAsL+TrONNP+U8wpliq6kjg lqaMv2K5YrCSfq75JfNeMZTS0fwH4n4tDZOAjSWwWk0ZjsUcRgQte03Uk3gRUXmmG1gO HpFg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@uliege.be header.s=ulg20190529 header.b=fmALJ666; 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-71433-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71433-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=uliege.be Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id z14-20020a170906074e00b00a3e6c395b22si1361008ejb.365.2024.02.19.05.54.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 05:54:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-71433-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@uliege.be header.s=ulg20190529 header.b=fmALJ666; 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-71433-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71433-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 am.mirrors.kernel.org (Postfix) with ESMTPS id D37591F23FA3 for ; Mon, 19 Feb 2024 13:54:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B803B383A1; Mon, 19 Feb 2024 13:53:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=uliege.be header.i=@uliege.be header.b="fmALJ666" 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 B23E0364D2; Mon, 19 Feb 2024 13:53:01 +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=1708350784; cv=none; b=poOetaK3L4gQjOsyTDDeGIQJDAtVi5gwgFlJGE9QDUqhBJbmZRgrZhoBSp/KUqLSyxOq05OLqhzImcUpncxJwQ4xjn6866h9ZOlZvunTsBO9nQ6722w4K6oMz802JmZPJo0QaeowlA2BgvebNtOWR9CAokr39ufhOFGW/j6bDQA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708350784; c=relaxed/simple; bh=7zlMxKEMlRi2fMVorHFpbWy+YlGO3wP3+8xPvDrFk8c=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=vAP+MaBT8qxLKfmfMxu9TKSJMPUyYq7Ytx3ZPG6ALqPYIHIl353gwRfZxf2OO6SbnssVf7UmT3d64yUZdnNyYvx/bIWGIn6ahNoCjVzZsKxvfNXohJZjH7/v7eY2/nyaBVlc1SbWIKm0JVUpY998GxoPGV4A7o5vAlz4cMphuy8= 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=fmALJ666; 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 ubuntu.home (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 028612012175; Mon, 19 Feb 2024 14:52:59 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 serv108.segi.ulg.ac.be 028612012175 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uliege.be; s=ulg20190529; t=1708350780; bh=GdqClNP24oSb21PimU1rdj3YpRVP83hpGrMM7xmTrzo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fmALJ666QvGHhyPzujiJe1P4IZsy/ia40rxc6jnJe27+BQuUCJKYrVXS5m1r8SVhE Hdpv5JuT8G854C58qUTp/Nve9Jfkm8DRKRUDblan/rj+Z5gS3Cbi0QJ/oaYG0rcHcg QmUc5m4vflMM2+UKeg8QyO3d5TIOmzoRnF5YsWV/8hL5FjzsRZ3KeNQwLNqT3+9MlT JW7EZtmCwUXsoGvMBuz7O0/Og/ZJP4o9KL3srtJr3qEKjDvbSdS/ZcUYAAaeSuoktT iGpspB1WVI9u9FG/Q627lpes1gDhqJ9WYs/u0sLvP9Kr5xExaMyE+2rSMRFsFRSilW XbuIIBdZQ15Ag== From: Justin Iurman To: netdev@vger.kernel.org Cc: davem@davemloft.net, dsahern@kernel.org, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux-kernel@vger.kernel.org, justin.iurman@uliege.be Subject: [PATCH net v3 2/2] selftests: ioam: refactoring to align with the fix Date: Mon, 19 Feb 2024 14:52:55 +0100 Message-Id: <20240219135255.15429-3-justin.iurman@uliege.be> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240219135255.15429-1-justin.iurman@uliege.be> References: <20240219135255.15429-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: 1791335695962621641 X-GMAIL-MSGID: 1791335695962621641 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 | 95 +++++++++++----------- 2 files changed, 66 insertions(+), 67 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..895e5bb5044b 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,80 @@ 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; struct ioam6_hdr *opt; - struct ipv6hdr *ip6h; - __u8 buffer[400], *p; - __u16 ioam_ns; + struct cmsghdr *cmsg; + struct msghdr msg; + struct iovec iov; + __u8 buffer[512]; __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)) + fd = socket(PF_INET6, SOCK_RAW, + !strcmp(argv[4], "encap") ? IPPROTO_IPV6 : IPPROTO_ICMPV6); + if (fd < 0) goto out; - fd = socket(AF_PACKET, SOCK_DGRAM, __cpu_to_be16(ETH_P_IPV6)); - if (!fd) - goto out; + setsockopt(fd, IPPROTO_IPV6, IPV6_RECVHOPOPTS, &on, sizeof(on)); - if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, - argv[1], strlen(argv[1]))) + 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; 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;