Skip to contentSkip to conversation

netfilter fix (1/7): make conntrack really search backwards

PATCH New Harald Welte 1 participant 1 message Jun 24, 2003

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 netfilter fix (1/7): make conntrack really search backwards

Hi Dave!

This patch is the first of a series of patches (7 fixes, 4 enhancements, 7 cosmetic changes) I have pending for 2.4.22-pre.

I'll take care of merging the patches with 2.5, but this will take another day. Expect them tomorrow.

===

Author: Martin Josefsson <[email protected]>
Really search _backwards_ to find the oldest unreplied connection to evict

include/linux/netfilter_ipv4/listhelp.h +16 -0
diff -Nru --exclude .depend --exclude '*.o' --exclude '*.ver' --exclude '.*.flags' --exclude '*.orig' --exclude '*.rej' --exclude '*~' linux-2.4.21-plain/include/linux/netfilter_ipv4/listhelp.h linux-2.4.21-dropback/include/linux/netfilter_ipv4/listhelp.h
@@ -39,6 +39,22 @@
 	(type)__i;				\
 })
 
+/* Just like LIST_FIND but we search backwards */
+#define LIST_FIND_B(head, cmpfn, type, args...)		\
+({							\
+	const struct list_head *__i = (head);		\
+							\
+	ASSERT_READ_LOCK(head);				\
+	do {						\
+		__i = __i->prev;			\
+		if (__i == (head)) {			\
+			__i = NULL;			\
+			break;				\
+		}					\
+	} while (!cmpfn((const type)__i , ## args));	\
+	(type)__i;					\
+})
+
 static inline int
 __list_cmp_same(const void *p1, const void *p2) { return p1 == p2; }
 
net/ipv4/netfilter/ip_conntrack_core.c +1 -1
diff -Nru --exclude .depend --exclude '*.o' --exclude '*.ver' --exclude '.*.flags' --exclude '*.orig' --exclude '*.rej' --exclude '*~' linux-2.4.21-plain/net/ipv4/netfilter/ip_conntrack_core.c linux-2.4.21-dropback/net/ipv4/netfilter/ip_conntrack_core.c
@@ -596,7 +596,7 @@
 	int dropped = 0;
 
 	READ_LOCK(&ip_conntrack_lock);
-	h = LIST_FIND(chain, unreplied, struct ip_conntrack_tuple_hash *);
+	h = LIST_FIND_B(chain, unreplied, struct ip_conntrack_tuple_hash *);
 	if (h)
 		atomic_inc(&h->ctrack->ct_general.use);
 	READ_UNLOCK(&ip_conntrack_lock);

Please apply, thanks.

Signature · 5 lines
- Harald Welte <[email protected]>             http://www.netfilter.org/
============================================================================
  "Fragmentation is like classful addressing -- an interesting early
   architectural error that shows how much experimentation was going
   on while IP was being designed."                    -- Paul Vixie