2016-09-12 12:55:12 +02:00
|
|
|
/*
|
|
|
|
* \brief Reflects an effective domain configuration node
|
|
|
|
* \author Martin Stein
|
|
|
|
* \date 2016-08-19
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 13:23:52 +01:00
|
|
|
* Copyright (C) 2016-2017 Genode Labs GmbH
|
2016-09-12 12:55:12 +02:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
2017-02-20 13:23:52 +01:00
|
|
|
* under the terms of the GNU Affero General Public License version 3.
|
2016-09-12 12:55:12 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _DOMAIN_H_
|
|
|
|
#define _DOMAIN_H_
|
|
|
|
|
|
|
|
/* local includes */
|
2019-10-03 20:30:26 +02:00
|
|
|
#include "forward_rule.h"
|
|
|
|
#include "transport_rule.h"
|
|
|
|
#include "nat_rule.h"
|
|
|
|
#include "ip_rule.h"
|
|
|
|
#include "arp_cache.h"
|
|
|
|
#include "port_allocator.h"
|
|
|
|
#include "pointer.h"
|
|
|
|
#include "ipv4_config.h"
|
|
|
|
#include "dhcp_server.h"
|
|
|
|
#include "interface.h"
|
|
|
|
#include "avl_string_tree.h"
|
2016-09-12 12:55:12 +02:00
|
|
|
|
|
|
|
/* Genode includes */
|
nic_router: DHCP client functionality
If the attribute 'interface' is not set in a 'domain' tag, the router tries to
dynamically receive and maintain an IP configuration for that domain by using
DHCP in the client role at all interfaces that connect to the domain. In the
DHCP discover phase, the router simply chooses the first DHCP offer that
arrives. So, no comparison of different DHCP offers is done. In the DHCP
request phase, the server is expected to provide an IP address, a gateway, a
subnet mask, and an IP lease time to the router. If anything substantial goes
wrong during a DHCP exchange, the router discards the outcome of the exchange
and goes back to the DHCP discover phase. At any time where there is no valid
IP configuration present at a domain, the domain does only act as DHCP client
and all other router functionality is disabled for the domain. A domain cannot
act as DHCP client and DHCP server at once. So, a 'domain' tag must either
have an 'interface' attribute or must not contain a 'dhcp-server' tag.
Ref #2534
2017-10-16 11:31:43 +02:00
|
|
|
#include <util/reconstructible.h>
|
2016-09-12 12:55:12 +02:00
|
|
|
|
2017-12-14 16:24:42 +01:00
|
|
|
namespace Genode {
|
|
|
|
|
|
|
|
class Xml_generator;
|
|
|
|
class Allocator;
|
|
|
|
}
|
2016-09-12 12:55:12 +02:00
|
|
|
|
|
|
|
namespace Net {
|
|
|
|
|
|
|
|
class Interface;
|
|
|
|
class Configuration;
|
|
|
|
class Domain_base;
|
|
|
|
class Domain;
|
|
|
|
using Domain_name = Genode::String<160>;
|
2018-06-01 21:45:18 +02:00
|
|
|
class Domain_tree;
|
2018-09-16 14:21:38 +02:00
|
|
|
class Domain_link_stats;
|
|
|
|
class Domain_object_stats;
|
2016-09-12 12:55:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-16 14:21:38 +02:00
|
|
|
struct Net::Domain_object_stats
|
|
|
|
{
|
|
|
|
Genode::size_t destroyed { 0 };
|
|
|
|
|
|
|
|
void dissolve_interface(Interface_object_stats const &stats);
|
|
|
|
|
|
|
|
void report(Genode::Xml_generator &xml);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct Net::Domain_link_stats : Domain_object_stats
|
|
|
|
{
|
|
|
|
Genode::size_t refused_for_ram { 0 };
|
|
|
|
Genode::size_t refused_for_ports { 0 };
|
|
|
|
Genode::size_t destroyed { 0 };
|
|
|
|
|
|
|
|
void dissolve_interface(Interface_link_stats const &stats);
|
|
|
|
|
|
|
|
void report(Genode::Xml_generator &xml);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-06-01 21:45:18 +02:00
|
|
|
class Net::Domain_tree : public Avl_string_tree<Domain, Domain_name> { };
|
2016-09-12 12:55:12 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Net::Domain_base
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
|
|
|
|
Domain_name const _name;
|
|
|
|
|
2016-12-06 14:39:17 +01:00
|
|
|
Domain_base(Genode::Xml_node const node);
|
2016-09-12 12:55:12 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-03-23 02:43:00 +01:00
|
|
|
class Net::Domain : public Domain_base,
|
2018-06-01 21:45:18 +02:00
|
|
|
public List<Domain>::Element,
|
|
|
|
public Genode::Avl_string_base
|
2016-09-12 12:55:12 +02:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
nic_router: DHCP client functionality
If the attribute 'interface' is not set in a 'domain' tag, the router tries to
dynamically receive and maintain an IP configuration for that domain by using
DHCP in the client role at all interfaces that connect to the domain. In the
DHCP discover phase, the router simply chooses the first DHCP offer that
arrives. So, no comparison of different DHCP offers is done. In the DHCP
request phase, the server is expected to provide an IP address, a gateway, a
subnet mask, and an IP lease time to the router. If anything substantial goes
wrong during a DHCP exchange, the router discards the outcome of the exchange
and goes back to the DHCP discover phase. At any time where there is no valid
IP configuration present at a domain, the domain does only act as DHCP client
and all other router functionality is disabled for the domain. A domain cannot
act as DHCP client and DHCP server at once. So, a 'domain' tag must either
have an 'interface' attribute or must not contain a 'dhcp-server' tag.
Ref #2534
2017-10-16 11:31:43 +02:00
|
|
|
Configuration &_config;
|
|
|
|
Genode::Xml_node _node;
|
|
|
|
Genode::Allocator &_alloc;
|
2018-03-23 02:43:00 +01:00
|
|
|
Ip_rule_list _ip_rules { };
|
|
|
|
Forward_rule_tree _tcp_forward_rules { };
|
|
|
|
Forward_rule_tree _udp_forward_rules { };
|
|
|
|
Transport_rule_list _tcp_rules { };
|
|
|
|
Transport_rule_list _udp_rules { };
|
2018-03-28 02:49:44 +02:00
|
|
|
Ip_rule_list _icmp_rules { };
|
2018-03-23 02:43:00 +01:00
|
|
|
Port_allocator _tcp_port_alloc { };
|
|
|
|
Port_allocator _udp_port_alloc { };
|
2018-03-28 02:49:44 +02:00
|
|
|
Port_allocator _icmp_port_alloc { };
|
2018-03-23 02:43:00 +01:00
|
|
|
Nat_rule_tree _nat_rules { };
|
|
|
|
Interface_list _interfaces { };
|
|
|
|
unsigned long _interface_cnt { 0 };
|
|
|
|
Pointer<Dhcp_server> _dhcp_server { };
|
nic_router: DHCP client functionality
If the attribute 'interface' is not set in a 'domain' tag, the router tries to
dynamically receive and maintain an IP configuration for that domain by using
DHCP in the client role at all interfaces that connect to the domain. In the
DHCP discover phase, the router simply chooses the first DHCP offer that
arrives. So, no comparison of different DHCP offers is done. In the DHCP
request phase, the server is expected to provide an IP address, a gateway, a
subnet mask, and an IP lease time to the router. If anything substantial goes
wrong during a DHCP exchange, the router discards the outcome of the exchange
and goes back to the DHCP discover phase. At any time where there is no valid
IP configuration present at a domain, the domain does only act as DHCP client
and all other router functionality is disabled for the domain. A domain cannot
act as DHCP client and DHCP server at once. So, a 'domain' tag must either
have an 'interface' attribute or must not contain a 'dhcp-server' tag.
Ref #2534
2017-10-16 11:31:43 +02:00
|
|
|
Genode::Reconstructible<Ipv4_config> _ip_config;
|
2018-05-16 13:55:13 +02:00
|
|
|
bool const _ip_config_dynamic { !ip_config().valid };
|
2018-03-23 02:43:00 +01:00
|
|
|
List<Domain> _ip_config_dependents { };
|
|
|
|
Arp_cache _arp_cache { *this };
|
|
|
|
Arp_waiter_list _foreign_arp_waiters { };
|
|
|
|
Link_side_tree _tcp_links { };
|
|
|
|
Link_side_tree _udp_links { };
|
2018-03-28 02:49:44 +02:00
|
|
|
Link_side_tree _icmp_links { };
|
2018-03-23 02:43:00 +01:00
|
|
|
Genode::size_t _tx_bytes { 0 };
|
|
|
|
Genode::size_t _rx_bytes { 0 };
|
2018-06-18 19:12:53 +02:00
|
|
|
bool const _verbose_packets;
|
2018-06-19 16:20:47 +02:00
|
|
|
bool const _verbose_packet_drop;
|
2018-06-18 19:04:40 +02:00
|
|
|
bool const _icmp_echo_server;
|
2018-05-10 13:38:45 +02:00
|
|
|
Genode::Session_label const _label;
|
2018-09-16 14:21:38 +02:00
|
|
|
Domain_link_stats _udp_stats { };
|
|
|
|
Domain_link_stats _tcp_stats { };
|
|
|
|
Domain_link_stats _icmp_stats { };
|
|
|
|
Domain_object_stats _arp_stats { };
|
|
|
|
Domain_object_stats _dhcp_stats { };
|
2016-09-12 12:55:12 +02:00
|
|
|
|
|
|
|
void _read_forward_rules(Genode::Cstring const &protocol,
|
|
|
|
Domain_tree &domains,
|
2016-12-06 14:39:17 +01:00
|
|
|
Genode::Xml_node const node,
|
2016-09-12 12:55:12 +02:00
|
|
|
char const *type,
|
|
|
|
Forward_rule_tree &rules);
|
|
|
|
|
|
|
|
void _read_transport_rules(Genode::Cstring const &protocol,
|
|
|
|
Domain_tree &domains,
|
2016-12-06 14:39:17 +01:00
|
|
|
Genode::Xml_node const node,
|
2016-09-12 12:55:12 +02:00
|
|
|
char const *type,
|
|
|
|
Transport_rule_list &rules);
|
|
|
|
|
2018-05-27 01:10:52 +02:00
|
|
|
void _invalid(char const *reason) const;
|
|
|
|
|
2018-06-13 13:28:22 +02:00
|
|
|
void _log_ip_config() const;
|
|
|
|
|
2018-03-19 19:16:17 +01:00
|
|
|
void __FIXME__dissolve_foreign_arp_waiters();
|
|
|
|
|
2016-09-12 12:55:12 +02:00
|
|
|
public:
|
|
|
|
|
2018-05-24 19:06:30 +02:00
|
|
|
struct Invalid : Genode::Exception { };
|
|
|
|
struct Ip_config_static : Genode::Exception { };
|
|
|
|
struct No_next_hop : Genode::Exception { };
|
2016-09-12 12:55:12 +02:00
|
|
|
|
|
|
|
Domain(Configuration &config,
|
2016-12-06 14:39:17 +01:00
|
|
|
Genode::Xml_node const node,
|
2016-09-12 12:55:12 +02:00
|
|
|
Genode::Allocator &alloc);
|
|
|
|
|
2017-10-06 13:00:05 +02:00
|
|
|
~Domain();
|
|
|
|
|
2018-03-22 21:06:11 +01:00
|
|
|
void init(Domain_tree &domains);
|
2016-09-12 12:55:12 +02:00
|
|
|
|
2018-06-02 00:18:02 +02:00
|
|
|
void deinit();
|
|
|
|
|
2016-09-12 12:55:12 +02:00
|
|
|
Ipv4_address const &next_hop(Ipv4_address const &ip) const;
|
|
|
|
|
2018-05-16 13:55:13 +02:00
|
|
|
void ip_config(Ipv4_config const &ip_config);
|
|
|
|
|
nic_router: DHCP client functionality
If the attribute 'interface' is not set in a 'domain' tag, the router tries to
dynamically receive and maintain an IP configuration for that domain by using
DHCP in the client role at all interfaces that connect to the domain. In the
DHCP discover phase, the router simply chooses the first DHCP offer that
arrives. So, no comparison of different DHCP offers is done. In the DHCP
request phase, the server is expected to provide an IP address, a gateway, a
subnet mask, and an IP lease time to the router. If anything substantial goes
wrong during a DHCP exchange, the router discards the outcome of the exchange
and goes back to the DHCP discover phase. At any time where there is no valid
IP configuration present at a domain, the domain does only act as DHCP client
and all other router functionality is disabled for the domain. A domain cannot
act as DHCP client and DHCP server at once. So, a 'domain' tag must either
have an 'interface' attribute or must not contain a 'dhcp-server' tag.
Ref #2534
2017-10-16 11:31:43 +02:00
|
|
|
void ip_config(Ipv4_address ip,
|
|
|
|
Ipv4_address subnet_mask,
|
2018-03-23 00:30:04 +01:00
|
|
|
Ipv4_address gateway,
|
|
|
|
Ipv4_address dns_server);
|
nic_router: DHCP client functionality
If the attribute 'interface' is not set in a 'domain' tag, the router tries to
dynamically receive and maintain an IP configuration for that domain by using
DHCP in the client role at all interfaces that connect to the domain. In the
DHCP discover phase, the router simply chooses the first DHCP offer that
arrives. So, no comparison of different DHCP offers is done. In the DHCP
request phase, the server is expected to provide an IP address, a gateway, a
subnet mask, and an IP lease time to the router. If anything substantial goes
wrong during a DHCP exchange, the router discards the outcome of the exchange
and goes back to the DHCP discover phase. At any time where there is no valid
IP configuration present at a domain, the domain does only act as DHCP client
and all other router functionality is disabled for the domain. A domain cannot
act as DHCP client and DHCP server at once. So, a 'domain' tag must either
have an 'interface' attribute or must not contain a 'dhcp-server' tag.
Ref #2534
2017-10-16 11:31:43 +02:00
|
|
|
|
|
|
|
void discard_ip_config();
|
|
|
|
|
2018-05-16 13:55:13 +02:00
|
|
|
void try_reuse_ip_config(Domain const &domain);
|
|
|
|
|
2017-12-13 17:02:01 +01:00
|
|
|
Link_side_tree &links(L3_protocol const protocol);
|
|
|
|
|
2018-02-07 18:38:49 +01:00
|
|
|
void attach_interface(Interface &interface);
|
2017-12-13 17:02:01 +01:00
|
|
|
|
2018-02-07 18:38:49 +01:00
|
|
|
void detach_interface(Interface &interface);
|
2017-12-13 17:02:01 +01:00
|
|
|
|
2017-12-14 16:24:42 +01:00
|
|
|
void raise_rx_bytes(Genode::size_t bytes) { _rx_bytes += bytes; }
|
|
|
|
|
|
|
|
void raise_tx_bytes(Genode::size_t bytes) { _tx_bytes += bytes; }
|
|
|
|
|
|
|
|
void report(Genode::Xml_generator &xml);
|
|
|
|
|
2016-09-12 12:55:12 +02:00
|
|
|
|
|
|
|
/*********
|
|
|
|
** log **
|
|
|
|
*********/
|
|
|
|
|
|
|
|
void print(Genode::Output &output) const;
|
|
|
|
|
|
|
|
|
|
|
|
/***************
|
|
|
|
** Accessors **
|
|
|
|
***************/
|
|
|
|
|
2018-06-19 16:20:47 +02:00
|
|
|
bool verbose_packets() const { return _verbose_packets; }
|
|
|
|
bool verbose_packet_drop() const { return _verbose_packet_drop; }
|
|
|
|
bool icmp_echo_server() const { return _icmp_echo_server; }
|
|
|
|
Genode::Session_label const &label() const { return _label; }
|
|
|
|
Ipv4_config const &ip_config() const { return *_ip_config; }
|
|
|
|
List<Domain> &ip_config_dependents() { return _ip_config_dependents; }
|
|
|
|
Domain_name const &name() const { return _name; }
|
|
|
|
Ip_rule_list &ip_rules() { return _ip_rules; }
|
|
|
|
Forward_rule_tree &tcp_forward_rules() { return _tcp_forward_rules; }
|
|
|
|
Forward_rule_tree &udp_forward_rules() { return _udp_forward_rules; }
|
|
|
|
Transport_rule_list &tcp_rules() { return _tcp_rules; }
|
|
|
|
Transport_rule_list &udp_rules() { return _udp_rules; }
|
|
|
|
Ip_rule_list &icmp_rules() { return _icmp_rules; }
|
|
|
|
Nat_rule_tree &nat_rules() { return _nat_rules; }
|
|
|
|
Interface_list &interfaces() { return _interfaces; }
|
|
|
|
Configuration &config() const { return _config; }
|
2018-05-10 13:38:45 +02:00
|
|
|
Dhcp_server &dhcp_server();
|
2018-06-19 16:20:47 +02:00
|
|
|
Arp_cache &arp_cache() { return _arp_cache; }
|
|
|
|
Arp_waiter_list &foreign_arp_waiters() { return _foreign_arp_waiters; }
|
|
|
|
Link_side_tree &tcp_links() { return _tcp_links; }
|
|
|
|
Link_side_tree &udp_links() { return _udp_links; }
|
|
|
|
Link_side_tree &icmp_links() { return _icmp_links; }
|
2018-09-16 14:21:38 +02:00
|
|
|
Domain_link_stats &udp_stats() { return _udp_stats; }
|
|
|
|
Domain_link_stats &tcp_stats() { return _tcp_stats; }
|
|
|
|
Domain_link_stats &icmp_stats() { return _icmp_stats; }
|
|
|
|
Domain_object_stats &arp_stats() { return _arp_stats; }
|
|
|
|
Domain_object_stats &dhcp_stats() { return _dhcp_stats; }
|
2016-09-12 12:55:12 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* _DOMAIN_H_ */
|