aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordiogo464 <[email protected]>2025-10-11 11:40:17 +0100
committerdiogo464 <[email protected]>2025-10-11 11:40:17 +0100
commit15a5bb445c3f599a110bfda0756baf18247ec05a (patch)
tree85eaabf1817736de06087012dc1eb4850b0f06b4 /src
parent521218ce06fbb7bd518eb6a069406936079e3ec2 (diff)
fixed clippy warnings
Diffstat (limited to 'src')
-rw-r--r--src/dhcp.rs27
-rw-r--r--src/main.rs42
-rw-r--r--src/tftp.rs41
3 files changed, 55 insertions, 55 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(())
diff --git a/src/main.rs b/src/main.rs
index c179ac0..819d656 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -14,10 +14,10 @@ use ipnet::Ipv4Net;
14 14
15use crate::dhcp::{DhcpOption, DhcpPacket}; 15use crate::dhcp::{DhcpOption, DhcpPacket};
16 16
17const BOOT_FILE_X64_BIOS: &'static str = "netboot.xyz.kpxe"; 17const BOOT_FILE_X64_BIOS: &str = "netboot.xyz.kpxe";
18const BOOT_FILE_X64_EFI: &'static str = "netboot.xyz.efi"; 18const BOOT_FILE_X64_EFI: &str = "netboot.xyz.efi";
19const BOOT_FILE_A64_EFI: &'static str = "netboot.xyz-arm64.efi"; 19const BOOT_FILE_A64_EFI: &str = "netboot.xyz-arm64.efi";
20const MENU_FILE: &'static str = "menu.ipxe"; 20const MENU_FILE: &str = "menu.ipxe";
21 21
22#[derive(Debug, Parser)] 22#[derive(Debug, Parser)]
23struct Cli { 23struct Cli {
@@ -235,14 +235,13 @@ fn handle_packet_4011(context: &Context, buf: &[u8], socket: &UdpSocket, sender_
235 235
236 let mut client_class = None; 236 let mut client_class = None;
237 for option in &packet.options { 237 for option in &packet.options {
238 if let DhcpOption::VendorClassIdentifier(vendor_class) = option { 238 if let DhcpOption::VendorClassIdentifier(vendor_class) = option
239 if let Ok(dhcp::PxeClassIdentifier::Client(class)) = 239 && let Ok(dhcp::PxeClassIdentifier::Client(class)) =
240 dhcp::PxeClassIdentifier::try_from(vendor_class.as_slice()) 240 dhcp::PxeClassIdentifier::try_from(vendor_class.as_slice())
241 { 241 {
242 println!("{class}"); 242 println!("{class}");
243 client_class = Some(class); 243 client_class = Some(class);
244 } 244 }
245 }
246 } 245 }
247 let client_class = match client_class { 246 let client_class = match client_class {
248 Some(class) => class, 247 Some(class) => class,
@@ -303,22 +302,19 @@ fn list_network_interfaces() -> Result<Vec<InterfaceAddr>> {
303 .to_string_lossy() 302 .to_string_lossy()
304 .into_owned(); 303 .into_owned();
305 304
306 match addr_family as i32 { 305 if addr_family as i32 == libc::AF_INET {
307 libc::AF_INET => { 306 let addr = ifa.ifa_addr as *const libc::sockaddr_in;
308 let addr = ifa.ifa_addr as *const libc::sockaddr_in; 307 let mask = ifa.ifa_netmask as *const libc::sockaddr_in;
309 let mask = ifa.ifa_netmask as *const libc::sockaddr_in; 308
310 309 let addr = Ipv4Addr::from((*addr).sin_addr.s_addr.to_ne_bytes());
311 let addr = Ipv4Addr::from((*addr).sin_addr.s_addr.to_ne_bytes()); 310 let mask = Ipv4Addr::from((*mask).sin_addr.s_addr.to_ne_bytes());
312 let mask = Ipv4Addr::from((*mask).sin_addr.s_addr.to_ne_bytes()); 311 let network = Ipv4Net::with_netmask(addr, mask).unwrap().trunc();
313 let network = Ipv4Net::with_netmask(addr, mask).unwrap().trunc(); 312
314 313 interfaces.push(InterfaceAddr {
315 interfaces.push(InterfaceAddr { 314 interface: name,
316 interface: name, 315 address: addr,
317 address: addr, 316 network,
318 network, 317 });
319 });
320 }
321 _ => {}
322 } 318 }
323 } 319 }
324 320
diff --git a/src/tftp.rs b/src/tftp.rs
index 72bac22..e99dcf0 100644
--- a/src/tftp.rs
+++ b/src/tftp.rs
@@ -32,15 +32,24 @@ pub enum TftpOp {
32 Oack, 32 Oack,
33} 33}
34 34
35impl Into<u16> for TftpOp { 35impl TftpOp {
36 fn into(self) -> u16 { 36 pub const CODE_READ_REQUEST: u16 = 1;
37 match self { 37 pub const CODE_WRITE_REQUEST: u16 = 2;
38 TftpOp::ReadRequest => 1, 38 pub const CODE_DATA: u16 = 3;
39 TftpOp::WriteRequest => 2, 39 pub const CODE_ACK: u16 = 4;
40 TftpOp::Data => 3, 40 pub const CODE_ERROR: u16 = 5;
41 TftpOp::Ack => 4, 41 pub const CODE_OACK: u16 = 6;
42 TftpOp::Error => 5, 42}
43 TftpOp::Oack => 6, 43
44impl From<TftpOp> for u16 {
45 fn from(value: TftpOp) -> Self {
46 match value {
47 TftpOp::ReadRequest => TftpOp::CODE_READ_REQUEST,
48 TftpOp::WriteRequest => TftpOp::CODE_WRITE_REQUEST,
49 TftpOp::Data => TftpOp::CODE_DATA,
50 TftpOp::Ack => TftpOp::CODE_ACK,
51 TftpOp::Error => TftpOp::CODE_ERROR,
52 TftpOp::Oack => TftpOp::CODE_OACK,
44 } 53 }
45 } 54 }
46} 55}
@@ -50,12 +59,12 @@ impl TryFrom<u16> for TftpOp {
50 59
51 fn try_from(value: u16) -> std::result::Result<Self, InvalidTftpOp> { 60 fn try_from(value: u16) -> std::result::Result<Self, InvalidTftpOp> {
52 match value { 61 match value {
53 1 => Ok(Self::ReadRequest), 62 Self::CODE_READ_REQUEST => Ok(Self::ReadRequest),
54 2 => Ok(Self::WriteRequest), 63 Self::CODE_WRITE_REQUEST => Ok(Self::WriteRequest),
55 3 => Ok(Self::Data), 64 Self::CODE_DATA => Ok(Self::Data),
56 4 => Ok(Self::Ack), 65 Self::CODE_ACK => Ok(Self::Ack),
57 5 => Ok(Self::Error), 66 Self::CODE_ERROR => Ok(Self::Error),
58 6 => Ok(Self::Oack), 67 Self::CODE_OACK => Ok(Self::Oack),
59 unknown => Err(InvalidTftpOp(unknown)), 68 unknown => Err(InvalidTftpOp(unknown)),
60 } 69 }
61 } 70 }
@@ -126,7 +135,7 @@ pub struct TftpReadRequestPacket {
126} 135}
127 136
128impl TftpReadRequestPacket { 137impl TftpReadRequestPacket {
129 pub fn write<W: Write>(&self, mut writer: W) -> Result<()> { 138 pub fn write<W: Write>(&self, _writer: W) -> Result<()> {
130 todo!() 139 todo!()
131 } 140 }
132} 141}