forked from M-Labs/artiq
1
0
Fork 0

Revert "Use an Ipv4AddrConfig enum instead of the USE_DHCP constant"

This reverts commit 1fe59d27dc.
This commit is contained in:
Sebastien Bourdeauducq 2022-07-08 17:56:20 +08:00
parent 542a5f934f
commit 9941ee3d2a
3 changed files with 15 additions and 40 deletions

View File

@ -19,7 +19,7 @@ use board_misoc::{clock, ethmac, net_settings};
use board_misoc::uart_console::Console;
use riscv::register::{mcause, mepc, mtval};
use smoltcp::iface::SocketStorage;
use smoltcp::wire::{HardwareAddress, IpAddress, Ipv4Address};
use smoltcp::wire::HardwareAddress;
fn check_integrity() -> bool {
extern {
@ -410,13 +410,10 @@ fn network_boot() {
let net_addresses = net_settings::get_adresses();
println!("Network addresses: {}", net_addresses);
let mut ip_addrs = [
IpCidr::new(IpAddress::Ipv4(Ipv4Address::UNSPECIFIED), 0),
IpCidr::new(net_addresses.ipv4_addr, 0),
IpCidr::new(net_addresses.ipv6_ll_addr, 0),
IpCidr::new(net_addresses.ipv6_ll_addr, 0)
];
if let net_settings::Ipv4AddrConfig::Static(ipv4) = net_addresses.ipv4_addr {
ip_addrs[0] = IpCidr::new(IpAddress::Ipv4(ipv4), 0);
}
let mut interface = match net_addresses.ipv6_addr {
Some(addr) => {
ip_addrs[2] = IpCidr::new(addr, 0);

View File

@ -1,6 +1,4 @@
use core::fmt;
use core::fmt::{Display, Formatter};
use core::str::FromStr;
use smoltcp::wire::{EthernetAddress, IpAddress, Ipv4Address};
@ -9,36 +7,12 @@ use config;
use i2c_eeprom;
pub enum Ipv4AddrConfig {
UseDhcp,
Static(Ipv4Address),
}
impl FromStr for Ipv4AddrConfig {
type Err = ();
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(if s == "use_dhcp" {
Ipv4AddrConfig::UseDhcp
} else {
Ipv4AddrConfig::Static(Ipv4Address::from_str(s)?)
})
}
}
impl Display for Ipv4AddrConfig {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
Ipv4AddrConfig::UseDhcp => write!(f, "use_dhcp"),
Ipv4AddrConfig::Static(ipv4) => write!(f, "{}", ipv4)
}
}
}
pub const USE_DHCP: IpAddress = IpAddress::Ipv4(Ipv4Address::UNSPECIFIED);
pub struct NetAddresses {
pub hardware_addr: EthernetAddress,
pub ipv4_addr: Ipv4AddrConfig,
pub ipv4_addr: IpAddress,
pub ipv6_ll_addr: IpAddress,
pub ipv6_addr: Option<IpAddress>
}
@ -78,9 +52,15 @@ pub fn get_adresses() -> NetAddresses {
}
let ipv4_addr;
match config::read_str("ip", |r| r.map(|s| s.parse())) {
match config::read_str("ip", |r| r.map(|s| {
if s == "use_dhcp" {
Ok(USE_DHCP)
} else {
s.parse()
}
})) {
Ok(Ok(addr)) => ipv4_addr = addr,
_ => ipv4_addr = Ipv4AddrConfig::UseDhcp,
_ => ipv4_addr = USE_DHCP,
}
let ipv6_ll_addr = IpAddress::v6(

View File

@ -32,7 +32,7 @@ use smoltcp::wire::{HardwareAddress, IpAddress, IpCidr, Ipv4Address};
use board_misoc::{csr, ident, clock, spiflash, config, net_settings, pmp, boot};
#[cfg(has_ethmac)]
use board_misoc::ethmac;
use board_misoc::net_settings::{NetAddresses, Ipv4AddrConfig};
use board_misoc::net_settings::{NetAddresses, USE_DHCP};
#[cfg(has_drtio)]
use board_artiq::drtioaux;
use board_artiq::drtio_routing;
@ -100,9 +100,7 @@ pub fn get_ip_addrs(net_addresses: &NetAddresses) -> [IpCidr; IP_ADDRESS_STORAGE
let mut storage = [
IpCidr::new(IpAddress::Ipv4(Ipv4Address::UNSPECIFIED), 0); IP_ADDRESS_STORAGE_SIZE
];
if let Ipv4AddrConfig::Static(ipv4) = net_addresses.ipv4_addr {
storage[IPV4_INDEX] = IpCidr::new(IpAddress::Ipv4(ipv4), 0);
}
storage[IPV4_INDEX] = IpCidr::new(net_addresses.ipv4_addr, 0);
storage[IPV6_LL_INDEX] = IpCidr::new(net_addresses.ipv6_ll_addr, 0);
if let Some(ipv6) = net_addresses.ipv6_addr {
storage[IPV6_INDEX] = IpCidr::new(ipv6, 0);
@ -164,7 +162,7 @@ fn startup() {
smoltcp::iface::NeighborCache::new(alloc::collections::btree_map::BTreeMap::new());
let net_addresses = net_settings::get_adresses();
info!("network addresses: {}", net_addresses);
let use_dhcp = if matches!(net_addresses.ipv4_addr, Ipv4AddrConfig::UseDhcp) {
let use_dhcp = if net_addresses.ipv4_addr == USE_DHCP {
info!("Will try to acquire an IPv4 address with DHCP");
true
} else {