From nobody@FreeBSD.org  Thu Sep 29 15:05:59 2011
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 2E2611065670
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 29 Sep 2011 15:05:59 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 043EF8FC1F
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 29 Sep 2011 15:05:59 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id p8TF5wBt047015
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 29 Sep 2011 15:05:58 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id p8TF5wir047014;
	Thu, 29 Sep 2011 15:05:58 GMT
	(envelope-from nobody)
Message-Id: <201109291505.p8TF5wir047014@red.freebsd.org>
Date: Thu, 29 Sep 2011 15:05:58 GMT
From: Damien Fleuriot <dam@my.gd>
To: freebsd-gnats-submit@FreeBSD.org
Subject: CARP - when preemption is enabled carp interface assumes MASTERship immediately even with higher advbase/advskew
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         161123
>Category:       kern
>Synopsis:       [carp] [patch] when preemption is enabled carp interface assumes MASTERship immediately even with higher advbase/advskew
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    glebius
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Sep 29 15:10:09 UTC 2011
>Closed-Date:    Thu Oct 20 15:55:58 UTC 2011
>Last-Modified:  Tue Jan 17 18:10:09 UTC 2012
>Originator:     Damien Fleuriot
>Release:        8.2-RELEASE
>Organization:
Hi-Media
>Environment:
FreeBSD pf2.multiprojet 8.2-RELEASE FreeBSD 8.2-RELEASE #1: Thu Sep 29 16:11:04 CEST 2011     root@pf2.multiprojet:/usr/obj/usr/src/sys/MULTI  amd64
>Description:
Under normal operating circumstances, a CARP interface goes through the following states:
- INIT : when it's down
- BACKUP : immediately upon being brought up, the interface assumes a BACKUP role and starts its timer to know if it should  claim mastership.
- MASTER : if the delay has expired (advbase * 3) without the interface seeing another master, it assumes mastership.


BUG: When preemption is enabled (net.inet.carp.preempt=1) , the CARP interface immediately assumes MASTERship regardless of its advbase and advskew values.

This causes CARP switchovers when a firewall from a CARP cluster is rebooted, for example.

In our case, this actually led to lost client connections, lost database sessions, developers' daemons crashes because of lost java/db connections...



This is a known problem with OpenBSD 3.8 and lower's implementation of CARP.
This has been fixed as of OpenBSD 3.9.

Refer: my post on -stable
http://docs.freebsd.org/cgi/getmsg.cgi?fetch=368260+0+current/freebsd-stable

>How-To-Repeat:
Set up 2 boxes with a shared CARP IP.
Enable CARP preemption.

Bring down your CARP interface on the BACKUP box.
Bring it up again.
Notice how your interface assumed MASTERship for a short time.
Check with dmesg which confirms that your box actually preempted.
>Fix:
The fix lies in sys/netinet/ip_carp.c in function carp_setrun(struct carp_softc *sc,
sa_family_t af).

All that is needed is to get rid of the code portion which instruct the CARP interface to immediately transition from INIT to MASTER if it has preemption enabled.

Patch attached.


Patch attached with submission follows:

--- sys/netinet/ip_carp.c	2011-09-29 15:00:07.000000000 +0200
+++ sys/netinet/ip_carp.c	2011-09-29 15:01:37.000000000 +0200
@@ -1390,22 +1390,10 @@
 
 	switch (sc->sc_state) {
 	case INIT:
-		if (carp_opts[CARPCTL_PREEMPT] && !carp_suppress_preempt) {
-			carp_send_ad_locked(sc);
-			carp_send_arp(sc);
-#ifdef INET6
-			carp_send_na(sc);
-#endif /* INET6 */
-			CARP_LOG("%s: INIT -> MASTER (preempting)\n",
-			    SC2IFP(sc)->if_xname);
-			carp_set_state(sc, MASTER);
-			carp_setroute(sc, RTM_ADD);
-		} else {
-			CARP_LOG("%s: INIT -> BACKUP\n", SC2IFP(sc)->if_xname);
-			carp_set_state(sc, BACKUP);
-			carp_setroute(sc, RTM_DELETE);
-			carp_setrun(sc, 0);
-		}
+		CARP_LOG("%s: INIT -> BACKUP\n", SC2IFP(sc)->if_xname);
+		carp_set_state(sc, BACKUP);
+		carp_setroute(sc, RTM_DELETE);
+		carp_setrun(sc, 0);
 		break;
 	case BACKUP:
 		callout_stop(&sc->sc_ad_tmo);


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-net 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Mon Oct 10 04:55:26 UTC 2011 
Responsible-Changed-Why:  
Over to maintainer(s). 

http://www.freebsd.org/cgi/query-pr.cgi?pr=161123 
Responsible-Changed-From-To: freebsd-net->glebius 
Responsible-Changed-By: glebius 
Responsible-Changed-When: Thu Oct 13 14:03:27 UTC 2011 
Responsible-Changed-Why:  
Take. 

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

From: Pavel Timofeev <timp87@gmail.com>
To: bug-followup@FreeBSD.org, dam@my.gd
Cc:  
Subject: Re: kern/161123: [carp] [patch] when preemption is enabled carp
 interface assumes MASTERship immediately even with higher advbase/advskew
Date: Thu, 13 Oct 2011 22:44:36 +0400

 --00151747b4c84f3b5304af32888c
 Content-Type: text/plain; charset=UTF-8
 
 Sorry, will it be in 9.0 RELEASE?
 
 --00151747b4c84f3b5304af32888c
 Content-Type: text/html; charset=UTF-8
 
 <p>Sorry, will it be in 9.0 RELEASE?</p>
 
 --00151747b4c84f3b5304af32888c--

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/161123: commit references a PR
Date: Fri, 14 Oct 2011 19:05:39 +0000 (UTC)

 Author: glebius
 Date: Fri Oct 14 19:05:26 2011
 New Revision: 226367
 URL: http://svn.freebsd.org/changeset/base/226367
 
 Log:
   Never switch directly from INIT to MASTER, since this produces
   nasty status flaps.
   
   PR:		kern/161123
   Submitted by:	Damien Fleuriot <dam my.gd>
   OpenBSD:	ip_carp.c, rev. 1.115
 
 Modified:
   head/sys/netinet/ip_carp.c
 
 Modified: head/sys/netinet/ip_carp.c
 ==============================================================================
 --- head/sys/netinet/ip_carp.c	Fri Oct 14 11:48:32 2011	(r226366)
 +++ head/sys/netinet/ip_carp.c	Fri Oct 14 19:05:26 2011	(r226367)
 @@ -1424,24 +1424,10 @@ carp_setrun(struct carp_softc *sc, sa_fa
  
  	switch (sc->sc_state) {
  	case INIT:
 -		if (carp_opts[CARPCTL_PREEMPT] && !carp_suppress_preempt) {
 -			carp_send_ad_locked(sc);
 -#ifdef INET
 -			carp_send_arp(sc);
 -#endif
 -#ifdef INET6
 -			carp_send_na(sc);
 -#endif /* INET6 */
 -			CARP_LOG("%s: INIT -> MASTER (preempting)\n",
 -			    SC2IFP(sc)->if_xname);
 -			carp_set_state(sc, MASTER);
 -			carp_setroute(sc, RTM_ADD);
 -		} else {
 -			CARP_LOG("%s: INIT -> BACKUP\n", SC2IFP(sc)->if_xname);
 -			carp_set_state(sc, BACKUP);
 -			carp_setroute(sc, RTM_DELETE);
 -			carp_setrun(sc, 0);
 -		}
 +		CARP_LOG("%s: INIT -> BACKUP\n", SC2IFP(sc)->if_xname);
 +		carp_set_state(sc, BACKUP);
 +		carp_setroute(sc, RTM_DELETE);
 +		carp_setrun(sc, 0);
  		break;
  	case BACKUP:
  		callout_stop(&sc->sc_ad_tmo);
 _______________________________________________
 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: gavin 
State-Changed-When: Wed Oct 19 16:40:19 UTC 2011 
State-Changed-Why:  
Mark this as patched, it is fixed in HEAD and awaiting MFC.  glebius@, 
is there any chance that this can be merged before 9.0 is released? 

http://www.freebsd.org/cgi/query-pr.cgi?pr=161123 
State-Changed-From-To: patched->closed 
State-Changed-By: glebius 
State-Changed-When: Thu Oct 20 15:55:34 UTC 2011 
State-Changed-Why:  
Merged to stable/9, will be availiable in 9.0-RELEASE. 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/161123: commit references a PR
Date: Thu, 20 Oct 2011 15:55:19 +0000 (UTC)

 Author: glebius
 Date: Thu Oct 20 15:55:01 2011
 New Revision: 226571
 URL: http://svn.freebsd.org/changeset/base/226571
 
 Log:
   MFhead r226367:
   
     Never switch directly from INIT to MASTER, since this produces
     nasty status flaps.
   
     PR:           kern/161123
     Submitted by: Damien Fleuriot <dam my.gd>
     OpenBSD:      ip_carp.c, rev. 1.115
   
   Approved by:	re (kib)
 
 Modified:
   stable/9/sys/netinet/ip_carp.c
 Directory Properties:
   stable/9/sys/   (props changed)
   stable/9/sys/amd64/include/xen/   (props changed)
   stable/9/sys/boot/   (props changed)
   stable/9/sys/boot/i386/efi/   (props changed)
   stable/9/sys/boot/ia64/efi/   (props changed)
   stable/9/sys/boot/ia64/ski/   (props changed)
   stable/9/sys/boot/powerpc/boot1.chrp/   (props changed)
   stable/9/sys/boot/powerpc/ofw/   (props changed)
   stable/9/sys/cddl/contrib/opensolaris/   (props changed)
   stable/9/sys/conf/   (props changed)
   stable/9/sys/contrib/dev/acpica/   (props changed)
   stable/9/sys/contrib/octeon-sdk/   (props changed)
   stable/9/sys/contrib/pf/   (props changed)
   stable/9/sys/contrib/x86emu/   (props changed)
 
 Modified: stable/9/sys/netinet/ip_carp.c
 ==============================================================================
 --- stable/9/sys/netinet/ip_carp.c	Thu Oct 20 15:53:26 2011	(r226570)
 +++ stable/9/sys/netinet/ip_carp.c	Thu Oct 20 15:55:01 2011	(r226571)
 @@ -1424,24 +1424,10 @@ carp_setrun(struct carp_softc *sc, sa_fa
  
  	switch (sc->sc_state) {
  	case INIT:
 -		if (carp_opts[CARPCTL_PREEMPT] && !carp_suppress_preempt) {
 -			carp_send_ad_locked(sc);
 -#ifdef INET
 -			carp_send_arp(sc);
 -#endif
 -#ifdef INET6
 -			carp_send_na(sc);
 -#endif /* INET6 */
 -			CARP_LOG("%s: INIT -> MASTER (preempting)\n",
 -			    SC2IFP(sc)->if_xname);
 -			carp_set_state(sc, MASTER);
 -			carp_setroute(sc, RTM_ADD);
 -		} else {
 -			CARP_LOG("%s: INIT -> BACKUP\n", SC2IFP(sc)->if_xname);
 -			carp_set_state(sc, BACKUP);
 -			carp_setroute(sc, RTM_DELETE);
 -			carp_setrun(sc, 0);
 -		}
 +		CARP_LOG("%s: INIT -> BACKUP\n", SC2IFP(sc)->if_xname);
 +		carp_set_state(sc, BACKUP);
 +		carp_setroute(sc, RTM_DELETE);
 +		carp_setrun(sc, 0);
  		break;
  	case BACKUP:
  		callout_stop(&sc->sc_ad_tmo);
 _______________________________________________
 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"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/161123: commit references a PR
Date: Tue, 17 Jan 2012 18:05:28 +0000 (UTC)

 Author: glebius
 Date: Tue Jan 17 18:05:13 2012
 New Revision: 230271
 URL: http://svn.freebsd.org/changeset/base/230271
 
 Log:
   MFhead r226367:
   
     Never switch directly from INIT to MASTER, since this produces
     nasty status flaps.
   
     PR:		kern/161123
     Submitted by:	Damien Fleuriot <dam my.gd>
     OpenBSD:	ip_carp.c, rev. 1.115
 
 Modified:
   stable/8/sys/netinet/ip_carp.c
 Directory Properties:
   stable/8/sys/   (props changed)
 
 Modified: stable/8/sys/netinet/ip_carp.c
 ==============================================================================
 --- stable/8/sys/netinet/ip_carp.c	Tue Jan 17 17:07:13 2012	(r230270)
 +++ stable/8/sys/netinet/ip_carp.c	Tue Jan 17 18:05:13 2012	(r230271)
 @@ -1391,22 +1391,10 @@ carp_setrun(struct carp_softc *sc, sa_fa
  
  	switch (sc->sc_state) {
  	case INIT:
 -		if (carp_opts[CARPCTL_PREEMPT] && !carp_suppress_preempt) {
 -			carp_send_ad_locked(sc);
 -			carp_send_arp(sc);
 -#ifdef INET6
 -			carp_send_na(sc);
 -#endif /* INET6 */
 -			CARP_LOG("%s: INIT -> MASTER (preempting)\n",
 -			    SC2IFP(sc)->if_xname);
 -			carp_set_state(sc, MASTER);
 -			carp_setroute(sc, RTM_ADD);
 -		} else {
 -			CARP_LOG("%s: INIT -> BACKUP\n", SC2IFP(sc)->if_xname);
 -			carp_set_state(sc, BACKUP);
 -			carp_setroute(sc, RTM_DELETE);
 -			carp_setrun(sc, 0);
 -		}
 +		CARP_LOG("%s: INIT -> BACKUP\n", SC2IFP(sc)->if_xname);
 +		carp_set_state(sc, BACKUP);
 +		carp_setroute(sc, RTM_DELETE);
 +		carp_setrun(sc, 0);
  		break;
  	case BACKUP:
  		callout_stop(&sc->sc_ad_tmo);
 _______________________________________________
 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"
 
>Unformatted:
