From 5c18b7d522588376fb6f91e6ac349e2d5ef48732 Mon Sep 17 00:00:00 2001 From: Philippe Antoine Date: Tue, 20 Jun 2023 16:20:34 +0200 Subject: [PATCH 1/3] detect: adds flow integer keywords Ticket: #6164 flow.pkts_toclient flow.pkts_toserver flow.bytes_toclient flow.bytes_toserver --- doc/userguide/rules/flow-keywords.rst | 83 +++++++- src/Makefile.am | 2 + src/detect-engine-register.c | 5 + src/detect-engine-register.h | 4 + src/detect-flow-pkts.c | 278 ++++++++++++++++++++++++++ src/detect-flow-pkts.h | 26 +++ 6 files changed, 397 insertions(+), 1 deletion(-) create mode 100644 src/detect-flow-pkts.c create mode 100644 src/detect-flow-pkts.h diff --git a/doc/userguide/rules/flow-keywords.rst b/doc/userguide/rules/flow-keywords.rst index bb0269299a19..6d451ce82aab 100644 --- a/doc/userguide/rules/flow-keywords.rst +++ b/doc/userguide/rules/flow-keywords.rst @@ -290,6 +290,7 @@ flow.age -------- Flow age in seconds (integer) +This keyword does not wait for the end of the flow, but will be checked at each packet. Syntax:: @@ -305,4 +306,84 @@ Signature example:: alert tcp any any -> any any (msg:"Flow longer than one hour"; flow.age:>3600; flowbits: isnotset, onehourflow; flowbits: onehourflow, name; sid:1; rev:1;) -In this example, we combine `flow.age` and `flowbits` to get an alert on the first packet after the flow's age is older than one hour. \ No newline at end of file +In this example, we combine `flow.age` and `flowbits` to get an alert on the first packet after the flow's age is older than one hour. + +flow.pkts_toclient +------------------ + +Flow number of packets to client (integer) +This keyword does not wait for the end of the flow, but will be checked at each packet. + +Syntax:: + + flow.pkts_toclient: [op] + +The number of packets can be matched exactly, or compared using the _op_ setting:: + + flow.pkts_toclient:3 # exactly 3 + flow.pkts_toclient:<3 # smaller than 3 + flow.pkts_toclient:>=2 # greater than or equal to 2 + +Signature example:: + + alert ip any any -> any any (msg:"Flow has 20 packets"; flow.pkts_toclient:20; sid:1;) + +flow.pkts_toserver +------------------ + +Flow number of packets to server (integer) +This keyword does not wait for the end of the flow, but will be checked at each packet. + +Syntax:: + + flow.pkts_toserver: [op] + +The number of packets can be matched exactly, or compared using the _op_ setting:: + + flow.pkts_toserver:3 # exactly 3 + flow.pkts_toserver:<3 # smaller than 3 + flow.pkts_toserver:>=2 # greater than or equal to 2 + +Signature example:: + + alert ip any any -> any any (msg:"Flow has 20 packets"; flow.pkts_toserver:20; sid:1;) + +flow.bytes_toclient +------------------- + +Flow number of bytes to client (integer) +This keyword does not wait for the end of the flow, but will be checked at each packet. + +Syntax:: + + flow.bytes_toclient: [op] + +The number of packets can be matched exactly, or compared using the _op_ setting:: + + flow.bytes_toclient:3 # exactly 3 + flow.bytes_toclient:<3 # smaller than 3 + flow.bytes_toclient:>=2 # greater than or equal to 2 + +Signature example:: + + alert ip any any -> any any (msg:"Flow has less than 2000 bytes"; flow.bytes_toclient:<2000; sid:1;) + +flow.bytes_toserver +------------------- + +Flow number of bytes to server (integer) +This keyword does not wait for the end of the flow, but will be checked at each packet. + +Syntax:: + + flow.bytes_toserver: [op] + +The number of packets can be matched exactly, or compared using the _op_ setting:: + + flow.bytes_toserver:3 # exactly 3 + flow.bytes_toserver:<3 # smaller than 3 + flow.bytes_toserver:>=2 # greater than or equal to 2 + +Signature example:: + + alert ip any any -> any any (msg:"Flow has less than 2000 bytes"; flow.bytes_toserver:<2000; sid:1;) \ No newline at end of file diff --git a/src/Makefile.am b/src/Makefile.am index 48a5ce850ce2..c5b2fe52e894 100755 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -166,6 +166,7 @@ noinst_HEADERS = \ detect-flowbits.h \ detect-flow.h \ detect-flow-age.h \ + detect-flow-pkts.h \ detect-flowint.h \ detect-flowvar.h \ detect-fragbits.h \ @@ -777,6 +778,7 @@ libsuricata_c_a_SOURCES = \ detect-flowbits.c \ detect-flow.c \ detect-flow-age.c \ + detect-flow-pkts.c \ detect-flowint.c \ detect-flowvar.c \ detect-fragbits.c \ diff --git a/src/detect-engine-register.c b/src/detect-engine-register.c index df6e4a738ffc..d570510949f4 100644 --- a/src/detect-engine-register.c +++ b/src/detect-engine-register.c @@ -114,6 +114,7 @@ #include "detect-rev.h" #include "detect-flow.h" #include "detect-flow-age.h" +#include "detect-flow-pkts.h" #include "detect-tcp-window.h" #include "detect-ftpbounce.h" #include "detect-isdataat.h" @@ -561,6 +562,10 @@ void SigTableSetup(void) DetectReplaceRegister(); DetectFlowRegister(); DetectFlowAgeRegister(); + DetectFlowPktsToClientRegister(); + DetectFlowPktsToServerRegister(); + DetectFlowBytesToClientRegister(); + DetectFlowBytesToServerRegister(); DetectWindowRegister(); DetectRpcRegister(); DetectFtpbounceRegister(); diff --git a/src/detect-engine-register.h b/src/detect-engine-register.h index 7d6c457ef9b0..24a0e56cce1b 100644 --- a/src/detect-engine-register.h +++ b/src/detect-engine-register.h @@ -110,6 +110,10 @@ enum DetectKeywordId { DETECT_FRAME, DETECT_FLOW_AGE, + DETECT_FLOW_PKTS_TO_CLIENT, + DETECT_FLOW_PKTS_TO_SERVER, + DETECT_FLOW_BYTES_TO_CLIENT, + DETECT_FLOW_BYTES_TO_SERVER, DETECT_AL_TLS_VERSION, DETECT_AL_TLS_SUBJECT, diff --git a/src/detect-flow-pkts.c b/src/detect-flow-pkts.c new file mode 100644 index 000000000000..7066b0b3bbc4 --- /dev/null +++ b/src/detect-flow-pkts.c @@ -0,0 +1,278 @@ +/* Copyright (C) 2023 Open Information Security Foundation + * + * You can copy, redistribute or modify this Program under the terms of + * the GNU General Public License version 2 as published by the Free + * Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * version 2 along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#include "suricata-common.h" +#include "rust.h" +#include "detect-flow-pkts.h" +#include "detect-engine.h" +#include "detect-engine-prefilter.h" +#include "detect-engine-uint.h" +#include "detect-parse.h" + +static int DetectFlowPktsToClientMatch( + DetectEngineThreadCtx *det_ctx, Packet *p, const Signature *s, const SigMatchCtx *ctx) +{ + if (p->flow == NULL) { + return 0; + } + uint32_t nb = p->flow->tosrcpktcnt; + + const DetectU32Data *du32 = (const DetectU32Data *)ctx; + return DetectU32Match(nb, du32); +} + +static void DetectFlowPktsToClientFree(DetectEngineCtx *de_ctx, void *ptr) +{ + rs_detect_u32_free(ptr); +} + +static int DetectFlowPktsToClientSetup(DetectEngineCtx *de_ctx, Signature *s, const char *rawstr) +{ + DetectU32Data *du32 = DetectU32Parse(rawstr); + if (du32 == NULL) + return -1; + + SigMatch *sm = SigMatchAlloc(); + if (sm == NULL) { + DetectFlowPktsToClientFree(de_ctx, du32); + return -1; + } + + sm->type = DETECT_FLOW_PKTS_TO_CLIENT; + sm->ctx = (SigMatchCtx *)du32; + + SigMatchAppendSMToList(s, sm, DETECT_SM_LIST_MATCH); + s->flags |= SIG_FLAG_REQUIRE_PACKET; + + return 0; +} + +static void PrefilterPacketFlowPktsToClientMatch( + DetectEngineThreadCtx *det_ctx, Packet *p, const void *pectx) +{ + const PrefilterPacketHeaderCtx *ctx = pectx; + if (!PrefilterPacketHeaderExtraMatch(ctx, p)) + return; + + DetectU32Data du32; + du32.mode = ctx->v1.u8[0]; + du32.arg1 = ctx->v1.u32[1]; + du32.arg2 = ctx->v1.u32[2]; + if (DetectFlowPktsToClientMatch(det_ctx, p, NULL, (const SigMatchCtx *)&du32)) { + PrefilterAddSids(&det_ctx->pmq, ctx->sigs_array, ctx->sigs_cnt); + } +} + +static int PrefilterSetupFlowPktsToClient(DetectEngineCtx *de_ctx, SigGroupHead *sgh) +{ + return PrefilterSetupPacketHeader(de_ctx, sgh, DETECT_FLOW_PKTS_TO_CLIENT, + PrefilterPacketU32Set, PrefilterPacketU32Compare, PrefilterPacketFlowPktsToClientMatch); +} + +static bool PrefilterFlowPktsToClientIsPrefilterable(const Signature *s) +{ + return PrefilterIsPrefilterableById(s, DETECT_FLOW_PKTS_TO_CLIENT); +} + +void DetectFlowPktsToClientRegister(void) +{ + sigmatch_table[DETECT_FLOW_PKTS_TO_CLIENT].name = "flow.pkts_toclient"; + sigmatch_table[DETECT_FLOW_PKTS_TO_CLIENT].desc = "match flow number of packets to client"; + sigmatch_table[DETECT_FLOW_PKTS_TO_CLIENT].url = "/rules/flow-keywords.html#flow-pkts_toclient"; + sigmatch_table[DETECT_FLOW_PKTS_TO_CLIENT].Match = DetectFlowPktsToClientMatch; + sigmatch_table[DETECT_FLOW_PKTS_TO_CLIENT].Setup = DetectFlowPktsToClientSetup; + sigmatch_table[DETECT_FLOW_PKTS_TO_CLIENT].Free = DetectFlowPktsToClientFree; + sigmatch_table[DETECT_FLOW_PKTS_TO_CLIENT].SupportsPrefilter = + PrefilterFlowPktsToClientIsPrefilterable; + sigmatch_table[DETECT_FLOW_PKTS_TO_CLIENT].SetupPrefilter = PrefilterSetupFlowPktsToClient; +} + +static int DetectFlowPktsToServerMatch( + DetectEngineThreadCtx *det_ctx, Packet *p, const Signature *s, const SigMatchCtx *ctx) +{ + if (p->flow == NULL) { + return 0; + } + uint32_t nb = p->flow->todstpktcnt; + + const DetectU32Data *du32 = (const DetectU32Data *)ctx; + return DetectU32Match(nb, du32); +} + +static void DetectFlowPktsToServerFree(DetectEngineCtx *de_ctx, void *ptr) +{ + rs_detect_u32_free(ptr); +} + +static int DetectFlowPktsToServerSetup(DetectEngineCtx *de_ctx, Signature *s, const char *rawstr) +{ + DetectU32Data *du32 = DetectU32Parse(rawstr); + if (du32 == NULL) + return -1; + + SigMatch *sm = SigMatchAlloc(); + if (sm == NULL) { + DetectFlowPktsToServerFree(de_ctx, du32); + return -1; + } + + sm->type = DETECT_FLOW_PKTS_TO_SERVER; + sm->ctx = (SigMatchCtx *)du32; + + SigMatchAppendSMToList(s, sm, DETECT_SM_LIST_MATCH); + s->flags |= SIG_FLAG_REQUIRE_PACKET; + + return 0; +} + +static void PrefilterPacketFlowPktsToServerMatch( + DetectEngineThreadCtx *det_ctx, Packet *p, const void *pectx) +{ + const PrefilterPacketHeaderCtx *ctx = pectx; + if (!PrefilterPacketHeaderExtraMatch(ctx, p)) + return; + + DetectU32Data du32; + du32.mode = ctx->v1.u8[0]; + du32.arg1 = ctx->v1.u32[1]; + du32.arg2 = ctx->v1.u32[2]; + if (DetectFlowPktsToServerMatch(det_ctx, p, NULL, (const SigMatchCtx *)&du32)) { + PrefilterAddSids(&det_ctx->pmq, ctx->sigs_array, ctx->sigs_cnt); + } +} + +static int PrefilterSetupFlowPktsToServer(DetectEngineCtx *de_ctx, SigGroupHead *sgh) +{ + return PrefilterSetupPacketHeader(de_ctx, sgh, DETECT_FLOW_PKTS_TO_SERVER, + PrefilterPacketU32Set, PrefilterPacketU32Compare, PrefilterPacketFlowPktsToServerMatch); +} + +static bool PrefilterFlowPktsToServerIsPrefilterable(const Signature *s) +{ + return PrefilterIsPrefilterableById(s, DETECT_FLOW_PKTS_TO_SERVER); +} + +void DetectFlowPktsToServerRegister(void) +{ + sigmatch_table[DETECT_FLOW_PKTS_TO_SERVER].name = "flow.pkts_toserver"; + sigmatch_table[DETECT_FLOW_PKTS_TO_SERVER].desc = "match flow number of packets to server"; + sigmatch_table[DETECT_FLOW_PKTS_TO_SERVER].url = "/rules/flow-keywords.html#flow-pkts_toserver"; + sigmatch_table[DETECT_FLOW_PKTS_TO_SERVER].Match = DetectFlowPktsToServerMatch; + sigmatch_table[DETECT_FLOW_PKTS_TO_SERVER].Setup = DetectFlowPktsToServerSetup; + sigmatch_table[DETECT_FLOW_PKTS_TO_SERVER].Free = DetectFlowPktsToServerFree; + sigmatch_table[DETECT_FLOW_PKTS_TO_SERVER].SupportsPrefilter = + PrefilterFlowPktsToServerIsPrefilterable; + sigmatch_table[DETECT_FLOW_PKTS_TO_SERVER].SetupPrefilter = PrefilterSetupFlowPktsToServer; +} + +static int DetectFlowBytesToClientMatch( + DetectEngineThreadCtx *det_ctx, Packet *p, const Signature *s, const SigMatchCtx *ctx) +{ + if (p->flow == NULL) { + return 0; + } + uint64_t nb = p->flow->tosrcbytecnt; + + const DetectU64Data *du64 = (const DetectU64Data *)ctx; + return DetectU64Match(nb, du64); +} + +static void DetectFlowBytesToClientFree(DetectEngineCtx *de_ctx, void *ptr) +{ + rs_detect_u64_free(ptr); +} + +static int DetectFlowBytesToClientSetup(DetectEngineCtx *de_ctx, Signature *s, const char *rawstr) +{ + DetectU64Data *du64 = DetectU64Parse(rawstr); + if (du64 == NULL) + return -1; + + SigMatch *sm = SigMatchAlloc(); + if (sm == NULL) { + DetectFlowBytesToClientFree(de_ctx, du64); + return -1; + } + + sm->type = DETECT_FLOW_BYTES_TO_CLIENT; + sm->ctx = (SigMatchCtx *)du64; + + SigMatchAppendSMToList(s, sm, DETECT_SM_LIST_MATCH); + s->flags |= SIG_FLAG_REQUIRE_PACKET; + + return 0; +} + +void DetectFlowBytesToClientRegister(void) +{ + sigmatch_table[DETECT_FLOW_BYTES_TO_CLIENT].name = "flow.bytes_toclient"; + sigmatch_table[DETECT_FLOW_BYTES_TO_CLIENT].desc = "match flow number of bytes to client"; + sigmatch_table[DETECT_FLOW_BYTES_TO_CLIENT].url = + "/rules/flow-keywords.html#flow-bytes_toclient"; + sigmatch_table[DETECT_FLOW_BYTES_TO_CLIENT].Match = DetectFlowBytesToClientMatch; + sigmatch_table[DETECT_FLOW_BYTES_TO_CLIENT].Setup = DetectFlowBytesToClientSetup; + sigmatch_table[DETECT_FLOW_BYTES_TO_CLIENT].Free = DetectFlowBytesToClientFree; +} + +static int DetectFlowBytesToServerMatch( + DetectEngineThreadCtx *det_ctx, Packet *p, const Signature *s, const SigMatchCtx *ctx) +{ + if (p->flow == NULL) { + return 0; + } + uint64_t nb = p->flow->todstbytecnt; + + const DetectU64Data *du64 = (const DetectU64Data *)ctx; + return DetectU64Match(nb, du64); +} + +static void DetectFlowBytesToServerFree(DetectEngineCtx *de_ctx, void *ptr) +{ + rs_detect_u64_free(ptr); +} + +static int DetectFlowBytesToServerSetup(DetectEngineCtx *de_ctx, Signature *s, const char *rawstr) +{ + DetectU64Data *du64 = DetectU64Parse(rawstr); + if (du64 == NULL) + return -1; + + SigMatch *sm = SigMatchAlloc(); + if (sm == NULL) { + DetectFlowBytesToServerFree(de_ctx, du64); + return -1; + } + + sm->type = DETECT_FLOW_BYTES_TO_SERVER; + sm->ctx = (SigMatchCtx *)du64; + + SigMatchAppendSMToList(s, sm, DETECT_SM_LIST_MATCH); + s->flags |= SIG_FLAG_REQUIRE_PACKET; + + return 0; +} + +void DetectFlowBytesToServerRegister(void) +{ + sigmatch_table[DETECT_FLOW_BYTES_TO_SERVER].name = "flow.bytes_toserver"; + sigmatch_table[DETECT_FLOW_BYTES_TO_SERVER].desc = "match flow number of bytes to server"; + sigmatch_table[DETECT_FLOW_BYTES_TO_SERVER].url = + "/rules/flow-keywords.html#flow-bytes_toserver"; + sigmatch_table[DETECT_FLOW_BYTES_TO_SERVER].Match = DetectFlowBytesToServerMatch; + sigmatch_table[DETECT_FLOW_BYTES_TO_SERVER].Setup = DetectFlowBytesToServerSetup; + sigmatch_table[DETECT_FLOW_BYTES_TO_SERVER].Free = DetectFlowBytesToServerFree; +} diff --git a/src/detect-flow-pkts.h b/src/detect-flow-pkts.h new file mode 100644 index 000000000000..ddc5cd172b2b --- /dev/null +++ b/src/detect-flow-pkts.h @@ -0,0 +1,26 @@ +/* Copyright (C) 2023 Open Information Security Foundation + * + * You can copy, redistribute or modify this Program under the terms of + * the GNU General Public License version 2 as published by the Free + * Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * version 2 along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#ifndef __DETECT_FLOW_PKTS_H__ +#define __DETECT_FLOW_PKTS_H__ + +void DetectFlowPktsToClientRegister(void); +void DetectFlowPktsToServerRegister(void); +void DetectFlowBytesToClientRegister(void); +void DetectFlowBytesToServerRegister(void); + +#endif /* __DETECT_FLOW_PKTS_H__ */ From 08721d59570eb7cd8a892e0c8b28b9be0bfd2ec5 Mon Sep 17 00:00:00 2001 From: Philippe Antoine Date: Wed, 30 Aug 2023 11:24:24 +0200 Subject: [PATCH 2/3] rust: fix clippy warnings for version 1.72.0 --- rust/src/applayer.rs | 2 +- rust/src/detect/byte_math.rs | 4 ++-- rust/src/detect/iprep.rs | 2 +- rust/src/ffi/base64.rs | 2 +- rust/src/pgsql/parser.rs | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/rust/src/applayer.rs b/rust/src/applayer.rs index 33fa83a92d00..255fa1593c2b 100644 --- a/rust/src/applayer.rs +++ b/rust/src/applayer.rs @@ -44,7 +44,7 @@ impl StreamSlice { #[cfg(test)] pub fn from_slice(slice: &[u8], flags: u8, offset: u64) -> Self { Self { - input: slice.as_ptr() as *const u8, + input: slice.as_ptr(), input_len: slice.len() as u32, flags, offset diff --git a/rust/src/detect/byte_math.rs b/rust/src/detect/byte_math.rs index 0cc60e52bfd7..80bd3d5ee178 100644 --- a/rust/src/detect/byte_math.rs +++ b/rust/src/detect/byte_math.rs @@ -432,7 +432,7 @@ pub unsafe extern "C" fn ScByteMathParse(c_arg: *const c_char) -> *mut DetectByt } }; match parse_bytemath(arg) { - Ok((_, detect)) => return Box::into_raw(Box::new(detect)) as *mut DetectByteMathData, + Ok((_, detect)) => return Box::into_raw(Box::new(detect)), Err(_) => return std::ptr::null_mut(), } } @@ -440,7 +440,7 @@ pub unsafe extern "C" fn ScByteMathParse(c_arg: *const c_char) -> *mut DetectByt #[no_mangle] pub unsafe extern "C" fn ScByteMathFree(ptr: *mut DetectByteMathData) { if !ptr.is_null() { - let _ = Box::from_raw(ptr as *mut DetectByteMathData); + let _ = Box::from_raw(ptr); } } diff --git a/rust/src/detect/iprep.rs b/rust/src/detect/iprep.rs index 4018ea97a45e..a2042325ec26 100644 --- a/rust/src/detect/iprep.rs +++ b/rust/src/detect/iprep.rs @@ -84,7 +84,7 @@ pub fn detect_parse_iprep(i: &str) -> IResult<&str, DetectIPRepData> { let (i, name) = take_while(is_alphanumeric_or_slash)(i)?; // copy as to have final zero let namez = CString::new(name).unwrap(); - let cat = unsafe { SRepCatGetByShortname(namez.as_ptr() as *const i8) }; + let cat = unsafe { SRepCatGetByShortname(namez.as_ptr()) }; if cat == 0 { return Err(Err::Error(make_error(i, ErrorKind::MapOpt))); } diff --git a/rust/src/ffi/base64.rs b/rust/src/ffi/base64.rs index 0019a6ff2b6f..ea72a344c393 100644 --- a/rust/src/ffi/base64.rs +++ b/rust/src/ffi/base64.rs @@ -46,7 +46,7 @@ pub unsafe extern "C" fn Base64Encode( if encoded.len() + 1 > *output_len as usize { return Base64ReturnCode::SC_BASE64_OVERFLOW; } - let output = std::slice::from_raw_parts_mut(&mut *(output as *mut u8), *output_len as usize); + let output = std::slice::from_raw_parts_mut(&mut *output, *output_len as usize); output[0..encoded.len()].copy_from_slice(encoded.as_bytes()); output[encoded.len()] = 0; *output_len = encoded.len() as c_ulong; diff --git a/rust/src/pgsql/parser.rs b/rust/src/pgsql/parser.rs index bb1a9ea09e35..ae07d5d5a078 100644 --- a/rust/src/pgsql/parser.rs +++ b/rust/src/pgsql/parser.rs @@ -593,7 +593,7 @@ pub fn pgsql_parse_startup_packet(i: &[u8]) -> IResult<&[u8], PgsqlFEMessage> { let (i, b) = take(len - PGSQL_LENGTH_FIELD)(i)?; let (_, message) = match proto_major { - 1 | 2 | 3 => { + 1..=3 => { let (b, proto_major) = be_u16(b)?; let (b, proto_minor) = be_u16(b)?; let (b, params) = pgsql_parse_startup_parameters(b)?; From 36bfd35367a3f7578141ca32bbd705dc6ee4cca0 Mon Sep 17 00:00:00 2001 From: Philippe Antoine Date: Wed, 30 Aug 2023 11:43:07 +0200 Subject: [PATCH 3/3] rdp: do not use zero-bit bitflag cf https://docs.rs/bitflags/latest/bitflags/#zero-bit-flags As warned by clippy 1.72.0 --- rust/src/rdp/parser.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/rust/src/rdp/parser.rs b/rust/src/rdp/parser.rs index 604d10a19c4d..a8004e290b96 100644 --- a/rust/src/rdp/parser.rs +++ b/rust/src/rdp/parser.rs @@ -160,7 +160,8 @@ pub enum Protocol { // rdp-spec, section 2.2.1.1.1 bitflags! { pub struct ProtocolFlags: u32 { - const PROTOCOL_RDP = Protocol::ProtocolRdp as u32; + //Protocol::ProtocolRdp is 0 as always supported + //and bitflags crate does not like zero-bit flags const PROTOCOL_SSL = Protocol::ProtocolSsl as u32; const PROTOCOL_HYBRID = Protocol::ProtocolHybrid as u32; const PROTOCOL_RDSTLS = Protocol::ProtocolRdsTls as u32; @@ -1089,7 +1090,7 @@ mod tests_negotiate_49350 { cookie: None, negotiation_request: Some(NegotiationRequest { flags: NegotiationRequestFlags::empty(), - protocols: ProtocolFlags::PROTOCOL_RDP, + protocols: ProtocolFlags { bits: Protocol::ProtocolRdp as u32 }, }), data: Vec::new(), }), @@ -1179,7 +1180,7 @@ mod tests_core_49350 { ), client_dig_product_id: Some(String::from("")), connection_hint: Some(ConnectionHint::ConnectionHintNotProvided), - server_selected_protocol: Some(ProtocolFlags::PROTOCOL_RDP), + server_selected_protocol: Some(ProtocolFlags { bits: Protocol::ProtocolRdp as u32 }), desktop_physical_width: None, desktop_physical_height: None, desktop_orientation: None,