Code Monkey home page Code Monkey logo

Comments (4)

belyalov avatar belyalov commented on August 24, 2024

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.

chenwng avatar chenwng commented on August 24, 2024

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.

belyalov avatar belyalov commented on August 24, 2024

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:

BPF_MAP_DEF(txcnt) = {
.map_type = BPF_MAP_TYPE_PERCPU_ARRAY,
.key_size = sizeof(__u32),
.value_size = sizeof(__u64),
.max_entries = 100,
.persistent_path = "/sys/fs/bpf/txcnt",
};

Please be sure to mount destination as bpffs

mount bpffs -t bpffs /sys/fs/bpf

from goebpf.

chenwng avatar chenwng commented on August 24, 2024

Thanks for the advice. I will try it. This can be closed.

from goebpf.

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.