From cab0fc9133f1596896202195cf157c5913839d5c Mon Sep 17 00:00:00 2001 From: adrien gaultier Date: Mon, 14 Oct 2024 23:13:45 +0200 Subject: [PATCH] add pid remove lock --- Cargo.lock | 1196 ----------------------- maps.py | 4 +- oryx-tui/src/app.rs | 46 +- oryx-tui/src/export.rs | 8 +- oryx-tui/src/filter.rs | 21 +- oryx-tui/src/filter/fuzzy.rs | 14 +- oryx-tui/src/lib.rs | 2 + oryx-tui/src/packet.rs | 73 +- oryx-tui/src/pid.rs | 277 ++++++ oryx-tui/src/section.rs | 6 +- oryx-tui/src/section/alert.rs | 4 +- oryx-tui/src/section/alert/syn_flood.rs | 6 +- oryx-tui/src/section/inspection.rs | 127 ++- oryx-tui/src/section/stats.rs | 11 +- 14 files changed, 509 insertions(+), 1286 deletions(-) delete mode 100644 Cargo.lock create mode 100644 oryx-tui/src/pid.rs diff --git a/Cargo.lock b/Cargo.lock deleted file mode 100644 index fdcb0e8..0000000 --- a/Cargo.lock +++ /dev/null @@ -1,1196 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "aho-corasick" -version = "1.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" -dependencies = [ - "memchr", -] - -[[package]] -name = "allocator-api2" -version = "0.2.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" - -[[package]] -name = "anstream" -version = "0.6.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526" -dependencies = [ - "anstyle", - "anstyle-parse", - "anstyle-query", - "anstyle-wincon", - "colorchoice", - "is_terminal_polyfill", - "utf8parse", -] - -[[package]] -name = "anstyle" -version = "1.0.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" - -[[package]] -name = "anstyle-parse" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb" -dependencies = [ - "utf8parse", -] - -[[package]] -name = "anstyle-query" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a" -dependencies = [ - "windows-sys 0.52.0", -] - -[[package]] -name = "anstyle-wincon" -version = "3.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8" -dependencies = [ - "anstyle", - "windows-sys 0.52.0", -] - -[[package]] -name = "anyhow" -version = "1.0.89" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" - -[[package]] -name = "assert_matches" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b34d609dfbaf33d6889b2b7106d3ca345eacad44200913df5ba02bfd31d2ba9" - -[[package]] -name = "autocfg" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" - -[[package]] -name = "aya" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7127cbe933572dfabb7a87d2c740f5b720c3e19b4d2b8c99a262ffa35c8761ff" -dependencies = [ - "assert_matches", - "aya-obj", - "bitflags", - "bytes", - "libc", - "log", - "object", - "once_cell", - "thiserror", -] - -[[package]] -name = "aya-obj" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56e133d505de14d5948a312060b8b12752c22a965632cc57da12f5db653de4c0" -dependencies = [ - "bytes", - "core-error", - "hashbrown", - "log", - "object", - "thiserror", -] - -[[package]] -name = "bitflags" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" - -[[package]] -name = "bytes" -version = "1.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" - -[[package]] -name = "cassowary" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df8670b8c7b9dae1793364eafadf7239c40d669904660c5960d74cfd80b46a53" - -[[package]] -name = "castaway" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0abae9be0aaf9ea96a3b1b8b1b55c602ca751eba1b1500220cea4ecbafe7c0d5" -dependencies = [ - "rustversion", -] - -[[package]] -name = "cc" -version = "1.1.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b16803a61b81d9eabb7eae2588776c4c1e584b738ede45fdbb4c972cec1e9945" -dependencies = [ - "shlex", -] - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "clap" -version = "4.5.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b97f376d85a664d5837dbae44bf546e6477a679ff6610010f17276f686d867e8" -dependencies = [ - "clap_builder", - "clap_derive", -] - -[[package]] -name = "clap_builder" -version = "4.5.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19bc80abd44e4bed93ca373a0704ccbd1b710dc5749406201bb018272808dc54" -dependencies = [ - "anstream", - "anstyle", - "clap_lex", - "strsim", -] - -[[package]] -name = "clap_derive" -version = "4.5.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ac6a0c7b1a9e9a5186361f67dfa1b88213572f427fb9ab038efb2bd8c582dab" -dependencies = [ - "heck", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "clap_lex" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" - -[[package]] -name = "colorchoice" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" - -[[package]] -name = "compact_str" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6050c3a16ddab2e412160b31f2c871015704239bca62f72f6e5f0be631d3f644" -dependencies = [ - "castaway", - "cfg-if", - "itoa", - "rustversion", - "ryu", - "static_assertions", -] - -[[package]] -name = "core-error" -version = "0.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efcdb2972eb64230b4c50646d8498ff73f5128d196a90c7236eec4cbe8619b8f" -dependencies = [ - "version_check", -] - -[[package]] -name = "crc32fast" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "crossterm" -version = "0.28.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "829d955a0bb380ef178a640b91779e3987da38c9aea133b20614cfed8cdea9c6" -dependencies = [ - "bitflags", - "crossterm_winapi", - "mio", - "parking_lot", - "rustix", - "signal-hook", - "signal-hook-mio", - "winapi", -] - -[[package]] -name = "crossterm_winapi" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acdd7c62a3665c7f6830a51635d9ac9b23ed385797f70a83bb8bafe9c572ab2b" -dependencies = [ - "winapi", -] - -[[package]] -name = "darling" -version = "0.20.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f63b86c8a8826a49b8c21f08a2d07338eec8d900540f8630dc76284be802989" -dependencies = [ - "darling_core", - "darling_macro", -] - -[[package]] -name = "darling_core" -version = "0.20.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95133861a8032aaea082871032f5815eb9e98cef03fa916ab4500513994df9e5" -dependencies = [ - "fnv", - "ident_case", - "proc-macro2", - "quote", - "strsim", - "syn", -] - -[[package]] -name = "darling_macro" -version = "0.20.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" -dependencies = [ - "darling_core", - "quote", - "syn", -] - -[[package]] -name = "derive_builder" -version = "0.20.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "507dfb09ea8b7fa618fcf76e953f4f5e192547945816d5358edffe39f6f94947" -dependencies = [ - "derive_builder_macro", -] - -[[package]] -name = "derive_builder_core" -version = "0.20.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d5bcf7b024d6835cfb3d473887cd966994907effbe9227e8c8219824d06c4e8" -dependencies = [ - "darling", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "derive_builder_macro" -version = "0.20.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab63b0e2bf4d5928aff72e83a7dace85d7bba5fe12dcc3c5a572d78caffd3f3c" -dependencies = [ - "derive_builder_core", - "syn", -] - -[[package]] -name = "dirs" -version = "5.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225" -dependencies = [ - "dirs-sys", -] - -[[package]] -name = "dirs-sys" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c" -dependencies = [ - "libc", - "option-ext", - "redox_users", - "windows-sys 0.48.0", -] - -[[package]] -name = "either" -version = "1.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" - -[[package]] -name = "env_filter" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f2c92ceda6ceec50f43169f9ee8424fe2db276791afde7b2cd8bc084cb376ab" -dependencies = [ - "log", - "regex", -] - -[[package]] -name = "env_logger" -version = "0.11.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e13fa619b91fb2381732789fc5de83b45675e882f66623b7d8cb4f643017018d" -dependencies = [ - "anstream", - "anstyle", - "env_filter", - "humantime", - "log", -] - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "errno" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - -[[package]] -name = "foldhash" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f81ec6369c545a7d40e4589b5597581fa1c441fe1cce96dd1de43159910a36a2" - -[[package]] -name = "font8x8" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "875488b8711a968268c7cf5d139578713097ca4635a76044e8fe8eedf831d07e" - -[[package]] -name = "futures-core" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" - -[[package]] -name = "getrandom" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" -dependencies = [ - "cfg-if", - "libc", - "wasi", -] - -[[package]] -name = "hashbrown" -version = "0.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" -dependencies = [ - "allocator-api2", - "equivalent", - "foldhash", -] - -[[package]] -name = "heck" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" - -[[package]] -name = "hermit-abi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" - -[[package]] -name = "humantime" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" - -[[package]] -name = "ident_case" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" - -[[package]] -name = "indexmap" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" -dependencies = [ - "equivalent", - "hashbrown", -] - -[[package]] -name = "instability" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b23a0c8dfe501baac4adf6ebbfa6eddf8f0c07f56b058cc1288017e32397846c" -dependencies = [ - "quote", - "syn", -] - -[[package]] -name = "is_terminal_polyfill" -version = "1.70.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" - -[[package]] -name = "itertools" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" -dependencies = [ - "either", -] - -[[package]] -name = "itoa" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" - -[[package]] -name = "kanal" -version = "0.1.0-pre8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b05d55519627edaf7fd0f29981f6dc03fb52df3f5b257130eb8d0bf2801ea1d7" -dependencies = [ - "futures-core", - "lock_api", -] - -[[package]] -name = "libc" -version = "0.2.159" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" - -[[package]] -name = "libmimalloc-sys" -version = "0.1.39" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23aa6811d3bd4deb8a84dde645f943476d13b248d818edcf8ce0b2f37f036b44" -dependencies = [ - "cc", - "libc", -] - -[[package]] -name = "libredox" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" -dependencies = [ - "bitflags", - "libc", -] - -[[package]] -name = "linux-raw-sys" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" - -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - -[[package]] -name = "log" -version = "0.4.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" - -[[package]] -name = "lru" -version = "0.12.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "234cf4f4a04dc1f57e24b96cc0cd600cf2af460d4161ac5ecdd0af8e1f3b2a38" -dependencies = [ - "hashbrown", -] - -[[package]] -name = "memchr" -version = "2.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" - -[[package]] -name = "mimalloc" -version = "0.1.43" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68914350ae34959d83f732418d51e2427a794055d0b9529f48259ac07af65633" -dependencies = [ - "libmimalloc-sys", -] - -[[package]] -name = "mio" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec" -dependencies = [ - "hermit-abi", - "libc", - "log", - "wasi", - "windows-sys 0.52.0", -] - -[[package]] -name = "network-types" -version = "0.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e82e9f64c09f56aa7c80c3fa087997bd99a913f91d9c74d36cf5fd75dd5773e6" - -[[package]] -name = "object" -version = "0.36.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aedf0a2d09c573ed1d8d85b30c119153926a2b36dce0ab28322c09a117a4683e" -dependencies = [ - "crc32fast", - "hashbrown", - "indexmap", - "memchr", -] - -[[package]] -name = "once_cell" -version = "1.20.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" - -[[package]] -name = "option-ext" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" - -[[package]] -name = "oryx-common" -version = "0.4.0" -dependencies = [ - "network-types", -] - -[[package]] -name = "oryx-tui" -version = "0.4.0" -dependencies = [ - "aya", - "clap", - "crossterm", - "dirs", - "env_logger", - "itertools", - "kanal", - "libc", - "log", - "mimalloc", - "mio", - "network-types", - "oryx-common", - "ratatui", - "serde", - "serde_json", - "tui-big-text", - "tui-input", - "uuid", -] - -[[package]] -name = "parking_lot" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets 0.52.6", -] - -[[package]] -name = "paste" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" - -[[package]] -name = "proc-macro2" -version = "1.0.87" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3e4daa0dcf6feba26f985457cdf104d4b4256fc5a09547140f3631bb076b19a" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.37" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "ratatui" -version = "0.28.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fdef7f9be5c0122f890d58bdf4d964349ba6a6161f705907526d891efabba57d" -dependencies = [ - "bitflags", - "cassowary", - "compact_str", - "crossterm", - "instability", - "itertools", - "lru", - "paste", - "strum", - "strum_macros", - "unicode-segmentation", - "unicode-truncate", - "unicode-width", -] - -[[package]] -name = "redox_syscall" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" -dependencies = [ - "bitflags", -] - -[[package]] -name = "redox_users" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43" -dependencies = [ - "getrandom", - "libredox", - "thiserror", -] - -[[package]] -name = "regex" -version = "1.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38200e5ee88914975b69f657f0801b6f6dccafd44fd9326302a4aaeecfacb1d8" -dependencies = [ - "aho-corasick", - "memchr", - "regex-automata", - "regex-syntax", -] - -[[package]] -name = "regex-automata" -version = "0.4.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "368758f23274712b504848e9d5a6f010445cc8b87a7cdb4d7cbee666c1288da3" -dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", -] - -[[package]] -name = "regex-syntax" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" - -[[package]] -name = "rustix" -version = "0.38.37" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", -] - -[[package]] -name = "rustversion" -version = "1.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e819f2bc632f285be6d7cd36e25940d45b2391dd6d9b939e79de557f7014248" - -[[package]] -name = "ryu" -version = "1.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" - -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "serde" -version = "1.0.210" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.210" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "serde_json" -version = "1.0.128" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" -dependencies = [ - "itoa", - "memchr", - "ryu", - "serde", -] - -[[package]] -name = "shlex" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" - -[[package]] -name = "signal-hook" -version = "0.3.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8621587d4798caf8eb44879d42e56b9a93ea5dcd315a6487c357130095b62801" -dependencies = [ - "libc", - "signal-hook-registry", -] - -[[package]] -name = "signal-hook-mio" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34db1a06d485c9142248b7a054f034b349b212551f3dfd19c94d45a754a217cd" -dependencies = [ - "libc", - "mio", - "signal-hook", -] - -[[package]] -name = "signal-hook-registry" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" -dependencies = [ - "libc", -] - -[[package]] -name = "smallvec" -version = "1.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" - -[[package]] -name = "static_assertions" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" - -[[package]] -name = "strsim" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" - -[[package]] -name = "strum" -version = "0.26.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06" -dependencies = [ - "strum_macros", -] - -[[package]] -name = "strum_macros" -version = "0.26.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be" -dependencies = [ - "heck", - "proc-macro2", - "quote", - "rustversion", - "syn", -] - -[[package]] -name = "syn" -version = "2.0.79" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "thiserror" -version = "1.0.64" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.64" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "tui-big-text" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "399b145b30537641e56878b64bf648e04e1df996efb5d32cd7f19944152e3868" -dependencies = [ - "derive_builder", - "font8x8", - "itertools", - "ratatui", -] - -[[package]] -name = "tui-input" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd137780d743c103a391e06fe952487f914b299a4fe2c3626677f6a6339a7c6b" -dependencies = [ - "ratatui", - "unicode-width", -] - -[[package]] -name = "unicode-ident" -version = "1.0.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" - -[[package]] -name = "unicode-segmentation" -version = "1.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" - -[[package]] -name = "unicode-truncate" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3644627a5af5fa321c95b9b235a72fd24cd29c648c2c379431e6628655627bf" -dependencies = [ - "itertools", - "unicode-segmentation", - "unicode-width", -] - -[[package]] -name = "unicode-width" -version = "0.1.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" - -[[package]] -name = "utf8parse" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" - -[[package]] -name = "uuid" -version = "1.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8c5f0a0af699448548ad1a2fbf920fb4bee257eae39953ba95cb84891a0446a" -dependencies = [ - "getrandom", - "serde", -] - -[[package]] -name = "version_check" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets 0.52.6", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", -] - -[[package]] -name = "windows-targets" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" -dependencies = [ - "windows_aarch64_gnullvm 0.52.6", - "windows_aarch64_msvc 0.52.6", - "windows_i686_gnu 0.52.6", - "windows_i686_gnullvm", - "windows_i686_msvc 0.52.6", - "windows_x86_64_gnu 0.52.6", - "windows_x86_64_gnullvm 0.52.6", - "windows_x86_64_msvc 0.52.6", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" - -[[package]] -name = "xtask" -version = "0.1.0" -dependencies = [ - "anyhow", - "clap", -] diff --git a/maps.py b/maps.py index 885c4af..520ee56 100644 --- a/maps.py +++ b/maps.py @@ -4,7 +4,7 @@ from functools import partial def hex2int(hex): - return int(hex.replace("0x", ""), 16) + return int(hex, 16) def parse_ipv4(rule): @@ -33,8 +33,6 @@ def parse_ipv6(rule): return {k: v} - - filter_idx_map = dict( transport={0: "tcp", 1: "udp"}, network={0: "ipv4", 1: "ipv6", 2: "icmp"}, diff --git a/oryx-tui/src/app.rs b/oryx-tui/src/app.rs index c1c528b..d47f438 100644 --- a/oryx-tui/src/app.rs +++ b/oryx-tui/src/app.rs @@ -12,7 +12,7 @@ use std::{ use crate::{filter::Filter, help::Help}; use crate::{filter::IoChannels, notification::Notification}; -use crate::{packet::AppPacket, section::Section}; +use crate::{packet::NetworkPacket, section::Section}; pub type AppResult = std::result::Result>; @@ -31,6 +31,17 @@ pub struct DataEventHandler { pub sender: kanal::Sender<[u8; RawPacket::LEN]>, pub handler: thread::JoinHandle<()>, } +#[derive(Debug, Clone)] +pub struct Channels { + pub sender: kanal::Sender, + pub receiver: kanal::Receiver, +} +impl Channels { + pub fn new() -> Self { + let (sender, receiver) = kanal::unbounded(); + Self { sender, receiver } + } +} #[derive(Debug)] pub struct App { @@ -38,7 +49,7 @@ pub struct App { pub help: Help, pub filter: Filter, pub start_sniffing: bool, - pub packets: Arc>>, + pub packets: Arc>>, pub notifications: Vec, pub section: Section, pub data_channel_sender: kanal::Sender<[u8; RawPacket::LEN]>, @@ -54,34 +65,37 @@ impl Default for App { impl App { pub fn new() -> Self { - let packets = Arc::new(Mutex::new(Vec::with_capacity(AppPacket::LEN * 1024 * 1024))); + let net_packets: Arc>> = Arc::new(Mutex::new(Vec::with_capacity( + NetworkPacket::LEN * 1024 * 1024, + ))); + let data_channels = Channels::new(); - let (sender, receiver) = kanal::unbounded(); - - let firewall_channels = IoChannels::new(); thread::spawn({ - let packets = packets.clone(); + let net_packets = net_packets.clone(); move || loop { - if let Ok(raw_packet) = receiver.recv() { - let app_packet = AppPacket::from(raw_packet); - let mut packets = packets.lock().unwrap(); - if packets.len() == packets.capacity() { - packets.reserve(1024 * 1024); + if let Ok(raw_packet) = data_channels.receiver.recv() { + let network_packet = NetworkPacket::from(raw_packet); + let mut net_packets = net_packets.lock().unwrap(); + if net_packets.len() == net_packets.capacity() { + net_packets.reserve(1024 * 1024); } - packets.push(app_packet); + + net_packets.push(network_packet); } } }); + let firewall_channels = IoChannels::new(); + Self { running: true, help: Help::new(), filter: Filter::new(firewall_channels.clone()), start_sniffing: false, - packets: packets.clone(), + packets: net_packets.clone(), notifications: Vec::new(), - section: Section::new(packets.clone(), firewall_channels.clone()), - data_channel_sender: sender, + section: Section::new(net_packets.clone(), firewall_channels.clone()), + data_channel_sender: data_channels.sender, is_editing: false, active_popup: None, } diff --git a/oryx-tui/src/export.rs b/oryx-tui/src/export.rs index 78599ca..c03ba33 100644 --- a/oryx-tui/src/export.rs +++ b/oryx-tui/src/export.rs @@ -8,11 +8,11 @@ use crate::{ app::AppResult, packet::{ network::{IpPacket, IpProto}, - AppPacket, + NetworkPacket, }, }; -pub fn export(packets: &[AppPacket]) -> AppResult<()> { +pub fn export(packets: &[NetworkPacket]) -> AppResult<()> { let uid = unsafe { libc::geteuid() }; let oryx_export_dir = dirs::home_dir().unwrap().join("oryx"); @@ -40,7 +40,7 @@ pub fn export(packets: &[AppPacket]) -> AppResult<()> { )?; for packet in packets { match packet { - AppPacket::Arp(p) => { + NetworkPacket::Arp(p) => { writeln!( file, "{:39} {:^11} {:39} {:^11} ARP", @@ -50,7 +50,7 @@ pub fn export(packets: &[AppPacket]) -> AppResult<()> { "-" )?; } - AppPacket::Ip(packet) => match packet { + NetworkPacket::Ip(packet) => match packet { IpPacket::V4(ipv4_packet) => match ipv4_packet.proto { IpProto::Tcp(p) => { writeln!( diff --git a/oryx-tui/src/filter.rs b/oryx-tui/src/filter.rs index a62a717..04f494b 100644 --- a/oryx-tui/src/filter.rs +++ b/oryx-tui/src/filter.rs @@ -26,7 +26,7 @@ use transport::TransportFilter; use tui_big_text::{BigText, PixelSize}; use crate::{ - app::AppResult, + app::{AppResult, Channels}, ebpf::{egress::load_egress, ingress::load_ingress}, event::Event, interface::Interface, @@ -40,25 +40,12 @@ pub enum FilterChannelSignal { Kill, } -#[derive(Debug, Clone)] -pub struct Channels { - pub sender: kanal::Sender, - pub receiver: kanal::Receiver, -} - #[derive(Debug, Clone)] pub struct IoChannels { pub ingress: Channels, pub egress: Channels, } -impl Channels { - pub fn new() -> Self { - let (sender, receiver) = kanal::unbounded(); - Self { sender, receiver } - } -} - impl IoChannels { pub fn new() -> Self { Self { @@ -68,12 +55,6 @@ impl IoChannels { } } -impl Default for Channels { - fn default() -> Self { - Self::new() - } -} - impl Default for IoChannels { fn default() -> Self { Self::new() diff --git a/oryx-tui/src/filter/fuzzy.rs b/oryx-tui/src/filter/fuzzy.rs index 124b45a..a8321b4 100644 --- a/oryx-tui/src/filter/fuzzy.rs +++ b/oryx-tui/src/filter/fuzzy.rs @@ -11,20 +11,20 @@ use ratatui::{ }; use tui_input::Input; -use crate::{app::TICK_RATE, packet::AppPacket}; +use crate::{app::TICK_RATE, packet::NetworkPacket}; #[derive(Debug, Clone, Default)] pub struct Fuzzy { enabled: bool, paused: bool, pub filter: Input, - pub packets: Vec, + pub packets: Vec, pub scroll_state: TableState, pub packet_end_index: usize, } impl Fuzzy { - pub fn new(packets: Arc>>) -> Arc> { + pub fn new(packets: Arc>>) -> Arc> { let fuzzy = Arc::new(Mutex::new(Self::default())); thread::spawn({ @@ -94,21 +94,21 @@ impl Fuzzy { self.scroll_state.select(Some(i)); } - pub fn find(&mut self, packets: &[AppPacket]) { + pub fn find(&mut self, packets: &[NetworkPacket]) { self.packets = packets .iter() .copied() .filter(|p| p.to_string().contains(self.filter.value())) - .collect::>(); + .collect::>(); } - pub fn append(&mut self, packets: &[AppPacket]) { + pub fn append(&mut self, packets: &[NetworkPacket]) { self.packets.append( &mut packets .iter() .copied() .filter(|p| p.to_string().contains(self.filter.value())) - .collect::>(), + .collect::>(), ); } diff --git a/oryx-tui/src/lib.rs b/oryx-tui/src/lib.rs index 7a46ac4..f6f24f0 100644 --- a/oryx-tui/src/lib.rs +++ b/oryx-tui/src/lib.rs @@ -27,3 +27,5 @@ pub mod packet; pub mod section; pub mod dns; + +pub mod pid; diff --git a/oryx-tui/src/packet.rs b/oryx-tui/src/packet.rs index 543469d..29473a0 100644 --- a/oryx-tui/src/packet.rs +++ b/oryx-tui/src/packet.rs @@ -10,17 +10,78 @@ use network_types::ip::IpHdr; use oryx_common::{ProtoHdr, RawPacket}; use transport::{TcpPacket, UdpPacket}; +use crate::pid::IpMap; + #[derive(Debug, Copy, Clone)] -pub enum AppPacket { +pub enum NetworkPacket { Ip(IpPacket), Arp(ArpPacket), } -impl AppPacket { +impl NetworkPacket { pub const LEN: usize = mem::size_of::(); } -impl Display for AppPacket { +#[derive(Debug, Copy, Clone)] +pub struct AppPacket { + pub packet: NetworkPacket, + pub pid: Option, +} + +impl AppPacket { + pub fn from_network_packet( + netpacket: &NetworkPacket, + tcp_map: &IpMap, + udp_map: &IpMap, + ) -> Self { + let pid = match netpacket { + NetworkPacket::Ip(IpPacket::V4(ipv4packet)) => match ipv4packet.proto { + IpProto::Tcp(_) => netpacket.try_get_pid(tcp_map), + IpProto::Udp(_) => netpacket.try_get_pid(udp_map), + _ => None, + }, + _ => None, + }; + Self { + packet: *netpacket, + pid, + } + } +} + +impl NetworkPacket { + fn get_possible_keys(&self) -> Option<[String; 2]> { + match self { + NetworkPacket::Ip(IpPacket::V4(ipv4packet)) => { + let src_ip = ipv4packet.src_ip; + let dst_ip = ipv4packet.dst_ip; + match ipv4packet.proto { + IpProto::Tcp(tcp) => Some([ + format!("{}:{}_{}:{}", src_ip, tcp.src_port, dst_ip, tcp.dst_port), + format!("{}:{}_{}:{}", dst_ip, tcp.dst_port, src_ip, tcp.src_port), + ]), + IpProto::Udp(udp) => Some([ + format!("{}:{}_{}:{}", src_ip, udp.src_port, dst_ip, udp.dst_port), + format!("{}:{}_{}:{}", dst_ip, udp.dst_port, src_ip, udp.src_port), + ]), + _ => None, + } + } + _ => None, + } + } + pub fn try_get_pid(&self, ipmap: &IpMap) -> Option { + if let Some(keys) = self.get_possible_keys() { + for k in keys { + if let Some(conn) = ipmap.map.get(&k) { + return conn.pid; + } + } + } + None + } +} +impl Display for NetworkPacket { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { match self { Self::Arp(packet) => write!(f, "{}", packet), @@ -29,7 +90,7 @@ impl Display for AppPacket { } } -impl From<[u8; RawPacket::LEN]> for AppPacket { +impl From<[u8; RawPacket::LEN]> for NetworkPacket { fn from(value: [u8; RawPacket::LEN]) -> Self { let raw_packet = value.as_ptr() as *const RawPacket; match unsafe { &*raw_packet } { @@ -87,7 +148,7 @@ impl From<[u8; RawPacket::LEN]> for AppPacket { } }; - AppPacket::Ip(IpPacket::V4(Ipv4Packet { + NetworkPacket::Ip(IpPacket::V4(Ipv4Packet { src_ip, dst_ip, ihl: u8::from_be(ipv4_packet.ihl()), @@ -153,7 +214,7 @@ impl From<[u8; RawPacket::LEN]> for AppPacket { } }; - AppPacket::Ip(IpPacket::V6(Ipv6Packet { + NetworkPacket::Ip(IpPacket::V6(Ipv6Packet { traffic_class: ipv6_packet.priority(), flow_label: ipv6_packet.flow_label, payload_length: u16::from_be(ipv6_packet.payload_len), diff --git a/oryx-tui/src/pid.rs b/oryx-tui/src/pid.rs new file mode 100644 index 0000000..3aef5b2 --- /dev/null +++ b/oryx-tui/src/pid.rs @@ -0,0 +1,277 @@ +use std::collections::HashMap; +use std::fs::{self, File}; +use std::io::{Read, Seek}; + +use std::net::IpAddr; +use std::num::ParseIntError; +use std::sync::{Arc, Mutex}; +use std::thread; +use std::time::Duration; + +use itertools::chain; +use log::info; + +use crate::app::AppResult; + +#[derive(Clone, Debug)] +pub struct Connection { + ip_local: IpAddr, + port_local: u16, + ip_remote: IpAddr, + port_remote: u16, + inode: u32, + pub pid: Option, +} +impl Connection { + pub fn key(&self) -> String { + format!( + "{}:{}_{}:{}", + self.ip_local, self.port_local, self.ip_remote, self.port_remote + ) + } + fn try_get_pid(&mut self, inode_pid_map_map: &HashMap) { + self.pid = inode_pid_map_map.get(&self.inode).copied(); + } +} + +impl TryFrom<&Vec<&str>> for Connection { + type Error = Box; + fn try_from(splits: &Vec<&str>) -> Result { + let ip_local: &str = splits[1]; + let mut ip_local_port = ip_local.split(":"); + let ip_local = ip_local_port.next().unwrap(); + let port_local = ip_local_port.next().unwrap(); + + let ip_local = match decode_hex_ipv4(ip_local) { + Ok(ip) => IpAddr::try_from(ip)?, + _ => IpAddr::try_from(decode_hex_ipv6(ip_local)?)?, + }; + + let port_local = decode_hex_port(port_local)?; + + let ip_remote = splits[2]; + let mut ip_remote_port = ip_remote.split(":"); + let ip_remote = ip_remote_port.next().unwrap(); + let port_remote = ip_remote_port.next().unwrap(); + + let ip_remote = match decode_hex_ipv4(ip_remote) { + Ok(ip) => IpAddr::try_from(ip)?, + _ => IpAddr::try_from(decode_hex_ipv6(ip_remote)?)?, + }; + let port_remote = decode_hex_port(port_remote)?; + + let inode = splits[9].parse::().unwrap(); + + Ok(Self { + ip_local, + port_local, + ip_remote, + port_remote, + + inode, + pid: None, + }) + } +} + +#[derive(Clone, Debug)] +pub struct IpMap { + pub map: HashMap, +} + +impl IpMap { + pub fn new() -> Self { + Self { + map: HashMap::new(), + } + } +} + +fn build_inode_map(target_inodes: Vec) -> HashMap { + let mut res = HashMap::::new(); + // Iterate over all directories in /proc (these represent PIDs) + if let Ok(entries) = fs::read_dir("/proc") { + for entry in entries.flatten() { + let pid_str = entry.file_name().to_str().unwrap().to_string(); + if !pid_str.chars().all(char::is_numeric) { + continue; + } + let fd_dir = format!("/proc/{}/fd", pid_str); + if let Ok(fds) = fs::read_dir(&fd_dir) { + for fd in fds.flatten() { + let link_path = fd.path(); + + if let Ok(link_target) = fs::read_link(&link_path) { + // Socket inodes are typically shown as "socket:[inode]" + if let Some(inode_str) = link_target.to_str() { + if inode_str.starts_with("socket:[") && inode_str.ends_with(']') { + if let Ok(inode) = inode_str[8..inode_str.len() - 1].parse::() + { + if target_inodes.contains(&inode) { + res.insert(inode, pid_str.parse::().unwrap()); + } + } + } + } + } + } + } + } + } + + res +} +fn decode_hex_port(hex_str: &str) -> Result { + Ok(u16::from_be_bytes([ + u8::from_str_radix(&hex_str[..2], 16)?, + u8::from_str_radix(&hex_str[2..], 16)?, + ])) +} + +fn decode_hex_ipv4(hex_str: &str) -> AppResult<[u8; 4]> { + let mut bytes = Vec::new(); + // Iterate over the string in chunks of 2 characters + for i in (0..hex_str.len()).step_by(2) { + // Get the current 2-character chunk + let byte_str = &hex_str[i..i + 2]; + + let byte = u8::from_str_radix(byte_str, 16)?; + bytes.push(byte); + } + let mut res: [u8; 4] = bytes.as_slice().try_into()?; + res.reverse(); + Ok(res) +} + +fn decode_hex_ipv6(hex_str: &str) -> AppResult<[u8; 4]> { + let mut bytes = Vec::new(); + // Iterate over the string in chunks of 2 characters + for i in (0..hex_str.len()).step_by(4) { + // Get the current 2-character chunk + let byte_str = &hex_str[i..i + 4]; + + let byte = u8::from_str_radix(byte_str, 16)?; + bytes.push(byte); + } + let mut res: [u8; 4] = bytes.as_slice().try_into()?; + res.reverse(); + Ok(res) +} + +#[derive(Debug)] +pub struct ConnectionsInfo { + sender: kanal::Sender<(IpMap, IpMap)>, +} + +impl ConnectionsInfo { + pub fn get_used_inodes(tcp_map: &IpMap, udp_map: &IpMap) -> Vec { + let mut res = Vec::new(); + + for (_, conn) in tcp_map.map.iter() { + res.push(conn.inode); + } + + for (_, conn) in udp_map.map.iter() { + res.push(conn.inode); + } + res + } + pub fn new(sender: kanal::Sender<(IpMap, IpMap)>) -> Self { + Self { sender } + } + + pub fn spawn(&self) { + let tcp_map: Arc> = Arc::new(Mutex::new(IpMap::new())); + let udp_map: Arc> = Arc::new(Mutex::new(IpMap::new())); + thread::spawn({ + let tcp_map = tcp_map.clone(); + let mut fd_tcp = File::open("/proc/net/tcp").unwrap(); + let mut fd_tcp6 = File::open("/proc/net/tcp6").unwrap(); + move || { + loop { + thread::sleep(Duration::from_millis(250)); + fd_tcp.seek(std::io::SeekFrom::Start(0)).unwrap(); + fd_tcp6.seek(std::io::SeekFrom::Start(0)).unwrap(); + + let mut buffer_tcp = String::new(); + let mut buffer_tcp6 = String::new(); + fd_tcp.read_to_string(&mut buffer_tcp).unwrap(); + fd_tcp6.read_to_string(&mut buffer_tcp6).unwrap(); + + let mut lines_tcp = buffer_tcp.lines(); + let mut lines_tcp6 = buffer_tcp6.lines(); + lines_tcp.next(); //header + lines_tcp6.next(); //header + + let mut map = tcp_map.lock().unwrap(); + for line in chain(lines_tcp, lines_tcp6) { + let splits: Vec<&str> = line.split_whitespace().collect(); + + match Connection::try_from(&splits) { + Ok(conn) => { + map.map.insert(conn.key(), conn); + } + _ => {} //error!("error parsing tcp conn{:#?}", splits)}, + } + } + info!("{:#?}", map); + } + } + }); + + thread::spawn({ + let udp_map = udp_map.clone(); + + move || { + let mut fd_udp = File::open("/proc/net/udp").unwrap(); + + loop { + thread::sleep(Duration::from_millis(250)); + fd_udp.seek(std::io::SeekFrom::Start(0)).unwrap(); + let mut buffer = String::new(); + fd_udp.read_to_string(&mut buffer).unwrap(); + + let mut lines = buffer.lines(); + + lines.next(); //header + let mut map = udp_map.lock().unwrap(); + for line in lines { + let splits: Vec<&str> = line.split_whitespace().collect(); + + match Connection::try_from(&splits) { + Ok(conn) => { + map.map.insert(conn.key(), conn); + } + _ => {} //error!("error parsing udp conn {:#?}", splits), + } + } + } + } + }); + + thread::spawn({ + let tcp_map = tcp_map.clone(); + let udp_map = udp_map.clone(); + let sender = self.sender.clone(); + move || loop { + thread::sleep(Duration::from_millis(500)); + + let mut _udp_map = udp_map.lock().unwrap(); + let mut _tcp_map = tcp_map.lock().unwrap(); + + let inodes = Self::get_used_inodes(&_tcp_map, &_udp_map); + + let inode_pid_map_map = build_inode_map(inodes); + + for (_, conn) in _udp_map.map.iter_mut() { + conn.try_get_pid(&inode_pid_map_map); + } + for (_, conn) in _tcp_map.map.iter_mut() { + conn.try_get_pid(&inode_pid_map_map); + } + + sender.send((_tcp_map.clone(), _udp_map.clone())).ok(); + } + }); + } +} diff --git a/oryx-tui/src/section.rs b/oryx-tui/src/section.rs index e9db88e..b73bd9f 100644 --- a/oryx-tui/src/section.rs +++ b/oryx-tui/src/section.rs @@ -23,7 +23,7 @@ use crate::{ app::{ActivePopup, AppResult}, event::Event, filter::IoChannels, - packet::AppPacket, + packet::NetworkPacket, }; #[derive(Debug, PartialEq)] @@ -45,11 +45,13 @@ pub struct Section { impl Section { pub fn new( - packets: Arc>>, + packets: Arc>>, + firewall_chans: IoChannels, ) -> Self { Self { focused_section: FocusedSection::Inspection, + inspection: Inspection::new(packets.clone()), stats: None, alert: Alert::new(packets.clone()), diff --git a/oryx-tui/src/section/alert.rs b/oryx-tui/src/section/alert.rs index 7263f57..15f4653 100644 --- a/oryx-tui/src/section/alert.rs +++ b/oryx-tui/src/section/alert.rs @@ -9,7 +9,7 @@ use ratatui::{ use std::sync::{atomic::Ordering, Arc, Mutex}; use syn_flood::SynFlood; -use crate::packet::AppPacket; +use crate::packet::NetworkPacket; #[derive(Debug)] pub struct Alert { @@ -19,7 +19,7 @@ pub struct Alert { } impl Alert { - pub fn new(packets: Arc>>) -> Self { + pub fn new(packets: Arc>>) -> Self { Self { syn_flood: SynFlood::new(packets), flash_count: 1, diff --git a/oryx-tui/src/section/alert/syn_flood.rs b/oryx-tui/src/section/alert/syn_flood.rs index c93dfc1..6c85ea3 100644 --- a/oryx-tui/src/section/alert/syn_flood.rs +++ b/oryx-tui/src/section/alert/syn_flood.rs @@ -16,7 +16,7 @@ use ratatui::{ use crate::packet::{ network::{IpPacket, IpProto}, - AppPacket, + NetworkPacket, }; const WIN_SIZE: usize = 100_000; @@ -28,7 +28,7 @@ pub struct SynFlood { } impl SynFlood { - pub fn new(packets: Arc>>) -> Self { + pub fn new(packets: Arc>>) -> Self { let map: Arc>> = Arc::new(Mutex::new(HashMap::new())); let detected = Arc::new(AtomicBool::new(false)); @@ -60,7 +60,7 @@ impl SynFlood { app_packets[start_index..app_packets.len().saturating_sub(1)] .iter() .for_each(|packet| { - if let AppPacket::Ip(ip_packet) = packet { + if let NetworkPacket::Ip(ip_packet) = packet { if let IpPacket::V4(ipv4_packet) = ip_packet { if let IpProto::Tcp(tcp_packet) = ipv4_packet.proto { if tcp_packet.syn == 1 { diff --git a/oryx-tui/src/section/inspection.rs b/oryx-tui/src/section/inspection.rs index 9bbca58..4370ae5 100644 --- a/oryx-tui/src/section/inspection.rs +++ b/oryx-tui/src/section/inspection.rs @@ -1,6 +1,11 @@ -use std::sync::{Arc, Mutex}; +use std::{ + sync::{Arc, Mutex}, + thread, +}; use crossterm::event::{KeyCode, KeyEvent}; + +use log::info; use ratatui::{ layout::{Alignment, Constraint, Direction, Flex, Layout, Margin, Rect}, style::{Style, Stylize}, @@ -14,29 +19,55 @@ use ratatui::{ use tui_input::backend::crossterm::EventHandler; use crate::{ - app::AppResult, + app::{AppResult, Channels}, export, filter::fuzzy::{self, Fuzzy}, notification::{Notification, NotificationLevel}, packet::{ network::{IpPacket, IpProto}, - AppPacket, + AppPacket, NetworkPacket, }, + pid::{self, IpMap}, }; #[derive(Debug)] pub struct Inspection { - pub packets: Arc>>, + pub packets: Arc>>, + pub state: TableState, pub fuzzy: Arc>, pub manuall_scroll: bool, pub packet_end_index: usize, pub packet_window_size: usize, pub packet_index: Option, + tcp_map: Arc>, + udp_map: Arc>, } impl Inspection { - pub fn new(packets: Arc>>) -> Self { + pub fn new(packets: Arc>>) -> Self { + let tcp_map = Arc::new(Mutex::new(IpMap::new())); + let udp_map = Arc::new(Mutex::new(IpMap::new())); + let conn_channels = Channels::new(); + let conn_info = pid::ConnectionsInfo::new(conn_channels.sender.clone()); + conn_info.spawn(); + + thread::spawn({ + let tcp_map = tcp_map.clone(); + let udp_map = udp_map.clone(); + let connection_info_receiver = conn_channels.receiver.clone(); + move || loop { + if let Ok((rcv_tcp_map, rcv_udp_map)) = connection_info_receiver.recv() { + let mut _tcp_map = tcp_map.lock().unwrap(); + *_tcp_map = rcv_tcp_map; + drop(_tcp_map); + let mut _udp_map = udp_map.lock().unwrap(); + *_udp_map = rcv_udp_map; + drop(_udp_map); + } + } + }); + Self { packets: packets.clone(), state: TableState::default(), @@ -45,6 +76,8 @@ impl Inspection { packet_end_index: 0, packet_window_size: 0, packet_index: None, + tcp_map, + udp_map, } } @@ -134,15 +167,15 @@ impl Inspection { } KeyCode::Char('s') => { - let app_packets = self.packets.lock().unwrap(); - if app_packets.is_empty() { + let net_packets = self.packets.lock().unwrap(); + if net_packets.is_empty() { Notification::send( "There is no packets".to_string(), NotificationLevel::Info, event_sender, )?; } else { - match export::export(&app_packets) { + match export::export(&net_packets) { Ok(_) => { Notification::send( "Packets exported to ~/oryx/capture file".to_string(), @@ -179,7 +212,7 @@ impl Inspection { if i > 1 { i - 1 } else if i == 0 && self.packet_end_index > self.packet_window_size { - // shit the window by one + // shift the window by one self.packet_end_index -= 1; 0 } else { @@ -221,7 +254,10 @@ impl Inspection { pub fn render(&mut self, frame: &mut Frame, block: Rect) { let app_packets = self.packets.lock().unwrap(); + let tcp_map = self.tcp_map.lock().unwrap().clone(); + let udp_map = self.udp_map.lock().unwrap().clone(); let mut fuzzy = self.fuzzy.lock().unwrap(); + let fuzzy_packets = fuzzy.clone().packets.clone(); let pattern = fuzzy.clone(); @@ -254,10 +290,11 @@ impl Inspection { }; let widths = [ - Constraint::Min(19), // Source Address - Constraint::Length(11), // Source Port - Constraint::Min(19), // Destination Address - Constraint::Length(16), // Destination Port + Constraint::Min(15), // Source Address + Constraint::Length(12), // Source Port + Constraint::Min(20), // Destination Address + Constraint::Length(17), // Destination Port + Constraint::Length(5), // Pid Constraint::Length(8), // Protocol Constraint::Length(3), // manual scroll sign ]; @@ -327,26 +364,40 @@ impl Inspection { } } }; + // + let packets_to_display = packets_to_display + .iter() + .map(|p| AppPacket::from_network_packet(p, &tcp_map, &udp_map)) + .collect::>(); // Style the packets let packets: Vec = if fuzzy.is_enabled() & !fuzzy.filter.value().is_empty() { packets_to_display .iter() - .map(|app_packet| match app_packet { - AppPacket::Arp(packet) => Row::new(vec![ + .map(|app_packet| match app_packet.packet { + NetworkPacket::Arp(packet) => Row::new(vec![ fuzzy::highlight(pattern, packet.src_mac.to_string()).blue(), Cell::from(Line::from("-").centered()).yellow(), fuzzy::highlight(pattern, packet.dst_mac.to_string()).blue(), Cell::from(Line::from("-").centered()).yellow(), + Cell::from(Line::from("-").centered()).yellow(), fuzzy::highlight(pattern, "ARP".to_string()).cyan(), ]), - AppPacket::Ip(packet) => match packet { + NetworkPacket::Ip(packet) => match packet { IpPacket::V4(ipv4_packet) => match ipv4_packet.proto { IpProto::Tcp(p) => Row::new(vec![ fuzzy::highlight(pattern, ipv4_packet.src_ip.to_string()).blue(), fuzzy::highlight(pattern, p.src_port.to_string()).yellow(), fuzzy::highlight(pattern, ipv4_packet.dst_ip.to_string()).blue(), fuzzy::highlight(pattern, p.dst_port.to_string()).yellow(), + Cell::from( + Line::from(match app_packet.pid { + Some(pid) => pid.to_string(), + None => "-".to_string(), + }) + .centered(), + ) + .yellow(), fuzzy::highlight(pattern, "TCP".to_string()).cyan(), ]), IpProto::Udp(p) => Row::new(vec![ @@ -354,6 +405,14 @@ impl Inspection { fuzzy::highlight(pattern, p.src_port.to_string()).yellow(), fuzzy::highlight(pattern, ipv4_packet.dst_ip.to_string()).blue(), fuzzy::highlight(pattern, p.dst_port.to_string()).yellow(), + Cell::from( + Line::from(match app_packet.pid { + Some(pid) => pid.to_string(), + None => "-".to_string(), + }) + .centered(), + ) + .yellow(), fuzzy::highlight(pattern, "UDP".to_string()).cyan(), ]), IpProto::Icmp(_) => Row::new(vec![ @@ -361,6 +420,7 @@ impl Inspection { Cell::from(Line::from("-").centered()).yellow(), fuzzy::highlight(pattern, ipv4_packet.dst_ip.to_string()).blue(), Cell::from(Line::from("-").centered()).yellow(), + Cell::from(Line::from("-").centered()).yellow(), fuzzy::highlight(pattern, "ICMP".to_string()).cyan(), ]), }, @@ -370,6 +430,7 @@ impl Inspection { fuzzy::highlight(pattern, p.src_port.to_string()).yellow(), fuzzy::highlight(pattern, ipv6_packet.dst_ip.to_string()).blue(), fuzzy::highlight(pattern, p.dst_port.to_string()).yellow(), + Cell::from(Line::from("-").centered()).yellow(), fuzzy::highlight(pattern, "TCP".to_string()).cyan(), ]), IpProto::Udp(p) => Row::new(vec![ @@ -377,6 +438,7 @@ impl Inspection { fuzzy::highlight(pattern, p.src_port.to_string()).yellow(), fuzzy::highlight(pattern, ipv6_packet.dst_ip.to_string()).blue(), fuzzy::highlight(pattern, p.dst_port.to_string()).yellow(), + Cell::from(Line::from("-").centered()).yellow(), fuzzy::highlight(pattern, "UDP".to_string()).cyan(), ]), IpProto::Icmp(_) => Row::new(vec![ @@ -384,6 +446,7 @@ impl Inspection { Cell::from(Line::from("-").centered()).yellow(), fuzzy::highlight(pattern, ipv6_packet.dst_ip.to_string()).blue(), Cell::from(Line::from("-").centered()).yellow(), + Cell::from(Line::from("-").centered()).yellow(), fuzzy::highlight(pattern, "ICMP".to_string()).cyan(), ]), }, @@ -393,8 +456,8 @@ impl Inspection { } else { packets_to_display .iter() - .map(|app_packet| match app_packet { - AppPacket::Arp(packet) => Row::new(vec![ + .map(|app_packet| match app_packet.packet { + NetworkPacket::Arp(packet) => Row::new(vec![ Span::from(packet.src_mac.to_string()) .into_centered_line() .blue(), @@ -403,9 +466,10 @@ impl Inspection { .into_centered_line() .blue(), Span::from("-").into_centered_line().yellow(), + Span::from("-").into_centered_line().yellow(), Span::from("ARP".to_string()).into_centered_line().cyan(), ]), - AppPacket::Ip(packet) => match packet { + NetworkPacket::Ip(packet) => match packet { IpPacket::V4(ipv4_packet) => match ipv4_packet.proto { IpProto::Tcp(p) => Row::new(vec![ Span::from(ipv4_packet.src_ip.to_string()) @@ -420,6 +484,12 @@ impl Inspection { Span::from(p.dst_port.to_string()) .into_centered_line() .yellow(), + Span::from(match app_packet.pid { + Some(pid) => pid.to_string(), + None => "-".to_string(), + }) + .into_centered_line() + .yellow(), Span::from("TCP".to_string()).into_centered_line().cyan(), ]), IpProto::Udp(p) => Row::new(vec![ @@ -435,6 +505,12 @@ impl Inspection { Span::from(p.dst_port.to_string()) .into_centered_line() .yellow(), + Span::from(match app_packet.pid { + Some(pid) => pid.to_string(), + None => "-".to_string(), + }) + .into_centered_line() + .yellow(), Span::from("UDP".to_string()).into_centered_line().cyan(), ]), IpProto::Icmp(_) => Row::new(vec![ @@ -446,6 +522,7 @@ impl Inspection { .into_centered_line() .blue(), Span::from("-").into_centered_line().yellow(), + Span::from("-").into_centered_line().yellow(), Span::from("ICMP".to_string()).into_centered_line().cyan(), ]), }, @@ -463,6 +540,7 @@ impl Inspection { Span::from(p.dst_port.to_string()) .into_centered_line() .yellow(), + Span::from("-").into_centered_line().yellow(), Span::from("TCP".to_string()).into_centered_line().cyan(), ]), IpProto::Udp(p) => Row::new(vec![ @@ -478,6 +556,7 @@ impl Inspection { Span::from(p.dst_port.to_string()) .into_centered_line() .yellow(), + Span::from("-").into_centered_line().yellow(), Span::from("UDP".to_string()).into_centered_line().cyan(), ]), IpProto::Icmp(_) => Row::new(vec![ @@ -489,6 +568,7 @@ impl Inspection { .into_centered_line() .blue(), Span::from("-").into_centered_line().yellow(), + Span::from("-").into_centered_line().yellow(), Span::from("ICMP".to_string()).into_centered_line().cyan(), ]), }, @@ -513,6 +593,7 @@ impl Inspection { Line::from("Source Port").centered(), Line::from("Destination Address").centered(), Line::from("Destination Port").centered(), + Line::from("Pid").centered(), Line::from("Protocol").centered(), { if self.manuall_scroll { @@ -640,7 +721,7 @@ impl Inspection { let fuzzy = self.fuzzy.lock().unwrap(); let packets = self.packets.lock().unwrap(); - let packet = if fuzzy.is_enabled() { + let net_packet = if fuzzy.is_enabled() { fuzzy.packets[self.packet_index.unwrap()] } else { packets[self.packet_index.unwrap()] @@ -657,9 +738,9 @@ impl Inspection { .border_type(BorderType::Thick), block, ); - match packet { - AppPacket::Ip(ip_packet) => ip_packet.render(block, frame), - AppPacket::Arp(arp_packet) => arp_packet.render(block, frame), + match net_packet { + NetworkPacket::Ip(ip_packet) => ip_packet.render(block, frame), + NetworkPacket::Arp(arp_packet) => arp_packet.render(block, frame), }; } } diff --git a/oryx-tui/src/section/stats.rs b/oryx-tui/src/section/stats.rs index 0f813d2..cdbf6c7 100644 --- a/oryx-tui/src/section/stats.rs +++ b/oryx-tui/src/section/stats.rs @@ -20,7 +20,7 @@ use crate::{ interface::NetworkInterface, packet::{ network::{IpPacket, IpProto}, - AppPacket, + NetworkPacket, }, }; @@ -41,7 +41,10 @@ pub struct Stats { } impl Stats { - pub fn new(packets: Arc>>, selected_interface: NetworkInterface) -> Self { + pub fn new( + packets: Arc>>, + selected_interface: NetworkInterface, + ) -> Self { let packet_stats: Arc> = Arc::new(Mutex::new(PacketStats::default())); thread::spawn({ @@ -59,10 +62,10 @@ impl Stats { let mut packet_stats = packet_stats.lock().unwrap(); for packet in packets[last_index..].iter() { match packet { - AppPacket::Arp(_) => { + NetworkPacket::Arp(_) => { packet_stats.link.arp += 1; } - AppPacket::Ip(packet) => match packet { + NetworkPacket::Ip(packet) => match packet { IpPacket::V4(ipv4_packet) => { packet_stats.network.ipv4 += 1;