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;