forked from M-Labs/artiq
Revert "Centralise all uses of the IPv4 index in net_settings.rs"
This reverts commit 95378cf9c9
.
This commit is contained in:
parent
93e82e2201
commit
f1b2a7041a
|
@ -1,21 +1,14 @@
|
|||
use core::fmt;
|
||||
use core::fmt::{Display, Formatter};
|
||||
use core::str::FromStr;
|
||||
use smoltcp::iface::{Interface, InterfaceBuilder};
|
||||
use smoltcp::phy::Device;
|
||||
|
||||
use smoltcp::wire::{EthernetAddress, IpAddress, IpCidr, Ipv4Address, Ipv4Cidr};
|
||||
use smoltcp::wire::{EthernetAddress, IpAddress, Ipv4Address};
|
||||
|
||||
use config;
|
||||
#[cfg(soc_platform = "kasli")]
|
||||
use i2c_eeprom;
|
||||
|
||||
|
||||
const IPV4_INDEX: usize = 0;
|
||||
const IPV6_LL_INDEX: usize = 1;
|
||||
const IPV6_INDEX: usize = 2;
|
||||
const IP_ADDRESS_STORAGE_SIZE: usize = 3;
|
||||
|
||||
pub enum Ipv4AddrConfig {
|
||||
UseDhcp,
|
||||
Static(Ipv4Address),
|
||||
|
@ -109,33 +102,3 @@ pub fn get_adresses() -> NetAddresses {
|
|||
ipv6_addr: ipv6_addr
|
||||
}
|
||||
}
|
||||
|
||||
pub trait InterfaceBuilderEx {
|
||||
fn init_ip_addrs(self, net_addresses: &NetAddresses) -> Self;
|
||||
}
|
||||
|
||||
impl<'a, DeviceT: for<'d> Device<'d>> InterfaceBuilderEx for InterfaceBuilder<'a, DeviceT> {
|
||||
fn init_ip_addrs(self, net_addresses: &NetAddresses) -> Self {
|
||||
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[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);
|
||||
}
|
||||
self.ip_addrs(storage)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait InterfaceEx {
|
||||
fn update_ipv4_addr(&mut self, addr: &Ipv4Cidr);
|
||||
}
|
||||
|
||||
impl<'a, DeviceT: for<'d> Device<'d>> InterfaceEx for Interface<'a, DeviceT> {
|
||||
fn update_ipv4_addr(&mut self, addr: &Ipv4Cidr) {
|
||||
self.update_ip_addrs(|storage| storage[IPV4_INDEX] = IpCidr::Ipv4(*addr))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,12 +27,12 @@ extern crate riscv;
|
|||
|
||||
use core::cell::RefCell;
|
||||
use core::convert::TryFrom;
|
||||
use smoltcp::wire::HardwareAddress;
|
||||
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::{Ipv4AddrConfig, InterfaceBuilderEx};
|
||||
use board_misoc::net_settings::{NetAddresses, Ipv4AddrConfig};
|
||||
#[cfg(has_drtio)]
|
||||
use board_artiq::drtioaux;
|
||||
use board_artiq::drtio_routing;
|
||||
|
@ -61,6 +61,13 @@ mod moninj;
|
|||
mod analyzer;
|
||||
mod dhcp;
|
||||
|
||||
// Fixed indexes for the IP addresses so that they can be modified with some
|
||||
// semblance of confidence
|
||||
pub const IPV4_INDEX: usize = 0;
|
||||
pub const IPV6_LL_INDEX: usize = 1;
|
||||
pub const IPV6_INDEX: usize = 2;
|
||||
const IP_ADDRESS_STORAGE_SIZE: usize = 3;
|
||||
|
||||
#[cfg(has_grabber)]
|
||||
fn grabber_thread(io: sched::Io) {
|
||||
loop {
|
||||
|
@ -89,6 +96,20 @@ fn setup_log_levels() {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_ip_addrs(net_addresses: &NetAddresses) -> [IpCidr; IP_ADDRESS_STORAGE_SIZE] {
|
||||
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[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);
|
||||
}
|
||||
storage
|
||||
}
|
||||
|
||||
fn startup() {
|
||||
clock::init();
|
||||
info!("ARTIQ runtime starting...");
|
||||
|
@ -151,7 +172,7 @@ fn startup() {
|
|||
};
|
||||
let interface = smoltcp::iface::InterfaceBuilder::new(net_device, vec![])
|
||||
.hardware_addr(HardwareAddress::Ethernet(net_addresses.hardware_addr))
|
||||
.init_ip_addrs(&net_addresses)
|
||||
.ip_addrs(get_ip_addrs(&net_addresses))
|
||||
.neighbor_cache(neighbor_cache)
|
||||
.finalize();
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ use fringe::OwnedStack;
|
|||
use fringe::generator::{Generator, Yielder, State as GeneratorState};
|
||||
use smoltcp::time::Duration;
|
||||
use smoltcp::Error as NetworkError;
|
||||
use smoltcp::wire::{IpEndpoint, Ipv4Cidr};
|
||||
use smoltcp::wire::{IpEndpoint, Ipv4Cidr, IpCidr};
|
||||
use smoltcp::iface::{Interface, SocketHandle};
|
||||
|
||||
use io::{Read, Write};
|
||||
|
@ -16,7 +16,7 @@ use board_misoc::clock;
|
|||
use urc::Urc;
|
||||
use board_misoc::ethmac::EthernetDevice;
|
||||
use smoltcp::phy::Tracer;
|
||||
use board_misoc::net_settings::InterfaceEx;
|
||||
use IPV4_INDEX;
|
||||
|
||||
#[derive(Fail, Debug)]
|
||||
pub enum Error {
|
||||
|
@ -276,7 +276,9 @@ impl<'a> Io<'a> {
|
|||
}
|
||||
|
||||
pub fn set_ipv4_address(&self, addr: &Ipv4Cidr) {
|
||||
self.network.borrow_mut().update_ipv4_addr(addr)
|
||||
self.network.borrow_mut().update_ip_addrs(|addrs| {
|
||||
addrs.as_mut()[IPV4_INDEX] = IpCidr::Ipv4(*addr);
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue