netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/5] netfilter: nf_tables fixes
@ 2014-02-05 15:03 Patrick McHardy
  2014-02-05 15:03 ` [PATCH 1/5] netfilter: nf_tables: fix potential oops when dumping sets Patrick McHardy
                   ` (4 more replies)
  0 siblings, 5 replies; 13+ messages in thread
From: Patrick McHardy @ 2014-02-05 15:03 UTC (permalink / raw)
  To: pablo; +Cc: netfilter-devel

The following patches fix a couple of bugs in nf_tables:

- potential NULL pointer dereference when dumping sets
- missing NFT_CT_L3PROTOCOL key in ct expression validation
- the module dependency issues we've discussed

Please note, the last patch is *not* a new feature but part of the
fix since NFPROTO_INET was previously also handled by nft_reject.
I just put it into a seperate patch for easier review.

Please apply, thanks.


Patrick McHardy (5):
      netfilter: nf_tables: fix potential oops when dumping sets
      netfilter: nft_ct: fix missing NFT_CT_L3PROTOCOL key in validity checks
      netfilter: nf_tables: add AF specific expression support
      netfilter: nft_reject: split up reject module into IPv4 and IPv6 specifc parts
      netfilter: nf_tables: add reject module for NFPROTO_INET


 include/net/netfilter/nf_tables.h    |  5 ++
 net/ipv4/netfilter/Kconfig           |  5 ++
 net/ipv4/netfilter/Makefile          |  1 +
 net/ipv4/netfilter/nft_reject_ipv4.c | 75 ++++++++++++++++++++++++++++++
 net/ipv6/netfilter/Kconfig           |  5 ++
 net/ipv6/netfilter/Makefile          |  1 +
 net/ipv6/netfilter/nft_reject_ipv6.c | 76 ++++++++++++++++++++++++++++++
 net/netfilter/Kconfig                |  6 ++-
 net/netfilter/Makefile               |  1 +
 net/netfilter/nf_tables_api.c        | 30 ++++++++----
 net/netfilter/nft_ct.c               |  1 +
 net/netfilter/nft_reject.c           | 89 ++++--------------------------------
 net/netfilter/nft_reject_inet.c      | 63 +++++++++++++++++++++++++
 13 files changed, 268 insertions(+), 90 deletions(-)

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 1/5] netfilter: nf_tables: fix potential oops when dumping sets
  2014-02-05 15:03 [PATCH 0/5] netfilter: nf_tables fixes Patrick McHardy
@ 2014-02-05 15:03 ` Patrick McHardy
  2014-02-05 23:23   ` Pablo Neira Ayuso
  2014-02-05 15:03 ` [PATCH 2/5] netfilter: nft_ct: fix missing NFT_CT_L3PROTOCOL key in validity checks Patrick McHardy
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 13+ messages in thread
From: Patrick McHardy @ 2014-02-05 15:03 UTC (permalink / raw)
  To: pablo; +Cc: netfilter-devel

Commit c9c8e48597 (netfilter: nf_tables: dump sets in all existing families)
changed nft_ctx_init_from_setattr() to only look up the address family if it
is not NFPROTO_UNSPEC. However if it is NFPROTO_UNSPEC and a table attribute
is given, nftables_afinfo_lookup() will dereference the NULL afi pointer.

Fix by checking for non-NULL afi and also move a check added by that commit
to the proper position.

Signed-off-by: Patrick McHardy <kaber@trash.net>
---
 net/netfilter/nf_tables_api.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index 9ce3053..9579aad 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -1943,6 +1943,9 @@ static int nft_ctx_init_from_setattr(struct nft_ctx *ctx,
 	}
 
 	if (nla[NFTA_SET_TABLE] != NULL) {
+		if (afi == NULL)
+			return -EAFNOSUPPORT;;
+
 		table = nf_tables_table_lookup(afi, nla[NFTA_SET_TABLE]);
 		if (IS_ERR(table))
 			return PTR_ERR(table);
@@ -2428,6 +2431,8 @@ static int nf_tables_delset(struct sock *nlsk, struct sk_buff *skb,
 	struct nft_ctx ctx;
 	int err;
 
+	if (nfmsg->nfgen_family == NFPROTO_UNSPEC)
+		return -EAFNOSUPPORT;
 	if (nla[NFTA_SET_TABLE] == NULL)
 		return -EINVAL;
 
@@ -2435,9 +2440,6 @@ static int nf_tables_delset(struct sock *nlsk, struct sk_buff *skb,
 	if (err < 0)
 		return err;
 
-	if (nfmsg->nfgen_family == NFPROTO_UNSPEC)
-		return -EAFNOSUPPORT;
-
 	set = nf_tables_set_lookup(ctx.table, nla[NFTA_SET_NAME]);
 	if (IS_ERR(set))
 		return PTR_ERR(set);
-- 
1.8.5.3


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 2/5] netfilter: nft_ct: fix missing NFT_CT_L3PROTOCOL key in validity checks
  2014-02-05 15:03 [PATCH 0/5] netfilter: nf_tables fixes Patrick McHardy
  2014-02-05 15:03 ` [PATCH 1/5] netfilter: nf_tables: fix potential oops when dumping sets Patrick McHardy
@ 2014-02-05 15:03 ` Patrick McHardy
  2014-02-05 23:24   ` Pablo Neira Ayuso
  2014-02-05 15:03 ` [PATCH 3/5] netfilter: nf_tables: add AF specific expression support Patrick McHardy
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 13+ messages in thread
From: Patrick McHardy @ 2014-02-05 15:03 UTC (permalink / raw)
  To: pablo; +Cc: netfilter-devel

The key was missing in the list of valid keys, add it.

Signed-off-by: Patrick McHardy <kaber@trash.net>
---
 net/netfilter/nft_ct.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/net/netfilter/nft_ct.c b/net/netfilter/nft_ct.c
index 917052e..75ebfe7 100644
--- a/net/netfilter/nft_ct.c
+++ b/net/netfilter/nft_ct.c
@@ -226,6 +226,7 @@ static int nft_ct_init_validate_get(const struct nft_expr *expr,
 		if (tb[NFTA_CT_DIRECTION] != NULL)
 			return -EINVAL;
 		break;
+	case NFT_CT_L3PROTOCOL:
 	case NFT_CT_PROTOCOL:
 	case NFT_CT_SRC:
 	case NFT_CT_DST:
-- 
1.8.5.3


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 3/5] netfilter: nf_tables: add AF specific expression support
  2014-02-05 15:03 [PATCH 0/5] netfilter: nf_tables fixes Patrick McHardy
  2014-02-05 15:03 ` [PATCH 1/5] netfilter: nf_tables: fix potential oops when dumping sets Patrick McHardy
  2014-02-05 15:03 ` [PATCH 2/5] netfilter: nft_ct: fix missing NFT_CT_L3PROTOCOL key in validity checks Patrick McHardy
@ 2014-02-05 15:03 ` Patrick McHardy
  2014-02-05 23:24   ` Pablo Neira Ayuso
  2014-02-05 15:03 ` [PATCH 4/5] netfilter: nft_reject: split up reject module into IPv4 and IPv6 specifc parts Patrick McHardy
  2014-02-05 15:03 ` [PATCH 5/5] netfilter: nf_tables: add reject module for NFPROTO_INET Patrick McHardy
  4 siblings, 1 reply; 13+ messages in thread
From: Patrick McHardy @ 2014-02-05 15:03 UTC (permalink / raw)
  To: pablo; +Cc: netfilter-devel

For the reject module, we need to add AF-specific implementations to
get rid of incorrect module dependencies. Try to load an AF-specific
module first and fall back to generic modules.

Signed-off-by: Patrick McHardy <kaber@trash.net>
---
 include/net/netfilter/nf_tables.h |  5 +++++
 net/netfilter/nf_tables_api.c     | 22 ++++++++++++++++------
 2 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/include/net/netfilter/nf_tables.h b/include/net/netfilter/nf_tables.h
index 57c8ff7..0f68e47 100644
--- a/include/net/netfilter/nf_tables.h
+++ b/include/net/netfilter/nf_tables.h
@@ -252,6 +252,7 @@ void nf_tables_unbind_set(const struct nft_ctx *ctx, struct nft_set *set,
  *	@owner: module reference
  *	@policy: netlink attribute policy
  *	@maxattr: highest netlink attribute number
+ *	@family: address family for AF-specific types
  */
 struct nft_expr_type {
 	const struct nft_expr_ops	*(*select_ops)(const struct nft_ctx *,
@@ -262,6 +263,7 @@ struct nft_expr_type {
 	struct module			*owner;
 	const struct nla_policy		*policy;
 	unsigned int			maxattr;
+	u8				family;
 };
 
 /**
@@ -529,6 +531,9 @@ void nft_unregister_expr(struct nft_expr_type *);
 #define MODULE_ALIAS_NFT_CHAIN(family, name) \
 	MODULE_ALIAS("nft-chain-" __stringify(family) "-" name)
 
+#define MODULE_ALIAS_NFT_AF_EXPR(family, name) \
+	MODULE_ALIAS("nft-expr-" __stringify(family) "-" name)
+
 #define MODULE_ALIAS_NFT_EXPR(name) \
 	MODULE_ALIAS("nft-expr-" name)
 
diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index 9579aad..f6dca04 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -1114,35 +1114,45 @@ void nft_unregister_expr(struct nft_expr_type *type)
 }
 EXPORT_SYMBOL_GPL(nft_unregister_expr);
 
-static const struct nft_expr_type *__nft_expr_type_get(struct nlattr *nla)
+static const struct nft_expr_type *__nft_expr_type_get(u8 family,
+						       struct nlattr *nla)
 {
 	const struct nft_expr_type *type;
 
 	list_for_each_entry(type, &nf_tables_expressions, list) {
-		if (!nla_strcmp(nla, type->name))
+		if (!nla_strcmp(nla, type->name) &&
+		    (!type->family || type->family == family))
 			return type;
 	}
 	return NULL;
 }
 
-static const struct nft_expr_type *nft_expr_type_get(struct nlattr *nla)
+static const struct nft_expr_type *nft_expr_type_get(u8 family,
+						     struct nlattr *nla)
 {
 	const struct nft_expr_type *type;
 
 	if (nla == NULL)
 		return ERR_PTR(-EINVAL);
 
-	type = __nft_expr_type_get(nla);
+	type = __nft_expr_type_get(family, nla);
 	if (type != NULL && try_module_get(type->owner))
 		return type;
 
 #ifdef CONFIG_MODULES
 	if (type == NULL) {
 		nfnl_unlock(NFNL_SUBSYS_NFTABLES);
+		request_module("nft-expr-%u-%.*s", family,
+			       nla_len(nla), (char *)nla_data(nla));
+		nfnl_lock(NFNL_SUBSYS_NFTABLES);
+		if (__nft_expr_type_get(family, nla))
+			return ERR_PTR(-EAGAIN);
+
+		nfnl_unlock(NFNL_SUBSYS_NFTABLES);
 		request_module("nft-expr-%.*s",
 			       nla_len(nla), (char *)nla_data(nla));
 		nfnl_lock(NFNL_SUBSYS_NFTABLES);
-		if (__nft_expr_type_get(nla))
+		if (__nft_expr_type_get(family, nla))
 			return ERR_PTR(-EAGAIN);
 	}
 #endif
@@ -1193,7 +1203,7 @@ static int nf_tables_expr_parse(const struct nft_ctx *ctx,
 	if (err < 0)
 		return err;
 
-	type = nft_expr_type_get(tb[NFTA_EXPR_NAME]);
+	type = nft_expr_type_get(ctx->afi->family, tb[NFTA_EXPR_NAME]);
 	if (IS_ERR(type))
 		return PTR_ERR(type);
 
-- 
1.8.5.3


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 4/5] netfilter: nft_reject: split up reject module into IPv4 and IPv6 specifc parts
  2014-02-05 15:03 [PATCH 0/5] netfilter: nf_tables fixes Patrick McHardy
                   ` (2 preceding siblings ...)
  2014-02-05 15:03 ` [PATCH 3/5] netfilter: nf_tables: add AF specific expression support Patrick McHardy
@ 2014-02-05 15:03 ` Patrick McHardy
  2014-02-05 23:26   ` Pablo Neira Ayuso
  2014-02-05 15:03 ` [PATCH 5/5] netfilter: nf_tables: add reject module for NFPROTO_INET Patrick McHardy
  4 siblings, 1 reply; 13+ messages in thread
From: Patrick McHardy @ 2014-02-05 15:03 UTC (permalink / raw)
  To: pablo; +Cc: netfilter-devel

Currently the nft_reject module depends on symbols from ipv6. This is
wrong since no generic module should force IPv6 support to be loaded.
Split up the module into AF-specific and a generic part.

Signed-off-by: Patrick McHardy <kaber@trash.net>
---
 net/ipv4/netfilter/Kconfig           |  5 ++
 net/ipv4/netfilter/Makefile          |  1 +
 net/ipv4/netfilter/nft_reject_ipv4.c | 74 ++++++++++++++++++++++++++++++
 net/ipv6/netfilter/Kconfig           |  5 ++
 net/ipv6/netfilter/Makefile          |  1 +
 net/ipv6/netfilter/nft_reject_ipv6.c | 75 ++++++++++++++++++++++++++++++
 net/netfilter/Kconfig                |  1 -
 net/netfilter/nft_reject.c           | 89 ++++--------------------------------
 8 files changed, 170 insertions(+), 81 deletions(-)
 create mode 100644 net/ipv4/netfilter/nft_reject_ipv4.c
 create mode 100644 net/ipv6/netfilter/nft_reject_ipv6.c

diff --git a/net/ipv4/netfilter/Kconfig b/net/ipv4/netfilter/Kconfig
index 81c6910..a26ce03 100644
--- a/net/ipv4/netfilter/Kconfig
+++ b/net/ipv4/netfilter/Kconfig
@@ -61,6 +61,11 @@ config NFT_CHAIN_NAT_IPV4
 	  packet transformations such as the source, destination address and
 	  source and destination ports.
 
+config NFT_REJECT_IPV4
+	depends on NF_TABLES_IPV4
+	default NFT_REJECT
+	tristate
+
 config NF_TABLES_ARP
 	depends on NF_TABLES
 	tristate "ARP nf_tables support"
diff --git a/net/ipv4/netfilter/Makefile b/net/ipv4/netfilter/Makefile
index c16be9d..90b8240 100644
--- a/net/ipv4/netfilter/Makefile
+++ b/net/ipv4/netfilter/Makefile
@@ -30,6 +30,7 @@ obj-$(CONFIG_NF_NAT_PROTO_GRE) += nf_nat_proto_gre.o
 obj-$(CONFIG_NF_TABLES_IPV4) += nf_tables_ipv4.o
 obj-$(CONFIG_NFT_CHAIN_ROUTE_IPV4) += nft_chain_route_ipv4.o
 obj-$(CONFIG_NFT_CHAIN_NAT_IPV4) += nft_chain_nat_ipv4.o
+obj-$(CONFIG_NFT_REJECT_IPV4) += nft_reject_ipv4.o
 obj-$(CONFIG_NF_TABLES_ARP) += nf_tables_arp.o
 
 # generic IP tables 
diff --git a/net/ipv4/netfilter/nft_reject_ipv4.c b/net/ipv4/netfilter/nft_reject_ipv4.c
new file mode 100644
index 0000000..e935d8d
--- /dev/null
+++ b/net/ipv4/netfilter/nft_reject_ipv4.c
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2008-2009 Patrick McHardy <kaber@trash.net>
+ * Copyright (c) 2013 Eric Leblond <eric@regit.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Development of this code funded by Astaro AG (http://www.astaro.com/)
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/netlink.h>
+#include <linux/netfilter.h>
+#include <linux/netfilter/nf_tables.h>
+#include <net/netfilter/nf_tables.h>
+#include <net/icmp.h>
+#include <net/netfilter/ipv4/nf_reject.h>
+#include <net/netfilter/nft_reject.h>
+
+static void nft_reject_ipv4_eval(const struct nft_expr *expr,
+				 struct nft_data data[NFT_REG_MAX + 1],
+				 const struct nft_pktinfo *pkt)
+{
+	struct nft_reject *priv = nft_expr_priv(expr);
+
+	switch (priv->type) {
+	case NFT_REJECT_ICMP_UNREACH:
+		nf_send_unreach(pkt->skb, priv->icmp_code);
+		break;
+	case NFT_REJECT_TCP_RST:
+		nf_send_reset(pkt->skb, pkt->ops->hooknum);
+		break;
+	}
+
+	data[NFT_REG_VERDICT].verdict = NF_DROP;
+}
+
+static struct nft_expr_type nft_reject_ipv4_type;
+static const struct nft_expr_ops nft_reject_ipv4_ops = {
+	.type		= &nft_reject_ipv4_type,
+	.size		= NFT_EXPR_SIZE(sizeof(struct nft_reject)),
+	.eval		= nft_reject_ipv4_eval,
+	.init		= nft_reject_init,
+	.dump		= nft_reject_dump,
+};
+
+static struct nft_expr_type nft_reject_ipv4_type __read_mostly = {
+	.family		= NFPROTO_IPV4,
+	.name		= "reject",
+	.ops		= &nft_reject_ipv4_ops,
+	.policy		= nft_reject_policy,
+	.maxattr	= NFTA_REJECT_MAX,
+	.owner		= THIS_MODULE,
+};
+
+static int __init nft_reject_ipv4_module_init(void)
+{
+	return nft_register_expr(&nft_reject_ipv4_type);
+}
+
+static void __exit nft_reject_ipv4_module_exit(void)
+{
+	nft_unregister_expr(&nft_reject_ipv4_type);
+}
+
+module_init(nft_reject_ipv4_module_init);
+module_exit(nft_reject_ipv4_module_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
+MODULE_ALIAS_NFT_AF_EXPR(AF_INET, "reject");
diff --git a/net/ipv6/netfilter/Kconfig b/net/ipv6/netfilter/Kconfig
index 35750df..4bff1f2 100644
--- a/net/ipv6/netfilter/Kconfig
+++ b/net/ipv6/netfilter/Kconfig
@@ -50,6 +50,11 @@ config NFT_CHAIN_NAT_IPV6
 	  packet transformations such as the source, destination address and
 	  source and destination ports.
 
+config NFT_REJECT_IPV6
+	depends on NF_TABLES_IPV6
+	default NFT_REJECT
+	tristate
+
 config IP6_NF_IPTABLES
 	tristate "IP6 tables support (required for filtering)"
 	depends on INET && IPV6
diff --git a/net/ipv6/netfilter/Makefile b/net/ipv6/netfilter/Makefile
index d1b4928..70d3dd6 100644
--- a/net/ipv6/netfilter/Makefile
+++ b/net/ipv6/netfilter/Makefile
@@ -27,6 +27,7 @@ obj-$(CONFIG_NF_DEFRAG_IPV6) += nf_defrag_ipv6.o
 obj-$(CONFIG_NF_TABLES_IPV6) += nf_tables_ipv6.o
 obj-$(CONFIG_NFT_CHAIN_ROUTE_IPV6) += nft_chain_route_ipv6.o
 obj-$(CONFIG_NFT_CHAIN_NAT_IPV6) += nft_chain_nat_ipv6.o
+obj-$(CONFIG_NFT_REJECT_IPV6) += nft_reject_ipv6.o
 
 # matches
 obj-$(CONFIG_IP6_NF_MATCH_AH) += ip6t_ah.o
diff --git a/net/ipv6/netfilter/nft_reject_ipv6.c b/net/ipv6/netfilter/nft_reject_ipv6.c
new file mode 100644
index 0000000..f732859
--- /dev/null
+++ b/net/ipv6/netfilter/nft_reject_ipv6.c
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2008-2009 Patrick McHardy <kaber@trash.net>
+ * Copyright (c) 2013 Eric Leblond <eric@regit.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Development of this code funded by Astaro AG (http://www.astaro.com/)
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/netlink.h>
+#include <linux/netfilter.h>
+#include <linux/netfilter/nf_tables.h>
+#include <net/netfilter/nf_tables.h>
+#include <net/netfilter/nft_reject.h>
+#include <net/netfilter/ipv6/nf_reject.h>
+
+static void nft_reject_ipv6_eval(const struct nft_expr *expr,
+				 struct nft_data data[NFT_REG_MAX + 1],
+				 const struct nft_pktinfo *pkt)
+{
+	struct nft_reject *priv = nft_expr_priv(expr);
+	struct net *net = dev_net((pkt->in != NULL) ? pkt->in : pkt->out);
+
+	switch (priv->type) {
+	case NFT_REJECT_ICMP_UNREACH:
+		nf_send_unreach6(net, pkt->skb, priv->icmp_code,
+				 pkt->ops->hooknum);
+		break;
+	case NFT_REJECT_TCP_RST:
+		nf_send_reset6(net, pkt->skb, pkt->ops->hooknum);
+		break;
+	}
+
+	data[NFT_REG_VERDICT].verdict = NF_DROP;
+}
+
+static struct nft_expr_type nft_reject_ipv6_type;
+static const struct nft_expr_ops nft_reject_ipv6_ops = {
+	.type		= &nft_reject_ipv6_type,
+	.size		= NFT_EXPR_SIZE(sizeof(struct nft_reject)),
+	.eval		= nft_reject_ipv6_eval,
+	.init		= nft_reject_init,
+	.dump		= nft_reject_dump,
+};
+
+static struct nft_expr_type nft_reject_ipv6_type __read_mostly = {
+	.family		= NFPROTO_IPV6,
+	.name		= "reject",
+	.ops		= &nft_reject_ipv6_ops,
+	.policy		= nft_reject_policy,
+	.maxattr	= NFTA_REJECT_MAX,
+	.owner		= THIS_MODULE,
+};
+
+static int __init nft_reject_ipv6_module_init(void)
+{
+	return nft_register_expr(&nft_reject_ipv6_type);
+}
+
+static void __exit nft_reject_ipv6_module_exit(void)
+{
+	nft_unregister_expr(&nft_reject_ipv6_type);
+}
+
+module_init(nft_reject_ipv6_module_init);
+module_exit(nft_reject_ipv6_module_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
+MODULE_ALIAS_NFT_AF_EXPR(AF_INET6, "reject");
diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
index c374675..ed8b50e 100644
--- a/net/netfilter/Kconfig
+++ b/net/netfilter/Kconfig
@@ -513,7 +513,6 @@ config NFT_QUEUE
 
 config NFT_REJECT
 	depends on NF_TABLES
-	depends on NF_TABLES_IPV6 || !NF_TABLES_IPV6
 	default m if NETFILTER_ADVANCED=n
 	tristate "Netfilter nf_tables reject support"
 	help
diff --git a/net/netfilter/nft_reject.c b/net/netfilter/nft_reject.c
index 5e204711..f3448c2 100644
--- a/net/netfilter/nft_reject.c
+++ b/net/netfilter/nft_reject.c
@@ -16,65 +16,23 @@
 #include <linux/netfilter.h>
 #include <linux/netfilter/nf_tables.h>
 #include <net/netfilter/nf_tables.h>
-#include <net/icmp.h>
-#include <net/netfilter/ipv4/nf_reject.h>
+#include <net/netfilter/nft_reject.h>
 
-#if IS_ENABLED(CONFIG_NF_TABLES_IPV6)
-#include <net/netfilter/ipv6/nf_reject.h>
-#endif
-
-struct nft_reject {
-	enum nft_reject_types	type:8;
-	u8			icmp_code;
-	u8			family;
-};
-
-static void nft_reject_eval(const struct nft_expr *expr,
-			      struct nft_data data[NFT_REG_MAX + 1],
-			      const struct nft_pktinfo *pkt)
-{
-	struct nft_reject *priv = nft_expr_priv(expr);
-#if IS_ENABLED(CONFIG_NF_TABLES_IPV6)
-	struct net *net = dev_net((pkt->in != NULL) ? pkt->in : pkt->out);
-#endif
-	switch (priv->type) {
-	case NFT_REJECT_ICMP_UNREACH:
-		if (priv->family == NFPROTO_IPV4)
-			nf_send_unreach(pkt->skb, priv->icmp_code);
-#if IS_ENABLED(CONFIG_NF_TABLES_IPV6)
-		else if (priv->family == NFPROTO_IPV6)
-			nf_send_unreach6(net, pkt->skb, priv->icmp_code,
-				      pkt->ops->hooknum);
-#endif
-		break;
-	case NFT_REJECT_TCP_RST:
-		if (priv->family == NFPROTO_IPV4)
-			nf_send_reset(pkt->skb, pkt->ops->hooknum);
-#if IS_ENABLED(CONFIG_NF_TABLES_IPV6)
-		else if (priv->family == NFPROTO_IPV6)
-			nf_send_reset6(net, pkt->skb, pkt->ops->hooknum);
-#endif
-		break;
-	}
-
-	data[NFT_REG_VERDICT].verdict = NF_DROP;
-}
-
-static const struct nla_policy nft_reject_policy[NFTA_REJECT_MAX + 1] = {
+const struct nla_policy nft_reject_policy[NFTA_REJECT_MAX + 1] = {
 	[NFTA_REJECT_TYPE]		= { .type = NLA_U32 },
 	[NFTA_REJECT_ICMP_CODE]		= { .type = NLA_U8 },
 };
+EXPORT_SYMBOL_GPL(nft_reject_policy);
 
-static int nft_reject_init(const struct nft_ctx *ctx,
-			   const struct nft_expr *expr,
-			   const struct nlattr * const tb[])
+int nft_reject_init(const struct nft_ctx *ctx,
+		    const struct nft_expr *expr,
+		    const struct nlattr * const tb[])
 {
 	struct nft_reject *priv = nft_expr_priv(expr);
 
 	if (tb[NFTA_REJECT_TYPE] == NULL)
 		return -EINVAL;
 
-	priv->family = ctx->afi->family;
 	priv->type = ntohl(nla_get_be32(tb[NFTA_REJECT_TYPE]));
 	switch (priv->type) {
 	case NFT_REJECT_ICMP_UNREACH:
@@ -89,8 +47,9 @@ static int nft_reject_init(const struct nft_ctx *ctx,
 
 	return 0;
 }
+EXPORT_SYMBOL_GPL(nft_reject_init);
 
-static int nft_reject_dump(struct sk_buff *skb, const struct nft_expr *expr)
+int nft_reject_dump(struct sk_buff *skb, const struct nft_expr *expr)
 {
 	const struct nft_reject *priv = nft_expr_priv(expr);
 
@@ -109,37 +68,7 @@ static int nft_reject_dump(struct sk_buff *skb, const struct nft_expr *expr)
 nla_put_failure:
 	return -1;
 }
-
-static struct nft_expr_type nft_reject_type;
-static const struct nft_expr_ops nft_reject_ops = {
-	.type		= &nft_reject_type,
-	.size		= NFT_EXPR_SIZE(sizeof(struct nft_reject)),
-	.eval		= nft_reject_eval,
-	.init		= nft_reject_init,
-	.dump		= nft_reject_dump,
-};
-
-static struct nft_expr_type nft_reject_type __read_mostly = {
-	.name		= "reject",
-	.ops		= &nft_reject_ops,
-	.policy		= nft_reject_policy,
-	.maxattr	= NFTA_REJECT_MAX,
-	.owner		= THIS_MODULE,
-};
-
-static int __init nft_reject_module_init(void)
-{
-	return nft_register_expr(&nft_reject_type);
-}
-
-static void __exit nft_reject_module_exit(void)
-{
-	nft_unregister_expr(&nft_reject_type);
-}
-
-module_init(nft_reject_module_init);
-module_exit(nft_reject_module_exit);
+EXPORT_SYMBOL_GPL(nft_reject_dump);
 
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
-MODULE_ALIAS_NFT_EXPR("reject");
-- 
1.8.5.3


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 5/5] netfilter: nf_tables: add reject module for NFPROTO_INET
  2014-02-05 15:03 [PATCH 0/5] netfilter: nf_tables fixes Patrick McHardy
                   ` (3 preceding siblings ...)
  2014-02-05 15:03 ` [PATCH 4/5] netfilter: nft_reject: split up reject module into IPv4 and IPv6 specifc parts Patrick McHardy
@ 2014-02-05 15:03 ` Patrick McHardy
  2014-02-05 23:28   ` Pablo Neira Ayuso
  4 siblings, 1 reply; 13+ messages in thread
From: Patrick McHardy @ 2014-02-05 15:03 UTC (permalink / raw)
  To: pablo; +Cc: netfilter-devel

Add a reject module for NFPROTO_INET. It does nothing but dispatch
to the AF-specific modules based on the hook family.

Signed-off-by: Patrick McHardy <kaber@trash.net>
---
 net/ipv4/netfilter/nft_reject_ipv4.c |  7 ++--
 net/ipv6/netfilter/nft_reject_ipv6.c |  7 ++--
 net/netfilter/Kconfig                |  5 +++
 net/netfilter/Makefile               |  1 +
 net/netfilter/nft_reject_inet.c      | 63 ++++++++++++++++++++++++++++++++++++
 5 files changed, 77 insertions(+), 6 deletions(-)
 create mode 100644 net/netfilter/nft_reject_inet.c

diff --git a/net/ipv4/netfilter/nft_reject_ipv4.c b/net/ipv4/netfilter/nft_reject_ipv4.c
index e935d8d..e79718a 100644
--- a/net/ipv4/netfilter/nft_reject_ipv4.c
+++ b/net/ipv4/netfilter/nft_reject_ipv4.c
@@ -20,9 +20,9 @@
 #include <net/netfilter/ipv4/nf_reject.h>
 #include <net/netfilter/nft_reject.h>
 
-static void nft_reject_ipv4_eval(const struct nft_expr *expr,
-				 struct nft_data data[NFT_REG_MAX + 1],
-				 const struct nft_pktinfo *pkt)
+void nft_reject_ipv4_eval(const struct nft_expr *expr,
+			  struct nft_data data[NFT_REG_MAX + 1],
+			  const struct nft_pktinfo *pkt)
 {
 	struct nft_reject *priv = nft_expr_priv(expr);
 
@@ -37,6 +37,7 @@ static void nft_reject_ipv4_eval(const struct nft_expr *expr,
 
 	data[NFT_REG_VERDICT].verdict = NF_DROP;
 }
+EXPORT_SYMBOL_GPL(nft_reject_ipv4_eval);
 
 static struct nft_expr_type nft_reject_ipv4_type;
 static const struct nft_expr_ops nft_reject_ipv4_ops = {
diff --git a/net/ipv6/netfilter/nft_reject_ipv6.c b/net/ipv6/netfilter/nft_reject_ipv6.c
index f732859..0bc19fa 100644
--- a/net/ipv6/netfilter/nft_reject_ipv6.c
+++ b/net/ipv6/netfilter/nft_reject_ipv6.c
@@ -19,9 +19,9 @@
 #include <net/netfilter/nft_reject.h>
 #include <net/netfilter/ipv6/nf_reject.h>
 
-static void nft_reject_ipv6_eval(const struct nft_expr *expr,
-				 struct nft_data data[NFT_REG_MAX + 1],
-				 const struct nft_pktinfo *pkt)
+void nft_reject_ipv6_eval(const struct nft_expr *expr,
+			  struct nft_data data[NFT_REG_MAX + 1],
+			  const struct nft_pktinfo *pkt)
 {
 	struct nft_reject *priv = nft_expr_priv(expr);
 	struct net *net = dev_net((pkt->in != NULL) ? pkt->in : pkt->out);
@@ -38,6 +38,7 @@ static void nft_reject_ipv6_eval(const struct nft_expr *expr,
 
 	data[NFT_REG_VERDICT].verdict = NF_DROP;
 }
+EXPORT_SYMBOL_GPL(nft_reject_ipv6_eval);
 
 static struct nft_expr_type nft_reject_ipv6_type;
 static const struct nft_expr_ops nft_reject_ipv6_ops = {
diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
index ed8b50e..e9410d1 100644
--- a/net/netfilter/Kconfig
+++ b/net/netfilter/Kconfig
@@ -520,6 +520,11 @@ config NFT_REJECT
 	  explicitly deny and notify via TCP reset/ICMP informational errors
 	  unallowed traffic.
 
+config NFT_REJECT_INET
+	depends on NF_TABLES_INET
+	default NFT_REJECT
+	tristate
+
 config NFT_COMPAT
 	depends on NF_TABLES
 	depends on NETFILTER_XTABLES
diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
index ee9c4de..bffdad7 100644
--- a/net/netfilter/Makefile
+++ b/net/netfilter/Makefile
@@ -79,6 +79,7 @@ obj-$(CONFIG_NFT_LIMIT)		+= nft_limit.o
 obj-$(CONFIG_NFT_NAT)		+= nft_nat.o
 obj-$(CONFIG_NFT_QUEUE)		+= nft_queue.o
 obj-$(CONFIG_NFT_REJECT) 	+= nft_reject.o
+obj-$(CONFIG_NFT_REJECT_INET)	+= nft_reject_inet.o
 obj-$(CONFIG_NFT_RBTREE)	+= nft_rbtree.o
 obj-$(CONFIG_NFT_HASH)		+= nft_hash.o
 obj-$(CONFIG_NFT_COUNTER)	+= nft_counter.o
diff --git a/net/netfilter/nft_reject_inet.c b/net/netfilter/nft_reject_inet.c
new file mode 100644
index 0000000..8a310f2
--- /dev/null
+++ b/net/netfilter/nft_reject_inet.c
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2014 Patrick McHardy <kaber@trash.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/netlink.h>
+#include <linux/netfilter.h>
+#include <linux/netfilter/nf_tables.h>
+#include <net/netfilter/nf_tables.h>
+#include <net/netfilter/nft_reject.h>
+
+static void nft_reject_inet_eval(const struct nft_expr *expr,
+				 struct nft_data data[NFT_REG_MAX + 1],
+				 const struct nft_pktinfo *pkt)
+{
+	switch (pkt->ops->pf) {
+	case NFPROTO_IPV4:
+		nft_reject_ipv4_eval(expr, data, pkt);
+	case NFPROTO_IPV6:
+		nft_reject_ipv6_eval(expr, data, pkt);
+	}
+}
+
+static struct nft_expr_type nft_reject_inet_type;
+static const struct nft_expr_ops nft_reject_inet_ops = {
+	.type		= &nft_reject_inet_type,
+	.size		= NFT_EXPR_SIZE(sizeof(struct nft_reject)),
+	.eval		= nft_reject_inet_eval,
+	.init		= nft_reject_init,
+	.dump		= nft_reject_dump,
+};
+
+static struct nft_expr_type nft_reject_inet_type __read_mostly = {
+	.family		= NFPROTO_INET,
+	.name		= "reject",
+	.ops		= &nft_reject_inet_ops,
+	.policy		= nft_reject_policy,
+	.maxattr	= NFTA_REJECT_MAX,
+	.owner		= THIS_MODULE,
+};
+
+static int __init nft_reject_inet_module_init(void)
+{
+	return nft_register_expr(&nft_reject_inet_type);
+}
+
+static void __exit nft_reject_inet_module_exit(void)
+{
+	nft_unregister_expr(&nft_reject_inet_type);
+}
+
+module_init(nft_reject_inet_module_init);
+module_exit(nft_reject_inet_module_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
+MODULE_ALIAS_NFT_AF_EXPR(1, "reject");
-- 
1.8.5.3


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/5] netfilter: nf_tables: fix potential oops when dumping sets
  2014-02-05 15:03 ` [PATCH 1/5] netfilter: nf_tables: fix potential oops when dumping sets Patrick McHardy
@ 2014-02-05 23:23   ` Pablo Neira Ayuso
  0 siblings, 0 replies; 13+ messages in thread
From: Pablo Neira Ayuso @ 2014-02-05 23:23 UTC (permalink / raw)
  To: Patrick McHardy; +Cc: netfilter-devel

On Wed, Feb 05, 2014 at 03:03:35PM +0000, Patrick McHardy wrote:
> Commit c9c8e48597 (netfilter: nf_tables: dump sets in all existing families)
> changed nft_ctx_init_from_setattr() to only look up the address family if it
> is not NFPROTO_UNSPEC. However if it is NFPROTO_UNSPEC and a table attribute
> is given, nftables_afinfo_lookup() will dereference the NULL afi pointer.
> 
> Fix by checking for non-NULL afi and also move a check added by that commit
> to the proper position.

Applied, thanks.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/5] netfilter: nft_ct: fix missing NFT_CT_L3PROTOCOL key in validity checks
  2014-02-05 15:03 ` [PATCH 2/5] netfilter: nft_ct: fix missing NFT_CT_L3PROTOCOL key in validity checks Patrick McHardy
@ 2014-02-05 23:24   ` Pablo Neira Ayuso
  0 siblings, 0 replies; 13+ messages in thread
From: Pablo Neira Ayuso @ 2014-02-05 23:24 UTC (permalink / raw)
  To: Patrick McHardy; +Cc: netfilter-devel

On Wed, Feb 05, 2014 at 03:03:36PM +0000, Patrick McHardy wrote:
> The key was missing in the list of valid keys, add it.

Also applied, thanks.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 3/5] netfilter: nf_tables: add AF specific expression support
  2014-02-05 15:03 ` [PATCH 3/5] netfilter: nf_tables: add AF specific expression support Patrick McHardy
@ 2014-02-05 23:24   ` Pablo Neira Ayuso
  0 siblings, 0 replies; 13+ messages in thread
From: Pablo Neira Ayuso @ 2014-02-05 23:24 UTC (permalink / raw)
  To: Patrick McHardy; +Cc: netfilter-devel

On Wed, Feb 05, 2014 at 03:03:37PM +0000, Patrick McHardy wrote:
> For the reject module, we need to add AF-specific implementations to
> get rid of incorrect module dependencies. Try to load an AF-specific
> module first and fall back to generic modules.

Applied, thanks Patrick.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 4/5] netfilter: nft_reject: split up reject module into IPv4 and IPv6 specifc parts
  2014-02-05 15:03 ` [PATCH 4/5] netfilter: nft_reject: split up reject module into IPv4 and IPv6 specifc parts Patrick McHardy
@ 2014-02-05 23:26   ` Pablo Neira Ayuso
  2014-02-06  4:53     ` Patrick McHardy
  0 siblings, 1 reply; 13+ messages in thread
From: Pablo Neira Ayuso @ 2014-02-05 23:26 UTC (permalink / raw)
  To: Patrick McHardy; +Cc: netfilter-devel

On Wed, Feb 05, 2014 at 03:03:38PM +0000, Patrick McHardy wrote:
> Currently the nft_reject module depends on symbols from ipv6. This is
> wrong since no generic module should force IPv6 support to be loaded.
> Split up the module into AF-specific and a generic part.

Applied, thanks. I have included this chunk which was missing:

--- /dev/null
+++ b/include/net/netfilter/nft_reject.h
@@ -0,0 +1,18 @@
+#ifndef _NFT_REJECT_H_
+#define _NFT_REJECT_H_
+
+struct nft_reject {
+       enum nft_reject_types   type:8;
+       u8                      icmp_code;
+       u8                      family;
+};
+
+extern const struct nla_policy nft_reject_policy[];
+
+int nft_reject_init(const struct nft_ctx *ctx,
+                   const struct nft_expr *expr,
+                   const struct nlattr * const tb[]);
+
+int nft_reject_dump(struct sk_buff *skb, const struct nft_expr *expr);
+
+#endif

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 5/5] netfilter: nf_tables: add reject module for NFPROTO_INET
  2014-02-05 15:03 ` [PATCH 5/5] netfilter: nf_tables: add reject module for NFPROTO_INET Patrick McHardy
@ 2014-02-05 23:28   ` Pablo Neira Ayuso
  0 siblings, 0 replies; 13+ messages in thread
From: Pablo Neira Ayuso @ 2014-02-05 23:28 UTC (permalink / raw)
  To: Patrick McHardy; +Cc: netfilter-devel

On Wed, Feb 05, 2014 at 03:03:39PM +0000, Patrick McHardy wrote:
> Add a reject module for NFPROTO_INET. It does nothing but dispatch
> to the AF-specific modules based on the hook family.

And also applied, including this chunk:

diff --git a/include/net/netfilter/nft_reject.h
b/include/net/netfilter/nft_reject.h
index 6ade783..72a18c0 100644
--- a/include/net/netfilter/nft_reject.h
+++ b/include/net/netfilter/nft_reject.h
@@ -15,4 +15,12 @@ int nft_reject_init(const struct nft_ctx *ctx,
 
 int nft_reject_dump(struct sk_buff *skb, const struct nft_expr
*expr);
 
+void nft_reject_ipv4_eval(const struct nft_expr *expr,
+                         struct nft_data data[NFT_REG_MAX + 1],
+                         const struct nft_pktinfo *pkt);
+
+void nft_reject_ipv6_eval(const struct nft_expr *expr,
+                         struct nft_data data[NFT_REG_MAX + 1],
+                         const struct nft_pktinfo *pkt);
+
 #endif

thanks Patrick!

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH 4/5] netfilter: nft_reject: split up reject module into IPv4 and IPv6 specifc parts
  2014-02-05 23:26   ` Pablo Neira Ayuso
@ 2014-02-06  4:53     ` Patrick McHardy
  2014-02-06  8:46       ` Pablo Neira Ayuso
  0 siblings, 1 reply; 13+ messages in thread
From: Patrick McHardy @ 2014-02-06  4:53 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: netfilter-devel

On Thu, Feb 06, 2014 at 12:26:57AM +0100, Pablo Neira Ayuso wrote:
> On Wed, Feb 05, 2014 at 03:03:38PM +0000, Patrick McHardy wrote:
> > Currently the nft_reject module depends on symbols from ipv6. This is
> > wrong since no generic module should force IPv6 support to be loaded.
> > Split up the module into AF-specific and a generic part.
> 
> Applied, thanks. I have included this chunk which was missing:

Oops, sorry.

> 
> --- /dev/null
> +++ b/include/net/netfilter/nft_reject.h
> @@ -0,0 +1,18 @@
> +#ifndef _NFT_REJECT_H_
> +#define _NFT_REJECT_H_
> +
> +struct nft_reject {
> +       enum nft_reject_types   type:8;
> +       u8                      icmp_code;
> +       u8                      family;

Family is actually not needed anymore.

> +};
> +
> +extern const struct nla_policy nft_reject_policy[];
> +
> +int nft_reject_init(const struct nft_ctx *ctx,
> +                   const struct nft_expr *expr,
> +                   const struct nlattr * const tb[]);
> +
> +int nft_reject_dump(struct sk_buff *skb, const struct nft_expr *expr);
> +
> +#endif

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 4/5] netfilter: nft_reject: split up reject module into IPv4 and IPv6 specifc parts
  2014-02-06  4:53     ` Patrick McHardy
@ 2014-02-06  8:46       ` Pablo Neira Ayuso
  0 siblings, 0 replies; 13+ messages in thread
From: Pablo Neira Ayuso @ 2014-02-06  8:46 UTC (permalink / raw)
  To: Patrick McHardy; +Cc: netfilter-devel

On Thu, Feb 06, 2014 at 04:53:08AM +0000, Patrick McHardy wrote:
> On Thu, Feb 06, 2014 at 12:26:57AM +0100, Pablo Neira Ayuso wrote:
> > On Wed, Feb 05, 2014 at 03:03:38PM +0000, Patrick McHardy wrote:
> > > Currently the nft_reject module depends on symbols from ipv6. This is
> > > wrong since no generic module should force IPv6 support to be loaded.
> > > Split up the module into AF-specific and a generic part.
> > 
> > Applied, thanks. I have included this chunk which was missing:
> 
> Oops, sorry.
> 
> > 
> > --- /dev/null
> > +++ b/include/net/netfilter/nft_reject.h
> > @@ -0,0 +1,18 @@
> > +#ifndef _NFT_REJECT_H_
> > +#define _NFT_REJECT_H_
> > +
> > +struct nft_reject {
> > +       enum nft_reject_types   type:8;
> > +       u8                      icmp_code;
> > +       u8                      family;
> 
> Family is actually not needed anymore.

Removed, thanks. Will push this shortly.

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2014-02-06  8:46 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-05 15:03 [PATCH 0/5] netfilter: nf_tables fixes Patrick McHardy
2014-02-05 15:03 ` [PATCH 1/5] netfilter: nf_tables: fix potential oops when dumping sets Patrick McHardy
2014-02-05 23:23   ` Pablo Neira Ayuso
2014-02-05 15:03 ` [PATCH 2/5] netfilter: nft_ct: fix missing NFT_CT_L3PROTOCOL key in validity checks Patrick McHardy
2014-02-05 23:24   ` Pablo Neira Ayuso
2014-02-05 15:03 ` [PATCH 3/5] netfilter: nf_tables: add AF specific expression support Patrick McHardy
2014-02-05 23:24   ` Pablo Neira Ayuso
2014-02-05 15:03 ` [PATCH 4/5] netfilter: nft_reject: split up reject module into IPv4 and IPv6 specifc parts Patrick McHardy
2014-02-05 23:26   ` Pablo Neira Ayuso
2014-02-06  4:53     ` Patrick McHardy
2014-02-06  8:46       ` Pablo Neira Ayuso
2014-02-05 15:03 ` [PATCH 5/5] netfilter: nf_tables: add reject module for NFPROTO_INET Patrick McHardy
2014-02-05 23:28   ` Pablo Neira Ayuso

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).