1// SPDX-License-Identifier: GPL-2.0
2#include "vmlinux.h"
3#include "bpf_tracing_net.h"
4#include <bpf/bpf_helpers.h>
5
6struct bpf_xfrm_info___local {
7 u32 if_id;
8 int link;
9} __attribute__((preserve_access_index));
10
11__u32 req_if_id;
12__u32 resp_if_id;
13
14int bpf_skb_set_xfrm_info(struct __sk_buff *skb_ctx,
15 const struct bpf_xfrm_info___local *from) __ksym;
16int bpf_skb_get_xfrm_info(struct __sk_buff *skb_ctx,
17 struct bpf_xfrm_info___local *to) __ksym;
18
19SEC("tc")
20int set_xfrm_info(struct __sk_buff *skb)
21{
22 struct bpf_xfrm_info___local info = { .if_id = req_if_id };
23
24 return bpf_skb_set_xfrm_info(skb, &info) ? TC_ACT_SHOT : TC_ACT_UNSPEC;
25}
26
27SEC("tc")
28int get_xfrm_info(struct __sk_buff *skb)
29{
30 struct bpf_xfrm_info___local info = {};
31
32 if (bpf_skb_get_xfrm_info(skb, &info) < 0)
33 return TC_ACT_SHOT;
34
35 resp_if_id = info.if_id;
36
37 return TC_ACT_UNSPEC;
38}
39
40char _license[] SEC("license") = "GPL";
41

source code of linux/tools/testing/selftests/bpf/progs/xfrm_info.c