def validate_nla(nla, maxtype, policy):
minlen = <NUM_LIT:0><EOL>type_ = nla_type(nla)<EOL>if type_ < <NUM_LIT:0> or type_ > maxtype:<EOL><INDENT>return <NUM_LIT:0><EOL><DEDENT>pt = policy[type_]<EOL>if pt.type_ > NLA_TYPE_MAX:<EOL><INDENT>raise BUG<EOL><DEDENT>if pt.minlen:<EOL><INDENT>minlen = pt.minlen<EOL><DEDENT>elif pt.type_ != NLA_UNSPEC:<EOL><INDENT>minlen = nla_attr_minlen[pt.type_]<EOL><DEDENT>if nla_len(nla) < minlen:<EOL><INDENT>return -NLE_RANGE<EOL><DEDENT>if pt.maxlen and nla_len(nla) > pt.maxlen:<EOL><INDENT>return -NLE_RANGE<EOL><DEDENT>if pt.type_ == NLA_STRING:<EOL><INDENT>data = nla_data(nla)<EOL>if data[nla_len(nla) - <NUM_LIT:1>] != <NUM_LIT:0>:<EOL><INDENT>return -NLE_INVAL<EOL><DEDENT><DEDENT>return <NUM_LIT:0><EOL>
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.