Merge to Fedora kernel-2.6.18-1.2257_FC5 patched with stable patch-2.6.18.5-vs2.0...
[linux-2.6.git] / net / ipv4 / netfilter / ip_nat_snmp_basic.c
index 2a48b6e..18b7fbd 100644 (file)
@@ -43,7 +43,7 @@
  * 2000-08-06: Convert to new helper API (Harald Welte).
  *
  */
-#include <linux/config.h>
+#include <linux/in.h>
 #include <linux/module.h>
 #include <linux/types.h>
 #include <linux/kernel.h>
@@ -53,6 +53,7 @@
 #include <linux/netfilter_ipv4/ip_conntrack_helper.h>
 #include <linux/netfilter_ipv4/ip_nat_helper.h>
 #include <linux/ip.h>
+#include <linux/udp.h>
 #include <net/checksum.h>
 #include <net/udp.h>
 #include <asm/uaccess.h>
@@ -248,6 +249,7 @@ static unsigned char asn1_header_decode(struct asn1_ctx *ctx,
        if (!asn1_id_decode(ctx, cls, con, tag))
                return 0;
                
+       def = len = 0;
        if (!asn1_length_decode(ctx, &def, &len))
                return 0;
                
@@ -667,7 +669,7 @@ static unsigned char snmp_object_decode(struct asn1_ctx *ctx,
        unsigned char *eoc, *end, *p;
        unsigned long *lp, *id;
        unsigned long ul;
-       long  l;
+       long l;
        
        *obj = NULL;
        id = NULL;
@@ -697,11 +699,13 @@ static unsigned char snmp_object_decode(struct asn1_ctx *ctx,
                return 0;
        }
        
+       type = 0;
        if (!snmp_tag_cls2syntax(tag, cls, &type)) {
                kfree(id);
                return 0;
        }
        
+       l = 0;
        switch (type) {
                case SNMP_INTEGER:
                        len = sizeof(long);
@@ -763,6 +767,7 @@ static unsigned char snmp_object_decode(struct asn1_ctx *ctx,
                        len *= sizeof(unsigned long);
                        *obj = kmalloc(sizeof(struct snmp_object) + len, GFP_ATOMIC);
                        if (*obj == NULL) {
+                               kfree(lp);
                                kfree(id);
                                if (net_ratelimit())
                                        printk("OOM in bsalg (%d)\n", __LINE__);
@@ -998,12 +1003,12 @@ static unsigned char snmp_trap_decode(struct asn1_ctx *ctx,
                
        return 1;
 
+err_addr_free:
+       kfree((unsigned long *)trap->ip_address);
+
 err_id_free:
        kfree(trap->id);
 
-err_addr_free:
-       kfree((unsigned long *)trap->ip_address);
-       
        return 0;
 }
 
@@ -1121,11 +1126,10 @@ static int snmp_parse_mangle(unsigned char *msg,
                struct snmp_v1_trap trap;
                unsigned char ret = snmp_trap_decode(&ctx, &trap, map, check);
                
-               /* Discard trap allocations regardless */
-               kfree(trap.id);
-               kfree((unsigned long *)trap.ip_address);
-               
-               if (!ret)
+               if (ret) {
+                       kfree(trap.id);
+                       kfree((unsigned long *)trap.ip_address);
+               } else 
                        return ret;
                
        } else {
@@ -1161,8 +1165,7 @@ static int snmp_parse_mangle(unsigned char *msg,
                
                if (!snmp_object_decode(&ctx, obj)) {
                        if (*obj) {
-                               if ((*obj)->id)
-                                       kfree((*obj)->id);
+                               kfree((*obj)->id);
                                kfree(*obj);
                        }       
                        kfree(obj);
@@ -1252,9 +1255,9 @@ static int help(struct sk_buff **pskb,
        struct udphdr *udph = (struct udphdr *)((u_int32_t *)iph + iph->ihl);
 
        /* SNMP replies and originating SNMP traps get mangled */
-       if (udph->source == ntohs(SNMP_PORT) && dir != IP_CT_DIR_REPLY)
+       if (udph->source == htons(SNMP_PORT) && dir != IP_CT_DIR_REPLY)
                return NF_ACCEPT;
-       if (udph->dest == ntohs(SNMP_TRAP_PORT) && dir != IP_CT_DIR_ORIGINAL)
+       if (udph->dest == htons(SNMP_TRAP_PORT) && dir != IP_CT_DIR_ORIGINAL)
                return NF_ACCEPT;
 
        /* No NAT? */
@@ -1275,7 +1278,7 @@ static int help(struct sk_buff **pskb,
                 return NF_DROP;
        }
 
-       if (!skb_ip_make_writable(pskb, (*pskb)->len))
+       if (!skb_make_writable(pskb, (*pskb)->len))
                return NF_DROP;
 
        spin_lock_bh(&snmp_lock);
@@ -1320,7 +1323,7 @@ static struct ip_conntrack_helper snmp_trap_helper = {
  *
  *****************************************************************************/
  
-static int __init init(void)
+static int __init ip_nat_snmp_basic_init(void)
 {
        int ret = 0;
 
@@ -1335,13 +1338,13 @@ static int __init init(void)
        return ret;
 }
 
-static void __exit fini(void)
+static void __exit ip_nat_snmp_basic_fini(void)
 {
        ip_conntrack_helper_unregister(&snmp_helper);
        ip_conntrack_helper_unregister(&snmp_trap_helper);
 }
 
-module_init(init);
-module_exit(fini);
+module_init(ip_nat_snmp_basic_init);
+module_exit(ip_nat_snmp_basic_fini);
 
-module_param(debug, bool, 0600);
+module_param(debug, int, 0600);