Skip to contentSkip to conversation

UDP connection tracking failure

BUG Harald Welte 2 participants 2 messages Sep 5, 2002 – Sep 7, 2002 4 messages not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): 1030623591.5131.295.camel@tux

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): 1030815452.2313.1.camel@tux

#4 lore raw
Quoted 6 lines · Martin Josefsson
Quoted 4 lines · Richard Gooch
Quoted 4 lines

The attached diff might help, I don't know how correct it is, I'm not so familiar with the gory details of conntrack yet. It might screw up the tcp timeouts (or not).

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Please test and report back to this list ([email protected]) if it works.

Yes, your patch works nicely, thank you. Will this be picked up and fed into the mainline kernel?

I will run it by the coreteam, they know the internals better than I do, This fix might not be 100% correct for all cases.

The problem is that TCP is making an assumption on the old behaviour in line 194 of ip_conntrack_proto_tcp.c

In general I think the way you have fixed the UDP case is correct - but you should somehow make sure that the TCP RST codepath is still working.

Signature · 5 lines
Live long and prosper
- Harald Welte / [email protected]               http://www.gnumonks.org/
============================================================================
GCS/E/IT d- s-: a-- C+++ UL++++$ P+++ L++++$ E--- W- N++ o? K- w--- O- M- 
V-- PS+ PE-- Y+ PGP++ t++ 5-- !X !R tv-- b+++ DI? !D G+ e* h+ r% y+(*)
#5 lore raw
Quoted 8 lines · Harald Welte
Quoted 2 lines

I will run it by the coreteam, they know the internals better than I do, This fix might not be 100% correct for all cases.

The problem is that TCP is making an assumption on the old behaviour in line 194 of ip_conntrack_proto_tcp.c

In general I think the way you have fixed the UDP case is correct - but you should somehow make sure that the TCP RST codepath is still working.

Ok, now I have two diffrent approaches to this.
#1 moves set_bit() into the protocol-handlers, this allows tcp to set the bit after the check.
(I've attached the changes to gre separately)

#2.moves set_bit() into resolve_normal_ct() and modifies the way we detect the RST to be the same way as we detect a SYN-ACK. This changes the tcp behavior slightly, now we only trigger that case if the previous sent out packet was a SYN and the packet we recieve in the REPLY direction is a RST. Before we could trigger on a RST sent in the ORIGINAL direction before we got a reply aswell, this behaviour is easy to get back (remove one line). The main diffrence is that we depend on the SYN_SENT state instead of no_other_reply_before_this_packet pseudo state.

Which one do you like best?
I kind of like #2.

Signature · 4 lines
/Martin

Never argue with an idiot. They drag you down to their level, then beat
you with experience.
net/ipv4/netfilter/ip_conntrack_core.c renamed from net/ipv4/netfilter/ip_conntrack_core.c.orig +1 -8
@@ -751,7 +751,6 @@
 static inline struct ip_conntrack *
 resolve_normal_ct(struct sk_buff *skb,
 		  struct ip_conntrack_protocol *proto,
-		  int *set_reply,
 		  unsigned int hooknum,
 		  enum ip_conntrack_info *ctinfo)
 {
@@ -776,8 +775,6 @@
 	/* It exists; we have (non-exclusive) reference. */
 	if (DIRECTION(h) == IP_CT_DIR_REPLY) {
 		*ctinfo = IP_CT_ESTABLISHED + IP_CT_IS_REPLY;
-		/* Please set reply bit if this packet OK */
-		*set_reply = 1;
 	} else {
 		/* Once we've had two way comms, always ESTABLISHED. */
 		if (h->ctrack->status & IPS_SEEN_REPLY) {
@@ -793,7 +792,6 @@
 			       h->ctrack);
 			*ctinfo = IP_CT_NEW;
 		}
-		*set_reply = 0;
 	}
 	skb->nfct = &h->ctrack->infos[*ctinfo];
 	return h->ctrack;
@@ -809,7 +806,6 @@
 	struct ip_conntrack *ct;
 	enum ip_conntrack_info ctinfo;
 	struct ip_conntrack_protocol *proto;
-	int set_reply;
 	int ret;
 
 	/* FIXME: Do this right please. --RR */
@@ -849,7 +845,7 @@
 	    && icmp_error_track(*pskb, &ctinfo, hooknum))
 		return NF_ACCEPT;
 
-	if (!(ct = resolve_normal_ct(*pskb, proto,&set_reply,hooknum,&ctinfo)))
+	if (!(ct = resolve_normal_ct(*pskb, proto, hooknum, &ctinfo)))
 		/* Not valid part of a connection */
 		return NF_ACCEPT;
 
@@ -877,8 +873,6 @@
 			return NF_ACCEPT;
 		}
 	}
-	if (set_reply)
-		set_bit(IPS_SEEN_REPLY_BIT, &ct->status);
 
 	return ret;
 }
net/ipv4/netfilter/ip_conntrack_proto_generic.c renamed from net/ipv4/netfilter/ip_conntrack_proto_generic.c.orig +4 -0
@@ -43,6 +43,10 @@
 		       struct iphdr *iph, size_t len,
 		       enum ip_conntrack_info conntrackinfo)
 {
+	/* This is a reply packet, set conntrack to replied. */
+	if (CTINFO2DIR(conntrackinfo) == IP_CT_DIR_REPLY)
+		set_bit(IPS_SEEN_REPLY_BIT, &conntrack->status);
+
 	ip_ct_refresh(conntrack, GENERIC_TIMEOUT);
 	return NF_ACCEPT;
 }
net/ipv4/netfilter/ip_conntrack_proto_icmp.c renamed from net/ipv4/netfilter/ip_conntrack_proto_icmp.c.orig +5 -0
@@ -72,6 +72,11 @@
 		       struct iphdr *iph, size_t len,
 		       enum ip_conntrack_info ctinfo)
 {
+	/* This is a reply packet, set conntrack to replied.
+	 * Not needed for icmp but it's here for completeness */
+	if (CTINFO2DIR(conntrackinfo) == IP_CT_DIR_REPLY)
+		set_bit(IPS_SEEN_REPLY_BIT, &conntrack->status);
+
 	/* Try to delete connection immediately after all replies:
            won't actually vanish as we still have skb, and del_timer
            means this will only run once even if count hits zero twice
net/ipv4/netfilter/ip_conntrack_proto_tcp.c renamed from net/ipv4/netfilter/ip_conntrack_proto_tcp.c.orig +6 -1
@@ -222,7 +222,12 @@
 		if (del_timer(&conntrack->timeout))
 			conntrack->timeout.function((unsigned long)conntrack);
 	} else {
-		/* Set ASSURED if we see see valid ack in ESTABLISHED after SYN_RECV */
+		/* This is a reply packet, set conntrack to replied. */
+		if (CTINFO2DIR(ctinfo) == IP_CT_DIR_REPLY)
+			set_bit(IPS_SEEN_REPLY_BIT, &conntrack->status);
+
+		/* Set ASSURED if we see valid ack in
+		 * ESTABLISHED after SYN_RECV */
 		if (oldtcpstate == TCP_CONNTRACK_SYN_RECV
 		    && CTINFO2DIR(ctinfo) == IP_CT_DIR_ORIGINAL
 		    && tcph->ack && !tcph->syn
net/ipv4/netfilter/ip_conntrack_proto_udp.c renamed from net/ipv4/netfilter/ip_conntrack_proto_udp.c.orig +4 -0
@@ -49,6 +49,10 @@
 		      struct iphdr *iph, size_t len,
 		      enum ip_conntrack_info conntrackinfo)
 {
+	/* This is a reply packet, set conntrack to replied. */
+	if (CTINFO2DIR(conntrackinfo) == IP_CT_DIR_REPLY)
+		set_bit(IPS_SEEN_REPLY_BIT, &conntrack->status);
+	
 	/* If we've seen traffic both ways, this is some kind of UDP
 	   stream.  Extend timeout. */
 	if (conntrack->status & IPS_SEEN_REPLY) {
net/ipv4/netfilter/ip_conntrack_proto_gre.c renamed from net/ipv4/netfilter/ip_conntrack_proto_gre.c.orig +4 -0
@@ -230,6 +230,10 @@
 		      struct iphdr *iph, size_t len,
 		      enum ip_conntrack_info conntrackinfo)
 {
+	/* This is a reply packet, set conntrack to replied. */
+	if (CTINFO2DIR(conntrackinfo) == IP_CT_DIR_REPLY)
+		set_bit(IPS_SEEN_REPLY_BIT, &ct->status);
+
 	/* If we've seen traffic both ways, this is a GRE connection.
 	 * Extend timeout. */
 	if (ct->status & IPS_SEEN_REPLY) {
net/ipv4/netfilter/ip_conntrack_core.c renamed from net/ipv4/netfilter/ip_conntrack_core.c.orig +3 -8
@@ -751,7 +751,6 @@
 static inline struct ip_conntrack *
 resolve_normal_ct(struct sk_buff *skb,
 		  struct ip_conntrack_protocol *proto,
-		  int *set_reply,
 		  unsigned int hooknum,
 		  enum ip_conntrack_info *ctinfo)
 {
@@ -776,8 +775,8 @@
 	/* It exists; we have (non-exclusive) reference. */
 	if (DIRECTION(h) == IP_CT_DIR_REPLY) {
 		*ctinfo = IP_CT_ESTABLISHED + IP_CT_IS_REPLY;
-		/* Please set reply bit if this packet OK */
-		*set_reply = 1;
+		/* This is a reply packet, set conntrack to replied. */
+		set_bit(IPS_SEEN_REPLY_BIT, &h->ctrack->status);
 	} else {
 		/* Once we've had two way comms, always ESTABLISHED. */
 		if (h->ctrack->status & IPS_SEEN_REPLY) {
@@ -793,7 +792,6 @@
 			       h->ctrack);
 			*ctinfo = IP_CT_NEW;
 		}
-		*set_reply = 0;
 	}
 	skb->nfct = &h->ctrack->infos[*ctinfo];
 	return h->ctrack;
@@ -809,7 +807,6 @@
 	struct ip_conntrack *ct;
 	enum ip_conntrack_info ctinfo;
 	struct ip_conntrack_protocol *proto;
-	int set_reply;
 	int ret;
 
 	/* FIXME: Do this right please. --RR */
@@ -849,7 +846,7 @@
 	    && icmp_error_track(*pskb, &ctinfo, hooknum))
 		return NF_ACCEPT;
 
-	if (!(ct = resolve_normal_ct(*pskb, proto,&set_reply,hooknum,&ctinfo)))
+	if (!(ct = resolve_normal_ct(*pskb, proto, hooknum, &ctinfo)))
 		/* Not valid part of a connection */
 		return NF_ACCEPT;
 
@@ -877,8 +874,6 @@
 			return NF_ACCEPT;
 		}
 	}
-	if (set_reply)
-		set_bit(IPS_SEEN_REPLY_BIT, &ct->status);
 
 	return ret;
 }
net/ipv4/netfilter/ip_conntrack_proto_tcp.c renamed from net/ipv4/netfilter/ip_conntrack_proto_tcp.c.orig +3 -1
@@ -218,7 +218,9 @@
 	   have an established connection: this is a fairly common
 	   problem case, so we can delete the conntrack
 	   immediately.  --RR */
-	if (!(conntrack->status & IPS_SEEN_REPLY) && tcph->rst) {
+	if (oldtcpstate == TCP_CONNTRACK_SYN_SENT
+	    && CTINFO2DIR(ctinfo) == IP_CT_DIR_REPLY
+	    && tcph->rst) {
 		if (del_timer(&conntrack->timeout))
 			conntrack->timeout.function((unsigned long)conntrack);
 	} else {