aboutsummaryrefslogtreecommitdiff
path: root/sys/netinet/ip_carp.c
diff options
context:
space:
mode:
authorGleb Smirnoff <glebius@FreeBSD.org>2014-02-22 19:20:40 +0000
committerGleb Smirnoff <glebius@FreeBSD.org>2014-02-22 19:20:40 +0000
commit4a2dd8d4fb595dff1ecc6af90e3794dde111368d (patch)
tree132919f241c3aafb9642cd2249cb2b4605ceb44d /sys/netinet/ip_carp.c
parentd000dd2f8692c5b60121091d1252e8a677c926c3 (diff)
downloadsrc-4a2dd8d4fb595dff1ecc6af90e3794dde111368d.tar.gz
src-4a2dd8d4fb595dff1ecc6af90e3794dde111368d.zip
Improve logging of send errors, reporting error code and interface.
Reduce code duplication between INET and INET6. Tested by: Lytochkin Boris <lytboris gmail.com>
Notes
Notes: svn path=/head/; revision=262341
Diffstat (limited to 'sys/netinet/ip_carp.c')
-rw-r--r--sys/netinet/ip_carp.c71
1 files changed, 33 insertions, 38 deletions
diff --git a/sys/netinet/ip_carp.c b/sys/netinet/ip_carp.c
index b6931a0a1235..c6499bce85bf 100644
--- a/sys/netinet/ip_carp.c
+++ b/sys/netinet/ip_carp.c
@@ -764,6 +764,35 @@ carp_send_ad(void *v)
}
static void
+carp_send_ad_error(struct carp_softc *sc, int error)
+{
+
+ if (error) {
+ if (sc->sc_sendad_errors < INT_MAX)
+ sc->sc_sendad_errors++;
+ if (sc->sc_sendad_errors == CARP_SENDAD_MAX_ERRORS) {
+ static const char fmt[] = "send error %d on %s";
+ char msg[sizeof(fmt) + IFNAMSIZ];
+
+ sprintf(msg, fmt, error, sc->sc_carpdev->if_xname);
+ 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
+ sc->sc_sendad_errors = 0;
+ }
+}
+
+static void
carp_send_ad_locked(struct carp_softc *sc)
{
struct carp_header ch;
@@ -839,25 +868,8 @@ carp_send_ad_locked(struct carp_softc *sc)
CARPSTATS_INC(carps_opackets);
- if (ip_output(m, NULL, NULL, IP_RAWOUTPUT,
- &sc->sc_carpdev->if_carp->cif_imo, NULL)) {
- if (sc->sc_sendad_errors < INT_MAX)
- sc->sc_sendad_errors++;
- if (sc->sc_sendad_errors == CARP_SENDAD_MAX_ERRORS)
- carp_demote_adj(V_carp_senderr_adj,
- "send error");
- sc->sc_sendad_success = 0;
- } else {
- if (sc->sc_sendad_errors >= CARP_SENDAD_MAX_ERRORS) {
- if (++sc->sc_sendad_success >=
- CARP_SENDAD_MIN_SUCCESS) {
- carp_demote_adj(-V_carp_senderr_adj,
- "send ok");
- sc->sc_sendad_errors = 0;
- }
- } else
- sc->sc_sendad_errors = 0;
- }
+ carp_send_ad_error(sc, ip_output(m, NULL, NULL, IP_RAWOUTPUT,
+ &sc->sc_carpdev->if_carp->cif_imo, NULL));
}
#endif /* INET */
#ifdef INET6
@@ -913,25 +925,8 @@ carp_send_ad_locked(struct carp_softc *sc)
CARPSTATS_INC(carps_opackets6);
- if (ip6_output(m, NULL, NULL, 0,
- &sc->sc_carpdev->if_carp->cif_im6o, NULL, NULL)) {
- if (sc->sc_sendad_errors < INT_MAX)
- sc->sc_sendad_errors++;
- if (sc->sc_sendad_errors == CARP_SENDAD_MAX_ERRORS)
- carp_demote_adj(V_carp_senderr_adj,
- "send6 error");
- sc->sc_sendad_success = 0;
- } else {
- if (sc->sc_sendad_errors >= CARP_SENDAD_MAX_ERRORS) {
- if (++sc->sc_sendad_success >=
- CARP_SENDAD_MIN_SUCCESS) {
- carp_demote_adj(-V_carp_senderr_adj,
- "send6 ok");
- sc->sc_sendad_errors = 0;
- }
- } else
- sc->sc_sendad_errors = 0;
- }
+ carp_send_ad_error(sc, ip6_output(m, NULL, NULL, 0,
+ &sc->sc_carpdev->if_carp->cif_im6o, NULL, NULL));
}
#endif /* INET6 */