nic_dump: support ICMP

Print out common header information of the Internet Control Message
Protocol.

Issue #2732
This commit is contained in:
Martin Stein 2018-03-26 14:23:06 +02:00 committed by Christian Helmuth
parent 365bd347a6
commit 009330ab4c
2 changed files with 45 additions and 3 deletions

View File

@ -220,6 +220,11 @@ void Packet_log<Ipv4_packet>::print(Output &output) const
print(output, " ", packet_log(*_pkt.data<Udp_packet const>(~0UL), _cfg));
break;
case Ipv4_packet::Protocol::ICMP:
print(output, " ", packet_log(*_pkt.data<Icmp_packet const>(~0UL), _cfg));
break;
default: ; }
}
@ -295,3 +300,35 @@ void Packet_log<Udp_packet>::print(Output &output) const
print(output, " ", packet_log(*_pkt.data<Dhcp_packet const>(~0UL), _cfg));
}
}
template <>
void Packet_log<Icmp_packet>::print(Output &output) const
{
using Genode::print;
/* print header attributes */
switch (_cfg.icmp) {
case Packet_log_style::COMPREHENSIVE:
print(output, "\033[32mICMP\033[0m");
print(output, " typ ", (unsigned)_pkt.type());
print(output, " cod ", (unsigned)_pkt.code());
print(output, " crc ", _pkt.checksum());
print(output, " roh ", _pkt.rest_of_header());
break;
case Packet_log_style::COMPACT:
print(output, "\033[32mICMP\033[0m ", (unsigned)_pkt.type(), " ",
(unsigned)_pkt.code());
break;
case Packet_log_style::SHORT:
print(output, "\033[32mICMP\033[0m");
break;
default: ;
}
}

View File

@ -22,6 +22,7 @@
#include <net/dhcp.h>
#include <net/ethernet.h>
#include <net/tcp.h>
#include <net/icmp.h>
#include <net/ipv4.h>
namespace Net {
@ -45,18 +46,19 @@ struct Net::Packet_log_config
{
using Style = Packet_log_style;
Style eth, arp, ipv4, dhcp, udp, tcp;
Style eth, arp, ipv4, dhcp, udp, icmp, tcp;
Packet_log_config(Style def = Style::COMPACT)
: eth(def), arp(def), ipv4(def), dhcp(def), udp(def), tcp(def) { }
: eth(def), arp(def), ipv4(def), dhcp(def), udp(def), icmp(def), tcp(def) { }
Packet_log_config(Style eth,
Style arp,
Style ipv4,
Style dhcp,
Style udp,
Style icmp,
Style tcp)
: eth(eth), arp(arp), ipv4(ipv4), dhcp(dhcp), udp(udp), tcp(tcp) { }
: eth(eth), arp(arp), ipv4(ipv4), dhcp(dhcp), udp(udp), icmp(icmp), tcp(tcp) { }
};
@ -114,6 +116,9 @@ namespace Net {
template <>
void Packet_log<Udp_packet>::print(Genode::Output &output) const;
template <>
void Packet_log<Icmp_packet>::print(Genode::Output &output) const;
}
#endif /* _PACKET_LOG_H_ */