genode/repos/os/src/server/nic_bridge/packet_handler.h

155 lines
3.7 KiB
C
Raw Normal View History

2011-12-22 16:19:25 +01:00
/*
* \brief Signal driven NIC packet handler
2011-12-22 16:19:25 +01:00
* \author Stefan Kalkowski
* \date 2010-08-18
*/
/*
* 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
* 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>
#include "vlan.h"
2011-12-22 16:19:25 +01:00
namespace Net {
class Packet_handler;
using ::Nic::Packet_stream_sink;
using ::Nic::Packet_stream_source;
typedef ::Nic::Packet_descriptor Packet_descriptor;
2011-12-22 16:19:25 +01:00
}
/**
* Generic packet handler used as base for NIC and client packet handlers.
*/
class Net::Packet_handler
{
private:
Packet_descriptor _packet { };
Net::Vlan &_vlan;
Genode::Session_label _label;
bool const &_verbose;
/**
* submit queue not empty anymore
*/
void _ready_to_submit();
/**
* 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.
*/
void _ack_avail() { }
/**
* acknoledgement queue not empty anymore
*/
void _ready_to_ack();
/**
* 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.
*/
void _packet_avail() { }
/**
* the link-state of changed
*/
void _link_state();
protected:
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;
public:
Packet_handler(Genode::Entrypoint&,
Vlan&,
Genode::Session_label const &label,
bool const &verbose);
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() { }
virtual Packet_stream_sink< ::Nic::Session::Policy> * sink() = 0;
virtual Packet_stream_source< ::Nic::Session::Policy> * source() = 0;
Net::Vlan & vlan() { return _vlan; }
/**
* 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.
*/
virtual bool handle_arp(Ethernet_frame &eth,
Size_guard &size_guard) = 0;
/*
* Handle an IP packet
*
* \param eth ethernet frame containing the IP packet.
* \param size ethernet frame's size.
*/
virtual bool handle_ip(Ethernet_frame &eth,
Size_guard &size_guard) = 0;
/*
* 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_ */