add icmpv4 fixes

a lot of debug spew is also enabled in this commit, intentionally,
because the next thing to chase out is the failure of TcpStream
on Drop.
This commit is contained in:
bunnie 2022-05-13 00:30:12 +08:00
parent bac650808d
commit c17219b6fe
2 changed files with 40 additions and 21 deletions

View file

@ -30,14 +30,20 @@ locales = {path = "../../locales"}
pddb = {path = "../pddb"} pddb = {path = "../pddb"}
[dependencies.smoltcp] [dependencies.smoltcp]
# ugh. we startd pulling in smoltcp as they were just fixing a bunch of bugs and getting ready for a 0.8.0 release. # smoltcp 0.8.0 mainline has a bug in ICMPv4. This git rev patches over it until the maintainers can
# this is the last commit that doesn't break things for Xous. They pulled in some random crate that isn't compatible # confirm a proper patch for the issue.
# with Xous in the commit after this -- we need to look into this and maybe send a PR so we can try to work with #git = "https://github.com/smoltcp-rs/smoltcp.git"
# the latest smoltcp. But later...let's just get things even working first with what we have. git = "https://github.com/betrusted-io/smoltcp.git"
git = "https://github.com/smoltcp-rs/smoltcp.git" rev = "35c8ec3d30c846442a1faae01fb0537641aef898"
# rev = "35e833e33dfd3e4efc3eb7d5de06bec17c54b011" # path = "../../../smoltcp"
rev = "007f8dd2e2d0a770609428aa4b0efb63f5dbb708" default-features = false
#path = "../../../smoltcp" features = [
"std", "log", # needed for `cargo test --no-default-features --features default` :/
"medium-ethernet", "medium-ip",
"phy-raw_socket",
"proto-ipv4", "proto-ipv6",
"socket-raw", "socket-icmp", "socket-udp", "socket-tcp",
]
#features = ["verbose"] #features = ["verbose"]
#version = "0.7.5" #version = "0.7.5"
#features = ["proto-ipv4"] #features = ["proto-ipv4"]

View file

@ -166,19 +166,17 @@ fn setup_icmp(iface: &mut Interface::<NetPhy>) -> SocketHandle {
); );
let icmp_socket = IcmpSocket::new(icmp_rx_buffer, icmp_tx_buffer); let icmp_socket = IcmpSocket::new(icmp_rx_buffer, icmp_tx_buffer);
let icmp_handle = iface.add_socket(icmp_socket); let icmp_handle = iface.add_socket(icmp_socket);
{ let icmp_socket = iface.get_socket::<IcmpSocket>(icmp_handle);
let icmp_socket = iface.get_socket::<IcmpSocket>(icmp_handle); icmp_socket
icmp_socket .bind(IcmpEndpoint::Ident(PING_IDENT))
.bind(IcmpEndpoint::Ident(PING_IDENT)) .expect("couldn't bind to icmp socket");
.expect("couldn't bind to icmp socket");
}
icmp_handle icmp_handle
} }
#[xous::xous_main] #[xous::xous_main]
fn xmain() -> ! { fn xmain() -> ! {
log_server::init_wait().unwrap(); log_server::init_wait().unwrap();
log::set_max_level(log::LevelFilter::Info); log::set_max_level(log::LevelFilter::Debug);
log::info!("my PID is {}", xous::process::id()); log::info!("my PID is {}", xous::process::id());
let xns = xous_names::XousNames::new().unwrap(); let xns = xous_names::XousNames::new().unwrap();
@ -374,13 +372,23 @@ fn xmain() -> ! {
} }
match FromPrimitive::from_usize(msg.body.id() & 0xffff) { match FromPrimitive::from_usize(msg.body.id() & 0xffff) {
Some(Opcode::Ping) => { Some(Opcode::Ping) => {
log::debug!("Ping");
let mut buf = unsafe { let mut buf = unsafe {
Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap())
}; };
let mut pkt = buf.to_original::<NetPingPacket, _>().unwrap(); let mut pkt = buf.to_original::<NetPingPacket, _>().unwrap();
let local_addr = match iface.ipv4_addr() {
Some(addr) => addr,
None => { // can't send a packet if we don't ourselves have an IP address
pkt.sent_ok = Some(false);
buf.replace(pkt)
.expect("Xous couldn't issue response to Ping request");
continue;
}
};
let socket = iface.get_socket::<IcmpSocket>(icmp_handle); let socket = iface.get_socket::<IcmpSocket>(icmp_handle);
if socket.can_send() { if socket.can_send() {
log::trace!("sending ping to {:?}", pkt.endpoint); log::debug!("sending ping to {:?}", pkt.endpoint);
let remote = IpAddress::from(pkt.endpoint); let remote = IpAddress::from(pkt.endpoint);
// we take advantage of the fact that the same CID is always returned for repeated connect requests to the same SID. // we take advantage of the fact that the same CID is always returned for repeated connect requests to the same SID.
let cid = match pkt.server { let cid = match pkt.server {
@ -436,6 +444,7 @@ fn xmain() -> ! {
seq_no: seq, seq_no: seq,
data: &echo_payload, data: &echo_payload,
}; };
socket.set_src_ipv4addr(local_addr);
let icmp_payload = socket.send(icmp_repr.buffer_len(), remote).unwrap(); let icmp_payload = socket.send(icmp_repr.buffer_len(), remote).unwrap();
let mut icmp_packet = Icmpv4Packet::new_unchecked(icmp_payload); let mut icmp_packet = Icmpv4Packet::new_unchecked(icmp_payload);
icmp_repr.emit(&mut icmp_packet, &device_caps.checksum); icmp_repr.emit(&mut icmp_packet, &device_caps.checksum);
@ -926,6 +935,7 @@ fn xmain() -> ! {
} }
Some(Opcode::StdUdpBind) => { Some(Opcode::StdUdpBind) => {
log::debug!("StdUdpBind");
let pid = msg.sender.pid(); let pid = msg.sender.pid();
std_udp_bind( std_udp_bind(
msg, msg,
@ -935,6 +945,7 @@ fn xmain() -> ! {
} }
Some(Opcode::StdUdpRx) => { Some(Opcode::StdUdpRx) => {
log::debug!("StdUdpRx");
let pid = msg.sender.pid(); let pid = msg.sender.pid();
std_udp_rx( std_udp_rx(
msg, msg,
@ -946,6 +957,7 @@ fn xmain() -> ! {
} }
Some(Opcode::StdUdpTx) => { Some(Opcode::StdUdpTx) => {
log::debug!("StdUdpTx");
let pid = msg.sender.pid(); let pid = msg.sender.pid();
std_udp_tx( std_udp_tx(
msg, msg,
@ -1140,6 +1152,7 @@ fn xmain() -> ! {
} }
} }
Some(Opcode::NetPump) => msg_scalar_unpack!(msg, wup_hi, wup_lo, _, _, { Some(Opcode::NetPump) => msg_scalar_unpack!(msg, wup_hi, wup_lo, _, _, {
log::debug!("NetPump");
// assume: if wup_hi/wup_lo == 0, then the wakeup is from a non-timer thread // assume: if wup_hi/wup_lo == 0, then the wakeup is from a non-timer thread
let wakeup: u64 = (wup_hi as u64) << 32 | (wup_lo as u64); let wakeup: u64 = (wup_hi as u64) << 32 | (wup_lo as u64);
if wakeup != 0 { if wakeup != 0 {
@ -1169,7 +1182,7 @@ fn xmain() -> ! {
// Connect calls take time to establish. This block checks to see if connections // Connect calls take time to establish. This block checks to see if connections
// have been made and issues callbacks as necessary. // have been made and issues callbacks as necessary.
log::trace!("pump: tcpconnect"); log::debug!("pump: tcpconnect");
for connection in tcp_connect_waiting.iter_mut() { for connection in tcp_connect_waiting.iter_mut() {
use smoltcp::socket::TcpState; use smoltcp::socket::TcpState;
let socket; let socket;
@ -1199,7 +1212,7 @@ fn xmain() -> ! {
} }
// This block handles TCP Rx for libstd callers // This block handles TCP Rx for libstd callers
log::trace!("pump: tcp rx"); log::debug!("pump: tcp rx");
for connection in tcp_rx_waiting.iter_mut() { for connection in tcp_rx_waiting.iter_mut() {
let socket; let socket;
let WaitingSocket { let WaitingSocket {
@ -1248,7 +1261,7 @@ fn xmain() -> ! {
} }
// This block handles TCP Tx for libstd callers // This block handles TCP Tx for libstd callers
log::trace!("pump: tcp tx"); log::debug!("pump: tcp tx");
for connection in tcp_tx_waiting.iter_mut() { for connection in tcp_tx_waiting.iter_mut() {
let socket; let socket;
let WaitingSocket { let WaitingSocket {
@ -1313,7 +1326,7 @@ fn xmain() -> ! {
} }
// this handles TCP std listeners // this handles TCP std listeners
log::trace!("pump: tcp listen"); log::debug!("pump: tcp listen");
for connection in tcp_accept_waiting.iter_mut() { for connection in tcp_accept_waiting.iter_mut() {
let ep: IpEndpoint; let ep: IpEndpoint;
let AcceptingSocket { let AcceptingSocket {
@ -1339,7 +1352,7 @@ fn xmain() -> ! {
} }
// this block handles StdUdp // this block handles StdUdp
log::trace!("pump: udp"); log::debug!("pump: udp");
for connection in udp_rx_waiting.iter_mut() { for connection in udp_rx_waiting.iter_mut() {
let socket; let socket;
let UdpStdState { let UdpStdState {