rust: fix collapsible_match warnings

warning: this `if` can be collapsed into the outer `match`
help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.95.0/index.html#collapsible_match
pull/15329/head
Philippe Antoine 3 months ago committed by Victor Julien
parent 899e9f045e
commit 1cdff9de8e

@ -350,10 +350,8 @@ fn parse_bytemath(input: &str) -> IResult<&str, DetectByteMathData, RuleParseErr
// Using left/right shift further restricts the value of nbytes. Note that // Using left/right shift further restricts the value of nbytes. Note that
// validation has already ensured nbytes is in [1..10] // validation has already ensured nbytes is in [1..10]
match byte_math.oper { match byte_math.oper {
ByteMathOperator::LeftShift | ByteMathOperator::RightShift => { ByteMathOperator::LeftShift | ByteMathOperator::RightShift if byte_math.nbytes > 4 => {
if byte_math.nbytes > 4 { return Err(make_error(format!("nbytes must be 1 through 4 (inclusive) when used with \"<<\" or \">>\"; {} is not valid", byte_math.nbytes)));
return Err(make_error(format!("nbytes must be 1 through 4 (inclusive) when used with \"<<\" or \">>\"; {} is not valid", byte_math.nbytes)));
}
} }
_ => {} _ => {}
}; };

@ -59,14 +59,14 @@ pub fn detect_parse_vlan_id(s: &str) -> Option<DetectUintArrayData<u16>> {
end: a.end, end: a.end,
}); });
} }
DetectUintIndex::Index((_, i)) => { DetectUintIndex::Index((_, i))
if !(-VLAN_MAX_LAYERS..=VLAN_MAX_LAYERS - 1).contains(&i) { if !(-VLAN_MAX_LAYERS..=VLAN_MAX_LAYERS - 1).contains(&i) =>
SCLogError!( {
"vlan id index should belong in range {:?}", SCLogError!(
(-VLAN_MAX_LAYERS..=VLAN_MAX_LAYERS - 1) "vlan id index should belong in range {:?}",
); (-VLAN_MAX_LAYERS..=VLAN_MAX_LAYERS - 1)
return None; );
} return None;
} }
_ => {} _ => {}
} }

@ -32,10 +32,8 @@ fn get_type(tx: &DHCPTransaction) -> Option<u8> {
{ {
#[allow(clippy::single_match)] #[allow(clippy::single_match)]
match code { match code {
DHCP_OPT_TYPE => { DHCP_OPT_TYPE if !option.data.is_empty() => {
if !option.data.is_empty() { return Some(option.data[0]);
return Some(option.data[0]);
}
} }
_ => {} _ => {}
} }
@ -90,15 +88,11 @@ fn log(extended: bool, tx: &DHCPTransaction, js: &mut JsonBuilder) -> Result<(),
js.set_string("client_id", &format_addr_hex(&clientid.data))?; js.set_string("client_id", &format_addr_hex(&clientid.data))?;
} }
DHCPOptionWrapper::TimeValue(ref time_value) => match code { DHCPOptionWrapper::TimeValue(ref time_value) => match code {
DHCP_OPT_ADDRESS_TIME => { DHCP_OPT_ADDRESS_TIME if extended => {
if extended { js.set_uint("lease_time", time_value.seconds as u64)?;
js.set_uint("lease_time", time_value.seconds as u64)?;
}
} }
DHCP_OPT_REBINDING_TIME => { DHCP_OPT_REBINDING_TIME if extended => {
if extended { js.set_uint("rebinding_time", time_value.seconds as u64)?;
js.set_uint("rebinding_time", time_value.seconds as u64)?;
}
} }
DHCP_OPT_RENEWAL_TIME => { DHCP_OPT_RENEWAL_TIME => {
js.set_uint("renewal_time", time_value.seconds as u64)?; js.set_uint("renewal_time", time_value.seconds as u64)?;
@ -106,43 +100,29 @@ fn log(extended: bool, tx: &DHCPTransaction, js: &mut JsonBuilder) -> Result<(),
_ => {} _ => {}
}, },
DHCPOptionWrapper::Generic(ref option) => match code { DHCPOptionWrapper::Generic(ref option) => match code {
DHCP_OPT_SUBNET_MASK => { DHCP_OPT_SUBNET_MASK if extended => {
if extended { js.set_string("subnet_mask", &dns_print_addr(&option.data))?;
js.set_string("subnet_mask", &dns_print_addr(&option.data))?;
}
} }
DHCP_OPT_HOSTNAME => { DHCP_OPT_HOSTNAME if !option.data.is_empty() => {
if !option.data.is_empty() { js.set_string_from_bytes("hostname", &option.data)?;
js.set_string_from_bytes("hostname", &option.data)?;
}
} }
DHCP_OPT_TYPE => { DHCP_OPT_TYPE => {
log_opt_type(js, option)?; log_opt_type(js, option)?;
} }
DHCP_OPT_REQUESTED_IP => { DHCP_OPT_REQUESTED_IP if extended => {
if extended { js.set_string("requested_ip", &dns_print_addr(&option.data))?;
js.set_string("requested_ip", &dns_print_addr(&option.data))?;
}
} }
DHCP_OPT_PARAMETER_LIST => { DHCP_OPT_PARAMETER_LIST if extended => {
if extended { log_opt_parameters(js, option)?;
log_opt_parameters(js, option)?;
}
} }
DHCP_OPT_DNS_SERVER => { DHCP_OPT_DNS_SERVER if extended => {
if extended { log_opt_dns_server(js, option)?;
log_opt_dns_server(js, option)?;
}
} }
DHCP_OPT_ROUTERS => { DHCP_OPT_ROUTERS if extended => {
if extended { log_opt_routers(js, option)?;
log_opt_routers(js, option)?;
}
} }
DHCP_OPT_VENDOR_CLASS_ID => { DHCP_OPT_VENDOR_CLASS_ID if extended && !option.data.is_empty() => {
if extended && !option.data.is_empty() { js.set_string_from_bytes("vendor_class_identifier", &option.data)?;
js.set_string_from_bytes("vendor_class_identifier", &option.data)?;
}
} }
_ => {} _ => {}
}, },

@ -38,9 +38,10 @@ use std::os::raw::{c_char, c_int, c_void};
use std::ptr; use std::ptr;
use suricata_sys::sys::{ use suricata_sys::sys::{
DetectEngineCtx, DetectEngineThreadCtx, SCDetectBufferSetActiveList, DetectEngineCtx, DetectEngineThreadCtx, SCDetectBufferSetActiveList,
SCDetectHelperBufferMpmRegister, SCDetectHelperBufferProgressRegister, SCDetectHelperKeywordRegister, SCDetectHelperBufferMpmRegister, SCDetectHelperBufferProgressRegister,
SCDetectHelperMultiBufferMpmRegister, SCDetectSignatureSetAppProto, SCSigMatchAppendSMToList, SCDetectHelperKeywordRegister, SCDetectHelperMultiBufferMpmRegister,
SCSigTableAppLiteElmt, SigMatchCtx, Signature, SCDetectSignatureSetAppProto, SCSigMatchAppendSMToList, SCSigTableAppLiteElmt, SigMatchCtx,
Signature,
}; };
unsafe extern "C" fn ike_get_nonce_data( unsafe extern "C" fn ike_get_nonce_data(
@ -191,37 +192,29 @@ unsafe extern "C" fn ike_detect_chosen_sa_match(
} else if tx.ike_version == 2 { } else if tx.ike_version == 2 {
for attr in tx.hdr.ikev2_transforms.iter() { for attr in tx.hdr.ikev2_transforms.iter() {
match attr { match attr {
IkeV2Transform::Encryption(e) => { IkeV2Transform::Encryption(e) if ctx.attribute == AttributeType::AlgEnc => {
if ctx.attribute == AttributeType::AlgEnc { if detect_match_uint(&ctx.value, e.0.into()) {
if detect_match_uint(&ctx.value, e.0.into()) { return 1;
return 1;
}
return 0;
} }
return 0;
} }
IkeV2Transform::Auth(e) => { IkeV2Transform::Auth(e) if ctx.attribute == AttributeType::AlgAuth => {
if ctx.attribute == AttributeType::AlgAuth { if detect_match_uint(&ctx.value, e.0.into()) {
if detect_match_uint(&ctx.value, e.0.into()) { return 1;
return 1;
}
return 0;
} }
return 0;
} }
IkeV2Transform::PRF(ref e) => { IkeV2Transform::PRF(ref e) if ctx.attribute == AttributeType::AlgPrf => {
if ctx.attribute == AttributeType::AlgPrf { if detect_match_uint(&ctx.value, e.0.into()) {
if detect_match_uint(&ctx.value, e.0.into()) { return 1;
return 1;
}
return 0;
} }
return 0;
} }
IkeV2Transform::DH(ref e) => { IkeV2Transform::DH(ref e) if ctx.attribute == AttributeType::AlgDh => {
if ctx.attribute == AttributeType::AlgDh { if detect_match_uint(&ctx.value, e.0.into()) {
if detect_match_uint(&ctx.value, e.0.into()) { return 1;
return 1;
}
return 0;
} }
return 0;
} }
_ => (), _ => (),
} }
@ -326,10 +319,12 @@ unsafe extern "C" fn ike_detect_nonce_payload_length_match(
) -> c_int { ) -> c_int {
let tx = cast_pointer!(tx, IKETransaction); let tx = cast_pointer!(tx, IKETransaction);
let ctx = cast_pointer!(ctx, DetectUintData<u32>); let ctx = cast_pointer!(ctx, DetectUintData<u32>);
if tx.ike_version == 1 && !tx.hdr.ikev1_header.nonce.is_empty() if tx.ike_version == 1
&& detect_match_uint(ctx, tx.hdr.ikev1_header.nonce.len() as u32) { && !tx.hdr.ikev1_header.nonce.is_empty()
return 1; && detect_match_uint(ctx, tx.hdr.ikev1_header.nonce.len() as u32)
} {
return 1;
}
return 0; return 0;
} }
@ -371,10 +366,12 @@ unsafe extern "C" fn ike_detect_payload_len_match(
) -> c_int { ) -> c_int {
let tx = cast_pointer!(tx, IKETransaction); let tx = cast_pointer!(tx, IKETransaction);
let ctx = cast_pointer!(ctx, DetectUintData<u32>); let ctx = cast_pointer!(ctx, DetectUintData<u32>);
if tx.ike_version == 1 && !tx.hdr.ikev1_header.key_exchange.is_empty() if tx.ike_version == 1
&& detect_match_uint(ctx, tx.hdr.ikev1_header.key_exchange.len() as u32) { && !tx.hdr.ikev1_header.key_exchange.is_empty()
return 1; && detect_match_uint(ctx, tx.hdr.ikev1_header.key_exchange.len() as u32)
} {
return 1;
}
return 0; return 0;
} }

@ -374,17 +374,13 @@ impl NFSState {
SCLogDebug!("OPENv4: status {} opendata {:?}", _s, _rd); SCLogDebug!("OPENv4: status {} opendata {:?}", _s, _rd);
insert_filename_with_getfh = true; insert_filename_with_getfh = true;
} }
Nfs4ResponseContent::GetFH(_s, Some(ref rd)) => { Nfs4ResponseContent::GetFH(_s, Some(ref rd)) if insert_filename_with_getfh => {
if insert_filename_with_getfh { self.namemap
self.namemap .insert(rd.value.to_vec(), xidmap.file_name.to_vec());
.insert(rd.value.to_vec(), xidmap.file_name.to_vec());
}
} }
Nfs4ResponseContent::PutRootFH(s) => { Nfs4ResponseContent::PutRootFH(s) if s == NFS4_OK && xidmap.file_name.is_empty() => {
if s == NFS4_OK && xidmap.file_name.is_empty() {
xidmap.file_name = b"<mount_root>".to_vec(); xidmap.file_name = b"<mount_root>".to_vec();
SCLogDebug!("filename {:?}", xidmap.file_name); SCLogDebug!("filename {:?}", xidmap.file_name);
}
} }
_ => {} _ => {}
} }

Loading…
Cancel
Save