Skip to content
  • Toke Høiland-Jørgensen's avatar
    bpf_xdp_redirect_map: Perform map lookup in eBPF helper · 43e74c02
    Toke Høiland-Jørgensen authored
    
    
    The bpf_redirect_map() helper used by XDP programs doesn't return any
    indication of whether it can successfully redirect to the map index it was
    given. Instead, BPF programs have to track this themselves, leading to
    programs using duplicate maps to track which entries are populated in the
    devmap.
    
    This patch fixes this by moving the map lookup into the bpf_redirect_map()
    helper, which makes it possible to return failure to the eBPF program. The
    lower bits of the flags argument is used as the return code, which means
    that existing users who pass a '0' flag argument will get XDP_ABORTED.
    
    With this, a BPF program can check the return code from the helper call and
    react by, for instance, substituting a different redirect. This works for
    any type of map used for redirect.
    
    Signed-off-by: default avatarToke Høiland-Jørgensen <toke@redhat.com>
    Acked-by: default avatarJonathan Lemon <jonathan.lemon@gmail.com>
    Acked-by: default avatarAndrii Nakryiko <andriin@fb.com>
    Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
    43e74c02