Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 26 Apr 2019 22:18:22 +0000 (UTC)
From:      Alexander Motin <mav@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r346770 - in stable/11: share/man/man4 sys/netinet
Message-ID:  <201904262218.x3QMIM3r071298@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mav
Date: Fri Apr 26 22:18:22 2019
New Revision: 346770
URL: https://svnweb.freebsd.org/changeset/base/346770

Log:
  MFC r333322: Keep CARP state as INIT when net.inet.carp.allow=0.
  
  Currently when net.inet.carp.allow=0 CARP state remains as MASTER, which is
  not very useful (if there are other masters -- it can lead to split brain,
  if there are none -- it makes no sense).  Having it as INIT makes it clear
  that carp packets are disabled.
  
  Sponsored by:	iXsystems, Inc.

Modified:
  stable/11/share/man/man4/carp.4
  stable/11/sys/netinet/ip_carp.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/share/man/man4/carp.4
==============================================================================
--- stable/11/share/man/man4/carp.4	Fri Apr 26 21:44:51 2019	(r346769)
+++ stable/11/share/man/man4/carp.4	Fri Apr 26 22:18:22 2019	(r346770)
@@ -93,9 +93,11 @@ Additionally, there are a number of global parameters 
 .Xr sysctl 8 :
 .Bl -tag -width ".Va net.inet.carp.ifdown_demotion_factor"
 .It Va net.inet.carp.allow
-Accept incoming
+Allow
 .Nm
-packets.
+operation.
+When disabled, virtual hosts remain in initial state, neither sending nor
+receiving announcements or traffic.
 Enabled by default.
 .It Va net.inet.carp.preempt
 Allow virtual hosts to preempt each other.

Modified: stable/11/sys/netinet/ip_carp.c
==============================================================================
--- stable/11/sys/netinet/ip_carp.c	Fri Apr 26 21:44:51 2019	(r346769)
+++ stable/11/sys/netinet/ip_carp.c	Fri Apr 26 22:18:22 2019	(r346770)
@@ -214,12 +214,14 @@ static VNET_DEFINE(int, carp_senderr_adj) = CARP_MAXSK
 static VNET_DEFINE(int, carp_ifdown_adj) = CARP_MAXSKEW;
 #define	V_carp_ifdown_adj	VNET(carp_ifdown_adj)
 
+static int carp_allow_sysctl(SYSCTL_HANDLER_ARGS);
 static int carp_dscp_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_INT(_net_inet_carp, OID_AUTO, allow, CTLFLAG_VNET | CTLFLAG_RW,
-    &VNET_NAME(carp_allow), 0, "Accept incoming CARP packets");
+SYSCTL_PROC(_net_inet_carp, OID_AUTO, allow,
+    CTLFLAG_VNET | CTLTYPE_INT | CTLFLAG_RW, 0, 0, carp_allow_sysctl, "I",
+    "Accept incoming CARP packets");
 SYSCTL_PROC(_net_inet_carp, OID_AUTO, dscp,
     CTLFLAG_VNET | CTLTYPE_INT | CTLFLAG_RW, 0, 0, carp_dscp_sysctl, "I",
     "DSCP value for carp packets");
@@ -1209,7 +1211,8 @@ carp_setrun(struct carp_softc *sc, sa_family_t af)
 
 	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))
+	    (sc->sc_naddrs == 0 && sc->sc_naddrs6 == 0) ||
+	    !V_carp_allow)
 		return;
 
 	switch (sc->sc_state) {
@@ -1984,7 +1987,8 @@ carp_sc_state(struct carp_softc *sc)
 	CARP_LOCK_ASSERT(sc);
 
 	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);
 #ifdef INET
 		callout_stop(&sc->sc_md_tmo);
@@ -2012,6 +2016,33 @@ carp_demote_adj(int adj, char *reason)
 	atomic_add_int(&V_carp_demotion, adj);
 	CARP_LOG("demoted by %d to %d (%s)\n", adj, V_carp_demotion, reason);
 	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)
+				carp_sc_state(sc);
+			CARP_UNLOCK(sc);
+		}
+		mtx_unlock(&carp_mtx);
+	}
+
+	return (0);
 }
 
 static int



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201904262218.x3QMIM3r071298>