From nobody Fri Oct 30 17:48:56 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4jGT9h4nN8z6xGZL for ; Fri, 30 Oct 2026 17:48:56 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4jGT9h43mcz4jqb for ; Fri, 30 Oct 2026 17:48:56 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1793382536; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=s0CsDRQFT+ClxfDvOo7mTcxiU68ELHgDNjnLcfjbN8A=; b=IkTI6xJSCuScF0j7p2H4djTSVel1ZIkZzhUf/m0Wa1CvD3JHFWHYepEJLIpWW0KBhLBeBa H2J0eyfVqT8z45Uzp2sdP1lFTcmvMSoNrjoDxJ72cVY5MNpTE3YmmDq591nQFpEDCYa4Ei gy3ZsZYAdijUjuocZtkw4N2wAzOxeQLfa2xXjB1dv/gHWklu6P2AFsvirq8R7hQJ4VAthq pClVwiZAPgU+LK6lGkPkUqWaTdJE/d7Z5iDdohW2kxFqPo56FSnzCB32b4hKtv/fee9ao0 PnCDFcJBIrTpY6gW6iT89UtTmPMi1wbjUHf2EiKUBCV6ju6O3HTCUDzYsfp+wA== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1793382536; b=kNlf64c5b/ZE1wt4xpSrswhnJu3ZTgbTXRPYm/C6IxpGjIDrxgsYc6QwGmh78q5MOLF8f2 kXnUn9KJ79TOBMB0Km9VrYT8qTeI/e0Io6tq0fYZHTH/S+AXtQPRYbf4vEaArhFKxu4K4T P6OKEKfNj/tyamZwkTTfH6QgxQF+3HgTHnAYwiJnqIY1kGhL2IKU1b2A755RJIFHE2AvRj zP1RD8uItJF7Pv5wcsHqXzyS8LXF6eUuy6NIU2ylIzLjBn7LL1QYtSI25natqSoh26nz+c A4OfTnjSlfBuDdcgzbhNgWAW7Gd/vumMMDS+CTE87cdIx7tHXb6xtMfgLSeTZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1793382536; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=s0CsDRQFT+ClxfDvOo7mTcxiU68ELHgDNjnLcfjbN8A=; b=A2VtSZoXliPwC37S2Mni1p625PHH688ocrlLB8tAS5qDEmCLq1SwbuF3YgmLfEU1A8w5mG IT89mCbh59R6lamL/F9y5mAy2QSkXPgtIjVtIJzIJWEcDbgncmdW/ROagJP83UgNxXe/8+ OwtWkyGLUBhfmV1hxTlOGli5CAK9GjHfZwyeVTrwaLpA/ydkN/bi2teKITKJlE6lV2kDj/ l+Oo39BpQgUFnove259xLYSeUuJrZKkY2IRpNXZwEOKHp/NWhuwNxEg1TsDMj5AywhCPGR z1Qt7snjYeVmRGeaLIf2SRSFOM8b9tyJ2y0ZYcA5TSN/YcoA5Oq1fPHbpXQhvg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4jGT9h3kh4zdvB for ; Fri, 30 Oct 2026 17:48:56 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 41b05 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Fri, 30 Oct 2026 17:48:56 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Cc: Olivier Cochard From: Kevin Bowling Subject: git: b021a5925f49 - stable/15 - carp: fix global demotion counter to VRRP advertisements List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org List-Id: Commit messages for all branches of the src repository List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kbowling X-Git-Repository: src X-Git-Refname: refs/heads/stable/15 X-Git-Reftype: branch X-Git-Commit: b021a5925f49475a8443f035f195489022378e42 Auto-Submitted: auto-generated Date: Fri, 30 Oct 2026 17:48:56 +0000 Message-Id: <6ae4d888.41b05.3c23ee40@gitrepo.freebsd.org> The branch stable/15 has been updated by kbowling: URL: https://cgit.FreeBSD.org/src/commit/?id=b021a5925f49475a8443f035f195489022378e42 commit b021a5925f49475a8443f035f195489022378e42 Author: Olivier Cochard AuthorDate: 2026-03-05 11:02:20 +0000 Commit: Kevin Bowling CommitDate: 2026-10-30 17:48:45 +0000 carp: fix global demotion counter to VRRP advertisements When net.inet.carp.preempt=1 and a physical interface goes down, the global V_carp_demotion counter is incremented. For CARP this was already reflected in outgoing advertisements via DEMOTE_ADVSKEW(), but VRRP sent the raw sc_vrrp_prio unchanged, so demotion had no effect. Add DEMOTE_VRRP_PRIO(), a macro analogous to DEMOTE_ADVSKEW(): It subtracts V_carp_demotion from the configured priority and clamps the result to [0, 254]. Priority 0 is VRRPv3's "resign" signal and causes backups to preempt immediately. Priority 255 (IP address owner) is never demoted. Reviewed by: kp Approved by: kp Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D55558 (cherry picked from commit 9f71153aec0cb455cd49af6d4ca7e4c16fd45d7a) --- sys/netinet/ip_carp.c | 17 ++++++++++--- tests/sys/netinet/carp.sh | 61 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 3 deletions(-) diff --git a/sys/netinet/ip_carp.c b/sys/netinet/ip_carp.c index 4f553b9aac5e..42049b6e7834 100644 --- a/sys/netinet/ip_carp.c +++ b/sys/netinet/ip_carp.c @@ -332,6 +332,17 @@ SYSCTL_VNET_PCPUSTAT(_net_inet_carp, OID_AUTO, stats, struct carpstats, (((sc)->sc_advskew + V_carp_demotion < 0) ? \ 0 : ((sc)->sc_advskew + V_carp_demotion))) +/* + * VRRPv3 priority is the inverse of CARP advskew: higher is better. + * Subtract the global demotion counter and clamp to [0, 254]. + * Priority 255 (IP address owner) is never demoted. + */ +#define DEMOTE_VRRP_PRIO(sc) \ + ((sc)->sc_vrrp_prio == 255 ? 255 : \ + (((int)(sc)->sc_vrrp_prio - V_carp_demotion < 0) ? 0 : \ + (((int)(sc)->sc_vrrp_prio - V_carp_demotion > 254) ? 254 : \ + (int)(sc)->sc_vrrp_prio - V_carp_demotion))) + static void carp_input_c(struct mbuf *, struct carp_header *, sa_family_t, int); static void vrrp_input_c(struct mbuf *, int, sa_family_t, int, int, uint16_t); static struct carp_softc @@ -1010,7 +1021,7 @@ vrrp_input_c(struct mbuf *m, int off, sa_family_t af, int ttl, * Same if the peer has a higher priority than us. */ if (ntohs(vh->vrrp_max_adver_int) < sc->sc_vrrp_adv_inter || - vh->vrrp_priority > sc->sc_vrrp_prio) { + vh->vrrp_priority > DEMOTE_VRRP_PRIO(sc)) { callout_stop(&sc->sc_ad_tmo); carp_set_state(sc, BACKUP, "more frequent advertisement received"); @@ -1024,7 +1035,7 @@ vrrp_input_c(struct mbuf *m, int off, sa_family_t af, int ttl, * and this one claims to be slower, treat him as down. */ if (V_carp_preempt && (ntohs(vh->vrrp_max_adver_int) > sc->sc_vrrp_adv_inter - || vh->vrrp_priority < sc->sc_vrrp_prio)) { + || vh->vrrp_priority < DEMOTE_VRRP_PRIO(sc))) { carp_master_down_locked(sc, "preempting a slower master"); break; @@ -1360,7 +1371,7 @@ vrrp_send_ad_locked(struct carp_softc *sc) .vrrp_version = CARP_VERSION_VRRPv3, .vrrp_type = VRRP_TYPE_ADVERTISEMENT, .vrrp_vrtid = sc->sc_vhid, - .vrrp_priority = sc->sc_vrrp_prio, + .vrrp_priority = DEMOTE_VRRP_PRIO(sc), .vrrp_count_addr = 0, .vrrp_max_adver_int = htons(sc->sc_vrrp_adv_inter), .vrrp_checksum = 0, diff --git a/tests/sys/netinet/carp.sh b/tests/sys/netinet/carp.sh index e6521d0a0708..7b484a21d8cf 100755 --- a/tests/sys/netinet/carp.sh +++ b/tests/sys/netinet/carp.sh @@ -505,6 +505,66 @@ negative_demotion_cleanup() vnet_cleanup } +atf_test_case "vrrp_preempt" "cleanup" +vrrp_preempt_head() +{ + atf_set descr 'Test VRRP preemption' + atf_set require.user root +} + +vrrp_preempt_body() +{ + carp_init + + epair1=$(vnet_mkepair) + epair2=$(vnet_mkepair) + + vnet_mkjail one ${epair1}a ${epair2}a + jexec one sysctl net.inet.carp.preempt=1 + jexec one ifconfig ${epair1}a 192.0.2.1/24 up + jexec one ifconfig ${epair1}a add vhid 1 carpver 3 192.0.2.254/24 \ + vrrpprio 10 pass foobar1 + jexec one ifconfig ${epair2}a 192.0.3.1/24 up + jexec one ifconfig ${epair2}a add vhid 2 carpver 3 192.0.3.254/24 \ + vrrpprio 10 pass foobar2 + + vnet_mkjail two ${epair1}b ${epair2}b + jexec two sysctl net.inet.carp.preempt=1 + jexec two ifconfig ${epair1}b 192.0.2.2/24 up + jexec two ifconfig ${epair2}b 192.0.3.2/24 up + jexec two ifconfig ${epair1}b add vhid 1 carpver 3 192.0.2.254/24 \ + vrrpprio 1 pass foobar1 + jexec two ifconfig ${epair2}b add vhid 2 carpver 3 192.0.3.254/24 \ + vrrpprio 1 pass foobar2 + + # Allow things to settle + wait_for_carp one ${epair1}a two ${epair1}b + wait_for_carp one ${epair2}a two ${epair2}b + + # Bring down one interface; preemption should demote the second interface too + jexec one ifconfig ${epair1}a down + sleep 3 + + if is_master one ${epair2}a + then + atf_fail "preemption did not affect the second interface" + fi + + # Bring interface back up; one should reclaim master + jexec one ifconfig ${epair1}a up + sleep 3 + + if ! is_master one ${epair2}a + then + atf_fail "Priority router did not take its master role back" + fi +} + +vrrp_preempt_cleanup() +{ + vnet_cleanup +} + atf_test_case "nd6_ns_source_mac" "cleanup" @@ -604,5 +664,6 @@ atf_init_test_cases() atf_add_test_case "unicast_ll_v6" atf_add_test_case "negative_demotion" atf_add_test_case "nd6_ns_source_mac" + atf_add_test_case "vrrp_preempt" atf_add_test_case "switch" }