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
package main
import (
"fmt"
"log"
"net"
"github.com/cilium/ebpf"
"github.com/cilium/ebpf/rlimit"
)
func main() {
// Allow the current process to lock memory for eBPF resources.
if err := rlimit.RemoveMemlock(); err != nil {
log.Fatal(err)
}
// Path where the map is pinned
pinPath := "/sys/fs/bpf/xdp-filter/filter_ipv4"
// Load the existing pinned map
ipMap, err := ebpf.LoadPinnedMap(pinPath, nil)
if err != nil {
log.Fatalf("failed to load pinned map: %v", err)
}
defer ipMap.Close()
fmt.Println("Filtered IP addresses:")
fmt.Printf(" %-15s Hit counters per CPU\n", "IP")
// Iterate over all entries in the map using a key-value pair
var key uint32
possibleCPUs := ebpf.MustPossibleCPU()
value := make([]uint64, possibleCPUs) // Allocate a slice for per-CPU values
// Initialize the iterator over the map
iter := ipMap.Iterate()
for iter.Next(&key, &value) {
ip := net.IPv4(byte(key>>24), byte(key>>16), byte(key>>8), byte(key)).String()
fmt.Printf(" %-15s %v\n", ip, value) // Print all counters per CPU
}
if err := iter.Err(); err != nil {
log.Fatalf("iterating over map failed: %v", err)
}
}
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
-
it seems per cpu lru hash is not supported but how do i access the per cpu map with golang?
https://github.com/xdp-project/xdp-tools/blob/master/xdp-filter/xdp-filter.c
this is what i've tried. any help on this?
Beta Was this translation helpful? Give feedback.
All reactions