GithubHelp home page GithubHelp logo

Comments (12)

pchaigno avatar pchaigno commented on June 23, 2024 2

I actually looked at Oko, and I realized that there are a couple of things not available in the uBPF, for example, maps. Although Oko has been built on top of uBPF.

Oko author here 👋

That's true, Oko supports additional features on top of ubpf, such as hash maps, arrays, and a simple verifier. I unfortunately never found the time to upstream all of those to ubpf 😞

I'd like to write complex eBPF functionalities using uBPF, isn't it possible? Imagine the following scenario for a single packet.
Wire -> NIC -> Kernel -> Userspace - Run a chain of BPF programs on the packet via uBPF -> Kernel -> NIC -> Wire

That is definitely possible. However, note that ubpf will only implement the actual uBPF loading and execution. To receive and send packets from userspace, you'll have to use something else, such as DPDK or Linux's AK_PACKET API.

from ubpf.

carverdamien avatar carverdamien commented on June 23, 2024 1

Hi!
What are you planning to do with ubpf ?

Example for prog.c

unsigned long int prog(char *addr) {
  if (addr)
    return 0;
  return 1;
}

Compile and run

$ clang -c prog.c -target bpf -o prog
$ vm/test prog
0x1
$ vm/test -m prog prog # addr will have the content of prog
0x0

from ubpf.

sarsanaee avatar sarsanaee commented on June 23, 2024

Thank you @carverdamien

I actually looked at Oko, and I realized that there are a couple of things not available in the uBPF, for example, maps. Although Oko has been built on top of uBPF.

I'd like to write complex eBPF functionalities using uBPF, isn't it possible? Imagine the following scenario for a single packet.

Wire -> NIC -> Kernel -> Userspace - Run a chain of BPF programs on the packet via uBPF -> Kernel -> NIC -> Wire

I'm also wondering what libraries I'm allowed or able to include in the uBPF programs?

from ubpf.

carverdamien avatar carverdamien commented on June 23, 2024

You can call external functions in a bpf program but they must be registered first. register_functions

from ubpf.

sarsanaee avatar sarsanaee commented on June 23, 2024

Hi @carverdamien

I'm wondering why I couldn't call for example sqrti function in our simple prog.c file.

Here is what I did.

unsigned long int prog(char *addr) {
  sqrti(16); // here I called the registered function.
  if (addr)
    return 0;
  return 1;
}

Here is the warning generated. warning: implicit declaration of function 'sqrti' is invalid in C99 [-Wimplicit-function-declaration] sqrti(16);

When I run the program I get the following:

Failed to load code: bad relocation type 10

Probably, I'm missing something obvious here.

Thanks,
Alireza

from ubpf.

jpsamaroo avatar jpsamaroo commented on June 23, 2024

Helper calls in BPF are encoded as a call to an integer, where the integer is the index of the registered function you want to call. I think it should look something like this in C:

static int (*sqrti)(int) = (void *)1; // 1 is the index of our registered sqrti

unsigned long int prog(char *addr) {
  sqrti(16); // here I called the registered function.
  if (addr)
    return 0;
  return 1;
}

Unfortunately, I haven't been able to compile this such that vm/test is happy with it; it always results in Failed to load code: bad relocation type 1.

from ubpf.

carverdamien avatar carverdamien commented on June 23, 2024

Compile with -O2

root@cda22c35d683:~# cat prog.c 
static int (*sqrti)(int) = (void *)3;
unsigned long int prog(char *addr) {
  return sqrti(16);
}
root@cda22c35d683:~# cat prog.s 
        .text
        .file   "prog.c"
        .globl  prog                    # -- Begin function prog
        .p2align        3
        .type   prog,@function
prog:                                   # @prog
# %bb.0:
        r1 = 16
        call 3
        r0 <<= 32
        r0 s>>= 32
        exit
.Lfunc_end0:
        .size   prog, .Lfunc_end0-prog
                                        # -- End function
        .addrsig
root@cda22c35d683:~# ./src/ubpf/vm/test -m prog prog
0x4

from ubpf.

sarsanaee avatar sarsanaee commented on June 23, 2024

Hello again,

Thanks for your time.

I have gone through the same steps. However, I'm still having troubles with Failed to load code: bad relocation type 10.

I also took a screenshot of my steps, which is similar to yours.

image

Isn't it a compiler version issue or something? Mine is "10.0.0"

from ubpf.

carverdamien avatar carverdamien commented on June 23, 2024

You might be confusing prog and prog.o

from ubpf.

sarsanaee avatar sarsanaee commented on June 23, 2024

True, thank you :)

from ubpf.

carverdamien avatar carverdamien commented on June 23, 2024

You are welcome ! :D

from ubpf.

sbates130272 avatar sbates130272 commented on June 23, 2024

+1 to @pchaigno upstreaming those Oko changes back into this repo ;-)!

from ubpf.

Related Issues (20)

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.