]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
nfs: implement get_event_info_by_id callback
authorVictor Julien <victor@inliniac.net>
Mon, 3 Jun 2019 14:08:29 +0000 (16:08 +0200)
committerVictor Julien <victor@inliniac.net>
Thu, 20 Jun 2019 18:14:58 +0000 (20:14 +0200)
rust/src/nfs/nfs.rs
src/app-layer-nfs-tcp.c

index fdea7008fbd15af850c085a4521dcb7989480300..f396d0eecb8133567772c0e191a65c555f704aa9 100644 (file)
@@ -91,6 +91,18 @@ pub enum NFSEvent {
     UnsupportedVersion = 2,
 }
 
+impl NFSEvent {
+    fn from_i32(value: i32) -> Option<NFSEvent> {
+        match value {
+            0 => Some(NFSEvent::MalformedData),
+            1 => Some(NFSEvent::NonExistingVersion),
+            2 => Some(NFSEvent::UnsupportedVersion),
+            _ => None,
+        }
+    }
+}
+
+
 #[derive(Debug)]
 pub enum NFSTransactionTypeData {
     RENAME(Vec<u8>),
@@ -1596,6 +1608,27 @@ pub extern "C" fn rs_nfs_state_get_events(tx: *mut libc::c_void)
     return tx.events;
 }
 
+#[no_mangle]
+pub extern "C" fn rs_nfs_state_get_event_info_by_id(event_id: libc::c_int,
+                                              event_name: *mut *const libc::c_char,
+                                              event_type: *mut AppLayerEventType)
+                                              -> i8
+{
+    if let Some(e) = NFSEvent::from_i32(event_id as i32) {
+        let estr = match e {
+            NFSEvent::MalformedData => { "malformed_data\0" },
+            NFSEvent::NonExistingVersion => { "non_existing_version\0" },
+            NFSEvent::UnsupportedVersion => { "unsupported_version\0" },
+        };
+        unsafe{
+            *event_name = estr.as_ptr() as *const libc::c_char;
+            *event_type = APP_LAYER_EVENT_TYPE_TRANSACTION;
+        };
+        0
+    } else {
+        -1
+    }
+}
 #[no_mangle]
 pub extern "C" fn rs_nfs_state_get_event_info(event_name: *const libc::c_char,
                                               event_id: *mut libc::c_int,
index ffa81a2a07e5178c01b3ce50c9069787f2af36cf..50565e37cb15cda97228858d038a128bb48ce4fb 100644 (file)
@@ -104,9 +104,7 @@ static int NFSTCPStateGetEventInfo(const char *event_name, int *event_id,
 static int NFSTCPStateGetEventInfoById(int event_id, const char **event_name,
     AppLayerEventType *event_type)
 {
-    *event_name = "NFS TCP event name (generic)";
-    *event_type = APP_LAYER_EVENT_TYPE_TRANSACTION;
-    return 0;
+    return rs_nfs_state_get_event_info_by_id(event_id, event_name, event_type);
 }
 
 static AppLayerDecoderEvents *NFSTCPGetEvents(void *tx)