forked from M-Labs/artiq
1
0
Fork 0

runtime: enable IPv6. Closes #349

This commit is contained in:
Sebastien Bourdeauducq 2019-10-19 17:14:11 +08:00
parent 05e8f24c24
commit 6d5dcb4211
3 changed files with 43 additions and 8 deletions

View File

@ -27,7 +27,7 @@ board_misoc = { path = "../libboard_misoc", features = ["uart_console", "smoltcp
logger_artiq = { path = "../liblogger_artiq" } logger_artiq = { path = "../liblogger_artiq" }
board_artiq = { path = "../libboard_artiq" } board_artiq = { path = "../libboard_artiq" }
proto_artiq = { path = "../libproto_artiq", features = ["log", "alloc"] } proto_artiq = { path = "../libproto_artiq", features = ["log", "alloc"] }
smoltcp = { version = "0.5.0", default-features = false, features = ["rust-1_28", "alloc", "log", "proto-ipv4", "socket-tcp"] } smoltcp = { version = "0.5.0", default-features = false, features = ["rust-1_28", "alloc", "log", "proto-ipv4", "proto-ipv6", "socket-tcp"] }
[dependencies.fringe] [dependencies.fringe]
git = "https://github.com/m-labs/libfringe" git = "https://github.com/m-labs/libfringe"

View File

@ -170,7 +170,7 @@ fn startup() {
match config::read_str("ip", |r| r.map(|s| s.parse())) { match config::read_str("ip", |r| r.map(|s| s.parse())) {
Ok(Ok(addr)) => { Ok(Ok(addr)) => {
protocol_addr = addr; protocol_addr = addr;
info!("using IP address {}", protocol_addr); info!("using IPv4 address {}", protocol_addr);
} }
_ => { _ => {
#[cfg(soc_platform = "kasli")] #[cfg(soc_platform = "kasli")]
@ -189,9 +189,23 @@ fn startup() {
{ {
protocol_addr = IpAddress::v4(192, 168, 1, 50); protocol_addr = IpAddress::v4(192, 168, 1, 50);
} }
info!("using default IP address {}", protocol_addr); info!("using default IPv4 address {}", protocol_addr);
} }
} }
let protocol_addr6_ll = IpAddress::v6(
0xfe80, 0x0000, 0x0000, 0x0000,
(((hardware_addr.0[0] ^ 0x02) as u16) << 8) | (hardware_addr.0[1] as u16),
((hardware_addr.0[2] as u16) << 8) | 0x00ff,
0xfe00 | (hardware_addr.0[3] as u16),
((hardware_addr.0[4] as u16) << 8) | (hardware_addr.0[5] as u16));
info!("using IPv6 link-local address {}", protocol_addr6_ll);
let protocol_addr6 = match config::read_str("ip6", |r| r.map(|s| s.parse())) {
Ok(Ok(addr)) => {
info!("using IPv6 configured address {}", addr);
Some(addr)
}
_ => None
};
let mut net_device = unsafe { ethmac::EthernetDevice::new() }; let mut net_device = unsafe { ethmac::EthernetDevice::new() };
net_device.reset_phy_if_any(); net_device.reset_phy_if_any();
@ -218,12 +232,31 @@ fn startup() {
let neighbor_cache = let neighbor_cache =
smoltcp::iface::NeighborCache::new(alloc::btree_map::BTreeMap::new()); smoltcp::iface::NeighborCache::new(alloc::btree_map::BTreeMap::new());
let mut interface = let mut interface = match protocol_addr6 {
smoltcp::iface::EthernetInterfaceBuilder::new(net_device) Some(addr) => {
.neighbor_cache(neighbor_cache) let ip_addrs = [
IpCidr::new(protocol_addr, 0),
IpCidr::new(protocol_addr6_ll, 0),
IpCidr::new(addr, 0)
];
smoltcp::iface::EthernetInterfaceBuilder::new(net_device)
.ethernet_addr(hardware_addr) .ethernet_addr(hardware_addr)
.ip_addrs([IpCidr::new(protocol_addr, 0)]) .ip_addrs(ip_addrs)
.finalize(); .neighbor_cache(neighbor_cache)
.finalize()
}
None => {
let ip_addrs = [
IpCidr::new(protocol_addr, 0),
IpCidr::new(protocol_addr6_ll, 0)
];
smoltcp::iface::EthernetInterfaceBuilder::new(net_device)
.ethernet_addr(hardware_addr)
.ip_addrs(ip_addrs)
.neighbor_cache(neighbor_cache)
.finalize()
}
};
#[cfg(has_drtio)] #[cfg(has_drtio)]
let drtio_routing_table = urc::Urc::new(RefCell::new( let drtio_routing_table = urc::Urc::new(RefCell::new(

View File

@ -240,6 +240,8 @@ In other cases, install OpenOCD as before, and flash the IP and MAC addresses di
Check that you can ping the device. If ping fails, check that the Ethernet link LED is ON - on Kasli, it is the LED next to the SFP0 connector. As a next step, look at the messages emitted on the UART during boot. Use a program such as flterm or PuTTY to connect to the device's serial port at 115200bps 8-N-1 and reboot the device. On Kasli, the serial port is on FTDI channel 2 with v1.1 hardware (with channel 0 being JTAG) and on FTDI channel 1 with v1.0 hardware. Check that you can ping the device. If ping fails, check that the Ethernet link LED is ON - on Kasli, it is the LED next to the SFP0 connector. As a next step, look at the messages emitted on the UART during boot. Use a program such as flterm or PuTTY to connect to the device's serial port at 115200bps 8-N-1 and reboot the device. On Kasli, the serial port is on FTDI channel 2 with v1.1 hardware (with channel 0 being JTAG) and on FTDI channel 1 with v1.0 hardware.
If you want to use IPv6, the device also has a link-local address that corresponds to its EUI-64, and an additional arbitrary IPv6 address can be defined by using the ``ip6`` configuration key. All IPv4 and IPv6 addresses can be used at the same time.
Miscellaneous configuration of the core device Miscellaneous configuration of the core device
---------------------------------------------- ----------------------------------------------