From owner-freebsd-bugs@FreeBSD.ORG Sat Aug 30 20:40:00 2008 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D7113106564A for ; Sat, 30 Aug 2008 20:40:00 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id B36798FC08 for ; Sat, 30 Aug 2008 20:40:00 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.2/8.14.2) with ESMTP id m7UKe0ZZ082203 for ; Sat, 30 Aug 2008 20:40:00 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.2/8.14.1/Submit) id m7UKe0vU082202; Sat, 30 Aug 2008 20:40:00 GMT (envelope-from gnats) Resent-Date: Sat, 30 Aug 2008 20:40:00 GMT Resent-Message-Id: <200808302040.m7UKe0vU082202@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, "Alexander V. Chernikov" Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B897F1065671 for ; 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 ; 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 ; 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" To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: kern/126984: [carp][patch] add carp userland notifications via devctl(4) X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 30 Aug 2008 20:40:00 -0000 >Number: 126984 >Category: kern >Synopsis: [carp][patch] add carp userland notifications via devctl(4) >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Sat Aug 30 20:40:00 UTC 2008 >Closed-Date: >Last-Modified: >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 #include #include +#include #include #include #include @@ -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: >Unformatted: