Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8d870052 authored by Alexey Dobriyan's avatar Alexey Dobriyan Committed by David S. Miller
Browse files

[NETFILTER]: x_tables: per-netns xt_tables



In fact all we want is per-netns set of rules, however doing that will
unnecessary complicate routines such as ipt_hook()/ipt_do_table, so
make full xt_table array per-netns.

Every user stubbed with init_net for a while.

Signed-off-by: default avatarAlexey Dobriyan <adobriyan@sw.ru>
Signed-off-by: default avatarPatrick McHardy <kaber@trash.net>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent a98da11d
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -335,7 +335,8 @@ extern int xt_check_target(const struct xt_target *target, unsigned short family
			   unsigned int size, const char *table, unsigned int hook,
			   unsigned short proto, int inv_proto);

extern struct xt_table *xt_register_table(struct xt_table *table,
extern struct xt_table *xt_register_table(struct net *net,
					  struct xt_table *table,
					  struct xt_table_info *bootstrap,
					  struct xt_table_info *newinfo);
extern void *xt_unregister_table(struct xt_table *table);
@@ -352,7 +353,8 @@ extern struct xt_target *xt_request_find_target(int af, const char *name,
extern int xt_find_revision(int af, const char *name, u8 revision, int target,
			    int *err);

extern struct xt_table *xt_find_table_lock(int af, const char *name);
extern struct xt_table *xt_find_table_lock(struct net *net, int af,
					   const char *name);
extern void xt_table_unlock(struct xt_table *t);

extern int xt_proto_init(int af);
+4 −0
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@
#include <net/netns/packet.h>
#include <net/netns/ipv4.h>
#include <net/netns/ipv6.h>
#include <net/netns/x_tables.h>

struct proc_dir_entry;
struct net_device;
@@ -56,6 +57,9 @@ struct net {
#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
	struct netns_ipv6	ipv6;
#endif
#ifdef CONFIG_NETFILTER
	struct netns_xt		xt;
#endif
};

#ifdef CONFIG_NET
+10 −0
Original line number Diff line number Diff line
#ifndef __NETNS_X_TABLES_H
#define __NETNS_X_TABLES_H

#include <linux/list.h>
#include <linux/net.h>

struct netns_xt {
	struct list_head tables[NPROTO];
};
#endif
+6 −6
Original line number Diff line number Diff line
@@ -870,7 +870,7 @@ static int get_info(void __user *user, int *len, int compat)
	if (compat)
		xt_compat_lock(NF_ARP);
#endif
	t = try_then_request_module(xt_find_table_lock(NF_ARP, name),
	t = try_then_request_module(xt_find_table_lock(&init_net, NF_ARP, name),
				    "arptable_%s", name);
	if (t && !IS_ERR(t)) {
		struct arpt_getinfo info;
@@ -926,7 +926,7 @@ static int get_entries(struct arpt_get_entries __user *uptr, int *len)
		return -EINVAL;
	}

	t = xt_find_table_lock(NF_ARP, get.name);
	t = xt_find_table_lock(&init_net, NF_ARP, get.name);
	if (t && !IS_ERR(t)) {
		struct xt_table_info *private = t->private;
		duprintf("t->private->number = %u\n",
@@ -966,7 +966,7 @@ static int __do_replace(const char *name, unsigned int valid_hooks,
		goto out;
	}

	t = try_then_request_module(xt_find_table_lock(NF_ARP, name),
	t = try_then_request_module(xt_find_table_lock(&init_net, NF_ARP, name),
				    "arptable_%s", name);
	if (!t || IS_ERR(t)) {
		ret = t ? PTR_ERR(t) : -ENOENT;
@@ -1132,7 +1132,7 @@ static int do_add_counters(void __user *user, unsigned int len, int compat)
		goto free;
	}

	t = xt_find_table_lock(NF_ARP, name);
	t = xt_find_table_lock(&init_net, NF_ARP, name);
	if (!t || IS_ERR(t)) {
		ret = t ? PTR_ERR(t) : -ENOENT;
		goto free;
@@ -1604,7 +1604,7 @@ static int compat_get_entries(struct compat_arpt_get_entries __user *uptr,
	}

	xt_compat_lock(NF_ARP);
	t = xt_find_table_lock(NF_ARP, get.name);
	t = xt_find_table_lock(&init_net, NF_ARP, get.name);
	if (t && !IS_ERR(t)) {
		struct xt_table_info *private = t->private;
		struct xt_table_info info;
@@ -1751,7 +1751,7 @@ int arpt_register_table(struct arpt_table *table,
		return ret;
	}

	new_table = xt_register_table(table, &bootstrap, newinfo);
	new_table = xt_register_table(&init_net, table, &bootstrap, newinfo);
	if (IS_ERR(new_table)) {
		xt_free_table_info(newinfo);
		return PTR_ERR(new_table);
+6 −6
Original line number Diff line number Diff line
@@ -1112,7 +1112,7 @@ static int get_info(void __user *user, int *len, int compat)
	if (compat)
		xt_compat_lock(AF_INET);
#endif
	t = try_then_request_module(xt_find_table_lock(AF_INET, name),
	t = try_then_request_module(xt_find_table_lock(&init_net, AF_INET, name),
				    "iptable_%s", name);
	if (t && !IS_ERR(t)) {
		struct ipt_getinfo info;
@@ -1170,7 +1170,7 @@ get_entries(struct ipt_get_entries __user *uptr, int *len)
		return -EINVAL;
	}

	t = xt_find_table_lock(AF_INET, get.name);
	t = xt_find_table_lock(&init_net, AF_INET, get.name);
	if (t && !IS_ERR(t)) {
		struct xt_table_info *private = t->private;
		duprintf("t->private->number = %u\n", private->number);
@@ -1208,7 +1208,7 @@ __do_replace(const char *name, unsigned int valid_hooks,
		goto out;
	}

	t = try_then_request_module(xt_find_table_lock(AF_INET, name),
	t = try_then_request_module(xt_find_table_lock(&init_net, AF_INET, name),
				    "iptable_%s", name);
	if (!t || IS_ERR(t)) {
		ret = t ? PTR_ERR(t) : -ENOENT;
@@ -1383,7 +1383,7 @@ do_add_counters(void __user *user, unsigned int len, int compat)
		goto free;
	}

	t = xt_find_table_lock(AF_INET, name);
	t = xt_find_table_lock(&init_net, AF_INET, name);
	if (!t || IS_ERR(t)) {
		ret = t ? PTR_ERR(t) : -ENOENT;
		goto free;
@@ -1924,7 +1924,7 @@ compat_get_entries(struct compat_ipt_get_entries __user *uptr, int *len)
	}

	xt_compat_lock(AF_INET);
	t = xt_find_table_lock(AF_INET, get.name);
	t = xt_find_table_lock(&init_net, AF_INET, get.name);
	if (t && !IS_ERR(t)) {
		struct xt_table_info *private = t->private;
		struct xt_table_info info;
@@ -2075,7 +2075,7 @@ int ipt_register_table(struct xt_table *table, const struct ipt_replace *repl)
		return ret;
	}

	new_table = xt_register_table(table, &bootstrap, newinfo);
	new_table = xt_register_table(&init_net, table, &bootstrap, newinfo);
	if (IS_ERR(new_table)) {
		xt_free_table_info(newinfo);
		return PTR_ERR(new_table);
Loading