net: sysctl: introduce sysctl SYSCTL_THREE
authorTonghao Zhang <xiangxia.m.yue@gmail.com>
Sun, 1 May 2022 03:55:23 +0000 (11:55 +0800)
committerPaolo Abeni <pabeni@redhat.com>
Tue, 3 May 2022 08:15:06 +0000 (10:15 +0200)
This patch introdues the SYSCTL_THREE.

KUnit:
[00:10:14] ================ sysctl_test (10 subtests) =================
[00:10:14] [PASSED] sysctl_test_api_dointvec_null_tbl_data
[00:10:14] [PASSED] sysctl_test_api_dointvec_table_maxlen_unset
[00:10:14] [PASSED] sysctl_test_api_dointvec_table_len_is_zero
[00:10:14] [PASSED] sysctl_test_api_dointvec_table_read_but_position_set
[00:10:14] [PASSED] sysctl_test_dointvec_read_happy_single_positive
[00:10:14] [PASSED] sysctl_test_dointvec_read_happy_single_negative
[00:10:14] [PASSED] sysctl_test_dointvec_write_happy_single_positive
[00:10:14] [PASSED] sysctl_test_dointvec_write_happy_single_negative
[00:10:14] [PASSED] sysctl_test_api_dointvec_write_single_less_int_min
[00:10:14] [PASSED] sysctl_test_api_dointvec_write_single_greater_int_max
[00:10:14] =================== [PASSED] sysctl_test ===================

./run_kselftest.sh -c sysctl
...
ok 1 selftests: sysctl: sysctl.sh

Cc: Luis Chamberlain <mcgrof@kernel.org>
Cc: Kees Cook <keescook@chromium.org>
Cc: Iurii Zaikin <yzaikin@google.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: Hideaki YOSHIFUJI <yoshfuji@linux-ipv6.org>
Cc: David Ahern <dsahern@kernel.org>
Cc: Simon Horman <horms@verge.net.au>
Cc: Julian Anastasov <ja@ssi.bg>
Cc: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: Jozsef Kadlecsik <kadlec@netfilter.org>
Cc: Florian Westphal <fw@strlen.de>
Cc: Shuah Khan <shuah@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Lorenz Bauer <lmb@cloudflare.com>
Cc: Akhmat Karakotov <hmukos@yandex-team.ru>
Signed-off-by: Tonghao Zhang <xiangxia.m.yue@gmail.com>
Reviewed-by: Simon Horman <horms@verge.net.au>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
fs/proc/proc_sysctl.c
include/linux/sysctl.h
net/core/sysctl_net_core.c
net/ipv4/sysctl_net_ipv4.c
net/ipv6/sysctl_net_ipv6.c
net/netfilter/ipvs/ip_vs_ctl.c

index 7d9cfc730bd4c345ccbd34f65e19c31c51fa2536..5851c2a92c0d1c88cd50a01e8169efebbc181fc7 100644 (file)
@@ -26,7 +26,7 @@ static const struct file_operations proc_sys_dir_file_operations;
 static const struct inode_operations proc_sys_dir_operations;
 
 /* shared constants to be used in various sysctls */
-const int sysctl_vals[] = { -1, 0, 1, 2, 4, 100, 200, 1000, 3000, INT_MAX, 65535 };
+const int sysctl_vals[] = { 0, 1, 2, 3, 4, 100, 200, 1000, 3000, INT_MAX, 65535, -1 };
 EXPORT_SYMBOL(sysctl_vals);
 
 const unsigned long sysctl_long_vals[] = { 0, 1, LONG_MAX };
index 6353d6db69b2eddc767c4ccc51e7c4fa3b44690e..80263f7cdb776cce32ec4f8a13ce60dc5d529019 100644 (file)
@@ -38,10 +38,10 @@ struct ctl_table_header;
 struct ctl_dir;
 
 /* Keep the same order as in fs/proc/proc_sysctl.c */
-#define SYSCTL_NEG_ONE                 ((void *)&sysctl_vals[0])
-#define SYSCTL_ZERO                    ((void *)&sysctl_vals[1])
-#define SYSCTL_ONE                     ((void *)&sysctl_vals[2])
-#define SYSCTL_TWO                     ((void *)&sysctl_vals[3])
+#define SYSCTL_ZERO                    ((void *)&sysctl_vals[0])
+#define SYSCTL_ONE                     ((void *)&sysctl_vals[1])
+#define SYSCTL_TWO                     ((void *)&sysctl_vals[2])
+#define SYSCTL_THREE                   ((void *)&sysctl_vals[3])
 #define SYSCTL_FOUR                    ((void *)&sysctl_vals[4])
 #define SYSCTL_ONE_HUNDRED             ((void *)&sysctl_vals[5])
 #define SYSCTL_TWO_HUNDRED             ((void *)&sysctl_vals[6])
@@ -51,6 +51,7 @@ struct ctl_dir;
 
 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
 #define SYSCTL_MAXOLDUID               ((void *)&sysctl_vals[10])
+#define SYSCTL_NEG_ONE                 ((void *)&sysctl_vals[11])
 
 extern const int sysctl_vals[];
 
index 3a0ce309ffcd9c39761d55aa9653064bd4ed1ecd..195ca5c2877125bf420128d3c6465ac216f459e5 100644 (file)
@@ -25,7 +25,6 @@
 
 #include "dev.h"
 
-static int three = 3;
 static int int_3600 = 3600;
 static int min_sndbuf = SOCK_MIN_SNDBUF;
 static int min_rcvbuf = SOCK_MIN_RCVBUF;
@@ -553,7 +552,7 @@ static struct ctl_table net_core_table[] = {
                .mode           = 0644,
                .proc_handler   = proc_dointvec_minmax,
                .extra1         = SYSCTL_ZERO,
-               .extra2         = &three,
+               .extra2         = SYSCTL_THREE,
        },
        {
                .procname       = "high_order_alloc_disable",
index 9ff60a389cd0945ef617e9767c5d75765245d9b3..cd448cdd3b38184d721c8dd09c058dfa24cc2a3b 100644 (file)
@@ -20,7 +20,6 @@
 #include <net/protocol.h>
 #include <net/netevent.h>
 
-static int three __maybe_unused = 3;
 static int tcp_retr1_max = 255;
 static int ip_local_port_range_min[] = { 1, 1 };
 static int ip_local_port_range_max[] = { 65535, 65535 };
@@ -1056,7 +1055,7 @@ static struct ctl_table ipv4_net_table[] = {
                .mode           = 0644,
                .proc_handler   = proc_fib_multipath_hash_policy,
                .extra1         = SYSCTL_ZERO,
-               .extra2         = &three,
+               .extra2         = SYSCTL_THREE,
        },
        {
                .procname       = "fib_multipath_hash_fields",
index 560c48d0ddb7d00d0194071d5f23dd6dd2061888..94a0a294c6a1d4a84da6f5feef8091c390f9e481 100644 (file)
@@ -23,7 +23,6 @@
 #endif
 #include <linux/ioam6.h>
 
-static int three = 3;
 static int flowlabel_reflect_max = 0x7;
 static int auto_flowlabels_max = IP6_AUTO_FLOW_LABEL_MAX;
 static u32 rt6_multipath_hash_fields_all_mask =
@@ -171,7 +170,7 @@ static struct ctl_table ipv6_table_template[] = {
                .mode           = 0644,
                .proc_handler   = proc_rt6_multipath_hash_policy,
                .extra1         = SYSCTL_ZERO,
-               .extra2         = &three,
+               .extra2         = SYSCTL_THREE,
        },
        {
                .procname       = "fib_multipath_hash_fields",
index 7f645328b47f388606cb64e17ff01fc371a07f31..efab2b06d3732b522b9e5d07982abf0363870fff 100644 (file)
@@ -1767,8 +1767,6 @@ static int ip_vs_zero_all(struct netns_ipvs *ipvs)
 
 #ifdef CONFIG_SYSCTL
 
-static int three = 3;
-
 static int
 proc_do_defense_mode(struct ctl_table *table, int write,
                     void *buffer, size_t *lenp, loff_t *ppos)
@@ -1977,7 +1975,7 @@ static struct ctl_table vs_vars[] = {
                .mode           = 0644,
                .proc_handler   = proc_dointvec_minmax,
                .extra1         = SYSCTL_ZERO,
-               .extra2         = &three,
+               .extra2         = SYSCTL_THREE,
        },
        {
                .procname       = "nat_icmp_send",