Comments (4)
Hi,
It is not supported by design: one system/xdp_program -> one interface. Otherwise additional complexity will be introduced only for this particular program type / usecase.
But nothing stops you to create few instances of ebpf.System
, like this:
xdps := map[string]goebpf.System{}
for _, iface := range []string{"eth0", "eth1"} {
bpf := goebpf.NewDefaultEbpfSystem()
bpf.LoadElf("test.elf")
xdp := bpf.GetProgramByName("xdp_test")
xdp.Load()
xdp.Attach(iface)
xdps[iface] = bpf
}
It will take more memory, but, remains simple.
from goebpf.
Thanks for the reply!
I suppose the way you provided will create two progs and two set of maps, and progs cannot share data via maps any more. That may not work in my case. I am creating some DNAT application, which accepts connection on one interface and modifies the dst address and saves the session info in the map and forwards the packet via another interface. When the return packet arrives on the another interface, a lookup in the map will be done to restore the address. I understand this can be achieved with two progs with different functions each attaching to different interfaces, but this will make the progs not so common and may require prog array if the same interface is used for both incoming and outgoing purpose.
Currently I crafted my own Detach() to release interfaces based on the logic of xdpProgram one. But this is a hack of the goebpf package.
from goebpf.
I suppose the way you provided will create two progs and two set of maps, and progs cannot share data via maps any more.
By default - yes, maps will not be shared. However it is super easy to make them shared across different programs / processes / etc:
Lines 8 to 14 in 4910d57
Please be sure to mount destination as bpffs
mount bpffs -t bpffs /sys/fs/bpf
from goebpf.
Thanks for the advice. I will try it. This can be closed.
from goebpf.
Related Issues (20)
- LoadElf() loads without error but elfSystem is empty HOT 4
- XDP example packet_counter - BPF map definition and LoadElf() fails HOT 1
- all tests fail HOT 3
- ebpf_create_map() failed: Operation not permitted HOT 3
- Include linux header file failed HOT 2
- Invalid BPF instruction while bpf map lookup after having called `htons` or `bpf_htons` HOT 3
- goebpf for windows HOT 1
- eBPF program in Go HOT 1
- My Go program cannot exit, it traps in `p.updateChannel <- p.items[int(p.fds[i])]`
- can't run xdp_dump HOT 6
- error while loading BPF_MAP_TYPE_PROG_ARRAY map HOT 1
- kprobe_events: device or resource busy / no such file or directory
- ebpf map insert 不支持struct?需要如何支持?
- xdp.Attach error when bind to eth0 on aws-ubuntu 22.04.1 HOT 1
- possible to include this example for ipv6 as well? HOT 1
- Crash on PerfEvents Stop() HOT 1
- bpf_trace_printk result in LoadElf() failed: loadPrograms() failed: map '' doesn't exist
- Incorrect padding causing errors in retrieving Ip/Tcp/Eth layer information with XDP/EBPF.
- LoadElf() failed: loadAndCreateMaps() failed: Invalid binary representation of BPF map
- LoadElf(prog.o) failed: loadAndCreateMaps() failed: map.Create() failed: ebpfObjPin to '/sys/fs/bpf/name_persistence_map' failed: File exists
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 goebpf.