Support for 2.6.28 and 2.6.29
[ipt_ACCOUNT] / linux-2.6 / net / ipv4 / netfilter / ipt_ACCOUNT.c
index d203f41..671c1c4 100644 (file)
@@ -2,8 +2,8 @@
  *   This is a module which is used for counting packets.                  *
  *   See http://www.intra2net.com/opensource/ipt_account                   *
  *   for further information                                               *
- *                                                                         * 
- *   Copyright (C) 2004-2006 by Intra2net AG                               *
+ *                                                                         *
+ *   Copyright (C) 2004-2008 by Intra2net AG                               *
  *   opensource@intra2net.com                                              *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
 #include <net/udp.h>
 #include <net/tcp.h>
 #include <linux/netfilter_ipv4/ip_tables.h>
-#include <asm/semaphore.h>
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
+    #include <linux/semaphore.h>
+#else
+    #include <asm/semaphore.h>
+#endif
+
 #include <linux/kernel.h>
 #include <linux/mm.h>
 #include <linux/string.h>
@@ -200,7 +206,14 @@ static int ipt_acc_table_insert(char *name, u_int32_t ip, u_int32_t netmask)
     return -1;
 }
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28)
+static bool ipt_acc_checkentry(const struct xt_tgchk_param *par)
+#else
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)
+static bool ipt_acc_checkentry(const char *tablename,
+#else
 static int ipt_acc_checkentry(const char *tablename,
+#endif
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
                               const void *e,
 #else
@@ -214,8 +227,13 @@ static int ipt_acc_checkentry(const char *tablename,
                               unsigned int targinfosize,
 #endif
                               unsigned int hook_mask)
+#endif /* >= 2.6.28 */
 {
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28)
+    struct ipt_acc_info *info = par->targinfo;
+#else
     struct ipt_acc_info *info = targinfo;
+#endif
     int table_nr;
 
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,17)
@@ -233,15 +251,26 @@ static int ipt_acc_checkentry(const char *tablename,
 
     if (table_nr == -1) {
         printk("ACCOUNT: Table insert problem. Aborting\n");
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)
+        return false;
+#else
         return 0;
+#endif
     }
     /* Table nr caching so we don't have to do an extra string compare 
        for every packet */
     info->table_nr = table_nr;
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)
+    return true;
+#else
     return 1;
+#endif
 }
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28)
+static void ipt_acc_destroy(const struct xt_tgdtor_param *par)
+#else
 static void ipt_acc_destroy(
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
                             const struct xt_target *target,
@@ -252,9 +281,14 @@ static void ipt_acc_destroy(
                             void *targinfo,
                             unsigned int targinfosize)
 #endif
+#endif /* >= 2.6.28 */
 {
     unsigned int i;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28)
+    struct ipt_acc_info *info = par->targinfo;
+#else
     struct ipt_acc_info *info = targinfo;
+#endif
 
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,17)
     if (targinfosize != IPT_ALIGN(sizeof(struct ipt_acc_info))) {
@@ -449,7 +483,14 @@ static void ipt_acc_depth2_insert(struct ipt_acc_mask_8 *mask_8,
     }
 }
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28)
+static unsigned int ipt_acc_target(struct sk_buff *skb, const struct xt_target_param *par)
+#else
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
+static unsigned int ipt_acc_target(struct sk_buff *skb,
+#else
 static unsigned int ipt_acc_target(struct sk_buff **pskb,
+#endif
                                    const struct net_device *in,
                                    const struct net_device *out,
                                    unsigned int hooknum,
@@ -462,9 +503,20 @@ static unsigned int ipt_acc_target(struct sk_buff **pskb,
                                    const void *targinfo,
                                    void *userinfo)
 #endif
+#endif /* 2.6.28 */
 {
-    const struct ipt_acc_info *info = 
+    const struct ipt_acc_info *info =
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28)
+        par->targinfo;
+#else
         (const struct ipt_acc_info *)targinfo;
+#endif
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
+    u_int32_t src_ip = ip_hdr(skb)->saddr;
+    u_int32_t dst_ip = ip_hdr(skb)->daddr;
+    u_int32_t size = ntohs(ip_hdr(skb)->tot_len);
+#else
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
     u_int32_t src_ip = ip_hdr(*pskb)->saddr;
     u_int32_t dst_ip = ip_hdr(*pskb)->daddr;
@@ -474,6 +526,7 @@ static unsigned int ipt_acc_target(struct sk_buff **pskb,
     u_int32_t dst_ip = (*pskb)->nh.iph->daddr;
     u_int32_t size = ntohs((*pskb)->nh.iph->tot_len);
 #endif
+#endif
 
     spin_lock_bh(&ipt_acc_lock);