ACCOUNT: simple reformat, use tabs instead of spaces

The result is not perfect, but at more manageable.
This commit is contained in:
Jan Engelhardt
2009-09-05 03:01:37 +02:00
parent 06c01131e8
commit dd6cb27da4
3 changed files with 985 additions and 985 deletions

View File

@@ -108,7 +108,7 @@ static int parse(int c, char **argv, int invert, unsigned int *flags,
/* Final check; nothing. */ /* Final check; nothing. */
static void final_check(unsigned int flags) static void final_check(unsigned int flags)
{ {
if (!(flags&IPT_ACCOUNT_OPT_ADDR) || !(flags&IPT_ACCOUNT_OPT_TABLE)) if (!(flags & IPT_ACCOUNT_OPT_ADDR) || !(flags & IPT_ACCOUNT_OPT_TABLE))
xtables_error(PARAMETER_PROBLEM, "ACCOUNT: needs --%s and --%s", xtables_error(PARAMETER_PROBLEM, "ACCOUNT: needs --%s and --%s",
opts[0].name, opts[1].name); opts[0].name, opts[1].name);
} }
@@ -164,7 +164,7 @@ print(const void *ip,
const struct xt_entry_target *target, const struct xt_entry_target *target,
int numeric) int numeric)
{ {
print_it (ip, target, 0); print_it(ip, target, 0);
} }
/* Saves the union ipt_targinfo in parsable form to stdout. */ /* Saves the union ipt_targinfo in parsable form to stdout. */

View File

@@ -85,7 +85,7 @@ static void ipt_acc_data_free(void *data, unsigned char depth)
if (depth == 1) { if (depth == 1) {
struct ipt_acc_mask_16 *mask_16 = (struct ipt_acc_mask_16 *)data; struct ipt_acc_mask_16 *mask_16 = (struct ipt_acc_mask_16 *)data;
unsigned int b; unsigned int b;
for (b=0; b <= 255; b++) { for (b = 0; b <= 255; b++) {
if (mask_16->mask_24[b]) { if (mask_16->mask_24[b]) {
free_page((unsigned long)mask_16->mask_24[b]); free_page((unsigned long)mask_16->mask_24[b]);
} }
@@ -97,12 +97,12 @@ static void ipt_acc_data_free(void *data, unsigned char depth)
/* Free for 24 bit network */ /* Free for 24 bit network */
if (depth == 2) { if (depth == 2) {
unsigned int a, b; unsigned int a, b;
for (a=0; a <= 255; a++) { for (a = 0; a <= 255; a++) {
if (((struct ipt_acc_mask_8 *)data)->mask_16[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_16 *mask_16 = (struct ipt_acc_mask_16*)
((struct ipt_acc_mask_8 *)data)->mask_16[a]; ((struct ipt_acc_mask_8 *)data)->mask_16[a];
for (b=0; b <= 255; b++) { for (b = 0; b <= 255; b++) {
if (mask_16->mask_24[b]) { if (mask_16->mask_24[b]) {
free_page((unsigned long)mask_16->mask_24[b]); free_page((unsigned long)mask_16->mask_24[b]);
} }
@@ -156,12 +156,12 @@ static int ipt_acc_table_insert(char *name, uint32_t ip, uint32_t netmask)
for (i = 0; i < ACCOUNT_MAX_TABLES; i++) { for (i = 0; i < ACCOUNT_MAX_TABLES; i++) {
/* Found free slot */ /* Found free slot */
if (ipt_acc_tables[i].name[0] == 0) { if (ipt_acc_tables[i].name[0] == 0) {
unsigned int netsize=0; unsigned int netsize = 0;
uint32_t calc_mask; uint32_t calc_mask;
int j; /* needs to be signed, otherwise we risk endless loop */ int j; /* needs to be signed, otherwise we risk endless loop */
DEBUGP("ACCOUNT: Found free slot: %d\n", i); DEBUGP("ACCOUNT: Found free slot: %d\n", i);
strncpy (ipt_acc_tables[i].name, name, ACCOUNT_TABLE_NAME_LEN-1); strncpy(ipt_acc_tables[i].name, name, ACCOUNT_TABLE_NAME_LEN-1);
ipt_acc_tables[i].ip = ip; ipt_acc_tables[i].ip = ip;
ipt_acc_tables[i].netmask = netmask; ipt_acc_tables[i].netmask = netmask;
@@ -169,7 +169,7 @@ static int ipt_acc_table_insert(char *name, uint32_t ip, uint32_t netmask)
/* Calculate netsize */ /* Calculate netsize */
calc_mask = htonl(netmask); calc_mask = htonl(netmask);
for (j = 31; j >= 0; j--) { for (j = 31; j >= 0; j--) {
if (calc_mask&(1<<j)) if (calc_mask & (1 << j))
netsize++; netsize++;
else else
break; break;
@@ -180,7 +180,7 @@ static int ipt_acc_table_insert(char *name, uint32_t ip, uint32_t netmask)
ipt_acc_tables[i].depth = 0; ipt_acc_tables[i].depth = 0;
else if (netsize >= 16) else if (netsize >= 16)
ipt_acc_tables[i].depth = 1; ipt_acc_tables[i].depth = 1;
else if(netsize >= 8) else if (netsize >= 8)
ipt_acc_tables[i].depth = 2; ipt_acc_tables[i].depth = 2;
DEBUGP("ACCOUNT: calculated netsize: %u -> " DEBUGP("ACCOUNT: calculated netsize: %u -> "
@@ -349,9 +349,9 @@ static void ipt_acc_depth0_insert(struct ipt_acc_mask_24 *mask_24,
/* Special: net_ip = 0.0.0.0/0 gets stored as src in slot 0 */ /* Special: net_ip = 0.0.0.0/0 gets stored as src in slot 0 */
if (!netmask) if (!netmask)
src_ip = 0; src_ip = 0;
if ((net_ip&netmask) == (src_ip&netmask)) if ((net_ip & netmask) == (src_ip & netmask))
is_src = 1; is_src = 1;
if ((net_ip&netmask) == (dst_ip&netmask) && netmask) if ((net_ip & netmask) == (dst_ip & netmask) && netmask)
is_dst = 1; is_dst = 1;
if (!is_src && !is_dst) { if (!is_src && !is_dst) {
@@ -362,8 +362,8 @@ static void ipt_acc_depth0_insert(struct ipt_acc_mask_24 *mask_24,
} }
/* Calculate array positions */ /* Calculate array positions */
src_slot = (unsigned char)((src_ip&0xFF000000) >> 24); src_slot = (unsigned char)((src_ip & 0xFF000000) >> 24);
dst_slot = (unsigned char)((dst_ip&0xFF000000) >> 24); dst_slot = (unsigned char)((dst_ip & 0xFF000000) >> 24);
/* Increase size counters */ /* Increase size counters */
if (is_src) { if (is_src) {
@@ -374,7 +374,7 @@ static void ipt_acc_depth0_insert(struct ipt_acc_mask_24 *mask_24,
is_src_new_ip = 1; is_src_new_ip = 1;
mask_24->ip[src_slot].src_packets++; mask_24->ip[src_slot].src_packets++;
mask_24->ip[src_slot].src_bytes+=size; mask_24->ip[src_slot].src_bytes += size;
} }
if (is_dst) { if (is_dst) {
DEBUGP("ACCOUNT: Calculated DST 8 bit network slot: %d\n", dst_slot); DEBUGP("ACCOUNT: Calculated DST 8 bit network slot: %d\n", dst_slot);
@@ -383,7 +383,7 @@ static void ipt_acc_depth0_insert(struct ipt_acc_mask_24 *mask_24,
is_dst_new_ip = 1; is_dst_new_ip = 1;
mask_24->ip[dst_slot].dst_packets++; mask_24->ip[dst_slot].dst_packets++;
mask_24->ip[dst_slot].dst_bytes+=size; mask_24->ip[dst_slot].dst_bytes += size;
} }
/* Increase itemcounter */ /* Increase itemcounter */
@@ -413,8 +413,8 @@ static void ipt_acc_depth1_insert(struct ipt_acc_mask_16 *mask_16,
uint32_t size, uint32_t *itemcount) uint32_t size, uint32_t *itemcount)
{ {
/* Do we need to process src IP? */ /* Do we need to process src IP? */
if ((net_ip&netmask) == (src_ip&netmask)) { if ((net_ip & netmask) == (src_ip & netmask)) {
unsigned char slot = (unsigned char)((src_ip&0x00FF0000) >> 16); unsigned char slot = (unsigned char)((src_ip & 0x00FF0000) >> 16);
DEBUGP("ACCOUNT: Calculated SRC 16 bit network slot: %d\n", slot); DEBUGP("ACCOUNT: Calculated SRC 16 bit network slot: %d\n", slot);
/* Do we need to create a new mask_24 bucket? */ /* Do we need to create a new mask_24 bucket? */
@@ -429,8 +429,8 @@ static void ipt_acc_depth1_insert(struct ipt_acc_mask_16 *mask_16,
} }
/* Do we need to process dst IP? */ /* Do we need to process dst IP? */
if ((net_ip&netmask) == (dst_ip&netmask)) { if ((net_ip & netmask) == (dst_ip & netmask)) {
unsigned char slot = (unsigned char)((dst_ip&0x00FF0000) >> 16); unsigned char slot = (unsigned char)((dst_ip & 0x00FF0000) >> 16);
DEBUGP("ACCOUNT: Calculated DST 16 bit network slot: %d\n", slot); DEBUGP("ACCOUNT: Calculated DST 16 bit network slot: %d\n", slot);
/* Do we need to create a new mask_24 bucket? */ /* Do we need to create a new mask_24 bucket? */
@@ -451,8 +451,8 @@ static void ipt_acc_depth2_insert(struct ipt_acc_mask_8 *mask_8,
uint32_t size, uint32_t *itemcount) uint32_t size, uint32_t *itemcount)
{ {
/* Do we need to process src IP? */ /* Do we need to process src IP? */
if ((net_ip&netmask) == (src_ip&netmask)) { if ((net_ip & netmask) == (src_ip & netmask)) {
unsigned char slot = (unsigned char)((src_ip&0x0000FF00) >> 8); unsigned char slot = (unsigned char)((src_ip & 0x0000FF00) >> 8);
DEBUGP("ACCOUNT: Calculated SRC 24 bit network slot: %d\n", slot); DEBUGP("ACCOUNT: Calculated SRC 24 bit network slot: %d\n", slot);
/* Do we need to create a new mask_24 bucket? */ /* Do we need to create a new mask_24 bucket? */
@@ -467,8 +467,8 @@ static void ipt_acc_depth2_insert(struct ipt_acc_mask_8 *mask_8,
} }
/* Do we need to process dst IP? */ /* Do we need to process dst IP? */
if ((net_ip&netmask) == (dst_ip&netmask)) { if ((net_ip & netmask) == (dst_ip & netmask)) {
unsigned char slot = (unsigned char)((dst_ip&0x0000FF00) >> 8); unsigned char slot = (unsigned char)((dst_ip & 0x0000FF00) >> 8);
DEBUGP("ACCOUNT: Calculated DST 24 bit network slot: %d\n", slot); DEBUGP("ACCOUNT: Calculated DST 24 bit network slot: %d\n", slot);
/* Do we need to create a new mask_24 bucket? */ /* Do we need to create a new mask_24 bucket? */
@@ -627,7 +627,7 @@ static int ipt_acc_handle_free(unsigned int handle)
ipt_acc_data_free(ipt_acc_handles[handle].data, ipt_acc_data_free(ipt_acc_handles[handle].data,
ipt_acc_handles[handle].depth); ipt_acc_handles[handle].depth);
memset (&ipt_acc_handles[handle], 0, sizeof (struct ipt_acc_handle)); memset(&ipt_acc_handles[handle], 0, sizeof(struct ipt_acc_handle));
return 0; return 0;
} }
@@ -636,7 +636,7 @@ static int ipt_acc_handle_free(unsigned int handle)
static int ipt_acc_handle_prepare_read(char *tablename, static int ipt_acc_handle_prepare_read(char *tablename,
struct ipt_acc_handle *dest, uint32_t *count) struct ipt_acc_handle *dest, uint32_t *count)
{ {
int table_nr=-1; int table_nr = -1;
unsigned char depth; unsigned char depth;
for (table_nr = 0; table_nr < ACCOUNT_MAX_TABLES; table_nr++) for (table_nr = 0; table_nr < ACCOUNT_MAX_TABLES; table_nr++)
@@ -689,7 +689,7 @@ static int ipt_acc_handle_prepare_read(char *tablename,
sizeof(struct ipt_acc_mask_24)); sizeof(struct ipt_acc_mask_24));
} }
} }
} else if(depth == 2) { } else if (depth == 2) {
struct ipt_acc_mask_8 *src_8 = struct ipt_acc_mask_8 *src_8 =
(struct ipt_acc_mask_8 *)ipt_acc_tables[table_nr].data; (struct ipt_acc_mask_8 *)ipt_acc_tables[table_nr].data;
struct ipt_acc_mask_8 *network_8 = struct ipt_acc_mask_8 *network_8 =
@@ -784,12 +784,12 @@ static int ipt_acc_handle_copy_data(void *to_user, unsigned long *to_user_pos,
uint32_t net_ip, uint32_t net_OR_mask) uint32_t net_ip, uint32_t net_OR_mask)
{ {
struct ipt_acc_handle_ip handle_ip; struct ipt_acc_handle_ip handle_ip;
size_t handle_ip_size = sizeof (struct ipt_acc_handle_ip); size_t handle_ip_size = sizeof(struct ipt_acc_handle_ip);
unsigned int i; unsigned int i;
for (i = 0; i <= 255; i++) { for (i = 0; i <= 255; i++) {
if (data->ip[i].src_packets || data->ip[i].dst_packets) { if (data->ip[i].src_packets || data->ip[i].dst_packets) {
handle_ip.ip = net_ip | net_OR_mask | (i<<24); handle_ip.ip = net_ip | net_OR_mask | (i << 24);
handle_ip.src_packets = data->ip[i].src_packets; handle_ip.src_packets = data->ip[i].src_packets;
handle_ip.src_bytes = data->ip[i].src_bytes; handle_ip.src_bytes = data->ip[i].src_bytes;
@@ -797,14 +797,14 @@ static int ipt_acc_handle_copy_data(void *to_user, unsigned long *to_user_pos,
handle_ip.dst_bytes = data->ip[i].dst_bytes; handle_ip.dst_bytes = data->ip[i].dst_bytes;
/* Temporary buffer full? Flush to userspace */ /* Temporary buffer full? Flush to userspace */
if (*tmpbuf_pos+handle_ip_size >= PAGE_SIZE) { if (*tmpbuf_pos + handle_ip_size >= PAGE_SIZE) {
if (copy_to_user(to_user + *to_user_pos, ipt_acc_tmpbuf, if (copy_to_user(to_user + *to_user_pos, ipt_acc_tmpbuf,
*tmpbuf_pos)) *tmpbuf_pos))
return -EFAULT; return -EFAULT;
*to_user_pos = *to_user_pos + *tmpbuf_pos; *to_user_pos = *to_user_pos + *tmpbuf_pos;
*tmpbuf_pos = 0; *tmpbuf_pos = 0;
} }
memcpy(ipt_acc_tmpbuf+*tmpbuf_pos, &handle_ip, handle_ip_size); memcpy(ipt_acc_tmpbuf + *tmpbuf_pos, &handle_ip, handle_ip_size);
*tmpbuf_pos += handle_ip_size; *tmpbuf_pos += handle_ip_size;
} }
} }
@@ -818,7 +818,7 @@ static int ipt_acc_handle_copy_data(void *to_user, unsigned long *to_user_pos,
*/ */
static int ipt_acc_handle_get_data(uint32_t handle, void *to_user) static int ipt_acc_handle_get_data(uint32_t handle, void *to_user)
{ {
unsigned long to_user_pos=0, tmpbuf_pos=0; unsigned long to_user_pos = 0, tmpbuf_pos = 0;
uint32_t net_ip; uint32_t net_ip;
unsigned char depth; unsigned char depth;
@@ -846,7 +846,7 @@ static int ipt_acc_handle_get_data(uint32_t handle, void *to_user)
/* Flush remaining data to userspace */ /* Flush remaining data to userspace */
if (tmpbuf_pos) if (tmpbuf_pos)
if (copy_to_user(to_user+to_user_pos, ipt_acc_tmpbuf, tmpbuf_pos)) if (copy_to_user(to_user + to_user_pos, ipt_acc_tmpbuf, tmpbuf_pos))
return -1; return -1;
return 0; return 0;
@@ -869,7 +869,7 @@ static int ipt_acc_handle_get_data(uint32_t handle, void *to_user)
/* Flush remaining data to userspace */ /* Flush remaining data to userspace */
if (tmpbuf_pos) if (tmpbuf_pos)
if (copy_to_user(to_user+to_user_pos, ipt_acc_tmpbuf, tmpbuf_pos)) if (copy_to_user(to_user + to_user_pos, ipt_acc_tmpbuf, tmpbuf_pos))
return -1; return -1;
return 0; return 0;
@@ -899,7 +899,7 @@ static int ipt_acc_handle_get_data(uint32_t handle, void *to_user)
/* Flush remaining data to userspace */ /* Flush remaining data to userspace */
if (tmpbuf_pos) if (tmpbuf_pos)
if (copy_to_user(to_user+to_user_pos, ipt_acc_tmpbuf, tmpbuf_pos)) if (copy_to_user(to_user + to_user_pos, ipt_acc_tmpbuf, tmpbuf_pos))
return -1; return -1;
return 0; return 0;
@@ -926,7 +926,7 @@ static int ipt_acc_set_ctl(struct sock *sk, int cmd,
break; break;
} }
if (copy_from_user (&handle, user, len)) { if (copy_from_user(&handle, user, len)) {
printk("ACCOUNT: ipt_acc_set_ctl: copy_from_user failed for " printk("ACCOUNT: ipt_acc_set_ctl: copy_from_user failed for "
"IPT_SO_SET_HANDLE_FREE\n"); "IPT_SO_SET_HANDLE_FREE\n");
break; break;
@@ -1017,7 +1017,7 @@ static int ipt_acc_get_ctl(struct sock *sk, int cmd, void *user, int *len)
break; break;
} }
if (copy_from_user (&handle, user, if (copy_from_user(&handle, user,
sizeof(struct ipt_acc_handle_sockopt))) { sizeof(struct ipt_acc_handle_sockopt))) {
return -EFAULT; return -EFAULT;
break; break;
@@ -1083,7 +1083,7 @@ static int ipt_acc_get_ctl(struct sock *sk, int cmd, void *user, int *len)
/* Determine size of table names */ /* Determine size of table names */
for (i = 0; i < ACCOUNT_MAX_TABLES; i++) { for (i = 0; i < ACCOUNT_MAX_TABLES; i++) {
if (ipt_acc_tables[i].name[0] != 0) if (ipt_acc_tables[i].name[0] != 0)
size += strlen (ipt_acc_tables[i].name) + 1; size += strlen(ipt_acc_tables[i].name) + 1;
} }
size += 1; /* Terminating NULL character */ size += 1; /* Terminating NULL character */
@@ -1098,7 +1098,7 @@ static int ipt_acc_get_ctl(struct sock *sk, int cmd, void *user, int *len)
tnames = ipt_acc_tmpbuf; tnames = ipt_acc_tmpbuf;
for (i = 0; i < ACCOUNT_MAX_TABLES; i++) { for (i = 0; i < ACCOUNT_MAX_TABLES; i++) {
if (ipt_acc_tables[i].name[0] != 0) { if (ipt_acc_tables[i].name[0] != 0) {
name_len = strlen (ipt_acc_tables[i].name) + 1; name_len = strlen(ipt_acc_tables[i].name) + 1;
memcpy(tnames, ipt_acc_tables[i].name, name_len); memcpy(tnames, ipt_acc_tables[i].name, name_len);
tnames += name_len; tnames += name_len;
} }
@@ -1194,9 +1194,9 @@ static int __init init(void)
return 0; return 0;
error_cleanup: error_cleanup:
if(ipt_acc_tables) if (ipt_acc_tables)
kfree(ipt_acc_tables); kfree(ipt_acc_tables);
if(ipt_acc_handles) if (ipt_acc_handles)
kfree(ipt_acc_handles); kfree(ipt_acc_handles);
if (ipt_acc_tmpbuf) if (ipt_acc_tmpbuf)
free_page((unsigned long)ipt_acc_tmpbuf); free_page((unsigned long)ipt_acc_tmpbuf);

View File

@@ -108,4 +108,4 @@ struct ipt_acc_mask_8 {
struct ipt_acc_mask_16 *mask_16[256]; struct ipt_acc_mask_16 *mask_16[256];
}; };
#endif /*_IPT_ACCOUNT_H*/ #endif /* _IPT_ACCOUNT_H */