Skip to content

Commit

Permalink
net: icmp: Fix Echo Replies with unspecified address
Browse files Browse the repository at this point in the history
Fix two issues with sending ICMP Echo Reply for requests sent for
multicast address:
* Use the originator IP address instead of multicast when selecting
  source address for the reply
* In case no address match is found, drop the packet, instead of
  replying with unspecified address.

Signed-off-by: Robert Lubos <[email protected]>
  • Loading branch information
rlubos authored and carlescufi committed Nov 30, 2023
1 parent 8252ec7 commit 222fa42
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion subsys/net/ip/icmpv4.c
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,12 @@ static int icmpv4_handle_echo_request(struct net_icmp_ctx *ctx,
net_ipv4_is_addr_bcast(net_pkt_iface(pkt),
(struct in_addr *)ip_hdr->dst)) {
src = net_if_ipv4_select_src_addr(net_pkt_iface(pkt),
(struct in_addr *)ip_hdr->dst);
(struct in_addr *)ip_hdr->src);

if (net_ipv4_is_addr_unspecified(src)) {
NET_DBG("DROP: No src address match");
goto drop;
}
} else {
src = (struct in_addr *)ip_hdr->dst;
}
Expand Down
7 changes: 6 additions & 1 deletion subsys/net/ip/icmpv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,12 @@ static int icmpv6_handle_echo_request(struct net_icmp_ctx *ctx,

if (net_ipv6_is_addr_mcast((struct in6_addr *)ip_hdr->dst)) {
src = net_if_ipv6_select_src_addr(net_pkt_iface(pkt),
(struct in6_addr *)ip_hdr->dst);
(struct in6_addr *)ip_hdr->src);

if (net_ipv6_is_addr_unspecified(src)) {
NET_DBG("DROP: No src address match");
goto drop;
}
} else {
src = (struct in6_addr *)ip_hdr->dst;
}
Expand Down

0 comments on commit 222fa42

Please sign in to comment.