Skip to content

Commit

Permalink
carp: Fix checking IPv4 multicast address
Browse files Browse the repository at this point in the history
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:		1378180 carp: support unicast
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D49053

(cherry picked from commit 1776633438f24df09cb9815650891bcef0152874)
  • Loading branch information
gmshake authored and fichtner committed Feb 25, 2025
1 parent 2640600 commit accbbd1
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions sys/netinet/ip_carp.c
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ carp_input_c(struct mbuf *m, struct carp_header *ch, sa_family_t af, int ttl)
sc = ifa->ifa_carp;
CARP_LOCK(sc);
if (ifa->ifa_addr->sa_family == AF_INET) {
multicast = IN_MULTICAST(sc->sc_carpaddr.s_addr);
multicast = IN_MULTICAST(ntohl(sc->sc_carpaddr.s_addr));
} else {
multicast = IN6_IS_ADDR_MULTICAST(&sc->sc_carpaddr6);
}
Expand Down Expand Up @@ -988,7 +988,7 @@ carp_send_ad_locked(struct carp_softc *sc)
m->m_pkthdr.rcvif = NULL;
m->m_len = len;
M_ALIGN(m, m->m_len);
if (IN_MULTICAST(sc->sc_carpaddr.s_addr))
if (IN_MULTICAST(ntohl(sc->sc_carpaddr.s_addr)))
m->m_flags |= M_MCAST;
ip = mtod(m, struct ip *);
ip->ip_v = IPVERSION;
Expand Down

0 comments on commit accbbd1

Please sign in to comment.