Skip to content

Commit 4a65798

Browse files
Florian Westphalummakynes
authored andcommitted
netfilter: conntrack: add mnemonics for sysctl table
Its a bit hard to see what table[3] really lines up with, so add human-readable mnemonics and use them for initialisation. This makes it easier to see e.g. which sysctls are not exported to unprivileged userns. objdiff shows no changes. Signed-off-by: Florian Westphal <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 4b216e2 commit 4a65798

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

net/netfilter/nf_conntrack_standalone.c

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -532,36 +532,45 @@ nf_conntrack_hash_sysctl(struct ctl_table *table, int write,
532532

533533
static struct ctl_table_header *nf_ct_netfilter_header;
534534

535+
enum nf_ct_sysctl_index {
536+
NF_SYSCTL_CT_MAX,
537+
NF_SYSCTL_CT_COUNT,
538+
NF_SYSCTL_CT_BUCKETS,
539+
NF_SYSCTL_CT_CHECKSUM,
540+
NF_SYSCTL_CT_LOG_INVALID,
541+
NF_SYSCTL_CT_EXPECT_MAX,
542+
};
543+
535544
static struct ctl_table nf_ct_sysctl_table[] = {
536-
{
545+
[NF_SYSCTL_CT_MAX] = {
537546
.procname = "nf_conntrack_max",
538547
.data = &nf_conntrack_max,
539548
.maxlen = sizeof(int),
540549
.mode = 0644,
541550
.proc_handler = proc_dointvec,
542551
},
543-
{
552+
[NF_SYSCTL_CT_COUNT] = {
544553
.procname = "nf_conntrack_count",
545554
.data = &init_net.ct.count,
546555
.maxlen = sizeof(int),
547556
.mode = 0444,
548557
.proc_handler = proc_dointvec,
549558
},
550-
{
559+
[NF_SYSCTL_CT_BUCKETS] = {
551560
.procname = "nf_conntrack_buckets",
552561
.data = &nf_conntrack_htable_size_user,
553562
.maxlen = sizeof(unsigned int),
554563
.mode = 0644,
555564
.proc_handler = nf_conntrack_hash_sysctl,
556565
},
557-
{
566+
[NF_SYSCTL_CT_CHECKSUM] = {
558567
.procname = "nf_conntrack_checksum",
559568
.data = &init_net.ct.sysctl_checksum,
560569
.maxlen = sizeof(unsigned int),
561570
.mode = 0644,
562571
.proc_handler = proc_dointvec,
563572
},
564-
{
573+
[NF_SYSCTL_CT_LOG_INVALID] = {
565574
.procname = "nf_conntrack_log_invalid",
566575
.data = &init_net.ct.sysctl_log_invalid,
567576
.maxlen = sizeof(unsigned int),
@@ -570,7 +579,7 @@ static struct ctl_table nf_ct_sysctl_table[] = {
570579
.extra1 = &log_invalid_proto_min,
571580
.extra2 = &log_invalid_proto_max,
572581
},
573-
{
582+
[NF_SYSCTL_CT_EXPECT_MAX] = {
574583
.procname = "nf_conntrack_expect_max",
575584
.data = &nf_ct_expect_max,
576585
.maxlen = sizeof(int),
@@ -600,16 +609,16 @@ static int nf_conntrack_standalone_init_sysctl(struct net *net)
600609
if (!table)
601610
goto out_kmemdup;
602611

603-
table[1].data = &net->ct.count;
604-
table[3].data = &net->ct.sysctl_checksum;
605-
table[4].data = &net->ct.sysctl_log_invalid;
612+
table[NF_SYSCTL_CT_COUNT].data = &net->ct.count;
613+
table[NF_SYSCTL_CT_CHECKSUM].data = &net->ct.sysctl_checksum;
614+
table[NF_SYSCTL_CT_LOG_INVALID].data = &net->ct.sysctl_log_invalid;
606615

607616
/* Don't export sysctls to unprivileged users */
608617
if (net->user_ns != &init_user_ns)
609-
table[0].procname = NULL;
618+
table[NF_SYSCTL_CT_MAX].procname = NULL;
610619

611620
if (!net_eq(&init_net, net))
612-
table[2].mode = 0444;
621+
table[NF_SYSCTL_CT_BUCKETS].mode = 0444;
613622

614623
net->ct.sysctl_header = register_net_sysctl(net, "net/netfilter", table);
615624
if (!net->ct.sysctl_header)

0 commit comments

Comments
 (0)