Beispiel #1
0
/* Compute the new instance sands */
void
vrrp_init_instance_sands(vrrp_t * vrrp)
{
	set_time_now();

	if (vrrp->state == VRRP_STATE_MAST	  ||
	    vrrp->state == VRRP_STATE_GOTO_MASTER ||
	    vrrp->state == VRRP_STATE_GOTO_FAULT  ||
	    vrrp->wantstate == VRRP_STATE_GOTO_MASTER) {
// TIMER  - GOTO_MASTER shouldn't be adver_int. Look at circumstances to set GOTO_MASTER
// i) backup and expire timer
// ii) backup and receive prio 0
// iii) master and receive higher prio advert
		vrrp->sands = timer_add_long(time_now, vrrp->adver_int);
		return;
	}

	/*
	 * When in the BACKUP state the expiry timer should be updated to
	 * time_now plus the Master Down Timer, when a non-preemptable packet is
	 * received. (When a preemptable packet is received, the wantstate is
	 * moved to GOTO_MASTER and this condition is caught above).
	 */
	if (vrrp->state == VRRP_STATE_BACK || vrrp->state == VRRP_STATE_FAULT)
		vrrp->sands = timer_add_long(time_now, vrrp->ms_down_timer);
}
Beispiel #2
0
/* This function is a wrapper for gettimeofday(). It uses local storage to
 * guarantee that the returned time will always be monotonic. If the time goes
 * backwards, it returns the same as previous one and readjust its internal
 * drift. If the time goes forward further than TIME_MAX_FORWARD_US
 * microseconds since last call, it will bound it to that value. It is designed
 * to be used as a drop-in replacement of gettimeofday(&now, NULL). It will
 * normally return 0, unless <now> is NULL, in which case it will return -1 and
 * set errno to EFAULT.
 */
static int
monotonic_gettimeofday(timeval_t *now)
{
	static timeval_t mono_date;
	static timeval_t drift; /* warning: signed seconds! */
	timeval_t sys_date, adjusted, deadline;

	if (!now) {
		errno = EFAULT;
		return -1;
	}

	timer_reset_lazy(*now);

	gettimeofday(&sys_date, NULL);

	/* on first call, we set mono_date to system date */
	if (mono_date.tv_sec == 0) {
		mono_date = sys_date;
		timer_reset(drift);
		*now = mono_date;
		return 0;
	}

	/* compute new adjusted time by adding the drift offset */
	adjusted = timer_add(sys_date, drift);

	/* check for jumps in the past, and bound to last date */
	if (timer_cmp(adjusted, mono_date) < 0)
		goto fixup;

	/* check for jumps too far in the future, and bound them to
	 * TIME_MAX_FORWARD_US microseconds.
	 */
	deadline = timer_add_long(mono_date, TIME_MAX_FORWARD_US);
	if (timer_cmp (adjusted, deadline) >= 0) {
		mono_date = deadline;
		goto fixup;
	}

	/* adjusted date is correct */
	mono_date = adjusted;
	*now = mono_date;
	return 0;

 fixup:
	/* Now we have to recompute the drift between sys_date and
	 * mono_date. Since it can be negative and we don't want to
	 * play with negative carries in all computations, we take
	 * care of always having the microseconds positive.
	 */
	drift = timer_sub(mono_date, sys_date);
	*now = mono_date;
	return 0;
}
Beispiel #3
0
static void
vrrp_preempt_delay_handler(vector_t *strvec)
{
	vrrp_t *vrrp = LIST_TAIL_DATA(vrrp_data->vrrp);
	vrrp->preempt_delay = atoi(vector_slot(strvec, 1));

	if (VRRP_IS_BAD_PREEMPT_DELAY(vrrp->preempt_delay)) {
		log_message(LOG_INFO, "(%s): Preempt_delay not valid! must be between 0-%d", vrrp->iname, TIMER_MAX_SEC);
		vrrp->preempt_delay = 0;
	}
	vrrp->preempt_delay *= TIMER_HZ;
	vrrp->preempt_time = timer_add_long(timer_now(), vrrp->preempt_delay);
}
Beispiel #4
0
/* Compute the new instance sands */
void
vrrp_init_instance_sands(vrrp_t * vrrp)
{
	set_time_now();

	if (vrrp->state == VRRP_STATE_MAST	  ||
	    vrrp->state == VRRP_STATE_GOTO_MASTER ||
	    vrrp->state == VRRP_STATE_GOTO_FAULT  ||
	    vrrp->wantstate == VRRP_STATE_GOTO_MASTER) {
		vrrp->sands = timer_add_long(time_now, vrrp->adver_int);
		return;
	}

	/*
	 * When in the BACKUP state the expiry timer should be updated to
	 * time_now plus the Master Down Timer, when a non-preemptable packet is
	 * received. (When a preemptable packet is received, the wantstate is
	 * moved to GOTO_MASTER and this condition is caught above).
	 */
	if (vrrp->state == VRRP_STATE_BACK || vrrp->state == VRRP_STATE_FAULT)
		vrrp->sands = timer_add_long(time_now, vrrp->ms_down_timer);
}
static void
vrrp_preempt_delay_handler(vector strvec)
{
	vrrp_rt *vrrp = LIST_TAIL_DATA(vrrp_data->vrrp);
	vrrp->preempt_delay = atoi(VECTOR_SLOT(strvec, 1));

	if (VRRP_IS_BAD_PREEMPT_DELAY(vrrp->preempt_delay)) {
		log_message(LOG_INFO, "VRRP Error : Preempt_delay not valid !\n");
		log_message(LOG_INFO, "             must be between 0-%d\n",
		       TIMER_MAX_SEC);
		vrrp->preempt_delay = 0;
	}
	vrrp->preempt_delay *= TIMER_HZ;
	vrrp->preempt_time = timer_add_long(timer_now(), vrrp->preempt_delay);
}
Beispiel #6
0
/* Compute the new instance sands */
void
vrrp_init_instance_sands(vrrp_rt * vrrp)
{
	set_time_now();

	if (vrrp->state == VRRP_STATE_MAST	  ||
	    vrrp->state == VRRP_STATE_GOTO_MASTER ||
	    vrrp->state == VRRP_STATE_GOTO_FAULT  ||
	    vrrp->wantstate == VRRP_STATE_GOTO_MASTER) {
		vrrp->sands.tv_sec = time_now.tv_sec + vrrp->adver_int / TIMER_HZ;
 		vrrp->sands.tv_usec = time_now.tv_usec;
		return;
	}

	if (vrrp->state == VRRP_STATE_BACK || vrrp->state == VRRP_STATE_FAULT)
		vrrp->sands = timer_add_long(time_now, vrrp->ms_down_timer);
}