Changeset View
Changeset View
Standalone View
Standalone View
sys/netinet/ip_carp.c
Show First 20 Lines • Show All 206 Lines • ▼ Show 20 Lines | |||||
/* Send error demotion factor. */ | /* Send error demotion factor. */ | ||||
static VNET_DEFINE(int, carp_senderr_adj) = CARP_MAXSKEW; | static VNET_DEFINE(int, carp_senderr_adj) = CARP_MAXSKEW; | ||||
#define V_carp_senderr_adj VNET(carp_senderr_adj) | #define V_carp_senderr_adj VNET(carp_senderr_adj) | ||||
/* Iface down demotion factor. */ | /* Iface down demotion factor. */ | ||||
static VNET_DEFINE(int, carp_ifdown_adj) = CARP_MAXSKEW; | static VNET_DEFINE(int, carp_ifdown_adj) = CARP_MAXSKEW; | ||||
#define V_carp_ifdown_adj VNET(carp_ifdown_adj) | #define V_carp_ifdown_adj VNET(carp_ifdown_adj) | ||||
static int carp_allow_sysctl(SYSCTL_HANDLER_ARGS); | |||||
static int carp_demote_adj_sysctl(SYSCTL_HANDLER_ARGS); | static int carp_demote_adj_sysctl(SYSCTL_HANDLER_ARGS); | ||||
SYSCTL_NODE(_net_inet, IPPROTO_CARP, carp, CTLFLAG_RW, 0, "CARP"); | SYSCTL_NODE(_net_inet, IPPROTO_CARP, carp, CTLFLAG_RW, 0, "CARP"); | ||||
SYSCTL_INT(_net_inet_carp, OID_AUTO, allow, CTLFLAG_VNET | CTLFLAG_RW, | SYSCTL_PROC(_net_inet_carp, OID_AUTO, allow, | ||||
&VNET_NAME(carp_allow), 0, "Accept incoming CARP packets"); | CTLFLAG_VNET | CTLTYPE_INT | CTLFLAG_RW, 0, 0, carp_allow_sysctl, "I", | ||||
"Accept incoming CARP packets"); | |||||
SYSCTL_INT(_net_inet_carp, OID_AUTO, preempt, CTLFLAG_VNET | CTLFLAG_RW, | SYSCTL_INT(_net_inet_carp, OID_AUTO, preempt, CTLFLAG_VNET | CTLFLAG_RW, | ||||
&VNET_NAME(carp_preempt), 0, "High-priority backup preemption mode"); | &VNET_NAME(carp_preempt), 0, "High-priority backup preemption mode"); | ||||
SYSCTL_INT(_net_inet_carp, OID_AUTO, log, CTLFLAG_VNET | CTLFLAG_RW, | SYSCTL_INT(_net_inet_carp, OID_AUTO, log, CTLFLAG_VNET | CTLFLAG_RW, | ||||
&VNET_NAME(carp_log), 0, "CARP log level"); | &VNET_NAME(carp_log), 0, "CARP log level"); | ||||
SYSCTL_PROC(_net_inet_carp, OID_AUTO, demotion, | SYSCTL_PROC(_net_inet_carp, OID_AUTO, demotion, | ||||
CTLFLAG_VNET | CTLTYPE_INT | CTLFLAG_RW, | CTLFLAG_VNET | CTLTYPE_INT | CTLFLAG_RW, | ||||
0, 0, carp_demote_adj_sysctl, "I", | 0, 0, carp_demote_adj_sysctl, "I", | ||||
"Adjust demotion factor (skew of advskew)"); | "Adjust demotion factor (skew of advskew)"); | ||||
▲ Show 20 Lines • Show All 1,060 Lines • ▼ Show 20 Lines | |||||
carp_setrun(struct carp_softc *sc, sa_family_t af) | carp_setrun(struct carp_softc *sc, sa_family_t af) | ||||
{ | { | ||||
struct timeval tv; | struct timeval tv; | ||||
CARP_LOCK_ASSERT(sc); | CARP_LOCK_ASSERT(sc); | ||||
if ((sc->sc_carpdev->if_flags & IFF_UP) == 0 || | if ((sc->sc_carpdev->if_flags & IFF_UP) == 0 || | ||||
sc->sc_carpdev->if_link_state != LINK_STATE_UP || | sc->sc_carpdev->if_link_state != LINK_STATE_UP || | ||||
(sc->sc_naddrs == 0 && sc->sc_naddrs6 == 0)) | (sc->sc_naddrs == 0 && sc->sc_naddrs6 == 0) || | ||||
!V_carp_allow) | |||||
return; | return; | ||||
switch (sc->sc_state) { | switch (sc->sc_state) { | ||||
case INIT: | case INIT: | ||||
carp_set_state(sc, BACKUP, "initialization complete"); | carp_set_state(sc, BACKUP, "initialization complete"); | ||||
carp_setrun(sc, 0); | carp_setrun(sc, 0); | ||||
break; | break; | ||||
case BACKUP: | case BACKUP: | ||||
▲ Show 20 Lines • Show All 756 Lines • ▼ Show 20 Lines | |||||
static void | static void | ||||
carp_sc_state(struct carp_softc *sc) | carp_sc_state(struct carp_softc *sc) | ||||
{ | { | ||||
CARP_LOCK_ASSERT(sc); | CARP_LOCK_ASSERT(sc); | ||||
if (sc->sc_carpdev->if_link_state != LINK_STATE_UP || | if (sc->sc_carpdev->if_link_state != LINK_STATE_UP || | ||||
!(sc->sc_carpdev->if_flags & IFF_UP)) { | !(sc->sc_carpdev->if_flags & IFF_UP) || | ||||
!V_carp_allow) { | |||||
callout_stop(&sc->sc_ad_tmo); | callout_stop(&sc->sc_ad_tmo); | ||||
#ifdef INET | #ifdef INET | ||||
callout_stop(&sc->sc_md_tmo); | callout_stop(&sc->sc_md_tmo); | ||||
#endif | #endif | ||||
#ifdef INET6 | #ifdef INET6 | ||||
callout_stop(&sc->sc_md6_tmo); | callout_stop(&sc->sc_md6_tmo); | ||||
#endif | #endif | ||||
carp_set_state(sc, INIT, "hardware interface down"); | carp_set_state(sc, INIT, "hardware interface down"); | ||||
Show All 11 Lines | |||||
} | } | ||||
static void | static void | ||||
carp_demote_adj(int adj, char *reason) | carp_demote_adj(int adj, char *reason) | ||||
{ | { | ||||
atomic_add_int(&V_carp_demotion, adj); | atomic_add_int(&V_carp_demotion, adj); | ||||
CARP_LOG("demoted by %d to %d (%s)\n", adj, V_carp_demotion, reason); | CARP_LOG("demoted by %d to %d (%s)\n", adj, V_carp_demotion, reason); | ||||
taskqueue_enqueue(taskqueue_swi, &carp_sendall_task); | taskqueue_enqueue(taskqueue_swi, &carp_sendall_task); | ||||
} | |||||
static int | |||||
carp_allow_sysctl(SYSCTL_HANDLER_ARGS) | |||||
{ | |||||
int new, error; | |||||
struct carp_softc *sc; | |||||
new = V_carp_allow; | |||||
error = sysctl_handle_int(oidp, &new, 0, req); | |||||
if (error || !req->newptr) | |||||
return (error); | |||||
if(V_carp_allow != new) { | |||||
V_carp_allow = new; | |||||
mtx_lock(&carp_mtx); | |||||
LIST_FOREACH(sc, &carp_list, sc_next) { | |||||
CARP_LOCK(sc); | |||||
if (curvnet == sc->sc_carpdev->if_vnet && (V_carp_allow == 0) != (sc->sc_state == INIT)) | |||||
carp_sc_state(sc); | |||||
CARP_UNLOCK(sc); | |||||
} | |||||
mtx_unlock(&carp_mtx); | |||||
} | |||||
return (0); | |||||
} | } | ||||
static int | static int | ||||
carp_demote_adj_sysctl(SYSCTL_HANDLER_ARGS) | carp_demote_adj_sysctl(SYSCTL_HANDLER_ARGS) | ||||
{ | { | ||||
int new, error; | int new, error; | ||||
new = V_carp_demotion; | new = V_carp_demotion; | ||||
▲ Show 20 Lines • Show All 158 Lines • Show Last 20 Lines |