2016-08-25 17:48:53 +02:00
|
|
|
/*
|
|
|
|
* \brief A net interface in form of a signal-driven NIC-packet handler
|
|
|
|
* \author Martin Stein
|
|
|
|
* \date 2016-08-24
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 13:23:52 +01:00
|
|
|
* Copyright (C) 2016-2017 Genode Labs GmbH
|
2016-08-25 17:48:53 +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-08-25 17:48:53 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _INTERFACE_H_
|
|
|
|
#define _INTERFACE_H_
|
|
|
|
|
2016-09-12 12:55:12 +02:00
|
|
|
/* local includes */
|
|
|
|
#include <link.h>
|
|
|
|
#include <arp_waiter.h>
|
2017-09-14 15:10:32 +02:00
|
|
|
#include <l3_protocol.h>
|
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 <dhcp_client.h>
|
2017-10-16 13:37:06 +02:00
|
|
|
#include <dhcp_server.h>
|
2017-12-13 17:02:01 +01:00
|
|
|
#include <list.h>
|
2018-09-16 14:21:38 +02:00
|
|
|
#include <report.h>
|
2016-09-12 12:55:12 +02:00
|
|
|
|
2016-08-25 17:48:53 +02:00
|
|
|
/* Genode includes */
|
|
|
|
#include <nic_session/nic_session.h>
|
2017-10-06 13:00:05 +02:00
|
|
|
#include <net/dhcp.h>
|
2018-03-23 17:34:01 +01:00
|
|
|
#include <net/icmp.h>
|
2016-08-25 17:48:53 +02:00
|
|
|
|
2018-09-16 14:21:38 +02:00
|
|
|
namespace Genode { class Xml_generator; }
|
|
|
|
|
2016-08-25 17:48:53 +02:00
|
|
|
namespace Net {
|
|
|
|
|
2016-09-12 12:55:12 +02:00
|
|
|
using Packet_descriptor = ::Nic::Packet_descriptor;
|
|
|
|
using Packet_stream_sink = ::Nic::Packet_stream_sink< ::Nic::Session::Policy>;
|
|
|
|
using Packet_stream_source = ::Nic::Packet_stream_source< ::Nic::Session::Policy>;
|
2018-02-07 18:38:49 +01:00
|
|
|
using Domain_name = Genode::String<160>;
|
2017-10-13 16:22:05 +02:00
|
|
|
class Ipv4_config;
|
2016-09-12 12:55:12 +02:00
|
|
|
class Forward_rule_tree;
|
|
|
|
class Transport_rule_list;
|
2016-08-25 17:48:53 +02:00
|
|
|
class Ethernet_frame;
|
|
|
|
class Arp_packet;
|
2018-02-07 18:38:49 +01:00
|
|
|
class Interface_policy;
|
2016-08-25 17:48:53 +02:00
|
|
|
class Interface;
|
2018-03-19 19:16:17 +01:00
|
|
|
using Interface_list = List<Interface>;
|
2018-09-16 14:21:38 +02:00
|
|
|
class Interface_link_stats;
|
|
|
|
class Interface_object_stats;
|
2017-10-06 13:00:05 +02:00
|
|
|
class Dhcp_server;
|
2016-09-12 12:55:12 +02:00
|
|
|
class Configuration;
|
|
|
|
class Domain;
|
2016-08-25 17:48:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-16 14:21:38 +02:00
|
|
|
struct Net::Interface_object_stats
|
|
|
|
{
|
|
|
|
Genode::size_t alive { 0 };
|
|
|
|
Genode::size_t destroyed { 0 };
|
|
|
|
|
|
|
|
void report(Genode::Xml_generator &xml);
|
|
|
|
|
|
|
|
~Interface_object_stats();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct Net::Interface_link_stats
|
|
|
|
{
|
|
|
|
Genode::size_t refused_for_ram { 0 };
|
|
|
|
Genode::size_t refused_for_ports { 0 };
|
|
|
|
Genode::size_t opening { 0 };
|
|
|
|
Genode::size_t open { 0 };
|
|
|
|
Genode::size_t closing { 0 };
|
|
|
|
Genode::size_t closed { 0 };
|
|
|
|
Genode::size_t dissolved_timeout_opening { 0 };
|
|
|
|
Genode::size_t dissolved_timeout_open { 0 };
|
|
|
|
Genode::size_t dissolved_timeout_closing { 0 };
|
|
|
|
Genode::size_t dissolved_timeout_closed { 0 };
|
|
|
|
Genode::size_t dissolved_no_timeout { 0 };
|
|
|
|
Genode::size_t destroyed { 0 };
|
|
|
|
|
|
|
|
void report(Genode::Xml_generator &xml);
|
|
|
|
|
|
|
|
~Interface_link_stats();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-02-07 18:38:49 +01:00
|
|
|
struct Net::Interface_policy
|
|
|
|
{
|
|
|
|
virtual Domain_name determine_domain_name() const = 0;
|
|
|
|
|
2018-03-19 19:16:17 +01:00
|
|
|
virtual void handle_config(Configuration const &config) = 0;
|
|
|
|
|
2018-09-16 14:21:38 +02:00
|
|
|
virtual Genode::Session_label const &label() const = 0;
|
|
|
|
|
|
|
|
virtual void report(Genode::Xml_generator &) const { throw Report::Empty(); }
|
|
|
|
|
2018-02-07 18:38:49 +01:00
|
|
|
virtual ~Interface_policy() { }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-03-19 19:16:17 +01:00
|
|
|
class Net::Interface : private Interface_list::Element
|
2016-08-25 17:48:53 +02:00
|
|
|
{
|
2018-03-19 19:16:17 +01:00
|
|
|
friend class List<Interface>;
|
|
|
|
friend class Genode::List<Interface>;
|
2016-08-25 17:48:53 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2018-06-07 16:17:08 +02:00
|
|
|
using Signal_handler = Genode::Signal_handler<Interface>;
|
|
|
|
using Signal_context_capability = Genode::Signal_context_capability;
|
|
|
|
|
2018-09-16 14:21:38 +02:00
|
|
|
enum { IPV4_TIME_TO_LIVE = 64 };
|
|
|
|
enum { MAX_FREE_OPS_PER_EMERGENCY = 1024 };
|
2018-03-23 17:34:01 +01:00
|
|
|
|
2018-03-19 19:16:17 +01:00
|
|
|
struct Dismiss_link : Genode::Exception { };
|
|
|
|
struct Dismiss_arp_waiter : Genode::Exception { };
|
|
|
|
|
2018-05-16 13:55:13 +02:00
|
|
|
struct Update_domain
|
|
|
|
{
|
|
|
|
Domain &old_domain;
|
|
|
|
Domain &new_domain;
|
2018-06-08 17:32:17 +02:00
|
|
|
|
|
|
|
Update_domain(Domain &old_domain,
|
|
|
|
Domain &new_domain)
|
|
|
|
:
|
|
|
|
old_domain(old_domain),
|
|
|
|
new_domain(new_domain)
|
|
|
|
{ }
|
2018-05-16 13:55:13 +02:00
|
|
|
};
|
|
|
|
|
2018-06-08 17:32:17 +02:00
|
|
|
Packet_stream_sink &_sink;
|
|
|
|
Packet_stream_source &_source;
|
|
|
|
bool &_session_link_state;
|
|
|
|
Signal_context_capability _session_link_state_sigh { };
|
|
|
|
Signal_handler _sink_ack;
|
|
|
|
Signal_handler _sink_submit;
|
|
|
|
Signal_handler _source_ack;
|
|
|
|
Signal_handler _source_submit;
|
|
|
|
Mac_address const _router_mac;
|
|
|
|
Mac_address const _mac;
|
|
|
|
Reference<Configuration> _config;
|
|
|
|
Interface_policy &_policy;
|
|
|
|
Timer::Connection &_timer;
|
|
|
|
Genode::Allocator &_alloc;
|
|
|
|
Pointer<Domain> _domain { };
|
|
|
|
Arp_waiter_list _own_arp_waiters { };
|
|
|
|
Link_list _tcp_links { };
|
|
|
|
Link_list _udp_links { };
|
|
|
|
Link_list _icmp_links { };
|
|
|
|
Link_list _dissolved_tcp_links { };
|
|
|
|
Link_list _dissolved_udp_links { };
|
|
|
|
Link_list _dissolved_icmp_links { };
|
|
|
|
Dhcp_allocation_tree _dhcp_allocations { };
|
|
|
|
Dhcp_allocation_list _released_dhcp_allocations { };
|
2020-03-04 15:09:21 +01:00
|
|
|
Genode::Constructible<Dhcp_client> _dhcp_client { };
|
2018-06-08 17:32:17 +02:00
|
|
|
Interface_list &_interfaces;
|
|
|
|
Genode::Constructible<Update_domain> _update_domain { };
|
2018-09-16 14:21:38 +02:00
|
|
|
Interface_link_stats _udp_stats { };
|
|
|
|
Interface_link_stats _tcp_stats { };
|
|
|
|
Interface_link_stats _icmp_stats { };
|
|
|
|
Interface_object_stats _arp_stats { };
|
|
|
|
Interface_object_stats _dhcp_stats { };
|
2018-03-19 19:16:17 +01:00
|
|
|
|
|
|
|
void _new_link(L3_protocol const protocol,
|
|
|
|
Link_side_id const &local_id,
|
|
|
|
Pointer<Port_allocator_guard> remote_port_alloc,
|
|
|
|
Domain &remote_domain,
|
|
|
|
Link_side_id const &remote_id);
|
2016-09-12 12:55:12 +02:00
|
|
|
|
2018-02-07 18:38:49 +01:00
|
|
|
void _destroy_released_dhcp_allocations(Domain &local_domain);
|
2017-10-06 13:00:05 +02:00
|
|
|
|
2018-02-07 18:38:49 +01:00
|
|
|
void _destroy_dhcp_allocation(Dhcp_allocation &allocation,
|
|
|
|
Domain &local_domain);
|
2017-10-06 13:00:05 +02:00
|
|
|
|
2018-02-07 18:38:49 +01:00
|
|
|
void _release_dhcp_allocation(Dhcp_allocation &allocation,
|
|
|
|
Domain &local_domain);
|
2017-10-06 13:00:05 +02:00
|
|
|
|
2017-12-05 15:45:54 +01:00
|
|
|
void _new_dhcp_allocation(Ethernet_frame ð,
|
|
|
|
Dhcp_packet &dhcp,
|
2018-02-07 18:38:49 +01:00
|
|
|
Dhcp_server &dhcp_srv,
|
|
|
|
Domain &local_domain);
|
2017-12-05 15:45:54 +01:00
|
|
|
|
2017-10-06 13:00:05 +02:00
|
|
|
void _send_dhcp_reply(Dhcp_server const &dhcp_srv,
|
2018-05-17 17:45:10 +02:00
|
|
|
Mac_address const ð_dst,
|
2017-10-06 13:00:05 +02:00
|
|
|
Mac_address const &client_mac,
|
|
|
|
Ipv4_address const &client_ip,
|
|
|
|
Dhcp_packet::Message_type msg_type,
|
2018-02-07 18:38:49 +01:00
|
|
|
Genode::uint32_t xid,
|
|
|
|
Ipv4_address_prefix const &local_intf);
|
2017-10-06 13:00:05 +02:00
|
|
|
|
2018-06-18 19:04:40 +02:00
|
|
|
void _send_icmp_echo_reply(Ethernet_frame ð,
|
|
|
|
Ipv4_packet &ip,
|
|
|
|
Icmp_packet &icmp,
|
|
|
|
Genode::size_t icmp_sz,
|
|
|
|
Size_guard &size_guard);
|
|
|
|
|
2018-02-07 18:38:49 +01:00
|
|
|
Forward_rule_tree &_forward_rules(Domain &local_domain,
|
|
|
|
L3_protocol const prot) const;
|
2016-08-25 17:48:53 +02:00
|
|
|
|
2018-02-07 18:38:49 +01:00
|
|
|
Transport_rule_list &_transport_rules(Domain &local_domain,
|
|
|
|
L3_protocol const prot) const;
|
2016-08-25 17:48:53 +02:00
|
|
|
|
2018-02-07 18:38:49 +01:00
|
|
|
void _handle_arp(Ethernet_frame ð,
|
2018-04-26 14:53:29 +02:00
|
|
|
Size_guard &size_guard,
|
2018-02-07 18:38:49 +01:00
|
|
|
Domain &local_domain);
|
2016-08-25 17:48:53 +02:00
|
|
|
|
2017-11-13 12:45:13 +01:00
|
|
|
void _handle_arp_reply(Ethernet_frame ð,
|
2018-04-26 14:53:29 +02:00
|
|
|
Size_guard &size_guard,
|
2018-02-07 18:38:49 +01:00
|
|
|
Arp_packet &arp,
|
|
|
|
Domain &local_domain);
|
2016-08-25 17:48:53 +02:00
|
|
|
|
2016-09-12 12:55:12 +02:00
|
|
|
void _handle_arp_request(Ethernet_frame ð,
|
2018-04-26 14:53:29 +02:00
|
|
|
Size_guard &size_guard,
|
2018-02-07 18:38:49 +01:00
|
|
|
Arp_packet &arp,
|
|
|
|
Domain &local_domain);
|
2016-08-25 17:48:53 +02:00
|
|
|
|
2017-11-13 12:45:13 +01:00
|
|
|
void _send_arp_reply(Ethernet_frame ð,
|
2018-04-26 14:53:29 +02:00
|
|
|
Size_guard &size_guard,
|
2017-11-13 12:45:13 +01:00
|
|
|
Arp_packet &arp);
|
|
|
|
|
2017-10-06 13:00:05 +02:00
|
|
|
void _handle_dhcp_request(Ethernet_frame ð,
|
2018-02-07 18:38:49 +01:00
|
|
|
Dhcp_packet &dhcp,
|
|
|
|
Domain &local_domain);
|
2017-10-06 13:00:05 +02:00
|
|
|
|
2016-09-12 12:55:12 +02:00
|
|
|
void _handle_ip(Ethernet_frame ð,
|
2018-04-26 14:53:29 +02:00
|
|
|
Size_guard &size_guard,
|
2018-02-07 18:38:49 +01:00
|
|
|
Packet_descriptor const &pkt,
|
|
|
|
Domain &local_domain);
|
2016-08-25 17:48:53 +02:00
|
|
|
|
2018-03-28 02:49:44 +02:00
|
|
|
void _handle_icmp_query(Ethernet_frame ð,
|
2018-04-26 14:53:29 +02:00
|
|
|
Size_guard &size_guard,
|
2018-03-28 02:49:44 +02:00
|
|
|
Ipv4_packet &ip,
|
|
|
|
Packet_descriptor const &pkt,
|
|
|
|
L3_protocol prot,
|
|
|
|
void *prot_base,
|
|
|
|
Genode::size_t prot_size,
|
|
|
|
Domain &local_domain);
|
|
|
|
|
2018-03-29 18:04:48 +02:00
|
|
|
void _handle_icmp_error(Ethernet_frame ð,
|
2018-04-26 14:53:29 +02:00
|
|
|
Size_guard &size_guard,
|
2018-03-29 18:04:48 +02:00
|
|
|
Ipv4_packet &ip,
|
|
|
|
Packet_descriptor const &pkt,
|
|
|
|
Domain &local_domain,
|
|
|
|
Icmp_packet &icmp,
|
|
|
|
Genode::size_t icmp_sz);
|
|
|
|
|
2018-06-18 19:04:40 +02:00
|
|
|
void _handle_icmp(Ethernet_frame ð,
|
|
|
|
Size_guard &size_guard,
|
|
|
|
Ipv4_packet &ip,
|
|
|
|
Packet_descriptor const &pkt,
|
|
|
|
L3_protocol prot,
|
|
|
|
void *prot_base,
|
|
|
|
Genode::size_t prot_size,
|
|
|
|
Domain &local_domain,
|
|
|
|
Ipv4_address_prefix const &local_intf);
|
2018-03-28 02:49:44 +02:00
|
|
|
|
2016-09-12 12:55:12 +02:00
|
|
|
void _adapt_eth(Ethernet_frame ð,
|
2018-02-07 18:38:49 +01:00
|
|
|
Ipv4_address const &dst_ip,
|
2016-09-12 12:55:12 +02:00
|
|
|
Packet_descriptor const &pkt,
|
2018-02-07 18:38:49 +01:00
|
|
|
Domain &remote_domain);
|
2016-08-25 17:48:53 +02:00
|
|
|
|
2016-09-12 12:55:12 +02:00
|
|
|
void _nat_link_and_pass(Ethernet_frame ð,
|
2018-04-26 14:53:29 +02:00
|
|
|
Size_guard &size_guard,
|
2016-09-12 12:55:12 +02:00
|
|
|
Ipv4_packet &ip,
|
2017-09-14 15:10:32 +02:00
|
|
|
L3_protocol const prot,
|
2016-09-12 12:55:12 +02:00
|
|
|
void *const prot_base,
|
|
|
|
Genode::size_t const prot_size,
|
|
|
|
Link_side_id const &local_id,
|
2018-02-07 18:38:49 +01:00
|
|
|
Domain &local_domain,
|
|
|
|
Domain &remote_domain);
|
2016-08-25 17:48:53 +02:00
|
|
|
|
2018-02-07 18:38:49 +01:00
|
|
|
void _broadcast_arp_request(Ipv4_address const &src_ip,
|
|
|
|
Ipv4_address const &dst_ip);
|
2016-08-25 17:48:53 +02:00
|
|
|
|
2018-02-07 18:38:49 +01:00
|
|
|
void _domain_broadcast(Ethernet_frame ð,
|
2018-04-26 14:53:29 +02:00
|
|
|
Size_guard &size_guard,
|
2018-02-07 18:38:49 +01:00
|
|
|
Domain &local_domain);
|
2017-11-13 12:45:13 +01:00
|
|
|
|
2017-09-21 20:00:37 +02:00
|
|
|
void _pass_prot(Ethernet_frame ð,
|
2018-04-26 14:53:29 +02:00
|
|
|
Size_guard &size_guard,
|
2017-09-21 20:00:37 +02:00
|
|
|
Ipv4_packet &ip,
|
2017-09-14 15:10:32 +02:00
|
|
|
L3_protocol const prot,
|
2017-09-21 20:00:37 +02:00
|
|
|
void *const prot_base,
|
|
|
|
Genode::size_t const prot_size);
|
|
|
|
|
|
|
|
void _pass_ip(Ethernet_frame ð,
|
2018-04-26 14:53:29 +02:00
|
|
|
Size_guard &size_guard,
|
2017-09-21 20:00:37 +02:00
|
|
|
Ipv4_packet &ip);
|
2016-08-25 17:48:53 +02:00
|
|
|
|
2018-09-30 17:27:44 +02:00
|
|
|
void _handle_pkt();
|
|
|
|
|
2018-06-19 16:20:47 +02:00
|
|
|
void _continue_handle_eth(Domain const &domain,
|
|
|
|
Packet_descriptor const &pkt);
|
2016-08-25 17:48:53 +02:00
|
|
|
|
2016-09-12 12:55:12 +02:00
|
|
|
Ipv4_address const &_router_ip() const;
|
2016-08-25 17:48:53 +02:00
|
|
|
|
2016-09-12 12:55:12 +02:00
|
|
|
void _handle_eth(void *const eth_base,
|
2018-04-26 14:53:29 +02:00
|
|
|
Size_guard &size_guard,
|
2016-09-12 12:55:12 +02:00
|
|
|
Packet_descriptor const &pkt);
|
2016-08-25 17:48:53 +02:00
|
|
|
|
2018-07-13 01:40:45 +02:00
|
|
|
void _handle_eth(Ethernet_frame ð,
|
|
|
|
Size_guard &size_guard,
|
|
|
|
Packet_descriptor const &pkt,
|
|
|
|
Domain &local_domain);
|
|
|
|
|
2016-09-12 12:55:12 +02:00
|
|
|
void _ack_packet(Packet_descriptor const &pkt);
|
2016-08-25 17:48:53 +02:00
|
|
|
|
2017-12-20 14:04:50 +01:00
|
|
|
void _send_alloc_pkt(Genode::Packet_descriptor &pkt,
|
|
|
|
void * &pkt_base,
|
|
|
|
Genode::size_t pkt_size);
|
|
|
|
|
|
|
|
void _send_submit_pkt(Genode::Packet_descriptor &pkt,
|
|
|
|
void * &pkt_base,
|
|
|
|
Genode::size_t pkt_size);
|
|
|
|
|
2018-03-19 19:16:17 +01:00
|
|
|
void _update_dhcp_allocations(Domain &old_domain,
|
|
|
|
Domain &new_domain);
|
|
|
|
|
|
|
|
void _update_own_arp_waiters(Domain &domain);
|
|
|
|
|
2018-05-14 15:08:36 +02:00
|
|
|
void _update_udp_tcp_links(L3_protocol prot,
|
|
|
|
Domain &cln_dom);
|
|
|
|
|
|
|
|
void _update_icmp_links(Domain &cln_dom);
|
2018-03-19 19:16:17 +01:00
|
|
|
|
|
|
|
void _update_link_check_nat(Link &link,
|
|
|
|
Domain &new_srv_dom,
|
|
|
|
L3_protocol prot,
|
|
|
|
Domain &cln_dom);
|
|
|
|
|
|
|
|
void _dismiss_link_log(Link &link,
|
|
|
|
char const *reason);
|
|
|
|
|
|
|
|
void _destroy_link(Link &link);
|
|
|
|
|
2020-03-09 16:23:31 +01:00
|
|
|
void _update_domain_object(Domain &new_domain);
|
|
|
|
|
2018-03-19 19:16:17 +01:00
|
|
|
void _detach_from_domain_raw();
|
|
|
|
|
|
|
|
void _detach_from_domain();
|
|
|
|
|
2018-05-29 15:24:40 +02:00
|
|
|
void _attach_to_domain_raw(Domain &domain);
|
2018-05-16 13:55:13 +02:00
|
|
|
|
2018-03-19 19:16:17 +01:00
|
|
|
void _apply_foreign_arp();
|
|
|
|
|
2018-05-27 16:27:38 +02:00
|
|
|
void _failed_to_send_packet_link();
|
|
|
|
|
|
|
|
void _failed_to_send_packet_alloc();
|
|
|
|
|
2018-03-23 17:34:01 +01:00
|
|
|
void _send_icmp_dst_unreachable(Ipv4_address_prefix const &local_intf,
|
|
|
|
Ethernet_frame const &req_eth,
|
|
|
|
Ipv4_packet const &req_ip,
|
2018-05-27 16:27:38 +02:00
|
|
|
Icmp_packet::Code const code);
|
2018-03-23 17:34:01 +01:00
|
|
|
|
2016-08-25 17:48:53 +02:00
|
|
|
|
|
|
|
/***********************************
|
|
|
|
** Packet-stream signal handlers **
|
|
|
|
***********************************/
|
|
|
|
|
2016-09-12 12:55:12 +02:00
|
|
|
void _ready_to_submit();
|
|
|
|
void _ack_avail() { }
|
|
|
|
void _ready_to_ack();
|
|
|
|
void _packet_avail() { }
|
2016-08-25 17:48:53 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2018-09-16 14:21:38 +02:00
|
|
|
struct Free_resources_and_retry_handle_eth : Genode::Exception { L3_protocol prot; Free_resources_and_retry_handle_eth(L3_protocol prot = (L3_protocol)0) : prot(prot) { } };
|
2018-07-13 01:40:45 +02:00
|
|
|
struct Bad_send_dhcp_args : Genode::Exception { };
|
|
|
|
struct Bad_transport_protocol : Genode::Exception { };
|
|
|
|
struct Bad_network_protocol : Genode::Exception { };
|
|
|
|
struct Packet_postponed : Genode::Exception { };
|
|
|
|
struct Alloc_dhcp_msg_buffer_failed : Genode::Exception { };
|
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
|
|
|
|
2018-06-13 13:28:22 +02:00
|
|
|
struct Drop_packet : Genode::Exception
|
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
|
|
|
{
|
2018-06-13 13:28:22 +02:00
|
|
|
char const *reason;
|
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
|
|
|
|
2018-06-13 13:28:22 +02:00
|
|
|
Drop_packet(char const *reason) : reason(reason) { }
|
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
|
|
|
};
|
2016-09-12 12:55:12 +02:00
|
|
|
|
2018-02-07 18:38:49 +01:00
|
|
|
Interface(Genode::Entrypoint &ep,
|
|
|
|
Timer::Connection &timer,
|
|
|
|
Mac_address const router_mac,
|
|
|
|
Genode::Allocator &alloc,
|
|
|
|
Mac_address const mac,
|
|
|
|
Configuration &config,
|
2018-03-19 19:16:17 +01:00
|
|
|
Interface_list &interfaces,
|
2018-06-07 16:17:08 +02:00
|
|
|
Packet_stream_sink &sink,
|
|
|
|
Packet_stream_source &source,
|
|
|
|
bool &session_link_state,
|
2018-03-19 19:16:17 +01:00
|
|
|
Interface_policy &policy);
|
2016-08-25 17:48:53 +02:00
|
|
|
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 15:42:15 +01:00
|
|
|
virtual ~Interface();
|
2016-08-25 17:48:53 +02:00
|
|
|
|
2017-10-16 13:37:06 +02:00
|
|
|
void dhcp_allocation_expired(Dhcp_allocation &allocation);
|
2017-10-06 13:00:05 +02:00
|
|
|
|
2017-12-20 14:04:50 +01:00
|
|
|
template <typename FUNC>
|
|
|
|
void send(Genode::size_t pkt_size, FUNC && write_to_pkt)
|
|
|
|
{
|
2018-06-07 16:17:08 +02:00
|
|
|
if (!link_state()) {
|
2018-05-27 16:27:38 +02:00
|
|
|
_failed_to_send_packet_link();
|
|
|
|
return;
|
|
|
|
}
|
2017-12-20 14:04:50 +01:00
|
|
|
try {
|
|
|
|
Packet_descriptor pkt;
|
|
|
|
void *pkt_base;
|
|
|
|
|
|
|
|
_send_alloc_pkt(pkt, pkt_base, pkt_size);
|
2018-04-26 14:53:29 +02:00
|
|
|
Size_guard size_guard(pkt_size);
|
|
|
|
write_to_pkt(pkt_base, size_guard);
|
2017-12-20 14:04:50 +01:00
|
|
|
_send_submit_pkt(pkt, pkt_base, pkt_size);
|
|
|
|
}
|
|
|
|
catch (Packet_stream_source::Packet_alloc_failed) {
|
2018-05-27 16:27:38 +02:00
|
|
|
_failed_to_send_packet_alloc();
|
2017-12-20 14:04:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-26 14:53:29 +02:00
|
|
|
void send(Ethernet_frame ð,
|
|
|
|
Size_guard &size_guard);
|
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
|
|
|
|
2017-12-13 02:00:09 +01:00
|
|
|
Link_list &dissolved_links(L3_protocol const protocol);
|
2017-12-13 17:02:01 +01:00
|
|
|
|
|
|
|
Link_list &links(L3_protocol const protocol);
|
|
|
|
|
|
|
|
void cancel_arp_waiting(Arp_waiter &waiter);
|
|
|
|
|
2018-05-16 13:55:13 +02:00
|
|
|
void handle_config_1(Configuration &config);
|
|
|
|
|
|
|
|
void handle_config_2();
|
2018-03-19 19:16:17 +01:00
|
|
|
|
2018-05-16 13:55:13 +02:00
|
|
|
void handle_config_3();
|
2018-03-19 19:16:17 +01:00
|
|
|
|
2018-06-05 18:31:40 +02:00
|
|
|
void attach_to_domain();
|
|
|
|
|
2018-03-19 19:16:17 +01:00
|
|
|
void detach_from_ip_config();
|
|
|
|
|
2018-05-16 13:55:13 +02:00
|
|
|
void attach_to_ip_config(Domain &domain,
|
|
|
|
Ipv4_config const &ip_config);
|
|
|
|
|
2018-03-23 02:43:00 +01:00
|
|
|
void detach_from_remote_ip_config();
|
|
|
|
|
2018-05-16 13:55:13 +02:00
|
|
|
void attach_to_remote_ip_config();
|
|
|
|
|
2018-05-24 19:06:30 +02:00
|
|
|
void attach_to_domain_finish();
|
|
|
|
|
2018-06-07 16:17:08 +02:00
|
|
|
bool link_state() const;
|
|
|
|
|
2018-06-05 18:31:40 +02:00
|
|
|
void handle_link_state();
|
|
|
|
|
2018-09-16 14:21:38 +02:00
|
|
|
void report(Genode::Xml_generator &xml);
|
|
|
|
|
2016-08-25 17:48:53 +02:00
|
|
|
|
|
|
|
/***************
|
|
|
|
** Accessors **
|
|
|
|
***************/
|
|
|
|
|
2018-09-16 14:21:38 +02:00
|
|
|
Configuration const &config() const { return _config(); }
|
|
|
|
Domain &domain() { return _domain(); }
|
|
|
|
Mac_address const &router_mac() const { return _router_mac; }
|
|
|
|
Mac_address const &mac() const { return _mac; }
|
|
|
|
Arp_waiter_list &own_arp_waiters() { return _own_arp_waiters; }
|
|
|
|
Signal_handler &sink_ack() { return _sink_ack; }
|
|
|
|
Signal_handler &sink_submit() { return _sink_submit; }
|
|
|
|
Signal_handler &source_ack() { return _source_ack; }
|
|
|
|
Signal_handler &source_submit() { return _source_submit; }
|
|
|
|
Interface_link_stats &udp_stats() { return _udp_stats; }
|
|
|
|
Interface_link_stats &tcp_stats() { return _tcp_stats; }
|
|
|
|
Interface_link_stats &icmp_stats() { return _icmp_stats; }
|
|
|
|
Interface_object_stats &arp_stats() { return _arp_stats; }
|
|
|
|
Interface_object_stats &dhcp_stats() { return _dhcp_stats; }
|
2018-06-07 16:17:08 +02:00
|
|
|
|
|
|
|
void session_link_state_sigh(Genode::Signal_context_capability sigh);
|
2016-08-25 17:48:53 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* _INTERFACE_H_ */
|