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: Stefan de Konink <stefan@konink.de> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
c9d8f1a642
commit
ba6b918ab2
|
@ -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 {
|
||||||
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)
|
||||||
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 @@ exit:
|
||||||
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
|
||||||
{
|
{
|
||||||
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
|
||||||
{
|
{
|
||||||
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[] = {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
.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)
|
||||||
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;
|
||||||
|
|
Loading…
Reference in New Issue