From 1d0c7967211baf2979379404afa80a45b21384e6 Mon Sep 17 00:00:00 2001 From: rstone Date: Thu, 18 Aug 2016 22:59:05 +0000 Subject: [PATCH] Don't check for broadcast IPs on non-bcast pkts in_broadcast() can be quite expensive, so skip calling it if the incoming mbuf wasn't sent to a broadcast L2 address in the first place. Reviewed by: gnn MFC after: 2 months Sponsored by: EMC / Isilon Storage Division Differential Revision: https://reviews.freebsd.org/D7309 --- UPDATING | 8 ++++++++ sys/netinet/udp_usrreq.c | 8 +++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/UPDATING b/UPDATING index cdea211db962..acf07dc9bf38 100644 --- a/UPDATING +++ b/UPDATING @@ -31,6 +31,14 @@ NOTE TO PEOPLE WHO THINK THAT FreeBSD 12.x IS SLOW: disable the most expensive debugging functionality run "ln -s 'abort:false,junk:false' /etc/malloc.conf".) +20160818: + The UDP receive code has been updated to only treat incoming UDP + packets that were addressed to an L2 broadcast address as L3 + broadcast packets. It is not expected that this will affect any + standards-conforming UDP application. The new behaviour can be + disabled by setting the sysctl net.inet.udp.require_l2_bcast to + 0. + 20160818: Remove the openbsd_poll system call. __FreeBSD_version has been bumped because of this. diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c index 173c44ce2a06..f0837cfe8cac 100644 --- a/sys/netinet/udp_usrreq.c +++ b/sys/netinet/udp_usrreq.c @@ -126,6 +126,11 @@ SYSCTL_INT(_net_inet_udp, OID_AUTO, blackhole, CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(udp_blackhole), 0, "Do not send port unreachables for refused connects"); +static VNET_DEFINE(int, udp_require_l2_bcast) = 1; +SYSCTL_INT(_net_inet_udp, OID_AUTO, require_l2_bcast, CTLFLAG_VNET | CTLFLAG_RW, + &VNET_NAME(udp_require_l2_bcast), 0, + "Only treat packets sent to an L2 broadcast address as broadcast packets"); + u_long udp_sendspace = 9216; /* really max datagram size */ SYSCTL_ULONG(_net_inet_udp, UDPCTL_MAXDGRAM, maxdgram, CTLFLAG_RW, &udp_sendspace, 0, "Maximum outgoing UDP datagram size"); @@ -523,7 +528,8 @@ udp_input(struct mbuf **mp, int *offp, int proto) pcbinfo = udp_get_inpcbinfo(proto); if (IN_MULTICAST(ntohl(ip->ip_dst.s_addr)) || - in_broadcast(ip->ip_dst, ifp)) { + ((!VNET_NAME(udp_require_l2_bcast) || m->m_flags & M_BCAST) && + in_broadcast(ip->ip_dst, ifp))) { struct inpcb *last; struct inpcbhead *pcblist; struct ip_moptions *imo;