From 579477045f2feb4f8592f66c049a052b9976d7a7 Mon Sep 17 00:00:00 2001 From: Jun-ichiro itojun Hagino Date: Mon, 1 Apr 2002 02:44:09 +0000 Subject: cleanup in_broadcast. don't consider /32 addrs as broadcast. --- sys/netinet/in.c | 63 ++++++++++++++++++++++++-------------------------------- 1 file changed, 27 insertions(+), 36 deletions(-) (limited to 'sys') diff --git a/sys/netinet/in.c b/sys/netinet/in.c index 27e3227b61b..54f07f5b797 100644 --- a/sys/netinet/in.c +++ b/sys/netinet/in.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in.c,v 1.24 2002/03/14 01:27:11 millert Exp $ */ +/* $OpenBSD: in.c,v 1.25 2002/04/01 02:44:08 itojun Exp $ */ /* $NetBSD: in.c,v 1.26 1996/02/13 23:41:39 christos Exp $ */ /* @@ -97,7 +97,14 @@ static int in_scrubprefix(struct in_ifaddr *); #ifndef SUBNETSARELOCAL #define SUBNETSARELOCAL 0 #endif + +#ifndef HOSTZEROBROADCAST +#define HOSTZEROBROADCAST 1 +#endif + int subnetsarelocal = SUBNETSARELOCAL; +int hostzeroisbroadcast = HOSTZEROBROADCAST; + /* * Return 1 if an internet address is for a ``local'' host * (one to which we have a connection). If subnetsarelocal @@ -831,16 +838,11 @@ in_broadcast(in, ifp) if (in.s_addr == INADDR_BROADCAST || in.s_addr == INADDR_ANY) return 1; - if (ifp && ((ifp->if_flags & IFF_BROADCAST) == 0)) - return 0; - if (ifp == NULL) - { + if (ifp == NULL) { if_first = ifnet.tqh_first; if_target = 0; - } - else - { + } else { if_first = ifp; if_target = ifp->if_list.tqe_next; } @@ -851,34 +853,23 @@ in_broadcast(in, ifp) * with a broadcast address. * If ifp is NULL, check against all the interfaces. */ - for (ifn = if_first; ifn != if_target; ifn = ifn->if_list.tqe_next) - for (ifa = ifn->if_addrlist.tqh_first; ifa; - ifa = ifa->ifa_list.tqe_next) - if (!ifp) - { - if (ifa->ifa_addr->sa_family == AF_INET && - ((ia->ia_subnetmask != 0xffffffff && - (((ifn->if_flags & IFF_BROADCAST) && - in.s_addr == ia->ia_broadaddr.sin_addr.s_addr) || - in.s_addr == ia->ia_subnet)) || - /* - * Check for old-style (host 0) broadcast. - */ - (in.s_addr == ia->ia_netbroadcast.s_addr || - in.s_addr == ia->ia_net))) - return 1; - } - else - if (ifa->ifa_addr->sa_family == AF_INET && - (((ifn->if_flags & IFF_BROADCAST) && - in.s_addr == ia->ia_broadaddr.sin_addr.s_addr) || - in.s_addr == ia->ia_netbroadcast.s_addr || - /* - * Check for old-style (host 0) broadcast. - */ - in.s_addr == ia->ia_subnet || - in.s_addr == ia->ia_net)) - return 1; + for (ifn = if_first; ifn != if_target; ifn = ifn->if_list.tqe_next) { + if ((ifn->if_flags & IFF_BROADCAST) == 0) + continue; + for (ifa = ifn->if_addrlist.tqh_first; ifa; + ifa = ifa->ifa_list.tqe_next) + if (ifa->ifa_addr->sa_family == AF_INET && + in.s_addr != ia->ia_addr.sin_addr.s_addr && + (in.s_addr == ia->ia_broadaddr.sin_addr.s_addr || + in.s_addr == ia->ia_netbroadcast.s_addr || + (hostzeroisbroadcast && + /* + * Check for old-style (host 0) broadcast. + */ + (in.s_addr == ia->ia_subnet || + in.s_addr == ia->ia_net)))) + return 1; + } return (0); #undef ia } -- cgit v1.2.3