Skip to content

Commit

Permalink
carp: fix send error demotion recovery
Browse files Browse the repository at this point in the history
The problem is that carp(4) would clear the error counter on first
successful send, and stop counting successes after that.  Fix this
logic and document it in human language.

PR:			260499
Differential revision:	https://reviews.freebsd.org/D33536

(cherry picked from commit 9a8cf95)
  • Loading branch information
glebius committed Jan 21, 2022
1 parent d7b1566 commit f7735c3
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions sys/netinet/ip_carp.c
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,13 @@ static void
carp_send_ad_error(struct carp_softc *sc, int error)
{

/*
* We track errors and successfull sends with this logic:
* - Any error resets success counter to 0.
* - MAX_ERRORS triggers demotion.
* - MIN_SUCCESS successes resets error counter to 0.
* - MIN_SUCCESS reverts demotion, if it was triggered before.
*/
if (error) {
if (sc->sc_sendad_errors < INT_MAX)
sc->sc_sendad_errors++;
Expand All @@ -865,17 +872,17 @@ carp_send_ad_error(struct carp_softc *sc, int error)
carp_demote_adj(V_carp_senderr_adj, msg);
}
sc->sc_sendad_success = 0;
} else {
if (sc->sc_sendad_errors >= CARP_SENDAD_MAX_ERRORS &&
++sc->sc_sendad_success >= CARP_SENDAD_MIN_SUCCESS) {
static const char fmt[] = "send ok on %s";
char msg[sizeof(fmt) + IFNAMSIZ];

sprintf(msg, fmt, sc->sc_carpdev->if_xname);
carp_demote_adj(-V_carp_senderr_adj, msg);
sc->sc_sendad_errors = 0;
} else
} else if (sc->sc_sendad_errors > 0) {
if (++sc->sc_sendad_success >= CARP_SENDAD_MIN_SUCCESS) {
if (sc->sc_sendad_errors >= CARP_SENDAD_MAX_ERRORS) {
static const char fmt[] = "send ok on %s";
char msg[sizeof(fmt) + IFNAMSIZ];

sprintf(msg, fmt, sc->sc_carpdev->if_xname);
carp_demote_adj(-V_carp_senderr_adj, msg);
}
sc->sc_sendad_errors = 0;
}
}
}

Expand Down

0 comments on commit f7735c3

Please sign in to comment.