]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
app/frames: implement name to id API for frames
authorVictor Julien <vjulien@oisf.net>
Fri, 3 Dec 2021 06:42:22 +0000 (07:42 +0100)
committerVictor Julien <vjulien@oisf.net>
Mon, 17 Jan 2022 18:32:29 +0000 (19:32 +0100)
23 files changed:
rust/src/applayer.rs
rust/src/applayertemplate/template.rs
rust/src/dcerpc/dcerpc.rs
rust/src/dcerpc/dcerpc_udp.rs
rust/src/dhcp/dhcp.rs
rust/src/dns/dns.rs
rust/src/http2/http2.rs
rust/src/ike/ike.rs
rust/src/krb/krb5.rs
rust/src/modbus/modbus.rs
rust/src/mqtt/mqtt.rs
rust/src/nfs/nfs.rs
rust/src/ntp/ntp.rs
rust/src/rdp/rdp.rs
rust/src/rfb/rfb.rs
rust/src/sip/sip.rs
rust/src/smb/smb.rs
rust/src/snmp/snmp.rs
rust/src/ssh/ssh.rs
src/app-layer-parser.c
src/app-layer-parser.h
src/app-layer-register.c
src/app-layer-register.h

index e8cad8ac9d7a51410a930eb839a7691e5b3486d8..38c7ef43139646d6d8b298117956fa83c54c84e5 100644 (file)
@@ -299,6 +299,9 @@ pub struct RustParser {
     /// Function to handle the end of data coming on one of the sides
     /// due to the stream reaching its 'depth' limit.
     pub truncate: Option<TruncateFn>,
+
+    pub get_frame_id_by_name: Option<GetFrameIdByName>,
+    pub get_frame_name_by_id: Option<GetFrameNameById>,
 }
 
 /// Create a slice, given a buffer and a length
@@ -344,6 +347,8 @@ pub type GetTxIteratorFn    = unsafe extern "C" fn (ipproto: u8, alproto: AppPro
 pub type GetTxDataFn = unsafe extern "C" fn(*mut c_void) -> *mut AppLayerTxData;
 pub type ApplyTxConfigFn = unsafe extern "C" fn (*mut c_void, *mut c_void, c_int, AppLayerTxConfig);
 pub type TruncateFn = unsafe extern "C" fn (*mut c_void, u8);
+pub type GetFrameIdByName = unsafe extern "C" fn(*const c_char) -> c_int;
+pub type GetFrameNameById = unsafe extern "C" fn(u8) -> *const c_char;
 
 
 // Defined in app-layer-register.h
index 8e185edba0a519359f97b3a94d508191baa552b8..7551cbf9eb166ef7a6d8b42ed6368b51d24bf0f9 100644 (file)
@@ -453,6 +453,8 @@ pub unsafe extern "C" fn rs_template_register_parser() {
         apply_tx_config: None,
         flags: APP_LAYER_PARSER_OPT_ACCEPT_GAPS,
         truncate: None,
+        get_frame_id_by_name: None,
+        get_frame_name_by_id: None,
     };
 
     let ip_proto_str = CString::new("tcp").unwrap();
index c4ecd5e012b3bcf07b49cbde84346c1a0c0758bd..3e2e3b635de30ccb9c2cc0bc6072903cd9565a42 100644 (file)
@@ -1372,6 +1372,8 @@ pub unsafe extern "C" fn rs_dcerpc_register_parser() {
         apply_tx_config: None,
         flags: APP_LAYER_PARSER_OPT_ACCEPT_GAPS,
         truncate: None,
+        get_frame_id_by_name: None,
+        get_frame_name_by_id: None,
     };
 
     let ip_proto_str = CString::new("tcp").unwrap();
index c3d827df9abb9b473bb573da30afd371b91c6909..b98ee827bb8984e098749263c068096c7f9d1a97 100644 (file)
@@ -351,6 +351,8 @@ pub unsafe extern "C" fn rs_dcerpc_udp_register_parser() {
         apply_tx_config: None,
         flags: APP_LAYER_PARSER_OPT_UNIDIR_TXS,
         truncate: None,
+        get_frame_id_by_name: None,
+        get_frame_name_by_id: None,
     };
 
     let ip_proto_str = CString::new("udp").unwrap();
index bc8bd05872f9881122fc2c30d5adb2fda23a539a..9dad3d2b71278baf5f8ace23926574dab41b9778 100644 (file)
@@ -295,6 +295,8 @@ pub unsafe extern "C" fn rs_dhcp_register_parser() {
         apply_tx_config    : None,
         flags              : APP_LAYER_PARSER_OPT_UNIDIR_TXS,
         truncate           : None,
+        get_frame_id_by_name: None,
+        get_frame_name_by_id: None,
     };
 
     let ip_proto_str = CString::new("udp").unwrap();
index 3bea3d711d9d9db0b1de605249c0d63f3a9aa598..072cbf981feb42ed3a95b4f250e1d28d1a2e3403 100644 (file)
@@ -943,6 +943,8 @@ pub unsafe extern "C" fn rs_dns_udp_register_parser() {
         apply_tx_config: Some(rs_dns_apply_tx_config),
         flags: APP_LAYER_PARSER_OPT_UNIDIR_TXS,
         truncate: None,
+        get_frame_id_by_name: None,
+        get_frame_name_by_id: None,
     };
 
     let ip_proto_str = CString::new("udp").unwrap();
@@ -986,6 +988,8 @@ pub unsafe extern "C" fn rs_dns_tcp_register_parser() {
         apply_tx_config: Some(rs_dns_apply_tx_config),
         flags: APP_LAYER_PARSER_OPT_ACCEPT_GAPS | APP_LAYER_PARSER_OPT_UNIDIR_TXS,
         truncate: None,
+        get_frame_id_by_name: None,
+        get_frame_name_by_id: None,
     };
 
     let ip_proto_str = CString::new("tcp").unwrap();
index 821921c5c74121ab5cb7a6e7930f28fdeee97df5..61705c30d0438d7d23b49d17c59feba4b9abea67 100644 (file)
@@ -1193,6 +1193,8 @@ pub unsafe extern "C" fn rs_http2_register_parser() {
         apply_tx_config: None,
         flags: 0,
         truncate: None,
+        get_frame_id_by_name: None,
+        get_frame_name_by_id: None,
     };
 
     let ip_proto_str = CString::new("tcp").unwrap();
index 40d44167c9ffbcc9bf2e9eb56a2caf3b8d13895c..eebb847b659327657adc86ae13e3c9c4cae09764 100644 (file)
@@ -422,6 +422,8 @@ pub unsafe extern "C" fn rs_ike_register_parser() {
         apply_tx_config    : None,
         flags              : APP_LAYER_PARSER_OPT_UNIDIR_TXS,
         truncate           : None,
+        get_frame_id_by_name: None,
+        get_frame_name_by_id: None,
     };
 
     let ip_proto_str = CString::new("udp").unwrap();
index 9e11c4c2d45a7c2e8e0261e3e294539e5ffd4df7..b1c10fef064e41858b292c5c5e8635ed2444109d 100644 (file)
@@ -550,6 +550,8 @@ pub unsafe extern "C" fn rs_register_krb5_parser() {
         apply_tx_config    : None,
         flags              : APP_LAYER_PARSER_OPT_UNIDIR_TXS,
         truncate           : None,
+        get_frame_id_by_name: None,
+        get_frame_name_by_id: None,
     };
     // register UDP parser
     let ip_proto_str = CString::new("udp").unwrap();
index ffdcffa60f72c0761757a4ef6270a289d7d28e28..37c584d505d2e6aedb49e63435dc4442e5430252 100644 (file)
@@ -405,6 +405,8 @@ pub unsafe extern "C" fn rs_modbus_register_parser() {
         apply_tx_config: None,
         flags: 0,
         truncate: None,
+        get_frame_id_by_name: None,
+        get_frame_name_by_id: None,
     };
 
     let ip_proto_str = CString::new("tcp").unwrap();
index 10682cc1c5abf2887c8f6cfdd80c520125923ab4..8776e3b84a8816f04030349230fc371fa72c33ce 100644 (file)
@@ -693,6 +693,8 @@ pub unsafe extern "C" fn rs_mqtt_register_parser(cfg_max_msg_len: u32) {
         apply_tx_config: None,
         flags: APP_LAYER_PARSER_OPT_UNIDIR_TXS,
         truncate: None,
+        get_frame_id_by_name: None,
+        get_frame_name_by_id: None,
     };
 
     let ip_proto_str = CString::new("tcp").unwrap();
index 278d2cc51825b50d631f46fa3e4a2cf52cae39c3..c3599d42e308dc77543dbc6d9d51b006db0d601f 100644 (file)
@@ -1863,6 +1863,8 @@ pub unsafe extern "C" fn rs_nfs_register_parser() {
         apply_tx_config: None,
         flags: APP_LAYER_PARSER_OPT_ACCEPT_GAPS,
         truncate: None,
+        get_frame_id_by_name: None,
+        get_frame_name_by_id: None,
     };
 
     let ip_proto_str = CString::new("tcp").unwrap();
@@ -1939,6 +1941,8 @@ pub unsafe extern "C" fn rs_nfs_udp_register_parser() {
         apply_tx_config: None,
         flags: APP_LAYER_PARSER_OPT_UNIDIR_TXS,
         truncate: None,
+        get_frame_id_by_name: None,
+        get_frame_name_by_id: None,
     };
 
     let ip_proto_str = CString::new("udp").unwrap();
index f8c888d130ea73b7eeb970fde781a36d43d786a8..51011b454579eab469a2e26dd10940b239ab386f 100644 (file)
@@ -292,6 +292,8 @@ pub unsafe extern "C" fn rs_register_ntp_parser() {
         apply_tx_config    : None,
         flags              : APP_LAYER_PARSER_OPT_UNIDIR_TXS,
         truncate           : None,
+        get_frame_id_by_name: None,
+        get_frame_name_by_id: None,
     };
 
     let ip_proto_str = CString::new("udp").unwrap();
index 835a13029b81379fb28f21d862178b6f2fd0d2d3..b6d266f22097d6e85010b3d4d8b86ea939a52d27 100644 (file)
@@ -487,6 +487,8 @@ pub unsafe extern "C" fn rs_rdp_register_parser() {
         apply_tx_config: None,
         flags: APP_LAYER_PARSER_OPT_UNIDIR_TXS,
         truncate: None,
+        get_frame_id_by_name: None,
+        get_frame_name_by_id: None,
     };
 
     let ip_proto_str = std::ffi::CString::new("tcp").unwrap();
index b07d2321ec2d2bc2fd9f3c6c49f1ebc35d67504b..1f95e0016225bd2356d5920a9a153ce00296349c 100644 (file)
@@ -596,6 +596,8 @@ pub unsafe extern "C" fn rs_rfb_register_parser() {
         apply_tx_config: None,
         flags: 0,
         truncate: None,
+        get_frame_id_by_name: None,
+        get_frame_name_by_id: None,
     };
 
     let ip_proto_str = CString::new("tcp").unwrap();
index 50ddec0ae9589fe460a7da995bc5cc7b3c84a386..f7dfc3df43db9d19e4660ae9980dd38d76a954ce 100755 (executable)
@@ -289,6 +289,8 @@ pub unsafe extern "C" fn rs_sip_register_parser() {
         apply_tx_config: None,
         flags: APP_LAYER_PARSER_OPT_UNIDIR_TXS,
         truncate: None,
+        get_frame_id_by_name: None,
+        get_frame_name_by_id: None,
     };
 
     let ip_proto_str = CString::new("udp").unwrap();
index c9d9aa3be754e33c72f50382a367a94e7cea16aa..6336ce4384a08f8be6eed96fe2ddda31cf985698 100644 (file)
@@ -2168,6 +2168,8 @@ pub unsafe extern "C" fn rs_smb_register_parser() {
         apply_tx_config: None,
         flags: APP_LAYER_PARSER_OPT_ACCEPT_GAPS,
         truncate: Some(rs_smb_state_truncate),
+        get_frame_id_by_name: None,
+        get_frame_name_by_id: None,
     };
 
     let ip_proto_str = CString::new("tcp").unwrap();
index 976d2590bed2183d4d9a166b9955055041624062..c12140db4e65d11aa2d08bd39ea340ea651e120d 100644 (file)
@@ -398,6 +398,8 @@ pub unsafe extern "C" fn rs_register_snmp_parser() {
         apply_tx_config    : None,
         flags              : APP_LAYER_PARSER_OPT_UNIDIR_TXS,
         truncate           : None,
+        get_frame_id_by_name: None,
+        get_frame_name_by_id: None,
     };
     let ip_proto_str = CString::new("udp").unwrap();
     if AppLayerProtoDetectConfProtoDetectionEnabled(ip_proto_str.as_ptr(), parser.name) != 0 {
index c5a4fc62d554515e46c323029fe88beb777dc281..874ac9faf72a24cde250e796bf94f2a68f4b2cce 100644 (file)
@@ -466,6 +466,8 @@ pub unsafe extern "C" fn rs_ssh_register_parser() {
         apply_tx_config: None,
         flags: 0,
         truncate: None,
+        get_frame_id_by_name: None,
+        get_frame_name_by_id: None,
     };
 
     let ip_proto_str = CString::new("tcp").unwrap();
index d77a5c70bff5367d1e9d4c94a8f5996bfe05ab0b..806d5e249e918e718dec6a59e6a01a2f44f17d7c 100644 (file)
@@ -122,6 +122,9 @@ typedef struct AppLayerParserProtoCtx_
 
     void (*SetStreamDepthFlag)(void *tx, uint8_t flags);
 
+    AppLayerParserGetFrameIdByNameFn GetFrameIdByName;
+    AppLayerParserGetFrameNameByIdFn GetFrameNameById;
+
     /* each app-layer has its own value */
     uint32_t stream_depth;
 
@@ -535,6 +538,16 @@ void AppLayerParserRegisterGetEventInfoById(uint8_t ipproto, AppProto alproto,
     SCReturn;
 }
 
+void AppLayerParserRegisterGetFrameFuncs(uint8_t ipproto, AppProto alproto,
+        AppLayerParserGetFrameIdByNameFn GetIdByNameFunc,
+        AppLayerParserGetFrameNameByIdFn GetNameByIdFunc)
+{
+    SCEnter();
+    alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].GetFrameIdByName = GetIdByNameFunc;
+    alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].GetFrameNameById = GetNameByIdFunc;
+    SCReturn;
+}
+
 void AppLayerParserRegisterGetEventInfo(uint8_t ipproto, AppProto alproto,
     int (*StateGetEventInfo)(const char *event_name, int *event_id,
                              AppLayerEventType *event_type))
@@ -1449,6 +1462,24 @@ void AppLayerParserSetStreamDepthFlag(uint8_t ipproto, AppProto alproto, void *s
     SCReturn;
 }
 
+int AppLayerParserGetFrameIdByName(uint8_t ipproto, AppProto alproto, const char *name)
+{
+    if (alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].GetFrameIdByName != NULL) {
+        return alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].GetFrameIdByName(name);
+    } else {
+        return -1;
+    }
+}
+
+const char *AppLayerParserGetFrameNameById(uint8_t ipproto, AppProto alproto, const uint8_t id)
+{
+    if (alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].GetFrameNameById != NULL) {
+        return alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].GetFrameNameById(id);
+    } else {
+        return NULL;
+    }
+}
+
 /***** Cleanup *****/
 
 void AppLayerParserStateProtoCleanup(
index 357c5153eb909b7fba30df6867a099c22d82242b..ec585ee3942526fc4bd1b308c192489c55e8b489 100644 (file)
@@ -154,6 +154,9 @@ typedef AppLayerGetTxIterTuple (*AppLayerGetTxIteratorFunc)
 
 /***** Parser related registration *****/
 
+typedef int (*AppLayerParserGetFrameIdByNameFn)(const char *frame_name);
+typedef const char *(*AppLayerParserGetFrameNameByIdFn)(const uint8_t id);
+
 /**
  * \brief Register app layer parser for the protocol.
  *
@@ -202,6 +205,9 @@ void AppLayerParserRegisterGetEventInfo(uint8_t ipproto, AppProto alproto,
 void AppLayerParserRegisterGetEventInfoById(uint8_t ipproto, AppProto alproto,
     int (*StateGetEventInfoById)(int event_id, const char **event_name,
                                  AppLayerEventType *event_type));
+void AppLayerParserRegisterGetFrameFuncs(uint8_t ipproto, AppProto alproto,
+        AppLayerParserGetFrameIdByNameFn GetFrameIdByName,
+        AppLayerParserGetFrameNameByIdFn GetFrameNameById);
 void AppLayerParserRegisterGetStreamDepth(uint8_t ipproto,
                                           AppProto alproto,
                                           uint32_t (*GetStreamDepth)(void));
@@ -268,6 +274,8 @@ void AppLayerParserSetStreamDepth(uint8_t ipproto, AppProto alproto, uint32_t st
 uint32_t AppLayerParserGetStreamDepth(const Flow *f);
 void AppLayerParserSetStreamDepthFlag(uint8_t ipproto, AppProto alproto, void *state, uint64_t tx_id, uint8_t flags);
 int AppLayerParserIsEnabled(AppProto alproto);
+int AppLayerParserGetFrameIdByName(uint8_t ipproto, AppProto alproto, const char *name);
+const char *AppLayerParserGetFrameNameById(uint8_t ipproto, AppProto alproto, const uint8_t id);
 
 /***** Cleanup *****/
 
index 83df3e35575675a642e072854a2f89e14bc34c68..70649e7a8495d55da454876de5d5d385fe2606bd 100644 (file)
@@ -179,6 +179,11 @@ int AppLayerRegisterParser(const struct AppLayerParser *p, AppProto alproto)
         AppLayerParserRegisterTruncateFunc(p->ip_proto, alproto, p->Truncate);
     }
 
+    if (p->GetFrameIdByName && p->GetFrameNameById) {
+        AppLayerParserRegisterGetFrameFuncs(
+                p->ip_proto, alproto, p->GetFrameIdByName, p->GetFrameNameById);
+    }
+
     return 0;
 }
 
index 90b3402b623d131e7ba73caec26ef2847c18c193..4772747eabe4f04a35ab73bddb4fe7d0dc42b52d 100644 (file)
@@ -70,6 +70,9 @@ typedef struct AppLayerParser {
 
     void (*Truncate)(void *state, uint8_t direction);
 
+    AppLayerParserGetFrameIdByNameFn GetFrameIdByName;
+    AppLayerParserGetFrameNameByIdFn GetFrameNameById;
+
 } AppLayerParser;
 
 /**