From patchwork Thu Feb 1 08:20:20 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: 13540782 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f173.google.com (mail-yw1-f173.google.com [209.85.128.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CC47D158D85 for ; Thu, 1 Feb 2024 08:20:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706775631; cv=none; b=ej2qFdiDGpZ0+sdIBzgOy8erCBrVa0CfqMYSnsLPUHFlAKKB/OG24iSjpGINusp0FZWGFBJa4aDjqYXP4+yTg9Ltx/yxX1O+HugivfG4vtZcmv5646+ocCOUFFZ/Pr7Q8o4UBvHpVRBMkudRh7+G/GAussCc8AN0580zw2s4Wsw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706775631; c=relaxed/simple; bh=9Q7dIWO/up+Z+zGT7zjSYYeM+tBMW5qlYmi941jKS2A=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Se3myD2TXei3DIDUnon6A2Sc/H8ID84xga1WgLO4nlcgNQLh6aJFJoRCmr53wbO6WIwIKJ1+ZHYezAQCQ0QFOhrmZ02FEl36P4CoCWIxMQy20wU02mFOo8hkXi6aMMD9MrXdcLC3fYn1YV5MllA1xeHUdE7HGYQw6hZesEj+Bno= 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=MZQI0aam; arc=none smtp.client-ip=209.85.128.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MZQI0aam" Received: by mail-yw1-f173.google.com with SMTP id 00721157ae682-60410da20a2so6221027b3.1 for ; Thu, 01 Feb 2024 00:20:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706775628; x=1707380428; 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=MZQI0aam6EbKWUw87fdn8a6gkgF8fueQzlmhK8zDPBLwBT7DHnJUT0s3O+94rzIQsN DCyfLRnw2BezgEWMsad7kYzK7Vjz8GZF33z/8pWR7iEGQEGdFwHaa1uAn7d8R5K7oCZs vECRu/Azw32PUYVusd4W0bnTk44ViXNWZgxV/X+J25YB449n5fDgEDjLoRlfCML8UG6t X520LQL44K0btDHxvDSfTe4Ai0xIWZ3S3ckcUG/6dVsrdOTDx9ix17tDDgyT3hU1FWex gXzug1yOJ5yUztvmOGpyFqpeMyzukO3WeXLsWPZpbxa3plXHS9lgm7xFN6Knyze5dS5T 2pHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706775628; x=1707380428; 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=pyXkAx0+rAXPxA0dWWFGxfdFXjDmRi7M6LXrqWT3QiLYSzrGTVzSrylXwCo4yc/NuN VCj1Oyabj5NNyConhb+2HGzKjw/4aG9wDDqVQZYQqmbarLKRDZBTzm/fsVJvhm32XE9a g0bNbqwrXu8kk+Sd1wctpUkUW2EAPfjAjiUd9g6/W+3wgk8FsPpOG2ANYqTP1fQyvfGE 8y6JpLyor3Fiz3TO2gEjDNQLjmSIOCX3f5wHhmfL3T01NavwGzsIFuRIlk/ysew7bOrO oU+LNV9xUfrRrZPKy+LKd/KiwoHk/EamsHwRBK+2xql/xyxg5+C6tSYPUKNj8fQBTkDu 4fng== X-Gm-Message-State: AOJu0YwHGwk4dvvi4RHJ2ZBwEAIzaOV0mxqj/B0HOOLw8nwiXqh6fabu pfo6ZSPzABEQWohMijI57PpRG/XyD+N2mtZAOOuRu1fP37Yzl61t8AMOQpUlAA0= X-Google-Smtp-Source: AGHT+IEcq/RocWCNxeO3/03eb8q9EqrBfVN7sOJgDgX31OQ13oK3BM95OMWrtTkiKdjY+eZr5I4K4A== X-Received: by 2002:a0d:ea4a:0:b0:5f0:4e4e:1b11 with SMTP id t71-20020a0dea4a000000b005f04e4e1b11mr3735523ywe.29.1706775628532; Thu, 01 Feb 2024 00:20:28 -0800 (PST) Received: from kickker.attlocal.net ([2600:1700:6cf8:1240:b616:d09e:9171:5ef4]) by smtp.gmail.com with ESMTPSA id w186-20020a0dd4c3000000b006041ca620f4sm209090ywd.81.2024.02.01.00.20.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 00:20:28 -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 v2 1/5] net/ipv6: set expires in rt6_add_dflt_router(). Date: Thu, 1 Feb 2024 00:20:20 -0800 Message-Id: <20240201082024.1018011-2-thinker.li@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240201082024.1018011-1-thinker.li@gmail.com> References: <20240201082024.1018011-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 --- 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 Thu Feb 1 08:20:21 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: 13540783 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f170.google.com (mail-yw1-f170.google.com [209.85.128.170]) (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 29CCD159571 for ; Thu, 1 Feb 2024 08:20:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706775632; cv=none; b=BeqKOdLFRWBuEIXhGKYca6arZgxbPAb6euMZc4pEZdzeU9h2P6hlylaBhEnBuJxnuvvsDpvnkD/1Vfn/Wgc4u3CXT5v6Nt0i1MvXypOUWKz5aPIyNsWqTJ+lhx1p9ODDJ7Mr5IUTZMDiVkFOa5XJdY71PWaOE/kyImjwpcwhbms= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706775632; c=relaxed/simple; bh=HpVbHkeOqkF/1RYJWf7zKLBWQVQE639n56ds1nqcRNQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=gpE3yHkoqA7vO/mdo9z5x3RXrmYKBVmN8h/IMm6dLCSMkqWVGhr1zCZ/DgM+9wU67Yl8n1bolmgPC9UBzqwZw41BOr6V0GRsmgL/yWwh+7WIEsRWrLIrnEbat7YolPeWKc3M24fF3I3rAW1NfHPdFNcZ8JO9c5XNNx8S12x+d4Y= 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=EDu50QIB; arc=none smtp.client-ip=209.85.128.170 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="EDu50QIB" Received: by mail-yw1-f170.google.com with SMTP id 00721157ae682-6041ddaa729so2980137b3.3 for ; Thu, 01 Feb 2024 00:20:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706775630; x=1707380430; 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=EDu50QIBIGS7qTv3yth91S21N0sPfLCcXvyMOJRC63H0yPljFSqwx2G0My9es9ZZYS l1eJn92it5gzBnqqbwcXgETWHSQnj55+9AiJe8KnY1wFxCV48swowj8Ruh3sQkROpeh1 rFc4VRT/uKL0bSmpVQU4SctFSFzJR3ysG0iYTdnDH6TSvQ0zjwbhq/EawJPidUdu1zFG ExYTr3pMSddXM6XRvzpKBsqz9oWbQJ51xHa+ejsl0kj2C7pd/Oeg+lBJ//29/3zIUkiL j0is6OKgYQsZM3JE+kLrEnY4noSWVYzxi7wqRBBU6l1d8UEQ3cRfjUaSkaw7st1PtfYF jvWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706775630; x=1707380430; 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=aqPQHkdvs/6LgpgGyDsJye0jNbQ+KWVw6i1He26ZCtLEMvrYIW8GlrPYzmCGtHw67T 3/SBx0y5Qqx6Npjew6iuoW4cnDmZOSRx2FQulIXrpQRQCvQ+WBm27Zlr83emJ9z/tAyq cjKQB525BfHp69cGc1Tzlm4UBmhXoAlTZ4+3WG1x+Ucvtq8DUtix+AAaclCBxUj4jPMd fxl2Z39UlT/gNYlTY1UK4CerR8dioK9lbCIEt9OSeIupX1Ec0/ZbmZd+ZVKFZa37j4M3 gUoHRSXOdCXok2eeCtHkObgzvFxD5+0rJ0GFVFeFrX+tyZPUAIbqAsjUUN2BKp1mJUbB N60Q== X-Gm-Message-State: AOJu0YztgUYKypo2ZpfBXN6dffGTg/yFXF5/igRC8y7u+3RBkssolCaW MZfgXlGh88j5Z9mreBDhkSB2vk0/pBEOCbeK7+0csO/hSi+EMaiHBjRlHZOnQpk= X-Google-Smtp-Source: AGHT+IEv4ezhZn7fQc6akmyy1ZyIac6nMT3H2WBZdoAKSRIj3lAH8hKA8UsS52HfYxXkpvRUe67mug== X-Received: by 2002:a81:77d6:0:b0:5ff:604e:2bf with SMTP id s205-20020a8177d6000000b005ff604e02bfmr4064811ywc.18.1706775629851; Thu, 01 Feb 2024 00:20:29 -0800 (PST) Received: from kickker.attlocal.net ([2600:1700:6cf8:1240:b616:d09e:9171:5ef4]) by smtp.gmail.com with ESMTPSA id w186-20020a0dd4c3000000b006041ca620f4sm209090ywd.81.2024.02.01.00.20.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 00:20:29 -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 v2 2/5] net/ipv6: Remove unnecessary clean. Date: Thu, 1 Feb 2024 00:20:21 -0800 Message-Id: <20240201082024.1018011-3-thinker.li@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240201082024.1018011-1-thinker.li@gmail.com> References: <20240201082024.1018011-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 --- 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 Thu Feb 1 08:20:22 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: 13540784 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 9769515959D for ; Thu, 1 Feb 2024 08:20:32 +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=1706775634; cv=none; b=KH768Wkje5IRGlexaGDUunQXI7WrgVSpQHuksap7T7ja55EcPPAAnd55uQhD4sxkJpCsPscWpgcnZBEW5JH3Eg42R0phJ/TPmAXALFLyim2QQQAbq7k9ODgcuX4vVhCVpFCgZzXP86prpDduRRh6QDP+6JuZBlo8BpFcZN428fU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706775634; c=relaxed/simple; bh=kh1xPEd8CvmvQvaCxYMmlihBYNDgzZREcao8Rc00jbM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=lRVMQIHYC5EjNDSHc18FphO7J3U9x/PDtCTHX4H584BpZR8ljUuCPUubXaWRT+F94cbJZwW9Xvhmxei/y4rTw4ddLhOZG2NKqgHCeevEq5aRjkLKVE1/bAZ+EiAZ99ZVG0qlyikW9sCY6lu4824oKLiWwtXamTC6M9MOSIyzAYg= 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=QHqzIpau; 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="QHqzIpau" Received: by mail-yw1-f175.google.com with SMTP id 00721157ae682-6041779e75eso7047357b3.3 for ; Thu, 01 Feb 2024 00:20:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706775631; x=1707380431; 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=GbPDls4iDH4Ud3kYcL5x4QMk/IFv/TA2L+2ZnRv8I3Y=; b=QHqzIpautqTtJwtK2z7YY0AryqGx61g9LAMKneb9GS6+EmSJlxY+tvWFcYyN+MF2xG ZuQzVOG6qd02BR9zQ6nA+YIn6tN6n4FvfeX5RZqblA+iznteG4N7t0IPd1k8FS2I0+dA xhQpgoD70Gr0y2n76hS7Zbz4AThwUDR5+InIwTJ+tqXxo7dcAgOlgGcjBbbQyZikyW1s wU41R6mCxLV18plHc/TmBJxhoHAzBV3F0SCo56wGm8KmyQDq8MuoDs4Bd4O5xfjFLYM+ TY22mNUmDnOHLY9YUEFvZXUZz83A0H55Wbi0zaMkBO0jF3g4U8dQzb3arzQBEJHbFj6j 5Vjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706775631; x=1707380431; 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=GbPDls4iDH4Ud3kYcL5x4QMk/IFv/TA2L+2ZnRv8I3Y=; b=jzWYM6bHajXWEOPRvYzqG6flQmzg1r23Fwd9arqRJClTTDLGzAh9ve68DAe0GJs2x4 +5Gd4kp4/sczsQ0PFeYw/gFc3/rfem274FJ/FX8RrzB10mQ2ii5cCLAPzQqfmDDbMOes TjRMzkxptA3Qr+BsfCXl/KxKxwC4yMjVkdlgu9CuuYZJo14lccutB66PcWv+WF4DG65E hxt8QhOB296Uv93TdPdY4gXPIXNJKr6tzC1+k+m19jNcxVUxlAbldzq5mEWpX943vel0 yGK2fgs+CXdPn9mSZzhjiJ4/bEvdVERs6YvccrdlFzD1FcmB6psRAv6mRoHo01CndH7C Uxuw== X-Gm-Message-State: AOJu0YySfX+8JPJsMbtB3nWaCStqvnW9ehlFUZxrrls90XOmtcu48HhN KXYKFzKC98SYKHKp335vRzKdq+FNdNiWPGp/i4pNsJ+IVVlKUUW/GyeWvUDPRJQ= X-Google-Smtp-Source: AGHT+IEDxzmUizXM+l+OujHc7TD8nMd0Jv0QivIpYbeJ+GdiezNJD/pNvyrRxuDzrYAH7rPkWU/uTQ== X-Received: by 2002:a81:924c:0:b0:5ff:92f1:8e24 with SMTP id j73-20020a81924c000000b005ff92f18e24mr4289533ywg.48.1706775631132; Thu, 01 Feb 2024 00:20:31 -0800 (PST) Received: from kickker.attlocal.net ([2600:1700:6cf8:1240:b616:d09e:9171:5ef4]) by smtp.gmail.com with ESMTPSA id w186-20020a0dd4c3000000b006041ca620f4sm209090ywd.81.2024.02.01.00.20.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 00:20:30 -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 v2 3/5] net/ipv6: Remove expired routes with a separated list of routes. Date: Thu, 1 Feb 2024 00:20:22 -0800 Message-Id: <20240201082024.1018011-4-thinker.li@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240201082024.1018011-1-thinker.li@gmail.com> References: <20240201082024.1018011-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 | 36 ++++++++++++++++++++++++++- net/ipv6/addrconf.c | 50 +++++++++++++++++++++++++++++++------ net/ipv6/ip6_fib.c | 58 +++++++++++++++++++++++++++++++++++++++---- net/ipv6/ndisc.c | 11 +++++++- net/ipv6/route.c | 14 +++++++++-- 5 files changed, 153 insertions(+), 16 deletions(-) diff --git a/include/net/ip6_fib.h b/include/net/ip6_fib.h index 360b12e61850..9cb616a4db9b 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,28 @@ 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 Thu Feb 1 08:20:23 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: 13540785 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f173.google.com (mail-yw1-f173.google.com [209.85.128.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BD3D915A48D for ; Thu, 1 Feb 2024 08:20:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706775635; cv=none; b=YEai3kVrMPx0WFHq66SwiQES3bHb8JNUsyYAcIv1cnDnadHADIgOiliNFp53PMkaa3fxzr61reK1rFc5LVB3XJyHc2k7k6d0cQ0zKHth7bR6xTXcp7kJGD6fm+auJgYrvR2Q8zetXMMaWha/e21dE0BsAt8voUpTRZj3iBf6bAs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706775635; c=relaxed/simple; bh=HRqkCqxtBKrUms3XCHQMXqP+vqbRKLRoHOHl89isBsQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=gMR59Y1fVPmgJCfTpri+Q+v4jOpqjg4F54Kdy77qfOXrryq87sAsZfSRwR8YxI863Jq5LfF9nzDoZWY/LK6ma0ItrF6KyLpwLOEzuFQ9y/C9vwyIJNy/Ybw7N1L3LDwpP9w42CoRJp0CXLn7G04EH1Q0OVxLFgRKviocJvD75Do= 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=dPEUrYcP; arc=none smtp.client-ip=209.85.128.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dPEUrYcP" Received: by mail-yw1-f173.google.com with SMTP id 00721157ae682-60406dba03cso7739997b3.0 for ; Thu, 01 Feb 2024 00:20:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706775632; x=1707380432; 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=dPEUrYcPgr2EFc4qMT//Z4iW7dG+286m6mSVztwnmF7J19M77gVLchAp/FiCqC62gY ipnkgrBFOrUV4qNwEVn2LM4cw0qmtoc/U3RqVJgi0pP0dydUNoOl2aJNFwkTqDl6raRj Uqkd2pBO/wITXhD75dOh2ZqtdjLoe8x4iYn45l2Oh3TtW7CAx7AmA9+2iKBuBBEd6Ou5 7Qjb2nVp9vKccacAMFtY1ySpCIAKnFYcQeOGZvnu5LaBRoUlTLDv/ro3BCI97X9wQsEV 4eJVH2ro21zkbzf8VXEtS1jqqsWrdavfrF5tHF84fEqKUuG7No3bxQgtweYA63P8Sk3e O+lA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706775632; x=1707380432; 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=qGPdZsduxld5SAzZ5raMm9Bq750yu17fpBK67lVm4fmV90nfjwLzFwRxbW12tW/jrc CHWFZ9X3meEadmQJZtcIdYpAGMBZCDztcG5wt1RTfpC0v+Ji+zXw95P9LXMyJA3GK5L1 MDsY+Df3N1T9WoH7x/aaMrUlrLwRpZnd1sU6WWKROShwtSaixrZcxCqWILXwo9VkGnYx ExVz4Gdz6dnjERrX4lANDJQY8aW4MH+QhBUt+TF33WQPgCY0ukdDLDGJynph5bz3UrKC eDNKfqVfdRGNErq3mXHScP+ZAMrCiRpHsfeK0BFRiapA/95H8prKKXq+CNmrOKUrR5pf 7Mvw== X-Gm-Message-State: AOJu0Yzrr/JIuIcOkJExpdta9xdhnO2Es0yx6aGP4td0hHgFKBxMDeOy xS1AQy7mIuCkuSLgI6a4e4BT90KGD8itRJ8rpFyBLwymJgJ5IMcCkbJo6fXarCs= X-Google-Smtp-Source: AGHT+IE9YnN4udsJRE7wQHvp0I+sdxDGGtiE1jhrK23rnqqeXfrSediHN3iuE87RTA1ACCaZnQ+Mrw== X-Received: by 2002:a0d:d903:0:b0:604:a75:4274 with SMTP id b3-20020a0dd903000000b006040a754274mr1410440ywe.51.1706775632489; Thu, 01 Feb 2024 00:20:32 -0800 (PST) Received: from kickker.attlocal.net ([2600:1700:6cf8:1240:b616:d09e:9171:5ef4]) by smtp.gmail.com with ESMTPSA id w186-20020a0dd4c3000000b006041ca620f4sm209090ywd.81.2024.02.01.00.20.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 00:20:32 -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 v2 4/5] net/ipv6: set expires in modify_prefix_route() if RTF_EXPIRES is set. Date: Thu, 1 Feb 2024 00:20:23 -0800 Message-Id: <20240201082024.1018011-5-thinker.li@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240201082024.1018011-1-thinker.li@gmail.com> References: <20240201082024.1018011-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 --- 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 Thu Feb 1 08:20:24 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: 13540786 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 7729A15A4A0 for ; Thu, 1 Feb 2024 08:20:35 +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=1706775637; cv=none; b=u1TH5iIw3GKYzDqAogjHy6Zc9+f9FHtNIhWxWrGMi4CD10e2PS8OtmJB+EcA5cDu4kjpgUJBSSo10BDTmhovTTeAAg8JSMarcggAZf4lZsM/JBAL18rJoi8Wz4rJl66shpIoGN8gl3Fj00prwsq95JGGbze0JJiQ//qAGHszkY0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706775637; c=relaxed/simple; bh=eISr1nSYpLUgO7TGB1jTeA78zrVUXIYlnFhUksdAN78=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Gm+/UpcJKyZTViI1iDgtTzIb85Q/317Y8zWeN6N1bti79Mnm/wNRpiABWEfrzXV7QAtJcGbIZnBZvuDAponYYvu2IjABS9eMk/lg47l418cE2gqrxf42rSrCnruZq5NDOG3bJ4DTuDzp2tg4k4Wep8V1CJiTTBJwFn+GITvEcww= 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=gy90SB+e; 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="gy90SB+e" Received: by mail-yw1-f172.google.com with SMTP id 00721157ae682-60406da718aso7006487b3.1 for ; Thu, 01 Feb 2024 00:20:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706775634; x=1707380434; 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=PtwHtCS36bNnk1CUbV/iOwOunx5AKCLAnCCDe8pyxjA=; b=gy90SB+eImH3ok/FWqzZXtwAZCdEhgE/D1l229XgZXEcrtXHENSm8Wiz9Xy6v7agqU GAEOrmQvPwC/Tmv9giRjbz+aLaUh1HC1vyAe4Bro4jltf7hnrkCBEpKWfN38u336y0tT 0Ajssggeqm3iUYnnrTkLeiklbDbQu+sSqy7JVJEiEH6+K1Egf7ZSbH+uxLPTSEz6O1gm kTgZEj9jGwvxn0ANSGc2fEklUC0puUWR348SJEBjQSI+PBE9BDSjt2h2rXP99Hzz+Q9n T0H3RQt4AYqmKcdwYUu4NfEJ1fpkayUMvfLQ75y4j2ITltaTUM8gT8yZPlHkLrRnmOrw 2P2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706775634; x=1707380434; 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=PtwHtCS36bNnk1CUbV/iOwOunx5AKCLAnCCDe8pyxjA=; b=qe+3C8vmGXfvzzA4rA8mE2vZSTMjTgrMpiE+0jm97Ug/CY4XmGSizHh+iwq7Hj7AKM FchiUw7EK5sNAaXv2sRdZjU8ivTKOtwq9nHkrm8XQ3q8XIUD7BAY8LJCkaaXmuCJT7nZ Fxf8cFKqRuuzo/XAK5yko72/aEQgL9HKrMvJ3k1RjgcnXNkp7gnAhR/N31oOjB2qTJhn k0O0W1iy3T2m/ndrtF6OGgDLL+CSBNM66DxPVkrB5xVe5gYtAjhbgZUxH4Ss3YgOmbVZ 1C0Tbo98NOTjgVEAbuFfqORwBeyXmL8/NGadF/8iaADrV93ks9nT8qQdv6WmGs08LK6v fU/A== X-Gm-Message-State: AOJu0YyVA7MW1xtqXgfG7VzJzlFhw/UXAIU7vsJl5P9GXuDJG2VXtYWj LNrZJZryNjuIjutwyTk04zV4MV7OKko3eP9Y9xQo67iUOryrpCbbQbCd9Y5qoBM= X-Google-Smtp-Source: AGHT+IFAuoF8mfrhzhQ/gACBtsOQR1n0C0e6JUhS9+Byck0VQQo+B5VojS7ZCzN+hFLOJ9nHdXG5eg== X-Received: by 2002:a0d:ea52:0:b0:5e2:2bfc:c6dd with SMTP id t79-20020a0dea52000000b005e22bfcc6ddmr3933164ywe.23.1706775633967; Thu, 01 Feb 2024 00:20:33 -0800 (PST) Received: from kickker.attlocal.net ([2600:1700:6cf8:1240:b616:d09e:9171:5ef4]) by smtp.gmail.com with ESMTPSA id w186-20020a0dd4c3000000b006041ca620f4sm209090ywd.81.2024.02.01.00.20.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 00:20:33 -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 v2 5/5] selftests/net: Adding test cases of replacing routes and route advertisements. Date: Thu, 1 Feb 2024 00:20:24 -0800 Message-Id: <20240201082024.1018011-6-thinker.li@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240201082024.1018011-1-thinker.li@gmail.com> References: <20240201082024.1018011-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 --- tools/testing/selftests/net/fib_tests.sh | 161 ++++++++++++++++++++--- 1 file changed, 146 insertions(+), 15 deletions(-) diff --git a/tools/testing/selftests/net/fib_tests.sh b/tools/testing/selftests/net/fib_tests.sh index b3ecccbbfcd2..38e786aad678 100755 --- a/tools/testing/selftests/net/fib_tests.sh +++ b/tools/testing/selftests/net/fib_tests.sh @@ -743,6 +743,16 @@ 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 +} + fib6_gc_test() { setup @@ -751,7 +761,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 +773,165 @@ 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" + sleep $(($EXPIRE * 2 + 1)) + N_EXP=$($IP -6 route list |grep expires|wc -l) + if [ $N_EXP -ne 0 ]; then + echo "FAIL: expected 0 routes with expires, got $N_EXP" ret=1 else ret=0 fi + 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)" + sleep $(($EXPIRE * 2 + 1)) + N_EXP=$($IP -6 route list |grep expires|wc -l) + if [ $N_EXP -ne 0 ]; then + echo "FAIL: expected 0 routes with expires, got $N_EXP" ret=1 else ret=0 fi - set +e + log_test $ret 0 "ipv6 route garbage collection (with permanent routes)" - log_test $ret 0 "ipv6 route garbage collection" + 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 + N_EXP=$($IP -6 route list |grep expires|wc -l) + if [ $N_EXP -ne 5 ]; then + log_test 1 0 "expected 5 routes with expires, got $N_EXP" + set +e + cleanup &> /dev/null + return + fi + # Wait for GC + sleep $(($EXPIRE * 2 + 1)) + N_EXP=$($IP -6 route list |grep expires|wc -l) + if [ $N_EXP -ne 0 ]; then + echo "FAIL: expected 0 routes with expires, got $N_EXP" + ret=1 + else + ret=0 + fi + + 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 + N_EXP=$($IP -6 route list |grep expires|wc -l) + if [ $N_EXP -ne 0 ]; then + log_test 1 0 "expected 0 routes with expires, got $N_EXP" + set +e + cleanup &> /dev/null + return + fi + + # Wait for GC + sleep $(($EXPIRE * 2 + 1)) + + N_PERM=$($IP -6 route list |grep -v expires|grep 2001:20::|wc -l) + if [ $N_PERM -ne 5 ]; then + echo "FAIL: expected 5 permanent routes, got $N_PERM" + ret=1 + else + ret=0 + fi + + 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 + + # Delete dummy_10 and remove all routes + $IP link del dev dummy_10 + + # 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 + + N_EXP=$($IP -6 route list|grep expires|wc -l) + if [ $N_EXP -ne 1 ]; then + # systemd may mess up the test. Make sure that + # systemd-networkd.service and systemd-networkd.socket are + # stopped. + log_test 1 0 "expected 1 routes with expires, got $N_EXP" + set +e + cleanup &> /dev/null + return + fi + + # Wait for GC + sleep $(($EXPIRE * 2 + 1)) + + N_EXP=$($IP -6 route list |grep expires|wc -l) + if [ $N_EXP -ne 0 ]; then + echo "FAIL: expected 0 routes with expires, got $N_EXP" + ret=1 + else + ret=0 + fi + + log_test $ret 0 "ipv6 route garbage collection (RA message)" + + set +e cleanup &> /dev/null }