X-Git-Url: http://developer.intra2net.com/git/?p=ipt_ACCOUNT;a=blobdiff_plain;f=linux%2Fnet%2Fipv4%2Fnetfilter%2Fipt_ACCOUNT.c;h=0013bdf8aa7d8ca55480488d0e7b325a105e861e;hp=7ef45db76ae864b714ef3c100f5f61c8cbfc665c;hb=491d7fffdf074139eae3396c01bc489150c1ac52;hpb=0f549f69eaee14d5db527e34e32beb9a6ab5048f diff --git a/linux/net/ipv4/netfilter/ipt_ACCOUNT.c b/linux/net/ipv4/netfilter/ipt_ACCOUNT.c index 7ef45db..0013bdf 100644 --- a/linux/net/ipv4/netfilter/ipt_ACCOUNT.c +++ b/linux/net/ipv4/netfilter/ipt_ACCOUNT.c @@ -3,7 +3,7 @@ * See http://www.intra2net.com/opensource/ipt_account * * for further information * * * - * Copyright (C) 2004 by Intra2net AG * + * Copyright (C) 2004-2005 by Intra2net AG * * opensource@intra2net.com * * * * This program is free software; you can redistribute it and/or modify * @@ -25,7 +25,6 @@ #include #include -struct in_device; #include #include @@ -39,9 +38,9 @@ struct in_device; #error "ipt_ACCOUNT needs at least a PAGE_SIZE of 4096" #endif -struct ipt_acc_table *ipt_acc_tables = NULL; -struct ipt_acc_handle *ipt_acc_handles = NULL; -void *ipt_acc_tmpbuf = NULL; +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 spinlock_t ipt_acc_lock = SPIN_LOCK_UNLOCKED; @@ -695,7 +694,8 @@ static int ipt_acc_handle_prepare_read_flush(char *tablename, u_int32_t *count) /* Copy 8 bit network data into a prepared buffer. We only copy entries != 0 to increase performance. */ -static int ipt_acc_handle_copy_data(void *to_user, int *pos, +static int ipt_acc_handle_copy_data(void *to_user, u_int32_t *to_user_pos, + u_int32_t *tmpbuf_pos, struct ipt_acc_mask_24 *data, u_int32_t net_ip, u_int32_t net_OR_mask) { @@ -713,13 +713,15 @@ static int ipt_acc_handle_copy_data(void *to_user, int *pos, handle_ip.dst_bytes = data->ip[i].dst_bytes; /* Temporary buffer full? Flush to userspace */ - if (*pos+handle_ip_size >= PAGE_SIZE) { - if (copy_to_user(to_user, ipt_acc_tmpbuf, *pos)) + if (*tmpbuf_pos+handle_ip_size >= PAGE_SIZE) { + if (copy_to_user(to_user + *to_user_pos, ipt_acc_tmpbuf, + *tmpbuf_pos)) return -EFAULT; - *pos = 0; + *to_user_pos = *to_user_pos + *tmpbuf_pos; + *tmpbuf_pos = 0; } - memcpy(ipt_acc_tmpbuf+*pos, &handle_ip, handle_ip_size); - *pos += handle_ip_size; + memcpy(ipt_acc_tmpbuf+*tmpbuf_pos, &handle_ip, handle_ip_size); + *tmpbuf_pos += handle_ip_size; } } @@ -732,7 +734,7 @@ static int ipt_acc_handle_copy_data(void *to_user, int *pos, */ static int ipt_acc_handle_get_data(u_int32_t handle, void *to_user) { - u_int32_t tmpbuf_pos=0, net_ip; + u_int32_t to_user_pos=0, tmpbuf_pos=0, net_ip; unsigned char depth; if (handle >= ACCOUNT_MAX_HANDLES) { @@ -753,12 +755,13 @@ static int ipt_acc_handle_get_data(u_int32_t handle, void *to_user) if (depth == 0) { struct ipt_acc_mask_24 *network = (struct ipt_acc_mask_24*)ipt_acc_handles[handle].data; - if (ipt_acc_handle_copy_data(to_user, &tmpbuf_pos, network, net_ip, 0)) + if (ipt_acc_handle_copy_data(to_user, &to_user_pos, &tmpbuf_pos, + network, net_ip, 0)) return -1; /* Flush remaining data to userspace */ if (tmpbuf_pos) - if (copy_to_user(to_user, ipt_acc_tmpbuf, tmpbuf_pos)) + if (copy_to_user(to_user+to_user_pos, ipt_acc_tmpbuf, tmpbuf_pos)) return -1; return 0; @@ -773,15 +776,15 @@ static int ipt_acc_handle_get_data(u_int32_t handle, void *to_user) if (network_16->mask_24[b]) { struct ipt_acc_mask_24 *network = (struct ipt_acc_mask_24*)network_16->mask_24[b]; - if (ipt_acc_handle_copy_data(to_user, &tmpbuf_pos, network, - net_ip, (b << 16))) + if (ipt_acc_handle_copy_data(to_user, &to_user_pos, + &tmpbuf_pos, network, net_ip, (b << 16))) return -1; } } /* Flush remaining data to userspace */ if (tmpbuf_pos) - if (copy_to_user(to_user, ipt_acc_tmpbuf, tmpbuf_pos)) + if (copy_to_user(to_user+to_user_pos, ipt_acc_tmpbuf, tmpbuf_pos)) return -1; return 0; @@ -800,8 +803,9 @@ static int ipt_acc_handle_get_data(u_int32_t handle, void *to_user) if (network_16->mask_24[b]) { struct ipt_acc_mask_24 *network = (struct ipt_acc_mask_24*)network_16->mask_24[b]; - if (ipt_acc_handle_copy_data(to_user, &tmpbuf_pos, - network, net_ip, (a << 8) | (b << 16))) + if (ipt_acc_handle_copy_data(to_user, + &to_user_pos, &tmpbuf_pos, + network, net_ip, (a << 8) | (b << 16))) return -1; } } @@ -810,7 +814,7 @@ static int ipt_acc_handle_get_data(u_int32_t handle, void *to_user) /* Flush remaining data to userspace */ if (tmpbuf_pos) - if (copy_to_user(to_user, ipt_acc_tmpbuf, tmpbuf_pos)) + if (copy_to_user(to_user+to_user_pos, ipt_acc_tmpbuf, tmpbuf_pos)) return -1; return 0;