Skip to content

Commit 30a332d

Browse files
committed
tui: display ARP packets
1 parent 2289c92 commit 30a332d

File tree

11 files changed

+443
-189
lines changed

11 files changed

+443
-189
lines changed

Cargo.lock

Lines changed: 18 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

oryx-tui/src/app.rs

Lines changed: 172 additions & 114 deletions
Large diffs are not rendered by default.

oryx-tui/src/ebpf.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use aya::maps::{MapData, RingBuf};
1010
use aya::programs::{tc, SchedClassifier, TcAttachType};
1111
use aya::{include_bytes_aligned, Bpf};
1212
use mio::{Events, Interest, Poll, Registry, Token};
13-
use oryx_common::IpPacket;
13+
use oryx_common::RawPacket;
1414

1515
use crate::event::Event;
1616
use crate::notification::{Notification, NotificationLevel};
@@ -166,8 +166,9 @@ impl Ebpf {
166166
if terminate.load(std::sync::atomic::Ordering::Relaxed) {
167167
break;
168168
}
169-
let packet: [u8; 40] = item.to_owned().try_into().unwrap();
170-
sender.send(Event::Packet(IpPacket::from(packet))).ok();
169+
let packet: [u8; RawPacket::LEN] =
170+
item.to_owned().try_into().unwrap();
171+
sender.send(Event::Packet(packet)).ok();
171172
}
172173
}
173174
}
@@ -283,8 +284,9 @@ impl Ebpf {
283284
if terminate.load(std::sync::atomic::Ordering::Relaxed) {
284285
break;
285286
}
286-
let packet: [u8; 40] = item.to_owned().try_into().unwrap();
287-
sender.send(Event::Packet(IpPacket::from(packet))).ok();
287+
let packet: [u8; RawPacket::LEN] =
288+
item.to_owned().try_into().unwrap();
289+
sender.send(Event::Packet(packet)).ok();
288290
}
289291
}
290292
}

oryx-tui/src/event.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
use crate::app::AppResult;
22
use crate::notification::Notification;
3-
use oryx_common::IpPacket;
43
use ratatui::crossterm::event::{
54
self, Event as CrosstermEvent, KeyEvent, KeyEventKind, MouseEvent,
65
};
76
use std::thread;
87
use std::time::{Duration, Instant};
98

10-
#[derive(Clone, Debug)]
9+
#[derive(Clone)]
1110
pub enum Event {
1211
Tick,
1312
Key(KeyEvent),
1413
Mouse(MouseEvent),
1514
Resize(u16, u16),
16-
Packet(IpPacket),
15+
Packet([u8; 48]),
1716
Notification(Notification),
1817
Reset,
1918
}

oryx-tui/src/export.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::fs::{create_dir, OpenOptions};
22
use std::io::prelude::*;
33
use std::os::unix::fs::chown;
44

5-
use oryx_common::IpPacket;
5+
use oryx_common::ip::IpPacket;
66

77
use crate::app::AppResult;
88

oryx-tui/src/filters/fuzzy.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,25 @@ use ratatui::{
55
};
66
use tui_input::Input;
77

8-
use oryx_common::IpPacket;
8+
use oryx_common::AppPacket;
99

1010
#[derive(Debug, Default)]
1111
pub struct Fuzzy {
1212
enabled: bool,
1313
paused: bool,
1414
pub filter: Input,
15-
pub packets: Vec<IpPacket>,
15+
pub packets: Vec<AppPacket>,
1616
pub scroll_state: TableState,
1717
pub packet_end_index: usize,
1818
}
1919

2020
impl Fuzzy {
21-
pub fn find(&mut self, packets: &[IpPacket]) {
21+
pub fn find(&mut self, packets: &[AppPacket]) {
2222
self.packets = packets
2323
.iter()
2424
.copied()
2525
.filter(|p| p.to_string().contains(self.filter.value()))
26-
.collect::<Vec<IpPacket>>();
26+
.collect::<Vec<AppPacket>>();
2727
}
2828

2929
pub fn enable(&mut self) {

oryx-tui/src/filters/link.rs

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
use std::fmt::Display;
2+
3+
use ratatui::{
4+
layout::{Alignment, Constraint, Direction, Flex, Layout, Rect},
5+
style::{Color, Style, Stylize},
6+
widgets::{Block, BorderType, Borders, Row, Table, TableState},
7+
Frame,
8+
};
9+
10+
use crate::app::FocusedBlock;
11+
12+
pub const NB_LINK_PROTOCOL: u16 = 1;
13+
14+
#[derive(Debug)]
15+
pub struct LinkFilter {
16+
pub state: TableState,
17+
pub selected_protocols: Vec<LinkProtocol>,
18+
pub applied_protocols: Vec<LinkProtocol>,
19+
}
20+
21+
#[derive(Debug, Copy, Clone, PartialEq)]
22+
pub enum LinkProtocol {
23+
Arp,
24+
}
25+
26+
impl Display for LinkProtocol {
27+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
28+
write!(f, "Arp")
29+
}
30+
}
31+
32+
impl Default for LinkFilter {
33+
fn default() -> Self {
34+
Self {
35+
state: TableState::default(),
36+
selected_protocols: vec![LinkProtocol::Arp],
37+
applied_protocols: Vec::new(),
38+
}
39+
}
40+
}
41+
42+
impl LinkFilter {
43+
pub fn apply(&mut self) {
44+
self.applied_protocols = self.selected_protocols.clone();
45+
self.selected_protocols.clear();
46+
}
47+
48+
pub fn render(&mut self, frame: &mut Frame, block: Rect, focused_block: &FocusedBlock) {
49+
let layout = Layout::default()
50+
.direction(Direction::Horizontal)
51+
.constraints(
52+
[
53+
Constraint::Fill(1),
54+
Constraint::Length(55),
55+
Constraint::Fill(1),
56+
]
57+
.as_ref(),
58+
)
59+
.flex(Flex::Center)
60+
.split(block);
61+
62+
let area = layout[1];
63+
64+
let widths = [Constraint::Length(2), Constraint::Fill(1)];
65+
let link_filters = vec![Row::new(vec![
66+
{
67+
if self.selected_protocols.contains(&LinkProtocol::Arp) {
68+
" "
69+
} else {
70+
""
71+
}
72+
},
73+
"ARP",
74+
])];
75+
76+
let table = Table::new(link_filters, widths)
77+
.highlight_style(Style::new().bg(ratatui::style::Color::DarkGray));
78+
79+
frame.render_widget(
80+
Block::new()
81+
.title(" Link Filters 󱪤 ")
82+
.title_style(Style::default().bold().fg(Color::Green))
83+
.title_alignment(Alignment::Center)
84+
.borders(Borders::LEFT)
85+
.border_type(if *focused_block == FocusedBlock::LinkFilter {
86+
BorderType::Thick
87+
} else {
88+
BorderType::default()
89+
})
90+
.border_style(Style::default().fg(Color::Green)),
91+
area,
92+
);
93+
94+
frame.render_stateful_widget(
95+
table,
96+
area.inner(ratatui::layout::Margin {
97+
horizontal: 6,
98+
vertical: 2,
99+
}),
100+
&mut self.state,
101+
);
102+
}
103+
}

0 commit comments

Comments
 (0)