Index | Thread | Search

From:
YASUOKA Masahiko <yasuoka@openbsd.org>
Subject:
SO_BROADCAST is not required
To:
tech@openbsd.org
Date:
Mon, 10 Mar 2025 10:55:24 +0900

Download raw body.

Thread
Hello,

I think SO_BROADCAST flag is needed to send a packet to a broadcast
address.  But actually, our stack doesn't require the flag.  The
behavior was introduced by the the following change on
sys/netinet/ip_output.c .

---
revision 1.103
date: 2001/06/14 18:00:02;  author: provos;  state: Exp;  lines: +9 -4;
limited broadcast 255.255.255.255 was not recognized correctly, reported
by crh@ubiqx.mn.org, fix from NetBSD; okay angelos@
---
(https://cvsweb.openbsd.org/cgi-bin/cvsweb/src/sys/netinet/ip_output.c#rev1.103)

To test the behavior, run tcpdump on the interface of the default
gateway and send a packet to 255.255.255.255 by a command like the
following.

  echo 'AAAA' | nc -u 255.255.255.255 65535


ok? comments?

Index: sys/netinet/ip_output.c
===================================================================
RCS file: /disk/cvs/openbsd/src/sys/netinet/ip_output.c,v
diff -u -p -r1.406 ip_output.c
--- sys/netinet/ip_output.c	2 Mar 2025 21:28:32 -0000	1.406
+++ sys/netinet/ip_output.c	10 Mar 2025 01:40:17 -0000
@@ -246,8 +246,14 @@ reroute:
 	if (IN_MULTICAST(ip->ip_dst.s_addr) ||
 	    (ip->ip_dst.s_addr == INADDR_BROADCAST)) {
 
-		m->m_flags |= (ip->ip_dst.s_addr == INADDR_BROADCAST) ?
-			M_BCAST : M_MCAST;
+		if (ip->ip_dst.s_addr == INADDR_BROADCAST) {
+			if ((flags & IP_ALLOWBROADCAST) == 0) {
+				error = EACCES;
+				goto bad;
+			}
+			m->m_flags |= M_BCAST;
+		} else
+			m->m_flags |= M_MCAST;
 
 		/*
 		 * IP destination address is multicast.  Make sure "dst"