FreeBSD/sys/netinet/ip_carp.c
/*
 * When in backup state, af indicates whether to reset the master down timer
 * for v4 or v6. If it's set to zero, reset the ones which are already pending.
 */
When in backup state, af indicates whether to reset the master down timer
for v4 or v6. If it's set to zero, reset the ones which are already pending.
When in backup state af indicates whether to reset the master down timer for v4 or v6 . If it ' s set to zero reset the ones which are already pending .
static void
carp_setrun(struct carp_softc *sc, sa_family_t af)
{
	struct timeval tv;
	CARP_LOCK_ASSERT(sc);
	if ((sc->sc_carpdev->if_flags & IFF_UP) == 0 ||
	    sc->sc_carpdev->if_link_state != LINK_STATE_UP ||
	    (sc->sc_naddrs == 0 && sc->sc_naddrs6 == 0))
		return;
	switch (sc->sc_state) {
	case INIT:
		carp_set_state(sc, BACKUP, "initialization complete");
		carp_setrun(sc, 0);
		break;
	case BACKUP:
		callout_stop(&sc->sc_ad_tmo);
		tv.tv_sec = 3 * sc->sc_advbase;
		tv.tv_usec = sc->sc_advskew * 1000000 / 256;
		switch (af) {
#ifdef INET
		case AF_INET:
			callout_reset(&sc->sc_md_tmo, tvtohz(&tv),
			    carp_master_down, sc);
			break;
#endif
#ifdef INET6
		case AF_INET6:
			callout_reset(&sc->sc_md6_tmo, tvtohz(&tv),
			    carp_master_down, sc);
			break;
#endif
		default:
#ifdef INET
			if (sc->sc_naddrs)
				callout_reset(&sc->sc_md_tmo, tvtohz(&tv),
				    carp_master_down, sc);
#endif
#ifdef INET6
			if (sc->sc_naddrs6)
				callout_reset(&sc->sc_md6_tmo, tvtohz(&tv),
				    carp_master_down, sc);
#endif
			break;
		}
		break;
	case MASTER:
		tv.tv_sec = sc->sc_advbase;
		tv.tv_usec = sc->sc_advskew * 1000000 / 256;
		callout_reset(&sc->sc_ad_tmo, tvtohz(&tv),
		    carp_send_ad, sc);
		break;
	}
}
static void carp_setrun ( struct carp_softc * sc , sa_family_t af ) { struct timeval tv ; CARP_LOCK_ASSERT ( sc ) ; if ( ( sc -> sc_carpdev -> if_flags & IFF_UP ) == 0 || sc -> sc_carpdev -> if_link_state != LINK_STATE_UP || ( sc -> sc_naddrs == 0 && sc -> sc_naddrs6 == 0 ) ) return ; switch ( sc -> sc_state ) { case INIT : carp_set_state ( sc , BACKUP , " " ) ; carp_setrun ( sc , 0 ) ; break ; case BACKUP : callout_stop ( & sc -> sc_ad_tmo ) ; tv . tv_sec = 3 * sc -> sc_advbase ; tv . tv_usec = sc -> sc_advskew * 1000000 / 256 ; switch ( af ) { #ifdef INET case AF_INET : callout_reset ( & sc -> sc_md_tmo , tvtohz ( & tv ) , carp_master_down , sc ) ; break ; #endif #ifdef INET6 case AF_INET6 : callout_reset ( & sc -> sc_md6_tmo , tvtohz ( & tv ) , carp_master_down , sc ) ; break ; #endif default : #ifdef INET if ( sc -> sc_naddrs ) callout_reset ( & sc -> sc_md_tmo , tvtohz ( & tv ) , carp_master_down , sc ) ; #endif #ifdef INET6 if ( sc -> sc_naddrs6 ) callout_reset ( & sc -> sc_md6_tmo , tvtohz ( & tv ) , carp_master_down , sc ) ; #endif break ; } break ; case MASTER : tv . tv_sec = sc -> sc_advbase ; tv . tv_usec = sc -> sc_advskew * 1000000 / 256 ; callout_reset ( & sc -> sc_ad_tmo , tvtohz ( & tv ) , carp_send_ad , sc ) ; break ; } }
When in backup state, af indicates whether to reset the master down timer
 for v4 or v6.
When in backup state af indicates whether to reset the master down timer for v4 or v6 .