From snb@smtp.earth.threerings.net  Fri Jul 28 02:10:10 2006
Return-Path: <snb@smtp.earth.threerings.net>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 0437016A4DE
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 28 Jul 2006 02:10:09 +0000 (UTC)
	(envelope-from snb@smtp.earth.threerings.net)
Received: from smtp.earth.threerings.net (mail.threerings.net [64.127.109.101])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 9114043D5A
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 28 Jul 2006 02:10:09 +0000 (GMT)
	(envelope-from snb@smtp.earth.threerings.net)
Received: by smtp.earth.threerings.net (Postfix, from userid 1004)
	id 9C20565E1; Thu, 27 Jul 2006 19:10:08 -0700 (PDT)
Message-Id: <20060728021008.9C20565E1@smtp.earth.threerings.net>
Date: Thu, 27 Jul 2006 19:10:08 -0700 (PDT)
From: Nick Barkas <snb@threerings.net>
Reply-To: Nick Barkas <snb@threerings.net>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [patch] support setting carp device state with ifconfig
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         100956
>Category:       bin
>Synopsis:       [patch] support setting carp device state with ifconfig(8)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    remko
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Fri Jul 28 02:10:13 GMT 2006
>Closed-Date:    Fri Nov 23 21:29:27 UTC 2012
>Last-Modified:  Fri Nov 23 21:29:27 UTC 2012
>Originator:     Nick Barkas
>Release:        FreeBSD 7.0-CURRENT i386
>Organization:
>Environment:
FreeBSD freebsd-current.sea.earth.threerings.net 7.0-CURRENT FreeBSD 7.0-CURRENT #0: Thu Jul 27 13:01:44 PDT 2006   root@freebsd61.sea.earth.threerings.net:/usr/obj/usr/src/sys/TEST  i386
>Description:
	carp(4) devices expose an ioctl allowing their states to be set to MASTER or
    BACKUP explicitly from userland. However, ifconfig does not have any option
    to do this. Attached is a patch based on OpenBSD's ifconfig which allows a
    state option to be given to carp interfaces, and a patch to the ifconfig man
    page.
>How-To-Repeat:
	ifconfig carpN state foo does not currently work.
>Fix:
--- src/sbin/ifconfig/ifcarp.c.orig	Tue Feb 22 06:07:47 2005
+++ src/sbin/ifconfig/ifcarp.c	Thu Jul 27 16:15:12 2006
@@ -57,6 +57,7 @@
 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);
 
 void
 carp_status(int s)
@@ -174,11 +175,34 @@
 	return;
 }
 
+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",


--- src/sbin/ifconfig/ifconfig.8.orig	Tue Jul 25 20:08:45 2006
+++ src/sbin/ifconfig/ifconfig.8	Thu Jul 27 19:02:50 2006
@@ -28,7 +28,7 @@
 .\"     From: @(#)ifconfig.8	8.3 (Berkeley) 1/5/94
 .\" $FreeBSD: /repoman/r/ncvs/src/sbin/ifconfig/ifconfig.8,v 1.119 2006/07/26 03:08:45 sam Exp $
 .\"
-.Dd July 25, 2006
+.Dd July 27, 2006
 .Dt IFCONFIG 8
 .Os
 .Sh NAME
@@ -1405,6 +1405,13 @@
 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.
 .El
 .Pp
 The
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->remko 
Responsible-Changed-By: remko 
Responsible-Changed-When: Sat Feb 24 10:07:45 UTC 2007 
Responsible-Changed-Why:  
I'll take it. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=100956 

From: Brian Gardner <brian@getsnappy.com>
To: bug-followup@FreeBSD.org, snb@threerings.net
Cc:  
Subject: Re: bin/100956: [patch] support setting carp device state with ifconfig(8)
Date: Wed, 22 Dec 2010 18:51:49 -0800

 I've been using this patch and lost it in a recent upgrade.  I've had =
 zero problems.  Any change of getting this committed?=

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/100956: commit references a PR
Date: Sun,  4 Mar 2012 10:37:40 +0000 (UTC)

 Author: remko
 Date: Sun Mar  4 10:37:26 2012
 New Revision: 232486
 URL: http://svn.freebsd.org/changeset/base/232486
 
 Log:
   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
   MFC after:	1 weeks
 
 Modified:
   stable/9/sbin/ifconfig/ifcarp.c
   stable/9/sbin/ifconfig/ifconfig.8
 
 Modified: stable/9/sbin/ifconfig/ifcarp.c
 ==============================================================================
 --- stable/9/sbin/ifconfig/ifcarp.c	Sun Mar  4 09:48:58 2012	(r232485)
 +++ stable/9/sbin/ifconfig/ifcarp.c	Sun Mar  4 10:37:26 2012	(r232486)
 @@ -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);
  
  void
  carp_status(int s)
 @@ -175,11 +176,34 @@ setcarp_advbase(const char *val, int d, 
  	return;
  }
  
 +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/9/sbin/ifconfig/ifconfig.8
 ==============================================================================
 --- stable/9/sbin/ifconfig/ifconfig.8	Sun Mar  4 09:48:58 2012	(r232485)
 +++ stable/9/sbin/ifconfig/ifconfig.8	Sun Mar  4 10:37:26 2012	(r232486)
 @@ -28,7 +28,7 @@
  .\"     From: @(#)ifconfig.8	8.3 (Berkeley) 1/5/94
  .\" $FreeBSD$
  .\"
 -.Dd December 17, 2011
 +.Dd March 4, 2012
  .Dt IFCONFIG 8
  .Os
  .Sh NAME
 @@ -2436,6 +2436,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.
  .El
  .Pp
  The
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->patched 
State-Changed-By: remko 
State-Changed-When: Sun Mar 4 10:42:37 UTC 2012 
State-Changed-Why:  
This had been patched in 9-stable, should be merged to 8 
and 7 after the dust had been settled. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=100956 
State-Changed-From-To: patched->closed 
State-Changed-By: remko 
State-Changed-When: Fri Nov 23 21:29:26 UTC 2012 
State-Changed-Why:  
Committed and MFC'ed.. with a slight delay. Thank you for your 
submission! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=100956 
>Unformatted:
