Commit 0ca7a4c8 authored by Eric W. Biederman's avatar Eric W. Biederman Committed by David S. Miller

net ax25: Simplify and cleanup the ax25 sysctl handling.

Don't register/unregister every ax25 table in a batch.  Instead register
and unregister per device ax25 sysctls as ax25 devices come and go.

This moves ax25 to be a completely modern sysctl user.  Registering the
sysctls in just the initial network namespace, removing the use of
.child entries that are no longer natively supported by the sysctl core
and taking advantage of the fact that there are no longer any ordering
constraints between registering and unregistering different sysctl
tables.
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 4e5ca785
...@@ -215,7 +215,7 @@ typedef struct ax25_dev { ...@@ -215,7 +215,7 @@ typedef struct ax25_dev {
struct ax25_dev *next; struct ax25_dev *next;
struct net_device *dev; struct net_device *dev;
struct net_device *forward; struct net_device *forward;
struct ctl_table *systable; struct ctl_table_header *sysheader;
int values[AX25_MAX_VALUES]; int values[AX25_MAX_VALUES];
#if defined(CONFIG_AX25_DAMA_SLAVE) || defined(CONFIG_AX25_DAMA_MASTER) #if defined(CONFIG_AX25_DAMA_SLAVE) || defined(CONFIG_AX25_DAMA_MASTER)
ax25_dama_info dama; ax25_dama_info dama;
...@@ -441,11 +441,11 @@ extern void ax25_uid_free(void); ...@@ -441,11 +441,11 @@ extern void ax25_uid_free(void);
/* sysctl_net_ax25.c */ /* sysctl_net_ax25.c */
#ifdef CONFIG_SYSCTL #ifdef CONFIG_SYSCTL
extern void ax25_register_sysctl(void); extern int ax25_register_dev_sysctl(ax25_dev *ax25_dev);
extern void ax25_unregister_sysctl(void); extern void ax25_unregister_dev_sysctl(ax25_dev *ax25_dev);
#else #else
static inline void ax25_register_sysctl(void) {}; static inline int ax25_register_dev_sysctl(ax25_dev *ax25_dev) { return 0 };
static inline void ax25_unregister_sysctl(void) {}; static inline void ax25_unregister_dev_sysctl(ax25_dev *ax25_dev) {};
#endif /* CONFIG_SYSCTL */ #endif /* CONFIG_SYSCTL */
#endif #endif
...@@ -1990,7 +1990,6 @@ static int __init ax25_init(void) ...@@ -1990,7 +1990,6 @@ static int __init ax25_init(void)
sock_register(&ax25_family_ops); sock_register(&ax25_family_ops);
dev_add_pack(&ax25_packet_type); dev_add_pack(&ax25_packet_type);
register_netdevice_notifier(&ax25_dev_notifier); register_netdevice_notifier(&ax25_dev_notifier);
ax25_register_sysctl();
proc_net_fops_create(&init_net, "ax25_route", S_IRUGO, &ax25_route_fops); proc_net_fops_create(&init_net, "ax25_route", S_IRUGO, &ax25_route_fops);
proc_net_fops_create(&init_net, "ax25", S_IRUGO, &ax25_info_fops); proc_net_fops_create(&init_net, "ax25", S_IRUGO, &ax25_info_fops);
...@@ -2015,7 +2014,6 @@ static void __exit ax25_exit(void) ...@@ -2015,7 +2014,6 @@ static void __exit ax25_exit(void)
ax25_uid_free(); ax25_uid_free();
ax25_dev_free(); ax25_dev_free();
ax25_unregister_sysctl();
unregister_netdevice_notifier(&ax25_dev_notifier); unregister_netdevice_notifier(&ax25_dev_notifier);
dev_remove_pack(&ax25_packet_type); dev_remove_pack(&ax25_packet_type);
......
...@@ -59,8 +59,6 @@ void ax25_dev_device_up(struct net_device *dev) ...@@ -59,8 +59,6 @@ void ax25_dev_device_up(struct net_device *dev)
return; return;
} }
ax25_unregister_sysctl();
dev->ax25_ptr = ax25_dev; dev->ax25_ptr = ax25_dev;
ax25_dev->dev = dev; ax25_dev->dev = dev;
dev_hold(dev); dev_hold(dev);
...@@ -90,7 +88,7 @@ void ax25_dev_device_up(struct net_device *dev) ...@@ -90,7 +88,7 @@ void ax25_dev_device_up(struct net_device *dev)
ax25_dev_list = ax25_dev; ax25_dev_list = ax25_dev;
spin_unlock_bh(&ax25_dev_lock); spin_unlock_bh(&ax25_dev_lock);
ax25_register_sysctl(); ax25_register_dev_sysctl(ax25_dev);
} }
void ax25_dev_device_down(struct net_device *dev) void ax25_dev_device_down(struct net_device *dev)
...@@ -100,7 +98,7 @@ void ax25_dev_device_down(struct net_device *dev) ...@@ -100,7 +98,7 @@ void ax25_dev_device_down(struct net_device *dev)
if ((ax25_dev = ax25_dev_ax25dev(dev)) == NULL) if ((ax25_dev = ax25_dev_ax25dev(dev)) == NULL)
return; return;
ax25_unregister_sysctl(); ax25_unregister_dev_sysctl(ax25_dev);
spin_lock_bh(&ax25_dev_lock); spin_lock_bh(&ax25_dev_lock);
...@@ -120,7 +118,6 @@ void ax25_dev_device_down(struct net_device *dev) ...@@ -120,7 +118,6 @@ void ax25_dev_device_down(struct net_device *dev)
spin_unlock_bh(&ax25_dev_lock); spin_unlock_bh(&ax25_dev_lock);
dev_put(dev); dev_put(dev);
kfree(ax25_dev); kfree(ax25_dev);
ax25_register_sysctl();
return; return;
} }
...@@ -130,7 +127,6 @@ void ax25_dev_device_down(struct net_device *dev) ...@@ -130,7 +127,6 @@ void ax25_dev_device_down(struct net_device *dev)
spin_unlock_bh(&ax25_dev_lock); spin_unlock_bh(&ax25_dev_lock);
dev_put(dev); dev_put(dev);
kfree(ax25_dev); kfree(ax25_dev);
ax25_register_sysctl();
return; return;
} }
...@@ -138,8 +134,6 @@ void ax25_dev_device_down(struct net_device *dev) ...@@ -138,8 +134,6 @@ void ax25_dev_device_down(struct net_device *dev)
} }
spin_unlock_bh(&ax25_dev_lock); spin_unlock_bh(&ax25_dev_lock);
dev->ax25_ptr = NULL; dev->ax25_ptr = NULL;
ax25_register_sysctl();
} }
int ax25_fwd_ioctl(unsigned int cmd, struct ax25_fwd_struct *fwd) int ax25_fwd_ioctl(unsigned int cmd, struct ax25_fwd_struct *fwd)
......
...@@ -29,17 +29,6 @@ static int min_proto[1], max_proto[] = { AX25_PROTO_MAX }; ...@@ -29,17 +29,6 @@ static int min_proto[1], max_proto[] = { AX25_PROTO_MAX };
static int min_ds_timeout[1], max_ds_timeout[] = {65535000}; static int min_ds_timeout[1], max_ds_timeout[] = {65535000};
#endif #endif
static struct ctl_table_header *ax25_table_header;
static ctl_table *ax25_table;
static int ax25_table_size;
static struct ctl_path ax25_path[] = {
{ .procname = "net", },
{ .procname = "ax25", },
{ }
};
static const ctl_table ax25_param_table[] = { static const ctl_table ax25_param_table[] = {
{ {
.procname = "ip_default_mode", .procname = "ip_default_mode",
...@@ -159,52 +148,37 @@ static const ctl_table ax25_param_table[] = { ...@@ -159,52 +148,37 @@ static const ctl_table ax25_param_table[] = {
{ } /* that's all, folks! */ { } /* that's all, folks! */
}; };
void ax25_register_sysctl(void) int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
{ {
ax25_dev *ax25_dev; char path[sizeof("net/ax25/") + IFNAMSIZ];
int n, k; int k;
struct ctl_table *table;
spin_lock_bh(&ax25_dev_lock);
for (ax25_table_size = sizeof(ctl_table), ax25_dev = ax25_dev_list; ax25_dev != NULL; ax25_dev = ax25_dev->next)
ax25_table_size += sizeof(ctl_table);
if ((ax25_table = kzalloc(ax25_table_size, GFP_ATOMIC)) == NULL) {
spin_unlock_bh(&ax25_dev_lock);
return;
}
for (n = 0, ax25_dev = ax25_dev_list; ax25_dev != NULL; ax25_dev = ax25_dev->next) {
struct ctl_table *child = kmemdup(ax25_param_table,
sizeof(ax25_param_table),
GFP_ATOMIC);
if (!child) {
while (n--)
kfree(ax25_table[n].child);
kfree(ax25_table);
spin_unlock_bh(&ax25_dev_lock);
return;
}
ax25_table[n].child = ax25_dev->systable = child;
ax25_table[n].procname = ax25_dev->dev->name;
ax25_table[n].mode = 0555;
table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
if (!table)
return -ENOMEM;
for (k = 0; k < AX25_MAX_VALUES; k++) for (k = 0; k < AX25_MAX_VALUES; k++)
child[k].data = &ax25_dev->values[k]; table[k].data = &ax25_dev->values[k];
n++; snprintf(path, sizeof(path), "net/ax25/%s", ax25_dev->dev->name);
ax25_dev->sysheader = register_net_sysctl(&init_net, path, table);
if (!ax25_dev->sysheader) {
kfree(table);
return -ENOMEM;
} }
spin_unlock_bh(&ax25_dev_lock); return 0;
ax25_table_header = register_net_sysctl_table(&init_net, ax25_path, ax25_table);
} }
void ax25_unregister_sysctl(void) void ax25_unregister_dev_sysctl(ax25_dev *ax25_dev)
{ {
ctl_table *p; struct ctl_table_header *header = ax25_dev->sysheader;
unregister_net_sysctl_table(ax25_table_header); struct ctl_table *table;
for (p = ax25_table; p->procname; p++) if (header) {
kfree(p->child); ax25_dev->sysheader = NULL;
kfree(ax25_table); table = header->ctl_table_arg;
unregister_net_sysctl_table(header);
kfree(table);
}
} }
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