nic_router: do DHCP requests without source IP

Issue #2738
This commit is contained in:
Martin Stein 2018-04-04 17:25:52 +02:00 committed by Christian Helmuth
parent 49f64a0cac
commit 0bd73e440d
2 changed files with 12 additions and 8 deletions

View File

@ -42,15 +42,16 @@ Dhcp_client::Dhcp_client(Genode::Allocator &alloc,
void Dhcp_client::discover() void Dhcp_client::discover()
{ {
_set_state(State::SELECT, _config().dhcp_discover_timeout()); _set_state(State::SELECT, _config().dhcp_discover_timeout());
_send(Message_type::DISCOVER, Ipv4_address(), Ipv4_address()); _send(Message_type::DISCOVER, Ipv4_address(), Ipv4_address(),
Ipv4_address());
} }
void Dhcp_client::_rerequest(State next_state) void Dhcp_client::_rerequest(State next_state)
{ {
_set_state(next_state, _rerequest_timeout(2)); _set_state(next_state, _rerequest_timeout(2));
_send(Message_type::REQUEST, _domain().ip_config().interface.address, Ipv4_address const client_ip = _domain().ip_config().interface.address;
Ipv4_address()); _send(Message_type::REQUEST, client_ip, Ipv4_address(), client_ip);
} }
@ -133,8 +134,9 @@ void Dhcp_client::_handle_dhcp_reply(Dhcp_packet &dhcp)
throw Drop_packet_inform("DHCP client expects an offer"); throw Drop_packet_inform("DHCP client expects an offer");
} }
_set_state(State::REQUEST, _config().dhcp_request_timeout()); _set_state(State::REQUEST, _config().dhcp_request_timeout());
_send(Message_type::REQUEST, dhcp.yiaddr(), _send(Message_type::REQUEST, Ipv4_address(),
dhcp.option<Dhcp_packet::Server_ipv4>().value()); dhcp.option<Dhcp_packet::Server_ipv4>().value(),
dhcp.yiaddr());
break; break;
case State::REQUEST: case State::REQUEST:
@ -170,7 +172,8 @@ void Dhcp_client::_handle_dhcp_reply(Dhcp_packet &dhcp)
void Dhcp_client::_send(Message_type msg_type, void Dhcp_client::_send(Message_type msg_type,
Ipv4_address client_ip, Ipv4_address client_ip,
Ipv4_address server_ip) Ipv4_address server_ip,
Ipv4_address requested_ip)
{ {
enum { PKT_SIZE = 1024 }; enum { PKT_SIZE = 1024 };
using Size_guard = Size_guard_tpl<PKT_SIZE, Interface::Send_buffer_too_small>; using Size_guard = Size_guard_tpl<PKT_SIZE, Interface::Send_buffer_too_small>;
@ -244,7 +247,7 @@ void Dhcp_client::_send(Message_type msg_type,
dhcp_opts.append_option<Dhcp_packet::Client_id>(client_mac); dhcp_opts.append_option<Dhcp_packet::Client_id>(client_mac);
dhcp_opts.append_option<Dhcp_packet::Max_msg_size>(PKT_SIZE - dhcp_off); dhcp_opts.append_option<Dhcp_packet::Max_msg_size>(PKT_SIZE - dhcp_off);
if (_state == State::REQUEST) { if (_state == State::REQUEST) {
dhcp_opts.append_option<Dhcp_packet::Requested_addr>(client_ip); dhcp_opts.append_option<Dhcp_packet::Requested_addr>(requested_ip);
dhcp_opts.append_option<Dhcp_packet::Server_ipv4>(server_ip); dhcp_opts.append_option<Dhcp_packet::Server_ipv4>(server_ip);
} }
break; break;

View File

@ -54,7 +54,8 @@ class Net::Dhcp_client
void _send(Dhcp_packet::Message_type msg_type, void _send(Dhcp_packet::Message_type msg_type,
Ipv4_address client_ip, Ipv4_address client_ip,
Ipv4_address server_ip); Ipv4_address server_ip,
Ipv4_address requested_ip);
Configuration &_config(); Configuration &_config();