Commit ba6b918a authored by Cong Wang's avatar Cong Wang Committed by David S. Miller

ping: move ping_group_range out of CONFIG_SYSCTL

Similarly, when CONFIG_SYSCTL is not set, ping_group_range should still
work, just that no one can change it. Therefore we should move it out of
sysctl_net_ipv4.c. And, it should not share the same seqlock with
ip_local_port_range.

BTW, rename it to ->ping_group_range instead.

Cc: David S. Miller <davem@davemloft.net>
Cc: Francois Romieu <romieu@fr.zoreil.com>
Reported-by: default avatarStefan de Konink <stefan@konink.de>
Signed-off-by: default avatarCong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent c9d8f1a6
...@@ -20,6 +20,11 @@ struct local_ports { ...@@ -20,6 +20,11 @@ struct local_ports {
int range[2]; int range[2];
}; };
struct ping_group_range {
seqlock_t lock;
kgid_t range[2];
};
struct netns_ipv4 { struct netns_ipv4 {
#ifdef CONFIG_SYSCTL #ifdef CONFIG_SYSCTL
struct ctl_table_header *forw_hdr; struct ctl_table_header *forw_hdr;
...@@ -72,7 +77,7 @@ struct netns_ipv4 { ...@@ -72,7 +77,7 @@ struct netns_ipv4 {
int sysctl_ip_no_pmtu_disc; int sysctl_ip_no_pmtu_disc;
int sysctl_ip_fwd_use_pmtu; int sysctl_ip_fwd_use_pmtu;
kgid_t sysctl_ping_group_range[2]; struct ping_group_range ping_group_range;
atomic_t dev_addr_genid; atomic_t dev_addr_genid;
......
...@@ -1658,6 +1658,14 @@ static __net_init int inet_init_net(struct net *net) ...@@ -1658,6 +1658,14 @@ static __net_init int inet_init_net(struct net *net)
seqlock_init(&net->ipv4.ip_local_ports.lock); seqlock_init(&net->ipv4.ip_local_ports.lock);
net->ipv4.ip_local_ports.range[0] = 32768; net->ipv4.ip_local_ports.range[0] = 32768;
net->ipv4.ip_local_ports.range[1] = 61000; net->ipv4.ip_local_ports.range[1] = 61000;
seqlock_init(&net->ipv4.ping_group_range.lock);
/*
* Sane defaults - nobody may create ping sockets.
* Boot scripts should set this to distro-specific group.
*/
net->ipv4.ping_group_range.range[0] = make_kgid(&init_user_ns, 1);
net->ipv4.ping_group_range.range[1] = make_kgid(&init_user_ns, 0);
return 0; return 0;
} }
......
...@@ -236,15 +236,15 @@ static struct sock *ping_lookup(struct net *net, struct sk_buff *skb, u16 ident) ...@@ -236,15 +236,15 @@ static struct sock *ping_lookup(struct net *net, struct sk_buff *skb, u16 ident)
static void inet_get_ping_group_range_net(struct net *net, kgid_t *low, static void inet_get_ping_group_range_net(struct net *net, kgid_t *low,
kgid_t *high) kgid_t *high)
{ {
kgid_t *data = net->ipv4.sysctl_ping_group_range; kgid_t *data = net->ipv4.ping_group_range.range;
unsigned int seq; unsigned int seq;
do { do {
seq = read_seqbegin(&net->ipv4.ip_local_ports.lock); seq = read_seqbegin(&net->ipv4.ping_group_range.lock);
*low = data[0]; *low = data[0];
*high = data[1]; *high = data[1];
} while (read_seqretry(&net->ipv4.ip_local_ports.lock, seq)); } while (read_seqretry(&net->ipv4.ping_group_range.lock, seq));
} }
......
...@@ -87,7 +87,7 @@ static void inet_get_ping_group_range_table(struct ctl_table *table, kgid_t *low ...@@ -87,7 +87,7 @@ static void inet_get_ping_group_range_table(struct ctl_table *table, kgid_t *low
{ {
kgid_t *data = table->data; kgid_t *data = table->data;
struct net *net = struct net *net =
container_of(table->data, struct net, ipv4.sysctl_ping_group_range); container_of(table->data, struct net, ipv4.ping_group_range.range);
unsigned int seq; unsigned int seq;
do { do {
seq = read_seqbegin(&net->ipv4.ip_local_ports.lock); seq = read_seqbegin(&net->ipv4.ip_local_ports.lock);
...@@ -102,7 +102,7 @@ static void set_ping_group_range(struct ctl_table *table, kgid_t low, kgid_t hig ...@@ -102,7 +102,7 @@ static void set_ping_group_range(struct ctl_table *table, kgid_t low, kgid_t hig
{ {
kgid_t *data = table->data; kgid_t *data = table->data;
struct net *net = struct net *net =
container_of(table->data, struct net, ipv4.sysctl_ping_group_range); container_of(table->data, struct net, ipv4.ping_group_range.range);
write_seqlock(&net->ipv4.ip_local_ports.lock); write_seqlock(&net->ipv4.ip_local_ports.lock);
data[0] = low; data[0] = low;
data[1] = high; data[1] = high;
...@@ -805,7 +805,7 @@ static struct ctl_table ipv4_net_table[] = { ...@@ -805,7 +805,7 @@ static struct ctl_table ipv4_net_table[] = {
}, },
{ {
.procname = "ping_group_range", .procname = "ping_group_range",
.data = &init_net.ipv4.sysctl_ping_group_range, .data = &init_net.ipv4.ping_group_range.range,
.maxlen = sizeof(gid_t)*2, .maxlen = sizeof(gid_t)*2,
.mode = 0644, .mode = 0644,
.proc_handler = ipv4_ping_group_range, .proc_handler = ipv4_ping_group_range,
...@@ -858,13 +858,6 @@ static __net_init int ipv4_sysctl_init_net(struct net *net) ...@@ -858,13 +858,6 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
table[i].data += (void *)net - (void *)&init_net; table[i].data += (void *)net - (void *)&init_net;
} }
/*
* Sane defaults - nobody may create ping sockets.
* Boot scripts should set this to distro-specific group.
*/
net->ipv4.sysctl_ping_group_range[0] = make_kgid(&init_user_ns, 1);
net->ipv4.sysctl_ping_group_range[1] = make_kgid(&init_user_ns, 0);
net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table); net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
if (net->ipv4.ipv4_hdr == NULL) if (net->ipv4.ipv4_hdr == NULL)
goto err_reg; goto err_reg;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment