title | description |
---|---|
Map Type 'BPF_MAP_TYPE_DEVMAP_HASH' |
This page documents the 'BPF_MAP_TYPE_DEVMAP_HASH' eBPF map type, including its defintion, usage, program types that can use it, and examples. |
The device hash map is a specialized map type which holds references to network devices.
This map type is used in combination with the bpf_redirect_map helper to redirect traffic to egress out of a different device.
Initially the value of this map was just the network interface index as __u32
. But after :octicons-tag-24: v5.8 the value has been optionally extended to add a file descriptor to a secondary XDP program.
The C structure of the values look as follows:
struct bpf_devmap_val {
__u32 ifindex; /* device index */
union {
int fd; /* prog fd on map write */
__u32 id; /* prog id on map read */
} bpf_prog;
};
The fd
/id
refers to an XDP program optionally set by userspace. If set, the referred XDP program will execute on the packet, in the context of the new network device after the packet has been redirected but before it egresses the network interface.
!!! note
Programs attached to a devmap must be loaded with the BPF_XDP_DEVMAP
expected attach type.
The value_size
can be 4
or 8
depending on kernel version and optional secondary program support. The key_size
can be freely chosen.
The following syscall commands work with this map type:
When set, the numa_node
attribute is respected during map creation.
Setting this flag will make it so the map can only be read via the syscall interface, but not written to.
For details please check the generic description.
Setting this flag will make it so the map can only be written to via the syscall interface, but not read from.