From patchwork Fri Apr 22 07:01:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tonghao Zhang X-Patchwork-Id: 12822854 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 21278C433EF for ; Fri, 22 Apr 2022 07:02:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1444627AbiDVHE5 (ORCPT ); Fri, 22 Apr 2022 03:04:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1444629AbiDVHEz (ORCPT ); Fri, 22 Apr 2022 03:04:55 -0400 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E18945130D; Fri, 22 Apr 2022 00:01:59 -0700 (PDT) Received: by mail-pl1-x631.google.com with SMTP id n18so8902500plg.5; Fri, 22 Apr 2022 00:01:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MopaOY7i6WBi8YVwl5BOvWJCH8y5VXovqDBUoTUNOUQ=; b=CAIG/mMVKrKt5OZGWXryYFW3dEEYvrDi47HBkS3yl3EL81bzNUMybiUWux9G8k7uLl 74yhzhrQDe5Y5BOvjBaCP75R0CD+cg9s2G4fa+raBO7Km2gRK0Gq4W6GoDvLtXrzT0aW 3LDFRFCF2C3rnBSiB4k8vv6T2yoWSNluiSprb4vF4oa2Q0cgLt9qEZsSf1jhQFbF7rj/ K+g9IOPkQSP7IMWK9f83U0Ol5oreu8VVD+6QcNr5hmHiPKUyn9Uy2lHW2U5nH2c6zf3n 4B+lyHOSTCxVYTply+wKDR3j/2lBhRM/nI8gQKiPBhSEK9Twj+qnXIBgBzBhfFJVWg4z Vepw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MopaOY7i6WBi8YVwl5BOvWJCH8y5VXovqDBUoTUNOUQ=; b=TJenvolwQlGWT2NZWUVxgUMvebCKd76+KruSDh25acG4LWwimwmKjiEwr/l2vg6oV2 +W710/uJv/5M4t3zUt1Q5yA1MUq/s7NJmhmAAXBqG+fqaWq9YfJ6+AGOGV0hls/5YHGq 4dD58aqzBGr4+0ECq9j2n97Qm04QtLQ/sxpuR+dBdV3noN1MGEOw6vjVN4wq16t0sdef R+ygxH6yU60rZFWvxo9/9o7k3Li5/o2ah3nqtFzHzalu/vmoVETlEgWaHhfhlpNx+1yT dpbYkQbDmwIUigd70p8g3ocz+Wh9KAU+P3kP92Pybk2vzV06s/q2DHbBQ2PYSI5ngHJ7 wXfA== X-Gm-Message-State: AOAM531E3KqARcQ5Ti0k2fwTqXy/UJ+kWvxcLZzBd5M37wi96GqOt2c6 47DDUPdmgKn1hEHvE8Ck9VSNq1n/aZdIgQ== X-Google-Smtp-Source: ABdhPJwF/GHqpbugqr3ld8NTA0tlHfBAr3TkH81dP2rfb/nqZUwZ5C02IvL9Q/OzxCbSb9K/PS0XOQ== X-Received: by 2002:a17:90a:ec09:b0:1d5:dd77:d050 with SMTP id l9-20020a17090aec0900b001d5dd77d050mr3673333pjy.53.1650610919136; Fri, 22 Apr 2022 00:01:59 -0700 (PDT) Received: from localhost.localdomain ([111.204.182.100]) by smtp.gmail.com with ESMTPSA id 10-20020a17090a1a0a00b001cd630f301fsm4873467pjk.36.2022.04.22.00.01.52 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Apr 2022 00:01:58 -0700 (PDT) From: xiangxia.m.yue@gmail.com To: netdev@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: Tonghao Zhang , Luis Chamberlain , Kees Cook , Iurii Zaikin , "David S. Miller" , Jakub Kicinski , Paolo Abeni , Hideaki YOSHIFUJI , David Ahern , Simon Horman , Julian Anastasov , Pablo Neira Ayuso , Jozsef Kadlecsik , Florian Westphal , Shuah Khan , Andrew Morton , Alexei Starovoitov , Eric Dumazet , Lorenz Bauer , Akhmat Karakotov Subject: [net-next v4 1/3] net: sysctl: use shared sysctl macro Date: Fri, 22 Apr 2022 15:01:39 +0800 Message-Id: <20220422070141.39397-2-xiangxia.m.yue@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20220422070141.39397-1-xiangxia.m.yue@gmail.com> References: <20220422070141.39397-1-xiangxia.m.yue@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Tonghao Zhang This patch replace two, four and long_one to SYSCTL_XXX. Cc: Luis Chamberlain Cc: Kees Cook Cc: Iurii Zaikin Cc: "David S. Miller" Cc: Jakub Kicinski Cc: Paolo Abeni Cc: Hideaki YOSHIFUJI Cc: David Ahern Cc: Simon Horman Cc: Julian Anastasov Cc: Pablo Neira Ayuso Cc: Jozsef Kadlecsik Cc: Florian Westphal Cc: Shuah Khan Cc: Andrew Morton Cc: Alexei Starovoitov Cc: Eric Dumazet Cc: Lorenz Bauer Cc: Akhmat Karakotov Signed-off-by: Tonghao Zhang --- net/core/sysctl_net_core.c | 10 ++++------ net/ipv4/sysctl_net_ipv4.c | 13 +++++-------- net/ipv6/sysctl_net_ipv6.c | 3 +-- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c index 8295e5877eb3..3a0ce309ffcd 100644 --- a/net/core/sysctl_net_core.c +++ b/net/core/sysctl_net_core.c @@ -25,13 +25,11 @@ #include "dev.h" -static int two = 2; static int three = 3; static int int_3600 = 3600; static int min_sndbuf = SOCK_MIN_SNDBUF; static int min_rcvbuf = SOCK_MIN_RCVBUF; static int max_skb_frags = MAX_SKB_FRAGS; -static long long_one __maybe_unused = 1; static long long_max __maybe_unused = LONG_MAX; static int net_msg_warn; /* Unused, but still a sysctl */ @@ -390,7 +388,7 @@ static struct ctl_table net_core_table[] = { .extra2 = SYSCTL_ONE, # else .extra1 = SYSCTL_ZERO, - .extra2 = &two, + .extra2 = SYSCTL_TWO, # endif }, # ifdef CONFIG_HAVE_EBPF_JIT @@ -401,7 +399,7 @@ static struct ctl_table net_core_table[] = { .mode = 0600, .proc_handler = proc_dointvec_minmax_bpf_restricted, .extra1 = SYSCTL_ZERO, - .extra2 = &two, + .extra2 = SYSCTL_TWO, }, { .procname = "bpf_jit_kallsyms", @@ -419,7 +417,7 @@ static struct ctl_table net_core_table[] = { .maxlen = sizeof(long), .mode = 0600, .proc_handler = proc_dolongvec_minmax_bpf_restricted, - .extra1 = &long_one, + .extra1 = SYSCTL_LONG_ONE, .extra2 = &bpf_jit_limit_max, }, #endif @@ -546,7 +544,7 @@ static struct ctl_table net_core_table[] = { .mode = 0644, .proc_handler = proc_dointvec_minmax, .extra1 = SYSCTL_ZERO, - .extra2 = &two, + .extra2 = SYSCTL_TWO, }, { .procname = "devconf_inherit_init_net", diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c index ad80d180b60b..9ff60a389cd0 100644 --- a/net/ipv4/sysctl_net_ipv4.c +++ b/net/ipv4/sysctl_net_ipv4.c @@ -20,10 +20,7 @@ #include #include -static int two = 2; static int three __maybe_unused = 3; -static int four = 4; -static int thousand = 1000; static int tcp_retr1_max = 255; static int ip_local_port_range_min[] = { 1, 1 }; static int ip_local_port_range_max[] = { 65535, 65535 }; @@ -1006,7 +1003,7 @@ static struct ctl_table ipv4_net_table[] = { .mode = 0644, .proc_handler = proc_dou8vec_minmax, .extra1 = SYSCTL_ZERO, - .extra2 = &two, + .extra2 = SYSCTL_TWO, }, { .procname = "tcp_max_syn_backlog", @@ -1117,7 +1114,7 @@ static struct ctl_table ipv4_net_table[] = { .mode = 0644, .proc_handler = proc_dou8vec_minmax, .extra1 = SYSCTL_ZERO, - .extra2 = &four, + .extra2 = SYSCTL_FOUR, }, { .procname = "tcp_recovery", @@ -1310,7 +1307,7 @@ static struct ctl_table ipv4_net_table[] = { .mode = 0644, .proc_handler = proc_dointvec_minmax, .extra1 = SYSCTL_ZERO, - .extra2 = &thousand, + .extra2 = SYSCTL_ONE_THOUSAND, }, { .procname = "tcp_pacing_ca_ratio", @@ -1319,7 +1316,7 @@ static struct ctl_table ipv4_net_table[] = { .mode = 0644, .proc_handler = proc_dointvec_minmax, .extra1 = SYSCTL_ZERO, - .extra2 = &thousand, + .extra2 = SYSCTL_ONE_THOUSAND, }, { .procname = "tcp_wmem", @@ -1391,7 +1388,7 @@ static struct ctl_table ipv4_net_table[] = { .mode = 0644, .proc_handler = proc_dou8vec_minmax, .extra1 = SYSCTL_ZERO, - .extra2 = &two, + .extra2 = SYSCTL_TWO, }, { } }; diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c index d53dd142bf87..560c48d0ddb7 100644 --- a/net/ipv6/sysctl_net_ipv6.c +++ b/net/ipv6/sysctl_net_ipv6.c @@ -23,7 +23,6 @@ #endif #include -static int two = 2; static int three = 3; static int flowlabel_reflect_max = 0x7; static int auto_flowlabels_max = IP6_AUTO_FLOW_LABEL_MAX; @@ -197,7 +196,7 @@ static struct ctl_table ipv6_table_template[] = { .mode = 0644, .proc_handler = proc_dou8vec_minmax, .extra1 = SYSCTL_ZERO, - .extra2 = &two, + .extra2 = SYSCTL_TWO, }, { .procname = "ioam6_id", From patchwork Fri Apr 22 07:01:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tonghao Zhang X-Patchwork-Id: 12822855 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A1DE6C433F5 for ; Fri, 22 Apr 2022 07:02:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1444630AbiDVHFE (ORCPT ); Fri, 22 Apr 2022 03:05:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1444628AbiDVHE6 (ORCPT ); Fri, 22 Apr 2022 03:04:58 -0400 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54B0427B26; Fri, 22 Apr 2022 00:02:06 -0700 (PDT) Received: by mail-pl1-x635.google.com with SMTP id t12so8896435pll.7; Fri, 22 Apr 2022 00:02:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0YL/1W76HvmByLgLp4pwjxZ6qnySO9QREG+pOsTEezc=; b=FyUQ6iUOgLMUKM7SwMJZinXE9FShXh7tkKccLEkDRe8Q/lwHaXuYeEJAEOgSQsPH5J oBZHjCQcmGRdOCuQ83JBYfha/PFWF534jBxmNO4ZF5kpESXaiJoZt+elw/ryP/0LmBFO RyQk877i4dpDyL8AOSn7I+fc46PbwzKgpGdZ213qqSgqxU6erdcHrOiLMuyEQnP2fGjT ClRxZNYclOPwUqb95dWBXM8ZdE7ZqKbQL99zsbiUgYQNbcIZTsuMOCmK12PhOMxFKKxq 3Skw6fQsnBAoup8g7Fmv6FwD926z2kXLvnnP9DoEANT0YreH97k7HZrC+/3NIwYt6yny 4jEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0YL/1W76HvmByLgLp4pwjxZ6qnySO9QREG+pOsTEezc=; b=IfM/fXLJcfCfN6prNjTllS6UE2S33Bkp1P6r9nvWn/3KMzK1UFoMHSmBaHfGf5L1s+ uiyP04GeFtgmjOJPI1Qo9RsNu8M1xXJX2KWm2ulPZ7TCMxfm1ZW2vIydwB4FcQ7NvTq9 mQKY3DXTNQKopDy5AJsuDx/MvXivOF/otD/oi/v1yC7gSSpHNi/qMf4DMBbu1I83c9k7 HJMW3esyIfk9ox4irCU+MzExd0tPCQ5ZwlopGBJQ2668cHsj5ryTA1Q2HWTadVUeZyPc sFls9bdTijC2XyYtezOKucbKHOT3/G+zxdEolXVGgPwceUp2EYRXolD+fFSgwUGx1QM2 zROQ== X-Gm-Message-State: AOAM530RRNQuS9fFBTO4zqkcmXK22SQRcAP80wZQv5bWBYr+7JR+gS4Q +u5AXxiW/7dhAlwLWPSQqteldD+P5LYm6Q== X-Google-Smtp-Source: ABdhPJwoTNbxhrXdtq91t7cNvXh+kcL8w8bA66BSjiPw5Xqf8c9wG9/WbWJoVPOe8woGaTMIiDBOBw== X-Received: by 2002:a17:90a:558a:b0:1c6:fad4:2930 with SMTP id c10-20020a17090a558a00b001c6fad42930mr3785820pji.159.1650610925535; Fri, 22 Apr 2022 00:02:05 -0700 (PDT) Received: from localhost.localdomain ([111.204.182.100]) by smtp.gmail.com with ESMTPSA id 10-20020a17090a1a0a00b001cd630f301fsm4873467pjk.36.2022.04.22.00.01.59 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Apr 2022 00:02:05 -0700 (PDT) From: xiangxia.m.yue@gmail.com To: netdev@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: Tonghao Zhang , Luis Chamberlain , Kees Cook , Iurii Zaikin , "David S. Miller" , Jakub Kicinski , Paolo Abeni , Hideaki YOSHIFUJI , David Ahern , Simon Horman , Julian Anastasov , Pablo Neira Ayuso , Jozsef Kadlecsik , Florian Westphal , Shuah Khan , Andrew Morton , Alexei Starovoitov , Eric Dumazet , Lorenz Bauer , Akhmat Karakotov Subject: [net-next v4 2/3] net: sysctl: introduce sysctl SYSCTL_THREE Date: Fri, 22 Apr 2022 15:01:40 +0800 Message-Id: <20220422070141.39397-3-xiangxia.m.yue@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20220422070141.39397-1-xiangxia.m.yue@gmail.com> References: <20220422070141.39397-1-xiangxia.m.yue@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Tonghao Zhang 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 Cc: Kees Cook Cc: Iurii Zaikin Cc: "David S. Miller" Cc: Jakub Kicinski Cc: Paolo Abeni Cc: Hideaki YOSHIFUJI Cc: David Ahern Cc: Simon Horman Cc: Julian Anastasov Cc: Pablo Neira Ayuso Cc: Jozsef Kadlecsik Cc: Florian Westphal Cc: Shuah Khan Cc: Andrew Morton Cc: Alexei Starovoitov Cc: Eric Dumazet Cc: Lorenz Bauer Cc: Akhmat Karakotov Signed-off-by: Tonghao Zhang Reviewed-by: Simon Horman --- fs/proc/proc_sysctl.c | 2 +- include/linux/sysctl.h | 9 +++++---- net/core/sysctl_net_core.c | 3 +-- net/ipv4/sysctl_net_ipv4.c | 3 +-- net/ipv6/sysctl_net_ipv6.c | 3 +-- net/netfilter/ipvs/ip_vs_ctl.c | 4 +--- 6 files changed, 10 insertions(+), 14 deletions(-) diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c index 7d9cfc730bd4..5851c2a92c0d 100644 --- a/fs/proc/proc_sysctl.c +++ b/fs/proc/proc_sysctl.c @@ -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 }; diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h index 6353d6db69b2..80263f7cdb77 100644 --- a/include/linux/sysctl.h +++ b/include/linux/sysctl.h @@ -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[]; diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c index 3a0ce309ffcd..195ca5c28771 100644 --- a/net/core/sysctl_net_core.c +++ b/net/core/sysctl_net_core.c @@ -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", diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c index 9ff60a389cd0..cd448cdd3b38 100644 --- a/net/ipv4/sysctl_net_ipv4.c +++ b/net/ipv4/sysctl_net_ipv4.c @@ -20,7 +20,6 @@ #include #include -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", diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c index 560c48d0ddb7..94a0a294c6a1 100644 --- a/net/ipv6/sysctl_net_ipv6.c +++ b/net/ipv6/sysctl_net_ipv6.c @@ -23,7 +23,6 @@ #endif #include -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", diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c index 7f645328b47f..efab2b06d373 100644 --- a/net/netfilter/ipvs/ip_vs_ctl.c +++ b/net/netfilter/ipvs/ip_vs_ctl.c @@ -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", From patchwork Fri Apr 22 07:01:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tonghao Zhang X-Patchwork-Id: 12822856 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2AD95C433F5 for ; Fri, 22 Apr 2022 07:02:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1444634AbiDVHFG (ORCPT ); Fri, 22 Apr 2022 03:05:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1444426AbiDVHFE (ORCPT ); Fri, 22 Apr 2022 03:05:04 -0400 Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77768255B8; Fri, 22 Apr 2022 00:02:12 -0700 (PDT) Received: by mail-pg1-x52c.google.com with SMTP id t4so6662800pgc.1; Fri, 22 Apr 2022 00:02:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cE//00fhKyhkv8zXzb0JNZA/ch37kTGzwrab8yh2zXs=; b=dffSvKf9Bj3Z40NmPRAcK536nBtfkysHMIPSAilGdkxKHJoxSm891joCuWO3eHsXOf ke7xnG1cbjwANIZppjNN/6KhIOt7fbXLMnBGKEi1u+3eX4vI/XdWmRivA/IWewBfCt7c lZN7LOQjfxM2tlRZNW9Ggr1kagr5O3Wo/QZaQNSFyiRUzZYp+EP7v6MEEmmGC3vdeo5r b3O/2/qSeej9D1ZbuQTvJceISd1FbdNjeParfwTjPcLW7FXDdvv7lRTFLBi8XToI7RRm EO8gUJaGnhmtzinHmeoK1gqJtlJfwvnHPTCwRvNXDI7eOEqaATipnNqI+4Dw9rgk6RpU yJFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cE//00fhKyhkv8zXzb0JNZA/ch37kTGzwrab8yh2zXs=; b=ygBIF/byN0142bWbt9J9wMGy9Pm4F6TG/7itDyVbq6SXULOQQZLy0EYrusfgTkkt/B s8tRkokc+XTQK9yZtJRGl6idZ4XF6o7YZ5tfV1pU4GpcFAp7hpmVKuWGHALRzhI+btmU oQ8tPHgzhdNflYW2GlL+egvuBiKCaTHnE31ZgljbZuhkvdBBfRYLlK/GWAazjcg7sgZA ULg9VRmOYLjOK5+02cZp3ximxBzu/WtrUPcCWXURpVSfFxK3Co5j794v/t1+i/tY24q1 Jh87EfNVD5RCfW/Nq6p1VcBZEhjLdANHdA9YwHiCbKxZWoj7OdDfh3yJuzP52IO7ZZNZ eXZw== X-Gm-Message-State: AOAM53113wGkbsxfy03NfHhvrtSg5a/HXXIirNt3U2Meex0EEy5EV2v4 OZPOsQbSghJvkAw8SEz+eFCzcQtt3pMoww== X-Google-Smtp-Source: ABdhPJwdWW2CvZ7R9SNKW7GyJYbRfgyz+K5TLOutaoNWp+V1hWfKMb/ll60CoEFpRGtAI5TOblxnvg== X-Received: by 2002:a05:6a00:1a01:b0:505:b3e5:b5fc with SMTP id g1-20020a056a001a0100b00505b3e5b5fcmr3558569pfv.53.1650610931570; Fri, 22 Apr 2022 00:02:11 -0700 (PDT) Received: from localhost.localdomain ([111.204.182.100]) by smtp.gmail.com with ESMTPSA id 10-20020a17090a1a0a00b001cd630f301fsm4873467pjk.36.2022.04.22.00.02.05 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Apr 2022 00:02:11 -0700 (PDT) From: xiangxia.m.yue@gmail.com To: netdev@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: Tonghao Zhang , Luis Chamberlain , Kees Cook , Iurii Zaikin , "David S. Miller" , Jakub Kicinski , Paolo Abeni , Hideaki YOSHIFUJI , David Ahern , Simon Horman , Julian Anastasov , Pablo Neira Ayuso , Jozsef Kadlecsik , Florian Westphal , Shuah Khan , Andrew Morton , Alexei Starovoitov , Eric Dumazet , Lorenz Bauer , Akhmat Karakotov Subject: [net-next v4 3/3] selftests/sysctl: add sysctl macro test Date: Fri, 22 Apr 2022 15:01:41 +0800 Message-Id: <20220422070141.39397-4-xiangxia.m.yue@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20220422070141.39397-1-xiangxia.m.yue@gmail.com> References: <20220422070141.39397-1-xiangxia.m.yue@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Tonghao Zhang Cc: Luis Chamberlain Cc: Kees Cook Cc: Iurii Zaikin Cc: "David S. Miller" Cc: Jakub Kicinski Cc: Paolo Abeni Cc: Hideaki YOSHIFUJI Cc: David Ahern Cc: Simon Horman Cc: Julian Anastasov Cc: Pablo Neira Ayuso Cc: Jozsef Kadlecsik Cc: Florian Westphal Cc: Shuah Khan Cc: Andrew Morton Cc: Alexei Starovoitov Cc: Eric Dumazet Cc: Lorenz Bauer Cc: Akhmat Karakotov Signed-off-by: Tonghao Zhang --- lib/test_sysctl.c | 21 ++++++++++++ tools/testing/selftests/sysctl/sysctl.sh | 43 ++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/lib/test_sysctl.c b/lib/test_sysctl.c index a5a3d6c27e1f..43b8d502f4c7 100644 --- a/lib/test_sysctl.c +++ b/lib/test_sysctl.c @@ -43,6 +43,7 @@ struct test_sysctl_data { int int_0001; int int_0002; int int_0003[4]; + int match_int[12]; int boot_int; @@ -95,6 +96,13 @@ static struct ctl_table test_table[] = { .mode = 0644, .proc_handler = proc_dointvec, }, + { + .procname = "match_int", + .data = &test_data.match_int, + .maxlen = sizeof(test_data.match_int), + .mode = 0444, + .proc_handler = proc_dointvec, + }, { .procname = "boot_int", .data = &test_data.boot_int, @@ -132,6 +140,19 @@ static struct ctl_table_header *test_sysctl_header; static int __init test_sysctl_init(void) { + test_data.match_int[0] = *(int *)SYSCTL_ZERO, + test_data.match_int[1] = *(int *)SYSCTL_ONE, + test_data.match_int[2] = *(int *)SYSCTL_TWO, + test_data.match_int[3] = *(int *)SYSCTL_THREE, + test_data.match_int[4] = *(int *)SYSCTL_FOUR, + test_data.match_int[5] = *(int *)SYSCTL_ONE_HUNDRED, + test_data.match_int[6] = *(int *)SYSCTL_TWO_HUNDRED, + test_data.match_int[7] = *(int *)SYSCTL_ONE_THOUSAND, + test_data.match_int[8] = *(int *)SYSCTL_THREE_THOUSAND, + test_data.match_int[9] = *(int *)SYSCTL_INT_MAX, + test_data.match_int[10] = *(int *)SYSCTL_MAXOLDUID, + test_data.match_int[11] = *(int *)SYSCTL_NEG_ONE, + test_data.bitmap_0001 = kzalloc(SYSCTL_TEST_BITMAP_SIZE/8, GFP_KERNEL); if (!test_data.bitmap_0001) return -ENOMEM; diff --git a/tools/testing/selftests/sysctl/sysctl.sh b/tools/testing/selftests/sysctl/sysctl.sh index 19515dcb7d04..cd74f4749748 100755 --- a/tools/testing/selftests/sysctl/sysctl.sh +++ b/tools/testing/selftests/sysctl/sysctl.sh @@ -40,6 +40,7 @@ ALL_TESTS="$ALL_TESTS 0004:1:1:uint_0001" ALL_TESTS="$ALL_TESTS 0005:3:1:int_0003" ALL_TESTS="$ALL_TESTS 0006:50:1:bitmap_0001" ALL_TESTS="$ALL_TESTS 0007:1:1:boot_int" +ALL_TESTS="$ALL_TESTS 0008:1:1:match_int" function allow_user_defaults() { @@ -785,6 +786,47 @@ sysctl_test_0007() return $ksft_skip } +sysctl_test_0008() +{ + TARGET="${SYSCTL}/match_int" + if [ ! -f $TARGET ]; then + echo "Skipping test for $TARGET as it is not present ..." + return $ksft_skip + fi + + echo -n "Testing if $TARGET is matched with kernel ..." + ORIG_VALUES=$(cat "${TARGET}") + + # SYSCTL_ZERO 0 + # SYSCTL_ONE 1 + # SYSCTL_TWO 2 + # SYSCTL_THREE 3 + # SYSCTL_FOUR 4 + # SYSCTL_ONE_HUNDRED 100 + # SYSCTL_TWO_HUNDRED 200 + # SYSCTL_ONE_THOUSAND 1000 + # SYSCTL_THREE_THOUSAND 3000 + # SYSCTL_INT_MAX INT_MAX + # SYSCTL_MAXOLDUID 65535 + # SYSCTL_NEG_ONE -1 + local VALUES=(0 1 2 3 4 100 200 1000 3000 $INT_MAX 65535 -1) + idx=0 + + for ori in $ORIG_VALUES; do + val=${VALUES[$idx]} + if [ $ori -ne $val ]; then + echo "Expected $val, got $ori, TEST FAILED" + rc=1 + test_rc + fi + + let idx=$idx+1 + done + + echo "ok" + return 0 +} + list_tests() { echo "Test ID list:" @@ -800,6 +842,7 @@ list_tests() echo "0005 x $(get_test_count 0005) - tests proc_douintvec() array" echo "0006 x $(get_test_count 0006) - tests proc_do_large_bitmap()" echo "0007 x $(get_test_count 0007) - tests setting sysctl from kernel boot param" + echo "0008 x $(get_test_count 0008) - tests sysctl macro values match" } usage()