From patchwork Wed Nov 13 12:51:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Hangbin Liu X-Patchwork-Id: 843347 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A52CF201022; Wed, 13 Nov 2024 12:52:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731502328; cv=none; b=cmU7cMNmI/8IZ00DDfolEn/XXBt/UgjKdXKgeMy0VzyjT3VonLnJ6Uecy8XHA+/IYqgz0h7d/wQfsnlvWXa44AOsdBqtF751JoRvX/Vg/Dx+LDCWHCp6aNMdQS3Jml9dQZjYN4kc88Zm2TanfGdY5iDavfrKfu05kY8AOh4naiM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731502328; c=relaxed/simple; bh=wXPMfk4R4lN+fsFTHmCqEuZRii5imvxepYxDIbkqZCw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=KFMDZ5/aDdm4kxRs7jOdOaN5Lp7TXkCy27TScuCuPKZ8/k9AVXOfldlcwq6FDXLL8ZgLkWu9DL+jzGX9xIACVkfdMeeDPemZVnZzy6ChuQ4dqvUm/KZg7ZCx3ECdoV9lYHXI3On2/vFL6tYDem5fgPyHGBWtZBemjZXPgFY83zg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Dkwosjhf; arc=none smtp.client-ip=209.85.214.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Dkwosjhf" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-20cdb889222so67959275ad.3; Wed, 13 Nov 2024 04:52:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731502325; x=1732107125; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=d82L2SdWhBMpOjB96IbZ0ZbezId4gnZTN7mnyHKj4b4=; b=DkwosjhfphAM1MkeSZHkpnAiguGas33WlAjb7ARrZ2bbZOIb3iui/ywKR8/bQ2Yf6I lRB1RHk1Pab6+9ya4mAinj4CfUJiisemiddYXoUJ02rl5uKdTxgBcvc6X2waedDz5WBd oLNW9jZ9omiOa1TBXj4MZr/i0rybqsagYrWHZrh/45k8KRHkosmaF5y0Oeyofkd1bYun 10d8qRn1lQAxZvueFXAslhW3o43wPe5R32w50LZrZAtIfl334wK42nGRh83bzht/aX0A +GDsTWPekV8OnLYWYvkN47k+C5fe4944wFoBF8cxiqzV3u4JDF+DvQLc/EssS1ZYOXrT 2L5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731502325; x=1732107125; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=d82L2SdWhBMpOjB96IbZ0ZbezId4gnZTN7mnyHKj4b4=; b=Zm2VYJn+/co3+xJ1QnnCCt7AObTBuzRdvG9KFAsHByQJtL6z1QILwcVc4NWAXF5Qc/ 2log13gCK4DE28dvNDLuvh1vYGA91X8bfbDC7zhnsG688ILD8AP1arnAH3tjGGte3dtT rN/DOn+xAibIRGHmq9IauAdw3rdaP2uRva2kofYAReOs3yH9lkOUc/vZVVDtsViQww/C +L/ZG8J2ev13SyHarQbd0AcmalzGxCRDqLpUj9MDHBYWnXvuED1zSPZvZRyPQER1VHEY qIzPj3F1GR5sbuCx64Br+xIKb+1B0VbaaA7t9Fdyzm4V1NdNfiM2b3n7fYWAe8euZ01X dMzg== X-Forwarded-Encrypted: i=1; AJvYcCV4t4SZeMUr4shNIraOiEZYQH3o7uDJVSgvsCPkf19tp12xRTRhUJCAJSWO2J1YWfjO+3pdcmIa9PThutV4U0UM@vger.kernel.org, AJvYcCW1OVwARR0CurVwxv03Nu8wEmZZlzVa3LUA2uZ0tm15Qicv5lD1qXAxK2Rl/u6V87XftRLR/6RrnY/z3aI=@vger.kernel.org X-Gm-Message-State: AOJu0Yz8L6JKffEXJBeGuXkkusXoDk2lqXf6N3gK/T36c1/FKpJCpbaM pJjiy0LM3Dm0//6syZAXiY+jJ7X3Ar4LDr5WXVyb8LKMXXL1JSOikdXoQVuKxY/MBw== X-Google-Smtp-Source: AGHT+IG46DaaLV6bSnoaWxiVbMQ7/nWpHKTmHrUv79u+WFof17So49wSTLYzAuL+ual5OHRS1yMtgQ== X-Received: by 2002:a17:902:f607:b0:211:81a7:fa95 with SMTP id d9443c01a7336-211b5d5cf37mr27238935ad.51.1731502325441; Wed, 13 Nov 2024 04:52:05 -0800 (PST) Received: from fedora.dns.podman ([43.228.180.230]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21177cfb0ecsm109276345ad.0.2024.11.13.04.52.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Nov 2024 04:52:04 -0800 (PST) From: Hangbin Liu To: netdev@vger.kernel.org Cc: "David S. Miller" , David Ahern , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan , Sam Edwards , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Hangbin Liu Subject: [PATCH net 1/2] net/ipv6: delete temporary address if mngtmpaddr is removed or un-mngtmpaddr Date: Wed, 13 Nov 2024 12:51:51 +0000 Message-ID: <20241113125152.752778-2-liuhangbin@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241113125152.752778-1-liuhangbin@gmail.com> References: <20241113125152.752778-1-liuhangbin@gmail.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 RFC8981 section 3.4 says that existing temporary addresses must have their lifetimes adjusted so that no temporary addresses should ever remain "valid" or "preferred" longer than the incoming SLAAC Prefix Information. This would strongly imply in Linux's case that if the "mngtmpaddr" address is deleted or un-flagged as such, its corresponding temporary addresses must be cleared out right away. But now the temporary address is renewed even after ‘mngtmpaddr’ is removed or becomes unmanaged. Fix this by deleting the temporary address with this situation. Fixes: 778964f2fdf0 ("ipv6/addrconf: fix timing bug in tempaddr regen") Signed-off-by: Hangbin Liu --- net/ipv6/addrconf.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index 94dceac52884..6852dbce5a7d 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -4644,6 +4644,10 @@ static void addrconf_verify_rtnl(struct net *net) !ifp->regen_count && ifp->ifpub) { /* This is a non-regenerated temporary addr. */ + if ((!ifp->valid_lft && !ifp->prefered_lft) || + ifp->ifpub->state == INET6_IFADDR_STATE_DEAD) + goto delete_ifp; + unsigned long regen_advance = ipv6_get_regen_advance(ifp->idev); if (age + regen_advance >= ifp->prefered_lft) { @@ -4671,6 +4675,7 @@ static void addrconf_verify_rtnl(struct net *net) if (ifp->valid_lft != INFINITY_LIFE_TIME && age >= ifp->valid_lft) { +delete_ifp: spin_unlock(&ifp->lock); in6_ifa_hold(ifp); rcu_read_unlock_bh(); From patchwork Wed Nov 13 12:51:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hangbin Liu X-Patchwork-Id: 843020 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C9A9A203715; Wed, 13 Nov 2024 12:52:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731502332; cv=none; b=PdzIDZcOFhVxZICRdU39GvbkY1PspNn5UlemP999G+xruSCUdtmlZ03Is8Cbo/he41qACRIK1dwLdyvIeqIKe7p0rbPrs2eNm81+wSgCH4DUrfG6lx3KGPyXiqqcpdZNuhTNFCFUixfcMsdbnExG7LuqoYyD37ejmdGq/oE9GxU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731502332; c=relaxed/simple; bh=7EK9WdjCqkV7Na+zQG7xEtIJkamZHlr1piJWfXSpWwg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QfgwfrU+f8OrFBrcbvtLiBJpX56neYO85ZnLUCvkyGXSRIkhwrmeA61CoJsPcLtyHQ4V7Eu1eYYEBOL6u2Nth7Q+s3i1RwI96+GOw09qT4gHG/ChzKKzLkagR17AIwSOsd+ff/4e2/qmxK/qnor7GXJpchx1AxdaLZtp+BOwSak= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=WZORVkgE; arc=none smtp.client-ip=209.85.214.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WZORVkgE" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-21145812538so63067945ad.0; Wed, 13 Nov 2024 04:52:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731502330; x=1732107130; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vmw2aGbUmIbympiMA9t+9QUm6FY7MHOvDDMcOvECtkw=; b=WZORVkgE8nbP/5d7hGl1Pw9IOklNSte7jMXLL90KuRBZvzsEdz+fE4Bqzb0brD6XP/ tKJ5x7nrc5WM/5aSv3lhRDMHenVNaRMaH+CYkhnVZ59Ssith1PCagd3efNdqKeNq4OiU IU3ugusrD6urC42xp709q6MQRhyG92KJCaenysgmNXDPZ+lN1/xDbx5/Z2vtSAJeSZSA 71qN1TFch2OKtdsqgpPU7WNf6HWODeD5CCeXsAQ1+9V4ayn+AFMQaAd5nangX8gN8HnE T2JWcTFQa6x+xunQF10+PnNlUrOs7ZKz03GHXckYYukbvr6GhIUa/xs+eCW5KywTLcyP 4qSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731502330; x=1732107130; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vmw2aGbUmIbympiMA9t+9QUm6FY7MHOvDDMcOvECtkw=; b=iYHGLqEeUIYLQB358iwF04Frmq0lJbSsU7heJs+K41lcoOdOZmcciXMfr0bRKDr1jL WsNtuP3+9aocv8Vq0nU1p0hyTwSWKj9yC3g4zBCVUSrDGFFqy7gitMEoEpvXZukL9+7F KEmGw0fuj//p9dJ7AM0lLs8nWV/Ivwkw/7qMOQTLoEYDAC7YH2uzjYQUrorhuSnx+g+f kRT4ovsG9plAShCR7Ywatv69Qd0YBvgTG32fD5vphsEA5XW4qcntQaRdY8OxxiiGR98v aZUSPuv9TQhXfBajRtsIxvep9CXq7RDoK6Uoh7GoJxQ5Q9fh96rh4XewQ+X/ARXA6mhP CckA== X-Forwarded-Encrypted: i=1; AJvYcCWr2DDArZsb+eSn9gM3QNZ/YiUhZzKwiIZ+LPSLPing3bbnqN6JglF40jLdqP9Y4Hukg+o5ijCO8K0LByIFoqCX@vger.kernel.org, AJvYcCXtAeop7IE1xbaBd6To7JMstnARMm460zFMv6uh8i9FRrkMH2k+FS5VcN1R6NLZcRx77+6wmqsic/sdJng=@vger.kernel.org X-Gm-Message-State: AOJu0Yyz9m01neFyTqFKAchb1zwOXlXDrVH/DIBUyd18nW9rpTHOWKiz tKyqVLlkGvDqrr3ZJSHXyivf1GD6M4AyEsDf7tqMWpwwVQAItbBf/fjmQk15D5+nkA== X-Google-Smtp-Source: AGHT+IF8bzWzZtwJ9Fp6GZBrHamBcZ5ADKAHqPgxdoKDpPxBrHsoI2HWrXBgoN0bekPl039O+BVBfQ== X-Received: by 2002:a17:902:d4c1:b0:20c:95d9:25e6 with SMTP id d9443c01a7336-21183d2659bmr289071655ad.34.1731502329822; Wed, 13 Nov 2024 04:52:09 -0800 (PST) Received: from fedora.dns.podman ([43.228.180.230]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21177cfb0ecsm109276345ad.0.2024.11.13.04.52.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Nov 2024 04:52:09 -0800 (PST) From: Hangbin Liu To: netdev@vger.kernel.org Cc: "David S. Miller" , David Ahern , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan , Sam Edwards , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Hangbin Liu Subject: [PATCH net 2/2] selftests/rtnetlink.sh: add mngtempaddr test Date: Wed, 13 Nov 2024 12:51:52 +0000 Message-ID: <20241113125152.752778-3-liuhangbin@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241113125152.752778-1-liuhangbin@gmail.com> References: <20241113125152.752778-1-liuhangbin@gmail.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add a test to check the temporary address could be added/removed correctly when mngtempaddr is set or removed/unmanaged. Suggested-by: Sam Edwards Signed-off-by: Hangbin Liu --- tools/testing/selftests/net/rtnetlink.sh | 89 ++++++++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/tools/testing/selftests/net/rtnetlink.sh b/tools/testing/selftests/net/rtnetlink.sh index bdf6f10d0558..f25a363d55bd 100755 --- a/tools/testing/selftests/net/rtnetlink.sh +++ b/tools/testing/selftests/net/rtnetlink.sh @@ -29,6 +29,7 @@ ALL_TESTS=" kci_test_bridge_parent_id kci_test_address_proto kci_test_enslave_bonding + kci_test_mngtmpaddr " devdummy="test-dummy0" @@ -44,6 +45,7 @@ check_err() if [ $ret -eq 0 ]; then ret=$1 fi + [ -n "$2" ] && echo "$2" } # same but inverted -- used when command must fail for test to pass @@ -1267,6 +1269,93 @@ kci_test_enslave_bonding() ip netns del "$testns" } +# If the mngtmpaddr or tempaddr missing, return 0 and stop waiting +check_tempaddr_exists() +{ + local start=${1-"1"} + addr_list=$(ip -j -n $testns addr show dev ${devdummy}) + for i in $(seq $start 4); do + if ! echo ${addr_list} | \ + jq -r '.[].addr_info[] | select(.mngtmpaddr == true) | .local' | \ + grep -q "200${i}"; then + check_err $? "No mngtmpaddr 200${i}:db8::1" + return 0 + fi + + if ! echo ${addr_list} | \ + jq -r '.[].addr_info[] | select(.temporary == true) | .local' | \ + grep -q "200${i}"; then + check_err $? "No tempaddr for 200${i}:db8::1" + return 0 + fi + done + return 1 +} + +kci_test_mngtmpaddr() +{ + local ret=0 + + setup_ns testns + if [ $? -ne 0 ]; then + end_test "SKIP mngtmpaddr tests: cannot add net namespace $testns" + return $ksft_skip + fi + + # 1. Create a dummy Ethernet interface + run_cmd ip -n $testns link add ${devdummy} type dummy + run_cmd ip -n $testns link set ${devdummy} up + run_cmd ip netns exec $testns sysctl -w net.ipv6.conf.${devdummy}.use_tempaddr=1 + # 2. Create several (3-4) mngtmpaddr addresses on that interface. + # with temp_*_lft configured to be pretty short (10 and 35 seconds + # for prefer/valid respectively) + for i in $(seq 1 4); do + run_cmd ip -n $testns addr add 200${i}:db8::1/64 dev ${devdummy} mngtmpaddr + tempaddr=$(ip -j -n $testns addr show dev ${devdummy} | \ + jq -r '.[].addr_info[] | select(.temporary == true) | .local' | \ + grep 200${i}) + #3. Confirm that temporary addresses are created immediately. + if [ -z $tempaddr ]; then + check_err 1 "no tempaddr created for 200${i}:db8::1" + else + run_cmd ip -n $testns addr change $tempaddr dev ${devdummy} \ + preferred_lft 10 valid_lft 35 + fi + done + + #4. Confirm that a preferred temporary address exists for each mngtmpaddr + # address at all times, polling once per second for at least 5 minutes. + slowwait 300 check_tempaddr_exists + + #5. Delete each mngtmpaddr address, one at a time (alternating between + # deleting and merely un-mngtmpaddr-ing), and confirm that the other + # mngtmpaddr addresses still have preferred temporaries. + for i in $(seq 1 4); do + if (( $i % 2 == 1 )); then + run_cmd ip -n $testns addr del 200${i}:db8::1/64 dev ${devdummy} + else + run_cmd ip -n $testns addr change 200${i}:db8::1/64 dev ${devdummy} + fi + # the temp addr should be deleted + if ip -j -n $testns addr show dev ${devdummy} | \ + jq -r '.[].addr_info[] | select(.temporary == true) | .local' | \ + grep -q "200${i}"; then + check_err 1 "tempaddr not deleted for 200${i}:db8::1" + fi + # Check other addresses are still exist + check_tempaddr_exists $((i + 1)) + done + + if [ $ret -ne 0 ]; then + end_test "FAIL: mngtmpaddr add/remove incorrect" + ip netns del "$testns" + return 1 + fi + + end_test "PASS: mngtmpaddr add/remove correctly" + ip netns del "$testns" +} + kci_test_rtnl() { local current_test