import struct


def unpack_attr(data):
    """Unpack an RTA in a netlink message

    RTAs are TLV attributes with body format dependent on attr.

    Returns attr type, value, rest of message.
    """
    rta_len, rta_type = struct.unpack("=HH", data[:4])
    rta_len = rta_len - 4  # the header
    data = data[4:]

    attr_body = data[:rta_len]
    data = data[rta_len:]

    return rta_type, attr_body, data