git: dc9db1f6b331 - main - netinet: make in_broadcast() and in_ifaddr_broadcast return bool
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 17 Feb 2025 23:31:07 UTC
The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=dc9db1f6b33168c0d02dd1b95f18086d3ec7a7ec commit dc9db1f6b33168c0d02dd1b95f18086d3ec7a7ec Author: Gleb Smirnoff <glebius@FreeBSD.org> AuthorDate: 2025-02-17 23:28:52 +0000 Commit: Gleb Smirnoff <glebius@FreeBSD.org> CommitDate: 2025-02-17 23:28:52 +0000 netinet: make in_broadcast() and in_ifaddr_broadcast return bool While here annotate deprecated condition with __predict_false() and slightly refactor in_broadcast() removing leftovers from old address list locking. Should be no functional change. --- sys/netinet/in.c | 26 +++++++++++--------------- sys/netinet/in.h | 4 ++-- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/sys/netinet/in.c b/sys/netinet/in.c index 28d3e2093c61..0cf148c38575 100644 --- a/sys/netinet/in.c +++ b/sys/netinet/in.c @@ -1269,7 +1269,7 @@ in_ifscrub_all(void) IFNET_RUNLOCK(); } -int +bool in_ifaddr_broadcast(struct in_addr in, struct in_ifaddr *ia) { @@ -1278,7 +1278,8 @@ in_ifaddr_broadcast(struct in_addr in, struct in_ifaddr *ia) * Optionally check for old-style (host 0) broadcast, but * taking into account that RFC 3021 obsoletes it. */ - (V_broadcast_lowest && ia->ia_subnetmask != IN_RFC3021_MASK && + __predict_false(V_broadcast_lowest && + ia->ia_subnetmask != IN_RFC3021_MASK && ntohl(in.s_addr) == ia->ia_subnet)) && /* * Check for an all one subnetmask. These @@ -1289,33 +1290,28 @@ in_ifaddr_broadcast(struct in_addr in, struct in_ifaddr *ia) } /* - * Return 1 if the address might be a local broadcast address. + * Return true if the address might be a local broadcast address. */ -int +bool in_broadcast(struct in_addr in, struct ifnet *ifp) { struct ifaddr *ifa; - int found; NET_EPOCH_ASSERT(); - if (in.s_addr == INADDR_BROADCAST || - in.s_addr == INADDR_ANY) - return (1); + if (in.s_addr == INADDR_BROADCAST || in.s_addr == INADDR_ANY) + return (true); if ((ifp->if_flags & IFF_BROADCAST) == 0) - return (0); - found = 0; + return (false); /* * Look through the list of addresses for a match * with a broadcast address. */ CK_STAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) if (ifa->ifa_addr->sa_family == AF_INET && - in_ifaddr_broadcast(in, (struct in_ifaddr *)ifa)) { - found = 1; - break; - } - return (found); + in_ifaddr_broadcast(in, (struct in_ifaddr *)ifa)) + return (true); + return (false); } /* diff --git a/sys/netinet/in.h b/sys/netinet/in.h index f4fc41178399..e03fe3391388 100644 --- a/sys/netinet/in.h +++ b/sys/netinet/in.h @@ -672,8 +672,8 @@ int getsourcefilter(int, uint32_t, struct sockaddr *, socklen_t, struct ifnet; struct mbuf; /* forward declarations for Standard C */ struct in_ifaddr; -int in_broadcast(struct in_addr, struct ifnet *); -int in_ifaddr_broadcast(struct in_addr, struct in_ifaddr *); +bool in_broadcast(struct in_addr, struct ifnet *); +bool in_ifaddr_broadcast(struct in_addr, struct in_ifaddr *); int in_canforward(struct in_addr); int in_localaddr(struct in_addr); bool in_localip(struct in_addr);