tools/testing/selftests/bpf/progs/xdp_metadata.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/xdp_metadata.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/xdp_metadata.c- Extension
.c- Size
- 2783 bytes
- Lines
- 112
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
vmlinux.hxdp_metadata.hbpf/bpf_helpers.hbpf/bpf_endian.h
Detected Declarations
function rxfunction redirect
Annotated Snippet
if (eth->h_proto == bpf_htons(ETH_P_IP)) {
iph = (void *)(eth + 1);
if (iph + 1 < data_end && iph->protocol == IPPROTO_UDP)
udp = (void *)(iph + 1);
}
if (eth->h_proto == bpf_htons(ETH_P_IPV6)) {
ip6h = (void *)(eth + 1);
if (ip6h + 1 < data_end && ip6h->nexthdr == IPPROTO_UDP)
udp = (void *)(ip6h + 1);
}
if (udp && udp + 1 > data_end)
udp = NULL;
}
if (!udp)
return XDP_PASS;
/* Forwarding UDP:8080 to AF_XDP */
if (udp->dest != bpf_htons(8080))
return XDP_PASS;
/* Reserve enough for all custom metadata. */
ret = bpf_xdp_adjust_meta(ctx, -(int)sizeof(struct xdp_meta));
if (ret != 0)
return XDP_DROP;
data = (void *)(long)ctx->data;
data_meta = (void *)(long)ctx->data_meta;
if (data_meta + sizeof(struct xdp_meta) > data)
return XDP_DROP;
meta = data_meta;
/* Export metadata. */
/* We expect veth bpf_xdp_metadata_rx_timestamp to return 0 HW
* timestamp, so put some non-zero value into AF_XDP frame for
* the userspace.
*/
bpf_xdp_metadata_rx_timestamp(ctx, ×tamp);
if (timestamp == 0)
meta->rx_timestamp = 1;
bpf_xdp_metadata_rx_hash(ctx, &meta->rx_hash, &meta->rx_hash_type);
bpf_xdp_metadata_rx_vlan_tag(ctx, &meta->rx_vlan_proto,
&meta->rx_vlan_tci);
return bpf_redirect_map(&xsk, ctx->rx_queue_index, XDP_PASS);
}
SEC("xdp")
int redirect(struct xdp_md *ctx)
{
return bpf_redirect_map(&dev_map, ctx->rx_queue_index, XDP_PASS);
}
char _license[] SEC("license") = "GPL";
Annotation
- Immediate include surface: `vmlinux.h`, `xdp_metadata.h`, `bpf/bpf_helpers.h`, `bpf/bpf_endian.h`.
- Detected declarations: `function rx`, `function redirect`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.