Coder Social home page Coder Social logo

rust-ebpf-demo's Introduction

Rust eBPF Hello World

This is a minimal example of how to write an eBPF filter in rust natively. This "hello-world" draws on a lot of inspiration from this blog post however I found the need to use gobpf unecessary.

The blog uses gobpf simply from what I can surmise to leverage gobpf ability to load ebpf programs for kprobes. gobpf uses the section names in a well understood format to attach the filter to the correct function.

Building

The following will has rustc emit the LLVM IR instead of produce a full library. The LLVM IR can then be fed into llc which can generate the correct eBPF object ELF file.

cargo rustc --release -- --emit=llvm-ir
cp target/release/deps/rust_ebpf_demo-*.ll rust_ebpf_demo.ll
cargo rustc --release -- --emit=llvm-bc
cp target/release/deps/rust_ebpf_demo-*.bc rust_ebpf_demo.bc
llc rust_ebpf_demo.bc -march=bpf -filetype=obj -o rust_ebpf_demo.o

Testing

In order to see the test you have to make sure you have the trace pipe enabled.

echo 1 > /sys/kernel/debug/tracing/tracing_on

# Once enabled you can do:
sudo cat /sys/kernel/debug/tracing/trace_pipe 

rust-ebpf-demo's People

Contributors

fzakaria avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

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.