SOURCES (LINUX_2_6): linux-2.6-nf-ACCOUNT.patch (NEW) - [extra] AC...
cieciwa
cieciwa at pld-linux.org
Fri Sep 16 16:20:29 CEST 2005
Author: cieciwa Date: Fri Sep 16 14:20:28 2005 GMT
Module: SOURCES Tag: LINUX_2_6
---- Log message:
- [extra] ACCOUNT - kernel patch.
---- Files affected:
SOURCES:
linux-2.6-nf-ACCOUNT.patch (NONE -> 1.1.2.1) (NEW)
---- Diffs:
================================================================
Index: SOURCES/linux-2.6-nf-ACCOUNT.patch
diff -u /dev/null SOURCES/linux-2.6-nf-ACCOUNT.patch:1.1.2.1
--- /dev/null Fri Sep 16 16:20:29 2005
+++ SOURCES/linux-2.6-nf-ACCOUNT.patch Fri Sep 16 16:20:23 2005
@@ -0,0 +1,1248 @@
+ include/linux/netfilter_ipv4/ip_tables.h | 11
+ include/linux/netfilter_ipv4/ipt_ACCOUNT.h | 100 ++
+ net/ipv4/netfilter/Makefile | 1
+ net/ipv4/netfilter/ipt_ACCOUNT.c | 1103 +++++++++++++++++++++++++++++
+ 4 files changed, 1215 insertions(+)
+
+diff -Nur --exclude '*.orig' linux-2.6.13.1.org/include/linux/netfilter_ipv4/ip_tables.h linux-2.6.13.1/include/linux/netfilter_ipv4/ip_tables.h
+--- linux-2.6.13.1.org/include/linux/netfilter_ipv4/ip_tables.h 2005-09-10 04:42:58.000000000 +0200
++++ linux-2.6.13.1/include/linux/netfilter_ipv4/ip_tables.h 2005-09-16 16:08:00.000000000 +0200
+@@ -156,11 +156,22 @@
+ #define IPT_SO_SET_ADD_COUNTERS (IPT_BASE_CTL + 1)
+ #define IPT_SO_SET_MAX IPT_SO_SET_ADD_COUNTERS
+
++#define IPT_SO_SET_ACCOUNT_HANDLE_FREE (IPT_BASE_CTL + 3)
++#define IPT_SO_SET_ACCOUNT_HANDLE_FREE_ALL (IPT_BASE_CTL + 4)
++#define IPT_SO_SET_ACCOUNT_MAX IPT_SO_SET_ACCOUNT_HANDLE_FREE_ALL
++
+ #define IPT_SO_GET_INFO (IPT_BASE_CTL)
+ #define IPT_SO_GET_ENTRIES (IPT_BASE_CTL + 1)
+ #define IPT_SO_GET_REVISION_MATCH (IPT_BASE_CTL + 2)
+ #define IPT_SO_GET_REVISION_TARGET (IPT_BASE_CTL + 3)
+ #define IPT_SO_GET_MAX IPT_SO_GET_REVISION_TARGET
++
++#define IPT_SO_GET_ACCOUNT_PREPARE_READ (IPT_BASE_CTL + 3)
++#define IPT_SO_GET_ACCOUNT_PREPARE_READ_FLUSH (IPT_BASE_CTL + 4)
++#define IPT_SO_GET_ACCOUNT_GET_DATA (IPT_BASE_CTL + 5)
++#define IPT_SO_GET_ACCOUNT_GET_HANDLE_USAGE (IPT_BASE_CTL + 6)
++#define IPT_SO_GET_ACCOUNT_GET_TABLE_NAMES (IPT_BASE_CTL + 7)
++#define IPT_SO_GET_ACCOUNT_MAX IPT_SO_GET_ACCOUNT_GET_TABLE_NAMES
+
+ /* CONTINUE verdict for targets */
+ #define IPT_CONTINUE 0xFFFFFFFF
+diff -Nur --exclude '*.orig' linux-2.6.13.1.org/include/linux/netfilter_ipv4/ipt_ACCOUNT.h linux-2.6.13.1/include/linux/netfilter_ipv4/ipt_ACCOUNT.h
+--- linux-2.6.13.1.org/include/linux/netfilter_ipv4/ipt_ACCOUNT.h 1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.13.1/include/linux/netfilter_ipv4/ipt_ACCOUNT.h 2005-09-16 16:04:05.000000000 +0200
+@@ -0,0 +1,100 @@
++/***************************************************************************
++ * Copyright (C) 2004 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 32
++#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 -Nur --exclude '*.orig' linux-2.6.13.1.org/net/ipv4/netfilter/Makefile linux-2.6.13.1/net/ipv4/netfilter/Makefile
+--- linux-2.6.13.1.org/net/ipv4/netfilter/Makefile 2005-09-10 04:42:58.000000000 +0200
++++ linux-2.6.13.1/net/ipv4/netfilter/Makefile 2005-09-16 16:04:05.000000000 +0200
+@@ -0,0 +0,1 @@
++obj-$(CONFIG_IP_NF_TARGET_ACCOUNT) += ipt_ACCOUNT.o
+diff -Nur --exclude '*.orig' linux-2.6.13.1.org/net/ipv4/netfilter/ipt_ACCOUNT.c linux-2.6.13.1/net/ipv4/netfilter/ipt_ACCOUNT.c
+--- linux-2.6.13.1.org/net/ipv4/netfilter/ipt_ACCOUNT.c 1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.13.1/net/ipv4/netfilter/ipt_ACCOUNT.c 2005-09-16 16:04:05.000000000 +0200
+@@ -0,0 +1,1103 @@
++/***************************************************************************
++ * This is a module which is used for counting packets. *
++ * See http://www.intra2net.com/opensource/ipt_account *
++ * for further information *
++ * *
++ * 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; *
++ * *
++ ***************************************************************************/
++
++#include <linux/module.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 <linux/netfilter_ipv4/lockhelp.h>
++#include <asm/semaphore.h>
++#include <linux/kernel.h>
++#include <linux/mm.h>
++#include <linux/string.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 */
++DECLARE_LOCK(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;
++ u_int32_t b;
++ for (b=0; b <= 255; b++) {
++ if (mask_16->mask_24[b] != 0) {
++ free_page((unsigned long)mask_16->mask_24[b]);
++ }
++ }
++ free_page((unsigned long)data);
++ return;
++ }
++
++ /* Free for 24 bit network */
++ if (depth == 2) {
++ u_int32_t 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)
++{
++ u_int32_t 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) {
++ u_int32_t calc_mask, netsize=0;
++ 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,
++ const struct ipt_entry *e,
++ void *targinfo,
++ unsigned int targinfosize,
++ unsigned int hook_mask)
++{
++ struct ipt_acc_info *info = targinfo;
++ int table_nr;
++
++ 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;
++ }
++
++ LOCK_BH(&ipt_acc_lock);
++ table_nr = ipt_acc_table_insert(info->table_name, info->net_ip,
++ info->net_mask);
++ 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_deleteentry(void *targinfo, unsigned int targinfosize)
++{
++ u_int32_t i;
++ struct ipt_acc_info *info = targinfo;
++
++ if (targinfosize != IPT_ALIGN(sizeof(struct ipt_acc_info))) {
++ DEBUGP("ACCOUNT: targinfosize %u != %u\n",
++ targinfosize, IPT_ALIGN(sizeof(struct ipt_acc_info)));
++ }
++
++ 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));
++ }
++
++ UNLOCK_BH(&ipt_acc_lock);
++ return;
++ }
++ }
++
++ /* Table not found */
++ printk("ACCOUNT: Table %s not found for destroy\n", info->table_name);
++ 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,
++ const void *targinfo,
++ void *userinfo)
++{
++ const struct ipt_acc_info *info =
++ (const struct ipt_acc_info *)targinfo;
++ 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);
++
++ 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));
++ 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