Comments (12)
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.
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.
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.
You can call external functions in a bpf program but they must be registered first. register_functions
from ubpf.
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.
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.
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.
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.
Isn't it a compiler version issue or something? Mine is "10.0.0"
from ubpf.
You might be confusing prog
and prog.o
from ubpf.
True, thank you :)
from ubpf.
You are welcome ! :D
from ubpf.
+1 to @pchaigno upstreaming those Oko changes back into this repo ;-)!
from ubpf.
Related Issues (20)
- Header files should contain SPDX-License-Identifier
- Adopt clang formatting for repo
- Enable dependabot on this repo to keep depedencies in synch
- Support multiple eBPF programs in the same section
- Add support for .maps section
- Consider renaming master branch to main branch HOT 1
- OpenSSF - The license document should be present at root and named "LICENSE.txt"
- Enable CodeQL task on repo
- Possible division bug in interpreter HOT 1
- uBPF unit test should also run the test cases via BPF_PROG_RUN and compare results HOT 1
- Fix code scanning alert - loading ELF files.
- Unaligned 64bit load in ubpf_vm.c @ line 444 HOT 3
- ubpf_jit_arm64.c fails under address sanitizer HOT 3
- uBPF should reject call instructions with src != 0 HOT 1
- bpf_conformance/arm64 should run with address sanitizer enabled HOT 3
- Eliminate duplicate test files between ubpf and bpf_conformance
- Should we remove string table support in the JIT? HOT 2
- Add JIT support for MIPS
- Add option to disable JIT
- ARM64 builds broken by changes in upstream repos
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ubpf.