xref: /openbsd-src/share/man/man9/ppsratecheck.9 (revision b2ea75c1b17e1a9a339660e7ed45cd24946b230e)
1.\"	$OpenBSD: ppsratecheck.9,v 1.1 2000/10/10 13:40:46 itojun Exp $
2.\"	$NetBSD: ppsratecheck.9,v 1.1 2000/08/03 00:09:39 itojun Exp $
3.\"
4.\" Copyright (c) 2000 The NetBSD Foundation, Inc.
5.\" All rights reserved.
6.\"
7.\" This code is derived from software contributed to The NetBSD Foundation
8.\" by Jun-ichiro itojun Hagino.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\"    notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\"    notice, this list of conditions and the following disclaimer in the
17.\"    documentation and/or other materials provided with the distribution.
18.\" 3. All advertising materials mentioning features or use of this software
19.\"    must display the following acknowledgement:
20.\"        This product includes software developed by the NetBSD
21.\"        Foundation, Inc. and its contributors.
22.\" 4. Neither the name of The NetBSD Foundation nor the names of its
23.\"    contributors may be used to endorse or promote products derived
24.\"    from this software without specific prior written permission.
25.\"
26.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36.\" POSSIBILITY OF SUCH DAMAGE.
37.\"
38.Dd August 3, 2000
39.Dt PPSRATECHECK 9
40.Os
41.Sh NAME
42.Nm ppsratecheck
43.Nd function to help implement rate-limited actions
44.Sh SYNOPSIS
45.Fd #include <sys/time.h>
46.Ft int
47.Fn ppsratecheck "struct timeval *lasttime" "int *curpps" "int maxpps"
48.Sh DESCRIPTION
49The
50.Fn ppsratecheck
51function provides easy way to perform packet-per-sec,
52or event-per-sec, rate limitation.
53The motivation for implementing
54.Fn ppsratecheck
55was to provide a mechanism that could be used to add rate limitation to
56network packet output.
57For certain network packets, we may want to impose rate limitation,
58to avoid denial-of-service attack possibilities.
59.Pp
60.Fa maxpps
61specifies maximum permitted packets, or events, per second.
62If
63.Fn ppsratecheck
64is called more than
65.Fa maxpps
66times in a given one second period,
67the function will return 0, indicating that we exceeded the limit.
68If we are below the limit, the function will return 1.
69If
70.Fa maxpps
71is set to 0, the function will always return 0
72.Pq no packets/events are permitted .
73Negative
74.Fa maxpps
75indicates that rate limitation is disabled, and
76.Fa ppsratecheck
77will always return 1.
78.Pp
79.Fa curpps
80and
81.Fa lasttime
82are used to maintain the number of recent calls.
83.Fa curpps
84will be incremented every time
85.Fn ppsratecheck
86is called, and will be reset whenever necessary.
87.Sh SEE ALSO
88.Xr log 9 ,
89.Xr printf 9 ,
90.Xr ratecheck 9 ,
91.Xr time 9
92.Sh HISTORY
93The
94.Fn ppsratecheck
95function appeared in
96.Nx 1.5 .
97