From patchwork Fri Feb 2 08:21:56 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: 13542396 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f169.google.com (mail-yw1-f169.google.com [209.85.128.169]) (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 0791717C6C for ; Fri, 2 Feb 2024 08:22:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706862138; cv=none; b=iUwHKc3vah3p5bM69qz0Qnzm298a/9J9zKpxS/QFPqjfmnI9cjMiOWr4mGzlh4NgIvkKaRRTFq+n99MSeuZb5C5MZr27TP7qu/HH711loRBduJE73/VL4c9qM+IZziNhDjk5ftbPBbLgVV+KhXBRaEXWVmVRJ4ConM10LX4sIpI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706862138; c=relaxed/simple; bh=9Q7dIWO/up+Z+zGT7zjSYYeM+tBMW5qlYmi941jKS2A=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=DL4+UWmEz8Horva+qNPrd2LLR87PUTJuqWmG7T57WyUX8Rne+4m8eOmW2a+Y+p5v+OPBJkK9A83YNtiv6Dw80kemJb4XYr22voivcaJOwaNPaxTvX1UCkFGka2Uh4IjhB8Ctu/E02dhKZTSth4/Z7ZPIqAbbWBfiqJ823RusQQw= 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=TJ1QjPWj; arc=none smtp.client-ip=209.85.128.169 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="TJ1QjPWj" Received: by mail-yw1-f169.google.com with SMTP id 00721157ae682-6002317a427so16603287b3.2 for ; Fri, 02 Feb 2024 00:22:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706862135; x=1707466935; 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=nPABcs344aIEO6XlzzqYh/8aI4dOCp92Q8NZDEsORFE=; b=TJ1QjPWj8NFAkazHWUekFrAtPyjJHdqrWQQeVO4AnBn7zazAGfACOq+4QhfJ8iEqo9 J8MrpSC/pgE6yT6wUEI8pqo6d13Wgu5t6r7KI9mdWoJ2ZyEl64UwbWicmAHpeCxVqJlc 91Syw4EHnT1I6BrPzlgEpCHx/5KGi1jUjlXJ9LWp99JUuulfEi9/Kn/kT2oepTZfoRdB O1/rZ518rkUOdLdS5d2jkMqCwLue/mfF5WjvXYkjkQ96nu+S1Juwkou5VeUQGVZAzYo8 iTjljL5WthnU533rjDpqBY67LSgCsRZqk9cEieoJiCUVMwEoXmHbm59/deeZvXFK6sZ3 dGWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706862135; x=1707466935; 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=nPABcs344aIEO6XlzzqYh/8aI4dOCp92Q8NZDEsORFE=; b=rfZexT/mdjqsxvWWfGKrGO3cVwKVI7Ci4ze5/2CNhS0NdujU77Aw+8/UuCZgc4bVdy a0vDwC/ItKbvMgv6wymu6REqkUKB0lqn0n7PsjOehEPO/if7tItg3hiozPMPF3QbRmEF bd7w0Jz/gLJSdlgrR4OLLIxeNftQPy8n2V97iEpt6cRr15DC9Fgg/7S2byHPyyyoz9EK rwPcLIWXiEmEHhwJGVnr3CfsmsfdFbsYmRiCQqSha9PZxcgt9ExJXBn+5BhL3skU3gI+ 8DIalvt2l7JcKFtHQO6zyXw/tJnx/ZsEJF+uHF/XJTBzkik1pc1XZFzSJRGucb9pj9bi n96w== X-Gm-Message-State: AOJu0Yz8y4JGq2148rfH7UZjbGMcqE9AaH3uZCp5Pl9khkCWxxI5Un7w NrKNE+syRXqU0DiU9lVQ5qiI9V328Kfhfu3Hj4U8qvR0EtJeG1cZZqWsaaJPGDU= X-Google-Smtp-Source: AGHT+IFUvVFVsmXs5THFD7rRdiArCigOzSIlki9YF0ufx8LgzMZ4Ejq8SGm/wF8bxTFCmBrmbeC1Pg== X-Received: by 2002:a81:bd13:0:b0:603:ebf7:947b with SMTP id b19-20020a81bd13000000b00603ebf7947bmr7929045ywi.48.1706862135626; Fri, 02 Feb 2024 00:22:15 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCVI/3UlVCLp8CP32aobTXwyL7LN5jBG4GZnwvU5MSmXBoEFJaNI9nQwAnf3lBwf1G1SAseIQOTZ4ERjUd6CYebLVabW1OoTYZcY0xGR+JiqL/Fty2az3oEWXO5kRyoikzcFlFIwhPBwAnmg46mPtRaSOg9/ixoVpCNIw6+cuvHjHbh2EP8mSQsz+21uWPJqVEsRzJ1DDRcVOStak6I5Oj5QfwIB3H5SvLoW6lWXgdi1k5x/oxmzE2rK6rtQX70xYkmEDyNpKd9lOXCP8BHwjnyNw9NLbh0015BwZj7VgEpJ/HQ62IAZzuU4z4LyPl3CymiUBZKqI2qIa5yoLkdANc6uk9AosnuuqtGSgQ== Received: from kickker.attlocal.net ([2600:1700:6cf8:1240:1486:7aa6:39a6:4840]) by smtp.gmail.com with ESMTPSA id w16-20020a81a210000000b0060022aff36dsm299679ywg.107.2024.02.02.00.22.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 00:22:15 -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 v3 1/5] net/ipv6: set expires in rt6_add_dflt_router(). Date: Fri, 2 Feb 2024 00:21:56 -0800 Message-Id: <20240202082200.227031-2-thinker.li@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240202082200.227031-1-thinker.li@gmail.com> References: <20240202082200.227031-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. Signed-off-by: Kui-Feng Lee Reviewed-by: Hangbin Liu Reviewed-by: David Ahern --- 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 Fri Feb 2 08:21:57 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: 13542397 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 8AA1818643 for ; Fri, 2 Feb 2024 08:22:18 +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=1706862140; cv=none; b=S2Yp10yrCXvtBcoeptLut1d0CRYX82twvVquLy6g5c4ChEdSKlwtKnr3kg8QzZ8dxvw+PzKJcWewA65hZ+Ogc9DQ9dmc3iIime4eWr0j2/KtY8BDlny+og2ev+yqEu+i+HzD6w6HB7CDVV/NZ4oiEpON6AcD1CA+183IfL+2ZGc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706862140; c=relaxed/simple; bh=HpVbHkeOqkF/1RYJWf7zKLBWQVQE639n56ds1nqcRNQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=YRmghGo4m2w5QDIeBRyjFe2pllnzZ4xQIVHnBdqPtMTGBFB3msTXE5UYr/oMOstlT2kDIA5l0DDjRErI+DOysA8GBeTLkOrvhgVF7364hchS74PAQpK8pBXX9nz3OcXEHpRUX0FwzVGX6Bs/jrCqkGPH2LlJJaXCekc335ukk9g= 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=cJJBKi3E; 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="cJJBKi3E" Received: by mail-yw1-f172.google.com with SMTP id 00721157ae682-6040d33380cso19077347b3.1 for ; Fri, 02 Feb 2024 00:22:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706862137; x=1707466937; 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=cmiXWwm1UAq4DNGfUdAw4+QPa0CLlToqX+zE/vJCLA0=; b=cJJBKi3ELIHtV3Gw+mfOYs7tll+0MnRV0ldes56aQhhgqQVVS7IBFndDT9JeMuINLn +K7l8vtlh5BuvGFG189uxX8IqES6Vrjg8GxGK3LA0hSt7TEFSk2UNrYHsJvdE9lHEGc0 vr7yKdrvRFz8g7tb3mJVYoGiVkE0vV9j9EFzKKRGaw+uDqv4XH7vFVH+JsZbp3bGozGm NHGyJOkyGE1yzaby+wbeUWOL/DlSTd76CasRz0zRffoBG1GgMLL5myeae6YMVtfqc9rM q2OtsuCWj3Nv6RyuEwRo+k7o8Pwrqa5Q1a0+XTQo8hN1EzhSRyRZImjM7QuPtDg0HPoW Kbkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706862137; x=1707466937; 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=cmiXWwm1UAq4DNGfUdAw4+QPa0CLlToqX+zE/vJCLA0=; b=dCK+0k1L7+tgj3jcdRZIUVON35u+p3ZDaNzepdf+lIZDj5BZQa7mbeI+uxKcpXAU/l IxEUj0LpqJggPAzh+KKfIV/HjIlWdfWUkhalFI1Ti/uSUns3OEHttQPTdvKVbjZ7brv+ yNr23xeaCd3XV4+cwP41m6ssSgJ7M+dEI313Bhfr7QpMpSJtA4MykqC5Pt4ay071sPaC vaesNkkU//XIaWMA9T5GNnRpvk4VEembws236q0ksEAnz8sPRAHhIQ/eNmhgX3zCXK/4 33P+BY9yub3oV8e1h7b/q0U6fQOrSnobKdLVlGkowAcwASLY5Syl7NJb+kGbGzhiDGsw OJfQ== X-Gm-Message-State: AOJu0YyFyspM3Nhk7w3YyDp9tzO1B75AV4/5NCsdwWcXXxRYO4bsrc8E KnL/q+NMHifZr3jcN5uKUQ4x/4iP3cu5WOEpLfOO98v4GP6/oMKbkZHgpQOx6Nw= X-Google-Smtp-Source: AGHT+IGnmLQd5h3tEgohA4gFtUZOQbPQHhbvRatbJpYDx8nC3k89H7MpHjS03gbrah7bcGuPrv0hwA== X-Received: by 2002:a05:690c:f82:b0:5f6:df70:bdda with SMTP id df2-20020a05690c0f8200b005f6df70bddamr1900130ywb.32.1706862137122; Fri, 02 Feb 2024 00:22:17 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCWl2EMRhDHFMHS6L78h/n6vZ/5UclrlAQTqUUqxaBJgAyEC9l1RfouUsLwDOxJkMpXXOtKVV0zK4DL+VLAyuZsignhH4YVmBFgv9SRl2tLGJ0EPdksUqAcnAsvKzH6A2naZA9Ry22RMBSG+0K7i6glYuqQ2JFEdkk8kHiahoBAXQn+aS6H6hnY4Cj1v6tIsmmvwzjiucB3WsuUzXoLt3023qwYjaS71y+92+g4FFgYDeVF4eQ9sdBWoE52U5xrWapuP5Nn7A5qA3m4gf5Mg5fGYFBspsCQ1j7SdWodnflUnv/oH+XdBWqSNDWQYHJWqun0h7JHSkGKxEhOEZUJkA5+IULhS4a+QL0wuIA== Received: from kickker.attlocal.net ([2600:1700:6cf8:1240:1486:7aa6:39a6:4840]) by smtp.gmail.com with ESMTPSA id w16-20020a81a210000000b0060022aff36dsm299679ywg.107.2024.02.02.00.22.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 00:22:16 -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 v3 2/5] net/ipv6: Remove unnecessary clean. Date: Fri, 2 Feb 2024 00:21:57 -0800 Message-Id: <20240202082200.227031-3-thinker.li@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240202082200.227031-1-thinker.li@gmail.com> References: <20240202082200.227031-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 Signed-off-by: Kui-Feng Lee Reviewed-by: David Ahern --- 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 Fri Feb 2 08:21:58 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: 13542398 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 2F2CE3CF65 for ; Fri, 2 Feb 2024 08:22:19 +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=1706862142; cv=none; b=ic+bfZ89RiP+XDxBPZXWmL4wJ2xJkSlA8iu2nrKGBNCfcl+6CoTXTlVLrDC4Z6zt90Yyoi+7Zlp+aB7sJydMviAelLABz7ce30vHN6vt+4hJuvx6OeH7bRyrvWOykc2ISLVPbgU3U+BhJRY41OO8DR+YkgBeYmqJNAGQogg4Thc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706862142; c=relaxed/simple; bh=ygxl2SkLZMa8WYxl4beisKobKbZkYQgc11K4L+LLd08=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=VVTUqSERXERE0eEgLFEIlmrAh+w4+AJTp2R2cJBBIhdnIW/8aj22SxOZ32nlnNPVGTaeNXGS36xeozD17AmQa6kFKvrcHHN5HLB//W9040PZRtPcQlj4YZ1VgAqqpVO5kx0X/p06RiyEE2KtxlZzVV5GnNpovtLqze055dWTfKg= 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=MRKdyNqU; 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="MRKdyNqU" Received: by mail-yw1-f177.google.com with SMTP id 00721157ae682-5edfcba97e3so19011007b3.2 for ; Fri, 02 Feb 2024 00:22:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706862138; x=1707466938; 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=kTLRtxvpw9ksVGQsz7KBND5IFih2AsprdEHMzMKAu28=; b=MRKdyNqU8UH0ebIpfWCbwhH9HXEOzawySYIw3tZGdJgI3rqFy5kCB9bsPvQhCGbnnx UeGeZzOnu7PWrDyt93RvGSTBo80gXnwOjT/NHfelc/QKewO30QlXum1Puh8rVYAEmheS fKhO4sbQLmeYPgl88uOoX/x5+Mf4VwbgadE2i4agEJY5Is7FZGPOUpwLpgSLB77MA7R3 1/Y35/QjKepis64itej4UpzXc4nhiVQqKIoczRPFzgKmo/0otHvMDoiy4Z1hb6iTHQcz HSsztxg+yhqxkJELUnu5Yw0nu70Qc3oCsQvtEjHCvkE5vM/pPmpCj/kqXOrHXgRBm1KA 87XA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706862138; x=1707466938; 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=kTLRtxvpw9ksVGQsz7KBND5IFih2AsprdEHMzMKAu28=; b=FnvdkVDhhywv9R7Nba9fRNYJa4iO1xQV89S9AZSA2pK38B+aevO5+7mdNkMFQqlrfM K36cozauzsskVaH8xhbg99RBwvPSJ0x5LjnGeNh8RPaJJxk6J+oii0eBPokldNTEeyGC hl3Eex1TcDpanDpIb6AlIlGujbWhJJA0wvPKpd5BzKonVyb8tT8NdyL08cpHCkbSHvMj M4tQedd3r8/gvCJZJ/CGde9a9/Cj1A8/EcuCC2/weTrFcz6EnUhwt0UCtHfkdeOjyZot jC/Jxa8p0CiYIfLFjwtp7Ros7J2VTVu6/WovEirNVUvqja3o9aTgXfBcI7kwHt3pTLty P3Cw== X-Gm-Message-State: AOJu0YytsULiXEBq9w96Yj/ZuegqO8A5NxbaXE7mSOUC0RywELg/8OjL lR/EgLZ+953pSy4rr2uG74ptseRwY3cTD7qCeALSctjnT/XQZfD4W0+EAD7bh7Y= X-Google-Smtp-Source: AGHT+IED4otHb0I4FguL96oNuz+rQ+85VFNuzRUTo/TKsUngq32P08ADNH9GN3fXTHKt/ghyGKDY1w== X-Received: by 2002:a81:ad08:0:b0:602:9161:2e73 with SMTP id l8-20020a81ad08000000b0060291612e73mr1475519ywh.29.1706862138433; Fri, 02 Feb 2024 00:22:18 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCXbketOedaMGRzfSZL6jeMSG6n4BESrNPv4fEwr1cRi9QFcAp51sypD5X/v7bWNXuxUenRY1A+CLm8uYA1hHp8ZbsUVC6llLTwz5rPiBnEJ+SZNCd54z4TviEMbYtKV3qVU4Gzz1AkNupbFErmHPDK7b9M+vQdS7SUhRZsAzaxxfW2Q+yq8C2JY6U81hg/N3onkELZr6quMdSg3/GFZAlUcRsvOHvsphTIEZ36ilGdFYstGqWPr0QO4H6g9sAeE7aufXVnh3FKPbz9CznQmEmsURixYJta/ywSuhE9dhZHdS5XCZHaBVDlV3PyRM+S78MfP87eTgMzb/YCTCPsFWJuAIojhKm4q5ZxUoQ== Received: from kickker.attlocal.net ([2600:1700:6cf8:1240:1486:7aa6:39a6:4840]) by smtp.gmail.com with ESMTPSA id w16-20020a81a210000000b0060022aff36dsm299679ywg.107.2024.02.02.00.22.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 00:22:18 -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 v3 3/5] net/ipv6: Remove expired routes with a separated list of routes. Date: Fri, 2 Feb 2024 00:21:58 -0800 Message-Id: <20240202082200.227031-4-thinker.li@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240202082200.227031-1-thinker.li@gmail.com> References: <20240202082200.227031-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. Signed-off-by: Kui-Feng Lee --- include/net/ip6_fib.h | 35 +++++++++++++++++++++++++- net/ipv6/addrconf.c | 50 +++++++++++++++++++++++++++++++------ net/ipv6/ip6_fib.c | 58 +++++++++++++++++++++++++++++++++++++++---- net/ipv6/ndisc.c | 11 +++++++- net/ipv6/route.c | 14 +++++++++-- 5 files changed, 152 insertions(+), 16 deletions(-) diff --git a/include/net/ip6_fib.h b/include/net/ip6_fib.h index 360b12e61850..fc581aa7802f 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,27 @@ 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 and make sure the + * route is on a table. + */ +static inline void fib6_add_gc_list(struct fib6_info *f6i) +{ + 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 733ace18806c..36bfa987c314 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,18 @@ 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); + /* If fib6_node is null, the f6i is just + * removed from the table. + */ + if (rcu_dereference_protected(f6i->fib6_node, + lockdep_is_held(&table->tb6_lock))) + fib6_add_gc_list(f6i); + spin_unlock_bh(&table->tb6_lock); + } fib6_info_release(f6i); } } @@ -2706,6 +2717,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 +2794,23 @@ 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); + /* If fib6_node is null, the f6i is + * just removed from the table. + */ + if (rcu_dereference_protected(rt->fib6_node, + lockdep_is_held(&table->tb6_lock))) + 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 +4765,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 +4786,21 @@ 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); + /* If fib6_node is null, the f6i is just removed + * from the table. + */ + if (rcu_dereference_protected(f6i->fib6_node, + lockdep_is_held(&table->tb6_lock))) + 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..d53dc519d317 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,40 @@ 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 +2368,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 +2428,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 +2441,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..5ca9fd4f7945 100644 --- a/net/ipv6/ndisc.c +++ b/net/ipv6/ndisc.c @@ -1410,8 +1410,17 @@ 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) { + spin_lock_bh(&rt->fib6_table->tb6_lock); fib6_set_expires(rt, jiffies + (HZ * lifetime)); + /* If fib6_node is null, the f6i is just removed from the + * table. + */ + if (rcu_dereference_protected(rt->fib6_node, + lockdep_is_held(&rt->fib6_table->tb6_lock))) + fib6_add_gc_list(rt); + spin_unlock_bh(&rt->fib6_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..cfaf226ecf98 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -989,10 +989,20 @@ 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)) + spin_lock_bh(&rt->fib6_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); + /* If fib6_node is null, the f6i is just removed + * from the table. + */ + if (rcu_dereference_protected(rt->fib6_node, + lockdep_is_held(&rt->fib6_table->tb6_lock))) + fib6_add_gc_list(rt); + } + spin_unlock_bh(&rt->fib6_table->tb6_lock); fib6_info_release(rt); } From patchwork Fri Feb 2 08:21:59 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: 13542399 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f174.google.com (mail-yw1-f174.google.com [209.85.128.174]) (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 915581865B for ; Fri, 2 Feb 2024 08:22:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706862143; cv=none; b=vENWieTnf2Wp5wysiE+2e5TOu4DSUQY+PnLvU9q7NVTOp8RnhzKv3X7nbZJLr3MdfzeBx1wMX1nREgaPJnDBD/eFlrVmVArUMDzlJ2tpboS3HJ9e8vjBzuCee9b5W4yrUvyqlRmMIH6Egzi9/znMUnChEN+p9RbjOeZBLwq+2JQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706862143; c=relaxed/simple; bh=HRqkCqxtBKrUms3XCHQMXqP+vqbRKLRoHOHl89isBsQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=V5qK+4OxE6cHF2gnIZuEkrSFnkGOcr+AIhzHsY0qP3TNuF+lixA2Z2qgIyk/lFdKOw3jU37LXUlgY5fG8z4Bu8xah1iDdJtdwir+TAo4aLsa4KUXwlm44d4Q+/VhMpcPu/1Twh2VfxbkcGlVnjLh/2txDAhc5d+UkJ/b4yTmTng= 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=K7Heaf13; arc=none smtp.client-ip=209.85.128.174 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="K7Heaf13" Received: by mail-yw1-f174.google.com with SMTP id 00721157ae682-60412a23225so18359457b3.2 for ; Fri, 02 Feb 2024 00:22:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706862140; x=1707466940; 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=5h17ojUPSOJID+Qge95Q9ZnvyDNG+2fV6vU1bRnAO9Q=; b=K7Heaf13HAOIYJaTRrdwOPHQZ4hxsNXtie8fLRDwlCSXEX3SbVwzdlnR4IotwAwKN4 K6g2UthG0nNuaMiEaWctLH9O2ZhYLZPP1pv9xvPxJjZoigx+NVM8F/92rX6qOnYNH64/ 4/CAK+bEQAFySeMD5XEdOi7/212rRbGQ83/W2KniA6fKR/nX1gxyiu6J9u2d0+EeHDRD +hsku+H5EisBLcFRcOxu/Q+MxtmoSY4CYqdGOVRdRIvg2BIwrm7H/OT3MDUjnxT9V7gY qCqL+xy65Dhmup5opxuePjPAeP+5hh44PFKAsVpWYcLa8XIAt8KKv0WBdURd4pe0QWWm loJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706862140; x=1707466940; 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=5h17ojUPSOJID+Qge95Q9ZnvyDNG+2fV6vU1bRnAO9Q=; b=ir7942vewogHwruG32BgmteMDOQ/UE16LMtu05qNJ7gQzq/BkwM/NH/3RhIZIp0IB+ ul6vsoTFwPCaMJBqNCBsRPWGscSimOtKf5/ughKwhJgI6jtv3ypSQLiLdfLn6viqG3kx Khg/tVddnJbJHE1j5CVN75Wib5PYwt6zheVaSQyOjCMjaJAuUvxxo6iTPDjYTGu/aP9A cQAahqiNGuCCjZnbYPjUV6ZUPF7skC6ZvZ87M0s9DPtC5ypwbYNpW6fpMtj97zmCOsNl 2xevF8iyM6URtViUZcVudYsip799X5cW1ZlzpxIawOmiDht7eWfWhAilJM+THjLF7TDs Gv6Q== X-Gm-Message-State: AOJu0Yzo/ASOu1vomPWpIvT1gS9YY2LbHZrcaaCSARbddcLcFiFYGRON 83FESIutcadZEE6D8doNfjsCSpr5WqNa1M9ieIjK/Y9QLVlJTYHCqnoPByQVk0k= X-Google-Smtp-Source: AGHT+IE/OUPSCu510+rCF9uVuCFaNKDK1p3sSv1KIRLMucmaXcVXIArFbU2oKeg1q83jX3o4eQIxVQ== X-Received: by 2002:a81:ac21:0:b0:5ff:5fda:fdae with SMTP id k33-20020a81ac21000000b005ff5fdafdaemr1583313ywh.42.1706862140002; Fri, 02 Feb 2024 00:22:20 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCUqUozuLKbetg5pwcTiFbQlkMxeIgcJtR3aMkq2S108iHhOK2mPliCNVUSjKjAUsu5JWcOudlknuarwLR2Y9MNIOaFMrHSZhiPxHnJaFq0zlnAj6FraoMYuJ0tn3LQwl11+Mgz/QcX4f9/TmAOAtW+RQGTrlMAJB7RP3NswnDcxpCVVFmLvbJ/xLCUS8wmLwMJXMXLCZroVYPt/pCwDHkArXnVXsyt4ERRLnWZrgwqtU5JQDO1AdYI64CeuWVDG2d3myzFa3S3atoF9H4za20cjv8xHglm/WPeC0BPGjR/rsdGi2IWE6I95t3MsZ1e6TYnfe9MBjuDC5Lss884wNvvELVlZF1eC6jrJ+A== Received: from kickker.attlocal.net ([2600:1700:6cf8:1240:1486:7aa6:39a6:4840]) by smtp.gmail.com with ESMTPSA id w16-20020a81a210000000b0060022aff36dsm299679ywg.107.2024.02.02.00.22.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 00:22:19 -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 v3 4/5] net/ipv6: set expires in modify_prefix_route() if RTF_EXPIRES is set. Date: Fri, 2 Feb 2024 00:21:59 -0800 Message-Id: <20240202082200.227031-5-thinker.li@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240202082200.227031-1-thinker.li@gmail.com> References: <20240202082200.227031-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. 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. Signed-off-by: Kui-Feng Lee Reviewed-by: Hangbin Liu --- 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 36bfa987c314..2f6cf6314646 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -4788,7 +4788,7 @@ static int modify_prefix_route(struct inet6_ifaddr *ifp, } else { 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 Fri Feb 2 08:22:00 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: 13542400 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 C0D1E18C28 for ; Fri, 2 Feb 2024 08:22:22 +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=1706862144; cv=none; b=jG93Pwnuu1QeVfgpTjp/UJnpo4BGMiGZ5LwyJtE/LT0NDVudb2TeeSn97dp7CSUvmk3peSQHS5KgLDLjVh6/KZIdW3BiHZGSBjTMgV4Q3aLaYaUJackcq551CpX5kz4widDv5lfCEbnmYZQLSHjGEBYWqVEHIX1iHbb18frUhks= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706862144; c=relaxed/simple; bh=hy9/837D+U/NR3by+SuuECFfeZE+jvlKmxEG6tSiODc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=UQypvr8wEMv9zfRdebW2dB2pnsY9LocjvDqfGyeh3t25/eBbn8OA2M94N8r7zfeZUbhB8LtVUg/sveKVnJqHMtjFW2QzU/w65Unz48fahoUJhDUvJ+mPw2ivEtGfYpOrQ3PEeH7nF+Dkv8QJ9zbYBrnVri3GM0NjaHHwsWG3FvI= 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=YJiB/8/C; 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="YJiB/8/C" Received: by mail-yw1-f179.google.com with SMTP id 00721157ae682-60410da20a2so18387947b3.1 for ; Fri, 02 Feb 2024 00:22:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706862141; x=1707466941; 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=q2wswQuZVEFnxNi/Z83JJqKEZkSlXTqxdCZ2walan4Y=; b=YJiB/8/Cw3O73qNwL8Md1tiJOQrEWQ6RCuAVCBFlqOnq0ZG3JXaQGJte2WOc7kiQJn msXO3FdxDw+Whr58wNZTzNw/wNImYBwmgUMTf7raooqKqcGBVU2X7dkFKiVEgPZNBUwP 3gO4yOjKIw2RrA7oz0ILq1bCOeOMsglGQmzNfFJfa/o9HbVbbOa7eh+hlFGiJ35867Qi 8I4zA0n7x29KWMulfJ0BAzVkz7/eAIxPKEng42RljV6WNqjCBsI9plbBRTw5dDllR33x jCyOwQMJkkT/Koayra8KnE61Xmkif3F1wSxQkpyp/j6hxhNLGoee71H+b2tIjvGTSTyO 7DtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706862141; x=1707466941; 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=q2wswQuZVEFnxNi/Z83JJqKEZkSlXTqxdCZ2walan4Y=; b=FRdNijfneSD4VOdi7lEfPsjaMu55i80z3aL4iiIsrCJa2N5SxLjq0+cdypxnuPhow/ rb93HE/kACdqtchaRh+yYBvi2rMtlWBp8ajzn/k5FfzFBn3wqyQiNjxMmnkwBxYbrkLZ Jj8dSUGtwATz3/I5lBjD/YFz+34OiG+ytYXP+HH7p4ZRVrYFdJZSkaIWktgV3eKcxA/I VmDdBbUAumDHV2nsaJcQoCTNQ5RRPh55X6zZn+75VtfwR5AYXfWdNZmzg61aI+gknxX+ IXgnAjE3y3rUwONXqPDFIMaqCMSLm6Ve+9p5Nx3aE0TlN1d/8ZQvUzbSkKmm7rD+wuP5 SxRA== X-Gm-Message-State: AOJu0Yxjqn8lcn4INL1YUSh677FFhHOYBlGtac/mS5cWSLfhzJTiMVMZ OnlXmPmiaAIqsrXuFyDH0mNX86O3q98o5a/23bZQOad0gX/v5nzZK/BgNV2anqA= X-Google-Smtp-Source: AGHT+IGp7SxnscYllJaGgNYF1EEODcnC1C7MktIcMxahB3SxkOs4aZZjJpiyxtO5vF3V+3lO8PfapQ== X-Received: by 2002:a81:ac20:0:b0:5ff:7a74:412e with SMTP id k32-20020a81ac20000000b005ff7a74412emr8035091ywh.38.1706862141349; Fri, 02 Feb 2024 00:22:21 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCUcmj8VYLqHnI4VhRTNYTqK/XQJMlYrFEJ/cmAMcJrfL/3B7kCnkEQ0tN6zG760WtmeWQrxIMCde3O+ivTFwvNlmQlb2u0QzMCSB9WtPNBRgIKQJUXUYp6TAXTwML4SRJ53DH2LCZVJ7Jrnbs9w4/mpX8gLzhY8VHZr3druk/AV0zZDeQwg3xXxuG+OSQggXZCdIppRjQGsq2Pv100GQ0CLVhKB+OCmir4n7R5PothvaT0Dr6ohda8iPvBAeshJ16+SchSftefHCBEbdDFHNWHeLnsi25DOHgH6rT5tMvo6H8/yI8IADsnv81nIFaGgrKbHqooY8BAylzCagfbElhNS5CnrqiofC5Ty/w== Received: from kickker.attlocal.net ([2600:1700:6cf8:1240:1486:7aa6:39a6:4840]) by smtp.gmail.com with ESMTPSA id w16-20020a81a210000000b0060022aff36dsm299679ywg.107.2024.02.02.00.22.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 00:22:21 -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 v3 5/5] selftests/net: Adding test cases of replacing routes and route advertisements. Date: Fri, 2 Feb 2024 00:22:00 -0800 Message-Id: <20240202082200.227031-6-thinker.li@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240202082200.227031-1-thinker.li@gmail.com> References: <20240202082200.227031-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. Signed-off-by: Kui-Feng Lee Reviewed-by: Hangbin Liu Tested-by: Hangbin Liu --- 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 }