From patchwork Thu Feb 8 22:06:49 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: 13550528 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f173.google.com (mail-yw1-f173.google.com [209.85.128.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A6BE54F60C for ; Thu, 8 Feb 2024 22:07:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707430043; cv=none; b=T0TsE1Z7K1rtacM4OuoNeqnr8g9zbIC0mwGMAaYBVtXmBLnnd8c49nGuAkWshFRDcbUveMGNm+UUX2sQveTz7itjwut2WtGmkYs6oCuuKPzNcZAevtlrMKVgQnnvGUeAk2+vK6r3fmgOY7rkWg6vTSMCPhxo6pueTaGlZCgjyIk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707430043; c=relaxed/simple; bh=4tSVrc3lDD9aUoYxlltfLeAwJNFQSEcmRZdoZavUtrI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=dRnNrx1qySFk3fV1ozMkkjVT28cgQTGpZDKvAKaHwd5hVHR7zjFLoSNYCEOUVBmDzNKvmr+N/B6KGDN9zPfEBv8uHwAhuvs1QmVdsZeylKN8V/gltviqckoJ5qCOlmDqAYuXjzuF8zgja3FM0zIj+9EBM72eyOGA6z/Udjubf5k= 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=U2bDGooq; arc=none smtp.client-ip=209.85.128.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="U2bDGooq" Received: by mail-yw1-f173.google.com with SMTP id 00721157ae682-604a1581cffso4161877b3.3 for ; Thu, 08 Feb 2024 14:07:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707430040; x=1708034840; 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=U2bDGooqMo/NwnIkjSHjKqXhedmSMwyjhjhA+lb8wjQBNFIsIQj7GC491YqUh9mVt8 7WYMZ0kBaVZkqx4Q0FwUYH8atk7t5szvVgiM0n7ucOtqIutmIFy098MTts+fILY3YDdo Txhs6kv2cK9nMtYLlKhMRf9m1Zij0Ltcm/7z0IsDqjzIUJZYFJTgH8CzA8n0nxbTLQKr /CJM1zQwUKpQKUo99WAGyqvMHNIvc2Umw8Tox74B2VvpYvjstC5djH94OQargrDfwc22 BP4nQTSh+1s76pqC4lqwa5XbkedfiHujL4fP1AWmK0+LubtO7au9MBx3cPZ3fxAmMCBj COug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707430040; x=1708034840; 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=QEuMienkLRrAjdAXrPeSUo7Ls+7XHiuLKUwZI7WHJgrXP099uCJ1Yau6Co47HYIuXm vNrU5eA/04f5sRNd0DyEG04uT39bvHFx3sj/tzcrnbBykM+n5LXbditXBO+cbuMRVohV oCZS8nTkhPb4MOQpf5z5SA+I2Vz0zZ8hk7/1L05cW/s5rEHwGDnfrxgeJ5DjT+1gu3n2 vnQ7fE90OMlxBa+8MubutQbbkLVJhJa8Jr91TMNhBBtmJ2rnvKwBHfDgUKLyRTSd4y9A tTUFx3V38FqcKRqc7HDK1gYgR9UZthK/QvSsftJ7J2iPdZMMykoLU52hl1zqJuhbI73e Tk2g== X-Gm-Message-State: AOJu0YxXYvd9dBr71Qqu9yJPC3gRR9exBQaVxbgHNoD0d7wfuLP/ID+r +IYj0lVXN6OggQGfluV+0TAZL2uuHBRw4iL1Ye3I1EVJOn3SSx9oK+33uiHr5II= X-Google-Smtp-Source: AGHT+IEuzCb8iOksw/WH1MloFE3Rn8ipz/0Ox25w7S5auRK4Dve+wsihBjLf9Zu0isriOzS7OMSXIA== X-Received: by 2002:a81:918d:0:b0:5ff:5cfd:7127 with SMTP id i135-20020a81918d000000b005ff5cfd7127mr683815ywg.14.1707430040131; Thu, 08 Feb 2024 14:07:20 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCUSpKkwuonOpXlSMLyn/fybXRwq3Vm2Jy9oAMTrpuoqOMSVt9wy1/uPqj/8xlmkMCJZh4EGjH0/RPhNt7bwGRZz8zk5Tz0mxl1d5ctho7aYvB0M73FxkD/yRzVP2KRM8u1V21gUCMNaelS66nGZP2ijxH7b9Wv2twkHeVzw797zwY8Tq7HfOxmmLvlA9yI6FF2QoToFyzzCwYOrTlJ1l3EtgedwMc66zsCMkC3ugw1js+4nSv5Z1f5u6YCRSQnxpZJo9VstClEoDSrsBctMnlI89uakNOdwk4bDNH4SyPfhxc2jaHnS9cSvVOOt/9Vm/8zY132lRExQxO5SDlewfmMDQOkiaKaECaRfxQ== Received: from kickker.attlocal.net ([2600:1700:6cf8:1240:1c58:82ab:ea0c:f407]) by smtp.gmail.com with ESMTPSA id m128-20020a0de386000000b006049e3167fcsm61320ywe.99.2024.02.08.14.07.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 14:07:19 -0800 (PST) From: thinker.li@gmail.com To: netdev@vger.kernel.org, ast@kernel.org, martin.lau@linux.dev, kernel-team@meta.com, davem@davemloft.net, dsahern@kernel.org, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, liuhangbin@gmail.com Cc: sinquersw@gmail.com, kuifeng@meta.com, Kui-Feng Lee Subject: [PATCH net-next v6 1/5] net/ipv6: set expires in rt6_add_dflt_router(). Date: Thu, 8 Feb 2024 14:06:49 -0800 Message-Id: <20240208220653.374773-2-thinker.li@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240208220653.374773-1-thinker.li@gmail.com> References: <20240208220653.374773-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 Thu Feb 8 22:06:50 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: 13550529 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f171.google.com (mail-yw1-f171.google.com [209.85.128.171]) (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 315484F21E for ; Thu, 8 Feb 2024 22:07:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707430044; cv=none; b=GFQ+J5c0zD+KO4dwpTL2RSaHpu20Q22AnepsyocSKGicE9jf18xVP8Uq1WTsaf7Nr2gLq8RzExj8HT38nhgM4Q5x+4lhnJ5KL0Nuh6QoWT1mK4/JT4UPhcPXpItlyeHRFBxgHxsXXdQ+9qI9OV3z1q2myskytGDlVU/VyGAKUfI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707430044; c=relaxed/simple; bh=Zb0KvqSVUFD6trhqRy7c97PHe4hgPnMtl+lYemNh+DI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=AOsDfDKZKJm8laPWAYX2oDB3rC5mwOiPrlEyJjBxYgpSmnOWFsfUIEdcXK/rbAjZDSG2eSC9ILO4IzolPeHXD+uPSHRSxN8dkmlhRq9N/c1GZaKpIi1iG+U7ieBLCyC7+1KYcePl6/PUNB71ipXmm3r3SlhSmOAcVW+LCmInUHU= 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=B6m6tNLa; arc=none smtp.client-ip=209.85.128.171 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="B6m6tNLa" Received: by mail-yw1-f171.google.com with SMTP id 00721157ae682-6047a616bfeso3764477b3.3 for ; Thu, 08 Feb 2024 14:07:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707430041; x=1708034841; 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=B6m6tNLadn/gOivfV/JBYpEeZr7wMdcS1KQqY+Rt24LMKCNFLX1ca1kuHlTryyZZIi 8pH78igj7z1yftQ2Ofv6U3tlr0FEWhAxQYJ0BSYzkBB5QqQLI2NY+woWtTEFn0ZfAg4V v+0clDlrgQo0kWzUUBU7BzyErPOE+QSPoaRnKCNW1dQMqskHDBNpHyxq9ZkFfLhrT8SR ewahJqp+TtKkRmjmUEAXzNJISTeqEx7UGaWMlFiYHHzDzifNbY1qcuaoZPDVwQyySGRQ 7XZqw4kcRrZzDoMHaPNncmx6FbGndxk/kmCpl4ol1xIlAXF7wwykzMXft7HANAoR9dt1 AwUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707430041; x=1708034841; 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=UQ+WLP7BIJIKn3ZqX9Wqajsm3eHp4Rxl8nUcMISgX+QRNcXB/An2nCo6zKje17rFJT uMmjIlmnXB0AaUUPTQ109KcbJwEeCFg8PC9PEvY0Kf6/bhqXWQM9etEkFCmQpzprwwYL i54ed8325wXL6AZyiSixjqPilXj2HyG+X6tVI+s3GWF13zcGjVrl97m4ieF4xI07CcX6 A1QfbliuoPYCnJxo33hPTdiQzyusPz/0zAKkhoqxw+mYC0hAB6fRzdnFGp2UQ5HYrYXO 0pcbBPkHR6xgFzUtF/W6tzJwDzA92UhlKty83TeAkjy74aYYhLihK5XCeZOPqiuWtIp5 aD5A== X-Gm-Message-State: AOJu0YwcF7kM8xY6klguoSb5GVj7vmSRDAaWmtciM0DmJXnePVhE/SoM UJbN6Ic3VUBB79/4PVfZoRgdih/4LmVoE8Gj5KDLzYBt42E8GyelhouYI9DznJo= X-Google-Smtp-Source: AGHT+IE4CHizE6bl/TPYpnwhMCbexjw/nj2L8uKN0qMkFlg2m8xFJUOyvS48AB7l+HkHluMWND1XhQ== X-Received: by 2002:a81:6ec6:0:b0:604:5be:7163 with SMTP id j189-20020a816ec6000000b0060405be7163mr686639ywc.41.1707430041528; Thu, 08 Feb 2024 14:07:21 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCV3KT94QkrJkZouOoc6aZBi0QWKni6NOQApIHs41mMgwMs2w/WRV///rq+kT70aD1J7Ktfz8cqgRuclhh1nlqiRTRdg1zdcsTuw6GQOb/tsSd0LfpBXBbXERaU2qDMnnxNc4ZTvOtv7G3EiNthXx67c6OojuFAq6iV0Z0xWcgcmC32jheh031wYKPVH9MPCCT0zRZsM41iiILiYgkK5MXLMXNGh4tCey3YTnMaJQKSzh19srGCAGqt6PmPDP8dwrkeFW5v1ldePkVrlrqnv5ZaSV6nH3KqKMKvmBIJutw3n7+4eisA1lW24LfUs+AU2VfcQuxX0+ZFS9tDnLEoZANvsbOV1Vkq0eBcYsQ== Received: from kickker.attlocal.net ([2600:1700:6cf8:1240:1c58:82ab:ea0c:f407]) by smtp.gmail.com with ESMTPSA id m128-20020a0de386000000b006049e3167fcsm61320ywe.99.2024.02.08.14.07.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 14:07:21 -0800 (PST) From: thinker.li@gmail.com To: netdev@vger.kernel.org, ast@kernel.org, martin.lau@linux.dev, kernel-team@meta.com, davem@davemloft.net, dsahern@kernel.org, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, liuhangbin@gmail.com Cc: sinquersw@gmail.com, kuifeng@meta.com, Kui-Feng Lee Subject: [PATCH net-next v6 2/5] net/ipv6: Remove unnecessary clean. Date: Thu, 8 Feb 2024 14:06:50 -0800 Message-Id: <20240208220653.374773-3-thinker.li@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240208220653.374773-1-thinker.li@gmail.com> References: <20240208220653.374773-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 Thu Feb 8 22:06:51 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: 13550530 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 6DFE35024F for ; Thu, 8 Feb 2024 22:07:24 +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=1707430046; cv=none; b=ZGulHCNxqLRCxQmDavxD/AjKSjQNAm5iN6gsY8wMOqJ1+mOMC/1jyDYeVnCXbXNRHJYMljePJRPHAElzrxsQJKk6hqo3cTeuguZv3HZ1yZCeWkGBn9oYipvgqU2SFgtBGQZkaVdva6NDqEP4bYww3RDOPB8Hxh68zVVD0xw3ICo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707430046; c=relaxed/simple; bh=/8RjjliBvKi/zKAnw8MUx75V9Iqx8lozrPN6JN3XUFA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=YiOSD+8TggVmcIT/2fD4CBMRVARPPM9c8nkOxu58Z3rKfPYVunqG6OOY3Lr6Gi7aDLj4wZHzBpR8Dut2O9DGflDzlX3EIOFaJSgBKhCilMvlVwG0y4YfVM9F1/CLa+P4E0zpkbqN9W9CCeHJL4mGhjgnV4juLjPtpLx0qoM63FA= 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=PawZXDQn; 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="PawZXDQn" Received: by mail-yw1-f179.google.com with SMTP id 00721157ae682-604ab54bb83so4243507b3.1 for ; Thu, 08 Feb 2024 14:07:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707430043; x=1708034843; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=pBLmUSswsfGUFbq02YaJy6+IZiP7sz7gw1Rb1UaLmZ8=; b=PawZXDQng2mRJNwiRm2RTriyZipo9n2HiOr+wUxkwb1GQ0h4JnM+K4Q8bL5RddsaQ4 JlBklXV6BUS3dyJBynr5qjpQfxXJoO0Bm5ZVXRZ2Yjsp1VHdlGQLfNBQSY2lGGVWl6Fg bzmRyoGzlY9HRCqFyTzmvbUic6SGZhUtMnJftudWkUwDHbgqAJsqznjoLDgYSyPb/nqp DeX9eT9chBg8UX0xiwK8Qq/aV2V6fcOwuGop1FdF1cMh8ujf2tGRotMU8Jwn8gEjtwn8 bHFqV5usF6BMU9pLSq9bcOUa1hfIMtk+WXWM9h4i2VLz+ln0W2efnA13q8J7nMqZziKS tAmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707430043; x=1708034843; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pBLmUSswsfGUFbq02YaJy6+IZiP7sz7gw1Rb1UaLmZ8=; b=aN4y+WOHCqxjeP7MxM8YondRGETBo9lJpsD6Pyo0zZH/JsgqNdbKlBZTkYkIvLpz39 yWd4N/rrZ6Jb/mStgGkcxE94IdNq1e1UVZ8XNd1u2nIeC1yjX8WtWr+Yy+HX/C+iPZjh aYbuiLYYlbSL/WgVHYT8dnhhB1u7kNgnKuQMUp+JDrvTjUOh9FVkRZv7thABSrtemyKL XGlzaQuanH8LXg2vpARovsLHt8QIaNB0ixdjcl1uG5xk0F2CgKxwT5kMV7lBUpZyFIyG t3sn7rl47ZhROqqbJ7i5Al2esFy45EyRsZnt7p4dFLnjY/nf5UkVUv//Ds0AmzJxPu9R rIZA== X-Gm-Message-State: AOJu0Yy5sBIuXGV5NbP+sCfzmmaldINU2oreM0hgESrYYbU9PPXGMC1w N/tXnzIOJclBEjdwgCjqB+IW/W5GAbjs3C9LIxr1DTVbL7Epk5SQ36xMz5mPK88= X-Google-Smtp-Source: AGHT+IGdaVou97BZzBMmw4YR2m31E5qGq8RKZefbnqpOJqRuToZ31IynHcY1mGyGeTR6pKeBs9TUvg== X-Received: by 2002:a81:7bc6:0:b0:604:91b1:5401 with SMTP id w189-20020a817bc6000000b0060491b15401mr723557ywc.38.1707430042918; Thu, 08 Feb 2024 14:07:22 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCXQo6JdtQMf+sHuk8AiI7B0i/YsRbLiJIxuXdVZQ5UgNaZewNfi/QuOOsLUvp4ZSO/v8TjtC1M02P14/nH09VAJmtnE8nGv8Rugf4FiB3ESV9JHQ11aXJKro7E6K+hjlsbBqPLksZdbGxaOaOttJXVoY3UBNR79nWWC9r4gtrNzGSQqbKQiDOKDPsVUvjEADqnNkTvzpx1H23hLKi44M09vxja1NUjlJsHPuloy/6nC4boOMaXz36SY3iLuf40kegvUmqmCLQCOfBtbB/rF8hTrw8faX0Oy9Se/bKzjGg/DIX6fwWhx7vx/du4ksPB1eMbgIBb8Uah0e8lRRRc+9YpoTTMOpE/7Mvg95A== Received: from kickker.attlocal.net ([2600:1700:6cf8:1240:1c58:82ab:ea0c:f407]) by smtp.gmail.com with ESMTPSA id m128-20020a0de386000000b006049e3167fcsm61320ywe.99.2024.02.08.14.07.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 14:07:22 -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 v6 3/5] net/ipv6: Remove expired routes with a separated list of routes. Date: Thu, 8 Feb 2024 14:06:51 -0800 Message-Id: <20240208220653.374773-4-thinker.li@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240208220653.374773-1-thinker.li@gmail.com> References: <20240208220653.374773-1-thinker.li@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Kui-Feng Lee FIB6 GC walks trees of fib6_tables to remove expired routes. Walking a tree can be expensive if the number of routes in a table is big, even if most of them are permanent. Checking routes in a separated list of routes having expiration will avoid this potential issue. Reviewed-by: David Ahern Signed-off-by: Kui-Feng Lee --- include/net/ip6_fib.h | 46 ++++++++++++++++++++++++++++++++- net/ipv6/addrconf.c | 41 ++++++++++++++++++++++++----- net/ipv6/ip6_fib.c | 60 +++++++++++++++++++++++++++++++++++++++---- net/ipv6/ndisc.c | 10 +++++++- net/ipv6/route.c | 13 ++++++++-- 5 files changed, 154 insertions(+), 16 deletions(-) diff --git a/include/net/ip6_fib.h b/include/net/ip6_fib.h index 360b12e61850..323c94f1845b 100644 --- a/include/net/ip6_fib.h +++ b/include/net/ip6_fib.h @@ -173,6 +173,9 @@ struct fib6_info { refcount_t fib6_ref; unsigned long expires; + + struct hlist_node gc_link; + struct dst_metrics *fib6_metrics; #define fib6_pmtu fib6_metrics->metrics[RTAX_MTU-1] @@ -241,12 +244,18 @@ static inline bool fib6_requires_src(const struct fib6_info *rt) return rt->fib6_src.plen > 0; } +/* The callers should hold f6i->fib6_table->tb6_lock if a route has ever + * been added to a table before. + */ static inline void fib6_clean_expires(struct fib6_info *f6i) { f6i->fib6_flags &= ~RTF_EXPIRES; f6i->expires = 0; } +/* The callers should hold f6i->fib6_table->tb6_lock if a route has ever + * been added to a table before. + */ static inline void fib6_set_expires(struct fib6_info *f6i, unsigned long expires) { @@ -327,8 +336,10 @@ static inline bool fib6_info_hold_safe(struct fib6_info *f6i) static inline void fib6_info_release(struct fib6_info *f6i) { - if (f6i && refcount_dec_and_test(&f6i->fib6_ref)) + if (f6i && refcount_dec_and_test(&f6i->fib6_ref)) { + DEBUG_NET_WARN_ON_ONCE(!hlist_unhashed(&f6i->gc_link)); call_rcu(&f6i->rcu, fib6_info_destroy_rcu); + } } enum fib6_walk_state { @@ -382,6 +393,7 @@ struct fib6_table { struct inet_peer_base tb6_peers; unsigned int flags; unsigned int fib_seq; + struct hlist_head tb6_gc_hlist; /* GC candidates */ #define RT6_TABLE_HAS_DFLT_ROUTER BIT(0) }; @@ -498,6 +510,38 @@ void fib6_gc_cleanup(void); int fib6_init(void); +/* Add the route to the gc list if it is not already there + * + * The callers should hold f6i->fib6_table->tb6_lock. + */ +static inline void fib6_add_gc_list(struct fib6_info *f6i) +{ + /* If fib6_node is null, the f6i is not in (or removed from) the + * table. + * + * There is a gap between finding the f6i from the table and + * calling this function without the protection of the tb6_lock. + * This check makes sure the f6i is not added to the gc list when + * it is not on the table. + */ + if (!rcu_dereference_protected(f6i->fib6_node, + lockdep_is_held(&f6i->fib6_table->tb6_lock))) + return; + + if (hlist_unhashed(&f6i->gc_link)) + hlist_add_head(&f6i->gc_link, &f6i->fib6_table->tb6_gc_hlist); +} + +/* Remove the route from the gc list if it is on the list. + * + * The callers should hold f6i->fib6_table->tb6_lock. + */ +static inline void fib6_remove_gc_list(struct fib6_info *f6i) +{ + if (!hlist_unhashed(&f6i->gc_link)) + hlist_del_init(&f6i->gc_link); +} + struct ipv6_route_iter { struct seq_net_private p; struct fib6_walker w; diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index d63f5d063f07..0ea44563454f 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -1255,6 +1255,7 @@ static void cleanup_prefix_route(struct inet6_ifaddr *ifp, unsigned long expires, bool del_rt, bool del_peer) { + struct fib6_table *table; struct fib6_info *f6i; f6i = addrconf_get_prefix_route(del_peer ? &ifp->peer_addr : &ifp->addr, @@ -1264,8 +1265,15 @@ cleanup_prefix_route(struct inet6_ifaddr *ifp, unsigned long expires, if (del_rt) ip6_del_rt(dev_net(ifp->idev->dev), f6i, false); else { - if (!(f6i->fib6_flags & RTF_EXPIRES)) + if (!(f6i->fib6_flags & RTF_EXPIRES)) { + table = f6i->fib6_table; + spin_lock_bh(&table->tb6_lock); + fib6_set_expires(f6i, expires); + fib6_add_gc_list(f6i); + + spin_unlock_bh(&table->tb6_lock); + } fib6_info_release(f6i); } } @@ -2706,6 +2714,7 @@ EXPORT_SYMBOL_GPL(addrconf_prefix_rcv_add_addr); void addrconf_prefix_rcv(struct net_device *dev, u8 *opt, int len, bool sllao) { struct prefix_info *pinfo; + struct fib6_table *table; __u32 valid_lft; __u32 prefered_lft; int addr_type, err; @@ -2782,11 +2791,20 @@ void addrconf_prefix_rcv(struct net_device *dev, u8 *opt, int len, bool sllao) if (valid_lft == 0) { ip6_del_rt(net, rt, false); rt = NULL; - } else if (addrconf_finite_timeout(rt_expires)) { - /* not infinity */ - fib6_set_expires(rt, jiffies + rt_expires); } else { - fib6_clean_expires(rt); + table = rt->fib6_table; + spin_lock_bh(&table->tb6_lock); + + if (addrconf_finite_timeout(rt_expires)) { + /* not infinity */ + fib6_set_expires(rt, jiffies + rt_expires); + fib6_add_gc_list(rt); + } else { + fib6_clean_expires(rt); + fib6_remove_gc_list(rt); + } + + spin_unlock_bh(&table->tb6_lock); } } else if (valid_lft) { clock_t expires = 0; @@ -4741,6 +4759,7 @@ static int modify_prefix_route(struct inet6_ifaddr *ifp, unsigned long expires, u32 flags, bool modify_peer) { + struct fib6_table *table; struct fib6_info *f6i; u32 prio; @@ -4761,10 +4780,18 @@ static int modify_prefix_route(struct inet6_ifaddr *ifp, ifp->rt_priority, ifp->idev->dev, expires, flags, GFP_KERNEL); } else { - if (!expires) + table = f6i->fib6_table; + spin_lock_bh(&table->tb6_lock); + + if (!expires) { fib6_clean_expires(f6i); - else + fib6_remove_gc_list(f6i); + } else { fib6_set_expires(f6i, expires); + fib6_add_gc_list(f6i); + } + + spin_unlock_bh(&table->tb6_lock); fib6_info_release(f6i); } diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c index 38a0348b1d17..805bbf26b3ef 100644 --- a/net/ipv6/ip6_fib.c +++ b/net/ipv6/ip6_fib.c @@ -160,6 +160,8 @@ struct fib6_info *fib6_info_alloc(gfp_t gfp_flags, bool with_fib6_nh) INIT_LIST_HEAD(&f6i->fib6_siblings); refcount_set(&f6i->fib6_ref, 1); + INIT_HLIST_NODE(&f6i->gc_link); + return f6i; } @@ -246,6 +248,7 @@ static struct fib6_table *fib6_alloc_table(struct net *net, u32 id) net->ipv6.fib6_null_entry); table->tb6_root.fn_flags = RTN_ROOT | RTN_TL_ROOT | RTN_RTINFO; inet_peer_base_init(&table->tb6_peers); + INIT_HLIST_HEAD(&table->tb6_gc_hlist); } return table; @@ -1055,6 +1058,9 @@ static void fib6_purge_rt(struct fib6_info *rt, struct fib6_node *fn, lockdep_is_held(&table->tb6_lock)); } } + + fib6_clean_expires(rt); + fib6_remove_gc_list(rt); } /* @@ -1115,10 +1121,13 @@ static int fib6_add_rt2node(struct fib6_node *fn, struct fib6_info *rt, rt->fib6_nsiblings = 0; if (!(iter->fib6_flags & RTF_EXPIRES)) return -EEXIST; - if (!(rt->fib6_flags & RTF_EXPIRES)) + if (!(rt->fib6_flags & RTF_EXPIRES)) { fib6_clean_expires(iter); - else + fib6_remove_gc_list(iter); + } else { fib6_set_expires(iter, rt->expires); + fib6_add_gc_list(iter); + } if (rt->fib6_pmtu) fib6_metric_set(iter, RTAX_MTU, @@ -1477,6 +1486,10 @@ int fib6_add(struct fib6_node *root, struct fib6_info *rt, if (rt->nh) list_add(&rt->nh_list, &rt->nh->f6i_list); __fib6_update_sernum_upto_root(rt, fib6_new_sernum(info->nl_net)); + + if (rt->fib6_flags & RTF_EXPIRES) + fib6_add_gc_list(rt); + fib6_start_gc(info->nl_net, rt); } @@ -2280,9 +2293,8 @@ static void fib6_flush_trees(struct net *net) * Garbage collection */ -static int fib6_age(struct fib6_info *rt, void *arg) +static int fib6_age(struct fib6_info *rt, struct fib6_gc_args *gc_args) { - struct fib6_gc_args *gc_args = arg; unsigned long now = jiffies; /* @@ -2307,6 +2319,42 @@ static int fib6_age(struct fib6_info *rt, void *arg) return 0; } +static void fib6_gc_table(struct net *net, + struct fib6_table *tb6, + struct fib6_gc_args *gc_args) +{ + struct fib6_info *rt; + struct hlist_node *n; + struct nl_info info = { + .nl_net = net, + .skip_notify = false, + }; + + hlist_for_each_entry_safe(rt, n, &tb6->tb6_gc_hlist, gc_link) + if (fib6_age(rt, gc_args) == -1) + fib6_del(rt, &info); +} + +static void fib6_gc_all(struct net *net, struct fib6_gc_args *gc_args) +{ + struct fib6_table *table; + struct hlist_head *head; + unsigned int h; + + rcu_read_lock(); + for (h = 0; h < FIB6_TABLE_HASHSZ; h++) { + head = &net->ipv6.fib_table_hash[h]; + hlist_for_each_entry_rcu(table, head, tb6_hlist) { + spin_lock_bh(&table->tb6_lock); + + fib6_gc_table(net, table, gc_args); + + spin_unlock_bh(&table->tb6_lock); + } + } + rcu_read_unlock(); +} + void fib6_run_gc(unsigned long expires, struct net *net, bool force) { struct fib6_gc_args gc_args; @@ -2322,7 +2370,7 @@ void fib6_run_gc(unsigned long expires, struct net *net, bool force) net->ipv6.sysctl.ip6_rt_gc_interval; gc_args.more = 0; - fib6_clean_all(net, fib6_age, &gc_args); + fib6_gc_all(net, &gc_args); now = jiffies; net->ipv6.ip6_rt_last_gc = now; @@ -2382,6 +2430,7 @@ static int __net_init fib6_net_init(struct net *net) net->ipv6.fib6_main_tbl->tb6_root.fn_flags = RTN_ROOT | RTN_TL_ROOT | RTN_RTINFO; inet_peer_base_init(&net->ipv6.fib6_main_tbl->tb6_peers); + INIT_HLIST_HEAD(&net->ipv6.fib6_main_tbl->tb6_gc_hlist); #ifdef CONFIG_IPV6_MULTIPLE_TABLES net->ipv6.fib6_local_tbl = kzalloc(sizeof(*net->ipv6.fib6_local_tbl), @@ -2394,6 +2443,7 @@ static int __net_init fib6_net_init(struct net *net) net->ipv6.fib6_local_tbl->tb6_root.fn_flags = RTN_ROOT | RTN_TL_ROOT | RTN_RTINFO; inet_peer_base_init(&net->ipv6.fib6_local_tbl->tb6_peers); + INIT_HLIST_HEAD(&net->ipv6.fib6_local_tbl->tb6_gc_hlist); #endif fib6_tables_init(net); diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c index a68462668158..73cb31afe935 100644 --- a/net/ipv6/ndisc.c +++ b/net/ipv6/ndisc.c @@ -1237,6 +1237,7 @@ static enum skb_drop_reason ndisc_router_discovery(struct sk_buff *skb) struct ndisc_options ndopts; struct fib6_info *rt = NULL; struct inet6_dev *in6_dev; + struct fib6_table *table; u32 defrtr_usr_metric; unsigned int pref = 0; __u32 old_if_flags; @@ -1410,8 +1411,15 @@ static enum skb_drop_reason ndisc_router_discovery(struct sk_buff *skb) inet6_rt_notify(RTM_NEWROUTE, rt, &nlinfo, NLM_F_REPLACE); } - if (rt) + if (rt) { + table = rt->fib6_table; + spin_lock_bh(&table->tb6_lock); + fib6_set_expires(rt, jiffies + (HZ * lifetime)); + fib6_add_gc_list(rt); + + spin_unlock_bh(&table->tb6_lock); + } if (in6_dev->cnf.accept_ra_min_hop_limit < 256 && ra_msg->icmph.icmp6_hop_limit) { if (in6_dev->cnf.accept_ra_min_hop_limit <= ra_msg->icmph.icmp6_hop_limit) { diff --git a/net/ipv6/route.c b/net/ipv6/route.c index dd6ff5b20918..707d65bc9c0e 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -931,6 +931,7 @@ int rt6_route_rcv(struct net_device *dev, u8 *opt, int len, struct net *net = dev_net(dev); struct route_info *rinfo = (struct route_info *) opt; struct in6_addr prefix_buf, *prefix; + struct fib6_table *table; unsigned int pref; unsigned long lifetime; struct fib6_info *rt; @@ -989,10 +990,18 @@ int rt6_route_rcv(struct net_device *dev, u8 *opt, int len, (rt->fib6_flags & ~RTF_PREF_MASK) | RTF_PREF(pref); if (rt) { - if (!addrconf_finite_timeout(lifetime)) + table = rt->fib6_table; + spin_lock_bh(&table->tb6_lock); + + if (!addrconf_finite_timeout(lifetime)) { fib6_clean_expires(rt); - else + fib6_remove_gc_list(rt); + } else { fib6_set_expires(rt, jiffies + HZ * lifetime); + fib6_add_gc_list(rt); + } + + spin_unlock_bh(&table->tb6_lock); fib6_info_release(rt); } From patchwork Thu Feb 8 22:06:52 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: 13550531 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f175.google.com (mail-yw1-f175.google.com [209.85.128.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5D5695025C for ; Thu, 8 Feb 2024 22:07:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707430048; cv=none; b=cKJlpJ38EGopFFemG5YYJdd849wsN3zYARZZllLh9A341ytGWH+6HiZnLGZ6H+QPjruKX+2KLPE3wty25+p37+sz0+eCVhCt7swCKJ4WT+Qn9WHRZaO1CfJKiL3sKWdIqee9/cqEme63CptznaXQfJNCzkd8/gs45NyD5T6vWqw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707430048; c=relaxed/simple; bh=iJ2gp3cWSbvHtaHeG7008WxTUZNgYdZaxfLImM+PHDU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=WTMLZOlqtAlngEXuyfHiN5Qs9fXZWwxRpsl9JsFzfYHwwJPRQXdkQuz7vAmS2k8AXinK/Kza8aQmzDfDCAu1S7O/VA8tNaFFlduBzMAm1Voh4muBdLgMsAo7vtt1DEr9E3nkmypmlhL4EnOXECih5VegPUsTyyVESOxhkPnlizg= 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=nMJQ7iJb; arc=none smtp.client-ip=209.85.128.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nMJQ7iJb" Received: by mail-yw1-f175.google.com with SMTP id 00721157ae682-604b94c0556so736377b3.3 for ; Thu, 08 Feb 2024 14:07:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707430045; x=1708034845; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2lRjgwKvhAvYDvsHrHhtQ/wCCCH8o6LGs4SUcgFa/0M=; b=nMJQ7iJb2uXiJJPbz2RG0GYBAvMZ5f97cqxZB0/WegIjRAjadCvJcZ+7MS3aAsGdLr 3XvvYEKMEbwGgeDQO85LL8hyn9qxJlsiAV7Tix+698lfKmWMt9k5sRO1Pu6T7wlyPQCB z34FU7CuDgLlrywYOwD/3HquPzsnKq0qZEiv6CDB4eNJCFdpu9JIOrgZcsTjxPvoYafE uHrCy2fO5S0sLYZWY5qxqSh6h2Fgk9/BX6K2ESPdnApDsfSaVxHyQdxZTct8NQ3bDsTA CF2b0+73D7MDmmqQ7o2DYrMummEVvA7iBTs1zVniagd7PZ98oLxVXYSFFOpx6T3c4+9D uMrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707430045; x=1708034845; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2lRjgwKvhAvYDvsHrHhtQ/wCCCH8o6LGs4SUcgFa/0M=; b=I8Y+dSKmVCulXxIEMLXiWEJZITSCBJMhnxFhzHmUfAYgVhmM/lmoaRB4Hywd28bYwJ rW6ymgvHWc6nQyQ7LLQDC2XWZU1nMGwMz4MwVfXChzktCVSEs4DTQwGC0LkxIbkOxvx3 X/acd7v5AsCJlztrzRwIyl9j7rEUZKk3khGmUYeaWMJG0r5VmKXNm8pLptNIy/WiAsrB qil0VIooZI4N8CFnborvzDtQDCk49hRCg0hWPDB5s9O8e+xc/Qai0/WwAEOexXbuWk8k ydQ8aX2unEjFBeBNgwRCcQqRVJjk9IMJzhx6rwd6DG7Zzh8BZriiXPnNOlwMZyeBSCWi IDYg== X-Gm-Message-State: AOJu0YymlPrI19puv/C9bx2iO0EAuaqbxmjKTCsOGzjuK2lhghpZvUX1 hyxliFpm4oap2A7/aBxPjFDDRD1JSKNrKnqA3b/lrr3BV9ZcQ3gFc09vRvH4P6M= X-Google-Smtp-Source: AGHT+IHSz7efhIyXAgWrc+sNF439FnzpghL0R1sVgZOBRLs11r5Rhl2KqyjgFPxkNxXHvGfzHUHuNA== X-Received: by 2002:a0d:e6d6:0:b0:604:b55:f078 with SMTP id p205-20020a0de6d6000000b006040b55f078mr707405ywe.7.1707430044171; Thu, 08 Feb 2024 14:07:24 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWmtnlkDhOJqwcr11XC93vEC3oCgrrmGJxKTcpEh1B8HjSdU+/R69FxRjnPgUTjleLC+Eu4NFp6tAffOY7eo21QCuOAV4h4Tylv8AVdd+Ul1V0I83mYq+UU/y+WlAzJmfw4cpwSUq4KQT8JhG6ftOMK8+gbAMz4UMwQkiUimW7EALxviHZFH/lXL2mZHqWU1Q44wg2apjopADxWfbocJe+g/+PtPHkshEp4AtwK/40XKp/KAiEAaRiqdUdeU2gzABhZEdee1Iq9Lpf65jUJMH5E1xPV7u4A4GMS94cbfwtnjDvLIBy3kWzf9weQ5IY/tn36p39NE/VKnr7tf3IxrL5VqevmZXBXbsxiyQ== Received: from kickker.attlocal.net ([2600:1700:6cf8:1240:1c58:82ab:ea0c:f407]) by smtp.gmail.com with ESMTPSA id m128-20020a0de386000000b006049e3167fcsm61320ywe.99.2024.02.08.14.07.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 14:07:23 -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 v6 4/5] net/ipv6: set expires in modify_prefix_route() if RTF_EXPIRES is set. Date: Thu, 8 Feb 2024 14:06:52 -0800 Message-Id: <20240208220653.374773-5-thinker.li@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240208220653.374773-1-thinker.li@gmail.com> References: <20240208220653.374773-1-thinker.li@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Kui-Feng Lee Make the decision to set or clean the expires of a route based on the RTF_EXPIRES flag, rather than the value of the "expires" argument. This patch doesn't make difference logically, but make inet6_addr_modify() and modify_prefix_route() consistent. The function inet6_addr_modify() is the only caller of modify_prefix_route(), and it passes the RTF_EXPIRES flag and an expiration value. The RTF_EXPIRES flag is turned on or off based on the value of valid_lft. The RTF_EXPIRES flag is turned on if valid_lft is a finite value (not infinite, not 0xffffffff). Even if valid_lft is 0, the RTF_EXPIRES flag remains on. The expiration value being passed is equal to the valid_lft value if the flag is on. However, if the valid_lft value is infinite, the expiration value becomes 0 and the RTF_EXPIRES flag is turned off. Despite this, modify_prefix_route() decides to set the expiration value if the received expiration value is not zero. This mixing of infinite and zero cases creates an inconsistency. Reviewed-by: Hangbin Liu Reviewed-by: David Ahern Signed-off-by: Kui-Feng Lee --- net/ipv6/addrconf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index 0ea44563454f..ca1b719323c0 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -4783,7 +4783,7 @@ static int modify_prefix_route(struct inet6_ifaddr *ifp, table = f6i->fib6_table; spin_lock_bh(&table->tb6_lock); - if (!expires) { + if (!(flags & RTF_EXPIRES)) { fib6_clean_expires(f6i); fib6_remove_gc_list(f6i); } else { From patchwork Thu Feb 8 22:06:53 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: 13550532 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f172.google.com (mail-yw1-f172.google.com [209.85.128.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 89EFD5025F for ; Thu, 8 Feb 2024 22:07:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707430049; cv=none; b=sAxmmIsHWkxjBce1kjuDuZLjWdO8+Cmpslp6zev+6lKk8NwD3YdisFOYJmIyyeoIf9jBP9Po/oLiWbqQ18I3lAnsVp7ukQRINigdDmfWk17iColQm+lyk8xD1263MEH+qsvTiJI1s0q45O8ITxs7GxmipusWXtCUdo/yS00tYls= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707430049; c=relaxed/simple; bh=6KvdwKAYUNOEx0dLHn/5abYIybKewuWQicN3vsA3JhI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kMIyYPBzrgmdbdztGvKzsRbAXzBWzDb/Sgz9CkSrdqrsvn2KxL4YNQn0OvY92+oXu0mWEJp/g35lwg3H4X7VDTyCA0NF3hpbbLv6dwrjDS6htCLifRDULAL7CpX36swd+Z5f/govt8lGhGjHpV+gW+7giOz3u2amWwK+d6o6yIU= 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=Bd0+yROL; arc=none smtp.client-ip=209.85.128.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Bd0+yROL" Received: by mail-yw1-f172.google.com with SMTP id 00721157ae682-60491b1fdeaso4425577b3.3 for ; Thu, 08 Feb 2024 14:07:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707430046; x=1708034846; 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=G1hbKUlbtkGTDmfJjhu1WKYZnsnwJfdOfPThlA7N/jg=; b=Bd0+yROLR/Gpmk52QutLe2zi8GmtHc6Vzumuiwnv2vhtJWJq0PIXg1hZ8g3qRACg7F GYJqcAbWYo5rHlzAYt6wODsDF/a/nx+EhnKFScMDL9fuQ14IrRLuvyQAPZDHuCB5mLFU 9lzXv1kfFeJWpO4+tDnAKfYx7NW1XGGD4oW2fLH4n2hV2wLYl1LqJg4yU/CbtId9Nb7k svh1UVYSRz/Y7ltm3J27SfQhM5rYORqz9CWWuBDkqYAv6v+Jyx+r6kErvjHtEkQsf9Jx JKiQ1dolbooXr/8eFRgvwT9OCGV8/k+ga8DLJgOFNxz75NIK/ZrcXhc/vDB68WnsHz02 Ux9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707430046; x=1708034846; 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=G1hbKUlbtkGTDmfJjhu1WKYZnsnwJfdOfPThlA7N/jg=; b=n6RqGhBLYRDKwbh2/wPd3cpxeT12rJaLEe+mDARaI1wX+zqKre2snRVVXJ8UmN0kdf c9AXVFCK8v8hkxwVeNE4qug7H+SO9ZgnzLadzg2exm87E8VG1drBxKirM7gQSf1gUDHD 3Y66+dcv1Pr30f04dAIp/hfKCEsHmAx3SUXTAiijiLD0cORuNa2ceprGNq7EeH1BwNyT gS7DKoLti34it+GFJNqghDjm4YLDSeg+ESB5iNg1+5k4HxP69py7R7CZkFJ77oXXdISE KLJXFSD86k+HPVdGqtlyGmzzkVfRybHPbtyUOW8wh2jjEdtRwv41wbIiv7dTWpQpKun+ v+aQ== X-Gm-Message-State: AOJu0YzeNv6PEpeCVFcUYiAUWK4auAtV29y+PUpJ0u8J09pPevy9GVFt CkbJjOzfk2SQot9hprSCL9kXtB8PSl/OSLlFIdntTtUtQ3LA8rBk63J20xQct58= X-Google-Smtp-Source: AGHT+IEl1xMhf3p0reD05U3MRSpLpwhWAkWT3uGyTCKRDd20pcqxB1/Cx8T/TM0IsrhVsIboObEnjQ== X-Received: by 2002:a81:dd09:0:b0:5eb:3851:2bba with SMTP id e9-20020a81dd09000000b005eb38512bbamr704311ywn.41.1707430045957; Thu, 08 Feb 2024 14:07:25 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCVWeO5NiQT5zgb+w5nEcfr5AP7xrKGcRniYBcH6Z3us82LUAuRk7HDLgXgA4wGZmoNAhHnHtVFUp8nqoT9r+2tVJd8H4xl8sN3ribOOvFjJ8dBM43VNRasRRgvzMvSYto20ZsPSM6bImEjKO47wwZKVPB2AUXlU/okqmCCch8ebQ4getATrDmq5Grom2ALfLV9seOd9pAirV370rXeiR6paJvvUtc0nFRZhMZBIOKAqDHf6DG46O2DyqGXj/ZnFkWyNNLMOICxXAa2ewDGMP9PuUdE1ji2MI0SSkYfbTIYpCD/zyzu6lJ0ViiSwYHW0vv2OAkzRARIcNWsj4bX0a/dO390lTGFGuceFWA== Received: from kickker.attlocal.net ([2600:1700:6cf8:1240:1c58:82ab:ea0c:f407]) by smtp.gmail.com with ESMTPSA id m128-20020a0de386000000b006049e3167fcsm61320ywe.99.2024.02.08.14.07.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 14:07:25 -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 v6 5/5] selftests/net: Adding test cases of replacing routes and route advertisements. Date: Thu, 8 Feb 2024 14:06:53 -0800 Message-Id: <20240208220653.374773-6-thinker.li@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240208220653.374773-1-thinker.li@gmail.com> References: <20240208220653.374773-1-thinker.li@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Kui-Feng Lee Add tests of changing permanent routes to temporary routes and the reversed case to make sure GC working correctly in these cases. Add tests for the temporary routes from RA. The existing device will be deleted between tests to remove all routes associated with it, so that the earlier tests don't mess up the later ones. Reviewed-by: Hangbin Liu Reviewed-by: David Ahern Tested-by: Hangbin Liu Signed-off-by: Kui-Feng Lee --- tools/testing/selftests/net/fib_tests.sh | 151 +++++++++++++++++++---- 1 file changed, 129 insertions(+), 22 deletions(-) diff --git a/tools/testing/selftests/net/fib_tests.sh b/tools/testing/selftests/net/fib_tests.sh index b3ecccbbfcd2..3ec1050e47a2 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,114 @@ 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)) + $NS_EXEC sysctl -wq net.ipv6.route.flush=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)) + $NS_EXEC sysctl -wq net.ipv6.route.flush=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)) + + $NS_EXEC sysctl -wq net.ipv6.route.flush=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 }