Skip to content

[1/2] Add flavor-specific log codegen callback#486

Open
yaakov-stein wants to merge 4 commits intofacebook:mainfrom
yaakov-stein:extract-log-codegen-callback
Open

[1/2] Add flavor-specific log codegen callback#486
yaakov-stein wants to merge 4 commits intofacebook:mainfrom
yaakov-stein:extract-log-codegen-callback

Conversation

@yaakov-stein
Copy link
Copy Markdown
Contributor

@yaakov-stein yaakov-stein commented Mar 20, 2026

Gave stack-pr a try, but it doesn't allow for multi-commit PR's :(

Stack:

Summary

The main goal here is to add a callback that gives flavors the ability to more finely control the logging process. This will enable us to easily use a new CGROUP_SOCK_ADDR elf-stub.

Notes

  • Moves cgen/matcher/packet.{c,h} to cgen/packet.{c,h}. It was a mistake to put this here in the first place as packet-based flavors can share more than matcher codegen. We correct the placement now.
  • Once again, no functional change. This moves a file around and add a callback.

@meta-cla meta-cla bot added the cla signed label Mar 20, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 20, 2026

Claude review of PR #486 (5cc7d36)

This PR has already received thorough review (24 inline comments across multiple iterations). Most substantive issues were previously identified. The findings below are new items not covered by existing comments.

Suggestions

  • bf_log_sock_addr padding holesrc/libbpfilter/include/bpfilter/runtime.h:146 — 2-byte implicit padding between dport and comm due to bf_aligned(8); consider explicit padding or field reorder before the follow-up PR locks in the layout

Nits

  • System header groupingsrc/libbpfilter/include/bpfilter/runtime.h:26<linux/in6.h> and <asm/types.h> separated by blank line; both are system headers and belong in the same group
  • Misleading byteorder Doxygensrc/libbpfilter/include/bpfilter/runtime.h:186 — union doc says "raw packet headers in network byteorder" but bf_log_pkt also contains host-byteorder fields (pkt_size, req_headers, headers)

Workflow run

@yaakov-stein yaakov-stein changed the title [1/2][`CGROUP_SOCK_ADDR Logging] Extract log codegen callback [1/2][CGROUP_SOCK_ADDR Logging] Extract log codegen callback Mar 20, 2026
@yaakov-stein yaakov-stein changed the title [1/2][CGROUP_SOCK_ADDR Logging] Extract log codegen callback [1/2][CGROUP_SOCK_ADDR Logging] Add flavor-specific log codegen callback Mar 20, 2026
@yaakov-stein yaakov-stein force-pushed the extract-log-codegen-callback branch from 86913cd to 219c17e Compare March 27, 2026 19:10
@yaakov-stein yaakov-stein force-pushed the extract-log-codegen-callback branch from 219c17e to 527d9cd Compare March 27, 2026 19:33
@yaakov-stein yaakov-stein force-pushed the extract-log-codegen-callback branch from 527d9cd to 6fa1882 Compare March 27, 2026 20:35
@yaakov-stein yaakov-stein force-pushed the extract-log-codegen-callback branch from 6fa1882 to e014ec7 Compare March 27, 2026 21:01
@yaakov-stein yaakov-stein marked this pull request as ready for review March 27, 2026 21:02
@yaakov-stein yaakov-stein marked this pull request as draft March 29, 2026 03:53
@yaakov-stein yaakov-stein force-pushed the extract-log-codegen-callback branch from e014ec7 to 5b8142a Compare March 29, 2026 20:06
@yaakov-stein yaakov-stein marked this pull request as ready for review March 29, 2026 20:09
@yaakov-stein yaakov-stein changed the title [1/2][CGROUP_SOCK_ADDR Logging] Add flavor-specific log codegen callback [1/2] Add flavor-specific log codegen callback Mar 29, 2026
@yaakov-stein yaakov-stein force-pushed the extract-log-codegen-callback branch from 5b8142a to af4ef14 Compare March 29, 2026 22:06
@yaakov-stein yaakov-stein force-pushed the extract-log-codegen-callback branch from af4ef14 to 9ecc187 Compare March 30, 2026 16:06
@yaakov-stein yaakov-stein force-pushed the extract-log-codegen-callback branch from 9ecc187 to 1ac5fdd Compare March 30, 2026 20:05
@yaakov-stein yaakov-stein requested a review from qdeslandes March 30, 2026 20:26
@yaakov-stein yaakov-stein force-pushed the extract-log-codegen-callback branch from 1ac5fdd to 91afd74 Compare March 30, 2026 20:30
#define static_assert _Static_assert
#endif

#include <linux/in6.h>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude: suggestion: <linux/in6.h> is needed only for sizeof(struct in6_addr) in struct bf_log_sock_addr, which has no producers or consumers yet (part 2/2). It widens the include set for all BPF stubs and all files that include runtime.h. Consider using __u8 saddr[16] / __u8 daddr[16] instead to avoid pulling in the header.

Also, <linux/in6.h> and <asm/types.h> are both system headers but are separated by a blank line, breaking the include-group convention from the style guide.

qdeslandes
qdeslandes previously approved these changes Apr 1, 2026
Rename the packet logging ELF stub from `log` to `pkt_log` to
establish naming symmetry with the upcoming `sock_log` stub for
socket-based hooks.
Restructure bf_log as a tagged union with packet and socket address
variants, discriminated by bf_log_type.
Move packet.c/h from cgen/matcher/ to cgen/ and rename
bf_matcher_generate_packet() to bf_packet_gen_inline_matcher(). This
file provides shared codegen utilities for all packet-based flavors,
not a matcher implementation, and will host additional shared packet
codegen like bf_packet_gen_inline_log() in subsequent commits.
@yaakov-stein yaakov-stein force-pushed the extract-log-codegen-callback branch from e840d57 to 5cc7d36 Compare April 1, 2026 23:49
@yaakov-stein yaakov-stein requested a review from qdeslandes April 1, 2026 23:49
#define static_assert _Static_assert
#endif

#include <linux/in6.h>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude: nit: <linux/in6.h> and <asm/types.h> are both system headers but are separated by a blank line, which per the style guide implies different include groups. Group them together:

#include <asm/types.h>
#include <linux/in6.h>

Note that <linux/in6.h> transitively includes <linux/types.h> (which pulls in <asm/types.h>), so the explicit <asm/types.h> may now be redundant -- but that is a separate cleanup.

__u16 dport;

/** Process name. */
bf_aligned(8) __u8 comm[BF_COMM_LEN];
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude: suggestion: struct bf_log_sock_addr has a 2-byte implicit padding hole between dport (offset 4+2=6) and comm (offset 8, due to bf_aligned(8)). When a BPF stub eventually populates this struct via bpf_ringbuf_reserve, those 2 padding bytes will contain stale ring buffer content.

Consider making the hole explicit with a __u16 _pad field (and zeroing it in the BPF writer), or reordering fields to eliminate it. Since this struct has no producer yet, now is the cheapest time to adjust the layout.

/**
* Flavor-specific payload, discriminated by `log_type`.
*
* - `BF_LOG_TYPE_PACKET`: use `pkt` — raw packet headers in network
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude: nit: The union Doxygen says use pkt -- raw packet headers in network byteorder, but struct bf_log_pkt also contains pkt_size, req_headers, and headers which are all in host byteorder. Only the raw header byte arrays (l2hdr, l3hdr, l4hdr) are in network byteorder. Consider rewording to match the top-level struct bf_log doc which correctly says "All fields are stored in host byteorder unless noted otherwise."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants