From ac1d075d73626c263b51c9bc24899270a0bbe87b Mon Sep 17 00:00:00 2001 From: Pankaj Garg Date: Tue, 18 Feb 2020 16:14:20 -0800 Subject: [PATCH] Drop packet if destination is unspecified (0.0.0.0/0) (#8321) --- core/src/cluster_info.rs | 40 ++++++++++++++++++++++++---------------- perf/src/packet.rs | 8 ++++++-- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/core/src/cluster_info.rs b/core/src/cluster_info.rs index beefe8ce6..5e6024794 100644 --- a/core/src/cluster_info.rs +++ b/core/src/cluster_info.rs @@ -1323,20 +1323,24 @@ impl ClusterInfo { .into_iter() .zip(addrs.into_iter()) .for_each(|(response, from_addr)| { - let len = response.len(); - trace!("get updates since response {}", len); - inc_new_counter_debug!("cluster_info-pull_request-rsp", len); - Self::split_gossip_messages(response) - .into_iter() - .for_each(|payload| { - let protocol = Protocol::PullResponse(self_id, payload); - // The remote node may not know its public IP:PORT. Instead of responding to the caller's - // gossip addr, respond to the origin addr. The last origin addr is picked from the list of - // addrs. - packets - .packets - .push(Packet::from_data(&from_addr, protocol)) - }) + if !from_addr.ip().is_unspecified() && from_addr.port() != 0 { + let len = response.len(); + trace!("get updates since response {}", len); + inc_new_counter_debug!("cluster_info-pull_request-rsp", len); + Self::split_gossip_messages(response) + .into_iter() + .for_each(|payload| { + let protocol = Protocol::PullResponse(self_id, payload); + // The remote node may not know its public IP:PORT. Instead of responding to the caller's + // gossip addr, respond to the origin addr. The last origin addr is picked from the list of + // addrs. + packets + .packets + .push(Packet::from_data(&from_addr, protocol)) + }) + } else { + trace!("Dropping Gossip pull response, as destination is unknown"); + } }); if packets.is_empty() { return None; @@ -1413,8 +1417,12 @@ impl ClusterInfo { let pushes: Vec<_> = me.write().unwrap().new_push_requests(); inc_new_counter_debug!("cluster_info-push_message-pushes", pushes.len()); pushes.into_iter().for_each(|(remote_gossip_addr, req)| { - let p = Packet::from_data(&remote_gossip_addr, &req); - packets.packets.push(p); + if !remote_gossip_addr.ip().is_unspecified() && remote_gossip_addr.port() != 0 { + let p = Packet::from_data(&remote_gossip_addr, &req); + packets.packets.push(p); + } else { + trace!("Dropping Gossip push response, as destination is unknown"); + } }); Some(packets) } else { diff --git a/perf/src/packet.rs b/perf/src/packet.rs index eb4f83477..a8debe504 100644 --- a/perf/src/packet.rs +++ b/perf/src/packet.rs @@ -85,8 +85,12 @@ pub fn to_packets_with_destination( ); out.packets.resize(dests_and_data.len(), Packet::default()); for (dest_and_data, o) in dests_and_data.iter().zip(out.packets.iter_mut()) { - if let Err(e) = Packet::populate_packet(o, Some(&dest_and_data.0), &dest_and_data.1) { - error!("Couldn't write to packet {:?}. Data skipped.", e); + if !dest_and_data.0.ip().is_unspecified() && dest_and_data.0.port() != 0 { + if let Err(e) = Packet::populate_packet(o, Some(&dest_and_data.0), &dest_and_data.1) { + error!("Couldn't write to packet {:?}. Data skipped.", e); + } + } else { + trace!("Dropping packet, as destination is unknown"); } } out