/* 0 or more than 0 is returned when validation is succeeded (either bypass because of optional transport mode, or next index of the mathced secpath state with the template. -1 is returned when no matching template is found. Otherwise "-2 - errored_index" is returned.  */
static int xfrm_policy_ok(struct xfrm_tmpl *tmpl, struct sec_path *sp, int start, unsigned short family)
/* 0 or more than 0 is returned when validation is succeeded (either bypass because of optional transport mode, or next index of the mathced secpath state with the template. -1 is returned when no matching template is found. Otherwise "-2 - errored_index" is returned.  */
static int xfrm_policy_ok(struct xfrm_tmpl *tmpl, struct sec_path *sp, int start, unsigned short family)
{
	int idx = start;
	if (tmpl->optional) {
		if (tmpl->mode == XFRM_MODE_TRANSPORT)
			return start;
	} else
		start = -1;
	for (; idx < sp->len; idx++) {
		if (xfrm_state_ok(tmpl, sp->xvec[idx], family))
			return ++idx;
		if (sp->xvec[idx]->props.mode != XFRM_MODE_TRANSPORT) {
			if (start == -1)
				start = -2-idx;
			break;
		}
	}
	return start;
}