github.com/cilium/ebpf@v0.15.1-0.20240517100537-8079b37aa138/docs/examples/features_test.go (about)

     1  package examples
     2  
     3  import (
     4  	"errors"
     5  	"fmt"
     6  
     7  	"github.com/cilium/ebpf"
     8  	"github.com/cilium/ebpf/features"
     9  )
    10  
    11  func DocDetectXDP() {
    12  	err := features.HaveProgramType(ebpf.XDP)
    13  	if errors.Is(err, ebpf.ErrNotSupported) {
    14  		fmt.Println("XDP program type is not supported")
    15  		return
    16  	}
    17  	if err != nil {
    18  		// Feature detection was inconclusive.
    19  		//
    20  		// Note: always log and investigate these errors! These can be caused
    21  		// by a lack of permissions, verifier errors, etc. Unless stated
    22  		// otherwise, probes are expected to be conclusive. Please file
    23  		// an issue if this is not the case in your environment.
    24  		panic(err)
    25  	}
    26  
    27  	fmt.Println("XDP program type is supported")
    28  }