Skip to contentSkip to conversation

netfilter: ctnetlink: use expect instead of master tuple in get operation

PATCH New [email protected] 1 participant 2 messages Dec 18, 2011

Subsystems (2)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

PATCH 1/2 netfilter: ctnetlink: use expect instead of master tuple in get operation

From: Pablo Neira Ayuso <[email protected]>

Use the expect tuple (if possible) instead of the master tuple for the get operation. If two or more expectations come from the same master, the returned expectation may not be the one that user-space is requesting.

This is how it works for the expect deletion operation.

Although I think that nobody has been seriously using this. We accept both possibilities, using the expect tuple if possible. I decided to do it like this to avoid breaking backward compatibility.

---
 net/netfilter/nf_conntrack_netlink.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
net/netfilter/nf_conntrack_netlink.c +3 -1
index ef21b22..81a0f11 100644
@@ -1847,7 +1847,9 @@ ctnetlink_get_expect(struct sock *ctnl, struct sk_buff *skb,
 	if (err < 0)
 		return err;
 
-	if (cda[CTA_EXPECT_MASTER])
+	if (cda[CTA_EXPECT_TUPLE])
+		err = ctnetlink_parse_tuple(cda, &tuple, CTA_EXPECT_TUPLE, u3);
+	else if (cda[CTA_EXPECT_MASTER])
 		err = ctnetlink_parse_tuple(cda, &tuple, CTA_EXPECT_MASTER, u3);
 	else
 		return -EINVAL;
Signature · 1 line
1.7.2.5
author maintainer
#1 lore raw

PATCH 2/2 netfilter: ctnetlink: support individual atomic-get-and-reset of counters

From: Pablo Neira Ayuso <[email protected]>

This allows to use the get operation to atomically get-and-reset counters.

---
 net/netfilter/nf_conntrack_netlink.c |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)
net/netfilter/nf_conntrack_netlink.c +11 -0
index 81a0f11..4b6b570 100644
@@ -1011,6 +1011,17 @@ ctnetlink_get_conntrack(struct sock *ctnl, struct sk_buff *skb,
 	if (err < 0)
 		goto out;
 
+	if (NFNL_MSG_TYPE(nlh->nlmsg_type) == IPCTNL_MSG_CT_GET_CTRZERO) {
+		struct nf_conn_counter *acct;
+
+		acct = nf_conn_acct_find(ct);
+		if (acct) {
+			atomic64_set(&acct[IP_CT_DIR_ORIGINAL].bytes, 0);
+			atomic64_set(&acct[IP_CT_DIR_ORIGINAL].packets, 0);
+			atomic64_set(&acct[IP_CT_DIR_REPLY].bytes, 0);
+			atomic64_set(&acct[IP_CT_DIR_REPLY].packets, 0);
+		}
+	}
 	return 0;
 
 free:
Signature · 1 line
1.7.2.5