Skip to content

Commit 7798df4

Browse files
committed
net: ipv4: Allow UDP packets with broadcast dst address
Make sure we are able to receive UDP packets with broadcast destination address. If CONFIG_NET_IPV4_ACCEPT_ZERO_BROADCAST is set, then check here also non-standard broadcast address that is described in RFC 1122 chapter 3.3.6. Fixes zephyrproject-rtos#11617 Signed-off-by: Jukka Rissanen <[email protected]>
1 parent 6d4a520 commit 7798df4

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

subsys/net/ip/Kconfig.ipv4

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ config NET_ICMPV4_ACCEPT_BROADCAST
4343
If set, then respond to ICMPv4 echo-request that is sent to
4444
broadcast address.
4545

46+
config NET_IPV4_ACCEPT_ZERO_BROADCAST
47+
bool "Accept 0.0.0.0 broadcast destination address"
48+
help
49+
If set, then accept UDP packets destined to non-standard
50+
0.0.0.0 broadcast address as described in RFC 1122 ch. 3.3.6
51+
4652
config NET_DHCPV4
4753
bool "Enable DHCPv4 client"
4854

subsys/net/ip/ipv4.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,15 @@ enum net_verdict net_ipv4_input(struct net_pkt *pkt)
166166
}
167167

168168
if ((!net_ipv4_is_my_addr(&hdr->dst) &&
169-
!net_ipv4_is_addr_mcast(&hdr->dst)) ||
170-
((hdr->proto == IPPROTO_UDP &&
171-
net_ipv4_addr_cmp(&hdr->dst, net_ipv4_broadcast_address()) &&
172-
!IS_ENABLED(CONFIG_NET_DHCPV4)) ||
173-
(hdr->proto == IPPROTO_TCP &&
174-
net_ipv4_is_addr_bcast(net_pkt_iface(pkt), &hdr->dst)))) {
169+
!net_ipv4_is_addr_mcast(&hdr->dst) &&
170+
!(hdr->proto == IPPROTO_UDP &&
171+
(net_ipv4_addr_cmp(&hdr->dst, net_ipv4_broadcast_address()) ||
172+
/* RFC 1122 ch. 3.3.6 The 0.0.0.0 is non-standard bcast addr */
173+
(IS_ENABLED(CONFIG_NET_IPV4_ACCEPT_ZERO_BROADCAST) &&
174+
net_ipv4_addr_cmp(&hdr->dst,
175+
net_ipv4_unspecified_address()))))) ||
176+
(hdr->proto == IPPROTO_TCP &&
177+
net_ipv4_is_addr_bcast(net_pkt_iface(pkt), &hdr->dst))) {
175178
NET_DBG("DROP: not for me");
176179
goto drop;
177180
}

0 commit comments

Comments
 (0)