/* Create attribute index based on a stream of attributes.  */
int nla_parse(struct nlattr *tb[], int maxtype, struct nlattr *head, int len, struct nla_policy *policy)
/* Create attribute index based on a stream of attributes.  */
int nla_parse(struct nlattr *tb[], int maxtype, struct nlattr *head, int len, struct nla_policy *policy)
{
	struct nlattr *nla;
	int rem, err;
	memset(tb, 0, sizeof(struct nlattr *) * (maxtype + 1));
	nla_for_each_attr(nla, head, len, rem) {
		int type = nla_type(nla);
		if (type == 0) {
			fprintf(stderr, "Illegal nla->nla_type == 0\n");
			continue;
		}
		if (type <= maxtype) {
			if (policy) {
				err = validate_nla(nla, maxtype, policy);
				if (err < 0)
					goto errout;
			}
			tb[type] = nla;
		}
	}
	if (rem > 0)
		fprintf(stderr, "netlink: %d bytes leftover after parsing "
		       "attributes.\n", rem);
	err = 0;
errout:
	return err;
}