feat(dpi): add SIP protocol detection and metadata extraction#262
Open
0xghost42 wants to merge 1 commit into
Open
feat(dpi): add SIP protocol detection and metadata extraction#2620xghost42 wants to merge 1 commit into
0xghost42 wants to merge 1 commit into
Conversation
Adds best-effort Deep Packet Inspection for plaintext SIP (RFC 3261) over TCP and UDP. SIP shares its request grammar with HTTP, so the detector runs before HTTP analysis and rejects payloads whose trailing version token is not "SIP/2.0" -- this prevents SIP INVITE/OPTIONS/ MESSAGE traffic from being misclassified as HTTP. Detection - Port 5060 (and 5061 hint) plus start-line signature. - Request methods covered: INVITE, ACK, BYE, CANCEL, REGISTER, OPTIONS, PRACK, SUBSCRIBE, NOTIFY, PUBLISH, INFO, REFER, MESSAGE, UPDATE. - Responses keyed off the "SIP/2.0 <status>" prefix. Extracted metadata - Request method / response status code + reason phrase. - From, To, Call-ID, User-Agent, Server headers (both long and compact form: f / t / i / c). - CSeq parsed into cseq_number + cseq_method. - Content-Type plus a derived has_sdp flag for application/sdp. Surfaces - ApplicationProtocol::Sip variant with Display formatter for the connection table. - DPI details panel in the TUI shows message type, method/status, From/To/Call-ID/CSeq/User-Agent/Server/Content-Type. - UDP state string reports SIP_REQUEST / SIP_RESPONSE. - ConnectionFilter general search matches sip, method, Call-ID, From, To, User-Agent, Server. - Per-protocol merge keeps stable identity fields and latest-wins for message_type / method / status / CSeq, mirroring how dialogs evolve. - get_timeout returns 5 min for SIP UDP flows to track idle dialogs. Tests - 10 new unit tests covering request/response parsing, compact headers, HTTP-vs-SIP disambiguation (OPTIONS, /, HTTP/1.1), method coverage, and rejection of truncated or wrongly-versioned payloads. - Full suite: cargo test (335 passed), cargo clippy -D warnings, cargo fmt --check, cargo build --release all clean. Closes domcyrus#260
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #260.
Summary
Adds best-effort Deep Packet Inspection for plaintext SIP (RFC 3261) over TCP and UDP. SIP shares its request grammar with HTTP, so the detector runs before HTTP analysis and rejects payloads whose trailing version token is not
SIP/2.0— this preventsINVITE/OPTIONS/MESSAGEtraffic from being misclassified as HTTP.What it does
Detection
INVITE,ACK,BYE,CANCEL,REGISTER,OPTIONS,PRACK,SUBSCRIBE,NOTIFY,PUBLISH,INFO,REFER,MESSAGE,UPDATE.SIP/2.0 <status>prefix.Extracted metadata (per the issue scope)
From,To,Call-ID,User-Agent,Server(long form + compactf/t/i/c).CSeqparsed intocseq_number+cseq_method.Content-Typeplus a derivedhas_sdpflag forapplication/sdp.Surfaces
ApplicationProtocol::Sip(SipInfo)variant with a Display formatter tuned for the connection-table column (requests show method + Call-ID; responses show status code + reason + CSeq method).From,To,Call-ID,CSeq,User-Agent,Server,Content-Type(with an(SDP)tag whenhas_sdpis set).SIP_REQUEST/SIP_RESPONSE.ConnectionFiltergeneral search matchessip, method, Call-ID, From, To, User-Agent, Server — so existing fuzzy search just works.message_type/method/status_code/CSeq, mirroring how dialogs evolve across multiple packets in the same connection.get_timeoutreturns 5 minutes for SIP UDP flows so idle dialogs stay tracked between transactions.Why detection runs before HTTP
INVITE sip:bob@x SIP/2.0andOPTIONS / HTTP/1.1both look likeMETHOD <uri> <version>. The disambiguator is the trailing version token.sip::is_sipchecks forSIP/2.0in the first line; only then does it consume the payload. HTTP traffic is rejected cheaply by the same check (theOPTIONSmethod also exists in SIP, so an explicit test for that case is included).Tests
10 new unit tests in
src/network/dpi/sip.rs:f,t,i,c).OPTIONS /HTTP is rejected;OPTIONS sip:…is accepted).None.Full suite locally:
cargo test --all-features→ 335 passed, 0 failed.cargo clippy --all-features --all-targets -- -D warnings→ clean.cargo fmt --all -- --check→ clean.cargo build --release→ clean.Test plan
Files touched
src/network/dpi/sip.rs— new module (~340 lines incl. tests).src/network/dpi/mod.rs— register module, addPORT_SIP/PORT_SIP_TLS, dispatch SIP before HTTP for TCP, after binary protocols for UDP.src/network/types.rs—SipInfo,SipMessageType, enum variant, Display arm,sort_key, dist counter, UDP state string, idle timeout.src/network/merge.rs—merge_sip_info(stable fields first-wins, dialog state latest-wins).src/filter.rs— general-search match arm for SIP metadata.src/ui.rs— DPI details panel rendering for SIP.No changes to ROADMAP / README / CONTRIBUTING — happy to add a roadmap tick if you'd prefer.