Compare commits

..

No commits in common. "6516224e327fc7cb62aa6782dccabb40d1325660" and "471fc61fb449ca985e1ac94cfb378b7d30d82326" have entirely different histories.

4 changed files with 8 additions and 47 deletions

2
Cargo.lock generated
View File

@ -13,7 +13,7 @@ dependencies = [
[[package]] [[package]]
name = "dhcprs" name = "dhcprs"
version = "0.1.3" version = "0.1.1"
dependencies = [ dependencies = [
"eui48", "eui48",
] ]

View File

@ -1,6 +1,6 @@
[package] [package]
name = "dhcprs" name = "dhcprs"
version = "0.1.3" version = "0.1.1"
edition = "2021" edition = "2021"
description = "A library for encoding and decoding DHCP/BOOTP packets" description = "A library for encoding and decoding DHCP/BOOTP packets"
license-file = "LICENSE" license-file = "LICENSE"

View File

@ -85,22 +85,22 @@ impl From<BOOTPPacket> for RawBOOTPPacket {
secs: item.secs, secs: item.secs,
flags: item.flags, flags: item.flags,
ciaddr: if item.ciaddr.is_some() { ciaddr: if item.ciaddr.is_some() {
u32::to_be(item.ciaddr.unwrap().into()) item.ciaddr.unwrap().into()
} else { } else {
0 0
}, },
yiaddr: if item.yiaddr.is_some() { yiaddr: if item.yiaddr.is_some() {
u32::to_be(item.yiaddr.unwrap().into()) item.yiaddr.unwrap().into()
} else { } else {
0 0
}, },
siaddr: if item.siaddr.is_some() { siaddr: if item.siaddr.is_some() {
u32::to_be(item.siaddr.unwrap().into()) item.siaddr.unwrap().into()
} else { } else {
0 0
}, },
giaddr: if item.giaddr.is_some() { giaddr: if item.giaddr.is_some() {
u32::to_be(item.giaddr.unwrap().into()) item.giaddr.unwrap().into()
} else { } else {
0 0
}, },

View File

@ -166,10 +166,10 @@ pub enum DHCPOption {
/*// RFC4833 /*// RFC4833
TimezonePOSIX(String), // 100 N IEEE 1003.1 String TimezonePOSIX(String), // 100 N IEEE 1003.1 String
TimezoneDB(String), // 101 N Reference to TZ Database*/ TimezoneDB(String), // 101 N Reference to TZ Database
// RFC3442 // RFC3442
ClasslessStaticRoute(Vec<(Ipv4Addr, u8, Ipv4Addr)>), // 121 n d1 ... dN r1 r2 r3 r4 d1 ... dN r1 r2 r3 r4 ClasslessStaticRoute(Vec<(Ipv4Addr, u32, Ipv4Addr)>), // 121 n d1 ... dN r1 r2 r3 r4 d1 ... dN r1 r2 r3 r4*/
// Catchall // Catchall
Option(u8, Vec<u8>), Option(u8, Vec<u8>),
@ -184,12 +184,6 @@ macro_rules! break_unwrap {
}; };
} }
macro_rules! div_ceil {
($lhs:expr, $rhs:expr) => {
$lhs / $rhs + if $lhs % $rhs != 0 { 1 } else { 0 }
}
}
impl DHCPOption { impl DHCPOption {
pub fn from_bytes(bytes: &[u8]) -> Vec<DHCPOption> { pub fn from_bytes(bytes: &[u8]) -> Vec<DHCPOption> {
let mut options: Vec<DHCPOption> = Vec::new(); let mut options: Vec<DHCPOption> = Vec::new();
@ -1236,28 +1230,6 @@ impl DHCPOption {
options.push(DHCPOption::STDAServer(addresses)); options.push(DHCPOption::STDAServer(addresses));
} }
121 => {
let mut length = break_unwrap!(iterator.next());
let mut routes: Vec<(Ipv4Addr, u8, Ipv4Addr)> = Vec::new();
while length > 0 {
let prefix_length = break_unwrap!(iterator.next());
let descriptor_length = div_ceil!(prefix_length, 8);
let mut prefix_octets: [u8; 4] = [0;4];
for count in 0..descriptor_length {
prefix_octets[count as usize] = break_unwrap!(iterator.next());
}
let router = Ipv4Addr::new(break_unwrap!(iterator.next()),break_unwrap!(iterator.next()),break_unwrap!(iterator.next()),break_unwrap!(iterator.next()));
routes.push((Ipv4Addr::from(prefix_octets), prefix_length, router));
length -= 1 + descriptor_length + 4;
}
options.push(DHCPOption::ClasslessStaticRoute(routes));
}
// Catchall for if we cannot decode the option to a specific enum variant. // Catchall for if we cannot decode the option to a specific enum variant.
n => { n => {
let count = break_unwrap!(iterator.next()); let count = break_unwrap!(iterator.next());
@ -1829,17 +1801,6 @@ impl DHCPOption {
bytes.push(b.len() as u8); bytes.push(b.len() as u8);
bytes.extend_from_slice(&b); bytes.extend_from_slice(&b);
} }
DHCPOption::ClasslessStaticRoute(routes) => {
bytes.push(121);
bytes.push(routes.iter().fold(0, |acc, (_, prefix_length, _)| acc + 1 + div_ceil!(prefix_length, 8) + 4));
for (prefix, prefix_length, router) in routes {
let descriptor_length = div_ceil!(prefix_length, 8);
bytes.push(prefix_length);
bytes.extend_from_slice(&prefix.octets()[..descriptor_length as usize]);
bytes.extend_from_slice(&router.octets());
}
}
} }
} }