xref: /linux/tools/testing/selftests/bpf/progs/xfrm_info.c (revision 0526b56cbc3c489642bd6a5fe4b718dea7ef0ee8)
1 // SPDX-License-Identifier: GPL-2.0
2 #include "vmlinux.h"
3 #include "bpf_tracing_net.h"
4 #include <bpf/bpf_helpers.h>
5 
6 struct 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 
14 int bpf_skb_set_xfrm_info(struct __sk_buff *skb_ctx,
15 			  const struct bpf_xfrm_info___local *from) __ksym;
16 int bpf_skb_get_xfrm_info(struct __sk_buff *skb_ctx,
17 			  struct bpf_xfrm_info___local *to) __ksym;
18 
19 SEC("tc")
20 int 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 
27 SEC("tc")
28 int 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 
40 char _license[] SEC("license") = "GPL";
41