This commit is contained in:
Baptiste Wicht 2016-09-29 09:51:46 +02:00
parent 56e865c6de
commit 9fec17d47b
No known key found for this signature in database
GPG Key ID: C5566B6C7F884532
2 changed files with 43 additions and 8 deletions

View File

@ -27,20 +27,52 @@ namespace arp {
struct layer; struct layer;
/*!
* \brief An entry in the ARP cache
*/
struct cache_entry { struct cache_entry {
uint64_t mac; uint64_t mac; ///< The MAC address
network::ip::address ip; network::ip::address ip; ///< The IP address
/*!
* \brief Construct a new empty cache entry
*/
cache_entry(){} cache_entry(){}
/*!
* \brief Construct a new cache entry
* \param mac The MAC address
* \param ip The IP address
*/
cache_entry(uint64_t mac, network::ip::address ip) : mac(mac), ip(ip) {} cache_entry(uint64_t mac, network::ip::address ip) : mac(mac), ip(ip) {}
}; };
/*!
* \brief An ARP cache
*/
struct cache { struct cache {
/*!
* \brief Construct a new cache.
* \param layer The ARP layer
* \param parent The parent layer (ethernet layer)
*/
cache(network::arp::layer* layer, network::ethernet::layer* parent); cache(network::arp::layer* layer, network::ethernet::layer* parent);
/*!
* \brief Update the cache entry for the given MAC address
* \param mac The MAC address
* \param ip The IP address
*/
void update_cache(uint64_t mac, network::ip::address ip); void update_cache(uint64_t mac, network::ip::address ip);
/*!
* \brief Indicates if the given MAC address is cached or not
*/
bool is_mac_cached(uint64_t mac) const ; bool is_mac_cached(uint64_t mac) const ;
/*!
* \brief Indicates if the given IP address is cached or not
*/
bool is_ip_cached(network::ip::address ip) const ; bool is_ip_cached(network::ip::address ip) const ;
/*! /*!
@ -83,10 +115,10 @@ struct cache {
private: private:
std::expected<void> arp_request(network::interface_descriptor& interface, network::ip::address ip); std::expected<void> arp_request(network::interface_descriptor& interface, network::ip::address ip);
network::arp::layer* arp_layer; network::arp::layer* arp_layer; ///< The ARP layer
network::ethernet::layer* ethernet_layer; network::ethernet::layer* ethernet_layer; ///< The ethernet layer
std::vector<cache_entry> mac_cache; std::vector<cache_entry> mac_cache; ///< The cache of MAC addresses
}; };
} // end of arp namespace } // end of arp namespace

View File

@ -57,16 +57,19 @@ struct layer {
*/ */
void decode(network::interface_descriptor& interface, network::packet& packet); void decode(network::interface_descriptor& interface, network::packet& packet);
/*!
* \brief Returns a reference to the ARP cache
*/
network::arp::cache& get_cache(); network::arp::cache& get_cache();
void wait_for_reply(); void wait_for_reply();
void wait_for_reply(size_t ms); void wait_for_reply(size_t ms);
private: private:
network::ethernet::layer* parent; network::ethernet::layer* parent; ///< The parent layer (ethernet)
network::arp::cache _cache; network::arp::cache _cache; ///< The ARP cache
condition_variable wait_queue; condition_variable wait_queue; ///< Wait queue for ARP packets
}; };
} // end of arp namespace } // end of arp namespace