From patchwork Tue Sep 19 18:04:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Patrick Rohr X-Patchwork-Id: 13391756 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 876E6347B9 for ; Tue, 19 Sep 2023 18:04:17 +0000 (UTC) Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91FD58F for ; Tue, 19 Sep 2023 11:04:15 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-59c09bcf078so53954887b3.1 for ; Tue, 19 Sep 2023 11:04:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695146655; x=1695751455; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:from:subject:message-id :mime-version:date:from:to:cc:subject:date:message-id:reply-to; bh=jEgqvZiSH68NpWe0D7XgUQ1V+edtJDC+LxT01O0evxo=; b=ejdF7mih8/YAH8Th1kqjgqNWUpi8JwdNTB/eEtbbsOZmzoapgytq8ZtYbP8hYuSAQI y9G6cK6LjJMKmhkDusOzO7LS2FJz5dM2luimOajH6f0LxVv7EBzvSuO4uixQCHrcULF5 6/GmQa+9gCdYmj/BKzk6FUJzt7JVbiCw4Ub6tCVaeTstFRnyKqX1cggFoi4cht4DumIv CIp3Sdu+iCRWQCks6b9eO30AJdLBod7eCym4IMqBdydMZ77f5Yi4H02ZEqHvsiFkoadm LeWkO3Zyw5/DSQQb9VdSai6vTv3kbBg7Jc5BlETsJAfeIEBWzP/Xk2Ck4WYJemPrLI88 xC0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695146655; x=1695751455; h=content-transfer-encoding:cc:to:from:subject:message-id :mime-version:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=jEgqvZiSH68NpWe0D7XgUQ1V+edtJDC+LxT01O0evxo=; b=wjYK8BK3Ja2NXct54nlkPble79E9i8HCsQLdYzIMqmXgRgQKzN5w0of/KpjJjpmjcO paPLzi/C1SkFR1O7qYLaXsl7FQckz6LhUNAjLeTKsmSS5hbhgwY3fjwz8C3x6rXOJRpa z2rt/hSV9FYOtjw81ZXN9dlPwUOxco1KYsTfIds8cTheL0avVQ5LhwOBisH9eKUr1R7T +f1e9rEvP5JaZ9UywakSoOX23R4bCKdX6oSqrX0cwEs4T9CQZfp7bPt40/cl0KJbb+rF mcppf6AvJvttjsXTogKnjKDZj9mgyJTDwWBjWXLEkTl1gqFxw7ErognTiSobmGJBAidl fG/g== X-Gm-Message-State: AOJu0YyJw9QXlB5EJUk6UkTmBBZPKx4FYQohatHIqwXy4h61CuhWm/dv 1aqKCRe5hkDDrsS5GspsqANctkZXdA== X-Google-Smtp-Source: AGHT+IFcNXmRnswPu6dB3Nz7y+c9ZAPzTby2KWItlOHpI6LJ2wY1E/WxeWhEZTlu+0QjQ/xt23KwKaaybA== X-Received: from prohr-desktop.mtv.corp.google.com ([2620:15c:211:200:3922:8ca0:e419:5554]) (user=prohr job=sendgmr) by 2002:a81:4512:0:b0:59b:b8bf:5973 with SMTP id s18-20020a814512000000b0059bb8bf5973mr5396ywa.0.1695146654850; Tue, 19 Sep 2023 11:04:14 -0700 (PDT) Date: Tue, 19 Sep 2023 11:04:11 -0700 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.42.0.459.ge4e396fd5e-goog Message-ID: <20230919180411.754981-1-prohr@google.com> Subject: [PATCH net-next v3] net: add sysctl to disable rfc4862 5.5.3e lifetime handling From: Patrick Rohr To: "David S. Miller" Cc: Linux Network Development Mailing List , Patrick Rohr , " =?utf-8?q?Maciej_=C5=BBenczykowski?= " , Lorenzo Colitti , Jen Linkova , Jiri Pirko X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org This change adds a sysctl to opt-out of RFC4862 section 5.5.3e's valid lifetime derivation mechanism. RFC4862 section 5.5.3e prescribes that the valid lifetime in a Router Advertisement PIO shall be ignored if it less than 2 hours and to reset the lifetime of the corresponding address to 2 hours. An in-progress 6man draft (see draft-ietf-6man-slaac-renum-07 section 4.2) is currently looking to remove this mechanism. While this draft has not been moving particularly quickly for other reasons, there is widespread consensus on section 4.2 which updates RFC4862 section 5.5.3e. Cc: Maciej Żenczykowski Cc: Lorenzo Colitti Cc: Jen Linkova Cc: Jiri Pirko Signed-off-by: Patrick Rohr Reviewed-by: Jiri Pirko --- Documentation/networking/ip-sysctl.rst | 11 ++++++++ include/linux/ipv6.h | 1 + net/ipv6/addrconf.c | 38 +++++++++++++++++--------- 3 files changed, 37 insertions(+), 13 deletions(-) diff --git a/Documentation/networking/ip-sysctl.rst b/Documentation/networking/ip-sysctl.rst index a66054d0763a..45d700e04dba 100644 --- a/Documentation/networking/ip-sysctl.rst +++ b/Documentation/networking/ip-sysctl.rst @@ -2304,6 +2304,17 @@ accept_ra_pinfo - BOOLEAN - enabled if accept_ra is enabled. - disabled if accept_ra is disabled. +ra_honor_pio_life - BOOLEAN + Whether to use RFC4862 Section 5.5.3e to determine the valid + lifetime of an address matching a prefix sent in a Router + Advertisement Prefix Information Option. + + - If enabled, the PIO valid lifetime will always be honored. + - If disabled, RFC4862 section 5.5.3e is used to determine + the valid lifetime of the address. + + Default: 0 (disabled) + accept_ra_rt_info_min_plen - INTEGER Minimum prefix length of Route Information in RA. diff --git a/include/linux/ipv6.h b/include/linux/ipv6.h index 5883551b1ee8..59fcc4fee7b7 100644 --- a/include/linux/ipv6.h +++ b/include/linux/ipv6.h @@ -35,6 +35,7 @@ struct ipv6_devconf { __s32 accept_ra_min_hop_limit; __s32 accept_ra_min_lft; __s32 accept_ra_pinfo; + __s32 ra_honor_pio_life; __s32 ignore_routes_with_linkdown; #ifdef CONFIG_IPV6_ROUTER_PREF __s32 accept_ra_rtr_pref; diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index 47d1dd8501b7..edfb450e5893 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -204,6 +204,7 @@ static struct ipv6_devconf ipv6_devconf __read_mostly = { .accept_ra_min_hop_limit= 1, .accept_ra_min_lft = 0, .accept_ra_pinfo = 1, + .ra_honor_pio_life = 0, #ifdef CONFIG_IPV6_ROUTER_PREF .accept_ra_rtr_pref = 1, .rtr_probe_interval = 60 * HZ, @@ -265,6 +266,7 @@ static struct ipv6_devconf ipv6_devconf_dflt __read_mostly = { .accept_ra_min_hop_limit= 1, .accept_ra_min_lft = 0, .accept_ra_pinfo = 1, + .ra_honor_pio_life = 0, #ifdef CONFIG_IPV6_ROUTER_PREF .accept_ra_rtr_pref = 1, .rtr_probe_interval = 60 * HZ, @@ -2657,22 +2659,23 @@ int addrconf_prefix_rcv_add_addr(struct net *net, struct net_device *dev, stored_lft = ifp->valid_lft - (now - ifp->tstamp) / HZ; else stored_lft = 0; - if (!create && stored_lft) { + + /* RFC4862 Section 5.5.3e: + * "Note that the preferred lifetime of the + * corresponding address is always reset to + * the Preferred Lifetime in the received + * Prefix Information option, regardless of + * whether the valid lifetime is also reset or + * ignored." + * + * So we should always update prefered_lft here. + */ + update_lft = !create && stored_lft; + + if (update_lft && !in6_dev->cnf.ra_honor_pio_life) { const u32 minimum_lft = min_t(u32, stored_lft, MIN_VALID_LIFETIME); valid_lft = max(valid_lft, minimum_lft); - - /* RFC4862 Section 5.5.3e: - * "Note that the preferred lifetime of the - * corresponding address is always reset to - * the Preferred Lifetime in the received - * Prefix Information option, regardless of - * whether the valid lifetime is also reset or - * ignored." - * - * So we should always update prefered_lft here. - */ - update_lft = 1; } if (update_lft) { @@ -6846,6 +6849,15 @@ static const struct ctl_table addrconf_sysctl[] = { .mode = 0644, .proc_handler = proc_dointvec, }, + { + .procname = "ra_honor_pio_life", + .data = &ipv6_devconf.ra_honor_pio_life, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = proc_dointvec_minmax, + .extra1 = SYSCTL_ZERO, + .extra2 = SYSCTL_ONE, + }, #ifdef CONFIG_IPV6_ROUTER_PREF { .procname = "accept_ra_rtr_pref",