From patchwork Wed Feb 7 19:29:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kui-Feng Lee X-Patchwork-Id: 13549008 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f178.google.com (mail-yw1-f178.google.com [209.85.128.178]) (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 A76381E514 for ; Wed, 7 Feb 2024 19:29:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707334185; cv=none; b=KMVC9Z9MDLPvroEQEZqrrL9ElvmGLSgUyNib3Rh7e3sMkkQEe8EF/717Qr/fDs3FyLVTwcBnDhko9k5xcfsmcJqaf7OiZbMFRj1t1Zodppin/RWl/W6pdhxtz6llQCqqjgVbDTwp/7gzZ8PLqtDNjHW9E6vUgcQGnBxMIPBnUrE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707334185; c=relaxed/simple; bh=4tSVrc3lDD9aUoYxlltfLeAwJNFQSEcmRZdoZavUtrI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=lpLisYtLvJWzbo2qRUwP22uq+ZwkTaGOtCfysMSYBxnDuMT3ILz2Fd9/m/DPvpNqs5X0WpR+6yUVhQJyqIPCCbBTE5Km84WobIXK424hei+vniluMJ+FGrYd7Yi5ro5QpIyYxuCCgRnot9MZyHNPkVfN0VycbOHsu97w+rjLT2U= 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=HiGb8QGe; arc=none smtp.client-ip=209.85.128.178 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="HiGb8QGe" Received: by mail-yw1-f178.google.com with SMTP id 00721157ae682-604a05e26c3so3393857b3.3 for ; Wed, 07 Feb 2024 11:29:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707334182; x=1707938982; 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=g8gr/KnM/VeL15b3iiujnM+2BUtml3tCCqm7xonJUZI=; b=HiGb8QGebrQL0dGJmAA5PS5Q9cd2EyvtkXdUhcB5tziRIoLL4WtcaA+xa4rrP+Di9A FHoTsisHOnL0U/IeHBLx2IpkTZvNx1Ks/ar66r6EoTJ04gQyDNqLu4ElY9BOcOKAJe8P uNa7jZ6nRVZdT2nIh8ieO/47vSF+CfncA558q/fy4nouW2sg9BfgGLXXd9ME2xJs+o46 OdDCZlTVeWSqBlQX4R+w2k2+nz2irAY1P0h+j6E4NvXTMw3uyeQKg1ufsCWNP3D/04PH oWsmG1F5ej7dqgaoLoefm0NDjZf5odjcpY0FdppDkjfph103EYteW6jw3fL/mAXDcWeG qQJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707334182; x=1707938982; 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=g8gr/KnM/VeL15b3iiujnM+2BUtml3tCCqm7xonJUZI=; b=XZzS2n1QCobIDvth4HunK8/WGJUUvrcfelflEODVLuieztkpoUR3C8eaPYgnv7BAMJ /yp7NU5gHhry7MCLhgRpR6tescKxNIvc78Q/hJo2tvzIK24S/jLWZEHwJ7An1UaxPUfF v5zl5UH367ttpLKwtLb1DIgL2hrDJA8f0F8Og8p82e2aa9Pmc5HX02sFDnmKHOaedgcN FfUGFwBlyaN203kTmmgM0LKtBC/9nlr1zNnQme6HUBEF9IX/KgFu7KtGIVkGDhWMxt2n 7DbJRuTESwI0O7RnvhvUAw2Vd2igimjR10amhIQJIP7mKHtlExYeRtJEUAFwLmk/RBTi yfHg== X-Gm-Message-State: AOJu0YxCOgxWLC6k6DfCcX4LDol7wZT/SoOAaoA7kMFHgPU3QLeVxuAy ZBgdm47X6BWRPHQyo/izkZmZB54ZPax95BrY6lPmJwQBMmIYmhZaSy2pHuuK X-Google-Smtp-Source: AGHT+IEBTK0CDpkXFnw67b9Ub5KCuvpWWwPirWHpk9VyUqk5PYjmDS3FHIUocNrbpg+upreUy5Aj9g== X-Received: by 2002:a0d:ec43:0:b0:604:99a:141 with SMTP id r3-20020a0dec43000000b00604099a0141mr5113568ywn.51.1707334182047; Wed, 07 Feb 2024 11:29:42 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCXYGPyRT7p3FBDXQqm3R6waf8MAngy/ZPufcjJUSjZ6ycoI7nLmvBIjQTCMPNKuOH3o94ALRQcheS5zpSf249Tby2avDbAJnGJ+Lp3ub9dKDvc3WI95U4T0mti9VXxk8/GV79/wIq9WmuMYTI3BVJDE1lkXTrjorvZF2hUcTGttKfBEoGszpL2hufQEcG2yzPDCrb2wzBvsZWMw+4Qtm5K4vi8OWAGvncLad+jxd5mqKqMasRd+PF8RRs7n/t3KIGvTXpXX6RzmYCy0Jab2tcwcdplJuqZR1EZq3u7qkri37JUQmHM23vXP+/e72u59czWsdB2GQLFADepV3XcbuDpIwO49FBLhYab66w== Received: from kickker.attlocal.net ([2600:1700:6cf8:1240:50ba:b8f8:e3dd:4d24]) by smtp.gmail.com with ESMTPSA id cn33-20020a05690c0d2100b006040cbbe952sm380088ywb.89.2024.02.07.11.29.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 11:29:41 -0800 (PST) From: thinker.li@gmail.com To: netdev@vger.kernel.org, ast@kernel.org, martin.lau@linux.dev, kernel-team@meta.com, davem@davemloft.net, dsahern@kernel.org, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, liuhangbin@gmail.com Cc: sinquersw@gmail.com, kuifeng@meta.com, Kui-Feng Lee Subject: [PATCH net-next v5 1/5] net/ipv6: set expires in rt6_add_dflt_router(). Date: Wed, 7 Feb 2024 11:29:29 -0800 Message-Id: <20240207192933.441744-2-thinker.li@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240207192933.441744-1-thinker.li@gmail.com> References: <20240207192933.441744-1-thinker.li@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Kui-Feng Lee Pass the duration of a lifetime (in seconds) to the function rt6_add_dflt_router() so that it can properly set the expiration time. The function ndisc_router_discovery() is the only one that calls rt6_add_dflt_router(), and it will later set the expiration time for the route created by rt6_add_dflt_router(). However, there is a gap of time between calling rt6_add_dflt_router() and setting the expiration time in ndisc_router_discovery(). During this period, there is a possibility that a new route may be removed from the routing table. By setting the correct expiration time in rt6_add_dflt_router(), we can prevent this from happening. The reason for setting RTF_EXPIRES in rt6_add_dflt_router() is to start the Garbage Collection (GC) timer, as it only activates when a route with RTF_EXPIRES is added to a table. Suggested-by: David Ahern Reviewed-by: Hangbin Liu Reviewed-by: David Ahern Signed-off-by: Kui-Feng Lee --- include/net/ip6_route.h | 3 ++- net/ipv6/ndisc.c | 3 ++- net/ipv6/route.c | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/include/net/ip6_route.h b/include/net/ip6_route.h index 28b065790261..52a51c69aa9d 100644 --- a/include/net/ip6_route.h +++ b/include/net/ip6_route.h @@ -170,7 +170,8 @@ struct fib6_info *rt6_get_dflt_router(struct net *net, struct fib6_info *rt6_add_dflt_router(struct net *net, const struct in6_addr *gwaddr, struct net_device *dev, unsigned int pref, - u32 defrtr_usr_metric); + u32 defrtr_usr_metric, + int lifetime); void rt6_purge_dflt_routers(struct net *net); diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c index a19999b30bc0..a68462668158 100644 --- a/net/ipv6/ndisc.c +++ b/net/ipv6/ndisc.c @@ -1382,7 +1382,8 @@ static enum skb_drop_reason ndisc_router_discovery(struct sk_buff *skb) neigh_release(neigh); rt = rt6_add_dflt_router(net, &ipv6_hdr(skb)->saddr, - skb->dev, pref, defrtr_usr_metric); + skb->dev, pref, defrtr_usr_metric, + lifetime); if (!rt) { ND_PRINTK(0, err, "RA: %s failed to add default route\n", diff --git a/net/ipv6/route.c b/net/ipv6/route.c index 63b4c6056582..98abba8f15cd 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -4355,7 +4355,8 @@ struct fib6_info *rt6_add_dflt_router(struct net *net, const struct in6_addr *gwaddr, struct net_device *dev, unsigned int pref, - u32 defrtr_usr_metric) + u32 defrtr_usr_metric, + int lifetime) { struct fib6_config cfg = { .fc_table = l3mdev_fib_table(dev) ? : RT6_TABLE_DFLT, @@ -4368,6 +4369,7 @@ struct fib6_info *rt6_add_dflt_router(struct net *net, .fc_nlinfo.portid = 0, .fc_nlinfo.nlh = NULL, .fc_nlinfo.nl_net = net, + .fc_expires = jiffies_to_clock_t(lifetime * HZ), }; cfg.fc_gateway = *gwaddr; From patchwork Wed Feb 7 19:29:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kui-Feng Lee X-Patchwork-Id: 13549009 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f172.google.com (mail-yw1-f172.google.com [209.85.128.172]) (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 09AA685C42 for ; Wed, 7 Feb 2024 19:29:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707334186; cv=none; b=NifTtZbJ8cW35MvoIdeBoB9aVUQ8foThy30GUxlhCdjE5v7mNLIFaD8CQjZ53FNmZ3cyUM6gI3Xue5MseGEcJSftjh1VV97F472NSj9L1st8G/ewnTIzBMxrUNZxzjF+TL5pH6K/6klgOdvhpaB2LaSjj/GW5No2a57pIl6nBsA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707334186; c=relaxed/simple; bh=Zb0KvqSVUFD6trhqRy7c97PHe4hgPnMtl+lYemNh+DI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=EQXxfTNVuhsFSas19qgy+/KlV4w+gKico1/sJQy+0VcsMZDwq2aFSG0ktctU3YC7RYu+sHUsCfVlNxokcRVxSvnzWF2jDErrYyNi3nkcrBBq2Pi/ioNhxoEn8DHsKhcgGGHU7xb0ct07aq7+onzrL11QLJ1zlDIMfR9qzWDxSk4= 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=YMANQWpS; arc=none smtp.client-ip=209.85.128.172 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="YMANQWpS" Received: by mail-yw1-f172.google.com with SMTP id 00721157ae682-604a05a36d2so4210957b3.0 for ; Wed, 07 Feb 2024 11:29:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707334183; x=1707938983; 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=FAhvacwnXC+gT2jQb1I4E2pL8pNEiK+4PVEePz3ZhJ8=; b=YMANQWpSeX3QLm8O6MtZp9VqcmTrjsQpEWzKsiwgcKuV8QTh+cowV8TYbbAQen8dYM E2Nuv19z2sJ0vevZWuPetVFtCcwriLDmJZrg9e7x0p69erzFdQN8vyV2A0xIyfAwxOhN en6kUcN5kYo43p6aDWDZfk71XVronweX7sKV1fElMDQ0BNmX9reHrWnRZDd7bonMgGfj IRiGlycebR2e19JnalGd2srsz5pxDJiWXAfkBM7tyslDByEThAm3zbvoktzCUzsukch2 2Ndtyigm7KTS8dfwAmG76enJlO81pC0vMhZopr6N1t/0V+zMvws48dS7ktaWfD69NLEB b3cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707334183; x=1707938983; 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=FAhvacwnXC+gT2jQb1I4E2pL8pNEiK+4PVEePz3ZhJ8=; b=ZhSxdrI4a9fTv1j+sKRXfjSMjwgaBkVvqS3yl5PY80z2GFosilpbb58W+DxFMuEuHA VPeeQgHB940RdPEOUAz7GOZgdLcSKISoSoVrCECwHtD+6uggGi4lBHp7Bmgd90NhGp1B 7NMK7NOilI9O4TfUEl0+iqw2Y3Ramin2rEJJgjPPApfwpdXIbMngdKEAq3vboPfIJbX/ c5ko2vxTaXnCgMBV74g0kkKKm5RL3qgbKydMjtrQLknRfIpMJpDS5z2bAZ/pCR2KKSzm pkcl+ZRNh9UU0PhTcNvRzNvD3/R1TIInEgKEhurZI8DKPfoCR1aptBFVYbmgRrVZs2TW vDOA== X-Gm-Message-State: AOJu0YwUuk+whqwe5ELvTKSqp4X67WFDQzp/vbc8v+2TC51n/Uc+sTKS ftExDTOAEDEel6RKG/yLCKhl5sixlRWoxXkR2CJ7aywaSkqd9x49fUMTCZpv X-Google-Smtp-Source: AGHT+IEg/r5XIgTBe5APRpYJI1nD/tOW7AjzXULl6h1ItepdteOWJUDuPcMSmDSgD/uWSDQmM2/E3g== X-Received: by 2002:a81:4043:0:b0:602:ab33:5f5 with SMTP id m3-20020a814043000000b00602ab3305f5mr6071610ywn.11.1707334183355; Wed, 07 Feb 2024 11:29:43 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWzxIou0X3VkyEBWHSshJQ+lJMQIatb275H90GSpxLtTRYkoRx04PYiqRe96oVpVpKcwNOn5Mys7pn7QowPIAyxbAmhKndonPO9x/2g/WLBi/ZIbca0tYHgX5TjoiJuJ/f7wQXzJ9Ukuktm3PydocU4M1sbta2rOoyijholXFC8Nzw0uRUntu0eIukxpG17gJNsrLIAy6O3ALzvaXL6yDS3N/TanBBqi/iy3bz+m1IvofquYiPyIpJ/OLJwEfrQ4RGAzSJFC3FJkv3agQHxu0sWTZDy9csz4nuKKnfXEvwGYjvGBaGbIJ09JvgtIo0JSWPTh0RnX5QybRzOSd3gMgUITGj0kHr+HRDEoA== Received: from kickker.attlocal.net ([2600:1700:6cf8:1240:50ba:b8f8:e3dd:4d24]) by smtp.gmail.com with ESMTPSA id cn33-20020a05690c0d2100b006040cbbe952sm380088ywb.89.2024.02.07.11.29.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 11:29:43 -0800 (PST) From: thinker.li@gmail.com To: netdev@vger.kernel.org, ast@kernel.org, martin.lau@linux.dev, kernel-team@meta.com, davem@davemloft.net, dsahern@kernel.org, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, liuhangbin@gmail.com Cc: sinquersw@gmail.com, kuifeng@meta.com, Kui-Feng Lee Subject: [PATCH net-next v5 2/5] net/ipv6: Remove unnecessary clean. Date: Wed, 7 Feb 2024 11:29:30 -0800 Message-Id: <20240207192933.441744-3-thinker.li@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240207192933.441744-1-thinker.li@gmail.com> References: <20240207192933.441744-1-thinker.li@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Kui-Feng Lee The route here is newly created. It is unnecessary to call fib6_clean_expires() on it. Suggested-by: Eric Dumazet Reviewed-by: Hangbin Liu Reviewed-by: David Ahern Signed-off-by: Kui-Feng Lee --- net/ipv6/route.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/net/ipv6/route.c b/net/ipv6/route.c index 98abba8f15cd..dd6ff5b20918 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -3765,8 +3765,6 @@ static struct fib6_info *ip6_route_info_create(struct fib6_config *cfg, if (cfg->fc_flags & RTF_EXPIRES) fib6_set_expires(rt, jiffies + clock_t_to_jiffies(cfg->fc_expires)); - else - fib6_clean_expires(rt); if (cfg->fc_protocol == RTPROT_UNSPEC) cfg->fc_protocol = RTPROT_BOOT; From patchwork Wed Feb 7 19:29:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kui-Feng Lee X-Patchwork-Id: 13549010 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f175.google.com (mail-yw1-f175.google.com [209.85.128.175]) (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 59C9A85C63 for ; Wed, 7 Feb 2024 19:29:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707334188; cv=none; b=CYHxgVtgFC4f62+LEfvmxzxmkPw04S3SYMdjUPYCGsPMjyGi7XZGSHTMSOzDfAjEt4DFp0jkMlYOkk5gXnSEIoWxgdTxz7yM2w99TTuwDb+K/n6eA9ZHfCKBm623uM83TEGekGrIzuO+VhNKtN6UlbvNDhBQ6pg5Gw6lMmVTiH0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707334188; c=relaxed/simple; bh=/8RjjliBvKi/zKAnw8MUx75V9Iqx8lozrPN6JN3XUFA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=cK/SX5J2758PAgGLDMXIecTs447+XpuhM920zFwK2pS/q3BLQhHgx7dS1acdaOVEskF3kGeTSfz0qEbQxjvT8eZppcH/Kc6sGt+jzwSDGOxzyk6+WvuIAV3qGxJgnYH7aF4/F0H7oCY1lwE00ga2MJ35GA462QRr2dDx3BzRmzY= 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=m7RhVvys; arc=none smtp.client-ip=209.85.128.175 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="m7RhVvys" Received: by mail-yw1-f175.google.com with SMTP id 00721157ae682-60482b91650so12048717b3.3 for ; Wed, 07 Feb 2024 11:29:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707334185; x=1707938985; 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=pBLmUSswsfGUFbq02YaJy6+IZiP7sz7gw1Rb1UaLmZ8=; b=m7RhVvys8mNkbSS3s1woqerMN2ILpX68zPGVXHIj4nwNWJiXkgz4/jRjAwLVz9Lt9C dqhc8Rek5K106739WlBxgT9kbTgzWLr/LUcpkd5DolG3pbHZ3vVHkieYJwagZBssBvvA PeuMKyNv9expr9FXC9FQ32deH5FGVM6o8BbDpfHLcpZVGW/ciLBgEa1iMdpGf97VreZn DOTWHrpEW+Em8lYSfin3XeOgeEJb8vZ03FCGmSkq5+lxSolcjiaJARXqQA6K/Jf2ot6m Zv0UJR3q8D41ZdlPop4B9XXOOd5oJNPjtf/eaY8v7vxl1re4Vxa1vRLM5U/Fhdg2MEUY BV5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707334185; x=1707938985; 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=pBLmUSswsfGUFbq02YaJy6+IZiP7sz7gw1Rb1UaLmZ8=; b=nbjp6IOOzDue4xld3Ikvj83i4d8BqHaTu1Bl+AvLPN+Hx1SYi4gfjIU2PnGKi3Ux5l +w5qFlTS2TI4jzDeWm49W6i8oPSaz9zQSRcRJs2+1bflrHBh6RjtuhMRfsduETkHdKvz 9JP5YNehg9ANsVO5nZMyxqgrKG9f1SnxyaGPqTJWjkgSzpuZyWqAm72/xC2NcYzVdkrw nuWQZIjzxTiGzr1zJzEcvLciJrZ/pdV0B50o4r0Ux8Mqw2Qoa9WuT8mxOF26hMqTmXg9 pYGoE9Bd+bT0B8WpbhPF9sYnngKzx+yDXsplChIrbq7lFF5pNr5mMpGmuf1wdL91rtJP fKfQ== X-Gm-Message-State: AOJu0Yw9XrLAAiDzfz/o+pneP5xOJtYzVJuHyik2rxZBnfLb6D00kosi E9yELdl2zFHI99OvT2SnCuNpBAYX1/6QFQpdL3uFjxklE52HoMlgMLbwuu0e X-Google-Smtp-Source: AGHT+IEqJ2Kc2DL0+Qtx+xYc8yprafqMQ78VWn254McpR7oYSHdcBOlXQhIdRJLPmHzpUOZTs1z7xg== X-Received: by 2002:a0d:d204:0:b0:602:a428:cbf1 with SMTP id u4-20020a0dd204000000b00602a428cbf1mr5672856ywd.24.1707334184938; Wed, 07 Feb 2024 11:29:44 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCV/jreq0G+jfcOWDSNZVbyA2DyOxOqcRFvGyb2GqDeO6Vt+Vx4yP5ZEOfTatZfG95Tb0jvwRY5sf10PmdtkPfuzba2g/j8raesQPNrLsXw8H+zoDchX6ATs6pKa5rUoihL2UvupXDvAwSyiNND0l7ecqTF2qt62wvcZa8JKZAd4cgwQkTus1fsiFYlVLViqXvQiCddEPGEdhRDWj2SHAbqaqkiB1rYQPVHJDe/c8X+UJZ0vYn79R6QZJzs8KmIJBj+33OIye0k9AikVNILY8l471N57eGCqjyscZfKD6f4GMyZfaLiKWL4PXJrZe3QBOGvMUORhMdrtbRCMUT4UAqGHoVmiqcGr/6SaWA== Received: from kickker.attlocal.net ([2600:1700:6cf8:1240:50ba:b8f8:e3dd:4d24]) by smtp.gmail.com with ESMTPSA id cn33-20020a05690c0d2100b006040cbbe952sm380088ywb.89.2024.02.07.11.29.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 11:29:44 -0800 (PST) From: thinker.li@gmail.com To: netdev@vger.kernel.org, ast@kernel.org, martin.lau@linux.dev, kernel-team@meta.com, davem@davemloft.net, dsahern@kernel.org, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, liuhangbin@gmail.com Cc: sinquersw@gmail.com, kuifeng@meta.com, Kui-Feng Lee Subject: [PATCH net-next v5 3/5] net/ipv6: Remove expired routes with a separated list of routes. Date: Wed, 7 Feb 2024 11:29:31 -0800 Message-Id: <20240207192933.441744-4-thinker.li@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240207192933.441744-1-thinker.li@gmail.com> References: <20240207192933.441744-1-thinker.li@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Kui-Feng Lee FIB6 GC walks trees of fib6_tables to remove expired routes. Walking a tree can be expensive if the number of routes in a table is big, even if most of them are permanent. Checking routes in a separated list of routes having expiration will avoid this potential issue. Reviewed-by: David Ahern Signed-off-by: Kui-Feng Lee --- include/net/ip6_fib.h | 46 ++++++++++++++++++++++++++++++++- net/ipv6/addrconf.c | 41 ++++++++++++++++++++++++----- net/ipv6/ip6_fib.c | 60 +++++++++++++++++++++++++++++++++++++++---- net/ipv6/ndisc.c | 10 +++++++- net/ipv6/route.c | 13 ++++++++-- 5 files changed, 154 insertions(+), 16 deletions(-) diff --git a/include/net/ip6_fib.h b/include/net/ip6_fib.h index 360b12e61850..323c94f1845b 100644 --- a/include/net/ip6_fib.h +++ b/include/net/ip6_fib.h @@ -173,6 +173,9 @@ struct fib6_info { refcount_t fib6_ref; unsigned long expires; + + struct hlist_node gc_link; + struct dst_metrics *fib6_metrics; #define fib6_pmtu fib6_metrics->metrics[RTAX_MTU-1] @@ -241,12 +244,18 @@ static inline bool fib6_requires_src(const struct fib6_info *rt) return rt->fib6_src.plen > 0; } +/* The callers should hold f6i->fib6_table->tb6_lock if a route has ever + * been added to a table before. + */ static inline void fib6_clean_expires(struct fib6_info *f6i) { f6i->fib6_flags &= ~RTF_EXPIRES; f6i->expires = 0; } +/* The callers should hold f6i->fib6_table->tb6_lock if a route has ever + * been added to a table before. + */ static inline void fib6_set_expires(struct fib6_info *f6i, unsigned long expires) { @@ -327,8 +336,10 @@ static inline bool fib6_info_hold_safe(struct fib6_info *f6i) static inline void fib6_info_release(struct fib6_info *f6i) { - if (f6i && refcount_dec_and_test(&f6i->fib6_ref)) + if (f6i && refcount_dec_and_test(&f6i->fib6_ref)) { + DEBUG_NET_WARN_ON_ONCE(!hlist_unhashed(&f6i->gc_link)); call_rcu(&f6i->rcu, fib6_info_destroy_rcu); + } } enum fib6_walk_state { @@ -382,6 +393,7 @@ struct fib6_table { struct inet_peer_base tb6_peers; unsigned int flags; unsigned int fib_seq; + struct hlist_head tb6_gc_hlist; /* GC candidates */ #define RT6_TABLE_HAS_DFLT_ROUTER BIT(0) }; @@ -498,6 +510,38 @@ void fib6_gc_cleanup(void); int fib6_init(void); +/* Add the route to the gc list if it is not already there + * + * The callers should hold f6i->fib6_table->tb6_lock. + */ +static inline void fib6_add_gc_list(struct fib6_info *f6i) +{ + /* If fib6_node is null, the f6i is not in (or removed from) the + * table. + * + * There is a gap between finding the f6i from the table and + * calling this function without the protection of the tb6_lock. + * This check makes sure the f6i is not added to the gc list when + * it is not on the table. + */ + if (!rcu_dereference_protected(f6i->fib6_node, + lockdep_is_held(&f6i->fib6_table->tb6_lock))) + return; + + if (hlist_unhashed(&f6i->gc_link)) + hlist_add_head(&f6i->gc_link, &f6i->fib6_table->tb6_gc_hlist); +} + +/* Remove the route from the gc list if it is on the list. + * + * The callers should hold f6i->fib6_table->tb6_lock. + */ +static inline void fib6_remove_gc_list(struct fib6_info *f6i) +{ + if (!hlist_unhashed(&f6i->gc_link)) + hlist_del_init(&f6i->gc_link); +} + struct ipv6_route_iter { struct seq_net_private p; struct fib6_walker w; diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index d63f5d063f07..0ea44563454f 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -1255,6 +1255,7 @@ static void cleanup_prefix_route(struct inet6_ifaddr *ifp, unsigned long expires, bool del_rt, bool del_peer) { + struct fib6_table *table; struct fib6_info *f6i; f6i = addrconf_get_prefix_route(del_peer ? &ifp->peer_addr : &ifp->addr, @@ -1264,8 +1265,15 @@ cleanup_prefix_route(struct inet6_ifaddr *ifp, unsigned long expires, if (del_rt) ip6_del_rt(dev_net(ifp->idev->dev), f6i, false); else { - if (!(f6i->fib6_flags & RTF_EXPIRES)) + if (!(f6i->fib6_flags & RTF_EXPIRES)) { + table = f6i->fib6_table; + spin_lock_bh(&table->tb6_lock); + fib6_set_expires(f6i, expires); + fib6_add_gc_list(f6i); + + spin_unlock_bh(&table->tb6_lock); + } fib6_info_release(f6i); } } @@ -2706,6 +2714,7 @@ EXPORT_SYMBOL_GPL(addrconf_prefix_rcv_add_addr); void addrconf_prefix_rcv(struct net_device *dev, u8 *opt, int len, bool sllao) { struct prefix_info *pinfo; + struct fib6_table *table; __u32 valid_lft; __u32 prefered_lft; int addr_type, err; @@ -2782,11 +2791,20 @@ void addrconf_prefix_rcv(struct net_device *dev, u8 *opt, int len, bool sllao) if (valid_lft == 0) { ip6_del_rt(net, rt, false); rt = NULL; - } else if (addrconf_finite_timeout(rt_expires)) { - /* not infinity */ - fib6_set_expires(rt, jiffies + rt_expires); } else { - fib6_clean_expires(rt); + table = rt->fib6_table; + spin_lock_bh(&table->tb6_lock); + + if (addrconf_finite_timeout(rt_expires)) { + /* not infinity */ + fib6_set_expires(rt, jiffies + rt_expires); + fib6_add_gc_list(rt); + } else { + fib6_clean_expires(rt); + fib6_remove_gc_list(rt); + } + + spin_unlock_bh(&table->tb6_lock); } } else if (valid_lft) { clock_t expires = 0; @@ -4741,6 +4759,7 @@ static int modify_prefix_route(struct inet6_ifaddr *ifp, unsigned long expires, u32 flags, bool modify_peer) { + struct fib6_table *table; struct fib6_info *f6i; u32 prio; @@ -4761,10 +4780,18 @@ static int modify_prefix_route(struct inet6_ifaddr *ifp, ifp->rt_priority, ifp->idev->dev, expires, flags, GFP_KERNEL); } else { - if (!expires) + table = f6i->fib6_table; + spin_lock_bh(&table->tb6_lock); + + if (!expires) { fib6_clean_expires(f6i); - else + fib6_remove_gc_list(f6i); + } else { fib6_set_expires(f6i, expires); + fib6_add_gc_list(f6i); + } + + spin_unlock_bh(&table->tb6_lock); fib6_info_release(f6i); } diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c index 38a0348b1d17..805bbf26b3ef 100644 --- a/net/ipv6/ip6_fib.c +++ b/net/ipv6/ip6_fib.c @@ -160,6 +160,8 @@ struct fib6_info *fib6_info_alloc(gfp_t gfp_flags, bool with_fib6_nh) INIT_LIST_HEAD(&f6i->fib6_siblings); refcount_set(&f6i->fib6_ref, 1); + INIT_HLIST_NODE(&f6i->gc_link); + return f6i; } @@ -246,6 +248,7 @@ static struct fib6_table *fib6_alloc_table(struct net *net, u32 id) net->ipv6.fib6_null_entry); table->tb6_root.fn_flags = RTN_ROOT | RTN_TL_ROOT | RTN_RTINFO; inet_peer_base_init(&table->tb6_peers); + INIT_HLIST_HEAD(&table->tb6_gc_hlist); } return table; @@ -1055,6 +1058,9 @@ static void fib6_purge_rt(struct fib6_info *rt, struct fib6_node *fn, lockdep_is_held(&table->tb6_lock)); } } + + fib6_clean_expires(rt); + fib6_remove_gc_list(rt); } /* @@ -1115,10 +1121,13 @@ static int fib6_add_rt2node(struct fib6_node *fn, struct fib6_info *rt, rt->fib6_nsiblings = 0; if (!(iter->fib6_flags & RTF_EXPIRES)) return -EEXIST; - if (!(rt->fib6_flags & RTF_EXPIRES)) + if (!(rt->fib6_flags & RTF_EXPIRES)) { fib6_clean_expires(iter); - else + fib6_remove_gc_list(iter); + } else { fib6_set_expires(iter, rt->expires); + fib6_add_gc_list(iter); + } if (rt->fib6_pmtu) fib6_metric_set(iter, RTAX_MTU, @@ -1477,6 +1486,10 @@ int fib6_add(struct fib6_node *root, struct fib6_info *rt, if (rt->nh) list_add(&rt->nh_list, &rt->nh->f6i_list); __fib6_update_sernum_upto_root(rt, fib6_new_sernum(info->nl_net)); + + if (rt->fib6_flags & RTF_EXPIRES) + fib6_add_gc_list(rt); + fib6_start_gc(info->nl_net, rt); } @@ -2280,9 +2293,8 @@ static void fib6_flush_trees(struct net *net) * Garbage collection */ -static int fib6_age(struct fib6_info *rt, void *arg) +static int fib6_age(struct fib6_info *rt, struct fib6_gc_args *gc_args) { - struct fib6_gc_args *gc_args = arg; unsigned long now = jiffies; /* @@ -2307,6 +2319,42 @@ static int fib6_age(struct fib6_info *rt, void *arg) return 0; } +static void fib6_gc_table(struct net *net, + struct fib6_table *tb6, + struct fib6_gc_args *gc_args) +{ + struct fib6_info *rt; + struct hlist_node *n; + struct nl_info info = { + .nl_net = net, + .skip_notify = false, + }; + + hlist_for_each_entry_safe(rt, n, &tb6->tb6_gc_hlist, gc_link) + if (fib6_age(rt, gc_args) == -1) + fib6_del(rt, &info); +} + +static void fib6_gc_all(struct net *net, struct fib6_gc_args *gc_args) +{ + struct fib6_table *table; + struct hlist_head *head; + unsigned int h; + + rcu_read_lock(); + for (h = 0; h < FIB6_TABLE_HASHSZ; h++) { + head = &net->ipv6.fib_table_hash[h]; + hlist_for_each_entry_rcu(table, head, tb6_hlist) { + spin_lock_bh(&table->tb6_lock); + + fib6_gc_table(net, table, gc_args); + + spin_unlock_bh(&table->tb6_lock); + } + } + rcu_read_unlock(); +} + void fib6_run_gc(unsigned long expires, struct net *net, bool force) { struct fib6_gc_args gc_args; @@ -2322,7 +2370,7 @@ void fib6_run_gc(unsigned long expires, struct net *net, bool force) net->ipv6.sysctl.ip6_rt_gc_interval; gc_args.more = 0; - fib6_clean_all(net, fib6_age, &gc_args); + fib6_gc_all(net, &gc_args); now = jiffies; net->ipv6.ip6_rt_last_gc = now; @@ -2382,6 +2430,7 @@ static int __net_init fib6_net_init(struct net *net) net->ipv6.fib6_main_tbl->tb6_root.fn_flags = RTN_ROOT | RTN_TL_ROOT | RTN_RTINFO; inet_peer_base_init(&net->ipv6.fib6_main_tbl->tb6_peers); + INIT_HLIST_HEAD(&net->ipv6.fib6_main_tbl->tb6_gc_hlist); #ifdef CONFIG_IPV6_MULTIPLE_TABLES net->ipv6.fib6_local_tbl = kzalloc(sizeof(*net->ipv6.fib6_local_tbl), @@ -2394,6 +2443,7 @@ static int __net_init fib6_net_init(struct net *net) net->ipv6.fib6_local_tbl->tb6_root.fn_flags = RTN_ROOT | RTN_TL_ROOT | RTN_RTINFO; inet_peer_base_init(&net->ipv6.fib6_local_tbl->tb6_peers); + INIT_HLIST_HEAD(&net->ipv6.fib6_local_tbl->tb6_gc_hlist); #endif fib6_tables_init(net); diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c index a68462668158..73cb31afe935 100644 --- a/net/ipv6/ndisc.c +++ b/net/ipv6/ndisc.c @@ -1237,6 +1237,7 @@ static enum skb_drop_reason ndisc_router_discovery(struct sk_buff *skb) struct ndisc_options ndopts; struct fib6_info *rt = NULL; struct inet6_dev *in6_dev; + struct fib6_table *table; u32 defrtr_usr_metric; unsigned int pref = 0; __u32 old_if_flags; @@ -1410,8 +1411,15 @@ static enum skb_drop_reason ndisc_router_discovery(struct sk_buff *skb) inet6_rt_notify(RTM_NEWROUTE, rt, &nlinfo, NLM_F_REPLACE); } - if (rt) + if (rt) { + table = rt->fib6_table; + spin_lock_bh(&table->tb6_lock); + fib6_set_expires(rt, jiffies + (HZ * lifetime)); + fib6_add_gc_list(rt); + + spin_unlock_bh(&table->tb6_lock); + } if (in6_dev->cnf.accept_ra_min_hop_limit < 256 && ra_msg->icmph.icmp6_hop_limit) { if (in6_dev->cnf.accept_ra_min_hop_limit <= ra_msg->icmph.icmp6_hop_limit) { diff --git a/net/ipv6/route.c b/net/ipv6/route.c index dd6ff5b20918..707d65bc9c0e 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -931,6 +931,7 @@ int rt6_route_rcv(struct net_device *dev, u8 *opt, int len, struct net *net = dev_net(dev); struct route_info *rinfo = (struct route_info *) opt; struct in6_addr prefix_buf, *prefix; + struct fib6_table *table; unsigned int pref; unsigned long lifetime; struct fib6_info *rt; @@ -989,10 +990,18 @@ int rt6_route_rcv(struct net_device *dev, u8 *opt, int len, (rt->fib6_flags & ~RTF_PREF_MASK) | RTF_PREF(pref); if (rt) { - if (!addrconf_finite_timeout(lifetime)) + table = rt->fib6_table; + spin_lock_bh(&table->tb6_lock); + + if (!addrconf_finite_timeout(lifetime)) { fib6_clean_expires(rt); - else + fib6_remove_gc_list(rt); + } else { fib6_set_expires(rt, jiffies + HZ * lifetime); + fib6_add_gc_list(rt); + } + + spin_unlock_bh(&table->tb6_lock); fib6_info_release(rt); } From patchwork Wed Feb 7 19:29:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kui-Feng Lee X-Patchwork-Id: 13549011 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f179.google.com (mail-yw1-f179.google.com [209.85.128.179]) (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 01F9285C42 for ; Wed, 7 Feb 2024 19:29:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707334189; cv=none; b=Fl56051kPXCfdqvno6+HaJVhNPN1Lgctlkl40lGFWcSzoNiDEV6yEMjvgdKGIdRyiIAOQohi3SAreqCZjgreQ9up6GRCfCu9NeEq6zVCmWaF86pc8/c2NTNMmvu1znMzDnvqUw5+0EN2mfKleSl0nd3xsyEnavSbL67947D8ZbM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707334189; c=relaxed/simple; bh=iJ2gp3cWSbvHtaHeG7008WxTUZNgYdZaxfLImM+PHDU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=AJVmTwcxBjKroeIWm5moe7z7P11n9vKBGmng0LaWW6LOZEkCmbjTFkfuvQ61Oo9X/Xa2UMwpaqPrgP74yHXk2o6L66kETNDkOM0J9EFJtiLybwzpnV599nkUmp4rfigXR3sScLqWmrhbtqZAL4KcXsYdYyqqLsXIKf7A/DquAOM= 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=jhCJ5MZ2; arc=none smtp.client-ip=209.85.128.179 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="jhCJ5MZ2" Received: by mail-yw1-f179.google.com with SMTP id 00721157ae682-60495209415so9002287b3.3 for ; Wed, 07 Feb 2024 11:29:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707334186; x=1707938986; 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=2lRjgwKvhAvYDvsHrHhtQ/wCCCH8o6LGs4SUcgFa/0M=; b=jhCJ5MZ2eYlqbELP6wsktWZlDL+L6HFznQOwWRjFco/uFJUQLIJVaPcYqf72/Ggmic KZt3bDrYnIXYRktyYFkV0CA0EKtb6m6mnoH5rjCrRhtil69tA24aFjZlXkRPjSRudtu9 tImFF3UMHLJiteMz+ZhQiMbLeoEjCmHfM+gvJ8sf49oDgTbcQGtFEMh7I7RuSPznaiCn 6ajmXQdE0JvbPHJ9wegMJ6qPQRuK8IOcjTXtl6W5u+4sneroqec0acKeN1WOf2sEPhrt UnbyUrCw2kfgkNjih7aujBnonceirhtUNmt2jem7MDd6aJuJUdVOavW6yDz0p3qBquc5 MlVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707334186; x=1707938986; 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=2lRjgwKvhAvYDvsHrHhtQ/wCCCH8o6LGs4SUcgFa/0M=; b=BQwg0Q3bo7hjeiLGByHa7CViwCZpk/Nnr99t9xqBa0BrhIoRmSmFEmsN+b1w5S/ZQi QFjAOevJbk9eDWPyyTpwn57Q63wk0+1QJAOeSM2+frBF1ETzTwVvGbPWcDO+NxcX93jk 7mc/QKm6zMvUk1O5XjRvrfP7/P8X6ovYtVk4bigA4kANOnxBm4UmR3L1gpHkl0liYlYC gDUcY877ZrZw1omWRPgLQ5QUeXvsivsD8cT1GigJPE9UafN8jRlOICzOfFRzrcUT/nuQ N8IlTFwBUOQqCDJbmc5Cnylq+3oyDfvQSCcPj8CINwIJTgkOicbCWkwIsJdDLmpEdELl QCLA== X-Gm-Message-State: AOJu0YxDVO1FRzvT7YSMuOF6ebex5CXjjVbs9vP/N7/74kekCwWpbYFU o523iTc4/auksJApgR46kgaGf3f+hDCl/aHrW1YoJ56wrsoGT25eUB28QqCN X-Google-Smtp-Source: AGHT+IGI+TYWanHusvzMpxvxMZjXd/MGvDI73K3smPmtiFF5K+Scfs1pbpsnFvmaV3rsI/JzTPslZg== X-Received: by 2002:a81:c508:0:b0:5ff:bb43:2a69 with SMTP id k8-20020a81c508000000b005ffbb432a69mr4957672ywi.40.1707334186352; Wed, 07 Feb 2024 11:29:46 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCUQ0AqgqhzWwp+Ehu+awOjLWeVg/vrsmsiDey78hUOlCt5qUOuVZF110NLuWZoGC6YTNx5VsMD6BECNkC/i6sGVGuRbgMeT/6TxfUbDFtUt3QO8Idc60lCWGpuh/fi6RpkH2S4p1k8/wYdMH37wOAIogK6veV9F9rIwL6RlqTLM2sfebCFivEOa2D27paTty/j9Tq45Ctk3XE6r+mYFkdM7u7UQs8MNeCuAqSvme7PEfNmHLk35MSzBV+BVB/CRJ36n+9Z55MHd1qciGOrsMAgAzOhfDOQulmCww2mizRm2PxDNWI7ehgNedXrE4XeXJJgwOnavCchHZei8U33AA6SSpf6cWfVoTL5fiA== Received: from kickker.attlocal.net ([2600:1700:6cf8:1240:50ba:b8f8:e3dd:4d24]) by smtp.gmail.com with ESMTPSA id cn33-20020a05690c0d2100b006040cbbe952sm380088ywb.89.2024.02.07.11.29.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 11:29:46 -0800 (PST) From: thinker.li@gmail.com To: netdev@vger.kernel.org, ast@kernel.org, martin.lau@linux.dev, kernel-team@meta.com, davem@davemloft.net, dsahern@kernel.org, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, liuhangbin@gmail.com Cc: sinquersw@gmail.com, kuifeng@meta.com, Kui-Feng Lee Subject: [PATCH net-next v5 4/5] net/ipv6: set expires in modify_prefix_route() if RTF_EXPIRES is set. Date: Wed, 7 Feb 2024 11:29:32 -0800 Message-Id: <20240207192933.441744-5-thinker.li@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240207192933.441744-1-thinker.li@gmail.com> References: <20240207192933.441744-1-thinker.li@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Kui-Feng Lee Make the decision to set or clean the expires of a route based on the RTF_EXPIRES flag, rather than the value of the "expires" argument. This patch doesn't make difference logically, but make inet6_addr_modify() and modify_prefix_route() consistent. The function inet6_addr_modify() is the only caller of modify_prefix_route(), and it passes the RTF_EXPIRES flag and an expiration value. The RTF_EXPIRES flag is turned on or off based on the value of valid_lft. The RTF_EXPIRES flag is turned on if valid_lft is a finite value (not infinite, not 0xffffffff). Even if valid_lft is 0, the RTF_EXPIRES flag remains on. The expiration value being passed is equal to the valid_lft value if the flag is on. However, if the valid_lft value is infinite, the expiration value becomes 0 and the RTF_EXPIRES flag is turned off. Despite this, modify_prefix_route() decides to set the expiration value if the received expiration value is not zero. This mixing of infinite and zero cases creates an inconsistency. Reviewed-by: Hangbin Liu Reviewed-by: David Ahern Signed-off-by: Kui-Feng Lee --- net/ipv6/addrconf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index 0ea44563454f..ca1b719323c0 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -4783,7 +4783,7 @@ static int modify_prefix_route(struct inet6_ifaddr *ifp, table = f6i->fib6_table; spin_lock_bh(&table->tb6_lock); - if (!expires) { + if (!(flags & RTF_EXPIRES)) { fib6_clean_expires(f6i); fib6_remove_gc_list(f6i); } else { From patchwork Wed Feb 7 19:29:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kui-Feng Lee X-Patchwork-Id: 13549012 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f177.google.com (mail-yw1-f177.google.com [209.85.128.177]) (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 34EC186144 for ; Wed, 7 Feb 2024 19:29:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707334190; cv=none; b=cWjSesnP7//A1fLEZj+zlemx236FJs7uK0hfe2+13cGKfzW09y1MaYvTSmxAYV7EDW0CVgtE5l5NYJIztBgyWFKVeXxeDm5Qk6dtKy6alk4VrOp9ZMlRyZfUbMzSCOBFDbeXBM9wRlJLycUfCwRYBzO8ux0OAYW+N/zfz7g8DyA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707334190; c=relaxed/simple; bh=Oo69ndk8HkyqvgtuNjqa8Z0aqTz0qVbZJ0jdM562xPc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=tojK4OAQbU8w2kuEraCPG7katbl5WzJoSJTnxZLp4LXsbm0mNeiWWTpF++5rL6Efr2qRPlgObUQnw09T6Y+xykg+FF1ZrPa3tdptEQYTQZAaIuqf/3TPyH3FYmzkNmBLeEs4xRZSw2ZssnKkjy3t/JjucQ6n1pe8/wMvGbuDdhg= 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=E8x5/tX7; arc=none smtp.client-ip=209.85.128.177 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="E8x5/tX7" Received: by mail-yw1-f177.google.com with SMTP id 00721157ae682-6049ffb9cedso4286027b3.0 for ; Wed, 07 Feb 2024 11:29:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707334188; x=1707938988; 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=qUSDzR+nEa82TMDtmmBQXA+zB3wxN5j0beDo3dnb/TA=; b=E8x5/tX7Yy9KpF9Nyw9ckPhM1L83FR4s9lGOP+O1ssTL9jmWfRTfxzWaTJwqRzaGi+ 4KH5feOhFyVuCyD7Aos5A0O0bsDhbE8vDlxLFY9i9CqxuTUeqoBxKSFsDZASz5UgkoMv CXp2imbJYFcHPxCiZXNclfQAhHau2BzYMZYV2ThkAspUWgdYMOOUW1Bf9eKct+bGLASE eW11zwA2eYg4pdfLoqMI0hQaWAtf2f99oJ4AFwRc+jzjDcWJV7saagFB2dwvl/dTj12O VCIjQwtRefjJKGDZkfpVCoYiRfx9Il7T3SUs8xcgIBk8SZ1fcslSVNjC8nSnPBxYA6Pe 7bng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707334188; x=1707938988; 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=qUSDzR+nEa82TMDtmmBQXA+zB3wxN5j0beDo3dnb/TA=; b=g7/TbCO3Ez5w+HkKhmwOgXXURpnciu8qHbk2CVBy3oSloepApcGJciU6QtX5RBAbXl gmAM9SE/iWdca7FpkTzDtjmvfweEIMLUBa2HCvX6dAS0AeBQyxUERJkDT6KgrzTPYYxW AjPCwzxiPnMEyniubiz2o7quNAh5sTDUTYvTs0F932+BZl6X3rf3x8ADx87rfZlrhYqL Qvke0sc8e/AB07jiel6XwyMPkIBzCgvEDXuDKXSu2wRBoT+d3cskB6FF9sU0uZbF5bAw TGj6WwiFlDfd9ntWXU8vPw0Urj8qJ7L/YxEGBxUFpbcabyC9yrTXBjkAhEJVxZb6ZGYj oQQA== X-Gm-Message-State: AOJu0YyTzcLX1y51+9cPRuqMrJ3aW6Ra/8MXf/vtZD+9XjUbPBG9QMRz qyn262O9RsEMJelH5fBSqmT/YJHtt/SDVYqHYweeaQkYte0q6Cmyvw2XeTfR X-Google-Smtp-Source: AGHT+IFE/JFpJ2qNWxR5qzXbuaWHH6SqJ1N5Ech5H+Pf8rZw5DPHCqsxGT4Vz9HaPG7HZiDNtZlNEw== X-Received: by 2002:a0d:e28d:0:b0:5ff:d3f3:6f4d with SMTP id l135-20020a0de28d000000b005ffd3f36f4dmr5826577ywe.42.1707334187678; Wed, 07 Feb 2024 11:29:47 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWeWE4rtP64W/7NBE9+f4s+XeRKmiEfjOfbOi5MfB9L6LELm7qoufHjFhsDUzrxLuNkrN2F79cq4a9YMn/cDsFgjVxkUKXjqyhQ1jk5TmQ0HldVpe56sVlPBbZp/JnTOnSIB9IecPW9BgfrD1VBjTAEILOrl2scl5H/Rf2ut2kVlAFxlOdHv7KI2yDnm3qHjPF8KWRwjqviGvt81DtI+/E3cLqgBBWuqo3MO4e3Gapuc6YoXBbO8HKH9/aNuarKL3S8edyl1tBKK+2fj2NcMtuN0mX8bXbck4dRw/3o4GtYC62NekjwFz75ca34gnQ+FjIUJA6zz2YwHP3p2ufGP/yW+40LADZQ+tarWA== Received: from kickker.attlocal.net ([2600:1700:6cf8:1240:50ba:b8f8:e3dd:4d24]) by smtp.gmail.com with ESMTPSA id cn33-20020a05690c0d2100b006040cbbe952sm380088ywb.89.2024.02.07.11.29.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 11:29:47 -0800 (PST) From: thinker.li@gmail.com To: netdev@vger.kernel.org, ast@kernel.org, martin.lau@linux.dev, kernel-team@meta.com, davem@davemloft.net, dsahern@kernel.org, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, liuhangbin@gmail.com Cc: sinquersw@gmail.com, kuifeng@meta.com, Kui-Feng Lee Subject: [PATCH net-next v5 5/5] selftests/net: Adding test cases of replacing routes and route advertisements. Date: Wed, 7 Feb 2024 11:29:33 -0800 Message-Id: <20240207192933.441744-6-thinker.li@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240207192933.441744-1-thinker.li@gmail.com> References: <20240207192933.441744-1-thinker.li@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Kui-Feng Lee Add tests of changing permanent routes to temporary routes and the reversed case to make sure GC working correctly in these cases. Add tests for the temporary routes from RA. The existing device will be deleted between tests to remove all routes associated with it, so that the earlier tests don't mess up the later ones. Reviewed-by: Hangbin Liu Reviewed-by: David Ahern Tested-by: Hangbin Liu Signed-off-by: Kui-Feng Lee --- tools/testing/selftests/net/fib_tests.sh | 148 +++++++++++++++++++---- 1 file changed, 126 insertions(+), 22 deletions(-) diff --git a/tools/testing/selftests/net/fib_tests.sh b/tools/testing/selftests/net/fib_tests.sh index b3ecccbbfcd2..b983462e2819 100755 --- a/tools/testing/selftests/net/fib_tests.sh +++ b/tools/testing/selftests/net/fib_tests.sh @@ -743,6 +743,43 @@ fib_notify_test() cleanup &> /dev/null } +# Create a new dummy_10 to remove all associated routes. +reset_dummy_10() +{ + $IP link del dev dummy_10 + + $IP link add dummy_10 type dummy + $IP link set dev dummy_10 up + $IP -6 address add 2001:10::1/64 dev dummy_10 +} + +check_rt_num() +{ + local expected=$1 + local num=$2 + + if [ $num -ne $expected ]; then + echo "FAIL: Expected $expected routes, got $num" + ret=1 + else + ret=0 + fi +} + +check_rt_num_clean() +{ + local expected=$1 + local num=$2 + + if [ $num -ne $expected ]; then + log_test 1 0 "expected $expected routes, got $num" + set +e + cleanup &> /dev/null + return 1 + fi + return 0 +} + fib6_gc_test() { setup @@ -751,7 +788,7 @@ fib6_gc_test() echo "Fib6 garbage collection test" set -e - EXPIRE=3 + EXPIRE=5 # Check expiration of routes every $EXPIRE seconds (GC) $NS_EXEC sysctl -wq net.ipv6.route.gc_interval=$EXPIRE @@ -763,44 +800,111 @@ fib6_gc_test() $NS_EXEC sysctl -wq net.ipv6.route.flush=1 # Temporary routes - for i in $(seq 1 1000); do + for i in $(seq 1 5); do # Expire route after $EXPIRE seconds $IP -6 route add 2001:20::$i \ via 2001:10::2 dev dummy_10 expires $EXPIRE done - sleep $(($EXPIRE * 2)) - N_EXP_SLEEP=$($IP -6 route list |grep expires|wc -l) - if [ $N_EXP_SLEEP -ne 0 ]; then - echo "FAIL: expected 0 routes with expires, got $N_EXP_SLEEP" - ret=1 - else - ret=0 - fi + sleep $(($EXPIRE * 2 + 1)) + check_rt_num 0 $($IP -6 route list |grep expires|wc -l) + log_test $ret 0 "ipv6 route garbage collection" + + reset_dummy_10 # Permanent routes - for i in $(seq 1 5000); do + for i in $(seq 1 5); do $IP -6 route add 2001:30::$i \ via 2001:10::2 dev dummy_10 done # Temporary routes - for i in $(seq 1 1000); do + for i in $(seq 1 5); do # Expire route after $EXPIRE seconds $IP -6 route add 2001:20::$i \ via 2001:10::2 dev dummy_10 expires $EXPIRE done - sleep $(($EXPIRE * 2)) - N_EXP_SLEEP=$($IP -6 route list |grep expires|wc -l) - if [ $N_EXP_SLEEP -ne 0 ]; then - echo "FAIL: expected 0 routes with expires," \ - "got $N_EXP_SLEEP (5000 permanent routes)" - ret=1 - else - ret=0 + sleep $(($EXPIRE * 2 + 1)) + check_rt_num 0 $($IP -6 route list |grep expires|wc -l) + log_test $ret 0 "ipv6 route garbage collection (with permanent routes)" + + reset_dummy_10 + + # Permanent routes + for i in $(seq 1 5); do + $IP -6 route add 2001:20::$i \ + via 2001:10::2 dev dummy_10 + done + # Replace with temporary routes + for i in $(seq 1 5); do + # Expire route after $EXPIRE seconds + $IP -6 route replace 2001:20::$i \ + via 2001:10::2 dev dummy_10 expires $EXPIRE + done + check_rt_num_clean 5 $($IP -6 route list |grep expires|wc -l) || return + # Wait for GC + sleep $(($EXPIRE * 2 + 1)) + check_rt_num 0 $($IP -6 route list |grep expires|wc -l) + log_test $ret 0 "ipv6 route garbage collection (replace with expires)" + + reset_dummy_10 + + # Temporary routes + for i in $(seq 1 5); do + # Expire route after $EXPIRE seconds + $IP -6 route add 2001:20::$i \ + via 2001:10::2 dev dummy_10 expires $EXPIRE + done + # Replace with permanent routes + for i in $(seq 1 5); do + $IP -6 route replace 2001:20::$i \ + via 2001:10::2 dev dummy_10 + done + check_rt_num_clean 0 $($IP -6 route list |grep expires|wc -l) || return + + # Wait for GC + sleep $(($EXPIRE * 2 + 1)) + + check_rt_num 5 $($IP -6 route list |grep -v expires|grep 2001:20::|wc -l) + log_test $ret 0 "ipv6 route garbage collection (replace with permanent)" + + # ra6 is required for the next test. (ipv6toolkit) + if [ ! -x "$(command -v ra6)" ]; then + echo "SKIP: ra6 not found." + set +e + cleanup &> /dev/null + return fi - set +e + # Delete dummy_10 and remove all routes + $IP link del dev dummy_10 - log_test $ret 0 "ipv6 route garbage collection" + # Create a pair of veth devices to send a RA message from one + # device to another. + $IP link add veth1 type veth peer name veth2 + $IP link set dev veth1 up + $IP link set dev veth2 up + $IP -6 address add 2001:10::1/64 dev veth1 nodad + $IP -6 address add 2001:10::2/64 dev veth2 nodad + + # Make veth1 ready to receive RA messages. + $NS_EXEC sysctl -wq net.ipv6.conf.veth1.accept_ra=2 + + # Send a RA message with a route from veth2 to veth1. + $NS_EXEC ra6 -i veth2 -d 2001:10::1 -t $EXPIRE + + # Wait for the RA message. + sleep 1 + + # systemd may mess up the test. You syould make sure that + # systemd-networkd.service and systemd-networkd.socket are stopped. + check_rt_num_clean 1 $($IP -6 route list|grep expires|wc -l) || return + + # Wait for GC + sleep $(($EXPIRE * 2 + 1)) + + check_rt_num 0 $($IP -6 route list |grep expires|wc -l) + log_test $ret 0 "ipv6 route garbage collection (RA message)" + + set +e cleanup &> /dev/null }