Skip to content

Commit

Permalink
detect: introduce "like" ip-only signature type
Browse files Browse the repository at this point in the history
Rules that look like they should be IP-only but contain a negated rule
address are now marked with an LIKE_IPONLY flag. This is so they are
treated like IPONLY rules with respect to flow action, but don't
interfere with other IPONLY processing like using the radix tree.

Ticket: OISF#5361
  • Loading branch information
jasonish committed May 11, 2022
1 parent b6407c4 commit 8aa9345
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/detect-engine-alert.c
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,8 @@ static inline void FlowApplySignatureActions(
* - match is in stream */
if (s->action & (ACTION_DROP | ACTION_PASS)) {
if ((pa->flags & (PACKET_ALERT_FLAG_STATE_MATCH | PACKET_ALERT_FLAG_STREAM_MATCH)) ||
(s->flags & (SIG_FLAG_IPONLY | SIG_FLAG_PDONLY | SIG_FLAG_APPLAYER))) {
(s->flags & (SIG_FLAG_IPONLY | SIG_FLAG_LIKE_IPONLY | SIG_FLAG_PDONLY |
SIG_FLAG_APPLAYER))) {
pa->flags |= PACKET_ALERT_FLAG_APPLY_ACTION_TO_FLOW;
SCLogDebug("packet %" PRIu64 " sid %u action %02x alert_flags %02x (set "
"PACKET_ALERT_FLAG_APPLY_ACTION_TO_FLOW)",
Expand Down
19 changes: 9 additions & 10 deletions src/detect-engine-build.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,6 @@ int SignatureIsIPOnly(DetectEngineCtx *de_ctx, const Signature *s)
/* TMATCH list can be ignored, it contains TAGs and
* tags are compatible to IP-only. */

/* if any of the addresses uses negation, we don't support
* it in ip-only */
if (s->init_data->src_contains_negation)
return 0;
if (s->init_data->dst_contains_negation)
return 0;

SigMatch *sm = s->init_data->smlists[DETECT_SM_LIST_MATCH];
if (sm == NULL)
goto iponly;
Expand All @@ -242,12 +235,16 @@ int SignatureIsIPOnly(DetectEngineCtx *de_ctx, const Signature *s)
}

iponly:
if (s->init_data->src_contains_negation || s->init_data->dst_contains_negation) {
/* Rule is IP only, but contains negated addresses. */
return SIG_FLAG_LIKE_IPONLY;
}
if (!(de_ctx->flags & DE_QUIET)) {
SCLogDebug("IP-ONLY (%" PRIu32 "): source %s, dest %s", s->id,
s->flags & SIG_FLAG_SRC_ANY ? "ANY" : "SET",
s->flags & SIG_FLAG_DST_ANY ? "ANY" : "SET");
}
return 1;
return SIG_FLAG_IPONLY;
}

/** \internal
Expand Down Expand Up @@ -1319,13 +1316,15 @@ static DetectPort *RulesGroupByPorts(DetectEngineCtx *de_ctx, int ipproto, uint3

void SignatureSetType(DetectEngineCtx *de_ctx, Signature *s)
{
uint32_t flags = 0;

/* see if the sig is dp only */
if (SignatureIsPDOnly(de_ctx, s) == 1) {
s->flags |= SIG_FLAG_PDONLY;

/* see if the sig is ip only */
} else if (SignatureIsIPOnly(de_ctx, s) == 1) {
s->flags |= SIG_FLAG_IPONLY;
} else if ((flags = SignatureIsIPOnly(de_ctx, s)) > 0) {
s->flags |= flags;

} else if (SignatureIsDEOnly(de_ctx, s) == 1) {
s->init_data->init_flags |= SIG_FLAG_INIT_DEONLY;
Expand Down
3 changes: 3 additions & 0 deletions src/detect.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ typedef struct DetectPort_ {
#define SIG_FLAG_DSIZE BIT_U32(5) /**< signature has a dsize setting */
#define SIG_FLAG_APPLAYER BIT_U32(6) /**< signature applies to app layer instead of packets */
#define SIG_FLAG_IPONLY BIT_U32(7) /**< ip only signature */
#define SIG_FLAG_LIKE_IPONLY \
BIT_U32(8) /**< signature that is almost ip only, but contains negation prevening some iponly \
optimizations */

// vacancy

Expand Down

0 comments on commit 8aa9345

Please sign in to comment.