package ubpf

  1. Overview
  2. Docs
OCaml bindings for userspace eBPF VM

Install

Dune Dependency

Authors

Maintainers

Sources

0.1.tar.gz
sha256=be7eb6623049a16dd37a8dc3577f4fa5673c655a0486747bd6eebe28a55a6940
md5=481ebf53773aa84fe5926ac8fb942e8a

README.md.html

README.md

OCaml bindings for the Userspace eBPF VM.

uBPF is patched to initialize R2 with data size.

let exec bpf data =
  let open Ubpf in
  let vm = load (`Bpf bpf) in
  try
    jit_compile vm;
    let ret = exec vm data in
    release vm;
    ret
  with exn ->
    release vm;
    raise exn

(* the following eBPF program returns 1 if the first byte of data is \001 or \002 *)
let raw_bpf = "\
\x15\x02\x06\x00\x00\x00\x00\x00\
\x71\x13\x00\x00\x00\x00\x00\x00\
\x15\x03\x02\x00\x02\x00\x00\x00\
\x15\x03\x01\x00\x01\x00\x00\x00\
\x05\x00\x02\x00\x00\x00\x00\x00\
\xb7\x00\x00\x00\x01\x00\x00\x00\
\x95\x00\x00\x00\x00\x00\x00\x00\
\xb7\x00\x00\x00\x00\x00\x00\x00\
\x95\x00\x00\x00\x00\x00\x00\x00"

exec raw_bpf "\000" = 0

exec raw_bpf "\001" = 1

exec raw_bpf "\002" = 1

exec raw_bpf "\003" = 0

See OCaml eBPF assembler to assemble raw ```Bpf``.

OCaml

Innovation. Community. Security.