ipt_account rate patch
PATCH 1/1 ipt_account rate patch
Here are some patches I did for ipt_account before ipt_ACCOUNT which supports larger subnets was re-released.
As well as per-ip packet and byte counting, the patches also does per-ip rate calculating, so you can use this as part of a rate limiting rule and drop packets that would exceed the rate.
You get to choose whether or not dropped packets should also be accounted.
Just as ipt_account supports total-subnet accounting, so we also support total-subnet rate calculations as well.
The rate calculations are an improved version of what is in ip_conntrack_rate.c, namely we can handle the timer wraps around zero.
Sam
libipt_account.c renamed from libipt_account.c.rate +131 -3
@@ -34,14 +34,50 @@"--ashort\n" " table will colect only short statistics (only total counters\n" " without splitting it into protocols.\n" +"--non-subnet\n" +" Traffic whose src or dst ip is not in the account subnet\n" +" should be counted as matching, even though no rate tests\n" +" can be done.\n" +"--above\n" +" Matches if any of the ranges are exceeded\n" +"--below\n" +" (Default) Matches if none of the ranges are exceeded\n" +"[!] --src-rate rate\n" +" TRUE if IP-specific rate on packets from that subnets [not] in range\n" +"[!] --src-subnet-rate\n" +" TRUE if rate on all packets from that subnets [not] in range\n" +"[!] --dst-rate rate\n" +" TRUE if IP-specific rate on packets to that subnets [not] in range\n" +"[!] --dst-subnet-rate rate\n" +" TRUE if rate on all packets to that subnets [not] in range\n" +"--ignore-src-over\n" +" Don't count packets if rate is exceeded.\n" +" Perhaps Use this if you intend to drop such packets.\n" +"--ignore-dst-over\n" +" Don't count packets if rate is exceeded.\n" +" Perhaps Use this if you intend to drop such packets.\n" +"--check-only\n" +" Don't count packets at all, just check decayed rate to\n" +" calculate if the packet would have been dropped.\n" , IPTABLES_VERSION); };static struct option opts[] = { - { .name ="aaddr" , .has_arg =1 , .flag =NULL , .val =201 }, - { .name ="aname" , .has_arg =1 , .flag =NULL , .val =202 }, - { .name ="ashort" , .has_arg =0 , .flag =NULL , .val =203 }, + { .name ="aaddr" , .has_arg =1 , .flag =NULL , .val =201 }, + { .name ="aname" , .has_arg =1 , .flag =NULL , .val =202 }, + { .name ="ashort" , .has_arg =0 , .flag =NULL , .val =203 }, + { .name ="src-rate" , .has_arg =1 , .flag =NULL , .val =204 }, + { .name ="src-subnet-rate" , .has_arg =1 , .flag =NULL , .val =205 }, + { .name ="dst-rate" , .has_arg =1 , .flag =NULL , .val =206 }, + { .name ="dst-subnet-rate" , .has_arg =1 , .flag =NULL , .val =207 }, + { .name ="ignore-src-over" , .has_arg =0 , .flag =NULL , .val =208 }, + { .name ="ignore-dst-over" , .has_arg =0 , .flag =NULL , .val =209 }, + { .name ="check-only" , .has_arg =0 , .flag =NULL , .val =210 }, + { .name ="not" , .has_arg =0 , .flag =NULL , .val =211 }, + { .name ="above" , .has_arg =0 , .flag =NULL , .val =211 }, + { .name ="below" , .has_arg =0 , .flag =NULL , .val =212 }, + { .name ="non-subnet" , .has_arg =0 , .flag =NULL , .val =213 }, { .name =0 , .has_arg =0 , .flag =0 , .val =0 } };
@@ -206,6 +242,39 @@case 203 : info->shortlisting =1 ;break ; +case 204 : + info->src_rate=atoi (optarg); +if (invert) info->accounting|=IPT_ACCOUNT_INVERT_src_RATE; +break ; +case 205 : + info->src_subnet_rate=atoi (optarg); +if (invert) info->accounting|=IPT_ACCOUNT_INVERT_src_SUBNET_RATE; +break ; +case 206 : + info->dest_rate=atoi (optarg); +if (invert) info->accounting|=IPT_ACCOUNT_INVERT_dest_RATE; +break ; +case 207 : + info->dest_subnet_rate=atoi (optarg); +if (invert) info->accounting|=IPT_ACCOUNT_INVERT_dest_SUBNET_RATE; +break ; +case 208 : + info->accounting|=IPT_ACCOUNT_src_OVER; +break ; +case 209 : + info->accounting|=IPT_ACCOUNT_dest_OVER; +break ; +case 210 : + info->accounting|=IPT_ACCOUNT_CHECKONLY ; +break ; +case 211 : + info->accounting|=IPT_ACCOUNT_INVERT ; +break ; +case 212 :/* we default to below */ +break ; +case 213 : + info->accounting|=IPT_ACCOUNT_INVERT_NAME ; +break ;default :return 0 ; }
@@ -235,6 +304,30 @@printf ("name: %s " , info->name);if (info->shortlisting)printf ("short-listing " ); + +if ((info->accounting &IPT_ACCOUNT_INVERT ) && (info->src_rate || info->src_subnet_rate || info->dest_rate || info->dest_subnet_rate)) +printf ("NOT " ); +printf ("(" ); +if (info->src_rate) +printf ("src-rate: %c %u B/s " ,(info->accounting & IPT_ACCOUNT_INVERT_src_RATE)?'>' :'<' ,info->src_rate); + +if (info->src_subnet_rate) +printf ("src-subnet-rate: %c %u B/s " ,(info->accounting & IPT_ACCOUNT_INVERT_src_SUBNET_RATE)?'>' :'<' ,info->src_subnet_rate); + +if (info->dest_rate) +printf ("dst-rate: %c %u B/s " ,(info->accounting & IPT_ACCOUNT_INVERT_dest_RATE)?'>' :'<' ,info->dest_rate); + +if (info->dest_subnet_rate) +printf ("dst-subnet-rate: %c %u B/s " ,(info->accounting & IPT_ACCOUNT_INVERT_dest_SUBNET_RATE)?'>' :'<' ,info->dest_subnet_rate); +printf (") " ); +if (info->accounting & IPT_ACCOUNT_src_OVER) +printf ("ignore-src-over " ); + +if (info->accounting & IPT_ACCOUNT_dest_OVER) +printf ("ignore-dst-over " ); + +if (info->accounting &IPT_ACCOUNT_CHECKONLY ) +printf ("check-only " ); }/* Function used for saving rule containing account match */
@@ -252,6 +345,41 @@printf ("--aname %s " , info->name);if (info->shortlisting)printf ("--ashort " ); + +if ((info->accounting &IPT_ACCOUNT_INVERT_NAME )) +printf ("--non-subnet " ); + +if ((info->accounting &IPT_ACCOUNT_INVERT ) && (info->src_rate || info->src_subnet_rate || info->dest_rate || info->dest_subnet_rate)) +printf ("--above " ); + +if (info->src_rate) { +if (info->accounting & IPT_ACCOUNT_INVERT_src_RATE)printf ("! " ); +printf ("--src-rate %u " ,info->src_rate); + } + +if (info->src_subnet_rate) { +if (info->accounting & IPT_ACCOUNT_INVERT_src_SUBNET_RATE)printf ("! " ); +printf ("--src-subnet-rate %u " ,info->src_subnet_rate); + } + +if (info->dest_rate) { +if (info->accounting & IPT_ACCOUNT_INVERT_dest_RATE)printf ("! " ); +printf ("--dst-rate %d " ,info->dest_rate); + } + +if (info->dest_subnet_rate) { +if (info->accounting & IPT_ACCOUNT_INVERT_dest_SUBNET_RATE)printf ("! " ); +printf ("--dst-subnet-rate %d " ,info->dest_subnet_rate); + } + +if (info->accounting & IPT_ACCOUNT_src_OVER) +printf ("--ignore-src-over " ); + +if (info->accounting & IPT_ACCOUNT_dest_OVER) +printf ("--ignore-dst-over " ); + +if (info->accounting &IPT_ACCOUNT_CHECKONLY ) +printf ("--check-only " ); }static struct iptables_match account = {
ipv4/netfilter/ipt_account.c +253 -50
457 lines not on this page · raw message
linux/netfilter_ipv4/ipt_account.h +20 -1
@@ -13,13 +13,32 @@#define IPT_ACCOUNT_NAME_LEN 64#define IPT_ACCOUNT_NAME "ipt_account" -#define IPT_ACCOUNT_VERSION "0.1.7" +#define IPT_ACCOUNT_VERSION "0.1.7-rate" + +/* Whether or not to account for packets which go over permitted rate +* If these are going to be dropped, it may be better not to count */ + +#define IPT_ACCOUNT_src_OVER 1 << 0 +#define IPT_ACCOUNT_dest_OVER 1 << 1 +#define IPT_ACCOUNT_CHECKONLY 1 << 2 +#define IPT_ACCOUNT_INVERT_src_RATE 1 << 3 +#define IPT_ACCOUNT_INVERT_src_SUBNET_RATE 1 << 4 +#define IPT_ACCOUNT_INVERT_dest_RATE 1 << 5 +#define IPT_ACCOUNT_INVERT_dest_SUBNET_RATE 1 << 6 +/* this IPT_ACCOUNT_INVERT is the most useful, the other INVERT are for insane people */ +#define IPT_ACCOUNT_INVERT 1 << 7 +#define IPT_ACCOUNT_INVERT_NAME 1 << 8struct t_ipt_account_info {char name[IPT_ACCOUNT_NAME_LEN ];u_int32_t network;u_int32_t netmask;int shortlisting:1 ; +int accounting:9 ; +u_int32_t src_rate; +u_int32_t src_subnet_rate; +u_int32_t dest_rate; +u_int32_t dest_subnet_rate; };#endif
Quoted 7 lines · Amin Azez
Here are some patches I did for
ipt_accountbeforeipt_ACCOUNTwhich supports larger subnets was re-released.As well as per-ip packet and byte counting, the patches also does per-ip rate calculating, so you can use this as part of a rate limiting rule and drop packets that would exceed the rate.
Quoted 7 lines
You get to choose whether or not dropped packets should also be accounted.
Just as
ipt_accountsupports total-subnet accounting, so we also support total-subnet rate calculations as well.The rate calculations are an improved version of what is in
ip_conntrack_rate.c, namely we can handle the timer wraps around zero.
How do you want me to handle this? The account patch is no longer in pom, the extension is still part of iptables. Do you want me to apply the iptables part or do you simply want to add it as an iptables.patch to the account repository?
Quoted 14 lines · Patrick McHardy
Quoted 12 lines · Amin Azez
Here are some patches I did for
ipt_accountbeforeipt_ACCOUNTwhich supports larger subnets was re-released.As well as per-ip packet and byte counting, the patches also does per-ip rate calculating, so you can use this as part of a rate limiting rule and drop packets that would exceed the rate.
You get to choose whether or not dropped packets should also be accounted.
Just as
ipt_accountsupports total-subnet accounting, so we also support total-subnet rate calculations as well.
Quoted 6 lines
Quoted 3 lines
The rate calculations are an improved version of what is in
ip_conntrack_rate.c, namely we can handle the timer wraps around zero.How do you want me to handle this? The account patch is no longer in pom, the extension is still part of iptables.
oh. Was there a strong reason for it being dropped? I see that most of the patchlets have gone from:
http://svn.netfilter.org/cgi-bin/viewcvs.cgi/trunk/patch-o-matic-ng/patchlets/
including the newer ipt_ACCOUNT
Quoted 4 lines
Do you want me to apply
the iptables part or do you simply want to add it as an iptables.patch to the account repository?
It won't make sense to do either until I can work out where the kernel side bit needs stashing.
Did I miss something about pom-ng cleanup?
Sam