aboutsummaryrefslogtreecommitdiff
path: root/net/netfilter/nf_sysctl.c
blob: 06ddddb2911f8f9691757bf9a130907f1bebfc47 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/* nf_sysctl.c	netfilter sysctl registration/unregistation
 *
 * Copyright (c) 2006 Patrick McHardy <kaber@trash.net>
 */
#include <linux/module.h>
#include <linux/sysctl.h>
#include <linux/string.h>
#include <linux/slab.h>

static void
path_free(struct ctl_table *path, struct ctl_table *table)
{
	struct ctl_table *t, *next;

	for (t = path; t != NULL && t != table; t = next) {
		next = t->child;
		kfree(t);
	}
}

static struct ctl_table *
path_dup(struct ctl_table *path, struct ctl_table *table)
{
	struct ctl_table *t, *last = NULL, *tmp;

	for (t = path; t != NULL; t = t->child) {
		/* twice the size since path elements are terminated by an
		 * empty element */
		tmp = kmemdup(t, 2 * sizeof(*t), GFP_KERNEL);
		if (tmp == NULL) {
			if (last != NULL)
				path_free(path, table);
			return NULL;
		}

		if (last != NULL)
			last->child = tmp;
		else
			path = tmp;
		last = tmp;
	}

	if (last != NULL)
		last->child = table;
	else
		path = table;

	return path;
}

struct ctl_table_header *
nf_register_sysctl_table(struct ctl_table *path, struct ctl_table *table)
{
	struct ctl_table_header *header;

	path = path_dup(path, table);
	if (path == NULL)
		return NULL;
	header = register_sysctl_table(path, 0);
	if (header == NULL)
		path_free(path, table);
	return header;
}
EXPORT_SYMBOL_GPL(nf_register_sysctl_table);

void
nf_unregister_sysctl_table(struct ctl_table_header *header,
			   struct ctl_table *table)
{
	struct ctl_table *path = header->ctl_table;

	unregister_sysctl_table(header);
	path_free(path, table);
}
EXPORT_SYMBOL_GPL(nf_unregister_sysctl_table);

/* net/netfilter */
static struct ctl_table nf_net_netfilter_table[] = {
	{
		.ctl_name	= NET_NETFILTER,
		.procname	= "netfilter",
		.mode		= 0555,
	},
	{
		.ctl_name	= 0
	}
};
struct ctl_table nf_net_netfilter_sysctl_path[] = {
	{
		.ctl_name	= CTL_NET,
		.procname	= "net",
		.mode		= 0555,
		.child		= nf_net_netfilter_table,
	},
	{
		.ctl_name	= 0
	}
};
EXPORT_SYMBOL_GPL(nf_net_netfilter_sysctl_path);

/* net/ipv4/netfilter */
static struct ctl_table nf_net_ipv4_netfilter_table[] = {
	{
		.ctl_name	= NET_IPV4_NETFILTER,
		.procname	= "netfilter",
		.mode		= 0555,
	},
	{
		.ctl_name	= 0
	}
};
static struct ctl_table nf_net_ipv4_table[] = {
	{
		.ctl_name	= NET_IPV4,
		.procname	= "ipv4",
		.mode		= 0555,
		.child		= nf_net_ipv4_netfilter_table,
	},
	{
		.ctl_name	= 0
	}
};
struct ctl_table nf_net_ipv4_netfilter_sysctl_path[] = {
	{
		.ctl_name	= CTL_NET,
		.procname	= "net",
		.mode		= 0555,
		.child		= nf_net_ipv4_table,
	},
	{
		.ctl_name	= 0
	}
};
EXPORT_SYMBOL_GPL(nf_net_ipv4_netfilter_sysctl_path);