suricata
util-flow-rate.h
Go to the documentation of this file.
1 /* Copyright (C) 2025 Open Information Security Foundation
2  *
3  * You can copy, redistribute or modify this Program under the terms of
4  * the GNU General Public License version 2 as published by the Free
5  * Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * version 2 along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15  * 02110-1301, USA.
16  */
17 
18 /**
19  * \file
20  *
21  * \author Shivani Bhardwaj <shivani@oisf.net>
22  */
23 
24 #ifndef SURICATA_UTIL_FLOW_RATE_H
25 #define SURICATA_UTIL_FLOW_RATE_H
26 
27 typedef struct FlowRateConfig_ {
28  uint64_t bytes;
31 
32 typedef struct FlowRateDirStore_ {
33  /* Ring buffer to store byte count per second in */
34  uint64_t *buf;
35  /* Total sum of bytes per direction */
36  uint64_t sum;
37  /* Last index that was updated in the buffer */
38  uint16_t last_idx;
39  /* Size of the ring; should be same for both directions */
40  uint16_t size;
41  /* start timestamp to define and track the beginning of buffer */
43  /* last timestamp that was processed in the buffer */
46 
47 typedef struct FlowRateStore_ {
50 
52 
53 bool FlowRateStorageEnabled(void);
57 void FlowRateStoreUpdate(FlowRateStore *, SCTime_t, uint32_t, int);
59 
60 #ifdef UNITTESTS
61 void FlowRateRegisterTests(void);
62 #endif
63 
64 #endif
FlowStorageId
Definition: flow-storage.h:31
FlowRateDirStore_::sum
uint64_t sum
Definition: util-flow-rate.h:36
FlowRateStoreInit
FlowRateStore * FlowRateStoreInit(void)
Definition: util-flow-rate.c:102
FlowRateDirStore_::start_ts
SCTime_t start_ts
Definition: util-flow-rate.h:42
FlowRateConfig_::interval
SCTime_t interval
Definition: util-flow-rate.h:29
FlowRateRegisterFlowStorage
void FlowRateRegisterFlowStorage(void)
Definition: util-flow-rate.c:60
FlowRateDirStore_
Definition: util-flow-rate.h:32
FlowRateIsExceeding
bool FlowRateIsExceeding(FlowRateStore *, int)
Definition: util-flow-rate.c:226
FlowRateStoreUpdate
void FlowRateStoreUpdate(FlowRateStore *, SCTime_t, uint32_t, int)
Definition: util-flow-rate.c:191
FlowRateStore_::dir
FlowRateDirStore dir[2]
Definition: util-flow-rate.h:48
flow_rate_config
FlowRateConfig flow_rate_config
Definition: util-flow-rate.c:39
FlowRateStorageEnabled
bool FlowRateStorageEnabled(void)
Definition: util-flow-rate.c:97
FlowRateConfig
struct FlowRateConfig_ FlowRateConfig
SCTime_t
Definition: util-time.h:40
FlowRateDirStore_::last_idx
uint16_t last_idx
Definition: util-flow-rate.h:38
FlowRateConfig_::bytes
uint64_t bytes
Definition: util-flow-rate.h:28
FlowRateStore
struct FlowRateStore_ FlowRateStore
FlowRateDirStore_::buf
uint64_t * buf
Definition: util-flow-rate.h:34
FlowRateRegisterTests
void FlowRateRegisterTests(void)
Definition: util-flow-rate.c:619
FlowRateDirStore_::size
uint16_t size
Definition: util-flow-rate.h:40
FlowRateDirStore_::last_ts
SCTime_t last_ts
Definition: util-flow-rate.h:44
FlowRateStore_
Definition: util-flow-rate.h:47
FlowRateConfig_
Definition: util-flow-rate.h:27
FlowRateGetStorageID
FlowStorageId FlowRateGetStorageID(void)
Definition: util-flow-rate.c:134
FlowRateDirStore
struct FlowRateDirStore_ FlowRateDirStore