Skip to content

fix(bpf): Correctly parse IP headers with options#337

Merged
mozillazg merged 2 commits intomasterfrom
fix-tcp-parse
Sep 7, 2025
Merged

fix(bpf): Correctly parse IP headers with options#337
mozillazg merged 2 commits intomasterfrom
fix-tcp-parse

Conversation

@mozillazg
Copy link
Owner

@mozillazg mozillazg commented Sep 7, 2025

This commit introduces several improvements to the eBPF probe to enhance robustness and feature completeness.

  • feat: Add fallback for PID attribution
    Uses bpf_get_current_task() as a fallback mechanism to resolve the process ID for a packet. This significantly improves PID attribution for scenarios where the primary flow-based mapping might fail, such as with short-lived connections. Includes a check for kernel support to ensure backward compatibility.

  • fix: Correctly parse IP headers with options
    The IP header length is now dynamically calculated based on the IHL (Internet Header Length) field. This fixes a bug where packets with IP options would be parsed incorrectly, leading to errors in L4 (TCP/UDP) header analysis.

  • chore: Clean up debug logs
    Commented out several debug_log statements to reduce noise and performance overhead.

This commit introduces several improvements to the eBPF probe to enhance robustness and feature completeness.

- feat: Add fallback for PID attribution
  Uses `bpf_get_current_task()` as a fallback mechanism to resolve the process ID for a packet. This significantly improves PID attribution for scenarios where the primary flow-based mapping might fail, such as with short-lived connections. Includes a check for kernel support to ensure backward compatibility.

- fix: Correctly parse IP headers with options
  The IP header length is now dynamically calculated based on the IHL (Internet Header Length) field. This fixes a bug where packets with IP options would be parsed incorrectly, leading to errors in L4 (TCP/UDP) header analysis.

- chore: Clean up debug logs
  Commented out several `debug_log` statements to reduce noise and performance overhead.
@mozillazg mozillazg changed the title feat(bpf): Improve PID attribution and IP parsing fix(bpf): Correctly parse IP headers with options Sep 7, 2025
Removes the PID fallback mechanism that uses bpf_get_current_task().
This is unsafe without a reliable way to detect interrupt context (e.g., bpf_in_interrupt()),
as it can lead to incorrect PID association.
The explanatory comment is updated to reflect this.
@coveralls
Copy link

Coverage Status

coverage: 73.632% (+0.2%) from 73.438%
when pulling c5151f3 on fix-tcp-parse
into 2b157b7 on master.

@mozillazg mozillazg merged commit a7eefa8 into master Sep 7, 2025
63 of 64 checks passed
@mozillazg mozillazg deleted the fix-tcp-parse branch September 7, 2025 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants