Getting Started

Resources and Prerequisites

This page lists all resources, reference projects, content sources, and target deliverables you will use throughout the learning path.

Content Sources

The exercises and reading materials in this roadmap are drawn from these primary sources:

SourceWhat It Provides
eBPFHub exercisesHands-on coding exercises with an in-browser editor and server-side runner
iximiuz labsInteractive networking and Linux fundamentals courses (especially Computer Networking Fundamentals)
xdp-tutorialOfficial XDP tutorial repo with progressive exercises from basic to advanced packet processing
Reading materials (listed below)Papers, blog posts, and documentation referenced in each chapter

Reference Projects

SourceDescription
KatranFacebook L4 load balancer (XDP). Read README.md now; study xdp_root.c in later chapters.
lb-from-scratchLiz Rice’s load balancer built from scratch - you must complete this
reuseport-ebpf-goRead after completing lb-from-scratch
DnsTraceDNS tracing project
eBPFeXPLOITeBPF exploit examples
bngBNG project

Reading Materials

These resources will be referenced again in the relevant chapters:

SourceRelated Chapter
Computer Networking FundamentalsByte Order + Network Tracing
XDP PaperXDP Packet Processing
Cilium BPF ArchitectureBPF Deep Dive
Cilium Network ConceptsXDP vs TC Program Types
Unimog BlogLoad Balancing
Facebook BPF FirewallIP Blocklist
Cilium Performance TuningAdvanced Topics

Additional Resources

xdp-tutorial Directory Guide

The xdp-tutorial repository is organized into progressive folders. Use this table to know which folder to study and when.

FolderWhat It TeachesWhen to Use
basic01-xdp-passMinimal XDP program that passes all packetsStart here; first XDP program
basic02-prog-by-nameLoading and attaching XDP programs by section nameRight after basic01
basic03-map-counterUsing BPF maps to count packetsWhen learning maps (Chapter 2+)
basic04-pinning-mapsPinning maps to the BPF filesystem for persistenceAfter basic03, before multi-program setups
packet01-parsingParsing Ethernet, IP, and TCP/UDP headers safelyCore skill; study before building any filter
packet02-rewritingRewriting packet headers (MAC, IP)Needed for load balancer and NAT projects
packet03-redirectingRedirecting packets between interfaces with bpf_redirectLoad balancer and forwarding use cases
tracing01-xdp-simpleTracing XDP events with bpf_printkDebugging any XDP program
tracing02-xdp-perf-eventPerf event output from XDP programsWhen you need structured event output
advanced01-xdp-load-balancerFull XDP load balancer exampleAfter completing packet01-03; compare with your own LB
advanced03-AF_XDPAF_XDP socket for user-space packet processingOptional; only if you need user-space fast path

Quick Reference

When you encounter a specific need, use this table to find the right BPF primitive or technique.

NeedSolutionNotes
Block IPs from a listBPF_MAP_TYPE_HASH with IP keysUsed in DDoS engine and IP blocklist
Count packets per sourceBPF_MAP_TYPE_PERCPU_HASH or BPF_MAP_TYPE_LRU_HASHPer-CPU variant avoids lock contention
Rate limitingBPF_MAP_TYPE_HASH + token bucket in BPFStore timestamp and token count per key
Round-robin backend selectionBPF_MAP_TYPE_ARRAY + atomic counterIndex into backend array with __sync_fetch_and_add
Consistent hashingHash 5-tuple, mod N backendsUse jhash or similar; see Katran for reference
DNS query inspectionParse UDP payload after L3/L4 headersMatch on QNAME field in DNS wire format
Pass packet to kernel stackReturn XDP_PASSDefault when no action needed
Drop packetReturn XDP_DROPFastest discard path in the kernel
Redirect to another interfacebpf_redirect() + return XDP_REDIRECTNeeded for load balancer forwarding
Rewrite MAC addressesDirect header modification via xdp_md->dataRequired after redirect to set correct L2 header
Share state between XDP and user spaceBPF_MAP_TYPE_HASH or BPF_MAP_TYPE_ARRAYPin maps to BPFFS for persistence across program reloads
Tail call to another BPF programBPF_MAP_TYPE_PROG_ARRAY + bpf_tail_call()Used in Katran’s xdp_root.c for program chaining
IP blocklist (CIDR ranges)BPF_MAP_TYPE_LPM_TRIELongest prefix match for subnet-level blocking
DNS query logBPF_MAP_TYPE_RINGBUF + Go consumerStream events to userspace without polling
Debug outputbpf_printk() + bpftool prog traceKernel trace pipe; use only during development
Routing lookupbpf_fib_lookup()Resolve next-hop MAC and interface from kernel FIB
String comparisonbpf_strncmp()Compare variable string against a constant
Substring searchbpf_strstr() (kernel 6.x+)Find a needle in a haystack buffer
Read kernel memorybpf_probe_read_kernel_str()Safe read from kernel address space
Read user memorybpf_probe_read_user_str()Safe read from user address space
Get process namebpf_get_current_comm()Returns the comm (name) of the running task
Convert port (network to host)bpf_ntohs()16-bit network byte order to host byte order
Convert IP (network to host)bpf_ntohl()32-bit network byte order to host byte order

Study Order Summary

Follow these phases in order. Each phase builds on the previous one.

PhaseFocusKey Deliverable
Phase 1: FoundationsC basics, kernel data types, byte order, BPF verifier rulesPass all Chapter 1 exercises
Phase 2: Packet ParsingEthernet/IP/UDP header parsing, bounds checking, XDP return codesParse and classify live packets
Phase 3: Maps and StateBPF map types, per-CPU maps, map pinning, user-space interactionIP blocklist with dynamic updates
Phase 4: Core ProjectsL4 Load Balancer, DDoS mitigation engine, DNS policy filterThree working XDP programs
Phase 5: Polish and ExtendPerformance tuning, metrics export, optional DNS resolver/forwarderProduction-ready code with documentation

What to Skip

The following topics are common in general C or systems programming curricula but are not needed for eBPF/XDP development. Skip them to stay focused.

TopicWhy It Is Not Needed
time.h / date-time functionsBPF programs use bpf_ktime_get_ns() instead of libc time functions
File I/O (fopen, fread, fwrite)BPF programs cannot access the filesystem; all state goes through maps
Dynamic memory (malloc, free)The BPF verifier forbids dynamic allocation; all memory is stack or map-based
RecursionBPF programs cannot recurse; the verifier rejects any backward jumps
Floating point arithmeticBPF has no floating point support; use integer math
Signal handling (signal.h)Only relevant in user-space loader code, not in BPF programs
Multi-threading (pthread)BPF programs are single-threaded per invocation; concurrency is handled by per-CPU maps
Standard I/O (printf, scanf)Use bpf_printk() for debug output; no standard I/O in kernel context
struct tm, strftimeNot available in BPF; timestamps are raw nanosecond values
Random number generationBPF has bpf_get_prandom_u32(); no need for libc random functions
Binary search treesUse BPF_MAP_TYPE_LPM_TRIE for prefix matching; BPF restricts custom tree structures
Linear/binary search algorithmsBPF maps provide O(1) hash lookup; no need to implement search manually
Complex data structures (linked lists, trees)BPF maps provide hash tables and arrays; custom data structures are restricted by the verifier

Optional but useful for pointer practice: Linked lists and stack/queue implementations. You will not use these in BPF, but they provide good struct + pointer practice.

Is TC Hook Needed?

Short answer: No. For the DDoS engine, DNS filter, and L4 load balancer projects in this roadmap, XDP is sufficient. You do not need to learn TC (Traffic Control) BPF hooks.

AspectXDPTC (cls_bpf)
Hook pointNIC driver, before SKB allocationAfter SKB is created, in the qdisc layer
DirectionIngress onlyBoth ingress and egress
PerformanceFastest possible; runs before the kernel network stackSlower; SKB overhead is already paid
Use case fitDDoS drop, DNS filtering, L4 LB forwardingEgress shaping, container networking, policy after routing
SKB accessNo SKB; works with raw xdp_mdFull SKB with metadata, mark, priority
When you need itWhenever you want to filter or redirect at line rateWhen you need egress hooks or SKB-level features (e.g., skb->mark)

Why XDP is enough for this roadmap:

  • DDoS mitigation needs fast ingress drop - XDP’s XDP_DROP is the fastest path.
  • DNS filtering inspects inbound UDP queries - all ingress, no egress hook needed.
  • L4 load balancing forwards packets with bpf_redirect before the kernel allocates an SKB, which is the whole performance advantage.
  • TC becomes relevant when you need egress policies (e.g., Cilium’s container networking) or need to read SKB metadata. That is outside the scope of this roadmap.

If you later work on container networking or need egress filtering, revisit TC at that point. For now, focus entirely on XDP.

Target Deliverables

These are the projects you should produce by the end of this learning path:

  1. L4 Load Balancer - eBPF/XDP based (challenge)
  2. DDoS Engine - XDP ingress filtering
  3. DNS Policy Filter - DNS query-based filtering
  4. DNS Resolver (optional) - challenge
  5. DNS Forwarder (optional) - challenge