tools/testing/selftests/bpf/progs/test_tunnel_kern.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/test_tunnel_kern.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/test_tunnel_kern.c- Extension
.c- Size
- 22214 bytes
- Lines
- 1026
- 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/bpf_core_read.hbpf/bpf_helpers.hbpf/bpf_endian.hbpf_kfuncs.hbpf_tracing_net.h
Detected Declarations
struct bpf_fou_encap___localstruct local_geneve_optenum bpf_fou_encap_type___localfunction gre_set_tunnelfunction gre_set_tunnel_no_keyfunction gre_get_tunnelfunction ip6gretap_set_tunnelfunction ip6gretap_get_tunnelfunction erspan_set_tunnelfunction erspan_get_tunnelfunction ip4ip6erspan_set_tunnelfunction ip4ip6erspan_get_tunnelfunction vxlan_set_tunnel_dstfunction vxlan_set_tunnel_srcfunction vxlan_get_tunnel_srcfunction veth_set_outer_dstfunction ip6vxlan_set_tunnel_dstfunction ip6vxlan_set_tunnel_srcfunction ip6vxlan_get_tunnel_srcfunction geneve_set_tunnelfunction geneve_get_tunnelfunction ip6geneve_set_tunnelfunction ip6geneve_get_tunnelfunction ipip_set_tunnelfunction ipip_get_tunnelfunction ipip_gue_set_tunnelfunction ipip_fou_set_tunnelfunction ipip_encap_get_tunnelfunction ipip6_set_tunnelfunction ipip6_get_tunnelfunction ip6ip6_set_tunnelfunction ip6ip6_get_tunnelfunction xfrm_get_statefunction xfrm_get_state_xdp
Annotated Snippet
struct bpf_fou_encap___local {
__be16 sport;
__be16 dport;
} __attribute__((preserve_access_index));
enum bpf_fou_encap_type___local {
FOU_BPF_ENCAP_FOU___local,
FOU_BPF_ENCAP_GUE___local,
};
int bpf_skb_set_fou_encap(struct __sk_buff *skb_ctx,
struct bpf_fou_encap___local *encap, int type) __ksym;
int bpf_skb_get_fou_encap(struct __sk_buff *skb_ctx,
struct bpf_fou_encap___local *encap) __ksym;
struct xfrm_state *
bpf_xdp_get_xfrm_state(struct xdp_md *ctx, struct bpf_xfrm_state_opts *opts,
u32 opts__sz) __ksym;
void bpf_xdp_xfrm_state_release(struct xfrm_state *x) __ksym;
struct {
__uint(type, BPF_MAP_TYPE_ARRAY);
__uint(max_entries, 1);
__type(key, __u32);
__type(value, __u32);
} local_ip_map SEC(".maps");
SEC("tc")
int gre_set_tunnel(struct __sk_buff *skb)
{
int ret;
struct bpf_tunnel_key key;
__builtin_memset(&key, 0x0, sizeof(key));
key.remote_ipv4 = 0xac100164; /* 172.16.1.100 */
key.tunnel_id = 2;
key.tunnel_tos = 0;
key.tunnel_ttl = 64;
ret = bpf_skb_set_tunnel_key(skb, &key, sizeof(key),
BPF_F_ZERO_CSUM_TX | BPF_F_SEQ_NUMBER);
if (ret < 0) {
log_err(ret);
return TC_ACT_SHOT;
}
return TC_ACT_OK;
}
SEC("tc")
int gre_set_tunnel_no_key(struct __sk_buff *skb)
{
int ret;
struct bpf_tunnel_key key;
__builtin_memset(&key, 0x0, sizeof(key));
key.remote_ipv4 = 0xac100164; /* 172.16.1.100 */
key.tunnel_ttl = 64;
ret = bpf_skb_set_tunnel_key(skb, &key, sizeof(key),
BPF_F_ZERO_CSUM_TX | BPF_F_SEQ_NUMBER |
BPF_F_NO_TUNNEL_KEY);
if (ret < 0) {
log_err(ret);
return TC_ACT_SHOT;
}
return TC_ACT_OK;
}
SEC("tc")
int gre_get_tunnel(struct __sk_buff *skb)
{
int ret;
struct bpf_tunnel_key key;
ret = bpf_skb_get_tunnel_key(skb, &key, sizeof(key), 0);
if (ret < 0) {
log_err(ret);
return TC_ACT_SHOT;
}
bpf_printk("key %d remote ip 0x%x\n", key.tunnel_id, key.remote_ipv4);
return TC_ACT_OK;
}
SEC("tc")
int ip6gretap_set_tunnel(struct __sk_buff *skb)
{
struct bpf_tunnel_key key;
int ret;
Annotation
- Immediate include surface: `vmlinux.h`, `bpf/bpf_core_read.h`, `bpf/bpf_helpers.h`, `bpf/bpf_endian.h`, `bpf_kfuncs.h`, `bpf_tracing_net.h`.
- Detected declarations: `struct bpf_fou_encap___local`, `struct local_geneve_opt`, `enum bpf_fou_encap_type___local`, `function gre_set_tunnel`, `function gre_set_tunnel_no_key`, `function gre_get_tunnel`, `function ip6gretap_set_tunnel`, `function ip6gretap_get_tunnel`, `function erspan_set_tunnel`, `function erspan_get_tunnel`.
- 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.