From patchwork Fri Feb 9 06:10:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Henrie X-Patchwork-Id: 13550887 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.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 E3B7C57306 for ; Fri, 9 Feb 2024 06:11:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707459093; cv=none; b=kjmoaIhcGW3bd/QyVh2XQkqJh0MFwZnYZphWHMvh6VSC0iATJQ6hQ6jrXV69Z53bBFApGT8ffBGO0vHcu/pzTOelVRllgxNZ5/Qor5i/LlLSJO0zgrIIcRiZYF4hVwprxhmXYJZpUm2L6eoXdfWx+BEG82B69L4ZvN12+g/6pns= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707459093; c=relaxed/simple; bh=ynUzPpAGylPTJLOrR9TVvlQRT3GJrcyzUzLgoh61uHo=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Q482Aklv099qJNkoQROfMK+6/IO6aj4TS0c07IiNwkDS+2o4fZDQq0b2Uh9BYhbex8h9BXkExTusQStMCF/dh6XevlJse8Hln+t20kv59yQSocmPPYujRsng2AYgIL17kWPyuHF2cmcNRfxDUoNNgtWDr4kPBqKfT548e3MupAA= 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=aAgyyMWb; arc=none smtp.client-ip=209.85.214.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="aAgyyMWb" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1d746ce7d13so5006605ad.0 for ; Thu, 08 Feb 2024 22:11:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707459091; x=1708063891; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=w69FvwPxJEmTE4Nu5S/qqkjkkefb5ZX1gIWH2ZAd6AU=; b=aAgyyMWbMqYX1XfWwHEjLZCqENtzUDXdCoPjdAimWt+IDDY5B2nQmfCzS0kuqlYnD9 22fwP/z1O82zuB0YMv4in7/fUZza6W9+0DgbJJ212lXoPJMPsJ1kPqGg6/G8ik8B//dq goOnwpAJ9xYBpDMnQ88R6M1CeOZn+2+BolqbomJcRppxKTGNea0oHeBgWBDuJlvveKrA 4s+ygKJYbWQReluVOl6l1BLtdBziP1E1116R+xG456lzs6XKTweWeM929tGAOkIAg26w NLsFOOCKtE/ZFwqqDtRHXLxZKgZbRSKY1Qg/ayz3JeJSPpti5azp3YkmRUAraADYKjCN c5Bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707459091; x=1708063891; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=w69FvwPxJEmTE4Nu5S/qqkjkkefb5ZX1gIWH2ZAd6AU=; b=J6OKMrKQIA64LeXKd7qfFIJUmCpALDUT/35aY4TiMVCi5T5ClWWTPTbqP0JyfKi0J4 zADUhRwJnpi/rmqKJHbAZbVHC6PRTetjzBW8aPKzxtgjpWEZ/LL+3LdM44UrrZ1mcnIx 7iF0sSeSx+okVYbP5wXIXlHusnJXdw6IAtiChxN07SlXnJ7mGT0VkNqOA1LncJNIwo/J O0HUM+gg9zL488OHMUueL3zXxG0PMYJQ4W/4paCI+PA+9ukOrwm3O/5Bv9+wKIk5d+fK OvMSr5AxKmC2f7c0al1xzA4VwZxF4Q87IEJLSE/9l8DoMU2guQ9mKYjSI6F0ocU3aTkG +o1g== X-Gm-Message-State: AOJu0Yy8V/a0uWGSAPg1A6dhML3NVQxpkChaU7bU58QPixsPiuv1B0jE JvqVkTcVjraSt2l3y8jvGK+TKShJNrPp6jvhTZqKULILpJf3h17vZTkxrkNA2Zo= X-Google-Smtp-Source: AGHT+IGSmQFQJZvypTr+dLZJ9+yhr19NLuqkqAKcJiGC7Lmnwj0okZcUm9ROLLrecI2vxVhrbZofiQ== X-Received: by 2002:a17:902:6bca:b0:1d9:2086:fe5f with SMTP id m10-20020a1709026bca00b001d92086fe5fmr629282plt.47.1707459090802; Thu, 08 Feb 2024 22:11:30 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWuKIOfbMMkj0lZWQyf2Mwva6njeppA67MLa36Vt4oaK+x3iYDgKMZSvZVjr9HXuRa0A8VegKiXEmne7zoxd62bd5qVOyxGV3FhSy9h0LYnRmZiw7ga1Gy1uPjqgUz55aThRIfDeDiMJ74OEo6OozGxNzxQJ11rULqifSCVLm8vy0t0y6gWlmeNZ0ANVzQaNXQ+/17imhCLgbnqzYVd5lnSxytkgvxaDQthDS7EBm4WUeeIgDJ1CgzLMiae47m1gOGZjE7frwE= Received: from petra.lan ([2607:fa18:9ffd:1:3fa5:2e62:9e44:c48d]) by smtp.gmail.com with ESMTPSA id je3-20020a170903264300b001d93765f38dsm740843plb.228.2024.02.08.22.11.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 22:11:30 -0800 (PST) From: Alex Henrie To: netdev@vger.kernel.org, dan@danm.net, bagasdotme@gmail.com, davem@davemloft.net, dsahern@kernel.org, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, jikos@kernel.org Cc: Alex Henrie Subject: [PATCH net-next 1/3] net: ipv6/addrconf: ensure that regen_advance is at least 2 seconds Date: Thu, 8 Feb 2024 23:10:26 -0700 Message-ID: <20240209061035.3757-1-alexhenrie24@gmail.com> X-Mailer: git-send-email 2.43.0 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 RFC 8981 defines REGEN_ADVANCE as follows: REGEN_ADVANCE = 2 + (TEMP_IDGEN_RETRIES * DupAddrDetectTransmits * RetransTimer / 1000) Thus, allowing it to be less than 2 seconds is technically a protocol violation. Link: https://datatracker.ietf.org/doc/html/rfc8981#name-defined-protocol-parameters Signed-off-by: Alex Henrie Reviewed-by: David Ahern --- net/ipv6/addrconf.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index d63f5d063f07..99a3ab6ec9d2 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -1331,6 +1331,13 @@ static void ipv6_del_addr(struct inet6_ifaddr *ifp) in6_ifa_put(ifp); } +static unsigned long ipv6_get_regen_advance(struct inet6_dev *idev) +{ + return 2 + idev->cnf.regen_max_retry * + idev->cnf.dad_transmits * + max(NEIGH_VAR(idev->nd_parms, RETRANS_TIME), HZ/100) / HZ; +} + static int ipv6_create_tempaddr(struct inet6_ifaddr *ifp, bool block) { struct inet6_dev *idev = ifp->idev; @@ -1372,9 +1379,7 @@ static int ipv6_create_tempaddr(struct inet6_ifaddr *ifp, bool block) age = (now - ifp->tstamp) / HZ; - regen_advance = idev->cnf.regen_max_retry * - idev->cnf.dad_transmits * - max(NEIGH_VAR(idev->nd_parms, RETRANS_TIME), HZ/100) / HZ; + regen_advance = ipv6_get_regen_advance(idev); /* recalculate max_desync_factor each time and update * idev->desync_factor if it's larger @@ -4577,9 +4582,7 @@ static void addrconf_verify_rtnl(struct net *net) !ifp->regen_count && ifp->ifpub) { /* This is a non-regenerated temporary addr. */ - unsigned long regen_advance = ifp->idev->cnf.regen_max_retry * - ifp->idev->cnf.dad_transmits * - max(NEIGH_VAR(ifp->idev->nd_parms, RETRANS_TIME), HZ/100) / HZ; + unsigned long regen_advance = ipv6_get_regen_advance(ifp->idev); if (age + regen_advance >= ifp->prefered_lft) { struct inet6_ifaddr *ifpub = ifp->ifpub; From patchwork Fri Feb 9 06:10:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Henrie X-Patchwork-Id: 13550888 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D31A457308 for ; Fri, 9 Feb 2024 06:11:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707459094; cv=none; b=QtuanpQEKLd7anVr7JOz3JaQJaZwsk5wzEPNVl7dYJfnbRAcIu6YjTs2LBdJ3PEoRTIJ4wI/1jRqD2vPhD3W5vzzMnnIZXOlycu/BJLEjkYYiwf3YSPTSuzTS11dc8pIbvswoNqaKPpfyTL26g98pyrsr051t1yMlUSnuk7PW7g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707459094; c=relaxed/simple; bh=ubL92FcxkIpFyfIcPM3CeT/GkW1OZXKjwcbZjfWmAN4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fmQO1SLfh0MuJ66qEapF8kfzBuuTvgEb0aqSTDi8YtKPIbmyQxkuTyEwG5UBncFnz1g1TvbTACR/lYQ8wlwHzJwZJbZ/Vz0EZULOuovm33rxiRjWiCRtKmEk1QCX2nQ1fJfJM/Ohx3U2RGFL9sdpzbc5XMfq9nkS+zX9nKvg9/4= 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=WP5i3Dwk; arc=none smtp.client-ip=209.85.215.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WP5i3Dwk" Received: by mail-pg1-f176.google.com with SMTP id 41be03b00d2f7-5d8b887bb0cso432656a12.2 for ; Thu, 08 Feb 2024 22:11:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707459092; x=1708063892; 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=9o7CI6YlNbi9i5nZkaLe03hZgpe+O5Hl3abf4ZeJwMo=; b=WP5i3DwkOU7ZWLLIO1ZEWRNd6rljSrMks9ZoJ6WMNzPUHm1IP976E9WsUiyps+hRBX iABEooMCcU/k0cyFimv3zLl6uKsYRg6D6pt9/jnpOTJ8/mHCsic71WTxHwTUf5lXtJLp HP+MZlQ5NK0uWShbTyrNNqvweGrj5JZVz5OMzEDi+AEpMIq0s5nZ1bJCnh4UtL5BcxFM DSl7/rowlPNNDDsJ6rBTYQJYSWpS/cqaRWmbA7bgcpU/5keIXuX0s1YkyBuaGBuLA52I TMW99pN6tL1onTpiF/IlZEYe5yrFtnrAI1Hq0vuodgc4VD28dU4+ME5lcocGJjnVY3dO 3xgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707459092; x=1708063892; 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=9o7CI6YlNbi9i5nZkaLe03hZgpe+O5Hl3abf4ZeJwMo=; b=bbY+r8u9Qq3w+dSqzfhfO7Y6Ajfx4Lcqr3j5igU6P2zKjWiN66R0qzxMzSJUQ/WBG+ ourSIoVfSpt+B7LP1lexYw6Db4OQBzrdAhy+4YXgP0WSkITDIDLzyefIC85yyAh9Av9/ rNwGjEc+a1Fxa9laU0BXgCThkh0iIynE4RNrftWBjI4d5HQvS3UXrBOJW9aDXemu9kwS Ho6v63rz/uZ0TkLIvY2JUQhRuhMLCCyTdyP4U6G/SmrY4VNlTZXoO9MH0z6anlPIwvjS BW8MGZ6mYjMAqssk5V794QZ5iUWa/mo3MnhPAzgfH9XBnaVeU8Fu1IyB2rEwdAA/IAbx DSuA== X-Gm-Message-State: AOJu0YyVtB7SMEK5LourAJeMlh5633k2+uVEq+AGjmZv+emc+QtngZKL nTLdMI5ptryiEwi+/yZYLeYjaLiPylHD+Pww4CqJPUC0aQCkAqDjYMQwDXRPN60= X-Google-Smtp-Source: AGHT+IHFGax0aWIMgO1hIgbV3MDH0/ZY6YljXIB0Ya8XUEEl9fUK7QOUqtt4yvNfbYtWtqWlsTEHkw== X-Received: by 2002:a05:6a20:9e47:b0:19e:4a98:ba84 with SMTP id mt7-20020a056a209e4700b0019e4a98ba84mr995947pzb.22.1707459091735; Thu, 08 Feb 2024 22:11:31 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWnAfzC6pHcZqEvGPXh39azpeQToHKwW5KTNrAE2+lzionLtaACwW49trxYdthEP2uGb9l9Ch7G0t09kW89kaRHShHmpXJZeZDK2nJoJt3w6aa9fm4LBA4N5o+9cQdtKSDmPj66ZniFmKKeP1K7ZM4PI7SAnF7oNqJUSn2LbuI9aPuGhVcZSasYY2pLxOK+HkPegPWZq/Hkq4cI/HGjneccI6dKyIOLscf76T6rh60o4sCvAK57VR9GB1DB2lkdv/EaWRwoUHA= Received: from petra.lan ([2607:fa18:9ffd:1:3fa5:2e62:9e44:c48d]) by smtp.gmail.com with ESMTPSA id je3-20020a170903264300b001d93765f38dsm740843plb.228.2024.02.08.22.11.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 22:11:31 -0800 (PST) From: Alex Henrie To: netdev@vger.kernel.org, dan@danm.net, bagasdotme@gmail.com, davem@davemloft.net, dsahern@kernel.org, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, jikos@kernel.org Cc: Alex Henrie Subject: [PATCH net-next 2/3] net: ipv6/addrconf: introduce a regen_min_advance sysctl Date: Thu, 8 Feb 2024 23:10:27 -0700 Message-ID: <20240209061035.3757-2-alexhenrie24@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240209061035.3757-1-alexhenrie24@gmail.com> References: <20240209061035.3757-1-alexhenrie24@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 In RFC 8981, REGEN_ADVANCE cannot be less than 2 seconds, and the RFC does not permit the creation of temporary addresses with lifetimes shorter than that: > When processing a Router Advertisement with a > Prefix Information option carrying a prefix for the purposes of > address autoconfiguration (i.e., the A bit is set), the host MUST > perform the following steps: > 5. A temporary address is created only if this calculated preferred > lifetime is greater than REGEN_ADVANCE time units. However, some users want to change their IPv6 address as frequently as possible regardless of the RFC's arbitrary minimum lifetime. For the benefit of those users, add a regen_min_advance sysctl parameter that can be set to below or above 2 seconds. Link: https://datatracker.ietf.org/doc/html/rfc8981 Signed-off-by: Alex Henrie --- Documentation/networking/ip-sysctl.rst | 8 ++++++++ include/linux/ipv6.h | 1 + include/net/addrconf.h | 5 +++-- net/ipv6/addrconf.c | 11 ++++++++++- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Documentation/networking/ip-sysctl.rst b/Documentation/networking/ip-sysctl.rst index 7afff42612e9..fcd6aa71b4fa 100644 --- a/Documentation/networking/ip-sysctl.rst +++ b/Documentation/networking/ip-sysctl.rst @@ -2535,6 +2535,14 @@ max_desync_factor - INTEGER Default: 600 +regen_min_advance - INTEGER + How far in advance (in seconds), at minimum, to create a new temporary + address before the current one is deprecated. This value is added to + the amount of time that may be required for duplicate address detection + to detemine when to create a new address. + + Default: 2 + regen_max_retry - INTEGER Number of attempts before give up attempting to generate valid temporary addresses. diff --git a/include/linux/ipv6.h b/include/linux/ipv6.h index 5e605e384aac..ef3aa060a289 100644 --- a/include/linux/ipv6.h +++ b/include/linux/ipv6.h @@ -27,6 +27,7 @@ struct ipv6_devconf { __s32 use_tempaddr; __s32 temp_valid_lft; __s32 temp_prefered_lft; + __s32 regen_min_advance; __s32 regen_max_retry; __s32 max_desync_factor; __s32 max_addresses; diff --git a/include/net/addrconf.h b/include/net/addrconf.h index 61ebe723ee4d..30d6f1e84e46 100644 --- a/include/net/addrconf.h +++ b/include/net/addrconf.h @@ -8,8 +8,9 @@ #define MIN_VALID_LIFETIME (2*3600) /* 2 hours */ -#define TEMP_VALID_LIFETIME (7*86400) -#define TEMP_PREFERRED_LIFETIME (86400) +#define TEMP_VALID_LIFETIME (7*86400) /* 1 week */ +#define TEMP_PREFERRED_LIFETIME (86400) /* 24 hours */ +#define REGEN_MIN_ADVANCE (2) /* 2 seconds */ #define REGEN_MAX_RETRY (3) #define MAX_DESYNC_FACTOR (600) diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index 99a3ab6ec9d2..0b78ffc101ef 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -195,6 +195,7 @@ static struct ipv6_devconf ipv6_devconf __read_mostly = { .use_tempaddr = 0, .temp_valid_lft = TEMP_VALID_LIFETIME, .temp_prefered_lft = TEMP_PREFERRED_LIFETIME, + .regen_min_advance = REGEN_MIN_ADVANCE, .regen_max_retry = REGEN_MAX_RETRY, .max_desync_factor = MAX_DESYNC_FACTOR, .max_addresses = IPV6_MAX_ADDRESSES, @@ -257,6 +258,7 @@ static struct ipv6_devconf ipv6_devconf_dflt __read_mostly = { .use_tempaddr = 0, .temp_valid_lft = TEMP_VALID_LIFETIME, .temp_prefered_lft = TEMP_PREFERRED_LIFETIME, + .regen_min_advance = REGEN_MIN_ADVANCE, .regen_max_retry = REGEN_MAX_RETRY, .max_desync_factor = MAX_DESYNC_FACTOR, .max_addresses = IPV6_MAX_ADDRESSES, @@ -1333,7 +1335,7 @@ static void ipv6_del_addr(struct inet6_ifaddr *ifp) static unsigned long ipv6_get_regen_advance(struct inet6_dev *idev) { - return 2 + idev->cnf.regen_max_retry * + return idev->cnf.regen_min_advance + idev->cnf.regen_max_retry * idev->cnf.dad_transmits * max(NEIGH_VAR(idev->nd_parms, RETRANS_TIME), HZ/100) / HZ; } @@ -6792,6 +6794,13 @@ static const struct ctl_table addrconf_sysctl[] = { .mode = 0644, .proc_handler = proc_dointvec, }, + { + .procname = "regen_min_advance", + .data = &ipv6_devconf.regen_min_advance, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = proc_dointvec, + }, { .procname = "regen_max_retry", .data = &ipv6_devconf.regen_max_retry, From patchwork Fri Feb 9 06:10:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Henrie X-Patchwork-Id: 13550889 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.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 CB78957310 for ; Fri, 9 Feb 2024 06:11:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707459095; cv=none; b=P7pEPOF4IE8OdWkKWJt560s//GQKkOPQ4M7EXKm9/QjQTW9DaF8kem+8aSjeykyx9ejSI8p1v5Sta8GpTtZeXCdAgckN5fbakWe6qyx+Cr9TCRZZzgFahbImGqJLfH6AfZ6UWWu/+yY5n73Q8PA0EoZIx7bpJynYlua0dhcXMeo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707459095; c=relaxed/simple; bh=dZG0QNi7SRRemjy+9xsvodF2DVs27fYnCafIVrknPc8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=e4sMlt0UcNlZimzVfqaryAH0ttCRnhYM649cCAUCOqWNTsez4QRbo3O17ilc0zhNRh+Njc1HnyEvchtYFLfwcXJ+G56cPS3JLw+Thsuebh+DBEIkLa1NXRytCFoJE4q9xN9v52gSer76DtKgPSHnikN1et4rz49Dox7QT8e1Fjs= 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=jJ4nmx7g; arc=none smtp.client-ip=209.85.214.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="jJ4nmx7g" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1d70b0e521eso4556105ad.1 for ; Thu, 08 Feb 2024 22:11:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707459093; x=1708063893; 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=sM+bOrDz8l8mOQF3TbcRWuLzYmI3ryKTQszVG53QEDc=; b=jJ4nmx7gcHhTkrQ+Uy9cYd06+Kw5r5+WFZ9+K12RsZGc0PpUPghVVkPaCKIrr+FHM8 bfXt3EEhQWGm7g0O/bMDkX+CVq0pGvUyESkhnmjFLo324AnxjaLQBMtAuLEcee7GErfj rTuFjYxjxhuGcRnIl69yHY9jwWqyMKJBv3Fk0VXc+aa+GdNCimic348pw+XMFtkACPnT vNjxBgx+KrvyrdgqPc6bC3hkqjtE5Z6kT441JhMYHQCx2a7hoXrgq7M+B4fRY0ntXY/N yYCwORKMqaARI7T3709+oxjTYDm/hlepWM69qQyG+flCuGxVPZxD3chUqNAc7fsKoRkC nigA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707459093; x=1708063893; 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=sM+bOrDz8l8mOQF3TbcRWuLzYmI3ryKTQszVG53QEDc=; b=XPFoMVuHDrLkwLa+dET1OCJYe/Cu43EcZQ47a+rV81dMACK8ChpMN3e87Wng4jGway ZUeyYayQxFIvXDGFo2IHw4oyzxc8hSonG4rNLVnEcxveITB3Jc+F9lai/6BwHQg/2J1P gYdMRsqlpv4VGY9wBcsvMMZzK63p2byzpnFMDcXlEMpWKO1EAbzDFY4YLZQzEXgXXheZ vvZ/OAhgKgc8CgivGqfe8YjEJTYITfacsX+mBc1LWy7ETTCxzqwTOl13rx1qZVoZE5Ca cWBVlfdr/wBuVovCrAT8cdBwMMmDpYMF9R5Tv8ON/REbCee3/NLVmZghP5c9gUgHOG5r AWlA== X-Gm-Message-State: AOJu0YxMqNx7ymtZMxO7I7Mme/Wxuh4ti7ePt+OMnZd8FGB9y4/dRRIP 85/nVObn5jWeTxj/QNVk+Dt4AIWHJIWZIYt86gVnBrkL5WPNdT7Rq0G0tv+v4o0= X-Google-Smtp-Source: AGHT+IGk9n3ZvfHCVpqVhZQz+azEG+pdSAVhPjmJoWF7AFiJF3vfcOT2y9h4GcQCVYjqGUXmlO1xgw== X-Received: by 2002:a17:902:c408:b0:1d9:aa2d:db69 with SMTP id k8-20020a170902c40800b001d9aa2ddb69mr693411plk.19.1707459092683; Thu, 08 Feb 2024 22:11:32 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWTkF0V2G9TkUSEkVvoBl9Zu3f78b18MfHPYpxLY/eD54jS9su/W3bVh5eoZK4aS6DJMwv42D/ozi5GQDf/3MC3Llg95xkY4NE7TMhPR4spSeE+Pazp1jmoQH/OrEOcEp/4E5j1n2TXeajVYywRWtOWxlOlRaM/wYfI2QAecRWUeavHPt5naQKBiZxfaDEaMIwTxWFoz6FeAKMIRlPhvjuwbk8BAH1wlRA/boCstTdtd9yc7VOFrUrbfd5pGCrl2At9hnkFKZ0= Received: from petra.lan ([2607:fa18:9ffd:1:3fa5:2e62:9e44:c48d]) by smtp.gmail.com with ESMTPSA id je3-20020a170903264300b001d93765f38dsm740843plb.228.2024.02.08.22.11.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 22:11:32 -0800 (PST) From: Alex Henrie To: netdev@vger.kernel.org, dan@danm.net, bagasdotme@gmail.com, davem@davemloft.net, dsahern@kernel.org, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, jikos@kernel.org Cc: Alex Henrie Subject: [PATCH net-next 3/3] net: ipv6/addrconf: clamp preferred_lft to the minimum required Date: Thu, 8 Feb 2024 23:10:28 -0700 Message-ID: <20240209061035.3757-3-alexhenrie24@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240209061035.3757-1-alexhenrie24@gmail.com> References: <20240209061035.3757-1-alexhenrie24@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 If the preferred lifetime was less than the minimum required lifetime, ipv6_create_tempaddr would error out without creating any new address. On my machine and network, this error happened immediately with the preferred lifetime set to 5 seconds or less, after a few minutes with the preferred lifetime set to 6 seconds, and not at all with the preferred lifetime set to 7 seconds. During my investigation, I found a Stack Exchange post from another person who seems to have had the same problem: They stopped getting new addresses if they lowered the preferred lifetime below 3 seconds, and they didn't really know why. The preferred lifetime is a preference, not a hard requirement. The kernel does not strictly forbid new connections on a deprecated address, nor does it guarantee that the address will be disposed of the instant its total valid lifetime expires. So rather than disable IPv6 privacy extensions altogether if the minimum required lifetime swells above the preferred lifetime, it is more in keeping with the user's intent to increase the temporary address's lifetime to the minimum necessary for the current network conditions. With these fixes, setting the preferred lifetime to 5 or 6 seconds "just works" because the extra fraction of a second is practically unnoticeable. It's even possible to reduce the time before deprecation to 1 or 2 seconds by setting /proc/sys/net/ipv6/conf/*/regen_min_advance and /proc/sys/net/ipv6/conf/*/dad_transmits to 0. I realize that that is a pretty niche use case, but I know at least one person who would gladly sacrifice performance and convenience to be sure that they are getting the maximum possible level of privacy. Link: https://serverfault.com/a/1031168/310447 Signed-off-by: Alex Henrie Reviewed-by: David Ahern --- net/ipv6/addrconf.c | 43 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index 0b78ffc101ef..8d3023e54822 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -1347,6 +1347,7 @@ static int ipv6_create_tempaddr(struct inet6_ifaddr *ifp, bool block) unsigned long regen_advance; unsigned long now = jiffies; s32 cnf_temp_preferred_lft; + u32 if_public_preferred_lft; struct inet6_ifaddr *ift; struct ifa6_config cfg; long max_desync_factor; @@ -1401,11 +1402,13 @@ static int ipv6_create_tempaddr(struct inet6_ifaddr *ifp, bool block) } } + if_public_preferred_lft = ifp->prefered_lft; + memset(&cfg, 0, sizeof(cfg)); cfg.valid_lft = min_t(__u32, ifp->valid_lft, idev->cnf.temp_valid_lft + age); cfg.preferred_lft = cnf_temp_preferred_lft + age - idev->desync_factor; - cfg.preferred_lft = min_t(__u32, ifp->prefered_lft, cfg.preferred_lft); + cfg.preferred_lft = min_t(__u32, if_public_preferred_lft, cfg.preferred_lft); cfg.preferred_lft = min_t(__u32, cfg.valid_lft, cfg.preferred_lft); cfg.plen = ifp->prefix_len; @@ -1414,19 +1417,41 @@ static int ipv6_create_tempaddr(struct inet6_ifaddr *ifp, bool block) write_unlock_bh(&idev->lock); - /* A temporary address is created only if this calculated Preferred - * Lifetime is greater than REGEN_ADVANCE time units. In particular, - * an implementation must not create a temporary address with a zero - * Preferred Lifetime. + /* From RFC 4941: + * + * A temporary address is created only if this calculated Preferred + * Lifetime is greater than REGEN_ADVANCE time units. In + * particular, an implementation must not create a temporary address + * with a zero Preferred Lifetime. + * + * ... + * + * When creating a temporary address, the lifetime values MUST be + * derived from the corresponding prefix as follows: + * + * ... + * + * * Its Preferred Lifetime is the lower of the Preferred Lifetime + * of the public address or TEMP_PREFERRED_LIFETIME - + * DESYNC_FACTOR. + * + * To comply with the RFC's requirements, clamp the preferred lifetime + * to a minimum of regen_advance, unless that would exceed valid_lft or + * ifp->prefered_lft. + * * Use age calculation as in addrconf_verify to avoid unnecessary * temporary addresses being generated. */ age = (now - tmp_tstamp + ADDRCONF_TIMER_FUZZ_MINUS) / HZ; if (cfg.preferred_lft <= regen_advance + age) { - in6_ifa_put(ifp); - in6_dev_put(idev); - ret = -1; - goto out; + cfg.preferred_lft = regen_advance + age + 1; + if (cfg.preferred_lft > cfg.valid_lft || + cfg.preferred_lft > if_public_preferred_lft) { + in6_ifa_put(ifp); + in6_dev_put(idev); + ret = -1; + goto out; + } } cfg.ifa_flags = IFA_F_TEMPORARY;