suricata
detect-dns-rcode.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-rcode.h"
23 #include "rust.h"
24 #include "detect-engine-uint.h"
25 
26 static int dns_rcode_list_id = 0;
27 
28 static void DetectDnsRcodeFree(DetectEngineCtx *, void *ptr);
29 
30 static int DetectDnsRcodeSetup(DetectEngineCtx *de_ctx, Signature *s, const char *str)
31 {
32  SCEnter();
33 
35  SCReturnInt(-1);
36  }
37 
38  void *detect = DetectU8Parse(str);
39  if (detect == NULL) {
40  SCLogError("failed to parse dns.rcode: %s", str);
41  SCReturnInt(-1);
42  }
43 
45  de_ctx, s, DETECT_AL_DNS_RCODE, (SigMatchCtx *)detect, dns_rcode_list_id) == NULL) {
46  DetectDnsRcodeFree(de_ctx, detect);
47  SCReturnInt(-1);
48  }
49 
50  SCReturnInt(0);
51 }
52 
53 static void DetectDnsRcodeFree(DetectEngineCtx *de_ctx, void *ptr)
54 {
55  SCEnter();
56  if (ptr != NULL) {
57  rs_detect_u8_free(ptr);
58  }
59  SCReturn;
60 }
61 
62 static int DetectDnsRcodeMatch(DetectEngineThreadCtx *det_ctx, Flow *f, uint8_t flags, void *state,
63  void *txv, const Signature *s, const SigMatchCtx *ctx)
64 {
65  return SCDnsDetectRcodeMatch(txv, (void *)ctx, flags);
66 }
67 
69 {
71  sigmatch_table[DETECT_AL_DNS_RCODE].desc = "Match the DNS header rcode flag.";
72  sigmatch_table[DETECT_AL_DNS_RCODE].url = "/rules/dns-keywords.html#dns-rcode";
73  sigmatch_table[DETECT_AL_DNS_RCODE].Setup = DetectDnsRcodeSetup;
74  sigmatch_table[DETECT_AL_DNS_RCODE].Free = DetectDnsRcodeFree;
76  sigmatch_table[DETECT_AL_DNS_RCODE].AppLayerTxMatch = DetectDnsRcodeMatch;
77 
80 
83 
84  dns_rcode_list_id = DetectBufferTypeGetByName("dns.rcode");
85 }
detect-engine-uint.h
SigTableElmt_::url
const char * url
Definition: detect.h:1299
DetectSignatureSetAppProto
int DetectSignatureSetAppProto(Signature *s, AppProto alproto)
Definition: detect-parse.c:1753
detect-engine.h
SigTableElmt_::desc
const char * desc
Definition: detect.h:1298
SigTableElmt_::Free
void(* Free)(DetectEngineCtx *, void *)
Definition: detect.h:1286
ALPROTO_DNS
@ ALPROTO_DNS
Definition: app-layer-protos.h:41
SigTableElmt_::name
const char * name
Definition: detect.h:1296
DnsQueryGetDataArgs::txv
void * txv
Definition: detect-dns-query.c:72
Flow_
Flow data structure.
Definition: flow.h:355
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:839
SigTableElmt_::AppLayerTxMatch
int(* AppLayerTxMatch)(DetectEngineThreadCtx *, Flow *, uint8_t flags, void *alstate, void *txv, const Signature *, const SigMatchCtx *)
Definition: detect.h:1267
rust.h
SIG_FLAG_TOCLIENT
#define SIG_FLAG_TOCLIENT
Definition: detect.h:267
SigTableElmt_::Setup
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
Definition: detect.h:1281
DetectBufferTypeGetByName
int DetectBufferTypeGetByName(const char *name)
Definition: detect-engine.c:1072
DetectU8Parse
DetectUintData_u8 * DetectU8Parse(const char *u8str)
This function is used to parse u8 options passed via some u8 keyword.
Definition: detect-engine-uint.c:85
SIG_FLAG_TOSERVER
#define SIG_FLAG_TOSERVER
Definition: detect.h:266
DetectDnsRcodeRegister
void DetectDnsRcodeRegister(void)
Definition: detect-dns-rcode.c:68
de_ctx
DetectEngineCtx * de_ctx
Definition: fuzz_siginit.c:17
DetectEngineThreadCtx_
Definition: detect.h:1095
SCEnter
#define SCEnter(...)
Definition: util-debug.h:271
DETECT_AL_DNS_RCODE
@ DETECT_AL_DNS_RCODE
Definition: detect-engine-register.h:233
SCReturn
#define SCReturn
Definition: util-debug.h:273
SigTableElmt_::Match
int(* Match)(DetectEngineThreadCtx *, Packet *, const Signature *, const SigMatchCtx *)
Definition: detect.h:1264
SigMatchCtx_
Used to start a pointer to SigMatch context Should never be dereferenced without casting to something...
Definition: detect.h:345
flags
uint8_t flags
Definition: decode-gre.h:0
detect-dns-rcode.h
suricata-common.h
sigmatch_table
SigTableElmt sigmatch_table[DETECT_TBLSIZE]
Definition: detect-parse.c:127
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:2079
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:596
DetectAppLayerInspectEngineRegister
void DetectAppLayerInspectEngineRegister(const char *name, AppProto alproto, uint32_t dir, int progress, InspectEngineFuncPtr Callback, InspectionBufferGetDataPtr GetData)
register inspect engine at start up time
Definition: detect-engine.c:169
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:447
SCReturnInt
#define SCReturnInt(x)
Definition: util-debug.h:275