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
// validation has already ensured nbytes is in [1..10]
match byte_math.oper {
ByteMathOperator::LeftShift | ByteMathOperator::RightShift => {
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)));
}
ByteMathOperator::LeftShift | ByteMathOperator::RightShift 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)));
}
_ => {}
};

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

@ -32,10 +32,8 @@ fn get_type(tx: &DHCPTransaction) -> Option<u8> {
{
#[allow(clippy::single_match)]
match code {
DHCP_OPT_TYPE => {
if !option.data.is_empty() {
return Some(option.data[0]);
}
DHCP_OPT_TYPE if !option.data.is_empty() => {
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))?;
}
DHCPOptionWrapper::TimeValue(ref time_value) => match code {
DHCP_OPT_ADDRESS_TIME => {
if extended {
js.set_uint("lease_time", time_value.seconds as u64)?;
}
DHCP_OPT_ADDRESS_TIME if extended => {
js.set_uint("lease_time", time_value.seconds as u64)?;
}
DHCP_OPT_REBINDING_TIME => {
if extended {
js.set_uint("rebinding_time", time_value.seconds as u64)?;
}
DHCP_OPT_REBINDING_TIME if extended => {
js.set_uint("rebinding_time", time_value.seconds as u64)?;
}
DHCP_OPT_RENEWAL_TIME => {
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 {
DHCP_OPT_SUBNET_MASK => {
if extended {
js.set_string("subnet_mask", &dns_print_addr(&option.data))?;
}
DHCP_OPT_SUBNET_MASK if extended => {
js.set_string("subnet_mask", &dns_print_addr(&option.data))?;
}
DHCP_OPT_HOSTNAME => {
if !option.data.is_empty() {
js.set_string_from_bytes("hostname", &option.data)?;
}
DHCP_OPT_HOSTNAME if !option.data.is_empty() => {
js.set_string_from_bytes("hostname", &option.data)?;
}
DHCP_OPT_TYPE => {
log_opt_type(js, option)?;
}
DHCP_OPT_REQUESTED_IP => {
if extended {
js.set_string("requested_ip", &dns_print_addr(&option.data))?;
}
DHCP_OPT_REQUESTED_IP if extended => {
js.set_string("requested_ip", &dns_print_addr(&option.data))?;
}
DHCP_OPT_PARAMETER_LIST => {
if extended {
log_opt_parameters(js, option)?;
}
DHCP_OPT_PARAMETER_LIST if extended => {
log_opt_parameters(js, option)?;
}
DHCP_OPT_DNS_SERVER => {
if extended {
log_opt_dns_server(js, option)?;
}
DHCP_OPT_DNS_SERVER if extended => {
log_opt_dns_server(js, option)?;
}
DHCP_OPT_ROUTERS => {
if extended {
log_opt_routers(js, option)?;
}
DHCP_OPT_ROUTERS if extended => {
log_opt_routers(js, option)?;
}
DHCP_OPT_VENDOR_CLASS_ID => {
if extended && !option.data.is_empty() {
js.set_string_from_bytes("vendor_class_identifier", &option.data)?;
}
DHCP_OPT_VENDOR_CLASS_ID if extended && !option.data.is_empty() => {
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 suricata_sys::sys::{
DetectEngineCtx, DetectEngineThreadCtx, SCDetectBufferSetActiveList,
SCDetectHelperBufferMpmRegister, SCDetectHelperBufferProgressRegister, SCDetectHelperKeywordRegister,
SCDetectHelperMultiBufferMpmRegister, SCDetectSignatureSetAppProto, SCSigMatchAppendSMToList,
SCSigTableAppLiteElmt, SigMatchCtx, Signature,
SCDetectHelperBufferMpmRegister, SCDetectHelperBufferProgressRegister,
SCDetectHelperKeywordRegister, SCDetectHelperMultiBufferMpmRegister,
SCDetectSignatureSetAppProto, SCSigMatchAppendSMToList, SCSigTableAppLiteElmt, SigMatchCtx,
Signature,
};
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 {
for attr in tx.hdr.ikev2_transforms.iter() {
match attr {
IkeV2Transform::Encryption(e) => {
if ctx.attribute == AttributeType::AlgEnc {
if detect_match_uint(&ctx.value, e.0.into()) {
return 1;
}
return 0;
IkeV2Transform::Encryption(e) if ctx.attribute == AttributeType::AlgEnc => {
if detect_match_uint(&ctx.value, e.0.into()) {
return 1;
}
return 0;
}
IkeV2Transform::Auth(e) => {
if ctx.attribute == AttributeType::AlgAuth {
if detect_match_uint(&ctx.value, e.0.into()) {
return 1;
}
return 0;
IkeV2Transform::Auth(e) if ctx.attribute == AttributeType::AlgAuth => {
if detect_match_uint(&ctx.value, e.0.into()) {
return 1;
}
return 0;
}
IkeV2Transform::PRF(ref e) => {
if ctx.attribute == AttributeType::AlgPrf {
if detect_match_uint(&ctx.value, e.0.into()) {
return 1;
}
return 0;
IkeV2Transform::PRF(ref e) if ctx.attribute == AttributeType::AlgPrf => {
if detect_match_uint(&ctx.value, e.0.into()) {
return 1;
}
return 0;
}
IkeV2Transform::DH(ref e) => {
if ctx.attribute == AttributeType::AlgDh {
if detect_match_uint(&ctx.value, e.0.into()) {
return 1;
}
return 0;
IkeV2Transform::DH(ref e) if ctx.attribute == AttributeType::AlgDh => {
if detect_match_uint(&ctx.value, e.0.into()) {
return 1;
}
return 0;
}
_ => (),
}
@ -326,10 +319,12 @@ unsafe extern "C" fn ike_detect_nonce_payload_length_match(
) -> c_int {
let tx = cast_pointer!(tx, IKETransaction);
let ctx = cast_pointer!(ctx, DetectUintData<u32>);
if tx.ike_version == 1 && !tx.hdr.ikev1_header.nonce.is_empty()
&& detect_match_uint(ctx, tx.hdr.ikev1_header.nonce.len() as u32) {
return 1;
}
if tx.ike_version == 1
&& !tx.hdr.ikev1_header.nonce.is_empty()
&& detect_match_uint(ctx, tx.hdr.ikev1_header.nonce.len() as u32)
{
return 1;
}
return 0;
}
@ -371,10 +366,12 @@ unsafe extern "C" fn ike_detect_payload_len_match(
) -> c_int {
let tx = cast_pointer!(tx, IKETransaction);
let ctx = cast_pointer!(ctx, DetectUintData<u32>);
if tx.ike_version == 1 && !tx.hdr.ikev1_header.key_exchange.is_empty()
&& detect_match_uint(ctx, tx.hdr.ikev1_header.key_exchange.len() as u32) {
return 1;
}
if tx.ike_version == 1
&& !tx.hdr.ikev1_header.key_exchange.is_empty()
&& detect_match_uint(ctx, tx.hdr.ikev1_header.key_exchange.len() as u32)
{
return 1;
}
return 0;
}

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

Loading…
Cancel
Save