Commit 607ea7cd authored by Konstantin Khlebnikov's avatar Konstantin Khlebnikov Committed by David S. Miller

net/ipv6/addrconf: simplify sysctl registration

Struct ctl_table_header holds pointer to sysctl table which could be used
for freeing it after unregistration. IPv4 sysctls already use that.
Remove redundant NULL assignment: ndev allocated using kzalloc.

This also saves some bytes: sysctl table could be shorter than
DEVCONF_MAX+1 if some options are disable in config.
Signed-off-by: default avatarKonstantin Khlebnikov <khlebnikov@yandex-team.ru>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 35c58459
...@@ -63,7 +63,8 @@ struct ipv6_devconf { ...@@ -63,7 +63,8 @@ struct ipv6_devconf {
} stable_secret; } stable_secret;
__s32 use_oif_addrs_only; __s32 use_oif_addrs_only;
__s32 keep_addr_on_down; __s32 keep_addr_on_down;
void *sysctl;
struct ctl_table_header *sysctl_header;
}; };
struct ipv6_params { struct ipv6_params {
......
...@@ -359,7 +359,6 @@ static struct inet6_dev *ipv6_add_dev(struct net_device *dev) ...@@ -359,7 +359,6 @@ static struct inet6_dev *ipv6_add_dev(struct net_device *dev)
ndev->addr_gen_mode = IN6_ADDR_GEN_MODE_EUI64; ndev->addr_gen_mode = IN6_ADDR_GEN_MODE_EUI64;
ndev->cnf.mtu6 = dev->mtu; ndev->cnf.mtu6 = dev->mtu;
ndev->cnf.sysctl = NULL;
ndev->nd_parms = neigh_parms_alloc(dev, &nd_tbl); ndev->nd_parms = neigh_parms_alloc(dev, &nd_tbl);
if (!ndev->nd_parms) { if (!ndev->nd_parms) {
kfree(ndev); kfree(ndev);
...@@ -5620,13 +5619,7 @@ int addrconf_sysctl_ignore_routes_with_linkdown(struct ctl_table *ctl, ...@@ -5620,13 +5619,7 @@ int addrconf_sysctl_ignore_routes_with_linkdown(struct ctl_table *ctl,
return ret; return ret;
} }
static struct addrconf_sysctl_table static const struct ctl_table addrconf_sysctl[] = {
{
struct ctl_table_header *sysctl_header;
struct ctl_table addrconf_vars[DEVCONF_MAX+1];
} addrconf_sysctl __read_mostly = {
.sysctl_header = NULL,
.addrconf_vars = {
{ {
.procname = "forwarding", .procname = "forwarding",
.data = &ipv6_devconf.forwarding, .data = &ipv6_devconf.forwarding,
...@@ -5944,52 +5937,50 @@ static struct addrconf_sysctl_table ...@@ -5944,52 +5937,50 @@ static struct addrconf_sysctl_table
{ {
/* sentinel */ /* sentinel */
} }
},
}; };
static int __addrconf_sysctl_register(struct net *net, char *dev_name, static int __addrconf_sysctl_register(struct net *net, char *dev_name,
struct inet6_dev *idev, struct ipv6_devconf *p) struct inet6_dev *idev, struct ipv6_devconf *p)
{ {
int i; int i;
struct addrconf_sysctl_table *t; struct ctl_table *table;
char path[sizeof("net/ipv6/conf/") + IFNAMSIZ]; char path[sizeof("net/ipv6/conf/") + IFNAMSIZ];
t = kmemdup(&addrconf_sysctl, sizeof(*t), GFP_KERNEL); table = kmemdup(addrconf_sysctl, sizeof(addrconf_sysctl), GFP_KERNEL);
if (!t) if (!table)
goto out; goto out;
for (i = 0; t->addrconf_vars[i].data; i++) { for (i = 0; table[i].data; i++) {
t->addrconf_vars[i].data += (char *)p - (char *)&ipv6_devconf; table[i].data += (char *)p - (char *)&ipv6_devconf;
t->addrconf_vars[i].extra1 = idev; /* embedded; no ref */ table[i].extra1 = idev; /* embedded; no ref */
t->addrconf_vars[i].extra2 = net; table[i].extra2 = net;
} }
snprintf(path, sizeof(path), "net/ipv6/conf/%s", dev_name); snprintf(path, sizeof(path), "net/ipv6/conf/%s", dev_name);
t->sysctl_header = register_net_sysctl(net, path, t->addrconf_vars); p->sysctl_header = register_net_sysctl(net, path, table);
if (!t->sysctl_header) if (!p->sysctl_header)
goto free; goto free;
p->sysctl = t;
return 0; return 0;
free: free:
kfree(t); kfree(table);
out: out:
return -ENOBUFS; return -ENOBUFS;
} }
static void __addrconf_sysctl_unregister(struct ipv6_devconf *p) static void __addrconf_sysctl_unregister(struct ipv6_devconf *p)
{ {
struct addrconf_sysctl_table *t; struct ctl_table *table;
if (!p->sysctl) if (!p->sysctl_header)
return; return;
t = p->sysctl; table = p->sysctl_header->ctl_table_arg;
p->sysctl = NULL; unregister_net_sysctl_table(p->sysctl_header);
unregister_net_sysctl_table(t->sysctl_header); p->sysctl_header = NULL;
kfree(t); kfree(table);
} }
static int addrconf_sysctl_register(struct inet6_dev *idev) static int addrconf_sysctl_register(struct inet6_dev *idev)
......
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