Propagate ARP errors

This commit is contained in:
Baptiste Wicht 2016-09-08 12:15:39 +02:00
parent 84240bd87c
commit ebbc9e63cd
4 changed files with 26 additions and 9 deletions

View File

@ -47,7 +47,7 @@ uint64_t get_mac(network::ip::address ip);
* \param ip The IP address to look for in the cache
* \return The MAC address of the IP address
*/
uint64_t get_mac_force(network::interface_descriptor& interface, network::ip::address ip);
std::expected<uint64_t> get_mac_force(network::interface_descriptor& interface, network::ip::address ip);
/*!
* \brief Returns the MAC address of the given IP address. If the

View File

@ -121,7 +121,7 @@ uint64_t network::arp::get_mac(network::ip::address ip){
thor_unreachable("The IP is not cached in the ARP table");
}
uint64_t network::arp::get_mac_force(network::interface_descriptor& interface, network::ip::address ip){
std::expected<uint64_t> network::arp::get_mac_force(network::interface_descriptor& interface, network::ip::address ip){
// Check cache first
if(is_ip_cached(ip)){
return get_mac(ip);
@ -137,8 +137,10 @@ uint64_t network::arp::get_mac_force(network::interface_descriptor& interface, n
logging::logf(logging::log_level::TRACE, "arp: IP %u.%u.%u.%u not cached, generate ARP Request\n",
ip(0), ip(1), ip(2), ip(3));
// TODO Handle error here
arp_request(interface, ip);
auto arp_result = arp_request(interface, ip);
if(!arp_result){
return std::make_expected_from_error<uint64_t>(arp_result.error());
}
while(!is_ip_cached(ip)){
network::arp::wait_for_reply();
@ -165,8 +167,10 @@ std::expected<uint64_t> network::arp::get_mac_force(network::interface_descripto
logging::logf(logging::log_level::TRACE, "arp: IP %u.%u.%u.%u not cached, generate ARP Request\n",
ip(0), ip(1), ip(2), ip(3));
// TODO Handle error here
arp_request(interface, ip);
auto arp_result = arp_request(interface, ip);
if(!arp_result){
return std::make_expected_from_error<uint64_t>(arp_result.error());
}
auto start = timer::milliseconds();

View File

@ -136,7 +136,12 @@ void network::icmp::ping(network::interface_descriptor& interface, network::ip::
auto target_mac = network::arp::get_mac_force(interface, target_ip);
logging::logf(logging::log_level::TRACE, "icmp: Target MAC Address: %h\n", target_mac);
if(!target_mac){
logging::logf(logging::log_level::TRACE, "icmp: Failed to get MAC Address from IP\n");
return;
}
logging::logf(logging::log_level::TRACE, "icmp: Target MAC Address: %h\n", *target_mac);
// Ask the ICMP layer to craft a packet
auto packet = network::icmp::prepare_packet(interface, target_ip, 0, type::ECHO_REQUEST, 0);

View File

@ -113,8 +113,12 @@ void network::ip::decode(network::interface_descriptor& interface, network::ethe
std::expected<network::ethernet::packet> network::ip::prepare_packet(network::interface_descriptor& interface, size_t size, address& target_ip, size_t protocol){
auto target_mac = network::arp::get_mac_force(interface, target_ip);
if(!target_mac){
return std::make_expected_from_error<network::ethernet::packet>(target_mac.error());
}
// Ask the ethernet layer to craft a packet
auto packet = network::ethernet::prepare_packet(interface, size + sizeof(header), target_mac, ethernet::ether_type::IPV4);
auto packet = network::ethernet::prepare_packet(interface, size + sizeof(header), *target_mac, ethernet::ether_type::IPV4);
if(packet){
::prepare_packet(*packet, interface, size, target_ip, protocol);
@ -126,8 +130,12 @@ std::expected<network::ethernet::packet> network::ip::prepare_packet(network::in
std::expected<network::ethernet::packet> network::ip::prepare_packet(char* buffer, network::interface_descriptor& interface, size_t size, address& target_ip, size_t protocol){
auto target_mac = network::arp::get_mac_force(interface, target_ip);
if(!target_mac){
return std::make_expected_from_error<network::ethernet::packet>(target_mac.error());
}
// Ask the ethernet layer to craft a packet
auto packet = network::ethernet::prepare_packet(buffer, interface, size + sizeof(header), target_mac, ethernet::ether_type::IPV4);
auto packet = network::ethernet::prepare_packet(buffer, interface, size + sizeof(header), *target_mac, ethernet::ether_type::IPV4);
if(packet){
::prepare_packet(*packet, interface, size, target_ip, protocol);