]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
nfs: switch to AppLayerResult
authorVictor Julien <victor@inliniac.net>
Fri, 13 Mar 2020 10:03:19 +0000 (11:03 +0100)
committerVictor Julien <victor@inliniac.net>
Tue, 17 Mar 2020 21:03:23 +0000 (22:03 +0100)
rust/src/nfs/nfs.rs
rust/src/nfs/nfs2.rs
rust/src/nfs/nfs3.rs
rust/src/nfs/nfs4.rs
src/app-layer-nfs-tcp.c
src/app-layer-nfs-udp.c

index 3aba46f7000f60758d0af62084c129061c9a8cb7..ccc4e525399c876885fd7e0ed9c559ca3eb117de 100644 (file)
@@ -28,6 +28,7 @@ use nom;
 use crate::log::*;
 use crate::applayer;
 use crate::applayer::LoggerFlags;
+use crate::parser::AppLayerResult;
 use crate::core::*;
 use crate::filetracker::*;
 use crate::filecontainer::*;
@@ -589,7 +590,7 @@ impl NFSState {
     }
 
     /// complete request record
-    fn process_request_record<'b>(&mut self, r: &RpcPacket<'b>) -> u32 {
+    fn process_request_record<'b>(&mut self, r: &RpcPacket<'b>) {
         SCLogDebug!("REQUEST {} procedure {} ({}) blob size {}",
                 r.hdr.xid, r.procedure, self.requestmap.len(), r.prog_data.len());
 
@@ -603,7 +604,7 @@ impl NFSState {
             2 => {
                 self.process_request_record_v2(r)
             },
-            _ => { },
+            _ => { },
         }
     }
 
@@ -744,15 +745,18 @@ impl NFSState {
         match xidmap.progver {
             2 => {
                 SCLogDebug!("NFSv2 reply record");
-                return self.process_reply_record_v2(r, &xidmap);
+                self.process_reply_record_v2(r, &xidmap);
+                return 0;
             },
             3 => {
                 SCLogDebug!("NFSv3 reply record");
-                return self.process_reply_record_v3(r, &mut xidmap);
+                self.process_reply_record_v3(r, &mut xidmap);
+                return 0;
             },
             4 => {
                 SCLogDebug!("NFSv4 reply record");
-                return self.process_reply_record_v4(r, &mut xidmap);
+                self.process_reply_record_v4(r, &mut xidmap);
+                return 0;
             },
             _ => {
                 SCLogDebug!("Invalid NFS version");
@@ -1006,7 +1010,7 @@ impl NFSState {
         }
     }
 
-    pub fn parse_tcp_data_ts_gap<'b>(&mut self, gap_size: u32) -> u32 {
+    pub fn parse_tcp_data_ts_gap<'b>(&mut self, gap_size: u32) -> AppLayerResult {
         SCLogDebug!("parse_tcp_data_ts_gap ({})", gap_size);
         if self.tcp_buffer_ts.len() > 0 {
             self.tcp_buffer_ts.clear();
@@ -1015,15 +1019,15 @@ impl NFSState {
         let consumed = self.filetracker_update(STREAM_TOSERVER, &gap, gap_size);
         if consumed > gap_size {
             SCLogDebug!("consumed more than GAP size: {} > {}", consumed, gap_size);
-            return 0;
+            return AppLayerResult::ok();
         }
         self.ts_ssn_gap = true;
         self.ts_gap = true;
         SCLogDebug!("parse_tcp_data_ts_gap ({}) done", gap_size);
-        return 0
+        return AppLayerResult::ok();
     }
 
-    pub fn parse_tcp_data_tc_gap<'b>(&mut self, gap_size: u32) -> u32 {
+    pub fn parse_tcp_data_tc_gap<'b>(&mut self, gap_size: u32) -> AppLayerResult {
         SCLogDebug!("parse_tcp_data_tc_gap ({})", gap_size);
         if self.tcp_buffer_tc.len() > 0 {
             self.tcp_buffer_tc.clear();
@@ -1032,18 +1036,17 @@ impl NFSState {
         let consumed = self.filetracker_update(STREAM_TOCLIENT, &gap, gap_size);
         if consumed > gap_size {
             SCLogDebug!("consumed more than GAP size: {} > {}", consumed, gap_size);
-            return 0;
+            return AppLayerResult::ok();
         }
         self.tc_ssn_gap = true;
         self.tc_gap = true;
         SCLogDebug!("parse_tcp_data_tc_gap ({}) done", gap_size);
-        return 0
+        return AppLayerResult::ok();
     }
 
     /// Parsing function, handling TCP chunks fragmentation
-    pub fn parse_tcp_data_ts<'b>(&mut self, i: &'b[u8]) -> u32 {
+    pub fn parse_tcp_data_ts<'b>(&mut self, i: &'b[u8]) -> AppLayerResult {
         let mut v : Vec<u8>;
-        let mut status = 0;
         SCLogDebug!("parse_tcp_data_ts ({})",i.len());
         //SCLogDebug!("{:?}",i);
         // Check if TCP data is being defragmented
@@ -1055,7 +1058,7 @@ impl NFSState {
                 if self.tcp_buffer_ts.len() + i.len() > 1000000 {
                     SCLogDebug!("parse_tcp_data_ts: TS buffer exploded {} {}",
                             self.tcp_buffer_ts.len(), i.len());
-                    return 1;
+                    return AppLayerResult::err();
                 };
                 v.extend_from_slice(i);
                 v.as_slice()
@@ -1065,12 +1068,15 @@ impl NFSState {
         let mut cur_i = tcp_buffer;
         if cur_i.len() > 1000000 {
             SCLogDebug!("BUG buffer exploded: {}", cur_i.len());
+            return AppLayerResult::err();
         }
         // take care of in progress file chunk transfers
         // and skip buffer beyond it
         let consumed = self.filetracker_update(STREAM_TOSERVER, cur_i, 0);
         if consumed > 0 {
-            if consumed > cur_i.len() as u32 { return 1; }
+            if consumed > cur_i.len() as u32 {
+                return AppLayerResult::err();
+            }
             cur_i = &cur_i[consumed as usize..];
         }
         if self.ts_gap {
@@ -1088,7 +1094,7 @@ impl NFSState {
                     0 => {
                         SCLogDebug!("incomplete, queue and retry with the next block (input {}). Looped {} times.", cur_i.len(), cnt);
                         self.tcp_buffer_tc.extend_from_slice(cur_i);
-                        return 0;
+                        return AppLayerResult::ok();
                     },
                     -1 => {
                         cur_i = &cur_i[1..];
@@ -1096,7 +1102,9 @@ impl NFSState {
                             SCLogDebug!("all post-GAP data in this chunk was bad. Looped {} times.", cnt);
                         }
                     },
-                    _ => { return 1; },
+                    _ => {
+                        return AppLayerResult::err();
+                    },
                 }
             }
             SCLogDebug!("TS GAP handling done (input {})", cur_i.len());
@@ -1126,7 +1134,7 @@ impl NFSState {
                                         match parse_nfs3_request_write(rpc_record.prog_data) {
                                             Ok((_, ref nfs_request_write)) => {
                                                 // deal with the partial nfs write data
-                                                status |= self.process_partial_write_request_record(rpc_record, nfs_request_write);
+                                                self.process_partial_write_request_record(rpc_record, nfs_request_write);
                                                 cur_i = remaining; // progress input past parsed record
                                             },
                                             _ => {
@@ -1145,7 +1153,7 @@ impl NFSState {
                                     Err(nom::Err::Failure(_e)) => {
                                         self.set_event(NFSEvent::MalformedData);
                                         SCLogDebug!("Parsing failed: {:?}", _e);
-                                        return 1;
+                                        return AppLayerResult::err();
                                     },
                                 }
                             }
@@ -1159,7 +1167,7 @@ impl NFSState {
                     match parse_rpc(&cur_i[..rec_size]) {
                         Ok((_, ref rpc_record)) => {
                             cur_i = &cur_i[rec_size..];
-                            status |= self.process_request_record(rpc_record);
+                            self.process_request_record(rpc_record);
                         },
                         Err(nom::Err::Incomplete(_)) => {
                             cur_i = &cur_i[rec_size..]; // progress input past parsed record
@@ -1168,14 +1176,12 @@ impl NFSState {
                             // so if we got incomplete anyway it's the data that is
                             // bad.
                             self.set_event(NFSEvent::MalformedData);
-
-                            status = 0;
                         },
                         Err(nom::Err::Error(_e)) |
                         Err(nom::Err::Failure(_e)) => {
                             self.set_event(NFSEvent::MalformedData);
                             SCLogDebug!("Parsing failed: {:?}", _e);
-                            return 1;
+                            return AppLayerResult::err();
                         },
                     }
                 },
@@ -1188,7 +1194,7 @@ impl NFSState {
                 Err(nom::Err::Failure(_e)) => {
                     self.set_event(NFSEvent::MalformedData);
                     SCLogDebug!("Parsing failed: {:?}", _e);
-                    return 1;
+                    return AppLayerResult::err();
                 },
             }
         };
@@ -1198,13 +1204,12 @@ impl NFSState {
             self.post_gap_housekeeping_for_files();
         }
 
-        status
+        AppLayerResult::ok()
     }
 
     /// Parsing function, handling TCP chunks fragmentation
-    pub fn parse_tcp_data_tc<'b>(&mut self, i: &'b[u8]) -> u32 {
+    pub fn parse_tcp_data_tc<'b>(&mut self, i: &'b[u8]) -> AppLayerResult {
         let mut v : Vec<u8>;
-        let mut status = 0;
         SCLogDebug!("parse_tcp_data_tc ({})",i.len());
         //SCLogDebug!("{:?}",i);
         // Check if TCP data is being defragmented
@@ -1215,7 +1220,7 @@ impl NFSState {
                 // sanity check vector length to avoid memory exhaustion
                 if self.tcp_buffer_tc.len() + i.len() > 100000 {
                     SCLogDebug!("TC buffer exploded");
-                    return 1;
+                    return AppLayerResult::err();
                 };
 
                 v.extend_from_slice(i);
@@ -1233,7 +1238,9 @@ impl NFSState {
         // and skip buffer beyond it
         let consumed = self.filetracker_update(STREAM_TOCLIENT, cur_i, 0);
         if consumed > 0 {
-            if consumed > cur_i.len() as u32 { return 1; }
+            if consumed > cur_i.len() as u32 {
+                return AppLayerResult::err();
+            }
             cur_i = &cur_i[consumed as usize..];
         }
         if self.tc_gap {
@@ -1251,7 +1258,7 @@ impl NFSState {
                     0 => {
                         SCLogDebug!("incomplete, queue and retry with the next block (input {}). Looped {} times.", cur_i.len(), cnt);
                         self.tcp_buffer_tc.extend_from_slice(cur_i);
-                        return 0;
+                        return AppLayerResult::ok();
                     },
                     -1 => {
                         cur_i = &cur_i[1..];
@@ -1259,7 +1266,9 @@ impl NFSState {
                             SCLogDebug!("all post-GAP data in this chunk was bad. Looped {} times.", cnt);
                         }
                     },
-                    _ => { return 1; },
+                    _ => {
+                        return AppLayerResult::err();
+                    }
                 }
             }
             SCLogDebug!("TC GAP handling done (input {})", cur_i.len());
@@ -1287,7 +1296,7 @@ impl NFSState {
                                         match parse_nfs3_reply_read(rpc_record.prog_data) {
                                             Ok((_, ref nfs_reply_read)) => {
                                                 // deal with the partial nfs read data
-                                                status |= self.process_partial_read_reply_record(rpc_record, nfs_reply_read);
+                                                self.process_partial_read_reply_record(rpc_record, nfs_reply_read);
                                                 cur_i = remaining; // progress input past parsed record
                                             },
                                             Err(nom::Err::Incomplete(_)) => {
@@ -1297,7 +1306,7 @@ impl NFSState {
                                             Err(nom::Err::Failure(_e)) => {
                                                 self.set_event(NFSEvent::MalformedData);
                                                 SCLogDebug!("Parsing failed: {:?}", _e);
-                                                return 1;
+                                                return AppLayerResult::err();
                                             }
                                         }
                                     },
@@ -1310,7 +1319,7 @@ impl NFSState {
                                     Err(nom::Err::Failure(_e)) => {
                                         self.set_event(NFSEvent::MalformedData);
                                         SCLogDebug!("Parsing failed: {:?}", _e);
-                                        return 1;
+                                        return AppLayerResult::err();
                                     }
                                 }
                             }
@@ -1323,7 +1332,7 @@ impl NFSState {
                     match parse_rpc_reply(&cur_i[..rec_size]) {
                         Ok((_, ref rpc_record)) => {
                             cur_i = &cur_i[rec_size..]; // progress input past parsed record
-                            status |= self.process_reply_record(rpc_record);
+                            self.process_reply_record(rpc_record);
                         },
                         Err(nom::Err::Incomplete(_)) => {
                             cur_i = &cur_i[rec_size..]; // progress input past parsed record
@@ -1332,14 +1341,12 @@ impl NFSState {
                             // so if we got incomplete anyway it's the data that is
                             // bad.
                             self.set_event(NFSEvent::MalformedData);
-
-                            status = 0;
                         },
                         Err(nom::Err::Error(_e)) |
                         Err(nom::Err::Failure(_e)) => {
                             self.set_event(NFSEvent::MalformedData);
                             SCLogDebug!("Parsing failed: {:?}", _e);
-                            return 1;
+                            return AppLayerResult::err();
                         }
                     }
                 },
@@ -1352,7 +1359,7 @@ impl NFSState {
                 Err(nom::Err::Failure(_e)) => {
                     self.set_event(NFSEvent::MalformedData);
                     SCLogDebug!("Parsing failed: {:?}", _e);
-                    return 1;
+                    return AppLayerResult::err();
                 },
             }
         };
@@ -1360,11 +1367,10 @@ impl NFSState {
         if self.check_post_gap_file_txs {
             self.post_gap_housekeeping_for_files();
         }
-        status
+        AppLayerResult::ok()
     }
     /// Parsing function
-    pub fn parse_udp_ts<'b>(&mut self, input: &'b[u8]) -> u32 {
-        let mut status = 0;
+    pub fn parse_udp_ts<'b>(&mut self, input: &'b[u8]) -> AppLayerResult {
         SCLogDebug!("parse_udp_ts ({})", input.len());
         if input.len() > 0 {
             match parse_rpc_udp_request(input) {
@@ -1372,42 +1378,45 @@ impl NFSState {
                     self.is_udp = true;
                     match rpc_record.progver {
                         3 => {
-                            status |= self.process_request_record(rpc_record);
+                            self.process_request_record(rpc_record);
                         },
                         2 => {
-                            status |= self.process_request_record_v2(rpc_record);
+                            self.process_request_record_v2(rpc_record);
                         },
-                        _ => { status = 0; },
+                        _ => { },
                     }
                 },
                 Err(nom::Err::Incomplete(_)) => {
                 },
                 Err(nom::Err::Error(_e)) |
-                Err(nom::Err::Failure(_e)) => { SCLogDebug!("Parsing failed: {:?}", _e); }
+                Err(nom::Err::Failure(_e)) => {
+                    SCLogDebug!("Parsing failed: {:?}", _e);
+                }
             }
         }
-        SCLogDebug!("status {}", status);
-        status
+        AppLayerResult::ok()
     }
 
     /// Parsing function
-    pub fn parse_udp_tc<'b>(&mut self, input: &'b[u8]) -> u32 {
-        let mut status = 0;
+    pub fn parse_udp_tc<'b>(&mut self, input: &'b[u8]) -> AppLayerResult {
         SCLogDebug!("parse_udp_tc ({})", input.len());
         if input.len() > 0 {
             match parse_rpc_udp_reply(input) {
                 Ok((_, ref rpc_record)) => {
                     self.is_udp = true;
-                    status |= self.process_reply_record(rpc_record);
+                    self.process_reply_record(rpc_record);
                 },
                 Err(nom::Err::Incomplete(_)) => {
                 },
                 Err(nom::Err::Error(_e)) |
-                Err(nom::Err::Failure(_e)) => { SCLogDebug!("Parsing failed: {:?}", _e); }
+                Err(nom::Err::Failure(_e)) => {
+                    SCLogDebug!("Parsing failed: {:?}", _e);
+                }
             }
-        };
-        status
+        }
+        AppLayerResult::ok()
     }
+
     fn getfiles(&mut self, direction: u8) -> * mut FileContainer {
         //SCLogDebug!("direction: {}", direction);
         if direction == STREAM_TOCLIENT {
@@ -1453,29 +1462,22 @@ pub extern "C" fn rs_nfs_parse_request(flow: &mut Flow,
                                        input: *const u8,
                                        input_len: u32,
                                        _data: *mut std::os::raw::c_void)
-                                       -> i8
+                                       -> AppLayerResult
 {
     let buf = unsafe{std::slice::from_raw_parts(input, input_len as usize)};
     SCLogDebug!("parsing {} bytes of request data", input_len);
 
     state.ts = flow.get_last_time().as_secs();
-    if state.parse_tcp_data_ts(buf) == 0 {
-        0
-    } else {
-        -1
-    }
+    state.parse_tcp_data_ts(buf)
 }
 
 #[no_mangle]
 pub extern "C" fn rs_nfs_parse_request_tcp_gap(
                                         state: &mut NFSState,
                                         input_len: u32)
-                                        -> i8
+                                        -> AppLayerResult
 {
-    if state.parse_tcp_data_ts_gap(input_len as u32) == 0 {
-        return 0;
-    }
-    return -1;
+    state.parse_tcp_data_ts_gap(input_len as u32)
 }
 
 #[no_mangle]
@@ -1485,29 +1487,22 @@ pub extern "C" fn rs_nfs_parse_response(flow: &mut Flow,
                                         input: *const u8,
                                         input_len: u32,
                                         _data: *mut std::os::raw::c_void)
-                                        -> i8
+                                        -> AppLayerResult
 {
     SCLogDebug!("parsing {} bytes of response data", input_len);
     let buf = unsafe{std::slice::from_raw_parts(input, input_len as usize)};
 
     state.ts = flow.get_last_time().as_secs();
-    if state.parse_tcp_data_tc(buf) == 0 {
-        0
-    } else {
-        -1
-    }
+    state.parse_tcp_data_tc(buf)
 }
 
 #[no_mangle]
 pub extern "C" fn rs_nfs_parse_response_tcp_gap(
                                         state: &mut NFSState,
                                         input_len: u32)
-                                        -> i8
+                                        -> AppLayerResult
 {
-    if state.parse_tcp_data_tc_gap(input_len as u32) == 0 {
-        return 0;
-    }
-    return -1;
+    state.parse_tcp_data_tc_gap(input_len as u32)
 }
 
 /// C binding parse a DNS request. Returns 1 on success, -1 on failure.
@@ -1518,16 +1513,11 @@ pub extern "C" fn rs_nfs_parse_request_udp(_flow: *mut Flow,
                                        input: *const u8,
                                        input_len: u32,
                                        _data: *mut std::os::raw::c_void)
-                                       -> i8
+                                       -> AppLayerResult
 {
     let buf = unsafe{std::slice::from_raw_parts(input, input_len as usize)};
     SCLogDebug!("parsing {} bytes of request data", input_len);
-
-    if state.parse_udp_ts(buf) == 0 {
-        0
-    } else {
-        -1
-    }
+    state.parse_udp_ts(buf)
 }
 
 #[no_mangle]
@@ -1537,16 +1527,11 @@ pub extern "C" fn rs_nfs_parse_response_udp(_flow: *mut Flow,
                                         input: *const u8,
                                         input_len: u32,
                                         _data: *mut std::os::raw::c_void)
-                                        -> i8
+                                        -> AppLayerResult
 {
     SCLogDebug!("parsing {} bytes of response data", input_len);
     let buf = unsafe{std::slice::from_raw_parts(input, input_len as usize)};
-
-    if state.parse_udp_tc(buf) == 0 {
-        0
-    } else {
-        -1
-    }
+    state.parse_udp_tc(buf)
 }
 
 #[no_mangle]
index 345d3f018f80f01e72f86cec093bb3454da027cd..ba7defd524be019cf8c636ddf624ae3d56367b38 100644 (file)
@@ -29,7 +29,7 @@ use nom::number::streaming::be_u32;
 
 impl NFSState {
     /// complete request record
-    pub fn process_request_record_v2<'b>(&mut self, r: &RpcPacket<'b>) -> u32 {
+    pub fn process_request_record_v2<'b>(&mut self, r: &RpcPacket<'b>) {
         SCLogDebug!("NFSv2: REQUEST {} procedure {} ({}) blob size {}",
                 r.hdr.xid, r.procedure, self.requestmap.len(), r.prog_data.len());
 
@@ -91,10 +91,9 @@ impl NFSState {
 
         SCLogDebug!("NFSv2: TS creating xidmap {}", r.hdr.xid);
         self.requestmap.insert(r.hdr.xid, xidmap);
-        return 0;
     }
 
-    pub fn process_reply_record_v2<'b>(&mut self, r: &RpcReplyPacket<'b>, xidmap: &NFSRequestXidMap) -> u32 {
+    pub fn process_reply_record_v2<'b>(&mut self, r: &RpcReplyPacket<'b>, xidmap: &NFSRequestXidMap) {
         let mut nfs_status = 0;
         let resp_handle = Vec::new();
 
@@ -120,6 +119,5 @@ impl NFSState {
                 r.hdr.xid, xidmap.procedure, r.prog_data.len());
 
         self.mark_response_tx_done(r.hdr.xid, r.reply_state, nfs_status, &resp_handle);
-        return 0;
     }
 }
index 8c2d2166ba88ccf13f91cd14833dde0bab79ca5c..bd3461b1d2dbf7268a5ab384bfddf717cdaa7b14 100644 (file)
@@ -30,7 +30,7 @@ use nom::number::streaming::be_u32;
 
 impl NFSState {
     /// complete NFS3 request record
-    pub fn process_request_record_v3<'b>(&mut self, r: &RpcPacket<'b>) -> u32 {
+    pub fn process_request_record_v3<'b>(&mut self, r: &RpcPacket<'b>) {
         SCLogDebug!("REQUEST {} procedure {} ({}) blob size {}",
                 r.hdr.xid, r.procedure, self.requestmap.len(), r.prog_data.len());
 
@@ -186,10 +186,9 @@ impl NFSState {
         }
 
         self.requestmap.insert(r.hdr.xid, xidmap);
-        return 0;
     }
 
-    pub fn process_reply_record_v3<'b>(&mut self, r: &RpcReplyPacket<'b>, xidmap: &mut NFSRequestXidMap) -> u32 {
+    pub fn process_reply_record_v3<'b>(&mut self, r: &RpcReplyPacket<'b>, xidmap: &mut NFSRequestXidMap) {
         let mut nfs_status = 0;
         let mut resp_handle = Vec::new();
 
@@ -273,7 +272,5 @@ impl NFSState {
         if xidmap.procedure != NFSPROC3_READ {
             self.mark_response_tx_done(r.hdr.xid, r.reply_state, nfs_status, &resp_handle);
         }
-
-        return 0;
     }
 }
index 1d4f94ba89ec082bd4ad023a7e7f812917347a3d..be12b2ca6ac8c513bc963cbaa4d1a246e36ad84f 100644 (file)
@@ -220,7 +220,7 @@ impl NFSState {
     }
 
     /// complete request record
-    pub fn process_request_record_v4<'b>(&mut self, r: &RpcPacket<'b>) -> u32 {
+    pub fn process_request_record_v4<'b>(&mut self, r: &RpcPacket<'b>) {
         SCLogDebug!("NFSv4 REQUEST {} procedure {} ({}) blob size {}",
                 r.hdr.xid, r.procedure, self.requestmap.len(), r.prog_data.len());
 
@@ -250,13 +250,13 @@ impl NFSState {
                         Err(nom::Err::Incomplete(_n)) => {
                             SCLogDebug!("NFSPROC4_COMPOUND/GSS INTEGRITIY: INCOMPLETE {:?}", _n);
                             self.set_event(NFSEvent::MalformedData);
-                            return 0;
+                            return;
                         },
                         Err(nom::Err::Error(_e)) |
                         Err(nom::Err::Failure(_e)) => {
                             SCLogDebug!("NFSPROC4_COMPOUND/GSS INTEGRITIY: Parsing failed: {:?}", _e);
                             self.set_event(NFSEvent::MalformedData);
-                            return 0;
+                            return;
                         },
                     }
                 }
@@ -280,7 +280,6 @@ impl NFSState {
         }
 
         self.requestmap.insert(r.hdr.xid, xidmap);
-        return 0;
     }
 
     fn compound_response<'b>(&mut self, r: &RpcReplyPacket<'b>,
@@ -363,7 +362,7 @@ impl NFSState {
     }
 
     pub fn process_reply_record_v4<'b>(&mut self, r: &RpcReplyPacket<'b>,
-            xidmap: &mut NFSRequestXidMap) -> u32 {
+            xidmap: &mut NFSRequestXidMap) {
         if xidmap.procedure == NFSPROC4_COMPOUND {
             let mut data = r.prog_data;
 
@@ -378,13 +377,13 @@ impl NFSState {
                     Err(nom::Err::Incomplete(_n)) => {
                         SCLogDebug!("NFSPROC4_COMPOUND/GSS INTEGRITIY: INCOMPLETE {:?}", _n);
                         self.set_event(NFSEvent::MalformedData);
-                        return 0;
+                        return;
                     },
                     Err(nom::Err::Error(_e)) |
                     Err(nom::Err::Failure(_e)) => {
                         SCLogDebug!("NFSPROC4_COMPOUND/GSS INTEGRITIY: Parsing failed: {:?}", _e);
                         self.set_event(NFSEvent::MalformedData);
-                        return 0;
+                        return;
                     },
                 }
             }
@@ -403,6 +402,5 @@ impl NFSState {
                 },
             };
         }
-        return 0;
     }
 }
index b7432596f9b947cc4bf4cb53eac4edd51edf090c..23ecfea3df02cd14b7faa491c70ae99f825b53f0 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2015 Open Information Security Foundation
+/* Copyright (C) 2015-2020 Open Information Security Foundation
  *
  * You can copy, redistribute or modify this Program under the terms of
  * the GNU General Public License version 2 as published by the Free
@@ -163,16 +163,14 @@ static AppLayerResult NFSTCPParseRequest(Flow *f, void *state,
     uint16_t file_flags = FileFlowToFlags(f, STREAM_TOSERVER);
     rs_nfs_setfileflags(0, state, file_flags);
 
-    int res;
     if (input == NULL && input_len > 0) {
-        res = rs_nfs_parse_request_tcp_gap(state, input_len);
+        AppLayerResult res = rs_nfs_parse_request_tcp_gap(state, input_len);
+        SCReturnStruct(res);
     } else {
-        res = rs_nfs_parse_request(f, state, pstate, input, input_len, local_data);
+        AppLayerResult res = rs_nfs_parse_request(f, state, pstate,
+                input, input_len, local_data);
+        SCReturnStruct(res);
     }
-    if (res < 0) {
-        SCReturnStruct(APP_LAYER_ERROR);
-    }
-    SCReturnStruct(APP_LAYER_OK);
 }
 
 static AppLayerResult NFSTCPParseResponse(Flow *f, void *state, AppLayerParserState *pstate,
@@ -182,16 +180,14 @@ static AppLayerResult NFSTCPParseResponse(Flow *f, void *state, AppLayerParserSt
     uint16_t file_flags = FileFlowToFlags(f, STREAM_TOCLIENT);
     rs_nfs_setfileflags(1, state, file_flags);
 
-    int res;
     if (input == NULL && input_len > 0) {
-        res = rs_nfs_parse_response_tcp_gap(state, input_len);
+        AppLayerResult res = rs_nfs_parse_response_tcp_gap(state, input_len);
+        SCReturnStruct(res);
     } else {
-        res = rs_nfs_parse_response(f, state, pstate, input, input_len, local_data);
-    }
-    if (res < 0) {
-        SCReturnStruct(APP_LAYER_ERROR);
+        AppLayerResult res = rs_nfs_parse_response(f, state, pstate,
+                input, input_len, local_data);
+        SCReturnStruct(res);
     }
-    SCReturnStruct(APP_LAYER_OK);
 }
 
 static uint64_t NFSTCPGetTxCnt(void *state)
index 2b923177fe41028304d1b23b82cfcc6224786ee6..dab800711a60c0386894b3ad8418260d455c5c5a 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2015 Open Information Security Foundation
+/* Copyright (C) 2015-2020 Open Information Security Foundation
  *
  * You can copy, redistribute or modify this Program under the terms of
  * the GNU General Public License version 2 as published by the Free
@@ -143,11 +143,9 @@ static AppLayerResult NFSParseRequest(Flow *f, void *state,
     uint16_t file_flags = FileFlowToFlags(f, STREAM_TOSERVER);
     rs_nfs_setfileflags(0, state, file_flags);
 
-    int res = rs_nfs_parse_request_udp(f, state, pstate, input, input_len, local_data);
-    if (res < 0) {
-        SCReturnStruct(APP_LAYER_ERROR);
-    }
-    SCReturnStruct(APP_LAYER_OK);
+    AppLayerResult res = rs_nfs_parse_request_udp(f, state, pstate,
+            input, input_len, local_data);
+    SCReturnStruct(res);
 }
 
 static AppLayerResult NFSParseResponse(Flow *f, void *state, AppLayerParserState *pstate,
@@ -157,11 +155,9 @@ static AppLayerResult NFSParseResponse(Flow *f, void *state, AppLayerParserState
     uint16_t file_flags = FileFlowToFlags(f, STREAM_TOCLIENT);
     rs_nfs_setfileflags(1, state, file_flags);
 
-    int res = rs_nfs_parse_response_udp(f, state, pstate, input, input_len, local_data);
-    if (res < 0) {
-        SCReturnStruct(APP_LAYER_ERROR);
-    }
-    SCReturnStruct(APP_LAYER_OK);
+    AppLayerResult res = rs_nfs_parse_response_udp(f, state, pstate,
+            input, input_len, local_data);
+    SCReturnStruct(res);
 }
 
 static uint64_t NFSGetTxCnt(void *state)