31 #include "rust-dns-dns-gen.h" 34 static void RustDNSUDPParserRegisterTests(
void);
37 static int RustDNSUDPParseRequest(
Flow *f,
void *state,
39 void *local_data,
const uint8_t
flags)
41 return rs_dns_parse_request(f, state, pstate, input, input_len,
45 static int RustDNSUDPParseResponse(
Flow *f,
void *state,
47 void *local_data,
const uint8_t
flags)
49 return rs_dns_parse_response(f, state, pstate, input, input_len,
53 static uint16_t DNSUDPProbe(
Flow *f, uint8_t *input, uint32_t
len)
55 if (len == 0 || len <
sizeof(DNSHeader)) {
60 if (!rs_dns_probe(input, len)) {
67 static int RustDNSGetAlstateProgress(
void *tx, uint8_t direction)
69 return rs_dns_tx_get_alstate_progress(tx, direction);
72 static uint64_t RustDNSGetTxCnt(
void *alstate)
74 return rs_dns_state_get_tx_count(alstate);
77 static void *RustDNSGetTx(
void *alstate, uint64_t
tx_id)
79 return rs_dns_state_get_tx(alstate, tx_id);
82 static void RustDNSSetTxLogged(
void *alstate,
void *tx,
LoggerId logged)
84 rs_dns_tx_set_logged(alstate, tx, logged);
87 static LoggerId RustDNSGetTxLogged(
void *alstate,
void *tx)
89 return rs_dns_tx_get_logged(alstate, tx);
92 static void RustDNSStateTransactionFree(
void *state, uint64_t
tx_id)
94 rs_dns_state_tx_free(state, tx_id);
99 return rs_dns_state_get_tx_detect_state(tx);
104 rs_dns_state_set_tx_detect_state(tx, s);
108 static void RustDNSSetDetectFlags(
void *tx, uint8_t dir, uint64_t
flags)
110 rs_dns_tx_set_detect_flags(tx, dir, flags);
113 static uint64_t RustDNSGetDetectFlags(
void *tx, uint8_t dir)
115 return rs_dns_tx_get_detect_flags(tx, dir);
120 return rs_dns_state_get_events(state,
id);
125 const char *proto_name =
"dns";
137 IPPROTO_UDP, proto_name,
ALPROTO_DNS, 0,
sizeof(DNSHeader),
142 #ifndef AFLFUZZ_APPLAYER 144 "enabling DNS detection on port 53.");
152 SCLogInfo(
"Protocol detection and parser disabled for %s protocol.",
159 RustDNSUDPParseRequest);
161 RustDNSUDPParseResponse);
163 rs_dns_state_new, rs_dns_state_free);
165 RustDNSStateTransactionFree);
169 RustDNSGetTxDetectState, RustDNSSetTxDetectState);
171 RustDNSGetDetectFlags, RustDNSSetDetectFlags);
177 RustDNSGetTxLogged, RustDNSSetTxLogged);
179 RustDNSGetAlstateProgress);
182 rs_dns_state_progress_completion_status);
190 SCLogInfo(
"Parsed disabled for %s protocol. Protocol detection" 191 "still on.", proto_name);
195 RustDNSUDPParserRegisterTests);
203 static int RustDNSUDPParserTest01 (
void)
209 uint8_t buf[] = { 0x00, 0x3c, 0x85, 0x00, 0x00, 0x01, 0x00, 0x00,
210 0x00, 0x01, 0x00, 0x00, 0x0b, 0x61, 0x62, 0x63,
211 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b,
212 0x03, 0x63, 0x6f, 0x6d, 0x00, 0x00, 0x0f, 0x00,
213 0x01, 0x00, 0x00, 0x06, 0x00, 0x01, 0x00, 0x01,
214 0x51, 0x80, 0x00, 0x25, 0x02, 0x6e, 0x73, 0x00,
215 0x0a, 0x68, 0x6f, 0x73, 0x74, 0x6d, 0x61, 0x73,
216 0x74, 0x65, 0x72, 0xc0, 0x2f, 0x01, 0x33, 0x2a,
217 0x76, 0x00, 0x00, 0x70, 0x80, 0x00, 0x00, 0x1c,
218 0x20, 0x00, 0x09, 0x3a, 0x80, 0x00, 0x01, 0x51,
220 size_t buflen =
sizeof(buf);
223 f =
UTHBuildFlow(AF_INET,
"1.2.3.4",
"1.2.3.5", 1024, 53);
225 f->
proto = IPPROTO_UDP;
227 f->
alstate = rs_dns_state_new();
237 static int RustDNSUDPParserTest02 (
void)
240 0x6D,0x08,0x84,0x80,0x00,0x01,0x00,0x08,0x00,0x00,0x00,0x01,0x03,0x57,0x57,0x57,
241 0x04,0x54,0x54,0x54,0x54,0x03,0x56,0x56,0x56,0x03,0x63,0x6F,0x6D,0x02,0x79,0x79,
242 0x00,0x00,0x01,0x00,0x01,0xC0,0x0C,0x00,0x05,0x00,0x01,0x00,0x00,0x0E,0x10,0x00,
243 0x02,0xC0,0x0C,0xC0,0x31,0x00,0x05,0x00,0x01,0x00,0x00,0x0E,0x10,0x00,0x02,0xC0,
244 0x31,0xC0,0x3F,0x00,0x05,0x00,0x01,0x00,0x00,0x0E,0x10,0x00,0x02,0xC0,0x3F,0xC0,
245 0x4D,0x00,0x05,0x00,0x01,0x00,0x00,0x0E,0x10,0x00,0x02,0xC0,0x4D,0xC0,0x5B,0x00,
246 0x05,0x00,0x01,0x00,0x00,0x0E,0x10,0x00,0x02,0xC0,0x5B,0xC0,0x69,0x00,0x05,0x00,
247 0x01,0x00,0x00,0x0E,0x10,0x00,0x02,0xC0,0x69,0xC0,0x77,0x00,0x05,0x00,0x01,0x00,
248 0x00,0x0E,0x10,0x00,0x02,0xC0,0x77,0xC0,0x85,0x00,0x05,0x00,0x01,0x00,0x00,0x0E,
249 0x10,0x00,0x02,0xC0,0x85,0x00,0x00,0x29,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
251 size_t buflen =
sizeof(buf);
254 f =
UTHBuildFlow(AF_INET,
"1.2.3.4",
"1.2.3.5", 1024, 53);
256 f->
proto = IPPROTO_UDP;
258 f->
alstate = rs_dns_state_new();
268 static int RustDNSUDPParserTest03 (
void)
271 0x6F,0xB4,0x84,0x80,0x00,0x01,0x00,0x02,0x00,0x02,0x00,0x03,0x03,0x57,0x57,0x77,
272 0x0B,0x56,0x56,0x56,0x56,0x56,0x56,0x56,0x56,0x56,0x56,0x56,0x03,0x55,0x55,0x55,
273 0x02,0x79,0x79,0x00,0x00,0x01,0x00,0x01,0xC0,0x0C,0x00,0x05,0x00,0x01,0x00,0x00,
274 0x0E,0x10,0x00,0x02,0xC0,0x10,0xC0,0x34,0x00,0x01,0x00,0x01,0x00,0x00,0x0E,0x10,
275 0x00,0x04,0xC3,0xEA,0x04,0x19,0xC0,0x34,0x00,0x02,0x00,0x01,0x00,0x00,0x0E,0x10,
276 0x00,0x0A,0x03,0x6E,0x73,0x31,0x03,0x61,0x67,0x62,0xC0,0x20,0xC0,0x46,0x00,0x02,
277 0x00,0x01,0x00,0x00,0x0E,0x10,0x00,0x06,0x03,0x6E,0x73,0x32,0xC0,0x56,0xC0,0x52,
278 0x00,0x01,0x00,0x01,0x00,0x00,0x0E,0x10,0x00,0x04,0xC3,0xEA,0x04,0x0A,0xC0,0x68,
279 0x00,0x01,0x00,0x01,0x00,0x00,0x0E,0x10,0x00,0x04,0xC3,0xEA,0x05,0x14,0x00,0x00,
280 0x29,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00
282 size_t buflen =
sizeof(buf);
285 f =
UTHBuildFlow(AF_INET,
"1.2.3.4",
"1.2.3.5", 1024, 53);
287 f->
proto = IPPROTO_UDP;
289 f->
alstate = rs_dns_state_new();
300 static int RustDNSUDPParserTest04 (
void)
303 0xc2,0x2f,0x81,0x80,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x0a,0x41,0x41,0x41,
304 0x41,0x41,0x4f,0x31,0x6b,0x51,0x41,0x05,0x3d,0x61,0x75,0x74,0x68,0x03,0x73,0x72,
305 0x76,0x06,0x74,0x75,0x6e,0x6e,0x65,0x6c,0x03,0x63,0x6f,0x6d,0x00,0x00,0x10,0x00,
308 0xc0,0x0c,0x00,0x10,0x00,0x01,0x00,0x00,0x00,0x03,0x00,0x22,
310 0x20, 0x41,0x68,0x76,0x4d,0x41,0x41,0x4f,0x31,0x6b,0x41,0x46,
311 0x45,0x35,0x54,0x45,0x39,0x51,0x54,0x6a,0x46,0x46,0x4e,0x30,0x39,0x52,0x4e,0x31,
312 0x6c,0x59,0x53,0x44,0x6b,0x00, 0xc0,0x1d,0x00,0x02,0x00,0x01,
313 0x00,0x09,0x3a,0x80,0x00,0x09,0x06,0x69,0x6f,0x64,0x69,0x6e,0x65,0xc0,0x21,0xc0,
314 0x6b,0x00,0x01,0x00,0x01,0x00,0x09,0x3a,0x80,0x00,0x04,0x0a,0x1e,0x1c,0x5f
316 size_t buflen =
sizeof(buf);
319 f =
UTHBuildFlow(AF_INET,
"1.2.3.4",
"1.2.3.5", 1024, 53);
321 f->
proto = IPPROTO_UDP;
323 f->
alstate = rs_dns_state_new();
334 static int RustDNSUDPParserTest05 (
void)
337 0xc2,0x2f,0x81,0x80,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x0a,0x41,0x41,0x41,
338 0x41,0x41,0x4f,0x31,0x6b,0x51,0x41,0x05,0x3d,0x61,0x75,0x74,0x68,0x03,0x73,0x72,
339 0x76,0x06,0x74,0x75,0x6e,0x6e,0x65,0x6c,0x03,0x63,0x6f,0x6d,0x00,0x00,0x10,0x00,
342 0xc0,0x0c,0x00,0x10,0x00,0x01,0x00,0x00,0x00,0x03,0x00,0x22,
344 0x40, 0x41,0x68,0x76,0x4d,0x41,0x41,0x4f,0x31,0x6b,0x41,0x46,
345 0x45,0x35,0x54,0x45,0x39,0x51,0x54,0x6a,0x46,0x46,0x4e,0x30,0x39,0x52,0x4e,0x31,
346 0x6c,0x59,0x53,0x44,0x6b,0x00, 0xc0,0x1d,0x00,0x02,0x00,0x01,
347 0x00,0x09,0x3a,0x80,0x00,0x09,0x06,0x69,0x6f,0x64,0x69,0x6e,0x65,0xc0,0x21,0xc0,
348 0x6b,0x00,0x01,0x00,0x01,0x00,0x09,0x3a,0x80,0x00,0x04,0x0a,0x1e,0x1c,0x5f
350 size_t buflen =
sizeof(buf);
353 f =
UTHBuildFlow(AF_INET,
"1.2.3.4",
"1.2.3.5", 1024, 53);
355 f->
proto = IPPROTO_UDP;
357 f->
alstate = rs_dns_state_new();
367 static void RustDNSUDPParserRegisterTests(
void)
void AppLayerProtoDetectPPRegister(uint8_t ipproto, const char *portstr, AppProto alproto, uint16_t min_depth, uint16_t max_depth, uint8_t direction, ProbingParserFPtr ProbingParser1, ProbingParserFPtr ProbingParser2)
register parser at a port
void AppLayerParserRegisterGetStateProgressFunc(uint8_t ipproto, AppProto alproto, int(*StateGetProgress)(void *alstate, uint8_t direction))
#define PASS
Pass the test.
int AppLayerProtoDetectConfProtoDetectionEnabled(const char *ipproto, const char *alproto)
Given a protocol name, checks if proto detection is enabled in the conf file.
void AppLayerParserRegisterDetectFlagsFuncs(uint8_t ipproto, AppProto alproto, uint64_t(*GetTxDetectFlags)(void *tx, uint8_t dir), void(*SetTxDetectFlags)(void *tx, uint8_t dir, uint64_t))
void AppLayerParserRegisterDetectStateFuncs(uint8_t ipproto, AppProto alproto, DetectEngineState *(*GetTxDetectState)(void *tx), int(*SetTxDetectState)(void *tx, DetectEngineState *))
void RegisterRustDNSUDPParsers(void)
#define FAIL_IF(expr)
Fail a test if expression evaluates to false.
void AppLayerParserRegisterLoggerFuncs(uint8_t ipproto, AppProto alproto, LoggerId(*StateGetTxLogged)(void *, void *), void(*StateSetTxLogged)(void *, void *, LoggerId))
int AppLayerParserConfParserEnabled(const char *ipproto, const char *alproto_name)
check if a parser is enabled in the config Returns enabled always if: were running unittests and when...
Flow * UTHBuildFlow(int family, const char *src, const char *dst, Port sp, Port dp)
Data structure to store app layer decoder events.
int AppLayerParserRegisterParser(uint8_t ipproto, AppProto alproto, uint8_t direction, AppLayerParserFPtr Parser)
Register app layer parser for the protocol.
void AppLayerParserRegisterGetTx(uint8_t ipproto, AppProto alproto, void *(StateGetTx)(void *alstate, uint64_t tx_id))
int AppLayerProtoDetectPPParseConfPorts(const char *ipproto_name, uint8_t ipproto, const char *alproto_name, AppProto alproto, uint16_t min_depth, uint16_t max_depth, ProbingParserFPtr ProbingParserTs, ProbingParserFPtr ProbingParserTc)
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
void AppLayerParserRegisterGetStateProgressCompletionStatus(AppProto alproto, int(*StateGetProgressCompletionStatus)(uint8_t direction))
int RunmodeIsUnittests(void)
#define SCLogWarning(err_code,...)
Macro used to log WARNING messages.
#define SCLogInfo(...)
Macro used to log INFORMATIONAL messages.
void AppLayerProtoDetectRegisterProtocol(AppProto alproto, const char *alproto_name)
Registers a protocol for protocol detection phase.
void AppLayerParserRegisterGetEventsFunc(uint8_t ipproto, AppProto alproto, AppLayerDecoderEvents *(*StateGetEvents)(void *, uint64_t))
void AppLayerParserRegisterProtocolUnittests(uint8_t ipproto, AppProto alproto, void(*RegisterUnittests)(void))
#define FAIL_IF_NULL(expr)
Fail a test if expression evaluates to NULL.
void AppLayerParserRegisterGetTxCnt(uint8_t ipproto, AppProto alproto, uint64_t(*StateGetTxCnt)(void *alstate))
void AppLayerParserRegisterStateFuncs(uint8_t ipproto, AppProto alproto, void *(*StateAlloc)(void), void(*StateFree)(void *))
AppProto alproto
application level protocol
#define FAIL_IF_NOT(expr)
Fail a test if expression to true.
void UTHFreeFlow(Flow *flow)
void DNSAppLayerRegisterGetEventInfo(uint8_t ipproto, AppProto alproto)
void AppLayerParserRegisterTxFreeFunc(uint8_t ipproto, AppProto alproto, void(*StateTransactionFree)(void *, uint64_t))