vserver 1.9.3
[linux-2.6.git] / net / ipv4 / netfilter / ip_nat_snmp_basic.c
index 00b4eff..32d6e96 100644 (file)
@@ -47,6 +47,7 @@
 #include <linux/module.h>
 #include <linux/types.h>
 #include <linux/kernel.h>
+#include <linux/moduleparam.h>
 #include <linux/netfilter_ipv4.h>
 #include <linux/netfilter_ipv4/ip_nat.h>
 #include <linux/netfilter_ipv4/ip_nat_helper.h>
@@ -252,7 +253,7 @@ static unsigned char asn1_header_decode(struct asn1_ctx *ctx,
        if (def)
                *eoc = ctx->pointer + len;
        else
-               *eoc = 0;
+               *eoc = NULL;
        return 1;
 }
 
@@ -862,6 +863,77 @@ static unsigned char snmp_request_decode(struct asn1_ctx *ctx,
        return 1;
 }
 
+/* 
+ * Fast checksum update for possibly oddly-aligned UDP byte, from the
+ * code example in the draft.
+ */
+static void fast_csum(unsigned char *csum,
+                      const unsigned char *optr,
+                      const unsigned char *nptr,
+                      int odd)
+{
+       long x, old, new;
+       
+       x = csum[0] * 256 + csum[1];
+       
+       x =~ x & 0xFFFF;
+       
+       if (odd) old = optr[0] * 256;
+       else old = optr[0];
+       
+       x -= old & 0xFFFF;
+       if (x <= 0) {
+               x--;
+               x &= 0xFFFF;
+       }
+       
+       if (odd) new = nptr[0] * 256;
+       else new = nptr[0];
+       
+       x += new & 0xFFFF;
+       if (x & 0x10000) {
+               x++;
+               x &= 0xFFFF;
+       }
+       
+       x =~ x & 0xFFFF;
+       csum[0] = x / 256;
+       csum[1] = x & 0xFF;
+}
+
+/* 
+ * Mangle IP address.
+ *     - begin points to the start of the snmp messgae
+ *      - addr points to the start of the address
+ */
+static inline void mangle_address(unsigned char *begin,
+                                  unsigned char *addr,
+                                  const struct oct1_map *map,
+                                  u_int16_t *check)
+{
+       if (map->from == NOCT1(*addr)) {
+               u_int32_t old;
+               
+               if (debug)
+                       memcpy(&old, (unsigned char *)addr, sizeof(old));
+                       
+               *addr = map->to;
+               
+               /* Update UDP checksum if being used */
+               if (*check) {
+                       unsigned char odd = !((addr - begin) % 2);
+                       
+                       fast_csum((unsigned char *)check,
+                                 &map->from, &map->to, odd);
+                                 
+               }
+               
+               if (debug)
+                       printk(KERN_DEBUG "bsalg: mapped %u.%u.%u.%u to "
+                              "%u.%u.%u.%u\n", NIPQUAD(old), NIPQUAD(*addr));
+       }
+}
+
 static unsigned char snmp_trap_decode(struct asn1_ctx *ctx,
                                       struct snmp_v1_trap *trap,
                                       const struct oct1_map *map,
@@ -952,77 +1024,6 @@ static void hex_dump(unsigned char *buf, size_t len)
        printk("\n");
 }
 
-/* 
- * Fast checksum update for possibly oddly-aligned UDP byte, from the
- * code example in the draft.
- */
-static void fast_csum(unsigned char *csum,
-                      const unsigned char *optr,
-                      const unsigned char *nptr,
-                      int odd)
-{
-       long x, old, new;
-       
-       x = csum[0] * 256 + csum[1];
-       
-       x =~ x & 0xFFFF;
-       
-       if (odd) old = optr[0] * 256;
-       else old = optr[0];
-       
-       x -= old & 0xFFFF;
-       if (x <= 0) {
-               x--;
-               x &= 0xFFFF;
-       }
-       
-       if (odd) new = nptr[0] * 256;
-       else new = nptr[0];
-       
-       x += new & 0xFFFF;
-       if (x & 0x10000) {
-               x++;
-               x &= 0xFFFF;
-       }
-       
-       x =~ x & 0xFFFF;
-       csum[0] = x / 256;
-       csum[1] = x & 0xFF;
-}
-
-/* 
- * Mangle IP address.
- *     - begin points to the start of the snmp messgae
- *      - addr points to the start of the address
- */
-static inline void mangle_address(unsigned char *begin,
-                                  unsigned char *addr,
-                                  const struct oct1_map *map,
-                                  u_int16_t *check)
-{
-       if (map->from == NOCT1(*addr)) {
-               u_int32_t old;
-               
-               if (debug)
-                       memcpy(&old, (unsigned char *)addr, sizeof(old));
-                       
-               *addr = map->to;
-               
-               /* Update UDP checksum if being used */
-               if (*check) {
-                       unsigned char odd = !((addr - begin) % 2);
-                       
-                       fast_csum((unsigned char *)check,
-                                 &map->from, &map->to, odd);
-                                 
-               }
-               
-               if (debug)
-                       printk(KERN_DEBUG "bsalg: mapped %u.%u.%u.%u to "
-                              "%u.%u.%u.%u\n", NIPQUAD(old), NIPQUAD(*addr));
-       }
-}
-
 /*
  * Parse and mangle SNMP message according to mapping.
  * (And this is the fucking 'basic' method).
@@ -1252,6 +1253,9 @@ static unsigned int nat_help(struct ip_conntrack *ct,
        int dir = CTINFO2DIR(ctinfo);
        struct iphdr *iph = (*pskb)->nh.iph;
        struct udphdr *udph = (struct udphdr *)((u_int32_t *)iph + iph->ihl);
+       
+       if (!skb_ip_make_writable(pskb, (*pskb)->len))
+               return NF_DROP;
 
        spin_lock_bh(&snmp_lock);
        
@@ -1357,4 +1361,4 @@ static void __exit fini(void)
 module_init(init);
 module_exit(fini);
 
-MODULE_PARM(debug, "i");
+module_param(debug, bool, 0600);