Commit 500ae766 authored by Bart De Schuymer's avatar Bart De Schuymer Committed by David S. Miller

[EBTABLES]: Add byte counter support, plus header cleanup.

parent 524c4554
......@@ -20,19 +20,6 @@
#define EBT_CHAIN_MAXNAMELEN EBT_TABLE_MAXNAMELEN
#define EBT_FUNCTION_MAXNAMELEN EBT_TABLE_MAXNAMELEN
// [gs]etsockopt numbers
#define EBT_BASE_CTL 128
#define EBT_SO_SET_ENTRIES (EBT_BASE_CTL)
#define EBT_SO_SET_COUNTERS (EBT_SO_SET_ENTRIES+1)
#define EBT_SO_SET_MAX (EBT_SO_SET_COUNTERS+1)
#define EBT_SO_GET_INFO (EBT_BASE_CTL)
#define EBT_SO_GET_ENTRIES (EBT_SO_GET_INFO+1)
#define EBT_SO_GET_INIT_INFO (EBT_SO_GET_ENTRIES+1)
#define EBT_SO_GET_INIT_ENTRIES (EBT_SO_GET_INIT_INFO+1)
#define EBT_SO_GET_MAX (EBT_SO_GET_INIT_ENTRIES+1)
// verdicts >0 are "branches"
#define EBT_ACCEPT -1
#define EBT_DROP -2
......@@ -40,13 +27,10 @@
#define EBT_RETURN -4
#define NUM_STANDARD_TARGETS 4
// return values for match() functions
#define EBT_MATCH 0
#define EBT_NOMATCH 1
struct ebt_counter
{
uint64_t pcnt;
uint64_t bcnt;
};
struct ebt_entries {
......@@ -178,8 +162,25 @@ struct ebt_replace
char *entries;
};
// [gs]etsockopt numbers
#define EBT_BASE_CTL 128
#define EBT_SO_SET_ENTRIES (EBT_BASE_CTL)
#define EBT_SO_SET_COUNTERS (EBT_SO_SET_ENTRIES+1)
#define EBT_SO_SET_MAX (EBT_SO_SET_COUNTERS+1)
#define EBT_SO_GET_INFO (EBT_BASE_CTL)
#define EBT_SO_GET_ENTRIES (EBT_SO_GET_INFO+1)
#define EBT_SO_GET_INIT_INFO (EBT_SO_GET_ENTRIES+1)
#define EBT_SO_GET_INIT_ENTRIES (EBT_SO_GET_INIT_INFO+1)
#define EBT_SO_GET_MAX (EBT_SO_GET_INIT_ENTRIES+1)
#ifdef __KERNEL__
// return values for match() functions
#define EBT_MATCH 0
#define EBT_NOMATCH 1
struct ebt_match
{
struct list_head list;
......
......@@ -194,6 +194,7 @@ unsigned int ebt_do_table (unsigned int hook, struct sk_buff **pskb,
// increase counter
(*(counter_base + i)).pcnt++;
(*(counter_base + i)).bcnt+=(**pskb).len;
// these should only watch: not modify, nor tell us
// what to do with the packet
......@@ -885,8 +886,10 @@ static void get_counters(struct ebt_counter *oldcounters,
// add other counters to those of cpu 0
for (cpu = 1; cpu < NR_CPUS; cpu++) {
counter_base = COUNTER_BASE(oldcounters, nentries, cpu);
for (i = 0; i < nentries; i++)
for (i = 0; i < nentries; i++) {
counters[i].pcnt += counter_base[i].pcnt;
counters[i].bcnt += counter_base[i].bcnt;
}
}
}
......@@ -1245,8 +1248,10 @@ static int update_counters(void *user, unsigned int len)
write_lock_bh(&t->lock);
// we add to the counters of the first cpu
for (i = 0; i < hlp.num_counters; i++)
for (i = 0; i < hlp.num_counters; i++) {
t->private->counters[i].pcnt += tmp[i].pcnt;
t->private->counters[i].bcnt += tmp[i].bcnt;
}
write_unlock_bh(&t->lock);
ret = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment