Skip to contentSkip to conversation

: several small patches

PATCH In review Patrick McHardy 3 participants 5 messages Jun 15, 2003 – Jun 20, 2003

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

PATCH 1/1 : several small patches

Hi Harald,
these are some patches that summed up, mostly one liners. If you would like i could also combine some of these.

1. ip_conntrack-outdated-comment.diff:
remove outdated comment in ip_conntrack_expect_related that seems to have it's origin in time before newnat. it also makes the initialization of new->use explicit.

2. ip-conntrack-unneeded-check.diff:
remove double-check for ct->master, master_ct() also does the check.

3. ip-conntrack-unconfirmed-expect.diff:
in init_conntrack: do not delete timer/call expect function for connections matching expectations from unconfirmed connections.

4. unneeded-init.diff:
this is an old patch which removes some memset(x,0,..) for data in bss segment. some more unneeded initializations since last post:

- conntrack->tuplehash[IP_CT_DIR_ORIGINAL].list.next = NULL in init_conntrack() seems to be forgotten when IPS_CONFIRMED was introduced.
- memset and INIT_LIST_HEAD in ip_conntrack_expect_related() are not required, memory is overwritten in the next line anyway and list-member heads don't need to be initialized.

5. ip-conntrack-expect-drop-refcnt.diff:
drop master conntrack refcnt before setting expectant = NULL in remove_expectations. untested but seems to make sense.

6. ip-conntrack-remove_expectations-list_for_each_safe.diff:
use list_for_each_safe in remove_expectations

Best regards,
Patrick

# This is a BitKeeper generated patch for the following project:
# Project Name: Linux kernel tree
# This patch format is intended for GNU patch command version 2.5 or higher. # This patch includes the following deltas:
# ChangeSet 1.1201 -> 1.1202
# net/ipv4/netfilter/ip_conntrack_core.c 1.19 -> 1.20
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 03/06/15 [email protected] 1.1202

# remove outdated comment, explicitly set usage count to 1
# --------------------------------------------
#
diff -Nru a/net/ipv4/netfilter/ip_conntrack_core.c b/net/ipv4/netfilter/ip_conntrack_core.c
--- a/net/ipv4/netfilter/ip_conntrack_core.c	Sun Jun 15 20:23:03 2003
+++ b/net/ipv4/netfilter/ip_conntrack_core.c	Sun Jun 15 20:23:03 2003
@@ -1041,10 +1041,7 @@
 	memcpy(new, expect, sizeof(*expect));
 	new->expectant = related_to;
 	new->sibling = NULL;
-	/* increase usage count. This sucks. The memset above overwrites
-	 * old usage count [if still present] and we increase to one.  Only
-	 * works because everything is done under ip_conntrack_lock() */
-	atomic_inc(&new->use);
+	atomic_set(&new->use, 1);

/* add to expected list for this connection */ list_add(&new->expected_list, &related_to->sibling_list);

# This is a BitKeeper generated patch for the following project:
# Project Name: Linux kernel tree
# This patch format is intended for GNU patch command version 2.5 or higher. # This patch includes the following deltas:
# ChangeSet 1.1202 -> 1.1203
# net/ipv4/netfilter/ip_conntrack_core.c 1.20 -> 1.21
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 03/06/15 [email protected] 1.1203

# remove double check for ct->master, master_ct() also checks
# --------------------------------------------
#
diff -Nru a/net/ipv4/netfilter/ip_conntrack_core.c b/net/ipv4/netfilter/ip_conntrack_core.c
--- a/net/ipv4/netfilter/ip_conntrack_core.c	Sun Jun 15 20:23:35 2003
+++ b/net/ipv4/netfilter/ip_conntrack_core.c	Sun Jun 15 20:23:35 2003
@@ -313,7 +313,7 @@
 	IP_NF_ASSERT(atomic_read(&nfct->use) == 0);
 	IP_NF_ASSERT(!timer_pending(&ct->timeout));

- if (ct->master && master_ct(ct))
+ if (master_ct(ct))
ip_conntrack_put(master_ct(ct));

/* To make sure we don't get any weird locking issues here:

# This is a BitKeeper generated patch for the following project:
# Project Name: Linux kernel tree
# This patch format is intended for GNU patch command version 2.5 or higher. # This patch includes the following deltas:
# ChangeSet 1.1203 -> 1.1204
# net/ipv4/netfilter/ip_conntrack_core.c 1.21 -> 1.22
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 03/06/15 [email protected] 1.1204
# [NETFILTER]: do not delete timer/call expect function for connections

# matching expectations from unconfirmed connections.
# --------------------------------------------
#
diff -Nru a/net/ipv4/netfilter/ip_conntrack_core.c b/net/ipv4/netfilter/ip_conntrack_core.c
--- a/net/ipv4/netfilter/ip_conntrack_core.c	Sun Jun 15 20:24:32 2003
+++ b/net/ipv4/netfilter/ip_conntrack_core.c	Sun Jun 15 20:24:32 2003
@@ -705,6 +705,14 @@
 			     struct ip_conntrack_expect *, tuple);
 	READ_UNLOCK(&ip_conntrack_expect_tuple_lock);

+ /* If master is not in hash table yet (ie. packet hasn't left

+	   this machine yet), how can other end know about expected?
+	   Hence these are not the droids you are looking for (if
+	   master ct never got confirmed, we'd hold a reference to it
+	   and weird things would happen to future packets). */

+ if (expected && !is_confirmed(expected->expectant))
+ expected = NULL;
+
/* Look up the conntrack helper for master connections only */ if (!expected)
conntrack->helper = ip_ct_find_helper(&repl_tuple);
@@ -715,12 +723,7 @@
&& ! del_timer(&expected->timeout))
expected = NULL;

- /* If master is not in hash table yet (ie. packet hasn't left

-	   this machine yet), how can other end know about expected?
-	   Hence these are not the droids you are looking for (if
-	   master ct never got confirmed, we'd hold a reference to it
-	   and weird things would happen to future packets). */

- if (expected && is_confirmed(expected->expectant)) {
+ if (expected) {
DEBUGP("conntrack: expectation arrives ct=%p exp=%p\n",
conntrack, expected);
/* Welcome, Mr. Bond. We've been expecting you... */

# This is a BitKeeper generated patch for the following project:
# Project Name: Linux kernel tree
# This patch format is intended for GNU patch command version 2.5 or higher. # This patch includes the following deltas:
# ChangeSet 1.1204 -> 1.1205
# net/ipv4/netfilter/ip_conntrack_core.c 1.22 -> 1.23
# net/ipv4/netfilter/ip_nat_ftp.c 1.6 -> 1.7
# net/ipv4/netfilter/ipt_ULOG.c 1.6 -> 1.7
# net/ipv4/netfilter/ip_conntrack_irc.c 1.6 -> 1.7
# net/ipv4/netfilter/ip_conntrack_ftp.c 1.9 -> 1.10
# net/ipv4/netfilter/ip_nat_irc.c 1.3 -> 1.4
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 03/06/15 [email protected] 1.1205
# [NETFILTER]: remove unneeded initilizations/memsets
# --------------------------------------------
#

net/ipv4/netfilter/ip_conntrack_core.c +0 -7
diff -Nru a/net/ipv4/netfilter/ip_conntrack_core.c b/net/ipv4/netfilter/ip_conntrack_core.c
@@ -695,9 +695,6 @@
 
 	INIT_LIST_HEAD(&conntrack->sibling_list);
 
-	/* Mark clearly that it's not in the hash table. */
-	conntrack->tuplehash[IP_CT_DIR_ORIGINAL].list.next = NULL;
-
 	WRITE_LOCK(&ip_conntrack_lock);
 	/* Need finding and deleting of expected ONLY if we win race */
 	READ_LOCK(&ip_conntrack_expect_tuple_lock);
@@ -1036,11 +1033,7 @@
 		return -ENOMEM;
 	}
 	
-	/* Zero out the new structure, then fill out it with the data */
 	DEBUGP("new expectation %p of conntrack %p\n", new, related_to);
-	memset(new, 0, sizeof(*expect));
-	INIT_LIST_HEAD(&new->list);
-	INIT_LIST_HEAD(&new->expected_list);
 	memcpy(new, expect, sizeof(*expect));
 	new->expectant = related_to;
 	new->sibling = NULL;
net/ipv4/netfilter/ip_conntrack_ftp.c +0 -1
diff -Nru a/net/ipv4/netfilter/ip_conntrack_ftp.c b/net/ipv4/netfilter/ip_conntrack_ftp.c
@@ -405,7 +405,6 @@
 		ports[0] = FTP_PORT;
 
 	for (i = 0; (i < MAX_PORTS) && ports[i]; i++) {
-		memset(&ftp[i], 0, sizeof(struct ip_conntrack_helper));
 		ftp[i].tuple.src.u.tcp.port = htons(ports[i]);
 		ftp[i].tuple.dst.protonum = IPPROTO_TCP;
 		ftp[i].mask.src.u.tcp.port = 0xFFFF;
net/ipv4/netfilter/ip_conntrack_irc.c +0 -2
diff -Nru a/net/ipv4/netfilter/ip_conntrack_irc.c b/net/ipv4/netfilter/ip_conntrack_irc.c
@@ -259,8 +259,6 @@
 
 	for (i = 0; (i < MAX_PORTS) && ports[i]; i++) {
 		hlpr = &irc_helpers[i];
-		memset(hlpr, 0,
-		       sizeof(struct ip_conntrack_helper));
 		hlpr->tuple.src.u.tcp.port = htons(ports[i]);
 		hlpr->tuple.dst.protonum = IPPROTO_TCP;
 		hlpr->mask.src.u.tcp.port = 0xFFFF;
net/ipv4/netfilter/ip_nat_ftp.c +0 -3
diff -Nru a/net/ipv4/netfilter/ip_nat_ftp.c b/net/ipv4/netfilter/ip_nat_ftp.c
@@ -306,9 +306,6 @@
 		ports[0] = FTP_PORT;
 
 	for (i = 0; (i < MAX_PORTS) && ports[i]; i++) {
-
-		memset(&ftp[i], 0, sizeof(struct ip_nat_helper));
-
 		ftp[i].tuple.dst.protonum = IPPROTO_TCP;
 		ftp[i].tuple.src.u.tcp.port = htons(ports[i]);
 		ftp[i].mask.dst.protonum = 0xFFFF;
net/ipv4/netfilter/ip_nat_irc.c +0 -3
diff -Nru a/net/ipv4/netfilter/ip_nat_irc.c b/net/ipv4/netfilter/ip_nat_irc.c
@@ -243,9 +243,6 @@
 
 	for (i = 0; (i < MAX_PORTS) && ports[i] != 0; i++) {
 		hlpr = &ip_nat_irc_helpers[i];
-		memset(hlpr, 0,
-		       sizeof(struct ip_nat_helper));
-
 		hlpr->tuple.dst.protonum = IPPROTO_TCP;
 		hlpr->tuple.src.u.tcp.port = htons(ports[i]);
 		hlpr->mask.src.u.tcp.port = 0xFFFF;
net/ipv4/netfilter/ipt_ULOG.c +0 -1
diff -Nru a/net/ipv4/netfilter/ipt_ULOG.c b/net/ipv4/netfilter/ipt_ULOG.c
@@ -322,7 +322,6 @@
 
 	/* initialize ulog_buffers */
 	for (i = 0; i < ULOG_MAXNLGROUPS; i++) {
-		memset(&ulog_buffers[i], 0, sizeof(ulog_buff_t));
 		init_timer(&ulog_buffers[i].timer);
 		ulog_buffers[i].timer.function = ulog_timer;
 		ulog_buffers[i].timer.data = i;

# This is a BitKeeper generated patch for the following project:
# Project Name: Linux kernel tree
# This patch format is intended for GNU patch command version 2.5 or higher. # This patch includes the following deltas:
# ChangeSet 1.1205 -> 1.1206
# net/ipv4/netfilter/ip_conntrack_core.c 1.23 -> 1.24
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 03/06/15 [email protected] 1.1206
# [NETFILTER]: drop reference to conntrack after removing confirmed expectation # --------------------------------------------
#

net/ipv4/netfilter/ip_conntrack_core.c +1 -0
diff -Nru a/net/ipv4/netfilter/ip_conntrack_core.c b/net/ipv4/netfilter/ip_conntrack_core.c
@@ -275,6 +275,7 @@
 		if (exp->sibling) {
 			DEBUGP("remove_expectations: skipping established %p of %p\n", exp->sibling, ct);
 			/* Indicate that this expectations parent is dead */
+			ip_conntrack_put(exp->expectant);
 			exp->expectant = NULL;
 			continue;
 		}

# This is a BitKeeper generated patch for the following project:
# Project Name: Linux kernel tree
# This patch format is intended for GNU patch command version 2.5 or higher. # This patch includes the following deltas:
# ChangeSet 1.1206 -> 1.1207
# net/ipv4/netfilter/ip_conntrack_core.c 1.24 -> 1.25
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 03/06/15 [email protected] 1.1207
# [NETFILTER]: use list_for_each_safe in remove_expectations
# --------------------------------------------
#

net/ipv4/netfilter/ip_conntrack_core.c +1 -3
diff -Nru a/net/ipv4/netfilter/ip_conntrack_core.c b/net/ipv4/netfilter/ip_conntrack_core.c
@@ -264,9 +264,7 @@
 
 	DEBUGP("remove_expectations(%p)\n", ct);
 
-	for (exp_entry = ct->sibling_list.next;
-	     exp_entry != &ct->sibling_list; exp_entry = next) {
-		next = exp_entry->next;
+	list_for_each_safe(exp_entry, next, &ct->sibling_list) {
 		exp = list_entry(exp_entry, struct ip_conntrack_expect,
 				 expected_list);
 
#1 lore raw

Hi again,

Quoted 4 lines · Patrick McHardy

5. ip-conntrack-expect-drop-refcnt.diff:
drop master conntrack refcnt before setting expectant = NULL in remove_expectations. untested but seems to make sense.

this patch seems to fix the ip_conntrack unload-loop. I can reliably trigger the loop by unloading ip_conntrack after unloading an conntrack helper which is helping some connection. No problems with this patch applied.

Best regards,
Patrick

#3 lore raw
In reply to Patrick McHardy
Quoted 2 lines · Patrick McHardy

Hi Harald,
these are some patches that summed up, mostly one liners.

Thanks.

Quoted 4 lines

1. ip_conntrack-outdated-comment.diff:
remove outdated comment in ip_conntrack_expect_related that seems to have it's origin in time before newnat. it also makes the initialization of new->use explicit.

fine with me.

Quoted 3 lines

2. ip-conntrack-unneeded-check.diff:
remove double-check for ct->master, master_ct() also does the check.

ack.

Quoted 3 lines

3. ip-conntrack-unconfirmed-expect.diff:
in init_conntrack: do not delete timer/call expect function for connections matching expectations from unconfirmed connections.

Again, correct.

Quoted 8 lines

4. unneeded-init.diff:
this is an old patch which removes some memset(x,0,..) for data in bss segment. some more unneeded initializations since last post:

- conntrack->tuplehash[IP_CT_DIR_ORIGINAL].list.next = NULL in init_conntrack() seems to be forgotten when IPS_CONFIRMED was introduced.

true.

Quoted 3 lines

- memset and INIT_LIST_HEAD in ip_conntrack_expect_related() are not required, memory is overwritten in the next line anyway and list-member heads don't need to be initialized.

ok, that was my mistake... I somehow didn't notice the fact that only the master list head needs to be initialized. But this is, obviously, correct.

Quoted 3 lines

5. ip-conntrack-expect-drop-refcnt.diff:
drop master conntrack refcnt before setting expectant = NULL in remove_expectations. untested but seems to make sense.

There have been recent changes in this part of code...

Jozsef: Any objections?

Quoted 2 lines

6. ip-conntrack-remove_expectations-list_for_each_safe.diff:
use list_for_each_safe in remove_expectations

ok, a cosmetic correction.

I'll put 1-4 and 6 into patch-o-matic, 5 is Jozsef's call.

Quoted 2 lines

Best regards,
Patrick

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
#2 lore raw
In reply to Patrick McHardy
Quoted 9 lines · Patrick McHardy
Quoted 3 lines

5. ip-conntrack-expect-drop-refcnt.diff:
drop master conntrack refcnt before setting expectant = NULL in remove_expectations. untested but seems to make sense.

this patch seems to fix the ip_conntrack unload-loop. I can reliably trigger the loop by unloading ip_conntrack after unloading an conntrack helper which is helping some connection. No problems with this patch applied.

sounds promising, I'll put it in pending.

Quoted 2 lines

Best regards,
Patrick

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
#4 lore raw
In reply to Harald Welte
Quoted 7 lines · Harald Welte
Quoted 3 lines

5. ip-conntrack-expect-drop-refcnt.diff:
drop master conntrack refcnt before setting expectant = NULL in remove_expectations. untested but seems to make sense.

There have been recent changes in this part of code...

Jozsef: Any objections?

It looks OK, I'll add to pom on the weekend.

Best regards,
Jozsef
-
E-mail : [email protected], [email protected] PGP key : http://www.kfki.hu/~kadlec/pgp_public_key.txt
Address : KFKI Research Institute for Particle and Nuclear Physics

          H-1525 Budapest 114, POB. 49, Hungary