1*5b0945b5SGregory Neil Shapiro /* 2*5b0945b5SGregory Neil Shapiro * Copyright (c) 2003 Proofpoint, Inc. and its suppliers. 3*5b0945b5SGregory Neil Shapiro * All rights reserved. 4*5b0945b5SGregory Neil Shapiro * 5*5b0945b5SGregory Neil Shapiro * By using this file, you agree to the terms and conditions set 6*5b0945b5SGregory Neil Shapiro * forth in the LICENSE file which can be found at the top level of 7*5b0945b5SGregory Neil Shapiro * the sendmail distribution. 8*5b0945b5SGregory Neil Shapiro * 9*5b0945b5SGregory Neil Shapiro * Contributed by Jose Marcio Martins da Cruz - Ecole des Mines de Paris 10*5b0945b5SGregory Neil Shapiro * Jose-Marcio.Martins@ensmp.fr 11*5b0945b5SGregory Neil Shapiro */ 12*5b0945b5SGregory Neil Shapiro 13*5b0945b5SGregory Neil Shapiro /* a part of this code is based on inetd.c for which this copyright applies: */ 14*5b0945b5SGregory Neil Shapiro /* 15*5b0945b5SGregory Neil Shapiro * Copyright (c) 1983, 1991, 1993, 1994 16*5b0945b5SGregory Neil Shapiro * The Regents of the University of California. All rights reserved. 17*5b0945b5SGregory Neil Shapiro * 18*5b0945b5SGregory Neil Shapiro * Redistribution and use in source and binary forms, with or without 19*5b0945b5SGregory Neil Shapiro * modification, are permitted provided that the following conditions 20*5b0945b5SGregory Neil Shapiro * are met: 21*5b0945b5SGregory Neil Shapiro * 1. Redistributions of source code must retain the above copyright 22*5b0945b5SGregory Neil Shapiro * notice, this list of conditions and the following disclaimer. 23*5b0945b5SGregory Neil Shapiro * 2. Redistributions in binary form must reproduce the above copyright 24*5b0945b5SGregory Neil Shapiro * notice, this list of conditions and the following disclaimer in the 25*5b0945b5SGregory Neil Shapiro * documentation and/or other materials provided with the distribution. 26*5b0945b5SGregory Neil Shapiro * 3. All advertising materials mentioning features or use of this software 27*5b0945b5SGregory Neil Shapiro * must display the following acknowledgement: 28*5b0945b5SGregory Neil Shapiro * This product includes software developed by the University of 29*5b0945b5SGregory Neil Shapiro * California, Berkeley and its contributors. 30*5b0945b5SGregory Neil Shapiro * 4. Neither the name of the University nor the names of its contributors 31*5b0945b5SGregory Neil Shapiro * may be used to endorse or promote products derived from this software 32*5b0945b5SGregory Neil Shapiro * without specific prior written permission. 33*5b0945b5SGregory Neil Shapiro * 34*5b0945b5SGregory Neil Shapiro * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 35*5b0945b5SGregory Neil Shapiro * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 36*5b0945b5SGregory Neil Shapiro * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 37*5b0945b5SGregory Neil Shapiro * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 38*5b0945b5SGregory Neil Shapiro * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 39*5b0945b5SGregory Neil Shapiro * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 40*5b0945b5SGregory Neil Shapiro * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 41*5b0945b5SGregory Neil Shapiro * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 42*5b0945b5SGregory Neil Shapiro * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 43*5b0945b5SGregory Neil Shapiro * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 44*5b0945b5SGregory Neil Shapiro * SUCH DAMAGE. 45*5b0945b5SGregory Neil Shapiro */ 46*5b0945b5SGregory Neil Shapiro 47*5b0945b5SGregory Neil Shapiro #ifndef RATECTRL_H 48*5b0945b5SGregory Neil Shapiro #define RATECTRL_H 1 49*5b0945b5SGregory Neil Shapiro 50*5b0945b5SGregory Neil Shapiro #include <sendmail.h> 51*5b0945b5SGregory Neil Shapiro 52*5b0945b5SGregory Neil Shapiro /* 53*5b0945b5SGregory Neil Shapiro ** stuff included - given some warnings (inet_ntoa) 54*5b0945b5SGregory Neil Shapiro ** - surely not everything is needed 55*5b0945b5SGregory Neil Shapiro */ 56*5b0945b5SGregory Neil Shapiro 57*5b0945b5SGregory Neil Shapiro #if NETINET || NETINET6 58*5b0945b5SGregory Neil Shapiro # include <arpa/inet.h> 59*5b0945b5SGregory Neil Shapiro #endif 60*5b0945b5SGregory Neil Shapiro 61*5b0945b5SGregory Neil Shapiro #include <sm/time.h> 62*5b0945b5SGregory Neil Shapiro 63*5b0945b5SGregory Neil Shapiro #ifndef HASH_ALG 64*5b0945b5SGregory Neil Shapiro # define HASH_ALG 2 65*5b0945b5SGregory Neil Shapiro #endif 66*5b0945b5SGregory Neil Shapiro 67*5b0945b5SGregory Neil Shapiro #ifndef RATECTL_DEBUG 68*5b0945b5SGregory Neil Shapiro # define RATECTL_DEBUG 0 69*5b0945b5SGregory Neil Shapiro #endif 70*5b0945b5SGregory Neil Shapiro 71*5b0945b5SGregory Neil Shapiro /* this should be a power of 2, otherwise CPMHMASK doesn't work well */ 72*5b0945b5SGregory Neil Shapiro #ifndef CPMHSIZE 73*5b0945b5SGregory Neil Shapiro # define CPMHSIZE 1024 74*5b0945b5SGregory Neil Shapiro #endif 75*5b0945b5SGregory Neil Shapiro 76*5b0945b5SGregory Neil Shapiro #define CPMHMASK (CPMHSIZE-1) 77*5b0945b5SGregory Neil Shapiro #define CHTSIZE 6 78*5b0945b5SGregory Neil Shapiro 79*5b0945b5SGregory Neil Shapiro /* Number of connections for a certain "tick" */ 80*5b0945b5SGregory Neil Shapiro typedef struct CTime 81*5b0945b5SGregory Neil Shapiro { 82*5b0945b5SGregory Neil Shapiro unsigned long ct_Ticks; 83*5b0945b5SGregory Neil Shapiro int ct_Count; 84*5b0945b5SGregory Neil Shapiro } 85*5b0945b5SGregory Neil Shapiro CTime_T; 86*5b0945b5SGregory Neil Shapiro 87*5b0945b5SGregory Neil Shapiro typedef struct CHash 88*5b0945b5SGregory Neil Shapiro { 89*5b0945b5SGregory Neil Shapiro #if NETINET6 && NETINET 90*5b0945b5SGregory Neil Shapiro union 91*5b0945b5SGregory Neil Shapiro { 92*5b0945b5SGregory Neil Shapiro struct in_addr c4_Addr; 93*5b0945b5SGregory Neil Shapiro struct in6_addr c6_Addr; 94*5b0945b5SGregory Neil Shapiro } cu_Addr; 95*5b0945b5SGregory Neil Shapiro # define ch_Addr4 cu_Addr.c4_Addr 96*5b0945b5SGregory Neil Shapiro # define ch_Addr6 cu_Addr.c6_Addr 97*5b0945b5SGregory Neil Shapiro #else /* NETINET6 && NETINET */ 98*5b0945b5SGregory Neil Shapiro # if NETINET6 99*5b0945b5SGregory Neil Shapiro struct in6_addr ch_Addr; 100*5b0945b5SGregory Neil Shapiro # define ch_Addr6 ch_Addr 101*5b0945b5SGregory Neil Shapiro # else /* NETINET6 */ 102*5b0945b5SGregory Neil Shapiro struct in_addr ch_Addr; 103*5b0945b5SGregory Neil Shapiro # define ch_Addr4 ch_Addr 104*5b0945b5SGregory Neil Shapiro # endif /* NETINET6 */ 105*5b0945b5SGregory Neil Shapiro #endif /* NETINET6 && NETINET */ 106*5b0945b5SGregory Neil Shapiro 107*5b0945b5SGregory Neil Shapiro int ch_Family; 108*5b0945b5SGregory Neil Shapiro time_t ch_LTime; 109*5b0945b5SGregory Neil Shapiro unsigned long ch_colls; 110*5b0945b5SGregory Neil Shapiro 111*5b0945b5SGregory Neil Shapiro /* 6 buckets for ticks: 60s */ 112*5b0945b5SGregory Neil Shapiro CTime_T ch_Times[CHTSIZE]; 113*5b0945b5SGregory Neil Shapiro #if _FFR_OCC 114*5b0945b5SGregory Neil Shapiro int ch_oc; /* open connections */ 115*5b0945b5SGregory Neil Shapiro #endif 116*5b0945b5SGregory Neil Shapiro } 117*5b0945b5SGregory Neil Shapiro CHash_T; 118*5b0945b5SGregory Neil Shapiro 119*5b0945b5SGregory Neil Shapiro #define SM_CLFL_NONE 0x00 120*5b0945b5SGregory Neil Shapiro #define SM_CLFL_UPDATE 0x01 121*5b0945b5SGregory Neil Shapiro #define SM_CLFL_EXC 0x02 /* check if limit is exceeded */ 122*5b0945b5SGregory Neil Shapiro 123*5b0945b5SGregory Neil Shapiro extern void connection_rate_check __P((SOCKADDR *, ENVELOPE *)); 124*5b0945b5SGregory Neil Shapiro extern int conn_limits __P((ENVELOPE *, time_t, SOCKADDR *, int, CHash_T *, int, int)); 125*5b0945b5SGregory Neil Shapiro extern bool occ_exceeded __P((ENVELOPE *, MCI *, const char *, SOCKADDR *)); 126*5b0945b5SGregory Neil Shapiro extern bool occ_close __P((ENVELOPE *, MCI *, const char *, SOCKADDR *)); 127*5b0945b5SGregory Neil Shapiro extern void dump_ch __P((SM_FILE_T *)); 128*5b0945b5SGregory Neil Shapiro #endif /* ! RATECTRL_H */ 129