Skip to content
Permalink
Browse files

net: ipv4: Send multicast ICMPv4 reply with correct src address

If we receive a multicast ICMPv4 packet, then send the reply back
with correct source address and not with multicast address.

Fixes #16257

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
  • Loading branch information...
jukkar committed May 20, 2019
1 parent 9a31f28 commit 60cb25d198b9b5ac0cb09cd3cff4211ce811f7e3
Showing with 10 additions and 2 deletions.
  1. +10 −2 subsys/net/ip/icmpv4.c
@@ -64,6 +64,7 @@ static enum net_verdict icmpv4_handle_echo_request(struct net_pkt *pkt,
struct net_icmp_hdr *icmp_hdr)
{
struct net_pkt *reply = NULL;
const struct in_addr *src;
s16_t payload_len;

/* If interface can not select src address based on dst addr
@@ -93,7 +94,14 @@ static enum net_verdict icmpv4_handle_echo_request(struct net_pkt *pkt,
goto drop;
}

if (net_ipv4_create(reply, &ip_hdr->dst, &ip_hdr->src) ||
if (net_ipv4_is_addr_mcast(&ip_hdr->dst)) {
src = net_if_ipv4_select_src_addr(net_pkt_iface(pkt),
&ip_hdr->dst);
} else {
src = &ip_hdr->dst;
}

if (net_ipv4_create(reply, src, &ip_hdr->src) ||
icmpv4_create(reply, NET_ICMPV4_ECHO_REPLY, 0) ||
net_pkt_copy(reply, pkt, payload_len)) {
NET_DBG("DROP: wrong buffer");
@@ -104,7 +112,7 @@ static enum net_verdict icmpv4_handle_echo_request(struct net_pkt *pkt,
net_ipv4_finalize(reply, IPPROTO_ICMP);

NET_DBG("Sending Echo Reply from %s to %s",
log_strdup(net_sprint_ipv4_addr(&ip_hdr->dst)),
log_strdup(net_sprint_ipv4_addr(src)),
log_strdup(net_sprint_ipv4_addr(&ip_hdr->src)));

if (net_send_data(reply) < 0) {

0 comments on commit 60cb25d

Please sign in to comment.
You can’t perform that action at this time.