2011-12-22 16:19:25 +01:00
|
|
|
/*
|
2013-05-28 13:53:03 +02:00
|
|
|
* \brief Signal driven NIC packet handler
|
2011-12-22 16:19:25 +01:00
|
|
|
* \author Stefan Kalkowski
|
|
|
|
* \date 2010-08-18
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 13:23:52 +01:00
|
|
|
* Copyright (C) 2010-2017 Genode Labs GmbH
|
2011-12-22 16:19:25 +01: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.
|
2011-12-22 16:19:25 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _PACKET_HANDLER_H_
|
|
|
|
#define _PACKET_HANDLER_H_
|
|
|
|
|
|
|
|
/* Genode */
|
|
|
|
#include <base/semaphore.h>
|
|
|
|
#include <base/thread.h>
|
|
|
|
#include <nic_session/connection.h>
|
|
|
|
#include <net/ethernet.h>
|
|
|
|
#include <net/ipv4.h>
|
|
|
|
|
2019-10-03 20:30:26 +02:00
|
|
|
#include "vlan.h"
|
2016-01-27 13:46:35 +01:00
|
|
|
|
2011-12-22 16:19:25 +01:00
|
|
|
namespace Net {
|
2015-03-16 17:33:26 +01:00
|
|
|
|
2013-05-28 13:53:03 +02:00
|
|
|
class Packet_handler;
|
2015-03-16 17:33:26 +01:00
|
|
|
|
|
|
|
using ::Nic::Packet_stream_sink;
|
|
|
|
using ::Nic::Packet_stream_source;
|
|
|
|
typedef ::Nic::Packet_descriptor Packet_descriptor;
|
2011-12-22 16:19:25 +01:00
|
|
|
}
|
|
|
|
|
2013-05-28 13:53:03 +02:00
|
|
|
/**
|
|
|
|
* Generic packet handler used as base for NIC and client packet handlers.
|
|
|
|
*/
|
|
|
|
class Net::Packet_handler
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
2018-06-29 16:00:25 +02:00
|
|
|
Packet_descriptor _packet { };
|
|
|
|
Net::Vlan &_vlan;
|
|
|
|
Genode::Session_label _label;
|
|
|
|
bool const &_verbose;
|
2013-05-28 13:53:03 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* submit queue not empty anymore
|
|
|
|
*/
|
2016-06-03 16:21:45 +02:00
|
|
|
void _ready_to_submit();
|
2013-05-28 13:53:03 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* acknoledgement queue not full anymore
|
|
|
|
*
|
|
|
|
* TODO: by now, we assume ACK and SUBMIT queue to be equally
|
|
|
|
* dimensioned. That's why we ignore this signal by now.
|
|
|
|
*/
|
2016-06-03 16:21:45 +02:00
|
|
|
void _ack_avail() { }
|
2013-05-28 13:53:03 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* acknoledgement queue not empty anymore
|
|
|
|
*/
|
2016-06-03 16:21:45 +02:00
|
|
|
void _ready_to_ack();
|
2013-05-28 13:53:03 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* submit queue not full anymore
|
|
|
|
*
|
|
|
|
* TODO: by now, we just drop packets that cannot be transferred
|
|
|
|
* to the other side, that's why we ignore this signal.
|
|
|
|
*/
|
2016-06-03 16:21:45 +02:00
|
|
|
void _packet_avail() { }
|
2013-05-28 13:53:03 +02:00
|
|
|
|
2015-03-11 11:33:03 +01:00
|
|
|
/**
|
|
|
|
* the link-state of changed
|
|
|
|
*/
|
2016-06-03 16:21:45 +02:00
|
|
|
void _link_state();
|
2015-03-11 11:33:03 +01:00
|
|
|
|
2013-05-28 13:53:03 +02:00
|
|
|
protected:
|
|
|
|
|
2016-06-03 16:21:45 +02:00
|
|
|
Genode::Signal_handler<Packet_handler> _sink_ack;
|
|
|
|
Genode::Signal_handler<Packet_handler> _sink_submit;
|
|
|
|
Genode::Signal_handler<Packet_handler> _source_ack;
|
|
|
|
Genode::Signal_handler<Packet_handler> _source_submit;
|
|
|
|
Genode::Signal_handler<Packet_handler> _client_link_state;
|
2013-05-28 13:53:03 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2018-06-29 16:00:25 +02:00
|
|
|
Packet_handler(Genode::Entrypoint&,
|
|
|
|
Vlan&,
|
|
|
|
Genode::Session_label const &label,
|
|
|
|
bool const &verbose);
|
2013-05-28 13:53:03 +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 ~Packet_handler() { }
|
|
|
|
|
2013-05-28 13:53:03 +02:00
|
|
|
virtual Packet_stream_sink< ::Nic::Session::Policy> * sink() = 0;
|
|
|
|
virtual Packet_stream_source< ::Nic::Session::Policy> * source() = 0;
|
|
|
|
|
2016-01-27 13:46:35 +01:00
|
|
|
Net::Vlan & vlan() { return _vlan; }
|
2013-05-28 13:53:03 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Broadcasts ethernet frame to all clients,
|
|
|
|
* as long as its really a broadcast packtet.
|
|
|
|
*
|
|
|
|
* \param eth ethernet frame to send.
|
|
|
|
* \param size ethernet frame's size.
|
|
|
|
*/
|
|
|
|
void inline broadcast_to_clients(Ethernet_frame *eth,
|
|
|
|
Genode::size_t size);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send ethernet frame
|
|
|
|
*
|
|
|
|
* \param eth ethernet frame to send.
|
|
|
|
* \param size ethernet frame's size.
|
|
|
|
*/
|
|
|
|
void send(Ethernet_frame *eth, Genode::size_t size);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle an ethernet packet
|
|
|
|
*
|
|
|
|
* \param src ethernet frame's address
|
|
|
|
* \param size ethernet frame's size.
|
|
|
|
*/
|
|
|
|
void handle_ethernet(void* src, Genode::size_t size);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle an ARP packet
|
|
|
|
*
|
|
|
|
* \param eth ethernet frame containing the ARP packet.
|
|
|
|
* \param size ethernet frame's size.
|
|
|
|
*/
|
2018-04-26 14:53:29 +02:00
|
|
|
virtual bool handle_arp(Ethernet_frame ð,
|
|
|
|
Size_guard &size_guard) = 0;
|
2013-05-28 13:53:03 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle an IP packet
|
|
|
|
*
|
|
|
|
* \param eth ethernet frame containing the IP packet.
|
|
|
|
* \param size ethernet frame's size.
|
|
|
|
*/
|
2018-04-26 14:53:29 +02:00
|
|
|
virtual bool handle_ip(Ethernet_frame ð,
|
|
|
|
Size_guard &size_guard) = 0;
|
2013-05-28 13:53:03 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Finalize handling of ethernet frame.
|
|
|
|
*
|
|
|
|
* \param eth ethernet frame to handle.
|
|
|
|
* \param size ethernet frame's size.
|
|
|
|
*/
|
|
|
|
virtual void finalize_packet(Ethernet_frame *eth,
|
|
|
|
Genode::size_t size) = 0;
|
|
|
|
};
|
|
|
|
|
2011-12-22 16:19:25 +01:00
|
|
|
#endif /* _PACKET_HANDLER_H_ */
|