Skip to content

Commit edd0e9d

Browse files
committed
wip: dns: dns.answer.name: use new buffer logic
This new logic is not yet in the template so wasn't in the initial implementation of the keyword.
1 parent 9341298 commit edd0e9d

1 file changed

Lines changed: 42 additions & 10 deletions

File tree

‎src/detect-dns-answer-name.c‎

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,29 +69,61 @@ static int DetectDnsAnswerNameSetup(DetectEngineCtx *de_ctx, Signature *s, const
6969
return 0;
7070
}
7171

72-
static uint8_t DetectEngineInspectDnsAnswerName(DetectEngineCtx *de_ctx,
73-
DetectEngineThreadCtx *det_ctx, const struct DetectEngineAppInspectionEngine_ *engine,
74-
const Signature *s, Flow *f, uint8_t flags, void *alstate, void *txv, uint64_t tx_id)
72+
static InspectionBuffer *GetBuffer(DetectEngineThreadCtx *det_ctx,
73+
const DetectEngineTransforms *transforms, void *txv, uint32_t index, int list_id)
7574
{
76-
uint8_t ret = 0;
75+
InspectionBuffer *buffer = InspectionBufferMultipleForListGet(det_ctx, list_id, index);
76+
if (buffer == NULL) {
77+
return NULL;
78+
}
79+
if (buffer->initialized) {
80+
return buffer;
81+
}
82+
7783
const uint8_t *data = NULL;
7884
uint32_t data_len = 0;
7985

86+
if (!SCDnsTxGetAnswerName(txv, index, &data, &data_len)) {
87+
InspectionBufferSetupMultiEmpty(buffer);
88+
return NULL;
89+
} else {
90+
InspectionBufferSetupMulti(buffer, transforms, data, data_len);
91+
return buffer;
92+
}
93+
}
94+
95+
static uint8_t DetectEngineInspectDnsAnswerName(DetectEngineCtx *de_ctx,
96+
DetectEngineThreadCtx *det_ctx, const DetectEngineAppInspectionEngine *engine,
97+
const Signature *s, Flow *f, uint8_t flags, void *alstate, void *txv, uint64_t tx_id)
98+
{
8099
if (flags & STREAM_TOSERVER) {
81100
FatalError("Should not see TOSERVER data");
82101
}
83102

103+
const DetectEngineTransforms *transforms = NULL;
104+
if (!engine->mpm) {
105+
transforms = engine->v2.transforms;
106+
}
107+
84108
for (uint32_t i = 0;; i++) {
85-
if (!SCDnsTxGetAnswerName(txv, i, &data, &data_len)) {
109+
InspectionBuffer *buffer = GetBuffer(det_ctx, transforms, txv, i, engine->sm_list);
110+
if (buffer == NULL || buffer->inspect == NULL) {
86111
break;
87112
}
88-
ret = DetectEngineContentInspection(de_ctx, det_ctx, s, engine->smd, NULL, f,
89-
(uint8_t *)data, data_len, 0, DETECT_CI_FLAGS_SINGLE,
90-
DETECT_ENGINE_CONTENT_INSPECTION_MODE_STATE);
113+
114+
det_ctx->buffer_offset = 0;
115+
det_ctx->discontinue_matching = 0;
116+
det_ctx->inspection_recursion_counter = 0;
117+
118+
const int match = DetectEngineContentInspection(de_ctx, det_ctx, s, engine->smd, NULL, f,
119+
(uint8_t *)buffer->inspect, buffer->inspect_len, buffer->inspect_offset,
120+
DETECT_CI_FLAGS_SINGLE, DETECT_ENGINE_CONTENT_INSPECTION_MODE_STATE);
121+
if (match == 1) {
122+
return DETECT_ENGINE_INSPECT_SIG_MATCH;
123+
}
91124
}
92125

93-
SCLogNotice("Returning %d.", ret);
94-
return ret;
126+
return DETECT_ENGINE_INSPECT_SIG_NO_MATCH;
95127
}
96128

97129
#ifdef UNITTESTS

0 commit comments

Comments
 (0)