nic_router: add verbose_packets per domain

A domain logs its packets if one of the global 'verbose_packets' or its local
'verbose_packets' is switched on.

Ref #2670
This commit is contained in:
Martin Stein 2018-02-04 15:58:25 +01:00 committed by Christian Helmuth
parent bd16f89617
commit 2a77976164
6 changed files with 38 additions and 23 deletions

View File

@ -224,7 +224,11 @@ append config {
<report bytes="yes" config="yes" interval_sec="60" /> <report bytes="yes" config="yes" interval_sec="60" />
<domain name="uplink" interface="10.0.2.55/24" gateway="10.0.2.1"> <domain name="uplink"
interface="10.0.2.55/24"
gateway="10.0.2.1"
verbose_packets="no">
<tcp-forward port="80" domain="http_server_1" to="192.168.1.18" /> <tcp-forward port="80" domain="http_server_1" to="192.168.1.18" />
<tcp-forward port="8080" domain="http_server_2" to="192.168.2.72" /> <tcp-forward port="8080" domain="http_server_2" to="192.168.2.72" />
<udp-forward port="1" domain="udp_server_2" to="18.17.16.15" /> <udp-forward port="1" domain="udp_server_2" to="18.17.16.15" />

View File

@ -377,6 +377,12 @@ sent by the router (ETH, IPv4, ARP, UDP, TCP, DHCP).
Log most important changes in the state of a domain (number of nic sessions Log most important changes in the state of a domain (number of nic sessions
connected, current IPv4 config). connected, current IPv4 config).
! <config>
! <domain verbose_packets="yes" ... >
! <config/>
Log most important protocol header fields of each packet that is received or
sent at a specific domain (ETH, IPv4, ARP, UDP, TCP, DHCP).
Examples Examples
######## ########

View File

@ -140,9 +140,10 @@
<xs:element name="udp-forward" type="L3_forward_rule" /> <xs:element name="udp-forward" type="L3_forward_rule" />
</xs:choice> </xs:choice>
<xs:attribute name="name" type="Domain_name" /> <xs:attribute name="name" type="Domain_name" />
<xs:attribute name="interface" type="Ipv4_address_prefix" /> <xs:attribute name="interface" type="Ipv4_address_prefix" />
<xs:attribute name="gateway" type="Ipv4_address" /> <xs:attribute name="gateway" type="Ipv4_address" />
<xs:attribute name="verbose_packets" type="Boolean" />
</xs:complexType> </xs:complexType>
</xs:element><!-- domain --> </xs:element><!-- domain -->

View File

@ -110,7 +110,9 @@ Domain::Domain(Configuration &config, Xml_node const node, Allocator &alloc)
Domain_base(node), _avl_member(_name, *this), _config(config), Domain_base(node), _avl_member(_name, *this), _config(config),
_node(node), _alloc(alloc), _node(node), _alloc(alloc),
_ip_config(_node.attribute_value("interface", Ipv4_address_prefix()), _ip_config(_node.attribute_value("interface", Ipv4_address_prefix()),
_node.attribute_value("gateway", Ipv4_address())) _node.attribute_value("gateway", Ipv4_address())),
_verbose_packets(_node.attribute_value("verbose_packets", false) ||
_config.verbose_packets())
{ {
if (_name == Domain_name()) { if (_name == Domain_name()) {
error("Missing name attribute in domain node"); error("Missing name attribute in domain node");

View File

@ -104,6 +104,7 @@ class Net::Domain : public Domain_base
Link_side_tree _udp_links { }; Link_side_tree _udp_links { };
Genode::size_t _tx_bytes { 0 }; Genode::size_t _tx_bytes { 0 };
Genode::size_t _rx_bytes { 0 }; Genode::size_t _rx_bytes { 0 };
bool const _verbose_packets { false };
void _read_forward_rules(Genode::Cstring const &protocol, void _read_forward_rules(Genode::Cstring const &protocol,
Domain_tree &domains, Domain_tree &domains,
@ -164,22 +165,23 @@ class Net::Domain : public Domain_base
** Accessors ** ** Accessors **
***************/ ***************/
Ipv4_config const &ip_config() const { return *_ip_config; } bool verbose_packets() const { return _verbose_packets; }
Domain_name const &name() { return _name; } Ipv4_config const &ip_config() const { return *_ip_config; }
Ip_rule_list &ip_rules() { return _ip_rules; } Domain_name const &name() { return _name; }
Forward_rule_tree &tcp_forward_rules() { return _tcp_forward_rules; } Ip_rule_list &ip_rules() { return _ip_rules; }
Forward_rule_tree &udp_forward_rules() { return _udp_forward_rules; } Forward_rule_tree &tcp_forward_rules() { return _tcp_forward_rules; }
Transport_rule_list &tcp_rules() { return _tcp_rules; } Forward_rule_tree &udp_forward_rules() { return _udp_forward_rules; }
Transport_rule_list &udp_rules() { return _udp_rules; } Transport_rule_list &tcp_rules() { return _tcp_rules; }
Nat_rule_tree &nat_rules() { return _nat_rules; } Transport_rule_list &udp_rules() { return _udp_rules; }
List<Interface> &interfaces() { return _interfaces; } Nat_rule_tree &nat_rules() { return _nat_rules; }
Configuration &config() const { return _config; } List<Interface> &interfaces() { return _interfaces; }
Domain_avl_member &avl_member() { return _avl_member; } Configuration &config() const { return _config; }
Dhcp_server &dhcp_server() { return _dhcp_server.deref(); } Domain_avl_member &avl_member() { return _avl_member; }
Arp_cache &arp_cache() { return _arp_cache; } Dhcp_server &dhcp_server() { return _dhcp_server.deref(); }
Arp_waiter_list &foreign_arp_waiters() { return _foreign_arp_waiters; } Arp_cache &arp_cache() { return _arp_cache; }
Link_side_tree &tcp_links() { return _tcp_links; } Arp_waiter_list &foreign_arp_waiters() { return _foreign_arp_waiters; }
Link_side_tree &udp_links() { return _udp_links; } Link_side_tree &tcp_links() { return _tcp_links; }
Link_side_tree &udp_links() { return _udp_links; }
}; };

View File

@ -879,7 +879,7 @@ void Interface::_handle_eth(void *const eth_base,
/* inspect and handle ethernet frame */ /* inspect and handle ethernet frame */
try { try {
Ethernet_frame *const eth = reinterpret_cast<Ethernet_frame *>(eth_base); Ethernet_frame *const eth = reinterpret_cast<Ethernet_frame *>(eth_base);
if (_config().verbose_packets()) { if (_domain.verbose_packets()) {
log("(router <- ", _domain, ") ", *eth); } log("(router <- ", _domain, ") ", *eth); }
if (_domain.ip_config().valid) { if (_domain.ip_config().valid) {
@ -953,7 +953,7 @@ void Interface::_send_submit_pkt(Packet_descriptor &pkt,
{ {
_source().submit_packet(pkt); _source().submit_packet(pkt);
_domain.raise_tx_bytes(pkt_size); _domain.raise_tx_bytes(pkt_size);
if (_config().verbose_packets()) { if (_domain.verbose_packets()) {
log("(", _domain, " <- router) ", log("(", _domain, " <- router) ",
*reinterpret_cast<Ethernet_frame *>(pkt_base)); *reinterpret_cast<Ethernet_frame *>(pkt_base));
} }