Skip to content

Commit dc3457a

Browse files
committed
Add README and makefile
1 parent 6a5aae9 commit dc3457a

File tree

8 files changed

+230
-135
lines changed

8 files changed

+230
-135
lines changed

README.md

Lines changed: 100 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,101 @@
11
# sentinel-go-ebpf-plugin
2-
Sentinel eBPF plugin implemented by golang language
2+
3+
This is an exploratory project. The purpose is to use the function of ebpf to implement some features such as sentinel traffic limit. The project is still being explored.
4+
5+
# Requirements
6+
Linux >= 4.9.
7+
8+
# Example
9+
10+
use `go generate` to compile the code.
11+
12+
```go
13+
$ make -C ../
14+
```
15+
16+
Then
17+
18+
```go
19+
$ go run -exec sudo ./ebpf
20+
```
21+
22+
Output as below:
23+
24+
```go
25+
2022/10/31 16:27:45 Comm Src addr Port -> Dest addr Port
26+
2022/10/31 16:27:54 google_guest_ag 10.182.0.2 55146 -> 74.125.137.95 443
27+
2022/10/31 16:28:11 google_osconfig 10.182.0.2 35330 -> 74.125.137.95 443
28+
```
29+
30+
31+
# Waht we can get
32+
33+
```go
34+
/* user accessible mirror of in-kernel sk_buff.
35+
* new fields can only be added to the end of this structure
36+
*/
37+
struct __sk_buff {
38+
__u32 len;
39+
__u32 pkt_type;
40+
__u32 mark;
41+
__u32 queue_mapping;
42+
__u32 protocol;
43+
__u32 vlan_present;
44+
__u32 vlan_tci;
45+
__u32 vlan_proto;
46+
__u32 priority;
47+
__u32 ingress_ifindex;
48+
__u32 ifindex;
49+
__u32 tc_index;
50+
__u32 cb[5];
51+
__u32 hash;
52+
__u32 tc_classid;
53+
__u32 data;
54+
__u32 data_end;
55+
__u32 napi_id;
56+
57+
/* Accessed by BPF_PROG_TYPE_sk_skb types from here to ... */
58+
__u32 family;
59+
__u32 remote_ip4; /* Stored in network byte order */
60+
__u32 local_ip4; /* Stored in network byte order */
61+
__u32 remote_ip6[4]; /* Stored in network byte order */
62+
__u32 local_ip6[4]; /* Stored in network byte order */
63+
__u32 remote_port; /* Stored in network byte order */
64+
__u32 local_port; /* stored in host byte order */
65+
/* ... here. */
66+
67+
__u32 data_meta;
68+
__bpf_md_ptr(struct bpf_flow_keys *, flow_keys);
69+
__u64 tstamp;
70+
__u32 wire_len;
71+
__u32 gso_segs;
72+
__bpf_md_ptr(struct bpf_sock *, sk);
73+
__u32 gso_size;
74+
};
75+
```
76+
77+
Some tcp header information:
78+
79+
```go
80+
__u32 remote_ip4; /* Stored in network byte order */
81+
__u32 local_ip4; /* Stored in network byte order */
82+
__u32 remote_ip6[4]; /* Stored in network byte order */
83+
__u32 local_ip6[4]; /* Stored in network byte order */
84+
__u32 remote_port; /* Stored in network byte order */
85+
__u32 local_port; /* stored in host byte order */
86+
```
87+
88+
data\_meta store the meta data.
89+
data is the pointer to the begin of data.
90+
data_end is the pointer to the end of data.
91+
92+
Using the data pointer, the starting point of each tcp data can be found. But if you want to get the entire http package, you need to get multiple tcp packages, which is more difficult.
93+
94+
# To continue research
95+
- use kprobe bpf to hook system call of application process
96+
- use uprobe bpf to hook entire http package
97+
98+
99+
# License
100+
MIT
101+

ebpf/ebpf-kernel/bpf_bpfeb.go renamed to ebpf/bpf_bpfeb.go

Lines changed: 15 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ebpf/ebpf-kernel/bpf_bpfel.go renamed to ebpf/bpf_bpfel.go

Lines changed: 15 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ebpf/ebpf-kernel/xdp.c

Lines changed: 0 additions & 65 deletions
This file was deleted.

ebpf/ebpf-user/main.go

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)