Skip to contentSkip to conversation

Netfilter/IPVS updates for net-next

PATCH In review Pablo Neira Ayuso 2 participants 5 messages May 29, 2014 – May 31, 2014

Subsystems (4)
lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

cover Netfilter/IPVS updates for net-next

Hi David,

This small patchset contains three accumulated Netfilter/IPVS updates, they are:

1) Refactorize common NAT code by encapsulating it into a helper function, similarly to what we do in other conntrack extensions, from Florian Westphal.

2) A minor format string mismatch fix for IPVS, from Masanari Iida.

3) Add quota support to the netfilter accounting infrastructure, now you can add quotas to accounting objects via the nfnetlink interface and use them from iptables. You can also listen to quota notifications from userspace. This enhancement from Mathieu Poirier.

You can pull these changes from:

git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git

Thanks!

----------------------------------------------------------------

The following changes since commit fd0d192be6e814495aec91f357b5801afc3b6262:

Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/jkirsher/net-next (2014-04-22 21:47:06 -0400)

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git master

for you to fetch changes up to f768e5bdefe1ec9adbf7a116dfb156b73cacb582:

netfilter: add helper for adding nat extension (2014-04-29 20:56:22 +0200)

----------------------------------------------------------------
Florian Westphal (1):
netfilter: add helper for adding nat extension

Masanari Iida (1):
netfilter: Fix format string mismatch in ip_vs_proto_name()

Mathieu Poirier (1):
netfilter: nfnetlink_acct: Adding quota support to accounting framework

 include/linux/netfilter/nfnetlink_acct.h      |    8 ++-
 include/net/netfilter/nf_nat.h                |    2 +
 include/uapi/linux/netfilter/nfnetlink.h      |    2 +
 include/uapi/linux/netfilter/nfnetlink_acct.h |    9 +++
 net/ipv4/netfilter/iptable_nat.c              |   14 +---
 net/ipv4/netfilter/nft_chain_nat_ipv4.c       |   12 +---
 net/ipv6/netfilter/ip6table_nat.c             |   14 +---
 net/ipv6/netfilter/nft_chain_nat_ipv6.c       |   12 +---
 net/netfilter/ipvs/ip_vs_core.c               |    2 +-
 net/netfilter/nf_nat_core.c                   |   24 ++++---
 net/netfilter/nfnetlink_acct.c                |   85 +++++++++++++++++++++++++
 net/netfilter/xt_nfacct.c                     |    5 +-
 12 files changed, 138 insertions(+), 51 deletions(-)
author maintainer
#1 lore raw

PATCH 1/3 netfilter: Fix format string mismatch in ip_vs_proto_name()

From: Masanari Iida <[email protected]>

Fix string mismatch in ip_vs_proto_name()

---
 net/netfilter/ipvs/ip_vs_core.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/ipvs/ip_vs_core.c +1 -1
index 4f26ee4..d9da8c4 100644
@@ -97,7 +97,7 @@ const char *ip_vs_proto_name(unsigned int proto)
 		return "ICMPv6";
 #endif
 	default:
-		sprintf(buf, "IP_%d", proto);
+		sprintf(buf, "IP_%u", proto);
 		return buf;
 	}
 }
Signature · 1 line
1.7.10.4
author maintainer
#2 lore raw

PATCH 2/3 netfilter: nfnetlink_acct: Adding quota support to accounting framework

In reply to Pablo Neira Ayuso

From: Mathieu Poirier <[email protected]>

nfacct objects already support accounting at the byte and packet level. As such it is a natural extension to add the possiblity to define a ceiling limit for both metrics.

All the support for quotas itself is added to nfnetlink acctounting framework to stay coherent with current accounting object management. Quota limit checks are implemented in xt_nfacct filter where statistic collection is already done.

Pablo Neira Ayuso has also contributed to this feature.

---
 include/linux/netfilter/nfnetlink_acct.h      |    8 ++-
 include/uapi/linux/netfilter/nfnetlink.h      |    2 +
 include/uapi/linux/netfilter/nfnetlink_acct.h |    9 +++
 net/netfilter/nfnetlink_acct.c                |   85 +++++++++++++++++++++++++
 net/netfilter/xt_nfacct.c                     |    5 +-
 5 files changed, 107 insertions(+), 2 deletions(-)
include/linux/netfilter/nfnetlink_acct.h +7 -1
index b2e85e5..6ec9757 100644
@@ -3,11 +3,17 @@
 
 #include <uapi/linux/netfilter/nfnetlink_acct.h>
 
+enum {
+	NFACCT_NO_QUOTA		= -1,
+	NFACCT_UNDERQUOTA,
+	NFACCT_OVERQUOTA,
+};
 
 struct nf_acct;
 
 struct nf_acct *nfnl_acct_find_get(const char *filter_name);
 void nfnl_acct_put(struct nf_acct *acct);
 void nfnl_acct_update(const struct sk_buff *skb, struct nf_acct *nfacct);
-
+extern int nfnl_acct_overquota(const struct sk_buff *skb,
+			      struct nf_acct *nfacct);
 #endif /* _NFNL_ACCT_H */
include/uapi/linux/netfilter/nfnetlink.h +2 -0
index 596ddd4..354a7e5 100644
@@ -20,6 +20,8 @@ enum nfnetlink_groups {
 #define NFNLGRP_CONNTRACK_EXP_DESTROY	NFNLGRP_CONNTRACK_EXP_DESTROY
 	NFNLGRP_NFTABLES,
 #define NFNLGRP_NFTABLES                NFNLGRP_NFTABLES
+	NFNLGRP_ACCT_QUOTA,
+#define NFNLGRP_ACCT_QUOTA		NFNLGRP_ACCT_QUOTA
 	__NFNLGRP_MAX,
 };
 #define NFNLGRP_MAX	(__NFNLGRP_MAX - 1)
include/uapi/linux/netfilter/nfnetlink_acct.h +9 -0
index c7b6269..51404ec 100644
@@ -10,15 +10,24 @@ enum nfnl_acct_msg_types {
 	NFNL_MSG_ACCT_GET,
 	NFNL_MSG_ACCT_GET_CTRZERO,
 	NFNL_MSG_ACCT_DEL,
+	NFNL_MSG_ACCT_OVERQUOTA,
 	NFNL_MSG_ACCT_MAX
 };
 
+enum nfnl_acct_flags {
+	NFACCT_F_QUOTA_PKTS	= (1 << 0),
+	NFACCT_F_QUOTA_BYTES	= (1 << 1),
+	NFACCT_F_OVERQUOTA	= (1 << 2), /* can't be set from userspace */
+};
+
 enum nfnl_acct_type {
 	NFACCT_UNSPEC,
 	NFACCT_NAME,
 	NFACCT_PKTS,
 	NFACCT_BYTES,
 	NFACCT_USE,
+	NFACCT_FLAGS,
+	NFACCT_QUOTA,
 	__NFACCT_MAX
 };
 #define NFACCT_MAX (__NFACCT_MAX - 1)
net/netfilter/nfnetlink_acct.c +85 -0

143 lines not on this page · raw message

net/netfilter/xt_nfacct.c +4 -1
index b3be0ef..8c646ed 100644
@@ -21,11 +21,14 @@ MODULE_ALIAS("ip6t_nfacct");
 
 static bool nfacct_mt(const struct sk_buff *skb, struct xt_action_param *par)
 {
+	int overquota;
 	const struct xt_nfacct_match_info *info = par->targinfo;
 
 	nfnl_acct_update(skb, info->nfacct);
 
-	return true;
+	overquota = nfnl_acct_overquota(skb, info->nfacct);
+
+	return overquota == NFACCT_UNDERQUOTA ? false : true;
 }
 
 static int
Signature · 1 line
1.7.10.4
author maintainer
#3 lore raw

PATCH 3/3 netfilter: add helper for adding nat extension

In reply to Pablo Neira Ayuso

From: Florian Westphal <[email protected]>

Reduce copy-past a bit by adding a common helper.

---
 include/net/netfilter/nf_nat.h          |    2 ++
 net/ipv4/netfilter/iptable_nat.c        |   14 +++-----------
 net/ipv4/netfilter/nft_chain_nat_ipv4.c |   12 +++---------
 net/ipv6/netfilter/ip6table_nat.c       |   14 +++-----------
 net/ipv6/netfilter/nft_chain_nat_ipv6.c |   12 +++---------
 net/netfilter/nf_nat_core.c             |   24 ++++++++++++++++--------
 6 files changed, 30 insertions(+), 48 deletions(-)
include/net/netfilter/nf_nat.h +2 -0
index 07eaaf6..a71dd33 100644
@@ -48,6 +48,8 @@ unsigned int nf_nat_setup_info(struct nf_conn *ct,
 extern unsigned int nf_nat_alloc_null_binding(struct nf_conn *ct,
 					      unsigned int hooknum);
 
+struct nf_conn_nat *nf_ct_nat_ext_add(struct nf_conn *ct);
+
 /* Is this tuple already taken? (not by us)*/
 int nf_nat_used_tuple(const struct nf_conntrack_tuple *tuple,
 		      const struct nf_conn *ignored_conntrack);
net/ipv4/netfilter/iptable_nat.c +3 -11
index ee28861..f1787c0 100644
@@ -91,17 +91,9 @@ nf_nat_ipv4_fn(const struct nf_hook_ops *ops,
 	if (nf_ct_is_untracked(ct))
 		return NF_ACCEPT;
 
-	nat = nfct_nat(ct);
-	if (!nat) {
-		/* NAT module was loaded late. */
-		if (nf_ct_is_confirmed(ct))
-			return NF_ACCEPT;
-		nat = nf_ct_ext_add(ct, NF_CT_EXT_NAT, GFP_ATOMIC);
-		if (nat == NULL) {
-			pr_debug("failed to add NAT extension\n");
-			return NF_ACCEPT;
-		}
-	}
+	nat = nf_ct_nat_ext_add(ct);
+	if (nat == NULL)
+		return NF_ACCEPT;
 
 	switch (ctinfo) {
 	case IP_CT_RELATED:
net/ipv4/netfilter/nft_chain_nat_ipv4.c +3 -9
index b5b256d..3964157 100644
@@ -48,15 +48,9 @@ static unsigned int nf_nat_fn(const struct nf_hook_ops *ops,
 
 	NF_CT_ASSERT(!(ip_hdr(skb)->frag_off & htons(IP_MF | IP_OFFSET)));
 
-	nat = nfct_nat(ct);
-	if (nat == NULL) {
-		/* Conntrack module was loaded late, can't add extension. */
-		if (nf_ct_is_confirmed(ct))
-			return NF_ACCEPT;
-		nat = nf_ct_ext_add(ct, NF_CT_EXT_NAT, GFP_ATOMIC);
-		if (nat == NULL)
-			return NF_ACCEPT;
-	}
+	nat = nf_ct_nat_ext_add(ct);
+	if (nat == NULL)
+		return NF_ACCEPT;
 
 	switch (ctinfo) {
 	case IP_CT_RELATED:
net/ipv6/netfilter/ip6table_nat.c +3 -11
index 84c7f33..387d8b8 100644
@@ -90,17 +90,9 @@ nf_nat_ipv6_fn(const struct nf_hook_ops *ops,
 	if (nf_ct_is_untracked(ct))
 		return NF_ACCEPT;
 
-	nat = nfct_nat(ct);
-	if (!nat) {
-		/* NAT module was loaded late. */
-		if (nf_ct_is_confirmed(ct))
-			return NF_ACCEPT;
-		nat = nf_ct_ext_add(ct, NF_CT_EXT_NAT, GFP_ATOMIC);
-		if (nat == NULL) {
-			pr_debug("failed to add NAT extension\n");
-			return NF_ACCEPT;
-		}
-	}
+	nat = nf_ct_nat_ext_add(ct);
+	if (nat == NULL)
+		return NF_ACCEPT;
 
 	switch (ctinfo) {
 	case IP_CT_RELATED:
net/ipv6/netfilter/nft_chain_nat_ipv6.c +3 -9
index 9c3297a..d189fcb 100644
@@ -47,15 +47,9 @@ static unsigned int nf_nat_ipv6_fn(const struct nf_hook_ops *ops,
 	if (ct == NULL || nf_ct_is_untracked(ct))
 		return NF_ACCEPT;
 
-	nat = nfct_nat(ct);
-	if (nat == NULL) {
-		/* Conntrack module was loaded late, can't add extension. */
-		if (nf_ct_is_confirmed(ct))
-			return NF_ACCEPT;
-		nat = nf_ct_ext_add(ct, NF_CT_EXT_NAT, GFP_ATOMIC);
-		if (nat == NULL)
-			return NF_ACCEPT;
-	}
+	nat = nf_ct_nat_ext_add(ct);
+	if (nat == NULL)
+		return NF_ACCEPT;
 
 	switch (ctinfo) {
 	case IP_CT_RELATED:
net/netfilter/nf_nat_core.c +16 -8
index 52ca952..09096a6 100644
@@ -358,6 +358,19 @@ out:
 	rcu_read_unlock();
 }
 
+struct nf_conn_nat *nf_ct_nat_ext_add(struct nf_conn *ct)
+{
+	struct nf_conn_nat *nat = nfct_nat(ct);
+	if (nat)
+		return nat;
+
+	if (!nf_ct_is_confirmed(ct))
+		nat = nf_ct_ext_add(ct, NF_CT_EXT_NAT, GFP_ATOMIC);
+
+	return nat;
+}
+EXPORT_SYMBOL_GPL(nf_ct_nat_ext_add);
+
 unsigned int
 nf_nat_setup_info(struct nf_conn *ct,
 		  const struct nf_nat_range *range,
@@ -368,14 +381,9 @@ nf_nat_setup_info(struct nf_conn *ct,
 	struct nf_conn_nat *nat;
 
 	/* nat helper or nfctnetlink also setup binding */
-	nat = nfct_nat(ct);
-	if (!nat) {
-		nat = nf_ct_ext_add(ct, NF_CT_EXT_NAT, GFP_ATOMIC);
-		if (nat == NULL) {
-			pr_debug("failed to add NAT extension\n");
-			return NF_ACCEPT;
-		}
-	}
+	nat = nf_ct_nat_ext_add(ct);
+	if (nat == NULL)
+		return NF_ACCEPT;
 
 	NF_CT_ASSERT(maniptype == NF_NAT_MANIP_SRC ||
 		     maniptype == NF_NAT_MANIP_DST);
Signature · 1 line
1.7.10.4
maintainer
#4 lore raw
In reply to Pablo Neira Ayuso

From: Pablo Neira Ayuso <[email protected]>
Date: Thu, 29 May 2014 17:54:57 +0200

Quoted 9 lines

This small patchset contains three accumulated Netfilter/IPVS updates, they are:

1) Refactorize common NAT code by encapsulating it into a helper function, similarly to what we do in other conntrack extensions, from Florian Westphal.

2) A minor format string mismatch fix for IPVS, from Masanari Iida.

Quoted 8 lines

3) Add quota support to the netfilter accounting infrastructure, now you can add quotas to accounting objects via the nfnetlink interface and use them from iptables. You can also listen to quota notifications from userspace. This enhancement from Mathieu Poirier.

You can pull these changes from:

git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git

Pulled into net-next, thanks Pablo!