1
0
Fork 0

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:
pca006132 2020-09-01 14:34:54 +08:00
parent 04437e876c
commit afecc83ecf
3 changed files with 29 additions and 20 deletions

10
src/Cargo.lock generated
View File

@ -203,7 +203,7 @@ dependencies = [
[[package]] [[package]]
name = "libasync" name = "libasync"
version = "0.0.0" 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 = [ dependencies = [
"embedded-hal", "embedded-hal",
"libcortex_a9", "libcortex_a9",
@ -215,7 +215,7 @@ dependencies = [
[[package]] [[package]]
name = "libboard_zynq" name = "libboard_zynq"
version = "0.0.0" 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 = [ dependencies = [
"bit_field", "bit_field",
"embedded-hal", "embedded-hal",
@ -249,7 +249,7 @@ dependencies = [
[[package]] [[package]]
name = "libcortex_a9" name = "libcortex_a9"
version = "0.0.0" 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 = [ dependencies = [
"bit_field", "bit_field",
"libregister", "libregister",
@ -265,7 +265,7 @@ checksum = "c7d73b3f436185384286bd8098d17ec07c9a7d2388a6599f824d8502b529702a"
[[package]] [[package]]
name = "libregister" name = "libregister"
version = "0.0.0" 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 = [ dependencies = [
"bit_field", "bit_field",
"vcell", "vcell",
@ -275,7 +275,7 @@ dependencies = [
[[package]] [[package]]
name = "libsupport_zynq" name = "libsupport_zynq"
version = "0.0.0" 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 = [ dependencies = [
"compiler_builtins", "compiler_builtins",
"libboard_zynq", "libboard_zynq",

View File

@ -1,22 +1,30 @@
use core::fmt; use core::fmt;
use libboard_zynq::smoltcp::wire::{EthernetAddress, IpAddress}; use libboard_zynq::smoltcp::wire::{EthernetAddress, IpAddress};
use super::Config; use super::Config;
pub struct NetAddresses { pub struct NetAddresses {
pub hardware_addr: EthernetAddress, pub hardware_addr: EthernetAddress,
pub ipv4_addr: IpAddress, pub ipv4_addr: IpAddress,
#[cfg(feature = "ipv6")]
pub ipv6_ll_addr: IpAddress, pub ipv6_ll_addr: IpAddress,
#[cfg(feature = "ipv6")]
pub ipv6_addr: Option<IpAddress> pub ipv6_addr: Option<IpAddress>
} }
impl fmt::Display for NetAddresses { impl fmt::Display for NetAddresses {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "MAC={} IPv4={} IPv6-LL={} IPv6=", write!(f, "MAC={} IPv4={} ",
self.hardware_addr, self.ipv4_addr, self.ipv6_ll_addr)?; self.hardware_addr, self.ipv4_addr)?;
#[cfg(feature = "ipv6")]
{
write!(f, "IPv6-LL={}", self.ipv6_ll_addr)?;
match self.ipv6_addr { match self.ipv6_addr {
Some(addr) => write!(f, " {}", addr)?, Some(addr) => write!(f, " {}", addr)?,
None => write!(f, "no configured address")? None => write!(f, " IPv6: no configured address")?
}
} }
Ok(()) Ok(())
} }
@ -25,7 +33,6 @@ impl fmt::Display for NetAddresses {
pub fn get_adresses(cfg: &Config) -> NetAddresses { pub fn get_adresses(cfg: &Config) -> NetAddresses {
let mut hardware_addr = EthernetAddress([0x02, 0x00, 0x00, 0x00, 0x00, 0x52]); let mut hardware_addr = EthernetAddress([0x02, 0x00, 0x00, 0x00, 0x00, 0x52]);
let mut ipv4_addr = IpAddress::v4(192, 168, 1, 52); 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()) { if let Ok(Ok(addr)) = cfg.read_str("mac").map(|s| s.parse()) {
hardware_addr = addr; 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()) { if let Ok(Ok(addr)) = cfg.read_str("ip").map(|s| s.parse()) {
ipv4_addr = addr; ipv4_addr = addr;
} }
if let Ok(Ok(addr)) = cfg.read_str("ip6").map(|s| s.parse()) { #[cfg(feature = "ipv6")]
ipv6_addr = Some(addr); let ipv6_addr = cfg.read_str("ipv6").ok().and_then(|s| s.parse().ok());
}
#[cfg(feature = "ipv6")]
let ipv6_ll_addr = IpAddress::v6( let ipv6_ll_addr = IpAddress::v6(
0xfe80, 0x0000, 0x0000, 0x0000, 0xfe80, 0x0000, 0x0000, 0x0000,
(((hardware_addr.0[0] ^ 0x02) as u16) << 8) | (hardware_addr.0[1] as u16), (((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)); ((hardware_addr.0[4] as u16) << 8) | (hardware_addr.0[5] as u16));
NetAddresses { NetAddresses {
hardware_addr: hardware_addr, hardware_addr,
ipv4_addr: ipv4_addr, ipv4_addr,
ipv6_ll_addr: ipv6_ll_addr, #[cfg(feature = "ipv6")]
ipv6_addr: ipv6_addr ipv6_ll_addr,
#[cfg(feature = "ipv6")]
ipv6_addr
} }
} }

View File

@ -25,7 +25,7 @@ log_buffer = { version = "1.2" }
libm = { version = "0.2", features = ["unstable"] } libm = { version = "0.2", features = ["unstable"] }
vcell = "0.1" 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" } 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" } 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" } libasync = { git = "https://git.m-labs.hk/M-Labs/zynq-rs.git" }
@ -35,4 +35,4 @@ dyld = { path = "../libdyld" }
dwarf = { path = "../libdwarf" } dwarf = { path = "../libdwarf" }
unwind = { path = "../libunwind" } unwind = { path = "../libunwind" }
libc = { path = "../libc" } libc = { path = "../libc" }
libconfig = { path = "../libconfig" } libconfig = { path = "../libconfig", features = ["ipv6"]}