patch-2.1.73 linux/net/ipv4/ip_masq_app.c

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

diff -u --recursive --new-file v2.1.72/linux/net/ipv4/ip_masq_app.c linux/net/ipv4/ip_masq_app.c
@@ -39,13 +39,6 @@
 #include <linux/proc_fs.h>
 #include <net/ip_masq.h>
 
-static const char *strProt[] = {"UDP","TCP"};
-
-static __inline__ const char * masq_proto_name(unsigned proto)
-{
-        return strProt[proto==IPPROTO_TCP];
-}
-
 #define IP_MASQ_APP_TAB_SIZE  16 /* must be power of 2 */
 
 #define IP_MASQ_APP_HASH(proto, port) ((port^proto) & (IP_MASQ_APP_TAB_SIZE-1))
@@ -74,7 +67,7 @@
         unsigned long flags;
         unsigned hash;
         if (!mapp) {
-                printk(KERN_ERR "register_ip_masq_app(): NULL arg\n");
+                IP_MASQ_ERR("register_ip_masq_app(): NULL arg\n");
                 return -EINVAL;
         }
         mapp->type = IP_MASQ_APP_TYPE(proto, port);
@@ -100,14 +93,14 @@
         unsigned hash;
         unsigned long flags;
         if (!mapp) {
-                printk(KERN_ERR "unregister_ip_masq_app(): NULL arg\n");
+                IP_MASQ_ERR("unregister_ip_masq_app(): NULL arg\n");
                 return -EINVAL;
         }
         /*
          * only allow unregistration if it has no attachments
          */
         if (mapp->n_attach)  {
-                printk(KERN_ERR "unregister_ip_masq_app(): has %d attachments. failed\n",
+                IP_MASQ_ERR("unregister_ip_masq_app(): has %d attachments. failed\n",
                        mapp->n_attach);
                 return -EINVAL;
         }
@@ -123,7 +116,7 @@
                 }
 
         restore_flags(flags);
-        printk(KERN_ERR "unregister_ip_masq_app(proto=%s,port=%u): not hashed!\n",
+        IP_MASQ_ERR("unregister_ip_masq_app(proto=%s,port=%u): not hashed!\n",
                masq_proto_name(IP_MASQ_APP_PROTO(mapp->type)), IP_MASQ_APP_PORT(mapp->type));
         return -EINVAL;
 }
@@ -165,7 +158,7 @@
         n_at = mapp->n_attach + delta;
         if (n_at < 0) {
                 restore_flags(flags);
-                printk(KERN_ERR "ip_masq_app: tried to set n_attach < 0 for (proto=%s,port==%d) ip_masq_app object.\n",
+                IP_MASQ_ERR("ip_masq_app: tried to set n_attach < 0 for (proto=%s,port==%d) ip_masq_app object.\n",
                        masq_proto_name(IP_MASQ_APP_PROTO(mapp->type)),
                        IP_MASQ_APP_PORT(mapp->type));
                 return -1;
@@ -183,14 +176,26 @@
 struct ip_masq_app * ip_masq_bind_app(struct ip_masq *ms)
 {
         struct ip_masq_app * mapp;
+
+	if (ms->protocol != IPPROTO_TCP && ms->protocol != IPPROTO_UDP)
+		return NULL;
+
         mapp = ip_masq_app_get(ms->protocol, ms->dport);
+
+#if 0000
+/* #ifdef CONFIG_IP_MASQUERADE_IPAUTOFW */
+	if (mapp == NULL)
+		mapp = ip_masq_app_get(ms->protocol, ms->sport);
+/* #endif */
+#endif
+
         if (mapp != NULL) {
                 /*
                  *	don't allow binding if already bound
                  */
 
                 if (ms->app != NULL) {
-                        printk(KERN_ERR "ip_masq_bind_app() called for already bound object.\n");
+                        IP_MASQ_ERR("ip_masq_bind_app() called for already bound object.\n");
                         return ms->app;
                 }
 
@@ -209,6 +214,10 @@
 {
         struct ip_masq_app * mapp;
         mapp = ms->app;
+
+	if (ms->protocol != IPPROTO_TCP && ms->protocol != IPPROTO_UDP)
+		return 0;
+
         if (mapp != NULL) {
                 if (mapp->masq_done_1) mapp->masq_done_1(mapp, ms);
                 ms->app = NULL;
@@ -236,14 +245,10 @@
 	if (ms_seq->delta || ms_seq->previous_delta) {
 		if(after(seq,ms_seq->init_seq) ) {
 			th->seq = htonl(seq + ms_seq->delta);
-#if DEBUG_CONFIG_IP_MASQ_APP
-			printk("masq_fix_seq() : added delta (%d) to seq\n",ms_seq->delta);
-#endif
+			IP_MASQ_DEBUG(1, "masq_fix_seq() : added delta (%d) to seq\n",ms_seq->delta);
 		} else {
 			th->seq = htonl(seq + ms_seq->previous_delta);
-#if DEBUG_CONFIG_IP_MASQ_APP
-	 		printk("masq_fix_seq() : added previous_delta (%d) to seq\n",ms_seq->previous_delta);
-#endif
+			IP_MASQ_DEBUG(1, "masq_fix_seq() : added previous_delta (%d) to seq\n",ms_seq->previous_delta);
 		}
 	}
 
@@ -269,14 +274,11 @@
         if (ms_seq->delta || ms_seq->previous_delta) {
                 if(after(ack_seq,ms_seq->init_seq)) {
                         th->ack_seq = htonl(ack_seq-ms_seq->delta);
-#if DEBUG_CONFIG_IP_MASQ_APP
-                        printk("masq_fix_ack_seq() : subtracted delta (%d) from ack_seq\n",ms_seq->delta);
-#endif
+                        IP_MASQ_DEBUG(1, "masq_fix_ack_seq() : subtracted delta (%d) from ack_seq\n",ms_seq->delta);
+
                 } else {
                         th->ack_seq = htonl(ack_seq-ms_seq->previous_delta);
-#if DEBUG_CONFIG_IP_MASQ_APP
-                        printk("masq_fix_ack_seq() : subtracted previous_delta (%d) from ack_seq\n",ms_seq->previous_delta);
-#endif
+                        IP_MASQ_DEBUG(1, "masq_fix_ack_seq() : subtracted previous_delta (%d) from ack_seq\n",ms_seq->previous_delta);
                 }
         }
 
@@ -369,7 +371,7 @@
  *	returns (new - old) skb->len diff.
  */
 
-int ip_masq_app_pkt_in(struct ip_masq *ms, struct sk_buff **skb_p)
+int ip_masq_app_pkt_in(struct ip_masq *ms, struct sk_buff **skb_p, __u32 maddr)
 {
         struct ip_masq_app * mapp;
         struct iphdr *iph;
@@ -414,7 +416,7 @@
         if ( mapp->pkt_in == NULL )
                 return 0;
 
-        diff = mapp->pkt_in(mapp, ms, skb_p);
+        diff = mapp->pkt_in(mapp, ms, skb_p, maddr);
 
         /*
          *	Update ip_masq seq stuff if len has changed.
@@ -529,7 +531,7 @@
 
                 n_skb = alloc_skb(MAX_HEADER + skb->len + diff, pri);
                 if (n_skb == NULL) {
-                        printk(KERN_ERR "skb_replace(): no room left (from %p)\n",
+                        IP_MASQ_ERR("skb_replace(): no room left (from %p)\n",
                                __builtin_return_address(0));
                         return skb;
 
@@ -589,9 +591,7 @@
         if (diff)
         {
                 struct iphdr *iph;
-#if DEBUG_CONFIG_IP_MASQ_APP
-                printk("masq_skb_replace(): pkt resized for %d bytes (len=%ld)\n", diff, skb->len);
-#endif
+                IP_MASQ_DEBUG(1, "masq_skb_replace(): pkt resized for %d bytes (len=%d)\n", diff, skb->len);
                 /*
                  * 	update ip header
                  */

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov