|
|
|
|
@ -858,6 +858,114 @@ static int DNSUDPParserTestLostResponse(void)
|
|
|
|
|
PASS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int DNSUDPParserTxCleanup(void)
|
|
|
|
|
{
|
|
|
|
|
uint64_t ret[4];
|
|
|
|
|
|
|
|
|
|
/* DNS request:
|
|
|
|
|
* - Flags: 0x0100 Standard query
|
|
|
|
|
* - A www.google.com
|
|
|
|
|
*/
|
|
|
|
|
uint8_t req[] = {
|
|
|
|
|
0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00,
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x03, 0x77, 0x77, 0x77,
|
|
|
|
|
0x06, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x03,
|
|
|
|
|
0x63, 0x6f, 0x6d, 0x00, 0x00, 0x01, 0x00, 0x01,
|
|
|
|
|
};
|
|
|
|
|
size_t reqlen = sizeof(req);
|
|
|
|
|
|
|
|
|
|
uint8_t res[] = {
|
|
|
|
|
0x00, 0x01, 0x81, 0x80, 0x00, 0x01, 0x00, 0x08,
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x03, 0x77, 0x77, 0x77,
|
|
|
|
|
0x06, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x03,
|
|
|
|
|
0x63, 0x6f, 0x6d, 0x00, 0x00, 0x01, 0x00, 0x01,
|
|
|
|
|
0xc0, 0x0c, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00,
|
|
|
|
|
0x01, 0x08, 0x00, 0x04, 0x18, 0xf4, 0x04, 0x38,
|
|
|
|
|
0xc0, 0x0c, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00,
|
|
|
|
|
0x01, 0x08, 0x00, 0x04, 0x18, 0xf4, 0x04, 0x39,
|
|
|
|
|
0xc0, 0x0c, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00,
|
|
|
|
|
0x01, 0x08, 0x00, 0x04, 0x18, 0xf4, 0x04, 0x34,
|
|
|
|
|
0xc0, 0x0c, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00,
|
|
|
|
|
0x01, 0x08, 0x00, 0x04, 0x18, 0xf4, 0x04, 0x35,
|
|
|
|
|
0xc0, 0x0c, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00,
|
|
|
|
|
0x01, 0x08, 0x00, 0x04, 0x18, 0xf4, 0x04, 0x36,
|
|
|
|
|
0xc0, 0x0c, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00,
|
|
|
|
|
0x01, 0x08, 0x00, 0x04, 0x18, 0xf4, 0x04, 0x3b,
|
|
|
|
|
0xc0, 0x0c, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00,
|
|
|
|
|
0x01, 0x08, 0x00, 0x04, 0x18, 0xf4, 0x04, 0x37,
|
|
|
|
|
0xc0, 0x0c, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00,
|
|
|
|
|
0x01, 0x08, 0x00, 0x04, 0x18, 0xf4, 0x04, 0x3a
|
|
|
|
|
};
|
|
|
|
|
size_t reslen = sizeof(res);
|
|
|
|
|
|
|
|
|
|
Flow *f = UTHBuildFlow(AF_INET, "1.1.1.1", "2.2.2.2", 1024, 53);
|
|
|
|
|
FAIL_IF_NULL(f);
|
|
|
|
|
f->proto = IPPROTO_UDP;
|
|
|
|
|
f->protomap = FlowGetProtoMapping(IPPROTO_UDP);
|
|
|
|
|
f->alproto = ALPROTO_DNS;
|
|
|
|
|
|
|
|
|
|
AppLayerParserThreadCtx *alp_tctx = AppLayerParserThreadCtxAlloc();
|
|
|
|
|
FAIL_IF_NULL(alp_tctx);
|
|
|
|
|
|
|
|
|
|
/* First request. */
|
|
|
|
|
req[1] = 0x01;
|
|
|
|
|
int r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_DNS,
|
|
|
|
|
STREAM_TOSERVER | STREAM_START, req, reqlen);
|
|
|
|
|
FAIL_IF_NOT(r == 0);
|
|
|
|
|
/* Second request. */
|
|
|
|
|
req[1] = 0x02;
|
|
|
|
|
r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_DNS,
|
|
|
|
|
STREAM_TOSERVER, req, reqlen);
|
|
|
|
|
FAIL_IF_NOT(r == 0);
|
|
|
|
|
/* Third request. */
|
|
|
|
|
req[1] = 0x03;
|
|
|
|
|
r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_DNS,
|
|
|
|
|
STREAM_TOSERVER, req, reqlen);
|
|
|
|
|
FAIL_IF_NOT(r == 0);
|
|
|
|
|
|
|
|
|
|
/* Now respond to the second. */
|
|
|
|
|
res[1] = 0x02;
|
|
|
|
|
r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_DNS,
|
|
|
|
|
STREAM_TOCLIENT, res, reslen);
|
|
|
|
|
FAIL_IF_NOT(r == 0);
|
|
|
|
|
|
|
|
|
|
/* Send a 4th request. */
|
|
|
|
|
req[1] = 0x04;
|
|
|
|
|
r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_DNS,
|
|
|
|
|
STREAM_TOSERVER, req, reqlen);
|
|
|
|
|
FAIL_IF_NOT(r == 0);
|
|
|
|
|
|
|
|
|
|
AppLayerParserTransactionsCleanup(f);
|
|
|
|
|
UTHAppLayerParserStateGetIds(f->alparser, &ret[0], &ret[1], &ret[2], &ret[3]);
|
|
|
|
|
FAIL_IF_NOT(ret[0] == 0); // inspect_id[0]
|
|
|
|
|
FAIL_IF_NOT(ret[1] == 0); // inspect_id[1]
|
|
|
|
|
FAIL_IF_NOT(ret[2] == 0); // log_id
|
|
|
|
|
FAIL_IF_NOT(ret[3] == 0); // min_id
|
|
|
|
|
|
|
|
|
|
/* Response to the third request. */
|
|
|
|
|
res[1] = 0x03;
|
|
|
|
|
r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_DNS,
|
|
|
|
|
STREAM_TOCLIENT, res, reslen);
|
|
|
|
|
FAIL_IF_NOT(r == 0);
|
|
|
|
|
DNSState *state = f->alstate;
|
|
|
|
|
DNSTransaction *tx = TAILQ_FIRST(&state->tx_list);
|
|
|
|
|
FAIL_IF_NULL(tx);
|
|
|
|
|
FAIL_IF(tx->replied);
|
|
|
|
|
FAIL_IF(!tx->reply_lost);
|
|
|
|
|
|
|
|
|
|
AppLayerParserTransactionsCleanup(f);
|
|
|
|
|
UTHAppLayerParserStateGetIds(f->alparser, &ret[0], &ret[1], &ret[2], &ret[3]);
|
|
|
|
|
FAIL_IF_NOT(ret[0] == 3); // inspect_id[0]
|
|
|
|
|
FAIL_IF_NOT(ret[1] == 3); // inspect_id[1]
|
|
|
|
|
FAIL_IF_NOT(ret[2] == 3); // log_id
|
|
|
|
|
FAIL_IF_NOT(ret[3] == 3); // min_id
|
|
|
|
|
|
|
|
|
|
/* Also free's state. */
|
|
|
|
|
UTHFreeFlow(f);
|
|
|
|
|
|
|
|
|
|
PASS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DNSUDPParserRegisterTests(void)
|
|
|
|
|
{
|
|
|
|
|
UtRegisterTest("DNSUDPParserTest01", DNSUDPParserTest01);
|
|
|
|
|
@ -870,6 +978,8 @@ void DNSUDPParserRegisterTests(void)
|
|
|
|
|
DNSUDPParserTestDelayedResponse);
|
|
|
|
|
UtRegisterTest("DNSUDPParserTestLostResponse",
|
|
|
|
|
DNSUDPParserTestLostResponse);
|
|
|
|
|
UtRegisterTest("DNSUDPParserTxCleanup",
|
|
|
|
|
DNSUDPParserTxCleanup);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
#endif /* HAVE_RUST */
|
|
|
|
|
|