Repository navigation
Fix wrong statement saying devmap_hash keys can have any size. - #271
Conversation
dylandreimerink
left a comment
There was a problem hiding this comment.
Oh wow. Yea, you are totally right. That was missed during the research for the docs. Its the only "_HASH" map type in eBPF that forces a 4 byte key, nuts.
Seems like the kernel contribution specifically focused on making a sparse ifindex -> dev mapping and not about allowing arbitrary keys:
A common pattern when using xdp_redirect_map() is to create a device map
where the lookup key is simply ifindex. Because device maps are arrays,
this leaves holes in the map, and the map has to be sized to fit the
largest ifindex, regardless of how many devices actually are actually
needed in the map.This patch adds a second type of device map where the key is looked up
using a hashmap, instead of being used as an array index. This allows maps
to be densely packed, so they can be smaller.
Thank you for fixing the docs 🙏
Hi,
Following this documentation, that was stating that the key_size for BPF_MAP_TYPE_DEVMAP_HASH could be freely chosen (ref) I've been trying to create a map of this kind with a key size of 8, always getting an EINVAL error.
After some debugging, I've found that the mainline kernel enforces a key_size of 4 for any kind of devmap, regardless of whether is a devmap or a devmap_hash (ref), which contradicts the current docs. This PR does that fix by explicitly stating that a devmap_hash must have a key size of 4.
I'm not an experienced eBPF developer, but after doing some debugging and some testing changing the values of key_size for my map, I couldn't find any other conclusion except that the docs were incorrect in this regard. Any feedback is appreciated.
I'm also leaving here the the eBPF program whose map I was unable to create, for reference: