LoadPinnedProgram loads a Program from a pin (file) on the BPF virtual filesystem. Requires at least Linux 4.11.
(fileName string, opts *LoadPinOptions)
| 1112 | // |
| 1113 | // Requires at least Linux 4.11. |
| 1114 | func LoadPinnedProgram(fileName string, opts *LoadPinOptions) (*Program, error) { |
| 1115 | fd, typ, err := sys.ObjGetTyped(&sys.ObjGetAttr{ |
| 1116 | Pathname: sys.NewStringPointer(fileName), |
| 1117 | FileFlags: opts.Marshal(), |
| 1118 | }) |
| 1119 | if err != nil { |
| 1120 | return nil, err |
| 1121 | } |
| 1122 | |
| 1123 | if typ != sys.BPF_TYPE_PROG { |
| 1124 | _ = fd.Close() |
| 1125 | return nil, fmt.Errorf("%s is not a Program", fileName) |
| 1126 | } |
| 1127 | |
| 1128 | p, err := newProgramFromFD(fd) |
| 1129 | if err == nil { |
| 1130 | p.pinnedPath = fileName |
| 1131 | |
| 1132 | if haveObjName() != nil { |
| 1133 | p.name = filepath.Base(fileName) |
| 1134 | } |
| 1135 | } |
| 1136 | |
| 1137 | return p, err |
| 1138 | } |
| 1139 | |
| 1140 | // ProgramGetNextID returns the ID of the next eBPF program. |
| 1141 | // |
searching dependent graphs…