{"record":{"id":"b870cc537ecf1483","repo":"cilium/cilium","slug":"program-s-is-nil-b870cc","errorCode":null,"errorMessage":"program %s is nil","messagePattern":"program (.+?) is nil","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/datapath/loader/xdp.go","lineNumber":301,"sourceCode":"\t}\n\tif err != nil {\n\t\treturn fmt.Errorf(\"attaching XDP program: %w\", err)\n\t}\n\n\tif err := commit(); err != nil {\n\t\treturn fmt.Errorf(\"committing bpf pins: %w\", err)\n\t}\n\n\treturn nil\n}\n\n// attachXDPProgram attaches prog with the given progName to link.\n//\n// bpffsDir should exist and point to the links/ subdirectory in the per-device\n// bpffs directory.\nfunc attachXDPProgram(logger *slog.Logger, iface netlink.Link, prog *ebpf.Program, progName, bpffsDir string, flags link.XDPAttachFlags) error {\n\tif prog == nil {\n\t\treturn fmt.Errorf(\"program %s is nil\", progName)\n\t}\n\n\t// Attempt to open and update an existing link.\n\tpin := filepath.Join(bpffsDir, progName)\n\terr := bpf.UpdateLink(pin, prog)\n\tswitch {\n\t// Update successful, nothing left to do.\n\tcase err == nil:\n\t\tlogger.Info(\"Updated link for program\",\n\t\t\tlogfields.Link, pin,\n\t\t\tlogfields.ProgName, progName,\n\t\t)\n\n\t\treturn nil\n\n\t// Link exists, but is defunct, and needs to be recreated. The program\n\t// no longer gets triggered at this point and the link needs to be removed\n\t// to proceed.","sourceCodeStart":283,"sourceCodeEnd":319,"githubUrl":"https://github.com/cilium/cilium/blob/ac7b90affa4baf0642e6685319d56907b3a73a6d/pkg/datapath/loader/xdp.go#L283-L319","documentation":"attachXDPProgram validates that the ebpf.Program handle for progName is non-nil before attaching. Cilium throws 'program %s is nil' when the collection/spec did not contain the expected named program, so attaching cannot proceed. This is a defensive check against loading a datapath object that lacks the required XDP program symbol.","triggerScenarios":"spec/collection lookup for progName (e.g. the XDP entrypoint program) yields nil because the compiled object's program name changed, the ELF was built from wrong source files, or the wrong object was compiled/loaded.","commonSituations":"Mistmatched bpf_xdp.c source and expected program name after a Cilium upgrade; build script compiling the wrong .o; datapath source-tree/bpf objects out of sync between cilium image and node state.","solutions":["Verify the compiled ELF contains progName (llvm-objdump -h / bpftool prog) and recompile the datapath","Ensure Cilium image and node bpf sources are from the same version; wipe /var/run/cilium/state and restart","Check the loader was handed the correct object path for XDP (not the generic bpf.o)","If integrating programmatically, confirm the collection map key/program name matches the ELF symbol"],"exampleFix":"// before\nprog := coll.Programs[progName]\nerr := attachXDPProgram(logger, iface, prog, progName, dir, flags)\n// after\nprog, ok := coll.Programs[progName]\nif !ok || prog == nil {\n    return fmt.Errorf(\"collection %s lacks program %s; recompile datapath\", objPath, progName)\n}\nerr := attachXDPProgram(logger, iface, prog, progName, dir, flags)","handlingStrategy":"type-guard","validationCode":"// after loading the collection\nprog, ok := coll.Programs[progName]\nif !ok || prog == nil {\n    return fmt.Errorf(\"program %s missing from %s\", progName, objPath)\n}","typeGuard":"func programExists(coll *ebpf.Collection, name string) (*ebpf.Program, bool) {\n    if coll == nil { return nil, false }\n    p, ok := coll.Programs[name]\n    return p, ok && p != nil\n}","tryCatchPattern":"// Go: guard before attach\nif prog == nil {\n    return fmt.Errorf(\"cannot attach: program %s not loaded; recompile datapath\", progName)\n}","preventionTips":["Recompile and reload the datapath together with every Cilium image upgrade","Validate the compiled object contains expected program names in CI (bpftool/llvm-objdump)","Keep bpf sources and agent binaries in the same container image","Never hand-edit or partially copy datapath object files"],"tags":["ebpf","xdp","nil-pointer","program-missing"],"backgroundTag":"ebpf-program-not-found","analyzedSha":"ac7b90affa4baf0642e6685319d56907b3a73a6d","analyzedAt":"2026-08-31T18:27:15.868Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}