Compare commits
No commits in common. "core" and "f15e229ab3f2520ff831297ecab3c11953e518ce" have entirely different histories.
core
...
f15e229ab3
57
Cargo.lock
generated
57
Cargo.lock
generated
@ -11,11 +11,31 @@ dependencies = [
|
|||||||
"memchr",
|
"memchr",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "autocfg"
|
||||||
|
version = "1.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bitflags"
|
||||||
|
version = "1.3.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cfg-if"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "dhcprs"
|
name = "dhcprs"
|
||||||
version = "0.1.3"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"eui48",
|
"eui48",
|
||||||
|
"libc",
|
||||||
|
"nix",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -28,12 +48,47 @@ dependencies = [
|
|||||||
"rustc-serialize",
|
"rustc-serialize",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libc"
|
||||||
|
version = "0.2.133"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c0f80d65747a3e43d1596c7c5492d95d5edddaabd45a7fcdb02b95f644164966"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "memchr"
|
name = "memchr"
|
||||||
version = "2.5.0"
|
version = "2.5.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
|
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "memoffset"
|
||||||
|
version = "0.6.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "nix"
|
||||||
|
version = "0.25.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e322c04a9e3440c327fca7b6c8a63e6890a32fa2ad689db972425f07e0d22abb"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
"bitflags",
|
||||||
|
"cfg-if",
|
||||||
|
"libc",
|
||||||
|
"memoffset",
|
||||||
|
"pin-utils",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pin-utils"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "regex"
|
name = "regex"
|
||||||
version = "1.6.0"
|
version = "1.6.0"
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "dhcprs"
|
name = "dhcprs"
|
||||||
version = "0.1.3"
|
version = "0.1.0"
|
||||||
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"
|
||||||
repository = "https://github.com/xnoe/dhcprs"
|
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
@ -13,4 +12,6 @@ name = "dhcprs"
|
|||||||
path = "src/lib.rs"
|
path = "src/lib.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
nix = "0.25.0"
|
||||||
eui48 = "1.1.0"
|
eui48 = "1.1.0"
|
||||||
|
libc = "0.2.133"
|
16
src/bootp.rs
16
src/bootp.rs
@ -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
|
||||||
},
|
},
|
||||||
@ -123,22 +123,22 @@ impl From<RawBOOTPPacket> for BOOTPPacket {
|
|||||||
ciaddr: if item.ciaddr == 0 {
|
ciaddr: if item.ciaddr == 0 {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(std::net::Ipv4Addr::from(u32::from_be(item.ciaddr)))
|
Some(std::net::Ipv4Addr::from(item.ciaddr))
|
||||||
},
|
},
|
||||||
yiaddr: if item.yiaddr == 0 {
|
yiaddr: if item.yiaddr == 0 {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(std::net::Ipv4Addr::from(u32::from_be(item.yiaddr)))
|
Some(std::net::Ipv4Addr::from(item.yiaddr))
|
||||||
},
|
},
|
||||||
siaddr: if item.siaddr == 0 {
|
siaddr: if item.siaddr == 0 {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(std::net::Ipv4Addr::from(u32::from_be(item.siaddr)))
|
Some(std::net::Ipv4Addr::from(item.siaddr))
|
||||||
},
|
},
|
||||||
giaddr: if item.giaddr == 0 {
|
giaddr: if item.giaddr == 0 {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(std::net::Ipv4Addr::from(u32::from_be(item.giaddr)))
|
Some(std::net::Ipv4Addr::from(item.giaddr))
|
||||||
},
|
},
|
||||||
chaddr: MacAddress::from_bytes(&item.chaddr[0..6]).unwrap(),
|
chaddr: MacAddress::from_bytes(&item.chaddr[0..6]).unwrap(),
|
||||||
sname: item.sname,
|
sname: item.sname,
|
||||||
|
43
src/dhcp.rs
43
src/dhcp.rs
@ -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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user