| 1 | # Examples |
| 2 | |
| 3 | A collection of programs showing how to use the library. |
| 4 | Please see our [guide on what makes a good example](https://ebpf-go.dev/contributing/new-example/) if you think something is missing. |
| 5 | |
| 6 | * Kprobe - Attach a program to the entry or exit of an arbitrary kernel symbol (function). |
| 7 | * [kprobe](kprobe/) - Kprobe using bpf2go. |
| 8 | * [kprobepin](kprobepin/) - Reuse a pinned map for the kprobe example. It assumes the BPF FS is mounted at `/sys/fs/bpf`. |
| 9 | * [kprobe_percpu](kprobe_percpu/) - Use a `BPF_MAP_TYPE_PERCPU_ARRAY` map. |
| 10 | * [ringbuffer](ringbuffer/) - Use a `BPF_MAP_TYPE_RINGBUF` map. |
| 11 | * Uprobe - Attach a program to the entry or exit of an arbitrary userspace binary symbol (function). |
| 12 | * [uretprobe](uretprobe/) - Uretprobe using bpf2go. |
| 13 | * Tracepoint - Attach a program to predetermined kernel tracepoints. |
| 14 | * [tracepoint_in_c](tracepoint_in_c/) - Tracepoint using bpf2go. |
| 15 | * [tracepoint_in_go](tracepoint_in_go/) - Tracepoint using the `ebpf.NewProgram` API and Go eBPF assembler. |
| 16 | * Cgroup - Attach a program to control groups (cgroups). |
| 17 | * [cgroup_skb](cgroup_skb/) - Count packets egressing the current cgroup. |
| 18 | * Fentry - Attach a program to the entrypoint of a kernel function. |
| 19 | Like kprobes, but with better performance and usability, for kernels 5.5 and later. |
| 20 | * [tcp_connect](fentry/) - Trace outgoing IPv4 TCP connections. |
| 21 | * [tcp_close](tcprtt/) - Log RTT of IPv4 TCP connections using eBPF CO-RE helpers. |
| 22 | * TCx - Attach a program to Linux TC (Traffic Control) to process incoming and outgoing packets. |
| 23 | * [tcx](./tcx/) - Print packet counts for ingress and egress. |
| 24 | * XDP - Attach a program to a network interface to process incoming packets. |
| 25 | * [xdp](xdp/) - Print packet counts by IPv4 source address. |
| 26 | * [xdp_live_frame](xdp_live_frame/) - XDP-based traffic generator that uses live frame mode. |
| 27 | * sched_ext - Attach a StructOpsMap to register a custom task scheduler. This feature is supported by kernel version starting from version 6.12. |
| 28 | * [sched_ext](sched_ext/) - Minimal sched_ext_ops. |
| 29 | |
| 30 | ## How to run |
| 31 | |
| 32 | ```bash |
| 33 | cd ebpf/examples/ |
| 34 | go run -exec sudo [./kprobe, ./uretprobe, ./ringbuffer, ...] |
| 35 | ``` |
| 36 | |
| 37 | ## How to recompile |
| 38 | |
| 39 | The examples are built via `go generate` invoked by the Makefile in the project root. |
| 40 | |
| 41 | ``` |
| 42 | make -C ../ |
| 43 | ``` |