Go to the documentation of this file.
82 PI_IRB_REMOVE(&it->
tree, node);
97 SCPortIntervalNodeFree(
de_ctx, it);
124 if (PI_IRB_INSERT(&it->
tree, pi) != NULL) {
154 (*list)->last = prev;
170 static bool SCPortIntervalIsOverlap(
193 if (port <= ptr->port2 && ptr->
port <= port2) {
197 SCLogDebug(
"No overlap found for [%d, %d] w [%d, %d]", port, port2, ptr->
port, ptr->
port2);
201 #define STACK_SIZE 100
230 while (current || stack_depth) {
231 while (current != NULL) {
232 if (current->
max < port) {
236 const bool is_overlap = SCPortIntervalIsOverlap(port, port2, current);
238 if (is_overlap && (new_port == NULL)) {
241 if (new_port == NULL) {
245 SCLogDebug(
"Found overlaps for [%u:%u], creating new port", port, port2);
246 new_port->
port = port;
247 new_port->
port2 = port2;
255 (*list)->
last = new_port;
256 }
else if (((*list)->last->port != new_port->
port) &&
257 ((*list)->last->port2 != new_port->
port2)) {
259 (*list)->last->next = new_port;
261 (*list)->
last = new_port;
263 SCLogDebug(
"Port already exists in the list");
266 }
else if (is_overlap && (new_port != NULL)) {
267 SCLogDebug(
"Found overlaps for [%u:%u], adding sigs", port, port2);
271 stack[stack_depth++] = current;
272 if (stack_depth == stack_size) {
273 SCLogDebug(
"Stack depth %d maxed out, realloc'ing..", stack_depth);
277 SCLogError(
"Couldn't realloc the interval tree stack");
285 if (stack_depth == 0) {
295 if (new_port != NULL)
296 SCPortIntervalSanitizeList(
de_ctx, list);
301 if (new_port != NULL)
321 SCLogDebug(
"Tree head should not be NULL. Nothing to do further.");
325 SCLogDebug(
"Finding overlaps for the range [%d, %d]", port, port2);
326 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.