nic_router: fix bugs in DHCP client functionality

Ref #2560
This commit is contained in:
Martin Stein 2017-11-03 14:06:46 +01:00 committed by Christian Helmuth
parent db6a2419f2
commit b2ea164c76
2 changed files with 12 additions and 2 deletions

View File

@ -88,7 +88,9 @@ void Dhcp_client::_handle_timeout(Duration)
void Dhcp_client::handle_ip(Ethernet_frame &eth, size_t eth_size) void Dhcp_client::handle_ip(Ethernet_frame &eth, size_t eth_size)
{ {
if (eth.dst() != _interface.router_mac()) { if (eth.dst() != _interface.router_mac() &&
eth.dst() != Mac_address(0xff))
{
throw Packet_ignored("DHCP client expects Ethernet targeting the router"); throw Packet_ignored("DHCP client expects Ethernet targeting the router");
} }
Ipv4_packet &ip = *new (eth.data<void>()) Ipv4_packet &ip = *new (eth.data<void>())
@ -109,6 +111,9 @@ void Dhcp_client::handle_ip(Ethernet_frame &eth, size_t eth_size)
if (dhcp.op() != Dhcp_packet::REPLY) { if (dhcp.op() != Dhcp_packet::REPLY) {
throw Packet_ignored("DHCP client expects DHCP reply"); throw Packet_ignored("DHCP client expects DHCP reply");
} }
if (dhcp.client_mac() != _interface.router_mac()) {
throw Packet_ignored("DHCP client expects DHCP targeting the router");
}
try { _handle_dhcp_reply(dhcp); } try { _handle_dhcp_reply(dhcp); }
catch (Dhcp_packet::Option_not_found) { catch (Dhcp_packet::Option_not_found) {
throw Packet_ignored("DHCP client misses DHCP option"); throw Packet_ignored("DHCP client misses DHCP option");

View File

@ -836,11 +836,16 @@ void Interface::_handle_eth(void *const eth_base,
catch (Ethernet_frame::No_ethernet_frame) { catch (Ethernet_frame::No_ethernet_frame) {
error("invalid ethernet frame"); } error("invalid ethernet frame"); }
catch (Interface::Bad_network_protocol) { catch (Bad_network_protocol) {
if (_config().verbose()) { if (_config().verbose()) {
log("unknown network layer protocol"); log("unknown network layer protocol");
} }
} }
catch (Packet_ignored exception) {
if (_config().verbose()) {
log("Packet ignored: ", exception.reason);
}
}
catch (Ipv4_packet::No_ip_packet) { catch (Ipv4_packet::No_ip_packet) {
error("invalid IP packet"); } error("invalid IP packet"); }