Drop packet if destination is unspecified (0.0.0.0/0) (#8321)

This commit is contained in:
Pankaj Garg 2020-02-18 16:14:20 -08:00 committed by GitHub
parent 73a278dc64
commit ac1d075d73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 18 deletions

View File

@ -1323,20 +1323,24 @@ impl ClusterInfo {
.into_iter() .into_iter()
.zip(addrs.into_iter()) .zip(addrs.into_iter())
.for_each(|(response, from_addr)| { .for_each(|(response, from_addr)| {
let len = response.len(); if !from_addr.ip().is_unspecified() && from_addr.port() != 0 {
trace!("get updates since response {}", len); let len = response.len();
inc_new_counter_debug!("cluster_info-pull_request-rsp", len); trace!("get updates since response {}", len);
Self::split_gossip_messages(response) inc_new_counter_debug!("cluster_info-pull_request-rsp", len);
.into_iter() Self::split_gossip_messages(response)
.for_each(|payload| { .into_iter()
let protocol = Protocol::PullResponse(self_id, payload); .for_each(|payload| {
// The remote node may not know its public IP:PORT. Instead of responding to the caller's let protocol = Protocol::PullResponse(self_id, payload);
// gossip addr, respond to the origin addr. The last origin addr is picked from the list of // The remote node may not know its public IP:PORT. Instead of responding to the caller's
// addrs. // gossip addr, respond to the origin addr. The last origin addr is picked from the list of
packets // addrs.
.packets packets
.push(Packet::from_data(&from_addr, protocol)) .packets
}) .push(Packet::from_data(&from_addr, protocol))
})
} else {
trace!("Dropping Gossip pull response, as destination is unknown");
}
}); });
if packets.is_empty() { if packets.is_empty() {
return None; return None;
@ -1413,8 +1417,12 @@ impl ClusterInfo {
let pushes: Vec<_> = me.write().unwrap().new_push_requests(); let pushes: Vec<_> = me.write().unwrap().new_push_requests();
inc_new_counter_debug!("cluster_info-push_message-pushes", pushes.len()); inc_new_counter_debug!("cluster_info-push_message-pushes", pushes.len());
pushes.into_iter().for_each(|(remote_gossip_addr, req)| { pushes.into_iter().for_each(|(remote_gossip_addr, req)| {
let p = Packet::from_data(&remote_gossip_addr, &req); if !remote_gossip_addr.ip().is_unspecified() && remote_gossip_addr.port() != 0 {
packets.packets.push(p); 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) Some(packets)
} else { } else {

View File

@ -85,8 +85,12 @@ pub fn to_packets_with_destination<T: Serialize>(
); );
out.packets.resize(dests_and_data.len(), Packet::default()); out.packets.resize(dests_and_data.len(), Packet::default());
for (dest_and_data, o) in dests_and_data.iter().zip(out.packets.iter_mut()) { 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) { if !dest_and_data.0.ip().is_unspecified() && dest_and_data.0.port() != 0 {
error!("Couldn't write to packet {:?}. Data skipped.", e); 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 out