Skip to content

Commit 1ec144f

Browse files
committed
update
1 parent ce845a8 commit 1ec144f

4 files changed

Lines changed: 78 additions & 66 deletions

File tree

oryx-ebpf/src/main.rs

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -318,36 +318,42 @@ fn process(ctx: TcContext) -> Result<i32, ()> {
318318
let igmp_type: *const u8 = ptr_at(&ctx, EthHdr::LEN + Ipv4Hdr::LEN)?;
319319
let igmp_type = unsafe { *igmp_type };
320320

321-
if igmp_type == 0x11 {
322-
if payload_length == 8 {
323-
// v1 or v2
324-
let max_response_time: *const u8 =
325-
ptr_at(&ctx, EthHdr::LEN + Ipv4Hdr::LEN + 1)?;
326-
327-
if unsafe { *max_response_time } == 0 {
328-
//v1
329-
let igmp_header: *const IGMPv1Hdr =
330-
ptr_at(&ctx, EthHdr::LEN + Ipv4Hdr::LEN)?;
331-
332-
unsafe {
333-
submit(RawData {
334-
frame: RawFrame {
335-
header: *eth_header,
336-
payload: RawPacket::Ip(
337-
IpHdr::V4(*ipv4_header),
338-
ProtoHdr::Igmp(IgmpHdr::V1(*igmp_header)),
339-
),
340-
},
341-
pid,
342-
});
321+
match igmp_type {
322+
0x11 => {
323+
if payload_length == 8 {
324+
// v1 or v2
325+
let max_response_time: *const u8 =
326+
ptr_at(&ctx, EthHdr::LEN + Ipv4Hdr::LEN + 1)?;
327+
328+
if unsafe { *max_response_time } == 0 {
329+
//v1
330+
let igmp_header: *const IGMPv1Hdr =
331+
ptr_at(&ctx, EthHdr::LEN + Ipv4Hdr::LEN)?;
332+
333+
unsafe {
334+
submit(RawData {
335+
frame: RawFrame {
336+
header: *eth_header,
337+
payload: RawPacket::Ip(
338+
IpHdr::V4(*ipv4_header),
339+
ProtoHdr::Igmp(IgmpHdr::V1(*igmp_header)),
340+
),
341+
},
342+
pid,
343+
});
344+
}
345+
} else {
346+
// v2
343347
}
344348
} else {
345-
// v2
349+
// v3
346350
}
347-
} else {
348-
// v3
349351
}
350-
} else {
352+
0x12 => {}
353+
0x16 => {}
354+
0x22 => {}
355+
0x17 => {}
356+
_ => {}
351357
}
352358
}
353359
_ => {}

oryx-tui/src/packet.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ use direction::TrafficDirection;
1111
use link::{ArpPacket, ArpType, MacAddr};
1212
use network::{IpPacket, icmp::IcmpPacket, icmp::icmpv4, icmp::icmpv6, ip::IpProto};
1313
use network_types::{eth::EthHdr, icmp::Icmp, ip::IpHdr};
14-
use oryx_common::{ProtoHdr, RawFrame, RawPacket};
14+
use oryx_common::{IgmpHdr, ProtoHdr, RawFrame, RawPacket};
1515
use transport::{SctpPacket, TcpPacket, UdpPacket};
1616

1717
use crate::packet::network::{
18-
icmp::icmpv4::Icmpv4Packet, icmp::icmpv6::Icmpv6Packet, ip::ipv4::Ipv4Packet,
19-
ip::ipv6::Ipv6Packet,
18+
icmp::{icmpv4::Icmpv4Packet, icmpv6::Icmpv6Packet},
19+
igmp::{IgmpPacket, IgmpType, igmpv1::IGMPv1Packet},
20+
ip::{ipv4::Ipv4Packet, ipv6::Ipv6Packet},
2021
};
2122

2223
#[derive(Debug, Copy, Clone)]
@@ -98,6 +99,17 @@ impl From<RawFrame> for EthFrame {
9899
checksum: u16::from_be_bytes(icmp_header.check),
99100
}))
100101
}
102+
ProtoHdr::Igmp(igmp_header) => match igmp_header {
103+
IgmpHdr::V1(igmpv1_hdr) => {
104+
let igmp_type =
105+
IgmpType::try_from(igmpv1_hdr.type_() | 1 << 1).unwrap();
106+
IpProto::Igmp(IgmpPacket::V1(IGMPv1Packet {
107+
igmp_type,
108+
checksum: igmpv1_hdr.checksum(),
109+
group_address: Ipv4Addr::from_bits(igmpv1_hdr.group_address()),
110+
}))
111+
}
112+
},
101113
_ => unreachable!(),
102114
};
103115

oryx-tui/src/packet/network/igmp.rs

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ pub mod igmpv1;
22
pub mod igmpv2;
33
pub mod igmpv3;
44

5+
use std::fmt::Display;
6+
57
use crate::packet::network::igmp::igmpv1::IGMPv1Packet;
68

79
#[derive(Debug, Copy, Clone)]
@@ -11,7 +13,7 @@ pub enum IgmpPacket {
1113
// V3(IGMPv3),
1214
}
1315

14-
#[derive(Debug, Copy, Clone)]
16+
#[derive(Debug, Copy, Clone, PartialEq)]
1517
pub enum IgmpType {
1618
MembershipQuery = 0x11,
1719
IGMPv1MembershipReport = 0x12,
@@ -20,19 +22,6 @@ pub enum IgmpType {
2022
LeaveGroup = 0x17,
2123
}
2224

23-
// impl From<u8> for IgmpType {
24-
// fn from(value: u8) -> Self {
25-
// match value {
26-
// 0x11 => IgmpType::MembershipQuery,
27-
// 0x12 => IgmpType::IGMPv1MembershipReport,
28-
// 0x16 => IgmpType::IGMPv2MembershipReport,
29-
// 0x22 => IgmpType::IGMPv3MembershipReport,
30-
// 0x17 => IgmpType::LeaveGroup,
31-
// _ => unreachable!(),
32-
// }
33-
// }
34-
// }
35-
3625
impl TryFrom<u8> for IgmpType {
3726
type Error = &'static str;
3827
fn try_from(value: u8) -> Result<Self, Self::Error> {
@@ -46,3 +35,25 @@ impl TryFrom<u8> for IgmpType {
4635
}
4736
}
4837
}
38+
39+
impl Display for IgmpType {
40+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
41+
match self {
42+
IgmpType::MembershipQuery => {
43+
write!(f, "Membership Query")
44+
}
45+
IgmpType::IGMPv1MembershipReport => {
46+
write!(f, "IGMPv1 Membership Report")
47+
}
48+
IgmpType::IGMPv2MembershipReport => {
49+
write!(f, "IGMPv2 Membership Report")
50+
}
51+
IgmpType::IGMPv3MembershipReport => {
52+
write!(f, "IGMPv3 Membership Report")
53+
}
54+
IgmpType::LeaveGroup => {
55+
write!(f, "Leave Group")
56+
}
57+
}
58+
}
59+
}

oryx-tui/src/packet/network/igmp/igmpv1.rs

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
1-
use core::fmt::Display;
21
use ratatui::{
32
Frame,
43
layout::{Constraint, Direction, Layout, Rect},
54
style::{Style, Stylize},
65
text::Span,
76
widgets::{Block, Borders, Padding, Paragraph, Row, Table},
87
};
8+
use std::net::Ipv4Addr;
99

10-
#[derive(Debug, Copy, Clone, PartialEq)]
11-
pub enum Igmpv1Type {
12-
HostMembershipQuery = 0x1,
13-
HostMembershipReport = 0x2,
14-
}
10+
use crate::packet::network::igmp::IgmpType;
1511

1612
#[derive(Debug, Copy, Clone)]
1713
pub struct IGMPv1Packet {
18-
pub igmp_type: Igmpv1Type,
19-
pub checksum: u8,
20-
pub group_address: u32,
14+
pub igmp_type: IgmpType,
15+
pub checksum: u16,
16+
pub group_address: Ipv4Addr,
2117
}
2218

2319
impl IGMPv1Packet {
@@ -54,7 +50,7 @@ impl IGMPv1Packet {
5450
Row::new(vec![
5551
Span::styled("Group Address", Style::new().bold()),
5652
Span::from({
57-
if self.igmp_type == Igmpv1Type::HostMembershipReport {
53+
if self.igmp_type == IgmpType::IGMPv1MembershipReport {
5854
self.group_address.to_string()
5955
} else {
6056
"-".to_string()
@@ -75,16 +71,3 @@ impl IGMPv1Packet {
7571
frame.render_widget(title, title_block);
7672
}
7773
}
78-
79-
impl Display for Igmpv1Type {
80-
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
81-
match self {
82-
Igmpv1Type::HostMembershipQuery => {
83-
write!(f, "Host Membership Query")
84-
}
85-
Igmpv1Type::HostMembershipReport => {
86-
write!(f, "Host Membership Report")
87-
}
88-
}
89-
}
90-
}

0 commit comments

Comments
 (0)