Bug 294817 - sys/netinet/carp:unicast_v4 fails intermittently
Summary: sys/netinet/carp:unicast_v4 fails intermittently
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: tests (show other bugs)
Version: 16.0-CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: Zhenlei Huang
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2026-04-26 15:59 UTC by Mark Johnston
Modified: 2026-05-19 21:51 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Johnston freebsd_committer freebsd_triage 2026-04-26 15:59:20 UTC
This test sets up a jail connected to two hosts configured with carp to provide the virtual address 192.0.2.1.  At one point the jail tries to ping 192.0.2.1, and it sometimes fails for me.

What seems to happen is that carp_uni_v4_two becomes the carp master, but routed configures the jail's default route such that the ping goes to the backup host rather than to the master host.  The backup host doesn't reply, so the test fails.

I'm not sure how routed decides which host to prefer, but for the test to work it presumably needs to prefer the carp master host?
Comment 1 Mark Johnston freebsd_committer freebsd_triage 2026-04-26 16:00:05 UTC
Zhenlei, since you modified the test in commit 93fbdef51a13b to use routed, I wonder if you can comment here?
Comment 2 Mark Johnston freebsd_committer freebsd_triage 2026-04-26 16:01:55 UTC
To be more explicit, when the test fails, I see that:
- carp_uni_v4_two is the carp master, and
- carp_uni_v4_one's default route points at carp_uni_v4_three
If the default route instead points at the carp master, then the test passes.
Comment 3 Zhenlei Huang freebsd_committer freebsd_triage 2026-04-26 18:20:19 UTC
The main reason to choose routed is to build the route table dynamically so do not need repeat hand writing route entries. Another consideration is to have routed learn the kernel route event so maybe some regression can be caught in future. Indeed it does caught one ( changes made to the socket by @glebius IIRC ).

IIRC, when I was working on the regression test, I found at least one problem.

One is on CARP master / slave transition, the routed appears to still install default route to the master. I'm not sure if this is related to this reported issue, but I think it deserves investigation. I'll look into this issue in next few days.
Comment 4 Zhenlei Huang freebsd_committer freebsd_triage 2026-04-26 18:58:35 UTC
BTW, @ivy has a proposal to remove RIP / RIPng from base [1]. There're some debases on that. This test case shall be updated before the proposal proceeds and lands finally.

[1] https://reviews.freebsd.org/D53484 .
Comment 5 Mark Johnston freebsd_committer freebsd_triage 2026-04-27 01:25:46 UTC
(In reply to Zhenlei Huang from comment #3)
> One is on CARP master / slave transition, the routed appears to still install default route to the master. I'm not sure if this is related to this reported issue, but I think it deserves investigation.

I'm not quite sure what you mean, but in my case at least, routed tends to install the default route pointing to the backup, not the master.  It seems to be timing-dependent though.
Comment 6 Zhenlei Huang freebsd_committer freebsd_triage 2026-04-27 02:21:11 UTC
(In reply to Mark Johnston from comment #5)
 > I'm not quite sure what you mean,

Sorry I did not express clearly.

> One is on CARP master / slave transition, the routed appears to still install
> default route to the master.

I meant, if the CARP master becomes slave ( and the CARP slave becomes master ), the routed(8) do not update the new next hop ( previous slave, now master )to CARP IP, hence the middle box's ( which acts as a router ) route table is not updated and keeps stale entry. That breaks the fail over function of some unicast CARP setup.

It is not clear to me who, the kernel part ( route socket ) or the routed(8), is to be blamed without investigation.

> but in my case at least, routed tends to install the default route pointing to the
> backup, not the master.  It seems to be timing-dependent though.

I'll look at it. There must be something wrong.
Comment 8 Zhenlei Huang freebsd_committer freebsd_triage 2026-04-29 05:34:34 UTC
It is weird as the tests run greatly on my local dev machine. I check CI and found on stable/14 sys.netinet/carp/unicast_v4 is good without one failure.

The first failing one is https://ci.freebsd.org/view/Test/job/FreeBSD-stable-14-amd64-test/1502/testReport/. I believe that was caused by https://github.com/freebsd/freebsd-ci/commit/0fc366ebd6604f4b45ca48e7517a8d66a9b339df .

Post fix [1] to the CI repository.

[1] https://github.com/freebsd/freebsd-ci/pull/197 .

Also CC Siva .
Comment 9 Zhenlei Huang freebsd_committer freebsd_triage 2026-04-29 05:46:02 UTC
(In reply to Mark Johnston from comment #7)
It appears the failure on main has different causes. It does not always fail. The test appears start failing on stable/15 CI until recently, see the history [1]. I'm still investigating.

[1] https://ci.freebsd.org/view/Test/job/FreeBSD-stable-15-amd64-test/683/testReport/junit/sys.netinet/carp/history/?start=0&count=1000&interval=1
Comment 10 Siva Mahadevan freebsd_committer freebsd_triage 2026-04-29 14:47:33 UTC
(In reply to Zhenlei Huang from comment #8)

> Post fix [1] to the CI repository.

Thanks, merged that fix now.

Also, I'm able to consistently reproduce the intermittent CARP unicast_v4 test failure locally on my machine too (after about 10+ consecutive runs). I was looking into 'routed' alternatives now that RIP is being removed, but I'll let you investigate further since you're already looking into it.
Comment 11 Zhenlei Huang freebsd_committer freebsd_triage 2026-04-30 18:12:02 UTC
(In reply to Siva Mahadevan from comment #10)
I'm planning to add more sanity checks to the unicast_v4 testcase. Current the testcase does not report important part ( the routing table ) thus the result of ping is not sufficient to diagnose.
Comment 12 Mark Johnston freebsd_committer freebsd_triage 2026-04-30 20:35:44 UTC
(In reply to Zhenlei Huang from comment #11)
I used kyua debug -p carp:unicast_v4 to pause the test after the failure.  I see this:

root@freebsd:~ # jexec carp_uni_v4_one netstat -rn
Routing tables

Internet:
Destination        Gateway            Flags         Netif Expire
192.0.2.1          198.51.100.224     UGH         epair1a
198.51.100.0/25    link#3             U           epair0a
198.51.100.1       link#7             UHS             lo0
198.51.100.128/25  link#5             U           epair1a
198.51.100.129     link#7             UHS             lo0
root@freebsd:~ # jexec carp_uni_v4_two ifconfig
lo0: flags=8008<LOOPBACK,MULTICAST> metric 0 mtu 16384
        options=680003<RXCSUM,TXCSUM,LINKSTATE,RXCSUM_IPV6,TXCSUM_IPV6>
        groups: lo
        nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL>
epair0b: flags=1008943<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST,LOWER_UP> metric 0 mtu 1500
        options=200019<RXCSUM,VLAN_MTU,VLAN_HWTAGGING,RXCSUM_IPV6>
        ether 58:9c:fc:10:53:6b
        inet 198.51.100.2 netmask 0xffffff80 broadcast 198.51.100.127
        inet 192.0.2.1 netmask 0xffffffff broadcast 192.0.2.1 vhid 1
        groups: epair
        carp: MASTER vhid 1 advbase 1 advskew 0
              peer 198.51.100.224 peer6 ff02::12
        media: Ethernet 10Gbase-T (10Gbase-T <full-duplex>)
        status: active
        nd6 options=829<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL,STABLEADDR>
root@freebsd:~ # jexec carp_uni_v4_three ifconfig
lo0: flags=8008<LOOPBACK,MULTICAST> metric 0 mtu 16384
        options=680003<RXCSUM,TXCSUM,LINKSTATE,RXCSUM_IPV6,TXCSUM_IPV6>
        groups: lo
        nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL>
epair1b: flags=1008943<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST,LOWER_UP> metric 0 mtu 1500
        options=200019<RXCSUM,VLAN_MTU,VLAN_HWTAGGING,RXCSUM_IPV6>
        ether 58:9c:fc:10:56:6c
        inet 198.51.100.224 netmask 0xffffff80 broadcast 198.51.100.255
        inet 192.0.2.1 netmask 0xffffffff broadcast 192.0.2.1 vhid 1
        groups: epair
        carp: BACKUP vhid 1 advbase 1 advskew 0
              peer 198.51.100.2 peer6 ff02::12
        media: Ethernet 10Gbase-T (10Gbase-T <full-duplex>)
        status: active
        nd6 options=829<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL,STABLEADDR>
root@freebsd:~ # jexec carp_uni_v4_one ping -c 1 192.0.2.1
PING 192.0.2.1 (192.0.2.1): 56 data bytes

--- 192.0.2.1 ping statistics ---
1 packets transmitted, 0 packets received, 100.0% packet loss
root@freebsd:~ #

When the test passes, the routing table looks like this:

root@freebsd:~ # jexec carp_uni_v4_one netstat -rn
Routing tables

Internet:
Destination        Gateway            Flags         Netif Expire
192.0.2.1          198.51.100.2       UGH         epair0a
198.51.100.0/25    link#3             U           epair0a
198.51.100.1       link#7             UHS             lo0
198.51.100.128/25  link#5             U           epair1a
198.51.100.129     link#7             UHS             lo0
root@freebsd:~ # jexec carp_uni_v4_one ping -c 1 192.0.2.1
PING 192.0.2.1 (192.0.2.1): 56 data bytes
64 bytes from 192.0.2.1: icmp_seq=0 ttl=64 time=0.027 ms

--- 192.0.2.1 ping statistics ---
1 packets transmitted, 1 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 0.027/0.027/0.027/0.000 ms

So the problem has to do with the routing tables: presumably, the default route should point at the master node.  Sometimes it doesn't.  Isn't this expected?  Both of the jails are running a routed instance, isn't carp_uni_v4_one going to choose the first router which announces itself?
Comment 13 Zhenlei Huang freebsd_committer freebsd_triage 2026-05-01 17:39:28 UTC
(In reply to Mark Johnston from comment #12)
Then that explains. The route table in carp_uni_v4_one is wrong.

> Isn't this expected
No.

> Both of the jails are running a routed instance, isn't carp_uni_v4_one going to
> choose the first router which announces itself?

If things go right ( kernel or routed ), only route to carp MASTER should be announced.


Let me think about it. Maybe I have to rewrite this testcase without routed first.

As for the route announcement ( by routed ) to carp BACKUP, I'll investigate that later.
Comment 14 Zhenlei Huang freebsd_committer freebsd_triage 2026-05-01 19:43:29 UTC
(In reply to Mark Johnston from comment #12)
(In reply to Zhenlei Huang from comment #13)

The test should be stable now with this fix https://reviews.freebsd.org/D56761 .
Comment 15 Mark Johnston freebsd_committer freebsd_triage 2026-05-01 20:08:37 UTC
(In reply to Zhenlei Huang from comment #13)
A dumb question perhaps, but how does being master vs. backup affect routed announcements?
Comment 16 commit-hook freebsd_committer freebsd_triage 2026-05-03 11:04:24 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=9137c66c2ea6cc09e3a6f8a042ecdc5a62e0f39e

commit 9137c66c2ea6cc09e3a6f8a042ecdc5a62e0f39e
Author:     Zhenlei Huang <zlei@FreeBSD.org>
AuthorDate: 2026-05-03 11:02:15 +0000
Commit:     Zhenlei Huang <zlei@FreeBSD.org>
CommitDate: 2026-05-03 11:02:15 +0000

    tests/carp: Rework unicast_v4

    For unicast tests, it is sufficient to use wait_for_carp() to verify
    the setup is sane. Additional sanity checks are not necessarily
    required but can serve purpose for redundancy.

    For some unclear reason routed(8) is advertising route to carp BACKUP.
    That makes the test flaky. Also routed(8) is marked deprecated and may
    be removed from base in the future. Let's just add static route entry
    manually for additional sanity checks.

    Other noticeable changes:
      1. Add atf_check to configuration steps to prevent potential failure
    on setup. That helps diagnosing on failure.
      2. Shorten the names of jails to improve readability.
      3. Prefer `[ifconfig|route|sysctl] -j` over `jexec [ifconfig|route|sysctl]`
    to make the lines shorter.

    PR:             294817
    Reviewed by:    glebius (previous version), pouria, markj
    Fixes:          93fbdef51a13 tests: carp: Update test case unicast_v4 to catch PR 284872
    MFC after:      3 days
    Differential Revision:  https://reviews.freebsd.org/D56761

 tests/sys/netinet/carp.sh | 80 ++++++++++++++++++++++++++---------------------
 1 file changed, 44 insertions(+), 36 deletions(-)
Comment 17 Zhenlei Huang freebsd_committer freebsd_triage 2026-05-06 19:13:47 UTC
(In reply to Mark Johnston from comment #15)
> A dumb question perhaps, but how does being master vs. backup affect routed announcements?

So I debugged and read the source code of routed(8). It turns out routed(8) use sysctl(... NET_RT_IFLIST ) to query the interfaces and the addresses. Unfortunately it does not distinguish the CARP state, hence it insists to advertise an address which is in BACKUP ( CARP ) state. That is apparently a wrong behavior.

Initially I thought routed(8) is to be blamed. But later I think there is a design flaw to query the addresses of an interface ( sysctl NET_RT_IFLIST ).

Indeed an address with BACKUP CARP state is special and should not be used as the source address, nor the destination. It only serves the purpose of configuration of a CARP instance. Unless a process ( typically ifconfig(8) ) want to query the configuration, the address with BACKUP CARP state should be excluded from the result.

I have not checked other routing daemons. The popular ones are bird, FRR and quagga. I'm not sure whether they are affected or not.
Comment 18 Gleb Smirnoff freebsd_committer freebsd_triage 2026-05-06 21:38:43 UTC
NET_RT_IFLIST is a legacy sysctl. Since carp(4) was refactored to not be "an interface" before FreeBSD 10.0-RELEASE, the NET_RT_IFLISTL was added. The libc getifaddrs(3) uses the latter. And most of software uses getifaddrs(3). With netlink(4) even that is considered to be a legacy thing.

routed is probably the single dinosaur that uses NET_RT_IFLIST.
Comment 19 commit-hook freebsd_committer freebsd_triage 2026-05-09 18:52:57 UTC
A commit in branch stable/15 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=107ef0c29503e5be2b81d22930ec0c675efba140

commit 107ef0c29503e5be2b81d22930ec0c675efba140
Author:     Zhenlei Huang <zlei@FreeBSD.org>
AuthorDate: 2026-05-03 11:02:15 +0000
Commit:     Zhenlei Huang <zlei@FreeBSD.org>
CommitDate: 2026-05-09 18:51:12 +0000

    tests/carp: Rework unicast_v4

    For unicast tests, it is sufficient to use wait_for_carp() to verify
    the setup is sane. Additional sanity checks are not necessarily
    required but can serve purpose for redundancy.

    For some unclear reason routed(8) is advertising route to carp BACKUP.
    That makes the test flaky. Also routed(8) is marked deprecated and may
    be removed from base in the future. Let's just add static route entry
    manually for additional sanity checks.

    Other noticeable changes:
      1. Add atf_check to configuration steps to prevent potential failure
    on setup. That helps diagnosing on failure.
      2. Shorten the names of jails to improve readability.
      3. Prefer `[ifconfig|route|sysctl] -j` over `jexec [ifconfig|route|sysctl]`
    to make the lines shorter.

    MFC note: At the time writing, routed(8) does not know carp addresses
    and does not distinguish carp addresses in MASTER|BACKUP|INIT state,
    hence insists advertising the wrong addresses.

    PR:             294817
    Reviewed by:    glebius (previous version), pouria, markj
    Fixes:          93fbdef51a13 tests: carp: Update test case unicast_v4 to catch PR 284872
    MFC after:      3 days
    Differential Revision:  https://reviews.freebsd.org/D56761

    (cherry picked from commit 9137c66c2ea6cc09e3a6f8a042ecdc5a62e0f39e)

 tests/sys/netinet/carp.sh | 80 ++++++++++++++++++++++++++---------------------
 1 file changed, 44 insertions(+), 36 deletions(-)
Comment 20 commit-hook freebsd_committer freebsd_triage 2026-05-10 06:27:20 UTC
A commit in branch stable/14 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=f956c425d4c6b93efefea357f34cd28a7d749db1

commit f956c425d4c6b93efefea357f34cd28a7d749db1
Author:     Zhenlei Huang <zlei@FreeBSD.org>
AuthorDate: 2026-05-03 11:02:15 +0000
Commit:     Zhenlei Huang <zlei@FreeBSD.org>
CommitDate: 2026-05-10 06:25:56 +0000

    tests/carp: Rework unicast_v4

    For unicast tests, it is sufficient to use wait_for_carp() to verify
    the setup is sane. Additional sanity checks are not necessarily
    required but can serve purpose for redundancy.

    For some unclear reason routed(8) is advertising route to carp BACKUP.
    That makes the test flaky. Also routed(8) is marked deprecated and may
    be removed from base in the future. Let's just add static route entry
    manually for additional sanity checks.

    Other noticeable changes:
      1. Add atf_check to configuration steps to prevent potential failure
    on setup. That helps diagnosing on failure.
      2. Shorten the names of jails to improve readability.
      3. Prefer `[ifconfig|route|sysctl] -j` over `jexec [ifconfig|route|sysctl]`
    to make the lines shorter.

    MFC note: At the time writing, routed(8) does not know carp addresses
    and does not distinguish carp addresses in MASTER|BACKUP|INIT state,
    hence insists advertising the wrong addresses.

    PR:             294817
    Reviewed by:    glebius (previous version), pouria, markj
    Fixes:          93fbdef51a13 tests: carp: Update test case unicast_v4 to catch PR 284872
    MFC after:      3 days
    Differential Revision:  https://reviews.freebsd.org/D56761

    (cherry picked from commit 9137c66c2ea6cc09e3a6f8a042ecdc5a62e0f39e)
    (cherry picked from commit 107ef0c29503e5be2b81d22930ec0c675efba140)

 tests/sys/netinet/carp.sh | 80 ++++++++++++++++++++++++++---------------------
 1 file changed, 44 insertions(+), 36 deletions(-)
Comment 21 Siva Mahadevan freebsd_committer freebsd_triage 2026-05-19 21:51:03 UTC
Closing as fixed now that the fixes are in.