patch-1.3.94 linux/net/ipv4/ip_masq_ftp.c

Next file: linux/net/ipv4/ip_masq_irc.c
Previous file: linux/net/ipv4/ip_masq_app.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v1.3.93/linux/net/ipv4/ip_masq_ftp.c linux/net/ipv4/ip_masq_ftp.c
@@ -66,12 +66,12 @@
 	iph = skb->h.iph;
         th = (struct tcphdr *)&(((char *)iph)[iph->ihl*4]);
         data = (char *)&th[1];
-        
+
         data_limit = skb->h.raw + skb->len - 18;
 
 	while (data < data_limit)
 	{
-		if (memcmp(data,"PORT ",5) && memcmp(data,"port ",5)) 
+		if (memcmp(data,"PORT ",5) && memcmp(data,"port ",5))
 		{
 			data ++;
 			continue;
@@ -99,21 +99,38 @@
 		from = (p1<<24) | (p2<<16) | (p3<<8) | p4;
 		port = (p5<<8) | p6;
 #if DEBUG_CONFIG_IP_MASQ_FTP
-		printk("PORT %lX:%X detected\n",from,port);
+		printk("PORT %X:%X detected\n",from,port);
 #endif	
 		/*
-		 * Now create an masquerade entry for it
+		 * Now update or create an masquerade entry for it
 		 */
-                n_ms = ip_masq_new(dev, IPPROTO_TCP,
-                                   htonl(from), htons(port),
-                                   iph->daddr, 0,
-                                   IP_MASQ_F_NO_DPORT);
-                                   
-		if (n_ms==NULL)
-			return 0;
+#if DEBUG_CONFIG_IP_MASQ_FTP
+		printk("protocol %d %lX:%X %X:%X\n", iph->protocol, htonl(from), htons(port), iph->daddr, 0);
+
+#endif	
+		n_ms = ip_masq_out_get_2(iph->protocol,
+					 htonl(from), htons(port),
+					 iph->daddr, 0);
+		if (n_ms) {
+			/* existing masquerade, clear timer */
+			ip_masq_set_expire(n_ms,0);
+		}
+		else {
+			n_ms = ip_masq_new(dev, IPPROTO_TCP,
+					   htonl(from), htons(port),
+					   iph->daddr, 0,
+					   IP_MASQ_F_NO_DPORT);
+					
+			if (n_ms==NULL)
+				return 0;
+		}
+
+                /*
+                 * keep for a bit longer than tcp_fin, caller may not reissue
+                 * PORT before tcp_fin_timeout.
+                 */
+                ip_masq_set_expire(n_ms, ip_masq_expire->tcp_fin_timeout*3);
 
-                ip_masq_set_expire(n_ms, ip_masq_expire->tcp_fin_timeout);
-                
 		/*
 		 * Replace the old PORT with the new one
 		 */
@@ -123,7 +140,10 @@
 			from>>24&255,from>>16&255,from>>8&255,from&255,
 			port>>8&255,port&255);
 		buf_len = strlen(buf);
- 
+#if DEBUG_CONFIG_IP_MASQ_FTP
+		printk("new PORT %X:%X\n",from,port);
+#endif	
+
 		/*
 		 * Calculate required delta-offset to keep TCP happy
 		 */
@@ -133,8 +153,8 @@
 		/*
 		 *	No shift.
 		 */
-		 
-		if (diff==0) 
+		
+		if (diff==0)
 		{
 			/*
 			 * simple case, just replace the old PORT cmd
@@ -153,6 +173,7 @@
 
 struct ip_masq_app ip_masq_ftp = {
         NULL,			/* next */
+	"ftp",			/* name */
         0,                      /* type */
         0,                      /* n_attach */
         masq_ftp_init_1,        /* ip_masq_init_1 */

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov with Sam's (original) version
of this