| 1 |
package features |
| 2 |
|
| 3 |
import ( |
| 4 |
"errors" |
| 5 |
|
| 6 |
"github.com/cilium/ebpf" |
| 7 |
"github.com/cilium/ebpf/asm" |
| 8 |
"github.com/cilium/ebpf/internal" |
| 9 |
"github.com/cilium/ebpf/internal/sys" |
| 10 |
) |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
func HaveLargeInstructions() error { |
| 19 |
return haveLargeInstructions() |
| 20 |
} |
| 21 |
|
| 22 |
var haveLargeInstructions = internal.NewFeatureTest(">4096 instructions", func() error { |
| 23 |
const maxInsns = 4096 |
| 24 |
|
| 25 |
insns := make(asm.Instructions, maxInsns, maxInsns+1) |
| 26 |
for i := range insns { |
| 27 |
insns[i] = asm.Mov.Imm(asm.R0, 1) |
| 28 |
} |
| 29 |
insns = append(insns, asm.Return()) |
| 30 |
|
| 31 |
return probeProgram(&ebpf.ProgramSpec{ |
| 32 |
Type: ebpf.SocketFilter, |
| 33 |
Instructions: insns, |
| 34 |
}) |
| 35 |
}, "5.2") |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
func HaveBoundedLoops() error { |
| 43 |
return haveBoundedLoops() |
| 44 |
} |
| 45 |
|
| 46 |
var haveBoundedLoops = internal.NewFeatureTest("bounded loops", func() error { |
| 47 |
return probeProgram(&ebpf.ProgramSpec{ |
| 48 |
Type: ebpf.SocketFilter, |
| 49 |
Instructions: asm.Instructions{ |
| 50 |
asm.Mov.Imm(asm.R0, 10), |
| 51 |
asm.Sub.Imm(asm.R0, 1).WithSymbol("loop"), |
| 52 |
asm.JNE.Imm(asm.R0, 0, "loop"), |
| 53 |
asm.Return(), |
| 54 |
}, |
| 55 |
}) |
| 56 |
}, "5.3") |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
func HaveV2ISA() error { |
| 64 |
return haveV2ISA() |
| 65 |
} |
| 66 |
|
| 67 |
var haveV2ISA = internal.NewFeatureTest("v2 ISA", func() error { |
| 68 |
err := probeProgram(&ebpf.ProgramSpec{ |
| 69 |
Type: ebpf.SocketFilter, |
| 70 |
Instructions: asm.Instructions{ |
| 71 |
asm.Mov.Imm(asm.R0, 0), |
| 72 |
asm.JLT.Imm(asm.R0, 0, "exit"), |
| 73 |
asm.Mov.Imm(asm.R0, 1), |
| 74 |
asm.Return().WithSymbol("exit"), |
| 75 |
}, |
| 76 |
}) |
| 77 |
|
| 78 |
if errors.Is(err, sys.ENOTSUPP) { |
| 79 |
return ebpf.ErrNotSupported |
| 80 |
} |
| 81 |
return err |
| 82 |
}, "4.14") |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
func HaveV3ISA() error { |
| 90 |
return haveV3ISA() |
| 91 |
} |
| 92 |
|
| 93 |
var haveV3ISA = internal.NewFeatureTest("v3 ISA", func() error { |
| 94 |
err := probeProgram(&ebpf.ProgramSpec{ |
| 95 |
Type: ebpf.SocketFilter, |
| 96 |
Instructions: asm.Instructions{ |
| 97 |
asm.Mov.Imm(asm.R0, 0), |
| 98 |
asm.JLT.Imm32(asm.R0, 0, "exit"), |
| 99 |
asm.Mov.Imm(asm.R0, 1), |
| 100 |
asm.Return().WithSymbol("exit"), |
| 101 |
}, |
| 102 |
}) |
| 103 |
|
| 104 |
if errors.Is(err, sys.ENOTSUPP) { |
| 105 |
return ebpf.ErrNotSupported |
| 106 |
} |
| 107 |
return err |
| 108 |
}, "5.1") |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
func HaveV4ISA() error { |
| 116 |
return haveV4ISA() |
| 117 |
} |
| 118 |
|
| 119 |
var haveV4ISA = internal.NewFeatureTest("v4 ISA", func() error { |
| 120 |
err := probeProgram(&ebpf.ProgramSpec{ |
| 121 |
Type: ebpf.SocketFilter, |
| 122 |
Instructions: asm.Instructions{ |
| 123 |
asm.Mov.Imm(asm.R0, 0), |
| 124 |
asm.JEq.Imm(asm.R0, 1, "error"), |
| 125 |
asm.LongJump("exit"), |
| 126 |
asm.Mov.Imm(asm.R0, 1).WithSymbol("error"), |
| 127 |
asm.Return().WithSymbol("exit"), |
| 128 |
}, |
| 129 |
}) |
| 130 |
|
| 131 |
if errors.Is(err, sys.ENOTSUPP) { |
| 132 |
return ebpf.ErrNotSupported |
| 133 |
} |
| 134 |
return err |
| 135 |
}, "6.6") |