Commit 8607ddb8 authored by Eric W. Biederman's avatar Eric W. Biederman Committed by David S. Miller

net ipv4: Convert devinet to use register_net_sysctl

Using an ascii path to register_net_sysctl as opposed to the slightly
awkward ctl_path allows for much simpler code.

We no longer need to malloc dev_name to keep it alive the length of our
sysctl register instead we can use a small temporary buffer on the
stack.
Signed-off-by: default avatarEric W. Biederman <ebiederm@xmission.com>
Acked-by: default avatarPavel Emelyanov <xemul@parallels.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 6105e293
...@@ -1585,7 +1585,6 @@ static int ipv4_doint_and_flush(ctl_table *ctl, int write, ...@@ -1585,7 +1585,6 @@ static int ipv4_doint_and_flush(ctl_table *ctl, int write,
static struct devinet_sysctl_table { static struct devinet_sysctl_table {
struct ctl_table_header *sysctl_header; struct ctl_table_header *sysctl_header;
struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX]; struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
char *dev_name;
} devinet_sysctl = { } devinet_sysctl = {
.devinet_vars = { .devinet_vars = {
DEVINET_SYSCTL_COMPLEX_ENTRY(FORWARDING, "forwarding", DEVINET_SYSCTL_COMPLEX_ENTRY(FORWARDING, "forwarding",
...@@ -1627,16 +1626,7 @@ static int __devinet_sysctl_register(struct net *net, char *dev_name, ...@@ -1627,16 +1626,7 @@ static int __devinet_sysctl_register(struct net *net, char *dev_name,
{ {
int i; int i;
struct devinet_sysctl_table *t; struct devinet_sysctl_table *t;
char path[sizeof("net/ipv4/conf/") + IFNAMSIZ];
#define DEVINET_CTL_PATH_DEV 3
struct ctl_path devinet_ctl_path[] = {
{ .procname = "net", },
{ .procname = "ipv4", },
{ .procname = "conf", },
{ /* to be set */ },
{ },
};
t = kmemdup(&devinet_sysctl, sizeof(*t), GFP_KERNEL); t = kmemdup(&devinet_sysctl, sizeof(*t), GFP_KERNEL);
if (!t) if (!t)
...@@ -1648,27 +1638,15 @@ static int __devinet_sysctl_register(struct net *net, char *dev_name, ...@@ -1648,27 +1638,15 @@ static int __devinet_sysctl_register(struct net *net, char *dev_name,
t->devinet_vars[i].extra2 = net; t->devinet_vars[i].extra2 = net;
} }
/* snprintf(path, sizeof(path), "net/ipv4/conf/%s", dev_name);
* Make a copy of dev_name, because '.procname' is regarded as const
* by sysctl and we wouldn't want anyone to change it under our feet
* (see SIOCSIFNAME).
*/
t->dev_name = kstrdup(dev_name, GFP_KERNEL);
if (!t->dev_name)
goto free;
devinet_ctl_path[DEVINET_CTL_PATH_DEV].procname = t->dev_name;
t->sysctl_header = register_net_sysctl_table(net, devinet_ctl_path, t->sysctl_header = register_net_sysctl(net, path, t->devinet_vars);
t->devinet_vars);
if (!t->sysctl_header) if (!t->sysctl_header)
goto free_procname; goto free;
p->sysctl = t; p->sysctl = t;
return 0; return 0;
free_procname:
kfree(t->dev_name);
free: free:
kfree(t); kfree(t);
out: out:
...@@ -1684,7 +1662,6 @@ static void __devinet_sysctl_unregister(struct ipv4_devconf *cnf) ...@@ -1684,7 +1662,6 @@ static void __devinet_sysctl_unregister(struct ipv4_devconf *cnf)
cnf->sysctl = NULL; cnf->sysctl = NULL;
unregister_net_sysctl_table(t->sysctl_header); unregister_net_sysctl_table(t->sysctl_header);
kfree(t->dev_name);
kfree(t); kfree(t);
} }
...@@ -1714,12 +1691,6 @@ static struct ctl_table ctl_forward_entry[] = { ...@@ -1714,12 +1691,6 @@ static struct ctl_table ctl_forward_entry[] = {
}, },
{ }, { },
}; };
static __net_initdata struct ctl_path net_ipv4_path[] = {
{ .procname = "net", },
{ .procname = "ipv4", },
{ },
};
#endif #endif
static __net_init int devinet_init_net(struct net *net) static __net_init int devinet_init_net(struct net *net)
...@@ -1765,7 +1736,7 @@ static __net_init int devinet_init_net(struct net *net) ...@@ -1765,7 +1736,7 @@ static __net_init int devinet_init_net(struct net *net)
goto err_reg_dflt; goto err_reg_dflt;
err = -ENOMEM; err = -ENOMEM;
forw_hdr = register_net_sysctl_table(net, net_ipv4_path, tbl); forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
if (forw_hdr == NULL) if (forw_hdr == NULL)
goto err_reg_ctl; goto err_reg_ctl;
net->ipv4.forw_hdr = forw_hdr; net->ipv4.forw_hdr = forw_hdr;
......
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