You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm testing out ebpf-go for the first time and I'm wondering how to populate an array of maps when loading the program. I have the following XDP program
package main
import (
"log/slog"
"net"
"os"
"os/signal"
"runtime"
"time"
"github.com/cilium/ebpf"
"github.com/cilium/ebpf/link"
"github.com/cilium/ebpf/rlimit"
)
func main() {
logger := slog.Default()
ifaceName := "ens1"
// Remove resource limits for kernels <5.11.
if err := rlimit.RemoveMemlock(); err != nil {
logger.Error("Removing memlock", "error", err)
os.Exit(1)
}
// Load the compiled eBPF ELF and load it into the kernel.
var objs udp_routerObjects
if err := loadUdp_routerObjects(&objs, &ebpf.CollectionOptions{
Maps: ebpf.MapOptions{
PinPath: "/sys/fs/bpf",
},
}); err != nil {
logger.Error("Loading eBPF objects", "error", err)
os.Exit(1)
}
defer objs.Close()
// Creating flow tables for each CPU
cpus := runtime.NumCPU()
for cpu := 0; cpu < cpus; cpu++ {
if err := objs.udp_routerMaps.PerCpuFlows.Update(&cpu, objs.udp_routerMaps.Flows, ebpf.UpdateAny); err != nil {
logger.Error("Inserting map", "cpu", cpu, "error", err)
os.Exit(1)
}
}
iface, err := net.InterfaceByName(ifaceName)
if err != nil {
logger.Error("Getting interface", "interface", ifaceName, "error", err)
os.Exit(1)
}
mode := link.XDPGenericMode
// Attach count_packets to the network interface.
link, err := link.AttachXDP(link.XDPOptions{
Program: objs.UdpRouter,
Interface: iface.Index,
Flags: mode,
})
if err != nil {
logger.Error("Attaching XDP", "interface", iface.Name, "error", err)
os.Exit(1)
}
defer link.Close()
logger.Info("Starting UDP Router", "interface", iface.Name)
// Event loop
tick := time.Tick(time.Second)
stop := make(chan os.Signal, 5)
signal.Notify(stop, os.Interrupt)
for {
select {
case <-tick:
logger.Info("Alive and well...")
case <-stop:
logger.Info("Received signal, exiting..")
return
}
}
}
However, it fails in the loop, where it's trying to create the flow tables for each CPU. I couldn't find in the manual details on how to initialize such arrays, so I could be doing it wrong. I see with strace one syscall that returns a not supported error, but can't really figure out what operation is causing it.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm testing out ebpf-go for the first time and I'm wondering how to populate an array of maps when loading the program. I have the following XDP program
My Go program for loading it is the following:
However, it fails in the loop, where it's trying to create the flow tables for each CPU. I couldn't find in the manual details on how to initialize such arrays, so I could be doing it wrong. I see with strace one syscall that returns a not supported error, but can't really figure out what operation is causing it.
Any ideas?
Beta Was this translation helpful? Give feedback.
All reactions