Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dhcpv4: use offered ip in requested ip option #310

Merged
merged 3 commits into from
Oct 22, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions src/dhcp/clientv4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ struct RequestState {
retry: u16,
endpoint_ip: Ipv4Address,
server_identifier: Ipv4Address,
requested_ip: Ipv4Address,
}

#[derive(Debug)]
Expand Down Expand Up @@ -118,8 +119,7 @@ impl Client {
/// DHCP requests when timeouts are ready.
///
/// Applying the obtained network configuration is left to the
/// user. You must configure the new IPv4 address from the
/// returned `Config`. Otherwise, DHCP will not work.
/// user.
///
/// A Config can be returned from any valid DHCP reply. The client
/// performs no bookkeeping on configuration or their changes.
Expand Down Expand Up @@ -198,9 +198,8 @@ impl Client {
};
net_debug!("DHCP recv {:?} from {} ({})", dhcp_repr.message_type, src_ip, server_identifier);

let config = if (dhcp_repr.message_type == DhcpMessageType::Offer ||
dhcp_repr.message_type == DhcpMessageType::Ack) &&
dhcp_repr.your_ip != Ipv4Address::UNSPECIFIED {
// once we receive the ack, we can pass the config to the user
let config = if dhcp_repr.message_type == DhcpMessageType::Ack {
let address = dhcp_repr.subnet_mask
.and_then(|mask| IpAddress::Ipv4(mask).to_prefix_len())
.map(|prefix_len| Ipv4Cidr::new(dhcp_repr.your_ip, prefix_len));
Expand All @@ -221,6 +220,7 @@ impl Client {
retry: 0,
endpoint_ip: *src_ip,
server_identifier,
requested_ip: dhcp_repr.your_ip // use the offered ip
};
Some(ClientState::Requesting(r_state))
}
Expand Down Expand Up @@ -321,15 +321,9 @@ impl Client {
addr: Ipv4Address::BROADCAST.into(),
port: UDP_SERVER_PORT,
};
let requested_ip = match iface.ipv4_addr() {
Some(addr) if !addr.is_unspecified() =>
Some(addr),
_ =>
None,
};
dhcp_repr.message_type = DhcpMessageType::Request;
dhcp_repr.broadcast = false;
dhcp_repr.requested_ip = requested_ip;
dhcp_repr.requested_ip = Some(r_state.requested_ip);
dhcp_repr.server_identifier = Some(r_state.server_identifier);
dhcp_repr.parameter_request_list = Some(PARAMETER_REQUEST_LIST);
net_trace!("DHCP send request to {} = {:?}", endpoint, dhcp_repr);
Expand Down