brintos

brintos / linux-shallow public Read only

0
0
Text · 936 B · a1d9f10 Raw
42 lines · c
1// SPDX-License-Identifier: GPL-2.02#define BPF_NO_KFUNC_PROTOTYPES3#include "vmlinux.h"4#include "bpf_tracing_net.h"5#include <bpf/bpf_helpers.h>6 7struct 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 15int bpf_skb_set_xfrm_info(struct __sk_buff *skb_ctx,16			  const struct bpf_xfrm_info___local *from) __ksym;17int bpf_skb_get_xfrm_info(struct __sk_buff *skb_ctx,18			  struct bpf_xfrm_info___local *to) __ksym;19 20SEC("tc")21int 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 28SEC("tc")29int 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 41char _license[] SEC("license") = "GPL";42