aboutsummaryrefslogtreecommitdiff
path: root/src/dhcp.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/dhcp.rs')
-rw-r--r--src/dhcp.rs27
1 files changed, 11 insertions, 16 deletions
diff --git a/src/dhcp.rs b/src/dhcp.rs
index 51680d1..47bae1e 100644
--- a/src/dhcp.rs
+++ b/src/dhcp.rs
@@ -9,10 +9,10 @@ use crate::wire;
9const MAGIC_COOKIE: [u8; 4] = [0x63, 0x82, 0x53, 0x63]; 9const MAGIC_COOKIE: [u8; 4] = [0x63, 0x82, 0x53, 0x63];
10const FLAG_BROADCAST: u16 = 1 << 15; 10const FLAG_BROADCAST: u16 = 1 << 15;
11 11
12pub const VENDOR_CLASS_PXE_CLIENT: &'static [u8] = b"PXEClient"; 12pub const VENDOR_CLASS_PXE_CLIENT: &[u8] = b"PXEClient";
13pub const VENDOR_CLASS_PXE_SERVER: &'static [u8] = b"PXEServer"; 13pub const VENDOR_CLASS_PXE_SERVER: &[u8] = b"PXEServer";
14 14
15pub const USER_CLASS_IPXE: &'static [u8] = b"iPXE"; 15pub const USER_CLASS_IPXE: &[u8] = b"iPXE";
16 16
17#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)] 17#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
18pub enum BootOp { 18pub enum BootOp {
@@ -248,8 +248,8 @@ pub enum PxeClassIdentifierKind {
248} 248}
249 249
250impl PxeClassIdentifierKind { 250impl PxeClassIdentifierKind {
251 pub const KIND_CLIENT: &'static str = "PXEClient"; 251 pub const KIND_CLIENT: &str = "PXEClient";
252 pub const KIND_SERVER: &'static str = "PXEServer"; 252 pub const KIND_SERVER: &str = "PXEServer";
253} 253}
254 254
255impl FromStr for PxeClassIdentifierKind { 255impl FromStr for PxeClassIdentifierKind {
@@ -555,11 +555,6 @@ fn read_len8_prefixed_vec(cursor: &mut Cursor<&[u8]>) -> Result<Vec<u8>> {
555 Ok(buf) 555 Ok(buf)
556} 556}
557 557
558fn read_len8_prefixed_string(cursor: &mut Cursor<&[u8]>) -> Result<String> {
559 let buf = read_len8_prefixed_vec(cursor)?;
560 Ok(String::from_utf8(buf).unwrap())
561}
562
563fn read_ipv4(cursor: &mut Cursor<&[u8]>) -> Result<Ipv4Addr> { 558fn read_ipv4(cursor: &mut Cursor<&[u8]>) -> Result<Ipv4Addr> {
564 Ok(Ipv4Addr::from_octets(read_arr(cursor)?)) 559 Ok(Ipv4Addr::from_octets(read_arr(cursor)?))
565} 560}
@@ -726,23 +721,23 @@ pub fn write_option<W: Write>(mut writer: W, option: &DhcpOption) -> Result<()>
726 wire::write_ipv4(&mut writer, *ip)?; 721 wire::write_ipv4(&mut writer, *ip)?;
727 } 722 }
728 DhcpOption::VendorClassIdentifier(vendor_class) => { 723 DhcpOption::VendorClassIdentifier(vendor_class) => {
729 write_option_len_prefixed_buf(&mut writer, &vendor_class)? 724 write_option_len_prefixed_buf(&mut writer, vendor_class)?
730 } 725 }
731 DhcpOption::TftpServerName(name) => write_option_len_prefixed_string(&mut writer, &name)?, 726 DhcpOption::TftpServerName(name) => write_option_len_prefixed_string(&mut writer, name)?,
732 DhcpOption::TftpFileName(name) => write_option_len_prefixed_string(&mut writer, &name)?, 727 DhcpOption::TftpFileName(name) => write_option_len_prefixed_string(&mut writer, name)?,
733 DhcpOption::UserClassInformation(user_class) => { 728 DhcpOption::UserClassInformation(user_class) => {
734 write_option_len_prefixed_buf(&mut writer, &user_class)? 729 write_option_len_prefixed_buf(&mut writer, user_class)?
735 } 730 }
736 DhcpOption::ClientSystemArchitecture(arch) => { 731 DhcpOption::ClientSystemArchitecture(arch) => {
737 wire::write_u8(&mut writer, 2)?; 732 wire::write_u8(&mut writer, 2)?;
738 wire::write_u16(&mut writer, u16::from(*arch))?; 733 wire::write_u16(&mut writer, u16::from(*arch))?;
739 } 734 }
740 DhcpOption::ClientMachineIdentifier(identifier) => { 735 DhcpOption::ClientMachineIdentifier(identifier) => {
741 write_option_len_prefixed_buf(&mut writer, &identifier)? 736 write_option_len_prefixed_buf(&mut writer, identifier)?
742 } 737 }
743 DhcpOption::Unknown { data, .. } => { 738 DhcpOption::Unknown { data, .. } => {
744 wire::write_u8(&mut writer, u8::try_from(data.len()).unwrap())?; 739 wire::write_u8(&mut writer, u8::try_from(data.len()).unwrap())?;
745 wire::write(&mut writer, &data)?; 740 wire::write(&mut writer, data)?;
746 } 741 }
747 } 742 }
748 Ok(()) 743 Ok(())