Go to the documentation of this file.
80 PI_IRB_REMOVE(&it->
tree, node);
95 SCPortIntervalNodeFree(
de_ctx, it);
122 if (PI_IRB_INSERT(&it->
tree, pi) != NULL) {
152 (*list)->last = prev;
168 static bool SCPortIntervalIsOverlap(
191 if (port <= ptr->port2 && ptr->
port <= port2) {
195 SCLogDebug(
"No overlap found for [%d, %d] w [%d, %d]", port, port2, ptr->
port, ptr->
port2);
199 #define STACK_SIZE 100
228 while (current || stack_depth) {
229 while (current != NULL) {
230 if (current->
max < port) {
234 const bool is_overlap = SCPortIntervalIsOverlap(port, port2, current);
236 if (is_overlap && (new_port == NULL)) {
239 if (new_port == NULL) {
243 SCLogDebug(
"Found overlaps for [%u:%u], creating new port", port, port2);
244 new_port->
port = port;
245 new_port->
port2 = port2;
253 (*list)->
last = new_port;
254 }
else if (((*list)->last->port != new_port->
port) &&
255 ((*list)->last->port2 != new_port->
port2)) {
257 (*list)->last->next = new_port;
259 (*list)->
last = new_port;
261 SCLogDebug(
"Port already exists in the list");
264 }
else if (is_overlap && (new_port != NULL)) {
265 SCLogDebug(
"Found overlaps for [%u:%u], adding sigs", port, port2);
269 stack[stack_depth++] = current;
270 if (stack_depth == stack_size) {
271 SCLogDebug(
"Stack depth %d maxed out, realloc'ing..", stack_depth);
275 SCLogError(
"Couldn't realloc the interval tree stack");
283 if (stack_depth == 0) {
293 if (new_port != NULL)
294 SCPortIntervalSanitizeList(
de_ctx, list);
299 if (new_port != NULL)
319 SCLogDebug(
"Tree head should not be NULL. Nothing to do further.");
323 SCLogDebug(
"Finding overlaps for the range [%d, %d]", port, port2);
324 SCPortIntervalFindOverlaps(
de_ctx, port, port2, ptr, list);
bool SigGroupHeadEqual(const SigGroupHead *sgha, const SigGroupHead *sghb)
Finds if two Signature Group Heads are the same.
void DetectPortFree(const DetectEngineCtx *de_ctx, DetectPort *dp)
Free a DetectPort and its members.
#define IRB_FOREACH_SAFE(x, name, head, y)
void SCPortIntervalFindOverlappingRanges(DetectEngineCtx *de_ctx, const uint16_t port, const uint16_t port2, const struct PI *head, DetectPort **list)
Callee function to find all overlapping port ranges as asked by the detection engine during Stage 2 o...
struct SigGroupHead_ * sh
main detection engine ctx
struct DetectPort_ * next
struct SigGroupHead_ * sh
DetectPort * DetectPortInit(void)
Alloc a DetectPort structure and update counters.
int SCPortIntervalInsert(DetectEngineCtx *de_ctx, SCPortIntervalTree *it, const DetectPort *p)
Function to insert a node in the interval tree.
Port structure for detection engine.
struct DetectPort_ * last
#define IRB_LEFT(elm, field)
void SigGroupHeadFree(const DetectEngineCtx *de_ctx, SigGroupHead *sgh)
Free a SigGroupHead and its members.
SCPortIntervalTree * SCPortIntervalTreeInit(void)
Function to initialize the interval tree.
#define SCRealloc(ptr, sz)
struct DetectPort_ * prev
#define SCLogError(...)
Macro used to log ERROR messages.
#define IRB_RIGHT(elm, field)
SCPortIntervalNode * head
#define DEBUG_VALIDATE_BUG_ON(exp)
void SCPortIntervalTreeFree(DetectEngineCtx *de_ctx, SCPortIntervalTree *it)
Function to free an entire interval tree.
IRB_GENERATE(PI, SCPortIntervalNode, irb, SCPortIntervalCompareAndUpdate)
int SigGroupHeadCopySigs(DetectEngineCtx *de_ctx, SigGroupHead *src, SigGroupHead **dst)
Copies the bitarray holding the sids from the source SigGroupHead to the destination SigGroupHead.