Git Product home page Git Product logo

libbpf's Introduction

libbpf

KubeArmor bpf library

One will only be able to go get and to use this go module (library) setting the CGO_LDFLAGS environment variable, since this is based on the aqua security libbpfgo that is a cgo wrapper of the C libbpf.

So be aware that using this library in your go code turns it into cgo code.


General Dependencies

Ubuntu

linux-tools-generic

libelf-dev

zlib1g-dev

clang


Using this library

One way is to use the shared library libbpf.so if it is already installed.

❯ CGO_LDFLAGS="/usr/lib/libbpf.so" go get github.com/kubearmor/libbpf

However, currently, the most common is to use the libbpf.a (static version). To do so, follow the steps below.

  • Clone this repository.

    ❯ git clone github.com/kubearmor/libbpf

  • Inside the repository folder, run make to download the C libbpf code and compile it.

    ❯ make

    This will generate the static libbpf.a file and the vmlinux.h and bpf/*.h headers inside ./include.

  • Now one is able to make correct use of this library. Be sure to use absolute paths.

    ❯ CGO_LDFLAGS="/path_to_this_repo/include/libbpf.a" CGO_CFLAGS="-I /path_to_this_repo/include" go get github.com/kubearmor/libbpf

The same environment variable need to be set when building the final application that uses this library.

❯ CGO_LDFLAGS="/path_to_this_repo/include/libbpf.a" CGO_CFLAGS="-I /path_to_this_repo/include" go build

Testing it

The use cases inside tests can be tested using make.

❯ make run-tests


KABPFMapElement interface

To satisfy KABPFMapElement interface, it's necessary to implement the following methods for an XXMapElem.

func (pme *XXMapElem) KeyPointer() unsafe.Pointer {
	...
}

func (pme *XXMapElem) ValuePointer() unsafe.Pointer {
	...
}

func (pme *XXMapElem) SetFoundValue(value []byte) {
	...
}

func (pme *XXMapElem) MapName() string {
	return "map_name"
}

Examples can also be found in tests.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.