suricata
util-radix6-tree.h
Go to the documentation of this file.
1 /* Copyright (C) 2007-2022 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 Victor Julien <victor@inliniac.net>
22  * Based on util-radix-tree.[ch] by:
23  * \author Anoop Saldanha <anoopsaldanha@gmail.com>
24  */
25 
26 #ifndef SURICATA_UTIL_RADIX6_TREE_H
27 #define SURICATA_UTIL_RADIX6_TREE_H
28 
29 #include "suricata-common.h"
30 
31 struct RadixUserData;
32 
33 /**
34  * \brief Structure for the node in the radix tree
35  */
36 typedef struct SCRadix6Node_ {
37  /** the key that has been stored in the tree */
38  uint8_t prefix_stream[16];
39 
40  /** holds bitmap of netmasks that come under this node in the tree */
41  uint8_t masks[17];
42 
43  /** the bit position where the bits differ in the nodes children. Used
44  * to determine the path to be taken during a lookup */
45  uint8_t bit;
46  /** bool to see if prefix_stream is filled */
47  bool has_prefix;
48 
49  /** User data that has is associated with this key. We need a user
50  * data field for each netblock value possible since one ip can be associated
51  * with any of the 128 netblocks. */
53 
54  /** the left and the right children of a node */
56 
57  /** the parent node for this tree */
60 
61 /**
62  * \brief Structure for the radix tree
63  */
64 typedef struct SCRadix6Tree_ {
65  /** the root node in the radix tree */
68 
69 typedef struct SCRadix6Config_ {
70  void (*Free)(void *);
71  /** function pointer that is supplied by the user to free the user data
72  * held by the user field of SCRadix6Node */
73  void (*PrintData)(void *);
75 
76 #define SC_RADIX6_TREE_INITIALIZER \
77  { \
78  .head = NULL \
79  }
80 
83 
84 SCRadix6Node *SCRadix6AddKeyIPV6(SCRadix6Tree *, const SCRadix6Config *, const uint8_t *, void *);
86  SCRadix6Tree *, const SCRadix6Config *, const uint8_t *, uint8_t, void *);
87 bool SCRadix6AddKeyIPV6String(SCRadix6Tree *, const SCRadix6Config *, const char *, void *);
88 
90  SCRadix6Tree *, const SCRadix6Config *, const uint8_t *, uint8_t);
91 void SCRadix6RemoveKeyIPV6(SCRadix6Tree *, const SCRadix6Config *, const uint8_t *);
92 
93 SCRadix6Node *SCRadix6TreeFindExactMatch(const SCRadix6Tree *, const uint8_t *, void **);
95  const SCRadix6Tree *, const uint8_t *, const uint8_t, void **);
96 SCRadix6Node *SCRadix6TreeFindBestMatch(const SCRadix6Tree *, const uint8_t *, void **);
97 SCRadix6Node *SCRadix6TreeFindBestMatch2(const SCRadix6Tree *, const uint8_t *, void **, uint8_t *);
98 
100 void SCRadix6PrintNodeInfo(SCRadix6Node *, int, void (*PrintData)(void *));
101 
102 void SCRadix6RegisterTests(void);
103 
104 typedef int (*SCRadix6ForEachNodeFunc)(
105  const SCRadix6Node *node, void *user_data, const uint8_t netmask, void *data);
106 
107 int SCRadix6ForEachNode(const SCRadix6Tree *tree, SCRadix6ForEachNodeFunc Callback, void *data);
108 
109 /** \brief compare content of 2 user data entries
110  * \retval true equal
111  * \retval false not equal
112  */
113 typedef bool (*SCRadix6TreeCompareFunc)(const void *ud1, const void *ud2);
115  const SCRadix6Tree *t1, const SCRadix6Tree *t2, SCRadix6TreeCompareFunc Callback);
116 
117 #endif /* SURICATA_UTIL_RADIX4_TREE_H */
SCRadix6Node_::masks
uint8_t masks[17]
Definition: util-radix6-tree.h:41
SCRadix6ForEachNodeFunc
int(* SCRadix6ForEachNodeFunc)(const SCRadix6Node *node, void *user_data, const uint8_t netmask, void *data)
Definition: util-radix6-tree.h:104
SCRadix6CompareTrees
bool SCRadix6CompareTrees(const SCRadix6Tree *t1, const SCRadix6Tree *t2, SCRadix6TreeCompareFunc Callback)
Definition: util-radix6-tree.c:418
SCRadix6RemoveKeyIPV6Netblock
void SCRadix6RemoveKeyIPV6Netblock(SCRadix6Tree *, const SCRadix6Config *, const uint8_t *, uint8_t)
Removes an IPV6 address netblock key from the tree.
Definition: util-radix6-tree.c:349
RadixUserData
Structure that hold the user data and the netmask associated with it.
Definition: util-radix-tree-common.h:41
SCRadix6RemoveKeyIPV6
void SCRadix6RemoveKeyIPV6(SCRadix6Tree *, const SCRadix6Config *, const uint8_t *)
Removes an IPV6 address key(not a netblock) from the Radix6 tree. Instead of using this function,...
Definition: util-radix6-tree.c:335
SCRadix6Node_::parent
struct SCRadix6Node_ * parent
Definition: util-radix6-tree.h:58
SCRadix6AddKeyIPV6Netblock
SCRadix6Node * SCRadix6AddKeyIPV6Netblock(SCRadix6Tree *, const SCRadix6Config *, const uint8_t *, uint8_t, void *)
Adds a new IPV6 netblock to the Radix6 tree.
Definition: util-radix6-tree.c:214
SCRadix6AddKeyIPV6
SCRadix6Node * SCRadix6AddKeyIPV6(SCRadix6Tree *, const SCRadix6Config *, const uint8_t *, void *)
Adds a new IPV6 address to the Radix6 tree.
Definition: util-radix6-tree.c:196
SCRadix6TreeFindBestMatch2
SCRadix6Node * SCRadix6TreeFindBestMatch2(const SCRadix6Tree *, const uint8_t *, void **, uint8_t *)
Definition: util-radix6-tree.c:179
SCRadix6Config
struct SCRadix6Config_ SCRadix6Config
SCRadix6Tree_::head
SCRadix6Node * head
Definition: util-radix6-tree.h:66
SCRadix6Node_::left
struct SCRadix6Node_ * left
Definition: util-radix6-tree.h:55
SCRadix6RegisterTests
void SCRadix6RegisterTests(void)
Definition: util-radix6-tree.c:946
SCRadix6PrintNodeInfo
void SCRadix6PrintNodeInfo(SCRadix6Node *, int, void(*PrintData)(void *))
SCRadix6Node_::prefix_stream
uint8_t prefix_stream[16]
Definition: util-radix6-tree.h:38
SCRadix6Node_::user_data
struct RadixUserData * user_data
Definition: util-radix6-tree.h:52
SCRadix6Node_::right
struct SCRadix6Node_ * right
Definition: util-radix6-tree.h:55
SCRadix6TreeFindExactMatch
SCRadix6Node * SCRadix6TreeFindExactMatch(const SCRadix6Tree *, const uint8_t *, void **)
Definition: util-radix6-tree.c:161
SCRadix6Config_::Free
void(* Free)(void *)
Definition: util-radix6-tree.h:70
SCRadix6Tree
struct SCRadix6Tree_ SCRadix6Tree
Structure for the radix tree.
SCRadix6Config_
Definition: util-radix6-tree.h:69
suricata-common.h
SCRadix6TreeInitialize
SCRadix6Tree SCRadix6TreeInitialize(void)
Definition: util-radix6-tree.c:360
SCRadix6Node
struct SCRadix6Node_ SCRadix6Node
Structure for the node in the radix tree.
SCRadix6Node_
Structure for the node in the radix tree.
Definition: util-radix6-tree.h:36
SCRadix6TreeRelease
void SCRadix6TreeRelease(SCRadix6Tree *, const SCRadix6Config *)
Definition: util-radix6-tree.c:366
SCRadix6TreeFindNetblock
SCRadix6Node * SCRadix6TreeFindNetblock(const SCRadix6Tree *, const uint8_t *, const uint8_t, void **)
Definition: util-radix6-tree.c:167
SCRadix6TreeCompareFunc
bool(* SCRadix6TreeCompareFunc)(const void *ud1, const void *ud2)
compare content of 2 user data entries
Definition: util-radix6-tree.h:113
SCRadix6Tree_
Structure for the radix tree.
Definition: util-radix6-tree.h:64
SCRadix6Config_::PrintData
void(* PrintData)(void *)
Definition: util-radix6-tree.h:73
SCRadix6TreeFindBestMatch
SCRadix6Node * SCRadix6TreeFindBestMatch(const SCRadix6Tree *, const uint8_t *, void **)
Definition: util-radix6-tree.c:173
SCRadix6ForEachNode
int SCRadix6ForEachNode(const SCRadix6Tree *tree, SCRadix6ForEachNodeFunc Callback, void *data)
Definition: util-radix6-tree.c:411
SCRadix6Node_::bit
uint8_t bit
Definition: util-radix6-tree.h:45
SCRadix6PrintTree
void SCRadix6PrintTree(SCRadix6Tree *, const SCRadix6Config *)
Definition: util-radix6-tree.c:355
SCRadix6AddKeyIPV6String
bool SCRadix6AddKeyIPV6String(SCRadix6Tree *, const SCRadix6Config *, const char *, void *)
Adds a new IPV6/netblock to the Radix6 tree from a string.
Definition: util-radix6-tree.c:262
SCRadix6Node_::has_prefix
bool has_prefix
Definition: util-radix6-tree.h:47