tools/testing/selftests/bpf/progs/twfw.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/twfw.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/twfw.c- Extension
.c- Size
- 1158 bytes
- Lines
- 59
- 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
linux/types.hbpf/bpf_helpers.hlinux/bpf.hstdint.h
Detected Declarations
struct twfw_tier_valuestruct rulestruct rules_mapstruct tiers_mapfunction twfw_verifier
Annotated Snippet
struct twfw_tier_value {
unsigned long mask[1];
};
struct rule {
uint8_t seqnum;
};
struct rules_map {
__uint(type, BPF_MAP_TYPE_ARRAY);
__type(key, __u32);
__type(value, struct rule);
__uint(max_entries, 1);
};
struct tiers_map {
__uint(type, BPF_MAP_TYPE_ARRAY);
__type(key, __u32);
__type(value, struct twfw_tier_value);
__uint(max_entries, 1);
};
struct rules_map rules SEC(".maps");
struct tiers_map tiers SEC(".maps");
SEC("cgroup_skb/ingress")
int twfw_verifier(struct __sk_buff* skb)
{
const uint32_t key = 0;
const struct twfw_tier_value* tier = bpf_map_lookup_elem(&tiers, &key);
if (!tier)
return 1;
struct rule* rule = bpf_map_lookup_elem(&rules, &key);
if (!rule)
return 1;
if (rule && rule->seqnum < TWFW_MAX_TIERS) {
/* rule->seqnum / 64 should always be 0 */
unsigned long mask = tier->mask[rule->seqnum / 64];
if (mask)
return 0;
}
return 1;
}
Annotation
- Immediate include surface: `linux/types.h`, `bpf/bpf_helpers.h`, `linux/bpf.h`, `stdint.h`.
- Detected declarations: `struct twfw_tier_value`, `struct rule`, `struct rules_map`, `struct tiers_map`, `function twfw_verifier`.
- 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.