updated copyrights
[ipt_ACCOUNT] / linux / net / ipv4 / netfilter / ipt_ACCOUNT.c
index 61855b2..68f0b95 100644 (file)
@@ -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  *
@@ -50,7 +50,7 @@ static spinlock_t ipt_acc_userspace_lock = SPIN_LOCK_UNLOCKED;
 
 
 /* Recursive free of all data structures */
-void ipt_acc_data_free(void *data, unsigned char depth)
+static void ipt_acc_data_free(void *data, unsigned char depth)
 {
     /* Empty data set */
     if (!data)
@@ -102,7 +102,7 @@ void ipt_acc_data_free(void *data, unsigned char depth)
 
 /* Look for existing table / insert new one. 
    Return internal ID or -1 on error */
-int ipt_acc_table_insert(char *name, u_int32_t ip, u_int32_t netmask)
+static int ipt_acc_table_insert(char *name, u_int32_t ip, u_int32_t netmask)
 {
     u_int32_t i;
 
@@ -217,7 +217,7 @@ static int ipt_acc_checkentry(const char *tablename,
     return 1;
 }
 
-void ipt_acc_deleteentry(void *targinfo, unsigned int targinfosize)
+static void ipt_acc_deleteentry(void *targinfo, unsigned int targinfosize)
 {
     u_int32_t i;
     struct ipt_acc_info *info = targinfo;
@@ -263,7 +263,7 @@ void ipt_acc_deleteentry(void *targinfo, unsigned int targinfosize)
     spin_unlock_bh(&ipt_acc_lock);
 }
 
-void ipt_acc_depth0_insert(struct ipt_acc_mask_24 *mask_24,
+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)
@@ -337,7 +337,7 @@ void ipt_acc_depth0_insert(struct ipt_acc_mask_24 *mask_24,
     DEBUGP("ACCOUNT: Itemcounter after: %d\n", *itemcount);
 }
 
-void ipt_acc_depth1_insert(struct ipt_acc_mask_16 *mask_16, 
+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)
@@ -375,7 +375,7 @@ void ipt_acc_depth1_insert(struct ipt_acc_mask_16 *mask_16,
     }
 }
 
-void ipt_acc_depth2_insert(struct ipt_acc_mask_8 *mask_8, 
+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)
@@ -495,7 +495,7 @@ static unsigned int ipt_acc_target(struct sk_buff **pskb,
     but there could be two or more applications accessing the data
     at the same time.
 */
-int ipt_acc_handle_find_slot(void)
+static int ipt_acc_handle_find_slot(void)
 {
     u_int32_t i;
     /* Insert new table */
@@ -515,7 +515,7 @@ int ipt_acc_handle_find_slot(void)
     return -1;
 }
 
-int ipt_acc_handle_free(u_int32_t handle)
+static int ipt_acc_handle_free(u_int32_t handle)
 {
     if (handle >= ACCOUNT_MAX_HANDLES) {
         printk("ACCOUNT: Invalid handle for ipt_acc_handle_free() specified:"
@@ -531,7 +531,7 @@ int ipt_acc_handle_free(u_int32_t handle)
 
 /* Prepare data for read without flush. Use only for debugging!
    Real applications should use read&flush as it's way more efficent */
-int ipt_acc_handle_prepare_read(char *tablename, u_int32_t *count)
+static int ipt_acc_handle_prepare_read(char *tablename, u_int32_t *count)
 {
     int handle, i, table_nr=-1;
     unsigned char depth;
@@ -649,7 +649,7 @@ int ipt_acc_handle_prepare_read(char *tablename, u_int32_t *count)
 }
 
 /* Prepare data for read and flush it */
-int ipt_acc_handle_prepare_read_flush(char *tablename, u_int32_t *count)
+static int ipt_acc_handle_prepare_read_flush(char *tablename, u_int32_t *count)
 {
     int handle, i, table_nr=-1;
     void *new_data_page;
@@ -695,7 +695,8 @@ 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.
 */
-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 +714,15 @@ 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;
         }
     }
     
@@ -730,9 +733,9 @@ int ipt_acc_handle_copy_data(void *to_user, int *pos,
    We only copy entries != 0 to increase performance.
    Overwrites ipt_acc_tmpbuf.
 */
-int ipt_acc_handle_get_data(u_int32_t handle, void *to_user)
+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 +756,13 @@ 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 +777,15 @@ 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 +804,9 @@ 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 +815,7 @@ 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;