Go to the documentation of this file.
45 #define PARSE_REGEX "^\\s*(!?\\s*[0-9]{1,3}|!?\\s*[xX][0-9a-fA-F]{1,2})\\s*$"
53 static void DetectTosRegisterTests(
void);
57 #define DETECT_IPTOS_MIN 0
58 #define DETECT_IPTOS_MAX 255
76 "/rules/header-keywords.html#tos";
99 if (!PacketIsIPv4(
p)) {
103 const IPV4Hdr *ip4h = PacketGetIPv4(
p);
109 return (tosd->
negated ^ result);
112 static DetectTosData *DetectTosParse(
const char *arg,
bool negate)
117 pcre2_match_data *match = NULL;
121 "The tos option value must be in the range "
128 char tosbytes_str[64] =
"";
129 pcre2len =
sizeof(tosbytes_str);
130 int res = pcre2_substring_copy_bynumber(match, 1, (PCRE2_UCHAR8 *)tosbytes_str, &pcre2len);
132 SCLogError(
"pcre2_substring_copy_bynumber failed");
138 if (tosbytes_str[0] ==
'x' || tosbytes_str[0] ==
'X') {
150 "%s. The tos option value must be in the range "
159 tosd->
tos = (uint8_t)tos;
162 pcre2_match_data_free(match);
167 pcre2_match_data_free(match);
191 DetectTosFree(
de_ctx, tosd);
212 static int DetectTosTest01(
void)
215 tosd = DetectTosParse(
"12",
false);
216 if (tosd != NULL && tosd->
tos == 12 && !tosd->
negated) {
217 DetectTosFree(NULL, tosd);
224 static int DetectTosTest02(
void)
227 tosd = DetectTosParse(
"123",
false);
228 if (tosd != NULL && tosd->
tos == 123 && !tosd->
negated) {
229 DetectTosFree(NULL, tosd);
236 static int DetectTosTest04(
void)
239 tosd = DetectTosParse(
"256",
false);
241 DetectTosFree(NULL, tosd);
248 static int DetectTosTest05(
void)
251 tosd = DetectTosParse(
"boom",
false);
253 DetectTosFree(NULL, tosd);
260 static int DetectTosTest06(
void)
263 tosd = DetectTosParse(
"x12",
false);
264 if (tosd != NULL && tosd->
tos == 0x12 && !tosd->
negated) {
265 DetectTosFree(NULL, tosd);
272 static int DetectTosTest07(
void)
275 tosd = DetectTosParse(
"X12",
false);
276 if (tosd != NULL && tosd->
tos == 0x12 && !tosd->
negated) {
277 DetectTosFree(NULL, tosd);
284 static int DetectTosTest08(
void)
287 tosd = DetectTosParse(
"x121",
false);
289 DetectTosFree(NULL, tosd);
296 static int DetectTosTest09(
void)
299 tosd = DetectTosParse(
"12",
true);
300 if (tosd != NULL && tosd->
tos == 12 && tosd->
negated) {
301 DetectTosFree(NULL, tosd);
308 static int DetectTosTest10(
void)
311 tosd = DetectTosParse(
"x12",
true);
312 if (tosd != NULL && tosd->
tos == 0x12 && tosd->
negated) {
313 DetectTosFree(NULL, tosd);
320 static int DetectTosTest12(
void)
323 uint8_t *buf = (uint8_t *)
"Hi all!";
324 uint16_t buflen = strlen((
char *)buf);
335 sigs[0]=
"alert ip any any -> any any (msg:\"Testing id 1\"; tos: 10 ; sid:1;)";
336 sigs[1]=
"alert ip any any -> any any (msg:\"Testing id 2\"; tos: ! 10; sid:2;)";
337 sigs[2]=
"alert ip any any -> any any (msg:\"Testing id 3\"; tos:20 ; sid:3;)";
338 sigs[3]=
"alert ip any any -> any any (msg:\"Testing id 3\"; tos:! 20; sid:4;)";
340 uint32_t sid[4] = {1, 2, 3, 4};
342 uint32_t results[1][4] =
355 void DetectTosRegisterTests(
void)
SigTableElmt * sigmatch_table
void(* Free)(DetectEngineCtx *, void *)
#define PKT_IS_PSEUDOPKT(p)
return 1 if the packet is a pseudo packet
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
#define SIGMATCH_QUOTES_OPTIONAL
main detection engine ctx
union PacketL3::Hdrs hdrs
Packet * UTHBuildPacket(uint8_t *payload, uint16_t payload_len, uint8_t ipproto)
UTHBuildPacket is a wrapper that build packets with default ip and port fields.
int DetectParsePcreExec(DetectParseRegex *parse_regex, pcre2_match_data **match, const char *str, int start_offset, int options)
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
#define IPV4_GET_RAW_IPTOS(ip4h)
void DetectSetupParseRegexes(const char *parse_str, DetectParseRegex *detect_parse)
SigMatch * SCSigMatchAppendSMToList(DetectEngineCtx *de_ctx, Signature *s, uint16_t type, SigMatchCtx *ctx, const int list)
Append a SigMatch to the list type.
SignatureInitData * init_data
Data structures and function prototypes for keeping state for the detection engine.
int StringParseInt64(int64_t *res, int base, size_t len, const char *str)
int(* Match)(DetectEngineThreadCtx *, Packet *, const Signature *, const SigMatchCtx *)
Used to start a pointer to SigMatch context Should never be dereferenced without casting to something...
int UTHGenericTest(Packet **pkt, int numpkts, const char *sigs[], uint32_t sids[], uint32_t *results, int numsigs)
UTHGenericTest: function that perform a generic check taking care of as maximum common unittest eleme...
void DetectTosRegister(void)
Register Tos keyword.
#define SCLogError(...)
Macro used to log ERROR messages.
#define SIGMATCH_HANDLE_NEGATION
#define DEBUG_VALIDATE_BUG_ON(exp)
void(* RegisterTests)(void)
#define SIG_FLAG_REQUIRE_PACKET
void UTHFreePackets(Packet **p, int numpkts)
UTHFreePackets: function to release the allocated data from UTHBuildPacket and the packet itself.