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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2016 Genode Labs GmbH
|
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
|
|
|
* under the terms of the GNU General Public License version 2.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _INTERFACE_H_
|
|
|
|
#define _INTERFACE_H_
|
|
|
|
|
2016-09-12 12:55:12 +02:00
|
|
|
/* local includes */
|
|
|
|
#include <link.h>
|
|
|
|
#include <arp_cache.h>
|
|
|
|
#include <arp_waiter.h>
|
|
|
|
|
2016-08-25 17:48:53 +02:00
|
|
|
/* Genode includes */
|
|
|
|
#include <nic_session/nic_session.h>
|
|
|
|
|
|
|
|
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>;
|
|
|
|
class Forward_rule_tree;
|
|
|
|
class Transport_rule_list;
|
2016-08-25 17:48:53 +02:00
|
|
|
class Ethernet_frame;
|
|
|
|
class Arp_packet;
|
|
|
|
class Interface;
|
2016-09-12 12:55:12 +02:00
|
|
|
class Configuration;
|
|
|
|
class Domain;
|
2016-08-25 17:48:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-12 12:55:12 +02:00
|
|
|
class Net::Interface
|
2016-08-25 17:48:53 +02:00
|
|
|
{
|
|
|
|
protected:
|
|
|
|
|
2016-09-12 12:55:12 +02:00
|
|
|
using Signal_handler = Genode::Signal_handler<Interface>;
|
|
|
|
|
|
|
|
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;
|
2016-08-25 17:48:53 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2016-09-12 12:55:12 +02:00
|
|
|
Genode::Timer &_timer;
|
|
|
|
Genode::Allocator &_alloc;
|
|
|
|
Domain &_domain;
|
|
|
|
Arp_cache _arp_cache;
|
|
|
|
Arp_waiter_list _own_arp_waiters;
|
|
|
|
Arp_waiter_list _foreign_arp_waiters;
|
|
|
|
Link_side_tree _tcp_links;
|
|
|
|
Link_side_tree _udp_links;
|
|
|
|
Link_list _closed_tcp_links;
|
|
|
|
Link_list _closed_udp_links;
|
|
|
|
|
|
|
|
void _new_link(Genode::uint8_t const protocol,
|
|
|
|
Link_side_id const &local_id,
|
|
|
|
Pointer<Port_allocator_guard> const remote_port_alloc,
|
|
|
|
Interface &remote_interface,
|
|
|
|
Link_side_id const &remote_id);
|
|
|
|
|
|
|
|
Forward_rule_tree &_forward_rules(Genode::uint8_t const prot) const;
|
2016-08-25 17:48:53 +02:00
|
|
|
|
2016-09-12 12:55:12 +02:00
|
|
|
Transport_rule_list &_transport_rules(Genode::uint8_t const prot) const;
|
2016-08-25 17:48:53 +02:00
|
|
|
|
2016-09-12 12:55:12 +02:00
|
|
|
void _handle_arp(Ethernet_frame ð, Genode::size_t const eth_size);
|
2016-08-25 17:48:53 +02:00
|
|
|
|
2016-09-12 12:55:12 +02:00
|
|
|
void _handle_arp_reply(Arp_packet &arp);
|
2016-08-25 17:48:53 +02:00
|
|
|
|
2016-09-12 12:55:12 +02:00
|
|
|
void _handle_arp_request(Ethernet_frame ð,
|
|
|
|
Genode::size_t const eth_size,
|
|
|
|
Arp_packet &arp);
|
2016-08-25 17:48:53 +02:00
|
|
|
|
2016-09-12 12:55:12 +02:00
|
|
|
void _handle_ip(Ethernet_frame ð,
|
|
|
|
Genode::size_t const eth_size,
|
|
|
|
Packet_descriptor const &pkt);
|
2016-08-25 17:48:53 +02:00
|
|
|
|
2016-09-12 12:55:12 +02:00
|
|
|
void _adapt_eth(Ethernet_frame ð,
|
|
|
|
Genode::size_t const eth_size,
|
|
|
|
Ipv4_address const &ip,
|
|
|
|
Packet_descriptor const &pkt,
|
|
|
|
Interface &interface);
|
2016-08-25 17:48:53 +02:00
|
|
|
|
2016-09-12 12:55:12 +02:00
|
|
|
void _nat_link_and_pass(Ethernet_frame ð,
|
|
|
|
Genode::size_t const eth_size,
|
|
|
|
Ipv4_packet &ip,
|
|
|
|
Genode::uint8_t const prot,
|
|
|
|
void *const prot_base,
|
|
|
|
Genode::size_t const prot_size,
|
|
|
|
Link_side_id const &local_id,
|
|
|
|
Interface &interface);
|
2016-08-25 17:48:53 +02:00
|
|
|
|
2016-09-12 12:55:12 +02:00
|
|
|
void _broadcast_arp_request(Ipv4_address const &ip);
|
2016-08-25 17:48:53 +02:00
|
|
|
|
2016-09-12 12:55:12 +02:00
|
|
|
void _send(Ethernet_frame ð, Genode::size_t const eth_size);
|
2016-08-25 17:48:53 +02:00
|
|
|
|
2016-09-12 12:55:12 +02:00
|
|
|
void _pass_ip(Ethernet_frame ð,
|
|
|
|
Genode::size_t const eth_size,
|
|
|
|
Ipv4_packet &ip,
|
|
|
|
Genode::uint8_t const prot,
|
|
|
|
void *const prot_base,
|
|
|
|
Genode::size_t const prot_size);
|
2016-08-25 17:48:53 +02:00
|
|
|
|
2016-09-12 12:55:12 +02:00
|
|
|
void _continue_handle_eth(Packet_descriptor const &pkt);
|
2016-08-25 17:48:53 +02:00
|
|
|
|
2016-09-12 12:55:12 +02:00
|
|
|
Link_list &_closed_links(Genode::uint8_t const protocol);
|
2016-08-25 17:48:53 +02:00
|
|
|
|
2016-09-12 12:55:12 +02:00
|
|
|
Link_side_tree &_links(Genode::uint8_t const protocol);
|
2016-08-25 17:48:53 +02:00
|
|
|
|
2016-09-12 12:55:12 +02:00
|
|
|
Configuration &_config() const;
|
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,
|
|
|
|
Genode::size_t const eth_size,
|
|
|
|
Packet_descriptor const &pkt);
|
2016-08-25 17:48:53 +02:00
|
|
|
|
2016-09-12 12:55:12 +02:00
|
|
|
void _ack_packet(Packet_descriptor const &pkt);
|
2016-08-25 17:48:53 +02:00
|
|
|
|
2016-09-12 12:55:12 +02:00
|
|
|
void _cancel_arp_waiting(Arp_waiter &waiter);
|
2016-08-25 17:48:53 +02:00
|
|
|
|
2016-09-12 12:55:12 +02:00
|
|
|
virtual Packet_stream_sink &_sink() = 0;
|
|
|
|
|
|
|
|
virtual Packet_stream_source &_source() = 0;
|
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:
|
|
|
|
|
2016-09-12 12:55:12 +02:00
|
|
|
struct Bad_transport_protocol : Genode::Exception { };
|
|
|
|
struct Bad_network_protocol : Genode::Exception { };
|
|
|
|
struct Packet_postponed : Genode::Exception { };
|
|
|
|
|
|
|
|
Interface(Genode::Entrypoint &ep,
|
|
|
|
Genode::Timer &timer,
|
|
|
|
Mac_address const router_mac,
|
|
|
|
Genode::Allocator &alloc,
|
|
|
|
Mac_address const mac,
|
|
|
|
Domain &domain);
|
2016-08-25 17:48:53 +02:00
|
|
|
|
|
|
|
~Interface();
|
|
|
|
|
2016-09-12 12:55:12 +02:00
|
|
|
void link_closed(Link &link, Genode::uint8_t const prot);
|
2016-08-25 17:48:53 +02:00
|
|
|
|
2016-09-12 12:55:12 +02:00
|
|
|
void dissolve_link(Link_side &link_side, Genode::uint8_t const prot);
|
2016-08-25 17:48:53 +02:00
|
|
|
|
|
|
|
|
2016-09-12 12:55:12 +02:00
|
|
|
/*********
|
|
|
|
** log **
|
|
|
|
*********/
|
|
|
|
|
|
|
|
void print(Genode::Output &output) const;
|
2016-08-25 17:48:53 +02:00
|
|
|
|
|
|
|
|
|
|
|
/***************
|
|
|
|
** Accessors **
|
|
|
|
***************/
|
|
|
|
|
2016-09-12 12:55:12 +02:00
|
|
|
Arp_waiter_list &own_arp_waiters() { return _own_arp_waiters; }
|
|
|
|
Arp_waiter_list &foreign_arp_waiters() { return _foreign_arp_waiters; }
|
2016-08-25 17:48:53 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* _INTERFACE_H_ */
|