From patchwork Wed Jan 31 06:40:37 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: 13538780 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yb1-f180.google.com (mail-yb1-f180.google.com [209.85.219.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4C79D51027 for ; Wed, 31 Jan 2024 06:40:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706683248; cv=none; b=dOLNEYP7d6GgYz01YNb+43S89e8s9KTFzRHinTwMBQxp4njNNZ5yTxd/sHZOBuv60M/R9KeD/RVi9DWp4HaNAag0voSmQWd+RJJpdxLR1Zo343rx3PtqyGMQ1Hu1SWAIZX9M74XOhBGS+ebghi+iuJwRLxCKP8C1J7rZ21GlKZw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706683248; c=relaxed/simple; bh=9Q7dIWO/up+Z+zGT7zjSYYeM+tBMW5qlYmi941jKS2A=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=BC7sV+djcxs/tXl85jfKtklpI25HzV/0eBuOoe/g91pxG3OQKoE6z/lqzJ22CP5OiM+bJn0usbkXGdCA2oXJGNbAEFe6fb9eYlh/7/1myZ2qzedlk6tC7V/1ynBhXKIad8PTUM0ltIKOOgju+2WmFA/y45lctuoL6v10eylVVPo= 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=NEL809fN; arc=none smtp.client-ip=209.85.219.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NEL809fN" Received: by mail-yb1-f180.google.com with SMTP id 3f1490d57ef6-dc23bf7e5aaso5311675276.0 for ; Tue, 30 Jan 2024 22:40:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706683246; x=1707288046; 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=NEL809fNKUA3nGZ9w7kTIJq+MtEsshkgDRC+5M03Ekss+KEs3gZ3Ai7sZ7Ym6rPdAC M4GJNyIQEs4wlJ8WpCujvGFCkdtsjflOdk+JWtR+Fbj5O2qg9HDer1VXp+gcDTmZrDHD pG17q1/vlIJeZfinYQqN4H01yViTEJn1WABleMB2SqV0ZQD26PfWXvKCFIeNyOmc/IhP KX02+KhFgI4La6RDKszSiT6E+LvhZwSj9we9eY9T1ECkAQhSt97vHgkt5Zfpi1wUmdPz R4E1G3juZv+BvMaHVlNnhKLq2Ulc2EJJ+Cb0MJO+il63GXCEBI24T5J4NToNc79eS3QB tr1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706683246; x=1707288046; 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=MjurDKZNmFQG2gVhls3N6HcSi/3ki2J51+bsSl2TsqnGzimBubADiwgc+b3Y4SEdY9 8oXQgoBRhoz0PLVEeGEt9cjp/AktaqHI3qvOez5ykYFRbyKSX4I8d80xjLlnXlNhIvX8 eeCmVtfCEjxDu02KbihMfd1ho47KaOfVylh+tQM0iyDAbTkbQMu4xs/NBf0gYZ7lhxb3 sLQwMpLe4VmIca8cAgHmtq8jf5HHlGtYa9MqSn1cxShQwU9OmjWV6Stj+krcW6EdqpWu YvSpUgeAKUvyUqputGpoJibxgD3M3jxxaYONn3AS64It1ISN/qUrcXJBRDeOlcrMr8Dc kQsg== X-Gm-Message-State: AOJu0YwJbPnTBOAVdB54Ow25Z0oH5/NT4yuPRJ4GyuukPSNBd2lPnQKu i9WummUKUfATSYMpLImR/pqQXG4WFak9lkFJKzJ63v1RNsBI3lQnjau0q5dDJBg= X-Google-Smtp-Source: AGHT+IEfQGVFjNCWjSn7MCJIqSM7dqJ+uB8EvLPOQ5efbIzM21xwJAtIMLZY6LgVecF/ZAkZWUg5NA== X-Received: by 2002:a25:a40a:0:b0:dc2:644e:fcf9 with SMTP id f10-20020a25a40a000000b00dc2644efcf9mr550038ybi.40.1706683246037; Tue, 30 Jan 2024 22:40:46 -0800 (PST) Received: from kickker.attlocal.net ([2600:1700:6cf8:1240:7a8:850:239d:3ddc]) by smtp.gmail.com with ESMTPSA id y9-20020a2586c9000000b00dc228b22cd5sm3345683ybm.41.2024.01.30.22.40.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 22: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 1/5] net/ipv6: set expires in rt6_add_dflt_router(). Date: Tue, 30 Jan 2024 22:40:37 -0800 Message-Id: <20240131064041.3445212-2-thinker.li@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240131064041.3445212-1-thinker.li@gmail.com> References: <20240131064041.3445212-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 Wed Jan 31 06:40:38 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: 13538781 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yb1-f178.google.com (mail-yb1-f178.google.com [209.85.219.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A5B063E496 for ; Wed, 31 Jan 2024 06:40:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706683250; cv=none; b=YUcHVDsjlrQskjI6ZEYdO/EKBEvGjBG5CSlRr+7QLNvDSjg3y2nNGLb+xRhS/VF1PRkJBsVcAfQB9TrQiBxM+ay/u256mvIlgamCfqTFZUqrBnsEdn5Mz+pwEOEGTjBGN9SGb5B7jA5Pf3KqNwDh87wXvfubVlUKLb7Ciyrfz/E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706683250; c=relaxed/simple; bh=UICTwqsBFDrXmAIgYZVBQMDeLjA/8fIOmmrguJ8MdYM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kY+hYq9vrA6KE+H/hBodi52gKKwe/6lggTor/OvMFfLlvb46ZyVNjonKQc/0a4Ik7ICWILDo6usn8JR/zxys1u7uRrkP6VUAj5t33XGEdMjty16tOWutF+5TA8vGurt0BXV6eBabI2xoxbe+A0UNZP8lWHC1JmRpLcl56i/q5ps= 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=f724HpMR; arc=none smtp.client-ip=209.85.219.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="f724HpMR" Received: by mail-yb1-f178.google.com with SMTP id 3f1490d57ef6-dc223d20a29so4416806276.3 for ; Tue, 30 Jan 2024 22:40:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706683247; x=1707288047; 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=hjNf2dCaNYpLB7TRGn31e6KV5r+kwnaQBIfaig0u3eU=; b=f724HpMR/h41w2nuF5pZyphJqtwLfHYK806azQtefrandv16zeJJCImMGzdsXDg/6i q8jF6jmNZtfmaKXOnmcDsHfWrASy35SMASSXcmKhf+AbySs1LPYQnA4+0jemmp/Z1In9 P94bqNGvWMQA/2sHl0li3NeFclQGG4goPCKPDDRkhk1N49forfnHsu84u4AlDXmQNoL9 k4BzwwYzJ+30RjaGZlh3lMTCOmdjQnGE14oCslK7wFlHxOl1OntvKJ0saTTzZ73mr/Ee 6WPhb0a1fX5Mnos7zbj5S0Q62+UgBqzsvM1rOR15R/Dnme6YiEIc13OvEK3Cr3PWNIib aa5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706683247; x=1707288047; 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=hjNf2dCaNYpLB7TRGn31e6KV5r+kwnaQBIfaig0u3eU=; b=dpC1UdLYQrVk91ofo8PzNLF/b/qNAZeiz9CbYu8CjIQR9z3svCPH3o4I13zS+1dIoi T4XjbdL9ert2pIZDc6BCgKKO9+scTUzGJkt345mxeWg0PBgdthKYf60ZNUbsefuxpD9f ouAlBe13Km2WlleSqmkVnUPY7XZUu7Y4/Pu/pAKFmANK4Nq89Vkltrot0SiaOPvzmVO3 daoeapg/XDmbdCKJfc61hc5JsSxwgHMhrKu859HH1jxDDx95AImMPZ/n4t2rX7OMZhcK 4li4lltn+LZXUdzUlXYJLkDEl36Z1Ma4aXiyZcPaL7cF0YbaeIwDpftm2g/PRnU18bFy xutg== X-Gm-Message-State: AOJu0Yx82eOXtL786pdxCQRb9Wbeu3tg7Hwxc2r3FX+tt6bP5npsfq9z tcXcGcoSFBTXAezrMaW9AVnj5PqW73CXeE4Hqe3T+LL81NaMKEk2Yzg0fdeJYkk= X-Google-Smtp-Source: AGHT+IFZG73APVMZR6jRsyp7l5wvAuxTthqU3G620TsFuSn592ADhrbFuy2BzPs2zXu0QPKqSbHlxg== X-Received: by 2002:a25:abc1:0:b0:dc2:82b0:1686 with SMTP id v59-20020a25abc1000000b00dc282b01686mr1002591ybi.33.1706683247401; Tue, 30 Jan 2024 22:40:47 -0800 (PST) Received: from kickker.attlocal.net ([2600:1700:6cf8:1240:7a8:850:239d:3ddc]) by smtp.gmail.com with ESMTPSA id y9-20020a2586c9000000b00dc228b22cd5sm3345683ybm.41.2024.01.30.22.40.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 22:40:47 -0800 (PST) From: thinker.li@gmail.com To: netdev@vger.kernel.org, ast@kernel.org, martin.lau@linux.dev, kernel-team@meta.com, davem@davemloft.net, dsahern@kernel.org, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, liuhangbin@gmail.com Cc: sinquersw@gmail.com, kuifeng@meta.com, Kui-Feng Lee Subject: [PATCH net-next 2/5] net/ipv6: Remove unnecessary clean. Date: Tue, 30 Jan 2024 22:40:38 -0800 Message-Id: <20240131064041.3445212-3-thinker.li@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240131064041.3445212-1-thinker.li@gmail.com> References: <20240131064041.3445212-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. Signed-off-by: Kui-Feng Lee Reviewed-by: Hangbin Liu --- net/ipv6/route.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/net/ipv6/route.c b/net/ipv6/route.c index 98abba8f15cd..dd6ff5b20918 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -3765,8 +3765,6 @@ static struct fib6_info *ip6_route_info_create(struct fib6_config *cfg, if (cfg->fc_flags & RTF_EXPIRES) fib6_set_expires(rt, jiffies + clock_t_to_jiffies(cfg->fc_expires)); - else - fib6_clean_expires(rt); if (cfg->fc_protocol == RTPROT_UNSPEC) cfg->fc_protocol = RTPROT_BOOT; From patchwork Wed Jan 31 06:40:39 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: 13538782 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yb1-f172.google.com (mail-yb1-f172.google.com [209.85.219.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 74E7C4E1C4 for ; Wed, 31 Jan 2024 06:40:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706683252; cv=none; b=I/lCAnGVCfBK6D3l8MafIWQe7T+yGC0yq2F/9AJQnoKS7oYW3gCN4AnCDl26pWRu6DqTe5ZqKp8wK8yV1qG13lpzO95KoAOChUTeWMX0NesNpqHB5tbgWJl8KONVenVj2+YrsmYgY8iIIhULdaC9PGXLfYjPQ/eORz4m7p/jGNk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706683252; c=relaxed/simple; bh=kh1xPEd8CvmvQvaCxYMmlihBYNDgzZREcao8Rc00jbM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=XD48Lel2JsLl5x2ub0C5O5sMaBgqzqXDt0Sd4n5HJ00iwMGvEGEpUb2HaNSchjSVUiLFxIDC8WIVkCa9H5tpReH9QfOY783qTNhTL6BktoRDMYGF7+PwiH/4UMbJZkdXu3rgZuOcnfHezIIJm1n5MkowwAAvnRu5dpxI6HTd60Y= 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=AJKU2W0x; arc=none smtp.client-ip=209.85.219.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="AJKU2W0x" Received: by mail-yb1-f172.google.com with SMTP id 3f1490d57ef6-dc372245aefso3878551276.2 for ; Tue, 30 Jan 2024 22:40:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706683249; x=1707288049; 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=AJKU2W0xxHyYDrLn0VlnQaV2Z4+iHjC+AtPZCCJnv0nNum1shzgCHN/wjt5AGPMERY 4LFrwzLGH87fCV7MofAn5DV6Dv3LroMxABQeHtVvwvcWIekWSfsxpwBv2H3xC7QcpYXf 4pWuTZ6dEyVIU9YeXNuf+NITjFrtbZwmfiQ87i12sx0j57L59xNCplwRj+SAtfpOxms7 G9X7cWqgTJwsHX6S391ErHWRsb2p4rVOhlguvRLw386b3LTdmnb5fgGdOsfmUBlEQSit lRccqAigX+5y08FaCkKLI5jnFrHQ/iRVmT4ssimzQuc2tblKbN+q0qNGwXBKosvD5dRh R98Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706683249; x=1707288049; 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=CxSUKWLiZShx+iRhMpgoAXh9HSAUJuIkhHoOn++OhYPCUtM4v33JlDd6KdGl7A3zMI 2KlsnWW+EEOzMCWgZP+kQSCRxYFv9Uf4k/j9NLK1JVGsSCYO58AvWBvC1wuvI0jy/OXV ibOj0tKuoSzFTDtmECYtxvlmOkWq5yQ6KRPyTlQgeeVBsaO8Xkfzc2epRQ9jQm3DLAxL anpeAqgW5ZUmoL2pk0MaPH9enviYTG992hY/Sb7gXgXzEl8SIbd6WY3/pCemZIEA35MG Aej1bl3rrjBWkDGe8gCIeMzRXXslq1HdrfnHJJ+57z0CcZ4hOzaMbCxHShMdYc6QcsCg 5hUg== X-Gm-Message-State: AOJu0YxY0fzURxijW8TfEpMQUh7pYM2jrjo/YkuXjOUMAHysEYVpubyj QsPSTOJVODCdhhDf30vKFiCv2eoVMyLIOK92sncsHatqiJ9TVDmkg7obyfdrmXA= X-Google-Smtp-Source: AGHT+IEVrGsA8Ki3fHiWjFZOZR8Ek/CNTzyFhZFStTEzo3R7o3oWbIHzcD8t0AyW0s6dzqN9xLsOGQ== X-Received: by 2002:a25:a2c3:0:b0:dc2:53b0:6353 with SMTP id c3-20020a25a2c3000000b00dc253b06353mr767777ybn.38.1706683248765; Tue, 30 Jan 2024 22:40:48 -0800 (PST) Received: from kickker.attlocal.net ([2600:1700:6cf8:1240:7a8:850:239d:3ddc]) by smtp.gmail.com with ESMTPSA id y9-20020a2586c9000000b00dc228b22cd5sm3345683ybm.41.2024.01.30.22.40.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 22:40:48 -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 3/5] net/ipv6: Remove expired routes with a separated list of routes. Date: Tue, 30 Jan 2024 22:40:39 -0800 Message-Id: <20240131064041.3445212-4-thinker.li@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240131064041.3445212-1-thinker.li@gmail.com> References: <20240131064041.3445212-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 Wed Jan 31 06:40:40 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: 13538783 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yb1-f179.google.com (mail-yb1-f179.google.com [209.85.219.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 9F8E93E496 for ; Wed, 31 Jan 2024 06:40:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706683253; cv=none; b=N4vMTlTu4kFfnOir/nsm+K1AYtWf7ZUaODJFk/PGE1+emRfDk/Djvk+AXcq3o2OzOFnKnHItU55vbroiBtX3QMFKktPDcN7fM4nzd3m9njZl4iuna4mxL0kaYAdRFsvvNw5B3Dejpbd7S6ThIUjuLPbTwaf+jz2D5UWZGSbQdsg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706683253; c=relaxed/simple; bh=HRqkCqxtBKrUms3XCHQMXqP+vqbRKLRoHOHl89isBsQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Fuy0NudmAlR65Zo/NGpz38k7pxjOyvpTCt6NXhtrbUJmKEyZXLH0lLJQavfboBbA6dbvglW4j8HzwctZCho9AZMjyWhzcNqsDjP7FwBrPT7j1p/mO93loMDWPOKgfM1x5gxRNeYpNA72fn81p7kj1+CzZxL/PG8wTMCKsIeprlg= 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=IoHO5YDQ; arc=none smtp.client-ip=209.85.219.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="IoHO5YDQ" Received: by mail-yb1-f179.google.com with SMTP id 3f1490d57ef6-dc6782e92c2so2472614276.3 for ; Tue, 30 Jan 2024 22:40:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706683250; x=1707288050; 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=IoHO5YDQFkdN2z0uoR4o81+6ATDnc28f+qVUG5WYm1fJVsVxiztWVazF3z26ZaLAhm XDqHA7atH9U9XA+K2VOdV2IQRTml/ZJur1qeKcQ/rKorWtuRAOOWgXmURo1rUb0vNXsP thc7ydvEh7U6xCCFZdK189rirY1CnZRL1bR1Skps9peeOS4o5WIPvu3uXDenwjegIBJJ VjbZQoGarmPImj+J6Hgz0zqCztILFLzr71NLiazvbQCBU0hRvdmPrsY3O62jPUGk45RX EE9zUnDLY+jtmtLbBVi3QJrS0uwiqWownYoI2/Ai2lQnQBL4ORK96yzX+eO1N5gunH8Q imqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706683250; x=1707288050; 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=H4Q9BzVvVEwjkqN1PYyfH8g9Bu/nHQk3BkVJ5hh1q+NpGzh3aNJw1YAmSi3gdEKYAM h0ZFxQD7wWR79X79gpT1EWH9jxbYGx2EkfB1+TttdBTYtOpTrspzn6UYH6tM92vxSPMC KMWExKXx/DhDMOmHiT92/OTcX8zNsUGAS5UyXXsphqHy86kENbVXRWJsOgmIg3kutn1a I4ZEIENZ6oQvajjqQuZFBHp5IFC6dq0goYyAYIrARg0YHsfryLXiWwdJAUlC4AzylitL 7x86NLrHyjTs24mZr0XssD0EZUCkyaYnx649ysUwggcf1gjwPcEAbk0rEoeeqBrLvc8b 4ijQ== X-Gm-Message-State: AOJu0Yw8iUtgSA3OVszhSEof3rtKajWzzrBdTLd/diWrzkH7jKb/thK8 wz41T9tl52A11B5UVuoWmwdFgX9LhI2ixC9kNpGB8j2OzYww5V/Yfc2poS06rcE= X-Google-Smtp-Source: AGHT+IEWlold55DZ4Ci3uoWB/dFaNf17WDA5928PGY/Zg3xPpzFFDUHQbdCWH6z71HyqNAP+Bah0QQ== X-Received: by 2002:a25:aacb:0:b0:dc2:4e83:e6be with SMTP id t69-20020a25aacb000000b00dc24e83e6bemr747922ybi.46.1706683250155; Tue, 30 Jan 2024 22:40:50 -0800 (PST) Received: from kickker.attlocal.net ([2600:1700:6cf8:1240:7a8:850:239d:3ddc]) by smtp.gmail.com with ESMTPSA id y9-20020a2586c9000000b00dc228b22cd5sm3345683ybm.41.2024.01.30.22.40.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 22:40:49 -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 4/5] net/ipv6: set expires in modify_prefix_route() if RTF_EXPIRES is set. Date: Tue, 30 Jan 2024 22:40:40 -0800 Message-Id: <20240131064041.3445212-5-thinker.li@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240131064041.3445212-1-thinker.li@gmail.com> References: <20240131064041.3445212-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 Wed Jan 31 06:40:41 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: 13538784 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yb1-f174.google.com (mail-yb1-f174.google.com [209.85.219.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DC7F44F8A8 for ; Wed, 31 Jan 2024 06:40:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706683254; cv=none; b=B3l+B4kQGneffrACsXbpBGBvsR/KEqBCZFcq35fMQF1XGIrIRhpmx8ssGXUColBWquNb3kv2oDMV129XaqE3VLtqJEfn9jV2G7oDlxgcdj0RZ0z1mULXUbV0uSVHP85jiXdeqSNQts3hcclXAvzbq95MKG0sXFy8z2C91m97SuQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706683254; c=relaxed/simple; bh=Ip3ont9EKGXbKqI4w+atvsRqqkJ8oRnmkodbu6cwvjg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=henMU0p0eDIjquuSbWwJ/Z3Sklk8pKTj0+/kDg16Un3blLw2bqvK13n6ng8Lxb0xSt2jYwSjR1V0I85LBwfCQ4+Ue33qEzQgqy3IAlutux8FV1BkYSt2Xa+w85MlFr3C/1vJyIUGNXl4C267/VUC4kIyiMtHytqw7lyvcK6xzh0= 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=c936dJdS; arc=none smtp.client-ip=209.85.219.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="c936dJdS" Received: by mail-yb1-f174.google.com with SMTP id 3f1490d57ef6-dc6c3902a98so104338276.1 for ; Tue, 30 Jan 2024 22:40:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706683251; x=1707288051; 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=Ho0Ox6SO1ixDdJOhOQI40PynCxm/m/ILX7aiBBia5rQ=; b=c936dJdS+klt0g7Gfqk/Mppy7C2yc9+MUuG+HEpZgCtbA7AxXE7PCak1Qh6QKPXDT8 5BhTZN/oSAGMAr2aasFtofZmiCYj1MRwZO1hpYSCEiqLZ8lmhYkCA4llMd0wgUrbB7/1 kPjgShdOn+F5AMnkrncIzh8yntMXnHN5RzIQ6gQWbR1MgFEAjoNx5OVAd769Zt0KKSSF utLy5LNS7RmGDLbYDbOt9Mf2pvQqsPEk/eS+SYHgC5iXgLRAb5hJv8DfxI2nXJ8auQpp poWaFBh+N+on1cVG6DR8qDZTOfe/vSumfrxUiTOQLMu6YTdrse5qUh9IOQhqeoG5AGmp 1g2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706683251; x=1707288051; 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=Ho0Ox6SO1ixDdJOhOQI40PynCxm/m/ILX7aiBBia5rQ=; b=TmMzA+W5txANupwRD6AqSWDWc6wz60eQPZYN/3uGJ8TMRpRxLVv7rv5C1kRCqvZJcs RaHIBGiawqKudXGu+KXRzFCLdEzQco3xcZLdcq/RlizT9P8I64Lew2Ynf+zOdBn2gxNe hRNWUNKFaKNw7kCOxNiYqU3vJOiBvQ4SaYKm3qXF4wUgu/u75ScbHPK4l2J5yzfC5EXF icRyxCxzievtnfaTy4VAr5OAJCsGvmj3dnvK190/mcDTMExLBcX6RaYt89QgXX+gkwSa G4Jvkq4ioPFgO8pr74RGy/1g2rIwJ9KrafIUujpQnX4Hwl7HHPnngWBeHIgXaxaH2JGq yTmQ== X-Gm-Message-State: AOJu0Yy10JDb+28V+tRG4Y5sA7QOd3IK7wXb8ay/TAMBKfYB9T8ZWaZa NS1lWIU61UcUEQERzxgKgQFuMyYiNXO0BSavsgIXhg+gKmSgH3pp/Gf2wEghLd4= X-Google-Smtp-Source: AGHT+IH+3CxGJXsDfO7gX8PlgCIhLIlIelEX0vPevI89GfHGOFpXbJh9/dSAztyQdqKtWxlxRgNOug== X-Received: by 2002:a25:2fc1:0:b0:dc6:54c5:2862 with SMTP id v184-20020a252fc1000000b00dc654c52862mr780064ybv.3.1706683251556; Tue, 30 Jan 2024 22:40:51 -0800 (PST) Received: from kickker.attlocal.net ([2600:1700:6cf8:1240:7a8:850:239d:3ddc]) by smtp.gmail.com with ESMTPSA id y9-20020a2586c9000000b00dc228b22cd5sm3345683ybm.41.2024.01.30.22.40.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 22:40:51 -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 5/5] selftests/net: Adding test cases of replacing routes and route advertisements. Date: Tue, 30 Jan 2024 22:40:41 -0800 Message-Id: <20240131064041.3445212-6-thinker.li@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240131064041.3445212-1-thinker.li@gmail.com> References: <20240131064041.3445212-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 | 159 +++++++++++++++++++++-- 1 file changed, 148 insertions(+), 11 deletions(-) diff --git a/tools/testing/selftests/net/fib_tests.sh b/tools/testing/selftests/net/fib_tests.sh index b3ecccbbfcd2..f69b55304ebb 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 @@ -768,15 +778,19 @@ fib6_gc_test() $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 $IP -6 route add 2001:30::$i \ @@ -788,19 +802,142 @@ fib6_gc_test() $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 100); 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 100); 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 100 ]; then + log_test 1 0 "expected 100 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 100); 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 100); 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 100 ]; then + echo "FAIL: expected 100 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 + + # Without stopping these two services, systemd may mess up the test + # by intercepting the RA message and adding routes. + if [ -x "$(command -v systemctl)" ]; then + systemctl stop systemd-networkd.socket + systemctl stop systemd-networkd.service + fi + # Make veth1 ready to receive RA messages. + $NS_EXEC sysctl -w net.ipv6.conf.veth1.accept_ra=2 &> /dev/null + $NS_EXEC sysctl -w net.ipv6.conf.veth1.accept_ra_rt_info_max_plen=127 &> /dev/null + + # Send a RA message with a route from veth2 to veth1. + $NS_EXEC ra6 -i veth2 -d 2001:10::1 -R "2003:10::/64#1#$EXPIRE" -t $EXPIRE + + # Wait for the RA message. + sleep 1 + + # There are 2 routes with expires. One is a default route and the + # other is the route to 2003:10::/64. + N_EXP=$($IP -6 route list |grep expires|wc -l) + if [ $N_EXP -ne 2 ]; then + log_test 1 0 "expected 2 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 }