Skip to content

Commit d29d32f

Browse files
committed
fix
1 parent dbad7a3 commit d29d32f

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

oryx-ebpf/src/main.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -315,20 +315,22 @@ fn process(ctx: TcContext) -> Result<i32, ()> {
315315
u16::from_be_bytes((*ipv4_header).tot_len) - (*ipv4_header).ihl() as u16
316316
};
317317

318-
let igmp_type: *const u8 = ptr_at(&ctx, EthHdr::LEN + Ipv4Hdr::LEN)?;
319-
let igmp_type = unsafe { u8::from_be(*igmp_type) };
318+
let ihl: u8 = ctx.load(EthHdr::LEN).map_err(|_| ())?;
319+
let ihl = (ihl & 0x0F) * 4;
320+
321+
let igmp_type: u8 = ctx.load(EthHdr::LEN + ihl as usize).map_err(|_| ())?;
320322

321323
match igmp_type {
322324
0x11 => {
323325
if payload_length == 8 {
324326
// v1 or v2
325-
let max_response_time: *const u8 =
326-
ptr_at(&ctx, EthHdr::LEN + Ipv4Hdr::LEN + 1)?;
327+
let max_response_time: u8 =
328+
ctx.load(EthHdr::LEN + ihl as usize + 1).map_err(|_| ())?;
327329

328-
if unsafe { *max_response_time } == 0 {
330+
if max_response_time == 0 {
329331
//v1
330332
let igmp_header: *const IGMPv1Hdr =
331-
ptr_at(&ctx, EthHdr::LEN + Ipv4Hdr::LEN)?;
333+
ptr_at(&ctx, EthHdr::LEN + ihl as usize)?;
332334

333335
unsafe {
334336
submit(RawData {
@@ -345,7 +347,7 @@ fn process(ctx: TcContext) -> Result<i32, ()> {
345347
} else {
346348
// v2
347349
let igmp_header: *const IGMPv2Hdr =
348-
ptr_at(&ctx, EthHdr::LEN + Ipv4Hdr::LEN)?;
350+
ptr_at(&ctx, EthHdr::LEN + ihl as usize)?;
349351

350352
unsafe {
351353
submit(RawData {
@@ -363,7 +365,7 @@ fn process(ctx: TcContext) -> Result<i32, ()> {
363365
} else {
364366
// v3
365367
let igmp_header: *const IGMPv3MembershipQueryHdr =
366-
ptr_at(&ctx, EthHdr::LEN + Ipv4Hdr::LEN)?;
368+
ptr_at(&ctx, EthHdr::LEN + ihl as usize)?;
367369

368370
unsafe {
369371
submit(RawData {
@@ -383,7 +385,7 @@ fn process(ctx: TcContext) -> Result<i32, ()> {
383385
}
384386
0x12 => {
385387
let igmp_header: *const IGMPv1Hdr =
386-
ptr_at(&ctx, EthHdr::LEN + Ipv4Hdr::LEN)?;
388+
ptr_at(&ctx, EthHdr::LEN + ihl as usize)?;
387389

388390
unsafe {
389391
submit(RawData {
@@ -400,7 +402,7 @@ fn process(ctx: TcContext) -> Result<i32, ()> {
400402
}
401403
0x16 | 0x17 => {
402404
let igmp_header: *const IGMPv2Hdr =
403-
ptr_at(&ctx, EthHdr::LEN + Ipv4Hdr::LEN)?;
405+
ptr_at(&ctx, EthHdr::LEN + ihl as usize)?;
404406

405407
unsafe {
406408
submit(RawData {
@@ -417,7 +419,7 @@ fn process(ctx: TcContext) -> Result<i32, ()> {
417419
}
418420
0x22 => {
419421
let igmp_header: *const IGMPv3MembershipReportHdr =
420-
ptr_at(&ctx, EthHdr::LEN + Ipv4Hdr::LEN)?;
422+
ptr_at(&ctx, EthHdr::LEN + ihl as usize)?;
421423

422424
unsafe {
423425
submit(RawData {

0 commit comments

Comments
 (0)