github.com/cilium/ebpf@v0.10.0/features/misc.go (about)

     1  package features
     2  
     3  import (
     4  	"github.com/cilium/ebpf"
     5  	"github.com/cilium/ebpf/asm"
     6  	"github.com/cilium/ebpf/internal"
     7  )
     8  
     9  // HaveLargeInstructions probes the running kernel if more than 4096 instructions
    10  // per program are supported.
    11  //
    12  // Upstream commit c04c0d2b968a ("bpf: increase complexity limit and maximum program size").
    13  //
    14  // See the package documentation for the meaning of the error return value.
    15  var HaveLargeInstructions = internal.NewFeatureTest(">4096 instructions", "5.2", func() error {
    16  	const maxInsns = 4096
    17  
    18  	insns := make(asm.Instructions, maxInsns, maxInsns+1)
    19  	for i := range insns {
    20  		insns[i] = asm.Mov.Imm(asm.R0, 1)
    21  	}
    22  	insns = append(insns, asm.Return())
    23  
    24  	return probeProgram(&ebpf.ProgramSpec{
    25  		Type:         ebpf.SocketFilter,
    26  		Instructions: insns,
    27  	})
    28  })
    29  
    30  // HaveBoundedLoops probes the running kernel if bounded loops are supported.
    31  //
    32  // Upstream commit 2589726d12a1 ("bpf: introduce bounded loops").
    33  //
    34  // See the package documentation for the meaning of the error return value.
    35  var HaveBoundedLoops = internal.NewFeatureTest("bounded loops", "5.3", func() error {
    36  	return probeProgram(&ebpf.ProgramSpec{
    37  		Type: ebpf.SocketFilter,
    38  		Instructions: asm.Instructions{
    39  			asm.Mov.Imm(asm.R0, 10),
    40  			asm.Sub.Imm(asm.R0, 1).WithSymbol("loop"),
    41  			asm.JNE.Imm(asm.R0, 0, "loop"),
    42  			asm.Return(),
    43  		},
    44  	})
    45  })
    46  
    47  // HaveV2ISA probes the running kernel if instructions of the v2 ISA are supported.
    48  //
    49  // Upstream commit 92b31a9af73b ("bpf: add BPF_J{LT,LE,SLT,SLE} instructions").
    50  //
    51  // See the package documentation for the meaning of the error return value.
    52  var HaveV2ISA = internal.NewFeatureTest("v2 ISA", "4.14", func() error {
    53  	return probeProgram(&ebpf.ProgramSpec{
    54  		Type: ebpf.SocketFilter,
    55  		Instructions: asm.Instructions{
    56  			asm.Mov.Imm(asm.R0, 0),
    57  			asm.JLT.Imm(asm.R0, 0, "exit"),
    58  			asm.Mov.Imm(asm.R0, 1),
    59  			asm.Return().WithSymbol("exit"),
    60  		},
    61  	})
    62  })
    63  
    64  // HaveV3ISA probes the running kernel if instructions of the v3 ISA are supported.
    65  //
    66  // Upstream commit 092ed0968bb6 ("bpf: verifier support JMP32").
    67  //
    68  // See the package documentation for the meaning of the error return value.
    69  var HaveV3ISA = internal.NewFeatureTest("v3 ISA", "5.1", func() error {
    70  	return probeProgram(&ebpf.ProgramSpec{
    71  		Type: ebpf.SocketFilter,
    72  		Instructions: asm.Instructions{
    73  			asm.Mov.Imm(asm.R0, 0),
    74  			asm.JLT.Imm32(asm.R0, 0, "exit"),
    75  			asm.Mov.Imm(asm.R0, 1),
    76  			asm.Return().WithSymbol("exit"),
    77  		},
    78  	})
    79  })