[RFC PATCH 14/39] sysctl: store IPv6 scalar sysctl bounds by value

From: wen . yang

Date: Wed Oct 28 2026 - 12:37:52 EST


From: Wen Yang <wen.yang@xxxxxxxxx>

Use numeric IPv6 bounds while preserving the IOAM native-word behavior.

Suggested-by: Joel Granados <joel.granados@xxxxxxxxxx>
Signed-off-by: Wen Yang <wen.yang@xxxxxxxxx>
---
net/ipv6/icmp.c | 22 ++++++++++-----------
net/ipv6/sysctl_net_ipv6.c | 40 ++++++++++++++++++++------------------
2 files changed, 31 insertions(+), 31 deletions(-)

diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
index 1ba2ff759075..4a38b2046876 100644
--- a/net/ipv6/icmp.c
+++ b/net/ipv6/icmp.c
@@ -1372,8 +1372,6 @@ EXPORT_SYMBOL(icmpv6_err_convert);

#ifdef CONFIG_SYSCTL

-static u32 icmpv6_errors_extension_mask_all =
- GENMASK_U8(ICMP_ERR_EXT_COUNT - 1, 0);

static const struct ctl_table ipv6_icmp_table_template[] = {
{
@@ -1389,8 +1387,8 @@ static const struct ctl_table ipv6_icmp_table_template[] = {
.maxlen = sizeof(u8),
.mode = 0644,
.proc_handler = proc_dou8vec_minmax,
- .min = 0,
- .max = U8_MAX,
+ .min = 0,
+ .max = U8_MAX,
},
{
.procname = "echo_ignore_multicast",
@@ -1398,8 +1396,8 @@ static const struct ctl_table ipv6_icmp_table_template[] = {
.maxlen = sizeof(u8),
.mode = 0644,
.proc_handler = proc_dou8vec_minmax,
- .min = 0,
- .max = U8_MAX,
+ .min = 0,
+ .max = U8_MAX,
},
{
.procname = "echo_ignore_anycast",
@@ -1407,8 +1405,8 @@ static const struct ctl_table ipv6_icmp_table_template[] = {
.maxlen = sizeof(u8),
.mode = 0644,
.proc_handler = proc_dou8vec_minmax,
- .min = 0,
- .max = U8_MAX,
+ .min = 0,
+ .max = U8_MAX,
},
{
.procname = "ratemask",
@@ -1423,8 +1421,8 @@ static const struct ctl_table ipv6_icmp_table_template[] = {
.maxlen = sizeof(u8),
.mode = 0644,
.proc_handler = proc_dou8vec_minmax,
- .extra1 = SYSCTL_ZERO,
- .extra2 = SYSCTL_ONE,
+ .min = 0,
+ .max = 1,
},
{
.procname = "errors_extension_mask",
@@ -1432,8 +1430,8 @@ static const struct ctl_table ipv6_icmp_table_template[] = {
.maxlen = sizeof(u8),
.mode = 0644,
.proc_handler = proc_dou8vec_minmax,
- .extra1 = SYSCTL_ZERO,
- .extra2 = &icmpv6_errors_extension_mask_all,
+ .min = 0,
+ .max = GENMASK_U8(ICMP_ERR_EXT_COUNT - 1, 0),
},
};

diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
index c870a364de60..144bbc1ae0c8 100644
--- a/net/ipv6/sysctl_net_ipv6.c
+++ b/net/ipv6/sysctl_net_ipv6.c
@@ -24,13 +24,6 @@
#endif
#include <linux/ioam6.h>

-static int flowlabel_reflect_max = 0x7;
-static int auto_flowlabels_max = IP6_AUTO_FLOW_LABEL_MAX;
-static u32 rt6_multipath_hash_fields_all_mask =
- FIB_MULTIPATH_HASH_FIELD_ALL_MASK;
-static u32 ioam6_id_max = IOAM6_DEFAULT_ID;
-static u64 ioam6_id_wide_max = IOAM6_DEFAULT_ID_WIDE;
-
static int proc_rt6_multipath_hash_policy(const struct ctl_table *table, int write,
void *buffer, size_t *lenp, loff_t *ppos)
{
@@ -96,7 +89,8 @@ static const struct ctl_table ipv6_table_template[] = {
.maxlen = sizeof(u8),
.mode = 0644,
.proc_handler = proc_dou8vec_minmax,
- .extra2 = &auto_flowlabels_max
+ .min = 0,
+ .max = IP6_AUTO_FLOW_LABEL_MAX,
},
{
.procname = "fwmark_reflect",
@@ -145,8 +139,8 @@ static const struct ctl_table ipv6_table_template[] = {
.maxlen = sizeof(int),
.mode = 0644,
.proc_handler = proc_dointvec_minmax,
- .extra1 = SYSCTL_ZERO,
- .extra2 = &flowlabel_reflect_max,
+ .min = 0,
+ .max = 0x7,
},
{
.procname = "max_dst_opts_number",
@@ -182,8 +176,8 @@ static const struct ctl_table ipv6_table_template[] = {
.maxlen = sizeof(u8),
.mode = 0644,
.proc_handler = proc_rt6_multipath_hash_policy,
- .extra1 = SYSCTL_ZERO,
- .extra2 = SYSCTL_THREE,
+ .min = 0,
+ .max = 3,
},
{
.procname = "fib_multipath_hash_fields",
@@ -191,8 +185,8 @@ static const struct ctl_table ipv6_table_template[] = {
.maxlen = sizeof(u32),
.mode = 0644,
.proc_handler = proc_rt6_multipath_hash_fields,
- .extra1 = SYSCTL_ONE,
- .extra2 = &rt6_multipath_hash_fields_all_mask,
+ .min = 1,
+ .max = FIB_MULTIPATH_HASH_FIELD_ALL_MASK,
},
{
.procname = "seg6_flowlabel",
@@ -207,8 +201,8 @@ static const struct ctl_table ipv6_table_template[] = {
.maxlen = sizeof(u8),
.mode = 0644,
.proc_handler = proc_dou8vec_minmax,
- .extra1 = SYSCTL_ZERO,
- .extra2 = SYSCTL_TWO,
+ .min = 0,
+ .max = 2,
},
{
.procname = "ioam6_id",
@@ -216,7 +210,8 @@ static const struct ctl_table ipv6_table_template[] = {
.maxlen = sizeof(u32),
.mode = 0644,
.proc_handler = proc_douintvec_minmax,
- .extra2 = &ioam6_id_max,
+ .min = 0,
+ .max = IOAM6_DEFAULT_ID,
},
{
.procname = "ioam6_id_wide",
@@ -224,7 +219,13 @@ static const struct ctl_table ipv6_table_template[] = {
.maxlen = sizeof(u64),
.mode = 0644,
.proc_handler = proc_doulongvec_minmax,
- .extra2 = &ioam6_id_wide_max,
+ .min = 0,
+ /* Preserve the native unsigned long bound read from the u64. */
+#if BITS_PER_LONG == 32 && defined(__BIG_ENDIAN)
+ .max = (unsigned long)(IOAM6_DEFAULT_ID_WIDE >> 32),
+#else
+ .max = (unsigned long)IOAM6_DEFAULT_ID_WIDE,
+#endif
},
};

@@ -242,7 +243,8 @@ static struct ctl_table ipv6_rotable[] = {
.maxlen = sizeof(int),
.mode = 0644,
.proc_handler = proc_dointvec_minmax,
- .extra1 = SYSCTL_ONE
+ .min = 1,
+ .max = INT_MAX,
},
#ifdef CONFIG_NETLABEL
{
--
2.25.1