|
@@ -57,6 +57,7 @@
|
|
|
#include <net/sock_reuseport.h>
|
|
|
#include <net/busy_poll.h>
|
|
|
#include <net/tcp.h>
|
|
|
+#include <net/xfrm.h>
|
|
|
#include <linux/bpf_trace.h>
|
|
|
|
|
|
/**
|
|
@@ -3743,6 +3744,49 @@ static const struct bpf_func_proto bpf_bind_proto = {
|
|
|
.arg3_type = ARG_CONST_SIZE,
|
|
|
};
|
|
|
|
|
|
+#ifdef CONFIG_XFRM
|
|
|
+BPF_CALL_5(bpf_skb_get_xfrm_state, struct sk_buff *, skb, u32, index,
|
|
|
+ struct bpf_xfrm_state *, to, u32, size, u64, flags)
|
|
|
+{
|
|
|
+ const struct sec_path *sp = skb_sec_path(skb);
|
|
|
+ const struct xfrm_state *x;
|
|
|
+
|
|
|
+ if (!sp || unlikely(index >= sp->len || flags))
|
|
|
+ goto err_clear;
|
|
|
+
|
|
|
+ x = sp->xvec[index];
|
|
|
+
|
|
|
+ if (unlikely(size != sizeof(struct bpf_xfrm_state)))
|
|
|
+ goto err_clear;
|
|
|
+
|
|
|
+ to->reqid = x->props.reqid;
|
|
|
+ to->spi = x->id.spi;
|
|
|
+ to->family = x->props.family;
|
|
|
+ if (to->family == AF_INET6) {
|
|
|
+ memcpy(to->remote_ipv6, x->props.saddr.a6,
|
|
|
+ sizeof(to->remote_ipv6));
|
|
|
+ } else {
|
|
|
+ to->remote_ipv4 = x->props.saddr.a4;
|
|
|
+ }
|
|
|
+
|
|
|
+ return 0;
|
|
|
+err_clear:
|
|
|
+ memset(to, 0, size);
|
|
|
+ return -EINVAL;
|
|
|
+}
|
|
|
+
|
|
|
+static const struct bpf_func_proto bpf_skb_get_xfrm_state_proto = {
|
|
|
+ .func = bpf_skb_get_xfrm_state,
|
|
|
+ .gpl_only = false,
|
|
|
+ .ret_type = RET_INTEGER,
|
|
|
+ .arg1_type = ARG_PTR_TO_CTX,
|
|
|
+ .arg2_type = ARG_ANYTHING,
|
|
|
+ .arg3_type = ARG_PTR_TO_UNINIT_MEM,
|
|
|
+ .arg4_type = ARG_CONST_SIZE,
|
|
|
+ .arg5_type = ARG_ANYTHING,
|
|
|
+};
|
|
|
+#endif
|
|
|
+
|
|
|
static const struct bpf_func_proto *
|
|
|
bpf_base_func_proto(enum bpf_func_id func_id)
|
|
|
{
|
|
@@ -3884,6 +3928,10 @@ tc_cls_act_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
|
|
|
return &bpf_get_socket_cookie_proto;
|
|
|
case BPF_FUNC_get_socket_uid:
|
|
|
return &bpf_get_socket_uid_proto;
|
|
|
+#ifdef CONFIG_XFRM
|
|
|
+ case BPF_FUNC_skb_get_xfrm_state:
|
|
|
+ return &bpf_skb_get_xfrm_state_proto;
|
|
|
+#endif
|
|
|
default:
|
|
|
return bpf_base_func_proto(func_id);
|
|
|
}
|