return;
}
+/**
+ * \brief Finds if two Signature Group Heads are the same.
+ *
+ * \param sgha First SGH to be compared
+ * \param sghb Secornd SGH to be compared
+ *
+ * \return true if they're a match, false otherwise
+ */
+bool SigGroupHeadEqual(const SigGroupHead *sgha, const SigGroupHead *sghb)
+{
+ if (sgha == NULL || sghb == NULL)
+ return false;
+
+ if (sgha->init->sig_size != sghb->init->sig_size)
+ return false;
+
+ if (sgha->init->max_sig_id != sghb->init->max_sig_id)
+ return false;
+
+ if (SCMemcmp(sgha->init->sig_array, sghb->init->sig_array, sgha->init->sig_size) != 0)
+ return false;
+
+ return true;
+}
+
void SigGroupHeadSetProtoAndDirection(SigGroupHead *sgh,
uint8_t ipproto, int dir)
{
void SigGroupHeadInitDataFree(SigGroupHeadInitData *sghid);
void SigGroupHeadSetSigCnt(SigGroupHead *sgh, uint32_t max_idx);
+bool SigGroupHeadEqual(const SigGroupHead *, const SigGroupHead *);
void SigGroupHeadSetProtoAndDirection(SigGroupHead *sgh,
uint8_t ipproto, int dir);
int SigGroupHeadBuildMatchArray(DetectEngineCtx *de_ctx, SigGroupHead *sgh, uint32_t max_idx);
return SC_OK;
}
+/**
+ * \brief Function to remove multiple sig entries corresponding to the same
+ * signature group and merge them into one.
+ *
+ * \param de_ctx Detection Engine Context
+ * \param list Pointer to the list to be modified
+ */
+static void SCPortIntervalSanitizeList(DetectEngineCtx *de_ctx, DetectPort **list)
+{
+ DetectPort *cur = (*list)->last;
+ if (cur == NULL)
+ return;
+
+ DetectPort *prev = (*list)->last->prev;
+ if (prev == NULL)
+ return;
+
+ /* rulegroup IDs are assigned much later so, compare SGHs */
+ if (SigGroupHeadEqual(prev->sh, cur->sh)) {
+ if (prev->port2 == (cur->port - 1)) {
+ /* Merge the port objects */
+ prev->port2 = cur->port2;
+ (*list)->last = prev;
+ (*list)->last->next = NULL;
+ DetectPortFree(de_ctx, cur);
+ }
+ }
+}
+
/**
* \brief Function to check if a port range overlaps with a given set of ports
*
((*list)->last->port2 != new_port->port)) {
DEBUG_VALIDATE_BUG_ON(new_port->port < (*list)->last->port);
(*list)->last->next = new_port;
+ new_port->prev = (*list)->last;
(*list)->last = new_port;
} else {
SCLogDebug("Port already exists in the list");
BUG_ON(popped == NULL);
current = IRB_RIGHT(popped, irb);
}
+ if (new_port != NULL)
+ SCPortIntervalSanitizeList(de_ctx, list);
if (stack != NULL)
SCFree(stack);
return;