-
Notifications
You must be signed in to change notification settings - Fork 99
/
Copy pathcgroup_skb.c
52 lines (44 loc) · 1.16 KB
/
cgroup_skb.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
/* Copyright Authors of Kmesh */
#include <linux/bpf.h>
#include <sys/socket.h>
#include <bpf/bpf_endian.h>
#include <bpf/bpf_helpers.h>
#include "bpf_log.h"
#include "bpf_common.h"
#include "probe.h"
#include "config.h"
SEC("cgroup_skb/ingress")
int cgroup_skb_ingress_prog(struct __sk_buff *skb)
{
if (!is_monitoring_enable()) {
return SK_PASS;
}
if (skb->family != AF_INET && skb->family != AF_INET6)
return SK_PASS;
struct bpf_sock *sk = skb->sk;
if (!sk)
return SK_PASS;
if (!is_managed_by_kmesh_skb(skb))
return SK_PASS;
observe_on_data(sk);
return SK_PASS;
}
SEC("cgroup_skb/egress")
int cgroup_skb_egress_prog(struct __sk_buff *skb)
{
if (!is_monitoring_enable()) {
return SK_PASS;
}
if (skb->family != AF_INET && skb->family != AF_INET6)
return SK_PASS;
struct bpf_sock *sk = skb->sk;
if (!sk)
return SK_PASS;
if (!is_managed_by_kmesh_skb(skb))
return SK_PASS;
observe_on_data(sk);
return SK_PASS;
}
char _license[] SEC("license") = "Dual BSD/GPL";
int _version SEC("version") = 1;