def validate_nla(nla, maxtype, policy):
    """https://github.com/thom311/libnl/blob/libnl3_2_25/lib/attr.c#L188.

    Positional arguments:
    nla -- nlattr class instance.
    maxtype -- integer.
    policy -- dictionary of nla_policy class instances as values, with nla types as keys.

    Returns:
    0 on success or a negative error code.
    """
    minlen = 0
    type_ = nla_type(nla)
    if type_ < 0 or type_ > maxtype:
        return 0

    pt = policy[type_]
    if pt.type_ > NLA_TYPE_MAX:
        raise BUG

    if pt.minlen:
        minlen = pt.minlen
    elif pt.type_ != NLA_UNSPEC:
        minlen = nla_attr_minlen[pt.type_]

    if nla_len(nla) < minlen:
        return -NLE_RANGE

    if pt.maxlen and nla_len(nla) > pt.maxlen:
        return -NLE_RANGE

    if pt.type_ == NLA_STRING:
        data = nla_data(nla)
        if data[nla_len(nla) - 1] != 0:
            return -NLE_INVAL

    return 0
https://github.com/thom311/libnl/blob/libnl3_2_25/lib/attr.c#L188.

    Positional arguments:
    nla -- nlattr class instance.
    maxtype -- integer.
    policy -- dictionary of nla_policy class instances as values, with nla types as keys.

    Returns:
    0 on success or a negative error code.