New object: set of sysctls [currently - root and per-net-ns].
Contains: pointer to parent set, list of tables and "should I see this set?"
method (->is_seen(set)).
Current lists of tables are subsumed by that; net-ns contains such a beast.
->lookup() for ctl_table_root returns pointer to ctl_table_set instead of
that to ->list of that ctl_table_set.
[folded compile fixes by rdd for configs without sysctl]
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
struct nsproxy;
struct ctl_table_root;
+struct ctl_table_set {
+ struct list_head list;
+ struct ctl_table_set *parent;
+ int (*is_seen)(struct ctl_table_set *);
+};
+
+extern void setup_sysctl_set(struct ctl_table_set *p,
+ struct ctl_table_set *parent,
+ int (*is_seen)(struct ctl_table_set *));
+
extern struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev);
extern struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
struct ctl_table_header *prev);
struct ctl_table_root {
struct list_head root_list;
- struct list_head header_list;
- struct list_head *(*lookup)(struct ctl_table_root *root,
+ struct ctl_table_set default_set;
+ struct ctl_table_set *(*lookup)(struct ctl_table_root *root,
struct nsproxy *namespaces);
int (*permissions)(struct ctl_table_root *root,
struct nsproxy *namespaces, struct ctl_table *table);
struct completion *unregistering;
struct ctl_table *ctl_table_arg;
struct ctl_table_root *root;
+ struct ctl_table_set *set;
};
/* struct ctl_path describes where in the hierarchy a table is added */
struct proc_dir_entry *proc_net;
struct proc_dir_entry *proc_net_stat;
- struct list_head sysctl_table_headers;
+#ifdef CONFIG_SYSCTL
+ struct ctl_table_set sysctls;
+#endif
struct net_device *loopback_dev; /* The loopback */
static struct ctl_table_root sysctl_table_root;
static struct ctl_table_header root_table_header = {
.ctl_table = root_table,
- .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.header_list),
+ .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
.root = &sysctl_table_root,
+ .set = &sysctl_table_root.default_set,
};
static struct ctl_table_root sysctl_table_root = {
.root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
- .header_list = LIST_HEAD_INIT(root_table_header.ctl_entry),
+ .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
};
static struct ctl_table kern_table[];
spin_unlock(&sysctl_lock);
}
+static struct ctl_table_set *
+lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
+{
+ struct ctl_table_set *set = &root->default_set;
+ if (root->lookup)
+ set = root->lookup(root, namespaces);
+ return set;
+}
+
static struct list_head *
lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
{
- struct list_head *header_list;
- header_list = &root->header_list;
- if (root->lookup)
- header_list = root->lookup(root, namespaces);
- return header_list;
+ struct ctl_table_set *set = lookup_header_set(root, namespaces);
+ return &set->list;
}
struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
struct nsproxy *namespaces,
const struct ctl_path *path, struct ctl_table *table)
{
- struct list_head *header_list;
struct ctl_table_header *header;
struct ctl_table *new, **prevp;
unsigned int n, npath;
}
#endif
spin_lock(&sysctl_lock);
- header_list = lookup_header_list(root, namespaces);
- list_add_tail(&header->ctl_entry, header_list);
+ header->set = lookup_header_set(root, namespaces);
+ list_add_tail(&header->ctl_entry, &header->set->list);
spin_unlock(&sysctl_lock);
return header;
kfree(header);
}
+void setup_sysctl_set(struct ctl_table_set *p,
+ struct ctl_table_set *parent,
+ int (*is_seen)(struct ctl_table_set *))
+{
+ INIT_LIST_HEAD(&p->list);
+ p->parent = parent ? parent : &sysctl_table_root.default_set;
+ p->is_seen = is_seen;
+}
+
#else /* !CONFIG_SYSCTL */
struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
{
{
}
+void setup_sysctl_set(struct ctl_table_set *p,
+ struct ctl_table_set *parent,
+ int (*is_seen)(struct ctl_table_set *))
+{
+}
+
#endif /* CONFIG_SYSCTL */
/*
#include <linux/if_tr.h>
#endif
-static struct list_head *
+static struct ctl_table_set *
net_ctl_header_lookup(struct ctl_table_root *root, struct nsproxy *namespaces)
{
- return &namespaces->net_ns->sysctl_table_headers;
+ return &namespaces->net_ns->sysctls;
+}
+
+static int is_seen(struct ctl_table_set *set)
+{
+ return ¤t->nsproxy->net_ns->sysctls == set;
}
/* Return standard mode bits for table entry. */
.permissions = net_ctl_permissions,
};
-static LIST_HEAD(net_sysctl_ro_tables);
-static struct list_head *net_ctl_ro_header_lookup(struct ctl_table_root *root,
- struct nsproxy *namespaces)
-{
- return &net_sysctl_ro_tables;
-}
-
static int net_ctl_ro_header_perms(struct ctl_table_root *root,
struct nsproxy *namespaces, struct ctl_table *table)
{
}
static struct ctl_table_root net_sysctl_ro_root = {
- .lookup = net_ctl_ro_header_lookup,
.permissions = net_ctl_ro_header_perms,
};
static int sysctl_net_init(struct net *net)
{
- INIT_LIST_HEAD(&net->sysctl_table_headers);
+ setup_sysctl_set(&net->sysctls, NULL, is_seen);
return 0;
}
static void sysctl_net_exit(struct net *net)
{
- WARN_ON(!list_empty(&net->sysctl_table_headers));
+ WARN_ON(!list_empty(&net->sysctls.list));
return;
}
if (ret)
goto out;
register_sysctl_root(&net_sysctl_root);
+ setup_sysctl_set(&net_sysctl_ro_root.default_set, NULL, NULL);
register_sysctl_root(&net_sysctl_ro_root);
out:
return ret;