• Yonghong Song's avatar
    tools/bpf: fix a netlink recv issue · 9d0b3c1f
    Yonghong Song authored
    Commit f7010770 ("tools/bpf: move bpf/lib netlink related
    functions into a new file") introduced a while loop for the
    netlink recv path. This while loop is needed since the
    buffer in recv syscall may not be enough to hold all the
    information and in such cases multiple recv calls are needed.
    
    There is a bug introduced by the above commit as
    the while loop may block on recv syscall if there is no
    more messages are expected. The netlink message header
    flag NLM_F_MULTI is used to indicate that more messages
    are expected and this patch fixed the bug by doing
    further recv syscall only if multipart message is expected.
    
    The patch added another fix regarding to message length of 0.
    When netlink recv returns message length of 0, there will be
    no more messages for returning data so the while loop
    can end.
    
    Fixes: f7010770 ("tools/bpf: move bpf/lib netlink related functions into a new file")
    Reported-by: default avatarBjörn Töpel <bjorn.topel@intel.com>
    Tested-by: default avatarBjörn Töpel <bjorn.topel@intel.com>
    Signed-off-by: default avatarYonghong Song <yhs@fb.com>
    Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
    9d0b3c1f
netlink.c 7.76 KB