]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
rust/sip: parse and log sdp
authorGiuseppe Longo <giuseppe@glongo.it>
Sat, 16 Mar 2024 14:36:42 +0000 (15:36 +0100)
committerVictor Julien <victor@inliniac.net>
Thu, 25 Apr 2024 04:52:25 +0000 (06:52 +0200)
If SDP payload is found within a SIP message, it will be parsed and then
logged.

Ticket #6627

rust/src/sip/log.rs
rust/src/sip/parser.rs

index a7a98d5eb1b3e979d684260c94036619b5cc3321..92989ba95e92bf99296d433ca4747a82eaf9d045 100644 (file)
@@ -18,6 +18,7 @@
 // written by Giuseppe Longo <giuseppe@glongo.it>
 
 use crate::jsonbuilder::{JsonBuilder, JsonError};
+use crate::sdp::logger::sdp_log;
 use crate::sip::sip::SIPTransaction;
 
 fn log(tx: &SIPTransaction, js: &mut JsonBuilder) -> Result<(), JsonError> {
@@ -27,6 +28,10 @@ fn log(tx: &SIPTransaction, js: &mut JsonBuilder) -> Result<(), JsonError> {
         js.set_string("method", &req.method)?
             .set_string("uri", &req.path)?
             .set_string("version", &req.version)?;
+
+        if let Some(sdp_body) = &req.body {
+            let _ = sdp_log(sdp_body, js);
+        }
     }
 
     if let Some(req_line) = &tx.request_line {
@@ -37,6 +42,9 @@ fn log(tx: &SIPTransaction, js: &mut JsonBuilder) -> Result<(), JsonError> {
         js.set_string("version", &resp.version)?
             .set_string("code", &resp.code)?
             .set_string("reason", &resp.reason)?;
+        if let Some(sdp_body) = &resp.body {
+            let _ = sdp_log(sdp_body, js);
+        }
     }
 
     if let Some(resp_line) = &tx.response_line {
index 996201e42b445441d4a8b8e64b9f573b8572beca..a7314f163914064fa29d60081e37f16f0f70ed83 100644 (file)
 
 // written by Giuseppe Longo <giuseppe@glongo.it>
 
+use crate::sdp::parser::{sdp_parse_message, SdpMessage};
 use nom7::bytes::streaming::{tag, take, take_while, take_while1};
 use nom7::character::streaming::{char, crlf};
 use nom7::character::{is_alphabetic, is_alphanumeric, is_digit, is_space};
-use nom7::combinator::map_res;
+use nom7::combinator::{map_res, opt};
 use nom7::sequence::delimited;
 use nom7::{Err, IResult, Needed};
 use std;
@@ -43,6 +44,7 @@ pub struct Request {
     pub headers_len: u16,
     pub body_offset: u16,
     pub body_len: u16,
+    pub body: Option<SdpMessage>,
 }
 
 #[derive(Debug)]
@@ -55,6 +57,7 @@ pub struct Response {
     pub headers_len: u16,
     pub body_offset: u16,
     pub body_len: u16,
+    pub body: Option<SdpMessage>,
 }
 
 /**
@@ -106,8 +109,9 @@ pub fn sip_parse_request(oi: &[u8]) -> IResult<&[u8], Request> {
     let headers_len = hi.len() - phi.len();
     let (bi, _) = crlf(phi)?;
     let body_offset = oi.len() - bi.len();
+    let (i, body) = opt(sdp_parse_message)(bi)?;
     Ok((
-        bi,
+        i,
         Request {
             method: method.into(),
             path: path.into(),
@@ -118,6 +122,7 @@ pub fn sip_parse_request(oi: &[u8]) -> IResult<&[u8], Request> {
             headers_len: headers_len as u16,
             body_offset: body_offset as u16,
             body_len: bi.len() as u16,
+            body,
         },
     ))
 }
@@ -134,8 +139,9 @@ pub fn sip_parse_response(oi: &[u8]) -> IResult<&[u8], Response> {
     let headers_len = hi.len() - phi.len();
     let (bi, _) = crlf(phi)?;
     let body_offset = oi.len() - bi.len();
+    let (i, body) = opt(sdp_parse_message)(bi)?;
     Ok((
-        bi,
+        i,
         Response {
             version,
             code: code.into(),
@@ -145,6 +151,7 @@ pub fn sip_parse_response(oi: &[u8]) -> IResult<&[u8], Response> {
             headers_len: headers_len as u16,
             body_offset: body_offset as u16,
             body_len: bi.len() as u16,
+            body,
         },
     ))
 }