rust: from_str implementation for EncryptionHandling

To move non-specific quic code to the right place
pull/14618/head
Philippe Antoine 9 months ago committed by Victor Julien
parent 89b6ab6730
commit b0850efd67

@ -23,3 +23,16 @@ pub enum EncryptionHandling {
ENCRYPTION_HANDLING_BYPASS = 1, // Skip processing of flow, bypass if possible
ENCRYPTION_HANDLING_FULL = 2, // Handle fully like any other protocol
}
impl std::str::FromStr for EncryptionHandling {
type Err = ();
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"full" => Ok(EncryptionHandling::ENCRYPTION_HANDLING_FULL),
"track-only" => Ok(EncryptionHandling::ENCRYPTION_HANDLING_TRACK_ONLY),
"bypass" => Ok(EncryptionHandling::ENCRYPTION_HANDLING_BYPASS),
_ => Err(()),
}
}
}

@ -35,6 +35,7 @@ use crate::{
};
use std::collections::VecDeque;
use std::ffi::CString;
use std::str::FromStr;
use suricata_sys::sys::{
AppLayerParserState, AppProto, SCAppLayerParserConfParserEnabled,
SCAppLayerParserRegisterLogger, SCAppLayerParserStateSetFlag,
@ -614,16 +615,11 @@ pub unsafe extern "C" fn SCRegisterQuicParser() {
if SCAppLayerParserConfParserEnabled(ip_proto_str.as_ptr(), parser.name) != 0 {
let _ = AppLayerRegisterParser(&parser, alproto);
if let Some(val) = conf_get("app-layer.protocols.quic.encryption-handling") {
let eh = match val {
"full" => EncryptionHandling::ENCRYPTION_HANDLING_FULL,
"track-only" => EncryptionHandling::ENCRYPTION_HANDLING_TRACK_ONLY,
"bypass" => EncryptionHandling::ENCRYPTION_HANDLING_BYPASS,
_ => {
SCFatalErrorOnInit!("Unknown value {} for quic.encryption-handling.", val);
EncryptionHandling::ENCRYPTION_HANDLING_TRACK_ONLY
}
};
unsafe { ENCRYPTION_BYPASS_ENABLED = eh };
if let Ok(eh) = EncryptionHandling::from_str(val) {
unsafe { ENCRYPTION_BYPASS_ENABLED = eh };
} else {
SCFatalErrorOnInit!("Unknown value {} for quic.encryption-handling.", val);
}
}
}
SCLogDebug!("Rust quic parser registered.");

Loading…
Cancel
Save