suricata
flow-callbacks.c
Go to the documentation of this file.
1/* Copyright (C) 2024 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#include "flow-callbacks.h"
19
25
26static FlowInitCallback *init_callbacks = NULL;
27
33
34static FlowUpdateCallback *update_callbacks = NULL;
35
41
42static FlowFinishCallback *finish_callbacks = NULL;
43
45{
46 FlowInitCallback *cb = SCCalloc(1, sizeof(*cb));
47 if (cb == NULL) {
48 return false;
49 }
50 cb->Callback = fn;
51 cb->user = user;
52 if (init_callbacks == NULL) {
53 init_callbacks = cb;
54 } else {
55 FlowInitCallback *current = init_callbacks;
56 while (current->next != NULL) {
57 current = current->next;
58 }
59 current->next = cb;
60 }
61 return true;
62}
63
65{
66 FlowInitCallback *cb = init_callbacks;
67 while (cb != NULL) {
68 cb->Callback(tv, f, p, cb->user);
69 cb = cb->next;
70 }
71}
72
74{
75 FlowUpdateCallback *cb = SCCalloc(1, sizeof(*cb));
76 if (cb == NULL) {
77 return false;
78 }
79 cb->Callback = fn;
80 cb->user = user;
81 if (update_callbacks == NULL) {
82 update_callbacks = cb;
83 } else {
84 FlowUpdateCallback *current = update_callbacks;
85 while (current->next != NULL) {
86 current = current->next;
87 }
88 current->next = cb;
89 }
90 return true;
91}
92
94{
95 FlowUpdateCallback *cb = update_callbacks;
96 while (cb != NULL) {
97 cb->Callback(tv, f, p, cb->user);
98 cb = cb->next;
99 }
100}
101
103{
104 FlowFinishCallback *cb = SCCalloc(1, sizeof(*cb));
105 if (cb == NULL) {
106 return false;
107 }
108 cb->Callback = fn;
109 cb->user = user;
110 if (finish_callbacks == NULL) {
111 finish_callbacks = cb;
112 } else {
113 FlowFinishCallback *current = finish_callbacks;
114 while (current->next != NULL) {
115 current = current->next;
116 }
117 current->next = cb;
118 }
119 return true;
120}
121
123{
124 FlowFinishCallback *cb = finish_callbacks;
125 while (cb != NULL) {
126 cb->Callback(tv, f, cb->user);
127 cb = cb->next;
128 }
129}
void SCFlowRunUpdateCallbacks(ThreadVars *tv, Flow *f, Packet *p)
bool SCFlowRegisterFinishCallback(SCFlowFinishCallbackFn fn, void *user)
Register a flow init callback.
struct FlowFinishCallback_ FlowFinishCallback
void SCFlowRunInitCallbacks(ThreadVars *tv, Flow *f, const Packet *p)
bool SCFlowRegisterInitCallback(SCFlowInitCallbackFn fn, void *user)
Register a flow init callback.
struct FlowInitCallback_ FlowInitCallback
struct FlowUpdateCallback_ FlowUpdateCallback
bool SCFlowRegisterUpdateCallback(SCFlowUpdateCallbackFn fn, void *user)
Register a flow update callback.
void SCFlowRunFinishCallbacks(ThreadVars *tv, Flow *f)
void(* SCFlowFinishCallbackFn)(ThreadVars *tv, Flow *f, void *user)
Function type for flow finish callbacks.
void(* SCFlowUpdateCallbackFn)(ThreadVars *tv, Flow *f, Packet *p, void *user)
Function type for flow update callbacks.
void(* SCFlowInitCallbackFn)(ThreadVars *tv, Flow *f, const Packet *p, void *user)
Function type for flow initialization callbacks.
ThreadVars * tv
SCFlowFinishCallbackFn Callback
struct FlowFinishCallback_ * next
struct FlowInitCallback_ * next
SCFlowInitCallbackFn Callback
struct FlowUpdateCallback_ * next
SCFlowUpdateCallbackFn Callback
Flow data structure.
Definition flow.h:356
Per thread variable structure.
Definition threadvars.h:58
#define SCCalloc(nm, sz)
Definition util-mem.h:53