* See http://www.intra2net.com/opensource/ipt_account *
* for further information *
* *
- * Copyright (C) 2004-2006 by Intra2net AG *
+ * Copyright (C) 2004-2007 by Intra2net AG *
* opensource@intra2net.com *
* *
* This program is free software; you can redistribute it and/or modify *
/* Mutex (semaphore) used for manipulating userspace handles/snapshot data */
static struct semaphore ipt_acc_userspace_mutex;
+/* Allocates a page and clears it */
+static void *ipt_acc_zalloc_page(void)
+{
+ // Don't use get_zeroed_page until it's fixed in the kernel.
+ // get_zeroed_page(GFP_ATOMIC)
+ void *mem = (void *)__get_free_page(GFP_ATOMIC);
+ if (mem) {
+ memset (mem, 0, PAGE_SIZE);
+ }
+
+ return mem;
+}
/* Recursive free of all data structures */
static void ipt_acc_data_free(void *data, unsigned char depth)
ipt_acc_tables[i].refcount++;
if ((ipt_acc_tables[i].data
- = (void *)get_zeroed_page(GFP_ATOMIC)) == NULL) {
+ = ipt_acc_zalloc_page()) == NULL) {
printk("ACCOUNT: out of memory for data of table: %s\n", name);
memset(&ipt_acc_tables[i], 0,
sizeof(struct ipt_acc_table));
/* 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) {
+ ipt_acc_zalloc_page()) == NULL) {
printk("ACCOUNT: Can't process packet because out of memory!\n");
return;
}
/* 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) {
+ = ipt_acc_zalloc_page()) == NULL) {
printk("ACCOUT: Can't process packet because out of memory!\n");
return;
}
/* 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) {
+ = ipt_acc_zalloc_page()) == NULL) {
printk("ACCOUNT: Can't process packet because out of memory!\n");
return;
}
/* 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) {
+ = ipt_acc_zalloc_page()) == NULL) {
printk("ACCOUNT: Can't process packet because out of memory!\n");
return;
}
{
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);
dest->itemcount = ipt_acc_tables[table_nr].itemcount;
/* allocate "root" table */
- if ((dest->data = (void*)get_zeroed_page(GFP_ATOMIC)) == NULL) {
+ if ((dest->data = ipt_acc_zalloc_page()) == NULL) {
printk("ACCOUNT: out of memory for root table "
"in ipt_acc_handle_prepare_read()\n");
return -1;
for (b = 0; b <= 255; b++) {
if (src_16->mask_24[b]) {
if ((network_16->mask_24[b] =
- (void*)get_zeroed_page(GFP_ATOMIC)) == NULL) {
+ ipt_acc_zalloc_page()) == NULL) {
printk("ACCOUNT: out of memory during copy of 16 bit "
"network in ipt_acc_handle_prepare_read()\n");
ipt_acc_data_free(dest->data, depth);
for (a = 0; a <= 255; a++) {
if (src_8->mask_16[a]) {
if ((network_8->mask_16[a] =
- (void*)get_zeroed_page(GFP_ATOMIC)) == NULL) {
+ ipt_acc_zalloc_page()) == NULL) {
printk("ACCOUNT: out of memory during copy of 24 bit network"
" in ipt_acc_handle_prepare_read()\n");
ipt_acc_data_free(dest->data, depth);
for (b = 0; b <= 255; b++) {
if (src_16->mask_24[b]) {
if ((network_16->mask_24[b] =
- (void*)get_zeroed_page(GFP_ATOMIC)) == NULL) {
+ ipt_acc_zalloc_page()) == NULL) {
printk("ACCOUNT: out of memory during copy of 16 bit"
" network in ipt_acc_handle_prepare_read()\n");
ipt_acc_data_free(dest->data, depth);
}
/* Try to allocate memory */
- if (!(new_data_page = (void*)get_zeroed_page(GFP_ATOMIC))) {
+ if (!(new_data_page = ipt_acc_zalloc_page())) {
printk("ACCOUNT: ipt_acc_handle_prepare_read_flush(): "
"Out of memory!\n");
return -1;
switch (cmd) {
case IPT_SO_SET_ACCOUNT_HANDLE_FREE:
if (len != sizeof(struct ipt_acc_handle_sockopt)) {
- printk("ACCOUNT: ipt_acc_set_ctl: wrong data size (%u != %u) "
+ printk("ACCOUNT: ipt_acc_set_ctl: wrong data size (%u != %zu) "
"for IPT_SO_SET_HANDLE_FREE\n",
len, sizeof(struct ipt_acc_handle_sockopt));
break;
struct ipt_acc_handle dest;
if (*len < sizeof(struct ipt_acc_handle_sockopt)) {
- printk("ACCOUNT: ipt_acc_get_ctl: wrong data size (%u != %u) "
+ printk("ACCOUNT: ipt_acc_get_ctl: wrong data size (%u != %zu) "
"for IPT_SO_GET_ACCOUNT_PREPARE_READ/READ_FLUSH\n",
*len, sizeof(struct ipt_acc_handle_sockopt));
break;
}
case IPT_SO_GET_ACCOUNT_GET_DATA:
if (*len < sizeof(struct ipt_acc_handle_sockopt)) {
- printk("ACCOUNT: ipt_acc_get_ctl: wrong data size (%u != %u)"
+ printk("ACCOUNT: ipt_acc_get_ctl: wrong data size (%u != %zu)"
" for IPT_SO_GET_ACCOUNT_PREPARE_READ/READ_FLUSH\n",
*len, sizeof(struct ipt_acc_handle_sockopt));
break;
if (*len < ipt_acc_handles[handle.handle_nr].itemcount
* sizeof(struct ipt_acc_handle_ip)) {
- printk("ACCOUNT: ipt_acc_get_ctl: not enough space (%u < %u)"
+ printk("ACCOUNT: ipt_acc_get_ctl: not enough space (%u < %zu)"
" to store data from IPT_SO_GET_ACCOUNT_GET_DATA\n",
*len, ipt_acc_handles[handle.handle_nr].itemcount
* sizeof(struct ipt_acc_handle_ip));
case IPT_SO_GET_ACCOUNT_GET_HANDLE_USAGE: {
unsigned int i;
if (*len < sizeof(struct ipt_acc_handle_sockopt)) {
- printk("ACCOUNT: ipt_acc_get_ctl: wrong data size (%u != %u)"
+ printk("ACCOUNT: ipt_acc_get_ctl: wrong data size (%u != %zu)"
" for IPT_SO_GET_ACCOUNT_GET_HANDLE_USAGE\n",
*len, sizeof(struct ipt_acc_handle_sockopt));
break;