def nlmsg_append(n, data, len_, pad):
    """Append data to tail of a Netlink message.

    https://github.com/thom311/libnl/blob/libnl3_2_25/lib/msg.c#L442

    Extends the Netlink message as needed and appends the data of given length to the message.

    Positional arguments:
    n -- Netlink message (nl_msg class instance).
    data -- data to add.
    len_ -- length of data (integer).
    pad -- number of bytes to align data to (integer).

    Returns:
    0 on success or a negative error code.
    """
    tmp = nlmsg_reserve(n, len_, pad)
    if tmp is None:
        return -NLE_NOMEM
    tmp[:len_] = data.bytearray[:len_]
    _LOGGER.debug('msg 0x%x: Appended %d bytes with padding %d', id(n), len_, pad)
    return 0