From patchwork Mon Feb 5 21:40:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kui-Feng Lee X-Patchwork-Id: 13546280 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yb1-f169.google.com (mail-yb1-f169.google.com [209.85.219.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 BB2211AB809 for ; Mon, 5 Feb 2024 21:40:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707169243; cv=none; b=iesDtJvaavgTZl1u1Fhb7C0k614sLeJOOp9+mLR+2bt6CuoU7zYZEjKpHNfx8/ZthZj/Bn8m++dNAO9M0q/bsSxpDhEIdSauKptgK3/R23C8XVpsAZWWHn99aR4Wmjh4xZd0vRorOGmv4hWN3EBELNYxfGKz/bLveOaveUuk3Cg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707169243; c=relaxed/simple; bh=4tSVrc3lDD9aUoYxlltfLeAwJNFQSEcmRZdoZavUtrI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=q2a/hItWXJnbSHx9tvP4HBpr/bkokk8RZv/k5joC4akNVR25hRd74FpZ8Wexn2kRXNGtEuA9XZWvYcoXVrruaDjsQ58bGzLj7/Ty2fTUMnmKxDkQ4K0U6W/YBKbmMdeU/SRphPZ8LpoBk6d9uycP8QxY/hI38NBQW7zA4+U2uFw= 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=j0Im4TbO; arc=none smtp.client-ip=209.85.219.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="j0Im4TbO" Received: by mail-yb1-f169.google.com with SMTP id 3f1490d57ef6-dc6d5206f18so257101276.1 for ; Mon, 05 Feb 2024 13:40:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707169240; x=1707774040; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=g8gr/KnM/VeL15b3iiujnM+2BUtml3tCCqm7xonJUZI=; b=j0Im4TbOAakpylAV2tFGDiBWJKCdJdKO2Fp1sSbpcLLRkSgO5SMsbGS1+4DVRZSqsv KBPY+x3Qu4gZuHW2f9WJWo4DiO2XsoY0YGjcESpjjwRpubJG3AbYW51xr+TghlE2Eg92 9Uq6nYEAhtylJGEc2xT9KGW+d4yAjMmZetyPs0LncdyMewXdxgbJT0WMMOUU3C4oz+iQ ri3kowI+XulPAW4mbkm6V98DI1CWjm4IW0HEM/5LsSbjlk4o9ZvT12lvZrkLUg+kVgbe OLel5yTP9qBgN6T+NzF/XrNzrjgHwL5OvbVgFWNuay9vWSLlEFjHM73yFpXKh1gyKvJ2 LvsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707169240; x=1707774040; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=g8gr/KnM/VeL15b3iiujnM+2BUtml3tCCqm7xonJUZI=; b=hoC+Lk1E2xYTON2mUsqbiQuURPYRvMhqyDFd9PZ1ux707bD/UHIshZmWsA76NS6NOu Qqsl0RZxBpkY0aWM/cQsINdj3SyYtfEnUNMuEU8k18d9Gy5d9CMC1MDAgRaqN6joqTFa GRXncZmuO6bqlo3PiHxiVb193s2ja3cvUUVnhQMnUcBTZvhxU0J3aMXl50uSlq1+toYe /aUFXipqvVy8T8dtlWRnFx9CanpPqAEwMT4yqdnDwsODM/rvu8bjq8cMx1et7wDVnm4S 9AgZmFgBq+zIoQ6whgJNLFRdHJiOtULALxMIzeSmltU6ziE7eBw+JAI5lylhtZ94yvSN RZSA== X-Gm-Message-State: AOJu0YygfNGXOCoxcB/u7h9A8RW9ofahiho3sU0rJ3qPxHeYb7WDIXRY 20cgGJd9Iefx1W7+Dit+nT+nqGXNm2CM31Qw3Yjis7xiR/OAqe8Wx3i2VrnfcJ4= X-Google-Smtp-Source: AGHT+IHiQftbmH2tt7yabB8Bw/dOeIed9WkrtPfzxSz6vlg71e+AbZgeAaFPFaVTSfBpN52dQSzTyQ== X-Received: by 2002:a25:664d:0:b0:dc2:40d8:ac5e with SMTP id z13-20020a25664d000000b00dc240d8ac5emr778978ybm.1.1707169240432; Mon, 05 Feb 2024 13:40:40 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCWJMGiwnQtxcvPLAIVimyyshiQ4jGyNtADpYAv4OR5eFQrMHuDXraHvKT1eCj4HvZlR8OSqrgwARaX4cnop3aTTFTcoJyM+XQyBnNsTrnJs35xvb0+AqyWmb32jJ83TKYduthzWIuIGFcyTGMM3Ic6qFvDzDhYoWa+GV2Mljd5HIXtUUOPDdTM0OGCNQRRZLo4nj0h5c4okOO0GM+ubptsR4o8tR6GBVNmyY7vDKPyAn5H73kgQm1s3p/R7GYWqYbnd5I6pS6PW+D9L/t4+fKg7hy3khKHjIoRZe3S4vhRpuf4PAoKZiunK9iQIT9ekT0k0LXCt+ljYGrz5HLDqvhDEZAp5bS5ouU2tTg== Received: from kickker.attlocal.net ([2600:1700:6cf8:1240:8b69:db05:cad3:f30f]) by smtp.gmail.com with ESMTPSA id d7-20020a258247000000b00dbf23ca7d82sm160936ybn.63.2024.02.05.13.40.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 13:40:40 -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 v4 1/5] net/ipv6: set expires in rt6_add_dflt_router(). Date: Mon, 5 Feb 2024 13:40:29 -0800 Message-Id: <20240205214033.937814-2-thinker.li@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240205214033.937814-1-thinker.li@gmail.com> References: <20240205214033.937814-1-thinker.li@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Kui-Feng Lee Pass the duration of a lifetime (in seconds) to the function rt6_add_dflt_router() so that it can properly set the expiration time. The function ndisc_router_discovery() is the only one that calls rt6_add_dflt_router(), and it will later set the expiration time for the route created by rt6_add_dflt_router(). However, there is a gap of time between calling rt6_add_dflt_router() and setting the expiration time in ndisc_router_discovery(). During this period, there is a possibility that a new route may be removed from the routing table. By setting the correct expiration time in rt6_add_dflt_router(), we can prevent this from happening. The reason for setting RTF_EXPIRES in rt6_add_dflt_router() is to start the Garbage Collection (GC) timer, as it only activates when a route with RTF_EXPIRES is added to a table. Suggested-by: David Ahern Reviewed-by: Hangbin Liu Reviewed-by: David Ahern Signed-off-by: Kui-Feng Lee --- include/net/ip6_route.h | 3 ++- net/ipv6/ndisc.c | 3 ++- net/ipv6/route.c | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/include/net/ip6_route.h b/include/net/ip6_route.h index 28b065790261..52a51c69aa9d 100644 --- a/include/net/ip6_route.h +++ b/include/net/ip6_route.h @@ -170,7 +170,8 @@ struct fib6_info *rt6_get_dflt_router(struct net *net, struct fib6_info *rt6_add_dflt_router(struct net *net, const struct in6_addr *gwaddr, struct net_device *dev, unsigned int pref, - u32 defrtr_usr_metric); + u32 defrtr_usr_metric, + int lifetime); void rt6_purge_dflt_routers(struct net *net); diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c index a19999b30bc0..a68462668158 100644 --- a/net/ipv6/ndisc.c +++ b/net/ipv6/ndisc.c @@ -1382,7 +1382,8 @@ static enum skb_drop_reason ndisc_router_discovery(struct sk_buff *skb) neigh_release(neigh); rt = rt6_add_dflt_router(net, &ipv6_hdr(skb)->saddr, - skb->dev, pref, defrtr_usr_metric); + skb->dev, pref, defrtr_usr_metric, + lifetime); if (!rt) { ND_PRINTK(0, err, "RA: %s failed to add default route\n", diff --git a/net/ipv6/route.c b/net/ipv6/route.c index 63b4c6056582..98abba8f15cd 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -4355,7 +4355,8 @@ struct fib6_info *rt6_add_dflt_router(struct net *net, const struct in6_addr *gwaddr, struct net_device *dev, unsigned int pref, - u32 defrtr_usr_metric) + u32 defrtr_usr_metric, + int lifetime) { struct fib6_config cfg = { .fc_table = l3mdev_fib_table(dev) ? : RT6_TABLE_DFLT, @@ -4368,6 +4369,7 @@ struct fib6_info *rt6_add_dflt_router(struct net *net, .fc_nlinfo.portid = 0, .fc_nlinfo.nlh = NULL, .fc_nlinfo.nl_net = net, + .fc_expires = jiffies_to_clock_t(lifetime * HZ), }; cfg.fc_gateway = *gwaddr; From patchwork Mon Feb 5 21:40:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kui-Feng Lee X-Patchwork-Id: 13546281 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yb1-f175.google.com (mail-yb1-f175.google.com [209.85.219.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 3B63359B57 for ; Mon, 5 Feb 2024 21:40:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707169244; cv=none; b=a/SQN1s7j7DzG50NKMTJ179AKryTv7s6a+c2owtEmK35IjM5iprricfIomJacZunxWKWJsGKgn5092QAJhkuP2qsVQb3GtjVKUaSa3uYqQCicvq233AME7ugQDl8NDgUZuIn/3LljE0+rbPQ+C4ySEszNdyBNnc/6Gh40ub60OI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707169244; c=relaxed/simple; bh=Zb0KvqSVUFD6trhqRy7c97PHe4hgPnMtl+lYemNh+DI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=OOjUpHt8hgNEDC5DNoH7Oq9tGIXzWDgq0TjVajqg6zGU5wsUmV/5WtS4JjPwiZ2uDyMyQRuQ+Cor9N35TG/2ZBBCFMAGM+JDfDbF7w8PDJUeKmJwHYQ3OItyUFpWy4eHOGg+Ps9P1+KLZn3HmpXlp903V3+zKGvBZmcWvauIU2o= 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=c52AJGM3; arc=none smtp.client-ip=209.85.219.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="c52AJGM3" Received: by mail-yb1-f175.google.com with SMTP id 3f1490d57ef6-dc6e08fde11so4466838276.1 for ; Mon, 05 Feb 2024 13:40:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707169241; x=1707774041; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FAhvacwnXC+gT2jQb1I4E2pL8pNEiK+4PVEePz3ZhJ8=; b=c52AJGM3xT9bBnM04a76VKdbbuNjntGt2+YNTbGEaUsBtGmNqIrQVVfY8GsMc2jFY9 4afR/Pg4ih7VTzyGMVuhOQ2XM0JkUOGYfq/8xzKSRaWnxgwaRLDdFQCdbGvqNxmpKR28 DefV3vwgbDgmEYfvtY1/mHMmAPyAUZpFHRVQH17gcGBWw3Vs5RrV9jlZ03rTCSDsQIB9 6bmrBP3fxZtmOBfg3ICSD3km/bCzH95vDvUHbSq1Sr77ZJS4DvJBbDxSv2zQYEdCDAfH srfkYj3v4Jjj60cpfoi7Nm8VvfSzDSCmaDB6f4XziIujLfy7SOOQNNs5m+TWji715Bwk csCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707169241; x=1707774041; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FAhvacwnXC+gT2jQb1I4E2pL8pNEiK+4PVEePz3ZhJ8=; b=O2VlnGNWHMOXzHypWpNSTQvEzNo1IHISMwXJ3H5kVb1eaImbqPJfyDKxOlmvTfCfdy kFX1kieXZOHiFcR1p2B0NdhtHWtaIreWR3MUM1JhkmVIKF3ItuqERem8ufxP4p+NcTSs 7VoAY0HIYLbHon0aJcE8MB9A26IVcElxTOTOFve77uhRFWaLd+Ny6V/xf1RPiB86Ea+F juGtl2UQ8MRtafeJo/06NlkI5i/GvgstbX/EG693LjXJ74pUl4HYTzL9vAO75VtY6xbB 1aO9xwSoAXqNdbe20gvWZEvr2L1ie/omxMVG+JlhuMpAWZ9ZlmgzsR7jy9ds5N/Bga5v PbEw== X-Gm-Message-State: AOJu0YxdlrHjRoYGhK07NYZOnaakx8ZnqbnzApNzBeMZ0QDPs3ISRHre O4V22WWcjFm7vRhJWwuFERxtbEhEyscx3PRjVivgq3qFmeAUfXZVfnO7/zi/AlY= X-Google-Smtp-Source: AGHT+IF3irtsu6Fg1CNjoiiaFDe770VgOe1/qohyW+kEa3ONasNcuitFRt7qhti41+gO5u6pErQtvw== X-Received: by 2002:a05:6902:e0b:b0:dc6:4ad3:1671 with SMTP id df11-20020a0569020e0b00b00dc64ad31671mr270683ybb.15.1707169241672; Mon, 05 Feb 2024 13:40:41 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCXj6b9xpMhBKljK7ycQknlK8SInG4wBKOwue9kOlAdnpvyW/jwk4Hz+QBvoVxT04BE+Rkyrtxx+S3G36tGu5l8blIFtKhPExDsrxDo367AgCBKdZdACwZqc9aSyzMC8mcwtnNKTb3iaEzrmqPw1VGkJiZTikIhgpyQUoCrk8LXUxGxcGI5MHnllfDcowsmNkWB1Tylo3GyvkxQ6K0x/nyukyaRKb11KQpkM9gppVoAllXC9BTNkAd2V4vOlAnDwRMvEnQZjITADxVC387OAml3S08HGpHmQGg15P11/LlgrEE+jn+V20ngeEAUtyJ77m1r0YqqQn5QeyZ83xNwTRAJ5DerlAuJdDSiOiQ== Received: from kickker.attlocal.net ([2600:1700:6cf8:1240:8b69:db05:cad3:f30f]) by smtp.gmail.com with ESMTPSA id d7-20020a258247000000b00dbf23ca7d82sm160936ybn.63.2024.02.05.13.40.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 13:40:41 -0800 (PST) From: thinker.li@gmail.com To: netdev@vger.kernel.org, ast@kernel.org, martin.lau@linux.dev, kernel-team@meta.com, davem@davemloft.net, dsahern@kernel.org, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, liuhangbin@gmail.com Cc: sinquersw@gmail.com, kuifeng@meta.com, Kui-Feng Lee Subject: [PATCH net-next v4 2/5] net/ipv6: Remove unnecessary clean. Date: Mon, 5 Feb 2024 13:40:30 -0800 Message-Id: <20240205214033.937814-3-thinker.li@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240205214033.937814-1-thinker.li@gmail.com> References: <20240205214033.937814-1-thinker.li@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Kui-Feng Lee The route here is newly created. It is unnecessary to call fib6_clean_expires() on it. Suggested-by: Eric Dumazet Reviewed-by: Hangbin Liu Reviewed-by: David Ahern Signed-off-by: Kui-Feng Lee --- net/ipv6/route.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/net/ipv6/route.c b/net/ipv6/route.c index 98abba8f15cd..dd6ff5b20918 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -3765,8 +3765,6 @@ static struct fib6_info *ip6_route_info_create(struct fib6_config *cfg, if (cfg->fc_flags & RTF_EXPIRES) fib6_set_expires(rt, jiffies + clock_t_to_jiffies(cfg->fc_expires)); - else - fib6_clean_expires(rt); if (cfg->fc_protocol == RTPROT_UNSPEC) cfg->fc_protocol = RTPROT_BOOT; From patchwork Mon Feb 5 21:40:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kui-Feng Lee X-Patchwork-Id: 13546282 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f182.google.com (mail-yw1-f182.google.com [209.85.128.182]) (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 A0D0059B6C for ; Mon, 5 Feb 2024 21:40:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707169246; cv=none; b=Jyxk3z2PI57gqRtaDOxqMfQeIahlVQDN78CaGYoa0D2H2ohgm0a5vI15Y3eBZJfnPiKUM5vl+hry39fOKjANVcq/tl8NNlcxEjd6c80ZViJVuSV+sul2jpAkzwwmLGFtpw0QRYT1Iu05oA4ioGurrPJBwW7KWOINNs289mmaxbs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707169246; c=relaxed/simple; bh=B8U9W9MoATT/D5vvsTYXsaSv886NhkkcAxJB5xpLi1M=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=am8E2zn+QkPhOAmrJiejKlo1XcjS4TRm/xCwU9SOhN6NKzWyRI2e8JKa1NazaTayYEUHWzl/ekalFLoj/Wrfm0guBTybsikE5xYKHPEShXbJJPaHZG/S+ra7m9/4t3pLWRPSaVMkyYrk6q2Hp39ccIrYjkPB3n/3FQE8yL8s2mo= 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=H8qGPYh9; arc=none smtp.client-ip=209.85.128.182 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="H8qGPYh9" Received: by mail-yw1-f182.google.com with SMTP id 00721157ae682-60406302a5eso2419547b3.0 for ; Mon, 05 Feb 2024 13:40:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707169243; x=1707774043; 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=p4gUEZdKTRHx3hZKWHyipuiFZMP74r4/N1iNN0WvQnQ=; b=H8qGPYh9E0olw2osRk1pya7ZvKgW2FJXyPhrKhRDVa7kmJOZyo1n3BeJAmqZbzuK9x fv4V0Jd4nlREio9AR8YMyBSvAG919eGi7ZE+xO9566xTaJvZxzv5Y4QqJc5NExA5YePL v+ZSY0vnRNDLOnwJFpaSqasMroi/aarUqH+iVv2reH+QTrkVaoJaMb5tmn4qfd944Gwm KU3zYZB5zsDIIWCYedxwfHuN1uhKfCRvTRlzZKUyZqinnUZPtESziF7+6lstW7rkXa9X tMWHZKY6oXBLwiJVEm7DrRtsGmbV6Cj50yjZb/rOuSQyH7C0YNI2OQw2On5Rv/TWR720 lafw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707169243; x=1707774043; 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=p4gUEZdKTRHx3hZKWHyipuiFZMP74r4/N1iNN0WvQnQ=; b=vdK3UBsQcZ+5cS1g19d/zecAoXp4I5eAfNRK7lknihdyZG778Whq3afy0uAklodtrO gm0tkVcKdQDpteEryNIfzYbdAaqPZ9adHu70ZxBMfDepbagtAGk4/VKi1mgiUBa1Ioga JXWfvANPfDDWb9IZL1daefrfUt81BM6yd3Q3jbl+n4RR193x4phpPsGUrQ/yrKPfD9tw mqGtLfacPziaZAq3GxwG4AKfOOq2Gc5aF5aE2mV4wZqBD2qntWrf3ZDOPqeU3v8kfMv7 PSOc6TaalhUHEn0lXV8hAYqejwmDe0p1eJA5GiVwLBcqbKbnSdBiCkAk+jKEHUvJoRc5 GcZQ== X-Gm-Message-State: AOJu0YyDtMmyPKHzMpZKFZL7Bwx5lNTLAGqOrTTvVQnT6ewaOKZYwGJg LiUTvNkDYbruGi/uDlnlYhfh/NMgk1ucGU0+po99NUINI16Q/a2yMdSmCgylgt4= X-Google-Smtp-Source: AGHT+IEbHsXzagNh0+eAuX3woOFK8tONFhtdQWiuwDDWjeaKR7mGaXPZ+NkZmQufUfgVfeNW2oICYA== X-Received: by 2002:a05:6902:218f:b0:dc2:3289:5b5d with SMTP id dl15-20020a056902218f00b00dc232895b5dmr818325ybb.57.1707169242976; Mon, 05 Feb 2024 13:40:42 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCUqI0O/ddDQg5PSy01dHTP/YqNv0CmBu//9UpGniylvhTo9nmv+mQRghpeImfqxUlTxitoLl5lUmNPClr5o59gLEEKRuAJZfAHaebykDkztKwmESgDre2lr8JU8YBbPPNX6qN5oJTD1Xb9GHSH3hbDRNYFv0qfwYZZM/Sv33fyTWFVXJ68R1cQzm9RwQ7SHSs/5I/mNtoE9KI3bpXOYskmr0BxC6x3VpcHZ5JS0KNEgeoIuYdqstAjwEYyINfulEFjT7/HoEn5chuMJ5sYtPiVCv81wbBofkoS/oAC4PrsxqjK1b3ioUTH+dpTsSrsm7J7YSO7/Hi++SUUxL1P0ita1hN16SVFldIbOmQ== Received: from kickker.attlocal.net ([2600:1700:6cf8:1240:8b69:db05:cad3:f30f]) by smtp.gmail.com with ESMTPSA id d7-20020a258247000000b00dbf23ca7d82sm160936ybn.63.2024.02.05.13.40.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 13:40:42 -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 v4 3/5] net/ipv6: Remove expired routes with a separated list of routes. Date: Mon, 5 Feb 2024 13:40:31 -0800 Message-Id: <20240205214033.937814-4-thinker.li@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240205214033.937814-1-thinker.li@gmail.com> References: <20240205214033.937814-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 Reviewed-by: David Ahern --- include/net/ip6_fib.h | 47 ++++++++++++++++++++++++++++++++- net/ipv6/addrconf.c | 41 ++++++++++++++++++++++++----- net/ipv6/ip6_fib.c | 60 +++++++++++++++++++++++++++++++++++++++---- net/ipv6/ndisc.c | 10 +++++++- net/ipv6/route.c | 13 ++++++++-- 5 files changed, 155 insertions(+), 16 deletions(-) diff --git a/include/net/ip6_fib.h b/include/net/ip6_fib.h index 360b12e61850..498e6c2a3caa 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,39 @@ 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 fib6_node is null, the f6i is not in (or removed from) the + * table. + * + * There is a gap between finding the f6i from the table and + * calling this function without the protection of the tb6_lock. + * This check makes sure the f6i is not added to the gc list when + * it is not on the table. + */ + if (!rcu_dereference_protected(f6i->fib6_node, + lockdep_is_held(&f6i->fib6_table->tb6_lock))) + return; + + if (hlist_unhashed(&f6i->gc_link)) + hlist_add_head(&f6i->gc_link, &f6i->fib6_table->tb6_gc_hlist); +} + +/* Remove the route from the gc list if it is on the list. + * + * The callers should hold f6i->fib6_table->tb6_lock. + */ +static inline void fib6_remove_gc_list(struct fib6_info *f6i) +{ + if (!hlist_unhashed(&f6i->gc_link)) + hlist_del_init(&f6i->gc_link); +} + struct ipv6_route_iter { struct seq_net_private p; struct fib6_walker w; diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index 733ace18806c..58c5270396f6 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -1255,6 +1255,7 @@ static void cleanup_prefix_route(struct inet6_ifaddr *ifp, unsigned long expires, bool del_rt, bool del_peer) { + struct fib6_table *table; struct fib6_info *f6i; f6i = addrconf_get_prefix_route(del_peer ? &ifp->peer_addr : &ifp->addr, @@ -1264,8 +1265,15 @@ cleanup_prefix_route(struct inet6_ifaddr *ifp, unsigned long expires, if (del_rt) ip6_del_rt(dev_net(ifp->idev->dev), f6i, false); else { - if (!(f6i->fib6_flags & RTF_EXPIRES)) + if (!(f6i->fib6_flags & RTF_EXPIRES)) { + table = f6i->fib6_table; + spin_lock_bh(&table->tb6_lock); + fib6_set_expires(f6i, expires); + fib6_add_gc_list(f6i); + + spin_unlock_bh(&table->tb6_lock); + } fib6_info_release(f6i); } } @@ -2706,6 +2714,7 @@ EXPORT_SYMBOL_GPL(addrconf_prefix_rcv_add_addr); void addrconf_prefix_rcv(struct net_device *dev, u8 *opt, int len, bool sllao) { struct prefix_info *pinfo; + struct fib6_table *table; __u32 valid_lft; __u32 prefered_lft; int addr_type, err; @@ -2782,11 +2791,20 @@ void addrconf_prefix_rcv(struct net_device *dev, u8 *opt, int len, bool sllao) if (valid_lft == 0) { ip6_del_rt(net, rt, false); rt = NULL; - } else if (addrconf_finite_timeout(rt_expires)) { - /* not infinity */ - fib6_set_expires(rt, jiffies + rt_expires); } else { - fib6_clean_expires(rt); + table = rt->fib6_table; + spin_lock_bh(&table->tb6_lock); + + if (addrconf_finite_timeout(rt_expires)) { + /* not infinity */ + fib6_set_expires(rt, jiffies + rt_expires); + fib6_add_gc_list(rt); + } else { + fib6_clean_expires(rt); + fib6_remove_gc_list(rt); + } + + spin_unlock_bh(&table->tb6_lock); } } else if (valid_lft) { clock_t expires = 0; @@ -4741,6 +4759,7 @@ static int modify_prefix_route(struct inet6_ifaddr *ifp, unsigned long expires, u32 flags, bool modify_peer) { + struct fib6_table *table; struct fib6_info *f6i; u32 prio; @@ -4761,10 +4780,18 @@ static int modify_prefix_route(struct inet6_ifaddr *ifp, ifp->rt_priority, ifp->idev->dev, expires, flags, GFP_KERNEL); } else { - if (!expires) + table = f6i->fib6_table; + spin_lock_bh(&table->tb6_lock); + + if (!expires) { fib6_clean_expires(f6i); - else + fib6_remove_gc_list(f6i); + } else { fib6_set_expires(f6i, expires); + fib6_add_gc_list(f6i); + } + + spin_unlock_bh(&table->tb6_lock); fib6_info_release(f6i); } diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c index 38a0348b1d17..805bbf26b3ef 100644 --- a/net/ipv6/ip6_fib.c +++ b/net/ipv6/ip6_fib.c @@ -160,6 +160,8 @@ struct fib6_info *fib6_info_alloc(gfp_t gfp_flags, bool with_fib6_nh) INIT_LIST_HEAD(&f6i->fib6_siblings); refcount_set(&f6i->fib6_ref, 1); + INIT_HLIST_NODE(&f6i->gc_link); + return f6i; } @@ -246,6 +248,7 @@ static struct fib6_table *fib6_alloc_table(struct net *net, u32 id) net->ipv6.fib6_null_entry); table->tb6_root.fn_flags = RTN_ROOT | RTN_TL_ROOT | RTN_RTINFO; inet_peer_base_init(&table->tb6_peers); + INIT_HLIST_HEAD(&table->tb6_gc_hlist); } return table; @@ -1055,6 +1058,9 @@ static void fib6_purge_rt(struct fib6_info *rt, struct fib6_node *fn, lockdep_is_held(&table->tb6_lock)); } } + + fib6_clean_expires(rt); + fib6_remove_gc_list(rt); } /* @@ -1115,10 +1121,13 @@ static int fib6_add_rt2node(struct fib6_node *fn, struct fib6_info *rt, rt->fib6_nsiblings = 0; if (!(iter->fib6_flags & RTF_EXPIRES)) return -EEXIST; - if (!(rt->fib6_flags & RTF_EXPIRES)) + if (!(rt->fib6_flags & RTF_EXPIRES)) { fib6_clean_expires(iter); - else + fib6_remove_gc_list(iter); + } else { fib6_set_expires(iter, rt->expires); + fib6_add_gc_list(iter); + } if (rt->fib6_pmtu) fib6_metric_set(iter, RTAX_MTU, @@ -1477,6 +1486,10 @@ int fib6_add(struct fib6_node *root, struct fib6_info *rt, if (rt->nh) list_add(&rt->nh_list, &rt->nh->f6i_list); __fib6_update_sernum_upto_root(rt, fib6_new_sernum(info->nl_net)); + + if (rt->fib6_flags & RTF_EXPIRES) + fib6_add_gc_list(rt); + fib6_start_gc(info->nl_net, rt); } @@ -2280,9 +2293,8 @@ static void fib6_flush_trees(struct net *net) * Garbage collection */ -static int fib6_age(struct fib6_info *rt, void *arg) +static int fib6_age(struct fib6_info *rt, struct fib6_gc_args *gc_args) { - struct fib6_gc_args *gc_args = arg; unsigned long now = jiffies; /* @@ -2307,6 +2319,42 @@ static int fib6_age(struct fib6_info *rt, void *arg) return 0; } +static void fib6_gc_table(struct net *net, + struct fib6_table *tb6, + struct fib6_gc_args *gc_args) +{ + struct fib6_info *rt; + struct hlist_node *n; + struct nl_info info = { + .nl_net = net, + .skip_notify = false, + }; + + hlist_for_each_entry_safe(rt, n, &tb6->tb6_gc_hlist, gc_link) + if (fib6_age(rt, gc_args) == -1) + fib6_del(rt, &info); +} + +static void fib6_gc_all(struct net *net, struct fib6_gc_args *gc_args) +{ + struct fib6_table *table; + struct hlist_head *head; + unsigned int h; + + rcu_read_lock(); + for (h = 0; h < FIB6_TABLE_HASHSZ; h++) { + head = &net->ipv6.fib_table_hash[h]; + hlist_for_each_entry_rcu(table, head, tb6_hlist) { + spin_lock_bh(&table->tb6_lock); + + fib6_gc_table(net, table, gc_args); + + spin_unlock_bh(&table->tb6_lock); + } + } + rcu_read_unlock(); +} + void fib6_run_gc(unsigned long expires, struct net *net, bool force) { struct fib6_gc_args gc_args; @@ -2322,7 +2370,7 @@ void fib6_run_gc(unsigned long expires, struct net *net, bool force) net->ipv6.sysctl.ip6_rt_gc_interval; gc_args.more = 0; - fib6_clean_all(net, fib6_age, &gc_args); + fib6_gc_all(net, &gc_args); now = jiffies; net->ipv6.ip6_rt_last_gc = now; @@ -2382,6 +2430,7 @@ static int __net_init fib6_net_init(struct net *net) net->ipv6.fib6_main_tbl->tb6_root.fn_flags = RTN_ROOT | RTN_TL_ROOT | RTN_RTINFO; inet_peer_base_init(&net->ipv6.fib6_main_tbl->tb6_peers); + INIT_HLIST_HEAD(&net->ipv6.fib6_main_tbl->tb6_gc_hlist); #ifdef CONFIG_IPV6_MULTIPLE_TABLES net->ipv6.fib6_local_tbl = kzalloc(sizeof(*net->ipv6.fib6_local_tbl), @@ -2394,6 +2443,7 @@ static int __net_init fib6_net_init(struct net *net) net->ipv6.fib6_local_tbl->tb6_root.fn_flags = RTN_ROOT | RTN_TL_ROOT | RTN_RTINFO; inet_peer_base_init(&net->ipv6.fib6_local_tbl->tb6_peers); + INIT_HLIST_HEAD(&net->ipv6.fib6_local_tbl->tb6_gc_hlist); #endif fib6_tables_init(net); diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c index a68462668158..73cb31afe935 100644 --- a/net/ipv6/ndisc.c +++ b/net/ipv6/ndisc.c @@ -1237,6 +1237,7 @@ static enum skb_drop_reason ndisc_router_discovery(struct sk_buff *skb) struct ndisc_options ndopts; struct fib6_info *rt = NULL; struct inet6_dev *in6_dev; + struct fib6_table *table; u32 defrtr_usr_metric; unsigned int pref = 0; __u32 old_if_flags; @@ -1410,8 +1411,15 @@ static enum skb_drop_reason ndisc_router_discovery(struct sk_buff *skb) inet6_rt_notify(RTM_NEWROUTE, rt, &nlinfo, NLM_F_REPLACE); } - if (rt) + if (rt) { + table = rt->fib6_table; + spin_lock_bh(&table->tb6_lock); + fib6_set_expires(rt, jiffies + (HZ * lifetime)); + fib6_add_gc_list(rt); + + spin_unlock_bh(&table->tb6_lock); + } if (in6_dev->cnf.accept_ra_min_hop_limit < 256 && ra_msg->icmph.icmp6_hop_limit) { if (in6_dev->cnf.accept_ra_min_hop_limit <= ra_msg->icmph.icmp6_hop_limit) { diff --git a/net/ipv6/route.c b/net/ipv6/route.c index dd6ff5b20918..707d65bc9c0e 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -931,6 +931,7 @@ int rt6_route_rcv(struct net_device *dev, u8 *opt, int len, struct net *net = dev_net(dev); struct route_info *rinfo = (struct route_info *) opt; struct in6_addr prefix_buf, *prefix; + struct fib6_table *table; unsigned int pref; unsigned long lifetime; struct fib6_info *rt; @@ -989,10 +990,18 @@ int rt6_route_rcv(struct net_device *dev, u8 *opt, int len, (rt->fib6_flags & ~RTF_PREF_MASK) | RTF_PREF(pref); if (rt) { - if (!addrconf_finite_timeout(lifetime)) + table = rt->fib6_table; + spin_lock_bh(&table->tb6_lock); + + if (!addrconf_finite_timeout(lifetime)) { fib6_clean_expires(rt); - else + fib6_remove_gc_list(rt); + } else { fib6_set_expires(rt, jiffies + HZ * lifetime); + fib6_add_gc_list(rt); + } + + spin_unlock_bh(&table->tb6_lock); fib6_info_release(rt); } From patchwork Mon Feb 5 21:40:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kui-Feng Lee X-Patchwork-Id: 13546283 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 96E6559B76 for ; Mon, 5 Feb 2024 21:40:45 +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=1707169247; cv=none; b=UNpdVwKyg+Is6hUXcR2Uma4KCcqxDqsqfiajIrijuEV6XIJi7y50wt+l9GutDo2+1BZJAm7C7IUXFwS+BqMkffWFs46HQeivRPceYNRuUUxhDmzS3D9MalQx1y/VoYAxwTF+KkCl6wap89zmJIb+BcVJ0hUzfZ7HemsbwuwEF+Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707169247; c=relaxed/simple; bh=qk407FI7frV3L8SMCUcipi9YvNbrW/8M4wub+qXsq6o=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=aQ9be5XjRsCedMoGC6CH4tQKhp5ZqGqe2wFlk2ym4jt6ejEN8qlvCEg2HVKvmH/gC2VmM+Oed2OqNvO5iJV8Nkn7MUg0PqfPV4kttkg8R9Hl8G2L+/GS77VxKxdHyGoWK66xAMSRNVt3MSspvrROLyyogMRSz+1XUtmvSxlT0ZM= 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=YIZjurpY; 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="YIZjurpY" Received: by mail-yw1-f179.google.com with SMTP id 00721157ae682-6041c6333cdso39550177b3.2 for ; Mon, 05 Feb 2024 13:40:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707169244; x=1707774044; 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=y8AkpGejsu4VJ2FN79PyTLfroPMs/1bJnlVtzqqA8Wg=; b=YIZjurpYaDPQc12fXwajj9WaxYWvgYZQtjdfW1ClP3g4VVT0hVvRJYafsw1JK7Awwl fOoSnurHdbRtSH83f2/AYGjXdqXwAsGw/rJ9fR6S4NWy5jtpVxxdURTAThkmjbufnVqH LS8dBul0TjHs95mFyyDbTRsCzQVqkyK3EyPca9YElL9lqdSvrAZFNNhTcVW5Zgy8gDtB Q6zca2+d7gTuR2RLYEPV57NWJxEoySpXmX3+NQIfcGWK7NWoTzxCagSog2HaLmFhvERy X8O+JEdWfiyc22N+pd8FEWExxFgcXqd9eSue3pJGx/F2O2m518JcT3cumQN1zIFXnrSm iNpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707169244; x=1707774044; 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=y8AkpGejsu4VJ2FN79PyTLfroPMs/1bJnlVtzqqA8Wg=; b=cBguL3i3fngJ36fXD0KmyjcOXC6CA48aKCTNqhGCBcC5G7xlU22mzzWl0RiMZHssQ9 02E0cJjFrbPB3/c43e3pRQ2TaA/1GKKabIgM7xvw4A6QNIYUZkl/OcH3MNejexD4c9+e cK2+EFI8neBMNeVbOySHHjmbbMFGk/bbQxJnX14HBnb4mdzPsttsg823f49WpxdR6cMf OaqPZ1KoYP3kfLBHYjLPDQd2zKs2IKWZvyhsIHqGlPCpSaUjSg3HkDluZWX3FSl7SadU 9HAgyq6gsksFxaWWQxuczXiimwFWpN7eXN5qP35mZWVh6qD+/FQ0cZPKZ9zZuskE59xz +F4g== X-Gm-Message-State: AOJu0YyZMclDVUeaPXAKQhEx95SS+cR0IiKy4haRVmWDVwGohxySxSAG QCnimi8op2Um9+QERz+2WpTRyF/9SlxxuoIynDwwJZ2+SfiD8yvQol0tqxLe X-Google-Smtp-Source: AGHT+IHAuKs6p2GGjlxA6NNH6he8x4WWVjkzuxoxeInenteS4vG0tnPDdNldzBZVAqVeymshYAs57w== X-Received: by 2002:a05:6902:1b8d:b0:dc2:2846:59dc with SMTP id ei13-20020a0569021b8d00b00dc2284659dcmr762916ybb.36.1707169244280; Mon, 05 Feb 2024 13:40:44 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCWAl/nidbZzLIGw9HJH1UqNdKVlVyOMvgCTY4d0SW8AIZAliAKRiVjEOzNX38ZfXTdODjLxpx9XNIV7dcr3mQ13qVtwOXYq4bWvzVcxg+C1WRJENRrnhdlujngU6exKhJjnnDtqJupEukz2yC2tyYX7xRNmk3dc0U3BUdsk+xlRHFPvYk6x/vyr6Dk1rP4/1mQO5Fyb5nntbFWx5UwMzE6ve2VnvhATKO7wwIAgGmDyB0fsOr4bpBlZpn1atCFH6qQ0kqEOIZs8mgzLKl1fKULr/n7Gd9TwWX2ddB/Waz56p01Y/v13CEtKBB62ZUZP1jnRA1MSUrKR/Ywa6kQcphVTMFNBlc4yaU5FmQ== Received: from kickker.attlocal.net ([2600:1700:6cf8:1240:8b69:db05:cad3:f30f]) by smtp.gmail.com with ESMTPSA id d7-20020a258247000000b00dbf23ca7d82sm160936ybn.63.2024.02.05.13.40.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 13:40:44 -0800 (PST) From: thinker.li@gmail.com To: netdev@vger.kernel.org, ast@kernel.org, martin.lau@linux.dev, kernel-team@meta.com, davem@davemloft.net, dsahern@kernel.org, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, liuhangbin@gmail.com Cc: sinquersw@gmail.com, kuifeng@meta.com, Kui-Feng Lee Subject: [PATCH net-next v4 4/5] net/ipv6: set expires in modify_prefix_route() if RTF_EXPIRES is set. Date: Mon, 5 Feb 2024 13:40:32 -0800 Message-Id: <20240205214033.937814-5-thinker.li@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240205214033.937814-1-thinker.li@gmail.com> References: <20240205214033.937814-1-thinker.li@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Kui-Feng Lee Make the decision to set or clean the expires of a route based on the RTF_EXPIRES flag, rather than the value of the "expires" argument. This patch doesn't make difference logically, but make inet6_addr_modify() and modify_prefix_route() consistent. The function inet6_addr_modify() is the only caller of modify_prefix_route(), and it passes the RTF_EXPIRES flag and an expiration value. The RTF_EXPIRES flag is turned on or off based on the value of valid_lft. The RTF_EXPIRES flag is turned on if valid_lft is a finite value (not infinite, not 0xffffffff). Even if valid_lft is 0, the RTF_EXPIRES flag remains on. The expiration value being passed is equal to the valid_lft value if the flag is on. However, if the valid_lft value is infinite, the expiration value becomes 0 and the RTF_EXPIRES flag is turned off. Despite this, modify_prefix_route() decides to set the expiration value if the received expiration value is not zero. This mixing of infinite and zero cases creates an inconsistency. Reviewed-by: Hangbin Liu Signed-off-by: Kui-Feng Lee Reviewed-by: David Ahern --- 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 58c5270396f6..486ec83b4668 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -4783,7 +4783,7 @@ static int modify_prefix_route(struct inet6_ifaddr *ifp, table = f6i->fib6_table; spin_lock_bh(&table->tb6_lock); - if (!expires) { + if (!(flags & RTF_EXPIRES)) { fib6_clean_expires(f6i); fib6_remove_gc_list(f6i); } else { From patchwork Mon Feb 5 21:40:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kui-Feng Lee X-Patchwork-Id: 13546284 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yb1-f176.google.com (mail-yb1-f176.google.com [209.85.219.176]) (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 DDCB559B7F for ; Mon, 5 Feb 2024 21:40:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707169248; cv=none; b=Flja4c4bCFTd2AghW7YA77Q6QcrqtT72DAIKfyo/IvKMvayegpkTgUWbmAQWjYbmv8jBZrl9tE5vPEEyaGfWv92jEU4XMpjW4ktMhW5V5HADTYr6M2AncYxUDD+QvjGLTNxgY3vCTdX4Dyl7v1jHWjMVWqS2S/3oR7KX+uoweVA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707169248; c=relaxed/simple; bh=28VAMkMgt1fDUM57a10aCWM/chIBrpsz0JcYGF0u1Do=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Z6MDjBZwYipX6JX5DtZK1Os+0nE6Fss8Tp/aEhTyOjT2tFI6mdpO8kfEoq6OMF8GOsF+j9Rz8csD9CTmpfmglgqGWc9QO9z0ng1wlzpP3wvAQSu4OvKO7xJR3HKttg5Jxl9IzXQj0PbTjBHDFGBHGV4bV94rj2NTZQjCLsnoEKo= 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=GyU4C3Wq; arc=none smtp.client-ip=209.85.219.176 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="GyU4C3Wq" Received: by mail-yb1-f176.google.com with SMTP id 3f1490d57ef6-dc6af9a988eso4144857276.0 for ; Mon, 05 Feb 2024 13:40:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707169245; x=1707774045; 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=/JxYGlYSVEP4MNYrTgK6GK+yeDj8pqTGFUi/P8FkNBk=; b=GyU4C3Wq3Tt7NiqlBnA6ZSWG8bYTGkgZQzPPY5In8GmriwKdhA3Gd86rNlVpWhXBNs N7aWWiqdbxmO20zgJHjoCOQ1mq1c3BGIr0jlr6ZJnv9h3YTrTTlBFgNEWI2zJjOboAOw je9yyzrtRshmShc8dOnez/t/tK2n0rH6tRGhJ6x1SK/5pWiSZVtNq89CsH+FfSoW42HS 1sNz1tQV/J2ZW8HvcFWqzH76Atv9dxZ8h+pa96yctg3J7R27Dr5QyFrntyjyUDpLgFUF xp1FlxXrvpKjQkw2jz2QMTKjzE/vz4ZDFr1t9t5vPO1CEWPApYQeTf/9Ol8SdkHcs1F6 IQ1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707169245; x=1707774045; 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=/JxYGlYSVEP4MNYrTgK6GK+yeDj8pqTGFUi/P8FkNBk=; b=eXHqFGHHWymlWSQIoiSuI6cC/86LqVyjLJ5BzLP9DpSj4fdCoFFnZgUhe0dEr5BRJh 1cifzlv9mCoCS1rSilN1t7H9vTJdPRmSGC09btsXN75MoXHBptyopz/ZIdK2kTnHZ1y+ lYvrAhIOq2S8AGXUcf+WR7XOQr/6yswylEHiNH5eJ1yBEhGB1KxXDck601Roy/qq290z GhataKav/9+Q+qoBFJNhAIIAJecF94gSPJEHfXA5RIk+k3QhzgmDs2mzsO8FWTpb6HDA f+tRPsng+el7uCkJ8lpGf0iRycXymWKmHKYXm/1jIJvww5J9ZJlyB0PQF5ByXzWn1Zlc siyw== X-Gm-Message-State: AOJu0Yz3UUPPrbTr2tOoTwAWXlpxn2qwe0bkpbeAXQwfk6HW+E3mEA8d dkQCfCrAKlD5XgJxeL57gvK1mw47V2HLfmAXiiuxUFrv4UhhjCcZXCc4D6I9 X-Google-Smtp-Source: AGHT+IFqOYijhFKpdsM/4/RbWTH2yNqjut8r3GrFWpB149WPEnorRSky/I8/gZF/WrttoLYwJAmgfg== X-Received: by 2002:a05:6902:2407:b0:dc2:5573:42df with SMTP id dr7-20020a056902240700b00dc2557342dfmr296542ybb.25.1707169245646; Mon, 05 Feb 2024 13:40:45 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCWQGyHNhpOErg7U3F93MN/ylZfhZwJgD/a36UkHZ3o+HJzJ6/Cm5B0a92+8uLVdPCUyTdZIm3efKdRw2k+yAIjPZz81jnIdrhBxgj+OJBtZWA9xbf/IuT2jiuy9A1KfVHIMJOql7MpaykODgqYclAu1CgnrpFjFAi4Z7KMiH3Ckibwl2e1fs1Z9tq02lXczYFt+G5Ln34hb7K3FvIUlQEwxi2dAeMXtLUjMe5LrDL0y46mUWyx0tX618ynHfK40ijXRNSB+ten/poRVcVkfJrO7GM1wDvJFfLLRBKv+viSnnWTA7QdzS1dv2+6JHoA19YlrDE528kHPodIJDHC6WLZGyWElWiwpK2UjQA== Received: from kickker.attlocal.net ([2600:1700:6cf8:1240:8b69:db05:cad3:f30f]) by smtp.gmail.com with ESMTPSA id d7-20020a258247000000b00dbf23ca7d82sm160936ybn.63.2024.02.05.13.40.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 13:40:45 -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 v4 5/5] selftests/net: Adding test cases of replacing routes and route advertisements. Date: Mon, 5 Feb 2024 13:40:33 -0800 Message-Id: <20240205214033.937814-6-thinker.li@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240205214033.937814-1-thinker.li@gmail.com> References: <20240205214033.937814-1-thinker.li@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Kui-Feng Lee Add tests of changing permanent routes to temporary routes and the reversed case to make sure GC working correctly in these cases. Add tests for the temporary routes from RA. The existing device will be deleted between tests to remove all routes associated with it, so that the earlier tests don't mess up the later ones. Reviewed-by: Hangbin Liu Tested-by: Hangbin Liu Signed-off-by: Kui-Feng Lee Reviewed-by: David Ahern --- 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 }