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