Skip to content

BPF: Improve headers#619

Merged
rsmarples merged 1 commit into
masterfrom
bpf_hdr
Jun 1, 2026
Merged

BPF: Improve headers#619
rsmarples merged 1 commit into
masterfrom
bpf_hdr

Conversation

@rsmarples
Copy link
Copy Markdown
Member

No description provided.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 1, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ddd7b564-a29b-4aae-8249-eccfffa1edf6

📥 Commits

Reviewing files that changed from the base of the PR and between 2d29048 and 70c76b7.

📒 Files selected for processing (1)
  • src/bpf.c
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/bpf.c

Walkthrough

The PR reorganizes BPF-related includes in src/bpf.c to conditionally select packet-filter headers and updates ARP BPF programs: the hardware-length check now uses sizeof(struct arphdr), and bpf_arp_rw’s arp_len is recomputed with explicit struct-field arithmetic.

Changes

ARP BPF packet filter updates

Layer / File(s) Summary
Header reorganization and BPF header setup
src/bpf.c
Include section restructured to add config.h and conditionally select BPF packet filtering headers based on USE_LIBPCAP, __linux__, or a fallback header.
ARP BPF instruction operand and formula updates
src/bpf.c
ARP BPF instruction arrays updated: bpf_arp_ether hardware-length check operand changed to sizeof(struct arphdr), and bpf_arp_rw ARP length computation refactored to use explicit struct-based arithmetic instead of sizeof(struct ether_arp).

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related PRs

  • NetworkConfiguration/dhcpcd#607: Both PRs modify the ARP BPF bytecode generation in src/bpf.c—especially bpf_arp_ether's hardware-length check and the bpf_arp_rw ARP program length computation—so the changes overlap directly in the same functions.
🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (1 warning, 2 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'BPF: Improve headers' is vague and does not provide specific information about the changes made to the BPF code. Consider revising the title to be more specific, such as 'BPF: Make header selection conditional and fix ARP length calculation' to better convey the actual changes.
Description check ❓ Inconclusive No pull request description was provided by the author, making it impossible to evaluate whether it relates to the changeset. Add a pull request description that explains the purpose of the changes, including the header selection improvements and ARP structure modifications.
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bpf_hdr

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/bpf.c`:
- Around line 272-273: The BPF check loads ar_hln and currently compares it
against sizeof(struct arphdr) which is wrong; change the BPF_JUMP that compares
offsetof(struct arphdr, ar_hln) to compare against the Ethernet hardware address
length (ETH_ALEN) instead of sizeof(struct arphdr). Locate the BPF_STMT(BPF_LD +
BPF_B + BPF_IND, offsetof(struct arphdr, ar_hln)) and its following
BPF_JUMP(...) and replace the comparison constant with ETH_ALEN (or an
equivalent sizeof(((struct ether_header*)0)->ether_shost)); ensure the build
includes the header that defines ETH_ALEN (e.g., <net/ethernet.h>) if not
already included.
- Around line 33-53: Replace the nonportable include <net/if_ether.h> with the
portable user-space header <netinet/if_ether.h> (or add a platform-specific
fallback) so src/bpf.c uses the same ethernet definitions as the rest of the
repo; and fix the ARP hardware-length BPF check that currently compares struct
arphdr::ar_hln against sizeof(struct arphdr) by comparing ar_hln to the Ethernet
hardware address length instead (e.g., ETH_ALEN or sizeof(((struct ether_header
*)0)->ether_shost)) in the ARP filter construction and any checks in bpf_arp_rw
so the filter validates that ar_hln == Ethernet address length rather than the
size of struct arphdr.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7326c66a-d599-44a0-92cf-6afb316a1036

📥 Commits

Reviewing files that changed from the base of the PR and between f70106a and 2d29048.

📒 Files selected for processing (1)
  • src/bpf.c

Comment thread src/bpf.c Outdated
Comment thread src/bpf.c Outdated
@rsmarples rsmarples merged commit db3abc1 into master Jun 1, 2026
6 checks passed
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.

1 participant