Re: feature of `packet per second`

2014-05-17 Thread bycn82

On 4/30/14 23:45, Freddie Cash wrote:
On Wed, Apr 30, 2014 at 8:31 AM, bycn82 byc...@gmail.com 
mailto:byc...@gmail.comwrote:


On 4/30/14 23:01, Julian Elischer wrote:

On 4/30/14, 8:52 PM, bycn82 wrote:

Hi

`packet per second` it is easy to be implemented using
iptables, there is a module named `recent`, but in using
ipfw, Do we have any solution to fulfill it? check the
link below

https://forums.freebsd.org/viewtopic.php?f=44t=42933p=258441#p258441

https://forums.freebsd.org/viewtopic.php?f=44t=42933p=258441#p258441


since I don't use linux.. what is packet per second?.. does
it report it or set a limit on it?


 bycn82

___
freebsd-ipfw@freebsd.org mailto:freebsd-ipfw@freebsd.org
mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-ipfw
To unsubscribe, send any mail to
freebsd-ipfw-unsubscr...@freebsd.org
mailto:freebsd-ipfw-unsubscr...@freebsd.org




Yes, Packets Per Secondmeans limit a connection based on the
packets number, for example, If I allow 2 ICMP packets come to my
server in each individual second.  only the first 2 packets will
be allow, all others in the same second will be dropped.


​For ICMP, specifically, there's a sysctl to control the rate (per 
second):


# sysctl -d ​net.inet.icmp.icmplim
net.inet.icmp.icmplim: Maximum number of ICMP responses per second


For everything else, you'd want to use dummynet(4).

--
Freddie Cash
fjwc...@gmail.com mailto:fjwc...@gmail.com


Hi
As Freddie said, for ICMP protocal, actually it comes with this 'PPS' 
feature.


So I just double checked the source code of ip_icmp.c file because I 
dont know this before.

And suddenly a question came into my mind. Why I dont know it before
Yes, I can list down all the sysctl option by `sysctl -a` command, But 
we dont have any page which introduced all the options,


root@FB10Head:~ # sysctl -a | grep rexmit_min
net.inet.tcp.rexmit_min: 30
root@FB10Head:~ # sysctl -a | grep icmplim
net.inet.icmp.icmplim: 200
net.inet.icmp.icmplim_output: 1
root@FB10Head:~ # sysctl -a | wc -l
4120
root@FB10Head:~ #

So, more than 4000 options!!! Maybe we should have mail-list to collect 
the introduction of all the options or a public WiKi page like wikipedia 
for it.


Regards,
bycn82

___
freebsd-ipfw@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-ipfw
To unsubscribe, send any mail to freebsd-ipfw-unsubscr...@freebsd.org

Re: feature of `packet per second`

2014-05-12 Thread bycn82

On 5/9/14 0:11, bycn82 wrote:

On 5/8/14 15:38, Luigi Rizzo wrote:

On Thu, May 08, 2014 at 09:09:21AM +0800, bycn82 wrote:

On 5/8/14 8:35, bycn82 wrote:

On 5/4/14 1:19, Luigi Rizzo wrote:


On Sat, May 3, 2014 at 2:27 PM, bycn82byc...@gmail.com
mailto:byc...@gmail.com  wrote:

 On 5/2/14 16:59, Luigi Rizzo wrote:


 On Wed, Apr 30, 2014 at 6:02 PM, bycn82byc...@gmail.com
 mailto:byc...@gmail.com  wrote:


 fjwc...@gmail.com  mailto:fjwc...@gmail.com
 mailto:fjwc...@gmail.com  mailto:fjwc...@gmail.com

 Thanks for your reply,  and it is good to know the sysctl
 for ICMP.

 finally it works.I just added a new `action` in firewall and
 it is called `pps`,  that means it can be generic purpose
 while the net.inet.icmp.icmplim is only for ICMP traffic.

 the usage will be like below

 root@F10:/usr/src/sbin/ipfw # .*/ipfw add pps 1 icmp from
 any to any*
 00100 pps 1 icmp from any to any
 root@F10:/usr/src/sbin/ipfw # ./ipfw show
 00100 9 540 pps 1 icmp from any to any
 65535 13319 1958894 allow ip from any to any
 root@F10:/usr/src/sbin/ipfw #


 ???hi,
 as julian said it would be great if you would like to share your
 code
 so we can integrate it in future ipfw releases.
 Once again citing Julian, dummynet is a bit of a superset of pps but
 not exactly, so i see value in the additional feature.

 One thing  ???to keep in mind in the implementation:

 the burst size used for limiting is an important parameter that
 everyone forgets. 1 pps is basically don't bother me.
 1000 pps could be 1000 packets every fixed 1-sec interval
 or 1 packet every ms or (this is more difficult)
 20 pkt in the last 50ms interval.

 If i were to implement the feature i would add two parameters
 (burst, I_max) with reasonable defaults and compute the internal
 interval and max_count as follows
if (burst  max_pps * I_max)
burst = max_pps * I_max; // make sure it is not too large
else if (burst  max_pps / HZ)
burst = max_pps * HZ;// nor too small
max_count = max_pps / burst;
interval = HZ * burst / max_pps;
count = 0; // actual counter

 then add { max_count, interval, timestamp, count } to the rule
 descriptor.
 On incoming packets:

if (ticks= r-interval + r-timestamp) {
r-timestamp = r-ticks;
r-count = 1;
return ACCEPT;
}
if (r-count  r-max_count)
return DENY;
r-count++;
return ACCEPT;

 cheers
 luigi


 Hi Luigi,
 You are right, it will be more generic if provide two parameters
 as you described,
 But this PPS feature should not be used to control the traffic
 rate, the dummynet you provided is the correct way.
 So I am thinking in what kind of scenario, people need this PPS
 feature?
 in my opinion, people will use PPS only when they want to limit
 the connections/transactions numbers. ( already have limit
 command to limit the connections)
 So I think provide a simple PPS feature is good enough, and we
 can improve it if someone complaint on this.


???pps has a strong reason to exist because it is a lot cheaper
than a dummynet pipe, and given its pur???pose is to police
traffic (icmp, dns requests, etc) which should not even
get close to the limit which is set, I think it is
a completely reasonable feature to have.

Given that the above code is the complete implementation
with the two parameters (burst and interval) there is no
reason not to use them, at least internally.

Then you could choose not to expose them as part of the
user interface (though since you are implementing a new
option from scratch, it is completely trivial to
parse 1, 2 or 3 arguments and set defaults for the others).

cheers
luigi

OK, PPS with 2 parameters , it is done,
But how to get the current time in millisecond?
any recommendation?

In order to get the millisecond, i tried to include the timeb.h but i
met below

FreeBSD has a global kernel variable called ticks which increments
(roughly) HZ times per second and is all you need for this
kind of coarse estimates.
In linux there is something similar (jiffies maybe ?),
and the code to build ipfw on linux does some reasonable
mapping.

The code i posted is, i believe,  complete and contains
all the details.

cheers
luigi


n file included from
/usr/src/sys/modules/ipfw/../../netpfil/ipfw/ip_fw2.c:42:
@/sys/timeb.h:42:2: error: this file includessys/timeb.h  which is
deprecated
[-Werror,-W#warnings]
#warning this file includessys/timeb.h  which is deprecated
   ^
any replacement for timeb.h


Man page patch for PPS

.It Cm pps Ar limit duration
Rule with the
.Cm pps
keyword will allow the first
.Ar limit
packets in each
.Ar duration
milliseconds.

and it will be like 

Re: feature of `packet per second`

2014-05-12 Thread Luigi Rizzo
On Mon, May 12, 2014 at 7:01 PM, bycn82 byc...@gmail.com wrote:
 On 5/9/14 0:11, bycn82 wrote:

...
 Done ,submitted.

 http://www.freebsd.org/cgi/query-pr.cgi?pr=kern/189721


can you clean up the formatting and style
(including some gratuitous whitespace changes).

Also there are several things to fix:
- please use { } even for blocks with a single statement
- please make count and duration 32 bit values. 16 bits are way
  too little for count, and there is no point to be stingy with count
- count should not be incremented upon a 'DENY' or it could wrap
  (very risky for 16-bit values);

cheers
luigi
___
freebsd-ipfw@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-ipfw
To unsubscribe, send any mail to freebsd-ipfw-unsubscr...@freebsd.org


Re: feature of `packet per second`

2014-05-08 Thread Luigi Rizzo
On Thu, May 08, 2014 at 09:09:21AM +0800, bycn82 wrote:
 On 5/8/14 8:35, bycn82 wrote:
  On 5/4/14 1:19, Luigi Rizzo wrote:
 
 
 
  On Sat, May 3, 2014 at 2:27 PM, bycn82 byc...@gmail.com 
  mailto:byc...@gmail.com wrote:
 
  On 5/2/14 16:59, Luigi Rizzo wrote:
 
 
 
  On Wed, Apr 30, 2014 at 6:02 PM, bycn82 byc...@gmail.com
  mailto:byc...@gmail.com wrote:
 
 
  fjwc...@gmail.com mailto:fjwc...@gmail.com
  mailto:fjwc...@gmail.com mailto:fjwc...@gmail.com
 
  Thanks for your reply,  and it is good to know the sysctl
  for ICMP.
 
  finally it works.I just added a new `action` in firewall and
  it is called `pps`,  that means it can be generic purpose
  while the net.inet.icmp.icmplim is only for ICMP traffic.
 
  the usage will be like below
 
  root@F10:/usr/src/sbin/ipfw # .*/ipfw add pps 1 icmp from
  any to any*
  00100 pps 1 icmp from any to any
  root@F10:/usr/src/sbin/ipfw # ./ipfw show
  00100 9 540 pps 1 icmp from any to any
  65535 13319 1958894 allow ip from any to any
  root@F10:/usr/src/sbin/ipfw #
 
 
  ???hi,
  as julian said it would be great if you would like to share your
  code
  so we can integrate it in future ipfw releases.
  Once again citing Julian, dummynet is a bit of a superset of pps but
  not exactly, so i see value in the additional feature.
 
  One thing  ???to keep in mind in the implementation:
 
  the burst size used for limiting is an important parameter that
  everyone forgets. 1 pps is basically don't bother me.
  1000 pps could be 1000 packets every fixed 1-sec interval
  or 1 packet every ms or (this is more difficult)
  20 pkt in the last 50ms interval.
 
  If i were to implement the feature i would add two parameters
  (burst, I_max) with reasonable defaults and compute the internal
  interval and max_count as follows
 if (burst  max_pps * I_max)
 burst = max_pps * I_max; // make sure it is not too large
 else if (burst  max_pps / HZ)
 burst = max_pps * HZ;// nor too small
 max_count = max_pps / burst;
 interval = HZ * burst / max_pps;
 count = 0; // actual counter
 
  then add { max_count, interval, timestamp, count } to the rule
  descriptor.
  On incoming packets:
 
 if (ticks = r-interval + r-timestamp) {
 r-timestamp = r-ticks;
 r-count = 1;
 return ACCEPT;
 }
 if (r-count  r-max_count)
 return DENY;
 r-count++;
 return ACCEPT;
 
  cheers
  luigi
 
  Hi Luigi,
  You are right, it will be more generic if provide two parameters
  as you described,
  But this PPS feature should not be used to control the traffic
  rate, the dummynet you provided is the correct way.
  So I am thinking in what kind of scenario, people need this PPS
  feature?
  in my opinion, people will use PPS only when they want to limit
  the connections/transactions numbers. ( already have limit
  command to limit the connections)
  So I think provide a simple PPS feature is good enough, and we
  can improve it if someone complaint on this.
 
 
  ???pps has a strong reason to exist because it is a lot cheaper
  than a dummynet pipe, and given its pur???pose is to police
  traffic (icmp, dns requests, etc) which should not even
  get close to the limit which is set, I think it is
  a completely reasonable feature to have.
 
  Given that the above code is the complete implementation
  with the two parameters (burst and interval) there is no
  reason not to use them, at least internally.
 
  Then you could choose not to expose them as part of the
  user interface (though since you are implementing a new
  option from scratch, it is completely trivial to
  parse 1, 2 or 3 arguments and set defaults for the others).
 
  cheers
  luigi
  OK, PPS with 2 parameters , it is done,
  But how to get the current time in millisecond?
  any recommendation?
 In order to get the millisecond, i tried to include the timeb.h but i 
 met below

FreeBSD has a global kernel variable called ticks which increments
(roughly) HZ times per second and is all you need for this
kind of coarse estimates.
In linux there is something similar (jiffies maybe ?),
and the code to build ipfw on linux does some reasonable
mapping.

The code i posted is, i believe,  complete and contains
all the details.

cheers
luigi

 
 n file included from 
 /usr/src/sys/modules/ipfw/../../netpfil/ipfw/ip_fw2.c:42:
 @/sys/timeb.h:42:2: error: this file includes sys/timeb.h which is 
 deprecated
[-Werror,-W#warnings]
 #warning this file includes sys/timeb.h which is deprecated
   ^
 any replacement for timeb.h
___
freebsd-ipfw@freebsd.org mailing list

Re: feature of `packet per second`

2014-05-08 Thread bycn82

On 5/8/14 15:38, Luigi Rizzo wrote:

On Thu, May 08, 2014 at 09:09:21AM +0800, bycn82 wrote:

On 5/8/14 8:35, bycn82 wrote:

On 5/4/14 1:19, Luigi Rizzo wrote:



On Sat, May 3, 2014 at 2:27 PM, bycn82byc...@gmail.com
mailto:byc...@gmail.com  wrote:

 On 5/2/14 16:59, Luigi Rizzo wrote:



 On Wed, Apr 30, 2014 at 6:02 PM, bycn82byc...@gmail.com
 mailto:byc...@gmail.com  wrote:


 fjwc...@gmail.commailto:fjwc...@gmail.com
 mailto:fjwc...@gmail.commailto:fjwc...@gmail.com

 Thanks for your reply,  and it is good to know the sysctl
 for ICMP.

 finally it works.I just added a new `action` in firewall and
 it is called `pps`,  that means it can be generic purpose
 while the net.inet.icmp.icmplim is only for ICMP traffic.

 the usage will be like below

 root@F10:/usr/src/sbin/ipfw # .*/ipfw add pps 1 icmp from
 any to any*
 00100 pps 1 icmp from any to any
 root@F10:/usr/src/sbin/ipfw # ./ipfw show
 00100 9 540 pps 1 icmp from any to any
 65535 13319 1958894 allow ip from any to any
 root@F10:/usr/src/sbin/ipfw #


 ???hi,
 as julian said it would be great if you would like to share your
 code
 so we can integrate it in future ipfw releases.
 Once again citing Julian, dummynet is a bit of a superset of pps but
 not exactly, so i see value in the additional feature.

 One thing  ???to keep in mind in the implementation:

 the burst size used for limiting is an important parameter that
 everyone forgets. 1 pps is basically don't bother me.
 1000 pps could be 1000 packets every fixed 1-sec interval
 or 1 packet every ms or (this is more difficult)
 20 pkt in the last 50ms interval.

 If i were to implement the feature i would add two parameters
 (burst, I_max) with reasonable defaults and compute the internal
 interval and max_count as follows
if (burst  max_pps * I_max)
burst = max_pps * I_max; // make sure it is not too large
else if (burst  max_pps / HZ)
burst = max_pps * HZ;// nor too small
max_count = max_pps / burst;
interval = HZ * burst / max_pps;
count = 0; // actual counter

 then add { max_count, interval, timestamp, count } to the rule
 descriptor.
 On incoming packets:

if (ticks= r-interval + r-timestamp) {
r-timestamp = r-ticks;
r-count = 1;
return ACCEPT;
}
if (r-count  r-max_count)
return DENY;
r-count++;
return ACCEPT;

 cheers
 luigi


 Hi Luigi,
 You are right, it will be more generic if provide two parameters
 as you described,
 But this PPS feature should not be used to control the traffic
 rate, the dummynet you provided is the correct way.
 So I am thinking in what kind of scenario, people need this PPS
 feature?
 in my opinion, people will use PPS only when they want to limit
 the connections/transactions numbers. ( already have limit
 command to limit the connections)
 So I think provide a simple PPS feature is good enough, and we
 can improve it if someone complaint on this.


???pps has a strong reason to exist because it is a lot cheaper
than a dummynet pipe, and given its pur???pose is to police
traffic (icmp, dns requests, etc) which should not even
get close to the limit which is set, I think it is
a completely reasonable feature to have.

Given that the above code is the complete implementation
with the two parameters (burst and interval) there is no
reason not to use them, at least internally.

Then you could choose not to expose them as part of the
user interface (though since you are implementing a new
option from scratch, it is completely trivial to
parse 1, 2 or 3 arguments and set defaults for the others).

cheers
luigi

OK, PPS with 2 parameters , it is done,
But how to get the current time in millisecond?
any recommendation?

In order to get the millisecond, i tried to include the timeb.h but i
met below

FreeBSD has a global kernel variable called ticks which increments
(roughly) HZ times per second and is all you need for this
kind of coarse estimates.
In linux there is something similar (jiffies maybe ?),
and the code to build ipfw on linux does some reasonable
mapping.

The code i posted is, i believe,  complete and contains
all the details.

cheers
luigi


n file included from
/usr/src/sys/modules/ipfw/../../netpfil/ipfw/ip_fw2.c:42:
@/sys/timeb.h:42:2: error: this file includessys/timeb.h  which is
deprecated
[-Werror,-W#warnings]
#warning this file includessys/timeb.h  which is deprecated
   ^
any replacement for timeb.h


Man page patch for PPS

.It Cm pps Ar limit duration
Rule with the
.Cm pps
keyword will allow the first
.Ar limit
packets in each
.Ar duration
milliseconds.

and it will be like blow
 pps _limit  duration_
   

Re: feature of `packet per second`

2014-05-08 Thread Luigi Rizzo
On Fri, May 09, 2014 at 12:11:16AM +0800, bycn82 wrote:
 On 5/8/14 15:38, Luigi Rizzo wrote:
...
   If i were to implement the feature i would add two parameters
   (burst, I_max) with reasonable defaults and compute the internal
   interval and max_count as follows
  if (burst  max_pps * I_max)
  burst = max_pps * I_max; // make sure it is not too large
  else if (burst  max_pps / HZ)
  burst = max_pps * HZ;// nor too small
  max_count = max_pps / burst;
  interval = HZ * burst / max_pps;
  count = 0; // actual counter
 
   then add { max_count, interval, timestamp, count } to the rule
   descriptor.
   On incoming packets:
 
  if (ticks= r-interval + r-timestamp) {
  r-timestamp = r-ticks;
  r-count = 1;
  return ACCEPT;
  }
  if (r-count  r-max_count)
  return DENY;
  r-count++;
  return ACCEPT;
 
   cheers
   luigi
 
   Hi Luigi,
   You are right, it will be more generic if provide two parameters
   as you described,
   But this PPS feature should not be used to control the traffic
   rate, the dummynet you provided is the correct way.
   So I am thinking in what kind of scenario, people need this PPS
   feature?
   in my opinion, people will use PPS only when they want to limit
   the connections/transactions numbers. ( already have limit
   command to limit the connections)
   So I think provide a simple PPS feature is good enough, and we
   can improve it if someone complaint on this.
...
 Man page patch for PPS
 
 .It Cm pps Ar limit duration
 Rule with the
 .Cm pps
 keyword will allow the first
 .Ar limit
 packets in each
 .Ar duration
 milliseconds.
 
 and it will be like blow
   pps _limit  duration_
   Rule with the pps keyword will allow the first _limit 
 _packets in
   each _duration _milliseconds.
 
 is that OK?

looks good to me.
Just remember that the value of HZ may be quite low (e.g. HZ=100
or less in some cases) so internally the code should round up
the intervals as needed.

cheers
luigi
___
freebsd-ipfw@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-ipfw
To unsubscribe, send any mail to freebsd-ipfw-unsubscr...@freebsd.org


Re: feature of `packet per second`

2014-05-08 Thread Chris H
 On 5/8/14 15:38, Luigi Rizzo wrote:
 On Thu, May 08, 2014 at 09:09:21AM +0800, bycn82 wrote:
 On 5/8/14 8:35, bycn82 wrote:
 On 5/4/14 1:19, Luigi Rizzo wrote:


 On Sat, May 3, 2014 at 2:27 PM, bycn82byc...@gmail.com
 mailto:byc...@gmail.com  wrote:

  On 5/2/14 16:59, Luigi Rizzo wrote:


  On Wed, Apr 30, 2014 at 6:02 PM, bycn82byc...@gmail.com
  mailto:byc...@gmail.com  wrote:


  fjwc...@gmail.commailto:fjwc...@gmail.com
  mailto:fjwc...@gmail.commailto:fjwc...@gmail.com

  Thanks for your reply,  and it is good to know the sysctl
  for ICMP.

  finally it works.I just added a new `action` in firewall and
  it is called `pps`,  that means it can be generic purpose
  while the net.inet.icmp.icmplim is only for ICMP traffic.

  the usage will be like below

  root@F10:/usr/src/sbin/ipfw # .*/ipfw add pps 1 icmp from
  any to any*
  00100 pps 1 icmp from any to any
  root@F10:/usr/src/sbin/ipfw # ./ipfw show
  00100 9 540 pps 1 icmp from any to any
  65535 13319 1958894 allow ip from any to any
  root@F10:/usr/src/sbin/ipfw #


  ???hi,
  as julian said it would be great if you would like to share your
  code
  so we can integrate it in future ipfw releases.
  Once again citing Julian, dummynet is a bit of a superset of pps but
  not exactly, so i see value in the additional feature.

  One thing  ???to keep in mind in the implementation:

  the burst size used for limiting is an important parameter that
  everyone forgets. 1 pps is basically don't bother me.
  1000 pps could be 1000 packets every fixed 1-sec interval
  or 1 packet every ms or (this is more difficult)
  20 pkt in the last 50ms interval.

  If i were to implement the feature i would add two parameters
  (burst, I_max) with reasonable defaults and compute the internal
  interval and max_count as follows
 if (burst  max_pps * I_max)
 burst = max_pps * I_max; // make sure it is not too large
 else if (burst  max_pps / HZ)
 burst = max_pps * HZ;// nor too small
 max_count = max_pps / burst;
 interval = HZ * burst / max_pps;
 count = 0; // actual counter

  then add { max_count, interval, timestamp, count } to the rule
  descriptor.
  On incoming packets:

 if (ticks= r-interval + r-timestamp) {
 r-timestamp = r-ticks;
 r-count = 1;
 return ACCEPT;
 }
 if (r-count  r-max_count)
 return DENY;
 r-count++;
 return ACCEPT;

  cheers
  luigi

  Hi Luigi,
  You are right, it will be more generic if provide two parameters
  as you described,
  But this PPS feature should not be used to control the traffic
  rate, the dummynet you provided is the correct way.
  So I am thinking in what kind of scenario, people need this PPS
  feature?
  in my opinion, people will use PPS only when they want to limit
  the connections/transactions numbers. ( already have limit
  command to limit the connections)
  So I think provide a simple PPS feature is good enough, and we
  can improve it if someone complaint on this.


 ???pps has a strong reason to exist because it is a lot cheaper
 than a dummynet pipe, and given its pur???pose is to police
 traffic (icmp, dns requests, etc) which should not even
 get close to the limit which is set, I think it is
 a completely reasonable feature to have.

 Given that the above code is the complete implementation
 with the two parameters (burst and interval) there is no
 reason not to use them, at least internally.

 Then you could choose not to expose them as part of the
 user interface (though since you are implementing a new
 option from scratch, it is completely trivial to
 parse 1, 2 or 3 arguments and set defaults for the others).

 cheers
 luigi
 OK, PPS with 2 parameters , it is done,
 But how to get the current time in millisecond?
 any recommendation?
 In order to get the millisecond, i tried to include the timeb.h but i
 met below
 FreeBSD has a global kernel variable called ticks which increments
 (roughly) HZ times per second and is all you need for this
 kind of coarse estimates.
 In linux there is something similar (jiffies maybe ?),
 and the code to build ipfw on linux does some reasonable
 mapping.

 The code i posted is, i believe,  complete and contains
 all the details.

 cheers
 luigi

 n file included from
 /usr/src/sys/modules/ipfw/../../netpfil/ipfw/ip_fw2.c:42:
 @/sys/timeb.h:42:2: error: this file includessys/timeb.h  which is
 deprecated
 [-Werror,-W#warnings]
 #warning this file includessys/timeb.h  which is deprecated
^
 any replacement for timeb.h

 Man page patch for PPS

 .It Cm pps Ar limit duration
 Rule with the
 .Cm pps
 keyword will allow the first
 .Ar 

Re: feature of `packet per second`

2014-05-07 Thread bycn82

On 5/4/14 1:19, Luigi Rizzo wrote:




On Sat, May 3, 2014 at 2:27 PM, bycn82 byc...@gmail.com 
mailto:byc...@gmail.com wrote:


On 5/2/14 16:59, Luigi Rizzo wrote:




On Wed, Apr 30, 2014 at 6:02 PM, bycn82 byc...@gmail.com
mailto:byc...@gmail.com wrote:


fjwc...@gmail.com mailto:fjwc...@gmail.com
mailto:fjwc...@gmail.com mailto:fjwc...@gmail.com

Thanks for your reply,  and it is good to know the sysctl for
ICMP.

finally it works.I just added a new `action` in firewall and
it is called `pps`,  that means it can be generic purpose
while the net.inet.icmp.icmplim is only for ICMP traffic.

the usage will be like below

root@F10:/usr/src/sbin/ipfw # .*/ipfw add pps 1 icmp from any
to any*
00100 pps 1 icmp from any to any
root@F10:/usr/src/sbin/ipfw # ./ipfw show
00100 9 540 pps 1 icmp from any to any
65535 13319 1958894 allow ip from any to any
root@F10:/usr/src/sbin/ipfw #


​hi,
as julian said it would be great if you would like to share your code
so we can integrate it in future ipfw releases.
Once again citing Julian, dummynet is a bit of a superset of pps but
not exactly, so i see value in the additional feature.

One thing  ​to keep in mind in the implementation:

the burst size used for limiting is an important parameter that
everyone forgets. 1 pps is basically don't bother me.
1000 pps could be 1000 packets every fixed 1-sec interval
or 1 packet every ms or (this is more difficult)
20 pkt in the last 50ms interval.

If i were to implement the feature i would add two parameters
(burst, I_max) with reasonable defaults and compute the internal
interval and max_count as follows
   if (burst  max_pps * I_max)
   burst = max_pps * I_max; // make sure it is not too large
   else if (burst  max_pps / HZ)
   burst = max_pps * HZ;// nor too small
   max_count = max_pps / burst;
   interval = HZ * burst / max_pps;
   count = 0; // actual counter

then add { max_count, interval, timestamp, count } to the rule
descriptor.
On incoming packets:

   if (ticks = r-interval + r-timestamp) {
   r-timestamp = r-ticks;
   r-count = 1;
   return ACCEPT;
   }
   if (r-count  r-max_count)
   return DENY;
   r-count++;
   return ACCEPT;

cheers
luigi


Hi Luigi,
You are right, it will be more generic if provide two parameters
as you described,
But this PPS feature should not be used to control the traffic
rate, the dummynet you provided is the correct way.
So I am thinking in what kind of scenario, people need this PPS
feature?
in my opinion, people will use PPS only when they want to limit
the connections/transactions numbers. ( already have limit command
to limit the connections)
So I think provide a simple PPS feature is good enough, and we can
improve it if someone complaint on this.


​pps has a strong reason to exist because it is a lot cheaper
than a dummynet pipe, and given its pur​pose is to police
traffic (icmp, dns requests, etc) which should not even
get close to the limit which is set, I think it is
a completely reasonable feature to have.

Given that the above code is the complete implementation
with the two parameters (burst and interval) there is no
reason not to use them, at least internally.

Then you could choose not to expose them as part of the
user interface (though since you are implementing a new
option from scratch, it is completely trivial to
parse 1, 2 or 3 arguments and set defaults for the others).

cheers
luigi

OK, PPS with 2 parameters , it is done,
But how to get the current time in millisecond?
any recommendation?
___
freebsd-ipfw@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-ipfw
To unsubscribe, send any mail to freebsd-ipfw-unsubscr...@freebsd.org

Re: feature of `packet per second`

2014-05-02 Thread Bill Yuan
I was coding it in dummynet way yesterday,
Personally I prefer to add it as a new action.
By the way, Is there anybody want to say something about the ip_fw.h? there
are two ip_fw.h files,
one in /sys/netinet/ another in usr/include/netinet, it is better to remove
one of it , or create a soft link instread?


On Fri, May 2, 2014 at 1:55 PM, Julian Elischer jul...@freebsd.org wrote:

 On 5/1/14, 12:02 AM, bycn82 wrote:

 On 4/30/14 23:45, Freddie Cash wrote:

 On Wed, Apr 30, 2014 at 8:31 AM, bycn82 byc...@gmail.com mailto:
 byc...@gmail.comwrote:


 On 4/30/14 23:01, Julian Elischer wrote:

 On 4/30/14, 8:52 PM, bycn82 wrote:

 Hi

 `packet per second` it is easy to be implemented using
 iptables, there is a module named `recent`, but in using
 ipfw, Do we have any solution to fulfill it? check the
 link below
 https://forums.freebsd.org/viewtopic.php?f=44t=42933p=258441#p258441
 https://forums.freebsd.org/viewtopic.php?f=44t=42933p=258441#p258441


 since I don't use linux.. what is packet per second?.. does
 it report it or set a limit on it?


  bycn82

 ___
 freebsd-ipfw@freebsd.org mailto:freebsd-ipfw@freebsd.org

 mailing list
 http://lists.freebsd.org/mailman/listinfo/freebsd-ipfw
 To unsubscribe, send any mail to
 freebsd-ipfw-unsubscr...@freebsd.org
 mailto:freebsd-ipfw-unsubscr...@freebsd.org





 Yes, Packets Per Secondmeans limit a connection based on the
 packets number, for example, If I allow 2 ICMP packets come to my
 server in each individual second.  only the first 2 packets will
 be allow, all others in the same second will be dropped.


 ​For ICMP, specifically, there's a sysctl to control the rate (per
 second):

 # sysctl -d ​net.inet.icmp.icmplim
 net.inet.icmp.icmplim: Maximum number of ICMP responses per second


 For everything else, you'd want to use dummynet(4).

 --
 Freddie Cash
 fjwc...@gmail.com mailto:fjwc...@gmail.com

 Thanks for your reply,  and it is good to know the sysctl for ICMP.

 finally it works.I just added a new `action` in firewall and it is called
 `pps`,  that means it can be generic purpose while the
 net.inet.icmp.icmplim is only for ICMP traffic.


 you probably should be using the dummynet extension to ipfw to do this
 but post your changes to a freebsd bug report anyhow so we can keep it
 somewhere.
 I doubt it would be needed in general as Dummynet give you so much more
 control and is I think a superset.
 Don't forget to add a patch for the man page  a patch with no man page
 change would never be accepted.


 the usage will be like below

 root@F10:/usr/src/sbin/ipfw # .*/ipfw add pps 1 icmp from any to any*

 00100 pps 1 icmp from any to any
 root@F10:/usr/src/sbin/ipfw # ./ipfw show
 00100 9 540 pps 1 icmp from any to any
 65535 13319 1958894 allow ip from any to any
 root@F10:/usr/src/sbin/ipfw #

 regards,
 bycn82

 ___
 freebsd-ipfw@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/freebsd-ipfw
 To unsubscribe, send any mail to freebsd-ipfw-unsubscr...@freebsd.org





___
freebsd-ipfw@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-ipfw
To unsubscribe, send any mail to freebsd-ipfw-unsubscr...@freebsd.org

Re: feature of `packet per second`

2014-05-02 Thread Luigi Rizzo
On Wed, Apr 30, 2014 at 6:02 PM, bycn82 byc...@gmail.com wrote:


 fjwc...@gmail.com mailto:fjwc...@gmail.com

 Thanks for your reply,  and it is good to know the sysctl for ICMP.

 finally it works.I just added a new `action` in firewall and it is called
 `pps`,  that means it can be generic purpose while the
 net.inet.icmp.icmplim is only for ICMP traffic.

 the usage will be like below

 root@F10:/usr/src/sbin/ipfw # .*/ipfw add pps 1 icmp from any to any*
 00100 pps 1 icmp from any to any
 root@F10:/usr/src/sbin/ipfw # ./ipfw show
 00100 9 540 pps 1 icmp from any to any
 65535 13319 1958894 allow ip from any to any
 root@F10:/usr/src/sbin/ipfw #


​hi,
as julian said it would be great if you would like to share your code
so we can integrate it in future ipfw releases.
Once again citing Julian, dummynet is a bit of a superset of pps but
not exactly, so i see value in the additional feature.

One thing  ​to keep in mind in the implementation:

the burst size used for limiting is an important parameter that
everyone forgets. 1 pps is basically don't bother me.
1000 pps could be 1000 packets every fixed 1-sec interval
or 1 packet every ms or (this is more difficult)
20 pkt in the last 50ms interval.

If i were to implement the feature i would add two parameters
(burst, I_max) with reasonable defaults and compute the internal
interval and max_count as follows

   if (burst  max_pps * I_max)
   burst = max_pps * I_max; // make sure it is not too large
   else if (burst  max_pps / HZ)
   burst = max_pps * HZ;// nor too small
   max_count = max_pps / burst;
   interval = HZ * burst / max_pps;
   count = 0; // actual counter

then add { max_count, interval, timestamp, count } to the rule descriptor.
On incoming packets:

   if (ticks = r-interval + r-timestamp) {
   r-timestamp = r-ticks;
   r-count = 1;
   return ACCEPT;
   }
   if (r-count  r-max_count)
   return DENY;
   r-count++;
   return ACCEPT;

cheers
luigi
___
freebsd-ipfw@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-ipfw
To unsubscribe, send any mail to freebsd-ipfw-unsubscr...@freebsd.org

feature of `packet per second`

2014-04-30 Thread bycn82

Hi

`packet per second` it is easy to be implemented using iptables, there 
is a module named `recent`, but in using ipfw, Do we have any solution 
to fulfill it? check the link below

https://forums.freebsd.org/viewtopic.php?f=44t=42933p=258441#p258441

 bycn82

___
freebsd-ipfw@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-ipfw
To unsubscribe, send any mail to freebsd-ipfw-unsubscr...@freebsd.org


Re: feature of `packet per second`

2014-04-30 Thread Julian Elischer

On 4/30/14, 8:52 PM, bycn82 wrote:

Hi

`packet per second` it is easy to be implemented using iptables, 
there is a module named `recent`, but in using ipfw, Do we have any 
solution to fulfill it? check the link below

https://forums.freebsd.org/viewtopic.php?f=44t=42933p=258441#p258441


since I don't use linux.. what is packet per second?.. does it 
report it or set a limit on it?


 bycn82

___
freebsd-ipfw@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-ipfw
To unsubscribe, send any mail to freebsd-ipfw-unsubscr...@freebsd.org




___
freebsd-ipfw@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-ipfw
To unsubscribe, send any mail to freebsd-ipfw-unsubscr...@freebsd.org


Re: feature of `packet per second`

2014-04-30 Thread bycn82

On 4/30/14 23:01, Julian Elischer wrote:

On 4/30/14, 8:52 PM, bycn82 wrote:

Hi

`packet per second` it is easy to be implemented using iptables, 
there is a module named `recent`, but in using ipfw, Do we have any 
solution to fulfill it? check the link below

https://forums.freebsd.org/viewtopic.php?f=44t=42933p=258441#p258441


since I don't use linux.. what is packet per second?.. does it 
report it or set a limit on it?


 bycn82

___
freebsd-ipfw@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-ipfw
To unsubscribe, send any mail to freebsd-ipfw-unsubscr...@freebsd.org





Yes, Packets Per Secondmeans limit a connection based on the packets 
number, for example, If I allow 2 ICMP packets come to my server in each 
individual second.  only the first 2 packets will be allow, all others 
in the same second will be dropped.


___
freebsd-ipfw@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-ipfw
To unsubscribe, send any mail to freebsd-ipfw-unsubscr...@freebsd.org


Re: feature of `packet per second`

2014-04-30 Thread Freddie Cash
On Wed, Apr 30, 2014 at 8:31 AM, bycn82 byc...@gmail.com wrote:

 On 4/30/14 23:01, Julian Elischer wrote:

 On 4/30/14, 8:52 PM, bycn82 wrote:

 Hi

 `packet per second` it is easy to be implemented using iptables, there
 is a module named `recent`, but in using ipfw, Do we have any solution to
 fulfill it? check the link below
 https://forums.freebsd.org/viewtopic.php?f=44t=42933p=258441#p258441


 since I don't use linux.. what is packet per second?.. does it report
 it or set a limit on it?


  bycn82

 ___
 freebsd-ipfw@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/freebsd-ipfw
 To unsubscribe, send any mail to freebsd-ipfw-unsubscr...@freebsd.org




  Yes, Packets Per Secondmeans limit a connection based on the packets
 number, for example, If I allow 2 ICMP packets come to my server in each
 individual second.  only the first 2 packets will be allow, all others in
 the same second will be dropped.


​For ICMP, specifically, there's a sysctl to control the rate (per second):

# sysctl -d ​net.inet.icmp.icmplim
net.inet.icmp.icmplim: Maximum number of ICMP responses per second


For everything else, you'd want to use dummynet(4).

-- 
Freddie Cash
fjwc...@gmail.com
___
freebsd-ipfw@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-ipfw
To unsubscribe, send any mail to freebsd-ipfw-unsubscr...@freebsd.org

Re: feature of `packet per second`

2014-04-30 Thread bycn82

On 4/30/14 23:45, Freddie Cash wrote:
On Wed, Apr 30, 2014 at 8:31 AM, bycn82 byc...@gmail.com 
mailto:byc...@gmail.comwrote:


On 4/30/14 23:01, Julian Elischer wrote:

On 4/30/14, 8:52 PM, bycn82 wrote:

Hi

`packet per second` it is easy to be implemented using
iptables, there is a module named `recent`, but in using
ipfw, Do we have any solution to fulfill it? check the
link below

https://forums.freebsd.org/viewtopic.php?f=44t=42933p=258441#p258441

https://forums.freebsd.org/viewtopic.php?f=44t=42933p=258441#p258441


since I don't use linux.. what is packet per second?.. does
it report it or set a limit on it?


 bycn82

___
freebsd-ipfw@freebsd.org mailto:freebsd-ipfw@freebsd.org
mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-ipfw
To unsubscribe, send any mail to
freebsd-ipfw-unsubscr...@freebsd.org
mailto:freebsd-ipfw-unsubscr...@freebsd.org




Yes, Packets Per Secondmeans limit a connection based on the
packets number, for example, If I allow 2 ICMP packets come to my
server in each individual second.  only the first 2 packets will
be allow, all others in the same second will be dropped.


​For ICMP, specifically, there's a sysctl to control the rate (per 
second):


# sysctl -d ​net.inet.icmp.icmplim
net.inet.icmp.icmplim: Maximum number of ICMP responses per second


For everything else, you'd want to use dummynet(4).

--
Freddie Cash
fjwc...@gmail.com mailto:fjwc...@gmail.com

Thanks for your reply,  and it is good to know the sysctl for ICMP.

finally it works.I just added a new `action` in firewall and it is 
called `pps`,  that means it can be generic purpose while the 
net.inet.icmp.icmplim is only for ICMP traffic.


the usage will be like below

root@F10:/usr/src/sbin/ipfw # .*/ipfw add pps 1 icmp from any to any*
00100 pps 1 icmp from any to any
root@F10:/usr/src/sbin/ipfw # ./ipfw show
00100 9 540 pps 1 icmp from any to any
65535 13319 1958894 allow ip from any to any
root@F10:/usr/src/sbin/ipfw #

regards,
bycn82

___
freebsd-ipfw@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-ipfw
To unsubscribe, send any mail to freebsd-ipfw-unsubscr...@freebsd.org