tools/testing/selftests/bpf/progs/test_dst_clear.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/test_dst_clear.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/test_dst_clear.c- Extension
.c- Size
- 1344 bytes
- Lines
- 58
- 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.hbpf_tracing_net.hbpf/bpf_helpers.hbpf/bpf_endian.h
Detected Declarations
function dst_clear
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2026 Meta Platforms, Inc. and affiliates. */
#include "vmlinux.h"
#include "bpf_tracing_net.h"
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_endian.h>
#define UDP_TEST_PORT 7777
void *bpf_cast_to_kern_ctx(void *) __ksym;
bool had_dst = false;
bool dst_cleared = false;
SEC("tc/egress")
int dst_clear(struct __sk_buff *skb)
{
struct sk_buff *kskb;
struct iphdr iph;
struct udphdr udph;
int err;
if (skb->protocol != __bpf_constant_htons(ETH_P_IP))
return TC_ACT_OK;
if (bpf_skb_load_bytes(skb, ETH_HLEN, &iph, sizeof(iph)))
return TC_ACT_OK;
if (iph.protocol != IPPROTO_UDP)
return TC_ACT_OK;
if (bpf_skb_load_bytes(skb, ETH_HLEN + sizeof(iph), &udph, sizeof(udph)))
return TC_ACT_OK;
if (udph.dest != __bpf_constant_htons(UDP_TEST_PORT))
return TC_ACT_OK;
kskb = bpf_cast_to_kern_ctx(skb);
had_dst = (kskb->_skb_refdst != 0);
/* Same-protocol encap (IPIP): protocol stays IPv4, but the dst
* from the original routing is no longer valid for the outer hdr.
*/
err = bpf_skb_adjust_room(skb, (s32)sizeof(struct iphdr),
BPF_ADJ_ROOM_MAC,
BPF_F_ADJ_ROOM_FIXED_GSO |
BPF_F_ADJ_ROOM_ENCAP_L3_IPV4);
if (err)
return TC_ACT_SHOT;
dst_cleared = (kskb->_skb_refdst == 0);
return TC_ACT_SHOT;
}
char __license[] SEC("license") = "GPL";
Annotation
- Immediate include surface: `vmlinux.h`, `bpf_tracing_net.h`, `bpf/bpf_helpers.h`, `bpf/bpf_endian.h`.
- Detected declarations: `function dst_clear`.
- 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.