svn commit: r243466 - stable/8/sbin/ifconfig

Remko Lodder remko at
Fri Nov 23 21:27:26 UTC 2012

Author: remko
Date: Fri Nov 23 21:27:26 2012
New Revision: 243466

  MFC r232486
  Add an ifconfig carp option that enables users to set
  the state of the carp cluster.
  This is a direct commit to stable/9 because -HEAD's
  code is very different. I discussed this with Gleb
  and the reason for this is that since we do not
  touch the kernel itself and are not adding very
  weird or confusing things, we can commit this to the
  stable branch directly.
  The options 'master' and 'backup' are now available,
  which enables the administrator to force a node into
  the backup or master state on the cluster. Ofcourse
  preempt has to be disabled otherwise the master node
  will become master again.
  One can do that with:
  sysctl net.inet.carp.preempt=0
  After that one can schedule maintenance on the node
  normally running as the master and such.
  PR:	 100956
  Discussed with:	glebius

Directory Properties:
  stable/8/sbin/ifconfig/   (props changed)

Modified: stable/8/sbin/ifconfig/ifcarp.c
--- stable/8/sbin/ifconfig/ifcarp.c	Fri Nov 23 20:04:39 2012	(r243465)
+++ stable/8/sbin/ifconfig/ifcarp.c	Fri Nov 23 21:27:26 2012	(r243466)
@@ -57,6 +57,7 @@ void setcarp_advbase(const char *,int, i
 void setcarp_advskew(const char *, int, int, const struct afswtch *rafp);
 void setcarp_passwd(const char *, int, int, const struct afswtch *rafp);
 void setcarp_vhid(const char *, int, int, const struct afswtch *rafp);
+void setcarp_state(const char *, int, int, const struct afswtch *rafp);
 carp_status(int s)
@@ -175,11 +176,34 @@ setcarp_advbase(const char *val, int d, 
+void setcarp_state(const char *val, int d, int s, const struct afswtch *afp)
+	struct carpreq carpr;
+	int i;
+	bzero((char *)&carpr, sizeof(struct carpreq));
+	ifr.ifr_data = (caddr_t)&carpr;
+	if (ioctl(s, SIOCGVH, (caddr_t)&ifr) == -1)
+		err(1, "SIOCGVH");
+	for (i = 0; i <= CARP_MAXSTATE; i++) {
+		if (!strcasecmp(val, carp_states[i])) {
+			carpr.carpr_state = i;
+			break;
+		}
+	}
+	if (ioctl(s, SIOCSVH, (caddr_t)&ifr) == -1)
+		err(1, "SIOCSVH");
 static struct cmd carp_cmds[] = {
 	DEF_CMD_ARG("advbase",	setcarp_advbase),
 	DEF_CMD_ARG("advskew",	setcarp_advskew),
 	DEF_CMD_ARG("pass",	setcarp_passwd),
 	DEF_CMD_ARG("vhid",	setcarp_vhid),
+	DEF_CMD_ARG("state",	setcarp_state),
 static struct afswtch af_carp = {
 	.af_name	= "af_carp",

Modified: stable/8/sbin/ifconfig/ifconfig.8
--- stable/8/sbin/ifconfig/ifconfig.8	Fri Nov 23 20:04:39 2012	(r243465)
+++ stable/8/sbin/ifconfig/ifconfig.8	Fri Nov 23 21:27:26 2012	(r243466)
@@ -2408,6 +2408,13 @@ Set the authentication key to
 Set the virtual host ID.
 This is a required setting.
 Acceptable values are 1 to 255.
+.It Cm state Ar state
+Force the interface into state 
+.Ar state . 
+Valid states are INIT, BACKUP, and MASTER. Note that manually setting the state
+to INIT is ignored by 
+.Xr carp 4 .
+This state is set automatically when the underlying interface is down.

More information about the svn-src-stable-8 mailing list