suricata
detect-dns-rrtype.c
Go to the documentation of this file.
1 /* Copyright (C) 2024 Open Information Security Foundation
2  *
3  * You can copy, redistribute or modify this Program under the terms of
4  * the GNU General Public License version 2 as published by the Free
5  * Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * version 2 along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15  * 02110-1301, USA.
16  */
17 
18 #include "suricata-common.h"
19 
20 #include "detect-parse.h"
21 #include "detect-engine.h"
22 #include "detect-dns-rrtype.h"
23 #include "rust.h"
24 #include "detect-engine-uint.h"
25 
26 static int dns_rrtype_list_id = 0;
27 
28 static void DetectDnsRrtypeFree(DetectEngineCtx *, void *ptr);
29 
30 static int DetectDnsRrtypeSetup(DetectEngineCtx *de_ctx, Signature *s, const char *str)
31 {
32  SCEnter();
33 
35  SCReturnInt(-1);
36  }
37 
38  void *detect = DetectU16Parse(str);
39  if (detect == NULL) {
40  SCLogError("failed to parse dns.rrtype: %s", str);
41  SCReturnInt(-1);
42  }
43 
45  dns_rrtype_list_id) == NULL) {
46  DetectDnsRrtypeFree(de_ctx, detect);
47  SCReturnInt(-1);
48  }
49 
50  SCReturnInt(0);
51 }
52 
53 static void DetectDnsRrtypeFree(DetectEngineCtx *de_ctx, void *ptr)
54 {
55  SCEnter();
56  if (ptr != NULL) {
57  rs_detect_u16_free(ptr);
58  }
59  SCReturn;
60 }
61 
62 static int DetectDnsRrtypeMatch(DetectEngineThreadCtx *det_ctx, Flow *f, uint8_t flags, void *state,
63  void *txv, const Signature *s, const SigMatchCtx *ctx)
64 {
65  return SCDnsDetectRrtypeMatch(txv, (void *)ctx, flags);
66 }
67 
69 {
71  sigmatch_table[DETECT_AL_DNS_RRTYPE].desc = "Match the DNS rrtype in message body.";
72  sigmatch_table[DETECT_AL_DNS_RRTYPE].url = "/rules/dns-keywords.html#dns-rrtype";
73  sigmatch_table[DETECT_AL_DNS_RRTYPE].Setup = DetectDnsRrtypeSetup;
74  sigmatch_table[DETECT_AL_DNS_RRTYPE].Free = DetectDnsRrtypeFree;
76  sigmatch_table[DETECT_AL_DNS_RRTYPE].AppLayerTxMatch = DetectDnsRrtypeMatch;
77 
80 
83 
84  dns_rrtype_list_id = DetectBufferTypeGetByName("dns.rrtype");
85 }
detect-engine-uint.h
SigTableElmt_::url
const char * url
Definition: detect.h:1322
DetectSignatureSetAppProto
int DetectSignatureSetAppProto(Signature *s, AppProto alproto)
Definition: detect-parse.c:1737
detect-engine.h
SigTableElmt_::desc
const char * desc
Definition: detect.h:1321
sigmatch_table
SigTableElmt * sigmatch_table
Definition: detect-parse.c:127
SigTableElmt_::Free
void(* Free)(DetectEngineCtx *, void *)
Definition: detect.h:1309
ALPROTO_DNS
@ ALPROTO_DNS
Definition: app-layer-protos.h:41
SigTableElmt_::name
const char * name
Definition: detect.h:1319
Flow_
Flow data structure.
Definition: flow.h:360
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:850
SigTableElmt_::AppLayerTxMatch
int(* AppLayerTxMatch)(DetectEngineThreadCtx *, Flow *, uint8_t flags, void *alstate, void *txv, const Signature *, const SigMatchCtx *)
Definition: detect.h:1290
rust.h
SIG_FLAG_TOCLIENT
#define SIG_FLAG_TOCLIENT
Definition: detect.h:268
SigTableElmt_::Setup
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
Definition: detect.h:1304
DetectDnsRrtypeRegister
void DetectDnsRrtypeRegister(void)
Definition: detect-dns-rrtype.c:68
DetectBufferTypeGetByName
int DetectBufferTypeGetByName(const char *name)
Definition: detect-engine.c:1086
SIG_FLAG_TOSERVER
#define SIG_FLAG_TOSERVER
Definition: detect.h:267
de_ctx
DetectEngineCtx * de_ctx
Definition: fuzz_siginit.c:17
DetectEngineThreadCtx_
Definition: detect.h:1106
SCEnter
#define SCEnter(...)
Definition: util-debug.h:271
SCReturn
#define SCReturn
Definition: util-debug.h:273
SigTableElmt_::Match
int(* Match)(DetectEngineThreadCtx *, Packet *, const Signature *, const SigMatchCtx *)
Definition: detect.h:1287
DETECT_AL_DNS_RRTYPE
@ DETECT_AL_DNS_RRTYPE
Definition: detect-engine-register.h:235
SigMatchCtx_
Used to start a pointer to SigMatch context Should never be dereferenced without casting to something...
Definition: detect.h:347
flags
uint8_t flags
Definition: decode-gre.h:0
DetectU16Parse
DetectUintData_u16 * DetectU16Parse(const char *u16str)
This function is used to parse u16 options passed via some u16 keyword.
Definition: detect-engine-uint.c:121
suricata-common.h
detect-dns-rrtype.h
DetectEngineInspectGenericList
uint8_t DetectEngineInspectGenericList(DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, const struct DetectEngineAppInspectionEngine_ *engine, const Signature *s, Flow *f, uint8_t flags, void *alstate, void *txv, uint64_t tx_id)
Do the content inspection & validation for a signature.
Definition: detect-engine.c:2093
str
#define str(s)
Definition: suricata-common.h:291
SCLogError
#define SCLogError(...)
Macro used to log ERROR messages.
Definition: util-debug.h:261
detect-parse.h
Signature_
Signature container.
Definition: detect.h:604
DetectAppLayerInspectEngineRegister
void DetectAppLayerInspectEngineRegister(const char *name, AppProto alproto, uint32_t dir, int progress, InspectEngineFuncPtr Callback, InspectionBufferGetDataPtr GetData)
Registers an app inspection engine.
Definition: detect-engine.c:233
SigMatchAppendSMToList
SigMatch * SigMatchAppendSMToList(DetectEngineCtx *de_ctx, Signature *s, uint16_t type, SigMatchCtx *ctx, const int list)
Append a SigMatch to the list type.
Definition: detect-parse.c:436
SCReturnInt
#define SCReturnInt(x)
Definition: util-debug.h:275