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
31struct RadixUserData;
32
33/**
34 * \brief Structure for the node in the radix tree
35 */
36typedef 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 */
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 */
64typedef struct SCRadix6Tree_ {
65 /** the root node in the radix tree */
68
69typedef 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
84SCRadix6Node *SCRadix6AddKeyIPV6(SCRadix6Tree *, const SCRadix6Config *, const uint8_t *, void *);
86 SCRadix6Tree *, const SCRadix6Config *, const uint8_t *, uint8_t, void *);
87bool SCRadix6AddKeyIPV6String(SCRadix6Tree *, const SCRadix6Config *, const char *, void *);
88
90 SCRadix6Tree *, const SCRadix6Config *, const uint8_t *, uint8_t);
91void SCRadix6RemoveKeyIPV6(SCRadix6Tree *, const SCRadix6Config *, const uint8_t *);
92
93SCRadix6Node *SCRadix6TreeFindExactMatch(const SCRadix6Tree *, const uint8_t *, void **);
95 const SCRadix6Tree *, const uint8_t *, const uint8_t, void **);
96SCRadix6Node *SCRadix6TreeFindBestMatch(const SCRadix6Tree *, const uint8_t *, void **);
97SCRadix6Node *SCRadix6TreeFindBestMatch2(const SCRadix6Tree *, const uint8_t *, void **, uint8_t *);
98
100void SCRadix6PrintNodeInfo(SCRadix6Node *, int, void (*PrintData)(void *));
101
102void SCRadix6RegisterTests(void);
103
105 const SCRadix6Node *node, void *user_data, const uint8_t netmask, void *data);
106
107int 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 */
113typedef 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 */
Structure that hold the user data and the netmask associated with it.
void(* PrintData)(void *)
void(* Free)(void *)
Structure for the node in the radix tree.
struct SCRadix6Node_ * left
struct RadixUserData * user_data
uint8_t prefix_stream[16]
uint8_t masks[17]
struct SCRadix6Node_ * right
struct SCRadix6Node_ * parent
Structure for the radix tree.
SCRadix6Node * head
int SCRadix6ForEachNode(const SCRadix6Tree *tree, SCRadix6ForEachNodeFunc Callback, void *data)
struct SCRadix6Tree_ SCRadix6Tree
Structure for the radix tree.
SCRadix6Tree SCRadix6TreeInitialize(void)
struct SCRadix6Node_ SCRadix6Node
Structure for the node in the radix tree.
int(* SCRadix6ForEachNodeFunc)(const SCRadix6Node *node, void *user_data, const uint8_t netmask, void *data)
SCRadix6Node * SCRadix6TreeFindExactMatch(const SCRadix6Tree *, const uint8_t *, void **)
void SCRadix6TreeRelease(SCRadix6Tree *, const SCRadix6Config *)
void SCRadix6RegisterTests(void)
struct SCRadix6Config_ SCRadix6Config
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,...
void SCRadix6PrintTree(SCRadix6Tree *, const SCRadix6Config *)
bool SCRadix6AddKeyIPV6String(SCRadix6Tree *, const SCRadix6Config *, const char *, void *)
Adds a new IPV6/netblock to the Radix6 tree from a string.
SCRadix6Node * SCRadix6TreeFindNetblock(const SCRadix6Tree *, const uint8_t *, const uint8_t, void **)
SCRadix6Node * SCRadix6TreeFindBestMatch2(const SCRadix6Tree *, const uint8_t *, void **, uint8_t *)
void SCRadix6RemoveKeyIPV6Netblock(SCRadix6Tree *, const SCRadix6Config *, const uint8_t *, uint8_t)
Removes an IPV6 address netblock key from the tree.
SCRadix6Node * SCRadix6AddKeyIPV6Netblock(SCRadix6Tree *, const SCRadix6Config *, const uint8_t *, uint8_t, void *)
Adds a new IPV6 netblock to the Radix6 tree.
SCRadix6Node * SCRadix6AddKeyIPV6(SCRadix6Tree *, const SCRadix6Config *, const uint8_t *, void *)
Adds a new IPV6 address to the Radix6 tree.
bool SCRadix6CompareTrees(const SCRadix6Tree *t1, const SCRadix6Tree *t2, SCRadix6TreeCompareFunc Callback)
bool(* SCRadix6TreeCompareFunc)(const void *ud1, const void *ud2)
compare content of 2 user data entries
void SCRadix6PrintNodeInfo(SCRadix6Node *, int, void(*PrintData)(void *))
SCRadix6Node * SCRadix6TreeFindBestMatch(const SCRadix6Tree *, const uint8_t *, void **)