Add Console Logger for Ethernet

This commit is contained in:
_Frky 2022-02-12 08:32:44 +01:00
parent 908ff3689d
commit 27f1c4ba65
3 changed files with 34 additions and 8 deletions

View file

@ -52,7 +52,6 @@ pub fn repl<'a, 'b>(
arp_repl.set_target_proto_addr(arp_req.get_sender_proto_addr().to_owned()); arp_repl.set_target_proto_addr(arp_req.get_sender_proto_addr().to_owned());
arp_repl.set_sender_proto_addr(arp_req.get_target_proto_addr().to_owned()); arp_repl.set_sender_proto_addr(arp_req.get_target_proto_addr().to_owned());
masscanned.log.arp_send_isat(&arp_repl); masscanned.log.arp_send_isat(&arp_repl);
masscanned.log.arp_send(&arp_repl);
} }
_ => { _ => {
info!("ARP Operation not handled: {:?}", arp_repl.get_operation()); info!("ARP Operation not handled: {:?}", arp_repl.get_operation());
@ -60,6 +59,7 @@ pub fn repl<'a, 'b>(
return None; return None;
} }
}; };
masscanned.log.arp_send(&arp_repl);
Some(arp_repl) Some(arp_repl)
} }

View file

@ -113,11 +113,7 @@ pub fn reply<'a, 'b>(
if !get_authorized_eth_addr(&masscanned.mac, masscanned.ip_addresses) if !get_authorized_eth_addr(&masscanned.mac, masscanned.ip_addresses)
.contains(&eth_req.get_destination()) .contains(&eth_req.get_destination())
{ {
info!( masscanned.log.eth_drop(eth_req, &client_info);
"Ignoring Ethernet packet from {} to {}",
eth_req.get_source(),
eth_req.get_destination(),
);
return None; return None;
} }
/* Fill client information for this packet with MAC addresses (src and dst) */ /* Fill client information for this packet with MAC addresses (src and dst) */
@ -136,6 +132,7 @@ pub fn reply<'a, 'b>(
eth_repl.set_ethertype(EtherTypes::Arp); eth_repl.set_ethertype(EtherTypes::Arp);
eth_repl.set_payload(arp_repl.packet()); eth_repl.set_payload(arp_repl.packet());
} else { } else {
masscanned.log.eth_drop(eth_req, &client_info);
return None; return None;
} }
} }
@ -145,6 +142,7 @@ pub fn reply<'a, 'b>(
p p
} else { } else {
warn!("error parsing IPv4 packet"); warn!("error parsing IPv4 packet");
masscanned.log.eth_drop(eth_req, &client_info);
return None; return None;
}; };
if let Some(mut ipv4_repl) = if let Some(mut ipv4_repl) =
@ -158,6 +156,7 @@ pub fn reply<'a, 'b>(
eth_repl.set_ethertype(EtherTypes::Ipv4); eth_repl.set_ethertype(EtherTypes::Ipv4);
eth_repl.set_payload(ipv4_repl.packet()); eth_repl.set_payload(ipv4_repl.packet());
} else { } else {
masscanned.log.eth_drop(eth_req, &client_info);
return None; return None;
} }
} }
@ -172,18 +171,20 @@ pub fn reply<'a, 'b>(
eth_repl.set_ethertype(EtherTypes::Ipv6); eth_repl.set_ethertype(EtherTypes::Ipv6);
eth_repl.set_payload(ipv6_repl.packet()); eth_repl.set_payload(ipv6_repl.packet());
} else { } else {
masscanned.log.eth_drop(eth_req, &client_info);
return None; return None;
} }
} }
/* Log & drop unknown network protocol */ /* Log & drop unknown network protocol */
_ => { _ => {
info!("Ethernet type not handled: {:?}", eth_req.get_ethertype()); info!("Ethernet type not handled: {:?}", eth_req.get_ethertype());
masscanned.log.eth_drop(eth_req, &client_info);
return None; return None;
} }
}; };
eth_repl.set_source(masscanned.mac); eth_repl.set_source(masscanned.mac);
eth_repl.set_destination(eth_req.get_source()); eth_repl.set_destination(eth_req.get_source());
debug!("sending Ethernet packet: {:?}", eth_repl); masscanned.log.eth_send(&eth_repl, &client_info);
Some(eth_repl) Some(eth_repl)
} }

View file

@ -51,7 +51,7 @@ impl ConsoleLogger {
pub fn new() -> Self { pub fn new() -> Self {
ConsoleLogger { ConsoleLogger {
arp: true, arp: true,
eth: false, eth: true,
} }
} }
} }
@ -59,6 +59,7 @@ impl ConsoleLogger {
impl Logger for ConsoleLogger { impl Logger for ConsoleLogger {
fn init(&self) { fn init(&self) {
println!("arp::init"); println!("arp::init");
println!("eth::init");
} }
fn arp_enabled(&self) -> bool { fn arp_enabled(&self) -> bool {
self.arp self.arp
@ -83,6 +84,30 @@ impl Logger for ConsoleLogger {
p.get_target_proto_addr() p.get_target_proto_addr()
); );
} }
fn eth_recv(&self, p: &EthernetPacket, _c: &ClientInfo) {
println!(
"eth::recv\t{:}\t{:}\t{:}",
p.get_ethertype(),
p.get_source(),
p.get_destination(),
);
}
fn eth_drop(&self, p: &EthernetPacket, _c: &ClientInfo) {
println!(
"eth::drop\t{:}\t{:}\t{:}",
p.get_ethertype(),
p.get_source(),
p.get_destination(),
);
}
fn eth_send(&self, p: &MutableEthernetPacket, _c: &ClientInfo) {
println!(
"eth::send\t{:}\t{:}\t{:}",
p.get_ethertype(),
p.get_destination(),
p.get_source(),
);
}
} }
pub struct MetaLogger { pub struct MetaLogger {