eBPF the Hard Way!¶
Welcome to eBPF the Hard Way - a comprehensive, hands-on guide to learning eBPF development from the ground up!
π― What You'll Build¶
This isn't just another tutorial. You'll build real, production-ready eBPF tools from scratch, understanding every line of code and concept along the way.
Learning by Building
We believe the best way to learn eBPF is by building actual tools. Each tutorial walks you through creating a complete monitoring tool, from the eBPF kernel program to the Go userspace application.
π§ What is eBPF?¶
eBPF (extended Berkeley Packet Filter) is a revolutionary technology that allows you to run sandboxed programs in the Linux kernel without changing kernel source code or loading kernel modules.
Why eBPF Matters¶
- π Observability: Monitor any aspect of your system in real-time
- π‘οΈ Security: Implement custom security policies and detection
- β‘ Performance: Near-zero overhead monitoring and analysis
- π§ Debugging: Create custom debugging tools for any application
π What You'll Learn¶
By working through this guide, you'll master:
- eBPF virtual machine and verifier
- Program types and attachment points
- Maps and data structures
- Helper functions and kernel interaction
- Writing eBPF programs in C
- Building userspace applications in Go
- Debugging eBPF programs
- Performance optimization techniques
- Cross-platform development
- Production deployment strategies
- CO-RE (Compile Once, Run Everywhere) development
- Network packet processing with XDP/TC
- Security monitoring with LSM hooks
- Testing strategies and frameworks
- Error handling and memory management
- Process execution monitoring
- File system activity tracking
- Network connection analysis
- Security event correlation
- Performance profiling tools
π Quick Start¶
Ready to dive in? Here's your learning path:
π± Beginners¶
- Set up your environment - Get everything installed
- Learn eBPF basics - Understand the core concepts
- Build your first tool - Create a complete eBPF application
- Explore basic tools - Learn from working examples
π Advanced Users¶
- Master CO-RE development - Build portable eBPF programs
- Network programming - XDP and TC packet processing
- Security monitoring - LSM hooks and event correlation
- Testing strategies - Comprehensive testing frameworks
Estimated Time
- Quick setup: 30 minutes
- First tool: 2-3 hours
- Basic proficiency: 1-2 weeks
- Advanced topics: 2-4 weeks
- Production mastery: 1-2 months (at your own pace)
π οΈ Tools You'll Build¶
Basic Tools¶
| Tool | Difficulty | Category | What It Does |
|---|---|---|---|
| execsnoop | π’ Beginner | Process Monitoring | Monitor process executions in real-time |
| rmdetect | π’ Beginner | File System | Monitor file deletions |
| opensnoop | π‘ Intermediate | File System | Monitor file opens |
Advanced Tools¶
| Tool | Difficulty | Category | What It Does |
|---|---|---|---|
| tcpconnect | π‘ Intermediate | Network | Monitor TCP connections |
| biolatency | π΄ Advanced | Performance | Measure block I/O latency |
| DDoS Protection | π΄ Advanced | Network Security | XDP-based DDoS mitigation |
| Load Balancer | π΄ Advanced | Network | Layer 4 load balancing with XDP |
| Security Monitor | π΄ Advanced | Security | LSM-based security event detection |
π Prerequisites¶
System Requirements
- Linux Kernel: 4.18+ (5.0+ recommended)
- Architecture: x86_64 or arm64
- Root Access: Required for loading eBPF programs
- BTF Support: Check with
ls /sys/kernel/btf/vmlinux
Development Knowledge
- C Programming: Basic knowledge (we'll teach eBPF-specific parts)
- Go Programming: Helpful but not required (examples are clear)
- Linux Systems: Understanding of processes, files, networking
π Why This Guide is Different¶
π Comprehensive Yet Practical¶
- Every concept is explained with working code
- No "magic" - you'll understand every line
- Progressive complexity from simple to advanced
π― Learning-Focused¶
- Clear learning objectives for each section
- Checkpoint exercises to test your understanding
- Common pitfalls and how to avoid them
π§ Production-Ready¶
- Real tools you can use in production
- Best practices and performance considerations
- Proper error handling and debugging techniques
π€ Community-Driven¶
- Open source and welcomes contributions
- Active community support
- Regular updates with new tools and concepts
πΊοΈ Learning Path¶
graph TD
A[Getting Started] --> B[eBPF Fundamentals]
B --> C[Your First Tool]
C --> D[Process Monitoring Tools]
D --> E[File System Tools]
E --> F[Network Tools]
F --> G[Performance Tools]
G --> H[Advanced Topics]
style A fill:#e1f5fe
style B fill:#f3e5f5
style C fill:#e8f5e8
style D fill:#fff3e0
style E fill:#fce4ec
style F fill:#e0f2f1
style G fill:#fff8e1
style H fill:#f1f8e9
π Ready to Start?¶
Choose your path:
-
Complete Beginner
Start with the fundamentals and build up your knowledge step by step.
-
Some Experience
Jump straight to building your first tool if you know the basics.
-
Advanced Developer
Explore advanced topics like CO-RE, XDP, LSM, and testing strategies.
-
Production Ready
Learn debugging, testing, and deployment strategies.
π Documentation Structure¶
π Core Learning Path¶
- Getting Started - Environment setup and eBPF basics
- Fundamentals - Core eBPF concepts and architecture
- First Tool - Step-by-step tool creation
- Tools - Complete working examples
π Advanced Topics¶
- CO-RE & BTF - Portable eBPF development
- Network Programming - XDP and TC packet processing
- Security Monitoring - LSM hooks and event correlation
- Testing Strategies - Comprehensive testing frameworks
- Performance - Optimization techniques
π Reference Materials¶
- Troubleshooting - Debug techniques and common issues
- Best Practices - Production-ready patterns
- API Reference - Helper functions and APIs
- Glossary - eBPF terminology
π Need Help?¶
- π¬ Discussions: Ask questions in GitHub Discussions
- π Issues: Report bugs or request features
- π Docs: Check our comprehensive reference sections
- π€ Contributing: Help improve this guide for others
Learning Philosophy
"The best way to learn eBPF is not by reading about it, but by building with it. This guide gives you the confidence to create, experiment, and innovate with eBPF."
Let's build something amazing together! π