Bug 284872 - [carp] Missing byte order correction causing certain unicast announcements to have invalid destination MAC address
Summary: [carp] Missing byte order correction causing certain unicast announcements to...
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 14.2-RELEASE
Hardware: Any Any
: --- Affects Some People
Assignee: Zhenlei Huang
URL: https://github.com/opnsense/src/issue...
Keywords:
Depends on:
Blocks:
 
Reported: 2025-02-18 03:40 UTC by Brett Merrick
Modified: 2025-03-02 11:43 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Brett Merrick 2025-02-18 03:40:43 UTC
sys/netinet/ip_carp.c - line 1248:

if (IN_MULTICAST(sc->sc_carpaddr.s_addr)) m->m_flags |= M_MCAST; 

Should read:

if (IN_MULTICAST(ntohl(sc->sc_carpaddr.s_addr))) m->m_flags |= M_MCAST; 

At present, any announcement where the peer IP address ends in .244-.239 rather than begins with 244.-239. get sent to an invalid multicast destination MAC address.

eg.

Frame 17: 70 bytes on wire (560 bits), 70 bytes captured (560 bits)
Ethernet II, Src: Microsoft_de:ed:00 (00:15:5d:de:ed:00), Dst: IPv4mcast_28:c9:ef (01:00:5e:28:c9:ef)
Internet Protocol Version 4, Src: 192.168.201.238, Dst: 192.168.201.239
Common Address Redundancy Protocol
Comment 1 devnull freebsd_committer freebsd_triage 2025-02-18 06:37:38 UTC
Nice find. There appear to be two instances of this problem:

% git grep -n IN_MULTICAST sys/netinet/ip_carp.c | grep -v ntohl
sys/netinet/ip_carp.c:858:		multicast = IN_MULTICAST(sc->sc_carpaddr.s_addr);
sys/netinet/ip_carp.c:1248:		if (IN_MULTICAST(sc->sc_carpaddr.s_addr))
Comment 2 Zhenlei Huang freebsd_committer freebsd_triage 2025-02-19 07:15:28 UTC
Post fix to https://reviews.freebsd.org/D49053 .
Comment 3 Zhenlei Huang freebsd_committer freebsd_triage 2025-02-19 07:41:00 UTC
Downstream (OPNsense) report: https://github.com/opnsense/src/issues/239
Comment 4 commit-hook freebsd_committer freebsd_triage 2025-02-22 19:29:02 UTC
A commit in branch main references this bug:

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

commit 1776633438f24df09cb9815650891bcef0152874
Author:     Zhenlei Huang <zlei@FreeBSD.org>
AuthorDate: 2025-02-22 19:26:33 +0000
Commit:     Zhenlei Huang <zlei@FreeBSD.org>
CommitDate: 2025-02-22 19:26:33 +0000

    carp: Fix checking IPv4 multicast address

    An IPv4 address stored in `struct in_addr` is in network byte order but
    `IN_MULTICAST` wants host order.

    PR:             284872
    Reported by:    Steven Perreau
    Reported by:    Brett Merrick <brett.merrick@itcollective.nz>
    Reviewed by:    Franco Fichtner <franco@opnsense.org>, ae, kp, glebius
    Tested by:      Steven Perreau
    Fixes:          137818006de5 carp: support unicast
    MFC after:      3 days
    Differential Revision:  https://reviews.freebsd.org/D49053

 sys/netinet/ip_carp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Comment 5 commit-hook freebsd_committer freebsd_triage 2025-02-22 19:29:06 UTC
A commit in branch main references this bug:

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

commit 93fbdef51a13b8facac3633f55804a59ca27f635
Author:     Zhenlei Huang <zlei@FreeBSD.org>
AuthorDate: 2025-02-22 19:26:32 +0000
Commit:     Zhenlei Huang <zlei@FreeBSD.org>
CommitDate: 2025-02-22 19:26:32 +0000

    tests: carp: Update test case unicast_v4 to catch PR 284872

    In the current test case unicast_v4, host one acts as a router, but it
    uses if_bridge(4) to verify the reachability to CARP master.
    Unfortunately, if_bridge(4) brings the two CARP hosts into the same
    broadcast domain, thus with an unusual (undocumented) setup, one host
    is in unicast mode but another one in multicast, or two hosts are both
    in multicast mode, the test case can falsely report success.

    Fix that by propagating route via routed(8).

    PR 284872 shows that CARP(4) happens to send packets with multicast
    destination when the unicast peer address is in the range x.x.x.224 ~
    x.x.x.239. Update the peer address in test case to catch that bug.

    PR:             284872
    Reviewed by:    kp
    MFC after:      3 days
    Differential Revision:  https://reviews.freebsd.org/D49076

 tests/sys/netinet/carp.sh | 38 +++++++++++++++++++++-----------------
 1 file changed, 21 insertions(+), 17 deletions(-)
Comment 6 commit-hook freebsd_committer freebsd_triage 2025-02-25 04:02:51 UTC
A commit in branch stable/14 references this bug:

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

commit cad2df3e90d19b083de11f940b20678716811459
Author:     Zhenlei Huang <zlei@FreeBSD.org>
AuthorDate: 2025-02-22 19:26:33 +0000
Commit:     Zhenlei Huang <zlei@FreeBSD.org>
CommitDate: 2025-02-25 04:01:22 +0000

    carp: Fix checking IPv4 multicast address

    An IPv4 address stored in `struct in_addr` is in network byte order but
    `IN_MULTICAST` wants host order.

    PR:             284872
    Reported by:    Steven Perreau
    Reported by:    Brett Merrick <brett.merrick@itcollective.nz>
    Reviewed by:    Franco Fichtner <franco@opnsense.org>, ae, kp, glebius
    Tested by:      Steven Perreau
    Fixes:          137818006de5 carp: support unicast
    MFC after:      3 days
    Differential Revision:  https://reviews.freebsd.org/D49053

    (cherry picked from commit 1776633438f24df09cb9815650891bcef0152874)

 sys/netinet/ip_carp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Comment 7 commit-hook freebsd_committer freebsd_triage 2025-02-25 04:02:54 UTC
A commit in branch stable/14 references this bug:

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

commit d8d8b9c9ca387217bf70b2db1038529d80af280b
Author:     Zhenlei Huang <zlei@FreeBSD.org>
AuthorDate: 2025-02-22 19:26:32 +0000
Commit:     Zhenlei Huang <zlei@FreeBSD.org>
CommitDate: 2025-02-25 04:01:22 +0000

    tests: carp: Update test case unicast_v4 to catch PR 284872

    In the current test case unicast_v4, host one acts as a router, but it
    uses if_bridge(4) to verify the reachability to CARP master.
    Unfortunately, if_bridge(4) brings the two CARP hosts into the same
    broadcast domain, thus with an unusual (undocumented) setup, one host
    is in unicast mode but another one in multicast, or two hosts are both
    in multicast mode, the test case can falsely report success.

    Fix that by propagating route via routed(8).

    PR 284872 shows that CARP(4) happens to send packets with multicast
    destination when the unicast peer address is in the range x.x.x.224 ~
    x.x.x.239. Update the peer address in test case to catch that bug.

    PR:             284872
    Reviewed by:    kp
    MFC after:      3 days
    Differential Revision:  https://reviews.freebsd.org/D49076

    (cherry picked from commit 93fbdef51a13b8facac3633f55804a59ca27f635)

 tests/sys/netinet/carp.sh | 38 +++++++++++++++++++++-----------------
 1 file changed, 21 insertions(+), 17 deletions(-)
Comment 8 Mark Linimon freebsd_committer freebsd_triage 2025-03-02 11:43:41 UTC
^Triage: assign to committer that resolved.