Add logging function calls for L3 dissectors

This commit is contained in:
_Frky 2022-02-12 10:16:37 +01:00
parent 7e5cb39dd3
commit 7b431950eb
3 changed files with 23 additions and 24 deletions

View file

@ -104,6 +104,9 @@ pub fn reply<'a, 'b>(
masscanned: &Masscanned,
mut client_info: &mut ClientInfo,
) -> Option<MutableEthernetPacket<'b>> {
/* Fill client information for this packet with MAC addresses (src and dst) */
client_info.mac.src = Some(eth_req.get_source());
client_info.mac.dst = Some(eth_req.get_destination());
masscanned.log.eth_recv(eth_req, &client_info);
let mut eth_repl;
/* First, check if the destination MAC address is one of those masscanned
@ -116,9 +119,6 @@ pub fn reply<'a, 'b>(
masscanned.log.eth_drop(eth_req, &client_info);
return None;
}
/* Fill client information for this packet with MAC addresses (src and dst) */
client_info.mac.src = Some(eth_req.get_source());
client_info.mac.dst = Some(eth_req.get_destination());
/* Build next layer payload for answer depending on the incoming packet */
match eth_req.get_ethertype() {
/* Construct answer to ARP request */

View file

@ -39,24 +39,20 @@ pub fn repl<'a, 'b>(
masscanned: &Masscanned,
mut client_info: &mut ClientInfo,
) -> Option<MutableIpv4Packet<'b>> {
debug!("receiving IPv4 packet: {:?}", ip_req);
/* Fill client info with source and dest. IP addresses */
client_info.ip.src = Some(IpAddr::V4(ip_req.get_source()));
client_info.ip.dst = Some(IpAddr::V4(ip_req.get_destination()));
masscanned.log.ipv4_recv(&ip_req, &client_info);
/* If masscanned is configured with IP addresses, then
* check that the dest. IP address of the packet is one of
* those handled by masscanned - otherwise, drop the packet.
**/
if let Some(ip_addr_list) = masscanned.ip_addresses {
if !ip_addr_list.contains(&IpAddr::V4(ip_req.get_destination())) {
info!(
"Ignoring IP packet from {} for {}",
ip_req.get_source(),
ip_req.get_destination()
);
masscanned.log.ipv4_drop(&ip_req, &client_info);
return None;
}
}
/* Fill client info with source and dest. IP addresses */
client_info.ip.src = Some(IpAddr::V4(ip_req.get_source()));
client_info.ip.dst = Some(IpAddr::V4(ip_req.get_destination()));
/* Fill client info with transport layer procotol */
client_info.transport = Some(ip_req.get_next_level_protocol());
let mut ip_repl;
@ -77,6 +73,7 @@ pub fn repl<'a, 'b>(
ip_repl.set_payload(icmp_repl.packet());
ip_repl.set_next_level_protocol(IpNextHeaderProtocols::Icmp);
} else {
masscanned.log.ipv4_drop(&ip_req, &client_info);
return None;
}
}
@ -99,6 +96,7 @@ pub fn repl<'a, 'b>(
ip_repl.set_payload(tcp_repl.packet());
ip_repl.set_next_level_protocol(IpNextHeaderProtocols::Tcp);
} else {
masscanned.log.ipv4_drop(&ip_req, &client_info);
return None;
}
}
@ -123,15 +121,13 @@ pub fn repl<'a, 'b>(
ip_repl.set_payload(udp_repl.packet());
ip_repl.set_next_level_protocol(IpNextHeaderProtocols::Udp);
} else {
masscanned.log.ipv4_drop(&ip_req, &client_info);
return None;
}
}
/* Next layer protocol not handled (yet) - dropping packet */
_ => {
info!(
"IPv4 upper layer not handled: {:?}",
ip_req.get_next_level_protocol()
);
masscanned.log.ipv4_drop(&ip_req, &client_info);
return None;
}
};
@ -150,7 +146,7 @@ pub fn repl<'a, 'b>(
/* FIXME when dest. was a multicast IP address */
ip_repl.set_source(ip_req.get_destination());
ip_repl.set_destination(ip_req.get_source());
debug!("sending IPv4 packet: {:?}", ip_repl);
masscanned.log.ipv4_send(&ip_repl, &client_info);
Some(ip_repl)
}

View file

@ -35,7 +35,10 @@ pub fn repl<'a, 'b>(
masscanned: &Masscanned,
mut client_info: &mut ClientInfo,
) -> Option<MutableIpv6Packet<'b>> {
debug!("receiving IPv6 packet: {:?}", ip_req);
/* Fill client info with source and dest. IP address */
client_info.ip.src = Some(IpAddr::V6(ip_req.get_source()));
client_info.ip.dst = Some(IpAddr::V6(ip_req.get_destination()));
masscanned.log.ipv6_recv(ip_req, client_info);
let src = ip_req.get_source();
let mut dst = ip_req.get_destination();
/* If masscanned is configured with IP addresses, check that
@ -46,7 +49,7 @@ pub fn repl<'a, 'b>(
if !ip_addr_list.contains(&IpAddr::V6(dst))
&& ip_req.get_next_header() != IpNextHeaderProtocols::Icmpv6
{
info!("Ignoring IP packet from {} for {}", &src, &dst);
masscanned.log.ipv6_drop(ip_req, client_info);
return None;
}
}
@ -84,6 +87,7 @@ pub fn repl<'a, 'b>(
ip_repl.set_hop_limit(255);
};
} else {
masscanned.log.ipv6_drop(ip_req, client_info);
return None;
}
}
@ -108,6 +112,7 @@ pub fn repl<'a, 'b>(
ip_repl.set_payload_length(tcp_len as u16);
ip_repl.set_payload(&tcp_repl.packet());
} else {
masscanned.log.ipv6_drop(ip_req, client_info);
return None;
}
}
@ -132,15 +137,13 @@ pub fn repl<'a, 'b>(
ip_repl.set_payload_length(udp_len as u16);
ip_repl.set_payload(&udp_repl.packet());
} else {
masscanned.log.ipv6_drop(ip_req, client_info);
return None;
}
}
/* Other protocols are not handled (yet) - dropping */
_ => {
info!(
"IPv6 upper layer not handled: {:?}",
ip_req.get_next_header()
);
masscanned.log.ipv6_drop(ip_req, client_info);
return None;
}
};
@ -153,7 +156,7 @@ pub fn repl<'a, 'b>(
/* Set packet source and dest. */
ip_repl.set_source(dst);
ip_repl.set_destination(src);
debug!("sending IPv6 packet: {:?}", ip_repl);
masscanned.log.ipv6_send(&ip_repl, client_info);
Some(ip_repl)
}