def nl_list_for_each_entry_safe(pos, n, head, member):
    """https://github.com/thom311/libnl/blob/libnl3_2_25/include/netlink/list.h#L84.

    Positional arguments:
    pos -- class instance holding an nl_list_head instance.
    n -- class instance holding an nl_list_head instance.
    head -- nl_list_head class instance.
    member -- attribute (string).

    Returns:
    Generator yielding a class instances.
    """
    pos = nl_list_entry(head.next_, type(pos), member)
    n = nl_list_entry(pos.member.next_, type(pos), member)
    while True:
        yield pos
        if getattr(pos, member) != head:
            pos = n
            n = nl_list_entry(n.member.next_, type(n), member)
            continue
        break