xiaohongshu
xiaohongshu
ebpf-cnf-scaffold
Scaffold new eBPF-based Cloud Native Network Function (CNF) projects with proper directory structure, boilerplate C kernel code, Go userspace application, bpf2go generation, and build configuration following established patterns. Use when creating new CNF examples or starting fresh eBPF projects.
Full skill instructions
This skill scaffolds complete eBPF-based CNF projects following the established patterns in this repository.
Creates a new eBPF CNF project with:
examples/{name}/)bytecode/{name}.c)main.go)bytecode/gen.go)examples/{name}/
├── main.go # Go userspace application
├── bytecode/
│ ├── gen.go # bpf2go generation directive
│ ├── {name}.c # eBPF kernel program (Restricted C)
│ ├── {name}_bpfel.go # Generated (after go generate)
│ └── {name}_bpfeb.go # Generated (after go generate)
├── go.mod # Go module file
├── README.md # Build and run instructions
└── Dockerfile # Optional containerization
For complex CNFs, use subpackages to organize code:
examples/{name}/
├── main.go # Entry point, CLI, event loop
├── main_test.go # Integration tests
├── bytecode/
│ ├── gen.go # bpf2go generation
│ ├── vmlinux.h # Kernel types for CO-RE
│ ├── {name}.c # eBPF program
│ ├── {name}_bpfel.go # Generated
│ └── {name}_bpfeb.go # Generated
├── {subpkg}/ # Internal package
│ ├── {subpkg}.go # Core functionality
│ ├── {subpkg}_test.go # Unit tests
│ └── options.go # Functional options
├── go.mod
└── README.md
Example from netkit-ipv6:
examples/netkit-ipv6/
├── main.go
├── main_test.go
├── bytecode/
│ ├── gen.go
│ ├── vmlinux.h
│ └── netkit_ipv6.c
├── netkit/ # Subpackage for device management
│ ├── netkit.go # CreatePair, Delete
│ ├── netkit_test.go
│ ├── options.go # WithL2Mode, WithL3Mode
│ └── ipv6.go # ConfigureIPv6LinkLocal
└── go.mod
Benefits of subpackages:
Before scaffolding, ask the user:
//go:build ignore
#include <linux/bpf.h>
#include <bpf/bpf_helpers.h>
// Add appropriate headers based on hook type
// XDP: <linux/if_ether.h>, <linux/ip.h>
// TC/tcx: <linux/pkt_cls.h>
// netkit: <linux/if_link.h>
char _license[] SEC("license") = "GPL";
SEC("{hook_section}")
int {function_name}(struct {ctx_type} *ctx) {
// TODO: Implement CNF logic
return {return_value};
}
package bytecode
//go:generate go tool bpf2go -type {types} {CapitalizedName} {name}.c -- -O2 -Wall -Werror
package main
import (
"log"
"os"
"os/signal"
"syscall"
"{module}/bytecode"
"github.com/cilium/ebpf"
"github.com/cilium/ebpf/link"
)
func main() {
// Load eBPF objects
spec, err := bytecode.Load{Name}()
if err != nil {
log.Fatalf("loading eBPF spec: %v", err)
}
objs := &bytecode.{Name}Objects{}
if err := spec.LoadAndAssign(objs, nil); err != nil {
log.Fatalf("loading eBPF objects: %v", err)
}
defer objs.Close()
// TODO: Attach program to hook
// TODO: Read from maps/ringbufs if needed
log.Println("{Name} CNF is running...")
// Wait for signal
sig := make(chan os.Signal, 1)
signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)
<-sig
log.Println("Shutting down...")
}
# {Name} CNF
{Description}
## Build
Compile the eBPF program:
```shell
go generate ./bytecode
```
Build the userspace application:
```shell
go build -o {name}
```
## Run
```shell
sudo ./{name}
```
## Test
```shell
sudo -E go test .
```
SEC("xdp")struct xdp_md *ctxXDP_PASS, XDP_DROP, XDP_TX, XDP_REDIRECT, XDP_ABORTEDlink.AttachXDP()SEC("tc") or SEC("tcx/ingress") / SEC("tcx/egress")struct __sk_buff *skbTC_ACT_OK, TC_ACT_SHOT, TC_ACT_REDIRECT, TC_ACT_PIPElink.AttachTCX() for tcx, link.AttachTC() for legacySEC("netkit/primary") and SEC("netkit/peer")struct __sk_buff *skbNETKIT_PASS, NETKIT_DROP, NETKIT_REDIRECTlink.AttachNetkit() with ebpf.AttachNetkitPrimary or ebpf.AttachNetkitPeerSEC("kprobe/function_name") or SEC("kretprobe/function_name")struct pt_regs *ctx0link.Kprobe() or link.Kretprobe()SEC("tracepoint/category/name")0link.Tracepoint()After creating the structure, initialize the Go module:
cd examples/{name}
go mod init github.com/{username}/xcnf/examples/{name}
go get -tool github.com/cilium/ebpf/cmd/bpf2go
go mod tidy
After scaffolding, remind the user to:
Enter the Linux VM (if using OrbStack):
orb
Generate vmlinux.h (for CO-RE programs):
cd examples/{name}/bytecode
bpftool btf dump file /sys/kernel/btf/vmlinux format c > vmlinux.h
Generate eBPF bytecode:
cd examples/{name}
go generate ./bytecode
Implement the CNF logic in:
bytecode/{name}.c - kernel-space processingmain.go - userspace control and data handlingBuild and test:
go build -o {name}
sudo ./{name}
bpf_printk for debugging)defer for cleanup (Close(), link cleanup)User: "Create a new CNF called 'rate-limiter' that uses XDP to rate limit incoming packets"
xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience