Skip to contentSkip to conversation

ctnetlink: optional packet drop to make event delivery reliable

PATCH In review Pablo Neira Ayuso 2 participants 5 messages Mar 24, 2009

Subsystems (2)
lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/1 ctnetlink: optional packet drop to make event delivery reliable

This patch adds reliable ctnetlink event delivery at the cost of dropping packets or aborting a ctnetlink operation (returning ENOBUFS to userspace). This behaviour is optional and it is set if one broadcast listener has set the NETLINK_BROADCAST_ERROR socket option. Thus, if the delivery fails, the packet is drop.

If the request comes from userspace, in case that the event was not delivered, we return -ENOBUFS. This means that the change has been applied but the event was not delivering. This error is not that easy to trigger as netlink retries one more time if the receiver buffer is full for request in user context.

---

 include/net/netfilter/nf_conntrack_core.h   |    7 ++-
 include/net/netfilter/nf_conntrack_ecache.h |   21 ++++++--
 net/netfilter/nf_conntrack_ecache.c         |   18 +++++--
 net/netfilter/nf_conntrack_expect.c         |    2 -
 net/netfilter/nf_conntrack_netlink.c        |   69 +++++++++++++++++----------
 5 files changed, 76 insertions(+), 41 deletions(-)
include/net/netfilter/nf_conntrack_core.h +5 -2
index 5a449b4..98078b2 100644
@@ -62,8 +62,11 @@ static inline int nf_conntrack_confirm(struct sk_buff *skb)
 	if (ct && ct != &nf_conntrack_untracked) {
 		if (!nf_ct_is_confirmed(ct) && !nf_ct_is_dying(ct))
 			ret = __nf_conntrack_confirm(skb);
-		if (likely(ret == NF_ACCEPT))
-			nf_ct_deliver_cached_events(ct);
+		if (likely(ret == NF_ACCEPT) &&
+		    nf_ct_deliver_cached_events(ct) < 0) {
+			NF_CT_STAT_INC_ATOMIC(nf_ct_net(ct), drop);
+			return NF_DROP;
+		}
 	}
 	return ret;
 }
include/net/netfilter/nf_conntrack_ecache.h +15 -6
index 0ff0dc6..e0d5157 100644
@@ -28,7 +28,7 @@ extern struct atomic_notifier_head nf_conntrack_chain;
 extern int nf_conntrack_register_notifier(struct notifier_block *nb);
 extern int nf_conntrack_unregister_notifier(struct notifier_block *nb);
 
-extern void nf_ct_deliver_cached_events(const struct nf_conn *ct);
+extern int nf_ct_deliver_cached_events(const struct nf_conn *ct);
 extern void __nf_ct_event_cache_init(struct nf_conn *ct);
 extern void nf_ct_event_cache_flush(struct net *net);
 
@@ -46,7 +46,7 @@ nf_conntrack_event_cache(enum ip_conntrack_events event, struct nf_conn *ct)
 	local_bh_enable();
 }
 
-static inline void
+static inline int
 nf_conntrack_event_report(enum ip_conntrack_events event,
 			  struct nf_conn *ct,
 			  u32 pid,
@@ -57,8 +57,14 @@ nf_conntrack_event_report(enum ip_conntrack_events event,
 		.pid	= pid,
 		.report = report
 	};
-	if (nf_ct_is_confirmed(ct) && !nf_ct_is_dying(ct))
-		atomic_notifier_call_chain(&nf_conntrack_chain, event, &item);
+	int ret = 0;
+
+	if (nf_ct_is_confirmed(ct) && !nf_ct_is_dying(ct)) {
+		ret = atomic_notifier_call_chain(&nf_conntrack_chain, 
+						 event, &item);
+		ret = notifier_to_errno(ret);
+	}
+	return ret;
 }
 
 static inline void
@@ -77,7 +83,7 @@ extern struct atomic_notifier_head nf_ct_expect_chain;
 extern int nf_ct_expect_register_notifier(struct notifier_block *nb);
 extern int nf_ct_expect_unregister_notifier(struct notifier_block *nb);
 
-static inline void
+static inline int
 nf_ct_expect_event_report(enum ip_conntrack_expect_events event,
 			  struct nf_conntrack_expect *exp,
 			  u32 pid,
@@ -88,7 +94,10 @@ nf_ct_expect_event_report(enum ip_conntrack_expect_events event,
 		.pid	= pid,
 		.report = report
 	};
-	atomic_notifier_call_chain(&nf_ct_expect_chain, event, &item);
+	int ret;
+
+	ret = atomic_notifier_call_chain(&nf_ct_expect_chain, event, &item);
+	return notifier_to_errno(ret);
 }
 
 static inline void
net/netfilter/nf_conntrack_ecache.c +12 -6
index dee4190..9c21269 100644
@@ -31,9 +31,11 @@ EXPORT_SYMBOL_GPL(nf_ct_expect_chain);
 
 /* deliver cached events and clear cache entry - must be called with locally
  * disabled softirqs */
-static inline void
+static inline int
 __nf_ct_deliver_cached_events(struct nf_conntrack_ecache *ecache)
 {
+	int ret = 0;
+
 	if (nf_ct_is_confirmed(ecache->ct) && !nf_ct_is_dying(ecache->ct)
 	    && ecache->events) {
 		struct nf_ct_event item = {
@@ -42,28 +44,32 @@ __nf_ct_deliver_cached_events(struct nf_conntrack_ecache *ecache)
 			.report	= 0
 		};
 
-		atomic_notifier_call_chain(&nf_conntrack_chain,
-					   ecache->events,
-					   &item);
+		ret = atomic_notifier_call_chain(&nf_conntrack_chain,
+						 ecache->events,
+						 &item);
+		ret = notifier_to_errno(ret);
 	}
 
 	ecache->events = 0;
 	nf_ct_put(ecache->ct);
 	ecache->ct = NULL;
+	return ret;
 }
 
 /* Deliver all cached events for a particular conntrack. This is called
  * by code prior to async packet handling for freeing the skb */
-void nf_ct_deliver_cached_events(const struct nf_conn *ct)
+int nf_ct_deliver_cached_events(const struct nf_conn *ct)
 {
 	struct net *net = nf_ct_net(ct);
 	struct nf_conntrack_ecache *ecache;
+	int ret = 0;
 
 	local_bh_disable();
 	ecache = per_cpu_ptr(net->ct.ecache, raw_smp_processor_id());
 	if (ecache->ct == ct)
-		__nf_ct_deliver_cached_events(ecache);
+		ret = __nf_ct_deliver_cached_events(ecache);
 	local_bh_enable();
+	return ret;
 }
 EXPORT_SYMBOL_GPL(nf_ct_deliver_cached_events);
 
net/netfilter/nf_conntrack_expect.c +1 -1
index 3a8a34a..91aa218 100644
@@ -445,7 +445,7 @@ int nf_ct_expect_related_report(struct nf_conntrack_expect *expect,
 out:
 	spin_unlock_bh(&nf_conntrack_lock);
 	if (ret == 0)
-		nf_ct_expect_event_report(IPEXP_NEW, expect, pid, report);
+		ret = nf_ct_expect_event_report(IPEXP_NEW, expect, pid, report);
 	return ret;
 }
 EXPORT_SYMBOL_GPL(nf_ct_expect_related_report);
net/netfilter/nf_conntrack_netlink.c +43 -26

133 lines not on this page · raw message

#1 lore raw

include/net/netfilter/nf_conntrack_core.h static inline int nf_conntrack_confirm(struct sk_buff *skb)

Quoted 5 lines · Pablo Neira Ayuso
include/net/netfilter/nf_conntrack_core.h +0 -0
index 5a449b4..98078b2 100644
@@ -62,8 +62,11 @@ static inline int nf_conntrack_confirm(struct sk_buff *skb)

What tree is this against? I get reject in my nf-next tree.

include/net/netfilter/nf_conntrack_core.h static inline int nf_conntrack_confirm(struct sk_buff *skb) · line 66

Quoted 7 lines
include/net/netfilter/nf_conntrack_core.h +2 -2
 	if (ct && ct != &nf_conntrack_untracked) {
 		if (!nf_ct_is_confirmed(ct) && !nf_ct_is_dying(ct))
 			ret = __nf_conntrack_confirm(skb);
-		if (likely(ret == NF_ACCEPT))
-			nf_ct_deliver_cached_events(ct);
+		if (likely(ret == NF_ACCEPT) &&
+		    nf_ct_deliver_cached_events(ct) < 0) {

The combined condition is unlikely I'd say. My main question though:
how does this make event delivery reliable? It will drop the packet, fine, but all state changes have already been performed, new connections have been confirmed, etc.

Quoted 5 lines
include/net/netfilter/nf_conntrack_core.h +3 -0
+			NF_CT_STAT_INC_ATOMIC(nf_ct_net(ct), drop);
+			return NF_DROP;
+		}
 	}
 	return ret;
author maintainer
#2 lore raw
Quoted 10 lines · Patrick McHardy

include/net/netfilter/nf_conntrack_core.h static inline int nf_conntrack_confirm(struct · line 62

Quoted 7 lines · Pablo Neira Ayuso
include/net/netfilter/nf_conntrack_core.h +0 -0
index 5a449b4..98078b2 100644
@@ -62,8 +62,11 @@ static inline int nf_conntrack_confirm(struct
 sk_buff *skb)

What tree is this against? I get reject in my nf-next tree.

net-next.git with some patches that you passed to 2.6.29 which are not in your tree yet. I was aware of this but I didn't know how to proceed exactly in this situation.

Quoted 8 lines

include/net/netfilter/nf_conntrack_core.h static inline int nf_conntrack_confirm(struct sk_buff *skb) · line 66

Quoted 7 lines
include/net/netfilter/nf_conntrack_core.h +2 -2
     if (ct && ct != &nf_conntrack_untracked) {
         if (!nf_ct_is_confirmed(ct) && !nf_ct_is_dying(ct))
             ret = __nf_conntrack_confirm(skb);
-        if (likely(ret == NF_ACCEPT))
-            nf_ct_deliver_cached_events(ct);
+        if (likely(ret == NF_ACCEPT) &&
+            nf_ct_deliver_cached_events(ct) < 0) {
Quoted 4 lines

The combined condition is unlikely I'd say. My main question though:
how does this make event delivery reliable? It will drop the packet, fine, but all state changes have already been performed, new connections have been confirmed, etc.

Indeed. This is patch is missing some flag in the conntrack that I could set to send the event once the packet is retransmitted.

Signature · 1 line
"Los honestos son inadaptados sociales" -- Les Luthiers
#3 lore raw
Quoted 11 lines · Pablo Neira Ayuso
Quoted 9 lines · Patrick McHardy

include/net/netfilter/nf_conntrack_core.h static inline int nf_conntrack_confirm(struct · line 62

Quoted 7 lines · Pablo Neira Ayuso
include/net/netfilter/nf_conntrack_core.h +0 -0
index 5a449b4..98078b2 100644
@@ -62,8 +62,11 @@ static inline int nf_conntrack_confirm(struct
 sk_buff *skb)

What tree is this against? I get reject in my nf-next tree.

Quoted 3 lines

net-next.git with some patches that you passed to 2.6.29 which are not in your tree yet. I was aware of this but I didn't know how to proceed exactly in this situation.

Patches should always apply cleanly to the tree they're submitted against. If conflicts occur, they're best handled during merging (IOW: myself or Dave will take care of them). Alternatively you can ask me to pull in Dave's latest tree before diffing against mine in case the patch causing the conflict is already present there.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
include/net/netfilter/nf_conntrack_core.h +2 -2
     if (ct && ct != &nf_conntrack_untracked) {
         if (!nf_ct_is_confirmed(ct) && !nf_ct_is_dying(ct))
             ret = __nf_conntrack_confirm(skb);
-        if (likely(ret == NF_ACCEPT))
-            nf_ct_deliver_cached_events(ct);
+        if (likely(ret == NF_ACCEPT) &&
+            nf_ct_deliver_cached_events(ct) < 0) {
Quoted 7 lines
Quoted 4 lines

The combined condition is unlikely I'd say. My main question though:
how does this make event delivery reliable? It will drop the packet, fine, but all state changes have already been performed, new connections have been confirmed, etc.

Indeed. This is patch is missing some flag in the conntrack that I could set to send the event once the packet is retransmitted.

But it seems rather pointless to add it in this state, it doesn't increase reliability one bit. Additionally reversing the order of state transitions and event delivery seems like a highly intrusive change since event delivery obviously already needs to know the new state, meaning we'd need to record all state changes, then deliver the event, then "commit" them. So I'd like to see what we're engaging in before merging this half finished patch.

author maintainer
#4 lore raw
Quoted 7 lines · Patrick McHardy

But it seems rather pointless to add it in this state, it doesn't increase reliability one bit. Additionally reversing the order of state transitions and event delivery seems like a highly intrusive change since event delivery obviously already needs to know the new state, meaning we'd need to record all state changes, then deliver the event, then "commit" them. So I'd like to see what we're engaging in before merging this half finished patch.

I see, I'm going to send you a new patch so we can discuss on something in particular.

Signature · 1 line
"Los honestos son inadaptados sociales" -- Les Luthiers