|
@@ -2,9 +2,9 @@
|
|
|
|
|
|
use byteorder::{ByteOrder, NetworkEndian};
|
|
|
|
|
|
-use crate::{Error, Result};
|
|
|
-use crate::wire::{EthernetAddress, Ipv4Address};
|
|
|
use crate::wire::arp::Hardware;
|
|
|
+use crate::wire::{EthernetAddress, Ipv4Address};
|
|
|
+use crate::{Error, Result};
|
|
|
|
|
|
pub const SERVER_PORT: u16 = 67;
|
|
|
pub const CLIENT_PORT: u16 = 68;
|
|
@@ -37,8 +37,11 @@ enum_with_unknown! {
|
|
|
impl MessageType {
|
|
|
fn opcode(&self) -> OpCode {
|
|
|
match *self {
|
|
|
- MessageType::Discover | MessageType::Inform | MessageType::Request |
|
|
|
- MessageType::Decline | MessageType::Release => OpCode::Request,
|
|
|
+ MessageType::Discover
|
|
|
+ | MessageType::Inform
|
|
|
+ | MessageType::Request
|
|
|
+ | MessageType::Decline
|
|
|
+ | MessageType::Release => OpCode::Request,
|
|
|
MessageType::Offer | MessageType::Ack | MessageType::Nak => OpCode::Reply,
|
|
|
MessageType::Unknown(_) => OpCode::Unknown(0),
|
|
|
}
|
|
@@ -59,7 +62,7 @@ pub enum DhcpOption<'a> {
|
|
|
Router(Ipv4Address),
|
|
|
SubnetMask(Ipv4Address),
|
|
|
MaximumDhcpMessageSize(u16),
|
|
|
- Other { kind: u8, data: &'a [u8] }
|
|
|
+ Other { kind: u8, data: &'a [u8] },
|
|
|
}
|
|
|
|
|
|
impl<'a> DhcpOption<'a> {
|
|
@@ -81,12 +84,10 @@ impl<'a> DhcpOption<'a> {
|
|
|
skip_len = length + 2;
|
|
|
let data = buffer.get(2..skip_len).ok_or(Error::Truncated)?;
|
|
|
match (kind, length) {
|
|
|
- (field::OPT_END, _) |
|
|
|
- (field::OPT_PAD, _) =>
|
|
|
- unreachable!(),
|
|
|
+ (field::OPT_END, _) | (field::OPT_PAD, _) => unreachable!(),
|
|
|
(field::OPT_DHCP_MESSAGE_TYPE, 1) => {
|
|
|
option = DhcpOption::MessageType(MessageType::from(data[0]));
|
|
|
- },
|
|
|
+ }
|
|
|
(field::OPT_REQUESTED_IP, 4) => {
|
|
|
option = DhcpOption::RequestedIp(Ipv4Address::from_bytes(data));
|
|
|
}
|
|
@@ -95,7 +96,8 @@ impl<'a> DhcpOption<'a> {
|
|
|
if hardware_type != Hardware::Ethernet {
|
|
|
return Err(Error::Unrecognized);
|
|
|
}
|
|
|
- option = DhcpOption::ClientIdentifier(EthernetAddress::from_bytes(&data[1..]));
|
|
|
+ option =
|
|
|
+ DhcpOption::ClientIdentifier(EthernetAddress::from_bytes(&data[1..]));
|
|
|
}
|
|
|
(field::OPT_SERVER_IDENTIFIER, 4) => {
|
|
|
option = DhcpOption::ServerIdentifier(Ipv4Address::from_bytes(data));
|
|
@@ -107,13 +109,20 @@ impl<'a> DhcpOption<'a> {
|
|
|
option = DhcpOption::SubnetMask(Ipv4Address::from_bytes(data));
|
|
|
}
|
|
|
(field::OPT_MAX_DHCP_MESSAGE_SIZE, 2) => {
|
|
|
- option = DhcpOption::MaximumDhcpMessageSize(u16::from_be_bytes([data[0], data[1]]));
|
|
|
+ option = DhcpOption::MaximumDhcpMessageSize(u16::from_be_bytes([
|
|
|
+ data[0], data[1],
|
|
|
+ ]));
|
|
|
}
|
|
|
(field::OPT_IP_LEASE_TIME, 4) => {
|
|
|
- option = DhcpOption::IpLeaseTime(u32::from_be_bytes([data[0], data[1], data[2], data[3]]))
|
|
|
+ option = DhcpOption::IpLeaseTime(u32::from_be_bytes([
|
|
|
+ data[0], data[1], data[2], data[3],
|
|
|
+ ]))
|
|
|
}
|
|
|
(_, _) => {
|
|
|
- option = DhcpOption::Other { kind: kind, data: data };
|
|
|
+ option = DhcpOption::Other {
|
|
|
+ kind: kind,
|
|
|
+ data: data,
|
|
|
+ };
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -126,20 +135,14 @@ impl<'a> DhcpOption<'a> {
|
|
|
&DhcpOption::EndOfList => 1,
|
|
|
&DhcpOption::Pad => 1,
|
|
|
&DhcpOption::MessageType(_) => 3,
|
|
|
- &DhcpOption::ClientIdentifier(eth_addr) => {
|
|
|
- 3 + eth_addr.as_bytes().len()
|
|
|
- }
|
|
|
- &DhcpOption::RequestedIp(ip) |
|
|
|
- &DhcpOption::ServerIdentifier(ip) |
|
|
|
- &DhcpOption::Router(ip) |
|
|
|
- &DhcpOption::SubnetMask(ip) => {
|
|
|
- 2 + ip.as_bytes().len()
|
|
|
- },
|
|
|
- &DhcpOption::MaximumDhcpMessageSize(_) => {
|
|
|
- 4
|
|
|
- }
|
|
|
+ &DhcpOption::ClientIdentifier(eth_addr) => 3 + eth_addr.as_bytes().len(),
|
|
|
+ &DhcpOption::RequestedIp(ip)
|
|
|
+ | &DhcpOption::ServerIdentifier(ip)
|
|
|
+ | &DhcpOption::Router(ip)
|
|
|
+ | &DhcpOption::SubnetMask(ip) => 2 + ip.as_bytes().len(),
|
|
|
+ &DhcpOption::MaximumDhcpMessageSize(_) => 4,
|
|
|
&DhcpOption::IpLeaseTime(_) => 6,
|
|
|
- &DhcpOption::Other { data, .. } => 2 + data.len()
|
|
|
+ &DhcpOption::Other { data, .. } => 2 + data.len(),
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -168,19 +171,19 @@ impl<'a> DhcpOption<'a> {
|
|
|
buffer[2] = u16::from(Hardware::Ethernet) as u8;
|
|
|
buffer[3..9].copy_from_slice(eth_addr.as_bytes());
|
|
|
}
|
|
|
- DhcpOption::RequestedIp(ip) => {
|
|
|
+ DhcpOption::RequestedIp(ip) => {
|
|
|
buffer[0] = field::OPT_REQUESTED_IP;
|
|
|
buffer[2..6].copy_from_slice(ip.as_bytes());
|
|
|
}
|
|
|
- DhcpOption::ServerIdentifier(ip) => {
|
|
|
+ DhcpOption::ServerIdentifier(ip) => {
|
|
|
buffer[0] = field::OPT_SERVER_IDENTIFIER;
|
|
|
buffer[2..6].copy_from_slice(ip.as_bytes());
|
|
|
}
|
|
|
- DhcpOption::Router(ip) => {
|
|
|
+ DhcpOption::Router(ip) => {
|
|
|
buffer[0] = field::OPT_ROUTER;
|
|
|
buffer[2..6].copy_from_slice(ip.as_bytes());
|
|
|
}
|
|
|
- DhcpOption::SubnetMask(mask) => {
|
|
|
+ DhcpOption::SubnetMask(mask) => {
|
|
|
buffer[0] = field::OPT_SUBNET_MASK;
|
|
|
buffer[2..6].copy_from_slice(mask.as_bytes());
|
|
|
}
|
|
@@ -192,7 +195,10 @@ impl<'a> DhcpOption<'a> {
|
|
|
buffer[0] = field::OPT_IP_LEASE_TIME;
|
|
|
buffer[2..6].copy_from_slice(&lease_time.to_be_bytes()[..]);
|
|
|
}
|
|
|
- DhcpOption::Other { kind, data: provided } => {
|
|
|
+ DhcpOption::Other {
|
|
|
+ kind,
|
|
|
+ data: provided,
|
|
|
+ } => {
|
|
|
buffer[0] = kind;
|
|
|
buffer[2..skip_length].copy_from_slice(provided);
|
|
|
}
|
|
@@ -207,7 +213,7 @@ impl<'a> DhcpOption<'a> {
|
|
|
#[derive(Debug, PartialEq)]
|
|
|
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
|
|
pub struct Packet<T: AsRef<[u8]>> {
|
|
|
- buffer: T
|
|
|
+ buffer: T,
|
|
|
}
|
|
|
|
|
|
pub(crate) mod field {
|
|
@@ -691,7 +697,7 @@ pub struct Repr<'a> {
|
|
|
/// The maximum size dhcp packet the interface can receive
|
|
|
pub max_size: Option<u16>,
|
|
|
/// The DHCP IP lease duration, specified in seconds.
|
|
|
- pub lease_duration: Option<u32>
|
|
|
+ pub lease_duration: Option<u32>,
|
|
|
}
|
|
|
|
|
|
impl<'a> Repr<'a> {
|
|
@@ -700,22 +706,39 @@ impl<'a> Repr<'a> {
|
|
|
let mut len = field::OPTIONS.start;
|
|
|
// message type and end-of-options options
|
|
|
len += 3 + 1;
|
|
|
- if self.requested_ip.is_some() { len += 6; }
|
|
|
- if self.client_identifier.is_some() { len += 9; }
|
|
|
- if self.server_identifier.is_some() { len += 6; }
|
|
|
- if self.max_size.is_some() { len += 4; }
|
|
|
- if self.router.is_some() { len += 6; }
|
|
|
- if self.subnet_mask.is_some() { len += 6; }
|
|
|
- if self.lease_duration.is_some() { len += 6; }
|
|
|
- if let Some(list) = self.parameter_request_list { len += list.len() + 2; }
|
|
|
+ if self.requested_ip.is_some() {
|
|
|
+ len += 6;
|
|
|
+ }
|
|
|
+ if self.client_identifier.is_some() {
|
|
|
+ len += 9;
|
|
|
+ }
|
|
|
+ if self.server_identifier.is_some() {
|
|
|
+ len += 6;
|
|
|
+ }
|
|
|
+ if self.max_size.is_some() {
|
|
|
+ len += 4;
|
|
|
+ }
|
|
|
+ if self.router.is_some() {
|
|
|
+ len += 6;
|
|
|
+ }
|
|
|
+ if self.subnet_mask.is_some() {
|
|
|
+ len += 6;
|
|
|
+ }
|
|
|
+ if self.lease_duration.is_some() {
|
|
|
+ len += 6;
|
|
|
+ }
|
|
|
+ if let Some(list) = self.parameter_request_list {
|
|
|
+ len += list.len() + 2;
|
|
|
+ }
|
|
|
|
|
|
len
|
|
|
}
|
|
|
|
|
|
/// Parse a DHCP packet and return a high-level representation.
|
|
|
pub fn parse<T>(packet: &Packet<&'a T>) -> Result<Self>
|
|
|
- where T: AsRef<[u8]> + ?Sized {
|
|
|
-
|
|
|
+ where
|
|
|
+ T: AsRef<[u8]> + ?Sized,
|
|
|
+ {
|
|
|
let transaction_id = packet.transaction_id();
|
|
|
let client_hardware_address = packet.client_hardware_address();
|
|
|
let client_ip = packet.client_ip();
|
|
@@ -753,12 +776,12 @@ impl<'a> Repr<'a> {
|
|
|
let (next_options, option) = DhcpOption::parse(options)?;
|
|
|
match option {
|
|
|
DhcpOption::EndOfList => break,
|
|
|
- DhcpOption::Pad => {},
|
|
|
+ DhcpOption::Pad => {}
|
|
|
DhcpOption::MessageType(value) => {
|
|
|
if value.opcode() == packet.opcode() {
|
|
|
message_type = Ok(value);
|
|
|
}
|
|
|
- },
|
|
|
+ }
|
|
|
DhcpOption::RequestedIp(ip) => {
|
|
|
requested_ip = Some(ip);
|
|
|
}
|
|
@@ -773,24 +796,30 @@ impl<'a> Repr<'a> {
|
|
|
}
|
|
|
DhcpOption::SubnetMask(mask) => {
|
|
|
subnet_mask = Some(mask);
|
|
|
- },
|
|
|
+ }
|
|
|
DhcpOption::MaximumDhcpMessageSize(size) => {
|
|
|
max_size = Some(size);
|
|
|
}
|
|
|
DhcpOption::IpLeaseTime(duration) => {
|
|
|
lease_duration = Some(duration);
|
|
|
}
|
|
|
- DhcpOption::Other {kind: field::OPT_PARAMETER_REQUEST_LIST, data} => {
|
|
|
+ DhcpOption::Other {
|
|
|
+ kind: field::OPT_PARAMETER_REQUEST_LIST,
|
|
|
+ data,
|
|
|
+ } => {
|
|
|
parameter_request_list = Some(data);
|
|
|
}
|
|
|
- DhcpOption::Other {kind: field::OPT_DOMAIN_NAME_SERVER, data} => {
|
|
|
+ DhcpOption::Other {
|
|
|
+ kind: field::OPT_DOMAIN_NAME_SERVER,
|
|
|
+ data,
|
|
|
+ } => {
|
|
|
let mut servers = [None; MAX_DNS_SERVER_COUNT];
|
|
|
for (server, chunk) in servers.iter_mut().zip(data.chunks(4)) {
|
|
|
*server = Some(Ipv4Address::from_bytes(chunk));
|
|
|
}
|
|
|
dns_servers = Some(servers);
|
|
|
}
|
|
|
- DhcpOption::Other {..} => {}
|
|
|
+ DhcpOption::Other { .. } => {}
|
|
|
}
|
|
|
options = next_options;
|
|
|
}
|
|
@@ -798,9 +827,21 @@ impl<'a> Repr<'a> {
|
|
|
let broadcast = packet.broadcast_flag();
|
|
|
|
|
|
Ok(Repr {
|
|
|
- transaction_id, client_hardware_address, client_ip, your_ip, server_ip, relay_agent_ip,
|
|
|
- broadcast, requested_ip, server_identifier, router,
|
|
|
- subnet_mask, client_identifier, parameter_request_list, dns_servers, max_size,
|
|
|
+ transaction_id,
|
|
|
+ client_hardware_address,
|
|
|
+ client_ip,
|
|
|
+ your_ip,
|
|
|
+ server_ip,
|
|
|
+ relay_agent_ip,
|
|
|
+ broadcast,
|
|
|
+ requested_ip,
|
|
|
+ server_identifier,
|
|
|
+ router,
|
|
|
+ subnet_mask,
|
|
|
+ client_identifier,
|
|
|
+ parameter_request_list,
|
|
|
+ dns_servers,
|
|
|
+ max_size,
|
|
|
lease_duration,
|
|
|
message_type: message_type?,
|
|
|
})
|
|
@@ -809,7 +850,9 @@ impl<'a> Repr<'a> {
|
|
|
/// Emit a high-level representation into a Dynamic Host
|
|
|
/// Configuration Protocol packet.
|
|
|
pub fn emit<T>(&self, packet: &mut Packet<&mut T>) -> Result<()>
|
|
|
- where T: AsRef<[u8]> + AsMut<[u8]> + ?Sized {
|
|
|
+ where
|
|
|
+ T: AsRef<[u8]> + AsMut<[u8]> + ?Sized,
|
|
|
+ {
|
|
|
packet.set_sname_and_boot_file_to_zero();
|
|
|
packet.set_opcode(self.message_type.opcode());
|
|
|
packet.set_hardware_type(Hardware::Ethernet);
|
|
@@ -850,7 +893,11 @@ impl<'a> Repr<'a> {
|
|
|
options = DhcpOption::IpLeaseTime(duration).emit(options);
|
|
|
}
|
|
|
if let Some(list) = self.parameter_request_list {
|
|
|
- options = DhcpOption::Other{ kind: field::OPT_PARAMETER_REQUEST_LIST, data: list }.emit(options);
|
|
|
+ options = DhcpOption::Other {
|
|
|
+ kind: field::OPT_PARAMETER_REQUEST_LIST,
|
|
|
+ data: list,
|
|
|
+ }
|
|
|
+ .emit(options);
|
|
|
}
|
|
|
DhcpOption::EndOfList.emit(options);
|
|
|
}
|
|
@@ -861,75 +908,80 @@ impl<'a> Repr<'a> {
|
|
|
|
|
|
#[cfg(test)]
|
|
|
mod test {
|
|
|
- use crate::wire::Ipv4Address;
|
|
|
use super::*;
|
|
|
+ use crate::wire::Ipv4Address;
|
|
|
|
|
|
const MAGIC_COOKIE: u32 = 0x63825363;
|
|
|
|
|
|
static DISCOVER_BYTES: &[u8] = &[
|
|
|
- 0x01, 0x01, 0x06, 0x00, 0x00, 0x00, 0x3d, 0x1d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0b, 0x82, 0x01,
|
|
|
- 0xfc, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x82, 0x53, 0x63,
|
|
|
- 0x35, 0x01, 0x01, 0x3d, 0x07, 0x01, 0x00, 0x0b, 0x82, 0x01, 0xfc, 0x42, 0x32, 0x04, 0x00, 0x00,
|
|
|
- 0x00, 0x00, 0x39, 0x2, 0x5, 0xdc, 0x37, 0x04, 0x01, 0x03, 0x06, 0x2a, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
+ 0x01, 0x01, 0x06, 0x00, 0x00, 0x00, 0x3d, 0x1d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0b,
|
|
|
+ 0x82, 0x01, 0xfc, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x82, 0x53, 0x63,
|
|
|
+ 0x35, 0x01, 0x01, 0x3d, 0x07, 0x01, 0x00, 0x0b, 0x82, 0x01, 0xfc, 0x42, 0x32, 0x04, 0x00,
|
|
|
+ 0x00, 0x00, 0x00, 0x39, 0x2, 0x5, 0xdc, 0x37, 0x04, 0x01, 0x03, 0x06, 0x2a, 0xff, 0x00,
|
|
|
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
];
|
|
|
|
|
|
static ACK_DNS_SERVER_BYTES: &[u8] = &[
|
|
|
- 0x02, 0x01, 0x06, 0x00, 0xcc, 0x34, 0x75, 0xab, 0x00, 0x00, 0x80, 0x00, 0x0a, 0xff, 0x06, 0x91,
|
|
|
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0xff, 0x06, 0xfe, 0x34, 0x17, 0xeb, 0xc9,
|
|
|
- 0xaa, 0x2f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x82, 0x53, 0x63,
|
|
|
- 0x35, 0x01, 0x05, 0x36, 0x04, 0xa3, 0x01, 0x4a, 0x16, 0x01, 0x04, 0xff, 0xff, 0xff, 0x00, 0x2b,
|
|
|
- 0x05, 0xdc, 0x03, 0x4e, 0x41, 0x50, 0x0f, 0x15, 0x6e, 0x61, 0x74, 0x2e, 0x70, 0x68, 0x79, 0x73,
|
|
|
- 0x69, 0x63, 0x73, 0x2e, 0x6f, 0x78, 0x2e, 0x61, 0x63, 0x2e, 0x75, 0x6b, 0x00, 0x03, 0x04, 0x0a,
|
|
|
- 0xff, 0x06, 0xfe, 0x06, 0x10, 0xa3, 0x01, 0x4a, 0x06, 0xa3, 0x01, 0x4a, 0x07, 0xa3, 0x01, 0x4a,
|
|
|
- 0x03, 0xa3, 0x01, 0x4a, 0x04, 0x2c, 0x10, 0xa3, 0x01, 0x4a, 0x03, 0xa3, 0x01, 0x4a, 0x04, 0xa3,
|
|
|
- 0x01, 0x4a, 0x06, 0xa3, 0x01, 0x4a, 0x07, 0x2e, 0x01, 0x08, 0xff
|
|
|
+ 0x02, 0x01, 0x06, 0x00, 0xcc, 0x34, 0x75, 0xab, 0x00, 0x00, 0x80, 0x00, 0x0a, 0xff, 0x06,
|
|
|
+ 0x91, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0xff, 0x06, 0xfe, 0x34, 0x17,
|
|
|
+ 0xeb, 0xc9, 0xaa, 0x2f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x82, 0x53, 0x63,
|
|
|
+ 0x35, 0x01, 0x05, 0x36, 0x04, 0xa3, 0x01, 0x4a, 0x16, 0x01, 0x04, 0xff, 0xff, 0xff, 0x00,
|
|
|
+ 0x2b, 0x05, 0xdc, 0x03, 0x4e, 0x41, 0x50, 0x0f, 0x15, 0x6e, 0x61, 0x74, 0x2e, 0x70, 0x68,
|
|
|
+ 0x79, 0x73, 0x69, 0x63, 0x73, 0x2e, 0x6f, 0x78, 0x2e, 0x61, 0x63, 0x2e, 0x75, 0x6b, 0x00,
|
|
|
+ 0x03, 0x04, 0x0a, 0xff, 0x06, 0xfe, 0x06, 0x10, 0xa3, 0x01, 0x4a, 0x06, 0xa3, 0x01, 0x4a,
|
|
|
+ 0x07, 0xa3, 0x01, 0x4a, 0x03, 0xa3, 0x01, 0x4a, 0x04, 0x2c, 0x10, 0xa3, 0x01, 0x4a, 0x03,
|
|
|
+ 0xa3, 0x01, 0x4a, 0x04, 0xa3, 0x01, 0x4a, 0x06, 0xa3, 0x01, 0x4a, 0x07, 0x2e, 0x01, 0x08,
|
|
|
+ 0xff,
|
|
|
];
|
|
|
|
|
|
static ACK_LEASE_TIME_BYTES: &[u8] = &[
|
|
|
- 0x02, 0x01, 0x06, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
- 0x0a, 0x22, 0x10, 0x0b, 0x0a, 0x22, 0x10, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x04, 0x91, 0x62, 0xd2,
|
|
|
- 0xa8, 0x6f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x82, 0x53, 0x63,
|
|
|
- 0x35, 0x01, 0x05, 0x36, 0x04, 0x0a, 0x22, 0x10, 0x0a, 0x33, 0x04, 0x00, 0x00, 0x02, 0x56, 0x01,
|
|
|
- 0x04, 0xff, 0xff, 0xff, 0x00, 0x03, 0x04, 0x0a, 0x22, 0x10, 0x0a, 0xff, 0x00, 0x00, 0x00, 0x00,
|
|
|
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
+ 0x02, 0x01, 0x06, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
+ 0x00, 0x0a, 0x22, 0x10, 0x0b, 0x0a, 0x22, 0x10, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x04, 0x91,
|
|
|
+ 0x62, 0xd2, 0xa8, 0x6f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x82, 0x53, 0x63,
|
|
|
+ 0x35, 0x01, 0x05, 0x36, 0x04, 0x0a, 0x22, 0x10, 0x0a, 0x33, 0x04, 0x00, 0x00, 0x02, 0x56,
|
|
|
+ 0x01, 0x04, 0xff, 0xff, 0xff, 0x00, 0x03, 0x04, 0x0a, 0x22, 0x10, 0x0a, 0xff, 0x00, 0x00,
|
|
|
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
];
|
|
|
|
|
|
const IP_NULL: Ipv4Address = Ipv4Address([0, 0, 0, 0]);
|
|
@@ -971,9 +1023,13 @@ mod test {
|
|
|
assert_eq!(options.len(), 6 + 1 + 7);
|
|
|
|
|
|
let (options, client_id) = DhcpOption::parse(options).unwrap();
|
|
|
- assert_eq!(client_id, DhcpOption::Other {
|
|
|
- kind: field::OPT_PARAMETER_REQUEST_LIST, data: &[1, 3, 6, 42]
|
|
|
- });
|
|
|
+ assert_eq!(
|
|
|
+ client_id,
|
|
|
+ DhcpOption::Other {
|
|
|
+ kind: field::OPT_PARAMETER_REQUEST_LIST,
|
|
|
+ data: &[1, 3, 6, 42]
|
|
|
+ }
|
|
|
+ );
|
|
|
assert_eq!(options.len(), 1 + 7);
|
|
|
|
|
|
let (options, client_id) = DhcpOption::parse(options).unwrap();
|
|
@@ -1007,7 +1063,8 @@ mod test {
|
|
|
options = DhcpOption::RequestedIp(IP_NULL).emit(options);
|
|
|
options = DhcpOption::MaximumDhcpMessageSize(DHCP_SIZE).emit(options);
|
|
|
let option = DhcpOption::Other {
|
|
|
- kind: field::OPT_PARAMETER_REQUEST_LIST, data: &[1, 3, 6, 42],
|
|
|
+ kind: field::OPT_PARAMETER_REQUEST_LIST,
|
|
|
+ data: &[1, 3, 6, 42],
|
|
|
};
|
|
|
options = option.emit(options);
|
|
|
DhcpOption::EndOfList.emit(options);
|
|
@@ -1106,7 +1163,10 @@ mod test {
|
|
|
let rest = dhcp_option.emit(&mut bytes);
|
|
|
assert_eq!(rest.len(), 0);
|
|
|
}
|
|
|
- assert_eq!(&bytes[0..2], &[field::OPT_PARAMETER_REQUEST_LIST, DATA.len() as u8]);
|
|
|
+ assert_eq!(
|
|
|
+ &bytes[0..2],
|
|
|
+ &[field::OPT_PARAMETER_REQUEST_LIST, DATA.len() as u8]
|
|
|
+ );
|
|
|
assert_eq!(&bytes[2..], DATA);
|
|
|
}
|
|
|
|
|
@@ -1118,10 +1178,14 @@ mod test {
|
|
|
// The packet described by ACK_BYTES advertises 4 DNS servers
|
|
|
// Here we ensure that we correctly parse the first 3 into our fixed
|
|
|
// length-3 array (see issue #305)
|
|
|
- assert_eq!(repr.dns_servers, Some([
|
|
|
- Some(Ipv4Address([163, 1, 74, 6])),
|
|
|
- Some(Ipv4Address([163, 1, 74, 7])),
|
|
|
- Some(Ipv4Address([163, 1, 74, 3]))]));
|
|
|
+ assert_eq!(
|
|
|
+ repr.dns_servers,
|
|
|
+ Some([
|
|
|
+ Some(Ipv4Address([163, 1, 74, 6])),
|
|
|
+ Some(Ipv4Address([163, 1, 74, 7])),
|
|
|
+ Some(Ipv4Address([163, 1, 74, 3]))
|
|
|
+ ])
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
#[test]
|