/*
* \brief Configurable print functionality for network packets
* \author Stefan Kalkowski
* \author Martin Stein
* \date 2017-09-27
*/
/*
* Copyright (C) 2017 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU Affero General Public License version 3.
*/
#ifndef _PACKET_LOG_H_
#define _PACKET_LOG_H_
/* Genode includes */
#include
#include
#include
#include
#include
#include
#include
namespace Net {
enum class Packet_log_style : Genode::uint8_t
{
NONE, SHORT, COMPACT, COMPREHENSIVE,
};
struct Packet_log_config;
template
struct Packet_log;
}
/**
* Configuration for the print functionality of network packets
*/
struct Net::Packet_log_config
{
using Style = Packet_log_style;
Style eth, arp, ipv4, dhcp, udp, tcp;
Packet_log_config(Style def = Style::COMPACT)
: eth(def), arp(def), ipv4(def), dhcp(def), udp(def), tcp(def) { }
Packet_log_config(Style eth,
Style arp,
Style ipv4,
Style dhcp,
Style udp,
Style tcp)
: eth(eth), arp(arp), ipv4(ipv4), dhcp(dhcp), udp(udp), tcp(tcp) { }
};
/**
* Wrapper for network packets to configure their print functionality
*/
template
class Net::Packet_log
{
private:
PKT const &_pkt;
Packet_log_config const &_cfg;
public:
Packet_log(PKT const &pkt, Packet_log_config const &cfg)
: _pkt(pkt), _cfg(cfg) { }
/*********
** log **
*********/
void print(Genode::Output &output) const;
};
namespace Net {
/* getting an instances via a function enables template-arg deduction */
template
Packet_log packet_log(PKT const &pkt, Packet_log_config const &cfg) {
return Packet_log(pkt, cfg); }
/************************************************************
** Packet log specializations for all supported protocols **
************************************************************/
template <>
void Packet_log::print(Genode::Output &output) const;
template <>
void Packet_log::print(Genode::Output &output) const;
template <>
void Packet_log::print(Genode::Output &output) const;
template <>
void Packet_log::print(Genode::Output &output) const;
template <>
void Packet_log::print(Genode::Output &output) const;
template <>
void Packet_log::print(Genode::Output &output) const;
}
#endif /* _PACKET_LOG_H_ */