From nobody@FreeBSD.org  Sat Aug 30 20:38:01 2008
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id B897F1065671
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 30 Aug 2008 20:38:01 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id A7D568FC0A
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 30 Aug 2008 20:38:01 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.2/8.14.2) with ESMTP id m7UKc0oY093715
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 30 Aug 2008 20:38:00 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.2/8.14.1/Submit) id m7UKc0Hc093714;
	Sat, 30 Aug 2008 20:38:00 GMT
	(envelope-from nobody)
Message-Id: <200808302038.m7UKc0Hc093714@www.freebsd.org>
Date: Sat, 30 Aug 2008 20:38:00 GMT
From: "Alexander V. Chernikov" <melifaro@ipfw.ru>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [carp][patch] add carp userland notifications via devctl(4)
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         126984
>Category:       kern
>Synopsis:       [carp] [patch] add carp userland notifications via devctl(4)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    glebius
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sat Aug 30 20:40:00 UTC 2008
>Closed-Date:    Mon Apr 11 11:09:41 UTC 2011
>Last-Modified:  Mon Apr 11 11:09:41 UTC 2011
>Originator:     Alexander V. Chernikov
>Release:        8.0
>Organization:
>Environment:
FreeBSD ws.su29.net 8.0-CURRENT FreeBSD 8.0-CURRENT #11: Thu Mar 13 05:13:16 MSK 2008     melifaro@ws.su29.net:/usr/obj/usr/src/sys/CURR  amd64
>Description:
Small patch to get change in carp(4) interface state more easily. Userland notification is done via devctl(4) and can be configured in devd.conf. This is useful when user wants to get notification for this event on e-mail or sms or needs to perform some additional actions. Changes are documented in carp(4) manual page and usage example is available in devd.conf
>How-To-Repeat:

>Fix:


Patch attached with submission follows:

--- sys/netinet/ip_carp.c.orig	2008-08-18 02:49:50.000000000 +0400
+++ sys/netinet/ip_carp.c	2008-08-18 02:16:50.000000000 +0400
@@ -35,6 +35,7 @@
 #include <sys/types.h>
 #include <sys/param.h>
 #include <sys/systm.h>
+#include <sys/bus.h>
 #include <sys/conf.h>
 #include <sys/kernel.h>
 #include <sys/limits.h>
@@ -2108,6 +2109,7 @@
 static void
 carp_set_state(struct carp_softc *sc, int state)
 {
+	char vhid_buf[15], *dev_msg;
 
 	if (sc->sc_carpdev)
 		CARP_SCLOCK_ASSERT(sc);
@@ -2119,15 +2121,20 @@
 	switch (state) {
 	case BACKUP:
 		SC2IFP(sc)->if_link_state = LINK_STATE_DOWN;
+		dev_msg = "CARP_SLAVE";
 		break;
 	case MASTER:
 		SC2IFP(sc)->if_link_state = LINK_STATE_UP;
+		dev_msg = "CARP_MASTER";
 		break;
 	default:
 		SC2IFP(sc)->if_link_state = LINK_STATE_UNKNOWN;
+		dev_msg = "CARP_UNKNOWN";
 		break;
 	}
 	rt_ifmsg(SC2IFP(sc));
+	snprintf(vhid_buf, sizeof(vhid_buf), "vhid=%d", sc->sc_vhid);
+	devctl_notify("IFNET", SC2IFP(sc)->if_xname, dev_msg, vhid_buf);
 }
 
 void
--- etc/devd.conf.orig	2008-08-31 00:01:05.000000000 +0400
+++ etc/devd.conf	2008-08-31 00:08:17.000000000 +0400
@@ -302,4 +302,16 @@
 	match "subsystem"	"ACAD";
 	action			"/etc/acpi_ac $notify";
 };
+
+# Example of CARP notify handler
+# The following variables are set:
+# subsystem:	name of CARP interface
+# type:		event (CARP_SLAVE for becoming SLAVE, CARP_MASTER for master)
+# vhid:		CARP inrface VHID
+notify 100 {
+        match "system"          "IFNET";
+        match "type"            "CARP_SLAVE";
+        action "/usr/local/etc/carp_down.sh $subsystem $vhid $type";
+};
+
 */
--- share/man/man4/carp.4.orig	2008-08-30 23:57:07.000000000 +0400
+++ share/man/man4/carp.4	2008-08-30 23:59:29.000000000 +0400
@@ -168,6 +168,22 @@
 than the state information is packed and synced with the second router.
 If the reply would be load balanced to second router, it will be
 dropped due to no state.
+.Sh NOTIFICATIONS
+Notifications on becoming MASTER/SLAVE are sent via 
+.Xr devctl 4
+interface. The following events in IFNET system are generated:
+.Bl -tag -width ".Va CARP_MASTER"
+.It Va CARP_SLAVE
+System has become SLAVE on given carp interface.
+.It Va CARP_MASTER
+System has become MASTER on given carp interface.
+.El
+.Pp
+Additionaly, 
+.Cm subsystem
+variable is set to interface name and
+.Cm vhid
+variable is set to given interface VHID.
 .Sh EXAMPLES
 For firewalls and routers with multiple interfaces, it is desirable to
 failover all of the


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-net 
Responsible-Changed-By: remko 
Responsible-Changed-When: Mon Sep 1 11:42:22 UTC 2008 
Responsible-Changed-Why:  
Carp is something networking related, bring it over. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=126984 
State-Changed-From-To: open->feedback 
State-Changed-By: glebius 
State-Changed-When: Fri Dec 5 14:37:54 UTC 2008 
State-Changed-Why:  
I've just committed a change that makes link state change announcement 
when CARP changes status. This includes devd announcement. This is more 
standard than arbitrary message and also makes us compatible with OpenBSD. 

Alexander, are you satisfied with this change? Can the PR be closed after 
merging? 



Responsible-Changed-From-To: freebsd-net->glebius 
Responsible-Changed-By: glebius 
Responsible-Changed-When: Fri Dec 5 14:37:54 UTC 2008 
Responsible-Changed-Why:  
I've just committed a change that makes link state change announcement 
when CARP changes status. This includes devd announcement. This is more 
standard than arbitrary message and also makes us compatible with OpenBSD. 

Alexander, are you satisfied with this change? Can the PR be closed after 
merging? 


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

From: "Alexander V. Chernikov" <melifaro@ipfw.ru>
To: bug-followup@FreeBSD.org, melifaro@ipfw.ru
Cc:  
Subject: Re: kern/126984: [carp] [patch] add carp userland notifications via
 devctl(4)
Date: Sun, 19 Apr 2009 21:22:17 +0400

 Yes, this is much better solution, thanks.
State-Changed-From-To: feedback->patched 
State-Changed-By: emaste 
State-Changed-When: Mon Aug 17 19:54:05 UTC 2009 
State-Changed-Why:  
Original submitter agrees with modified patch, which has been committed as 
revision 185636. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=126984 
State-Changed-From-To: patched->closed 
State-Changed-By: glebius 
State-Changed-When: Mon Apr 11 11:08:13 UTC 2011 
State-Changed-Why:  
No need to merge, there have already been several releases after patch. 

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