int l2tp_packet_add_string(struct l2tp_packet_t *pack, int id, const char *val, int M)
{
	struct l2tp_attr_t *attr = attr_alloc(id, M, pack->hide_avps);
	size_t val_len = strlen(val);

	if (!attr)
		return -1;

	if (attr->H) {
		if (pack->last_RV == NULL)
			if (l2tp_packet_add_random_vector(pack) < 0)
				goto err;
		if (encode_attr(pack, attr, val, val_len) < 0)
			goto err;
	} else {
		attr->length = val_len;
		attr->val.string = _strdup(val);
		if (!attr->val.string) {
			log_emerg("l2tp: out of memory\n");
			goto err;
		}
	}
	list_add_tail(&attr->entry, &pack->attrs);

	return 0;

err:
	mempool_free(attr);
	return -1;
}
int l2tp_packet_add_string(struct l2tp_packet_t *pack, int id, const char *val, int M)
{
	struct l2tp_attr_t *attr = attr_alloc(id, M, pack->hide_avps);
	size_t val_len = strlen(val);

	if (!attr)
		return -1;

	if (attr->H) {
		if (pack->last_RV == NULL)
			if (l2tp_packet_add_random_vector(pack) < 0)
				goto err;
		if (encode_attr(pack, attr, val, val_len) < 0)
			goto err;
	} else {
		attr->length = val_len;
		attr->val.string = _strdup(val);
		if (!attr->val.string) {
			log_emerg("l2tp: out of memory\n");
			goto err;
		}
	}
	list_add_tail(&attr->entry, &pack->attrs);

	return 0;

err:
	mempool_free(attr);
	return -1;
}