Wasm bpf is participating 2021 OSC China Open Source Project Selection , please vote for it!
Wasm bpf in 2021 OSC China Open Source Project Selection {{projectVoteCount} has been obtained in, please vote for it!
2021 OSC China Open Source Project Selection It is in hot progress. Come and vote for your favorite open source project!
2021 OSC China Open Source Project Selection>>> Midfield Review
Wasm bpf won the 2021 OSC China Open Source Project Selection "The Best Popularity Project" !
Authorization Agreement MIT
development language C/C++
operating system Cross platform
Software type Open source software
Classification big data data processing
Open source organizations nothing
region domestic
deliverer osc_18663073
intended for unknown
Recording time 2023-02-16

Software Introduction

Wasm bpf is a WebAssembly eBPF library and runtime based on CO-RE (Write Once – Run Everywhere) libbpf and wasm-micro-runtime realization.

Wasm was originally developed for the purpose of browser security sandbox. So far, WebAssembly has become a high-performance, cross platform and multilingual software sandbox environment for cloud native software components. Wasm lightweight container is also very suitable for the next generation server free platform runtime. Another exciting trend is the rise of eBPF, which enables cloud native developers to build secure networks, service grids and a variety of observable components. It is also gradually penetrating and penetrating into various components of the kernel, providing more powerful programmable interaction capabilities in the kernel state.

Now, with the help of Wasm bpf compilation tool chain and runtime, we can use Wasm to write eBPF programs as cross platform modules, and use C/C++or Rust to write and publish Wasm eBPF programs. By using eBPF programs in WebAssembly, we can not only enable Wasm applications to enjoy the high performance of eBPF and access to system interfaces, but also enable eBPF programs to use Wasm's sandbox, flexibility, cross platform, and dynamic loading, and use Wasm's OCI image to easily and quickly distribute and manage eBPF programs. Combining these two technologies, we will give eBPF and Wasm ecology a new development experience!

  • Highlights:
  • currency : Provides most of the eBPF functions for WASM. For example, from ring buffer perhaps perf buffer Get data from, pass maps provide kernel EBPF and User status Bi directional communication and dynamics between Wasm programs load , additional perhaps Disattach EBPF program, etc. It supports a large number of eBPF program types and map types, covering Tracing , Networking , Security Use scenarios for.
  • High performance : For complex data types, no additional serialize expenses. adopt Shared memory To avoid additional data copies between the host and the WASM side.
  • Simple and convenient development experience : Provide and libbpf-bootstrap Similar development experience, Auto generate Wasm-eBPF skeleton Header file and the type definition.
  • Very light : The binary file compiled is only 1.5 MB The size of the compiled WASM module is ~90K , which is much lighter than the traditional way of distributing and running eBPF programs in containers, while maintaining good isolation and sandbox characteristics. You can easily use any language, build your own Wasm-eBPF runtime on any platform, and use the same tool chain to build applications!

 WASI-bpf

Use C/C++to build an eBPF application in Wasm, load the eBPF bytecode into the kernel and process the corresponding data returned by the kernel

     /* Load and verify BPF application */ skel = bootstrap_bpf__open(); if (!skel) { fprintf (stderr, " Failed to open and load BPF skeleton \\n " ); return  one ; }
 <span style="color:var(--color-prettylights-syntax-comment)"><span style="color:var(--color-prettylights-syntax-comment)">/*</span> Parameterize BPF code with minimum duration parameter <span style="color:var(--color-prettylights-syntax-comment)" >*/</span></span> skel->rodata->min_duration_ns = env.min_duration_ms * <span style="color:var(--color-prettylights-syntax-constant)">1000000ULL</span>; < span style="color:var(--color-prettylights-syntax-comment)"><span style="color:var(--color-prettylights-syntax-comment)">/*</span> Load & verify BPF programs <span style="color:var(--color-prettylights-syntax-comment)">*/</span></span> err = bootstrap_bpf__load(skel); <span style="color:var(--color-prettylights-syntax-keyword)">if</span> (err)  { <span style="color:var(--color-prettylights-syntax-constant)">fprintf</span>(stderr, <span style="color:var(--color-prettylights-syntax-string)"><span style="color:var(--color-prettylights-syntax-string)">"</span>Failed to load and verify BPF skeleton<span>\\n</span><span style="color:var(--color-prettylights-syntax-string)">"</span></span>);  <span style="color:var(--color-prettylights-syntax-keyword)">goto</span> cleanup; } < span style="color:var(--color-prettylights-syntax-comment)"><span style="color:var(--color-prettylights-syntax-comment)">/*</span> Attach tracepoints <span style="color:var(--color-prettylights-syntax-comment)">*/</span></span> err = bootstrap_bpf__attach(skel); <span style="color:var(--color-prettylights-syntax-keyword)">if</span> (err)  { <span style="color:var(--color-prettylights-syntax-constant)">fprintf</span>(stderr, <span style="color:var(--color-prettylights-syntax-string)"><span style="color:var(--color-prettylights-syntax-string)">"</span>Failed to attach BPF skeleton<span>\\n</span><span style="color:var(--color-prettylights-syntax-string)">"</span></span>);  <span style="color:var(--color-prettylights-syntax-keyword)">goto</span> cleanup; }</ pre>

Use Rust to write an eBPF application in Wasm:

 extern  "C"  fn handle_event ( _ctx :  u32 ,  data :  u32 ,  _data_sz :  u32 )  {
     let event_slice = unsafe  { slice :: from_raw_parts ( data as  * const  Event ,  one )  } ;
     let event = & event_slice [ zero ] ;
     let pid = event . pid ;
     let ppid = event . ppid ;
     let exit_code = event . exit_code ;
     if event . exit_event == one  {
         print ! (
             "{:<8} {:<5} {:<16} {:<7} {:<7} [{}]" , "TIME" , "EXIT" , unsafe  {  CStr ::from_ptr ( event.comm.as_ptr ( )  as * const  i8 )  } .to_str ( ) .unwrap ( ) , pid, ppid, exit_code ) ; .. .
 }

One line command downloads and runs the eBPF program from Github Packages on the cloud, or publishes it through Github Packages:

 # push to Github Packages ecli push  https://ghcr.io/eunomia-bpf/sigsnoop:latest # pull from Github Packages ecli pull  https://ghcr.io/eunomia-bpf/sigsnoop:latest # run eBPF program ecli run  https://ghcr.io/eunomia-bpf/sigsnoop:latest
  • Subsequent update plan:
    • Continue to improve multilingual support;
    • Support more perfect eBPF features;
    • Explore more application scenarios;
Expand to read the full text

code

Gitee index of is
exceed Items for

comment

Click to lead the topic 📣 Post and join the discussion 🔥
No content temporarily
{{o.pubDate | formatDate}}

{{formatAllHtml(o.title)}}

{{parseInt(o.replyCount) | bigNumberTransform}}
{{parseInt(o.viewCount) | bigNumberTransform}}
No more
No content temporarily
Issued a question and answer
{{o.pubDate | formatDate}}

{{formatAllHtml(o.title)}}

{{parseInt(o.replyCount) | bigNumberTransform}}
{{parseInt(o.viewCount) | bigNumberTransform}}
No more
No content temporarily
No content temporarily
zero comment
ten Collection
 OSCHINA
Log in to view more high-quality content
 Back to top
Top