forked from M-Labs/nac3
libconfig/net_settings: made ipv6 optional feature
This is to prepare for szl, which cannot use ipv6 due to memory limitation.
This commit is contained in:
parent
04437e876c
commit
afecc83ecf
10
src/Cargo.lock
generated
10
src/Cargo.lock
generated
@ -203,7 +203,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "libasync"
|
||||
version = "0.0.0"
|
||||
source = "git+https://git.m-labs.hk/M-Labs/zynq-rs.git#273f9ea72b738c1c85fdc398c3486c2f0564881e"
|
||||
source = "git+https://git.m-labs.hk/M-Labs/zynq-rs.git#a73df780d0d0e757738f27feac162904f5bf93f9"
|
||||
dependencies = [
|
||||
"embedded-hal",
|
||||
"libcortex_a9",
|
||||
@ -215,7 +215,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "libboard_zynq"
|
||||
version = "0.0.0"
|
||||
source = "git+https://git.m-labs.hk/M-Labs/zynq-rs.git#273f9ea72b738c1c85fdc398c3486c2f0564881e"
|
||||
source = "git+https://git.m-labs.hk/M-Labs/zynq-rs.git#a73df780d0d0e757738f27feac162904f5bf93f9"
|
||||
dependencies = [
|
||||
"bit_field",
|
||||
"embedded-hal",
|
||||
@ -249,7 +249,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "libcortex_a9"
|
||||
version = "0.0.0"
|
||||
source = "git+https://git.m-labs.hk/M-Labs/zynq-rs.git#273f9ea72b738c1c85fdc398c3486c2f0564881e"
|
||||
source = "git+https://git.m-labs.hk/M-Labs/zynq-rs.git#a73df780d0d0e757738f27feac162904f5bf93f9"
|
||||
dependencies = [
|
||||
"bit_field",
|
||||
"libregister",
|
||||
@ -265,7 +265,7 @@ checksum = "c7d73b3f436185384286bd8098d17ec07c9a7d2388a6599f824d8502b529702a"
|
||||
[[package]]
|
||||
name = "libregister"
|
||||
version = "0.0.0"
|
||||
source = "git+https://git.m-labs.hk/M-Labs/zynq-rs.git#273f9ea72b738c1c85fdc398c3486c2f0564881e"
|
||||
source = "git+https://git.m-labs.hk/M-Labs/zynq-rs.git#a73df780d0d0e757738f27feac162904f5bf93f9"
|
||||
dependencies = [
|
||||
"bit_field",
|
||||
"vcell",
|
||||
@ -275,7 +275,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "libsupport_zynq"
|
||||
version = "0.0.0"
|
||||
source = "git+https://git.m-labs.hk/M-Labs/zynq-rs.git#273f9ea72b738c1c85fdc398c3486c2f0564881e"
|
||||
source = "git+https://git.m-labs.hk/M-Labs/zynq-rs.git#a73df780d0d0e757738f27feac162904f5bf93f9"
|
||||
dependencies = [
|
||||
"compiler_builtins",
|
||||
"libboard_zynq",
|
||||
|
@ -1,22 +1,30 @@
|
||||
use core::fmt;
|
||||
|
||||
use libboard_zynq::smoltcp::wire::{EthernetAddress, IpAddress};
|
||||
|
||||
use super::Config;
|
||||
|
||||
pub struct NetAddresses {
|
||||
pub hardware_addr: EthernetAddress,
|
||||
pub ipv4_addr: IpAddress,
|
||||
#[cfg(feature = "ipv6")]
|
||||
pub ipv6_ll_addr: IpAddress,
|
||||
#[cfg(feature = "ipv6")]
|
||||
pub ipv6_addr: Option<IpAddress>
|
||||
}
|
||||
|
||||
impl fmt::Display for NetAddresses {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "MAC={} IPv4={} IPv6-LL={} IPv6=",
|
||||
self.hardware_addr, self.ipv4_addr, self.ipv6_ll_addr)?;
|
||||
match self.ipv6_addr {
|
||||
Some(addr) => write!(f, "{}", addr)?,
|
||||
None => write!(f, "no configured address")?
|
||||
write!(f, "MAC={} IPv4={} ",
|
||||
self.hardware_addr, self.ipv4_addr)?;
|
||||
|
||||
#[cfg(feature = "ipv6")]
|
||||
{
|
||||
write!(f, "IPv6-LL={}", self.ipv6_ll_addr)?;
|
||||
match self.ipv6_addr {
|
||||
Some(addr) => write!(f, " {}", addr)?,
|
||||
None => write!(f, " IPv6: no configured address")?
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@ -25,7 +33,6 @@ impl fmt::Display for NetAddresses {
|
||||
pub fn get_adresses(cfg: &Config) -> NetAddresses {
|
||||
let mut hardware_addr = EthernetAddress([0x02, 0x00, 0x00, 0x00, 0x00, 0x52]);
|
||||
let mut ipv4_addr = IpAddress::v4(192, 168, 1, 52);
|
||||
let mut ipv6_addr = None;
|
||||
|
||||
if let Ok(Ok(addr)) = cfg.read_str("mac").map(|s| s.parse()) {
|
||||
hardware_addr = addr;
|
||||
@ -33,10 +40,10 @@ pub fn get_adresses(cfg: &Config) -> NetAddresses {
|
||||
if let Ok(Ok(addr)) = cfg.read_str("ip").map(|s| s.parse()) {
|
||||
ipv4_addr = addr;
|
||||
}
|
||||
if let Ok(Ok(addr)) = cfg.read_str("ip6").map(|s| s.parse()) {
|
||||
ipv6_addr = Some(addr);
|
||||
}
|
||||
#[cfg(feature = "ipv6")]
|
||||
let ipv6_addr = cfg.read_str("ipv6").ok().and_then(|s| s.parse().ok());
|
||||
|
||||
#[cfg(feature = "ipv6")]
|
||||
let ipv6_ll_addr = IpAddress::v6(
|
||||
0xfe80, 0x0000, 0x0000, 0x0000,
|
||||
(((hardware_addr.0[0] ^ 0x02) as u16) << 8) | (hardware_addr.0[1] as u16),
|
||||
@ -45,9 +52,11 @@ pub fn get_adresses(cfg: &Config) -> NetAddresses {
|
||||
((hardware_addr.0[4] as u16) << 8) | (hardware_addr.0[5] as u16));
|
||||
|
||||
NetAddresses {
|
||||
hardware_addr: hardware_addr,
|
||||
ipv4_addr: ipv4_addr,
|
||||
ipv6_ll_addr: ipv6_ll_addr,
|
||||
ipv6_addr: ipv6_addr
|
||||
hardware_addr,
|
||||
ipv4_addr,
|
||||
#[cfg(feature = "ipv6")]
|
||||
ipv6_ll_addr,
|
||||
#[cfg(feature = "ipv6")]
|
||||
ipv6_addr
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ log_buffer = { version = "1.2" }
|
||||
libm = { version = "0.2", features = ["unstable"] }
|
||||
vcell = "0.1"
|
||||
|
||||
libboard_zynq = { git = "https://git.m-labs.hk/M-Labs/zynq-rs.git" }
|
||||
libboard_zynq = { git = "https://git.m-labs.hk/M-Labs/zynq-rs.git", features = ["ipv6"]}
|
||||
libsupport_zynq = { default-features = false, features = ["alloc_core"], git = "https://git.m-labs.hk/M-Labs/zynq-rs.git" }
|
||||
libcortex_a9 = { git = "https://git.m-labs.hk/M-Labs/zynq-rs.git" }
|
||||
libasync = { git = "https://git.m-labs.hk/M-Labs/zynq-rs.git" }
|
||||
@ -35,4 +35,4 @@ dyld = { path = "../libdyld" }
|
||||
dwarf = { path = "../libdwarf" }
|
||||
unwind = { path = "../libunwind" }
|
||||
libc = { path = "../libc" }
|
||||
libconfig = { path = "../libconfig" }
|
||||
libconfig = { path = "../libconfig", features = ["ipv6"]}
|
||||
|
Loading…
Reference in New Issue
Block a user