1.\" $OpenBSD: ppsratecheck.9,v 1.5 2013/06/04 19:27:11 schwarze 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.\" 19.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29.\" POSSIBILITY OF SUCH DAMAGE. 30.\" 31.Dd $Mdocdate: June 4 2013 $ 32.Dt PPSRATECHECK 9 33.Os 34.Sh NAME 35.Nm ppsratecheck 36.Nd function to help implement rate-limited actions 37.Sh SYNOPSIS 38.In sys/time.h 39.Ft int 40.Fn ppsratecheck "struct timeval *lasttime" "int *curpps" "int maxpps" 41.Sh DESCRIPTION 42The 43.Fn ppsratecheck 44function provides an easy way to perform packet-per-sec, 45or event-per-sec, rate limitation. 46The motivation for implementing 47.Fn ppsratecheck 48was to provide a mechanism that could be used to add rate limitation to 49network packet output. 50For certain network packets, we may want to impose rate limitation, 51to avoid denial-of-service attack possibilities. 52.Pp 53.Fa maxpps 54specifies maximum permitted packets, or events, per second. 55If 56.Fn ppsratecheck 57is called more than 58.Fa maxpps 59times in a given one second period, 60the function will return 0, indicating that we exceeded the limit. 61If we are below the limit, the function will return 1. 62If 63.Fa maxpps 64is set to 0, the function will always return 0 65.Pq no packets/events are permitted . 66Negative 67.Fa maxpps 68indicates that rate limitation is disabled, and 69.Fn ppsratecheck 70will always return 1. 71.Pp 72.Fa curpps 73and 74.Fa lasttime 75are used to maintain the number of recent calls. 76.Fa curpps 77will be incremented every time 78.Fn ppsratecheck 79is called, and will be reset whenever necessary. 80.Sh SEE ALSO 81.Xr log 9 , 82.Xr printf 9 , 83.Xr ratecheck 9 , 84.Xr time 9 85.Sh HISTORY 86The 87.Fn ppsratecheck 88function appeared in 89.Nx 1.5 . 90