SOURCES (LINUX_2_6): kernel-ipt_ACCOUNT.patch (NEW) - extracted fr...

zbyniu zbyniu at pld-linux.org
Wed Aug 15 12:59:22 CEST 2007


Author: zbyniu                       Date: Wed Aug 15 10:59:22 2007 GMT
Module: SOURCES                       Tag: LINUX_2_6
---- Log message:
- extracted from http://www.intra2net.com/de/produkte/opensource/ipt_account/pom-ng-ipt_ACCOUNT-1.10.tgz

---- Files affected:
SOURCES:
   kernel-ipt_ACCOUNT.patch (NONE -> 1.1.2.1)  (NEW)

---- Diffs:

================================================================
Index: SOURCES/kernel-ipt_ACCOUNT.patch
diff -u /dev/null SOURCES/kernel-ipt_ACCOUNT.patch:1.1.2.1
--- /dev/null	Wed Aug 15 12:59:22 2007
+++ SOURCES/kernel-ipt_ACCOUNT.patch	Wed Aug 15 12:59:17 2007
@@ -0,0 +1,1323 @@
+diff -uNrp linux/include/linux/netfilter_ipv4/ipt_ACCOUNT.h linux-2.6/include/linux/netfilter_ipv4/ipt_ACCOUNT.h
+--- linux/include/linux/netfilter_ipv4/ipt_ACCOUNT.h	1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6/include/linux/netfilter_ipv4/ipt_ACCOUNT.h	2006-10-26 12:24:51.000000000 +0200
+@@ -0,0 +1,100 @@
++/***************************************************************************
++ *   Copyright (C) 2004-2005 by Intra2net AG                               *
++ *   opensource at intra2net.com                                              *
++ *                                                                         *
++ *   This program is free software; you can redistribute it and/or modify  *
++ *   it under the terms of the GNU General Public License                  *
++ *   version 2 as published by the Free Software Foundation;               *
++ *                                                                         *
++ ***************************************************************************/
++
++#ifndef _IPT_ACCOUNT_H
++#define _IPT_ACCOUNT_H
++
++#define ACCOUNT_MAX_TABLES 128
++#define ACCOUNT_TABLE_NAME_LEN 32
++#define ACCOUNT_MAX_HANDLES 10
++
++/* Structure for the userspace part of ipt_ACCOUNT */
++struct ipt_acc_info {
++    u_int32_t net_ip;
++    u_int32_t net_mask;
++    char table_name[ACCOUNT_TABLE_NAME_LEN];
++    int32_t table_nr;
++};
++
++/* Internal table structure, generated by check_entry() */
++struct ipt_acc_table {
++    char name[ACCOUNT_TABLE_NAME_LEN];     /* name of the table */
++    u_int32_t ip;                          /* base IP of network */
++    u_int32_t netmask;                     /* netmask of the network */
++    unsigned char depth;                   /* size of network: 
++                                                 0: 8 bit, 1: 16bit, 2: 24 bit */
++    u_int32_t refcount;                    /* refcount of this table. 
++                                                 if zero, destroy it */
++    u_int32_t itemcount;                   /* number of IPs in this table */
++    void *data;                            /* pointer to the actual data, 
++                                                 depending on netmask */
++};
++
++/* Internal handle structure */
++struct ipt_acc_handle {
++    u_int32_t ip;                          /* base IP of network. Used for 
++                                                 caculating the final IP during
++                                                 get_data() */
++    unsigned char depth;                   /* size of network. See above for 
++                                                 details */
++    u_int32_t itemcount;                   /* number of IPs in this table */
++    void *data;                            /* pointer to the actual data, 
++                                                 depending on size */
++};
++
++/* Handle structure for communication with the userspace library */
++struct ipt_acc_handle_sockopt {
++    u_int32_t handle_nr;                   /* Used for HANDLE_FREE */
++    char name[ACCOUNT_TABLE_NAME_LEN];     /* Used for HANDLE_PREPARE_READ/
++                                                 HANDLE_READ_FLUSH */
++    u_int32_t itemcount;                   /* Used for HANDLE_PREPARE_READ/
++                                                 HANDLE_READ_FLUSH */
++};
++
++/* Used for every IP entry 
++   Size is 16 bytes so that 256 (class C network) * 16 
++   fits in one kernel (zero) page */
++struct ipt_acc_ip {
++    u_int32_t src_packets;
++    u_int32_t src_bytes;
++    u_int32_t dst_packets;
++    u_int32_t dst_bytes;
++};
++
++/*
++    Used for every IP when returning data
++*/
++struct ipt_acc_handle_ip {
++    u_int32_t ip;
++    u_int32_t src_packets;
++    u_int32_t src_bytes;
++    u_int32_t dst_packets;
++    u_int32_t dst_bytes;
++};
++
++/*
++    The IPs are organized as an array so that direct slot
++    calculations are possible.
++    Only 8 bit networks are preallocated, 16/24 bit networks
++    allocate their slots when needed -> very efficent.
++*/
++struct ipt_acc_mask_24 {
++    struct ipt_acc_ip ip[256];
++};
++
++struct ipt_acc_mask_16 {
++    struct ipt_acc_mask_24 *mask_24[256];
++};
++
++struct ipt_acc_mask_8 {
++    struct ipt_acc_mask_16 *mask_16[256];
++};
++
++#endif /*_IPT_ACCOUNT_H*/
+diff -uNrp linux/net/ipv4/netfilter/ipt_ACCOUNT.c linux-2.6/net/ipv4/netfilter/ipt_ACCOUNT.c
+--- linux/net/ipv4/netfilter/ipt_ACCOUNT.c	1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6/net/ipv4/netfilter/ipt_ACCOUNT.c	2007-07-25 15:07:46.000000000 +0200
+@@ -0,0 +1,1159 @@
++/***************************************************************************
++ *   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                               *
++ *   opensource at intra2net.com                                              *
++ *                                                                         *
++ *   This program is free software; you can redistribute it and/or modify  *
++ *   it under the terms of the GNU General Public License                  *
++ *   version 2 as published by the Free Software Foundation;               *
++ *                                                                         *
++ ***************************************************************************/
++
++#include <linux/module.h>
++#include <linux/version.h>
++#include <linux/skbuff.h>
++#include <linux/ip.h>
++#include <net/icmp.h>
++#include <net/udp.h>
++#include <net/tcp.h>
++#include <linux/netfilter_ipv4/ip_tables.h>
++#include <asm/semaphore.h>
++#include <linux/kernel.h>
++#include <linux/mm.h>
++#include <linux/string.h>
++#include <linux/spinlock.h>
++#include <asm/uaccess.h>
++
++#include <net/route.h>
++#include <linux/netfilter_ipv4/ipt_ACCOUNT.h>
++
++#if 0
++#define DEBUGP printk
++#else
++#define DEBUGP(format, args...)
++#endif
++
++#if (PAGE_SIZE < 4096)
++#error "ipt_ACCOUNT needs at least a PAGE_SIZE of 4096"
++#endif
++
++static struct ipt_acc_table *ipt_acc_tables = NULL;
++static struct ipt_acc_handle *ipt_acc_handles = NULL;
++static void *ipt_acc_tmpbuf = NULL;
++
++/* Spinlock used for manipulating the current accounting tables/data */
++static DEFINE_SPINLOCK(ipt_acc_lock);
++/* Mutex (semaphore) used for manipulating userspace handles/snapshot data */
++static struct semaphore ipt_acc_userspace_mutex;
++
++
++/* Recursive free of all data structures */
++static void ipt_acc_data_free(void *data, unsigned char depth)
++{
++    /* Empty data set */
++    if (!data)
++        return;
++
++    /* Free for 8 bit network */
++    if (depth == 0) {
++        free_page((unsigned long)data);
++        return;
++    }
++
++    /* Free for 16 bit network */
++    if (depth == 1) {
++        struct ipt_acc_mask_16 *mask_16 = (struct ipt_acc_mask_16 *)data;
++        unsigned int b;
++        for (b=0; b <= 255; b++) {
++            if (mask_16->mask_24[b]) {
++                free_page((unsigned long)mask_16->mask_24[b]);
++            }
++        }
++        free_page((unsigned long)data);
++        return;
++    }
++
++    /* Free for 24 bit network */
++    if (depth == 2) {
++        unsigned int a, b;
++        for (a=0; a <= 255; a++) {
++            if (((struct ipt_acc_mask_8 *)data)->mask_16[a]) {
++                struct ipt_acc_mask_16 *mask_16 = (struct ipt_acc_mask_16*)
++                                   ((struct ipt_acc_mask_8 *)data)->mask_16[a];
++
++                for (b=0; b <= 255; b++) {
++                    if (mask_16->mask_24[b]) {
++                        free_page((unsigned long)mask_16->mask_24[b]);
++                    }
++                }
++                free_page((unsigned long)mask_16);
++            }
++        }
++        free_page((unsigned long)data);
++        return;
++    }
++
++    printk("ACCOUNT: ipt_acc_data_free called with unknown depth: %d\n", 
++           depth);
++    return;
++}
++
++/* Look for existing table / insert new one. 
++   Return internal ID or -1 on error */
++static int ipt_acc_table_insert(char *name, u_int32_t ip, u_int32_t netmask)
++{
++    unsigned int i;
++
++    DEBUGP("ACCOUNT: ipt_acc_table_insert: %s, %u.%u.%u.%u/%u.%u.%u.%u\n",
++                                         name, NIPQUAD(ip), NIPQUAD(netmask));
++
++    /* Look for existing table */
++    for (i = 0; i < ACCOUNT_MAX_TABLES; i++) {
++        if (strncmp(ipt_acc_tables[i].name, name, 
++                    ACCOUNT_TABLE_NAME_LEN) == 0) {
++            DEBUGP("ACCOUNT: Found existing slot: %d - "
++                   "%u.%u.%u.%u/%u.%u.%u.%u\n", i, 
++                   NIPQUAD(ipt_acc_tables[i].ip), 
++                   NIPQUAD(ipt_acc_tables[i].netmask));
++
++            if (ipt_acc_tables[i].ip != ip 
++                || ipt_acc_tables[i].netmask != netmask) {
++                printk("ACCOUNT: Table %s found, but IP/netmask mismatch. "
++                       "IP/netmask found: %u.%u.%u.%u/%u.%u.%u.%u\n",
++                       name, NIPQUAD(ipt_acc_tables[i].ip), 
++                       NIPQUAD(ipt_acc_tables[i].netmask));
++                return -1;
++            }
++
++            ipt_acc_tables[i].refcount++;
++            DEBUGP("ACCOUNT: Refcount: %d\n", ipt_acc_tables[i].refcount);
++            return i;
++        }
++    }
++
++    /* Insert new table */
++    for (i = 0; i < ACCOUNT_MAX_TABLES; i++) {
++        /* Found free slot */
++        if (ipt_acc_tables[i].name[0] == 0) {
++            unsigned int netsize=0;
++            u_int32_t calc_mask;
++            int j;  /* needs to be signed, otherwise we risk endless loop */
++
++            DEBUGP("ACCOUNT: Found free slot: %d\n", i);
++            strncpy (ipt_acc_tables[i].name, name, ACCOUNT_TABLE_NAME_LEN-1);
++
++            ipt_acc_tables[i].ip = ip;
++            ipt_acc_tables[i].netmask = netmask;
++
++            /* Calculate netsize */
++            calc_mask = htonl(netmask);
++            for (j = 31; j >= 0; j--) {
++                if (calc_mask&(1<<j))
++                    netsize++;
++                else
++                    break;
++            }
++
++            /* Calculate depth from netsize */
++            if (netsize >= 24)
++                ipt_acc_tables[i].depth = 0;
++            else if (netsize >= 16)
++                ipt_acc_tables[i].depth = 1;
++            else if(netsize >= 8)
++                ipt_acc_tables[i].depth = 2;
++
++            DEBUGP("ACCOUNT: calculated netsize: %u -> "
++                   "ipt_acc_table depth %u\n", netsize, 
++                   ipt_acc_tables[i].depth);
++
++            ipt_acc_tables[i].refcount++;
++            if ((ipt_acc_tables[i].data
++                = (void *)get_zeroed_page(GFP_ATOMIC)) == NULL) {
++                printk("ACCOUNT: out of memory for data of table: %s\n", name);
++                memset(&ipt_acc_tables[i], 0, 
++                       sizeof(struct ipt_acc_table));
++                return -1;
++            }
++
++            return i;
++        }
++    }
++
++    /* No free slot found */
++    printk("ACCOUNT: No free table slot found (max: %d). "
++           "Please increase ACCOUNT_MAX_TABLES.\n", ACCOUNT_MAX_TABLES);
++    return -1;
++}
++
++static int ipt_acc_checkentry(const char *tablename,
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
++                              const void *e,
++#else
++                              const struct ipt_entry *e,
++#endif
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
++                              const struct xt_target *target,
++#endif
++                              void *targinfo,
++#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
++                              unsigned int targinfosize,
++#endif
++                              unsigned int hook_mask)
++{
++    struct ipt_acc_info *info = targinfo;
++    int table_nr;
++
++#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,17)
++    if (targinfosize != IPT_ALIGN(sizeof(struct ipt_acc_info))) {
++        DEBUGP("ACCOUNT: targinfosize %u != %u\n",
++               targinfosize, IPT_ALIGN(sizeof(struct ipt_acc_info)));
++        return 0;
++    }
++#endif
++
++    spin_lock_bh(&ipt_acc_lock);
++    table_nr = ipt_acc_table_insert(info->table_name, info->net_ip,
++                                                      info->net_mask);
++    spin_unlock_bh(&ipt_acc_lock);
++
++    if (table_nr == -1) {
++        printk("ACCOUNT: Table insert problem. Aborting\n");
++        return 0;
++    }
++    /* Table nr caching so we don't have to do an extra string compare 
++       for every packet */
++    info->table_nr = table_nr;
++
++    return 1;
++}
++
++static void ipt_acc_destroy(
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
++                            const struct xt_target *target,
++#endif
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,19)
++                            void *targinfo)
++#else
++                            void *targinfo,
++                            unsigned int targinfosize)
++#endif
++{
++    unsigned int i;
++    struct ipt_acc_info *info = targinfo;
++
++#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,17)
++    if (targinfosize != IPT_ALIGN(sizeof(struct ipt_acc_info))) {
++        DEBUGP("ACCOUNT: targinfosize %u != %u\n",
++               targinfosize, IPT_ALIGN(sizeof(struct ipt_acc_info)));
++    }
++#endif
++
++    spin_lock_bh(&ipt_acc_lock);
++
++    DEBUGP("ACCOUNT: ipt_acc_deleteentry called for table: %s (#%d)\n", 
++           info->table_name, info->table_nr);
++
++    info->table_nr = -1;    /* Set back to original state */
++
++    /* Look for table */
++    for (i = 0; i < ACCOUNT_MAX_TABLES; i++) {
++        if (strncmp(ipt_acc_tables[i].name, info->table_name, 
++                    ACCOUNT_TABLE_NAME_LEN) == 0) {
++            DEBUGP("ACCOUNT: Found table at slot: %d\n", i);
++
++            ipt_acc_tables[i].refcount--;
++            DEBUGP("ACCOUNT: Refcount left: %d\n", 
++                   ipt_acc_tables[i].refcount);
++
++            /* Table not needed anymore? */
++            if (ipt_acc_tables[i].refcount == 0) {
++                DEBUGP("ACCOUNT: Destroying table at slot: %d\n", i);
++                ipt_acc_data_free(ipt_acc_tables[i].data, 
++                                      ipt_acc_tables[i].depth);
++                memset(&ipt_acc_tables[i], 0, 
++                       sizeof(struct ipt_acc_table));
++            }
++
++            spin_unlock_bh(&ipt_acc_lock);
++            return;
++        }
++    }
++
++    /* Table not found */
++    printk("ACCOUNT: Table %s not found for destroy\n", info->table_name);
++    spin_unlock_bh(&ipt_acc_lock);
++}
++
++static void ipt_acc_depth0_insert(struct ipt_acc_mask_24 *mask_24,
++                               u_int32_t net_ip, u_int32_t netmask,
++                               u_int32_t src_ip, u_int32_t dst_ip,
++                               u_int32_t size, u_int32_t *itemcount)
++{
++    unsigned char is_src = 0, is_dst = 0, src_slot, dst_slot;
++    char is_src_new_ip = 0, is_dst_new_ip = 0; /* Check if this entry is new */
++
++    DEBUGP("ACCOUNT: ipt_acc_depth0_insert: %u.%u.%u.%u/%u.%u.%u.%u "
++           "for net %u.%u.%u.%u/%u.%u.%u.%u, size: %u\n", NIPQUAD(src_ip), 
++           NIPQUAD(dst_ip), NIPQUAD(net_ip), NIPQUAD(netmask), size);
++
++    /* Check if src/dst is inside our network. */
++    /* Special: net_ip = 0.0.0.0/0 gets stored as src in slot 0 */
++    if (!netmask)
++        src_ip = 0;
++    if ((net_ip&netmask) == (src_ip&netmask))
++        is_src = 1;
++    if ((net_ip&netmask) == (dst_ip&netmask) && netmask)
++        is_dst = 1;
++
++    if (!is_src && !is_dst) {
++        DEBUGP("ACCOUNT: Skipping packet %u.%u.%u.%u/%u.%u.%u.%u "
++               "for net %u.%u.%u.%u/%u.%u.%u.%u\n", NIPQUAD(src_ip), 
++               NIPQUAD(dst_ip), NIPQUAD(net_ip), NIPQUAD(netmask));
++        return;
++    }
++
++    /* Calculate array positions */
++    src_slot = (unsigned char)((src_ip&0xFF000000) >> 24);
++    dst_slot = (unsigned char)((dst_ip&0xFF000000) >> 24);
++
++    /* Increase size counters */
++    if (is_src) {
++        /* Calculate network slot */
++        DEBUGP("ACCOUNT: Calculated SRC 8 bit network slot: %d\n", src_slot);
++        if (!mask_24->ip[src_slot].src_packets 
++            && !mask_24->ip[src_slot].dst_packets)
++            is_src_new_ip = 1;
++
++        mask_24->ip[src_slot].src_packets++;
++        mask_24->ip[src_slot].src_bytes+=size;
++    }
++    if (is_dst) {
++        DEBUGP("ACCOUNT: Calculated DST 8 bit network slot: %d\n", dst_slot);
++        if (!mask_24->ip[dst_slot].src_packets 
++            && !mask_24->ip[dst_slot].dst_packets)
++            is_dst_new_ip = 1;
++
++        mask_24->ip[dst_slot].dst_packets++;
++        mask_24->ip[dst_slot].dst_bytes+=size;
++    }
++
++    /* Increase itemcounter */
++    DEBUGP("ACCOUNT: Itemcounter before: %d\n", *itemcount);
++    if (src_slot == dst_slot) {
++        if (is_src_new_ip || is_dst_new_ip) {
++            DEBUGP("ACCOUNT: src_slot == dst_slot: %d, %d\n", 
++                   is_src_new_ip, is_dst_new_ip);
++            (*itemcount)++;
++        }
++    } else {
++        if (is_src_new_ip) {
++            DEBUGP("ACCOUNT: New src_ip: %u.%u.%u.%u\n", NIPQUAD(src_ip));
++            (*itemcount)++;
++        }
++        if (is_dst_new_ip) {
++            DEBUGP("ACCOUNT: New dst_ip: %u.%u.%u.%u\n", NIPQUAD(dst_ip));
++            (*itemcount)++;
++        }
++    }
++    DEBUGP("ACCOUNT: Itemcounter after: %d\n", *itemcount);
++}
++
++static void ipt_acc_depth1_insert(struct ipt_acc_mask_16 *mask_16, 
++                               u_int32_t net_ip, u_int32_t netmask, 
++                               u_int32_t src_ip, u_int32_t dst_ip,
++                               u_int32_t size, u_int32_t *itemcount)
++{
++    /* Do we need to process src IP? */
++    if ((net_ip&netmask) == (src_ip&netmask)) {
++        unsigned char slot = (unsigned char)((src_ip&0x00FF0000) >> 16);
++        DEBUGP("ACCOUNT: Calculated SRC 16 bit network slot: %d\n", slot);
++
++        /* Do we need to create a new mask_24 bucket? */
++        if (!mask_16->mask_24[slot] && (mask_16->mask_24[slot] = 
++             (void *)get_zeroed_page(GFP_ATOMIC)) == NULL) {
++            printk("ACCOUNT: Can't process packet because out of memory!\n");
++            return;
++        }
++
++        ipt_acc_depth0_insert((struct ipt_acc_mask_24 *)mask_16->mask_24[slot],
++                                  net_ip, netmask, src_ip, 0, size, itemcount);
++    }
++
++    /* Do we need to process dst IP? */
++    if ((net_ip&netmask) == (dst_ip&netmask)) {
++        unsigned char slot = (unsigned char)((dst_ip&0x00FF0000) >> 16);
++        DEBUGP("ACCOUNT: Calculated DST 16 bit network slot: %d\n", slot);
++
++        /* Do we need to create a new mask_24 bucket? */
++        if (!mask_16->mask_24[slot] && (mask_16->mask_24[slot] 
++            = (void *)get_zeroed_page(GFP_ATOMIC)) == NULL) {
++            printk("ACCOUT: Can't process packet because out of memory!\n");
++            return;
++        }
++
++        ipt_acc_depth0_insert((struct ipt_acc_mask_24 *)mask_16->mask_24[slot],
++                                  net_ip, netmask, 0, dst_ip, size, itemcount);
++    }
++}
++
++static void ipt_acc_depth2_insert(struct ipt_acc_mask_8 *mask_8, 
++                               u_int32_t net_ip, u_int32_t netmask,
++                               u_int32_t src_ip, u_int32_t dst_ip,
++                               u_int32_t size, u_int32_t *itemcount)
++{
++    /* Do we need to process src IP? */
++    if ((net_ip&netmask) == (src_ip&netmask)) {
++        unsigned char slot = (unsigned char)((src_ip&0x0000FF00) >> 8);
++        DEBUGP("ACCOUNT: Calculated SRC 24 bit network slot: %d\n", slot);
++
++        /* Do we need to create a new mask_24 bucket? */
++        if (!mask_8->mask_16[slot] && (mask_8->mask_16[slot] 
++            = (void *)get_zeroed_page(GFP_ATOMIC)) == NULL) {
++            printk("ACCOUNT: Can't process packet because out of memory!\n");
++            return;
++        }
++
++        ipt_acc_depth1_insert((struct ipt_acc_mask_16 *)mask_8->mask_16[slot],
++                                  net_ip, netmask, src_ip, 0, size, itemcount);
++    }
++
++    /* Do we need to process dst IP? */
++    if ((net_ip&netmask) == (dst_ip&netmask)) {
++        unsigned char slot = (unsigned char)((dst_ip&0x0000FF00) >> 8);
++        DEBUGP("ACCOUNT: Calculated DST 24 bit network slot: %d\n", slot);
++
++        /* Do we need to create a new mask_24 bucket? */
++        if (!mask_8->mask_16[slot] && (mask_8->mask_16[slot] 
++            = (void *)get_zeroed_page(GFP_ATOMIC)) == NULL) {
++            printk("ACCOUNT: Can't process packet because out of memory!\n");
++            return;
++        }
++
++        ipt_acc_depth1_insert((struct ipt_acc_mask_16 *)mask_8->mask_16[slot],
++                                  net_ip, netmask, 0, dst_ip, size, itemcount);
++    }
++}
++
++static unsigned int ipt_acc_target(struct sk_buff **pskb,
++                                   const struct net_device *in,
++                                   const struct net_device *out,
++                                   unsigned int hooknum,
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
++                                   const struct xt_target *target,
++#endif
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,19)
++                                   const void *targinfo)
++#else
++                                   const void *targinfo,
++                                   void *userinfo)
++#endif
++{
++    const struct ipt_acc_info *info = 
++        (const struct ipt_acc_info *)targinfo;
++#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;
++    u_int32_t size = ntohs(ip_hdr(*pskb)->tot_len);
++#else
++    u_int32_t src_ip = (*pskb)->nh.iph->saddr;
++    u_int32_t dst_ip = (*pskb)->nh.iph->daddr;
++    u_int32_t size = ntohs((*pskb)->nh.iph->tot_len);
++#endif
++
++    spin_lock_bh(&ipt_acc_lock);
++
++    if (ipt_acc_tables[info->table_nr].name[0] == 0) {
++        printk("ACCOUNT: ipt_acc_target: Invalid table id %u. "
++               "IPs %u.%u.%u.%u/%u.%u.%u.%u\n", info->table_nr, 
++               NIPQUAD(src_ip), NIPQUAD(dst_ip));
++        spin_unlock_bh(&ipt_acc_lock);
++        return IPT_CONTINUE;
++    }
++
++    /* 8 bit network or "any" network */
++    if (ipt_acc_tables[info->table_nr].depth == 0) {
++        /* Count packet and check if the IP is new */
++        ipt_acc_depth0_insert(
++            (struct ipt_acc_mask_24 *)ipt_acc_tables[info->table_nr].data,
++            ipt_acc_tables[info->table_nr].ip, 
++            ipt_acc_tables[info->table_nr].netmask,
++            src_ip, dst_ip, size, &ipt_acc_tables[info->table_nr].itemcount);
<<Diff was trimmed, longer than 597 lines>>


More information about the pld-cvs-commit mailing list