Example #1
0
int
pptpd_assign_call(pptpd *_this, pptp_call *call)
{
	int shuffle_cnt = 0, call_id;

	shuffle_cnt = 0;
	slist_itr_first(&_this->call_free_list);
	while (slist_length(&_this->call_free_list) > 1 &&
	    slist_itr_has_next(&_this->call_free_list)) {
		call_id = (int)slist_itr_next(&_this->call_free_list);
		if (call_id == 0)
			break;
		slist_itr_remove(&_this->call_free_list);
		if (call_id == PPTPD_SHUFFLE_MARK) {
			if (shuffle_cnt++ > 0)
				break;
			slist_shuffle(&_this->call_free_list);
			slist_add(&_this->call_free_list,
			    (void *)PPTPD_SHUFFLE_MARK);
			slist_itr_first(&_this->call_free_list);
			continue;
		}
		call->id = call_id;
		hash_insert(_this->call_id_map, CALL_MAP_KEY(call), call);

		return 0;
	}
	errno = EBUSY;
	pptpd_log(_this, LOG_ERR, "call request reached limit=%d",
	    PPTP_MAX_CALL);
	return -1;
}
Example #2
0
/** assign the call to the l2tpd */
int
l2tpd_assign_call(l2tpd *_this, l2tp_call *call)
{
	int    shuffle_cnt;
	u_int  session_id;

	shuffle_cnt = 0;
	do {
		session_id = (uintptr_t)slist_remove_first(
		    &_this->free_session_id_list);
		if (session_id != L2TP_SESSION_ID_SHUFFLE_MARK)
			break;
		L2TPD_ASSERT(shuffle_cnt == 0);
		if (shuffle_cnt++ > 0) {
			l2tpd_log(_this, LOG_ERR,
			    "unexpected errror in %s(): free_session_id_list "
			    "full", __func__);
			slist_add(&_this->free_session_id_list,
			    (void *)L2TP_SESSION_ID_SHUFFLE_MARK);
			return 1;
		}
		slist_shuffle(&_this->free_session_id_list);
		slist_add(&_this->free_session_id_list,
		    (void *)L2TP_SESSION_ID_SHUFFLE_MARK);
	} while (1);
	call->id = session_id;

	return 0;
}