From daaa8a3a396b128a6b15511155703d9c0d7368b1 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Tue, 9 May 2017 21:31:09 -0600 Subject: [PATCH 001/155] Add ethernetd, ipd, tcpd, and udpd --- Cargo.toml | 21 + src/ethernetd/main.rs | 110 ++++ src/ethernetd/scheme.rs | 164 ++++++ src/ipd/interface/ethernet.rs | 155 ++++++ src/ipd/interface/loopback.rs | 50 ++ src/ipd/interface/mod.rs | 19 + src/ipd/main.rs | 341 +++++++++++++ src/tcpd/main.rs | 937 ++++++++++++++++++++++++++++++++++ src/udpd/main.rs | 586 +++++++++++++++++++++ 9 files changed, 2383 insertions(+) create mode 100644 Cargo.toml create mode 100644 src/ethernetd/main.rs create mode 100644 src/ethernetd/scheme.rs create mode 100644 src/ipd/interface/ethernet.rs create mode 100644 src/ipd/interface/loopback.rs create mode 100644 src/ipd/interface/mod.rs create mode 100644 src/ipd/main.rs create mode 100644 src/tcpd/main.rs create mode 100644 src/udpd/main.rs diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000000..393ef6e3e1 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "redox_netstack" +version = "0.1.0" + +[[bin]] +name = "ipd" +path = "src/ipd/main.rs" + +[[bin]] +name = "tcpd" +path = "src/tcpd/main.rs" + +[[bin]] +name = "udpd" +path = "src/udpd/main.rs" + +[dependencies] +netutils = { git = "https://github.com/redox-os/netutils.git" } +rand = "0.3" +redox_event = "0.1" +redox_syscall = "0.1" diff --git a/src/ethernetd/main.rs b/src/ethernetd/main.rs new file mode 100644 index 0000000000..7185435937 --- /dev/null +++ b/src/ethernetd/main.rs @@ -0,0 +1,110 @@ +extern crate event; +extern crate netutils; +extern crate syscall; + +use event::EventQueue; +use std::cell::RefCell; +use std::fs::File; +use std::io::{Result, Read, Write}; +use std::os::unix::io::FromRawFd; +use std::process; +use std::rc::Rc; + +use syscall::{Packet, SchemeMut, EWOULDBLOCK}; + +use scheme::EthernetScheme; + +mod scheme; + +fn daemon(network_fd: usize, socket_fd: usize) { + let network = unsafe { File::from_raw_fd(network_fd) }; + let socket = Rc::new(RefCell::new(unsafe { File::from_raw_fd(socket_fd) })); + let scheme = Rc::new(RefCell::new(EthernetScheme::new(network))); + let todo = Rc::new(RefCell::new(Vec::::new())); + + let mut event_queue = EventQueue::<()>::new().expect("ethernetd: failed to create event queue"); + + let socket_net = socket.clone(); + let scheme_net = scheme.clone(); + let todo_net = todo.clone(); + event_queue.add(network_fd, move |_count: usize| -> Result> { + if scheme_net.borrow_mut().input()? > 0 { + let mut todo = todo_net.borrow_mut(); + let mut i = 0; + while i < todo.len() { + let a = todo[i].a; + scheme_net.borrow_mut().handle(&mut todo[i]); + if todo[i].a == (-EWOULDBLOCK) as usize { + todo[i].a = a; + i += 1; + } else { + socket_net.borrow_mut().write(&mut todo[i])?; + todo.remove(i); + } + } + + for (id, handle) in scheme_net.borrow_mut().handles.iter() { + if let Some(frame) = handle.frames.get(0) { + socket_net.borrow_mut().write(&Packet { + id: 0, + pid: 0, + uid: 0, + gid: 0, + a: syscall::number::SYS_FEVENT, + b: *id, + c: syscall::flag::EVENT_READ, + d: frame.data.len() + })?; + } + } + } + Ok(None) + }).expect("ethernetd: failed to listen for network events"); + + event_queue.add(socket_fd, move |_count: usize| -> Result> { + loop { + let mut packet = Packet::default(); + if socket.borrow_mut().read(&mut packet)? == 0 { + break; + } + + let a = packet.a; + scheme.borrow_mut().handle(&mut packet); + if packet.a == (-EWOULDBLOCK) as usize { + packet.a = a; + todo.borrow_mut().push(packet); + } else { + socket.borrow_mut().write(&mut packet)?; + } + } + + Ok(None) + }).expect("ethernetd: failed to listen for scheme events"); + + event_queue.trigger_all(0).expect("ethernetd: failed to trigger events"); + + event_queue.run().expect("ethernetd: failed to run event loop"); +} + +fn main() { + match syscall::open("network:", syscall::O_RDWR | syscall::O_NONBLOCK) { + Ok(network_fd) => { + // Daemonize + if unsafe { syscall::clone(0).unwrap() } == 0 { + match syscall::open(":ethernet", syscall::O_RDWR | syscall::O_CREAT | syscall::O_NONBLOCK) { + Ok(socket_fd) => { + daemon(network_fd, socket_fd); + }, + Err(err) => { + println!("ethernetd: failed to create ethernet scheme: {}", err); + process::exit(1); + } + } + } + }, + Err(err) => { + println!("ethernetd: failed to open network: {}", err); + process::exit(1); + } + } +} diff --git a/src/ethernetd/scheme.rs b/src/ethernetd/scheme.rs new file mode 100644 index 0000000000..7b1b3bdda9 --- /dev/null +++ b/src/ethernetd/scheme.rs @@ -0,0 +1,164 @@ +use std::collections::{BTreeMap, VecDeque}; +use std::fs::File; +use std::io::{self, Read, Write}; +use std::os::unix::io::AsRawFd; +use std::{cmp, str, u16}; + +use netutils::{getcfg, MacAddr, EthernetII}; +use syscall; +use syscall::error::{Error, Result, EACCES, EBADF, EINVAL, EIO, EWOULDBLOCK}; +use syscall::flag::O_NONBLOCK; +use syscall::scheme::SchemeMut; + +#[derive(Clone)] +pub struct Handle { + /// The flags this handle was opened with + flags: usize, + /// The Host's MAC address + pub host_addr: MacAddr, + /// The ethernet type + pub ethertype: u16, + /// The data + pub frames: VecDeque, +} + +pub struct EthernetScheme { + network: File, + next_id: usize, + pub handles: BTreeMap +} + +impl EthernetScheme { + pub fn new(network: File) -> EthernetScheme { + EthernetScheme { + network: network, + next_id: 1, + handles: BTreeMap::new(), + } + } + + //TODO: Minimize allocation + //TODO: Reduce iteration cost (use BTreeMap of ethertype to handle?) + pub fn input(&mut self) -> io::Result { + let mut total = 0; + loop { + let mut bytes = [0; 65536]; + let count = self.network.read(&mut bytes)?; + if count == 0 { + break; + } + if let Some(frame) = EthernetII::from_bytes(&bytes[.. count]) { + for (_id, handle) in self.handles.iter_mut() { + if frame.header.ethertype.get() == handle.ethertype { + handle.frames.push_back(frame.clone()); + } + } + total += count; + } + } + Ok(total) + } +} + +impl SchemeMut for EthernetScheme { + fn open(&mut self, url: &[u8], flags: usize, uid: u32, _gid: u32) -> Result { + if uid == 0 { + let mac_addr = MacAddr::from_str(&getcfg("mac").map_err(|err| Error::new(err.raw_os_error().unwrap_or(EIO)))?); + let path = try!(str::from_utf8(url).or(Err(Error::new(EINVAL)))); + + let ethertype = u16::from_str_radix(path, 16).unwrap_or(0); + + let next_id = self.next_id; + self.next_id += 1; + + self.handles.insert(next_id, Handle { + flags: flags, + host_addr: mac_addr, + ethertype: ethertype, + frames: VecDeque::new() + }); + + Ok(next_id) + } else { + Err(Error::new(EACCES)) + } + } + + fn dup(&mut self, id: usize, _buf: &[u8]) -> Result { + let next_id = self.next_id; + self.next_id += 1; + + let handle = { + let handle = self.handles.get(&id).ok_or(Error::new(EBADF))?; + handle.clone() + }; + + self.handles.insert(next_id, handle); + + Ok(next_id) + } + + fn read(&mut self, id: usize, buf: &mut [u8]) -> Result { + let handle = self.handles.get_mut(&id).ok_or(Error::new(EBADF))?; + + if let Some(frame) = handle.frames.pop_front() { + let data = frame.to_bytes(); + for (b, d) in buf.iter_mut().zip(data.iter()) { + *b = *d; + } + + Ok(cmp::min(buf.len(), data.len())) + } else if handle.flags & O_NONBLOCK == O_NONBLOCK { + Ok(0) + } else { + Err(Error::new(EWOULDBLOCK)) + } + } + + fn write(&mut self, id: usize, buf: &[u8]) -> Result { + let handle = self.handles.get(&id).ok_or(Error::new(EBADF))?; + + if let Some(mut frame) = EthernetII::from_bytes(buf) { + frame.header.src = handle.host_addr; + frame.header.ethertype.set(handle.ethertype); + self.network.write(&frame.to_bytes()).map_err(|err| Error::new(err.raw_os_error().unwrap_or(EIO))) + } else { + Err(Error::new(EINVAL)) + } + } + + fn fevent(&mut self, id: usize, _flags: usize) -> Result { + let _handle = self.handles.get(&id).ok_or(Error::new(EBADF))?; + + Ok(id) + } + + fn fpath(&mut self, id: usize, buf: &mut [u8]) -> Result { + let handle = self.handles.get(&id).ok_or(Error::new(EBADF))?; + + let path_string = format!("ethernet:{:X}", handle.ethertype); + let path = path_string.as_bytes(); + + let mut i = 0; + while i < buf.len() && i < path.len() { + buf[i] = path[i]; + i += 1; + } + + Ok(i) + } + + fn fsync(&mut self, id: usize) -> Result { + let _handle = self.handles.get(&id).ok_or(Error::new(EBADF))?; + + syscall::fsync(self.network.as_raw_fd()) + } + + fn close(&mut self, id: usize) -> Result { + let handle = self.handles.remove(&id).ok_or(Error::new(EBADF))?; + + drop(handle); + + Ok(0) + } +} diff --git a/src/ipd/interface/ethernet.rs b/src/ipd/interface/ethernet.rs new file mode 100644 index 0000000000..d914a78431 --- /dev/null +++ b/src/ipd/interface/ethernet.rs @@ -0,0 +1,155 @@ +use netutils::{getcfg, n16, Ipv4Addr, MacAddr, Ipv4, EthernetII, EthernetIIHeader, Arp}; +use std::collections::BTreeMap; +use std::fs::File; +use std::io::{Result, Read, Write}; +use std::os::unix::io::FromRawFd; + +use interface::Interface; + +pub struct EthernetInterface { + mac: MacAddr, + ip: Ipv4Addr, + router: Ipv4Addr, + subnet: Ipv4Addr, + arp_file: File, + ip_file: File, + arp: BTreeMap, + rarp: BTreeMap, +} + +impl EthernetInterface { + pub fn new(arp_fd: usize, ip_fd: usize) -> Self { + EthernetInterface { + mac: MacAddr::from_str(&getcfg("mac").unwrap()), + ip: Ipv4Addr::from_str(&getcfg("ip").unwrap()), + router: Ipv4Addr::from_str(&getcfg("ip_router").unwrap()), + subnet: Ipv4Addr::from_str(&getcfg("ip_subnet").unwrap()), + arp_file: unsafe { File::from_raw_fd(arp_fd) }, + ip_file: unsafe { File::from_raw_fd(ip_fd) }, + arp: BTreeMap::new(), + rarp: BTreeMap::new(), + } + } +} + +impl Interface for EthernetInterface { + fn ip(&self) -> Ipv4Addr { + self.ip + } + + fn routable(&self, dst: Ipv4Addr) -> bool { + dst != Ipv4Addr::LOOPBACK + } + + fn arp_event(&mut self) -> Result<()> { + loop { + let mut bytes = [0; 65536]; + let count = self.arp_file.read(&mut bytes)?; + if count == 0 { + break; + } + if let Some(frame) = EthernetII::from_bytes(&bytes[.. count]) { + if let Some(packet) = Arp::from_bytes(&frame.data) { + if packet.header.oper.get() == 1 { + if packet.header.dst_ip == self.ip { + if packet.header.src_ip != Ipv4Addr::BROADCAST && frame.header.src != MacAddr::BROADCAST { + self.arp.insert(packet.header.src_ip, frame.header.src); + self.rarp.insert(frame.header.src, packet.header.src_ip); + } + + let mut response = Arp { + header: packet.header, + data: packet.data.clone(), + }; + response.header.oper.set(2); + response.header.dst_mac = packet.header.src_mac; + response.header.dst_ip = packet.header.src_ip; + response.header.src_mac = self.mac; + response.header.src_ip = self.ip; + + let mut response_frame = EthernetII { + header: frame.header, + data: response.to_bytes() + }; + + response_frame.header.dst = response_frame.header.src; + response_frame.header.src = self.mac; + + self.arp_file.write(&response_frame.to_bytes())?; + } + } + } + } + } + + Ok(()) + } + + fn recv(&mut self) -> Result> { + let mut ips = Vec::new(); + + loop { + let mut bytes = [0; 65536]; + let count = self.ip_file.read(&mut bytes)?; + if count == 0 { + break; + } + if let Some(frame) = EthernetII::from_bytes(&bytes[.. count]) { + if let Some(ip) = Ipv4::from_bytes(&frame.data) { + if ip.header.dst == self.ip || ip.header.dst == Ipv4Addr::BROADCAST { + //TODO: Handle ping here + + if ip.header.src != Ipv4Addr::BROADCAST && frame.header.src != MacAddr::BROADCAST { + self.arp.insert(ip.header.src, frame.header.src); + self.rarp.insert(frame.header.src, ip.header.src); + } + + ips.push(ip); + } + } + } + } + + Ok(ips) + } + + fn send(&mut self, ip: Ipv4) -> Result { + let mut dst = MacAddr::BROADCAST; + if ip.header.dst != Ipv4Addr::BROADCAST { + let mut needs_routing = false; + + for octet in 0..4 { + let me = self.ip.bytes[octet]; + let mask = self.subnet.bytes[octet]; + let them = ip.header.dst.bytes[octet]; + if me & mask != them & mask { + needs_routing = true; + break; + } + } + + let route_addr = if needs_routing { + self.router + } else { + ip.header.dst + }; + + if let Some(mac) = self.arp.get(&route_addr) { + dst = *mac; + } else { + println!("ipd: need to arp {}", route_addr.to_string()); + } + } + + let frame = EthernetII { + header: EthernetIIHeader { + dst: dst, + src: self.mac, + ethertype: n16::new(0x800), + }, + data: ip.to_bytes() + }; + + self.ip_file.write(&frame.to_bytes()) + } +} diff --git a/src/ipd/interface/loopback.rs b/src/ipd/interface/loopback.rs new file mode 100644 index 0000000000..a957ef8818 --- /dev/null +++ b/src/ipd/interface/loopback.rs @@ -0,0 +1,50 @@ +use netutils::{Ipv4Addr, Ipv4}; +use std::io::Result; + +use interface::Interface; + +pub struct LoopbackInterface { + packets: Vec +} + +impl LoopbackInterface { + pub fn new() -> Self { + LoopbackInterface { + packets: Vec::new() + } + } +} + +impl Interface for LoopbackInterface { + fn ip(&self) -> Ipv4Addr { + Ipv4Addr::LOOPBACK + } + + fn routable(&self, dst: Ipv4Addr) -> bool { + dst == Ipv4Addr::LOOPBACK + } + + fn recv(&mut self) -> Result> { + let mut ips = Vec::new(); + + for ip in self.packets.drain(..) { + ips.push(ip); + } + + Ok(ips) + } + + fn send(&mut self, ip: Ipv4) -> Result { + self.packets.push(ip); + + Ok(0) + } + + fn arp_event(&mut self) -> Result<()> { + Ok(()) + } + + fn has_loopback_data(&self) -> bool { + ! self.packets.is_empty() + } +} diff --git a/src/ipd/interface/mod.rs b/src/ipd/interface/mod.rs new file mode 100644 index 0000000000..2fa89d9d2e --- /dev/null +++ b/src/ipd/interface/mod.rs @@ -0,0 +1,19 @@ +use netutils::{Ipv4, Ipv4Addr}; +use std::io::Result; + +pub use self::ethernet::EthernetInterface; +pub use self::loopback::LoopbackInterface; + +mod ethernet; +mod loopback; + +pub trait Interface { + fn ip(&self) -> Ipv4Addr; + fn routable(&self, dst: Ipv4Addr) -> bool; + fn recv(&mut self) -> Result>; + fn send(&mut self, ip: Ipv4) -> Result; + + fn arp_event(&mut self) -> Result<()>; + + fn has_loopback_data(&self) -> bool { false } +} diff --git a/src/ipd/main.rs b/src/ipd/main.rs new file mode 100644 index 0000000000..49e332fcf7 --- /dev/null +++ b/src/ipd/main.rs @@ -0,0 +1,341 @@ +extern crate event; +extern crate netutils; +extern crate syscall; + +use event::EventQueue; +use netutils::{Ipv4Addr, Ipv4, Tcp}; +use std::cell::RefCell; +use std::collections::{BTreeMap, VecDeque}; +use std::fs::File; +use std::io::{self, Read, Write}; +use std::os::unix::io::FromRawFd; +use std::{process, slice, str}; +use std::rc::Rc; +use syscall::data::Packet; +use syscall::error::{Error, Result, EACCES, EADDRNOTAVAIL, EBADF, EIO, EINVAL, ENOENT, EWOULDBLOCK}; +use syscall::flag::{EVENT_READ, O_NONBLOCK}; +use syscall::scheme::SchemeMut; + +use interface::{Interface, EthernetInterface, LoopbackInterface}; + +mod interface; + +struct Handle { + proto: u8, + flags: usize, + events: usize, + data: VecDeque>, + todo: VecDeque, +} + +struct Ipd { + scheme_file: File, + interfaces: Vec>, + next_id: usize, + handles: BTreeMap, +} + +impl Ipd { + fn new(scheme_file: File) -> Self { + Ipd { + scheme_file: scheme_file, + interfaces: Vec::new(), + next_id: 1, + handles: BTreeMap::new(), + } + } + + fn scheme_event(&mut self) -> io::Result<()> { + loop { + let mut packet = Packet::default(); + if self.scheme_file.read(&mut packet)? == 0 { + break; + } + + let a = packet.a; + self.handle(&mut packet); + if packet.a == (-EWOULDBLOCK) as usize { + packet.a = a; + if let Some(mut handle) = self.handles.get_mut(&packet.b) { + handle.todo.push_back(packet); + } + } else { + self.scheme_file.write(&packet)?; + } + } + + Ok(()) + } + + fn ip_event(&mut self, if_id: usize) -> io::Result<()> { + if let Some(mut interface) = self.interfaces.get_mut(if_id) { + for ip in interface.recv()? { + for (id, handle) in self.handles.iter_mut() { + if ip.header.proto == handle.proto { + handle.data.push_back(ip.to_bytes()); + + while ! handle.todo.is_empty() && ! handle.data.is_empty() { + let mut packet = handle.todo.pop_front().unwrap(); + let buf = unsafe { slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) }; + let data = handle.data.pop_front().unwrap(); + + let mut i = 0; + while i < buf.len() && i < data.len() { + buf[i] = data[i]; + i += 1; + } + packet.a = i; + + self.scheme_file.write(&packet)?; + } + + if handle.events & EVENT_READ == EVENT_READ { + if let Some(data) = handle.data.get(0) { + self.scheme_file.write(&Packet { + id: 0, + pid: 0, + uid: 0, + gid: 0, + a: syscall::number::SYS_FEVENT, + b: *id, + c: EVENT_READ, + d: data.len() + })?; + } + } + } + } + } + } + + Ok(()) + } + + fn loopback_event(&mut self, loopback_id: usize) -> io::Result<()> { + let handle_loopback = if let Some(interface) = self.interfaces.get(loopback_id) { + interface.has_loopback_data() + } else { + false + }; + + if handle_loopback { + self.ip_event(loopback_id)?; + } + + Ok(()) + } +} + +impl SchemeMut for Ipd { + fn open(&mut self, url: &[u8], flags: usize, uid: u32, _gid: u32) -> Result { + if uid == 0 { + let path = str::from_utf8(url).or(Err(Error::new(EINVAL)))?; + + let proto = u8::from_str_radix(path, 16).or(Err(Error::new(ENOENT)))?; + + let id = self.next_id; + self.next_id += 1; + + self.handles.insert(id, Handle { + proto: proto, + flags: flags, + events: 0, + data: VecDeque::new(), + todo: VecDeque::new(), + }); + + Ok(id) + } else { + Err(Error::new(EACCES)) + } + } + + fn dup(&mut self, file: usize, _buf: &[u8]) -> Result { + let handle = { + let handle = self.handles.get(&file).ok_or(Error::new(EBADF))?; + Handle { + proto: handle.proto, + flags: handle.flags, + events: 0, + data: handle.data.clone(), + todo: VecDeque::new(), + } + }; + + let id = self.next_id; + self.next_id += 1; + + self.handles.insert(id, handle); + + Ok(id) + } + + fn read(&mut self, file: usize, buf: &mut [u8]) -> Result { + let mut handle = self.handles.get_mut(&file).ok_or(Error::new(EBADF))?; + + if let Some(data) = handle.data.pop_front() { + let mut i = 0; + while i < buf.len() && i < data.len() { + buf[i] = data[i]; + i += 1; + } + + Ok(i) + } else if handle.flags & O_NONBLOCK == O_NONBLOCK { + Ok(0) + } else { + Err(Error::new(EWOULDBLOCK)) + } + } + + fn write(&mut self, file: usize, buf: &[u8]) -> Result { + let handle = self.handles.get(&file).ok_or(Error::new(EBADF))?; + + if let Some(mut ip) = Ipv4::from_bytes(buf) { + for mut interface in self.interfaces.iter_mut() { + let if_ip = interface.ip(); + if ip.header.src == if_ip || (ip.header.src == Ipv4Addr::NULL && interface.routable(ip.header.dst)) { + ip.header.src = if_ip; + ip.header.proto = handle.proto; + + if let Some(mut tcp) = Tcp::from_bytes(&ip.data) { + tcp.checksum(&ip.header.src, &ip.header.dst); + ip.data = tcp.to_bytes(); + } + + ip.checksum(); + + interface.send(ip).map_err(|err| Error::new(err.raw_os_error().unwrap_or(EIO)))?; + + return Ok(buf.len()); + } + } + + Err(Error::new(EADDRNOTAVAIL)) + } else { + Err(Error::new(EINVAL)) + } + } + + fn fevent(&mut self, file: usize, flags: usize) -> Result { + let mut handle = self.handles.get_mut(&file).ok_or(Error::new(EBADF))?; + + handle.events = flags; + + Ok(file) + } + + fn fpath(&mut self, id: usize, buf: &mut [u8]) -> Result { + let handle = self.handles.get(&id).ok_or(Error::new(EBADF))?; + + let path_string = format!("ip:{:X}", handle.proto); + let path = path_string.as_bytes(); + + let mut i = 0; + while i < buf.len() && i < path.len() { + buf[i] = path[i]; + i += 1; + } + + Ok(i) + } + + fn fsync(&mut self, file: usize) -> Result { + let _handle = self.handles.get(&file).ok_or(Error::new(EBADF))?; + + Ok(0) + } + + fn close(&mut self, file: usize) -> Result { + let handle = self.handles.remove(&file).ok_or(Error::new(EBADF))?; + + drop(handle); + + Ok(0) + } +} + +fn daemon(arp_fd: usize, ip_fd: usize, scheme_fd: usize) { + let scheme_file = unsafe { File::from_raw_fd(scheme_fd) }; + + let ipd = Rc::new(RefCell::new(Ipd::new(scheme_file))); + + let mut event_queue = EventQueue::<()>::new().expect("ipd: failed to create event queue"); + + //TODO: Multiple interfaces + { + let if_id = { + let mut ipd = ipd.borrow_mut(); + let if_id = ipd.interfaces.len(); + ipd.interfaces.push(Box::new(EthernetInterface::new(arp_fd, ip_fd))); + if_id + }; + + let arp_ipd = ipd.clone(); + event_queue.add(arp_fd, move |_count: usize| -> io::Result> { + if let Some(mut interface) = arp_ipd.borrow_mut().interfaces.get_mut(if_id) { + interface.arp_event()?; + } + + Ok(None) + }).expect("ipd: failed to listen to events on ethernet:806"); + + let ip_ipd = ipd.clone(); + event_queue.add(ip_fd, move |_count: usize| -> io::Result> { + ip_ipd.borrow_mut().ip_event(if_id)?; + + Ok(None) + }).expect("ipd: failed to listen to events on ethernet:800"); + } + + let loopback_id = { + let mut ipd = ipd.borrow_mut(); + let if_id = ipd.interfaces.len(); + ipd.interfaces.push(Box::new(LoopbackInterface::new())); + if_id + }; + + event_queue.add(scheme_fd, move |_count: usize| -> io::Result> { + let mut ipd = ipd.borrow_mut(); + + ipd.loopback_event(loopback_id)?; + ipd.scheme_event()?; + ipd.loopback_event(loopback_id)?; + + Ok(None) + }).expect("ipd: failed to listen to events on :ip"); + + // Make sure that all descriptors are at EOF + event_queue.trigger_all(0).expect("ipd: failed to trigger event queue"); + + event_queue.run().expect("ipd: failed to run event queue"); +} + +fn main() { + match syscall::open("ethernet:806", syscall::O_RDWR | syscall::O_NONBLOCK) { + Ok(arp_fd) => match syscall::open("ethernet:800", syscall::O_RDWR | syscall::O_NONBLOCK) { + Ok(ip_fd) => { + // Daemonize + if unsafe { syscall::clone(0).unwrap() } == 0 { + match syscall::open(":ip", syscall::O_RDWR | syscall::O_CREAT | syscall::O_NONBLOCK) { + Ok(scheme_fd) => { + daemon(arp_fd, ip_fd, scheme_fd); + }, + Err(err) => { + println!("ipd: failed to create ip scheme: {}", err); + process::exit(1); + } + } + } + }, + Err(err) => { + println!("ipd: failed to open ethernet:800: {}", err); + process::exit(1); + } + }, + Err(err) => { + println!("ipd: failed to open ethernet:806: {}", err); + process::exit(1); + } + } +} diff --git a/src/tcpd/main.rs b/src/tcpd/main.rs new file mode 100644 index 0000000000..8878b006f3 --- /dev/null +++ b/src/tcpd/main.rs @@ -0,0 +1,937 @@ +extern crate event; +extern crate netutils; +extern crate rand; +extern crate syscall; + +use rand::{Rng, OsRng}; +use std::collections::{BTreeMap, VecDeque}; +use std::cell::RefCell; +use std::fs::File; +use std::io::{self, Read, Write}; +use std::{mem, process, slice, str}; +use std::ops::{Deref, DerefMut}; +use std::os::unix::io::FromRawFd; +use std::rc::Rc; + +use event::EventQueue; +use netutils::{n16, n32, Ipv4, Ipv4Addr, Ipv4Header, Tcp, TcpHeader, Checksum, TCP_FIN, TCP_SYN, TCP_RST, TCP_PSH, TCP_ACK}; +use syscall::data::{Packet, TimeSpec}; +use syscall::error::{Error, Result, EACCES, EADDRINUSE, EBADF, EIO, EINVAL, EISCONN, EMSGSIZE, ENOTCONN, ETIMEDOUT, EWOULDBLOCK}; +use syscall::flag::{CLOCK_MONOTONIC, EVENT_READ, F_GETFL, F_SETFL, O_ACCMODE, O_CREAT, O_RDWR, O_NONBLOCK}; +use syscall::scheme::SchemeMut; + +fn add_time(a: &TimeSpec, b: &TimeSpec) -> TimeSpec { + let mut secs = a.tv_sec + b.tv_sec; + + let mut nsecs = a.tv_nsec + b.tv_nsec; + while nsecs >= 1000000000 { + nsecs -= 1000000000; + secs += 1; + } + + TimeSpec { + tv_sec: secs, + tv_nsec: nsecs + } +} + +fn parse_socket(socket: &str) -> (Ipv4Addr, u16) { + let mut socket_parts = socket.split(":"); + let host = Ipv4Addr::from_str(socket_parts.next().unwrap_or("")); + let port = socket_parts.next().unwrap_or("").parse::().unwrap_or(0); + (host, port) +} + +#[derive(Copy, Clone, Debug, Eq, PartialEq)] +enum State { + Listen, + SynSent, + SynReceived, + Established, + FinWait1, + FinWait2, + CloseWait, + Closing, + LastAck, + TimeWait, + Closed +} + +struct TcpHandle { + local: (Ipv4Addr, u16), + remote: (Ipv4Addr, u16), + flags: usize, + events: usize, + read_timeout: Option, + write_timeout: Option, + ttl: u8, + state: State, + seq: u32, + ack: u32, + data: VecDeque<(Ipv4, Tcp)>, + todo_dup: VecDeque, + todo_read: VecDeque<(Option, Packet)>, + todo_write: VecDeque<(Option, Packet)>, +} + +impl TcpHandle { + fn is_connected(&self) -> bool { + self.remote.0 != Ipv4Addr::NULL && self.remote.1 != 0 + } + + fn read_closed(&self) -> bool { + self.state == State::CloseWait || self.state == State::LastAck || self.state == State::TimeWait || self.state == State::Closed + } + + fn matches(&self, ip: &Ipv4, tcp: &Tcp) -> bool { + // Local address not set or IP dst matches or is broadcast + (self.local.0 == Ipv4Addr::NULL || ip.header.dst == self.local.0 || ip.header.dst == Ipv4Addr::BROADCAST) + // Local port matches UDP dst + && tcp.header.dst.get() == self.local.1 + // Remote address not set or is broadcast, or IP src matches + && (self.remote.0 == Ipv4Addr::NULL || self.remote.0 == Ipv4Addr::BROADCAST || ip.header.src == self.remote.0) + // Remote port not set or UDP src matches + && (self.remote.1 == 0 || tcp.header.src.get() == self.remote.1) + } + + fn create_tcp(&self, flags: u16, data: Vec) -> Tcp { + Tcp { + header: TcpHeader { + src: n16::new(self.local.1), + dst: n16::new(self.remote.1), + sequence: n32::new(self.seq), + ack_num: n32::new(self.ack), + flags: n16::new(((mem::size_of::() << 10) & 0xF000) as u16 | (flags & 0xFFF)), + window_size: n16::new(8192), + checksum: Checksum { data: 0 }, + urgent_pointer: n16::new(0), + }, + options: Vec::new(), + data: data + } + } + + fn create_ip(&self, id: u16, data: Vec) -> Ipv4 { + Ipv4 { + header: Ipv4Header { + ver_hlen: 0x45, + services: 0, + len: n16::new((data.len() + mem::size_of::()) as u16), + id: n16::new(id), + flags_fragment: n16::new(0), + ttl: self.ttl, + proto: 0x06, + checksum: Checksum { data: 0 }, + src: self.local.0, + dst: self.remote.0 + }, + options: Vec::new(), + data: data + } + } +} + +#[derive(Copy, Clone)] +enum SettingKind { + Ttl, + ReadTimeout, + WriteTimeout +} + +enum Handle { + Tcp(TcpHandle), + Setting(usize, SettingKind), +} + +struct Tcpd { + scheme_file: File, + tcp_file: File, + time_file: File, + ports: BTreeMap, + next_id: usize, + handles: BTreeMap, + rng: OsRng, +} + +impl Tcpd { + fn new(scheme_file: File, tcp_file: File, time_file: File) -> Self { + Tcpd { + scheme_file: scheme_file, + tcp_file: tcp_file, + time_file: time_file, + ports: BTreeMap::new(), + next_id: 1, + handles: BTreeMap::new(), + rng: OsRng::new().expect("tcpd: failed to open RNG") + } + } + + fn scheme_event(&mut self) -> io::Result<()> { + loop { + let mut packet = Packet::default(); + if self.scheme_file.read(&mut packet)? == 0 { + break; + } + + let a = packet.a; + self.handle(&mut packet); + if packet.a == (-EWOULDBLOCK) as usize { + if let Some(mut handle) = self.handles.get_mut(&packet.b) { + if let Handle::Tcp(ref mut handle) = *handle { + match a { + syscall::number::SYS_DUP => { + packet.a = a; + handle.todo_dup.push_back(packet); + }, + syscall::number::SYS_READ => { + packet.a = a; + + let timeout = match handle.read_timeout { + Some(read_timeout) => { + let mut time = TimeSpec::default(); + syscall::clock_gettime(CLOCK_MONOTONIC, &mut time).map_err(|err| io::Error::from_raw_os_error(err.errno))?; + + let timeout = add_time(&time, &read_timeout); + self.time_file.write(&timeout)?; + Some(timeout) + }, + None => None + }; + + handle.todo_read.push_back((timeout, packet)); + }, + syscall::number::SYS_WRITE => { + packet.a = a; + + let timeout = match handle.write_timeout { + Some(write_timeout) => { + let mut time = TimeSpec::default(); + syscall::clock_gettime(CLOCK_MONOTONIC, &mut time).map_err(|err| io::Error::from_raw_os_error(err.errno))?; + + let timeout = add_time(&time, &write_timeout); + self.time_file.write(&timeout)?; + Some(timeout) + }, + None => None + }; + + handle.todo_write.push_back((timeout, packet)); + }, + _ => { + self.scheme_file.write(&packet)?; + } + } + } + } + } else { + self.scheme_file.write(&packet)?; + } + } + + Ok(()) + } + + fn tcp_event(&mut self) -> io::Result<()> { + loop { + let mut bytes = [0; 65536]; + let count = self.tcp_file.read(&mut bytes)?; + if count == 0 { + break; + } + if let Some(ip) = Ipv4::from_bytes(&bytes[.. count]) { + if let Some(tcp) = Tcp::from_bytes(&ip.data) { + let mut closing = Vec::new(); + let mut found_connection = false; + for (id, handle) in self.handles.iter_mut() { + if let Handle::Tcp(ref mut handle) = *handle { + if handle.state != State::Listen && handle.matches(&ip, &tcp) { + found_connection = true; + + match handle.state { + State::SynReceived => if tcp.header.flags.get() & (TCP_SYN | TCP_ACK) == TCP_ACK && tcp.header.ack_num.get() == handle.seq { + handle.state = State::Established; + }, + State::SynSent => if tcp.header.flags.get() & (TCP_SYN | TCP_ACK) == TCP_SYN | TCP_ACK && tcp.header.ack_num.get() == handle.seq { + handle.state = State::Established; + handle.ack = tcp.header.sequence.get() + 1; + + let tcp = handle.create_tcp(TCP_ACK, Vec::new()); + let ip = handle.create_ip(self.rng.gen(), tcp.to_bytes()); + self.tcp_file.write(&ip.to_bytes())?; + }, + State::Established => if tcp.header.flags.get() & (TCP_SYN | TCP_ACK) == TCP_ACK && tcp.header.ack_num.get() == handle.seq { + handle.ack = tcp.header.sequence.get(); + + if ! tcp.data.is_empty() { + handle.data.push_back((ip.clone(), tcp.clone())); + handle.ack += tcp.data.len() as u32; + + let tcp = handle.create_tcp(TCP_ACK, Vec::new()); + let ip = handle.create_ip(self.rng.gen(), tcp.to_bytes()); + self.tcp_file.write(&ip.to_bytes())?; + } else if tcp.header.flags.get() & TCP_FIN == TCP_FIN { + handle.state = State::CloseWait; + + handle.ack += 1; + + let tcp = handle.create_tcp(TCP_ACK, Vec::new()); + let ip = handle.create_ip(self.rng.gen(), tcp.to_bytes()); + self.tcp_file.write(&ip.to_bytes())?; + } + }, + //TODO: Time wait + State::FinWait1 => if tcp.header.flags.get() & (TCP_SYN | TCP_ACK) == TCP_ACK && tcp.header.ack_num.get() == handle.seq { + handle.ack = tcp.header.sequence.get() + 1; + + if tcp.header.flags.get() & TCP_FIN == TCP_FIN { + handle.state = State::TimeWait; + + let tcp = handle.create_tcp(TCP_ACK, Vec::new()); + let ip = handle.create_ip(self.rng.gen(), tcp.to_bytes()); + self.tcp_file.write(&ip.to_bytes())?; + + closing.push(*id); + } else { + handle.state = State::FinWait2; + } + }, + State::FinWait2 => if tcp.header.flags.get() & (TCP_SYN | TCP_ACK | TCP_FIN) == TCP_ACK | TCP_FIN && tcp.header.ack_num.get() == handle.seq { + handle.ack = tcp.header.sequence.get() + 1; + + handle.state = State::TimeWait; + + let tcp = handle.create_tcp(TCP_ACK, Vec::new()); + let ip = handle.create_ip(self.rng.gen(), tcp.to_bytes()); + self.tcp_file.write(&ip.to_bytes())?; + + closing.push(*id); + }, + State::LastAck => if tcp.header.flags.get() & (TCP_SYN | TCP_ACK) == TCP_ACK && tcp.header.ack_num.get() == handle.seq { + handle.state = State::Closed; + closing.push(*id); + }, + _ => () + } + + while ! handle.todo_read.is_empty() && (! handle.data.is_empty() || handle.read_closed()) { + let (_timeout, mut packet) = handle.todo_read.pop_front().unwrap(); + let buf = unsafe { slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) }; + if let Some((_ip, tcp)) = handle.data.pop_front() { + let mut i = 0; + while i < buf.len() && i < tcp.data.len() { + buf[i] = tcp.data[i]; + i += 1; + } + packet.a = i; + } else { + packet.a = 0; + } + + self.scheme_file.write(&packet)?; + } + + if ! handle.todo_write.is_empty() && handle.state == State::Established { + let (_timeout, mut packet) = handle.todo_write.pop_front().unwrap(); + let buf = unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }; + + let tcp = handle.create_tcp(TCP_ACK | TCP_PSH, buf.to_vec()); + let ip = handle.create_ip(self.rng.gen(), tcp.to_bytes()); + let result = self.tcp_file.write(&ip.to_bytes()).map_err(|err| Error::new(err.raw_os_error().unwrap_or(EIO))); + if result.is_ok() { + handle.seq += buf.len() as u32; + } + packet.a = Error::mux(result.and(Ok(buf.len()))); + + self.scheme_file.write(&packet)?; + } + + if handle.events & EVENT_READ == EVENT_READ { + if let Some(&(ref _ip, ref tcp)) = handle.data.get(0) { + self.scheme_file.write(&Packet { + id: 0, + pid: 0, + uid: 0, + gid: 0, + a: syscall::number::SYS_FEVENT, + b: *id, + c: EVENT_READ, + d: tcp.data.len() + })?; + } + } + } + } + } + + for file in closing { + if let Handle::Tcp(handle) = self.handles.remove(&file).unwrap() { + let remove = if let Some(mut port) = self.ports.get_mut(&handle.local.1) { + *port = *port + 1; + *port == 0 + } else { + false + }; + + if remove { + self.ports.remove(&handle.local.1); + } + } + } + + if ! found_connection && tcp.header.flags.get() & (TCP_SYN | TCP_ACK) == TCP_SYN { + let mut new_handles = Vec::new(); + + for (_id, handle) in self.handles.iter_mut() { + if let Handle::Tcp(ref mut handle) = *handle { + if handle.state == State::Listen && handle.matches(&ip, &tcp) { + handle.data.push_back((ip.clone(), tcp.clone())); + + while ! handle.todo_dup.is_empty() && ! handle.data.is_empty() { + let mut packet = handle.todo_dup.pop_front().unwrap(); + let (ip, tcp) = handle.data.pop_front().unwrap(); + + let mut new_handle = TcpHandle { + local: handle.local, + remote: (ip.header.src, tcp.header.src.get()), + flags: handle.flags, + events: 0, + read_timeout: handle.read_timeout, + write_timeout: handle.write_timeout, + ttl: handle.ttl, + state: State::SynReceived, + seq: self.rng.gen(), + ack: tcp.header.sequence.get() + 1, + data: VecDeque::new(), + todo_dup: VecDeque::new(), + todo_read: VecDeque::new(), + todo_write: VecDeque::new(), + }; + + let tcp = new_handle.create_tcp(TCP_SYN | TCP_ACK, Vec::new()); + let ip = new_handle.create_ip(self.rng.gen(), tcp.to_bytes()); + self.tcp_file.write(&ip.to_bytes())?; + + new_handle.seq += 1; + + handle.data.retain(|&(ref ip, ref tcp)| { + if new_handle.matches(ip, tcp) { + false + } else { + true + } + }); + + if let Some(mut port) = self.ports.get_mut(&handle.local.1) { + *port = *port + 1; + } + + let id = self.next_id; + self.next_id += 1; + + packet.a = id; + + new_handles.push((packet, Handle::Tcp(new_handle))); + } + } + } + } + + for (packet, new_handle) in new_handles { + self.handles.insert(packet.a, new_handle); + self.scheme_file.write(&packet)?; + } + } + } + } + } + + Ok(()) + } + + fn time_event(&mut self) -> io::Result<()> { + let mut time = TimeSpec::default(); + if self.time_file.read(&mut time)? < mem::size_of::() { + return Err(io::Error::from_raw_os_error(EINVAL)); + } + + for (_id, handle) in self.handles.iter_mut() { + if let Handle::Tcp(ref mut handle) = *handle { + let mut i = 0; + while i < handle.todo_read.len() { + if let Some(timeout) = handle.todo_read.get(i).map(|e| e.0.clone()).unwrap_or(None) { + if time.tv_sec > timeout.tv_sec || (time.tv_sec == timeout.tv_sec && time.tv_nsec >= timeout.tv_nsec) { + let (_timeout, mut packet) = handle.todo_read.remove(i).unwrap(); + packet.a = (-ETIMEDOUT) as usize; + self.scheme_file.write(&packet)?; + } else { + i += 1; + } + } else { + i += 1; + } + } + + let mut i = 0; + while i < handle.todo_write.len() { + if let Some(timeout) = handle.todo_write.get(i).map(|e| e.0.clone()).unwrap_or(None) { + if time.tv_sec > timeout.tv_sec || (time.tv_sec == timeout.tv_sec && time.tv_nsec >= timeout.tv_nsec) { + let (_timeout, mut packet) = handle.todo_write.remove(i).unwrap(); + packet.a = (-ETIMEDOUT) as usize; + self.scheme_file.write(&packet)?; + } else { + i += 1; + } + } else { + i += 1; + } + } + } + } + + Ok(()) + } +} + +impl SchemeMut for Tcpd { + fn open(&mut self, url: &[u8], flags: usize, uid: u32, _gid: u32) -> Result { + let path = str::from_utf8(url).or(Err(Error::new(EINVAL)))?; + + let mut parts = path.split("/"); + let remote = parse_socket(parts.next().unwrap_or("")); + let mut local = parse_socket(parts.next().unwrap_or("")); + + if local.1 == 0 { + local.1 = self.rng.gen_range(32768, 65535); + } + + if local.1 <= 1024 && uid != 0 { + return Err(Error::new(EACCES)); + } + + if self.ports.contains_key(&local.1) { + return Err(Error::new(EADDRINUSE)); + } + + let mut handle = TcpHandle { + local: local, + remote: remote, + flags: flags, + events: 0, + read_timeout: None, + write_timeout: None, + ttl: 64, + state: State::Listen, + seq: 0, + ack: 0, + data: VecDeque::new(), + todo_dup: VecDeque::new(), + todo_read: VecDeque::new(), + todo_write: VecDeque::new(), + }; + + if handle.is_connected() { + handle.seq = self.rng.gen(); + handle.ack = 0; + handle.state = State::SynSent; + + let tcp = handle.create_tcp(TCP_SYN, Vec::new()); + let ip = handle.create_ip(self.rng.gen(), tcp.to_bytes()); + self.tcp_file.write(&ip.to_bytes()).map_err(|err| Error::new(err.raw_os_error().unwrap_or(EIO)))?; + + handle.seq += 1; + } + + self.ports.insert(local.1, 1); + + let id = self.next_id; + self.next_id += 1; + + self.handles.insert(id, Handle::Tcp(handle)); + + Ok(id) + } + + fn dup(&mut self, file: usize, buf: &[u8]) -> Result { + let handle = match *self.handles.get_mut(&file).ok_or(Error::new(EBADF))? { + Handle::Tcp(ref mut handle) => { + let mut new_handle = TcpHandle { + local: handle.local, + remote: handle.remote, + flags: handle.flags, + events: 0, + read_timeout: handle.read_timeout, + write_timeout: handle.write_timeout, + ttl: handle.ttl, + state: handle.state, + seq: handle.seq, + ack: handle.ack, + data: VecDeque::new(), + todo_dup: VecDeque::new(), + todo_read: VecDeque::new(), + todo_write: VecDeque::new(), + }; + + let path = str::from_utf8(buf).or(Err(Error::new(EINVAL)))?; + + if path == "ttl" { + Handle::Setting(file, SettingKind::Ttl) + } else if path == "read_timeout" { + Handle::Setting(file, SettingKind::ReadTimeout) + } else if path == "write_timeout" { + Handle::Setting(file, SettingKind::WriteTimeout) + } else if path == "listen" { + if handle.is_connected() { + return Err(Error::new(EISCONN)); + } else if let Some((ip, tcp)) = handle.data.pop_front() { + new_handle.remote = (ip.header.src, tcp.header.src.get()); + + new_handle.seq = self.rng.gen(); + new_handle.ack = tcp.header.sequence.get() + 1; + new_handle.state = State::SynReceived; + + let tcp = new_handle.create_tcp(TCP_SYN | TCP_ACK, Vec::new()); + let ip = new_handle.create_ip(self.rng.gen(), tcp.to_bytes()); + self.tcp_file.write(&ip.to_bytes()).map_err(|err| Error::new(err.raw_os_error().unwrap_or(EIO))).and(Ok(buf.len()))?; + + new_handle.seq += 1; + } else { + return Err(Error::new(EWOULDBLOCK)); + } + + handle.data.retain(|&(ref ip, ref tcp)| { + if new_handle.matches(ip, tcp) { + false + } else { + true + } + }); + + Handle::Tcp(new_handle) + } else if path.is_empty() { + new_handle.data = handle.data.clone(); + + Handle::Tcp(new_handle) + } else if handle.is_connected() { + return Err(Error::new(EISCONN)); + } else { + new_handle.remote = parse_socket(path); + + if new_handle.is_connected() { + new_handle.seq = self.rng.gen(); + new_handle.ack = 0; + new_handle.state = State::SynSent; + + handle.data.retain(|&(ref ip, ref tcp)| { + if new_handle.matches(ip, tcp) { + new_handle.data.push_back((ip.clone(), tcp.clone())); + false + } else { + true + } + }); + + let tcp = new_handle.create_tcp(TCP_SYN, Vec::new()); + let ip = new_handle.create_ip(self.rng.gen(), tcp.to_bytes()); + self.tcp_file.write(&ip.to_bytes()).map_err(|err| Error::new(err.raw_os_error().unwrap_or(EIO))).and(Ok(buf.len()))?; + + new_handle.seq += 1; + + Handle::Tcp(new_handle) + } else { + return Err(Error::new(EINVAL)); + } + } + }, + Handle::Setting(file, kind) => { + Handle::Setting(file, kind) + } + }; + + let id = self.next_id; + self.next_id += 1; + + self.handles.insert(id, handle); + + Ok(id) + } + + fn read(&mut self, file: usize, buf: &mut [u8]) -> Result { + let (file, kind) = match *self.handles.get_mut(&file).ok_or(Error::new(EBADF))? { + Handle::Tcp(ref mut handle) => { + if ! handle.is_connected() { + return Err(Error::new(ENOTCONN)); + } else if let Some((ip, mut tcp)) = handle.data.pop_front() { + let len = std::cmp::min(buf.len(), tcp.data.len()); + for (i, c) in tcp.data.drain(0..len).enumerate() { + buf[i] = c; + } + if !tcp.data.is_empty() { + handle.data.push_front((ip, tcp)); + } + + return Ok(len); + } else if handle.flags & O_NONBLOCK == O_NONBLOCK || handle.read_closed() { + return Ok(0); + } else { + return Err(Error::new(EWOULDBLOCK)); + } + }, + Handle::Setting(file, kind) => { + (file, kind) + } + }; + + if let Handle::Tcp(ref mut handle) = *self.handles.get_mut(&file).ok_or(Error::new(EBADF))? { + let get_timeout = |timeout: &Option, buf: &mut [u8]| -> Result { + if let Some(ref timespec) = *timeout { + timespec.deref().read(buf).map_err(|err| Error::new(err.raw_os_error().unwrap_or(EIO))) + } else { + Ok(0) + } + }; + + match kind { + SettingKind::Ttl => { + if let Some(mut ttl) = buf.get_mut(0) { + *ttl = handle.ttl; + Ok(1) + } else { + Ok(0) + } + }, + SettingKind::ReadTimeout => { + get_timeout(&handle.read_timeout, buf) + }, + SettingKind::WriteTimeout => { + get_timeout(&handle.write_timeout, buf) + } + } + } else { + Err(Error::new(EBADF)) + } + } + + fn write(&mut self, file: usize, buf: &[u8]) -> Result { + let (file, kind) = match *self.handles.get_mut(&file).ok_or(Error::new(EBADF))? { + Handle::Tcp(ref mut handle) => { + if ! handle.is_connected() { + return Err(Error::new(ENOTCONN)); + } else if buf.len() >= 65507 { + return Err(Error::new(EMSGSIZE)); + } else { + match handle.state { + State::Established => { + let tcp = handle.create_tcp(TCP_ACK | TCP_PSH, buf.to_vec()); + let ip = handle.create_ip(self.rng.gen(), tcp.to_bytes()); + self.tcp_file.write(&ip.to_bytes()).map_err(|err| Error::new(err.raw_os_error().unwrap_or(EIO)))?; + handle.seq += buf.len() as u32; + return Ok(buf.len()); + }, + _ => { + return Err(Error::new(EWOULDBLOCK)); + } + } + } + }, + Handle::Setting(file, kind) => { + (file, kind) + } + }; + + if let Handle::Tcp(ref mut handle) = *self.handles.get_mut(&file).ok_or(Error::new(EBADF))? { + let set_timeout = |timeout: &mut Option, buf: &[u8]| -> Result { + if buf.len() >= mem::size_of::() { + let mut timespec = TimeSpec::default(); + let count = timespec.deref_mut().write(buf).map_err(|err| Error::new(err.raw_os_error().unwrap_or(EIO)))?; + *timeout = Some(timespec); + Ok(count) + } else { + *timeout = None; + Ok(0) + } + }; + + match kind { + SettingKind::Ttl => { + if let Some(ttl) = buf.get(0) { + handle.ttl = *ttl; + Ok(1) + } else { + Ok(0) + } + }, + SettingKind::ReadTimeout => { + set_timeout(&mut handle.read_timeout, buf) + }, + SettingKind::WriteTimeout => { + set_timeout(&mut handle.write_timeout, buf) + } + } + } else { + Err(Error::new(EBADF)) + } + } + + fn fcntl(&mut self, file: usize, cmd: usize, arg: usize) -> Result { + if let Handle::Tcp(ref mut handle) = *self.handles.get_mut(&file).ok_or(Error::new(EBADF))? { + match cmd { + F_GETFL => Ok(handle.flags), + F_SETFL => { + handle.flags = arg & ! O_ACCMODE; + Ok(0) + }, + _ => Err(Error::new(EINVAL)) + } + } else { + Err(Error::new(EBADF)) + } + } + + fn fevent(&mut self, file: usize, flags: usize) -> Result { + if let Handle::Tcp(ref mut handle) = *self.handles.get_mut(&file).ok_or(Error::new(EBADF))? { + handle.events = flags; + Ok(file) + } else { + Err(Error::new(EBADF)) + } + } + + fn fpath(&mut self, file: usize, buf: &mut [u8]) -> Result { + if let Handle::Tcp(ref mut handle) = *self.handles.get_mut(&file).ok_or(Error::new(EBADF))? { + let path_string = format!("udp:{}:{}/{}:{}", handle.remote.0.to_string(), handle.remote.1, handle.local.0.to_string(), handle.local.1); + let path = path_string.as_bytes(); + + let mut i = 0; + while i < buf.len() && i < path.len() { + buf[i] = path[i]; + i += 1; + } + + Ok(i) + } else { + Err(Error::new(EBADF)) + } + } + + fn fsync(&mut self, file: usize) -> Result { + let _handle = self.handles.get(&file).ok_or(Error::new(EBADF))?; + + Ok(0) + } + + fn close(&mut self, file: usize) -> Result { + let closed = { + if let Handle::Tcp(ref mut handle) = *self.handles.get_mut(&file).ok_or(Error::new(EBADF))? { + handle.data.clear(); + + match handle.state { + State::SynReceived | State::Established => { + handle.state = State::FinWait1; + + let tcp = handle.create_tcp(TCP_FIN | TCP_ACK, Vec::new()); + let ip = handle.create_ip(self.rng.gen(), tcp.to_bytes()); + self.tcp_file.write(&ip.to_bytes()).map_err(|err| Error::new(err.raw_os_error().unwrap_or(EIO)))?; + + handle.seq += 1; + + false + }, + State::CloseWait => { + handle.state = State::LastAck; + + let tcp = handle.create_tcp(TCP_FIN | TCP_ACK, Vec::new()); + let ip = handle.create_ip(self.rng.gen(), tcp.to_bytes()); + self.tcp_file.write(&ip.to_bytes()).map_err(|err| Error::new(err.raw_os_error().unwrap_or(EIO)))?; + + handle.seq += 1; + + false + }, + _ => true + } + } else { + true + } + }; + + if closed { + if let Handle::Tcp(handle) = self.handles.remove(&file).ok_or(Error::new(EBADF))? { + let remove = if let Some(mut port) = self.ports.get_mut(&handle.local.1) { + *port = *port + 1; + *port == 0 + } else { + false + }; + + if remove { + self.ports.remove(&handle.local.1); + } + } + } + + Ok(0) + } +} + +fn daemon(scheme_fd: usize, tcp_fd: usize, time_fd: usize) { + let scheme_file = unsafe { File::from_raw_fd(scheme_fd) }; + let tcp_file = unsafe { File::from_raw_fd(tcp_fd) }; + let time_file = unsafe { File::from_raw_fd(time_fd) }; + + let tcpd = Rc::new(RefCell::new(Tcpd::new(scheme_file, tcp_file, time_file))); + + let mut event_queue = EventQueue::<()>::new().expect("tcpd: failed to create event queue"); + + let time_tcpd = tcpd.clone(); + event_queue.add(time_fd, move |_count: usize| -> io::Result> { + time_tcpd.borrow_mut().time_event()?; + Ok(None) + }).expect("tcpd: failed to listen to events on time:"); + + let tcp_tcpd = tcpd.clone(); + event_queue.add(tcp_fd, move |_count: usize| -> io::Result> { + tcp_tcpd.borrow_mut().tcp_event()?; + Ok(None) + }).expect("tcpd: failed to listen to events on ip:6"); + + event_queue.add(scheme_fd, move |_count: usize| -> io::Result> { + tcpd.borrow_mut().scheme_event()?; + Ok(None) + }).expect("tcpd: failed to listen to events on :tcp"); + + event_queue.trigger_all(0).expect("tcpd: failed to trigger event queue"); + + event_queue.run().expect("tcpd: failed to run event queue"); +} + +fn main() { + let time_path = format!("time:{}", CLOCK_MONOTONIC); + match syscall::open(&time_path, O_RDWR) { + Ok(time_fd) => { + match syscall::open("ip:6", O_RDWR | O_NONBLOCK) { + Ok(tcp_fd) => { + // Daemonize + if unsafe { syscall::clone(0).unwrap() } == 0 { + match syscall::open(":tcp", O_RDWR | O_CREAT | O_NONBLOCK) { + Ok(scheme_fd) => { + daemon(scheme_fd, tcp_fd, time_fd); + }, + Err(err) => { + println!("tcpd: failed to create tcp scheme: {}", err); + process::exit(1); + } + } + } + }, + Err(err) => { + println!("tcpd: failed to open ip:6: {}", err); + process::exit(1); + } + } + }, + Err(err) => { + println!("tcpd: failed to open {}: {}", time_path, err); + process::exit(1); + } + } +} diff --git a/src/udpd/main.rs b/src/udpd/main.rs new file mode 100644 index 0000000000..23d6479af7 --- /dev/null +++ b/src/udpd/main.rs @@ -0,0 +1,586 @@ +extern crate event; +extern crate netutils; +extern crate rand; +extern crate syscall; + +use rand::{Rng, OsRng}; +use std::collections::{BTreeMap, VecDeque}; +use std::cell::RefCell; +use std::fs::File; +use std::io::{self, Read, Write}; +use std::{mem, process, slice, str}; +use std::ops::{Deref, DerefMut}; +use std::os::unix::io::FromRawFd; +use std::rc::Rc; + +use event::EventQueue; +use netutils::{n16, Ipv4, Ipv4Addr, Ipv4Header, Checksum}; +use netutils::udp::{Udp, UdpHeader}; +use syscall::data::{Packet, TimeSpec}; +use syscall::error::{Error, Result, EACCES, EADDRINUSE, EBADF, EIO, EINVAL, EMSGSIZE, ENOTCONN, ETIMEDOUT, EWOULDBLOCK}; +use syscall::flag::{CLOCK_MONOTONIC, EVENT_READ, F_GETFL, F_SETFL, O_ACCMODE, O_CREAT, O_RDWR, O_NONBLOCK}; +use syscall::number::{SYS_READ, SYS_WRITE}; +use syscall::scheme::SchemeMut; + +fn add_time(a: &TimeSpec, b: &TimeSpec) -> TimeSpec { + let mut secs = a.tv_sec + b.tv_sec; + + let mut nsecs = a.tv_nsec + b.tv_nsec; + while nsecs >= 1000000000 { + nsecs -= 1000000000; + secs += 1; + } + + TimeSpec { + tv_sec: secs, + tv_nsec: nsecs + } +} + +fn parse_socket(socket: &str) -> (Ipv4Addr, u16) { + let mut socket_parts = socket.split(":"); + let host = Ipv4Addr::from_str(socket_parts.next().unwrap_or("")); + let port = socket_parts.next().unwrap_or("").parse::().unwrap_or(0); + (host, port) +} + +struct UdpHandle { + local: (Ipv4Addr, u16), + remote: (Ipv4Addr, u16), + flags: usize, + events: usize, + read_timeout: Option, + write_timeout: Option, + ttl: u8, + data: VecDeque>, + todo: VecDeque<(Option, Packet)>, +} + +#[derive(Copy, Clone)] +enum SettingKind { + Ttl, + ReadTimeout, + WriteTimeout +} + +enum Handle { + Udp(UdpHandle), + Setting(usize, SettingKind), +} + +struct Udpd { + scheme_file: File, + udp_file: File, + time_file: File, + ports: BTreeMap, + next_id: usize, + handles: BTreeMap, + rng: OsRng, +} + +impl Udpd { + fn new(scheme_file: File, udp_file: File, time_file: File) -> Self { + Udpd { + scheme_file: scheme_file, + udp_file: udp_file, + time_file: time_file, + ports: BTreeMap::new(), + next_id: 1, + handles: BTreeMap::new(), + rng: OsRng::new().expect("udpd: failed to open RNG") + } + } + + fn scheme_event(&mut self) -> io::Result<()> { + loop { + let mut packet = Packet::default(); + if self.scheme_file.read(&mut packet)? == 0 { + break; + } + + let a = packet.a; + self.handle(&mut packet); + if packet.a == (-EWOULDBLOCK) as usize { + packet.a = a; + if let Some(mut handle) = self.handles.get_mut(&packet.b) { + if let Handle::Udp(ref mut handle) = *handle { + let timeout = match packet.a { + SYS_READ => match handle.read_timeout { + Some(read_timeout) => { + let mut time = TimeSpec::default(); + syscall::clock_gettime(CLOCK_MONOTONIC, &mut time).map_err(|err| io::Error::from_raw_os_error(err.errno))?; + + let timeout = add_time(&time, &read_timeout); + self.time_file.write(&timeout)?; + Some(timeout) + }, + None => None + }, + SYS_WRITE => match handle.write_timeout { + Some(write_timeout) => { + let mut time = TimeSpec::default(); + syscall::clock_gettime(CLOCK_MONOTONIC, &mut time).map_err(|err| io::Error::from_raw_os_error(err.errno))?; + + let timeout = add_time(&time, &write_timeout); + self.time_file.write(&timeout)?; + Some(timeout) + }, + None => None + }, + _ => None + }; + + handle.todo.push_back((timeout, packet)); + } + } + } else { + self.scheme_file.write(&packet)?; + } + } + + Ok(()) + } + + fn udp_event(&mut self) -> io::Result<()> { + loop { + let mut bytes = [0; 65536]; + let count = self.udp_file.read(&mut bytes)?; + if count == 0 { + break; + } + if let Some(ip) = Ipv4::from_bytes(&bytes[.. count]) { + if let Some(udp) = Udp::from_bytes(&ip.data) { + for (id, handle) in self.handles.iter_mut() { + if let Handle::Udp(ref mut handle) = *handle { + // Local address not set or IP dst matches or is broadcast + if (handle.local.0 == Ipv4Addr::NULL || ip.header.dst == handle.local.0 || ip.header.dst == Ipv4Addr::BROADCAST) + // Local port matches UDP dst + && udp.header.dst.get() == handle.local.1 + // Remote address not set or is broadcast, or IP src matches + && (handle.remote.0 == Ipv4Addr::NULL || handle.remote.0 == Ipv4Addr::BROADCAST || ip.header.src == handle.remote.0) + // Remote port not set or UDP src matches + && (handle.remote.1 == 0 || udp.header.src.get() == handle.remote.1) + { + handle.data.push_back(udp.data.clone()); + + while ! handle.todo.is_empty() && ! handle.data.is_empty() { + let (_timeout, mut packet) = handle.todo.pop_front().unwrap(); + let buf = unsafe { slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) }; + let data = handle.data.pop_front().unwrap(); + + let mut i = 0; + while i < buf.len() && i < data.len() { + buf[i] = data[i]; + i += 1; + } + packet.a = i; + + self.scheme_file.write(&packet)?; + } + + if handle.events & EVENT_READ == EVENT_READ { + if let Some(data) = handle.data.get(0) { + self.scheme_file.write(&Packet { + id: 0, + pid: 0, + uid: 0, + gid: 0, + a: syscall::number::SYS_FEVENT, + b: *id, + c: EVENT_READ, + d: data.len() + })?; + } + } + } + } + } + } + } + } + + Ok(()) + } + + fn time_event(&mut self) -> io::Result<()> { + let mut time = TimeSpec::default(); + if self.time_file.read(&mut time)? < mem::size_of::() { + return Err(io::Error::from_raw_os_error(EINVAL)); + } + + for (_id, handle) in self.handles.iter_mut() { + if let Handle::Udp(ref mut handle) = *handle { + let mut i = 0; + while i < handle.todo.len() { + if let Some(timeout) = handle.todo.get(i).map(|e| e.0.clone()).unwrap_or(None) { + if time.tv_sec > timeout.tv_sec || (time.tv_sec == timeout.tv_sec && time.tv_nsec >= timeout.tv_nsec) { + let (_timeout, mut packet) = handle.todo.remove(i).unwrap(); + packet.a = (-ETIMEDOUT) as usize; + self.scheme_file.write(&packet)?; + } else { + i += 1; + } + } else { + i += 1; + } + } + } + } + + Ok(()) + } +} + +impl SchemeMut for Udpd { + fn open(&mut self, url: &[u8], flags: usize, uid: u32, _gid: u32) -> Result { + let path = str::from_utf8(url).or(Err(Error::new(EINVAL)))?; + + let mut parts = path.split("/"); + let remote = parse_socket(parts.next().unwrap_or("")); + let mut local = parse_socket(parts.next().unwrap_or("")); + + if local.1 == 0 { + local.1 = self.rng.gen_range(32768, 65535); + } + + if local.1 <= 1024 && uid != 0 { + return Err(Error::new(EACCES)); + } + + if self.ports.contains_key(&local.1) { + return Err(Error::new(EADDRINUSE)); + } + + self.ports.insert(local.1, 1); + + let id = self.next_id; + self.next_id += 1; + + self.handles.insert(id, Handle::Udp(UdpHandle { + local: local, + remote: remote, + flags: flags, + events: 0, + ttl: 64, + read_timeout: None, + write_timeout: None, + data: VecDeque::new(), + todo: VecDeque::new(), + })); + + Ok(id) + } + + fn dup(&mut self, file: usize, buf: &[u8]) -> Result { + let handle = match *self.handles.get(&file).ok_or(Error::new(EBADF))? { + Handle::Udp(ref handle) => { + let mut handle = UdpHandle { + local: handle.local, + remote: handle.remote, + flags: handle.flags, + events: 0, + ttl: handle.ttl, + read_timeout: handle.read_timeout, + write_timeout: handle.write_timeout, + data: handle.data.clone(), + todo: VecDeque::new(), + }; + + let path = str::from_utf8(buf).or(Err(Error::new(EINVAL)))?; + + if path == "ttl" { + Handle::Setting(file, SettingKind::Ttl) + } else if path == "read_timeout" { + Handle::Setting(file, SettingKind::ReadTimeout) + } else if path == "write_timeout" { + Handle::Setting(file, SettingKind::WriteTimeout) + } else { + if handle.remote.0 == Ipv4Addr::NULL || handle.remote.1 == 0 { + handle.remote = parse_socket(path); + } + + if let Some(mut port) = self.ports.get_mut(&handle.local.1) { + *port = *port + 1; + } + + Handle::Udp(handle) + } + }, + Handle::Setting(file, kind) => { + Handle::Setting(file, kind) + } + }; + + let id = self.next_id; + self.next_id += 1; + + self.handles.insert(id, handle); + + Ok(id) + } + + fn read(&mut self, file: usize, buf: &mut [u8]) -> Result { + let (file, kind) = match *self.handles.get_mut(&file).ok_or(Error::new(EBADF))? { + Handle::Udp(ref mut handle) => { + if handle.remote.0 == Ipv4Addr::NULL || handle.remote.1 == 0 { + return Err(Error::new(ENOTCONN)); + } else if let Some(data) = handle.data.pop_front() { + let mut i = 0; + while i < buf.len() && i < data.len() { + buf[i] = data[i]; + i += 1; + } + + return Ok(i); + } else if handle.flags & O_NONBLOCK == O_NONBLOCK { + return Ok(0); + } else { + return Err(Error::new(EWOULDBLOCK)); + } + }, + Handle::Setting(file, kind) => { + (file, kind) + } + }; + + if let Handle::Udp(ref mut handle) = *self.handles.get_mut(&file).ok_or(Error::new(EBADF))? { + let get_timeout = |timeout: &Option, buf: &mut [u8]| -> Result { + if let Some(ref timespec) = *timeout { + timespec.deref().read(buf).map_err(|err| Error::new(err.raw_os_error().unwrap_or(EIO))) + } else { + Ok(0) + } + }; + + match kind { + SettingKind::Ttl => { + if let Some(mut ttl) = buf.get_mut(0) { + *ttl = handle.ttl; + Ok(1) + } else { + Ok(0) + } + }, + SettingKind::ReadTimeout => { + get_timeout(&handle.read_timeout, buf) + }, + SettingKind::WriteTimeout => { + get_timeout(&handle.write_timeout, buf) + } + } + } else { + Err(Error::new(EBADF)) + } + } + + fn write(&mut self, file: usize, buf: &[u8]) -> Result { + let (file, kind) = match *self.handles.get(&file).ok_or(Error::new(EBADF))? { + Handle::Udp(ref handle) => { + if handle.remote.0 == Ipv4Addr::NULL || handle.remote.1 == 0 { + return Err(Error::new(ENOTCONN)); + } else if buf.len() >= 65507 { + return Err(Error::new(EMSGSIZE)); + } else { + let udp_data = buf.to_vec(); + + let udp = Udp { + header: UdpHeader { + src: n16::new(handle.local.1), + dst: n16::new(handle.remote.1), + len: n16::new((udp_data.len() + mem::size_of::()) as u16), + checksum: Checksum { data: 0 } + }, + data: udp_data + }; + + let ip_data = udp.to_bytes(); + + let ip = Ipv4 { + header: Ipv4Header { + ver_hlen: 0x45, + services: 0, + len: n16::new((ip_data.len() + mem::size_of::()) as u16), + id: n16::new(self.rng.gen()), + flags_fragment: n16::new(0), + ttl: handle.ttl, + proto: 0x11, + checksum: Checksum { data: 0 }, + src: handle.local.0, + dst: handle.remote.0 + }, + options: Vec::new(), + data: ip_data + }; + + return self.udp_file.write(&ip.to_bytes()).map_err(|err| Error::new(err.raw_os_error().unwrap_or(EIO))).and(Ok(buf.len())); + } + }, + Handle::Setting(file, kind) => { + (file, kind) + } + }; + + if let Handle::Udp(ref mut handle) = *self.handles.get_mut(&file).ok_or(Error::new(EBADF))? { + let set_timeout = |timeout: &mut Option, buf: &[u8]| -> Result { + if buf.len() >= mem::size_of::() { + let mut timespec = TimeSpec::default(); + let count = timespec.deref_mut().write(buf).map_err(|err| Error::new(err.raw_os_error().unwrap_or(EIO)))?; + *timeout = Some(timespec); + Ok(count) + } else { + *timeout = None; + Ok(0) + } + }; + + match kind { + SettingKind::Ttl => { + if let Some(ttl) = buf.get(0) { + handle.ttl = *ttl; + Ok(1) + } else { + Ok(0) + } + }, + SettingKind::ReadTimeout => { + set_timeout(&mut handle.read_timeout, buf) + }, + SettingKind::WriteTimeout => { + set_timeout(&mut handle.write_timeout, buf) + } + } + } else { + Err(Error::new(EBADF)) + } + } + + fn fcntl(&mut self, file: usize, cmd: usize, arg: usize) -> Result { + if let Handle::Udp(ref mut handle) = *self.handles.get_mut(&file).ok_or(Error::new(EBADF))? { + match cmd { + F_GETFL => Ok(handle.flags), + F_SETFL => { + handle.flags = arg & ! O_ACCMODE; + Ok(0) + }, + _ => Err(Error::new(EINVAL)) + } + } else { + Err(Error::new(EBADF)) + } + } + + fn fevent(&mut self, file: usize, flags: usize) -> Result { + if let Handle::Udp(ref mut handle) = *self.handles.get_mut(&file).ok_or(Error::new(EBADF))? { + handle.events = flags; + Ok(file) + } else { + Err(Error::new(EBADF)) + } + } + + fn fpath(&mut self, file: usize, buf: &mut [u8]) -> Result { + if let Handle::Udp(ref mut handle) = *self.handles.get_mut(&file).ok_or(Error::new(EBADF))? { + let path_string = format!("udp:{}:{}/{}:{}", handle.remote.0.to_string(), handle.remote.1, handle.local.0.to_string(), handle.local.1); + let path = path_string.as_bytes(); + + let mut i = 0; + while i < buf.len() && i < path.len() { + buf[i] = path[i]; + i += 1; + } + + Ok(i) + } else { + Err(Error::new(EBADF)) + } + } + + fn fsync(&mut self, file: usize) -> Result { + let _handle = self.handles.get(&file).ok_or(Error::new(EBADF))?; + + Ok(0) + } + + fn close(&mut self, file: usize) -> Result { + let handle = self.handles.remove(&file).ok_or(Error::new(EBADF))?; + + if let Handle::Udp(ref handle) = handle { + let remove = if let Some(mut port) = self.ports.get_mut(&handle.local.1) { + *port = *port + 1; + *port == 0 + } else { + false + }; + + if remove { + drop(self.ports.remove(&handle.local.1)); + } + } + + drop(handle); + + Ok(0) + } +} +fn daemon(scheme_fd: usize, udp_fd: usize, time_fd: usize) { + let scheme_file = unsafe { File::from_raw_fd(scheme_fd) }; + let udp_file = unsafe { File::from_raw_fd(udp_fd) }; + let time_file = unsafe { File::from_raw_fd(time_fd) }; + + let udpd = Rc::new(RefCell::new(Udpd::new(scheme_file, udp_file, time_file))); + + let mut event_queue = EventQueue::<()>::new().expect("udpd: failed to create event queue"); + + let time_udpd = udpd.clone(); + event_queue.add(time_fd, move |_count: usize| -> io::Result> { + time_udpd.borrow_mut().time_event()?; + Ok(None) + }).expect("udpd: failed to listen to events on time:"); + + let udp_udpd = udpd.clone(); + event_queue.add(udp_fd, move |_count: usize| -> io::Result> { + udp_udpd.borrow_mut().udp_event()?; + Ok(None) + }).expect("udpd: failed to listen to events on ip:11"); + + event_queue.add(scheme_fd, move |_count: usize| -> io::Result> { + udpd.borrow_mut().scheme_event()?; + Ok(None) + }).expect("udpd: failed to listen to events on :udp"); + + event_queue.trigger_all(0).expect("udpd: failed to trigger event queue"); + + event_queue.run().expect("udpd: failed to run event queue"); +} + +fn main() { + let time_path = format!("time:{}", CLOCK_MONOTONIC); + match syscall::open(&time_path, O_RDWR) { + Ok(time_fd) => { + match syscall::open("ip:11", O_RDWR | O_NONBLOCK) { + Ok(udp_fd) => { + // Daemonize + if unsafe { syscall::clone(0).unwrap() } == 0 { + match syscall::open(":udp", O_RDWR | O_CREAT | O_NONBLOCK) { + Ok(scheme_fd) => { + daemon(scheme_fd, udp_fd, time_fd); + }, + Err(err) => { + println!("udpd: failed to create udp scheme: {}", err); + process::exit(1); + } + } + } + }, + Err(err) => { + println!("udpd: failed to open ip:11: {}", err); + process::exit(1); + } + } + }, + Err(err) => { + println!("udpd: failed to open {}: {}", time_path, err); + process::exit(1); + } + } +} From 6bfd4be40e29966d0e41fd43d99699a8498e0529 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Tue, 9 May 2017 21:35:58 -0600 Subject: [PATCH 002/155] Fix missing ethernetd --- Cargo.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 393ef6e3e1..8440d9f3c0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,10 @@ name = "redox_netstack" version = "0.1.0" +[[bin]] +name = "ethernetd" +path = "src/ethernetd/main.rs" + [[bin]] name = "ipd" path = "src/ipd/main.rs" From 69bb8fb80bf50b183cb2c8bc80b89bd8ff9bf29c Mon Sep 17 00:00:00 2001 From: Egor Karavaev Date: Sun, 11 Jun 2017 00:53:30 +0300 Subject: [PATCH 003/155] Add icmpd daemon, only Echo reply for now. --- Cargo.toml | 6 ++- src/icmpd/error.rs | 80 ++++++++++++++++++++++++++++++ src/icmpd/main.rs | 115 ++++++++++++++++++++++++++++++++++++++++++++ src/icmpd/packet.rs | 100 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 300 insertions(+), 1 deletion(-) create mode 100644 src/icmpd/error.rs create mode 100644 src/icmpd/main.rs create mode 100644 src/icmpd/packet.rs diff --git a/Cargo.toml b/Cargo.toml index 8440d9f3c0..c29a186b3e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,8 +18,12 @@ path = "src/tcpd/main.rs" name = "udpd" path = "src/udpd/main.rs" +[[bin]] +name = "icmpd" +path = "src/icmpd/main.rs" + [dependencies] netutils = { git = "https://github.com/redox-os/netutils.git" } rand = "0.3" -redox_event = "0.1" +redox_event = { path = "../event" } redox_syscall = "0.1" diff --git a/src/icmpd/error.rs b/src/icmpd/error.rs new file mode 100644 index 0000000000..cc939b6072 --- /dev/null +++ b/src/icmpd/error.rs @@ -0,0 +1,80 @@ +use std::result; +use std::fmt; +use syscall::error::Error as SyscallError; +use std::io::Error as IOError; +use std::convert; + +pub enum ParsingError { + NotEnoughData, + IncorrectChecksum, +} + +enum ErrorType { + Syscall(SyscallError), + IOError(IOError), + ParsingError(ParsingError), +} + +pub struct Error { + error_type: ErrorType, + descr: String, +} + +impl Error { + pub fn from_parsing_error>(parsing_error: ParsingError, descr: S) -> Error { + Error { + error_type: ErrorType::ParsingError(parsing_error), + descr: descr.into(), + } + } + pub fn from_syscall_error>(syscall_error: SyscallError, descr: S) -> Error { + Error { + error_type: ErrorType::Syscall(syscall_error), + descr: descr.into(), + } + } + + pub fn from_io_error>(io_error: IOError, descr: S) -> Error { + Error { + error_type: ErrorType::IOError(io_error), + descr: descr.into(), + } + } +} + +impl fmt::Display for ParsingError { + fn fmt(&self, f: &mut fmt::Formatter) -> result::Result<(), fmt::Error> { + write!(f, "{}", match *self { + ParsingError::NotEnoughData => "not enough data", + ParsingError::IncorrectChecksum => "checksum error", + }) + } +} + +impl fmt::Display for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> result::Result<(), fmt::Error> { + match self.error_type { + ErrorType::Syscall(ref syscall_error) => { + write!(f, "{} : syscall error: {}", self.descr, syscall_error) + } + ErrorType::IOError(ref io_error) => { + write!(f, "{} : io error : {}", self.descr, io_error) + } + ErrorType::ParsingError(ref parsign_error) => { + write!(f, + "{} : packet parsing error : {}", + self.descr, + parsign_error) + } + } + } +} + +impl convert::From for Error { + fn from(e: IOError) -> Self { + Error::from_io_error(e, "") + } +} + +pub type Result = result::Result; +pub type ParsingResult = result::Result; diff --git a/src/icmpd/main.rs b/src/icmpd/main.rs new file mode 100644 index 0000000000..4e7c582876 --- /dev/null +++ b/src/icmpd/main.rs @@ -0,0 +1,115 @@ +extern crate event; +extern crate syscall; +extern crate netutils; + +use error::{Result, Error, ParsingError}; +use event::EventQueue; +use netutils::{Ipv4, Ipv4Header, Checksum, n16}; +use packet::{Packet, MutPacket}; +use std::fs::File; +use std::io::{Read, Write}; +use std::os::unix::io::{RawFd, FromRawFd}; +use std::process; +use std::mem; + +mod error; +mod packet; + +const MAX_PACKET_SIZE: usize = 2048; + +fn do_echo_response(in_ip_packet: &Ipv4, + in_icmp_packet: &Packet, + icmp_file: &mut File) + -> Result<()> { + let mut ip_data = vec![0; in_icmp_packet.get_total_data_size()]; + { + let mut out_icmp_packet = + MutPacket::from_bytes(&mut ip_data) + .map_err(|e| Error::from_parsing_error(e, "can't parse empty icmp header"))?; + out_icmp_packet.set_echo_response(); + { + let payload = out_icmp_packet.get_payload(); + let in_payload = in_icmp_packet.get_payload(); + if payload.len() != in_payload.len() { + return Err(Error::from_parsing_error(ParsingError::NotEnoughData, + " can't copy icmp payload to echo response")); + } + //WARNING: copy_from_slice can panic if the slices' lengths are different + payload.copy_from_slice(in_icmp_packet.get_payload()); + } + out_icmp_packet.compute_checksum(); + } + let out_ip_packet = Ipv4 { + header: Ipv4Header { + ver_hlen: 0x45, + services: 0, + len: n16::new((ip_data.len() + mem::size_of::()) as u16), + id: n16::new(0), + flags_fragment: n16::new(0), + ttl: in_ip_packet.header.ttl, + proto: 1, + checksum: Checksum { data: 0 }, + src: in_ip_packet.header.dst, + dst: in_ip_packet.header.src, + }, + options: Vec::new(), + data: ip_data, + }; + icmp_file + .write(&out_ip_packet.to_bytes()) + .map_err(|e| Error::from_io_error(e, " can't send an echo response packet")) + .map(|_| ()) +} + +fn on_icmp_packet(icmp_file: &mut File) -> Result> { + let mut packet_buffer = [0; MAX_PACKET_SIZE]; + loop { + let bytes_readed = + icmp_file + .read(&mut packet_buffer) + .map_err(|e| Error::from_io_error(e, "failed to read a packet from ip:1"))?; + if bytes_readed == 0 { + break; + } + let ip_packet = Ipv4::from_bytes(&packet_buffer[..bytes_readed]) + .ok_or(Error::from_parsing_error(ParsingError::NotEnoughData, + "failed to parse ip header"))?; + let icmp_packet = + Packet::from_bytes(&ip_packet.data) + .map_err(|e| Error::from_parsing_error(e, "failed to parse ICMP packet"))?; + + if icmp_packet.is_echo_request() { + do_echo_response(&ip_packet, &icmp_packet, icmp_file)?; + } + } + Ok(None) +} + +fn run() -> Result<()> { + use syscall::flag::*; + + let icmp_fd = syscall::open("ip:1", O_RDWR | O_NONBLOCK) + .map_err(|e| Error::from_syscall_error(e, "failed to open ip:1"))?; + + if unsafe { syscall::clone(0).unwrap() } != 0 { + return Ok(()); + } + + let mut event_queue = + EventQueue::<(), Error>::new() + .map_err(|e| Error::from_io_error(e, "failed to create event queue"))?; + let mut icmp_file = unsafe { File::from_raw_fd(icmp_fd as RawFd) }; + event_queue + .add(icmp_fd as RawFd, + move |_fd| -> Result> { on_icmp_packet(&mut icmp_file) }) + .map_err(|e| Error::from_io_error(e, "failed to listen to events on ip:1"))?; + event_queue.run() +} + +fn main() { + match run() { + Err(err) => println!("icmpd: {}", err), + _ => {} + } + process::exit(0); +} diff --git a/src/icmpd/packet.rs b/src/icmpd/packet.rs new file mode 100644 index 0000000000..5dddb80e6e --- /dev/null +++ b/src/icmpd/packet.rs @@ -0,0 +1,100 @@ +use error::{ParsingResult, ParsingError}; +use netutils::Checksum; +use std::mem; + +#[repr(packed)] +pub struct Header { + icmp_type: u8, + icmp_code: u8, + crc: u16, +} + +pub struct Packet<'a> { + header: &'a Header, + payload: &'a [u8], +} + +pub struct MutPacket<'a> { + header: &'a mut Header, + payload: &'a mut [u8], +} + +impl<'a> Packet<'a> { + pub fn from_bytes<'b>(bytes: &'b [u8]) -> ParsingResult> + where 'b: 'a + { + if bytes.len() < mem::size_of::
() { + Err(ParsingError::NotEnoughData) + } else { + let (header_bytes, payload_bytes) = bytes.split_at(mem::size_of::
()); + let packet = Packet { + header: unsafe { mem::transmute(header_bytes.as_ptr()) }, + payload: payload_bytes, + }; + if packet.is_checksum_ok() { + Ok(packet) + } else { + Err(ParsingError::IncorrectChecksum) + } + } + } + + fn is_checksum_ok(&self) -> bool { + let header_ptr = self.header as *const Header as usize; + let total_size = self.get_total_data_size(); + let mut crc = unsafe { Checksum::sum(header_ptr, total_size) }; + crc -= u16::from_be(self.header.crc) as usize; + let crc = Checksum::compile(crc); + crc == u16::from_be(self.header.crc) + } + + pub fn is_echo_request(&self) -> bool { + self.header.icmp_type == ECHO_REQUEST_TYPE && self.header.icmp_code == ECHO_REQUEST_CODE + } + + pub fn get_payload(&self) -> &[u8] { + self.payload + } + + pub fn get_total_data_size(&self) -> usize { + mem::size_of::
() + self.payload.len() + } +} + +impl<'a> MutPacket<'a> { + pub fn from_bytes<'b>(bytes: &'b mut [u8]) -> ParsingResult> + where 'b: 'a + { + if bytes.len() < mem::size_of::
() { + Err(ParsingError::NotEnoughData) + } else { + let (header_bytes, payload_bytes) = bytes.split_at_mut(mem::size_of::
()); + Ok(MutPacket { + header: unsafe { mem::transmute(header_bytes.as_ptr()) }, + payload: payload_bytes, + }) + } + } + + pub fn set_echo_response(&mut self) { + self.header.icmp_type = ECHO_RESPONSE_TYPE; + self.header.icmp_code = ECHO_RESPONSE_CODE; + } + + pub fn compute_checksum(&mut self) { + self.header.crc = 0; + let header_ptr = self.header as *mut Header as usize; + let total_size = mem::size_of::
() + self.payload.len(); + let crc = Checksum::compile(unsafe { Checksum::sum(header_ptr, total_size) }); + self.header.crc = crc + } + + pub fn get_payload(&mut self) -> &mut [u8] { + self.payload + } +} + +const ECHO_REQUEST_TYPE: u8 = 8; +const ECHO_REQUEST_CODE: u8 = 0; +const ECHO_RESPONSE_TYPE: u8 = 0; +const ECHO_RESPONSE_CODE: u8 = 0; From 8301ee85a1fc81ffee14c056f0fd341ec819143b Mon Sep 17 00:00:00 2001 From: Egor Karavaev Date: Mon, 12 Jun 2017 00:23:04 +0300 Subject: [PATCH 004/155] Add initial support for icmp scheme. --- src/icmpd/main.rs | 108 ++++------------- src/icmpd/packet.rs | 38 +++++- src/icmpd/scheme.rs | 288 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 347 insertions(+), 87 deletions(-) create mode 100644 src/icmpd/scheme.rs diff --git a/src/icmpd/main.rs b/src/icmpd/main.rs index 4e7c582876..2623547228 100644 --- a/src/icmpd/main.rs +++ b/src/icmpd/main.rs @@ -2,114 +2,58 @@ extern crate event; extern crate syscall; extern crate netutils; -use error::{Result, Error, ParsingError}; +use error::{Result, Error}; use event::EventQueue; -use netutils::{Ipv4, Ipv4Header, Checksum, n16}; -use packet::{Packet, MutPacket}; +use scheme::Icmpd; +use std::cell::RefCell; use std::fs::File; -use std::io::{Read, Write}; use std::os::unix::io::{RawFd, FromRawFd}; use std::process; -use std::mem; +use std::rc::Rc; mod error; mod packet; - -const MAX_PACKET_SIZE: usize = 2048; - -fn do_echo_response(in_ip_packet: &Ipv4, - in_icmp_packet: &Packet, - icmp_file: &mut File) - -> Result<()> { - let mut ip_data = vec![0; in_icmp_packet.get_total_data_size()]; - { - let mut out_icmp_packet = - MutPacket::from_bytes(&mut ip_data) - .map_err(|e| Error::from_parsing_error(e, "can't parse empty icmp header"))?; - out_icmp_packet.set_echo_response(); - { - let payload = out_icmp_packet.get_payload(); - let in_payload = in_icmp_packet.get_payload(); - if payload.len() != in_payload.len() { - return Err(Error::from_parsing_error(ParsingError::NotEnoughData, - " can't copy icmp payload to echo response")); - } - //WARNING: copy_from_slice can panic if the slices' lengths are different - payload.copy_from_slice(in_icmp_packet.get_payload()); - } - out_icmp_packet.compute_checksum(); - } - let out_ip_packet = Ipv4 { - header: Ipv4Header { - ver_hlen: 0x45, - services: 0, - len: n16::new((ip_data.len() + mem::size_of::()) as u16), - id: n16::new(0), - flags_fragment: n16::new(0), - ttl: in_ip_packet.header.ttl, - proto: 1, - checksum: Checksum { data: 0 }, - src: in_ip_packet.header.dst, - dst: in_ip_packet.header.src, - }, - options: Vec::new(), - data: ip_data, - }; - icmp_file - .write(&out_ip_packet.to_bytes()) - .map_err(|e| Error::from_io_error(e, " can't send an echo response packet")) - .map(|_| ()) -} - -fn on_icmp_packet(icmp_file: &mut File) -> Result> { - let mut packet_buffer = [0; MAX_PACKET_SIZE]; - loop { - let bytes_readed = - icmp_file - .read(&mut packet_buffer) - .map_err(|e| Error::from_io_error(e, "failed to read a packet from ip:1"))?; - if bytes_readed == 0 { - break; - } - let ip_packet = Ipv4::from_bytes(&packet_buffer[..bytes_readed]) - .ok_or(Error::from_parsing_error(ParsingError::NotEnoughData, - "failed to parse ip header"))?; - let icmp_packet = - Packet::from_bytes(&ip_packet.data) - .map_err(|e| Error::from_parsing_error(e, "failed to parse ICMP packet"))?; - - if icmp_packet.is_echo_request() { - do_echo_response(&ip_packet, &icmp_packet, icmp_file)?; - } - } - Ok(None) -} +mod scheme; fn run() -> Result<()> { use syscall::flag::*; let icmp_fd = syscall::open("ip:1", O_RDWR | O_NONBLOCK) - .map_err(|e| Error::from_syscall_error(e, "failed to open ip:1"))?; + .map_err(|e| Error::from_syscall_error(e, "failed to open ip:1"))? as + RawFd; + + let scheme_fd = syscall::open(":icmp", O_RDWR | O_CREAT | O_NONBLOCK) + .map_err(|e| Error::from_syscall_error(e, "failed to open :icmp"))? as + RawFd; if unsafe { syscall::clone(0).unwrap() } != 0 { return Ok(()); } + let icmpd = Rc::new(RefCell::new(Icmpd::new(unsafe { File::from_raw_fd(icmp_fd) }, + unsafe { File::from_raw_fd(scheme_fd) }))); + let mut event_queue = EventQueue::<(), Error>::new() .map_err(|e| Error::from_io_error(e, "failed to create event queue"))?; - let mut icmp_file = unsafe { File::from_raw_fd(icmp_fd as RawFd) }; + + let icmpd_ = icmpd.clone(); + event_queue - .add(icmp_fd as RawFd, - move |_fd| -> Result> { on_icmp_packet(&mut icmp_file) }) + .add(icmp_fd, move |_fd| icmpd_.borrow_mut().on_icmp_packet()) .map_err(|e| Error::from_io_error(e, "failed to listen to events on ip:1"))?; + + event_queue + .add(scheme_fd, move |_fd| icmpd.borrow_mut().on_scheme_event()) + .map_err(|e| Error::from_io_error(e, "failed to listen to events on icmp"))?; + event_queue.run() } fn main() { - match run() { - Err(err) => println!("icmpd: {}", err), - _ => {} + if let Err(err) = run() { + println!("icmpd: {}", err); + process::exit(1); } process::exit(0); } diff --git a/src/icmpd/packet.rs b/src/icmpd/packet.rs index 5dddb80e6e..fb35ce745a 100644 --- a/src/icmpd/packet.rs +++ b/src/icmpd/packet.rs @@ -19,6 +19,15 @@ pub struct MutPacket<'a> { payload: &'a mut [u8], } +pub enum PacketKind { + EchoRequest, + EchoResponse, + HostUnreachable, + PortUnreachable, + ProtoUnreachable, + Unknown, +} + impl<'a> Packet<'a> { pub fn from_bytes<'b>(bytes: &'b [u8]) -> ParsingResult> where 'b: 'a @@ -48,8 +57,15 @@ impl<'a> Packet<'a> { crc == u16::from_be(self.header.crc) } - pub fn is_echo_request(&self) -> bool { - self.header.icmp_type == ECHO_REQUEST_TYPE && self.header.icmp_code == ECHO_REQUEST_CODE + pub fn get_kind(&self) -> PacketKind { + match (self.header.icmp_type, self.header.icmp_code) { + (ECHO_REQUEST_TYPE, ECHO_REQUEST_CODE) => PacketKind::EchoRequest, + (ECHO_RESPONSE_TYPE, ECHO_RESPONSE_CODE) => PacketKind::EchoResponse, + (UNREACHABLE_TYPE, UNREACHABLE_HOST_CODE) => PacketKind::HostUnreachable, + (UNREACHABLE_TYPE, UNREACHABLE_PROTO_CODE) => PacketKind::ProtoUnreachable, + (UNREACHABLE_TYPE, UNREACHABLE_PORT_CODE) => PacketKind::PortUnreachable, + _ => PacketKind::Unknown, + } } pub fn get_payload(&self) -> &[u8] { @@ -76,9 +92,17 @@ impl<'a> MutPacket<'a> { } } - pub fn set_echo_response(&mut self) { - self.header.icmp_type = ECHO_RESPONSE_TYPE; - self.header.icmp_code = ECHO_RESPONSE_CODE; + pub fn set_kind(&mut self, packet_type: PacketKind) { + let (new_type, new_code) = match packet_type { + EchoRequest => (ECHO_REQUEST_TYPE, ECHO_REQUEST_CODE), + EchoResponse => (ECHO_RESPONSE_TYPE, ECHO_RESPONSE_CODE), + HostUnreachable => (UNREACHABLE_TYPE, UNREACHABLE_HOST_CODE), + PortUnreachable => (UNREACHABLE_TYPE, UNREACHABLE_PORT_CODE), + ProtoUnreachable => (UNREACHABLE_TYPE, UNREACHABLE_PROTO_CODE), + Unknown => (self.header.icmp_type, self.header.icmp_code), + }; + self.header.icmp_type = new_type; + self.header.icmp_code = new_code; } pub fn compute_checksum(&mut self) { @@ -98,3 +122,7 @@ const ECHO_REQUEST_TYPE: u8 = 8; const ECHO_REQUEST_CODE: u8 = 0; const ECHO_RESPONSE_TYPE: u8 = 0; const ECHO_RESPONSE_CODE: u8 = 0; +const UNREACHABLE_TYPE: u8 = 3; +const UNREACHABLE_HOST_CODE: u8 = 1; +const UNREACHABLE_PROTO_CODE: u8 = 2; +const UNREACHABLE_PORT_CODE: u8 = 3; diff --git a/src/icmpd/scheme.rs b/src/icmpd/scheme.rs new file mode 100644 index 0000000000..22616f6f67 --- /dev/null +++ b/src/icmpd/scheme.rs @@ -0,0 +1,288 @@ +use error::{Result, Error, ParsingError}; +use netutils::{Ipv4, Ipv4Header, Checksum, n16}; +use netutils; +use packet::{Header, Packet, MutPacket, PacketKind}; +use std::collections::{BTreeMap, HashSet, VecDeque}; +use std::fs::File; +use std::io::{Read, Write}; +use std::mem; +use std::net::Ipv4Addr; +use syscall::SchemeMut; +use syscall; + +//Some reasonable limits, 65k is a waste of memory +const MAX_PACKET_SIZE: usize = 2048; +const MAX_ICMP_PAYLOAD_SIZE: usize = 2000; + +enum HandleType { + Echo, +} + +struct Handle { + handle_type: HandleType, + events: usize, + flags: usize, + ip_addr: Ipv4Addr, + payload_queue: VecDeque>, +} + +impl Handle { + pub fn new(handle_type: HandleType, ip_addr: Ipv4Addr, flags: usize) -> Handle { + Handle { + handle_type, + events: 0, + ip_addr, + payload_queue: VecDeque::new(), + flags, + } + } +} + +pub struct Icmpd { + icmp_file: File, + scheme_file: File, + next_fd: usize, + echo_ips: BTreeMap>, + handles: BTreeMap, +} + +impl Icmpd { + pub fn new(icmp_file: File, scheme_file: File) -> Icmpd { + Icmpd { + icmp_file, + scheme_file, + next_fd: 0, + echo_ips: BTreeMap::new(), + handles: BTreeMap::new(), + } + } + + pub fn on_scheme_event(&mut self) -> Result> { + loop { + let mut packet = syscall::Packet::default(); + if self.scheme_file.read(&mut packet)? == 0 { + break; + } + self.handle(&mut packet); + } + Ok(None) + } + + pub fn on_icmp_packet(&mut self) -> Result> { + let mut packet_buffer = [0; MAX_PACKET_SIZE]; + loop { + let bytes_readed = + self.icmp_file + .read(&mut packet_buffer) + .map_err(|e| Error::from_io_error(e, "failed to read a packet from ip:1"))?; + if bytes_readed == 0 { + break; + } + let ip_packet = Ipv4::from_bytes(&packet_buffer[..bytes_readed]) + .ok_or(Error::from_parsing_error(ParsingError::NotEnoughData, + "failed to parse ip header"))?; + let icmp_packet = + Packet::from_bytes(&ip_packet.data) + .map_err(|e| Error::from_parsing_error(e, "failed to parse ICMP packet"))?; + + match icmp_packet.get_kind() { + PacketKind::EchoRequest => self.on_echo_request(&ip_packet, &icmp_packet)?, + PacketKind::EchoResponse => self.on_echo_response(&ip_packet, &icmp_packet)?, + _ => (), + } + } + Ok(None) + } + + fn on_echo_request(&mut self, ip_packet: &Ipv4, icmp_packet: &Packet) -> Result<()> { + let echo_response = produce_icmp_packet(Ipv4Addr::from(ip_packet.header.src.bytes), + PacketKind::EchoResponse, + icmp_packet.get_payload())?; + self.icmp_file + .write(&echo_response) + .map_err(|e| Error::from_io_error(e, " can't send an echo response packet")) + .map(|_| ()) + } + + fn on_echo_response(&mut self, ip_packet: &Ipv4, icmp_packet: &Packet) -> Result<()> { + if let Some(fd_set) = self.echo_ips + .get_mut(&Ipv4Addr::from(ip_packet.header.src.bytes)) { + for fd in fd_set.iter() { + if let Some(handle) = self.handles.get_mut(fd) { + handle + .payload_queue + .push_back(Vec::from(icmp_packet.get_payload())); + post_fevent(&mut self.scheme_file, + *fd, + syscall::EVENT_READ, + icmp_packet.get_payload().len())?; + } + } + } + Ok(()) + } + + fn open_echo(&mut self, ip_addr: Ipv4Addr, flags: usize) -> syscall::Result { + let fd = self.next_fd; + self.next_fd += 1; + let handle = Handle::new(HandleType::Echo, ip_addr, flags); + self.handles.insert(fd, handle); + self.echo_ips + .entry(ip_addr) + .or_insert_with(|| HashSet::new()) + .insert(fd); + Ok(fd) + } + + fn read_echo(handle: &mut Handle, buf: &mut [u8]) -> syscall::Result { + if let Some(payload) = handle.payload_queue.pop_front() { + //TODO replace with a proper memcpy + let mut i = 0; + while i < buf.len() && i < payload.len() { + buf[i] = payload[i]; + i += 1; + } + Ok(i) + } else { + Ok(0) + } + } +} + +impl SchemeMut for Icmpd { + fn open(&mut self, url: &[u8], flags: usize, _uid: u32, _gid: u32) -> syscall::Result { + use std::str; + use std::str::FromStr; + + // if uid != 0 { + // return Err(syscall::Error::new(syscall::EACCES)); + // } + + let path = str::from_utf8(url) + .or(Err(syscall::Error::new(syscall::EINVAL)))?; + let mut parts = path.split("/"); + let method = parts.next().ok_or(syscall::Error::new(syscall::EINVAL))?; + match method { + "echo" => { + let addr = parts.next().ok_or(syscall::Error::new(syscall::EINVAL))?; + let addr = Ipv4Addr::from_str(&addr) + .map_err(|_| syscall::Error::new(syscall::EINVAL))?; + self.open_echo(addr, flags) + } + _ => Err(syscall::Error::new(syscall::EINVAL)), + } + } + + fn close(&mut self, fd: usize) -> syscall::Result { + let (ip, ip_set) = { + let handle = self.handles + .get_mut(&fd) + .ok_or(syscall::Error::new(syscall::EBADF))?; + match handle.handle_type { + HandleType::Echo => (handle.ip_addr, &mut self.echo_ips), + } + }; + self.handles.remove(&fd); + let remove_ip = if let Some(fd_set) = ip_set.get_mut(&ip) { + fd_set.remove(&fd); + fd_set.is_empty() + } else { + false + }; + + if remove_ip { + ip_set.remove(&ip); + } + + Ok(0) + } + + fn write(&mut self, fd: usize, buf: &[u8]) -> syscall::Result { + if buf.len() > MAX_ICMP_PAYLOAD_SIZE { + return Err(syscall::Error::new(syscall::EMSGSIZE)); + } + let handle = self.handles + .get_mut(&fd) + .ok_or(syscall::Error::new(syscall::EBADF))?; + match handle.handle_type { + HandleType::Echo => { + let echo_request = + produce_icmp_packet(handle.ip_addr, PacketKind::EchoRequest, buf) + .map_err(|_| syscall::Error::new(syscall::EPROTO))?; + self.icmp_file + .write(&echo_request) + .map_err(|_| syscall::Error::new(syscall::EPROTO)) + } + } + } + + fn read(&mut self, fd: usize, buf: &mut [u8]) -> syscall::Result { + let handle = self.handles + .get_mut(&fd) + .ok_or(syscall::Error::new(syscall::EBADF))?; + match handle.handle_type { + HandleType::Echo => Icmpd::read_echo(handle, buf), + } + } + + fn fevent(&mut self, fd: usize, events: usize) -> syscall::Result { + let handle = self.handles + .get_mut(&fd) + .ok_or(syscall::Error::new(syscall::EBADF))?; + handle.events = events; + Ok(fd) + } +} + +fn produce_icmp_packet(to_ip: Ipv4Addr, kind: PacketKind, payload: &[u8]) -> Result> { + let mut ip_data = vec![0; mem::size_of::
() + payload.len()]; + { + let mut out_icmp_packet = + MutPacket::from_bytes(&mut ip_data) + .map_err(|e| Error::from_parsing_error(e, "can't parse empty icmp header"))?; + out_icmp_packet.set_kind(kind); + { + let out_payload = out_icmp_packet.get_payload(); + if out_payload.len() != payload.len() { + return Err(Error::from_parsing_error(ParsingError::NotEnoughData, + " can't copy icmp payload to echo response")); + } + //WARNING: copy_from_slice can panic if the slices' lengths are different + out_payload.copy_from_slice(payload); + } + out_icmp_packet.compute_checksum(); + } + let out_ip_packet = Ipv4 { + header: Ipv4Header { + ver_hlen: 0x45, + services: 0, + len: n16::new((ip_data.len() + mem::size_of::()) as u16), + id: n16::new(0), + flags_fragment: n16::new(0), + ttl: 64, + proto: 1, + checksum: Checksum { data: 0 }, + src: netutils::Ipv4Addr::NULL, + dst: netutils::Ipv4Addr { bytes: to_ip.octets() }, + }, + options: Vec::new(), + data: ip_data, + }; + Ok(out_ip_packet.to_bytes()) +} + +fn post_fevent(scheme_file: &mut File, fd: usize, event: usize, data_len: usize) -> Result<()> { + scheme_file + .write(&syscall::Packet { + id: 0, + pid: 0, + uid: 0, + gid: 0, + a: syscall::number::SYS_FEVENT, + b: fd, + c: event, + d: data_len, + }) + .map(|_| ()) + .map_err(|e| Error::from_io_error(e, "failed to post fevent")) +} From 47563fa29ebaf75650b85f8fed7a77b05b55cb64 Mon Sep 17 00:00:00 2001 From: Egor Karavaev Date: Mon, 12 Jun 2017 15:25:15 +0300 Subject: [PATCH 005/155] Add support for Echo sub-header. --- src/icmpd/error.rs | 30 +++++++---- src/icmpd/main.rs | 22 +++++++- src/icmpd/packet.rs | 123 ++++++++++++++++++++++++++++++++++++++------ src/icmpd/scheme.rs | 48 +++++++++++------ 4 files changed, 180 insertions(+), 43 deletions(-) diff --git a/src/icmpd/error.rs b/src/icmpd/error.rs index cc939b6072..ae8007e961 100644 --- a/src/icmpd/error.rs +++ b/src/icmpd/error.rs @@ -4,15 +4,17 @@ use syscall::error::Error as SyscallError; use std::io::Error as IOError; use std::convert; -pub enum ParsingError { +pub enum PacketError { NotEnoughData, IncorrectChecksum, + NoEchoHeader, + SubheaderAlreadPresent, } enum ErrorType { Syscall(SyscallError), IOError(IOError), - ParsingError(ParsingError), + PacketError(PacketError), } pub struct Error { @@ -21,9 +23,9 @@ pub struct Error { } impl Error { - pub fn from_parsing_error>(parsing_error: ParsingError, descr: S) -> Error { + pub fn from_parsing_error>(parsing_error: PacketError, descr: S) -> Error { Error { - error_type: ErrorType::ParsingError(parsing_error), + error_type: ErrorType::PacketError(parsing_error), descr: descr.into(), } } @@ -40,13 +42,23 @@ impl Error { descr: descr.into(), } } + + pub fn is_unrecoverable(&self) -> bool { + match self.error_type { + ErrorType::PacketError(_) => false, + ErrorType::IOError(_) | + ErrorType::Syscall(_) => true, + } + } } -impl fmt::Display for ParsingError { +impl fmt::Display for PacketError { fn fmt(&self, f: &mut fmt::Formatter) -> result::Result<(), fmt::Error> { write!(f, "{}", match *self { - ParsingError::NotEnoughData => "not enough data", - ParsingError::IncorrectChecksum => "checksum error", + PacketError::NotEnoughData => "not enough data", + PacketError::IncorrectChecksum => "checksum error", + PacketError::NoEchoHeader => "echo header is missing", + PacketError::SubheaderAlreadPresent => "subheader is already present", }) } } @@ -60,7 +72,7 @@ impl fmt::Display for Error { ErrorType::IOError(ref io_error) => { write!(f, "{} : io error : {}", self.descr, io_error) } - ErrorType::ParsingError(ref parsign_error) => { + ErrorType::PacketError(ref parsign_error) => { write!(f, "{} : packet parsing error : {}", self.descr, @@ -77,4 +89,4 @@ impl convert::From for Error { } pub type Result = result::Result; -pub type ParsingResult = result::Result; +pub type PacketResult = result::Result; diff --git a/src/icmpd/main.rs b/src/icmpd/main.rs index 2623547228..f44089e1f5 100644 --- a/src/icmpd/main.rs +++ b/src/icmpd/main.rs @@ -40,11 +40,29 @@ fn run() -> Result<()> { let icmpd_ = icmpd.clone(); event_queue - .add(icmp_fd, move |_fd| icmpd_.borrow_mut().on_icmp_packet()) + .add(icmp_fd, move |_fd| { + if let Err(err) = icmpd_.borrow_mut().on_icmp_packet() { + if err.is_unrecoverable() { + return Err(err); + } else { + println!("icmpd: network error: {}", err); + } + } + Ok(None) + }) .map_err(|e| Error::from_io_error(e, "failed to listen to events on ip:1"))?; event_queue - .add(scheme_fd, move |_fd| icmpd.borrow_mut().on_scheme_event()) + .add(scheme_fd, move |_fd| { + if let Err(err) = icmpd.borrow_mut().on_scheme_event() { + if err.is_unrecoverable() { + return Err(err); + } else { + println!("icmpd: scheme error: {}", err); + } + } + Ok(None) + }) .map_err(|e| Error::from_io_error(e, "failed to listen to events on icmp"))?; event_queue.run() diff --git a/src/icmpd/packet.rs b/src/icmpd/packet.rs index fb35ce745a..fea7e9cfca 100644 --- a/src/icmpd/packet.rs +++ b/src/icmpd/packet.rs @@ -1,4 +1,4 @@ -use error::{ParsingResult, ParsingError}; +use error::{PacketResult, PacketError}; use netutils::Checksum; use std::mem; @@ -9,14 +9,28 @@ pub struct Header { crc: u16, } +#[derive(Copy, Clone)] +#[repr(packed)] +pub struct EchoHeader { + id: u16, + seq: u16, +} + +pub enum SubHeader<'a> { + Echo(&'a EchoHeader), + None, +} + pub struct Packet<'a> { header: &'a Header, payload: &'a [u8], + subheader: SubHeader<'a>, } pub struct MutPacket<'a> { header: &'a mut Header, payload: &'a mut [u8], + subheader: SubHeader<'a>, } pub enum PacketKind { @@ -28,22 +42,61 @@ pub enum PacketKind { Unknown, } +impl EchoHeader { + pub fn new(id: u16, seq: u16) -> EchoHeader { + EchoHeader { + id: id.to_be(), + seq: seq.to_be(), + } + } + + pub fn get_id(&self) -> u16 { + u16::from_be(self.id) + } + + pub fn get_seq(&self) -> u16 { + u16::from_be(self.seq) + } +} + +impl<'a> SubHeader<'a> { + pub fn get_size(&self) -> usize { + match *self { + SubHeader::None => 0, + SubHeader::Echo(_) => mem::size_of::(), + } + } +} + impl<'a> Packet<'a> { - pub fn from_bytes<'b>(bytes: &'b [u8]) -> ParsingResult> + pub fn from_bytes<'b>(bytes: &'b [u8]) -> PacketResult> where 'b: 'a { if bytes.len() < mem::size_of::
() { - Err(ParsingError::NotEnoughData) + Err(PacketError::NotEnoughData) } else { let (header_bytes, payload_bytes) = bytes.split_at(mem::size_of::
()); - let packet = Packet { + let mut packet = Packet { header: unsafe { mem::transmute(header_bytes.as_ptr()) }, payload: payload_bytes, + subheader: SubHeader::None, }; - if packet.is_checksum_ok() { - Ok(packet) - } else { - Err(ParsingError::IncorrectChecksum) + if !packet.is_checksum_ok() { + return Err(PacketError::IncorrectChecksum); + } + match packet.get_kind() { + PacketKind::EchoResponse => { + if packet.payload.len() < mem::size_of::() { + return Err(PacketError::NoEchoHeader); + } + let (echo_header_payload, payload) = + packet.payload.split_at(mem::size_of::()); + packet.subheader = + SubHeader::Echo(unsafe { mem::transmute(echo_header_payload.as_ptr()) }); + packet.payload = payload; + Ok(packet) + } + _ => Ok(packet), } } } @@ -73,33 +126,65 @@ impl<'a> Packet<'a> { } pub fn get_total_data_size(&self) -> usize { - mem::size_of::
() + self.payload.len() + mem::size_of::
() + self.subheader.get_size() + self.payload.len() + } + + pub fn get_subheader(&self) -> &SubHeader<'a> { + &self.subheader } } impl<'a> MutPacket<'a> { - pub fn from_bytes<'b>(bytes: &'b mut [u8]) -> ParsingResult> + pub fn from_bytes<'b>(bytes: &'b mut [u8]) -> PacketResult> where 'b: 'a { if bytes.len() < mem::size_of::
() { - Err(ParsingError::NotEnoughData) + Err(PacketError::NotEnoughData) } else { let (header_bytes, payload_bytes) = bytes.split_at_mut(mem::size_of::
()); Ok(MutPacket { header: unsafe { mem::transmute(header_bytes.as_ptr()) }, payload: payload_bytes, + subheader: SubHeader::None, }) } } + pub fn set_subheader(self, subheader: &SubHeader) -> PacketResult> { + match self.subheader { + SubHeader::None => {} + _ => return Err(PacketError::SubheaderAlreadPresent), + }; + + if self.payload.len() < subheader.get_size() { + return Err(PacketError::NotEnoughData); + } + + let (subheader_bytes, new_payload) = self.payload.split_at_mut(subheader.get_size()); + let new_subheader = match *subheader { + SubHeader::Echo(echo_sub_header) => { + let echo_sub_header_mut: &mut EchoHeader = + unsafe { mem::transmute(subheader_bytes.as_ptr()) }; + *echo_sub_header_mut = echo_sub_header.clone(); + SubHeader::Echo(echo_sub_header_mut) + } + SubHeader::None => SubHeader::None, + }; + Ok(MutPacket { + header: self.header, + payload: new_payload, + subheader: new_subheader, + }) + } + pub fn set_kind(&mut self, packet_type: PacketKind) { let (new_type, new_code) = match packet_type { - EchoRequest => (ECHO_REQUEST_TYPE, ECHO_REQUEST_CODE), - EchoResponse => (ECHO_RESPONSE_TYPE, ECHO_RESPONSE_CODE), - HostUnreachable => (UNREACHABLE_TYPE, UNREACHABLE_HOST_CODE), - PortUnreachable => (UNREACHABLE_TYPE, UNREACHABLE_PORT_CODE), - ProtoUnreachable => (UNREACHABLE_TYPE, UNREACHABLE_PROTO_CODE), - Unknown => (self.header.icmp_type, self.header.icmp_code), + PacketKind::EchoRequest => (ECHO_REQUEST_TYPE, ECHO_REQUEST_CODE), + PacketKind::EchoResponse => (ECHO_RESPONSE_TYPE, ECHO_RESPONSE_CODE), + PacketKind::HostUnreachable => (UNREACHABLE_TYPE, UNREACHABLE_HOST_CODE), + PacketKind::PortUnreachable => (UNREACHABLE_TYPE, UNREACHABLE_PORT_CODE), + PacketKind::ProtoUnreachable => (UNREACHABLE_TYPE, UNREACHABLE_PROTO_CODE), + PacketKind::Unknown => (self.header.icmp_type, self.header.icmp_code), }; self.header.icmp_type = new_type; self.header.icmp_code = new_code; @@ -116,6 +201,10 @@ impl<'a> MutPacket<'a> { pub fn get_payload(&mut self) -> &mut [u8] { self.payload } + + pub fn get_total_header_size(subheader: &SubHeader) -> usize { + mem::size_of::
() + subheader.get_size() + } } const ECHO_REQUEST_TYPE: u8 = 8; diff --git a/src/icmpd/scheme.rs b/src/icmpd/scheme.rs index 22616f6f67..e943f31a7d 100644 --- a/src/icmpd/scheme.rs +++ b/src/icmpd/scheme.rs @@ -1,7 +1,7 @@ -use error::{Result, Error, ParsingError}; +use error::{Result, Error, PacketError}; use netutils::{Ipv4, Ipv4Header, Checksum, n16}; use netutils; -use packet::{Header, Packet, MutPacket, PacketKind}; +use packet::{Header, Packet, MutPacket, PacketKind, SubHeader, EchoHeader}; use std::collections::{BTreeMap, HashSet, VecDeque}; use std::fs::File; use std::io::{Read, Write}; @@ -24,6 +24,7 @@ struct Handle { flags: usize, ip_addr: Ipv4Addr, payload_queue: VecDeque>, + seq: u16, } impl Handle { @@ -34,6 +35,7 @@ impl Handle { ip_addr, payload_queue: VecDeque::new(), flags, + seq: 0, } } } @@ -79,7 +81,7 @@ impl Icmpd { break; } let ip_packet = Ipv4::from_bytes(&packet_buffer[..bytes_readed]) - .ok_or(Error::from_parsing_error(ParsingError::NotEnoughData, + .ok_or(Error::from_parsing_error(PacketError::NotEnoughData, "failed to parse ip header"))?; let icmp_packet = Packet::from_bytes(&ip_packet.data) @@ -97,6 +99,7 @@ impl Icmpd { fn on_echo_request(&mut self, ip_packet: &Ipv4, icmp_packet: &Packet) -> Result<()> { let echo_response = produce_icmp_packet(Ipv4Addr::from(ip_packet.header.src.bytes), PacketKind::EchoResponse, + &SubHeader::None, icmp_packet.get_payload())?; self.icmp_file .write(&echo_response) @@ -109,13 +112,17 @@ impl Icmpd { .get_mut(&Ipv4Addr::from(ip_packet.header.src.bytes)) { for fd in fd_set.iter() { if let Some(handle) = self.handles.get_mut(fd) { - handle - .payload_queue - .push_back(Vec::from(icmp_packet.get_payload())); - post_fevent(&mut self.scheme_file, - *fd, - syscall::EVENT_READ, - icmp_packet.get_payload().len())?; + if let &SubHeader::Echo(echo_subheader) = icmp_packet.get_subheader() { + if echo_subheader.get_id() == *fd as u16 { + handle + .payload_queue + .push_back(Vec::from(icmp_packet.get_payload())); + post_fevent(&mut self.scheme_file, + *fd, + syscall::EVENT_READ, + icmp_packet.get_payload().len())?; + } + } } } } @@ -207,8 +214,12 @@ impl SchemeMut for Icmpd { match handle.handle_type { HandleType::Echo => { let echo_request = - produce_icmp_packet(handle.ip_addr, PacketKind::EchoRequest, buf) - .map_err(|_| syscall::Error::new(syscall::EPROTO))?; + produce_icmp_packet(handle.ip_addr, + PacketKind::EchoRequest, + &SubHeader::Echo(&EchoHeader::new(fd as u16, handle.seq)), + buf) + .map_err(|_| syscall::Error::new(syscall::EPROTO))?; + handle.seq += 1; self.icmp_file .write(&echo_request) .map_err(|_| syscall::Error::new(syscall::EPROTO)) @@ -234,17 +245,24 @@ impl SchemeMut for Icmpd { } } -fn produce_icmp_packet(to_ip: Ipv4Addr, kind: PacketKind, payload: &[u8]) -> Result> { - let mut ip_data = vec![0; mem::size_of::
() + payload.len()]; +fn produce_icmp_packet(to_ip: Ipv4Addr, + kind: PacketKind, + subheader: &SubHeader, + payload: &[u8]) + -> Result> { + let mut ip_data = vec![0; MutPacket::get_total_header_size(subheader) + payload.len()]; { let mut out_icmp_packet = MutPacket::from_bytes(&mut ip_data) .map_err(|e| Error::from_parsing_error(e, "can't parse empty icmp header"))?; + out_icmp_packet = out_icmp_packet + .set_subheader(subheader) + .map_err(|e| Error::from_parsing_error(e, "can't set subheader"))?; out_icmp_packet.set_kind(kind); { let out_payload = out_icmp_packet.get_payload(); if out_payload.len() != payload.len() { - return Err(Error::from_parsing_error(ParsingError::NotEnoughData, + return Err(Error::from_parsing_error(PacketError::NotEnoughData, " can't copy icmp payload to echo response")); } //WARNING: copy_from_slice can panic if the slices' lengths are different From ce69cdbb8fe0340d09e5c09072c29e93130e1728 Mon Sep 17 00:00:00 2001 From: Egor Karavaev Date: Mon, 12 Jun 2017 19:59:25 +0300 Subject: [PATCH 006/155] Add small fix after testing with ping. --- src/icmpd/error.rs | 8 ++++---- src/icmpd/main.rs | 7 ++++--- src/icmpd/packet.rs | 11 +++-------- src/icmpd/scheme.rs | 33 +++++++++++++++------------------ 4 files changed, 26 insertions(+), 33 deletions(-) diff --git a/src/icmpd/error.rs b/src/icmpd/error.rs index ae8007e961..8c94e2af8c 100644 --- a/src/icmpd/error.rs +++ b/src/icmpd/error.rs @@ -1,8 +1,8 @@ -use std::result; -use std::fmt; -use syscall::error::Error as SyscallError; -use std::io::Error as IOError; use std::convert; +use std::fmt; +use std::io::Error as IOError; +use std::result; +use syscall::error::Error as SyscallError; pub enum PacketError { NotEnoughData, diff --git a/src/icmpd/main.rs b/src/icmpd/main.rs index f44089e1f5..4284ae5d87 100644 --- a/src/icmpd/main.rs +++ b/src/icmpd/main.rs @@ -18,6 +18,10 @@ mod scheme; fn run() -> Result<()> { use syscall::flag::*; + if unsafe { syscall::clone(0).unwrap() } != 0 { + return Ok(()); + } + let icmp_fd = syscall::open("ip:1", O_RDWR | O_NONBLOCK) .map_err(|e| Error::from_syscall_error(e, "failed to open ip:1"))? as RawFd; @@ -26,9 +30,6 @@ fn run() -> Result<()> { .map_err(|e| Error::from_syscall_error(e, "failed to open :icmp"))? as RawFd; - if unsafe { syscall::clone(0).unwrap() } != 0 { - return Ok(()); - } let icmpd = Rc::new(RefCell::new(Icmpd::new(unsafe { File::from_raw_fd(icmp_fd) }, unsafe { File::from_raw_fd(scheme_fd) }))); diff --git a/src/icmpd/packet.rs b/src/icmpd/packet.rs index fea7e9cfca..ade4f6e4a0 100644 --- a/src/icmpd/packet.rs +++ b/src/icmpd/packet.rs @@ -13,7 +13,7 @@ pub struct Header { #[repr(packed)] pub struct EchoHeader { id: u16, - seq: u16, + //Seq is set by the caller } pub enum SubHeader<'a> { @@ -43,20 +43,15 @@ pub enum PacketKind { } impl EchoHeader { - pub fn new(id: u16, seq: u16) -> EchoHeader { + pub fn new(id: u16) -> EchoHeader { EchoHeader { id: id.to_be(), - seq: seq.to_be(), } } pub fn get_id(&self) -> u16 { u16::from_be(self.id) } - - pub fn get_seq(&self) -> u16 { - u16::from_be(self.seq) - } } impl<'a> SubHeader<'a> { @@ -193,7 +188,7 @@ impl<'a> MutPacket<'a> { pub fn compute_checksum(&mut self) { self.header.crc = 0; let header_ptr = self.header as *mut Header as usize; - let total_size = mem::size_of::
() + self.payload.len(); + let total_size = Self::get_total_header_size(&self.subheader) + self.payload.len(); let crc = Checksum::compile(unsafe { Checksum::sum(header_ptr, total_size) }); self.header.crc = crc } diff --git a/src/icmpd/scheme.rs b/src/icmpd/scheme.rs index e943f31a7d..1360ea345e 100644 --- a/src/icmpd/scheme.rs +++ b/src/icmpd/scheme.rs @@ -1,7 +1,7 @@ use error::{Result, Error, PacketError}; use netutils::{Ipv4, Ipv4Header, Checksum, n16}; use netutils; -use packet::{Header, Packet, MutPacket, PacketKind, SubHeader, EchoHeader}; +use packet::{Packet, MutPacket, PacketKind, SubHeader, EchoHeader}; use std::collections::{BTreeMap, HashSet, VecDeque}; use std::fs::File; use std::io::{Read, Write}; @@ -24,7 +24,6 @@ struct Handle { flags: usize, ip_addr: Ipv4Addr, payload_queue: VecDeque>, - seq: u16, } impl Handle { @@ -35,7 +34,6 @@ impl Handle { ip_addr, payload_queue: VecDeque::new(), flags, - seq: 0, } } } @@ -66,6 +64,7 @@ impl Icmpd { break; } self.handle(&mut packet); + self.scheme_file.write(&packet)?; } Ok(None) } @@ -108,19 +107,22 @@ impl Icmpd { } fn on_echo_response(&mut self, ip_packet: &Ipv4, icmp_packet: &Packet) -> Result<()> { - if let Some(fd_set) = self.echo_ips - .get_mut(&Ipv4Addr::from(ip_packet.header.src.bytes)) { - for fd in fd_set.iter() { - if let Some(handle) = self.handles.get_mut(fd) { - if let &SubHeader::Echo(echo_subheader) = icmp_packet.get_subheader() { + if let &SubHeader::Echo(echo_subheader) = icmp_packet.get_subheader() { + if let Some(fd_set) = self.echo_ips + .get_mut(&Ipv4Addr::from(ip_packet.header.src.bytes)) { + for fd in fd_set.iter() { + if let Some(handle) = self.handles.get_mut(fd) { if echo_subheader.get_id() == *fd as u16 { handle .payload_queue .push_back(Vec::from(icmp_packet.get_payload())); - post_fevent(&mut self.scheme_file, - *fd, - syscall::EVENT_READ, - icmp_packet.get_payload().len())?; + + if handle.events & syscall::EVENT_READ == syscall::EVENT_READ { + post_fevent(&mut self.scheme_file, + *fd, + syscall::EVENT_READ, + icmp_packet.get_payload().len())?; + } } } } @@ -161,10 +163,6 @@ impl SchemeMut for Icmpd { use std::str; use std::str::FromStr; - // if uid != 0 { - // return Err(syscall::Error::new(syscall::EACCES)); - // } - let path = str::from_utf8(url) .or(Err(syscall::Error::new(syscall::EINVAL)))?; let mut parts = path.split("/"); @@ -216,10 +214,9 @@ impl SchemeMut for Icmpd { let echo_request = produce_icmp_packet(handle.ip_addr, PacketKind::EchoRequest, - &SubHeader::Echo(&EchoHeader::new(fd as u16, handle.seq)), + &SubHeader::Echo(&EchoHeader::new(fd as u16)), buf) .map_err(|_| syscall::Error::new(syscall::EPROTO))?; - handle.seq += 1; self.icmp_file .write(&echo_request) .map_err(|_| syscall::Error::new(syscall::EPROTO)) From 53db52c119ef224f14c7de150da31347bb9ead70 Mon Sep 17 00:00:00 2001 From: Egor Karavaev Date: Tue, 13 Jun 2017 16:23:49 +0300 Subject: [PATCH 007/155] Fix clippy warnings. --- Cargo.toml | 2 +- src/icmpd/packet.rs | 36 +++++++++++++++++------------------ src/icmpd/scheme.rs | 46 +++++++++++++++++++++++++-------------------- 3 files changed, 45 insertions(+), 39 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c29a186b3e..16aa9d1275 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,5 +25,5 @@ path = "src/icmpd/main.rs" [dependencies] netutils = { git = "https://github.com/redox-os/netutils.git" } rand = "0.3" -redox_event = { path = "../event" } +redox_event = { git = "https://github.com/redox-os/event.git" } redox_syscall = "0.1" diff --git a/src/icmpd/packet.rs b/src/icmpd/packet.rs index ade4f6e4a0..0426d61d90 100644 --- a/src/icmpd/packet.rs +++ b/src/icmpd/packet.rs @@ -2,6 +2,15 @@ use error::{PacketResult, PacketError}; use netutils::Checksum; use std::mem; +const ECHO_REQUEST_TYPE: u8 = 8; +const ECHO_REQUEST_CODE: u8 = 0; +const ECHO_RESPONSE_TYPE: u8 = 0; +const ECHO_RESPONSE_CODE: u8 = 0; +const UNREACHABLE_TYPE: u8 = 3; +const UNREACHABLE_HOST_CODE: u8 = 1; +const UNREACHABLE_PROTO_CODE: u8 = 2; +const UNREACHABLE_PORT_CODE: u8 = 3; + #[repr(packed)] pub struct Header { icmp_type: u8, @@ -44,9 +53,7 @@ pub enum PacketKind { impl EchoHeader { pub fn new(id: u16) -> EchoHeader { - EchoHeader { - id: id.to_be(), - } + EchoHeader { id: id.to_be() } } pub fn get_id(&self) -> u16 { @@ -72,7 +79,7 @@ impl<'a> Packet<'a> { } else { let (header_bytes, payload_bytes) = bytes.split_at(mem::size_of::
()); let mut packet = Packet { - header: unsafe { mem::transmute(header_bytes.as_ptr()) }, + header: unsafe { &*(header_bytes.as_ptr() as *const Header) }, payload: payload_bytes, subheader: SubHeader::None, }; @@ -86,8 +93,10 @@ impl<'a> Packet<'a> { } let (echo_header_payload, payload) = packet.payload.split_at(mem::size_of::()); - packet.subheader = - SubHeader::Echo(unsafe { mem::transmute(echo_header_payload.as_ptr()) }); + packet.subheader = SubHeader::Echo(unsafe { + &*(echo_header_payload.as_ptr() as + *const EchoHeader) + }); packet.payload = payload; Ok(packet) } @@ -138,7 +147,7 @@ impl<'a> MutPacket<'a> { } else { let (header_bytes, payload_bytes) = bytes.split_at_mut(mem::size_of::
()); Ok(MutPacket { - header: unsafe { mem::transmute(header_bytes.as_ptr()) }, + header: unsafe { &mut *(header_bytes.as_ptr() as *mut Header) }, payload: payload_bytes, subheader: SubHeader::None, }) @@ -159,8 +168,8 @@ impl<'a> MutPacket<'a> { let new_subheader = match *subheader { SubHeader::Echo(echo_sub_header) => { let echo_sub_header_mut: &mut EchoHeader = - unsafe { mem::transmute(subheader_bytes.as_ptr()) }; - *echo_sub_header_mut = echo_sub_header.clone(); + unsafe { &mut *(subheader_bytes.as_ptr() as *mut EchoHeader) }; + *echo_sub_header_mut = *echo_sub_header; SubHeader::Echo(echo_sub_header_mut) } SubHeader::None => SubHeader::None, @@ -201,12 +210,3 @@ impl<'a> MutPacket<'a> { mem::size_of::
() + subheader.get_size() } } - -const ECHO_REQUEST_TYPE: u8 = 8; -const ECHO_REQUEST_CODE: u8 = 0; -const ECHO_RESPONSE_TYPE: u8 = 0; -const ECHO_RESPONSE_CODE: u8 = 0; -const UNREACHABLE_TYPE: u8 = 3; -const UNREACHABLE_HOST_CODE: u8 = 1; -const UNREACHABLE_PROTO_CODE: u8 = 2; -const UNREACHABLE_PORT_CODE: u8 = 3; diff --git a/src/icmpd/scheme.rs b/src/icmpd/scheme.rs index 1360ea345e..4f42e9a47f 100644 --- a/src/icmpd/scheme.rs +++ b/src/icmpd/scheme.rs @@ -64,7 +64,7 @@ impl Icmpd { break; } self.handle(&mut packet); - self.scheme_file.write(&packet)?; + self.scheme_file.write_all(&packet)?; } Ok(None) } @@ -80,8 +80,10 @@ impl Icmpd { break; } let ip_packet = Ipv4::from_bytes(&packet_buffer[..bytes_readed]) - .ok_or(Error::from_parsing_error(PacketError::NotEnoughData, - "failed to parse ip header"))?; + .ok_or_else(|| { + Error::from_parsing_error(PacketError::NotEnoughData, + "failed to parse ip header") + })?; let icmp_packet = Packet::from_bytes(&ip_packet.data) .map_err(|e| Error::from_parsing_error(e, "failed to parse ICMP packet"))?; @@ -107,7 +109,7 @@ impl Icmpd { } fn on_echo_response(&mut self, ip_packet: &Ipv4, icmp_packet: &Packet) -> Result<()> { - if let &SubHeader::Echo(echo_subheader) = icmp_packet.get_subheader() { + if let SubHeader::Echo(echo_subheader) = *icmp_packet.get_subheader() { if let Some(fd_set) = self.echo_ips .get_mut(&Ipv4Addr::from(ip_packet.header.src.bytes)) { for fd in fd_set.iter() { @@ -138,7 +140,7 @@ impl Icmpd { self.handles.insert(fd, handle); self.echo_ips .entry(ip_addr) - .or_insert_with(|| HashSet::new()) + .or_insert_with(HashSet::new) .insert(fd); Ok(fd) } @@ -164,13 +166,17 @@ impl SchemeMut for Icmpd { use std::str::FromStr; let path = str::from_utf8(url) - .or(Err(syscall::Error::new(syscall::EINVAL)))?; - let mut parts = path.split("/"); - let method = parts.next().ok_or(syscall::Error::new(syscall::EINVAL))?; + .or_else(|_| Err(syscall::Error::new(syscall::EINVAL)))?; + let mut parts = path.split('/'); + let method = parts + .next() + .ok_or_else(|| syscall::Error::new(syscall::EINVAL))?; match method { "echo" => { - let addr = parts.next().ok_or(syscall::Error::new(syscall::EINVAL))?; - let addr = Ipv4Addr::from_str(&addr) + let addr = parts + .next() + .ok_or_else(|| syscall::Error::new(syscall::EINVAL))?; + let addr = Ipv4Addr::from_str(addr) .map_err(|_| syscall::Error::new(syscall::EINVAL))?; self.open_echo(addr, flags) } @@ -182,7 +188,7 @@ impl SchemeMut for Icmpd { let (ip, ip_set) = { let handle = self.handles .get_mut(&fd) - .ok_or(syscall::Error::new(syscall::EBADF))?; + .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; match handle.handle_type { HandleType::Echo => (handle.ip_addr, &mut self.echo_ips), } @@ -208,15 +214,15 @@ impl SchemeMut for Icmpd { } let handle = self.handles .get_mut(&fd) - .ok_or(syscall::Error::new(syscall::EBADF))?; + .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; match handle.handle_type { HandleType::Echo => { - let echo_request = - produce_icmp_packet(handle.ip_addr, - PacketKind::EchoRequest, - &SubHeader::Echo(&EchoHeader::new(fd as u16)), - buf) - .map_err(|_| syscall::Error::new(syscall::EPROTO))?; + let echo_request = produce_icmp_packet(handle.ip_addr, + PacketKind::EchoRequest, + &SubHeader::Echo(&EchoHeader::new(fd as + u16)), + buf) + .map_err(|_| syscall::Error::new(syscall::EPROTO))?; self.icmp_file .write(&echo_request) .map_err(|_| syscall::Error::new(syscall::EPROTO)) @@ -227,7 +233,7 @@ impl SchemeMut for Icmpd { fn read(&mut self, fd: usize, buf: &mut [u8]) -> syscall::Result { let handle = self.handles .get_mut(&fd) - .ok_or(syscall::Error::new(syscall::EBADF))?; + .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; match handle.handle_type { HandleType::Echo => Icmpd::read_echo(handle, buf), } @@ -236,7 +242,7 @@ impl SchemeMut for Icmpd { fn fevent(&mut self, fd: usize, events: usize) -> syscall::Result { let handle = self.handles .get_mut(&fd) - .ok_or(syscall::Error::new(syscall::EBADF))?; + .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; handle.events = events; Ok(fd) } From a2d75af7d7a4d84dcf980b4d5ab83bb271a57b82 Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Fri, 16 Jun 2017 16:39:48 -0700 Subject: [PATCH 008/155] Correct fpath() for tcpd --- src/tcpd/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tcpd/main.rs b/src/tcpd/main.rs index 8878b006f3..9ee1d240ad 100644 --- a/src/tcpd/main.rs +++ b/src/tcpd/main.rs @@ -798,7 +798,7 @@ impl SchemeMut for Tcpd { fn fpath(&mut self, file: usize, buf: &mut [u8]) -> Result { if let Handle::Tcp(ref mut handle) = *self.handles.get_mut(&file).ok_or(Error::new(EBADF))? { - let path_string = format!("udp:{}:{}/{}:{}", handle.remote.0.to_string(), handle.remote.1, handle.local.0.to_string(), handle.local.1); + let path_string = format!("tcp:{}:{}/{}:{}", handle.remote.0.to_string(), handle.remote.1, handle.local.0.to_string(), handle.local.1); let path = path_string.as_bytes(); let mut i = 0; From 20793828c401587636f0b50473ae5ca5292f1082 Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Thu, 22 Jun 2017 15:26:18 -0700 Subject: [PATCH 009/155] tcpd: fix bug in partial reads that was breaking https in curl --- src/tcpd/main.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/tcpd/main.rs b/src/tcpd/main.rs index 9ee1d240ad..1c3a881ccc 100644 --- a/src/tcpd/main.rs +++ b/src/tcpd/main.rs @@ -316,13 +316,15 @@ impl Tcpd { while ! handle.todo_read.is_empty() && (! handle.data.is_empty() || handle.read_closed()) { let (_timeout, mut packet) = handle.todo_read.pop_front().unwrap(); let buf = unsafe { slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) }; - if let Some((_ip, tcp)) = handle.data.pop_front() { - let mut i = 0; - while i < buf.len() && i < tcp.data.len() { - buf[i] = tcp.data[i]; - i += 1; + if let Some((ip, mut tcp)) = handle.data.pop_front() { + let len = std::cmp::min(buf.len(), tcp.data.len()); + for (i, c) in tcp.data.drain(0..len).enumerate() { + buf[i] = c; } - packet.a = i; + if !tcp.data.is_empty() { + handle.data.push_front((ip, tcp)); + } + packet.a = len; } else { packet.a = 0; } From 133d38ba7e41a1b61c3d95d492b9f3dd31d02d93 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Thu, 20 Jul 2017 20:01:22 -0600 Subject: [PATCH 010/155] Trim network config --- .gitignore | 2 ++ src/ethernetd/scheme.rs | 3 ++- src/ipd/interface/ethernet.rs | 8 ++++---- 3 files changed, 8 insertions(+), 5 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..fa8d85ac52 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +Cargo.lock +target diff --git a/src/ethernetd/scheme.rs b/src/ethernetd/scheme.rs index 7b1b3bdda9..bbd6bc94df 100644 --- a/src/ethernetd/scheme.rs +++ b/src/ethernetd/scheme.rs @@ -63,7 +63,8 @@ impl EthernetScheme { impl SchemeMut for EthernetScheme { fn open(&mut self, url: &[u8], flags: usize, uid: u32, _gid: u32) -> Result { if uid == 0 { - let mac_addr = MacAddr::from_str(&getcfg("mac").map_err(|err| Error::new(err.raw_os_error().unwrap_or(EIO)))?); + let mac_str = getcfg("mac").map_err(|err| Error::new(err.raw_os_error().unwrap_or(EIO)))?; + let mac_addr = MacAddr::from_str(mac_str.trim()); let path = try!(str::from_utf8(url).or(Err(Error::new(EINVAL)))); let ethertype = u16::from_str_radix(path, 16).unwrap_or(0); diff --git a/src/ipd/interface/ethernet.rs b/src/ipd/interface/ethernet.rs index d914a78431..4898c36fc6 100644 --- a/src/ipd/interface/ethernet.rs +++ b/src/ipd/interface/ethernet.rs @@ -20,10 +20,10 @@ pub struct EthernetInterface { impl EthernetInterface { pub fn new(arp_fd: usize, ip_fd: usize) -> Self { EthernetInterface { - mac: MacAddr::from_str(&getcfg("mac").unwrap()), - ip: Ipv4Addr::from_str(&getcfg("ip").unwrap()), - router: Ipv4Addr::from_str(&getcfg("ip_router").unwrap()), - subnet: Ipv4Addr::from_str(&getcfg("ip_subnet").unwrap()), + mac: MacAddr::from_str(&getcfg("mac").unwrap().trim()), + ip: Ipv4Addr::from_str(&getcfg("ip").unwrap().trim()), + router: Ipv4Addr::from_str(&getcfg("ip_router").unwrap().trim()), + subnet: Ipv4Addr::from_str(&getcfg("ip_subnet").unwrap().trim()), arp_file: unsafe { File::from_raw_fd(arp_fd) }, ip_file: unsafe { File::from_raw_fd(ip_fd) }, arp: BTreeMap::new(), From 7f1eddc84d835423406ebf082cbbbdf9fc4b5025 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sat, 22 Jul 2017 13:16:41 -0600 Subject: [PATCH 011/155] Return error when dup buf is not empty --- src/ethernetd/scheme.rs | 6 +++++- src/ipd/main.rs | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/ethernetd/scheme.rs b/src/ethernetd/scheme.rs index bbd6bc94df..f6da2aa7a3 100644 --- a/src/ethernetd/scheme.rs +++ b/src/ethernetd/scheme.rs @@ -85,7 +85,11 @@ impl SchemeMut for EthernetScheme { } } - fn dup(&mut self, id: usize, _buf: &[u8]) -> Result { + fn dup(&mut self, id: usize, buf: &[u8]) -> Result { + if ! buf.is_empty() { + return Err(Error::new(EINVAL)); + } + let next_id = self.next_id; self.next_id += 1; diff --git a/src/ipd/main.rs b/src/ipd/main.rs index 49e332fcf7..c5ce140634 100644 --- a/src/ipd/main.rs +++ b/src/ipd/main.rs @@ -150,7 +150,11 @@ impl SchemeMut for Ipd { } } - fn dup(&mut self, file: usize, _buf: &[u8]) -> Result { + fn dup(&mut self, file: usize, buf: &[u8]) -> Result { + if ! buf.is_empty() { + return Err(Error::new(EINVAL)); + } + let handle = { let handle = self.handles.get(&file).ok_or(Error::new(EBADF))?; Handle { From b34622184095a9765a2064e1d72087980494c2df Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Wed, 26 Jul 2017 07:54:58 -0600 Subject: [PATCH 012/155] Add Cargo.lock --- .gitignore | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index fa8d85ac52..b83d22266a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ -Cargo.lock -target +/target/ From 51abd85d7093f84ddb4fc7fb1b5d58a07d2a0782 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Wed, 26 Jul 2017 08:02:46 -0600 Subject: [PATCH 013/155] Add Cargo.lock file --- Cargo.lock | 416 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 416 insertions(+) create mode 100644 Cargo.lock diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000000..cc524095eb --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,416 @@ +[root] +name = "redox_netstack" +version = "0.1.0" +dependencies = [ + "netutils 0.1.0 (git+https://github.com/redox-os/netutils.git)", + "rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_event 0.1.0 (git+https://github.com/redox-os/event.git)", + "redox_syscall 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "base64" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "base64" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "byteorder" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "byteorder" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "coco" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "either 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "scopeguard 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "either" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "futures" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "gcc" +version = "0.3.51" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "httparse" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "hyper" +version = "0.10.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "base64 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "httparse 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "mime 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)", + "traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "typeable 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "unicase 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "hyper-rustls" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "hyper 0.10.12 (registry+https://github.com/rust-lang/crates.io-index)", + "rustls 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "webpki-roots 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "idna" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-normalization 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "kernel32-sys" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "language-tags" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "lazy_static" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "libc" +version = "0.2.28" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "log" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "matches" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "mime" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "netutils" +version = "0.1.0" +source = "git+https://github.com/redox-os/netutils.git#9d3b8daeb9240fd8b761b8435cbb404bb2c1232b" +dependencies = [ + "hyper 0.10.12 (registry+https://github.com/rust-lang/crates.io-index)", + "hyper-rustls 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.28 (registry+https://github.com/rust-lang/crates.io-index)", + "ntpclient 0.0.1 (git+https://github.com/willem66745/ntpclient-rust)", + "redox_event 0.1.0 (git+https://github.com/redox-os/event.git)", + "redox_syscall 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "termion 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "ntpclient" +version = "0.0.1" +source = "git+https://github.com/willem66745/ntpclient-rust#7e3bdf60eb940825789a8da5181025320e3050b0" +dependencies = [ + "byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "num_cpus" +version = "1.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.28 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "percent-encoding" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "rand" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.28 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rayon" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rayon-core 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rayon-core" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "coco 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.28 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "redox_event" +version = "0.1.0" +source = "git+https://github.com/redox-os/event.git#42d552e4765efbfb4ec39ce174900d3f48548a70" +dependencies = [ + "redox_syscall 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "redox_syscall" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "redox_termios" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "redox_syscall 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "ring" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "gcc 0.3.51 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.28 (registry+https://github.com/rust-lang/crates.io-index)", + "rayon 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "untrusted 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rustls" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "base64 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "ring 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)", + "untrusted 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "webpki 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "safemem" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "scopeguard" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "termion" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.28 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_termios 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "time" +version = "0.1.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.28 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "traitobject" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "typeable" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "unicase" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "version_check 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "unicode-bidi" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "unicode-normalization" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "untrusted" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "url" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "idna 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "percent-encoding 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "version_check" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "webpki" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "ring 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)", + "untrusted 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "webpki-roots" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "untrusted 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "webpki 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "winapi" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "winapi-build" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[metadata] +"checksum base64 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "30e93c03064e7590d0466209155251b90c22e37fab1daf2771582598b5827557" +"checksum base64 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "96434f987501f0ed4eb336a411e0631ecd1afa11574fe148587adc4ff96143c9" +"checksum byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855" +"checksum byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff81738b726f5d099632ceaffe7fb65b90212e8dce59d518729e7e8634032d3d" +"checksum coco 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c06169f5beb7e31c7c67ebf5540b8b472d23e3eade3b2ec7d1f5b504a85f91bd" +"checksum either 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "18785c1ba806c258137c937e44ada9ee7e69a37e3c72077542cd2f069d78562a" +"checksum futures 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "4b63a4792d4f8f686defe3b39b92127fea6344de5d38202b2ee5a11bbbf29d6a" +"checksum gcc 0.3.51 (registry+https://github.com/rust-lang/crates.io-index)" = "120d07f202dcc3f72859422563522b66fe6463a4c513df062874daad05f85f0a" +"checksum httparse 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "af2f2dd97457e8fb1ae7c5a420db346af389926e36f43768b96f101546b04a07" +"checksum hyper 0.10.12 (registry+https://github.com/rust-lang/crates.io-index)" = "0f01e4a20f5dfa5278d7762b7bdb7cab96e24378b9eca3889fbd4b5e94dc7063" +"checksum hyper-rustls 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "04535774f79684c99528944ebdb89756c945c027e55ce52faa245879d836c8fb" +"checksum idna 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "014b298351066f1512874135335d62a789ffe78a9974f94b43ed5621951eaf7d" +"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" +"checksum language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a" +"checksum lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3b37545ab726dd833ec6420aaba8231c5b320814b9029ad585555d2a03e94fbf" +"checksum libc 0.2.28 (registry+https://github.com/rust-lang/crates.io-index)" = "bb7b49972ee23d8aa1026c365a5b440ba08e35075f18c459980c7395c221ec48" +"checksum log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "880f77541efa6e5cc74e76910c9884d9859683118839d6a1dc3b11e63512565b" +"checksum matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "100aabe6b8ff4e4a7e32c1c13523379802df0772b82466207ac25b013f193376" +"checksum mime 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ba626b8a6de5da682e1caa06bdb42a335aee5a84db8e5046a3e8ab17ba0a3ae0" +"checksum netutils 0.1.0 (git+https://github.com/redox-os/netutils.git)" = "" +"checksum ntpclient 0.0.1 (git+https://github.com/willem66745/ntpclient-rust)" = "" +"checksum num_cpus 1.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "aec53c34f2d0247c5ca5d32cca1478762f301740468ee9ee6dcb7a0dd7a0c584" +"checksum percent-encoding 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "de154f638187706bde41d9b4738748933d64e6b37bdbffc0b47a97d16a6ae356" +"checksum rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "022e0636ec2519ddae48154b028864bdce4eaf7d35226ab8e65c611be97b189d" +"checksum rayon 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a77c51c07654ddd93f6cb543c7a849863b03abc7e82591afda6dc8ad4ac3ac4a" +"checksum rayon-core 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7febc28567082c345f10cddc3612c6ea020fc3297a1977d472cf9fdb73e6e493" +"checksum redox_event 0.1.0 (git+https://github.com/redox-os/event.git)" = "" +"checksum redox_syscall 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)" = "80dcf663dc552529b9bfc7bdb30ea12e5fa5d3545137d850a91ad410053f68e9" +"checksum redox_termios 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc495930de8d330f14856cface52561b7d79a072c76e438cf8f34d7233a35fa7" +"checksum ring 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1f2a6dc7fc06a05e6de183c5b97058582e9da2de0c136eafe49609769c507724" +"checksum rustls 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "17727f4b991294da2c84d75a43c003151ff58072212768800f66c56ee46dca43" +"checksum safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e27a8b19b835f7aea908818e871f5cc3a5a186550c30773be987e155e8163d8f" +"checksum scopeguard 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c79eb2c3ac4bc2507cda80e7f3ac5b88bd8eae4c0914d5663e6a8933994be918" +"checksum termion 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8affd752d0f2c7127d6d5f1b98182a5471606b48b1a955165d39eb5e4887ceba" +"checksum time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)" = "d5d788d3aa77bc0ef3e9621256885555368b47bd495c13dd2e7413c89f845520" +"checksum traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079" +"checksum typeable 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1410f6f91f21d1612654e7cc69193b0334f909dcf2c790c4826254fbb86f8887" +"checksum unicase 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7f4765f83163b74f957c797ad9253caf97f103fb064d3999aea9568d09fc8a33" +"checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" +"checksum unicode-normalization 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "51ccda9ef9efa3f7ef5d91e8f9b83bbe6955f9bf86aec89d5cce2c874625920f" +"checksum untrusted 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6b65243989ef6aacd9c0d6bd2b822765c3361d8ed352185a6f3a41f3a718c673" +"checksum url 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "eeb819346883532a271eb626deb43c4a1bb4c4dd47c519bd78137c3e72a4fe27" +"checksum version_check 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6b772017e347561807c1aa192438c5fd74242a670a6cffacc40f2defd1dc069d" +"checksum webpki 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e499345fc4c6b7c79a5b8756d4592c4305510a13512e79efafe00dfbd67bbac6" +"checksum webpki-roots 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5bfb3f50499f21ad2317f442845e3b5805b007f1e728f59885c99e61b8c181a7" +"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" +"checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" From d2f9874f9d216b4e4a92435aab58c69a4f414ba0 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Wed, 26 Jul 2017 08:17:40 -0600 Subject: [PATCH 014/155] Update Cargo.lock --- Cargo.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index cc524095eb..127c2b9a69 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -147,7 +147,7 @@ dependencies = [ [[package]] name = "netutils" version = "0.1.0" -source = "git+https://github.com/redox-os/netutils.git#9d3b8daeb9240fd8b761b8435cbb404bb2c1232b" +source = "git+https://github.com/redox-os/netutils.git#f5ccf7232353107e46e3d9308a1631633ee0398a" dependencies = [ "hyper 0.10.12 (registry+https://github.com/rust-lang/crates.io-index)", "hyper-rustls 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", From f4a98827647d578286c85aa31f5a248b49d017d4 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sat, 29 Jul 2017 08:24:45 -0600 Subject: [PATCH 015/155] Update Cargo.lock --- Cargo.lock | 65 ++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 53 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 127c2b9a69..65a5604dc6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3,9 +3,9 @@ name = "redox_netstack" version = "0.1.0" dependencies = [ "netutils 0.1.0 (git+https://github.com/redox-os/netutils.git)", - "rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", "redox_event 0.1.0 (git+https://github.com/redox-os/event.git)", - "redox_syscall 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -25,6 +25,11 @@ dependencies = [ "safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "bitflags" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "byteorder" version = "0.5.3" @@ -44,6 +49,19 @@ dependencies = [ "scopeguard 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "conv" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "custom_derive 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "custom_derive" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "either" version = "1.1.0" @@ -131,6 +149,23 @@ name = "log" version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "magenta" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "conv 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "magenta-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "magenta-sys" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "matches" version = "0.1.6" @@ -154,7 +189,7 @@ dependencies = [ "libc 0.2.28 (registry+https://github.com/rust-lang/crates.io-index)", "ntpclient 0.0.1 (git+https://github.com/willem66745/ntpclient-rust)", "redox_event 0.1.0 (git+https://github.com/redox-os/event.git)", - "redox_syscall 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", "termion 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -182,10 +217,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "rand" -version = "0.3.15" +version = "0.3.16" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "libc 0.2.28 (registry+https://github.com/rust-lang/crates.io-index)", + "magenta 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -206,7 +242,7 @@ dependencies = [ "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.28 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.6.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -214,12 +250,12 @@ name = "redox_event" version = "0.1.0" source = "git+https://github.com/redox-os/event.git#42d552e4765efbfb4ec39ce174900d3f48548a70" dependencies = [ - "redox_syscall 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "redox_syscall" -version = "0.1.27" +version = "0.1.28" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -227,7 +263,7 @@ name = "redox_termios" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "redox_syscall 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -271,7 +307,7 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "libc 0.2.28 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", "redox_termios 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -282,7 +318,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.28 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -369,9 +405,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [metadata] "checksum base64 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "30e93c03064e7590d0466209155251b90c22e37fab1daf2771582598b5827557" "checksum base64 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "96434f987501f0ed4eb336a411e0631ecd1afa11574fe148587adc4ff96143c9" +"checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d" "checksum byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855" "checksum byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff81738b726f5d099632ceaffe7fb65b90212e8dce59d518729e7e8634032d3d" "checksum coco 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c06169f5beb7e31c7c67ebf5540b8b472d23e3eade3b2ec7d1f5b504a85f91bd" +"checksum conv 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "78ff10625fd0ac447827aa30ea8b861fead473bb60aeb73af6c1c58caf0d1299" +"checksum custom_derive 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "ef8ae57c4978a2acd8b869ce6b9ca1dfe817bff704c220209fdef2c0b75a01b9" "checksum either 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "18785c1ba806c258137c937e44ada9ee7e69a37e3c72077542cd2f069d78562a" "checksum futures 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "4b63a4792d4f8f686defe3b39b92127fea6344de5d38202b2ee5a11bbbf29d6a" "checksum gcc 0.3.51 (registry+https://github.com/rust-lang/crates.io-index)" = "120d07f202dcc3f72859422563522b66fe6463a4c513df062874daad05f85f0a" @@ -384,17 +423,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3b37545ab726dd833ec6420aaba8231c5b320814b9029ad585555d2a03e94fbf" "checksum libc 0.2.28 (registry+https://github.com/rust-lang/crates.io-index)" = "bb7b49972ee23d8aa1026c365a5b440ba08e35075f18c459980c7395c221ec48" "checksum log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "880f77541efa6e5cc74e76910c9884d9859683118839d6a1dc3b11e63512565b" +"checksum magenta 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4bf0336886480e671965f794bc9b6fce88503563013d1bfb7a502c81fe3ac527" +"checksum magenta-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "40d014c7011ac470ae28e2f76a02bfea4a8480f73e701353b49ad7a8d75f4699" "checksum matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "100aabe6b8ff4e4a7e32c1c13523379802df0772b82466207ac25b013f193376" "checksum mime 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ba626b8a6de5da682e1caa06bdb42a335aee5a84db8e5046a3e8ab17ba0a3ae0" "checksum netutils 0.1.0 (git+https://github.com/redox-os/netutils.git)" = "" "checksum ntpclient 0.0.1 (git+https://github.com/willem66745/ntpclient-rust)" = "" "checksum num_cpus 1.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "aec53c34f2d0247c5ca5d32cca1478762f301740468ee9ee6dcb7a0dd7a0c584" "checksum percent-encoding 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "de154f638187706bde41d9b4738748933d64e6b37bdbffc0b47a97d16a6ae356" -"checksum rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "022e0636ec2519ddae48154b028864bdce4eaf7d35226ab8e65c611be97b189d" +"checksum rand 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)" = "eb250fd207a4729c976794d03db689c9be1d634ab5a1c9da9492a13d8fecbcdf" "checksum rayon 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a77c51c07654ddd93f6cb543c7a849863b03abc7e82591afda6dc8ad4ac3ac4a" "checksum rayon-core 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7febc28567082c345f10cddc3612c6ea020fc3297a1977d472cf9fdb73e6e493" "checksum redox_event 0.1.0 (git+https://github.com/redox-os/event.git)" = "" -"checksum redox_syscall 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)" = "80dcf663dc552529b9bfc7bdb30ea12e5fa5d3545137d850a91ad410053f68e9" +"checksum redox_syscall 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)" = "ddab7acd8e7bf3e49dfdf78ac1209b992329eb2f66e0bf672ab49c70a76d1d68" "checksum redox_termios 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc495930de8d330f14856cface52561b7d79a072c76e438cf8f34d7233a35fa7" "checksum ring 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1f2a6dc7fc06a05e6de183c5b97058582e9da2de0c136eafe49609769c507724" "checksum rustls 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "17727f4b991294da2c84d75a43c003151ff58072212768800f66c56ee46dca43" From 48eb950401fb078069fbace7927dbe061efa182a Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Wed, 2 Aug 2017 19:52:23 -0600 Subject: [PATCH 016/155] Update Cargo.lock --- Cargo.lock | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 65a5604dc6..0039474212 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5,7 +5,7 @@ dependencies = [ "netutils 0.1.0 (git+https://github.com/redox-os/netutils.git)", "rand 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", "redox_event 0.1.0 (git+https://github.com/redox-os/event.git)", - "redox_syscall 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -141,7 +141,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libc" -version = "0.2.28" +version = "0.2.29" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -182,15 +182,15 @@ dependencies = [ [[package]] name = "netutils" version = "0.1.0" -source = "git+https://github.com/redox-os/netutils.git#f5ccf7232353107e46e3d9308a1631633ee0398a" +source = "git+https://github.com/redox-os/netutils.git#cdc0ebd10322ce0e9885da558a9d89d5c5d8abc4" dependencies = [ "hyper 0.10.12 (registry+https://github.com/rust-lang/crates.io-index)", "hyper-rustls 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.28 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", "ntpclient 0.0.1 (git+https://github.com/willem66745/ntpclient-rust)", "redox_event 0.1.0 (git+https://github.com/redox-os/event.git)", - "redox_syscall 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", - "termion 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", + "termion 1.5.0 (git+https://github.com/redox-os/termion.git?branch=redox_termios)", ] [[package]] @@ -207,7 +207,7 @@ name = "num_cpus" version = "1.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.28 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -220,7 +220,7 @@ name = "rand" version = "0.3.16" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.28 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", "magenta 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -240,7 +240,7 @@ dependencies = [ "coco 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.28 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -250,20 +250,20 @@ name = "redox_event" version = "0.1.0" source = "git+https://github.com/redox-os/event.git#42d552e4765efbfb4ec39ce174900d3f48548a70" dependencies = [ - "redox_syscall 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "redox_syscall" -version = "0.1.28" +version = "0.1.29" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "redox_termios" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "redox_syscall 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -273,7 +273,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "gcc 0.3.51 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.28 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "untrusted 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -304,11 +304,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "termion" version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" +source = "git+https://github.com/redox-os/termion.git?branch=redox_termios#cd455e835842831125df0ca23507384f5ae06c8b" dependencies = [ - "libc 0.2.28 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_termios 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -317,8 +317,8 @@ version = "0.1.38" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.28 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -421,7 +421,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a" "checksum lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3b37545ab726dd833ec6420aaba8231c5b320814b9029ad585555d2a03e94fbf" -"checksum libc 0.2.28 (registry+https://github.com/rust-lang/crates.io-index)" = "bb7b49972ee23d8aa1026c365a5b440ba08e35075f18c459980c7395c221ec48" +"checksum libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)" = "8a014d9226c2cc402676fbe9ea2e15dd5222cd1dd57f576b5b283178c944a264" "checksum log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "880f77541efa6e5cc74e76910c9884d9859683118839d6a1dc3b11e63512565b" "checksum magenta 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4bf0336886480e671965f794bc9b6fce88503563013d1bfb7a502c81fe3ac527" "checksum magenta-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "40d014c7011ac470ae28e2f76a02bfea4a8480f73e701353b49ad7a8d75f4699" @@ -435,13 +435,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum rayon 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a77c51c07654ddd93f6cb543c7a849863b03abc7e82591afda6dc8ad4ac3ac4a" "checksum rayon-core 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7febc28567082c345f10cddc3612c6ea020fc3297a1977d472cf9fdb73e6e493" "checksum redox_event 0.1.0 (git+https://github.com/redox-os/event.git)" = "" -"checksum redox_syscall 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)" = "ddab7acd8e7bf3e49dfdf78ac1209b992329eb2f66e0bf672ab49c70a76d1d68" -"checksum redox_termios 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc495930de8d330f14856cface52561b7d79a072c76e438cf8f34d7233a35fa7" +"checksum redox_syscall 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)" = "3c9309631a35303bffb47e397198e3668cb544fe8834cd3da2a744441e70e524" +"checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" "checksum ring 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1f2a6dc7fc06a05e6de183c5b97058582e9da2de0c136eafe49609769c507724" "checksum rustls 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "17727f4b991294da2c84d75a43c003151ff58072212768800f66c56ee46dca43" "checksum safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e27a8b19b835f7aea908818e871f5cc3a5a186550c30773be987e155e8163d8f" "checksum scopeguard 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c79eb2c3ac4bc2507cda80e7f3ac5b88bd8eae4c0914d5663e6a8933994be918" -"checksum termion 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8affd752d0f2c7127d6d5f1b98182a5471606b48b1a955165d39eb5e4887ceba" +"checksum termion 1.5.0 (git+https://github.com/redox-os/termion.git?branch=redox_termios)" = "" "checksum time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)" = "d5d788d3aa77bc0ef3e9621256885555368b47bd495c13dd2e7413c89f845520" "checksum traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079" "checksum typeable 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1410f6f91f21d1612654e7cc69193b0334f909dcf2c790c4826254fbb86f8887" From e088dca7bd4539ce9d85f8b6974f2b236e0a589a Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Wed, 2 Aug 2017 21:14:39 -0600 Subject: [PATCH 017/155] Update Cargo.lock --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0039474212..e6f28f0b28 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -182,7 +182,7 @@ dependencies = [ [[package]] name = "netutils" version = "0.1.0" -source = "git+https://github.com/redox-os/netutils.git#cdc0ebd10322ce0e9885da558a9d89d5c5d8abc4" +source = "git+https://github.com/redox-os/netutils.git#47c0003ae18d23ff63cebe75e22bdc0bdbc069d7" dependencies = [ "hyper 0.10.12 (registry+https://github.com/rust-lang/crates.io-index)", "hyper-rustls 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -304,7 +304,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "termion" version = "1.5.0" -source = "git+https://github.com/redox-os/termion.git?branch=redox_termios#cd455e835842831125df0ca23507384f5ae06c8b" +source = "git+https://github.com/redox-os/termion.git?branch=redox_termios#18e589b9d92e8f93ae75475389e234bbe5deb109" dependencies = [ "libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", From cce699888aa12286cb16539a5acea212f61d95b2 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sat, 19 Aug 2017 14:46:58 -0600 Subject: [PATCH 018/155] Update Cargo.lock --- Cargo.lock | 63 +++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 51 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e6f28f0b28..0b19915a09 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5,9 +5,14 @@ dependencies = [ "netutils 0.1.0 (git+https://github.com/redox-os/netutils.git)", "rand 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", "redox_event 0.1.0 (git+https://github.com/redox-os/event.git)", - "redox_syscall 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "arg_parser" +version = "0.1.0" +source = "git+https://github.com/redox-os/arg-parser.git#1b6a9505a1e9c39af1836ecbee293a987619a539" + [[package]] name = "base64" version = "0.5.2" @@ -67,6 +72,11 @@ name = "either" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "extra" +version = "0.1.0" +source = "git+https://github.com/redox-os/libextra.git#402932084acd5fef4812945887ceaaa2ddd5f264" + [[package]] name = "futures" version = "0.1.14" @@ -74,7 +84,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "gcc" -version = "0.3.51" +version = "0.3.52" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -182,14 +192,17 @@ dependencies = [ [[package]] name = "netutils" version = "0.1.0" -source = "git+https://github.com/redox-os/netutils.git#47c0003ae18d23ff63cebe75e22bdc0bdbc069d7" +source = "git+https://github.com/redox-os/netutils.git#a09e97dbe67e1e8d194da7c9900e1e5b2111cded" dependencies = [ + "arg_parser 0.1.0 (git+https://github.com/redox-os/arg-parser.git)", + "extra 0.1.0 (git+https://github.com/redox-os/libextra.git)", "hyper 0.10.12 (registry+https://github.com/rust-lang/crates.io-index)", "hyper-rustls 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", "ntpclient 0.0.1 (git+https://github.com/willem66745/ntpclient-rust)", + "pbr 1.0.0 (git+https://github.com/a8m/pb)", "redox_event 0.1.0 (git+https://github.com/redox-os/event.git)", - "redox_syscall 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)", "termion 1.5.0 (git+https://github.com/redox-os/termion.git?branch=redox_termios)", ] @@ -210,6 +223,18 @@ dependencies = [ "libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "pbr" +version = "1.0.0" +source = "git+https://github.com/a8m/pb#e9369ed2b94df4f554fe79c2643de41f7338475f" +dependencies = [ + "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", + "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "percent-encoding" version = "1.0.0" @@ -250,12 +275,12 @@ name = "redox_event" version = "0.1.0" source = "git+https://github.com/redox-os/event.git#42d552e4765efbfb4ec39ce174900d3f48548a70" dependencies = [ - "redox_syscall 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "redox_syscall" -version = "0.1.29" +version = "0.1.30" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -263,7 +288,7 @@ name = "redox_termios" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "redox_syscall 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -271,7 +296,7 @@ name = "ring" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "gcc 0.3.51 (registry+https://github.com/rust-lang/crates.io-index)", + "gcc 0.3.52 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -307,7 +332,17 @@ version = "1.5.0" source = "git+https://github.com/redox-os/termion.git?branch=redox_termios#18e589b9d92e8f93ae75475389e234bbe5deb109" dependencies = [ "libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "termion" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)", "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -318,7 +353,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -403,6 +438,7 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" [metadata] +"checksum arg_parser 0.1.0 (git+https://github.com/redox-os/arg-parser.git)" = "" "checksum base64 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "30e93c03064e7590d0466209155251b90c22e37fab1daf2771582598b5827557" "checksum base64 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "96434f987501f0ed4eb336a411e0631ecd1afa11574fe148587adc4ff96143c9" "checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d" @@ -412,8 +448,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum conv 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "78ff10625fd0ac447827aa30ea8b861fead473bb60aeb73af6c1c58caf0d1299" "checksum custom_derive 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "ef8ae57c4978a2acd8b869ce6b9ca1dfe817bff704c220209fdef2c0b75a01b9" "checksum either 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "18785c1ba806c258137c937e44ada9ee7e69a37e3c72077542cd2f069d78562a" +"checksum extra 0.1.0 (git+https://github.com/redox-os/libextra.git)" = "" "checksum futures 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "4b63a4792d4f8f686defe3b39b92127fea6344de5d38202b2ee5a11bbbf29d6a" -"checksum gcc 0.3.51 (registry+https://github.com/rust-lang/crates.io-index)" = "120d07f202dcc3f72859422563522b66fe6463a4c513df062874daad05f85f0a" +"checksum gcc 0.3.52 (registry+https://github.com/rust-lang/crates.io-index)" = "1b7d19683108136d21d32723077e69cd5df2bfd6d102c74a01d743cf2b65cf97" "checksum httparse 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "af2f2dd97457e8fb1ae7c5a420db346af389926e36f43768b96f101546b04a07" "checksum hyper 0.10.12 (registry+https://github.com/rust-lang/crates.io-index)" = "0f01e4a20f5dfa5278d7762b7bdb7cab96e24378b9eca3889fbd4b5e94dc7063" "checksum hyper-rustls 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "04535774f79684c99528944ebdb89756c945c027e55ce52faa245879d836c8fb" @@ -430,18 +467,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum netutils 0.1.0 (git+https://github.com/redox-os/netutils.git)" = "" "checksum ntpclient 0.0.1 (git+https://github.com/willem66745/ntpclient-rust)" = "" "checksum num_cpus 1.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "aec53c34f2d0247c5ca5d32cca1478762f301740468ee9ee6dcb7a0dd7a0c584" +"checksum pbr 1.0.0 (git+https://github.com/a8m/pb)" = "" "checksum percent-encoding 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "de154f638187706bde41d9b4738748933d64e6b37bdbffc0b47a97d16a6ae356" "checksum rand 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)" = "eb250fd207a4729c976794d03db689c9be1d634ab5a1c9da9492a13d8fecbcdf" "checksum rayon 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a77c51c07654ddd93f6cb543c7a849863b03abc7e82591afda6dc8ad4ac3ac4a" "checksum rayon-core 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7febc28567082c345f10cddc3612c6ea020fc3297a1977d472cf9fdb73e6e493" "checksum redox_event 0.1.0 (git+https://github.com/redox-os/event.git)" = "" -"checksum redox_syscall 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)" = "3c9309631a35303bffb47e397198e3668cb544fe8834cd3da2a744441e70e524" +"checksum redox_syscall 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)" = "8312fba776a49cf390b7b62f3135f9b294d8617f7a7592cfd0ac2492b658cd7b" "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" "checksum ring 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1f2a6dc7fc06a05e6de183c5b97058582e9da2de0c136eafe49609769c507724" "checksum rustls 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "17727f4b991294da2c84d75a43c003151ff58072212768800f66c56ee46dca43" "checksum safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e27a8b19b835f7aea908818e871f5cc3a5a186550c30773be987e155e8163d8f" "checksum scopeguard 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c79eb2c3ac4bc2507cda80e7f3ac5b88bd8eae4c0914d5663e6a8933994be918" "checksum termion 1.5.0 (git+https://github.com/redox-os/termion.git?branch=redox_termios)" = "" +"checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" "checksum time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)" = "d5d788d3aa77bc0ef3e9621256885555368b47bd495c13dd2e7413c89f845520" "checksum traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079" "checksum typeable 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1410f6f91f21d1612654e7cc69193b0334f909dcf2c790c4826254fbb86f8887" From 4d6bf893973fec64b123690ea80be251dfe7a1ac Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Mon, 21 Aug 2017 19:00:54 -0600 Subject: [PATCH 019/155] Add debug messages, update lock file --- Cargo.lock | 21 +++++---------------- src/ethernetd/main.rs | 2 ++ src/icmpd/main.rs | 2 ++ src/ipd/main.rs | 2 ++ src/tcpd/main.rs | 2 ++ src/udpd/main.rs | 2 ++ 6 files changed, 15 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0b19915a09..1c9ca4a0da 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -84,7 +84,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "gcc" -version = "0.3.52" +version = "0.3.53" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -192,7 +192,7 @@ dependencies = [ [[package]] name = "netutils" version = "0.1.0" -source = "git+https://github.com/redox-os/netutils.git#a09e97dbe67e1e8d194da7c9900e1e5b2111cded" +source = "git+https://github.com/redox-os/netutils.git#849b72c5b9e77a654a51521276dc6f2223a67aec" dependencies = [ "arg_parser 0.1.0 (git+https://github.com/redox-os/arg-parser.git)", "extra 0.1.0 (git+https://github.com/redox-os/libextra.git)", @@ -203,7 +203,7 @@ dependencies = [ "pbr 1.0.0 (git+https://github.com/a8m/pb)", "redox_event 0.1.0 (git+https://github.com/redox-os/event.git)", "redox_syscall 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)", - "termion 1.5.0 (git+https://github.com/redox-os/termion.git?branch=redox_termios)", + "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -296,7 +296,7 @@ name = "ring" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "gcc 0.3.52 (registry+https://github.com/rust-lang/crates.io-index)", + "gcc 0.3.53 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -326,16 +326,6 @@ name = "scopeguard" version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "termion" -version = "1.5.0" -source = "git+https://github.com/redox-os/termion.git?branch=redox_termios#18e589b9d92e8f93ae75475389e234bbe5deb109" -dependencies = [ - "libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "termion" version = "1.5.1" @@ -450,7 +440,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum either 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "18785c1ba806c258137c937e44ada9ee7e69a37e3c72077542cd2f069d78562a" "checksum extra 0.1.0 (git+https://github.com/redox-os/libextra.git)" = "" "checksum futures 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "4b63a4792d4f8f686defe3b39b92127fea6344de5d38202b2ee5a11bbbf29d6a" -"checksum gcc 0.3.52 (registry+https://github.com/rust-lang/crates.io-index)" = "1b7d19683108136d21d32723077e69cd5df2bfd6d102c74a01d743cf2b65cf97" +"checksum gcc 0.3.53 (registry+https://github.com/rust-lang/crates.io-index)" = "e8310f7e9c890398b0e80e301c4f474e9918d2b27fca8f48486ca775fa9ffc5a" "checksum httparse 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "af2f2dd97457e8fb1ae7c5a420db346af389926e36f43768b96f101546b04a07" "checksum hyper 0.10.12 (registry+https://github.com/rust-lang/crates.io-index)" = "0f01e4a20f5dfa5278d7762b7bdb7cab96e24378b9eca3889fbd4b5e94dc7063" "checksum hyper-rustls 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "04535774f79684c99528944ebdb89756c945c027e55ce52faa245879d836c8fb" @@ -479,7 +469,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum rustls 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "17727f4b991294da2c84d75a43c003151ff58072212768800f66c56ee46dca43" "checksum safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e27a8b19b835f7aea908818e871f5cc3a5a186550c30773be987e155e8163d8f" "checksum scopeguard 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c79eb2c3ac4bc2507cda80e7f3ac5b88bd8eae4c0914d5663e6a8933994be918" -"checksum termion 1.5.0 (git+https://github.com/redox-os/termion.git?branch=redox_termios)" = "" "checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" "checksum time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)" = "d5d788d3aa77bc0ef3e9621256885555368b47bd495c13dd2e7413c89f845520" "checksum traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079" diff --git a/src/ethernetd/main.rs b/src/ethernetd/main.rs index 7185435937..f29f21b197 100644 --- a/src/ethernetd/main.rs +++ b/src/ethernetd/main.rs @@ -87,10 +87,12 @@ fn daemon(network_fd: usize, socket_fd: usize) { } fn main() { + println!("ethernetd: opening network:"); match syscall::open("network:", syscall::O_RDWR | syscall::O_NONBLOCK) { Ok(network_fd) => { // Daemonize if unsafe { syscall::clone(0).unwrap() } == 0 { + println!("ethernetd: providing ethernet:"); match syscall::open(":ethernet", syscall::O_RDWR | syscall::O_CREAT | syscall::O_NONBLOCK) { Ok(socket_fd) => { daemon(network_fd, socket_fd); diff --git a/src/icmpd/main.rs b/src/icmpd/main.rs index 4284ae5d87..25026b656c 100644 --- a/src/icmpd/main.rs +++ b/src/icmpd/main.rs @@ -22,10 +22,12 @@ fn run() -> Result<()> { return Ok(()); } + println!("icmpd: opening ip:1:"); let icmp_fd = syscall::open("ip:1", O_RDWR | O_NONBLOCK) .map_err(|e| Error::from_syscall_error(e, "failed to open ip:1"))? as RawFd; + println!("icmpd: prividing icmp:"); let scheme_fd = syscall::open(":icmp", O_RDWR | O_CREAT | O_NONBLOCK) .map_err(|e| Error::from_syscall_error(e, "failed to open :icmp"))? as RawFd; diff --git a/src/ipd/main.rs b/src/ipd/main.rs index c5ce140634..3c5693feb6 100644 --- a/src/ipd/main.rs +++ b/src/ipd/main.rs @@ -316,11 +316,13 @@ fn daemon(arp_fd: usize, ip_fd: usize, scheme_fd: usize) { } fn main() { + println!("ipd: opening ethernet:806"); match syscall::open("ethernet:806", syscall::O_RDWR | syscall::O_NONBLOCK) { Ok(arp_fd) => match syscall::open("ethernet:800", syscall::O_RDWR | syscall::O_NONBLOCK) { Ok(ip_fd) => { // Daemonize if unsafe { syscall::clone(0).unwrap() } == 0 { + println!("ipd: providing ip:"); match syscall::open(":ip", syscall::O_RDWR | syscall::O_CREAT | syscall::O_NONBLOCK) { Ok(scheme_fd) => { daemon(arp_fd, ip_fd, scheme_fd); diff --git a/src/tcpd/main.rs b/src/tcpd/main.rs index 1c3a881ccc..ae1c56d593 100644 --- a/src/tcpd/main.rs +++ b/src/tcpd/main.rs @@ -910,10 +910,12 @@ fn main() { let time_path = format!("time:{}", CLOCK_MONOTONIC); match syscall::open(&time_path, O_RDWR) { Ok(time_fd) => { + println!("tcpd: opening ip:6"); match syscall::open("ip:6", O_RDWR | O_NONBLOCK) { Ok(tcp_fd) => { // Daemonize if unsafe { syscall::clone(0).unwrap() } == 0 { + println!("tcpd: providing tcp:"); match syscall::open(":tcp", O_RDWR | O_CREAT | O_NONBLOCK) { Ok(scheme_fd) => { daemon(scheme_fd, tcp_fd, time_fd); diff --git a/src/udpd/main.rs b/src/udpd/main.rs index 23d6479af7..43d511d625 100644 --- a/src/udpd/main.rs +++ b/src/udpd/main.rs @@ -557,10 +557,12 @@ fn main() { let time_path = format!("time:{}", CLOCK_MONOTONIC); match syscall::open(&time_path, O_RDWR) { Ok(time_fd) => { + println!("udpd: opening ip:11"); match syscall::open("ip:11", O_RDWR | O_NONBLOCK) { Ok(udp_fd) => { // Daemonize if unsafe { syscall::clone(0).unwrap() } == 0 { + println!("udpd: providing udp:"); match syscall::open(":udp", O_RDWR | O_CREAT | O_NONBLOCK) { Ok(scheme_fd) => { daemon(scheme_fd, udp_fd, time_fd); From 5f70470c5c668c83ddd4d63b1ee87bae5647a038 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sat, 16 Sep 2017 11:59:08 -0600 Subject: [PATCH 020/155] Send events on connect --- src/tcpd/main.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/tcpd/main.rs b/src/tcpd/main.rs index ae1c56d593..f95011fa5a 100644 --- a/src/tcpd/main.rs +++ b/src/tcpd/main.rs @@ -383,7 +383,7 @@ impl Tcpd { if ! found_connection && tcp.header.flags.get() & (TCP_SYN | TCP_ACK) == TCP_SYN { let mut new_handles = Vec::new(); - for (_id, handle) in self.handles.iter_mut() { + for (id, handle) in self.handles.iter_mut() { if let Handle::Tcp(ref mut handle) = *handle { if handle.state == State::Listen && handle.matches(&ip, &tcp) { handle.data.push_back((ip.clone(), tcp.clone())); @@ -435,6 +435,21 @@ impl Tcpd { new_handles.push((packet, Handle::Tcp(new_handle))); } } + + if handle.events & EVENT_READ == EVENT_READ { + if let Some(&(ref _ip, ref tcp)) = handle.data.get(0) { + self.scheme_file.write(&Packet { + id: 0, + pid: 0, + uid: 0, + gid: 0, + a: syscall::number::SYS_FEVENT, + b: *id, + c: EVENT_READ, + d: tcp.data.len() + })?; + } + } } } From 47179f97019ee36c9fb785ad01fe0dd351065691 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sun, 17 Sep 2017 16:37:52 -0600 Subject: [PATCH 021/155] Update dependencies, better implementation of C socket --- Cargo.lock | 83 +++++++--------- src/ipd/main.rs | 3 +- src/tcpd/main.rs | 246 ++++++++++++++++++++++++++--------------------- 3 files changed, 175 insertions(+), 157 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1c9ca4a0da..80b91d1fe1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5,21 +5,13 @@ dependencies = [ "netutils 0.1.0 (git+https://github.com/redox-os/netutils.git)", "rand 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", "redox_event 0.1.0 (git+https://github.com/redox-os/event.git)", - "redox_syscall 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "arg_parser" version = "0.1.0" -source = "git+https://github.com/redox-os/arg-parser.git#1b6a9505a1e9c39af1836ecbee293a987619a539" - -[[package]] -name = "base64" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", -] +source = "git+https://github.com/redox-os/arg-parser.git#288d2fd9ae27ed2c7a3aaf5a77cf07e2b2bd356c" [[package]] name = "base64" @@ -79,12 +71,12 @@ source = "git+https://github.com/redox-os/libextra.git#402932084acd5fef481294588 [[package]] name = "futures" -version = "0.1.14" +version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "gcc" -version = "0.3.53" +version = "0.3.54" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -94,10 +86,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "hyper" -version = "0.10.12" +version = "0.10.13" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "base64 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "base64 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "httparse 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -115,7 +107,7 @@ name = "hyper-rustls" version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "hyper 0.10.12 (registry+https://github.com/rust-lang/crates.io-index)", + "hyper 0.10.13 (registry+https://github.com/rust-lang/crates.io-index)", "rustls 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "webpki-roots 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -151,7 +143,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libc" -version = "0.2.29" +version = "0.2.30" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -192,17 +184,17 @@ dependencies = [ [[package]] name = "netutils" version = "0.1.0" -source = "git+https://github.com/redox-os/netutils.git#849b72c5b9e77a654a51521276dc6f2223a67aec" +source = "git+https://github.com/redox-os/netutils.git#ec1a835a9d4a95a8e41c4e994a540d298d897cd4" dependencies = [ "arg_parser 0.1.0 (git+https://github.com/redox-os/arg-parser.git)", "extra 0.1.0 (git+https://github.com/redox-os/libextra.git)", - "hyper 0.10.12 (registry+https://github.com/rust-lang/crates.io-index)", + "hyper 0.10.13 (registry+https://github.com/rust-lang/crates.io-index)", "hyper-rustls 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", "ntpclient 0.0.1 (git+https://github.com/willem66745/ntpclient-rust)", "pbr 1.0.0 (git+https://github.com/a8m/pb)", "redox_event 0.1.0 (git+https://github.com/redox-os/event.git)", - "redox_syscall 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -220,7 +212,7 @@ name = "num_cpus" version = "1.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -229,7 +221,7 @@ version = "1.0.0" source = "git+https://github.com/a8m/pb#e9369ed2b94df4f554fe79c2643de41f7338475f" dependencies = [ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -245,7 +237,7 @@ name = "rand" version = "0.3.16" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", "magenta 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -263,9 +255,9 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "coco 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -275,12 +267,12 @@ name = "redox_event" version = "0.1.0" source = "git+https://github.com/redox-os/event.git#42d552e4765efbfb4ec39ce174900d3f48548a70" dependencies = [ - "redox_syscall 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "redox_syscall" -version = "0.1.30" +version = "0.1.31" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -288,7 +280,7 @@ name = "redox_termios" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "redox_syscall 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -296,11 +288,11 @@ name = "ring" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "gcc 0.3.53 (registry+https://github.com/rust-lang/crates.io-index)", + "gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "untrusted 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -312,7 +304,7 @@ dependencies = [ "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "ring 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)", - "untrusted 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "webpki 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -331,8 +323,8 @@ name = "termion" version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -342,8 +334,8 @@ version = "0.1.38" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -380,7 +372,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "untrusted" -version = "0.5.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -405,7 +397,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "ring 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)", - "untrusted 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -413,7 +405,7 @@ name = "webpki-roots" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "untrusted 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "webpki 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -429,7 +421,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [metadata] "checksum arg_parser 0.1.0 (git+https://github.com/redox-os/arg-parser.git)" = "" -"checksum base64 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "30e93c03064e7590d0466209155251b90c22e37fab1daf2771582598b5827557" "checksum base64 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "96434f987501f0ed4eb336a411e0631ecd1afa11574fe148587adc4ff96143c9" "checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d" "checksum byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855" @@ -439,16 +430,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum custom_derive 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "ef8ae57c4978a2acd8b869ce6b9ca1dfe817bff704c220209fdef2c0b75a01b9" "checksum either 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "18785c1ba806c258137c937e44ada9ee7e69a37e3c72077542cd2f069d78562a" "checksum extra 0.1.0 (git+https://github.com/redox-os/libextra.git)" = "" -"checksum futures 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "4b63a4792d4f8f686defe3b39b92127fea6344de5d38202b2ee5a11bbbf29d6a" -"checksum gcc 0.3.53 (registry+https://github.com/rust-lang/crates.io-index)" = "e8310f7e9c890398b0e80e301c4f474e9918d2b27fca8f48486ca775fa9ffc5a" +"checksum futures 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "05a23db7bd162d4e8265968602930c476f688f0c180b44bdaf55e0cb2c687558" +"checksum gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)" = "5e33ec290da0d127825013597dbdfc28bee4964690c7ce1166cbc2a7bd08b1bb" "checksum httparse 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "af2f2dd97457e8fb1ae7c5a420db346af389926e36f43768b96f101546b04a07" -"checksum hyper 0.10.12 (registry+https://github.com/rust-lang/crates.io-index)" = "0f01e4a20f5dfa5278d7762b7bdb7cab96e24378b9eca3889fbd4b5e94dc7063" +"checksum hyper 0.10.13 (registry+https://github.com/rust-lang/crates.io-index)" = "368cb56b2740ebf4230520e2b90ebb0461e69034d85d1945febd9b3971426db2" "checksum hyper-rustls 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "04535774f79684c99528944ebdb89756c945c027e55ce52faa245879d836c8fb" "checksum idna 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "014b298351066f1512874135335d62a789ffe78a9974f94b43ed5621951eaf7d" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a" "checksum lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3b37545ab726dd833ec6420aaba8231c5b320814b9029ad585555d2a03e94fbf" -"checksum libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)" = "8a014d9226c2cc402676fbe9ea2e15dd5222cd1dd57f576b5b283178c944a264" +"checksum libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)" = "2370ca07ec338939e356443dac2296f581453c35fe1e3a3ed06023c49435f915" "checksum log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "880f77541efa6e5cc74e76910c9884d9859683118839d6a1dc3b11e63512565b" "checksum magenta 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4bf0336886480e671965f794bc9b6fce88503563013d1bfb7a502c81fe3ac527" "checksum magenta-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "40d014c7011ac470ae28e2f76a02bfea4a8480f73e701353b49ad7a8d75f4699" @@ -463,7 +454,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum rayon 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a77c51c07654ddd93f6cb543c7a849863b03abc7e82591afda6dc8ad4ac3ac4a" "checksum rayon-core 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7febc28567082c345f10cddc3612c6ea020fc3297a1977d472cf9fdb73e6e493" "checksum redox_event 0.1.0 (git+https://github.com/redox-os/event.git)" = "" -"checksum redox_syscall 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)" = "8312fba776a49cf390b7b62f3135f9b294d8617f7a7592cfd0ac2492b658cd7b" +"checksum redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)" = "8dde11f18c108289bef24469638a04dce49da56084f2d50618b226e47eb04509" "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" "checksum ring 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1f2a6dc7fc06a05e6de183c5b97058582e9da2de0c136eafe49609769c507724" "checksum rustls 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "17727f4b991294da2c84d75a43c003151ff58072212768800f66c56ee46dca43" @@ -476,7 +467,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum unicase 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7f4765f83163b74f957c797ad9253caf97f103fb064d3999aea9568d09fc8a33" "checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" "checksum unicode-normalization 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "51ccda9ef9efa3f7ef5d91e8f9b83bbe6955f9bf86aec89d5cce2c874625920f" -"checksum untrusted 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6b65243989ef6aacd9c0d6bd2b822765c3361d8ed352185a6f3a41f3a718c673" +"checksum untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f392d7819dbe58833e26872f5f6f0d68b7bbbe90fc3667e98731c4a15ad9a7ae" "checksum url 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "eeb819346883532a271eb626deb43c4a1bb4c4dd47c519bd78137c3e72a4fe27" "checksum version_check 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6b772017e347561807c1aa192438c5fd74242a670a6cffacc40f2defd1dc069d" "checksum webpki 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e499345fc4c6b7c79a5b8756d4592c4305510a13512e79efafe00dfbd67bbac6" diff --git a/src/ipd/main.rs b/src/ipd/main.rs index 3c5693feb6..b95b38c955 100644 --- a/src/ipd/main.rs +++ b/src/ipd/main.rs @@ -3,7 +3,8 @@ extern crate netutils; extern crate syscall; use event::EventQueue; -use netutils::{Ipv4Addr, Ipv4, Tcp}; +use netutils::{Ipv4Addr, Ipv4}; +use netutils::tcp::Tcp; use std::cell::RefCell; use std::collections::{BTreeMap, VecDeque}; use std::fs::File; diff --git a/src/tcpd/main.rs b/src/tcpd/main.rs index f95011fa5a..a3245070d5 100644 --- a/src/tcpd/main.rs +++ b/src/tcpd/main.rs @@ -14,7 +14,8 @@ use std::os::unix::io::FromRawFd; use std::rc::Rc; use event::EventQueue; -use netutils::{n16, n32, Ipv4, Ipv4Addr, Ipv4Header, Tcp, TcpHeader, Checksum, TCP_FIN, TCP_SYN, TCP_RST, TCP_PSH, TCP_ACK}; +use netutils::{n16, n32, Ipv4, Ipv4Addr, Ipv4Header, Checksum}; +use netutils::tcp::{Tcp, TcpHeader, TCP_FIN, TCP_SYN, TCP_RST, TCP_PSH, TCP_ACK}; use syscall::data::{Packet, TimeSpec}; use syscall::error::{Error, Result, EACCES, EADDRINUSE, EBADF, EIO, EINVAL, EISCONN, EMSGSIZE, ENOTCONN, ETIMEDOUT, EWOULDBLOCK}; use syscall::flag::{CLOCK_MONOTONIC, EVENT_READ, F_GETFL, F_SETFL, O_ACCMODE, O_CREAT, O_RDWR, O_NONBLOCK}; @@ -42,6 +43,12 @@ fn parse_socket(socket: &str) -> (Ipv4Addr, u16) { (host, port) } +#[derive(Debug)] +struct EmptyHandle { + privileged: bool, + flags: usize +} + #[derive(Copy, Clone, Debug, Eq, PartialEq)] enum State { Listen, @@ -57,6 +64,7 @@ enum State { Closed } +#[derive(Debug)] struct TcpHandle { local: (Ipv4Addr, u16), remote: (Ipv4Addr, u16), @@ -131,14 +139,16 @@ impl TcpHandle { } } -#[derive(Copy, Clone)] +#[derive(Copy, Clone, Debug)] enum SettingKind { Ttl, ReadTimeout, WriteTimeout } +#[derive(Debug)] enum Handle { + Empty(EmptyHandle), Tcp(TcpHandle), Setting(usize, SettingKind), } @@ -434,20 +444,20 @@ impl Tcpd { new_handles.push((packet, Handle::Tcp(new_handle))); } - } - if handle.events & EVENT_READ == EVENT_READ { - if let Some(&(ref _ip, ref tcp)) = handle.data.get(0) { - self.scheme_file.write(&Packet { - id: 0, - pid: 0, - uid: 0, - gid: 0, - a: syscall::number::SYS_FEVENT, - b: *id, - c: EVENT_READ, - d: tcp.data.len() - })?; + if handle.events & EVENT_READ == EVENT_READ { + if let Some(&(ref _ip, ref tcp)) = handle.data.get(0) { + self.scheme_file.write(&Packet { + id: 0, + pid: 0, + uid: 0, + gid: 0, + a: syscall::number::SYS_FEVENT, + b: *id, + c: EVENT_READ, + d: tcp.data.len() + })?; + } } } } @@ -507,69 +517,66 @@ impl Tcpd { Ok(()) } -} -impl SchemeMut for Tcpd { - fn open(&mut self, url: &[u8], flags: usize, uid: u32, _gid: u32) -> Result { - let path = str::from_utf8(url).or(Err(Error::new(EINVAL)))?; + fn inner_dup(&mut self, file: usize, path: &str) -> Result { + Ok(match *self.handles.get_mut(&file).ok_or(Error::new(EBADF))? { + Handle::Empty(ref handle) => { + if path.is_empty() { + Handle::Empty(EmptyHandle { + privileged: handle.privileged, + flags: handle.flags + }) + } else { + let mut parts = path.split("/"); + let remote = parse_socket(parts.next().unwrap_or("")); + let mut local = parse_socket(parts.next().unwrap_or("")); - let mut parts = path.split("/"); - let remote = parse_socket(parts.next().unwrap_or("")); - let mut local = parse_socket(parts.next().unwrap_or("")); + if local.1 == 0 { + local.1 = self.rng.gen_range(32768, 65535); + } - if local.1 == 0 { - local.1 = self.rng.gen_range(32768, 65535); - } + if local.1 <= 1024 && ! handle.privileged { + return Err(Error::new(EACCES)); + } - if local.1 <= 1024 && uid != 0 { - return Err(Error::new(EACCES)); - } + if self.ports.contains_key(&local.1) { + return Err(Error::new(EADDRINUSE)); + } - if self.ports.contains_key(&local.1) { - return Err(Error::new(EADDRINUSE)); - } + let mut new_handle = TcpHandle { + local: local, + remote: remote, + flags: handle.flags, + events: 0, + read_timeout: None, + write_timeout: None, + ttl: 64, + state: State::Listen, + seq: 0, + ack: 0, + data: VecDeque::new(), + todo_dup: VecDeque::new(), + todo_read: VecDeque::new(), + todo_write: VecDeque::new(), + }; - let mut handle = TcpHandle { - local: local, - remote: remote, - flags: flags, - events: 0, - read_timeout: None, - write_timeout: None, - ttl: 64, - state: State::Listen, - seq: 0, - ack: 0, - data: VecDeque::new(), - todo_dup: VecDeque::new(), - todo_read: VecDeque::new(), - todo_write: VecDeque::new(), - }; + if new_handle.is_connected() { + new_handle.seq = self.rng.gen(); + new_handle.ack = 0; + new_handle.state = State::SynSent; - if handle.is_connected() { - handle.seq = self.rng.gen(); - handle.ack = 0; - handle.state = State::SynSent; + let tcp = new_handle.create_tcp(TCP_SYN, Vec::new()); + let ip = new_handle.create_ip(self.rng.gen(), tcp.to_bytes()); + self.tcp_file.write(&ip.to_bytes()).map_err(|err| Error::new(err.raw_os_error().unwrap_or(EIO)))?; - let tcp = handle.create_tcp(TCP_SYN, Vec::new()); - let ip = handle.create_ip(self.rng.gen(), tcp.to_bytes()); - self.tcp_file.write(&ip.to_bytes()).map_err(|err| Error::new(err.raw_os_error().unwrap_or(EIO)))?; + new_handle.seq += 1; + } - handle.seq += 1; - } + self.ports.insert(new_handle.local.1, 1); - self.ports.insert(local.1, 1); - - let id = self.next_id; - self.next_id += 1; - - self.handles.insert(id, Handle::Tcp(handle)); - - Ok(id) - } - - fn dup(&mut self, file: usize, buf: &[u8]) -> Result { - let handle = match *self.handles.get_mut(&file).ok_or(Error::new(EBADF))? { + Handle::Tcp(new_handle) + } + }, Handle::Tcp(ref mut handle) => { let mut new_handle = TcpHandle { local: handle.local, @@ -588,8 +595,6 @@ impl SchemeMut for Tcpd { todo_write: VecDeque::new(), }; - let path = str::from_utf8(buf).or(Err(Error::new(EINVAL)))?; - if path == "ttl" { Handle::Setting(file, SettingKind::Ttl) } else if path == "read_timeout" { @@ -608,7 +613,7 @@ impl SchemeMut for Tcpd { let tcp = new_handle.create_tcp(TCP_SYN | TCP_ACK, Vec::new()); let ip = new_handle.create_ip(self.rng.gen(), tcp.to_bytes()); - self.tcp_file.write(&ip.to_bytes()).map_err(|err| Error::new(err.raw_os_error().unwrap_or(EIO))).and(Ok(buf.len()))?; + self.tcp_file.write(&ip.to_bytes()).map_err(|err| Error::new(err.raw_os_error().unwrap_or(EIO)))?; new_handle.seq += 1; } else { @@ -628,41 +633,45 @@ impl SchemeMut for Tcpd { new_handle.data = handle.data.clone(); Handle::Tcp(new_handle) - } else if handle.is_connected() { - return Err(Error::new(EISCONN)); } else { - new_handle.remote = parse_socket(path); - - if new_handle.is_connected() { - new_handle.seq = self.rng.gen(); - new_handle.ack = 0; - new_handle.state = State::SynSent; - - handle.data.retain(|&(ref ip, ref tcp)| { - if new_handle.matches(ip, tcp) { - new_handle.data.push_back((ip.clone(), tcp.clone())); - false - } else { - true - } - }); - - let tcp = new_handle.create_tcp(TCP_SYN, Vec::new()); - let ip = new_handle.create_ip(self.rng.gen(), tcp.to_bytes()); - self.tcp_file.write(&ip.to_bytes()).map_err(|err| Error::new(err.raw_os_error().unwrap_or(EIO))).and(Ok(buf.len()))?; - - new_handle.seq += 1; - - Handle::Tcp(new_handle) - } else { - return Err(Error::new(EINVAL)); - } + return Err(Error::new(EINVAL)); } }, Handle::Setting(file, kind) => { Handle::Setting(file, kind) } - }; + }) + } +} + +impl SchemeMut for Tcpd { + fn open(&mut self, url: &[u8], flags: usize, uid: u32, _gid: u32) -> Result { + let path = str::from_utf8(url).or(Err(Error::new(EINVAL)))?; + + let id = self.next_id; + self.next_id += 1; + + self.handles.insert(id, Handle::Empty(EmptyHandle { + privileged: uid == 0, + flags: flags + })); + + match self.inner_dup(id, path) { + Ok(handle) => { + self.handles.insert(id, handle); + Ok(id) + }, + Err(err) => { + self.handles.remove(&id); + Err(err) + } + } + } + + fn dup(&mut self, file: usize, buf: &[u8]) -> Result { + let path = str::from_utf8(buf).or(Err(Error::new(EINVAL)))?; + + let handle = self.inner_dup(file, path)?; let id = self.next_id; self.next_id += 1; @@ -674,6 +683,9 @@ impl SchemeMut for Tcpd { fn read(&mut self, file: usize, buf: &mut [u8]) -> Result { let (file, kind) = match *self.handles.get_mut(&file).ok_or(Error::new(EBADF))? { + Handle::Empty(ref _handle) => { + return Err(Error::new(EBADF)); + }, Handle::Tcp(ref mut handle) => { if ! handle.is_connected() { return Err(Error::new(ENOTCONN)); @@ -730,6 +742,9 @@ impl SchemeMut for Tcpd { fn write(&mut self, file: usize, buf: &[u8]) -> Result { let (file, kind) = match *self.handles.get_mut(&file).ok_or(Error::new(EBADF))? { + Handle::Empty(ref _handle) => { + return Err(Error::new(EBADF)); + }, Handle::Tcp(ref mut handle) => { if ! handle.is_connected() { return Err(Error::new(ENOTCONN)); @@ -790,17 +805,28 @@ impl SchemeMut for Tcpd { } fn fcntl(&mut self, file: usize, cmd: usize, arg: usize) -> Result { - if let Handle::Tcp(ref mut handle) = *self.handles.get_mut(&file).ok_or(Error::new(EBADF))? { - match cmd { - F_GETFL => Ok(handle.flags), - F_SETFL => { - handle.flags = arg & ! O_ACCMODE; - Ok(0) - }, - _ => Err(Error::new(EINVAL)) + match *self.handles.get_mut(&file).ok_or(Error::new(EBADF))? { + Handle::Empty(ref mut handle) => { + match cmd { + F_GETFL => Ok(handle.flags), + F_SETFL => { + handle.flags = arg & ! O_ACCMODE; + Ok(0) + }, + _ => Err(Error::new(EINVAL)) + } + }, + Handle::Tcp(ref mut handle) => { + match cmd { + F_GETFL => Ok(handle.flags), + F_SETFL => { + handle.flags = arg & ! O_ACCMODE; + Ok(0) + }, + _ => Err(Error::new(EINVAL)) + } } - } else { - Err(Error::new(EBADF)) + _ => Err(Error::new(EBADF)) } } From 091d7472a6ff5e98608edf1d9265e684b322c8e4 Mon Sep 17 00:00:00 2001 From: Egor Karavaev Date: Thu, 7 Sep 2017 23:23:40 +0300 Subject: [PATCH 022/155] Replace usize with RawFd where it makes sense. --- src/ethernetd/main.rs | 6 +++--- src/ethernetd/scheme.rs | 2 +- src/ipd/interface/ethernet.rs | 4 ++-- src/ipd/main.rs | 6 +++--- src/tcpd/main.rs | 6 +++--- src/udpd/main.rs | 6 +++--- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/ethernetd/main.rs b/src/ethernetd/main.rs index f29f21b197..c6e6efa008 100644 --- a/src/ethernetd/main.rs +++ b/src/ethernetd/main.rs @@ -6,7 +6,7 @@ use event::EventQueue; use std::cell::RefCell; use std::fs::File; use std::io::{Result, Read, Write}; -use std::os::unix::io::FromRawFd; +use std::os::unix::io::{RawFd, FromRawFd}; use std::process; use std::rc::Rc; @@ -16,7 +16,7 @@ use scheme::EthernetScheme; mod scheme; -fn daemon(network_fd: usize, socket_fd: usize) { +fn daemon(network_fd: RawFd, socket_fd: RawFd) { let network = unsafe { File::from_raw_fd(network_fd) }; let socket = Rc::new(RefCell::new(unsafe { File::from_raw_fd(socket_fd) })); let scheme = Rc::new(RefCell::new(EthernetScheme::new(network))); @@ -95,7 +95,7 @@ fn main() { println!("ethernetd: providing ethernet:"); match syscall::open(":ethernet", syscall::O_RDWR | syscall::O_CREAT | syscall::O_NONBLOCK) { Ok(socket_fd) => { - daemon(network_fd, socket_fd); + daemon(network_fd as RawFd, socket_fd as RawFd); }, Err(err) => { println!("ethernetd: failed to create ethernet scheme: {}", err); diff --git a/src/ethernetd/scheme.rs b/src/ethernetd/scheme.rs index f6da2aa7a3..1286d9e5e4 100644 --- a/src/ethernetd/scheme.rs +++ b/src/ethernetd/scheme.rs @@ -156,7 +156,7 @@ impl SchemeMut for EthernetScheme { fn fsync(&mut self, id: usize) -> Result { let _handle = self.handles.get(&id).ok_or(Error::new(EBADF))?; - syscall::fsync(self.network.as_raw_fd()) + syscall::fsync(self.network.as_raw_fd() as usize) } fn close(&mut self, id: usize) -> Result { diff --git a/src/ipd/interface/ethernet.rs b/src/ipd/interface/ethernet.rs index 4898c36fc6..28e561bc66 100644 --- a/src/ipd/interface/ethernet.rs +++ b/src/ipd/interface/ethernet.rs @@ -2,7 +2,7 @@ use netutils::{getcfg, n16, Ipv4Addr, MacAddr, Ipv4, EthernetII, EthernetIIHeade use std::collections::BTreeMap; use std::fs::File; use std::io::{Result, Read, Write}; -use std::os::unix::io::FromRawFd; +use std::os::unix::io::{RawFd, FromRawFd}; use interface::Interface; @@ -18,7 +18,7 @@ pub struct EthernetInterface { } impl EthernetInterface { - pub fn new(arp_fd: usize, ip_fd: usize) -> Self { + pub fn new(arp_fd: RawFd, ip_fd: RawFd) -> Self { EthernetInterface { mac: MacAddr::from_str(&getcfg("mac").unwrap().trim()), ip: Ipv4Addr::from_str(&getcfg("ip").unwrap().trim()), diff --git a/src/ipd/main.rs b/src/ipd/main.rs index b95b38c955..43b3909338 100644 --- a/src/ipd/main.rs +++ b/src/ipd/main.rs @@ -9,7 +9,7 @@ use std::cell::RefCell; use std::collections::{BTreeMap, VecDeque}; use std::fs::File; use std::io::{self, Read, Write}; -use std::os::unix::io::FromRawFd; +use std::os::unix::io::{RawFd, FromRawFd}; use std::{process, slice, str}; use std::rc::Rc; use syscall::data::Packet; @@ -260,7 +260,7 @@ impl SchemeMut for Ipd { } } -fn daemon(arp_fd: usize, ip_fd: usize, scheme_fd: usize) { +fn daemon(arp_fd: RawFd, ip_fd: RawFd, scheme_fd: RawFd) { let scheme_file = unsafe { File::from_raw_fd(scheme_fd) }; let ipd = Rc::new(RefCell::new(Ipd::new(scheme_file))); @@ -326,7 +326,7 @@ fn main() { println!("ipd: providing ip:"); match syscall::open(":ip", syscall::O_RDWR | syscall::O_CREAT | syscall::O_NONBLOCK) { Ok(scheme_fd) => { - daemon(arp_fd, ip_fd, scheme_fd); + daemon(arp_fd as RawFd, ip_fd as RawFd, scheme_fd as RawFd); }, Err(err) => { println!("ipd: failed to create ip scheme: {}", err); diff --git a/src/tcpd/main.rs b/src/tcpd/main.rs index a3245070d5..fb11257778 100644 --- a/src/tcpd/main.rs +++ b/src/tcpd/main.rs @@ -10,7 +10,7 @@ use std::fs::File; use std::io::{self, Read, Write}; use std::{mem, process, slice, str}; use std::ops::{Deref, DerefMut}; -use std::os::unix::io::FromRawFd; +use std::os::unix::io::{RawFd, FromRawFd}; use std::rc::Rc; use event::EventQueue; @@ -916,7 +916,7 @@ impl SchemeMut for Tcpd { } } -fn daemon(scheme_fd: usize, tcp_fd: usize, time_fd: usize) { +fn daemon(scheme_fd: RawFd, tcp_fd: RawFd, time_fd: RawFd) { let scheme_file = unsafe { File::from_raw_fd(scheme_fd) }; let tcp_file = unsafe { File::from_raw_fd(tcp_fd) }; let time_file = unsafe { File::from_raw_fd(time_fd) }; @@ -959,7 +959,7 @@ fn main() { println!("tcpd: providing tcp:"); match syscall::open(":tcp", O_RDWR | O_CREAT | O_NONBLOCK) { Ok(scheme_fd) => { - daemon(scheme_fd, tcp_fd, time_fd); + daemon(scheme_fd as RawFd, tcp_fd as RawFd, time_fd as RawFd); }, Err(err) => { println!("tcpd: failed to create tcp scheme: {}", err); diff --git a/src/udpd/main.rs b/src/udpd/main.rs index 43d511d625..cfcf4d94d0 100644 --- a/src/udpd/main.rs +++ b/src/udpd/main.rs @@ -10,7 +10,7 @@ use std::fs::File; use std::io::{self, Read, Write}; use std::{mem, process, slice, str}; use std::ops::{Deref, DerefMut}; -use std::os::unix::io::FromRawFd; +use std::os::unix::io::{RawFd, FromRawFd}; use std::rc::Rc; use event::EventQueue; @@ -522,7 +522,7 @@ impl SchemeMut for Udpd { Ok(0) } } -fn daemon(scheme_fd: usize, udp_fd: usize, time_fd: usize) { +fn daemon(scheme_fd: RawFd, udp_fd: RawFd, time_fd: RawFd) { let scheme_file = unsafe { File::from_raw_fd(scheme_fd) }; let udp_file = unsafe { File::from_raw_fd(udp_fd) }; let time_file = unsafe { File::from_raw_fd(time_fd) }; @@ -565,7 +565,7 @@ fn main() { println!("udpd: providing udp:"); match syscall::open(":udp", O_RDWR | O_CREAT | O_NONBLOCK) { Ok(scheme_fd) => { - daemon(scheme_fd, udp_fd, time_fd); + daemon(scheme_fd as RawFd, udp_fd as RawFd, time_fd as RawFd); }, Err(err) => { println!("udpd: failed to create udp scheme: {}", err); From 1ad591ad05910d91beb59da825bd11dbdf42b5df Mon Sep 17 00:00:00 2001 From: Egor Karavaev Date: Fri, 8 Sep 2017 00:02:17 +0300 Subject: [PATCH 023/155] Add Smolnetd daemon. --- Cargo.toml | 4 +++ src/smolnetd/error.rs | 52 +++++++++++++++++++++++++++++++++++ src/smolnetd/main.rs | 62 ++++++++++++++++++++++++++++++++++++++++++ src/smolnetd/scheme.rs | 23 ++++++++++++++++ 4 files changed, 141 insertions(+) create mode 100644 src/smolnetd/error.rs create mode 100644 src/smolnetd/main.rs create mode 100644 src/smolnetd/scheme.rs diff --git a/Cargo.toml b/Cargo.toml index 16aa9d1275..73b09a4933 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,6 +22,10 @@ path = "src/udpd/main.rs" name = "icmpd" path = "src/icmpd/main.rs" +[[bin]] +name = "smolnetd" +path = "src/smolnetd/main.rs" + [dependencies] netutils = { git = "https://github.com/redox-os/netutils.git" } rand = "0.3" diff --git a/src/smolnetd/error.rs b/src/smolnetd/error.rs new file mode 100644 index 0000000000..5ab5ba3071 --- /dev/null +++ b/src/smolnetd/error.rs @@ -0,0 +1,52 @@ +use std::convert; +use std::fmt; +use std::result; +use std::io::Error as IOError; +use syscall::error::Error as SyscallError; + +enum ErrorType { + Syscall(SyscallError), + IOError(IOError), +} + +pub struct Error { + error_type: ErrorType, + descr: String, +} + +impl Error { + pub fn from_syscall_error>(syscall_error: SyscallError, descr: S) -> Error { + Error { + error_type: ErrorType::Syscall(syscall_error), + descr: descr.into(), + } + } + + pub fn from_io_error>(io_error: IOError, descr: S) -> Error { + Error { + error_type: ErrorType::IOError(io_error), + descr: descr.into(), + } + } +} + +impl fmt::Display for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> result::Result<(), fmt::Error> { + match self.error_type { + ErrorType::Syscall(ref syscall_error) => { + write!(f, "{}: syscall error: {}", self.descr, syscall_error) + } + ErrorType::IOError(ref io_error) => { + write!(f, "{} : io error : {}", self.descr, io_error) + } + } + } +} + +impl convert::From for Error { + fn from(e: IOError) -> Self { + Error::from_io_error(e, "") + } +} + +pub type Result = result::Result; diff --git a/src/smolnetd/main.rs b/src/smolnetd/main.rs new file mode 100644 index 0000000000..be52c81a2f --- /dev/null +++ b/src/smolnetd/main.rs @@ -0,0 +1,62 @@ +extern crate event; +extern crate syscall; + +use error::{Error, Result}; +use event::EventQueue; +use scheme::Smolnetd; +use std::os::unix::io::{FromRawFd, RawFd}; +use std::process; +use std::rc::Rc; +use std::fs::File; +use std::cell::RefCell; + +mod error; +mod scheme; + +fn run() -> Result<()> { + use syscall::flag::*; + + if unsafe { syscall::clone(0).unwrap() } != 0 { + return Ok(()); + } + + println!("icmpd: opening network:"); + let network_fd = syscall::open("network:", O_RDWR | O_NONBLOCK) + .map_err(|e| Error::from_syscall_error(e, "failed to open network:"))? as + RawFd; + + println!("icmpd: opening :ip"); + let ip_fd = syscall::open(":ip", O_RDWR | O_NONBLOCK) + .map_err(|e| Error::from_syscall_error(e, "failed to open :ip"))? as RawFd; + + let (network_file, ip_file) = + unsafe { (File::from_raw_fd(network_fd), File::from_raw_fd(ip_fd)) }; + let smolnetd = Rc::new(RefCell::new(Smolnetd::new(network_file, ip_file))); + + let mut event_queue = EventQueue::<(), Error>::new() + .map_err(|e| Error::from_io_error(e, "failed to create event queue"))?; + + let smolnetd_ = smolnetd.clone(); + + event_queue + .add(network_fd, move |_| { + smolnetd_.borrow_mut().on_network_scheme_event() + }) + .map_err(|e| { + Error::from_io_error(e, "failed to listen to network events") + })?; + + event_queue + .add(ip_fd, move |_| smolnetd.borrow_mut().on_ip_scheme_event()) + .map_err(|e| Error::from_io_error(e, "failed to listen to ip events"))?; + + event_queue.run() +} + +fn main() { + if let Err(err) = run() { + println!("smoltcpd: {}", err); + process::exit(1); + } + process::exit(0); +} diff --git a/src/smolnetd/scheme.rs b/src/smolnetd/scheme.rs new file mode 100644 index 0000000000..2447d83e93 --- /dev/null +++ b/src/smolnetd/scheme.rs @@ -0,0 +1,23 @@ +use error::Result; +use std::fs::File; + +pub struct Smolnetd { + network_file: File, + ip_file: File, +} + +impl Smolnetd { + pub fn new(network_file: File, ip_file: File) -> Smolnetd { + Smolnetd { + network_file, + ip_file, + } + } + pub fn on_network_scheme_event(&mut self) -> Result> { + Ok(None) + } + + pub fn on_ip_scheme_event(&mut self) -> Result> { + Ok(None) + } +} From fb539515d7c4a6da5654fa8e5caf619f9e9e15c3 Mon Sep 17 00:00:00 2001 From: Egor Karavaev Date: Sat, 9 Sep 2017 00:41:11 +0300 Subject: [PATCH 024/155] Initial integraion of smoltcpd. --- Cargo.lock | 100 ++++++++++++++++++++++------------- Cargo.toml | 5 ++ src/smolnetd/main.rs | 1 + src/smolnetd/scheme.rs | 116 ++++++++++++++++++++++++++++++++++++++++- 4 files changed, 183 insertions(+), 39 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 80b91d1fe1..9d529e7365 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5,13 +5,22 @@ dependencies = [ "netutils 0.1.0 (git+https://github.com/redox-os/netutils.git)", "rand 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", "redox_event 0.1.0 (git+https://github.com/redox-os/event.git)", - "redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)", + "smoltcp 0.4.0-pre (git+https://github.com/m-labs/smoltcp.git)", ] [[package]] name = "arg_parser" version = "0.1.0" -source = "git+https://github.com/redox-os/arg-parser.git#288d2fd9ae27ed2c7a3aaf5a77cf07e2b2bd356c" +source = "git+https://github.com/redox-os/arg-parser.git#1b6a9505a1e9c39af1836ecbee293a987619a539" + +[[package]] +name = "base64" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] [[package]] name = "base64" @@ -71,12 +80,12 @@ source = "git+https://github.com/redox-os/libextra.git#402932084acd5fef481294588 [[package]] name = "futures" -version = "0.1.16" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "gcc" -version = "0.3.54" +version = "0.3.53" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -86,10 +95,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "hyper" -version = "0.10.13" +version = "0.10.12" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "base64 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "base64 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", "httparse 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -107,7 +116,7 @@ name = "hyper-rustls" version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "hyper 0.10.13 (registry+https://github.com/rust-lang/crates.io-index)", + "hyper 0.10.12 (registry+https://github.com/rust-lang/crates.io-index)", "rustls 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "webpki-roots 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -143,7 +152,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libc" -version = "0.2.30" +version = "0.2.29" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -168,6 +177,11 @@ dependencies = [ "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "managed" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "matches" version = "0.1.6" @@ -184,17 +198,17 @@ dependencies = [ [[package]] name = "netutils" version = "0.1.0" -source = "git+https://github.com/redox-os/netutils.git#ec1a835a9d4a95a8e41c4e994a540d298d897cd4" +source = "git+https://github.com/redox-os/netutils.git#849b72c5b9e77a654a51521276dc6f2223a67aec" dependencies = [ "arg_parser 0.1.0 (git+https://github.com/redox-os/arg-parser.git)", "extra 0.1.0 (git+https://github.com/redox-os/libextra.git)", - "hyper 0.10.13 (registry+https://github.com/rust-lang/crates.io-index)", + "hyper 0.10.12 (registry+https://github.com/rust-lang/crates.io-index)", "hyper-rustls 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", "ntpclient 0.0.1 (git+https://github.com/willem66745/ntpclient-rust)", "pbr 1.0.0 (git+https://github.com/a8m/pb)", "redox_event 0.1.0 (git+https://github.com/redox-os/event.git)", - "redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)", "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -212,7 +226,7 @@ name = "num_cpus" version = "1.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -221,7 +235,7 @@ version = "1.0.0" source = "git+https://github.com/a8m/pb#e9369ed2b94df4f554fe79c2643de41f7338475f" dependencies = [ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -237,7 +251,7 @@ name = "rand" version = "0.3.16" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", "magenta 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -255,9 +269,9 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "coco 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -267,12 +281,12 @@ name = "redox_event" version = "0.1.0" source = "git+https://github.com/redox-os/event.git#42d552e4765efbfb4ec39ce174900d3f48548a70" dependencies = [ - "redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "redox_syscall" -version = "0.1.31" +version = "0.1.30" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -280,7 +294,7 @@ name = "redox_termios" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -288,11 +302,11 @@ name = "ring" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)", + "gcc 0.3.53 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "untrusted 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -304,7 +318,7 @@ dependencies = [ "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "ring 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)", - "untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "untrusted 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "webpki 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -318,13 +332,22 @@ name = "scopeguard" version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "smoltcp" +version = "0.4.0-pre" +source = "git+https://github.com/m-labs/smoltcp.git#9cb813134c88dd41904d409de45818829bd94889" +dependencies = [ + "byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "managed 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "termion" version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)", "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -334,8 +357,8 @@ version = "0.1.38" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -372,7 +395,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "untrusted" -version = "0.5.1" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -397,7 +420,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "ring 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)", - "untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "untrusted 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -405,7 +428,7 @@ name = "webpki-roots" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "untrusted 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "webpki 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -421,6 +444,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [metadata] "checksum arg_parser 0.1.0 (git+https://github.com/redox-os/arg-parser.git)" = "" +"checksum base64 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "30e93c03064e7590d0466209155251b90c22e37fab1daf2771582598b5827557" "checksum base64 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "96434f987501f0ed4eb336a411e0631ecd1afa11574fe148587adc4ff96143c9" "checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d" "checksum byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855" @@ -430,19 +454,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum custom_derive 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "ef8ae57c4978a2acd8b869ce6b9ca1dfe817bff704c220209fdef2c0b75a01b9" "checksum either 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "18785c1ba806c258137c937e44ada9ee7e69a37e3c72077542cd2f069d78562a" "checksum extra 0.1.0 (git+https://github.com/redox-os/libextra.git)" = "" -"checksum futures 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "05a23db7bd162d4e8265968602930c476f688f0c180b44bdaf55e0cb2c687558" -"checksum gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)" = "5e33ec290da0d127825013597dbdfc28bee4964690c7ce1166cbc2a7bd08b1bb" +"checksum futures 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "4b63a4792d4f8f686defe3b39b92127fea6344de5d38202b2ee5a11bbbf29d6a" +"checksum gcc 0.3.53 (registry+https://github.com/rust-lang/crates.io-index)" = "e8310f7e9c890398b0e80e301c4f474e9918d2b27fca8f48486ca775fa9ffc5a" "checksum httparse 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "af2f2dd97457e8fb1ae7c5a420db346af389926e36f43768b96f101546b04a07" -"checksum hyper 0.10.13 (registry+https://github.com/rust-lang/crates.io-index)" = "368cb56b2740ebf4230520e2b90ebb0461e69034d85d1945febd9b3971426db2" +"checksum hyper 0.10.12 (registry+https://github.com/rust-lang/crates.io-index)" = "0f01e4a20f5dfa5278d7762b7bdb7cab96e24378b9eca3889fbd4b5e94dc7063" "checksum hyper-rustls 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "04535774f79684c99528944ebdb89756c945c027e55ce52faa245879d836c8fb" "checksum idna 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "014b298351066f1512874135335d62a789ffe78a9974f94b43ed5621951eaf7d" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a" "checksum lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3b37545ab726dd833ec6420aaba8231c5b320814b9029ad585555d2a03e94fbf" -"checksum libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)" = "2370ca07ec338939e356443dac2296f581453c35fe1e3a3ed06023c49435f915" +"checksum libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)" = "8a014d9226c2cc402676fbe9ea2e15dd5222cd1dd57f576b5b283178c944a264" "checksum log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "880f77541efa6e5cc74e76910c9884d9859683118839d6a1dc3b11e63512565b" "checksum magenta 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4bf0336886480e671965f794bc9b6fce88503563013d1bfb7a502c81fe3ac527" "checksum magenta-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "40d014c7011ac470ae28e2f76a02bfea4a8480f73e701353b49ad7a8d75f4699" +"checksum managed 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "61eb783b4fa77e8fa4d27ec400f97ed9168546b8b30341a120b7ba9cc6571aaf" "checksum matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "100aabe6b8ff4e4a7e32c1c13523379802df0772b82466207ac25b013f193376" "checksum mime 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ba626b8a6de5da682e1caa06bdb42a335aee5a84db8e5046a3e8ab17ba0a3ae0" "checksum netutils 0.1.0 (git+https://github.com/redox-os/netutils.git)" = "" @@ -454,12 +479,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum rayon 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a77c51c07654ddd93f6cb543c7a849863b03abc7e82591afda6dc8ad4ac3ac4a" "checksum rayon-core 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7febc28567082c345f10cddc3612c6ea020fc3297a1977d472cf9fdb73e6e493" "checksum redox_event 0.1.0 (git+https://github.com/redox-os/event.git)" = "" -"checksum redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)" = "8dde11f18c108289bef24469638a04dce49da56084f2d50618b226e47eb04509" +"checksum redox_syscall 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)" = "8312fba776a49cf390b7b62f3135f9b294d8617f7a7592cfd0ac2492b658cd7b" "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" "checksum ring 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1f2a6dc7fc06a05e6de183c5b97058582e9da2de0c136eafe49609769c507724" "checksum rustls 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "17727f4b991294da2c84d75a43c003151ff58072212768800f66c56ee46dca43" "checksum safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e27a8b19b835f7aea908818e871f5cc3a5a186550c30773be987e155e8163d8f" "checksum scopeguard 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c79eb2c3ac4bc2507cda80e7f3ac5b88bd8eae4c0914d5663e6a8933994be918" +"checksum smoltcp 0.4.0-pre (git+https://github.com/m-labs/smoltcp.git)" = "" "checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" "checksum time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)" = "d5d788d3aa77bc0ef3e9621256885555368b47bd495c13dd2e7413c89f845520" "checksum traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079" @@ -467,7 +493,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum unicase 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7f4765f83163b74f957c797ad9253caf97f103fb064d3999aea9568d09fc8a33" "checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" "checksum unicode-normalization 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "51ccda9ef9efa3f7ef5d91e8f9b83bbe6955f9bf86aec89d5cce2c874625920f" -"checksum untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f392d7819dbe58833e26872f5f6f0d68b7bbbe90fc3667e98731c4a15ad9a7ae" +"checksum untrusted 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6b65243989ef6aacd9c0d6bd2b822765c3361d8ed352185a6f3a41f3a718c673" "checksum url 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "eeb819346883532a271eb626deb43c4a1bb4c4dd47c519bd78137c3e72a4fe27" "checksum version_check 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6b772017e347561807c1aa192438c5fd74242a670a6cffacc40f2defd1dc069d" "checksum webpki 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e499345fc4c6b7c79a5b8756d4592c4305510a13512e79efafe00dfbd67bbac6" diff --git a/Cargo.toml b/Cargo.toml index 73b09a4933..a8a6f44305 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,3 +31,8 @@ netutils = { git = "https://github.com/redox-os/netutils.git" } rand = "0.3" redox_event = { git = "https://github.com/redox-os/event.git" } redox_syscall = "0.1" + +[dependencies.smoltcp] +git = "https://github.com/m-labs/smoltcp.git" +default-features = false +features = ["std"] diff --git a/src/smolnetd/main.rs b/src/smolnetd/main.rs index be52c81a2f..4be9d06beb 100644 --- a/src/smolnetd/main.rs +++ b/src/smolnetd/main.rs @@ -1,5 +1,6 @@ extern crate event; extern crate syscall; +extern crate smoltcp; use error::{Error, Result}; use event::EventQueue; diff --git a/src/smolnetd/scheme.rs b/src/smolnetd/scheme.rs index 2447d83e93..70071f55ae 100644 --- a/src/smolnetd/scheme.rs +++ b/src/smolnetd/scheme.rs @@ -1,23 +1,135 @@ use error::Result; +use std::rc::Rc; use std::fs::File; +use std::cell::RefCell; +use std::time::Instant; +use std::io::{Read, Write}; +use syscall::SchemeMut; +use syscall; +use smoltcp; + +struct NetworkDevice { + network_file: Rc>, +} + +impl NetworkDevice { + const MTU: usize = 1520; + + pub fn new(network_file: File) -> NetworkDevice { + NetworkDevice { + network_file: Rc::new(RefCell::new(network_file)), + } + } +} + +struct TxBuffer { + buffer: Vec, + network_file: Rc>, +} + +impl AsRef<[u8]> for TxBuffer { + fn as_ref(&self) -> &[u8] { + self.buffer.as_ref() + } +} + +impl AsMut<[u8]> for TxBuffer { + fn as_mut(&mut self) -> &mut [u8] { + self.buffer.as_mut() + } +} + +impl Drop for TxBuffer { + fn drop(&mut self) { + let _ = self.network_file.borrow_mut().write(&self.buffer); + } +} + +impl smoltcp::phy::Device for NetworkDevice { + type RxBuffer = Vec; + type TxBuffer = TxBuffer; + + fn limits(&self) -> smoltcp::phy::DeviceLimits { + let mut limits = smoltcp::phy::DeviceLimits::default(); + limits.max_transmission_unit = Self::MTU; + limits.max_burst_size = Some(1); + limits + } + + fn receive(&mut self, _timestamp: u64) -> smoltcp::Result { + let mut buffer = Vec::with_capacity(65536); + if let Ok(count) = self.network_file.borrow_mut().read(&mut buffer) { + if count == 0 { + return Err(smoltcp::Error::Exhausted); + } + buffer.resize(count, 0); + Ok(buffer) + } else { + Err(smoltcp::Error::Exhausted) + } + } + + fn transmit(&mut self, _timestamp: u64, length: usize) -> smoltcp::Result { + Ok(TxBuffer { + network_file: self.network_file.clone(), + buffer: vec![0; length], + }) + } +} pub struct Smolnetd { - network_file: File, + iface: smoltcp::iface::EthernetInterface<'static, 'static, 'static, NetworkDevice>, + sockets: smoltcp::socket::SocketSet<'static, 'static, 'static>, ip_file: File, + startup_time: Instant, } +struct IpHandler<'a>(&'a mut Smolnetd); + impl Smolnetd { pub fn new(network_file: File, ip_file: File) -> Smolnetd { + let arp_cache = smoltcp::iface::SliceArpCache::new(vec![Default::default(); 8]); + let hardware_addr = smoltcp::wire::EthernetAddress([0x02, 0x00, 0x00, 0x00, 0x00, 0x01]); + let protocol_addrs = [smoltcp::wire::IpAddress::v4(192, 168, 69, 1)]; + let network_device = NetworkDevice::new(network_file); Smolnetd { - network_file, + iface: smoltcp::iface::EthernetInterface::new( + Box::new(network_device), + Box::new(arp_cache) as Box, + hardware_addr, + protocol_addrs, + ), + sockets: smoltcp::socket::SocketSet::new(vec![]), + startup_time: Instant::now(), ip_file, } } + pub fn on_network_scheme_event(&mut self) -> Result> { + let timestamp = self.get_timestamp(); + let _ = self.iface.poll(&mut self.sockets, timestamp); Ok(None) } pub fn on_ip_scheme_event(&mut self) -> Result> { + loop { + let mut packet = syscall::Packet::default(); + if self.ip_file.read(&mut packet)? == 0 { + break; + } + IpHandler(self).handle(&mut packet); + self.ip_file.write_all(&packet)?; + } Ok(None) } + + fn get_timestamp(&self) -> u64 { + let duration = Instant::now().duration_since(self.startup_time); + let duration_ms = (duration.as_secs() * 1000) + (duration.subsec_nanos() / 1000000) as u64; + duration_ms + } +} + +impl<'a> SchemeMut for IpHandler<'a> { + } From 5b89874deb6e6b4e8feb6f198fafa9bdec7a0b64 Mon Sep 17 00:00:00 2001 From: Egor Karavaev Date: Sat, 9 Sep 2017 23:17:19 +0300 Subject: [PATCH 025/155] Wip. --- Cargo.lock | 2 + Cargo.toml | 7 +- src/icmpd/main.rs | 7 +- src/smolnetd/device.rs | 74 +++++++++ src/smolnetd/main.rs | 73 +++++++-- src/smolnetd/scheme.rs | 332 ++++++++++++++++++++++++++++++----------- 6 files changed, 390 insertions(+), 105 deletions(-) create mode 100644 src/smolnetd/device.rs diff --git a/Cargo.lock b/Cargo.lock index 9d529e7365..7b55db6412 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,7 @@ name = "redox_netstack" version = "0.1.0" dependencies = [ + "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "netutils 0.1.0 (git+https://github.com/redox-os/netutils.git)", "rand 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", "redox_event 0.1.0 (git+https://github.com/redox-os/event.git)", @@ -338,6 +339,7 @@ version = "0.4.0-pre" source = "git+https://github.com/m-labs/smoltcp.git#9cb813134c88dd41904d409de45818829bd94889" dependencies = [ "byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "managed 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/Cargo.toml b/Cargo.toml index a8a6f44305..938eeb57f7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,7 +32,12 @@ rand = "0.3" redox_event = { git = "https://github.com/redox-os/event.git" } redox_syscall = "0.1" +[dependencies.log] +version = "0.3" +default-features = false +features = ["release_max_level_off"] + [dependencies.smoltcp] git = "https://github.com/m-labs/smoltcp.git" default-features = false -features = ["std"] +features = ["std", "log"] diff --git a/src/icmpd/main.rs b/src/icmpd/main.rs index 25026b656c..4d5cb96728 100644 --- a/src/icmpd/main.rs +++ b/src/icmpd/main.rs @@ -18,9 +18,9 @@ mod scheme; fn run() -> Result<()> { use syscall::flag::*; - if unsafe { syscall::clone(0).unwrap() } != 0 { - return Ok(()); - } + // if unsafe { syscall::clone(0).unwrap() } != 0 { + // return Ok(()); + // } println!("icmpd: opening ip:1:"); let icmp_fd = syscall::open("ip:1", O_RDWR | O_NONBLOCK) @@ -32,7 +32,6 @@ fn run() -> Result<()> { .map_err(|e| Error::from_syscall_error(e, "failed to open :icmp"))? as RawFd; - let icmpd = Rc::new(RefCell::new(Icmpd::new(unsafe { File::from_raw_fd(icmp_fd) }, unsafe { File::from_raw_fd(scheme_fd) }))); diff --git a/src/smolnetd/device.rs b/src/smolnetd/device.rs new file mode 100644 index 0000000000..b96e8fe185 --- /dev/null +++ b/src/smolnetd/device.rs @@ -0,0 +1,74 @@ +use std::rc::Rc; +use std::fs::File; +use std::cell::RefCell; +use std::io::Write; +use std::collections::VecDeque; +use smoltcp; + +pub struct NetworkDevice { + network_file: Rc>, + input_queue: Rc>>>, +} + +impl NetworkDevice { + pub const MTU: usize = 120; + + pub fn new( + network_file: Rc>, + input_queue: Rc>>>, + ) -> NetworkDevice { + NetworkDevice { + network_file, + input_queue, + } + } +} + +pub struct TxBuffer { + buffer: Vec, + network_file: Rc>, +} + +impl AsRef<[u8]> for TxBuffer { + fn as_ref(&self) -> &[u8] { + self.buffer.as_ref() + } +} + +impl AsMut<[u8]> for TxBuffer { + fn as_mut(&mut self) -> &mut [u8] { + self.buffer.as_mut() + } +} + +impl Drop for TxBuffer { + fn drop(&mut self) { + let _ = self.network_file.borrow_mut().write(&self.buffer); + } +} + +impl smoltcp::phy::Device for NetworkDevice { + type RxBuffer = Vec; + type TxBuffer = TxBuffer; + + fn limits(&self) -> smoltcp::phy::DeviceLimits { + let mut limits = smoltcp::phy::DeviceLimits::default(); + limits.max_transmission_unit = Self::MTU; + limits.max_burst_size = Some(1); + limits + } + + fn receive(&mut self, _timestamp: u64) -> smoltcp::Result { + self.input_queue + .borrow_mut() + .pop_front() + .ok_or(smoltcp::Error::Exhausted) + } + + fn transmit(&mut self, _timestamp: u64, length: usize) -> smoltcp::Result { + Ok(TxBuffer { + network_file: self.network_file.clone(), + buffer: vec![0; length], + }) + } +} diff --git a/src/smolnetd/main.rs b/src/smolnetd/main.rs index 4be9d06beb..d783e52c97 100644 --- a/src/smolnetd/main.rs +++ b/src/smolnetd/main.rs @@ -1,38 +1,75 @@ extern crate event; -extern crate syscall; +#[macro_use] +extern crate log; +extern crate netutils; extern crate smoltcp; +extern crate syscall; use error::{Error, Result}; use event::EventQueue; use scheme::Smolnetd; +use std::cell::RefCell; +use std::fs::File; use std::os::unix::io::{FromRawFd, RawFd}; use std::process; use std::rc::Rc; -use std::fs::File; -use std::cell::RefCell; mod error; +mod device; mod scheme; +struct SimpleLogger; + +impl log::Log for SimpleLogger { + fn enabled(&self, _metadata: &log::LogMetadata) -> bool { + true + } + + fn log(&self, record: &log::LogRecord) { + if self.enabled(record.metadata()) { + println!("{} : {}", record.level(), record.args()); + } + } +} + fn run() -> Result<()> { use syscall::flag::*; - if unsafe { syscall::clone(0).unwrap() } != 0 { - return Ok(()); + unsafe { + log::set_logger_raw(|max_log_level| { + max_log_level.set(log::LogLevelFilter::Trace); + &SimpleLogger + }).expect("Can't initialize logger"); } - println!("icmpd: opening network:"); + // if unsafe { syscall::clone(0).unwrap() } != 0 { + // return Ok(()); + // } + + trace!("opening network:"); let network_fd = syscall::open("network:", O_RDWR | O_NONBLOCK) .map_err(|e| Error::from_syscall_error(e, "failed to open network:"))? as RawFd; - println!("icmpd: opening :ip"); - let ip_fd = syscall::open(":ip", O_RDWR | O_NONBLOCK) + trace!("opening :ip"); + let ip_fd = syscall::open(":ip", O_RDWR | O_CREAT | O_NONBLOCK) .map_err(|e| Error::from_syscall_error(e, "failed to open :ip"))? as RawFd; - let (network_file, ip_file) = - unsafe { (File::from_raw_fd(network_fd), File::from_raw_fd(ip_fd)) }; - let smolnetd = Rc::new(RefCell::new(Smolnetd::new(network_file, ip_file))); + let time_path = format!("time:{}", syscall::CLOCK_MONOTONIC); + let time_fd = syscall::open(&time_path, syscall::O_RDWR) + .map_err(|e| Error::from_syscall_error(e, "failed to open time:"))? as + RawFd; + + let (network_file, ip_file, time_file) = unsafe { + ( + File::from_raw_fd(network_fd), + File::from_raw_fd(ip_fd), + File::from_raw_fd(time_fd), + ) + }; + let smolnetd = Rc::new(RefCell::new( + Smolnetd::new(network_file, ip_file, time_file), + )); let mut event_queue = EventQueue::<(), Error>::new() .map_err(|e| Error::from_io_error(e, "failed to create event queue"))?; @@ -47,16 +84,26 @@ fn run() -> Result<()> { Error::from_io_error(e, "failed to listen to network events") })?; + let smolnetd_ = smolnetd.clone(); + event_queue - .add(ip_fd, move |_| smolnetd.borrow_mut().on_ip_scheme_event()) + .add(ip_fd, move |_| smolnetd_.borrow_mut().on_ip_scheme_event()) .map_err(|e| Error::from_io_error(e, "failed to listen to ip events"))?; + event_queue + .add(time_fd, move |_| smolnetd.borrow_mut().on_time_event()) + .map_err(|e| { + Error::from_io_error(e, "failed to listen to time events") + })?; + + event_queue.trigger_all(0)?; + event_queue.run() } fn main() { if let Err(err) = run() { - println!("smoltcpd: {}", err); + error!("smoltcpd: {}", err); process::exit(1); } process::exit(0); diff --git a/src/smolnetd/scheme.rs b/src/smolnetd/scheme.rs index 70071f55ae..34a0b2912e 100644 --- a/src/smolnetd/scheme.rs +++ b/src/smolnetd/scheme.rs @@ -1,97 +1,59 @@ -use error::Result; -use std::rc::Rc; -use std::fs::File; -use std::cell::RefCell; -use std::time::Instant; -use std::io::{Read, Write}; -use syscall::SchemeMut; -use syscall; +use device::NetworkDevice; +use error::{Error, Result}; +use netutils::{getcfg, MacAddr}; use smoltcp; +use std::collections::{BTreeMap, VecDeque}; +use std::fs::File; +use std::io::{Read, Write}; +use std::mem; +use std::net::Ipv4Addr; +use std::str::FromStr; +use std::time::Instant; +use std::rc::Rc; +use std::cell::RefCell; +use smoltcp::socket::AsSocket; +use syscall; -struct NetworkDevice { - network_file: Rc>, -} - -impl NetworkDevice { - const MTU: usize = 1520; - - pub fn new(network_file: File) -> NetworkDevice { - NetworkDevice { - network_file: Rc::new(RefCell::new(network_file)), - } - } -} - -struct TxBuffer { - buffer: Vec, - network_file: Rc>, -} - -impl AsRef<[u8]> for TxBuffer { - fn as_ref(&self) -> &[u8] { - self.buffer.as_ref() - } -} - -impl AsMut<[u8]> for TxBuffer { - fn as_mut(&mut self) -> &mut [u8] { - self.buffer.as_mut() - } -} - -impl Drop for TxBuffer { - fn drop(&mut self) { - let _ = self.network_file.borrow_mut().write(&self.buffer); - } -} - -impl smoltcp::phy::Device for NetworkDevice { - type RxBuffer = Vec; - type TxBuffer = TxBuffer; - - fn limits(&self) -> smoltcp::phy::DeviceLimits { - let mut limits = smoltcp::phy::DeviceLimits::default(); - limits.max_transmission_unit = Self::MTU; - limits.max_burst_size = Some(1); - limits - } - - fn receive(&mut self, _timestamp: u64) -> smoltcp::Result { - let mut buffer = Vec::with_capacity(65536); - if let Ok(count) = self.network_file.borrow_mut().read(&mut buffer) { - if count == 0 { - return Err(smoltcp::Error::Exhausted); - } - buffer.resize(count, 0); - Ok(buffer) - } else { - Err(smoltcp::Error::Exhausted) - } - } - - fn transmit(&mut self, _timestamp: u64, length: usize) -> smoltcp::Result { - Ok(TxBuffer { - network_file: self.network_file.clone(), - buffer: vec![0; length], - }) - } +struct IpHandle { + flags: usize, + events: usize, + socket_handle: smoltcp::socket::SocketHandle, } pub struct Smolnetd { iface: smoltcp::iface::EthernetInterface<'static, 'static, 'static, NetworkDevice>, - sockets: smoltcp::socket::SocketSet<'static, 'static, 'static>, + socket_set: smoltcp::socket::SocketSet<'static, 'static, 'static>, ip_file: File, + time_file: File, + network_file: Rc>, startup_time: Instant, + ip_sockets: BTreeMap, + input_queue: Rc>>>, + next_fd: usize, } -struct IpHandler<'a>(&'a mut Smolnetd); +struct IpScheme<'a>(&'a mut Smolnetd); impl Smolnetd { - pub fn new(network_file: File, ip_file: File) -> Smolnetd { + const IP_BUFFER_SIZE: usize = 128; + const CHECK_TIMEOUT_MS: i64 = 1000; + + pub fn new(network_file: File, ip_file: File, time_file: File) -> Smolnetd { let arp_cache = smoltcp::iface::SliceArpCache::new(vec![Default::default(); 8]); - let hardware_addr = smoltcp::wire::EthernetAddress([0x02, 0x00, 0x00, 0x00, 0x00, 0x01]); - let protocol_addrs = [smoltcp::wire::IpAddress::v4(192, 168, 69, 1)]; - let network_device = NetworkDevice::new(network_file); + //TODO Use smoltcp::wire::EthernetAddress::from_str + let mac_addr = MacAddr::from_str(&getcfg("mac").unwrap().trim()); + let hardware_addr = smoltcp::wire::EthernetAddress(mac_addr.bytes); + //TODO Use smoltcp::wire::Ipv4Addr::from_str + let ip_bytes = Ipv4Addr::from_str(&getcfg("ip").unwrap().trim()) + .unwrap() + .octets(); + let protocol_addrs = [ + smoltcp::wire::IpAddress::Ipv4(smoltcp::wire::Ipv4Address::from_bytes(&ip_bytes)), + ]; + trace!("mac {:?} ip {:?}", hardware_addr, protocol_addrs); + let input_queue = Rc::new(RefCell::new(VecDeque::new())); + let network_file = Rc::new(RefCell::new(network_file)); + let network_device = NetworkDevice::new(network_file.clone(), input_queue.clone()); Smolnetd { iface: smoltcp::iface::EthernetInterface::new( Box::new(network_device), @@ -99,37 +61,233 @@ impl Smolnetd { hardware_addr, protocol_addrs, ), - sockets: smoltcp::socket::SocketSet::new(vec![]), + socket_set: smoltcp::socket::SocketSet::new(vec![]), startup_time: Instant::now(), ip_file, + time_file, + ip_sockets: BTreeMap::new(), + next_fd: 0, + input_queue, + network_file, } } pub fn on_network_scheme_event(&mut self) -> Result> { - let timestamp = self.get_timestamp(); - let _ = self.iface.poll(&mut self.sockets, timestamp); + if self.read_frames()? > 0 { + self.poll().map(Some)?; + } Ok(None) } pub fn on_ip_scheme_event(&mut self) -> Result> { + use syscall::SchemeMut; + loop { let mut packet = syscall::Packet::default(); if self.ip_file.read(&mut packet)? == 0 { break; } - IpHandler(self).handle(&mut packet); + IpScheme(self).handle(&mut packet); self.ip_file.write_all(&packet)?; } Ok(None) } + pub fn on_time_event(&mut self) -> Result> { + let mut time = syscall::data::TimeSpec::default(); + if self.time_file.read(&mut time)? < mem::size_of::() { + panic!(); + } + let mut time_ms = time.tv_sec * 1000i64 + (time.tv_nsec as i64) / 1_000_000i64; + time_ms += Smolnetd::CHECK_TIMEOUT_MS; + time.tv_sec = time_ms / 1000; + time.tv_nsec = ((time_ms % 1000) * 1_000_00) as i32; + self.time_file + .write_all(&time) + .map_err(|e| Error::from_io_error(e, "Failed to write to time file"))?; + + self.poll().map(Some)?; + Ok(None) + } + + fn poll(&mut self) -> Result<()> { + let timestamp = self.get_timestamp(); + self.iface + .poll(&mut self.socket_set, timestamp) + .expect("poll error"); + self.notify_ip_sockets() + } + + fn read_frames(&mut self) -> Result { + let mut total_frames = 0; + loop { + let mut buffer = vec![0; 65536]; + let count = self.network_file + .borrow_mut() + .read(&mut buffer) + .map_err(|e| { + Error::from_io_error(e, "Failed to read from network file") + })?; + if count == 0 { + break; + } + trace!("got frame {}", count); + buffer.resize(count, 0); + self.input_queue.borrow_mut().push_back(buffer); + total_frames += 1; + } + Ok(total_frames) + } + fn get_timestamp(&self) -> u64 { let duration = Instant::now().duration_since(self.startup_time); let duration_ms = (duration.as_secs() * 1000) + (duration.subsec_nanos() / 1000000) as u64; duration_ms } + + fn network_fsync(&mut self) -> syscall::Result { + use std::os::unix::io::AsRawFd; + syscall::fsync(self.network_file.borrow_mut().as_raw_fd() as usize) + } + + fn notify_ip_sockets(&mut self) -> Result<()> { + for (&fd, ref handle) in &self.ip_sockets { + let socket: &mut smoltcp::socket::RawSocket = + self.socket_set.get_mut(handle.socket_handle).as_socket(); + if socket.can_send() { + post_fevent(&mut self.ip_file, fd, syscall::EVENT_READ, 1)?; + } + } + Ok(()) + } } -impl<'a> SchemeMut for IpHandler<'a> { - +impl<'a> syscall::SchemeMut for IpScheme<'a> { + fn open(&mut self, url: &[u8], flags: usize, uid: u32, _gid: u32) -> syscall::Result { + use std::str; + + if uid != 0 { + return Err(syscall::Error::new(syscall::EACCES)); + } + let path = str::from_utf8(url).or_else(|_| Err(syscall::Error::new(syscall::EINVAL)))?; + let proto = u8::from_str_radix(path, 16).or(Err(syscall::Error::new(syscall::ENOENT)))?; + + let mut rx_packets = Vec::with_capacity(Smolnetd::IP_BUFFER_SIZE); + let mut tx_packets = Vec::with_capacity(Smolnetd::IP_BUFFER_SIZE); + for _ in 0..Smolnetd::IP_BUFFER_SIZE { + rx_packets.push(smoltcp::socket::RawPacketBuffer::new( + vec![0; NetworkDevice::MTU], + )); + tx_packets.push(smoltcp::socket::RawPacketBuffer::new( + vec![0; NetworkDevice::MTU], + )); + } + let rx_buffer = smoltcp::socket::RawSocketBuffer::new(rx_packets); + let tx_buffer = smoltcp::socket::RawSocketBuffer::new(tx_packets); + let raw_socket = smoltcp::socket::RawSocket::new( + smoltcp::wire::IpVersion::Ipv4, + smoltcp::wire::IpProtocol::from(proto), + rx_buffer, + tx_buffer, + ); + + let socket_handle = self.0.socket_set.add(raw_socket); + let id = self.0.next_fd; + trace!("Open {} -> {}", path, id); + + self.0.ip_sockets.insert( + id, + IpHandle { + flags, + events: 0, + socket_handle, + }, + ); + self.0.next_fd += 1; + Ok(id) + } + + fn close(&mut self, fd: usize) -> syscall::Result { + trace!("Close {}", fd); + let socket_handle = { + let handle = self.0 + .ip_sockets + .get(&fd) + .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; + handle.socket_handle + }; + self.0.ip_sockets.remove(&fd); + self.0.socket_set.remove(socket_handle); + Ok(0) + } + + fn write(&mut self, fd: usize, buf: &[u8]) -> syscall::Result { + trace!("Write {} len {}", fd, buf.len()); + + let handle = self.0 + .ip_sockets + .get(&fd) + .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; + let socket: &mut smoltcp::socket::RawSocket = + self.0.socket_set.get_mut(handle.socket_handle).as_socket(); + socket.send_slice(buf).expect("Can't send slice"); + Ok(buf.len()) + } + + fn read(&mut self, fd: usize, buf: &mut [u8]) -> syscall::Result { + trace!("Read {}", fd); + use smoltcp::socket::AsSocket; + + let handle = self.0 + .ip_sockets + .get(&fd) + .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; + let socket: &mut smoltcp::socket::RawSocket = + self.0.socket_set.get_mut(handle.socket_handle).as_socket(); + if socket.can_recv() { + let length = socket.recv_slice(buf).expect("Can't receive slice"); + Ok(length) + } else if handle.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { + Ok(0) + } else { + Err(syscall::Error::new(syscall::EWOULDBLOCK)) + } + } + + fn fevent(&mut self, fd: usize, events: usize) -> syscall::Result { + trace!("fevent {}", fd); + let handle = self.0 + .ip_sockets + .get_mut(&fd) + .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; + handle.events = events; + Ok(fd) + } + + fn fsync(&mut self, fd: usize) -> syscall::Result { + trace!("fsync {}", fd); + { + let _handle = self.0 + .ip_sockets + .get_mut(&fd) + .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; + } + self.0.network_fsync() + } +} + +fn post_fevent(scheme_file: &mut File, fd: usize, event: usize, data_len: usize) -> Result<()> { + scheme_file + .write(&syscall::Packet { + id: 0, + pid: 0, + uid: 0, + gid: 0, + a: syscall::number::SYS_FEVENT, + b: fd, + c: event, + d: data_len, + }) + .map(|_| ()) + .map_err(|e| Error::from_io_error(e, "failed to post fevent")) } From 4058f5c4e8b5ed5eeb50dafc446d11afad207795 Mon Sep 17 00:00:00 2001 From: Egor Karavaev Date: Sun, 17 Sep 2017 00:03:29 +0300 Subject: [PATCH 026/155] Udp scheme support. --- Cargo.lock | 6 +- Cargo.toml | 3 +- src/smolnetd/device.rs | 2 +- src/smolnetd/main.rs | 21 +++- src/smolnetd/scheme.rs | 225 ++++++++++++++++++++++++++++++++++++----- 5 files changed, 223 insertions(+), 34 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7b55db6412..8203619c13 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7,7 +7,7 @@ dependencies = [ "rand 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", "redox_event 0.1.0 (git+https://github.com/redox-os/event.git)", "redox_syscall 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)", - "smoltcp 0.4.0-pre (git+https://github.com/m-labs/smoltcp.git)", + "smoltcp 0.4.0-pre (git+https://github.com/batonius/smoltcp.git?branch=default_route)", ] [[package]] @@ -336,7 +336,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "smoltcp" version = "0.4.0-pre" -source = "git+https://github.com/m-labs/smoltcp.git#9cb813134c88dd41904d409de45818829bd94889" +source = "git+https://github.com/batonius/smoltcp.git?branch=default_route#b64a43d93f3829e0127664b946be116e1f1fc583" dependencies = [ "byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -487,7 +487,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum rustls 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "17727f4b991294da2c84d75a43c003151ff58072212768800f66c56ee46dca43" "checksum safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e27a8b19b835f7aea908818e871f5cc3a5a186550c30773be987e155e8163d8f" "checksum scopeguard 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c79eb2c3ac4bc2507cda80e7f3ac5b88bd8eae4c0914d5663e6a8933994be918" -"checksum smoltcp 0.4.0-pre (git+https://github.com/m-labs/smoltcp.git)" = "" +"checksum smoltcp 0.4.0-pre (git+https://github.com/batonius/smoltcp.git?branch=default_route)" = "" "checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" "checksum time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)" = "d5d788d3aa77bc0ef3e9621256885555368b47bd495c13dd2e7413c89f845520" "checksum traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079" diff --git a/Cargo.toml b/Cargo.toml index 938eeb57f7..622615f407 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,6 +38,7 @@ default-features = false features = ["release_max_level_off"] [dependencies.smoltcp] -git = "https://github.com/m-labs/smoltcp.git" +git = "https://github.com/batonius/smoltcp.git" +branch = "default_route" default-features = false features = ["std", "log"] diff --git a/src/smolnetd/device.rs b/src/smolnetd/device.rs index b96e8fe185..9ac0705aef 100644 --- a/src/smolnetd/device.rs +++ b/src/smolnetd/device.rs @@ -11,7 +11,7 @@ pub struct NetworkDevice { } impl NetworkDevice { - pub const MTU: usize = 120; + pub const MTU: usize = 1520; pub fn new( network_file: Rc>, diff --git a/src/smolnetd/main.rs b/src/smolnetd/main.rs index d783e52c97..cdf6723b27 100644 --- a/src/smolnetd/main.rs +++ b/src/smolnetd/main.rs @@ -55,20 +55,26 @@ fn run() -> Result<()> { let ip_fd = syscall::open(":ip", O_RDWR | O_CREAT | O_NONBLOCK) .map_err(|e| Error::from_syscall_error(e, "failed to open :ip"))? as RawFd; + trace!("opening :udp"); + let udp_fd = syscall::open(":udp", O_RDWR | O_CREAT | O_NONBLOCK) + .map_err(|e| Error::from_syscall_error(e, "failed to open :udp"))? as + RawFd; + let time_path = format!("time:{}", syscall::CLOCK_MONOTONIC); let time_fd = syscall::open(&time_path, syscall::O_RDWR) .map_err(|e| Error::from_syscall_error(e, "failed to open time:"))? as RawFd; - let (network_file, ip_file, time_file) = unsafe { + let (network_file, ip_file, time_file, udp_file) = unsafe { ( File::from_raw_fd(network_fd), File::from_raw_fd(ip_fd), File::from_raw_fd(time_fd), + File::from_raw_fd(udp_fd), ) }; let smolnetd = Rc::new(RefCell::new( - Smolnetd::new(network_file, ip_file, time_file), + Smolnetd::new(network_file, ip_file, udp_file, time_file), )); let mut event_queue = EventQueue::<(), Error>::new() @@ -90,6 +96,17 @@ fn run() -> Result<()> { .add(ip_fd, move |_| smolnetd_.borrow_mut().on_ip_scheme_event()) .map_err(|e| Error::from_io_error(e, "failed to listen to ip events"))?; + let smolnetd_ = smolnetd.clone(); + + event_queue + .add( + udp_fd, + move |_| smolnetd_.borrow_mut().on_udp_scheme_event(), + ) + .map_err(|e| { + Error::from_io_error(e, "failed to listen to udp events") + })?; + event_queue .add(time_fd, move |_| smolnetd.borrow_mut().on_time_event()) .map_err(|e| { diff --git a/src/smolnetd/scheme.rs b/src/smolnetd/scheme.rs index 34a0b2912e..74cc29cdf3 100644 --- a/src/smolnetd/scheme.rs +++ b/src/smolnetd/scheme.rs @@ -12,33 +12,48 @@ use std::time::Instant; use std::rc::Rc; use std::cell::RefCell; use smoltcp::socket::AsSocket; +use syscall::SchemeMut; use syscall; -struct IpHandle { +struct RawHandle { flags: usize, events: usize, socket_handle: smoltcp::socket::SocketHandle, } +struct UdpHandle { + flags: usize, + events: usize, + remote_endpoint: smoltcp::wire::IpEndpoint, + socket_handle: smoltcp::socket::SocketHandle, +} + pub struct Smolnetd { + network_file: Rc>, + ip_file: File, + udp_file: File, + time_file: File, + iface: smoltcp::iface::EthernetInterface<'static, 'static, 'static, NetworkDevice>, socket_set: smoltcp::socket::SocketSet<'static, 'static, 'static>, - ip_file: File, - time_file: File, - network_file: Rc>, + startup_time: Instant, - ip_sockets: BTreeMap, - input_queue: Rc>>>, next_fd: usize, + + raw_sockets: BTreeMap, + udp_sockets: BTreeMap, + + input_queue: Rc>>>, } struct IpScheme<'a>(&'a mut Smolnetd); +struct UdpScheme<'a>(&'a mut Smolnetd); impl Smolnetd { const IP_BUFFER_SIZE: usize = 128; const CHECK_TIMEOUT_MS: i64 = 1000; - pub fn new(network_file: File, ip_file: File, time_file: File) -> Smolnetd { + pub fn new(network_file: File, ip_file: File, udp_file: File, time_file: File) -> Smolnetd { let arp_cache = smoltcp::iface::SliceArpCache::new(vec![Default::default(); 8]); //TODO Use smoltcp::wire::EthernetAddress::from_str let mac_addr = MacAddr::from_str(&getcfg("mac").unwrap().trim()); @@ -50,22 +65,31 @@ impl Smolnetd { let protocol_addrs = [ smoltcp::wire::IpAddress::Ipv4(smoltcp::wire::Ipv4Address::from_bytes(&ip_bytes)), ]; + let default_gw = smoltcp::wire::IpAddress::Ipv4(smoltcp::wire::Ipv4Address::from_bytes( + &Ipv4Addr::from_str(&getcfg("ip_router").unwrap().trim()) + .unwrap() + .octets(), + )); trace!("mac {:?} ip {:?}", hardware_addr, protocol_addrs); let input_queue = Rc::new(RefCell::new(VecDeque::new())); let network_file = Rc::new(RefCell::new(network_file)); let network_device = NetworkDevice::new(network_file.clone(), input_queue.clone()); + let mut iface = smoltcp::iface::EthernetInterface::new( + Box::new(network_device), + Box::new(arp_cache) as Box, + hardware_addr, + protocol_addrs, + ); + iface.set_default_gateway(24, Some(default_gw)); Smolnetd { - iface: smoltcp::iface::EthernetInterface::new( - Box::new(network_device), - Box::new(arp_cache) as Box, - hardware_addr, - protocol_addrs, - ), + iface, socket_set: smoltcp::socket::SocketSet::new(vec![]), startup_time: Instant::now(), ip_file, + udp_file, time_file, - ip_sockets: BTreeMap::new(), + raw_sockets: BTreeMap::new(), + udp_sockets: BTreeMap::new(), next_fd: 0, input_queue, network_file, @@ -80,8 +104,6 @@ impl Smolnetd { } pub fn on_ip_scheme_event(&mut self) -> Result> { - use syscall::SchemeMut; - loop { let mut packet = syscall::Packet::default(); if self.ip_file.read(&mut packet)? == 0 { @@ -93,6 +115,18 @@ impl Smolnetd { Ok(None) } + pub fn on_udp_scheme_event(&mut self) -> Result> { + loop { + let mut packet = syscall::Packet::default(); + if self.udp_file.read(&mut packet)? == 0 { + break; + } + UdpScheme(self).handle(&mut packet); + self.udp_file.write_all(&packet)?; + } + Ok(None) + } + pub fn on_time_event(&mut self) -> Result> { let mut time = syscall::data::TimeSpec::default(); if self.time_file.read(&mut time)? < mem::size_of::() { @@ -115,7 +149,7 @@ impl Smolnetd { self.iface .poll(&mut self.socket_set, timestamp) .expect("poll error"); - self.notify_ip_sockets() + self.notify_raw_sockets() } fn read_frames(&mut self) -> Result { @@ -150,8 +184,8 @@ impl Smolnetd { syscall::fsync(self.network_file.borrow_mut().as_raw_fd() as usize) } - fn notify_ip_sockets(&mut self) -> Result<()> { - for (&fd, ref handle) in &self.ip_sockets { + fn notify_raw_sockets(&mut self) -> Result<()> { + for (&fd, ref handle) in &self.raw_sockets { let socket: &mut smoltcp::socket::RawSocket = self.socket_set.get_mut(handle.socket_handle).as_socket(); if socket.can_send() { @@ -195,9 +229,9 @@ impl<'a> syscall::SchemeMut for IpScheme<'a> { let id = self.0.next_fd; trace!("Open {} -> {}", path, id); - self.0.ip_sockets.insert( + self.0.raw_sockets.insert( id, - IpHandle { + RawHandle { flags, events: 0, socket_handle, @@ -211,12 +245,12 @@ impl<'a> syscall::SchemeMut for IpScheme<'a> { trace!("Close {}", fd); let socket_handle = { let handle = self.0 - .ip_sockets + .raw_sockets .get(&fd) .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; handle.socket_handle }; - self.0.ip_sockets.remove(&fd); + self.0.raw_sockets.remove(&fd); self.0.socket_set.remove(socket_handle); Ok(0) } @@ -225,7 +259,7 @@ impl<'a> syscall::SchemeMut for IpScheme<'a> { trace!("Write {} len {}", fd, buf.len()); let handle = self.0 - .ip_sockets + .raw_sockets .get(&fd) .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; let socket: &mut smoltcp::socket::RawSocket = @@ -239,7 +273,7 @@ impl<'a> syscall::SchemeMut for IpScheme<'a> { use smoltcp::socket::AsSocket; let handle = self.0 - .ip_sockets + .raw_sockets .get(&fd) .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; let socket: &mut smoltcp::socket::RawSocket = @@ -257,7 +291,7 @@ impl<'a> syscall::SchemeMut for IpScheme<'a> { fn fevent(&mut self, fd: usize, events: usize) -> syscall::Result { trace!("fevent {}", fd); let handle = self.0 - .ip_sockets + .raw_sockets .get_mut(&fd) .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; handle.events = events; @@ -268,7 +302,133 @@ impl<'a> syscall::SchemeMut for IpScheme<'a> { trace!("fsync {}", fd); { let _handle = self.0 - .ip_sockets + .raw_sockets + .get_mut(&fd) + .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; + } + self.0.network_fsync() + } +} + +impl<'a> syscall::SchemeMut for UdpScheme<'a> { + fn open(&mut self, url: &[u8], flags: usize, uid: u32, _gid: u32) -> syscall::Result { + use std::str; + + if uid != 0 { + return Err(syscall::Error::new(syscall::EACCES)); + } + let path = str::from_utf8(url).or_else(|_| Err(syscall::Error::new(syscall::EINVAL)))?; + let mut parts = path.split("/"); + let (remote_ip, remote_port) = parse_socket(parts.next().unwrap_or("")); + let (local_ip, local_port) = parse_socket(parts.next().unwrap_or("")); + + let mut rx_packets = Vec::with_capacity(Smolnetd::IP_BUFFER_SIZE); + let mut tx_packets = Vec::with_capacity(Smolnetd::IP_BUFFER_SIZE); + for _ in 0..Smolnetd::IP_BUFFER_SIZE { + rx_packets.push(smoltcp::socket::UdpPacketBuffer::new( + vec![0; NetworkDevice::MTU], + )); + tx_packets.push(smoltcp::socket::UdpPacketBuffer::new( + vec![0; NetworkDevice::MTU], + )); + } + let rx_buffer = smoltcp::socket::UdpSocketBuffer::new(rx_packets); + let tx_buffer = smoltcp::socket::UdpSocketBuffer::new(tx_packets); + let mut udp_socket = smoltcp::socket::UdpSocket::new(rx_buffer, tx_buffer); + + if !local_ip.is_unspecified() && local_port != 0 { + let udp_socket: &mut smoltcp::socket::UdpSocket = udp_socket.as_socket(); + udp_socket.bind(smoltcp::wire::IpEndpoint::new( + smoltcp::wire::IpAddress::Ipv4( + smoltcp::wire::Ipv4Address::from_bytes(&local_ip.octets()), + ), + local_port, + )).unwrap(); + } + + let socket_handle = self.0.socket_set.add(udp_socket); + let id = self.0.next_fd; + trace!("Open {} -> {}", path, id); + + self.0.udp_sockets.insert( + id, + UdpHandle { + flags, + events: 0, + socket_handle, + remote_endpoint: smoltcp::wire::IpEndpoint::new( + smoltcp::wire::IpAddress::Ipv4( + smoltcp::wire::Ipv4Address::from_bytes(&remote_ip.octets()), + ), + remote_port, + ), + }, + ); + self.0.next_fd += 1; + Ok(id) + } + + fn close(&mut self, fd: usize) -> syscall::Result { + trace!("Close {}", fd); + let socket_handle = { + let handle = self.0 + .udp_sockets + .get(&fd) + .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; + handle.socket_handle + }; + self.0.udp_sockets.remove(&fd); + self.0.socket_set.remove(socket_handle); + Ok(0) + } + + fn write(&mut self, fd: usize, buf: &[u8]) -> syscall::Result { + trace!("Write {} len {}", fd, buf.len()); + + let handle = self.0 + .udp_sockets + .get(&fd) + .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; + let socket: &mut smoltcp::socket::UdpSocket = + self.0.socket_set.get_mut(handle.socket_handle).as_socket(); + socket.send_slice(buf, handle.remote_endpoint).expect("Can't send slice"); + Ok(buf.len()) + } + + fn read(&mut self, fd: usize, buf: &mut [u8]) -> syscall::Result { + trace!("Read {}", fd); + + let handle = self.0 + .udp_sockets + .get(&fd) + .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; + let socket: &mut smoltcp::socket::UdpSocket = + self.0.socket_set.get_mut(handle.socket_handle).as_socket(); + if socket.can_recv() { + let (length, _) = socket.recv_slice(buf).expect("Can't receive slice"); + Ok(length) + } else if handle.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { + Ok(0) + } else { + Err(syscall::Error::new(syscall::EWOULDBLOCK)) + } + } + + fn fevent(&mut self, fd: usize, events: usize) -> syscall::Result { + trace!("fevent {}", fd); + let handle = self.0 + .udp_sockets + .get_mut(&fd) + .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; + handle.events = events; + Ok(fd) + } + + fn fsync(&mut self, fd: usize) -> syscall::Result { + trace!("fsync {}", fd); + { + let _handle = self.0 + .udp_sockets .get_mut(&fd) .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; } @@ -291,3 +451,14 @@ fn post_fevent(scheme_file: &mut File, fd: usize, event: usize, data_len: usize) .map(|_| ()) .map_err(|e| Error::from_io_error(e, "failed to post fevent")) } + +fn parse_socket(socket: &str) -> (Ipv4Addr, u16) { + let mut socket_parts = socket.split(":"); + let host = Ipv4Addr::from_str(socket_parts.next().unwrap_or("")).unwrap(); + let port = socket_parts + .next() + .unwrap_or("") + .parse::() + .unwrap_or(0); + (host, port) +} From 0c5fff907c693e83ee535406da227a80bba5a49c Mon Sep 17 00:00:00 2001 From: Egor Karavaev Date: Mon, 18 Sep 2017 21:53:06 +0300 Subject: [PATCH 027/155] Factor out logger. --- src/smolnetd/logger.rs | 22 ++++++++++++++++++++++ src/smolnetd/main.rs | 23 +++-------------------- 2 files changed, 25 insertions(+), 20 deletions(-) create mode 100644 src/smolnetd/logger.rs diff --git a/src/smolnetd/logger.rs b/src/smolnetd/logger.rs new file mode 100644 index 0000000000..0fd36d9b1b --- /dev/null +++ b/src/smolnetd/logger.rs @@ -0,0 +1,22 @@ +use log::{set_logger_raw, Log, LogLevelFilter, LogMetadata, LogRecord}; + +struct Logger; + +impl Log for Logger { + fn enabled(&self, _: &LogMetadata) -> bool { + true + } + + fn log(&self, record: &LogRecord) { + println!("{}: {}", record.level(), record.args()); + } +} + +pub fn init_logger() { + unsafe { + set_logger_raw(|max_log_level| { + max_log_level.set(LogLevelFilter::Trace); + &Logger + }).expect("Can't initialize logger"); + } +} diff --git a/src/smolnetd/main.rs b/src/smolnetd/main.rs index cdf6723b27..cfa84de487 100644 --- a/src/smolnetd/main.rs +++ b/src/smolnetd/main.rs @@ -17,30 +17,12 @@ use std::rc::Rc; mod error; mod device; mod scheme; - -struct SimpleLogger; - -impl log::Log for SimpleLogger { - fn enabled(&self, _metadata: &log::LogMetadata) -> bool { - true - } - - fn log(&self, record: &log::LogRecord) { - if self.enabled(record.metadata()) { - println!("{} : {}", record.level(), record.args()); - } - } -} +mod logger; fn run() -> Result<()> { use syscall::flag::*; - unsafe { - log::set_logger_raw(|max_log_level| { - max_log_level.set(log::LogLevelFilter::Trace); - &SimpleLogger - }).expect("Can't initialize logger"); - } + logger::init_logger(); // if unsafe { syscall::clone(0).unwrap() } != 0 { // return Ok(()); @@ -73,6 +55,7 @@ fn run() -> Result<()> { File::from_raw_fd(udp_fd), ) }; + let smolnetd = Rc::new(RefCell::new( Smolnetd::new(network_file, ip_file, udp_file, time_file), )); From 203fa64580f4ecfa98afbaedb28473e6b58dcc73 Mon Sep 17 00:00:00 2001 From: Egor Karavaev Date: Mon, 18 Sep 2017 23:26:16 +0300 Subject: [PATCH 028/155] Add BufferPool. --- src/smolnetd/buffer_pool.rs | 92 +++++++++++++++++++++++++++++++++++++ src/smolnetd/device.rs | 7 +-- src/smolnetd/main.rs | 1 + src/smolnetd/scheme.rs | 31 +++++++------ 4 files changed, 115 insertions(+), 16 deletions(-) create mode 100644 src/smolnetd/buffer_pool.rs diff --git a/src/smolnetd/buffer_pool.rs b/src/smolnetd/buffer_pool.rs new file mode 100644 index 0000000000..2bd2e475c5 --- /dev/null +++ b/src/smolnetd/buffer_pool.rs @@ -0,0 +1,92 @@ +use std::ops::{Deref, DerefMut, Drop}; +use std::rc::Rc; +use std::cell::RefCell; +use std::mem::swap; + +type BufferStack = Rc>>>; + +pub struct Buffer { + buffer: Vec, + stack: BufferStack, +} + +impl Buffer { + pub fn resize(&mut self, new_len: usize) { + self.buffer.resize(new_len, 0u8); + } +} + +impl AsRef<[u8]> for Buffer { + fn as_ref(&self) -> &[u8] { + &self.buffer + } +} + +impl AsMut<[u8]> for Buffer { + fn as_mut(&mut self) -> &mut [u8] { + &mut self.buffer + } +} + +impl Deref for Buffer { + type Target = [u8]; + + fn deref(&self) -> &Self::Target { + &self.buffer + } +} + +impl DerefMut for Buffer { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.buffer + } +} + +impl Drop for Buffer { + fn drop(&mut self) { + let mut tmp = vec![]; + swap(&mut tmp, &mut self.buffer); + { + let mut stack = self.stack.borrow_mut(); + trace!("Returning buffer: {}", stack.len()); + stack.push(tmp); + } + } +} + +pub struct BufferPool { + buffers_size: usize, + stack: BufferStack, +} + +impl BufferPool { + pub fn new(buffers_size: usize) -> BufferPool { + BufferPool { + buffers_size, + stack: Rc::new(RefCell::new(vec![])), + } + } + + pub fn get_buffer(&mut self) -> Buffer { + let buffer = match self.stack.borrow_mut().pop() { + None => { + trace!("Allocating ingress buffer"); + vec![0u8; self.buffers_size] + } + Some(mut v) => { + trace!("Reusing ingress buffer"); + // memsetting the buffer with `resize` would be a waste of time + let capacity = v.capacity(); + unsafe { + v.set_len(capacity); + } + v + } + }; + + Buffer { + buffer, + stack: self.stack.clone(), + } + } +} diff --git a/src/smolnetd/device.rs b/src/smolnetd/device.rs index 9ac0705aef..5589fc51b9 100644 --- a/src/smolnetd/device.rs +++ b/src/smolnetd/device.rs @@ -4,10 +4,11 @@ use std::cell::RefCell; use std::io::Write; use std::collections::VecDeque; use smoltcp; +use buffer_pool::Buffer; pub struct NetworkDevice { network_file: Rc>, - input_queue: Rc>>>, + input_queue: Rc>>, } impl NetworkDevice { @@ -15,7 +16,7 @@ impl NetworkDevice { pub fn new( network_file: Rc>, - input_queue: Rc>>>, + input_queue: Rc>>, ) -> NetworkDevice { NetworkDevice { network_file, @@ -48,7 +49,7 @@ impl Drop for TxBuffer { } impl smoltcp::phy::Device for NetworkDevice { - type RxBuffer = Vec; + type RxBuffer = Buffer; type TxBuffer = TxBuffer; fn limits(&self) -> smoltcp::phy::DeviceLimits { diff --git a/src/smolnetd/main.rs b/src/smolnetd/main.rs index cfa84de487..4b84242e03 100644 --- a/src/smolnetd/main.rs +++ b/src/smolnetd/main.rs @@ -15,6 +15,7 @@ use std::process; use std::rc::Rc; mod error; +mod buffer_pool; mod device; mod scheme; mod logger; diff --git a/src/smolnetd/scheme.rs b/src/smolnetd/scheme.rs index 74cc29cdf3..ac8596128d 100644 --- a/src/smolnetd/scheme.rs +++ b/src/smolnetd/scheme.rs @@ -1,5 +1,3 @@ -use device::NetworkDevice; -use error::{Error, Result}; use netutils::{getcfg, MacAddr}; use smoltcp; use std::collections::{BTreeMap, VecDeque}; @@ -15,6 +13,10 @@ use smoltcp::socket::AsSocket; use syscall::SchemeMut; use syscall; +use device::NetworkDevice; +use error::{Error, Result}; +use buffer_pool::{Buffer, BufferPool}; + struct RawHandle { flags: usize, events: usize, @@ -43,14 +45,16 @@ pub struct Smolnetd { raw_sockets: BTreeMap, udp_sockets: BTreeMap, - input_queue: Rc>>>, + input_queue: Rc>>, + input_buffer_pool: BufferPool, } struct IpScheme<'a>(&'a mut Smolnetd); struct UdpScheme<'a>(&'a mut Smolnetd); impl Smolnetd { - const IP_BUFFER_SIZE: usize = 128; + const INGRESS_PACKET_SIZE: usize = 2048; + const SOCKET_BUFFER_SIZE: usize = 128; //packets const CHECK_TIMEOUT_MS: i64 = 1000; pub fn new(network_file: File, ip_file: File, udp_file: File, time_file: File) -> Smolnetd { @@ -93,6 +97,7 @@ impl Smolnetd { next_fd: 0, input_queue, network_file, + input_buffer_pool: BufferPool::new(Self::INGRESS_PACKET_SIZE), } } @@ -155,7 +160,7 @@ impl Smolnetd { fn read_frames(&mut self) -> Result { let mut total_frames = 0; loop { - let mut buffer = vec![0; 65536]; + let mut buffer = self.input_buffer_pool.get_buffer(); let count = self.network_file .borrow_mut() .read(&mut buffer) @@ -166,7 +171,7 @@ impl Smolnetd { break; } trace!("got frame {}", count); - buffer.resize(count, 0); + buffer.resize(count); self.input_queue.borrow_mut().push_back(buffer); total_frames += 1; } @@ -206,9 +211,9 @@ impl<'a> syscall::SchemeMut for IpScheme<'a> { let path = str::from_utf8(url).or_else(|_| Err(syscall::Error::new(syscall::EINVAL)))?; let proto = u8::from_str_radix(path, 16).or(Err(syscall::Error::new(syscall::ENOENT)))?; - let mut rx_packets = Vec::with_capacity(Smolnetd::IP_BUFFER_SIZE); - let mut tx_packets = Vec::with_capacity(Smolnetd::IP_BUFFER_SIZE); - for _ in 0..Smolnetd::IP_BUFFER_SIZE { + let mut rx_packets = Vec::with_capacity(Smolnetd::SOCKET_BUFFER_SIZE); + let mut tx_packets = Vec::with_capacity(Smolnetd::SOCKET_BUFFER_SIZE); + for _ in 0..Smolnetd::SOCKET_BUFFER_SIZE { rx_packets.push(smoltcp::socket::RawPacketBuffer::new( vec![0; NetworkDevice::MTU], )); @@ -269,7 +274,6 @@ impl<'a> syscall::SchemeMut for IpScheme<'a> { } fn read(&mut self, fd: usize, buf: &mut [u8]) -> syscall::Result { - trace!("Read {}", fd); use smoltcp::socket::AsSocket; let handle = self.0 @@ -280,6 +284,7 @@ impl<'a> syscall::SchemeMut for IpScheme<'a> { self.0.socket_set.get_mut(handle.socket_handle).as_socket(); if socket.can_recv() { let length = socket.recv_slice(buf).expect("Can't receive slice"); + trace!("Read fd {} len {}", fd, length); Ok(length) } else if handle.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { Ok(0) @@ -322,9 +327,9 @@ impl<'a> syscall::SchemeMut for UdpScheme<'a> { let (remote_ip, remote_port) = parse_socket(parts.next().unwrap_or("")); let (local_ip, local_port) = parse_socket(parts.next().unwrap_or("")); - let mut rx_packets = Vec::with_capacity(Smolnetd::IP_BUFFER_SIZE); - let mut tx_packets = Vec::with_capacity(Smolnetd::IP_BUFFER_SIZE); - for _ in 0..Smolnetd::IP_BUFFER_SIZE { + let mut rx_packets = Vec::with_capacity(Smolnetd::SOCKET_BUFFER_SIZE); + let mut tx_packets = Vec::with_capacity(Smolnetd::SOCKET_BUFFER_SIZE); + for _ in 0..Smolnetd::SOCKET_BUFFER_SIZE { rx_packets.push(smoltcp::socket::UdpPacketBuffer::new( vec![0; NetworkDevice::MTU], )); From 05650efcb170f209552f544a7c4a8ee708d5449c Mon Sep 17 00:00:00 2001 From: Egor Karavaev Date: Tue, 19 Sep 2017 00:42:37 +0300 Subject: [PATCH 029/155] Split scheme.rs. --- src/smolnetd/device.rs | 11 +- src/smolnetd/main.rs | 11 +- src/smolnetd/scheme.rs | 469 ------------------------------------- src/smolnetd/scheme/ip.rs | 148 ++++++++++++ src/smolnetd/scheme/mod.rs | 205 ++++++++++++++++ src/smolnetd/scheme/udp.rs | 171 ++++++++++++++ 6 files changed, 536 insertions(+), 479 deletions(-) delete mode 100644 src/smolnetd/scheme.rs create mode 100644 src/smolnetd/scheme/ip.rs create mode 100644 src/smolnetd/scheme/mod.rs create mode 100644 src/smolnetd/scheme/udp.rs diff --git a/src/smolnetd/device.rs b/src/smolnetd/device.rs index 5589fc51b9..37cbb9d5c0 100644 --- a/src/smolnetd/device.rs +++ b/src/smolnetd/device.rs @@ -1,9 +1,10 @@ -use std::rc::Rc; -use std::fs::File; -use std::cell::RefCell; -use std::io::Write; -use std::collections::VecDeque; use smoltcp; +use std::cell::RefCell; +use std::collections::VecDeque; +use std::fs::File; +use std::io::Write; +use std::rc::Rc; + use buffer_pool::Buffer; pub struct NetworkDevice { diff --git a/src/smolnetd/main.rs b/src/smolnetd/main.rs index 4b84242e03..77dcc103f3 100644 --- a/src/smolnetd/main.rs +++ b/src/smolnetd/main.rs @@ -5,20 +5,21 @@ extern crate netutils; extern crate smoltcp; extern crate syscall; -use error::{Error, Result}; -use event::EventQueue; -use scheme::Smolnetd; use std::cell::RefCell; use std::fs::File; use std::os::unix::io::{FromRawFd, RawFd}; use std::process; use std::rc::Rc; -mod error; +use error::{Error, Result}; +use event::EventQueue; +use scheme::Smolnetd; + mod buffer_pool; mod device; -mod scheme; +mod error; mod logger; +mod scheme; fn run() -> Result<()> { use syscall::flag::*; diff --git a/src/smolnetd/scheme.rs b/src/smolnetd/scheme.rs deleted file mode 100644 index ac8596128d..0000000000 --- a/src/smolnetd/scheme.rs +++ /dev/null @@ -1,469 +0,0 @@ -use netutils::{getcfg, MacAddr}; -use smoltcp; -use std::collections::{BTreeMap, VecDeque}; -use std::fs::File; -use std::io::{Read, Write}; -use std::mem; -use std::net::Ipv4Addr; -use std::str::FromStr; -use std::time::Instant; -use std::rc::Rc; -use std::cell::RefCell; -use smoltcp::socket::AsSocket; -use syscall::SchemeMut; -use syscall; - -use device::NetworkDevice; -use error::{Error, Result}; -use buffer_pool::{Buffer, BufferPool}; - -struct RawHandle { - flags: usize, - events: usize, - socket_handle: smoltcp::socket::SocketHandle, -} - -struct UdpHandle { - flags: usize, - events: usize, - remote_endpoint: smoltcp::wire::IpEndpoint, - socket_handle: smoltcp::socket::SocketHandle, -} - -pub struct Smolnetd { - network_file: Rc>, - ip_file: File, - udp_file: File, - time_file: File, - - iface: smoltcp::iface::EthernetInterface<'static, 'static, 'static, NetworkDevice>, - socket_set: smoltcp::socket::SocketSet<'static, 'static, 'static>, - - startup_time: Instant, - next_fd: usize, - - raw_sockets: BTreeMap, - udp_sockets: BTreeMap, - - input_queue: Rc>>, - input_buffer_pool: BufferPool, -} - -struct IpScheme<'a>(&'a mut Smolnetd); -struct UdpScheme<'a>(&'a mut Smolnetd); - -impl Smolnetd { - const INGRESS_PACKET_SIZE: usize = 2048; - const SOCKET_BUFFER_SIZE: usize = 128; //packets - const CHECK_TIMEOUT_MS: i64 = 1000; - - pub fn new(network_file: File, ip_file: File, udp_file: File, time_file: File) -> Smolnetd { - let arp_cache = smoltcp::iface::SliceArpCache::new(vec![Default::default(); 8]); - //TODO Use smoltcp::wire::EthernetAddress::from_str - let mac_addr = MacAddr::from_str(&getcfg("mac").unwrap().trim()); - let hardware_addr = smoltcp::wire::EthernetAddress(mac_addr.bytes); - //TODO Use smoltcp::wire::Ipv4Addr::from_str - let ip_bytes = Ipv4Addr::from_str(&getcfg("ip").unwrap().trim()) - .unwrap() - .octets(); - let protocol_addrs = [ - smoltcp::wire::IpAddress::Ipv4(smoltcp::wire::Ipv4Address::from_bytes(&ip_bytes)), - ]; - let default_gw = smoltcp::wire::IpAddress::Ipv4(smoltcp::wire::Ipv4Address::from_bytes( - &Ipv4Addr::from_str(&getcfg("ip_router").unwrap().trim()) - .unwrap() - .octets(), - )); - trace!("mac {:?} ip {:?}", hardware_addr, protocol_addrs); - let input_queue = Rc::new(RefCell::new(VecDeque::new())); - let network_file = Rc::new(RefCell::new(network_file)); - let network_device = NetworkDevice::new(network_file.clone(), input_queue.clone()); - let mut iface = smoltcp::iface::EthernetInterface::new( - Box::new(network_device), - Box::new(arp_cache) as Box, - hardware_addr, - protocol_addrs, - ); - iface.set_default_gateway(24, Some(default_gw)); - Smolnetd { - iface, - socket_set: smoltcp::socket::SocketSet::new(vec![]), - startup_time: Instant::now(), - ip_file, - udp_file, - time_file, - raw_sockets: BTreeMap::new(), - udp_sockets: BTreeMap::new(), - next_fd: 0, - input_queue, - network_file, - input_buffer_pool: BufferPool::new(Self::INGRESS_PACKET_SIZE), - } - } - - pub fn on_network_scheme_event(&mut self) -> Result> { - if self.read_frames()? > 0 { - self.poll().map(Some)?; - } - Ok(None) - } - - pub fn on_ip_scheme_event(&mut self) -> Result> { - loop { - let mut packet = syscall::Packet::default(); - if self.ip_file.read(&mut packet)? == 0 { - break; - } - IpScheme(self).handle(&mut packet); - self.ip_file.write_all(&packet)?; - } - Ok(None) - } - - pub fn on_udp_scheme_event(&mut self) -> Result> { - loop { - let mut packet = syscall::Packet::default(); - if self.udp_file.read(&mut packet)? == 0 { - break; - } - UdpScheme(self).handle(&mut packet); - self.udp_file.write_all(&packet)?; - } - Ok(None) - } - - pub fn on_time_event(&mut self) -> Result> { - let mut time = syscall::data::TimeSpec::default(); - if self.time_file.read(&mut time)? < mem::size_of::() { - panic!(); - } - let mut time_ms = time.tv_sec * 1000i64 + (time.tv_nsec as i64) / 1_000_000i64; - time_ms += Smolnetd::CHECK_TIMEOUT_MS; - time.tv_sec = time_ms / 1000; - time.tv_nsec = ((time_ms % 1000) * 1_000_00) as i32; - self.time_file - .write_all(&time) - .map_err(|e| Error::from_io_error(e, "Failed to write to time file"))?; - - self.poll().map(Some)?; - Ok(None) - } - - fn poll(&mut self) -> Result<()> { - let timestamp = self.get_timestamp(); - self.iface - .poll(&mut self.socket_set, timestamp) - .expect("poll error"); - self.notify_raw_sockets() - } - - fn read_frames(&mut self) -> Result { - let mut total_frames = 0; - loop { - let mut buffer = self.input_buffer_pool.get_buffer(); - let count = self.network_file - .borrow_mut() - .read(&mut buffer) - .map_err(|e| { - Error::from_io_error(e, "Failed to read from network file") - })?; - if count == 0 { - break; - } - trace!("got frame {}", count); - buffer.resize(count); - self.input_queue.borrow_mut().push_back(buffer); - total_frames += 1; - } - Ok(total_frames) - } - - fn get_timestamp(&self) -> u64 { - let duration = Instant::now().duration_since(self.startup_time); - let duration_ms = (duration.as_secs() * 1000) + (duration.subsec_nanos() / 1000000) as u64; - duration_ms - } - - fn network_fsync(&mut self) -> syscall::Result { - use std::os::unix::io::AsRawFd; - syscall::fsync(self.network_file.borrow_mut().as_raw_fd() as usize) - } - - fn notify_raw_sockets(&mut self) -> Result<()> { - for (&fd, ref handle) in &self.raw_sockets { - let socket: &mut smoltcp::socket::RawSocket = - self.socket_set.get_mut(handle.socket_handle).as_socket(); - if socket.can_send() { - post_fevent(&mut self.ip_file, fd, syscall::EVENT_READ, 1)?; - } - } - Ok(()) - } -} - -impl<'a> syscall::SchemeMut for IpScheme<'a> { - fn open(&mut self, url: &[u8], flags: usize, uid: u32, _gid: u32) -> syscall::Result { - use std::str; - - if uid != 0 { - return Err(syscall::Error::new(syscall::EACCES)); - } - let path = str::from_utf8(url).or_else(|_| Err(syscall::Error::new(syscall::EINVAL)))?; - let proto = u8::from_str_radix(path, 16).or(Err(syscall::Error::new(syscall::ENOENT)))?; - - let mut rx_packets = Vec::with_capacity(Smolnetd::SOCKET_BUFFER_SIZE); - let mut tx_packets = Vec::with_capacity(Smolnetd::SOCKET_BUFFER_SIZE); - for _ in 0..Smolnetd::SOCKET_BUFFER_SIZE { - rx_packets.push(smoltcp::socket::RawPacketBuffer::new( - vec![0; NetworkDevice::MTU], - )); - tx_packets.push(smoltcp::socket::RawPacketBuffer::new( - vec![0; NetworkDevice::MTU], - )); - } - let rx_buffer = smoltcp::socket::RawSocketBuffer::new(rx_packets); - let tx_buffer = smoltcp::socket::RawSocketBuffer::new(tx_packets); - let raw_socket = smoltcp::socket::RawSocket::new( - smoltcp::wire::IpVersion::Ipv4, - smoltcp::wire::IpProtocol::from(proto), - rx_buffer, - tx_buffer, - ); - - let socket_handle = self.0.socket_set.add(raw_socket); - let id = self.0.next_fd; - trace!("Open {} -> {}", path, id); - - self.0.raw_sockets.insert( - id, - RawHandle { - flags, - events: 0, - socket_handle, - }, - ); - self.0.next_fd += 1; - Ok(id) - } - - fn close(&mut self, fd: usize) -> syscall::Result { - trace!("Close {}", fd); - let socket_handle = { - let handle = self.0 - .raw_sockets - .get(&fd) - .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; - handle.socket_handle - }; - self.0.raw_sockets.remove(&fd); - self.0.socket_set.remove(socket_handle); - Ok(0) - } - - fn write(&mut self, fd: usize, buf: &[u8]) -> syscall::Result { - trace!("Write {} len {}", fd, buf.len()); - - let handle = self.0 - .raw_sockets - .get(&fd) - .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; - let socket: &mut smoltcp::socket::RawSocket = - self.0.socket_set.get_mut(handle.socket_handle).as_socket(); - socket.send_slice(buf).expect("Can't send slice"); - Ok(buf.len()) - } - - fn read(&mut self, fd: usize, buf: &mut [u8]) -> syscall::Result { - use smoltcp::socket::AsSocket; - - let handle = self.0 - .raw_sockets - .get(&fd) - .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; - let socket: &mut smoltcp::socket::RawSocket = - self.0.socket_set.get_mut(handle.socket_handle).as_socket(); - if socket.can_recv() { - let length = socket.recv_slice(buf).expect("Can't receive slice"); - trace!("Read fd {} len {}", fd, length); - Ok(length) - } else if handle.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { - Ok(0) - } else { - Err(syscall::Error::new(syscall::EWOULDBLOCK)) - } - } - - fn fevent(&mut self, fd: usize, events: usize) -> syscall::Result { - trace!("fevent {}", fd); - let handle = self.0 - .raw_sockets - .get_mut(&fd) - .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; - handle.events = events; - Ok(fd) - } - - fn fsync(&mut self, fd: usize) -> syscall::Result { - trace!("fsync {}", fd); - { - let _handle = self.0 - .raw_sockets - .get_mut(&fd) - .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; - } - self.0.network_fsync() - } -} - -impl<'a> syscall::SchemeMut for UdpScheme<'a> { - fn open(&mut self, url: &[u8], flags: usize, uid: u32, _gid: u32) -> syscall::Result { - use std::str; - - if uid != 0 { - return Err(syscall::Error::new(syscall::EACCES)); - } - let path = str::from_utf8(url).or_else(|_| Err(syscall::Error::new(syscall::EINVAL)))?; - let mut parts = path.split("/"); - let (remote_ip, remote_port) = parse_socket(parts.next().unwrap_or("")); - let (local_ip, local_port) = parse_socket(parts.next().unwrap_or("")); - - let mut rx_packets = Vec::with_capacity(Smolnetd::SOCKET_BUFFER_SIZE); - let mut tx_packets = Vec::with_capacity(Smolnetd::SOCKET_BUFFER_SIZE); - for _ in 0..Smolnetd::SOCKET_BUFFER_SIZE { - rx_packets.push(smoltcp::socket::UdpPacketBuffer::new( - vec![0; NetworkDevice::MTU], - )); - tx_packets.push(smoltcp::socket::UdpPacketBuffer::new( - vec![0; NetworkDevice::MTU], - )); - } - let rx_buffer = smoltcp::socket::UdpSocketBuffer::new(rx_packets); - let tx_buffer = smoltcp::socket::UdpSocketBuffer::new(tx_packets); - let mut udp_socket = smoltcp::socket::UdpSocket::new(rx_buffer, tx_buffer); - - if !local_ip.is_unspecified() && local_port != 0 { - let udp_socket: &mut smoltcp::socket::UdpSocket = udp_socket.as_socket(); - udp_socket.bind(smoltcp::wire::IpEndpoint::new( - smoltcp::wire::IpAddress::Ipv4( - smoltcp::wire::Ipv4Address::from_bytes(&local_ip.octets()), - ), - local_port, - )).unwrap(); - } - - let socket_handle = self.0.socket_set.add(udp_socket); - let id = self.0.next_fd; - trace!("Open {} -> {}", path, id); - - self.0.udp_sockets.insert( - id, - UdpHandle { - flags, - events: 0, - socket_handle, - remote_endpoint: smoltcp::wire::IpEndpoint::new( - smoltcp::wire::IpAddress::Ipv4( - smoltcp::wire::Ipv4Address::from_bytes(&remote_ip.octets()), - ), - remote_port, - ), - }, - ); - self.0.next_fd += 1; - Ok(id) - } - - fn close(&mut self, fd: usize) -> syscall::Result { - trace!("Close {}", fd); - let socket_handle = { - let handle = self.0 - .udp_sockets - .get(&fd) - .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; - handle.socket_handle - }; - self.0.udp_sockets.remove(&fd); - self.0.socket_set.remove(socket_handle); - Ok(0) - } - - fn write(&mut self, fd: usize, buf: &[u8]) -> syscall::Result { - trace!("Write {} len {}", fd, buf.len()); - - let handle = self.0 - .udp_sockets - .get(&fd) - .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; - let socket: &mut smoltcp::socket::UdpSocket = - self.0.socket_set.get_mut(handle.socket_handle).as_socket(); - socket.send_slice(buf, handle.remote_endpoint).expect("Can't send slice"); - Ok(buf.len()) - } - - fn read(&mut self, fd: usize, buf: &mut [u8]) -> syscall::Result { - trace!("Read {}", fd); - - let handle = self.0 - .udp_sockets - .get(&fd) - .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; - let socket: &mut smoltcp::socket::UdpSocket = - self.0.socket_set.get_mut(handle.socket_handle).as_socket(); - if socket.can_recv() { - let (length, _) = socket.recv_slice(buf).expect("Can't receive slice"); - Ok(length) - } else if handle.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { - Ok(0) - } else { - Err(syscall::Error::new(syscall::EWOULDBLOCK)) - } - } - - fn fevent(&mut self, fd: usize, events: usize) -> syscall::Result { - trace!("fevent {}", fd); - let handle = self.0 - .udp_sockets - .get_mut(&fd) - .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; - handle.events = events; - Ok(fd) - } - - fn fsync(&mut self, fd: usize) -> syscall::Result { - trace!("fsync {}", fd); - { - let _handle = self.0 - .udp_sockets - .get_mut(&fd) - .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; - } - self.0.network_fsync() - } -} - -fn post_fevent(scheme_file: &mut File, fd: usize, event: usize, data_len: usize) -> Result<()> { - scheme_file - .write(&syscall::Packet { - id: 0, - pid: 0, - uid: 0, - gid: 0, - a: syscall::number::SYS_FEVENT, - b: fd, - c: event, - d: data_len, - }) - .map(|_| ()) - .map_err(|e| Error::from_io_error(e, "failed to post fevent")) -} - -fn parse_socket(socket: &str) -> (Ipv4Addr, u16) { - let mut socket_parts = socket.split(":"); - let host = Ipv4Addr::from_str(socket_parts.next().unwrap_or("")).unwrap(); - let port = socket_parts - .next() - .unwrap_or("") - .parse::() - .unwrap_or(0); - (host, port) -} diff --git a/src/smolnetd/scheme/ip.rs b/src/smolnetd/scheme/ip.rs new file mode 100644 index 0000000000..9264d58006 --- /dev/null +++ b/src/smolnetd/scheme/ip.rs @@ -0,0 +1,148 @@ +use smoltcp::socket::{AsSocket, RawPacketBuffer, RawSocket, RawSocketBuffer, SocketHandle}; +use smoltcp::wire::{IpProtocol, IpVersion}; +use std::collections::BTreeMap; +use syscall; + +use device::NetworkDevice; +use error::Result; +use super::{Smolnetd, SocketSet}; + +pub struct RawHandle { + flags: usize, + events: usize, + socket_handle: SocketHandle, +} + +pub struct IpScheme { + next_ip_fd: usize, + raw_sockets: BTreeMap, + socket_set: SocketSet, +} + +impl IpScheme { + pub fn new(socket_set: SocketSet) -> IpScheme { + IpScheme { + next_ip_fd: 1, + raw_sockets: BTreeMap::new(), + socket_set, + } + } + + pub fn notify_ready_sockets Result<()>>(&self, mut f: F) -> Result<()> { + for (&fd, ref handle) in &self.raw_sockets { + let mut socket_set = self.socket_set.borrow_mut(); + let socket: &mut RawSocket = socket_set.get_mut(handle.socket_handle).as_socket(); + if socket.can_send() { + f(fd)? + } + } + Ok(()) + } +} + +impl<'a> syscall::SchemeMut for IpScheme { + fn open(&mut self, url: &[u8], flags: usize, uid: u32, _gid: u32) -> syscall::Result { + use std::str; + + if uid != 0 { + return Err(syscall::Error::new(syscall::EACCES)); + } + let path = str::from_utf8(url).or_else(|_| Err(syscall::Error::new(syscall::EINVAL)))?; + let proto = u8::from_str_radix(path, 16).or(Err(syscall::Error::new(syscall::ENOENT)))?; + + let mut rx_packets = Vec::with_capacity(Smolnetd::SOCKET_BUFFER_SIZE); + let mut tx_packets = Vec::with_capacity(Smolnetd::SOCKET_BUFFER_SIZE); + for _ in 0..Smolnetd::SOCKET_BUFFER_SIZE { + rx_packets.push(RawPacketBuffer::new(vec![0; NetworkDevice::MTU])); + tx_packets.push(RawPacketBuffer::new(vec![0; NetworkDevice::MTU])); + } + let rx_buffer = RawSocketBuffer::new(rx_packets); + let tx_buffer = RawSocketBuffer::new(tx_packets); + let raw_socket = RawSocket::new( + IpVersion::Ipv4, + IpProtocol::from(proto), + rx_buffer, + tx_buffer, + ); + + let socket_handle = self.socket_set.borrow_mut().add(raw_socket); + let id = self.next_ip_fd; + trace!("IP Open {} -> {}", path, id); + + self.raw_sockets.insert( + id, + RawHandle { + flags, + events: 0, + socket_handle, + }, + ); + self.next_ip_fd += 1; + Ok(id) + } + + fn close(&mut self, fd: usize) -> syscall::Result { + trace!("IP Close {}", fd); + let socket_handle = { + let handle = self.raw_sockets + .get(&fd) + .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; + handle.socket_handle + }; + self.raw_sockets.remove(&fd); + self.socket_set.borrow_mut().remove(socket_handle); + Ok(0) + } + + fn write(&mut self, fd: usize, buf: &[u8]) -> syscall::Result { + trace!("IP Write {} len {}", fd, buf.len()); + + let handle = self.raw_sockets + .get(&fd) + .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; + let mut socket_set = self.socket_set.borrow_mut(); + let socket: &mut RawSocket = socket_set.get_mut(handle.socket_handle).as_socket(); + socket.send_slice(buf).expect("Can't send slice"); + Ok(buf.len()) + } + + fn read(&mut self, fd: usize, buf: &mut [u8]) -> syscall::Result { + use smoltcp::socket::AsSocket; + + let handle = self.raw_sockets + .get(&fd) + .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; + let mut socket_set = self.socket_set.borrow_mut(); + let socket: &mut RawSocket = socket_set.get_mut(handle.socket_handle).as_socket(); + if socket.can_recv() { + let length = socket.recv_slice(buf).expect("Can't receive slice"); + trace!("IP Read fd {} len {}", fd, length); + Ok(length) + } else if handle.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { + Ok(0) + } else { + Err(syscall::Error::new(syscall::EWOULDBLOCK)) + } + } + + fn fevent(&mut self, fd: usize, events: usize) -> syscall::Result { + trace!("IP fevent {}", fd); + let handle = self.raw_sockets + .get_mut(&fd) + .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; + handle.events = events; + Ok(fd) + } + + fn fsync(&mut self, fd: usize) -> syscall::Result { + trace!("IP fsync {}", fd); + { + let _handle = self.raw_sockets + .get_mut(&fd) + .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; + } + Ok(0) + // TODO Implement fsyncing + // self.0.network_fsync() + } +} diff --git a/src/smolnetd/scheme/mod.rs b/src/smolnetd/scheme/mod.rs new file mode 100644 index 0000000000..51a1522355 --- /dev/null +++ b/src/smolnetd/scheme/mod.rs @@ -0,0 +1,205 @@ +use netutils::{getcfg, MacAddr}; +use smoltcp; +use std::cell::RefCell; +use std::collections::VecDeque; +use std::fs::File; +use std::io::{Read, Write}; +use std::mem; +use std::net::Ipv4Addr; +use std::rc::Rc; +use std::str::FromStr; +use std::time::Instant; +use syscall::SchemeMut; +use syscall; + +use buffer_pool::{Buffer, BufferPool}; +use device::NetworkDevice; +use error::{Error, Result}; +use self::ip::IpScheme; +use self::udp::UdpScheme; + +mod ip; +mod udp; + +type SocketSet = Rc>>; + +pub struct Smolnetd { + network_file: Rc>, + ip_file: File, + udp_file: File, + time_file: File, + + iface: smoltcp::iface::EthernetInterface<'static, 'static, 'static, NetworkDevice>, + socket_set: SocketSet, + + startup_time: Instant, + + ip_scheme: IpScheme, + udp_scheme: UdpScheme, + + input_queue: Rc>>, + input_buffer_pool: BufferPool, +} + +impl Smolnetd { + const INGRESS_PACKET_SIZE: usize = 2048; + const SOCKET_BUFFER_SIZE: usize = 128; //packets + const CHECK_TIMEOUT_MS: i64 = 1000; + + pub fn new(network_file: File, ip_file: File, udp_file: File, time_file: File) -> Smolnetd { + let arp_cache = smoltcp::iface::SliceArpCache::new(vec![Default::default(); 8]); + //TODO Use smoltcp::wire::EthernetAddress::from_str + let mac_addr = MacAddr::from_str(&getcfg("mac").unwrap().trim()); + let hardware_addr = smoltcp::wire::EthernetAddress(mac_addr.bytes); + //TODO Use smoltcp::wire::Ipv4Addr::from_str + let ip_bytes = Ipv4Addr::from_str(&getcfg("ip").unwrap().trim()) + .unwrap() + .octets(); + let protocol_addrs = [ + smoltcp::wire::IpAddress::Ipv4(smoltcp::wire::Ipv4Address::from_bytes(&ip_bytes)), + ]; + let default_gw = smoltcp::wire::IpAddress::Ipv4(smoltcp::wire::Ipv4Address::from_bytes( + &Ipv4Addr::from_str(&getcfg("ip_router").unwrap().trim()) + .unwrap() + .octets(), + )); + trace!("mac {:?} ip {:?}", hardware_addr, protocol_addrs); + let input_queue = Rc::new(RefCell::new(VecDeque::new())); + let network_file = Rc::new(RefCell::new(network_file)); + let network_device = NetworkDevice::new(network_file.clone(), input_queue.clone()); + let mut iface = smoltcp::iface::EthernetInterface::new( + Box::new(network_device), + Box::new(arp_cache) as Box, + hardware_addr, + protocol_addrs, + ); + iface.set_default_gateway(24, Some(default_gw)); + let socket_set = Rc::new(RefCell::new(smoltcp::socket::SocketSet::new(vec![]))); + Smolnetd { + iface, + socket_set: socket_set.clone(), + startup_time: Instant::now(), + ip_file, + udp_file, + time_file, + ip_scheme: IpScheme::new(socket_set.clone()), + udp_scheme: UdpScheme::new(socket_set.clone()), + input_queue, + network_file, + input_buffer_pool: BufferPool::new(Self::INGRESS_PACKET_SIZE), + } + } + + pub fn on_network_scheme_event(&mut self) -> Result> { + if self.read_frames()? > 0 { + self.poll().map(Some)?; + } + Ok(None) + } + + pub fn on_ip_scheme_event(&mut self) -> Result> { + loop { + let mut packet = syscall::Packet::default(); + if self.ip_file.read(&mut packet)? == 0 { + break; + } + self.ip_scheme.handle(&mut packet); + self.ip_file.write_all(&packet)?; + } + Ok(None) + } + + pub fn on_udp_scheme_event(&mut self) -> Result> { + loop { + let mut packet = syscall::Packet::default(); + if self.udp_file.read(&mut packet)? == 0 { + break; + } + self.udp_scheme.handle(&mut packet); + self.udp_file.write_all(&packet)?; + } + Ok(None) + } + + pub fn on_time_event(&mut self) -> Result> { + let mut time = syscall::data::TimeSpec::default(); + if self.time_file.read(&mut time)? < mem::size_of::() { + panic!(); + } + let mut time_ms = time.tv_sec * 1000i64 + (time.tv_nsec as i64) / 1_000_000i64; + time_ms += Smolnetd::CHECK_TIMEOUT_MS; + time.tv_sec = time_ms / 1000; + time.tv_nsec = ((time_ms % 1000) * 1_000_00) as i32; + self.time_file + .write_all(&time) + .map_err(|e| Error::from_io_error(e, "Failed to write to time file"))?; + + self.poll().map(Some)?; + Ok(None) + } + + fn poll(&mut self) -> Result<()> { + let timestamp = self.get_timestamp(); + self.iface + .poll(&mut *self.socket_set.borrow_mut(), timestamp) + .expect("poll error"); + self.notify_raw_sockets() + } + + fn read_frames(&mut self) -> Result { + let mut total_frames = 0; + loop { + let mut buffer = self.input_buffer_pool.get_buffer(); + let count = self.network_file + .borrow_mut() + .read(&mut buffer) + .map_err(|e| { + Error::from_io_error(e, "Failed to read from network file") + })?; + if count == 0 { + break; + } + trace!("got frame {}", count); + buffer.resize(count); + self.input_queue.borrow_mut().push_back(buffer); + total_frames += 1; + } + Ok(total_frames) + } + + fn get_timestamp(&self) -> u64 { + let duration = Instant::now().duration_since(self.startup_time); + let duration_ms = (duration.as_secs() * 1000) + (duration.subsec_nanos() / 1000000) as u64; + duration_ms + } + + fn network_fsync(&mut self) -> syscall::Result { + use std::os::unix::io::AsRawFd; + syscall::fsync(self.network_file.borrow_mut().as_raw_fd() as usize) + } + + fn notify_raw_sockets(&mut self) -> Result<()> { + let ip_file = &mut self.ip_file; + self.ip_scheme + .notify_ready_sockets(|fd| post_fevent(ip_file, fd, syscall::EVENT_READ, 1))?; + let udp_file = &mut self.udp_file; + self.udp_scheme + .notify_ready_sockets(|fd| post_fevent(udp_file, fd, syscall::EVENT_READ, 1)) + } +} + +fn post_fevent(scheme_file: &mut File, fd: usize, event: usize, data_len: usize) -> Result<()> { + scheme_file + .write(&syscall::Packet { + id: 0, + pid: 0, + uid: 0, + gid: 0, + a: syscall::number::SYS_FEVENT, + b: fd, + c: event, + d: data_len, + }) + .map(|_| ()) + .map_err(|e| Error::from_io_error(e, "failed to post fevent")) +} diff --git a/src/smolnetd/scheme/udp.rs b/src/smolnetd/scheme/udp.rs new file mode 100644 index 0000000000..0d538f94d6 --- /dev/null +++ b/src/smolnetd/scheme/udp.rs @@ -0,0 +1,171 @@ +use netutils::Ipv4Addr; +use smoltcp::socket::{AsSocket, SocketHandle, UdpPacketBuffer, UdpSocket, UdpSocketBuffer}; +use smoltcp::wire::{IpAddress, IpEndpoint, Ipv4Address}; +use std::collections::BTreeMap; +use syscall; + +use device::NetworkDevice; +use error::Result; +use super::{Smolnetd, SocketSet}; + +pub struct UdpHandle { + flags: usize, + events: usize, + remote_endpoint: IpEndpoint, + pub socket_handle: SocketHandle, +} + +pub struct UdpScheme { + next_udp_fd: usize, + udp_sockets: BTreeMap, + socket_set: SocketSet, +} + +impl UdpScheme { + pub fn new(socket_set: SocketSet) -> UdpScheme { + UdpScheme { + next_udp_fd: 1, + udp_sockets: BTreeMap::new(), + socket_set, + } + } + + pub fn notify_ready_sockets Result<()>>(&self, mut f: F) -> Result<()> { + for (&fd, ref handle) in &self.udp_sockets { + let mut socket_set = self.socket_set.borrow_mut(); + let socket: &mut UdpSocket = socket_set.get_mut(handle.socket_handle).as_socket(); + if socket.can_send() { + f(fd)? + } + } + Ok(()) + } +} + +impl syscall::SchemeMut for UdpScheme { + fn open(&mut self, url: &[u8], flags: usize, _uid: u32, _gid: u32) -> syscall::Result { + use std::str; + + let path = str::from_utf8(url).or_else(|_| Err(syscall::Error::new(syscall::EINVAL)))?; + trace!("Udp open {} ", path); + let mut parts = path.split("/"); + let (remote_ip, remote_port) = parse_socket(parts.next().unwrap_or("")); + let (local_ip, local_port) = parse_socket(parts.next().unwrap_or("")); + + let mut rx_packets = Vec::with_capacity(Smolnetd::SOCKET_BUFFER_SIZE); + let mut tx_packets = Vec::with_capacity(Smolnetd::SOCKET_BUFFER_SIZE); + for _ in 0..Smolnetd::SOCKET_BUFFER_SIZE { + rx_packets.push(UdpPacketBuffer::new(vec![0; NetworkDevice::MTU])); + tx_packets.push(UdpPacketBuffer::new(vec![0; NetworkDevice::MTU])); + } + let rx_buffer = UdpSocketBuffer::new(rx_packets); + let tx_buffer = UdpSocketBuffer::new(tx_packets); + let mut udp_socket = UdpSocket::new(rx_buffer, tx_buffer); + + if local_ip != Ipv4Addr::NULL && local_port != 0 { + let udp_socket: &mut UdpSocket = udp_socket.as_socket(); + udp_socket + .bind(IpEndpoint::new( + IpAddress::Ipv4(Ipv4Address::from_bytes(&local_ip.bytes)), + local_port, + )) + .unwrap(); + } + + let socket_handle = self.socket_set.borrow_mut().add(udp_socket); + let id = self.next_udp_fd; + + self.udp_sockets.insert( + id, + UdpHandle { + flags, + events: 0, + socket_handle, + remote_endpoint: IpEndpoint::new( + IpAddress::Ipv4(Ipv4Address::from_bytes(&remote_ip.bytes)), + remote_port, + ), + }, + ); + self.next_udp_fd += 1; + trace!("Udp open fd {} ", id); + Ok(id) + } + + fn close(&mut self, fd: usize) -> syscall::Result { + trace!("Upd close {}", fd); + let socket_handle = { + let handle = self.udp_sockets + .get(&fd) + .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; + handle.socket_handle + }; + self.udp_sockets.remove(&fd); + self.socket_set.borrow_mut().remove(socket_handle); + Ok(0) + } + + fn write(&mut self, fd: usize, buf: &[u8]) -> syscall::Result { + trace!("Upd write {} len {}", fd, buf.len()); + + let handle = self.udp_sockets + .get(&fd) + .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; + let mut socket_set = self.socket_set.borrow_mut(); + let socket: &mut UdpSocket = socket_set.get_mut(handle.socket_handle).as_socket(); + socket + .send_slice(buf, handle.remote_endpoint) + .expect("Can't send slice"); + Ok(buf.len()) + } + + fn read(&mut self, fd: usize, buf: &mut [u8]) -> syscall::Result { + let handle = self.udp_sockets.get(&fd).ok_or_else(|| { + trace!("UDP read EBADF {}", fd); + syscall::Error::new(syscall::EBADF) + })?; + let mut socket_set = self.socket_set.borrow_mut(); + let socket: &mut UdpSocket = socket_set.get_mut(handle.socket_handle).as_socket(); + if socket.can_recv() { + let (length, _) = socket.recv_slice(buf).expect("Can't receive slice"); + trace!("Upd read {}", fd); + Ok(length) + } else if handle.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { + Ok(0) + } else { + Err(syscall::Error::new(syscall::EWOULDBLOCK)) + } + } + + fn fevent(&mut self, fd: usize, events: usize) -> syscall::Result { + trace!("udp fevent {}", fd); + let handle = self.udp_sockets + .get_mut(&fd) + .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; + handle.events = events; + Ok(fd) + } + + fn fsync(&mut self, fd: usize) -> syscall::Result { + trace!("udp fsync {}", fd); + { + let _handle = self.udp_sockets + .get_mut(&fd) + .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; + } + Ok(0) + // TODO Implement fsyncing + // self.0.network_fsync() + } +} + +fn parse_socket(socket: &str) -> (Ipv4Addr, u16) { + let mut socket_parts = socket.split(":"); + let host = Ipv4Addr::from_str(socket_parts.next().unwrap_or("")); + let port = socket_parts + .next() + .unwrap_or("") + .parse::() + .unwrap_or(0); + (host, port) +} From a15184ce1fc8bc8d8efed5cb2bbc1e55fbe3597d Mon Sep 17 00:00:00 2001 From: Egor Karavaev Date: Wed, 20 Sep 2017 00:23:22 +0300 Subject: [PATCH 030/155] Initial support for UDP options. --- Cargo.lock | 83 +++++++++++------------ src/smolnetd/scheme/udp.rs | 132 ++++++++++++++++++++++++++----------- 2 files changed, 130 insertions(+), 85 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8203619c13..dac3c45467 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6,22 +6,14 @@ dependencies = [ "netutils 0.1.0 (git+https://github.com/redox-os/netutils.git)", "rand 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", "redox_event 0.1.0 (git+https://github.com/redox-os/event.git)", - "redox_syscall 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", "smoltcp 0.4.0-pre (git+https://github.com/batonius/smoltcp.git?branch=default_route)", ] [[package]] name = "arg_parser" version = "0.1.0" -source = "git+https://github.com/redox-os/arg-parser.git#1b6a9505a1e9c39af1836ecbee293a987619a539" - -[[package]] -name = "base64" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", -] +source = "git+https://github.com/redox-os/arg-parser.git#288d2fd9ae27ed2c7a3aaf5a77cf07e2b2bd356c" [[package]] name = "base64" @@ -81,12 +73,12 @@ source = "git+https://github.com/redox-os/libextra.git#402932084acd5fef481294588 [[package]] name = "futures" -version = "0.1.14" +version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "gcc" -version = "0.3.53" +version = "0.3.54" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -96,10 +88,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "hyper" -version = "0.10.12" +version = "0.10.13" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "base64 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "base64 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "httparse 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -117,7 +109,7 @@ name = "hyper-rustls" version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "hyper 0.10.12 (registry+https://github.com/rust-lang/crates.io-index)", + "hyper 0.10.13 (registry+https://github.com/rust-lang/crates.io-index)", "rustls 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "webpki-roots 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -153,7 +145,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libc" -version = "0.2.29" +version = "0.2.31" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -199,17 +191,17 @@ dependencies = [ [[package]] name = "netutils" version = "0.1.0" -source = "git+https://github.com/redox-os/netutils.git#849b72c5b9e77a654a51521276dc6f2223a67aec" +source = "git+https://github.com/redox-os/netutils.git#ec1a835a9d4a95a8e41c4e994a540d298d897cd4" dependencies = [ "arg_parser 0.1.0 (git+https://github.com/redox-os/arg-parser.git)", "extra 0.1.0 (git+https://github.com/redox-os/libextra.git)", - "hyper 0.10.12 (registry+https://github.com/rust-lang/crates.io-index)", + "hyper 0.10.13 (registry+https://github.com/rust-lang/crates.io-index)", "hyper-rustls 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)", "ntpclient 0.0.1 (git+https://github.com/willem66745/ntpclient-rust)", "pbr 1.0.0 (git+https://github.com/a8m/pb)", "redox_event 0.1.0 (git+https://github.com/redox-os/event.git)", - "redox_syscall 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -227,7 +219,7 @@ name = "num_cpus" version = "1.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -236,7 +228,7 @@ version = "1.0.0" source = "git+https://github.com/a8m/pb#e9369ed2b94df4f554fe79c2643de41f7338475f" dependencies = [ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)", "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -252,7 +244,7 @@ name = "rand" version = "0.3.16" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)", "magenta 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -270,9 +262,9 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "coco 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -282,12 +274,12 @@ name = "redox_event" version = "0.1.0" source = "git+https://github.com/redox-os/event.git#42d552e4765efbfb4ec39ce174900d3f48548a70" dependencies = [ - "redox_syscall 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "redox_syscall" -version = "0.1.30" +version = "0.1.31" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -295,7 +287,7 @@ name = "redox_termios" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "redox_syscall 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -303,11 +295,11 @@ name = "ring" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "gcc 0.3.53 (registry+https://github.com/rust-lang/crates.io-index)", + "gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "untrusted 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -319,7 +311,7 @@ dependencies = [ "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "ring 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)", - "untrusted 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "webpki 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -348,8 +340,8 @@ name = "termion" version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -359,8 +351,8 @@ version = "0.1.38" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -397,7 +389,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "untrusted" -version = "0.5.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -422,7 +414,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "ring 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)", - "untrusted 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -430,7 +422,7 @@ name = "webpki-roots" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "untrusted 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "webpki 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -446,7 +438,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [metadata] "checksum arg_parser 0.1.0 (git+https://github.com/redox-os/arg-parser.git)" = "" -"checksum base64 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "30e93c03064e7590d0466209155251b90c22e37fab1daf2771582598b5827557" "checksum base64 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "96434f987501f0ed4eb336a411e0631ecd1afa11574fe148587adc4ff96143c9" "checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d" "checksum byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855" @@ -456,16 +447,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum custom_derive 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "ef8ae57c4978a2acd8b869ce6b9ca1dfe817bff704c220209fdef2c0b75a01b9" "checksum either 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "18785c1ba806c258137c937e44ada9ee7e69a37e3c72077542cd2f069d78562a" "checksum extra 0.1.0 (git+https://github.com/redox-os/libextra.git)" = "" -"checksum futures 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "4b63a4792d4f8f686defe3b39b92127fea6344de5d38202b2ee5a11bbbf29d6a" -"checksum gcc 0.3.53 (registry+https://github.com/rust-lang/crates.io-index)" = "e8310f7e9c890398b0e80e301c4f474e9918d2b27fca8f48486ca775fa9ffc5a" +"checksum futures 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "05a23db7bd162d4e8265968602930c476f688f0c180b44bdaf55e0cb2c687558" +"checksum gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)" = "5e33ec290da0d127825013597dbdfc28bee4964690c7ce1166cbc2a7bd08b1bb" "checksum httparse 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "af2f2dd97457e8fb1ae7c5a420db346af389926e36f43768b96f101546b04a07" -"checksum hyper 0.10.12 (registry+https://github.com/rust-lang/crates.io-index)" = "0f01e4a20f5dfa5278d7762b7bdb7cab96e24378b9eca3889fbd4b5e94dc7063" +"checksum hyper 0.10.13 (registry+https://github.com/rust-lang/crates.io-index)" = "368cb56b2740ebf4230520e2b90ebb0461e69034d85d1945febd9b3971426db2" "checksum hyper-rustls 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "04535774f79684c99528944ebdb89756c945c027e55ce52faa245879d836c8fb" "checksum idna 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "014b298351066f1512874135335d62a789ffe78a9974f94b43ed5621951eaf7d" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a" "checksum lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3b37545ab726dd833ec6420aaba8231c5b320814b9029ad585555d2a03e94fbf" -"checksum libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)" = "8a014d9226c2cc402676fbe9ea2e15dd5222cd1dd57f576b5b283178c944a264" +"checksum libc 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)" = "d1419b2939a0bc44b77feb34661583c7546b532b192feab36249ab584b86856c" "checksum log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "880f77541efa6e5cc74e76910c9884d9859683118839d6a1dc3b11e63512565b" "checksum magenta 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4bf0336886480e671965f794bc9b6fce88503563013d1bfb7a502c81fe3ac527" "checksum magenta-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "40d014c7011ac470ae28e2f76a02bfea4a8480f73e701353b49ad7a8d75f4699" @@ -481,7 +472,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum rayon 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a77c51c07654ddd93f6cb543c7a849863b03abc7e82591afda6dc8ad4ac3ac4a" "checksum rayon-core 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7febc28567082c345f10cddc3612c6ea020fc3297a1977d472cf9fdb73e6e493" "checksum redox_event 0.1.0 (git+https://github.com/redox-os/event.git)" = "" -"checksum redox_syscall 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)" = "8312fba776a49cf390b7b62f3135f9b294d8617f7a7592cfd0ac2492b658cd7b" +"checksum redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)" = "8dde11f18c108289bef24469638a04dce49da56084f2d50618b226e47eb04509" "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" "checksum ring 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1f2a6dc7fc06a05e6de183c5b97058582e9da2de0c136eafe49609769c507724" "checksum rustls 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "17727f4b991294da2c84d75a43c003151ff58072212768800f66c56ee46dca43" @@ -495,7 +486,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum unicase 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7f4765f83163b74f957c797ad9253caf97f103fb064d3999aea9568d09fc8a33" "checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" "checksum unicode-normalization 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "51ccda9ef9efa3f7ef5d91e8f9b83bbe6955f9bf86aec89d5cce2c874625920f" -"checksum untrusted 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6b65243989ef6aacd9c0d6bd2b822765c3361d8ed352185a6f3a41f3a718c673" +"checksum untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f392d7819dbe58833e26872f5f6f0d68b7bbbe90fc3667e98731c4a15ad9a7ae" "checksum url 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "eeb819346883532a271eb626deb43c4a1bb4c4dd47c519bd78137c3e72a4fe27" "checksum version_check 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6b772017e347561807c1aa192438c5fd74242a670a6cffacc40f2defd1dc069d" "checksum webpki 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e499345fc4c6b7c79a5b8756d4592c4305510a13512e79efafe00dfbd67bbac6" diff --git a/src/smolnetd/scheme/udp.rs b/src/smolnetd/scheme/udp.rs index 0d538f94d6..f04d7feac2 100644 --- a/src/smolnetd/scheme/udp.rs +++ b/src/smolnetd/scheme/udp.rs @@ -2,22 +2,43 @@ use netutils::Ipv4Addr; use smoltcp::socket::{AsSocket, SocketHandle, UdpPacketBuffer, UdpSocket, UdpSocketBuffer}; use smoltcp::wire::{IpAddress, IpEndpoint, Ipv4Address}; use std::collections::BTreeMap; +use std::str; use syscall; use device::NetworkDevice; use error::Result; use super::{Smolnetd, SocketSet}; -pub struct UdpHandle { +enum Setting { + Ttl, + ReadTimeout, + WriteTimeout, +} + +struct UdpHandle { flags: usize, events: usize, remote_endpoint: IpEndpoint, - pub socket_handle: SocketHandle, + socket_handle: SocketHandle, +} + +enum FdHandle { + Setting(SocketHandle, Setting), + Socket(UdpHandle), +} + +impl FdHandle { + fn socket_handle(&self) -> SocketHandle { + match *self { + FdHandle::Socket(UdpHandle { socket_handle, .. }) => socket_handle, + FdHandle::Setting(socket_handle, _) => socket_handle, + } + } } pub struct UdpScheme { next_udp_fd: usize, - udp_sockets: BTreeMap, + udp_fds: BTreeMap, socket_set: SocketSet, } @@ -25,17 +46,19 @@ impl UdpScheme { pub fn new(socket_set: SocketSet) -> UdpScheme { UdpScheme { next_udp_fd: 1, - udp_sockets: BTreeMap::new(), + udp_fds: BTreeMap::new(), socket_set, } } pub fn notify_ready_sockets Result<()>>(&self, mut f: F) -> Result<()> { - for (&fd, ref handle) in &self.udp_sockets { - let mut socket_set = self.socket_set.borrow_mut(); - let socket: &mut UdpSocket = socket_set.get_mut(handle.socket_handle).as_socket(); - if socket.can_send() { - f(fd)? + for (&fd, handle) in &self.udp_fds { + if let &FdHandle::Socket(UdpHandle { socket_handle, .. }) = handle { + let mut socket_set = self.socket_set.borrow_mut(); + let socket: &mut UdpSocket = socket_set.get_mut(socket_handle).as_socket(); + if socket.can_send() { + f(fd)? + } } } Ok(()) @@ -44,8 +67,6 @@ impl UdpScheme { impl syscall::SchemeMut for UdpScheme { fn open(&mut self, url: &[u8], flags: usize, _uid: u32, _gid: u32) -> syscall::Result { - use std::str; - let path = str::from_utf8(url).or_else(|_| Err(syscall::Error::new(syscall::EINVAL)))?; trace!("Udp open {} ", path); let mut parts = path.split("/"); @@ -75,9 +96,9 @@ impl syscall::SchemeMut for UdpScheme { let socket_handle = self.socket_set.borrow_mut().add(udp_socket); let id = self.next_udp_fd; - self.udp_sockets.insert( + self.udp_fds.insert( id, - UdpHandle { + FdHandle::Socket(UdpHandle { flags, events: 0, socket_handle, @@ -85,7 +106,7 @@ impl syscall::SchemeMut for UdpScheme { IpAddress::Ipv4(Ipv4Address::from_bytes(&remote_ip.bytes)), remote_port, ), - }, + }), ); self.next_udp_fd += 1; trace!("Udp open fd {} ", id); @@ -95,61 +116,94 @@ impl syscall::SchemeMut for UdpScheme { fn close(&mut self, fd: usize) -> syscall::Result { trace!("Upd close {}", fd); let socket_handle = { - let handle = self.udp_sockets + let handle = self.udp_fds .get(&fd) .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; - handle.socket_handle + handle.socket_handle() }; - self.udp_sockets.remove(&fd); - self.socket_set.borrow_mut().remove(socket_handle); + self.udp_fds.remove(&fd); + let mut socket_set = self.socket_set.borrow_mut(); + socket_set.release(socket_handle); + //TODO: removing sockets in release should make prune unnecessary + socket_set.prune(); Ok(0) } fn write(&mut self, fd: usize, buf: &[u8]) -> syscall::Result { trace!("Upd write {} len {}", fd, buf.len()); - let handle = self.udp_sockets + let handle = self.udp_fds .get(&fd) .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; - let mut socket_set = self.socket_set.borrow_mut(); - let socket: &mut UdpSocket = socket_set.get_mut(handle.socket_handle).as_socket(); - socket - .send_slice(buf, handle.remote_endpoint) - .expect("Can't send slice"); + match *handle { + FdHandle::Setting(_, _) => { + //TODO: udp settings + // pretend we've accepted + } + FdHandle::Socket(ref handle) => { + let mut socket_set = self.socket_set.borrow_mut(); + let socket: &mut UdpSocket = socket_set.get_mut(handle.socket_handle).as_socket(); + socket + .send_slice(buf, handle.remote_endpoint) + .expect("Can't send slice"); + } + } Ok(buf.len()) } fn read(&mut self, fd: usize, buf: &mut [u8]) -> syscall::Result { - let handle = self.udp_sockets.get(&fd).ok_or_else(|| { + let handle = self.udp_fds.get(&fd).ok_or_else(|| { trace!("UDP read EBADF {}", fd); syscall::Error::new(syscall::EBADF) })?; - let mut socket_set = self.socket_set.borrow_mut(); - let socket: &mut UdpSocket = socket_set.get_mut(handle.socket_handle).as_socket(); - if socket.can_recv() { - let (length, _) = socket.recv_slice(buf).expect("Can't receive slice"); - trace!("Upd read {}", fd); - Ok(length) - } else if handle.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { - Ok(0) - } else { - Err(syscall::Error::new(syscall::EWOULDBLOCK)) + match *handle { + FdHandle::Setting(_, _) => { + //TODO: udp settings + Ok(0) + } + FdHandle::Socket(ref handle) => { + let mut socket_set = self.socket_set.borrow_mut(); + let socket: &mut UdpSocket = socket_set.get_mut(handle.socket_handle).as_socket(); + if socket.can_recv() { + let (length, _) = socket.recv_slice(buf).expect("Can't receive slice"); + trace!("Upd read {}", fd); + Ok(length) + } else if handle.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { + Ok(0) + } else { + Err(syscall::Error::new(syscall::EWOULDBLOCK)) + } + } } } + fn dup(&mut self, fd: usize, buf: &[u8]) -> syscall::Result { + let handle = self.udp_fds + .get_mut(&fd) + .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; + let path = str::from_utf8(buf).or_else(|_| Err(syscall::Error::new(syscall::EINVAL)))?; + trace!("udp dup {} {}", fd, path); + Ok(0) + } + fn fevent(&mut self, fd: usize, events: usize) -> syscall::Result { trace!("udp fevent {}", fd); - let handle = self.udp_sockets + let handle = self.udp_fds .get_mut(&fd) .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; - handle.events = events; - Ok(fd) + match *handle { + FdHandle::Setting(_, _) => Err(syscall::Error::new(syscall::EBADF)), + FdHandle::Socket(ref mut handle) => { + handle.events = events; + Ok(fd) + } + } } fn fsync(&mut self, fd: usize) -> syscall::Result { trace!("udp fsync {}", fd); { - let _handle = self.udp_sockets + let _handle = self.udp_fds .get_mut(&fd) .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; } From e9f9e821c668ba85fc89c536d3cc0c34e8cab614 Mon Sep 17 00:00:00 2001 From: Egor Karavaev Date: Thu, 21 Sep 2017 00:35:17 +0300 Subject: [PATCH 031/155] Use FromStr implementations from smoltcp. --- src/smolnetd/scheme/mod.rs | 26 +++++++++----------------- src/smolnetd/scheme/udp.rs | 22 ++++++++++------------ 2 files changed, 19 insertions(+), 29 deletions(-) diff --git a/src/smolnetd/scheme/mod.rs b/src/smolnetd/scheme/mod.rs index 51a1522355..4cdb88b172 100644 --- a/src/smolnetd/scheme/mod.rs +++ b/src/smolnetd/scheme/mod.rs @@ -1,11 +1,10 @@ -use netutils::{getcfg, MacAddr}; +use netutils::getcfg; use smoltcp; use std::cell::RefCell; use std::collections::VecDeque; use std::fs::File; use std::io::{Read, Write}; use std::mem; -use std::net::Ipv4Addr; use std::rc::Rc; use std::str::FromStr; use std::time::Instant; @@ -48,21 +47,14 @@ impl Smolnetd { pub fn new(network_file: File, ip_file: File, udp_file: File, time_file: File) -> Smolnetd { let arp_cache = smoltcp::iface::SliceArpCache::new(vec![Default::default(); 8]); - //TODO Use smoltcp::wire::EthernetAddress::from_str - let mac_addr = MacAddr::from_str(&getcfg("mac").unwrap().trim()); - let hardware_addr = smoltcp::wire::EthernetAddress(mac_addr.bytes); - //TODO Use smoltcp::wire::Ipv4Addr::from_str - let ip_bytes = Ipv4Addr::from_str(&getcfg("ip").unwrap().trim()) - .unwrap() - .octets(); - let protocol_addrs = [ - smoltcp::wire::IpAddress::Ipv4(smoltcp::wire::Ipv4Address::from_bytes(&ip_bytes)), - ]; - let default_gw = smoltcp::wire::IpAddress::Ipv4(smoltcp::wire::Ipv4Address::from_bytes( - &Ipv4Addr::from_str(&getcfg("ip_router").unwrap().trim()) - .unwrap() - .octets(), - )); + let hardware_addr = smoltcp::wire::EthernetAddress::from_str( + &getcfg("mac").unwrap().trim(), + ).expect("Can't parse the 'mac' cfg"); + let local_ip = smoltcp::wire::IpAddress::from_str(&getcfg("ip").unwrap().trim()) + .expect("Can't parse the 'ip' cfg."); + let protocol_addrs = [local_ip]; + let default_gw = smoltcp::wire::IpAddress::from_str(&getcfg("ip_router").unwrap().trim()) + .expect("Can't parse the 'ip_router' cfg."); trace!("mac {:?} ip {:?}", hardware_addr, protocol_addrs); let input_queue = Rc::new(RefCell::new(VecDeque::new())); let network_file = Rc::new(RefCell::new(network_file)); diff --git a/src/smolnetd/scheme/udp.rs b/src/smolnetd/scheme/udp.rs index f04d7feac2..23ab741029 100644 --- a/src/smolnetd/scheme/udp.rs +++ b/src/smolnetd/scheme/udp.rs @@ -1,7 +1,7 @@ -use netutils::Ipv4Addr; use smoltcp::socket::{AsSocket, SocketHandle, UdpPacketBuffer, UdpSocket, UdpSocketBuffer}; use smoltcp::wire::{IpAddress, IpEndpoint, Ipv4Address}; use std::collections::BTreeMap; +use std::str::FromStr; use std::str; use syscall; @@ -83,13 +83,10 @@ impl syscall::SchemeMut for UdpScheme { let tx_buffer = UdpSocketBuffer::new(tx_packets); let mut udp_socket = UdpSocket::new(rx_buffer, tx_buffer); - if local_ip != Ipv4Addr::NULL && local_port != 0 { + if !local_ip.is_unspecified() && local_port != 0 { let udp_socket: &mut UdpSocket = udp_socket.as_socket(); udp_socket - .bind(IpEndpoint::new( - IpAddress::Ipv4(Ipv4Address::from_bytes(&local_ip.bytes)), - local_port, - )) + .bind(IpEndpoint::new(local_ip, local_port)) .unwrap(); } @@ -102,10 +99,7 @@ impl syscall::SchemeMut for UdpScheme { flags, events: 0, socket_handle, - remote_endpoint: IpEndpoint::new( - IpAddress::Ipv4(Ipv4Address::from_bytes(&remote_ip.bytes)), - remote_port, - ), + remote_endpoint: IpEndpoint::new(remote_ip, remote_port), }), ); self.next_udp_fd += 1; @@ -213,9 +207,13 @@ impl syscall::SchemeMut for UdpScheme { } } -fn parse_socket(socket: &str) -> (Ipv4Addr, u16) { +fn parse_socket(socket: &str) -> (IpAddress, u16) { let mut socket_parts = socket.split(":"); - let host = Ipv4Addr::from_str(socket_parts.next().unwrap_or("")); + let host = IpAddress::Ipv4( + Ipv4Address::from_str(socket_parts.next().unwrap_or("")) + .unwrap_or_else(|_| Ipv4Address::new(0, 0, 0, 0)), + ); + let port = socket_parts .next() .unwrap_or("") From 0a41339def74d2f6602645cd687745f1368f0b43 Mon Sep 17 00:00:00 2001 From: Egor Karavaev Date: Tue, 26 Sep 2017 01:07:49 +0300 Subject: [PATCH 032/155] UDP dup. --- Cargo.lock | 14 ++--- Cargo.toml | 2 +- src/smolnetd/main.rs | 1 + src/smolnetd/port_set.rs | 62 ++++++++++++++++++++++ src/smolnetd/scheme/mod.rs | 8 +-- src/smolnetd/scheme/udp.rs | 102 ++++++++++++++++++++++++++++++++----- 6 files changed, 163 insertions(+), 26 deletions(-) create mode 100644 src/smolnetd/port_set.rs diff --git a/Cargo.lock b/Cargo.lock index dac3c45467..a2763effc0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7,7 +7,7 @@ dependencies = [ "rand 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", "redox_event 0.1.0 (git+https://github.com/redox-os/event.git)", "redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", - "smoltcp 0.4.0-pre (git+https://github.com/batonius/smoltcp.git?branch=default_route)", + "smoltcp 0.4.0 (git+https://github.com/batonius/smoltcp.git?branch=default_route)", ] [[package]] @@ -172,7 +172,7 @@ dependencies = [ [[package]] name = "managed" -version = "0.3.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -327,12 +327,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "smoltcp" -version = "0.4.0-pre" -source = "git+https://github.com/batonius/smoltcp.git?branch=default_route#b64a43d93f3829e0127664b946be116e1f1fc583" +version = "0.4.0" +source = "git+https://github.com/batonius/smoltcp.git?branch=default_route#59d883a4b30a9caa7e7cc198cd75149b45ca1d69" dependencies = [ "byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", - "managed 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "managed 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -460,7 +460,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "880f77541efa6e5cc74e76910c9884d9859683118839d6a1dc3b11e63512565b" "checksum magenta 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4bf0336886480e671965f794bc9b6fce88503563013d1bfb7a502c81fe3ac527" "checksum magenta-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "40d014c7011ac470ae28e2f76a02bfea4a8480f73e701353b49ad7a8d75f4699" -"checksum managed 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "61eb783b4fa77e8fa4d27ec400f97ed9168546b8b30341a120b7ba9cc6571aaf" +"checksum managed 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b5d48e8c30a4363e2981fe4db20527f6ab0f32a243bbc75379dea5a64f60dae4" "checksum matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "100aabe6b8ff4e4a7e32c1c13523379802df0772b82466207ac25b013f193376" "checksum mime 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ba626b8a6de5da682e1caa06bdb42a335aee5a84db8e5046a3e8ab17ba0a3ae0" "checksum netutils 0.1.0 (git+https://github.com/redox-os/netutils.git)" = "" @@ -478,7 +478,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum rustls 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "17727f4b991294da2c84d75a43c003151ff58072212768800f66c56ee46dca43" "checksum safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e27a8b19b835f7aea908818e871f5cc3a5a186550c30773be987e155e8163d8f" "checksum scopeguard 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c79eb2c3ac4bc2507cda80e7f3ac5b88bd8eae4c0914d5663e6a8933994be918" -"checksum smoltcp 0.4.0-pre (git+https://github.com/batonius/smoltcp.git?branch=default_route)" = "" +"checksum smoltcp 0.4.0 (git+https://github.com/batonius/smoltcp.git?branch=default_route)" = "" "checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" "checksum time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)" = "d5d788d3aa77bc0ef3e9621256885555368b47bd495c13dd2e7413c89f845520" "checksum traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079" diff --git a/Cargo.toml b/Cargo.toml index 622615f407..0639af3499 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,4 +41,4 @@ features = ["release_max_level_off"] git = "https://github.com/batonius/smoltcp.git" branch = "default_route" default-features = false -features = ["std", "log"] +features = ["std", "log", "socket-raw", "socket-udp", "socket-tcp"] diff --git a/src/smolnetd/main.rs b/src/smolnetd/main.rs index 77dcc103f3..d161688c2b 100644 --- a/src/smolnetd/main.rs +++ b/src/smolnetd/main.rs @@ -20,6 +20,7 @@ mod device; mod error; mod logger; mod scheme; +mod port_set; fn run() -> Result<()> { use syscall::flag::*; diff --git a/src/smolnetd/port_set.rs b/src/smolnetd/port_set.rs new file mode 100644 index 0000000000..66d42244b9 --- /dev/null +++ b/src/smolnetd/port_set.rs @@ -0,0 +1,62 @@ +use std::collections::btree_map::{BTreeMap, Entry}; + +pub struct PortSet { + from: u16, + range: u16, + next: u16, + ports: BTreeMap, +} + +impl PortSet { + pub fn new(from: u16, to: u16) -> Option { + if from > to { + return None; + } + Some(PortSet { + from, + range: to - from + 1, + next: 0, + ports: BTreeMap::new(), + }) + } + + pub fn get_port(&mut self) -> Option { + if self.ports.len() >= self.range as usize { + return None; + } + + let port = loop { + if let Entry::Vacant(entry) = self.ports.entry(self.next) { + entry.insert(1); + let port = self.from + self.next; + self.next = self.next.wrapping_add(1); + break port; + } + self.next = self.next.wrapping_add(1); + }; + + return Some(port); + } + + pub fn claim_port(&mut self, port: u16) -> bool { + if let Entry::Vacant(entry) = self.ports.entry(port) { + entry.insert(1); + true + } else { + false + } + } + + pub fn acquire_port(&mut self, port: u16) { + *self.ports.entry(port).or_insert(0) += 1; + } + + pub fn release_port(&mut self, port: u16) { + if let Entry::Occupied(mut entry) = self.ports.entry(port) { + *entry.get_mut() -= 1; + if *entry.get() == 0 { + entry.remove(); + } + } + } +} diff --git a/src/smolnetd/scheme/mod.rs b/src/smolnetd/scheme/mod.rs index 4cdb88b172..a389b3bf74 100644 --- a/src/smolnetd/scheme/mod.rs +++ b/src/smolnetd/scheme/mod.rs @@ -52,20 +52,20 @@ impl Smolnetd { ).expect("Can't parse the 'mac' cfg"); let local_ip = smoltcp::wire::IpAddress::from_str(&getcfg("ip").unwrap().trim()) .expect("Can't parse the 'ip' cfg."); - let protocol_addrs = [local_ip]; + let protocol_addrs = [smoltcp::wire::IpCidr::new(local_ip, 24).unwrap()]; let default_gw = smoltcp::wire::IpAddress::from_str(&getcfg("ip_router").unwrap().trim()) .expect("Can't parse the 'ip_router' cfg."); - trace!("mac {:?} ip {:?}", hardware_addr, protocol_addrs); + // trace!("mac {:?} ip {}", hardware_addr, protocol_addrs); let input_queue = Rc::new(RefCell::new(VecDeque::new())); let network_file = Rc::new(RefCell::new(network_file)); let network_device = NetworkDevice::new(network_file.clone(), input_queue.clone()); - let mut iface = smoltcp::iface::EthernetInterface::new( + let iface = smoltcp::iface::EthernetInterface::new( Box::new(network_device), Box::new(arp_cache) as Box, hardware_addr, protocol_addrs, + default_gw, ); - iface.set_default_gateway(24, Some(default_gw)); let socket_set = Rc::new(RefCell::new(smoltcp::socket::SocketSet::new(vec![]))); Smolnetd { iface, diff --git a/src/smolnetd/scheme/udp.rs b/src/smolnetd/scheme/udp.rs index 23ab741029..c6c6e9e9bc 100644 --- a/src/smolnetd/scheme/udp.rs +++ b/src/smolnetd/scheme/udp.rs @@ -8,6 +8,7 @@ use syscall; use device::NetworkDevice; use error::Result; use super::{Smolnetd, SocketSet}; +use port_set::PortSet; enum Setting { Ttl, @@ -40,6 +41,7 @@ pub struct UdpScheme { next_udp_fd: usize, udp_fds: BTreeMap, socket_set: SocketSet, + port_set: PortSet, } impl UdpScheme { @@ -48,6 +50,7 @@ impl UdpScheme { next_udp_fd: 1, udp_fds: BTreeMap::new(), socket_set, + port_set: PortSet::new(1025u16, 0xFFFFu16).expect("Wrong UDP port numbers"), } } @@ -66,12 +69,18 @@ impl UdpScheme { } impl syscall::SchemeMut for UdpScheme { - fn open(&mut self, url: &[u8], flags: usize, _uid: u32, _gid: u32) -> syscall::Result { + fn open(&mut self, url: &[u8], flags: usize, uid: u32, _gid: u32) -> syscall::Result { let path = str::from_utf8(url).or_else(|_| Err(syscall::Error::new(syscall::EINVAL)))?; + trace!("Udp open {} ", path); + let mut parts = path.split("/"); - let (remote_ip, remote_port) = parse_socket(parts.next().unwrap_or("")); - let (local_ip, local_port) = parse_socket(parts.next().unwrap_or("")); + let remote_endpoint = parse_endpoint(parts.next().unwrap_or("")); + let mut local_endpoint = parse_endpoint(parts.next().unwrap_or("")); + + if local_endpoint.port <= 1024 && uid != 0 { + return Err(syscall::Error::new(syscall::EACCES)); + } let mut rx_packets = Vec::with_capacity(Smolnetd::SOCKET_BUFFER_SIZE); let mut tx_packets = Vec::with_capacity(Smolnetd::SOCKET_BUFFER_SIZE); @@ -83,11 +92,19 @@ impl syscall::SchemeMut for UdpScheme { let tx_buffer = UdpSocketBuffer::new(tx_packets); let mut udp_socket = UdpSocket::new(rx_buffer, tx_buffer); - if !local_ip.is_unspecified() && local_port != 0 { + if local_endpoint.port == 0 { + local_endpoint.port = self.port_set + .get_port() + .ok_or_else(|| syscall::Error::new(syscall::EINVAL))?; + } else if !self.port_set.claim_port(local_endpoint.port) { + return Err(syscall::Error::new(syscall::EADDRINUSE)); + } + + { let udp_socket: &mut UdpSocket = udp_socket.as_socket(); udp_socket - .bind(IpEndpoint::new(local_ip, local_port)) - .unwrap(); + .bind(local_endpoint) + .expect("Can't bind udp socket to local endpoint"); } let socket_handle = self.socket_set.borrow_mut().add(udp_socket); @@ -99,7 +116,7 @@ impl syscall::SchemeMut for UdpScheme { flags, events: 0, socket_handle, - remote_endpoint: IpEndpoint::new(remote_ip, remote_port), + remote_endpoint: remote_endpoint, }), ); self.next_udp_fd += 1; @@ -117,9 +134,16 @@ impl syscall::SchemeMut for UdpScheme { }; self.udp_fds.remove(&fd); let mut socket_set = self.socket_set.borrow_mut(); + let endpoint = { + let socket: &mut UdpSocket = socket_set.get_mut(socket_handle).as_socket(); + socket.endpoint() + }; socket_set.release(socket_handle); //TODO: removing sockets in release should make prune unnecessary socket_set.prune(); + if endpoint.port != 0 { + self.port_set.release_port(endpoint.port); + } Ok(0) } @@ -135,6 +159,9 @@ impl syscall::SchemeMut for UdpScheme { // pretend we've accepted } FdHandle::Socket(ref handle) => { + if !handle.remote_endpoint.is_specified() { + return Err(syscall::Error::new(syscall::EADDRNOTAVAIL)); + } let mut socket_set = self.socket_set.borrow_mut(); let socket: &mut UdpSocket = socket_set.get_mut(handle.socket_handle).as_socket(); socket @@ -146,6 +173,7 @@ impl syscall::SchemeMut for UdpScheme { } fn read(&mut self, fd: usize, buf: &mut [u8]) -> syscall::Result { + trace!("udp read {} {}", fd, buf.len()); let handle = self.udp_fds.get(&fd).ok_or_else(|| { trace!("UDP read EBADF {}", fd); syscall::Error::new(syscall::EBADF) @@ -153,7 +181,7 @@ impl syscall::SchemeMut for UdpScheme { match *handle { FdHandle::Setting(_, _) => { //TODO: udp settings - Ok(0) + Ok(buf.len()) } FdHandle::Socket(ref handle) => { let mut socket_set = self.socket_set.borrow_mut(); @@ -172,12 +200,58 @@ impl syscall::SchemeMut for UdpScheme { } fn dup(&mut self, fd: usize, buf: &[u8]) -> syscall::Result { - let handle = self.udp_fds - .get_mut(&fd) - .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; let path = str::from_utf8(buf).or_else(|_| Err(syscall::Error::new(syscall::EINVAL)))?; trace!("udp dup {} {}", fd, path); - Ok(0) + + let handle = { + let handle = self.udp_fds + .get_mut(&fd) + .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; + + let socket_handle = handle.socket_handle(); + + match path { + "ttl" => FdHandle::Setting(socket_handle, Setting::Ttl), + "read_timeout" => FdHandle::Setting(socket_handle, Setting::ReadTimeout), + "write_timeout" => FdHandle::Setting(socket_handle, Setting::WriteTimeout), + _ => { + let remote_endpoint = parse_endpoint(path); + if let &mut FdHandle::Socket(ref udp_handle) = handle { + FdHandle::Socket(UdpHandle { + flags: udp_handle.flags, + events: udp_handle.events, + remote_endpoint: if remote_endpoint.is_specified() { + remote_endpoint + } else { + udp_handle.remote_endpoint + }, + socket_handle, + }) + } else { + FdHandle::Socket(UdpHandle { + flags: 0, + events: 0, + remote_endpoint: remote_endpoint, + socket_handle, + }) + } + } + } + }; + + self.socket_set.borrow_mut().retain(handle.socket_handle()); + let port = { + let mut socket_set = self.socket_set.borrow_mut(); + let socket: &mut UdpSocket = socket_set.get_mut(handle.socket_handle()).as_socket(); + socket.endpoint().port + }; + self.port_set.acquire_port(port); + + let id = self.next_udp_fd; + self.udp_fds.insert(id, handle); + self.next_udp_fd += 1; + + Ok(id) } fn fevent(&mut self, fd: usize, events: usize) -> syscall::Result { @@ -207,7 +281,7 @@ impl syscall::SchemeMut for UdpScheme { } } -fn parse_socket(socket: &str) -> (IpAddress, u16) { +fn parse_endpoint(socket: &str) -> IpEndpoint { let mut socket_parts = socket.split(":"); let host = IpAddress::Ipv4( Ipv4Address::from_str(socket_parts.next().unwrap_or("")) @@ -219,5 +293,5 @@ fn parse_socket(socket: &str) -> (IpAddress, u16) { .unwrap_or("") .parse::() .unwrap_or(0); - (host, port) + IpEndpoint::new(host, port) } From c62eca07d927879ef69ddf3523b21dffd3802ca7 Mon Sep 17 00:00:00 2001 From: Egor Karavaev Date: Tue, 26 Sep 2017 22:24:04 +0300 Subject: [PATCH 033/155] Move file descriptors to schemas. --- src/smolnetd/scheme/ip.rs | 24 +++++++++++++++++++++--- src/smolnetd/scheme/mod.rs | 37 ++++++------------------------------- src/smolnetd/scheme/udp.rs | 27 +++++++++++++++++++++++---- 3 files changed, 50 insertions(+), 38 deletions(-) diff --git a/src/smolnetd/scheme/ip.rs b/src/smolnetd/scheme/ip.rs index 9264d58006..f454b555be 100644 --- a/src/smolnetd/scheme/ip.rs +++ b/src/smolnetd/scheme/ip.rs @@ -1,11 +1,15 @@ use smoltcp::socket::{AsSocket, RawPacketBuffer, RawSocket, RawSocketBuffer, SocketHandle}; use smoltcp::wire::{IpProtocol, IpVersion}; +use std::fs::File; +use std::io::{Read, Write}; use std::collections::BTreeMap; +use syscall::SchemeMut; use syscall; use device::NetworkDevice; use error::Result; use super::{Smolnetd, SocketSet}; +use super::post_fevent; pub struct RawHandle { flags: usize, @@ -17,23 +21,37 @@ pub struct IpScheme { next_ip_fd: usize, raw_sockets: BTreeMap, socket_set: SocketSet, + ip_file: File, } impl IpScheme { - pub fn new(socket_set: SocketSet) -> IpScheme { + pub fn new(socket_set: SocketSet, ip_file: File) -> IpScheme { IpScheme { next_ip_fd: 1, raw_sockets: BTreeMap::new(), socket_set, + ip_file, } } - pub fn notify_ready_sockets Result<()>>(&self, mut f: F) -> Result<()> { + pub fn on_scheme_event(&mut self) -> Result> { + loop { + let mut packet = syscall::Packet::default(); + if self.ip_file.read(&mut packet)? == 0 { + break; + } + self.handle(&mut packet); + self.ip_file.write_all(&packet)?; + } + Ok(None) + } + + pub fn notify_sockets(&mut self) -> Result<()> { for (&fd, ref handle) in &self.raw_sockets { let mut socket_set = self.socket_set.borrow_mut(); let socket: &mut RawSocket = socket_set.get_mut(handle.socket_handle).as_socket(); if socket.can_send() { - f(fd)? + post_fevent(&mut self.ip_file, fd, syscall::EVENT_READ, 1)?; } } Ok(()) diff --git a/src/smolnetd/scheme/mod.rs b/src/smolnetd/scheme/mod.rs index a389b3bf74..fcc36778b8 100644 --- a/src/smolnetd/scheme/mod.rs +++ b/src/smolnetd/scheme/mod.rs @@ -8,7 +8,6 @@ use std::mem; use std::rc::Rc; use std::str::FromStr; use std::time::Instant; -use syscall::SchemeMut; use syscall; use buffer_pool::{Buffer, BufferPool}; @@ -24,8 +23,6 @@ type SocketSet = Rc>, - ip_file: File, - udp_file: File, time_file: File, iface: smoltcp::iface::EthernetInterface<'static, 'static, 'static, NetworkDevice>, @@ -71,11 +68,9 @@ impl Smolnetd { iface, socket_set: socket_set.clone(), startup_time: Instant::now(), - ip_file, - udp_file, time_file, - ip_scheme: IpScheme::new(socket_set.clone()), - udp_scheme: UdpScheme::new(socket_set.clone()), + ip_scheme: IpScheme::new(socket_set.clone(), ip_file), + udp_scheme: UdpScheme::new(socket_set.clone(), udp_file), input_queue, network_file, input_buffer_pool: BufferPool::new(Self::INGRESS_PACKET_SIZE), @@ -90,27 +85,11 @@ impl Smolnetd { } pub fn on_ip_scheme_event(&mut self) -> Result> { - loop { - let mut packet = syscall::Packet::default(); - if self.ip_file.read(&mut packet)? == 0 { - break; - } - self.ip_scheme.handle(&mut packet); - self.ip_file.write_all(&packet)?; - } - Ok(None) + self.ip_scheme.on_scheme_event() } pub fn on_udp_scheme_event(&mut self) -> Result> { - loop { - let mut packet = syscall::Packet::default(); - if self.udp_file.read(&mut packet)? == 0 { - break; - } - self.udp_scheme.handle(&mut packet); - self.udp_file.write_all(&packet)?; - } - Ok(None) + self.udp_scheme.on_scheme_event() } pub fn on_time_event(&mut self) -> Result> { @@ -171,12 +150,8 @@ impl Smolnetd { } fn notify_raw_sockets(&mut self) -> Result<()> { - let ip_file = &mut self.ip_file; - self.ip_scheme - .notify_ready_sockets(|fd| post_fevent(ip_file, fd, syscall::EVENT_READ, 1))?; - let udp_file = &mut self.udp_file; - self.udp_scheme - .notify_ready_sockets(|fd| post_fevent(udp_file, fd, syscall::EVENT_READ, 1)) + self.ip_scheme.notify_sockets()?; + self.udp_scheme.notify_sockets() } } diff --git a/src/smolnetd/scheme/udp.rs b/src/smolnetd/scheme/udp.rs index c6c6e9e9bc..a1a7eed66e 100644 --- a/src/smolnetd/scheme/udp.rs +++ b/src/smolnetd/scheme/udp.rs @@ -1,14 +1,18 @@ use smoltcp::socket::{AsSocket, SocketHandle, UdpPacketBuffer, UdpSocket, UdpSocketBuffer}; use smoltcp::wire::{IpAddress, IpEndpoint, Ipv4Address}; use std::collections::BTreeMap; +use std::fs::File; +use std::io::{Read, Write}; use std::str::FromStr; use std::str; +use syscall::SchemeMut; use syscall; use device::NetworkDevice; use error::Result; use super::{Smolnetd, SocketSet}; use port_set::PortSet; +use super::post_fevent; enum Setting { Ttl, @@ -42,25 +46,40 @@ pub struct UdpScheme { udp_fds: BTreeMap, socket_set: SocketSet, port_set: PortSet, + udp_file: File, } impl UdpScheme { - pub fn new(socket_set: SocketSet) -> UdpScheme { + pub fn new(socket_set: SocketSet, udp_file: File) -> UdpScheme { UdpScheme { next_udp_fd: 1, udp_fds: BTreeMap::new(), socket_set, - port_set: PortSet::new(1025u16, 0xFFFFu16).expect("Wrong UDP port numbers"), + // 49152..65535 is the suggested range for dynamic private ports + port_set: PortSet::new(49152u16, 65535u16).expect("Wrong UDP port numbers"), + udp_file, } } - pub fn notify_ready_sockets Result<()>>(&self, mut f: F) -> Result<()> { + pub fn on_scheme_event(&mut self) -> Result> { + loop { + let mut packet = syscall::Packet::default(); + if self.udp_file.read(&mut packet)? == 0 { + break; + } + self.handle(&mut packet); + self.udp_file.write_all(&packet)?; + } + Ok(None) + } + + pub fn notify_sockets(&mut self) -> Result<()> { for (&fd, handle) in &self.udp_fds { if let &FdHandle::Socket(UdpHandle { socket_handle, .. }) = handle { let mut socket_set = self.socket_set.borrow_mut(); let socket: &mut UdpSocket = socket_set.get_mut(socket_handle).as_socket(); if socket.can_send() { - f(fd)? + post_fevent(&mut self.udp_file, fd, syscall::EVENT_READ, 1)?; } } } From 3198a8eb6942f244055c8240962aaafc9e4b60f7 Mon Sep 17 00:00:00 2001 From: Egor Karavaev Date: Tue, 26 Sep 2017 23:51:04 +0300 Subject: [PATCH 034/155] UDP settings. --- src/smolnetd/buffer_pool.rs | 2 +- src/smolnetd/device.rs | 2 +- src/smolnetd/main.rs | 18 +-- src/smolnetd/port_set.rs | 2 +- src/smolnetd/scheme/ip.rs | 5 +- src/smolnetd/scheme/mod.rs | 24 ++-- src/smolnetd/scheme/udp.rs | 217 +++++++++++++++++++++++++++--------- 7 files changed, 192 insertions(+), 78 deletions(-) diff --git a/src/smolnetd/buffer_pool.rs b/src/smolnetd/buffer_pool.rs index 2bd2e475c5..f336266778 100644 --- a/src/smolnetd/buffer_pool.rs +++ b/src/smolnetd/buffer_pool.rs @@ -86,7 +86,7 @@ impl BufferPool { Buffer { buffer, - stack: self.stack.clone(), + stack: Rc::clone(&self.stack), } } } diff --git a/src/smolnetd/device.rs b/src/smolnetd/device.rs index 37cbb9d5c0..74f0785cd6 100644 --- a/src/smolnetd/device.rs +++ b/src/smolnetd/device.rs @@ -69,7 +69,7 @@ impl smoltcp::phy::Device for NetworkDevice { fn transmit(&mut self, _timestamp: u64, length: usize) -> smoltcp::Result { Ok(TxBuffer { - network_file: self.network_file.clone(), + network_file: Rc::clone(&self.network_file), buffer: vec![0; length], }) } diff --git a/src/smolnetd/main.rs b/src/smolnetd/main.rs index d161688c2b..65fd372f88 100644 --- a/src/smolnetd/main.rs +++ b/src/smolnetd/main.rs @@ -33,8 +33,8 @@ fn run() -> Result<()> { trace!("opening network:"); let network_fd = syscall::open("network:", O_RDWR | O_NONBLOCK) - .map_err(|e| Error::from_syscall_error(e, "failed to open network:"))? as - RawFd; + .map_err(|e| Error::from_syscall_error(e, "failed to open network:"))? + as RawFd; trace!("opening :ip"); let ip_fd = syscall::open(":ip", O_RDWR | O_CREAT | O_NONBLOCK) @@ -42,13 +42,13 @@ fn run() -> Result<()> { trace!("opening :udp"); let udp_fd = syscall::open(":udp", O_RDWR | O_CREAT | O_NONBLOCK) - .map_err(|e| Error::from_syscall_error(e, "failed to open :udp"))? as - RawFd; + .map_err(|e| Error::from_syscall_error(e, "failed to open :udp"))? + as RawFd; let time_path = format!("time:{}", syscall::CLOCK_MONOTONIC); let time_fd = syscall::open(&time_path, syscall::O_RDWR) - .map_err(|e| Error::from_syscall_error(e, "failed to open time:"))? as - RawFd; + .map_err(|e| Error::from_syscall_error(e, "failed to open time:"))? + as RawFd; let (network_file, ip_file, time_file, udp_file) = unsafe { ( @@ -66,7 +66,7 @@ fn run() -> Result<()> { let mut event_queue = EventQueue::<(), Error>::new() .map_err(|e| Error::from_io_error(e, "failed to create event queue"))?; - let smolnetd_ = smolnetd.clone(); + let smolnetd_ = Rc::clone(&smolnetd); event_queue .add(network_fd, move |_| { @@ -76,13 +76,13 @@ fn run() -> Result<()> { Error::from_io_error(e, "failed to listen to network events") })?; - let smolnetd_ = smolnetd.clone(); + let smolnetd_ = Rc::clone(&smolnetd); event_queue .add(ip_fd, move |_| smolnetd_.borrow_mut().on_ip_scheme_event()) .map_err(|e| Error::from_io_error(e, "failed to listen to ip events"))?; - let smolnetd_ = smolnetd.clone(); + let smolnetd_ = Rc::clone(&smolnetd); event_queue .add( diff --git a/src/smolnetd/port_set.rs b/src/smolnetd/port_set.rs index 66d42244b9..88011ec337 100644 --- a/src/smolnetd/port_set.rs +++ b/src/smolnetd/port_set.rs @@ -35,7 +35,7 @@ impl PortSet { self.next = self.next.wrapping_add(1); }; - return Some(port); + Some(port) } pub fn claim_port(&mut self, port: u16) -> bool { diff --git a/src/smolnetd/scheme/ip.rs b/src/smolnetd/scheme/ip.rs index f454b555be..4b2a4932fa 100644 --- a/src/smolnetd/scheme/ip.rs +++ b/src/smolnetd/scheme/ip.rs @@ -47,7 +47,7 @@ impl IpScheme { } pub fn notify_sockets(&mut self) -> Result<()> { - for (&fd, ref handle) in &self.raw_sockets { + for (&fd, handle) in &self.raw_sockets { let mut socket_set = self.socket_set.borrow_mut(); let socket: &mut RawSocket = socket_set.get_mut(handle.socket_handle).as_socket(); if socket.can_send() { @@ -66,7 +66,8 @@ impl<'a> syscall::SchemeMut for IpScheme { return Err(syscall::Error::new(syscall::EACCES)); } let path = str::from_utf8(url).or_else(|_| Err(syscall::Error::new(syscall::EINVAL)))?; - let proto = u8::from_str_radix(path, 16).or(Err(syscall::Error::new(syscall::ENOENT)))?; + let proto = + u8::from_str_radix(path, 16).or_else(|_| Err(syscall::Error::new(syscall::ENOENT)))?; let mut rx_packets = Vec::with_capacity(Smolnetd::SOCKET_BUFFER_SIZE); let mut tx_packets = Vec::with_capacity(Smolnetd::SOCKET_BUFFER_SIZE); diff --git a/src/smolnetd/scheme/mod.rs b/src/smolnetd/scheme/mod.rs index fcc36778b8..ed4758bc36 100644 --- a/src/smolnetd/scheme/mod.rs +++ b/src/smolnetd/scheme/mod.rs @@ -44,18 +44,17 @@ impl Smolnetd { pub fn new(network_file: File, ip_file: File, udp_file: File, time_file: File) -> Smolnetd { let arp_cache = smoltcp::iface::SliceArpCache::new(vec![Default::default(); 8]); - let hardware_addr = smoltcp::wire::EthernetAddress::from_str( - &getcfg("mac").unwrap().trim(), - ).expect("Can't parse the 'mac' cfg"); - let local_ip = smoltcp::wire::IpAddress::from_str(&getcfg("ip").unwrap().trim()) + let hardware_addr = smoltcp::wire::EthernetAddress::from_str(getcfg("mac").unwrap().trim()) + .expect("Can't parse the 'mac' cfg"); + let local_ip = smoltcp::wire::IpAddress::from_str(getcfg("ip").unwrap().trim()) .expect("Can't parse the 'ip' cfg."); let protocol_addrs = [smoltcp::wire::IpCidr::new(local_ip, 24).unwrap()]; - let default_gw = smoltcp::wire::IpAddress::from_str(&getcfg("ip_router").unwrap().trim()) + let default_gw = smoltcp::wire::IpAddress::from_str(getcfg("ip_router").unwrap().trim()) .expect("Can't parse the 'ip_router' cfg."); // trace!("mac {:?} ip {}", hardware_addr, protocol_addrs); let input_queue = Rc::new(RefCell::new(VecDeque::new())); let network_file = Rc::new(RefCell::new(network_file)); - let network_device = NetworkDevice::new(network_file.clone(), input_queue.clone()); + let network_device = NetworkDevice::new(Rc::clone(&network_file), Rc::clone(&input_queue)); let iface = smoltcp::iface::EthernetInterface::new( Box::new(network_device), Box::new(arp_cache) as Box, @@ -66,11 +65,11 @@ impl Smolnetd { let socket_set = Rc::new(RefCell::new(smoltcp::socket::SocketSet::new(vec![]))); Smolnetd { iface, - socket_set: socket_set.clone(), + socket_set: Rc::clone(&socket_set), startup_time: Instant::now(), time_file, - ip_scheme: IpScheme::new(socket_set.clone(), ip_file), - udp_scheme: UdpScheme::new(socket_set.clone(), udp_file), + ip_scheme: IpScheme::new(Rc::clone(&socket_set), ip_file), + udp_scheme: UdpScheme::new(Rc::clone(&socket_set), udp_file), input_queue, network_file, input_buffer_pool: BufferPool::new(Self::INGRESS_PACKET_SIZE), @@ -97,10 +96,10 @@ impl Smolnetd { if self.time_file.read(&mut time)? < mem::size_of::() { panic!(); } - let mut time_ms = time.tv_sec * 1000i64 + (time.tv_nsec as i64) / 1_000_000i64; + let mut time_ms = time.tv_sec * 1000i64 + i64::from(time.tv_nsec) / 1_000_000i64; time_ms += Smolnetd::CHECK_TIMEOUT_MS; time.tv_sec = time_ms / 1000; - time.tv_nsec = ((time_ms % 1000) * 1_000_00) as i32; + time.tv_nsec = ((time_ms % 1000) * 1_000_000) as i32; self.time_file .write_all(&time) .map_err(|e| Error::from_io_error(e, "Failed to write to time file"))?; @@ -140,8 +139,7 @@ impl Smolnetd { fn get_timestamp(&self) -> u64 { let duration = Instant::now().duration_since(self.startup_time); - let duration_ms = (duration.as_secs() * 1000) + (duration.subsec_nanos() / 1000000) as u64; - duration_ms + (duration.as_secs() * 1000) + u64::from(duration.subsec_nanos() / 1_000_000) } fn network_fsync(&mut self) -> syscall::Result { diff --git a/src/smolnetd/scheme/udp.rs b/src/smolnetd/scheme/udp.rs index a1a7eed66e..59cbbbe725 100644 --- a/src/smolnetd/scheme/udp.rs +++ b/src/smolnetd/scheme/udp.rs @@ -5,7 +5,11 @@ use std::fs::File; use std::io::{Read, Write}; use std::str::FromStr; use std::str; +use std::mem; +use std::ops::Deref; +use std::ops::DerefMut; use syscall::SchemeMut; +use syscall::data::TimeSpec; use syscall; use device::NetworkDevice; @@ -14,6 +18,7 @@ use super::{Smolnetd, SocketSet}; use port_set::PortSet; use super::post_fevent; +#[derive(Copy, Clone, Eq, PartialEq)] enum Setting { Ttl, ReadTimeout, @@ -24,19 +29,27 @@ struct UdpHandle { flags: usize, events: usize, remote_endpoint: IpEndpoint, + read_timeout: Option, + write_timeout: Option, socket_handle: SocketHandle, } +struct SettingHandle { + fd: usize, + socket_handle: SocketHandle, + setting: Setting, +} + enum FdHandle { - Setting(SocketHandle, Setting), + Setting(SettingHandle), Socket(UdpHandle), } impl FdHandle { fn socket_handle(&self) -> SocketHandle { match *self { - FdHandle::Socket(UdpHandle { socket_handle, .. }) => socket_handle, - FdHandle::Setting(socket_handle, _) => socket_handle, + FdHandle::Socket(UdpHandle { socket_handle, .. }) | + FdHandle::Setting(SettingHandle { socket_handle, .. }) => socket_handle, } } } @@ -56,7 +69,7 @@ impl UdpScheme { udp_fds: BTreeMap::new(), socket_set, // 49152..65535 is the suggested range for dynamic private ports - port_set: PortSet::new(49152u16, 65535u16).expect("Wrong UDP port numbers"), + port_set: PortSet::new(49_152u16, 65_535u16).expect("Wrong UDP port numbers"), udp_file, } } @@ -75,7 +88,7 @@ impl UdpScheme { pub fn notify_sockets(&mut self) -> Result<()> { for (&fd, handle) in &self.udp_fds { - if let &FdHandle::Socket(UdpHandle { socket_handle, .. }) = handle { + if let FdHandle::Socket(UdpHandle { socket_handle, .. }) = *handle { let mut socket_set = self.socket_set.borrow_mut(); let socket: &mut UdpSocket = socket_set.get_mut(socket_handle).as_socket(); if socket.can_send() { @@ -85,6 +98,83 @@ impl UdpScheme { } Ok(()) } + + fn get_setting( + &mut self, + fd: usize, + setting: Setting, + buf: &mut [u8], + ) -> syscall::Result { + let handle = self.udp_fds + .get_mut(&fd) + .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; + let handle = match *handle { + FdHandle::Socket(ref mut handle) => handle, + _ => { + return Err(syscall::Error::new(syscall::EBADF)); + } + }; + let timespec = match (setting, handle.read_timeout, handle.write_timeout) { + (Setting::ReadTimeout, Some(read_timeout), _) => read_timeout, + (Setting::WriteTimeout, _, Some(write_timeout)) => write_timeout, + _ => { + return Ok(0); + } + }; + + if buf.len() < mem::size_of::() { + Ok(0) + } else { + let count = timespec.deref().read(buf).map_err(|err| { + syscall::Error::new(err.raw_os_error().unwrap_or(syscall::EIO)) + })?; + Ok(count) + } + } + + fn update_setting( + &mut self, + fd: usize, + setting: Setting, + buf: &[u8], + ) -> syscall::Result { + let handle = self.udp_fds + .get_mut(&fd) + .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; + let handle = match *handle { + FdHandle::Socket(ref mut handle) => handle, + _ => { + return Err(syscall::Error::new(syscall::EBADF)); + } + }; + match setting { + Setting::ReadTimeout | Setting::WriteTimeout => { + let (timeout, count) = { + if buf.len() < mem::size_of::() { + (None, 0) + } else { + let mut timespec = TimeSpec::default(); + let count = timespec.deref_mut().write(buf).map_err(|err| { + syscall::Error::new(err.raw_os_error().unwrap_or(syscall::EIO)) + })?; + (Some(timespec), count) + } + }; + match setting { + Setting::ReadTimeout => { + handle.read_timeout = timeout; + } + Setting::WriteTimeout => { + handle.write_timeout = timeout; + } + _ => {} + }; + return Ok(count); + } + Setting::Ttl => {} + } + Ok(0) + } } impl syscall::SchemeMut for UdpScheme { @@ -93,7 +183,7 @@ impl syscall::SchemeMut for UdpScheme { trace!("Udp open {} ", path); - let mut parts = path.split("/"); + let mut parts = path.split('/'); let remote_endpoint = parse_endpoint(parts.next().unwrap_or("")); let mut local_endpoint = parse_endpoint(parts.next().unwrap_or("")); @@ -135,6 +225,8 @@ impl syscall::SchemeMut for UdpScheme { flags, events: 0, socket_handle, + write_timeout: None, + read_timeout: None, remote_endpoint: remote_endpoint, }), ); @@ -169,53 +261,60 @@ impl syscall::SchemeMut for UdpScheme { fn write(&mut self, fd: usize, buf: &[u8]) -> syscall::Result { trace!("Upd write {} len {}", fd, buf.len()); - let handle = self.udp_fds - .get(&fd) - .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; - match *handle { - FdHandle::Setting(_, _) => { - //TODO: udp settings - // pretend we've accepted - } - FdHandle::Socket(ref handle) => { - if !handle.remote_endpoint.is_specified() { - return Err(syscall::Error::new(syscall::EADDRNOTAVAIL)); + let (fd, setting) = { + let handle = self.udp_fds + .get(&fd) + .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; + + match *handle { + FdHandle::Setting(ref setting_handle) => { + (setting_handle.fd, setting_handle.setting) + } + FdHandle::Socket(ref handle) => { + if !handle.remote_endpoint.is_specified() { + return Err(syscall::Error::new(syscall::EADDRNOTAVAIL)); + } + let mut socket_set = self.socket_set.borrow_mut(); + let socket: &mut UdpSocket = + socket_set.get_mut(handle.socket_handle).as_socket(); + socket + .send_slice(buf, handle.remote_endpoint) + .expect("Can't send slice"); + return Ok(buf.len()); } - let mut socket_set = self.socket_set.borrow_mut(); - let socket: &mut UdpSocket = socket_set.get_mut(handle.socket_handle).as_socket(); - socket - .send_slice(buf, handle.remote_endpoint) - .expect("Can't send slice"); } - } - Ok(buf.len()) + }; + self.update_setting(fd, setting, buf) } fn read(&mut self, fd: usize, buf: &mut [u8]) -> syscall::Result { trace!("udp read {} {}", fd, buf.len()); - let handle = self.udp_fds.get(&fd).ok_or_else(|| { - trace!("UDP read EBADF {}", fd); - syscall::Error::new(syscall::EBADF) - })?; - match *handle { - FdHandle::Setting(_, _) => { - //TODO: udp settings - Ok(buf.len()) - } - FdHandle::Socket(ref handle) => { - let mut socket_set = self.socket_set.borrow_mut(); - let socket: &mut UdpSocket = socket_set.get_mut(handle.socket_handle).as_socket(); - if socket.can_recv() { - let (length, _) = socket.recv_slice(buf).expect("Can't receive slice"); - trace!("Upd read {}", fd); - Ok(length) - } else if handle.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { - Ok(0) - } else { - Err(syscall::Error::new(syscall::EWOULDBLOCK)) + let (fd, setting) = { + let handle = self.udp_fds.get(&fd).ok_or_else(|| { + trace!("UDP read EBADF {}", fd); + syscall::Error::new(syscall::EBADF) + })?; + match *handle { + FdHandle::Setting(ref setting_handle) => { + (setting_handle.fd, setting_handle.setting) + } + FdHandle::Socket(ref handle) => { + let mut socket_set = self.socket_set.borrow_mut(); + let socket: &mut UdpSocket = + socket_set.get_mut(handle.socket_handle).as_socket(); + return if socket.can_recv() { + let (length, _) = socket.recv_slice(buf).expect("Can't receive slice"); + trace!("Upd read {}", fd); + Ok(length) + } else if handle.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { + Ok(0) + } else { + Err(syscall::Error::new(syscall::EWOULDBLOCK)) + }; } } - } + }; + self.get_setting(fd, setting, buf) } fn dup(&mut self, fd: usize, buf: &[u8]) -> syscall::Result { @@ -230,15 +329,29 @@ impl syscall::SchemeMut for UdpScheme { let socket_handle = handle.socket_handle(); match path { - "ttl" => FdHandle::Setting(socket_handle, Setting::Ttl), - "read_timeout" => FdHandle::Setting(socket_handle, Setting::ReadTimeout), - "write_timeout" => FdHandle::Setting(socket_handle, Setting::WriteTimeout), + "ttl" => FdHandle::Setting(SettingHandle { + socket_handle, + fd, + setting: Setting::Ttl, + }), + "read_timeout" => FdHandle::Setting(SettingHandle { + socket_handle, + fd, + setting: Setting::ReadTimeout, + }), + "write_timeout" => FdHandle::Setting(SettingHandle { + socket_handle, + fd, + setting: Setting::WriteTimeout, + }), _ => { let remote_endpoint = parse_endpoint(path); - if let &mut FdHandle::Socket(ref udp_handle) = handle { + if let FdHandle::Socket(ref udp_handle) = *handle { FdHandle::Socket(UdpHandle { flags: udp_handle.flags, events: udp_handle.events, + read_timeout: udp_handle.read_timeout, + write_timeout: udp_handle.write_timeout, remote_endpoint: if remote_endpoint.is_specified() { remote_endpoint } else { @@ -250,6 +363,8 @@ impl syscall::SchemeMut for UdpScheme { FdHandle::Socket(UdpHandle { flags: 0, events: 0, + read_timeout: None, + write_timeout: None, remote_endpoint: remote_endpoint, socket_handle, }) @@ -279,7 +394,7 @@ impl syscall::SchemeMut for UdpScheme { .get_mut(&fd) .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; match *handle { - FdHandle::Setting(_, _) => Err(syscall::Error::new(syscall::EBADF)), + FdHandle::Setting(_) => Err(syscall::Error::new(syscall::EBADF)), FdHandle::Socket(ref mut handle) => { handle.events = events; Ok(fd) @@ -301,7 +416,7 @@ impl syscall::SchemeMut for UdpScheme { } fn parse_endpoint(socket: &str) -> IpEndpoint { - let mut socket_parts = socket.split(":"); + let mut socket_parts = socket.split(':'); let host = IpAddress::Ipv4( Ipv4Address::from_str(socket_parts.next().unwrap_or("")) .unwrap_or_else(|_| Ipv4Address::new(0, 0, 0, 0)), From 2a8478db8fd40f5b87ebd2fd942428701b305814 Mon Sep 17 00:00:00 2001 From: Egor Karavaev Date: Thu, 28 Sep 2017 01:02:52 +0300 Subject: [PATCH 035/155] UDP blocking WIP. --- Cargo.lock | 2 +- src/smolnetd/scheme/udp.rs | 89 +++++++++++++++++++++++++++++++++++++- 2 files changed, 88 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a2763effc0..0e8ec0058a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -328,7 +328,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "smoltcp" version = "0.4.0" -source = "git+https://github.com/batonius/smoltcp.git?branch=default_route#59d883a4b30a9caa7e7cc198cd75149b45ca1d69" +source = "git+https://github.com/batonius/smoltcp.git?branch=default_route#0412399884af1076f24c79e5b7b78f284798a166" dependencies = [ "byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/src/smolnetd/scheme/udp.rs b/src/smolnetd/scheme/udp.rs index 59cbbbe725..e3d7e7783a 100644 --- a/src/smolnetd/scheme/udp.rs +++ b/src/smolnetd/scheme/udp.rs @@ -13,7 +13,7 @@ use syscall::data::TimeSpec; use syscall; use device::NetworkDevice; -use error::Result; +use error::{Error, Result}; use super::{Smolnetd, SocketSet}; use port_set::PortSet; use super::post_fevent; @@ -54,12 +54,19 @@ impl FdHandle { } } +struct WaitHandle { + until: Option, + packet: syscall::Packet, +} + pub struct UdpScheme { next_udp_fd: usize, udp_fds: BTreeMap, socket_set: SocketSet, port_set: PortSet, udp_file: File, + read_wait_queue: BTreeMap>, + write_wait_queue: BTreeMap>, } impl UdpScheme { @@ -71,6 +78,8 @@ impl UdpScheme { // 49152..65535 is the suggested range for dynamic private ports port_set: PortSet::new(49_152u16, 65_535u16).expect("Wrong UDP port numbers"), udp_file, + read_wait_queue: BTreeMap::new(), + write_wait_queue: BTreeMap::new(), } } @@ -80,8 +89,14 @@ impl UdpScheme { if self.udp_file.read(&mut packet)? == 0 { break; } + let a = packet.a; self.handle(&mut packet); - self.udp_file.write_all(&packet)?; + if packet.a != (-syscall::EWOULDBLOCK) as usize { + self.udp_file.write_all(&packet)?; + } else { + packet.a = a; + self.handle_block(packet)?; + } } Ok(None) } @@ -99,6 +114,61 @@ impl UdpScheme { Ok(()) } + fn handle_block(&mut self, mut packet: syscall::Packet) -> Result<()> { + let syscall_result = self.try_handle_block(&mut packet); + if let Err(syscall_error) = syscall_result { + packet.a = (-syscall_error.errno) as usize; + self.udp_file.write_all(&packet)?; + Err(Error::from_syscall_error( + syscall_error, + "Can't handle blocked socket", + )) + } else { + Ok(()) + } + } + + fn try_handle_block(&mut self, packet: &mut syscall::Packet) -> syscall::Result<()> { + let fd = packet.b; + let (socket_handle, read_timeout, write_timeout) = { + let handle = self.udp_fds + .get(&fd) + .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; + + if let FdHandle::Socket(ref udp_handle) = *handle { + Ok(( + udp_handle.socket_handle, + udp_handle.read_timeout, + udp_handle.write_timeout, + )) + } else { + Err(syscall::Error::new(syscall::EBADF)) + } + }?; + + let (mut timeout, queue) = match packet.a { + syscall::SYS_READ => Ok((read_timeout, &mut self.read_wait_queue)), + syscall::SYS_WRITE => Ok((write_timeout, &mut self.write_wait_queue)), + _ => Err(syscall::Error::new(syscall::EBADF)), + }?; + + if let Some(ref mut timeout) = timeout { + let mut cur_time = TimeSpec::default(); + syscall::clock_gettime(syscall::CLOCK_MONOTONIC, &mut cur_time)?; + *timeout = add_time(timeout, &cur_time) + } + + queue + .entry(socket_handle) + .or_insert_with(|| vec![]) + .push(WaitHandle { + until: timeout, + packet: *packet, + }); + + Ok(()) + } + fn get_setting( &mut self, fd: usize, @@ -249,6 +319,8 @@ impl syscall::SchemeMut for UdpScheme { let socket: &mut UdpSocket = socket_set.get_mut(socket_handle).as_socket(); socket.endpoint() }; + self.write_wait_queue.remove(&socket_handle); + self.read_wait_queue.remove(&socket_handle); socket_set.release(socket_handle); //TODO: removing sockets in release should make prune unnecessary socket_set.prune(); @@ -429,3 +501,16 @@ fn parse_endpoint(socket: &str) -> IpEndpoint { .unwrap_or(0); IpEndpoint::new(host, port) } + +fn add_time(a: &TimeSpec, b: &TimeSpec) -> TimeSpec { + let mut secs = a.tv_sec + b.tv_sec; + let mut nsecs = a.tv_nsec + b.tv_nsec; + + secs += i64::from(nsecs) / 1_000_000_000; + nsecs %= 1_000_000_000; + + TimeSpec { + tv_sec: secs, + tv_nsec: nsecs, + } +} From 4d9a8c2777d5242c451ac800c065e3658af43627 Mon Sep 17 00:00:00 2001 From: Egor Karavaev Date: Mon, 2 Oct 2017 19:22:22 +0300 Subject: [PATCH 036/155] Blocking UDP. --- Cargo.lock | 22 ++--- src/smolnetd/buffer_pool.rs | 3 - src/smolnetd/scheme/mod.rs | 4 +- src/smolnetd/scheme/udp.rs | 177 +++++++++++++++++++++++++++++++----- 4 files changed, 168 insertions(+), 38 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0e8ec0058a..313e9f6f0a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -44,7 +44,7 @@ name = "coco" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "either 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "either 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "scopeguard 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -63,7 +63,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "either" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -96,7 +96,7 @@ dependencies = [ "language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "mime 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", - "num_cpus 1.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)", "traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "typeable 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -140,7 +140,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "lazy_static" -version = "0.2.8" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -216,7 +216,7 @@ dependencies = [ [[package]] name = "num_cpus" -version = "1.6.2" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "libc 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)", @@ -263,9 +263,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "coco 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)", - "num_cpus 1.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -296,7 +296,7 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -445,7 +445,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum coco 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c06169f5beb7e31c7c67ebf5540b8b472d23e3eade3b2ec7d1f5b504a85f91bd" "checksum conv 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "78ff10625fd0ac447827aa30ea8b861fead473bb60aeb73af6c1c58caf0d1299" "checksum custom_derive 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "ef8ae57c4978a2acd8b869ce6b9ca1dfe817bff704c220209fdef2c0b75a01b9" -"checksum either 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "18785c1ba806c258137c937e44ada9ee7e69a37e3c72077542cd2f069d78562a" +"checksum either 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cbee135e9245416869bf52bd6ccc9b59e2482651510784e089b874272f02a252" "checksum extra 0.1.0 (git+https://github.com/redox-os/libextra.git)" = "" "checksum futures 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "05a23db7bd162d4e8265968602930c476f688f0c180b44bdaf55e0cb2c687558" "checksum gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)" = "5e33ec290da0d127825013597dbdfc28bee4964690c7ce1166cbc2a7bd08b1bb" @@ -455,7 +455,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum idna 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "014b298351066f1512874135335d62a789ffe78a9974f94b43ed5621951eaf7d" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a" -"checksum lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3b37545ab726dd833ec6420aaba8231c5b320814b9029ad585555d2a03e94fbf" +"checksum lazy_static 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c9e5e58fa1a4c3b915a561a78a22ee0cac6ab97dca2504428bc1cb074375f8d5" "checksum libc 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)" = "d1419b2939a0bc44b77feb34661583c7546b532b192feab36249ab584b86856c" "checksum log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "880f77541efa6e5cc74e76910c9884d9859683118839d6a1dc3b11e63512565b" "checksum magenta 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4bf0336886480e671965f794bc9b6fce88503563013d1bfb7a502c81fe3ac527" @@ -465,7 +465,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum mime 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ba626b8a6de5da682e1caa06bdb42a335aee5a84db8e5046a3e8ab17ba0a3ae0" "checksum netutils 0.1.0 (git+https://github.com/redox-os/netutils.git)" = "" "checksum ntpclient 0.0.1 (git+https://github.com/willem66745/ntpclient-rust)" = "" -"checksum num_cpus 1.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "aec53c34f2d0247c5ca5d32cca1478762f301740468ee9ee6dcb7a0dd7a0c584" +"checksum num_cpus 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "514f0d73e64be53ff320680ca671b64fe3fb91da01e1ae2ddc99eb51d453b20d" "checksum pbr 1.0.0 (git+https://github.com/a8m/pb)" = "" "checksum percent-encoding 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "de154f638187706bde41d9b4738748933d64e6b37bdbffc0b47a97d16a6ae356" "checksum rand 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)" = "eb250fd207a4729c976794d03db689c9be1d634ab5a1c9da9492a13d8fecbcdf" diff --git a/src/smolnetd/buffer_pool.rs b/src/smolnetd/buffer_pool.rs index f336266778..f3248c1958 100644 --- a/src/smolnetd/buffer_pool.rs +++ b/src/smolnetd/buffer_pool.rs @@ -48,7 +48,6 @@ impl Drop for Buffer { swap(&mut tmp, &mut self.buffer); { let mut stack = self.stack.borrow_mut(); - trace!("Returning buffer: {}", stack.len()); stack.push(tmp); } } @@ -70,11 +69,9 @@ impl BufferPool { pub fn get_buffer(&mut self) -> Buffer { let buffer = match self.stack.borrow_mut().pop() { None => { - trace!("Allocating ingress buffer"); vec![0u8; self.buffers_size] } Some(mut v) => { - trace!("Reusing ingress buffer"); // memsetting the buffer with `resize` would be a waste of time let capacity = v.capacity(); unsafe { diff --git a/src/smolnetd/scheme/mod.rs b/src/smolnetd/scheme/mod.rs index ed4758bc36..118a862982 100644 --- a/src/smolnetd/scheme/mod.rs +++ b/src/smolnetd/scheme/mod.rs @@ -113,7 +113,7 @@ impl Smolnetd { self.iface .poll(&mut *self.socket_set.borrow_mut(), timestamp) .expect("poll error"); - self.notify_raw_sockets() + self.notify_sockets() } fn read_frames(&mut self) -> Result { @@ -147,7 +147,7 @@ impl Smolnetd { syscall::fsync(self.network_file.borrow_mut().as_raw_fd() as usize) } - fn notify_raw_sockets(&mut self) -> Result<()> { + fn notify_sockets(&mut self) -> Result<()> { self.ip_scheme.notify_sockets()?; self.udp_scheme.notify_sockets() } diff --git a/src/smolnetd/scheme/udp.rs b/src/smolnetd/scheme/udp.rs index e3d7e7783a..764af80d5e 100644 --- a/src/smolnetd/scheme/udp.rs +++ b/src/smolnetd/scheme/udp.rs @@ -18,7 +18,7 @@ use super::{Smolnetd, SocketSet}; use port_set::PortSet; use super::post_fevent; -#[derive(Copy, Clone, Eq, PartialEq)] +#[derive(Copy, Clone, Eq, PartialEq, Debug)] enum Setting { Ttl, ReadTimeout, @@ -54,19 +54,27 @@ impl FdHandle { } } +#[derive(Default, Clone)] struct WaitHandle { until: Option, packet: syscall::Packet, } +#[derive(Default)] +struct WaitQueues { + read_queue: Vec, + write_queue: Vec, +} + +type WaitQueueMap = BTreeMap; + pub struct UdpScheme { next_udp_fd: usize, udp_fds: BTreeMap, socket_set: SocketSet, port_set: PortSet, udp_file: File, - read_wait_queue: BTreeMap>, - write_wait_queue: BTreeMap>, + wait_queue_map: WaitQueueMap, } impl UdpScheme { @@ -78,8 +86,7 @@ impl UdpScheme { // 49152..65535 is the suggested range for dynamic private ports port_set: PortSet::new(49_152u16, 65_535u16).expect("Wrong UDP port numbers"), udp_file, - read_wait_queue: BTreeMap::new(), - write_wait_queue: BTreeMap::new(), + wait_queue_map: BTreeMap::new(), } } @@ -102,19 +109,109 @@ impl UdpScheme { } pub fn notify_sockets(&mut self) -> Result<()> { + // Notify non-blocking sockets for (&fd, handle) in &self.udp_fds { - if let FdHandle::Socket(UdpHandle { socket_handle, .. }) = *handle { + if let FdHandle::Socket(UdpHandle { + socket_handle, + events, + .. + }) = *handle + { let mut socket_set = self.socket_set.borrow_mut(); let socket: &mut UdpSocket = socket_set.get_mut(socket_handle).as_socket(); - if socket.can_send() { + + if events & syscall::EVENT_READ == syscall::EVENT_READ && socket.can_recv() { post_fevent(&mut self.udp_file, fd, syscall::EVENT_READ, 1)?; } + + if events & syscall::EVENT_WRITE == syscall::EVENT_WRITE && socket.can_send() { + post_fevent(&mut self.udp_file, fd, syscall::EVENT_WRITE, 1)?; + } + } + } + + // Wake up blocking queue + self.wake_up_queues()?; + + Ok(()) + } + + fn wake_up_queues(&mut self) -> Result<()> { + let mut cur_time = TimeSpec::default(); + syscall::clock_gettime(syscall::CLOCK_MONOTONIC, &mut cur_time) + .map_err(|e| Error::from_syscall_error(e, "Can't get time"))?; + + let socket_handles: Vec<_> = self.wait_queue_map.keys().cloned().collect(); + + for socket_handle in socket_handles { + let (can_recv, can_send) = { + let mut socket_set = self.socket_set.borrow_mut(); + let socket: &mut UdpSocket = socket_set.get_mut(socket_handle).as_socket(); + (socket.can_recv(), socket.can_send()) + }; + + if can_recv { + self.wake_up_wait_queue(socket_handle, cur_time, |wq| &mut wq.read_queue)?; + } + + if can_send { + self.wake_up_wait_queue(socket_handle, cur_time, |wq| &mut wq.write_queue)?; } } Ok(()) } + fn wake_up_wait_queue( + &mut self, + socket_handle: SocketHandle, + cur_time: syscall::TimeSpec, + f: F, + ) -> Result<()> + where + F: Fn(&mut WaitQueues) -> &mut Vec, + { + let mut input_queue = if let Some(wait_queues) = self.wait_queue_map.get_mut(&socket_handle) + { + ::std::mem::replace(f(wait_queues), vec![]) + } else { + vec![] + }; + + let mut to_retain = vec![]; + + for wait_handle in input_queue.drain(..) { + let mut packet = wait_handle.packet; + self.handle(&mut packet); + if packet.a == (-syscall::EWOULDBLOCK) as usize { + match wait_handle.until { + Some(until) + if (until.tv_sec >= cur_time.tv_sec + || (until.tv_sec == cur_time.tv_sec + && until.tv_nsec >= cur_time.tv_nsec)) => + { + trace!("Timeouting fd {}", packet.b); + packet.a = (-syscall::ETIMEDOUT) as usize; + self.udp_file.write_all(&packet)?; + } + _ => { + to_retain.push(wait_handle); + } + } + } else { + trace!("Waking up fd {}", packet.b); + self.udp_file.write_all(&packet)?; + } + } + + if let Some(wait_queues) = self.wait_queue_map.get_mut(&socket_handle) { + f(wait_queues).extend(to_retain); + } + + Ok(()) + } + fn handle_block(&mut self, mut packet: syscall::Packet) -> Result<()> { + trace!("Handling blocking call"); let syscall_result = self.try_handle_block(&mut packet); if let Err(syscall_error) = syscall_result { packet.a = (-syscall_error.errno) as usize; @@ -146,9 +243,9 @@ impl UdpScheme { } }?; - let (mut timeout, queue) = match packet.a { - syscall::SYS_READ => Ok((read_timeout, &mut self.read_wait_queue)), - syscall::SYS_WRITE => Ok((write_timeout, &mut self.write_wait_queue)), + let mut timeout = match packet.a { + syscall::SYS_READ => Ok(read_timeout), + syscall::SYS_WRITE => Ok(write_timeout), _ => Err(syscall::Error::new(syscall::EBADF)), }?; @@ -158,13 +255,21 @@ impl UdpScheme { *timeout = add_time(timeout, &cur_time) } - queue + trace!("Adding {} to wait queie", fd); + let wait_queues = self.wait_queue_map .entry(socket_handle) - .or_insert_with(|| vec![]) - .push(WaitHandle { - until: timeout, - packet: *packet, - }); + .or_insert_with(|| WaitQueues::default()); + + let queue = match packet.a { + syscall::SYS_READ => Ok(&mut wait_queues.read_queue), + syscall::SYS_WRITE => Ok(&mut wait_queues.write_queue), + _ => Err(syscall::Error::new(syscall::EBADF)), + }?; + + queue.push(WaitHandle { + until: timeout, + packet: *packet, + }); Ok(()) } @@ -192,6 +297,8 @@ impl UdpScheme { } }; + trace!("Getting {:?} from {}", setting, fd); + if buf.len() < mem::size_of::() { Ok(0) } else { @@ -217,6 +324,7 @@ impl UdpScheme { return Err(syscall::Error::new(syscall::EBADF)); } }; + trace!("Setting {:?} to {}", setting, fd); match setting { Setting::ReadTimeout | Setting::WriteTimeout => { let (timeout, count) = { @@ -319,8 +427,27 @@ impl syscall::SchemeMut for UdpScheme { let socket: &mut UdpSocket = socket_set.get_mut(socket_handle).as_socket(); socket.endpoint() }; - self.write_wait_queue.remove(&socket_handle); - self.read_wait_queue.remove(&socket_handle); + let remove = if let Some(ref mut wait_queues) = self.wait_queue_map.get_mut(&socket_handle) + { + wait_queues.read_queue.retain( + |&WaitHandle { + packet: syscall::Packet { a, .. }, + .. + }| a != fd, + ); + wait_queues.write_queue.retain( + |&WaitHandle { + packet: syscall::Packet { a, .. }, + .. + }| a != fd, + ); + wait_queues.read_queue.is_empty() && wait_queues.write_queue.is_empty() + } else { + false + }; + if remove { + self.wait_queue_map.remove(&socket_handle); + } socket_set.release(socket_handle); //TODO: removing sockets in release should make prune unnecessary socket_set.prune(); @@ -349,10 +476,16 @@ impl syscall::SchemeMut for UdpScheme { let mut socket_set = self.socket_set.borrow_mut(); let socket: &mut UdpSocket = socket_set.get_mut(handle.socket_handle).as_socket(); - socket - .send_slice(buf, handle.remote_endpoint) - .expect("Can't send slice"); - return Ok(buf.len()); + return if socket.can_send() { + socket + .send_slice(buf, handle.remote_endpoint) + .expect("Can't send slice"); + Ok(buf.len()) + } else if handle.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { + Ok(0) + } else { + Err(syscall::Error::new(syscall::EWOULDBLOCK)) + }; } } }; From de733b4bf86ff85a36e06fbc97ab1838b9723bcd Mon Sep 17 00:00:00 2001 From: Egor Karavaev Date: Mon, 2 Oct 2017 22:11:31 +0300 Subject: [PATCH 037/155] Factor out generic socket scheme. --- src/smolnetd/scheme/mod.rs | 5 +- src/smolnetd/scheme/socket.rs | 545 +++++++++++++++++++++++++ src/smolnetd/scheme/udp.rs | 649 ------------------------------ src/smolnetd/scheme/udp_socket.rs | 247 ++++++++++++ 4 files changed, 795 insertions(+), 651 deletions(-) create mode 100644 src/smolnetd/scheme/socket.rs delete mode 100644 src/smolnetd/scheme/udp.rs create mode 100644 src/smolnetd/scheme/udp_socket.rs diff --git a/src/smolnetd/scheme/mod.rs b/src/smolnetd/scheme/mod.rs index 118a862982..04cec36e43 100644 --- a/src/smolnetd/scheme/mod.rs +++ b/src/smolnetd/scheme/mod.rs @@ -14,10 +14,11 @@ use buffer_pool::{Buffer, BufferPool}; use device::NetworkDevice; use error::{Error, Result}; use self::ip::IpScheme; -use self::udp::UdpScheme; +use self::udp_socket::UdpScheme; mod ip; -mod udp; +mod socket; +mod udp_socket; type SocketSet = Rc>>; diff --git a/src/smolnetd/scheme/socket.rs b/src/smolnetd/scheme/socket.rs new file mode 100644 index 0000000000..75ab6a49cc --- /dev/null +++ b/src/smolnetd/scheme/socket.rs @@ -0,0 +1,545 @@ +use smoltcp::socket::{AsSocket, Socket, SocketHandle}; +use std::collections::BTreeMap; +use std::fs::File; +use std::io::{Read, Write}; +use std::str; +use std::marker::PhantomData; +use syscall::SchemeMut; +use syscall::data::TimeSpec; +use syscall; + +use error::{Error, Result}; +use super::SocketSet; +use super::post_fevent; + +pub struct SocketFile { + pub flags: usize, + events: usize, + socket_handle: SocketHandle, + pub data: DataT, + pub read_timeout: Option, + pub write_timeout: Option, +} + +impl SocketFile { + pub fn clone_with_data(&self, data: DataT) -> SocketFile { + SocketFile { + flags: self.flags, + events: self.events, + read_timeout: self.read_timeout, + write_timeout: self.write_timeout, + socket_handle: self.socket_handle, + data + } + } + + pub fn new_with_data(socket_handle: SocketHandle, data: DataT) -> SocketFile { + SocketFile { + flags: 0, + events: 0, + read_timeout: None, + write_timeout: None, + socket_handle, + data + } + } +} + +pub struct SettingFile { + pub fd: usize, + pub socket_handle: SocketHandle, + pub setting: SettingT, +} + +pub enum SchemeFile +where + SocketT: SchemeSocket, +{ + Setting(SettingFile), + Socket(SocketFile), +} + +impl SchemeFile +where + SocketT: SchemeSocket, +{ + fn socket_handle(&self) -> SocketHandle { + match *self { + SchemeFile::Socket(SocketFile { socket_handle, .. }) | + SchemeFile::Setting(SettingFile { socket_handle, .. }) => socket_handle, + } + } +} + +#[derive(Default, Clone)] +struct WaitHandle { + until: Option, + packet: syscall::Packet, +} + +#[derive(Default)] +struct WaitQueues { + read_queue: Vec, + write_queue: Vec, +} + +pub trait SchemeSocket +where + Self: ::std::marker::Sized, +{ + type SchemeDataT; + type DataT; + type SettingT: Copy; + + fn new_scheme_data() -> Self::SchemeDataT; + + fn can_send(&self) -> bool; + fn can_recv(&self) -> bool; + + fn get_setting(&SocketFile, Self::SettingT, &mut [u8]) -> syscall::Result; + fn set_setting(&mut SocketFile, Self::SettingT, &[u8]) -> syscall::Result; + + fn new_socket( + &str, + u32, + &mut Self::SchemeDataT, + ) -> syscall::Result<(Socket<'static, 'static>, Self::DataT)>; + fn close_file(&self, &SchemeFile, &mut Self::SchemeDataT) -> syscall::Result<()>; + + fn write_buf(&mut self, &mut SocketFile, buf: &[u8]) -> syscall::Result; + fn read_buf(&mut self, &mut SocketFile, buf: &mut [u8]) -> syscall::Result; + + fn dup( + &self, + &mut SchemeFile, + usize, + SocketHandle, + &str, + &mut Self::SchemeDataT, + ) -> syscall::Result>; +} + +type WaitQueueMap = BTreeMap; + +pub struct SocketScheme +where + SocketT: SchemeSocket, + Socket<'static, 'static>: AsSocket, +{ + next_fd: usize, + fds: BTreeMap>, + socket_set: SocketSet, + scheme_file: File, + wait_queue_map: WaitQueueMap, + scheme_data: SocketT::SchemeDataT, + _phantom_socket: PhantomData, +} + +impl SocketScheme +where + SocketT: SchemeSocket, + Socket<'static, 'static>: AsSocket, +{ + pub fn new(socket_set: SocketSet, scheme_file: File) -> SocketScheme { + SocketScheme { + next_fd: 1, + fds: BTreeMap::new(), + socket_set, + scheme_data: SocketT::new_scheme_data(), + scheme_file, + wait_queue_map: BTreeMap::new(), + _phantom_socket: PhantomData, + } + } + + pub fn on_scheme_event(&mut self) -> Result> { + loop { + let mut packet = syscall::Packet::default(); + if self.scheme_file.read(&mut packet)? == 0 { + break; + } + let a = packet.a; + self.handle(&mut packet); + if packet.a != (-syscall::EWOULDBLOCK) as usize { + self.scheme_file.write_all(&packet)?; + } else { + packet.a = a; + self.handle_block(packet)?; + } + } + Ok(None) + } + + pub fn notify_sockets(&mut self) -> Result<()> { + // Notify non-blocking sockets + for (&fd, handle) in &self.fds { + if let SchemeFile::Socket(SocketFile { + socket_handle, + events, + .. + }) = *handle + { + let mut socket_set = self.socket_set.borrow_mut(); + let socket: &mut SocketT = socket_set.get_mut(socket_handle).as_socket(); + + if events & syscall::EVENT_READ == syscall::EVENT_READ && socket.can_recv() { + post_fevent(&mut self.scheme_file, fd, syscall::EVENT_READ, 1)?; + } + + if events & syscall::EVENT_WRITE == syscall::EVENT_WRITE && socket.can_send() { + post_fevent(&mut self.scheme_file, fd, syscall::EVENT_WRITE, 1)?; + } + } + } + + // Wake up blocking queue + self.wake_up_queues()?; + + Ok(()) + } + + fn wake_up_queues(&mut self) -> Result<()> { + let mut cur_time = TimeSpec::default(); + syscall::clock_gettime(syscall::CLOCK_MONOTONIC, &mut cur_time) + .map_err(|e| Error::from_syscall_error(e, "Can't get time"))?; + + let socket_handles: Vec<_> = self.wait_queue_map.keys().cloned().collect(); + + for socket_handle in socket_handles { + let (can_recv, can_send) = { + let mut socket_set = self.socket_set.borrow_mut(); + let socket: &mut SocketT = socket_set.get_mut(socket_handle).as_socket(); + (socket.can_recv(), socket.can_send()) + }; + + if can_recv { + self.wake_up_wait_queue(socket_handle, cur_time, |wq| &mut wq.read_queue)?; + } + + if can_send { + self.wake_up_wait_queue(socket_handle, cur_time, |wq| &mut wq.write_queue)?; + } + } + Ok(()) + } + + fn wake_up_wait_queue( + &mut self, + socket_handle: SocketHandle, + cur_time: syscall::TimeSpec, + f: F, + ) -> Result<()> + where + F: Fn(&mut WaitQueues) -> &mut Vec, + { + let mut input_queue = if let Some(wait_queues) = self.wait_queue_map.get_mut(&socket_handle) + { + ::std::mem::replace(f(wait_queues), vec![]) + } else { + vec![] + }; + + let mut to_retain = vec![]; + + for wait_handle in input_queue.drain(..) { + let mut packet = wait_handle.packet; + self.handle(&mut packet); + if packet.a == (-syscall::EWOULDBLOCK) as usize { + match wait_handle.until { + Some(until) + if (until.tv_sec >= cur_time.tv_sec + || (until.tv_sec == cur_time.tv_sec + && until.tv_nsec >= cur_time.tv_nsec)) => + { + trace!("Timeouting fd {}", packet.b); + packet.a = (-syscall::ETIMEDOUT) as usize; + self.scheme_file.write_all(&packet)?; + } + _ => { + to_retain.push(wait_handle); + } + } + } else { + trace!("Waking up fd {}", packet.b); + self.scheme_file.write_all(&packet)?; + } + } + + if let Some(wait_queues) = self.wait_queue_map.get_mut(&socket_handle) { + f(wait_queues).extend(to_retain); + } + + Ok(()) + } + + fn handle_block(&mut self, mut packet: syscall::Packet) -> Result<()> { + trace!("Handling blocking call"); + let syscall_result = self.try_handle_block(&mut packet); + if let Err(syscall_error) = syscall_result { + packet.a = (-syscall_error.errno) as usize; + self.scheme_file.write_all(&packet)?; + Err(Error::from_syscall_error( + syscall_error, + "Can't handle blocked socket", + )) + } else { + Ok(()) + } + } + + fn try_handle_block(&mut self, packet: &mut syscall::Packet) -> syscall::Result<()> { + let fd = packet.b; + let (socket_handle, read_timeout, write_timeout) = { + let handle = self.fds + .get(&fd) + .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; + + if let SchemeFile::Socket(ref scheme_file) = *handle { + Ok(( + scheme_file.socket_handle, + scheme_file.read_timeout, + scheme_file.write_timeout, + )) + } else { + Err(syscall::Error::new(syscall::EBADF)) + } + }?; + + let mut timeout = match packet.a { + syscall::SYS_READ => Ok(read_timeout), + syscall::SYS_WRITE => Ok(write_timeout), + _ => Err(syscall::Error::new(syscall::EBADF)), + }?; + + if let Some(ref mut timeout) = timeout { + let mut cur_time = TimeSpec::default(); + syscall::clock_gettime(syscall::CLOCK_MONOTONIC, &mut cur_time)?; + *timeout = add_time(timeout, &cur_time) + } + + trace!("Adding {} to wait queie", fd); + let wait_queues = self.wait_queue_map + .entry(socket_handle) + .or_insert_with(|| WaitQueues::default()); + + let queue = match packet.a { + syscall::SYS_READ => Ok(&mut wait_queues.read_queue), + syscall::SYS_WRITE => Ok(&mut wait_queues.write_queue), + _ => Err(syscall::Error::new(syscall::EBADF)), + }?; + + queue.push(WaitHandle { + until: timeout, + packet: *packet, + }); + + Ok(()) + } + + fn get_setting( + &mut self, + fd: usize, + setting: SocketT::SettingT, + buf: &mut [u8], + ) -> syscall::Result { + let handle = self.fds + .get_mut(&fd) + .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; + let handle = match *handle { + SchemeFile::Socket(ref mut handle) => handle, + _ => { + return Err(syscall::Error::new(syscall::EBADF)); + } + }; + + SocketT::get_setting(handle, setting, buf) + } + + fn update_setting( + &mut self, + fd: usize, + setting: SocketT::SettingT, + buf: &[u8], + ) -> syscall::Result { + let handle = self.fds + .get_mut(&fd) + .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; + let handle = match *handle { + SchemeFile::Socket(ref mut handle) => handle, + _ => { + return Err(syscall::Error::new(syscall::EBADF)); + } + }; + SocketT::set_setting(handle, setting, buf) + } +} + +impl syscall::SchemeMut for SocketScheme +where + SocketT: SchemeSocket, + Socket<'static, 'static>: AsSocket, +{ + fn open(&mut self, url: &[u8], flags: usize, uid: u32, _gid: u32) -> syscall::Result { + let path = str::from_utf8(url).or_else(|_| Err(syscall::Error::new(syscall::EINVAL)))?; + + let (socket, data) = SocketT::new_socket(path, uid, &mut self.scheme_data)?; + + let socket_handle = self.socket_set.borrow_mut().add(socket); + let id = self.next_fd; + + self.fds.insert( + id, + SchemeFile::Socket(SocketFile { + flags, + events: 0, + socket_handle, + write_timeout: None, + read_timeout: None, + data, + }), + ); + self.next_fd += 1; + Ok(id) + } + + fn close(&mut self, fd: usize) -> syscall::Result { + let socket_handle = { + let handle = self.fds + .get(&fd) + .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; + handle.socket_handle() + }; + let scheme_file = self.fds.remove(&fd); + let mut socket_set = self.socket_set.borrow_mut(); + if let Some(scheme_file) = scheme_file { + let socket: &mut SocketT = socket_set.get_mut(socket_handle).as_socket(); + socket.close_file(&scheme_file, &mut self.scheme_data)?; + } + let remove_wq = + if let Some(ref mut wait_queues) = self.wait_queue_map.get_mut(&socket_handle) { + wait_queues.read_queue.retain( + |&WaitHandle { + packet: syscall::Packet { a, .. }, + .. + }| a != fd, + ); + wait_queues.write_queue.retain( + |&WaitHandle { + packet: syscall::Packet { a, .. }, + .. + }| a != fd, + ); + wait_queues.read_queue.is_empty() && wait_queues.write_queue.is_empty() + } else { + false + }; + if remove_wq { + self.wait_queue_map.remove(&socket_handle); + } + socket_set.release(socket_handle); + //TODO: removing sockets in release should make prune unnecessary + socket_set.prune(); + Ok(0) + } + + fn write(&mut self, fd: usize, buf: &[u8]) -> syscall::Result { + let (fd, setting) = { + let handle = self.fds + .get_mut(&fd) + .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; + + match *handle { + SchemeFile::Setting(ref setting_handle) => { + (setting_handle.fd, setting_handle.setting) + } + SchemeFile::Socket(ref mut handle) => { + let mut socket_set = self.socket_set.borrow_mut(); + let socket: &mut SocketT = socket_set.get_mut(handle.socket_handle).as_socket(); + + return ::write_buf(socket, handle, buf); + } + } + }; + self.update_setting(fd, setting, buf) + } + + fn read(&mut self, fd: usize, buf: &mut [u8]) -> syscall::Result { + let (fd, setting) = { + let handle = self.fds + .get_mut(&fd) + .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; + match *handle { + SchemeFile::Setting(ref setting_handle) => { + (setting_handle.fd, setting_handle.setting) + } + SchemeFile::Socket(ref mut handle) => { + let mut socket_set = self.socket_set.borrow_mut(); + let socket: &mut SocketT = socket_set.get_mut(handle.socket_handle).as_socket(); + return ::read_buf(socket, handle, buf); + } + } + }; + self.get_setting(fd, setting, buf) + } + + fn dup(&mut self, fd: usize, buf: &[u8]) -> syscall::Result { + let path = str::from_utf8(buf).or_else(|_| Err(syscall::Error::new(syscall::EINVAL)))?; + + let handle = { + let handle = self.fds + .get_mut(&fd) + .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; + + let socket_handle = handle.socket_handle(); + let mut socket_set = self.socket_set.borrow_mut(); + let socket: &mut SocketT = socket_set.get_mut(handle.socket_handle()).as_socket(); + + socket.dup(handle, fd, socket_handle, path, &mut self.scheme_data) + }?; + + self.socket_set.borrow_mut().retain(handle.socket_handle()); + + let id = self.next_fd; + self.fds.insert(id, handle); + self.next_fd += 1; + + Ok(id) + } + + fn fevent(&mut self, fd: usize, events: usize) -> syscall::Result { + let handle = self.fds + .get_mut(&fd) + .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; + match *handle { + SchemeFile::Setting(_) => Err(syscall::Error::new(syscall::EBADF)), + SchemeFile::Socket(ref mut handle) => { + handle.events = events; + Ok(fd) + } + } + } + + fn fsync(&mut self, fd: usize) -> syscall::Result { + { + let _handle = self.fds + .get_mut(&fd) + .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; + } + Ok(0) + // TODO Implement fsyncing + // self.0.network_fsync() + } +} + +fn add_time(a: &TimeSpec, b: &TimeSpec) -> TimeSpec { + let mut secs = a.tv_sec + b.tv_sec; + let mut nsecs = a.tv_nsec + b.tv_nsec; + + secs += i64::from(nsecs) / 1_000_000_000; + nsecs %= 1_000_000_000; + + TimeSpec { + tv_sec: secs, + tv_nsec: nsecs, + } +} diff --git a/src/smolnetd/scheme/udp.rs b/src/smolnetd/scheme/udp.rs deleted file mode 100644 index 764af80d5e..0000000000 --- a/src/smolnetd/scheme/udp.rs +++ /dev/null @@ -1,649 +0,0 @@ -use smoltcp::socket::{AsSocket, SocketHandle, UdpPacketBuffer, UdpSocket, UdpSocketBuffer}; -use smoltcp::wire::{IpAddress, IpEndpoint, Ipv4Address}; -use std::collections::BTreeMap; -use std::fs::File; -use std::io::{Read, Write}; -use std::str::FromStr; -use std::str; -use std::mem; -use std::ops::Deref; -use std::ops::DerefMut; -use syscall::SchemeMut; -use syscall::data::TimeSpec; -use syscall; - -use device::NetworkDevice; -use error::{Error, Result}; -use super::{Smolnetd, SocketSet}; -use port_set::PortSet; -use super::post_fevent; - -#[derive(Copy, Clone, Eq, PartialEq, Debug)] -enum Setting { - Ttl, - ReadTimeout, - WriteTimeout, -} - -struct UdpHandle { - flags: usize, - events: usize, - remote_endpoint: IpEndpoint, - read_timeout: Option, - write_timeout: Option, - socket_handle: SocketHandle, -} - -struct SettingHandle { - fd: usize, - socket_handle: SocketHandle, - setting: Setting, -} - -enum FdHandle { - Setting(SettingHandle), - Socket(UdpHandle), -} - -impl FdHandle { - fn socket_handle(&self) -> SocketHandle { - match *self { - FdHandle::Socket(UdpHandle { socket_handle, .. }) | - FdHandle::Setting(SettingHandle { socket_handle, .. }) => socket_handle, - } - } -} - -#[derive(Default, Clone)] -struct WaitHandle { - until: Option, - packet: syscall::Packet, -} - -#[derive(Default)] -struct WaitQueues { - read_queue: Vec, - write_queue: Vec, -} - -type WaitQueueMap = BTreeMap; - -pub struct UdpScheme { - next_udp_fd: usize, - udp_fds: BTreeMap, - socket_set: SocketSet, - port_set: PortSet, - udp_file: File, - wait_queue_map: WaitQueueMap, -} - -impl UdpScheme { - pub fn new(socket_set: SocketSet, udp_file: File) -> UdpScheme { - UdpScheme { - next_udp_fd: 1, - udp_fds: BTreeMap::new(), - socket_set, - // 49152..65535 is the suggested range for dynamic private ports - port_set: PortSet::new(49_152u16, 65_535u16).expect("Wrong UDP port numbers"), - udp_file, - wait_queue_map: BTreeMap::new(), - } - } - - pub fn on_scheme_event(&mut self) -> Result> { - loop { - let mut packet = syscall::Packet::default(); - if self.udp_file.read(&mut packet)? == 0 { - break; - } - let a = packet.a; - self.handle(&mut packet); - if packet.a != (-syscall::EWOULDBLOCK) as usize { - self.udp_file.write_all(&packet)?; - } else { - packet.a = a; - self.handle_block(packet)?; - } - } - Ok(None) - } - - pub fn notify_sockets(&mut self) -> Result<()> { - // Notify non-blocking sockets - for (&fd, handle) in &self.udp_fds { - if let FdHandle::Socket(UdpHandle { - socket_handle, - events, - .. - }) = *handle - { - let mut socket_set = self.socket_set.borrow_mut(); - let socket: &mut UdpSocket = socket_set.get_mut(socket_handle).as_socket(); - - if events & syscall::EVENT_READ == syscall::EVENT_READ && socket.can_recv() { - post_fevent(&mut self.udp_file, fd, syscall::EVENT_READ, 1)?; - } - - if events & syscall::EVENT_WRITE == syscall::EVENT_WRITE && socket.can_send() { - post_fevent(&mut self.udp_file, fd, syscall::EVENT_WRITE, 1)?; - } - } - } - - // Wake up blocking queue - self.wake_up_queues()?; - - Ok(()) - } - - fn wake_up_queues(&mut self) -> Result<()> { - let mut cur_time = TimeSpec::default(); - syscall::clock_gettime(syscall::CLOCK_MONOTONIC, &mut cur_time) - .map_err(|e| Error::from_syscall_error(e, "Can't get time"))?; - - let socket_handles: Vec<_> = self.wait_queue_map.keys().cloned().collect(); - - for socket_handle in socket_handles { - let (can_recv, can_send) = { - let mut socket_set = self.socket_set.borrow_mut(); - let socket: &mut UdpSocket = socket_set.get_mut(socket_handle).as_socket(); - (socket.can_recv(), socket.can_send()) - }; - - if can_recv { - self.wake_up_wait_queue(socket_handle, cur_time, |wq| &mut wq.read_queue)?; - } - - if can_send { - self.wake_up_wait_queue(socket_handle, cur_time, |wq| &mut wq.write_queue)?; - } - } - Ok(()) - } - - fn wake_up_wait_queue( - &mut self, - socket_handle: SocketHandle, - cur_time: syscall::TimeSpec, - f: F, - ) -> Result<()> - where - F: Fn(&mut WaitQueues) -> &mut Vec, - { - let mut input_queue = if let Some(wait_queues) = self.wait_queue_map.get_mut(&socket_handle) - { - ::std::mem::replace(f(wait_queues), vec![]) - } else { - vec![] - }; - - let mut to_retain = vec![]; - - for wait_handle in input_queue.drain(..) { - let mut packet = wait_handle.packet; - self.handle(&mut packet); - if packet.a == (-syscall::EWOULDBLOCK) as usize { - match wait_handle.until { - Some(until) - if (until.tv_sec >= cur_time.tv_sec - || (until.tv_sec == cur_time.tv_sec - && until.tv_nsec >= cur_time.tv_nsec)) => - { - trace!("Timeouting fd {}", packet.b); - packet.a = (-syscall::ETIMEDOUT) as usize; - self.udp_file.write_all(&packet)?; - } - _ => { - to_retain.push(wait_handle); - } - } - } else { - trace!("Waking up fd {}", packet.b); - self.udp_file.write_all(&packet)?; - } - } - - if let Some(wait_queues) = self.wait_queue_map.get_mut(&socket_handle) { - f(wait_queues).extend(to_retain); - } - - Ok(()) - } - - fn handle_block(&mut self, mut packet: syscall::Packet) -> Result<()> { - trace!("Handling blocking call"); - let syscall_result = self.try_handle_block(&mut packet); - if let Err(syscall_error) = syscall_result { - packet.a = (-syscall_error.errno) as usize; - self.udp_file.write_all(&packet)?; - Err(Error::from_syscall_error( - syscall_error, - "Can't handle blocked socket", - )) - } else { - Ok(()) - } - } - - fn try_handle_block(&mut self, packet: &mut syscall::Packet) -> syscall::Result<()> { - let fd = packet.b; - let (socket_handle, read_timeout, write_timeout) = { - let handle = self.udp_fds - .get(&fd) - .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; - - if let FdHandle::Socket(ref udp_handle) = *handle { - Ok(( - udp_handle.socket_handle, - udp_handle.read_timeout, - udp_handle.write_timeout, - )) - } else { - Err(syscall::Error::new(syscall::EBADF)) - } - }?; - - let mut timeout = match packet.a { - syscall::SYS_READ => Ok(read_timeout), - syscall::SYS_WRITE => Ok(write_timeout), - _ => Err(syscall::Error::new(syscall::EBADF)), - }?; - - if let Some(ref mut timeout) = timeout { - let mut cur_time = TimeSpec::default(); - syscall::clock_gettime(syscall::CLOCK_MONOTONIC, &mut cur_time)?; - *timeout = add_time(timeout, &cur_time) - } - - trace!("Adding {} to wait queie", fd); - let wait_queues = self.wait_queue_map - .entry(socket_handle) - .or_insert_with(|| WaitQueues::default()); - - let queue = match packet.a { - syscall::SYS_READ => Ok(&mut wait_queues.read_queue), - syscall::SYS_WRITE => Ok(&mut wait_queues.write_queue), - _ => Err(syscall::Error::new(syscall::EBADF)), - }?; - - queue.push(WaitHandle { - until: timeout, - packet: *packet, - }); - - Ok(()) - } - - fn get_setting( - &mut self, - fd: usize, - setting: Setting, - buf: &mut [u8], - ) -> syscall::Result { - let handle = self.udp_fds - .get_mut(&fd) - .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; - let handle = match *handle { - FdHandle::Socket(ref mut handle) => handle, - _ => { - return Err(syscall::Error::new(syscall::EBADF)); - } - }; - let timespec = match (setting, handle.read_timeout, handle.write_timeout) { - (Setting::ReadTimeout, Some(read_timeout), _) => read_timeout, - (Setting::WriteTimeout, _, Some(write_timeout)) => write_timeout, - _ => { - return Ok(0); - } - }; - - trace!("Getting {:?} from {}", setting, fd); - - if buf.len() < mem::size_of::() { - Ok(0) - } else { - let count = timespec.deref().read(buf).map_err(|err| { - syscall::Error::new(err.raw_os_error().unwrap_or(syscall::EIO)) - })?; - Ok(count) - } - } - - fn update_setting( - &mut self, - fd: usize, - setting: Setting, - buf: &[u8], - ) -> syscall::Result { - let handle = self.udp_fds - .get_mut(&fd) - .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; - let handle = match *handle { - FdHandle::Socket(ref mut handle) => handle, - _ => { - return Err(syscall::Error::new(syscall::EBADF)); - } - }; - trace!("Setting {:?} to {}", setting, fd); - match setting { - Setting::ReadTimeout | Setting::WriteTimeout => { - let (timeout, count) = { - if buf.len() < mem::size_of::() { - (None, 0) - } else { - let mut timespec = TimeSpec::default(); - let count = timespec.deref_mut().write(buf).map_err(|err| { - syscall::Error::new(err.raw_os_error().unwrap_or(syscall::EIO)) - })?; - (Some(timespec), count) - } - }; - match setting { - Setting::ReadTimeout => { - handle.read_timeout = timeout; - } - Setting::WriteTimeout => { - handle.write_timeout = timeout; - } - _ => {} - }; - return Ok(count); - } - Setting::Ttl => {} - } - Ok(0) - } -} - -impl syscall::SchemeMut for UdpScheme { - fn open(&mut self, url: &[u8], flags: usize, uid: u32, _gid: u32) -> syscall::Result { - let path = str::from_utf8(url).or_else(|_| Err(syscall::Error::new(syscall::EINVAL)))?; - - trace!("Udp open {} ", path); - - let mut parts = path.split('/'); - let remote_endpoint = parse_endpoint(parts.next().unwrap_or("")); - let mut local_endpoint = parse_endpoint(parts.next().unwrap_or("")); - - if local_endpoint.port <= 1024 && uid != 0 { - return Err(syscall::Error::new(syscall::EACCES)); - } - - let mut rx_packets = Vec::with_capacity(Smolnetd::SOCKET_BUFFER_SIZE); - let mut tx_packets = Vec::with_capacity(Smolnetd::SOCKET_BUFFER_SIZE); - for _ in 0..Smolnetd::SOCKET_BUFFER_SIZE { - rx_packets.push(UdpPacketBuffer::new(vec![0; NetworkDevice::MTU])); - tx_packets.push(UdpPacketBuffer::new(vec![0; NetworkDevice::MTU])); - } - let rx_buffer = UdpSocketBuffer::new(rx_packets); - let tx_buffer = UdpSocketBuffer::new(tx_packets); - let mut udp_socket = UdpSocket::new(rx_buffer, tx_buffer); - - if local_endpoint.port == 0 { - local_endpoint.port = self.port_set - .get_port() - .ok_or_else(|| syscall::Error::new(syscall::EINVAL))?; - } else if !self.port_set.claim_port(local_endpoint.port) { - return Err(syscall::Error::new(syscall::EADDRINUSE)); - } - - { - let udp_socket: &mut UdpSocket = udp_socket.as_socket(); - udp_socket - .bind(local_endpoint) - .expect("Can't bind udp socket to local endpoint"); - } - - let socket_handle = self.socket_set.borrow_mut().add(udp_socket); - let id = self.next_udp_fd; - - self.udp_fds.insert( - id, - FdHandle::Socket(UdpHandle { - flags, - events: 0, - socket_handle, - write_timeout: None, - read_timeout: None, - remote_endpoint: remote_endpoint, - }), - ); - self.next_udp_fd += 1; - trace!("Udp open fd {} ", id); - Ok(id) - } - - fn close(&mut self, fd: usize) -> syscall::Result { - trace!("Upd close {}", fd); - let socket_handle = { - let handle = self.udp_fds - .get(&fd) - .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; - handle.socket_handle() - }; - self.udp_fds.remove(&fd); - let mut socket_set = self.socket_set.borrow_mut(); - let endpoint = { - let socket: &mut UdpSocket = socket_set.get_mut(socket_handle).as_socket(); - socket.endpoint() - }; - let remove = if let Some(ref mut wait_queues) = self.wait_queue_map.get_mut(&socket_handle) - { - wait_queues.read_queue.retain( - |&WaitHandle { - packet: syscall::Packet { a, .. }, - .. - }| a != fd, - ); - wait_queues.write_queue.retain( - |&WaitHandle { - packet: syscall::Packet { a, .. }, - .. - }| a != fd, - ); - wait_queues.read_queue.is_empty() && wait_queues.write_queue.is_empty() - } else { - false - }; - if remove { - self.wait_queue_map.remove(&socket_handle); - } - socket_set.release(socket_handle); - //TODO: removing sockets in release should make prune unnecessary - socket_set.prune(); - if endpoint.port != 0 { - self.port_set.release_port(endpoint.port); - } - Ok(0) - } - - fn write(&mut self, fd: usize, buf: &[u8]) -> syscall::Result { - trace!("Upd write {} len {}", fd, buf.len()); - - let (fd, setting) = { - let handle = self.udp_fds - .get(&fd) - .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; - - match *handle { - FdHandle::Setting(ref setting_handle) => { - (setting_handle.fd, setting_handle.setting) - } - FdHandle::Socket(ref handle) => { - if !handle.remote_endpoint.is_specified() { - return Err(syscall::Error::new(syscall::EADDRNOTAVAIL)); - } - let mut socket_set = self.socket_set.borrow_mut(); - let socket: &mut UdpSocket = - socket_set.get_mut(handle.socket_handle).as_socket(); - return if socket.can_send() { - socket - .send_slice(buf, handle.remote_endpoint) - .expect("Can't send slice"); - Ok(buf.len()) - } else if handle.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { - Ok(0) - } else { - Err(syscall::Error::new(syscall::EWOULDBLOCK)) - }; - } - } - }; - self.update_setting(fd, setting, buf) - } - - fn read(&mut self, fd: usize, buf: &mut [u8]) -> syscall::Result { - trace!("udp read {} {}", fd, buf.len()); - let (fd, setting) = { - let handle = self.udp_fds.get(&fd).ok_or_else(|| { - trace!("UDP read EBADF {}", fd); - syscall::Error::new(syscall::EBADF) - })?; - match *handle { - FdHandle::Setting(ref setting_handle) => { - (setting_handle.fd, setting_handle.setting) - } - FdHandle::Socket(ref handle) => { - let mut socket_set = self.socket_set.borrow_mut(); - let socket: &mut UdpSocket = - socket_set.get_mut(handle.socket_handle).as_socket(); - return if socket.can_recv() { - let (length, _) = socket.recv_slice(buf).expect("Can't receive slice"); - trace!("Upd read {}", fd); - Ok(length) - } else if handle.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { - Ok(0) - } else { - Err(syscall::Error::new(syscall::EWOULDBLOCK)) - }; - } - } - }; - self.get_setting(fd, setting, buf) - } - - fn dup(&mut self, fd: usize, buf: &[u8]) -> syscall::Result { - let path = str::from_utf8(buf).or_else(|_| Err(syscall::Error::new(syscall::EINVAL)))?; - trace!("udp dup {} {}", fd, path); - - let handle = { - let handle = self.udp_fds - .get_mut(&fd) - .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; - - let socket_handle = handle.socket_handle(); - - match path { - "ttl" => FdHandle::Setting(SettingHandle { - socket_handle, - fd, - setting: Setting::Ttl, - }), - "read_timeout" => FdHandle::Setting(SettingHandle { - socket_handle, - fd, - setting: Setting::ReadTimeout, - }), - "write_timeout" => FdHandle::Setting(SettingHandle { - socket_handle, - fd, - setting: Setting::WriteTimeout, - }), - _ => { - let remote_endpoint = parse_endpoint(path); - if let FdHandle::Socket(ref udp_handle) = *handle { - FdHandle::Socket(UdpHandle { - flags: udp_handle.flags, - events: udp_handle.events, - read_timeout: udp_handle.read_timeout, - write_timeout: udp_handle.write_timeout, - remote_endpoint: if remote_endpoint.is_specified() { - remote_endpoint - } else { - udp_handle.remote_endpoint - }, - socket_handle, - }) - } else { - FdHandle::Socket(UdpHandle { - flags: 0, - events: 0, - read_timeout: None, - write_timeout: None, - remote_endpoint: remote_endpoint, - socket_handle, - }) - } - } - } - }; - - self.socket_set.borrow_mut().retain(handle.socket_handle()); - let port = { - let mut socket_set = self.socket_set.borrow_mut(); - let socket: &mut UdpSocket = socket_set.get_mut(handle.socket_handle()).as_socket(); - socket.endpoint().port - }; - self.port_set.acquire_port(port); - - let id = self.next_udp_fd; - self.udp_fds.insert(id, handle); - self.next_udp_fd += 1; - - Ok(id) - } - - fn fevent(&mut self, fd: usize, events: usize) -> syscall::Result { - trace!("udp fevent {}", fd); - let handle = self.udp_fds - .get_mut(&fd) - .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; - match *handle { - FdHandle::Setting(_) => Err(syscall::Error::new(syscall::EBADF)), - FdHandle::Socket(ref mut handle) => { - handle.events = events; - Ok(fd) - } - } - } - - fn fsync(&mut self, fd: usize) -> syscall::Result { - trace!("udp fsync {}", fd); - { - let _handle = self.udp_fds - .get_mut(&fd) - .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; - } - Ok(0) - // TODO Implement fsyncing - // self.0.network_fsync() - } -} - -fn parse_endpoint(socket: &str) -> IpEndpoint { - let mut socket_parts = socket.split(':'); - let host = IpAddress::Ipv4( - Ipv4Address::from_str(socket_parts.next().unwrap_or("")) - .unwrap_or_else(|_| Ipv4Address::new(0, 0, 0, 0)), - ); - - let port = socket_parts - .next() - .unwrap_or("") - .parse::() - .unwrap_or(0); - IpEndpoint::new(host, port) -} - -fn add_time(a: &TimeSpec, b: &TimeSpec) -> TimeSpec { - let mut secs = a.tv_sec + b.tv_sec; - let mut nsecs = a.tv_nsec + b.tv_nsec; - - secs += i64::from(nsecs) / 1_000_000_000; - nsecs %= 1_000_000_000; - - TimeSpec { - tv_sec: secs, - tv_nsec: nsecs, - } -} diff --git a/src/smolnetd/scheme/udp_socket.rs b/src/smolnetd/scheme/udp_socket.rs new file mode 100644 index 0000000000..e06825a1e3 --- /dev/null +++ b/src/smolnetd/scheme/udp_socket.rs @@ -0,0 +1,247 @@ +use super::socket::*; + +use smoltcp::socket::{AsSocket, Socket, SocketHandle, UdpPacketBuffer, UdpSocket, UdpSocketBuffer}; +use smoltcp::wire::{IpAddress, IpEndpoint, Ipv4Address}; +use std::io::{Read, Write}; +use std::str::FromStr; +use std::str; +use std::mem; +use std::ops::Deref; +use std::ops::DerefMut; +use syscall::data::TimeSpec; +use syscall; + +use device::NetworkDevice; +use super::Smolnetd; +use port_set::PortSet; + +pub type UdpScheme = SocketScheme>; + +#[derive(Copy, Clone, Eq, PartialEq, Debug)] +pub enum Setting { + Ttl, + ReadTimeout, + WriteTimeout, +} + +impl<'a, 'b> SchemeSocket for UdpSocket<'a, 'b> { + type SchemeDataT = PortSet; + type DataT = IpEndpoint; + type SettingT = Setting; + + fn new_scheme_data() -> Self::SchemeDataT { + PortSet::new(49_152u16, 65_535u16).expect("Wrong UDP port numbers") + } + + fn can_send(&self) -> bool { + self.can_send() + } + + fn can_recv(&self) -> bool { + self.can_recv() + } + + fn get_setting( + file: &SocketFile, + setting: Self::SettingT, + buf: &mut [u8], + ) -> syscall::Result { + let timespec = match (setting, file.read_timeout, file.write_timeout) { + (Setting::ReadTimeout, Some(read_timeout), _) => read_timeout, + (Setting::WriteTimeout, _, Some(write_timeout)) => write_timeout, + _ => { + return Ok(0); + } + }; + + if buf.len() < mem::size_of::() { + Ok(0) + } else { + let count = timespec.deref().read(buf).map_err(|err| { + syscall::Error::new(err.raw_os_error().unwrap_or(syscall::EIO)) + })?; + Ok(count) + } + } + + fn set_setting( + file: &mut SocketFile, + setting: Self::SettingT, + buf: &[u8], + ) -> syscall::Result { + match setting { + Setting::ReadTimeout | Setting::WriteTimeout => { + let (timeout, count) = { + if buf.len() < mem::size_of::() { + (None, 0) + } else { + let mut timespec = TimeSpec::default(); + let count = timespec.deref_mut().write(buf).map_err(|err| { + syscall::Error::new(err.raw_os_error().unwrap_or(syscall::EIO)) + })?; + (Some(timespec), count) + } + }; + match setting { + Setting::ReadTimeout => { + file.read_timeout = timeout; + } + Setting::WriteTimeout => { + file.write_timeout = timeout; + } + _ => {} + }; + return Ok(count); + } + Setting::Ttl => {} + } + Ok(0) + } + + fn new_socket( + path: &str, + uid: u32, + port_set: &mut Self::SchemeDataT, + ) -> syscall::Result<(Socket<'static, 'static>, Self::DataT)> { + let mut parts = path.split('/'); + let remote_endpoint = parse_endpoint(parts.next().unwrap_or("")); + let mut local_endpoint = parse_endpoint(parts.next().unwrap_or("")); + + if local_endpoint.port <= 1024 && uid != 0 { + return Err(syscall::Error::new(syscall::EACCES)); + } + + let mut rx_packets = Vec::with_capacity(Smolnetd::SOCKET_BUFFER_SIZE); + let mut tx_packets = Vec::with_capacity(Smolnetd::SOCKET_BUFFER_SIZE); + for _ in 0..Smolnetd::SOCKET_BUFFER_SIZE { + rx_packets.push(UdpPacketBuffer::new(vec![0; NetworkDevice::MTU])); + tx_packets.push(UdpPacketBuffer::new(vec![0; NetworkDevice::MTU])); + } + let rx_buffer = UdpSocketBuffer::new(rx_packets); + let tx_buffer = UdpSocketBuffer::new(tx_packets); + let mut udp_socket = UdpSocket::new(rx_buffer, tx_buffer); + + if local_endpoint.port == 0 { + local_endpoint.port = port_set + .get_port() + .ok_or_else(|| syscall::Error::new(syscall::EINVAL))?; + } else if !port_set.claim_port(local_endpoint.port) { + return Err(syscall::Error::new(syscall::EADDRINUSE)); + } + + { + let udp_socket: &mut UdpSocket = udp_socket.as_socket(); + udp_socket + .bind(local_endpoint) + .expect("Can't bind udp socket to local endpoint"); + } + + Ok((udp_socket, remote_endpoint)) + } + + fn close_file( + &self, + file: &SchemeFile, + port_set: &mut Self::SchemeDataT, + ) -> syscall::Result<()> { + if let &SchemeFile::Socket(_) = file { + port_set.release_port(self.endpoint().port); + } + Ok(()) + } + + fn write_buf( + &mut self, + file: &mut SocketFile, + buf: &[u8], + ) -> syscall::Result { + if !file.data.is_specified() { + return Err(syscall::Error::new(syscall::EADDRNOTAVAIL)); + } + return if self.can_send() { + self.send_slice(buf, file.data).expect("Can't send slice"); + Ok(buf.len()) + } else if file.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { + Ok(0) + } else { + Err(syscall::Error::new(syscall::EWOULDBLOCK)) + }; + } + + fn read_buf( + &mut self, + file: &mut SocketFile, + buf: &mut [u8], + ) -> syscall::Result { + return if self.can_recv() { + let (length, _) = self.recv_slice(buf).expect("Can't receive slice"); + Ok(length) + } else if file.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { + Ok(0) + } else { + Err(syscall::Error::new(syscall::EWOULDBLOCK)) + }; + } + + fn dup( + &self, + file: &mut SchemeFile, + fd: usize, + socket_handle: SocketHandle, + path: &str, + port_set: &mut Self::SchemeDataT, + ) -> syscall::Result> { + let handle = match path { + "ttl" => SchemeFile::Setting(SettingFile { + socket_handle, + fd, + setting: Setting::Ttl, + }), + "read_timeout" => SchemeFile::Setting(SettingFile { + socket_handle, + fd, + setting: Setting::ReadTimeout, + }), + "write_timeout" => SchemeFile::Setting(SettingFile { + socket_handle, + fd, + setting: Setting::WriteTimeout, + }), + _ => { + let remote_endpoint = parse_endpoint(path); + if let SchemeFile::Socket(ref udp_handle) = *file { + SchemeFile::Socket(udp_handle.clone_with_data( + if remote_endpoint.is_specified() { + remote_endpoint + } else { + udp_handle.data + }, + )) + } else { + SchemeFile::Socket(SocketFile::new_with_data(socket_handle, remote_endpoint)) + } + } + }; + + if let SchemeFile::Socket(_) = handle { + port_set.acquire_port(self.endpoint().port); + } + + Ok(handle) + } +} + +fn parse_endpoint(socket: &str) -> IpEndpoint { + let mut socket_parts = socket.split(':'); + let host = IpAddress::Ipv4( + Ipv4Address::from_str(socket_parts.next().unwrap_or("")) + .unwrap_or_else(|_| Ipv4Address::new(0, 0, 0, 0)), + ); + + let port = socket_parts + .next() + .unwrap_or("") + .parse::() + .unwrap_or(0); + IpEndpoint::new(host, port) +} From 672c93eee0878a91ed129002168b6d989f30707c Mon Sep 17 00:00:00 2001 From: Egor Karavaev Date: Tue, 3 Oct 2017 00:30:14 +0300 Subject: [PATCH 038/155] TCP scheme. --- Cargo.lock | 4 +- Cargo.toml | 5 +- src/smolnetd/main.rs | 29 +++- src/smolnetd/scheme/mod.rs | 22 ++- src/smolnetd/scheme/tcp_socket.rs | 238 ++++++++++++++++++++++++++++++ 5 files changed, 286 insertions(+), 12 deletions(-) create mode 100644 src/smolnetd/scheme/tcp_socket.rs diff --git a/Cargo.lock b/Cargo.lock index 313e9f6f0a..2d8472754c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7,7 +7,7 @@ dependencies = [ "rand 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", "redox_event 0.1.0 (git+https://github.com/redox-os/event.git)", "redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", - "smoltcp 0.4.0 (git+https://github.com/batonius/smoltcp.git?branch=default_route)", + "smoltcp 0.4.0", ] [[package]] @@ -328,7 +328,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "smoltcp" version = "0.4.0" -source = "git+https://github.com/batonius/smoltcp.git?branch=default_route#0412399884af1076f24c79e5b7b78f284798a166" dependencies = [ "byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -478,7 +477,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum rustls 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "17727f4b991294da2c84d75a43c003151ff58072212768800f66c56ee46dca43" "checksum safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e27a8b19b835f7aea908818e871f5cc3a5a186550c30773be987e155e8163d8f" "checksum scopeguard 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c79eb2c3ac4bc2507cda80e7f3ac5b88bd8eae4c0914d5663e6a8933994be918" -"checksum smoltcp 0.4.0 (git+https://github.com/batonius/smoltcp.git?branch=default_route)" = "" "checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" "checksum time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)" = "d5d788d3aa77bc0ef3e9621256885555368b47bd495c13dd2e7413c89f845520" "checksum traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079" diff --git a/Cargo.toml b/Cargo.toml index 0639af3499..8a510e8304 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,7 +38,8 @@ default-features = false features = ["release_max_level_off"] [dependencies.smoltcp] -git = "https://github.com/batonius/smoltcp.git" -branch = "default_route" +path = "../smoltcp" +# git = "https://github.com/batonius/smoltcp.git" +# branch = "default_route" default-features = false features = ["std", "log", "socket-raw", "socket-udp", "socket-tcp"] diff --git a/src/smolnetd/main.rs b/src/smolnetd/main.rs index 65fd372f88..286070d40b 100644 --- a/src/smolnetd/main.rs +++ b/src/smolnetd/main.rs @@ -45,23 +45,33 @@ fn run() -> Result<()> { .map_err(|e| Error::from_syscall_error(e, "failed to open :udp"))? as RawFd; + trace!("opening :tcp"); + let tcp_fd = syscall::open(":tcp", O_RDWR | O_CREAT | O_NONBLOCK) + .map_err(|e| Error::from_syscall_error(e, "failed to open :tcp"))? + as RawFd; + let time_path = format!("time:{}", syscall::CLOCK_MONOTONIC); let time_fd = syscall::open(&time_path, syscall::O_RDWR) .map_err(|e| Error::from_syscall_error(e, "failed to open time:"))? as RawFd; - let (network_file, ip_file, time_file, udp_file) = unsafe { + let (network_file, ip_file, time_file, udp_file, tcp_file) = unsafe { ( File::from_raw_fd(network_fd), File::from_raw_fd(ip_fd), File::from_raw_fd(time_fd), File::from_raw_fd(udp_fd), + File::from_raw_fd(tcp_fd), ) }; - let smolnetd = Rc::new(RefCell::new( - Smolnetd::new(network_file, ip_file, udp_file, time_file), - )); + let smolnetd = Rc::new(RefCell::new(Smolnetd::new( + network_file, + ip_file, + udp_file, + tcp_file, + time_file, + ))); let mut event_queue = EventQueue::<(), Error>::new() .map_err(|e| Error::from_io_error(e, "failed to create event queue"))?; @@ -93,6 +103,17 @@ fn run() -> Result<()> { Error::from_io_error(e, "failed to listen to udp events") })?; + let smolnetd_ = Rc::clone(&smolnetd); + + event_queue + .add( + tcp_fd, + move |_| smolnetd_.borrow_mut().on_tcp_scheme_event(), + ) + .map_err(|e| { + Error::from_io_error(e, "failed to listen to tcp events") + })?; + event_queue .add(time_fd, move |_| smolnetd.borrow_mut().on_time_event()) .map_err(|e| { diff --git a/src/smolnetd/scheme/mod.rs b/src/smolnetd/scheme/mod.rs index 04cec36e43..9424759431 100644 --- a/src/smolnetd/scheme/mod.rs +++ b/src/smolnetd/scheme/mod.rs @@ -15,10 +15,12 @@ use device::NetworkDevice; use error::{Error, Result}; use self::ip::IpScheme; use self::udp_socket::UdpScheme; +use self::tcp_socket::TcpScheme; mod ip; mod socket; mod udp_socket; +mod tcp_socket; type SocketSet = Rc>>; @@ -33,6 +35,7 @@ pub struct Smolnetd { ip_scheme: IpScheme, udp_scheme: UdpScheme, + tcp_scheme: TcpScheme, input_queue: Rc>>, input_buffer_pool: BufferPool, @@ -41,9 +44,15 @@ pub struct Smolnetd { impl Smolnetd { const INGRESS_PACKET_SIZE: usize = 2048; const SOCKET_BUFFER_SIZE: usize = 128; //packets - const CHECK_TIMEOUT_MS: i64 = 1000; + const CHECK_TIMEOUT_MS: i64 = 10; - pub fn new(network_file: File, ip_file: File, udp_file: File, time_file: File) -> Smolnetd { + pub fn new( + network_file: File, + ip_file: File, + udp_file: File, + tcp_file: File, + time_file: File, + ) -> Smolnetd { let arp_cache = smoltcp::iface::SliceArpCache::new(vec![Default::default(); 8]); let hardware_addr = smoltcp::wire::EthernetAddress::from_str(getcfg("mac").unwrap().trim()) .expect("Can't parse the 'mac' cfg"); @@ -71,6 +80,7 @@ impl Smolnetd { time_file, ip_scheme: IpScheme::new(Rc::clone(&socket_set), ip_file), udp_scheme: UdpScheme::new(Rc::clone(&socket_set), udp_file), + tcp_scheme: TcpScheme::new(Rc::clone(&socket_set), tcp_file), input_queue, network_file, input_buffer_pool: BufferPool::new(Self::INGRESS_PACKET_SIZE), @@ -92,6 +102,10 @@ impl Smolnetd { self.udp_scheme.on_scheme_event() } + pub fn on_tcp_scheme_event(&mut self) -> Result> { + self.tcp_scheme.on_scheme_event() + } + pub fn on_time_event(&mut self) -> Result> { let mut time = syscall::data::TimeSpec::default(); if self.time_file.read(&mut time)? < mem::size_of::() { @@ -111,6 +125,7 @@ impl Smolnetd { fn poll(&mut self) -> Result<()> { let timestamp = self.get_timestamp(); + // trace!("Poll {}", timestamp); self.iface .poll(&mut *self.socket_set.borrow_mut(), timestamp) .expect("poll error"); @@ -150,7 +165,8 @@ impl Smolnetd { fn notify_sockets(&mut self) -> Result<()> { self.ip_scheme.notify_sockets()?; - self.udp_scheme.notify_sockets() + self.udp_scheme.notify_sockets()?; + self.tcp_scheme.notify_sockets() } } diff --git a/src/smolnetd/scheme/tcp_socket.rs b/src/smolnetd/scheme/tcp_socket.rs new file mode 100644 index 0000000000..c283a3b4c1 --- /dev/null +++ b/src/smolnetd/scheme/tcp_socket.rs @@ -0,0 +1,238 @@ +use super::socket::*; + +use smoltcp::socket::{AsSocket, Socket, SocketHandle, TcpSocket, TcpSocketBuffer}; +use smoltcp::wire::{IpAddress, IpEndpoint, Ipv4Address}; +use std::io::{Read, Write}; +use std::str::FromStr; +use std::str; +use std::mem; +use std::ops::Deref; +use std::ops::DerefMut; +use syscall::data::TimeSpec; +use syscall; + +use super::Smolnetd; +use port_set::PortSet; + +pub type TcpScheme = SocketScheme>; + +#[derive(Copy, Clone, Eq, PartialEq, Debug)] +pub enum Setting { + Ttl, + ReadTimeout, + WriteTimeout, +} + +impl<'a> SchemeSocket for TcpSocket<'a> { + type SchemeDataT = PortSet; + type DataT = (); + type SettingT = Setting; + + fn new_scheme_data() -> Self::SchemeDataT { + PortSet::new(49_152u16, 65_535u16).expect("Wrong TCP port numbers") + } + + fn can_send(&self) -> bool { + self.can_send() + } + + fn can_recv(&self) -> bool { + self.can_recv() + } + + fn get_setting( + file: &SocketFile, + setting: Self::SettingT, + buf: &mut [u8], + ) -> syscall::Result { + trace!("TCP get setting {:?}", setting); + let timespec = match (setting, file.read_timeout, file.write_timeout) { + (Setting::ReadTimeout, Some(read_timeout), _) => read_timeout, + (Setting::WriteTimeout, _, Some(write_timeout)) => write_timeout, + _ => { + return Ok(0); + } + }; + + if buf.len() < mem::size_of::() { + Ok(0) + } else { + let count = timespec.deref().read(buf).map_err(|err| { + syscall::Error::new(err.raw_os_error().unwrap_or(syscall::EIO)) + })?; + Ok(count) + } + } + + fn set_setting( + file: &mut SocketFile, + setting: Self::SettingT, + buf: &[u8], + ) -> syscall::Result { + trace!("TCP set setting {:?}", setting); + match setting { + Setting::ReadTimeout | Setting::WriteTimeout => { + let (timeout, count) = { + if buf.len() < mem::size_of::() { + (None, 0) + } else { + let mut timespec = TimeSpec::default(); + let count = timespec.deref_mut().write(buf).map_err(|err| { + syscall::Error::new(err.raw_os_error().unwrap_or(syscall::EIO)) + })?; + (Some(timespec), count) + } + }; + match setting { + Setting::ReadTimeout => { + file.read_timeout = timeout; + } + Setting::WriteTimeout => { + file.write_timeout = timeout; + } + _ => {} + }; + return Ok(count); + } + Setting::Ttl => {} + } + Ok(0) + } + + fn new_socket( + path: &str, + uid: u32, + port_set: &mut Self::SchemeDataT, + ) -> syscall::Result<(Socket<'static, 'static>, Self::DataT)> { + trace!("TCP open {}", path); + let mut parts = path.split('/'); + let remote_endpoint = parse_endpoint(parts.next().unwrap_or("")); + let mut local_endpoint = parse_endpoint(parts.next().unwrap_or("")); + + if local_endpoint.port <= 1024 && uid != 0 { + return Err(syscall::Error::new(syscall::EACCES)); + } + + let rx_packets = vec![0; 65535]; + let tx_packets = vec![0; 65535]; + let rx_buffer = TcpSocketBuffer::new(rx_packets); + let tx_buffer = TcpSocketBuffer::new(tx_packets); + let mut tcp_socket = TcpSocket::new(rx_buffer, tx_buffer); + + if local_endpoint.port == 0 { + local_endpoint.port = port_set + .get_port() + .ok_or_else(|| syscall::Error::new(syscall::EINVAL))?; + } else if !port_set.claim_port(local_endpoint.port) { + return Err(syscall::Error::new(syscall::EADDRINUSE)); + } + + { + let tcp_socket: &mut TcpSocket = tcp_socket.as_socket(); + trace!("Connecting tcp {} {}", local_endpoint, remote_endpoint); + tcp_socket + .connect(remote_endpoint, local_endpoint) + .expect("Can't connect tcp socket "); + } + + Ok((tcp_socket, ())) + } + + fn close_file( + &self, + file: &SchemeFile, + port_set: &mut Self::SchemeDataT, + ) -> syscall::Result<()> { + if let &SchemeFile::Socket(_) = file { + port_set.release_port(self.local_endpoint().port); + } + Ok(()) + } + + fn write_buf( + &mut self, + file: &mut SocketFile, + buf: &[u8], + ) -> syscall::Result { + if !self.is_open() { + return Err(syscall::Error::new(syscall::EADDRNOTAVAIL)); + } + return if self.can_send() { + self.send_slice(buf).expect("Can't send slice"); + Ok(buf.len()) + } else if file.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { + Ok(0) + } else { + Err(syscall::Error::new(syscall::EWOULDBLOCK)) + }; + } + + fn read_buf( + &mut self, + file: &mut SocketFile, + buf: &mut [u8], + ) -> syscall::Result { + return if self.can_recv() { + let length = self.recv_slice(buf).expect("Can't receive slice"); + Ok(length) + } else if file.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { + Ok(0) + } else { + Err(syscall::Error::new(syscall::EWOULDBLOCK)) + }; + } + + fn dup( + &self, + file: &mut SchemeFile, + fd: usize, + socket_handle: SocketHandle, + path: &str, + port_set: &mut Self::SchemeDataT, + ) -> syscall::Result> { + trace!("TCP dup {}", path); + let handle = match path { + "ttl" => SchemeFile::Setting(SettingFile { + socket_handle, + fd, + setting: Setting::Ttl, + }), + "read_timeout" => SchemeFile::Setting(SettingFile { + socket_handle, + fd, + setting: Setting::ReadTimeout, + }), + "write_timeout" => SchemeFile::Setting(SettingFile { + socket_handle, + fd, + setting: Setting::WriteTimeout, + }), + _ => if let SchemeFile::Socket(ref tcp_handle) = *file { + SchemeFile::Socket(tcp_handle.clone_with_data(())) + } else { + SchemeFile::Socket(SocketFile::new_with_data(socket_handle, ())) + }, + }; + + if let SchemeFile::Socket(_) = handle { + port_set.acquire_port(self.local_endpoint().port); + } + + Ok(handle) + } +} + +fn parse_endpoint(socket: &str) -> IpEndpoint { + let mut socket_parts = socket.split(':'); + let host = IpAddress::Ipv4( + Ipv4Address::from_str(socket_parts.next().unwrap_or("")) + .unwrap_or_else(|_| Ipv4Address::new(0, 0, 0, 0)), + ); + + let port = socket_parts + .next() + .unwrap_or("") + .parse::() + .unwrap_or(0); + IpEndpoint::new(host, port) +} From 57f7378a5ccf1022d5fb7c5b2682cc1bcca0324c Mon Sep 17 00:00:00 2001 From: Egor Karavaev Date: Tue, 3 Oct 2017 00:52:44 +0300 Subject: [PATCH 039/155] Update smoltcp. --- Cargo.toml | 5 ++--- src/smolnetd/device.rs | 6 +++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8a510e8304..0639af3499 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,8 +38,7 @@ default-features = false features = ["release_max_level_off"] [dependencies.smoltcp] -path = "../smoltcp" -# git = "https://github.com/batonius/smoltcp.git" -# branch = "default_route" +git = "https://github.com/batonius/smoltcp.git" +branch = "default_route" default-features = false features = ["std", "log", "socket-raw", "socket-udp", "socket-tcp"] diff --git a/src/smolnetd/device.rs b/src/smolnetd/device.rs index 74f0785cd6..a572c56ef6 100644 --- a/src/smolnetd/device.rs +++ b/src/smolnetd/device.rs @@ -53,10 +53,10 @@ impl smoltcp::phy::Device for NetworkDevice { type RxBuffer = Buffer; type TxBuffer = TxBuffer; - fn limits(&self) -> smoltcp::phy::DeviceLimits { - let mut limits = smoltcp::phy::DeviceLimits::default(); + fn capabilities(&self) -> smoltcp::phy::DeviceCapabilities { + let mut limits = smoltcp::phy::DeviceCapabilities::default(); limits.max_transmission_unit = Self::MTU; - limits.max_burst_size = Some(1); + limits.max_burst_size = Some(5); limits } From 6166bdcb609f285c770e0f5f4fd15c02b5ca1664 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Mon, 2 Oct 2017 20:55:29 -0600 Subject: [PATCH 040/155] Fix permissions, daemonize --- Cargo.lock | 4 +++- Cargo.toml | 2 +- src/smolnetd/main.rs | 17 +++++++---------- src/smolnetd/scheme/mod.rs | 6 +++--- src/smolnetd/scheme/tcp_socket.rs | 3 +-- src/smolnetd/scheme/udp_socket.rs | 2 +- 6 files changed, 16 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2d8472754c..7e798c699c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7,7 +7,7 @@ dependencies = [ "rand 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", "redox_event 0.1.0 (git+https://github.com/redox-os/event.git)", "redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", - "smoltcp 0.4.0", + "smoltcp 0.4.0 (git+https://github.com/batonius/smoltcp.git?branch=default_route)", ] [[package]] @@ -328,6 +328,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "smoltcp" version = "0.4.0" +source = "git+https://github.com/batonius/smoltcp.git?branch=default_route#253a14b425fa77ddfe096352cf3d8d6a9dbcafbc" dependencies = [ "byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -477,6 +478,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum rustls 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "17727f4b991294da2c84d75a43c003151ff58072212768800f66c56ee46dca43" "checksum safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e27a8b19b835f7aea908818e871f5cc3a5a186550c30773be987e155e8163d8f" "checksum scopeguard 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c79eb2c3ac4bc2507cda80e7f3ac5b88bd8eae4c0914d5663e6a8933994be918" +"checksum smoltcp 0.4.0 (git+https://github.com/batonius/smoltcp.git?branch=default_route)" = "" "checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" "checksum time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)" = "d5d788d3aa77bc0ef3e9621256885555368b47bd495c13dd2e7413c89f845520" "checksum traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079" diff --git a/Cargo.toml b/Cargo.toml index 0639af3499..febfbe50e4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,4 +41,4 @@ features = ["release_max_level_off"] git = "https://github.com/batonius/smoltcp.git" branch = "default_route" default-features = false -features = ["std", "log", "socket-raw", "socket-udp", "socket-tcp"] +features = ["std", "log", "socket-raw", "socket-udp", "socket-tcp"] diff --git a/src/smolnetd/main.rs b/src/smolnetd/main.rs index 286070d40b..2ac8cc8095 100644 --- a/src/smolnetd/main.rs +++ b/src/smolnetd/main.rs @@ -25,12 +25,6 @@ mod port_set; fn run() -> Result<()> { use syscall::flag::*; - logger::init_logger(); - - // if unsafe { syscall::clone(0).unwrap() } != 0 { - // return Ok(()); - // } - trace!("opening network:"); let network_fd = syscall::open("network:", O_RDWR | O_NONBLOCK) .map_err(|e| Error::from_syscall_error(e, "failed to open network:"))? @@ -126,9 +120,12 @@ fn run() -> Result<()> { } fn main() { - if let Err(err) = run() { - error!("smoltcpd: {}", err); - process::exit(1); + if unsafe { syscall::clone(0).unwrap() } == 0 { + logger::init_logger(); + + if let Err(err) = run() { + error!("smoltcpd: {}", err); + process::exit(1); + } } - process::exit(0); } diff --git a/src/smolnetd/scheme/mod.rs b/src/smolnetd/scheme/mod.rs index 9424759431..fabffd93b4 100644 --- a/src/smolnetd/scheme/mod.rs +++ b/src/smolnetd/scheme/mod.rs @@ -126,9 +126,9 @@ impl Smolnetd { fn poll(&mut self) -> Result<()> { let timestamp = self.get_timestamp(); // trace!("Poll {}", timestamp); - self.iface - .poll(&mut *self.socket_set.borrow_mut(), timestamp) - .expect("poll error"); + if let Err(err) = self.iface.poll(&mut *self.socket_set.borrow_mut(), timestamp) { + error!("poll error: {}", err); + } self.notify_sockets() } diff --git a/src/smolnetd/scheme/tcp_socket.rs b/src/smolnetd/scheme/tcp_socket.rs index c283a3b4c1..dbb4d1d7f8 100644 --- a/src/smolnetd/scheme/tcp_socket.rs +++ b/src/smolnetd/scheme/tcp_socket.rs @@ -11,7 +11,6 @@ use std::ops::DerefMut; use syscall::data::TimeSpec; use syscall; -use super::Smolnetd; use port_set::PortSet; pub type TcpScheme = SocketScheme>; @@ -109,7 +108,7 @@ impl<'a> SchemeSocket for TcpSocket<'a> { let remote_endpoint = parse_endpoint(parts.next().unwrap_or("")); let mut local_endpoint = parse_endpoint(parts.next().unwrap_or("")); - if local_endpoint.port <= 1024 && uid != 0 { + if local_endpoint.port > 0 && local_endpoint.port <= 1024 && uid != 0 { return Err(syscall::Error::new(syscall::EACCES)); } diff --git a/src/smolnetd/scheme/udp_socket.rs b/src/smolnetd/scheme/udp_socket.rs index e06825a1e3..a9c40cf066 100644 --- a/src/smolnetd/scheme/udp_socket.rs +++ b/src/smolnetd/scheme/udp_socket.rs @@ -107,7 +107,7 @@ impl<'a, 'b> SchemeSocket for UdpSocket<'a, 'b> { let remote_endpoint = parse_endpoint(parts.next().unwrap_or("")); let mut local_endpoint = parse_endpoint(parts.next().unwrap_or("")); - if local_endpoint.port <= 1024 && uid != 0 { + if local_endpoint.port > 0 && local_endpoint.port <= 1024 && uid != 0 { return Err(syscall::Error::new(syscall::EACCES)); } From 37275adba687c990e2f949e061e7b0baa08fff62 Mon Sep 17 00:00:00 2001 From: Egor Karavaev Date: Tue, 3 Oct 2017 18:35:44 +0300 Subject: [PATCH 041/155] Update smoltcp. --- Cargo.lock | 6 +++--- Cargo.toml | 3 +-- src/smolnetd/scheme/mod.rs | 6 +++--- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7e798c699c..a299142344 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7,7 +7,7 @@ dependencies = [ "rand 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", "redox_event 0.1.0 (git+https://github.com/redox-os/event.git)", "redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", - "smoltcp 0.4.0 (git+https://github.com/batonius/smoltcp.git?branch=default_route)", + "smoltcp 0.4.0 (git+https://github.com/m-labs/smoltcp.git)", ] [[package]] @@ -328,7 +328,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "smoltcp" version = "0.4.0" -source = "git+https://github.com/batonius/smoltcp.git?branch=default_route#253a14b425fa77ddfe096352cf3d8d6a9dbcafbc" +source = "git+https://github.com/m-labs/smoltcp.git#d88ef3c8d3c8ab59ba4381cd60ee6e69e4138fcd" dependencies = [ "byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -478,7 +478,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum rustls 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "17727f4b991294da2c84d75a43c003151ff58072212768800f66c56ee46dca43" "checksum safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e27a8b19b835f7aea908818e871f5cc3a5a186550c30773be987e155e8163d8f" "checksum scopeguard 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c79eb2c3ac4bc2507cda80e7f3ac5b88bd8eae4c0914d5663e6a8933994be918" -"checksum smoltcp 0.4.0 (git+https://github.com/batonius/smoltcp.git?branch=default_route)" = "" +"checksum smoltcp 0.4.0 (git+https://github.com/m-labs/smoltcp.git)" = "" "checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" "checksum time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)" = "d5d788d3aa77bc0ef3e9621256885555368b47bd495c13dd2e7413c89f845520" "checksum traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079" diff --git a/Cargo.toml b/Cargo.toml index febfbe50e4..ba9b58d6eb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,7 +38,6 @@ default-features = false features = ["release_max_level_off"] [dependencies.smoltcp] -git = "https://github.com/batonius/smoltcp.git" -branch = "default_route" +git = "https://github.com/m-labs/smoltcp.git" default-features = false features = ["std", "log", "socket-raw", "socket-udp", "socket-tcp"] diff --git a/src/smolnetd/scheme/mod.rs b/src/smolnetd/scheme/mod.rs index fabffd93b4..03ed2e3a3c 100644 --- a/src/smolnetd/scheme/mod.rs +++ b/src/smolnetd/scheme/mod.rs @@ -58,8 +58,8 @@ impl Smolnetd { .expect("Can't parse the 'mac' cfg"); let local_ip = smoltcp::wire::IpAddress::from_str(getcfg("ip").unwrap().trim()) .expect("Can't parse the 'ip' cfg."); - let protocol_addrs = [smoltcp::wire::IpCidr::new(local_ip, 24).unwrap()]; - let default_gw = smoltcp::wire::IpAddress::from_str(getcfg("ip_router").unwrap().trim()) + let protocol_addrs = [smoltcp::wire::IpCidr::new(local_ip, 24)]; + let default_gw = smoltcp::wire::Ipv4Address::from_str(getcfg("ip_router").unwrap().trim()) .expect("Can't parse the 'ip_router' cfg."); // trace!("mac {:?} ip {}", hardware_addr, protocol_addrs); let input_queue = Rc::new(RefCell::new(VecDeque::new())); @@ -70,7 +70,7 @@ impl Smolnetd { Box::new(arp_cache) as Box, hardware_addr, protocol_addrs, - default_gw, + Some(default_gw), ); let socket_set = Rc::new(RefCell::new(smoltcp::socket::SocketSet::new(vec![]))); Smolnetd { From 309be700958d5c63549a6a9ec714fc24ef446d44 Mon Sep 17 00:00:00 2001 From: Egor Karavaev Date: Tue, 3 Oct 2017 20:37:32 +0300 Subject: [PATCH 042/155] Improved timeout handling. --- src/smolnetd/scheme/mod.rs | 81 +++++++++++++------ src/smolnetd/scheme/socket.rs | 2 +- src/smolnetd/scheme/{tcp_socket.rs => tcp.rs} | 14 ++-- src/smolnetd/scheme/{udp_socket.rs => udp.rs} | 10 +-- 4 files changed, 69 insertions(+), 38 deletions(-) rename src/smolnetd/scheme/{tcp_socket.rs => tcp.rs} (96%) rename src/smolnetd/scheme/{udp_socket.rs => udp.rs} (98%) diff --git a/src/smolnetd/scheme/mod.rs b/src/smolnetd/scheme/mod.rs index 03ed2e3a3c..5efed421ab 100644 --- a/src/smolnetd/scheme/mod.rs +++ b/src/smolnetd/scheme/mod.rs @@ -14,13 +14,13 @@ use buffer_pool::{Buffer, BufferPool}; use device::NetworkDevice; use error::{Error, Result}; use self::ip::IpScheme; -use self::udp_socket::UdpScheme; -use self::tcp_socket::TcpScheme; +use self::udp::UdpScheme; +use self::tcp::TcpScheme; mod ip; mod socket; -mod udp_socket; -mod tcp_socket; +mod udp; +mod tcp; type SocketSet = Rc>>; @@ -44,7 +44,8 @@ pub struct Smolnetd { impl Smolnetd { const INGRESS_PACKET_SIZE: usize = 2048; const SOCKET_BUFFER_SIZE: usize = 128; //packets - const CHECK_TIMEOUT_MS: i64 = 10; + const MIN_CHECK_TIMEOUT_MS: i64 = 10; + const MAX_CHECK_TIMEOUT_MS: i64 = 500; pub fn new( network_file: File, @@ -95,41 +96,76 @@ impl Smolnetd { } pub fn on_ip_scheme_event(&mut self) -> Result> { - self.ip_scheme.on_scheme_event() + self.ip_scheme.on_scheme_event()?; + self.poll()?; + Ok(None) } pub fn on_udp_scheme_event(&mut self) -> Result> { - self.udp_scheme.on_scheme_event() + self.udp_scheme.on_scheme_event()?; + self.poll()?; + Ok(None) } pub fn on_tcp_scheme_event(&mut self) -> Result> { - self.tcp_scheme.on_scheme_event() + self.tcp_scheme.on_scheme_event()?; + self.poll()?; + Ok(None) } pub fn on_time_event(&mut self) -> Result> { + let timeout = self.poll()?; + self.schedule_timeout(timeout)?; + Ok(None) + } + + fn schedule_timeout(&mut self, timeout: i64) -> Result<()> { let mut time = syscall::data::TimeSpec::default(); if self.time_file.read(&mut time)? < mem::size_of::() { - panic!(); + return Err(Error::from_syscall_error( + syscall::Error::new(syscall::EBADF), + "Can't read current time", + )); } let mut time_ms = time.tv_sec * 1000i64 + i64::from(time.tv_nsec) / 1_000_000i64; - time_ms += Smolnetd::CHECK_TIMEOUT_MS; + time_ms += timeout; time.tv_sec = time_ms / 1000; time.tv_nsec = ((time_ms % 1000) * 1_000_000) as i32; self.time_file .write_all(&time) .map_err(|e| Error::from_io_error(e, "Failed to write to time file"))?; - - self.poll().map(Some)?; - Ok(None) + Ok(()) } - fn poll(&mut self) -> Result<()> { - let timestamp = self.get_timestamp(); - // trace!("Poll {}", timestamp); - if let Err(err) = self.iface.poll(&mut *self.socket_set.borrow_mut(), timestamp) { - error!("poll error: {}", err); - } - self.notify_sockets() + fn poll(&mut self) -> Result { + let mut iter_limit = 10usize; + let timeout = loop { + iter_limit -= 1; + if iter_limit == 0 { + break 0; + } + let timestamp = self.get_timestamp(); + match self.iface + .poll(&mut *self.socket_set.borrow_mut(), timestamp) + { + Err(err) => { + error!("poll error: {}", err); + break 0; + } + Ok(None) => { + break ::std::u64::MAX; + } + Ok(Some(n)) if n > 0 => { + break n; + } + _ => {} + } + }; + self.notify_sockets()?; + Ok(::std::cmp::min( + ::std::cmp::max(Smolnetd::MIN_CHECK_TIMEOUT_MS, timeout as i64), + Smolnetd::MAX_CHECK_TIMEOUT_MS, + )) } fn read_frames(&mut self) -> Result { @@ -158,11 +194,6 @@ impl Smolnetd { (duration.as_secs() * 1000) + u64::from(duration.subsec_nanos() / 1_000_000) } - fn network_fsync(&mut self) -> syscall::Result { - use std::os::unix::io::AsRawFd; - syscall::fsync(self.network_file.borrow_mut().as_raw_fd() as usize) - } - fn notify_sockets(&mut self) -> Result<()> { self.ip_scheme.notify_sockets()?; self.udp_scheme.notify_sockets()?; diff --git a/src/smolnetd/scheme/socket.rs b/src/smolnetd/scheme/socket.rs index 75ab6a49cc..9b26c1eb07 100644 --- a/src/smolnetd/scheme/socket.rs +++ b/src/smolnetd/scheme/socket.rs @@ -320,7 +320,7 @@ where trace!("Adding {} to wait queie", fd); let wait_queues = self.wait_queue_map .entry(socket_handle) - .or_insert_with(|| WaitQueues::default()); + .or_insert_with(WaitQueues::default); let queue = match packet.a { syscall::SYS_READ => Ok(&mut wait_queues.read_queue), diff --git a/src/smolnetd/scheme/tcp_socket.rs b/src/smolnetd/scheme/tcp.rs similarity index 96% rename from src/smolnetd/scheme/tcp_socket.rs rename to src/smolnetd/scheme/tcp.rs index dbb4d1d7f8..1a26e01f39 100644 --- a/src/smolnetd/scheme/tcp_socket.rs +++ b/src/smolnetd/scheme/tcp.rs @@ -112,8 +112,8 @@ impl<'a> SchemeSocket for TcpSocket<'a> { return Err(syscall::Error::new(syscall::EACCES)); } - let rx_packets = vec![0; 65535]; - let tx_packets = vec![0; 65535]; + let rx_packets = vec![0; 65_535]; + let tx_packets = vec![0; 65_535]; let rx_buffer = TcpSocketBuffer::new(rx_packets); let tx_buffer = TcpSocketBuffer::new(tx_packets); let mut tcp_socket = TcpSocket::new(rx_buffer, tx_buffer); @@ -142,7 +142,7 @@ impl<'a> SchemeSocket for TcpSocket<'a> { file: &SchemeFile, port_set: &mut Self::SchemeDataT, ) -> syscall::Result<()> { - if let &SchemeFile::Socket(_) = file { + if let SchemeFile::Socket(_) = *file { port_set.release_port(self.local_endpoint().port); } Ok(()) @@ -156,14 +156,14 @@ impl<'a> SchemeSocket for TcpSocket<'a> { if !self.is_open() { return Err(syscall::Error::new(syscall::EADDRNOTAVAIL)); } - return if self.can_send() { + if self.can_send() { self.send_slice(buf).expect("Can't send slice"); Ok(buf.len()) } else if file.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { Ok(0) } else { Err(syscall::Error::new(syscall::EWOULDBLOCK)) - }; + } } fn read_buf( @@ -171,14 +171,14 @@ impl<'a> SchemeSocket for TcpSocket<'a> { file: &mut SocketFile, buf: &mut [u8], ) -> syscall::Result { - return if self.can_recv() { + if self.can_recv() { let length = self.recv_slice(buf).expect("Can't receive slice"); Ok(length) } else if file.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { Ok(0) } else { Err(syscall::Error::new(syscall::EWOULDBLOCK)) - }; + } } fn dup( diff --git a/src/smolnetd/scheme/udp_socket.rs b/src/smolnetd/scheme/udp.rs similarity index 98% rename from src/smolnetd/scheme/udp_socket.rs rename to src/smolnetd/scheme/udp.rs index a9c40cf066..030d53c495 100644 --- a/src/smolnetd/scheme/udp_socket.rs +++ b/src/smolnetd/scheme/udp.rs @@ -144,7 +144,7 @@ impl<'a, 'b> SchemeSocket for UdpSocket<'a, 'b> { file: &SchemeFile, port_set: &mut Self::SchemeDataT, ) -> syscall::Result<()> { - if let &SchemeFile::Socket(_) = file { + if let SchemeFile::Socket(_) = *file { port_set.release_port(self.endpoint().port); } Ok(()) @@ -158,14 +158,14 @@ impl<'a, 'b> SchemeSocket for UdpSocket<'a, 'b> { if !file.data.is_specified() { return Err(syscall::Error::new(syscall::EADDRNOTAVAIL)); } - return if self.can_send() { + if self.can_send() { self.send_slice(buf, file.data).expect("Can't send slice"); Ok(buf.len()) } else if file.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { Ok(0) } else { Err(syscall::Error::new(syscall::EWOULDBLOCK)) - }; + } } fn read_buf( @@ -173,14 +173,14 @@ impl<'a, 'b> SchemeSocket for UdpSocket<'a, 'b> { file: &mut SocketFile, buf: &mut [u8], ) -> syscall::Result { - return if self.can_recv() { + if self.can_recv() { let (length, _) = self.recv_slice(buf).expect("Can't receive slice"); Ok(length) } else if file.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { Ok(0) } else { Err(syscall::Error::new(syscall::EWOULDBLOCK)) - }; + } } fn dup( From 5c6187749b1e40f8f51c58ebeaac300328155e74 Mon Sep 17 00:00:00 2001 From: Egor Karavaev Date: Tue, 3 Oct 2017 21:32:16 +0300 Subject: [PATCH 043/155] Non-blocking IP sockets. --- src/smolnetd/scheme/ip.rs | 240 ++++++++++++++++++++------------------ 1 file changed, 126 insertions(+), 114 deletions(-) diff --git a/src/smolnetd/scheme/ip.rs b/src/smolnetd/scheme/ip.rs index 4b2a4932fa..6c8c74a2c8 100644 --- a/src/smolnetd/scheme/ip.rs +++ b/src/smolnetd/scheme/ip.rs @@ -1,71 +1,105 @@ -use smoltcp::socket::{AsSocket, RawPacketBuffer, RawSocket, RawSocketBuffer, SocketHandle}; +use super::socket::*; + +use smoltcp::socket::{RawPacketBuffer, RawSocket, RawSocketBuffer, Socket, SocketHandle}; use smoltcp::wire::{IpProtocol, IpVersion}; -use std::fs::File; use std::io::{Read, Write}; -use std::collections::BTreeMap; -use syscall::SchemeMut; +use std::str; +use std::mem; +use std::ops::Deref; +use std::ops::DerefMut; +use syscall::data::TimeSpec; use syscall; use device::NetworkDevice; -use error::Result; -use super::{Smolnetd, SocketSet}; -use super::post_fevent; +use super::Smolnetd; -pub struct RawHandle { - flags: usize, - events: usize, - socket_handle: SocketHandle, +pub type IpScheme = SocketScheme>; + +#[derive(Copy, Clone, Eq, PartialEq, Debug)] +pub enum Setting { + ReadTimeout, + WriteTimeout, } -pub struct IpScheme { - next_ip_fd: usize, - raw_sockets: BTreeMap, - socket_set: SocketSet, - ip_file: File, -} +impl<'a, 'b> SchemeSocket for RawSocket<'a, 'b> { + type SchemeDataT = (); + type DataT = (); + type SettingT = Setting; -impl IpScheme { - pub fn new(socket_set: SocketSet, ip_file: File) -> IpScheme { - IpScheme { - next_ip_fd: 1, - raw_sockets: BTreeMap::new(), - socket_set, - ip_file, - } + fn new_scheme_data() -> Self::SchemeDataT { + () } - pub fn on_scheme_event(&mut self) -> Result> { - loop { - let mut packet = syscall::Packet::default(); - if self.ip_file.read(&mut packet)? == 0 { - break; + fn can_send(&self) -> bool { + self.can_send() + } + + fn can_recv(&self) -> bool { + self.can_recv() + } + + fn get_setting( + file: &SocketFile, + setting: Self::SettingT, + buf: &mut [u8], + ) -> syscall::Result { + let timespec = match (setting, file.read_timeout, file.write_timeout) { + (Setting::ReadTimeout, Some(read_timeout), _) => read_timeout, + (Setting::WriteTimeout, _, Some(write_timeout)) => write_timeout, + _ => { + return Ok(0); } - self.handle(&mut packet); - self.ip_file.write_all(&packet)?; + }; + + if buf.len() < mem::size_of::() { + Ok(0) + } else { + let count = timespec.deref().read(buf).map_err(|err| { + syscall::Error::new(err.raw_os_error().unwrap_or(syscall::EIO)) + })?; + Ok(count) } - Ok(None) } - pub fn notify_sockets(&mut self) -> Result<()> { - for (&fd, handle) in &self.raw_sockets { - let mut socket_set = self.socket_set.borrow_mut(); - let socket: &mut RawSocket = socket_set.get_mut(handle.socket_handle).as_socket(); - if socket.can_send() { - post_fevent(&mut self.ip_file, fd, syscall::EVENT_READ, 1)?; + fn set_setting( + file: &mut SocketFile, + setting: Self::SettingT, + buf: &[u8], + ) -> syscall::Result { + match setting { + Setting::ReadTimeout | Setting::WriteTimeout => { + let (timeout, count) = { + if buf.len() < mem::size_of::() { + (None, 0) + } else { + let mut timespec = TimeSpec::default(); + let count = timespec.deref_mut().write(buf).map_err(|err| { + syscall::Error::new(err.raw_os_error().unwrap_or(syscall::EIO)) + })?; + (Some(timespec), count) + } + }; + match setting { + Setting::ReadTimeout => { + file.read_timeout = timeout; + } + Setting::WriteTimeout => { + file.write_timeout = timeout; + } + }; + return Ok(count); } } - Ok(()) } -} - -impl<'a> syscall::SchemeMut for IpScheme { - fn open(&mut self, url: &[u8], flags: usize, uid: u32, _gid: u32) -> syscall::Result { - use std::str; + fn new_socket( + path: &str, + uid: u32, + _: &mut Self::SchemeDataT, + ) -> syscall::Result<(Socket<'static, 'static>, Self::DataT)> { if uid != 0 { return Err(syscall::Error::new(syscall::EACCES)); } - let path = str::from_utf8(url).or_else(|_| Err(syscall::Error::new(syscall::EINVAL)))?; let proto = u8::from_str_radix(path, 16).or_else(|_| Err(syscall::Error::new(syscall::ENOENT)))?; @@ -77,91 +111,69 @@ impl<'a> syscall::SchemeMut for IpScheme { } let rx_buffer = RawSocketBuffer::new(rx_packets); let tx_buffer = RawSocketBuffer::new(tx_packets); - let raw_socket = RawSocket::new( + let ip_socket = RawSocket::new( IpVersion::Ipv4, IpProtocol::from(proto), rx_buffer, tx_buffer, ); - - let socket_handle = self.socket_set.borrow_mut().add(raw_socket); - let id = self.next_ip_fd; - trace!("IP Open {} -> {}", path, id); - - self.raw_sockets.insert( - id, - RawHandle { - flags, - events: 0, - socket_handle, - }, - ); - self.next_ip_fd += 1; - Ok(id) + Ok((ip_socket, ())) } - fn close(&mut self, fd: usize) -> syscall::Result { - trace!("IP Close {}", fd); - let socket_handle = { - let handle = self.raw_sockets - .get(&fd) - .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; - handle.socket_handle - }; - self.raw_sockets.remove(&fd); - self.socket_set.borrow_mut().remove(socket_handle); - Ok(0) + fn close_file(&self, _: &SchemeFile, _: &mut Self::SchemeDataT) -> syscall::Result<()> { + Ok(()) } - fn write(&mut self, fd: usize, buf: &[u8]) -> syscall::Result { - trace!("IP Write {} len {}", fd, buf.len()); - - let handle = self.raw_sockets - .get(&fd) - .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; - let mut socket_set = self.socket_set.borrow_mut(); - let socket: &mut RawSocket = socket_set.get_mut(handle.socket_handle).as_socket(); - socket.send_slice(buf).expect("Can't send slice"); - Ok(buf.len()) - } - - fn read(&mut self, fd: usize, buf: &mut [u8]) -> syscall::Result { - use smoltcp::socket::AsSocket; - - let handle = self.raw_sockets - .get(&fd) - .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; - let mut socket_set = self.socket_set.borrow_mut(); - let socket: &mut RawSocket = socket_set.get_mut(handle.socket_handle).as_socket(); - if socket.can_recv() { - let length = socket.recv_slice(buf).expect("Can't receive slice"); - trace!("IP Read fd {} len {}", fd, length); - Ok(length) - } else if handle.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { + fn write_buf( + &mut self, + file: &mut SocketFile, + buf: &[u8], + ) -> syscall::Result { + if self.can_send() { + self.send_slice(buf).expect("Can't send slice"); + Ok(buf.len()) + } else if file.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { Ok(0) } else { Err(syscall::Error::new(syscall::EWOULDBLOCK)) } } - fn fevent(&mut self, fd: usize, events: usize) -> syscall::Result { - trace!("IP fevent {}", fd); - let handle = self.raw_sockets - .get_mut(&fd) - .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; - handle.events = events; - Ok(fd) + fn read_buf( + &mut self, + file: &mut SocketFile, + buf: &mut [u8], + ) -> syscall::Result { + if self.can_recv() { + let length = self.recv_slice(buf).expect("Can't receive slice"); + Ok(length) + } else if file.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { + Ok(0) + } else { + Err(syscall::Error::new(syscall::EWOULDBLOCK)) + } } - fn fsync(&mut self, fd: usize) -> syscall::Result { - trace!("IP fsync {}", fd); - { - let _handle = self.raw_sockets - .get_mut(&fd) - .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; + fn dup( + &self, + _: &mut SchemeFile, + fd: usize, + socket_handle: SocketHandle, + path: &str, + _: &mut Self::SchemeDataT, + ) -> syscall::Result> { + match path { + "write_timeout" => Ok(SchemeFile::Setting(SettingFile { + socket_handle, + fd, + setting: Setting::WriteTimeout, + })), + "read_timeout" => Ok(SchemeFile::Setting(SettingFile { + socket_handle, + fd, + setting: Setting::ReadTimeout, + })), + _ => Err(syscall::Error::new(syscall::EBADF)), } - Ok(0) - // TODO Implement fsyncing - // self.0.network_fsync() } } From 5b018426d2141e01136e64fdaed6256a9ab5acb0 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Wed, 4 Oct 2017 20:29:41 -0600 Subject: [PATCH 044/155] Update Cargo.lock --- Cargo.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index a299142344..87c44fa9ff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -328,7 +328,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "smoltcp" version = "0.4.0" -source = "git+https://github.com/m-labs/smoltcp.git#d88ef3c8d3c8ab59ba4381cd60ee6e69e4138fcd" +source = "git+https://github.com/m-labs/smoltcp.git#b0fc1d9542ef3b8e7add3b90dcf2d6f1fc4c633e" dependencies = [ "byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", From 454dfd9a39c59f357f2de59a834781c94040748e Mon Sep 17 00:00:00 2001 From: Egor Karavaev Date: Wed, 4 Oct 2017 18:43:07 +0300 Subject: [PATCH 045/155] Support for tcp listen. --- src/smolnetd/buffer_pool.rs | 4 +- src/smolnetd/main.rs | 2 + src/smolnetd/scheme/ip.rs | 41 +++++--- src/smolnetd/scheme/mod.rs | 1 - src/smolnetd/scheme/socket.rs | 175 +++++++++++++++++++++------------- src/smolnetd/scheme/tcp.rs | 83 ++++++++++++---- src/smolnetd/scheme/udp.rs | 22 ++++- 7 files changed, 227 insertions(+), 101 deletions(-) diff --git a/src/smolnetd/buffer_pool.rs b/src/smolnetd/buffer_pool.rs index f3248c1958..c96baea781 100644 --- a/src/smolnetd/buffer_pool.rs +++ b/src/smolnetd/buffer_pool.rs @@ -68,9 +68,7 @@ impl BufferPool { pub fn get_buffer(&mut self) -> Buffer { let buffer = match self.stack.borrow_mut().pop() { - None => { - vec![0u8; self.buffers_size] - } + None => vec![0u8; self.buffers_size], Some(mut v) => { // memsetting the buffer with `resize` would be a waste of time let capacity = v.capacity(); diff --git a/src/smolnetd/main.rs b/src/smolnetd/main.rs index 2ac8cc8095..1f78c09590 100644 --- a/src/smolnetd/main.rs +++ b/src/smolnetd/main.rs @@ -1,3 +1,5 @@ +#![feature(drain_filter)] + extern crate event; #[macro_use] extern crate log; diff --git a/src/smolnetd/scheme/ip.rs b/src/smolnetd/scheme/ip.rs index 6c8c74a2c8..d48fd52f4f 100644 --- a/src/smolnetd/scheme/ip.rs +++ b/src/smolnetd/scheme/ip.rs @@ -161,19 +161,38 @@ impl<'a, 'b> SchemeSocket for RawSocket<'a, 'b> { socket_handle: SocketHandle, path: &str, _: &mut Self::SchemeDataT, - ) -> syscall::Result> { + ) -> syscall::Result> { match path { - "write_timeout" => Ok(SchemeFile::Setting(SettingFile { - socket_handle, - fd, - setting: Setting::WriteTimeout, - })), - "read_timeout" => Ok(SchemeFile::Setting(SettingFile { - socket_handle, - fd, - setting: Setting::ReadTimeout, - })), + "write_timeout" => Ok(( + SchemeFile::Setting(SettingFile { + socket_handle, + fd, + setting: Setting::WriteTimeout, + }), + None, + )), + "read_timeout" => Ok(( + SchemeFile::Setting(SettingFile { + socket_handle, + fd, + setting: Setting::ReadTimeout, + }), + None, + )), _ => Err(syscall::Error::new(syscall::EBADF)), } } + + fn fpath(&self, _file: &SchemeFile, buf: &mut [u8]) -> syscall::Result { + let path = format!("ip:{}", self.ip_protocol()); + let path = path.as_bytes(); + + let mut i = 0; + while i < buf.len() && i < path.len() { + buf[i] = path[i]; + i += 1; + } + + Ok(i) + } } diff --git a/src/smolnetd/scheme/mod.rs b/src/smolnetd/scheme/mod.rs index 5efed421ab..39f3977ac5 100644 --- a/src/smolnetd/scheme/mod.rs +++ b/src/smolnetd/scheme/mod.rs @@ -181,7 +181,6 @@ impl Smolnetd { if count == 0 { break; } - trace!("got frame {}", count); buffer.resize(count); self.input_queue.borrow_mut().push_back(buffer); total_frames += 1; diff --git a/src/smolnetd/scheme/socket.rs b/src/smolnetd/scheme/socket.rs index 9b26c1eb07..586e4501a0 100644 --- a/src/smolnetd/scheme/socket.rs +++ b/src/smolnetd/scheme/socket.rs @@ -29,7 +29,7 @@ impl SocketFile { read_timeout: self.read_timeout, write_timeout: self.write_timeout, socket_handle: self.socket_handle, - data + data, } } @@ -40,7 +40,7 @@ impl SocketFile { read_timeout: None, write_timeout: None, socket_handle, - data + data, } } } @@ -77,11 +77,11 @@ struct WaitHandle { packet: syscall::Packet, } -#[derive(Default)] -struct WaitQueues { - read_queue: Vec, - write_queue: Vec, -} +type WaitQueue = Vec; + +type WaitQueueMap = BTreeMap; + +pub type DupResult = (SchemeFile, Option<(Socket<'static, 'static>, T::DataT)>); pub trait SchemeSocket where @@ -109,6 +109,8 @@ where fn write_buf(&mut self, &mut SocketFile, buf: &[u8]) -> syscall::Result; fn read_buf(&mut self, &mut SocketFile, buf: &mut [u8]) -> syscall::Result; + fn fpath(&self, &SchemeFile, &mut [u8]) -> syscall::Result; + fn dup( &self, &mut SchemeFile, @@ -116,11 +118,9 @@ where SocketHandle, &str, &mut Self::SchemeDataT, - ) -> syscall::Result>; + ) -> syscall::Result>; } -type WaitQueueMap = BTreeMap; - pub struct SocketScheme where SocketT: SchemeSocket, @@ -206,35 +206,19 @@ where let socket_handles: Vec<_> = self.wait_queue_map.keys().cloned().collect(); for socket_handle in socket_handles { - let (can_recv, can_send) = { - let mut socket_set = self.socket_set.borrow_mut(); - let socket: &mut SocketT = socket_set.get_mut(socket_handle).as_socket(); - (socket.can_recv(), socket.can_send()) - }; - - if can_recv { - self.wake_up_wait_queue(socket_handle, cur_time, |wq| &mut wq.read_queue)?; - } - - if can_send { - self.wake_up_wait_queue(socket_handle, cur_time, |wq| &mut wq.write_queue)?; - } + self.wake_up_wait_queue(socket_handle, cur_time)?; } Ok(()) } - fn wake_up_wait_queue( + fn wake_up_wait_queue( &mut self, socket_handle: SocketHandle, cur_time: syscall::TimeSpec, - f: F, - ) -> Result<()> - where - F: Fn(&mut WaitQueues) -> &mut Vec, - { - let mut input_queue = if let Some(wait_queues) = self.wait_queue_map.get_mut(&socket_handle) + ) -> Result<()> { + let mut input_queue = if let Some(wait_queue) = self.wait_queue_map.get_mut(&socket_handle) { - ::std::mem::replace(f(wait_queues), vec![]) + ::std::mem::replace(wait_queue, vec![]) } else { vec![] }; @@ -247,11 +231,10 @@ where if packet.a == (-syscall::EWOULDBLOCK) as usize { match wait_handle.until { Some(until) - if (until.tv_sec >= cur_time.tv_sec + if (until.tv_sec < cur_time.tv_sec || (until.tv_sec == cur_time.tv_sec - && until.tv_nsec >= cur_time.tv_nsec)) => + && until.tv_nsec < cur_time.tv_nsec)) => { - trace!("Timeouting fd {}", packet.b); packet.a = (-syscall::ETIMEDOUT) as usize; self.scheme_file.write_all(&packet)?; } @@ -260,20 +243,41 @@ where } } } else { - trace!("Waking up fd {}", packet.b); + trace!("Waking up {} with {}", packet.b, packet.a); self.scheme_file.write_all(&packet)?; } } - if let Some(wait_queues) = self.wait_queue_map.get_mut(&socket_handle) { - f(wait_queues).extend(to_retain); + if let Some(wait_queue) = self.wait_queue_map.get_mut(&socket_handle) { + wait_queue.extend(to_retain); } Ok(()) } + fn move_handle_to_new_socket_handle( + wait_queue_map: &mut WaitQueueMap, + fd: usize, + from: SocketHandle, + to: SocketHandle, + ) -> syscall::Result<()> { + trace!("Moving {} from {:?} to {:?}", fd, from, to); + let mut to_move = vec![]; + + if let Some(wait_queue) = wait_queue_map.get_mut(&from) { + to_move = wait_queue + .drain_filter(|wh| wh.packet.b == fd) + .collect::>(); + } + + wait_queue_map + .entry(to) + .or_insert_with(|| vec![]) + .extend(to_move); + Ok(()) + } + fn handle_block(&mut self, mut packet: syscall::Packet) -> Result<()> { - trace!("Handling blocking call"); let syscall_result = self.try_handle_block(&mut packet); if let Err(syscall_error) = syscall_result { packet.a = (-syscall_error.errno) as usize; @@ -306,9 +310,9 @@ where }?; let mut timeout = match packet.a { - syscall::SYS_READ => Ok(read_timeout), syscall::SYS_WRITE => Ok(write_timeout), - _ => Err(syscall::Error::new(syscall::EBADF)), + syscall::SYS_READ => Ok(read_timeout), + _ => Ok(None), }?; if let Some(ref mut timeout) = timeout { @@ -317,18 +321,11 @@ where *timeout = add_time(timeout, &cur_time) } - trace!("Adding {} to wait queie", fd); - let wait_queues = self.wait_queue_map + let wait_queue = self.wait_queue_map .entry(socket_handle) - .or_insert_with(WaitQueues::default); + .or_insert_with(|| vec![]); - let queue = match packet.a { - syscall::SYS_READ => Ok(&mut wait_queues.read_queue), - syscall::SYS_WRITE => Ok(&mut wait_queues.write_queue), - _ => Err(syscall::Error::new(syscall::EBADF)), - }?; - - queue.push(WaitHandle { + wait_queue.push(WaitHandle { until: timeout, packet: *packet, }); @@ -381,6 +378,7 @@ where { fn open(&mut self, url: &[u8], flags: usize, uid: u32, _gid: u32) -> syscall::Result { let path = str::from_utf8(url).or_else(|_| Err(syscall::Error::new(syscall::EINVAL)))?; + trace!("open {}", path); let (socket, data) = SocketT::new_socket(path, uid, &mut self.scheme_data)?; @@ -403,6 +401,7 @@ where } fn close(&mut self, fd: usize) -> syscall::Result { + trace!("close {}", fd); let socket_handle = { let handle = self.fds .get(&fd) @@ -416,20 +415,14 @@ where socket.close_file(&scheme_file, &mut self.scheme_data)?; } let remove_wq = - if let Some(ref mut wait_queues) = self.wait_queue_map.get_mut(&socket_handle) { - wait_queues.read_queue.retain( + if let Some(ref mut wait_queue) = self.wait_queue_map.get_mut(&socket_handle) { + wait_queue.retain( |&WaitHandle { packet: syscall::Packet { a, .. }, .. }| a != fd, ); - wait_queues.write_queue.retain( - |&WaitHandle { - packet: syscall::Packet { a, .. }, - .. - }| a != fd, - ); - wait_queues.read_queue.is_empty() && wait_queues.write_queue.is_empty() + wait_queue.is_empty() } else { false }; @@ -485,22 +478,42 @@ where fn dup(&mut self, fd: usize, buf: &[u8]) -> syscall::Result { let path = str::from_utf8(buf).or_else(|_| Err(syscall::Error::new(syscall::EINVAL)))?; - let handle = { + let new_file = { let handle = self.fds .get_mut(&fd) .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; let socket_handle = handle.socket_handle(); - let mut socket_set = self.socket_set.borrow_mut(); - let socket: &mut SocketT = socket_set.get_mut(handle.socket_handle()).as_socket(); - socket.dup(handle, fd, socket_handle, path, &mut self.scheme_data) - }?; + let (new_handle, update_with) = { + let mut socket_set = self.socket_set.borrow_mut(); + let socket: &mut SocketT = socket_set.get_mut(handle.socket_handle()).as_socket(); + socket.dup(handle, fd, socket_handle, path, &mut self.scheme_data)? + }; - self.socket_set.borrow_mut().retain(handle.socket_handle()); + if let Some((socket, data)) = update_with { + if let SchemeFile::Socket(ref mut handle) = *handle { + let socket_handle = self.socket_set.borrow_mut().add(socket); + trace!("Updating {} to a new socket handle {:?}", fd, socket_handle); + Self::move_handle_to_new_socket_handle( + &mut self.wait_queue_map, + fd, + handle.socket_handle, + socket_handle, + )?; + handle.socket_handle = socket_handle; + handle.data = data; + } else { + self.socket_set.borrow_mut().retain(handle.socket_handle()); + } + } else { + self.socket_set.borrow_mut().retain(handle.socket_handle()); + } + new_handle + }; let id = self.next_fd; - self.fds.insert(id, handle); + self.fds.insert(id, new_file); self.next_fd += 1; Ok(id) @@ -529,6 +542,36 @@ where // TODO Implement fsyncing // self.0.network_fsync() } + + fn fpath(&mut self, fd: usize, buf: &mut [u8]) -> syscall::Result { + let handle = self.fds + .get_mut(&fd) + .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; + + let mut socket_set = self.socket_set.borrow_mut(); + let socket: &mut SocketT = socket_set.get_mut(handle.socket_handle()).as_socket(); + + socket.fpath(handle, buf) + } + + fn fcntl(&mut self, fd: usize, cmd: usize, arg: usize) -> syscall::Result { + let handle = self.fds + .get_mut(&fd) + .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; + + if let SchemeFile::Socket(ref mut socket_file) = *handle { + match cmd { + syscall::F_GETFL => Ok(socket_file.flags), + syscall::F_SETFL => { + socket_file.flags = arg & !syscall::O_ACCMODE; + Ok(0) + } + _ => Err(syscall::Error::new(syscall::EINVAL)), + } + } else { + Err(syscall::Error::new(syscall::EBADF)) + } + } } fn add_time(a: &TimeSpec, b: &TimeSpec) -> TimeSpec { diff --git a/src/smolnetd/scheme/tcp.rs b/src/smolnetd/scheme/tcp.rs index 1a26e01f39..0889ac7de9 100644 --- a/src/smolnetd/scheme/tcp.rs +++ b/src/smolnetd/scheme/tcp.rs @@ -116,7 +116,7 @@ impl<'a> SchemeSocket for TcpSocket<'a> { let tx_packets = vec![0; 65_535]; let rx_buffer = TcpSocketBuffer::new(rx_packets); let tx_buffer = TcpSocketBuffer::new(tx_packets); - let mut tcp_socket = TcpSocket::new(rx_buffer, tx_buffer); + let mut socket = TcpSocket::new(rx_buffer, tx_buffer); if local_endpoint.port == 0 { local_endpoint.port = port_set @@ -127,14 +127,22 @@ impl<'a> SchemeSocket for TcpSocket<'a> { } { - let tcp_socket: &mut TcpSocket = tcp_socket.as_socket(); - trace!("Connecting tcp {} {}", local_endpoint, remote_endpoint); - tcp_socket - .connect(remote_endpoint, local_endpoint) - .expect("Can't connect tcp socket "); + let tcp_socket: &mut TcpSocket = socket.as_socket(); + + if remote_endpoint.is_specified() { + trace!("Connecting tcp {} {}", local_endpoint, remote_endpoint); + tcp_socket + .connect(remote_endpoint, local_endpoint) + .expect("Can't connect tcp socket "); + } else { + trace!("Listening tcp {}", local_endpoint); + tcp_socket + .listen(local_endpoint) + .expect("Can't listen on local endpoint"); + } } - Ok((tcp_socket, ())) + Ok((socket, ())) } fn close_file( @@ -153,10 +161,9 @@ impl<'a> SchemeSocket for TcpSocket<'a> { file: &mut SocketFile, buf: &[u8], ) -> syscall::Result { - if !self.is_open() { - return Err(syscall::Error::new(syscall::EADDRNOTAVAIL)); - } - if self.can_send() { + if !self.is_active() { + Err(syscall::Error::new(syscall::ENOTCONN)) + } else if self.can_send() { self.send_slice(buf).expect("Can't send slice"); Ok(buf.len()) } else if file.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { @@ -171,7 +178,9 @@ impl<'a> SchemeSocket for TcpSocket<'a> { file: &mut SocketFile, buf: &mut [u8], ) -> syscall::Result { - if self.can_recv() { + if !self.is_active() { + Err(syscall::Error::new(syscall::ENOTCONN)) + } else if self.can_recv() { let length = self.recv_slice(buf).expect("Can't receive slice"); Ok(length) } else if file.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { @@ -188,8 +197,7 @@ impl<'a> SchemeSocket for TcpSocket<'a> { socket_handle: SocketHandle, path: &str, port_set: &mut Self::SchemeDataT, - ) -> syscall::Result> { - trace!("TCP dup {}", path); + ) -> syscall::Result> { let handle = match path { "ttl" => SchemeFile::Setting(SettingFile { socket_handle, @@ -206,18 +214,57 @@ impl<'a> SchemeSocket for TcpSocket<'a> { fd, setting: Setting::WriteTimeout, }), - _ => if let SchemeFile::Socket(ref tcp_handle) = *file { - SchemeFile::Socket(tcp_handle.clone_with_data(())) + "listen" => if let SchemeFile::Socket(ref tcp_handle) = *file { + if !self.is_active() { + return Err(syscall::Error::new(syscall::EWOULDBLOCK)); + } + trace!("TCP creating new listening socket"); + let new_handle = SchemeFile::Socket(tcp_handle.clone_with_data(())); + + let rx_packets = vec![0; 65_535]; + let tx_packets = vec![0; 65_535]; + let rx_buffer = TcpSocketBuffer::new(rx_packets); + let tx_buffer = TcpSocketBuffer::new(tx_packets); + let mut socket = TcpSocket::new(rx_buffer, tx_buffer); + { + let tcp_socket: &mut TcpSocket = socket.as_socket(); + tcp_socket + .listen(self.local_endpoint()) + .expect("Can't listen on local endpoint"); + } + port_set.acquire_port(self.local_endpoint().port); + return Ok((new_handle, Some((socket, ())))); } else { - SchemeFile::Socket(SocketFile::new_with_data(socket_handle, ())) + return Err(syscall::Error::new(syscall::EBADF)); }, + _ => { + trace!("TCP dup unknown {}", path); + if let SchemeFile::Socket(ref tcp_handle) = *file { + SchemeFile::Socket(tcp_handle.clone_with_data(())) + } else { + SchemeFile::Socket(SocketFile::new_with_data(socket_handle, ())) + } + } }; if let SchemeFile::Socket(_) = handle { port_set.acquire_port(self.local_endpoint().port); } - Ok(handle) + Ok((handle, None)) + } + + fn fpath(&self, _: &SchemeFile, buf: &mut [u8]) -> syscall::Result { + let path = format!("tcp:{}/{}", self.remote_endpoint(), self.local_endpoint()); + let path = path.as_bytes(); + + let mut i = 0; + while i < buf.len() && i < path.len() { + buf[i] = path[i]; + i += 1; + } + + Ok(i) } } diff --git a/src/smolnetd/scheme/udp.rs b/src/smolnetd/scheme/udp.rs index 030d53c495..93203e4bca 100644 --- a/src/smolnetd/scheme/udp.rs +++ b/src/smolnetd/scheme/udp.rs @@ -82,6 +82,7 @@ impl<'a, 'b> SchemeSocket for UdpSocket<'a, 'b> { (Some(timespec), count) } }; + trace!("Setting {:?} to {:?}", setting, timeout); match setting { Setting::ReadTimeout => { file.read_timeout = timeout; @@ -190,7 +191,7 @@ impl<'a, 'b> SchemeSocket for UdpSocket<'a, 'b> { socket_handle: SocketHandle, path: &str, port_set: &mut Self::SchemeDataT, - ) -> syscall::Result> { + ) -> syscall::Result> { let handle = match path { "ttl" => SchemeFile::Setting(SettingFile { socket_handle, @@ -227,7 +228,24 @@ impl<'a, 'b> SchemeSocket for UdpSocket<'a, 'b> { port_set.acquire_port(self.endpoint().port); } - Ok(handle) + Ok((handle, None)) + } + + fn fpath(&self, file: &SchemeFile, buf: &mut [u8]) -> syscall::Result { + if let &SchemeFile::Socket(ref socket_file) = file { + let path = format!("udp:{}/{}", socket_file.data, self.endpoint()); + let path = path.as_bytes(); + + let mut i = 0; + while i < buf.len() && i < path.len() { + buf[i] = path[i]; + i += 1; + } + + Ok(i) + } else { + Err(syscall::Error::new(syscall::EBADF)) + } } } From 0584743789b459b77a33dad238a2bb092cc94d8b Mon Sep 17 00:00:00 2001 From: Egor Karavaev Date: Sat, 7 Oct 2017 00:18:10 +0300 Subject: [PATCH 046/155] Updating upstream smoltcp. --- Cargo.lock | 4 +-- src/smolnetd/scheme/ip.rs | 16 ++++++---- src/smolnetd/scheme/socket.rs | 59 ++++++++++++++++++---------------- src/smolnetd/scheme/tcp.rs | 60 ++++++++++++++++++++--------------- src/smolnetd/scheme/udp.rs | 33 +++++++++++-------- 5 files changed, 98 insertions(+), 74 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 87c44fa9ff..bc0ed2071e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -191,7 +191,7 @@ dependencies = [ [[package]] name = "netutils" version = "0.1.0" -source = "git+https://github.com/redox-os/netutils.git#ec1a835a9d4a95a8e41c4e994a540d298d897cd4" +source = "git+https://github.com/redox-os/netutils.git#29b8efd41d8c56b33c619db78e5b019934dbb7a3" dependencies = [ "arg_parser 0.1.0 (git+https://github.com/redox-os/arg-parser.git)", "extra 0.1.0 (git+https://github.com/redox-os/libextra.git)", @@ -328,7 +328,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "smoltcp" version = "0.4.0" -source = "git+https://github.com/m-labs/smoltcp.git#b0fc1d9542ef3b8e7add3b90dcf2d6f1fc4c633e" +source = "git+https://github.com/m-labs/smoltcp.git#096ce02ac4c935c4df485a79107fb26b5897065d" dependencies = [ "byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/src/smolnetd/scheme/ip.rs b/src/smolnetd/scheme/ip.rs index d48fd52f4f..4edb53b5f9 100644 --- a/src/smolnetd/scheme/ip.rs +++ b/src/smolnetd/scheme/ip.rs @@ -1,7 +1,8 @@ use super::socket::*; -use smoltcp::socket::{RawPacketBuffer, RawSocket, RawSocketBuffer, Socket, SocketHandle}; +use smoltcp::socket::{RawPacketBuffer, RawSocket, RawSocketBuffer, SocketHandle}; use smoltcp::wire::{IpProtocol, IpVersion}; +use smoltcp; use std::io::{Read, Write}; use std::str; use std::mem; @@ -93,10 +94,11 @@ impl<'a, 'b> SchemeSocket for RawSocket<'a, 'b> { } fn new_socket( + socket_set: &mut smoltcp::socket::SocketSet<'static, 'static, 'static>, path: &str, uid: u32, _: &mut Self::SchemeDataT, - ) -> syscall::Result<(Socket<'static, 'static>, Self::DataT)> { + ) -> syscall::Result<(SocketHandle, Self::DataT)> { if uid != 0 { return Err(syscall::Error::new(syscall::EACCES)); } @@ -117,7 +119,9 @@ impl<'a, 'b> SchemeSocket for RawSocket<'a, 'b> { rx_buffer, tx_buffer, ); - Ok((ip_socket, ())) + + let socket_handle = socket_set.add(ip_socket); + Ok((socket_handle, ())) } fn close_file(&self, _: &SchemeFile, _: &mut Self::SchemeDataT) -> syscall::Result<()> { @@ -155,10 +159,10 @@ impl<'a, 'b> SchemeSocket for RawSocket<'a, 'b> { } fn dup( - &self, - _: &mut SchemeFile, - fd: usize, + _socket_set: &mut smoltcp::socket::SocketSet<'static, 'static, 'static>, socket_handle: SocketHandle, + _file: &mut SchemeFile, + fd: usize, path: &str, _: &mut Self::SchemeDataT, ) -> syscall::Result> { diff --git a/src/smolnetd/scheme/socket.rs b/src/smolnetd/scheme/socket.rs index 586e4501a0..7d5b3ec05e 100644 --- a/src/smolnetd/scheme/socket.rs +++ b/src/smolnetd/scheme/socket.rs @@ -1,4 +1,5 @@ -use smoltcp::socket::{AsSocket, Socket, SocketHandle}; +use smoltcp::socket::{AnySocket, SocketHandle}; +use smoltcp; use std::collections::BTreeMap; use std::fs::File; use std::io::{Read, Write}; @@ -81,7 +82,7 @@ type WaitQueue = Vec; type WaitQueueMap = BTreeMap; -pub type DupResult = (SchemeFile, Option<(Socket<'static, 'static>, T::DataT)>); +pub type DupResult = (SchemeFile, Option<(SocketHandle, T::DataT)>); pub trait SchemeSocket where @@ -100,10 +101,11 @@ where fn set_setting(&mut SocketFile, Self::SettingT, &[u8]) -> syscall::Result; fn new_socket( + &mut smoltcp::socket::SocketSet<'static, 'static, 'static>, &str, u32, &mut Self::SchemeDataT, - ) -> syscall::Result<(Socket<'static, 'static>, Self::DataT)>; + ) -> syscall::Result<(SocketHandle, Self::DataT)>; fn close_file(&self, &SchemeFile, &mut Self::SchemeDataT) -> syscall::Result<()>; fn write_buf(&mut self, &mut SocketFile, buf: &[u8]) -> syscall::Result; @@ -112,10 +114,10 @@ where fn fpath(&self, &SchemeFile, &mut [u8]) -> syscall::Result; fn dup( - &self, + &mut smoltcp::socket::SocketSet<'static, 'static, 'static>, + SocketHandle, &mut SchemeFile, usize, - SocketHandle, &str, &mut Self::SchemeDataT, ) -> syscall::Result>; @@ -123,8 +125,7 @@ where pub struct SocketScheme where - SocketT: SchemeSocket, - Socket<'static, 'static>: AsSocket, + SocketT: SchemeSocket + AnySocket<'static, 'static>, { next_fd: usize, fds: BTreeMap>, @@ -137,8 +138,7 @@ where impl SocketScheme where - SocketT: SchemeSocket, - Socket<'static, 'static>: AsSocket, + SocketT: SchemeSocket + AnySocket<'static, 'static>, { pub fn new(socket_set: SocketSet, scheme_file: File) -> SocketScheme { SocketScheme { @@ -180,7 +180,7 @@ where }) = *handle { let mut socket_set = self.socket_set.borrow_mut(); - let socket: &mut SocketT = socket_set.get_mut(socket_handle).as_socket(); + let socket = socket_set.get::(socket_handle); if events & syscall::EVENT_READ == syscall::EVENT_READ && socket.can_recv() { post_fevent(&mut self.scheme_file, fd, syscall::EVENT_READ, 1)?; @@ -373,16 +373,19 @@ where impl syscall::SchemeMut for SocketScheme where - SocketT: SchemeSocket, - Socket<'static, 'static>: AsSocket, + SocketT: SchemeSocket + AnySocket<'static, 'static>, { fn open(&mut self, url: &[u8], flags: usize, uid: u32, _gid: u32) -> syscall::Result { let path = str::from_utf8(url).or_else(|_| Err(syscall::Error::new(syscall::EINVAL)))?; trace!("open {}", path); - let (socket, data) = SocketT::new_socket(path, uid, &mut self.scheme_data)?; + let (socket_handle, data) = SocketT::new_socket( + &mut self.socket_set.borrow_mut(), + path, + uid, + &mut self.scheme_data, + )?; - let socket_handle = self.socket_set.borrow_mut().add(socket); let id = self.next_fd; self.fds.insert( @@ -411,7 +414,7 @@ where let scheme_file = self.fds.remove(&fd); let mut socket_set = self.socket_set.borrow_mut(); if let Some(scheme_file) = scheme_file { - let socket: &mut SocketT = socket_set.get_mut(socket_handle).as_socket(); + let socket = socket_set.get::(socket_handle); socket.close_file(&scheme_file, &mut self.scheme_data)?; } let remove_wq = @@ -447,9 +450,9 @@ where } SchemeFile::Socket(ref mut handle) => { let mut socket_set = self.socket_set.borrow_mut(); - let socket: &mut SocketT = socket_set.get_mut(handle.socket_handle).as_socket(); + let mut socket = socket_set.get::(handle.socket_handle); - return ::write_buf(socket, handle, buf); + return ::write_buf(&mut socket, handle, buf); } } }; @@ -467,8 +470,8 @@ where } SchemeFile::Socket(ref mut handle) => { let mut socket_set = self.socket_set.borrow_mut(); - let socket: &mut SocketT = socket_set.get_mut(handle.socket_handle).as_socket(); - return ::read_buf(socket, handle, buf); + let mut socket = socket_set.get::(handle.socket_handle); + return ::read_buf(&mut socket, handle, buf); } } }; @@ -485,15 +488,17 @@ where let socket_handle = handle.socket_handle(); - let (new_handle, update_with) = { - let mut socket_set = self.socket_set.borrow_mut(); - let socket: &mut SocketT = socket_set.get_mut(handle.socket_handle()).as_socket(); - socket.dup(handle, fd, socket_handle, path, &mut self.scheme_data)? - }; + let (new_handle, update_with) = SocketT::dup( + &mut self.socket_set.borrow_mut(), + socket_handle, + handle, + fd, + path, + &mut self.scheme_data, + )?; - if let Some((socket, data)) = update_with { + if let Some((socket_handle, data)) = update_with { if let SchemeFile::Socket(ref mut handle) = *handle { - let socket_handle = self.socket_set.borrow_mut().add(socket); trace!("Updating {} to a new socket handle {:?}", fd, socket_handle); Self::move_handle_to_new_socket_handle( &mut self.wait_queue_map, @@ -549,7 +554,7 @@ where .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; let mut socket_set = self.socket_set.borrow_mut(); - let socket: &mut SocketT = socket_set.get_mut(handle.socket_handle()).as_socket(); + let socket = socket_set.get::(handle.socket_handle()); socket.fpath(handle, buf) } diff --git a/src/smolnetd/scheme/tcp.rs b/src/smolnetd/scheme/tcp.rs index 0889ac7de9..46e6de4173 100644 --- a/src/smolnetd/scheme/tcp.rs +++ b/src/smolnetd/scheme/tcp.rs @@ -1,7 +1,8 @@ use super::socket::*; -use smoltcp::socket::{AsSocket, Socket, SocketHandle, TcpSocket, TcpSocketBuffer}; +use smoltcp::socket::{SocketHandle, TcpSocket, TcpSocketBuffer}; use smoltcp::wire::{IpAddress, IpEndpoint, Ipv4Address}; +use smoltcp; use std::io::{Read, Write}; use std::str::FromStr; use std::str; @@ -99,10 +100,11 @@ impl<'a> SchemeSocket for TcpSocket<'a> { } fn new_socket( + socket_set: &mut smoltcp::socket::SocketSet<'static, 'static, 'static>, path: &str, uid: u32, port_set: &mut Self::SchemeDataT, - ) -> syscall::Result<(Socket<'static, 'static>, Self::DataT)> { + ) -> syscall::Result<(SocketHandle, Self::DataT)> { trace!("TCP open {}", path); let mut parts = path.split('/'); let remote_endpoint = parse_endpoint(parts.next().unwrap_or("")); @@ -116,7 +118,7 @@ impl<'a> SchemeSocket for TcpSocket<'a> { let tx_packets = vec![0; 65_535]; let rx_buffer = TcpSocketBuffer::new(rx_packets); let tx_buffer = TcpSocketBuffer::new(tx_packets); - let mut socket = TcpSocket::new(rx_buffer, tx_buffer); + let socket = TcpSocket::new(rx_buffer, tx_buffer); if local_endpoint.port == 0 { local_endpoint.port = port_set @@ -126,23 +128,23 @@ impl<'a> SchemeSocket for TcpSocket<'a> { return Err(syscall::Error::new(syscall::EADDRINUSE)); } - { - let tcp_socket: &mut TcpSocket = socket.as_socket(); + let socket_handle = socket_set.add(socket); - if remote_endpoint.is_specified() { - trace!("Connecting tcp {} {}", local_endpoint, remote_endpoint); - tcp_socket - .connect(remote_endpoint, local_endpoint) - .expect("Can't connect tcp socket "); - } else { - trace!("Listening tcp {}", local_endpoint); - tcp_socket - .listen(local_endpoint) - .expect("Can't listen on local endpoint"); - } + let mut tcp_socket = socket_set.get::(socket_handle); + + if remote_endpoint.is_specified() { + trace!("Connecting tcp {} {}", local_endpoint, remote_endpoint); + tcp_socket + .connect(remote_endpoint, local_endpoint) + .expect("Can't connect tcp socket "); + } else { + trace!("Listening tcp {}", local_endpoint); + tcp_socket + .listen(local_endpoint) + .expect("Can't listen on local endpoint"); } - Ok((socket, ())) + Ok((socket_handle, ())) } fn close_file( @@ -191,13 +193,18 @@ impl<'a> SchemeSocket for TcpSocket<'a> { } fn dup( - &self, + socket_set: &mut smoltcp::socket::SocketSet<'static, 'static, 'static>, + socket_handle: SocketHandle, file: &mut SchemeFile, fd: usize, - socket_handle: SocketHandle, path: &str, port_set: &mut Self::SchemeDataT, ) -> syscall::Result> { + let (is_active, local_endpoint) = { + let socket = socket_set.get::(socket_handle); + (socket.is_active(), socket.local_endpoint()) + }; + let handle = match path { "ttl" => SchemeFile::Setting(SettingFile { socket_handle, @@ -215,7 +222,7 @@ impl<'a> SchemeSocket for TcpSocket<'a> { setting: Setting::WriteTimeout, }), "listen" => if let SchemeFile::Socket(ref tcp_handle) = *file { - if !self.is_active() { + if !is_active { return Err(syscall::Error::new(syscall::EWOULDBLOCK)); } trace!("TCP creating new listening socket"); @@ -225,15 +232,16 @@ impl<'a> SchemeSocket for TcpSocket<'a> { let tx_packets = vec![0; 65_535]; let rx_buffer = TcpSocketBuffer::new(rx_packets); let tx_buffer = TcpSocketBuffer::new(tx_packets); - let mut socket = TcpSocket::new(rx_buffer, tx_buffer); + let socket = TcpSocket::new(rx_buffer, tx_buffer); + let new_socket_handle = socket_set.add(socket); { - let tcp_socket: &mut TcpSocket = socket.as_socket(); + let mut tcp_socket = socket_set.get::(new_socket_handle); tcp_socket - .listen(self.local_endpoint()) + .listen(local_endpoint) .expect("Can't listen on local endpoint"); } - port_set.acquire_port(self.local_endpoint().port); - return Ok((new_handle, Some((socket, ())))); + port_set.acquire_port(local_endpoint.port); + return Ok((new_handle, Some((new_socket_handle, ())))); } else { return Err(syscall::Error::new(syscall::EBADF)); }, @@ -248,7 +256,7 @@ impl<'a> SchemeSocket for TcpSocket<'a> { }; if let SchemeFile::Socket(_) = handle { - port_set.acquire_port(self.local_endpoint().port); + port_set.acquire_port(local_endpoint.port); } Ok((handle, None)) diff --git a/src/smolnetd/scheme/udp.rs b/src/smolnetd/scheme/udp.rs index 93203e4bca..9641984b7d 100644 --- a/src/smolnetd/scheme/udp.rs +++ b/src/smolnetd/scheme/udp.rs @@ -1,7 +1,8 @@ use super::socket::*; -use smoltcp::socket::{AsSocket, Socket, SocketHandle, UdpPacketBuffer, UdpSocket, UdpSocketBuffer}; +use smoltcp::socket::{SocketHandle, UdpPacketBuffer, UdpSocket, UdpSocketBuffer}; use smoltcp::wire::{IpAddress, IpEndpoint, Ipv4Address}; +use smoltcp; use std::io::{Read, Write}; use std::str::FromStr; use std::str; @@ -100,10 +101,11 @@ impl<'a, 'b> SchemeSocket for UdpSocket<'a, 'b> { } fn new_socket( + socket_set: &mut smoltcp::socket::SocketSet<'static, 'static, 'static>, path: &str, uid: u32, port_set: &mut Self::SchemeDataT, - ) -> syscall::Result<(Socket<'static, 'static>, Self::DataT)> { + ) -> syscall::Result<(SocketHandle, Self::DataT)> { let mut parts = path.split('/'); let remote_endpoint = parse_endpoint(parts.next().unwrap_or("")); let mut local_endpoint = parse_endpoint(parts.next().unwrap_or("")); @@ -120,7 +122,7 @@ impl<'a, 'b> SchemeSocket for UdpSocket<'a, 'b> { } let rx_buffer = UdpSocketBuffer::new(rx_packets); let tx_buffer = UdpSocketBuffer::new(tx_packets); - let mut udp_socket = UdpSocket::new(rx_buffer, tx_buffer); + let udp_socket = UdpSocket::new(rx_buffer, tx_buffer); if local_endpoint.port == 0 { local_endpoint.port = port_set @@ -130,14 +132,14 @@ impl<'a, 'b> SchemeSocket for UdpSocket<'a, 'b> { return Err(syscall::Error::new(syscall::EADDRINUSE)); } - { - let udp_socket: &mut UdpSocket = udp_socket.as_socket(); - udp_socket - .bind(local_endpoint) - .expect("Can't bind udp socket to local endpoint"); - } + let socket_handle = socket_set.add(udp_socket); - Ok((udp_socket, remote_endpoint)) + let mut udp_socket = socket_set.get::(socket_handle); + udp_socket + .bind(local_endpoint) + .expect("Can't bind udp socket to local endpoint"); + + Ok((socket_handle, remote_endpoint)) } fn close_file( @@ -185,10 +187,10 @@ impl<'a, 'b> SchemeSocket for UdpSocket<'a, 'b> { } fn dup( - &self, + socket_set: &mut smoltcp::socket::SocketSet, + socket_handle: SocketHandle, file: &mut SchemeFile, fd: usize, - socket_handle: SocketHandle, path: &str, port_set: &mut Self::SchemeDataT, ) -> syscall::Result> { @@ -224,8 +226,13 @@ impl<'a, 'b> SchemeSocket for UdpSocket<'a, 'b> { } }; + let endpoint = { + let socket = socket_set.get::(socket_handle); + socket.endpoint() + }; + if let SchemeFile::Socket(_) = handle { - port_set.acquire_port(self.endpoint().port); + port_set.acquire_port(endpoint.port); } Ok((handle, None)) From ecd3848de9a7f191556419869dc4fc7838c3de79 Mon Sep 17 00:00:00 2001 From: Egor Karavaev Date: Sat, 7 Oct 2017 01:29:36 +0300 Subject: [PATCH 047/155] Code cleanup. --- src/smolnetd/main.rs | 2 +- src/smolnetd/scheme/ip.rs | 126 +++---------- src/smolnetd/scheme/mod.rs | 65 ++++--- src/smolnetd/scheme/socket.rs | 336 +++++++++++++++++++++------------- src/smolnetd/scheme/tcp.rs | 157 ++++------------ src/smolnetd/scheme/udp.rs | 155 ++++------------ 6 files changed, 346 insertions(+), 495 deletions(-) diff --git a/src/smolnetd/main.rs b/src/smolnetd/main.rs index 1f78c09590..60cf1df69d 100644 --- a/src/smolnetd/main.rs +++ b/src/smolnetd/main.rs @@ -21,8 +21,8 @@ mod buffer_pool; mod device; mod error; mod logger; -mod scheme; mod port_set; +mod scheme; fn run() -> Result<()> { use syscall::flag::*; diff --git a/src/smolnetd/scheme/ip.rs b/src/smolnetd/scheme/ip.rs index 4edb53b5f9..be014679a4 100644 --- a/src/smolnetd/scheme/ip.rs +++ b/src/smolnetd/scheme/ip.rs @@ -1,31 +1,19 @@ -use super::socket::*; - use smoltcp::socket::{RawPacketBuffer, RawSocket, RawSocketBuffer, SocketHandle}; use smoltcp::wire::{IpProtocol, IpVersion}; -use smoltcp; -use std::io::{Read, Write}; use std::str; -use std::mem; -use std::ops::Deref; -use std::ops::DerefMut; -use syscall::data::TimeSpec; +use syscall::{Error as SyscallError, Result as SyscallResult}; use syscall; use device::NetworkDevice; -use super::Smolnetd; +use super::{Smolnetd, SocketSet}; +use super::socket::{DupResult, SchemeFile, SchemeSocket, SocketFile, SocketScheme}; pub type IpScheme = SocketScheme>; -#[derive(Copy, Clone, Eq, PartialEq, Debug)] -pub enum Setting { - ReadTimeout, - WriteTimeout, -} - impl<'a, 'b> SchemeSocket for RawSocket<'a, 'b> { type SchemeDataT = (); type DataT = (); - type SettingT = Setting; + type SettingT = (); fn new_scheme_data() -> Self::SchemeDataT { () @@ -40,70 +28,32 @@ impl<'a, 'b> SchemeSocket for RawSocket<'a, 'b> { } fn get_setting( - file: &SocketFile, - setting: Self::SettingT, - buf: &mut [u8], - ) -> syscall::Result { - let timespec = match (setting, file.read_timeout, file.write_timeout) { - (Setting::ReadTimeout, Some(read_timeout), _) => read_timeout, - (Setting::WriteTimeout, _, Some(write_timeout)) => write_timeout, - _ => { - return Ok(0); - } - }; - - if buf.len() < mem::size_of::() { - Ok(0) - } else { - let count = timespec.deref().read(buf).map_err(|err| { - syscall::Error::new(err.raw_os_error().unwrap_or(syscall::EIO)) - })?; - Ok(count) - } + _file: &SocketFile, + _setting: Self::SettingT, + _buf: &mut [u8], + ) -> SyscallResult { + Ok(0) } fn set_setting( - file: &mut SocketFile, - setting: Self::SettingT, - buf: &[u8], - ) -> syscall::Result { - match setting { - Setting::ReadTimeout | Setting::WriteTimeout => { - let (timeout, count) = { - if buf.len() < mem::size_of::() { - (None, 0) - } else { - let mut timespec = TimeSpec::default(); - let count = timespec.deref_mut().write(buf).map_err(|err| { - syscall::Error::new(err.raw_os_error().unwrap_or(syscall::EIO)) - })?; - (Some(timespec), count) - } - }; - match setting { - Setting::ReadTimeout => { - file.read_timeout = timeout; - } - Setting::WriteTimeout => { - file.write_timeout = timeout; - } - }; - return Ok(count); - } - } + _file: &mut SocketFile, + _setting: Self::SettingT, + _buf: &[u8], + ) -> SyscallResult { + Ok(0) } fn new_socket( - socket_set: &mut smoltcp::socket::SocketSet<'static, 'static, 'static>, + socket_set: &mut SocketSet, path: &str, uid: u32, _: &mut Self::SchemeDataT, - ) -> syscall::Result<(SocketHandle, Self::DataT)> { + ) -> SyscallResult<(SocketHandle, Self::DataT)> { if uid != 0 { - return Err(syscall::Error::new(syscall::EACCES)); + return Err(SyscallError::new(syscall::EACCES)); } let proto = - u8::from_str_radix(path, 16).or_else(|_| Err(syscall::Error::new(syscall::ENOENT)))?; + u8::from_str_radix(path, 16).or_else(|_| Err(SyscallError::new(syscall::ENOENT)))?; let mut rx_packets = Vec::with_capacity(Smolnetd::SOCKET_BUFFER_SIZE); let mut tx_packets = Vec::with_capacity(Smolnetd::SOCKET_BUFFER_SIZE); @@ -124,7 +74,7 @@ impl<'a, 'b> SchemeSocket for RawSocket<'a, 'b> { Ok((socket_handle, ())) } - fn close_file(&self, _: &SchemeFile, _: &mut Self::SchemeDataT) -> syscall::Result<()> { + fn close_file(&self, _: &SchemeFile, _: &mut Self::SchemeDataT) -> SyscallResult<()> { Ok(()) } @@ -132,14 +82,14 @@ impl<'a, 'b> SchemeSocket for RawSocket<'a, 'b> { &mut self, file: &mut SocketFile, buf: &[u8], - ) -> syscall::Result { + ) -> SyscallResult { if self.can_send() { self.send_slice(buf).expect("Can't send slice"); Ok(buf.len()) } else if file.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { Ok(0) } else { - Err(syscall::Error::new(syscall::EWOULDBLOCK)) + Err(SyscallError::new(syscall::EWOULDBLOCK)) } } @@ -147,47 +97,27 @@ impl<'a, 'b> SchemeSocket for RawSocket<'a, 'b> { &mut self, file: &mut SocketFile, buf: &mut [u8], - ) -> syscall::Result { + ) -> SyscallResult { if self.can_recv() { let length = self.recv_slice(buf).expect("Can't receive slice"); Ok(length) } else if file.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { Ok(0) } else { - Err(syscall::Error::new(syscall::EWOULDBLOCK)) + Err(SyscallError::new(syscall::EWOULDBLOCK)) } } fn dup( - _socket_set: &mut smoltcp::socket::SocketSet<'static, 'static, 'static>, - socket_handle: SocketHandle, + _socket_set: &mut SocketSet, _file: &mut SchemeFile, - fd: usize, - path: &str, + _path: &str, _: &mut Self::SchemeDataT, - ) -> syscall::Result> { - match path { - "write_timeout" => Ok(( - SchemeFile::Setting(SettingFile { - socket_handle, - fd, - setting: Setting::WriteTimeout, - }), - None, - )), - "read_timeout" => Ok(( - SchemeFile::Setting(SettingFile { - socket_handle, - fd, - setting: Setting::ReadTimeout, - }), - None, - )), - _ => Err(syscall::Error::new(syscall::EBADF)), - } + ) -> SyscallResult> { + Err(SyscallError::new(syscall::EBADF)) } - fn fpath(&self, _file: &SchemeFile, buf: &mut [u8]) -> syscall::Result { + fn fpath(&self, _file: &SchemeFile, buf: &mut [u8]) -> SyscallResult { let path = format!("ip:{}", self.ip_protocol()); let path = path.as_bytes(); diff --git a/src/smolnetd/scheme/mod.rs b/src/smolnetd/scheme/mod.rs index 39f3977ac5..a65296521b 100644 --- a/src/smolnetd/scheme/mod.rs +++ b/src/smolnetd/scheme/mod.rs @@ -1,35 +1,38 @@ use netutils::getcfg; -use smoltcp; +use smoltcp::iface::{ArpCache, EthernetInterface, SliceArpCache}; +use smoltcp::socket::SocketSet as SmoltcpSocketSet; +use smoltcp::wire::{EthernetAddress, IpAddress, IpCidr, IpEndpoint, Ipv4Address}; use std::cell::RefCell; use std::collections::VecDeque; use std::fs::File; use std::io::{Read, Write}; -use std::mem; +use std::mem::size_of; use std::rc::Rc; use std::str::FromStr; use std::time::Instant; +use syscall::data::TimeSpec; use syscall; use buffer_pool::{Buffer, BufferPool}; use device::NetworkDevice; use error::{Error, Result}; use self::ip::IpScheme; -use self::udp::UdpScheme; use self::tcp::TcpScheme; +use self::udp::UdpScheme; mod ip; mod socket; -mod udp; mod tcp; +mod udp; -type SocketSet = Rc>>; +type SocketSet = SmoltcpSocketSet<'static, 'static, 'static>; pub struct Smolnetd { network_file: Rc>, time_file: File, - iface: smoltcp::iface::EthernetInterface<'static, 'static, 'static, NetworkDevice>, - socket_set: SocketSet, + iface: EthernetInterface<'static, 'static, 'static, NetworkDevice>, + socket_set: Rc>, startup_time: Instant, @@ -54,26 +57,25 @@ impl Smolnetd { tcp_file: File, time_file: File, ) -> Smolnetd { - let arp_cache = smoltcp::iface::SliceArpCache::new(vec![Default::default(); 8]); - let hardware_addr = smoltcp::wire::EthernetAddress::from_str(getcfg("mac").unwrap().trim()) + let arp_cache = SliceArpCache::new(vec![Default::default(); 8]); + let hardware_addr = EthernetAddress::from_str(getcfg("mac").unwrap().trim()) .expect("Can't parse the 'mac' cfg"); - let local_ip = smoltcp::wire::IpAddress::from_str(getcfg("ip").unwrap().trim()) - .expect("Can't parse the 'ip' cfg."); - let protocol_addrs = [smoltcp::wire::IpCidr::new(local_ip, 24)]; - let default_gw = smoltcp::wire::Ipv4Address::from_str(getcfg("ip_router").unwrap().trim()) + let local_ip = + IpAddress::from_str(getcfg("ip").unwrap().trim()).expect("Can't parse the 'ip' cfg."); + let protocol_addrs = [IpCidr::new(local_ip, 24)]; + let default_gw = Ipv4Address::from_str(getcfg("ip_router").unwrap().trim()) .expect("Can't parse the 'ip_router' cfg."); - // trace!("mac {:?} ip {}", hardware_addr, protocol_addrs); let input_queue = Rc::new(RefCell::new(VecDeque::new())); let network_file = Rc::new(RefCell::new(network_file)); let network_device = NetworkDevice::new(Rc::clone(&network_file), Rc::clone(&input_queue)); - let iface = smoltcp::iface::EthernetInterface::new( + let iface = EthernetInterface::new( Box::new(network_device), - Box::new(arp_cache) as Box, + Box::new(arp_cache) as Box, hardware_addr, protocol_addrs, Some(default_gw), ); - let socket_set = Rc::new(RefCell::new(smoltcp::socket::SocketSet::new(vec![]))); + let socket_set = Rc::new(RefCell::new(SocketSet::new(vec![]))); Smolnetd { iface, socket_set: Rc::clone(&socket_set), @@ -97,31 +99,31 @@ impl Smolnetd { pub fn on_ip_scheme_event(&mut self) -> Result> { self.ip_scheme.on_scheme_event()?; - self.poll()?; + let _ = self.poll()?; Ok(None) } pub fn on_udp_scheme_event(&mut self) -> Result> { self.udp_scheme.on_scheme_event()?; - self.poll()?; + let _ = self.poll()?; Ok(None) } pub fn on_tcp_scheme_event(&mut self) -> Result> { self.tcp_scheme.on_scheme_event()?; - self.poll()?; + let _ = self.poll()?; Ok(None) } pub fn on_time_event(&mut self) -> Result> { let timeout = self.poll()?; - self.schedule_timeout(timeout)?; + self.schedule_time_event(timeout)?; Ok(None) } - fn schedule_timeout(&mut self, timeout: i64) -> Result<()> { - let mut time = syscall::data::TimeSpec::default(); - if self.time_file.read(&mut time)? < mem::size_of::() { + fn schedule_time_event(&mut self, timeout: i64) -> Result<()> { + let mut time = TimeSpec::default(); + if self.time_file.read(&mut time)? < size_of::() { return Err(Error::from_syscall_error( syscall::Error::new(syscall::EBADF), "Can't read current time", @@ -215,3 +217,18 @@ fn post_fevent(scheme_file: &mut File, fd: usize, event: usize, data_len: usize) .map(|_| ()) .map_err(|e| Error::from_io_error(e, "failed to post fevent")) } + +fn parse_endpoint(socket: &str) -> IpEndpoint { + let mut socket_parts = socket.split(':'); + let host = IpAddress::Ipv4( + Ipv4Address::from_str(socket_parts.next().unwrap_or("")) + .unwrap_or_else(|_| Ipv4Address::new(0, 0, 0, 0)), + ); + + let port = socket_parts + .next() + .unwrap_or("") + .parse::() + .unwrap_or(0); + IpEndpoint::new(host, port) +} diff --git a/src/smolnetd/scheme/socket.rs b/src/smolnetd/scheme/socket.rs index 7d5b3ec05e..b36af6e1d7 100644 --- a/src/smolnetd/scheme/socket.rs +++ b/src/smolnetd/scheme/socket.rs @@ -1,25 +1,29 @@ use smoltcp::socket::{AnySocket, SocketHandle}; -use smoltcp; +use std::cell::RefCell; use std::collections::BTreeMap; use std::fs::File; use std::io::{Read, Write}; -use std::str; use std::marker::PhantomData; -use syscall::SchemeMut; +use std::mem; +use std::ops::Deref; +use std::ops::DerefMut; +use std::rc::Rc; +use std::str; use syscall::data::TimeSpec; +use syscall::{Error as SyscallError, Packet as SyscallPacket, Result as SyscallResult, SchemeMut}; use syscall; use error::{Error, Result}; -use super::SocketSet; -use super::post_fevent; +use super::{SocketSet, post_fevent}; pub struct SocketFile { pub flags: usize, + pub data: DataT, + events: usize, socket_handle: SocketHandle, - pub data: DataT, - pub read_timeout: Option, - pub write_timeout: Option, + read_timeout: Option, + write_timeout: Option, } impl SocketFile { @@ -46,10 +50,18 @@ impl SocketFile { } } -pub struct SettingFile { - pub fd: usize, - pub socket_handle: SocketHandle, - pub setting: SettingT, +#[derive(Copy, Clone)] +enum Setting { + Ttl, + ReadTimeout, + WriteTimeout, + #[allow(dead_code)] Other(SettingT), +} + +pub struct SettingFile { + fd: usize, + socket_handle: SocketHandle, + setting: Setting, } pub enum SchemeFile @@ -64,7 +76,7 @@ impl SchemeFile where SocketT: SchemeSocket, { - fn socket_handle(&self) -> SocketHandle { + pub fn socket_handle(&self) -> SocketHandle { match *self { SchemeFile::Socket(SocketFile { socket_handle, .. }) | SchemeFile::Setting(SettingFile { socket_handle, .. }) => socket_handle, @@ -75,14 +87,17 @@ where #[derive(Default, Clone)] struct WaitHandle { until: Option, - packet: syscall::Packet, + packet: SyscallPacket, } type WaitQueue = Vec; type WaitQueueMap = BTreeMap; -pub type DupResult = (SchemeFile, Option<(SocketHandle, T::DataT)>); +pub type DupResult = ( + SchemeFile, + Option<(SocketHandle, ::DataT)>, +); pub trait SchemeSocket where @@ -97,30 +112,30 @@ where fn can_send(&self) -> bool; fn can_recv(&self) -> bool; - fn get_setting(&SocketFile, Self::SettingT, &mut [u8]) -> syscall::Result; - fn set_setting(&mut SocketFile, Self::SettingT, &[u8]) -> syscall::Result; + fn get_setting(&SocketFile, Self::SettingT, &mut [u8]) -> SyscallResult; + fn set_setting(&mut SocketFile, Self::SettingT, &[u8]) -> SyscallResult; fn new_socket( - &mut smoltcp::socket::SocketSet<'static, 'static, 'static>, + &mut SocketSet, &str, u32, &mut Self::SchemeDataT, - ) -> syscall::Result<(SocketHandle, Self::DataT)>; - fn close_file(&self, &SchemeFile, &mut Self::SchemeDataT) -> syscall::Result<()>; + ) -> SyscallResult<(SocketHandle, Self::DataT)>; - fn write_buf(&mut self, &mut SocketFile, buf: &[u8]) -> syscall::Result; - fn read_buf(&mut self, &mut SocketFile, buf: &mut [u8]) -> syscall::Result; + fn close_file(&self, &SchemeFile, &mut Self::SchemeDataT) -> SyscallResult<()>; - fn fpath(&self, &SchemeFile, &mut [u8]) -> syscall::Result; + fn write_buf(&mut self, &mut SocketFile, buf: &[u8]) -> SyscallResult; + + fn read_buf(&mut self, &mut SocketFile, buf: &mut [u8]) -> SyscallResult; + + fn fpath(&self, &SchemeFile, &mut [u8]) -> SyscallResult; fn dup( - &mut smoltcp::socket::SocketSet<'static, 'static, 'static>, - SocketHandle, + &mut SocketSet, &mut SchemeFile, - usize, &str, &mut Self::SchemeDataT, - ) -> syscall::Result>; + ) -> SyscallResult>; } pub struct SocketScheme @@ -128,8 +143,8 @@ where SocketT: SchemeSocket + AnySocket<'static, 'static>, { next_fd: usize, - fds: BTreeMap>, - socket_set: SocketSet, + files: BTreeMap>, + socket_set: Rc>, scheme_file: File, wait_queue_map: WaitQueueMap, scheme_data: SocketT::SchemeDataT, @@ -140,10 +155,10 @@ impl SocketScheme where SocketT: SchemeSocket + AnySocket<'static, 'static>, { - pub fn new(socket_set: SocketSet, scheme_file: File) -> SocketScheme { + pub fn new(socket_set: Rc>, scheme_file: File) -> SocketScheme { SocketScheme { next_fd: 1, - fds: BTreeMap::new(), + files: BTreeMap::new(), socket_set, scheme_data: SocketT::new_scheme_data(), scheme_file, @@ -154,7 +169,7 @@ where pub fn on_scheme_event(&mut self) -> Result> { loop { - let mut packet = syscall::Packet::default(); + let mut packet = SyscallPacket::default(); if self.scheme_file.read(&mut packet)? == 0 { break; } @@ -172,12 +187,12 @@ where pub fn notify_sockets(&mut self) -> Result<()> { // Notify non-blocking sockets - for (&fd, handle) in &self.fds { + for (&fd, file) in &self.files { if let SchemeFile::Socket(SocketFile { socket_handle, events, .. - }) = *handle + }) = *file { let mut socket_set = self.socket_set.borrow_mut(); let socket = socket_set.get::(socket_handle); @@ -243,7 +258,6 @@ where } } } else { - trace!("Waking up {} with {}", packet.b, packet.a); self.scheme_file.write_all(&packet)?; } } @@ -255,13 +269,12 @@ where Ok(()) } - fn move_handle_to_new_socket_handle( + fn move_file_to_new_socket_handle( wait_queue_map: &mut WaitQueueMap, fd: usize, from: SocketHandle, to: SocketHandle, - ) -> syscall::Result<()> { - trace!("Moving {} from {:?} to {:?}", fd, from, to); + ) -> SyscallResult<()> { let mut to_move = vec![]; if let Some(wait_queue) = wait_queue_map.get_mut(&from) { @@ -277,7 +290,7 @@ where Ok(()) } - fn handle_block(&mut self, mut packet: syscall::Packet) -> Result<()> { + fn handle_block(&mut self, mut packet: SyscallPacket) -> Result<()> { let syscall_result = self.try_handle_block(&mut packet); if let Err(syscall_error) = syscall_result { packet.a = (-syscall_error.errno) as usize; @@ -291,21 +304,21 @@ where } } - fn try_handle_block(&mut self, packet: &mut syscall::Packet) -> syscall::Result<()> { + fn try_handle_block(&mut self, packet: &mut SyscallPacket) -> SyscallResult<()> { let fd = packet.b; let (socket_handle, read_timeout, write_timeout) = { - let handle = self.fds + let file = self.files .get(&fd) - .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; + .ok_or_else(|| SyscallError::new(syscall::EBADF))?; - if let SchemeFile::Socket(ref scheme_file) = *handle { + if let SchemeFile::Socket(ref scheme_file) = *file { Ok(( scheme_file.socket_handle, scheme_file.read_timeout, scheme_file.write_timeout, )) } else { - Err(syscall::Error::new(syscall::EBADF)) + Err(SyscallError::new(syscall::EBADF)) } }?; @@ -336,38 +349,83 @@ where fn get_setting( &mut self, fd: usize, - setting: SocketT::SettingT, + setting: Setting, buf: &mut [u8], - ) -> syscall::Result { - let handle = self.fds + ) -> SyscallResult { + let file = self.files .get_mut(&fd) - .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; - let handle = match *handle { - SchemeFile::Socket(ref mut handle) => handle, + .ok_or_else(|| SyscallError::new(syscall::EBADF))?; + let file = match *file { + SchemeFile::Socket(ref mut file) => file, _ => { - return Err(syscall::Error::new(syscall::EBADF)); + return Err(SyscallError::new(syscall::EBADF)); } }; - SocketT::get_setting(handle, setting, buf) + if let Setting::Other(setting) = setting { + SocketT::get_setting(file, setting, buf) + } else { + let timespec = match (setting, file.read_timeout, file.write_timeout) { + (Setting::ReadTimeout, Some(read_timeout), _) => read_timeout, + (Setting::WriteTimeout, _, Some(write_timeout)) => write_timeout, + _ => { + return Ok(0); + } + }; + + if buf.len() < mem::size_of::() { + Ok(0) + } else { + let count = timespec.deref().read(buf).map_err(|err| { + SyscallError::new(err.raw_os_error().unwrap_or(syscall::EIO)) + })?; + Ok(count) + } + } } fn update_setting( &mut self, fd: usize, - setting: SocketT::SettingT, + setting: Setting, buf: &[u8], - ) -> syscall::Result { - let handle = self.fds + ) -> SyscallResult { + let file = self.files .get_mut(&fd) - .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; - let handle = match *handle { - SchemeFile::Socket(ref mut handle) => handle, + .ok_or_else(|| SyscallError::new(syscall::EBADF))?; + let file = match *file { + SchemeFile::Socket(ref mut file) => file, _ => { - return Err(syscall::Error::new(syscall::EBADF)); + return Err(SyscallError::new(syscall::EBADF)); } }; - SocketT::set_setting(handle, setting, buf) + match setting { + Setting::ReadTimeout | Setting::WriteTimeout => { + let (timeout, count) = { + if buf.len() < mem::size_of::() { + (None, 0) + } else { + let mut timespec = TimeSpec::default(); + let count = timespec.deref_mut().write(buf).map_err(|err| { + SyscallError::new(err.raw_os_error().unwrap_or(syscall::EIO)) + })?; + (Some(timespec), count) + } + }; + match setting { + Setting::ReadTimeout => { + file.read_timeout = timeout; + } + Setting::WriteTimeout => { + file.write_timeout = timeout; + } + _ => {} + }; + Ok(count) + } + Setting::Ttl => Ok(0), + Setting::Other(setting) => SocketT::set_setting(file, setting, buf), + } } } @@ -375,9 +433,8 @@ impl syscall::SchemeMut for SocketScheme where SocketT: SchemeSocket + AnySocket<'static, 'static>, { - fn open(&mut self, url: &[u8], flags: usize, uid: u32, _gid: u32) -> syscall::Result { - let path = str::from_utf8(url).or_else(|_| Err(syscall::Error::new(syscall::EINVAL)))?; - trace!("open {}", path); + fn open(&mut self, url: &[u8], flags: usize, uid: u32, _gid: u32) -> SyscallResult { + let path = str::from_utf8(url).or_else(|_| Err(SyscallError::new(syscall::EINVAL)))?; let (socket_handle, data) = SocketT::new_socket( &mut self.socket_set.borrow_mut(), @@ -388,7 +445,7 @@ where let id = self.next_fd; - self.fds.insert( + self.files.insert( id, SchemeFile::Socket(SocketFile { flags, @@ -403,15 +460,14 @@ where Ok(id) } - fn close(&mut self, fd: usize) -> syscall::Result { - trace!("close {}", fd); + fn close(&mut self, fd: usize) -> SyscallResult { let socket_handle = { - let handle = self.fds + let file = self.files .get(&fd) - .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; - handle.socket_handle() + .ok_or_else(|| SyscallError::new(syscall::EBADF))?; + file.socket_handle() }; - let scheme_file = self.fds.remove(&fd); + let scheme_file = self.files.remove(&fd); let mut socket_set = self.socket_set.borrow_mut(); if let Some(scheme_file) = scheme_file { let socket = socket_set.get::(socket_handle); @@ -421,7 +477,7 @@ where if let Some(ref mut wait_queue) = self.wait_queue_map.get_mut(&socket_handle) { wait_queue.retain( |&WaitHandle { - packet: syscall::Packet { a, .. }, + packet: SyscallPacket { a, .. }, .. }| a != fd, ); @@ -438,143 +494,165 @@ where Ok(0) } - fn write(&mut self, fd: usize, buf: &[u8]) -> syscall::Result { + fn write(&mut self, fd: usize, buf: &[u8]) -> SyscallResult { let (fd, setting) = { - let handle = self.fds + let file = self.files .get_mut(&fd) - .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; + .ok_or_else(|| SyscallError::new(syscall::EBADF))?; - match *handle { + match *file { SchemeFile::Setting(ref setting_handle) => { (setting_handle.fd, setting_handle.setting) } - SchemeFile::Socket(ref mut handle) => { + SchemeFile::Socket(ref mut file) => { let mut socket_set = self.socket_set.borrow_mut(); - let mut socket = socket_set.get::(handle.socket_handle); - - return ::write_buf(&mut socket, handle, buf); + let mut socket = socket_set.get::(file.socket_handle); + return SocketT::write_buf(&mut socket, file, buf); } } }; self.update_setting(fd, setting, buf) } - fn read(&mut self, fd: usize, buf: &mut [u8]) -> syscall::Result { + fn read(&mut self, fd: usize, buf: &mut [u8]) -> SyscallResult { let (fd, setting) = { - let handle = self.fds + let file = self.files .get_mut(&fd) - .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; - match *handle { + .ok_or_else(|| SyscallError::new(syscall::EBADF))?; + match *file { SchemeFile::Setting(ref setting_handle) => { (setting_handle.fd, setting_handle.setting) } - SchemeFile::Socket(ref mut handle) => { + SchemeFile::Socket(ref mut file) => { let mut socket_set = self.socket_set.borrow_mut(); - let mut socket = socket_set.get::(handle.socket_handle); - return ::read_buf(&mut socket, handle, buf); + let mut socket = socket_set.get::(file.socket_handle); + return SocketT::read_buf(&mut socket, file, buf); } } }; self.get_setting(fd, setting, buf) } - fn dup(&mut self, fd: usize, buf: &[u8]) -> syscall::Result { - let path = str::from_utf8(buf).or_else(|_| Err(syscall::Error::new(syscall::EINVAL)))?; + fn dup(&mut self, fd: usize, buf: &[u8]) -> SyscallResult { + let path = str::from_utf8(buf).or_else(|_| Err(SyscallError::new(syscall::EINVAL)))?; let new_file = { - let handle = self.fds + let file = self.files .get_mut(&fd) - .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; + .ok_or_else(|| SyscallError::new(syscall::EBADF))?; - let socket_handle = handle.socket_handle(); + let socket_handle = file.socket_handle(); - let (new_handle, update_with) = SocketT::dup( - &mut self.socket_set.borrow_mut(), - socket_handle, - handle, - fd, - path, - &mut self.scheme_data, - )?; + let (new_handle, update_with) = match path { + "ttl" => ( + SchemeFile::Setting(SettingFile { + socket_handle, + fd, + setting: Setting::Ttl, + }), + None, + ), + "read_timeout" => ( + SchemeFile::Setting(SettingFile { + socket_handle, + fd, + setting: Setting::ReadTimeout, + }), + None, + ), + "write_timeout" => ( + SchemeFile::Setting(SettingFile { + socket_handle, + fd, + setting: Setting::WriteTimeout, + }), + None, + ), + _ => SocketT::dup( + &mut self.socket_set.borrow_mut(), + file, + path, + &mut self.scheme_data, + )?, + }; if let Some((socket_handle, data)) = update_with { - if let SchemeFile::Socket(ref mut handle) = *handle { - trace!("Updating {} to a new socket handle {:?}", fd, socket_handle); - Self::move_handle_to_new_socket_handle( + if let SchemeFile::Socket(ref mut file) = *file { + Self::move_file_to_new_socket_handle( &mut self.wait_queue_map, fd, - handle.socket_handle, + file.socket_handle, socket_handle, )?; - handle.socket_handle = socket_handle; - handle.data = data; + file.socket_handle = socket_handle; + file.data = data; } else { - self.socket_set.borrow_mut().retain(handle.socket_handle()); + self.socket_set.borrow_mut().retain(file.socket_handle()); } } else { - self.socket_set.borrow_mut().retain(handle.socket_handle()); + self.socket_set.borrow_mut().retain(file.socket_handle()); } new_handle }; let id = self.next_fd; - self.fds.insert(id, new_file); + self.files.insert(id, new_file); self.next_fd += 1; Ok(id) } - fn fevent(&mut self, fd: usize, events: usize) -> syscall::Result { - let handle = self.fds + fn fevent(&mut self, fd: usize, events: usize) -> SyscallResult { + let file = self.files .get_mut(&fd) - .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; - match *handle { - SchemeFile::Setting(_) => Err(syscall::Error::new(syscall::EBADF)), - SchemeFile::Socket(ref mut handle) => { - handle.events = events; + .ok_or_else(|| SyscallError::new(syscall::EBADF))?; + match *file { + SchemeFile::Setting(_) => Err(SyscallError::new(syscall::EBADF)), + SchemeFile::Socket(ref mut file) => { + file.events = events; Ok(fd) } } } - fn fsync(&mut self, fd: usize) -> syscall::Result { + fn fsync(&mut self, fd: usize) -> SyscallResult { { - let _handle = self.fds + let _file = self.files .get_mut(&fd) - .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; + .ok_or_else(|| SyscallError::new(syscall::EBADF))?; } Ok(0) // TODO Implement fsyncing // self.0.network_fsync() } - fn fpath(&mut self, fd: usize, buf: &mut [u8]) -> syscall::Result { - let handle = self.fds + fn fpath(&mut self, fd: usize, buf: &mut [u8]) -> SyscallResult { + let file = self.files .get_mut(&fd) - .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; + .ok_or_else(|| SyscallError::new(syscall::EBADF))?; let mut socket_set = self.socket_set.borrow_mut(); - let socket = socket_set.get::(handle.socket_handle()); + let socket = socket_set.get::(file.socket_handle()); - socket.fpath(handle, buf) + socket.fpath(file, buf) } - fn fcntl(&mut self, fd: usize, cmd: usize, arg: usize) -> syscall::Result { - let handle = self.fds + fn fcntl(&mut self, fd: usize, cmd: usize, arg: usize) -> SyscallResult { + let file = self.files .get_mut(&fd) - .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; + .ok_or_else(|| SyscallError::new(syscall::EBADF))?; - if let SchemeFile::Socket(ref mut socket_file) = *handle { + if let SchemeFile::Socket(ref mut socket_file) = *file { match cmd { syscall::F_GETFL => Ok(socket_file.flags), syscall::F_SETFL => { socket_file.flags = arg & !syscall::O_ACCMODE; Ok(0) } - _ => Err(syscall::Error::new(syscall::EINVAL)), + _ => Err(SyscallError::new(syscall::EINVAL)), } } else { - Err(syscall::Error::new(syscall::EBADF)) + Err(SyscallError::new(syscall::EBADF)) } } } diff --git a/src/smolnetd/scheme/tcp.rs b/src/smolnetd/scheme/tcp.rs index 46e6de4173..1ce10f3020 100644 --- a/src/smolnetd/scheme/tcp.rs +++ b/src/smolnetd/scheme/tcp.rs @@ -1,32 +1,18 @@ -use super::socket::*; - use smoltcp::socket::{SocketHandle, TcpSocket, TcpSocketBuffer}; -use smoltcp::wire::{IpAddress, IpEndpoint, Ipv4Address}; -use smoltcp; -use std::io::{Read, Write}; -use std::str::FromStr; use std::str; -use std::mem; -use std::ops::Deref; -use std::ops::DerefMut; -use syscall::data::TimeSpec; +use syscall::{Error as SyscallError, Result as SyscallResult}; use syscall; use port_set::PortSet; +use super::socket::{DupResult, SchemeFile, SchemeSocket, SocketFile, SocketScheme}; +use super::{parse_endpoint, SocketSet}; pub type TcpScheme = SocketScheme>; -#[derive(Copy, Clone, Eq, PartialEq, Debug)] -pub enum Setting { - Ttl, - ReadTimeout, - WriteTimeout, -} - impl<'a> SchemeSocket for TcpSocket<'a> { type SchemeDataT = PortSet; type DataT = (); - type SettingT = Setting; + type SettingT = (); fn new_scheme_data() -> Self::SchemeDataT { PortSet::new(49_152u16, 65_535u16).expect("Wrong TCP port numbers") @@ -41,77 +27,34 @@ impl<'a> SchemeSocket for TcpSocket<'a> { } fn get_setting( - file: &SocketFile, - setting: Self::SettingT, - buf: &mut [u8], - ) -> syscall::Result { - trace!("TCP get setting {:?}", setting); - let timespec = match (setting, file.read_timeout, file.write_timeout) { - (Setting::ReadTimeout, Some(read_timeout), _) => read_timeout, - (Setting::WriteTimeout, _, Some(write_timeout)) => write_timeout, - _ => { - return Ok(0); - } - }; - - if buf.len() < mem::size_of::() { - Ok(0) - } else { - let count = timespec.deref().read(buf).map_err(|err| { - syscall::Error::new(err.raw_os_error().unwrap_or(syscall::EIO)) - })?; - Ok(count) - } + _file: &SocketFile, + _setting: Self::SettingT, + _buf: &mut [u8], + ) -> SyscallResult { + Ok(0) } fn set_setting( - file: &mut SocketFile, - setting: Self::SettingT, - buf: &[u8], - ) -> syscall::Result { - trace!("TCP set setting {:?}", setting); - match setting { - Setting::ReadTimeout | Setting::WriteTimeout => { - let (timeout, count) = { - if buf.len() < mem::size_of::() { - (None, 0) - } else { - let mut timespec = TimeSpec::default(); - let count = timespec.deref_mut().write(buf).map_err(|err| { - syscall::Error::new(err.raw_os_error().unwrap_or(syscall::EIO)) - })?; - (Some(timespec), count) - } - }; - match setting { - Setting::ReadTimeout => { - file.read_timeout = timeout; - } - Setting::WriteTimeout => { - file.write_timeout = timeout; - } - _ => {} - }; - return Ok(count); - } - Setting::Ttl => {} - } + _file: &mut SocketFile, + _setting: Self::SettingT, + _buf: &[u8], + ) -> SyscallResult { Ok(0) } fn new_socket( - socket_set: &mut smoltcp::socket::SocketSet<'static, 'static, 'static>, + socket_set: &mut SocketSet, path: &str, uid: u32, port_set: &mut Self::SchemeDataT, - ) -> syscall::Result<(SocketHandle, Self::DataT)> { + ) -> SyscallResult<(SocketHandle, Self::DataT)> { trace!("TCP open {}", path); let mut parts = path.split('/'); let remote_endpoint = parse_endpoint(parts.next().unwrap_or("")); let mut local_endpoint = parse_endpoint(parts.next().unwrap_or("")); if local_endpoint.port > 0 && local_endpoint.port <= 1024 && uid != 0 { - return Err(syscall::Error::new(syscall::EACCES)); + return Err(SyscallError::new(syscall::EACCES)); } let rx_packets = vec![0; 65_535]; @@ -123,9 +66,9 @@ impl<'a> SchemeSocket for TcpSocket<'a> { if local_endpoint.port == 0 { local_endpoint.port = port_set .get_port() - .ok_or_else(|| syscall::Error::new(syscall::EINVAL))?; + .ok_or_else(|| SyscallError::new(syscall::EINVAL))?; } else if !port_set.claim_port(local_endpoint.port) { - return Err(syscall::Error::new(syscall::EADDRINUSE)); + return Err(SyscallError::new(syscall::EADDRINUSE)); } let socket_handle = socket_set.add(socket); @@ -151,7 +94,7 @@ impl<'a> SchemeSocket for TcpSocket<'a> { &self, file: &SchemeFile, port_set: &mut Self::SchemeDataT, - ) -> syscall::Result<()> { + ) -> SyscallResult<()> { if let SchemeFile::Socket(_) = *file { port_set.release_port(self.local_endpoint().port); } @@ -162,16 +105,16 @@ impl<'a> SchemeSocket for TcpSocket<'a> { &mut self, file: &mut SocketFile, buf: &[u8], - ) -> syscall::Result { + ) -> SyscallResult { if !self.is_active() { - Err(syscall::Error::new(syscall::ENOTCONN)) + Err(SyscallError::new(syscall::ENOTCONN)) } else if self.can_send() { self.send_slice(buf).expect("Can't send slice"); Ok(buf.len()) } else if file.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { Ok(0) } else { - Err(syscall::Error::new(syscall::EWOULDBLOCK)) + Err(SyscallError::new(syscall::EWOULDBLOCK)) } } @@ -179,51 +122,36 @@ impl<'a> SchemeSocket for TcpSocket<'a> { &mut self, file: &mut SocketFile, buf: &mut [u8], - ) -> syscall::Result { + ) -> SyscallResult { if !self.is_active() { - Err(syscall::Error::new(syscall::ENOTCONN)) + Err(SyscallError::new(syscall::ENOTCONN)) } else if self.can_recv() { let length = self.recv_slice(buf).expect("Can't receive slice"); Ok(length) } else if file.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { Ok(0) } else { - Err(syscall::Error::new(syscall::EWOULDBLOCK)) + Err(SyscallError::new(syscall::EWOULDBLOCK)) } } fn dup( - socket_set: &mut smoltcp::socket::SocketSet<'static, 'static, 'static>, - socket_handle: SocketHandle, + socket_set: &mut SocketSet, file: &mut SchemeFile, - fd: usize, path: &str, port_set: &mut Self::SchemeDataT, - ) -> syscall::Result> { + ) -> SyscallResult> { + let socket_handle = file.socket_handle(); + let (is_active, local_endpoint) = { let socket = socket_set.get::(socket_handle); (socket.is_active(), socket.local_endpoint()) }; - let handle = match path { - "ttl" => SchemeFile::Setting(SettingFile { - socket_handle, - fd, - setting: Setting::Ttl, - }), - "read_timeout" => SchemeFile::Setting(SettingFile { - socket_handle, - fd, - setting: Setting::ReadTimeout, - }), - "write_timeout" => SchemeFile::Setting(SettingFile { - socket_handle, - fd, - setting: Setting::WriteTimeout, - }), + let file = match path { "listen" => if let SchemeFile::Socket(ref tcp_handle) = *file { if !is_active { - return Err(syscall::Error::new(syscall::EWOULDBLOCK)); + return Err(SyscallError::new(syscall::EWOULDBLOCK)); } trace!("TCP creating new listening socket"); let new_handle = SchemeFile::Socket(tcp_handle.clone_with_data(())); @@ -243,7 +171,7 @@ impl<'a> SchemeSocket for TcpSocket<'a> { port_set.acquire_port(local_endpoint.port); return Ok((new_handle, Some((new_socket_handle, ())))); } else { - return Err(syscall::Error::new(syscall::EBADF)); + return Err(SyscallError::new(syscall::EBADF)); }, _ => { trace!("TCP dup unknown {}", path); @@ -255,14 +183,14 @@ impl<'a> SchemeSocket for TcpSocket<'a> { } }; - if let SchemeFile::Socket(_) = handle { + if let SchemeFile::Socket(_) = file { port_set.acquire_port(local_endpoint.port); } - Ok((handle, None)) + Ok((file, None)) } - fn fpath(&self, _: &SchemeFile, buf: &mut [u8]) -> syscall::Result { + fn fpath(&self, _: &SchemeFile, buf: &mut [u8]) -> SyscallResult { let path = format!("tcp:{}/{}", self.remote_endpoint(), self.local_endpoint()); let path = path.as_bytes(); @@ -275,18 +203,3 @@ impl<'a> SchemeSocket for TcpSocket<'a> { Ok(i) } } - -fn parse_endpoint(socket: &str) -> IpEndpoint { - let mut socket_parts = socket.split(':'); - let host = IpAddress::Ipv4( - Ipv4Address::from_str(socket_parts.next().unwrap_or("")) - .unwrap_or_else(|_| Ipv4Address::new(0, 0, 0, 0)), - ); - - let port = socket_parts - .next() - .unwrap_or("") - .parse::() - .unwrap_or(0); - IpEndpoint::new(host, port) -} diff --git a/src/smolnetd/scheme/udp.rs b/src/smolnetd/scheme/udp.rs index 9641984b7d..87f65b9bdb 100644 --- a/src/smolnetd/scheme/udp.rs +++ b/src/smolnetd/scheme/udp.rs @@ -1,34 +1,20 @@ -use super::socket::*; - use smoltcp::socket::{SocketHandle, UdpPacketBuffer, UdpSocket, UdpSocketBuffer}; -use smoltcp::wire::{IpAddress, IpEndpoint, Ipv4Address}; -use smoltcp; -use std::io::{Read, Write}; -use std::str::FromStr; +use smoltcp::wire::IpEndpoint; use std::str; -use std::mem; -use std::ops::Deref; -use std::ops::DerefMut; -use syscall::data::TimeSpec; +use syscall::{Error as SyscallError, Result as SyscallResult}; use syscall; use device::NetworkDevice; -use super::Smolnetd; use port_set::PortSet; +use super::socket::{DupResult, SchemeFile, SchemeSocket, SocketFile, SocketScheme}; +use super::{parse_endpoint, Smolnetd, SocketSet}; pub type UdpScheme = SocketScheme>; -#[derive(Copy, Clone, Eq, PartialEq, Debug)] -pub enum Setting { - Ttl, - ReadTimeout, - WriteTimeout, -} - impl<'a, 'b> SchemeSocket for UdpSocket<'a, 'b> { type SchemeDataT = PortSet; type DataT = IpEndpoint; - type SettingT = Setting; + type SettingT = (); fn new_scheme_data() -> Self::SchemeDataT { PortSet::new(49_152u16, 65_535u16).expect("Wrong UDP port numbers") @@ -43,75 +29,33 @@ impl<'a, 'b> SchemeSocket for UdpSocket<'a, 'b> { } fn get_setting( - file: &SocketFile, - setting: Self::SettingT, - buf: &mut [u8], - ) -> syscall::Result { - let timespec = match (setting, file.read_timeout, file.write_timeout) { - (Setting::ReadTimeout, Some(read_timeout), _) => read_timeout, - (Setting::WriteTimeout, _, Some(write_timeout)) => write_timeout, - _ => { - return Ok(0); - } - }; - - if buf.len() < mem::size_of::() { - Ok(0) - } else { - let count = timespec.deref().read(buf).map_err(|err| { - syscall::Error::new(err.raw_os_error().unwrap_or(syscall::EIO)) - })?; - Ok(count) - } + _file: &SocketFile, + _setting: Self::SettingT, + _buf: &mut [u8], + ) -> SyscallResult { + Ok(0) } fn set_setting( - file: &mut SocketFile, - setting: Self::SettingT, - buf: &[u8], - ) -> syscall::Result { - match setting { - Setting::ReadTimeout | Setting::WriteTimeout => { - let (timeout, count) = { - if buf.len() < mem::size_of::() { - (None, 0) - } else { - let mut timespec = TimeSpec::default(); - let count = timespec.deref_mut().write(buf).map_err(|err| { - syscall::Error::new(err.raw_os_error().unwrap_or(syscall::EIO)) - })?; - (Some(timespec), count) - } - }; - trace!("Setting {:?} to {:?}", setting, timeout); - match setting { - Setting::ReadTimeout => { - file.read_timeout = timeout; - } - Setting::WriteTimeout => { - file.write_timeout = timeout; - } - _ => {} - }; - return Ok(count); - } - Setting::Ttl => {} - } + _file: &mut SocketFile, + _setting: Self::SettingT, + _buf: &[u8], + ) -> SyscallResult { Ok(0) } fn new_socket( - socket_set: &mut smoltcp::socket::SocketSet<'static, 'static, 'static>, + socket_set: &mut SocketSet, path: &str, uid: u32, port_set: &mut Self::SchemeDataT, - ) -> syscall::Result<(SocketHandle, Self::DataT)> { + ) -> SyscallResult<(SocketHandle, Self::DataT)> { let mut parts = path.split('/'); let remote_endpoint = parse_endpoint(parts.next().unwrap_or("")); let mut local_endpoint = parse_endpoint(parts.next().unwrap_or("")); if local_endpoint.port > 0 && local_endpoint.port <= 1024 && uid != 0 { - return Err(syscall::Error::new(syscall::EACCES)); + return Err(SyscallError::new(syscall::EACCES)); } let mut rx_packets = Vec::with_capacity(Smolnetd::SOCKET_BUFFER_SIZE); @@ -127,9 +71,9 @@ impl<'a, 'b> SchemeSocket for UdpSocket<'a, 'b> { if local_endpoint.port == 0 { local_endpoint.port = port_set .get_port() - .ok_or_else(|| syscall::Error::new(syscall::EINVAL))?; + .ok_or_else(|| SyscallError::new(syscall::EINVAL))?; } else if !port_set.claim_port(local_endpoint.port) { - return Err(syscall::Error::new(syscall::EADDRINUSE)); + return Err(SyscallError::new(syscall::EADDRINUSE)); } let socket_handle = socket_set.add(udp_socket); @@ -146,7 +90,7 @@ impl<'a, 'b> SchemeSocket for UdpSocket<'a, 'b> { &self, file: &SchemeFile, port_set: &mut Self::SchemeDataT, - ) -> syscall::Result<()> { + ) -> SyscallResult<()> { if let SchemeFile::Socket(_) = *file { port_set.release_port(self.endpoint().port); } @@ -157,9 +101,9 @@ impl<'a, 'b> SchemeSocket for UdpSocket<'a, 'b> { &mut self, file: &mut SocketFile, buf: &[u8], - ) -> syscall::Result { + ) -> SyscallResult { if !file.data.is_specified() { - return Err(syscall::Error::new(syscall::EADDRNOTAVAIL)); + return Err(SyscallError::new(syscall::EADDRNOTAVAIL)); } if self.can_send() { self.send_slice(buf, file.data).expect("Can't send slice"); @@ -167,7 +111,7 @@ impl<'a, 'b> SchemeSocket for UdpSocket<'a, 'b> { } else if file.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { Ok(0) } else { - Err(syscall::Error::new(syscall::EWOULDBLOCK)) + Err(SyscallError::new(syscall::EWOULDBLOCK)) } } @@ -175,41 +119,25 @@ impl<'a, 'b> SchemeSocket for UdpSocket<'a, 'b> { &mut self, file: &mut SocketFile, buf: &mut [u8], - ) -> syscall::Result { + ) -> SyscallResult { if self.can_recv() { let (length, _) = self.recv_slice(buf).expect("Can't receive slice"); Ok(length) } else if file.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { Ok(0) } else { - Err(syscall::Error::new(syscall::EWOULDBLOCK)) + Err(SyscallError::new(syscall::EWOULDBLOCK)) } } fn dup( - socket_set: &mut smoltcp::socket::SocketSet, - socket_handle: SocketHandle, + socket_set: &mut SocketSet, file: &mut SchemeFile, - fd: usize, path: &str, port_set: &mut Self::SchemeDataT, - ) -> syscall::Result> { - let handle = match path { - "ttl" => SchemeFile::Setting(SettingFile { - socket_handle, - fd, - setting: Setting::Ttl, - }), - "read_timeout" => SchemeFile::Setting(SettingFile { - socket_handle, - fd, - setting: Setting::ReadTimeout, - }), - "write_timeout" => SchemeFile::Setting(SettingFile { - socket_handle, - fd, - setting: Setting::WriteTimeout, - }), + ) -> SyscallResult> { + let socket_handle = file.socket_handle(); + let file = match path { _ => { let remote_endpoint = parse_endpoint(path); if let SchemeFile::Socket(ref udp_handle) = *file { @@ -231,15 +159,15 @@ impl<'a, 'b> SchemeSocket for UdpSocket<'a, 'b> { socket.endpoint() }; - if let SchemeFile::Socket(_) = handle { + if let SchemeFile::Socket(_) = file { port_set.acquire_port(endpoint.port); } - Ok((handle, None)) + Ok((file, None)) } - fn fpath(&self, file: &SchemeFile, buf: &mut [u8]) -> syscall::Result { - if let &SchemeFile::Socket(ref socket_file) = file { + fn fpath(&self, file: &SchemeFile, buf: &mut [u8]) -> SyscallResult { + if let SchemeFile::Socket(ref socket_file) = *file { let path = format!("udp:{}/{}", socket_file.data, self.endpoint()); let path = path.as_bytes(); @@ -251,22 +179,7 @@ impl<'a, 'b> SchemeSocket for UdpSocket<'a, 'b> { Ok(i) } else { - Err(syscall::Error::new(syscall::EBADF)) + Err(SyscallError::new(syscall::EBADF)) } } } - -fn parse_endpoint(socket: &str) -> IpEndpoint { - let mut socket_parts = socket.split(':'); - let host = IpAddress::Ipv4( - Ipv4Address::from_str(socket_parts.next().unwrap_or("")) - .unwrap_or_else(|_| Ipv4Address::new(0, 0, 0, 0)), - ); - - let port = socket_parts - .next() - .unwrap_or("") - .parse::() - .unwrap_or(0); - IpEndpoint::new(host, port) -} From bc6d234bd03a9fcd3173a3c028b15b3635683ddc Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Mon, 9 Oct 2017 20:49:23 -0600 Subject: [PATCH 048/155] Utilize null namespace --- src/smolnetd/main.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/smolnetd/main.rs b/src/smolnetd/main.rs index 2ac8cc8095..d961fd794e 100644 --- a/src/smolnetd/main.rs +++ b/src/smolnetd/main.rs @@ -70,6 +70,8 @@ fn run() -> Result<()> { let mut event_queue = EventQueue::<(), Error>::new() .map_err(|e| Error::from_io_error(e, "failed to create event queue"))?; + syscall::setrens(0, 0).expect("smolnetd: failed to enter null namespace"); + let smolnetd_ = Rc::clone(&smolnetd); event_queue From 7f7109b218556ac1523e04f6a3f93dd557ca7f70 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Wed, 11 Oct 2017 20:54:45 -0600 Subject: [PATCH 049/155] Update Cargo.lock --- Cargo.lock | 82 ++++++++++++++++++++++-------------------------------- 1 file changed, 33 insertions(+), 49 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bc0ed2071e..9591875b51 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,7 +4,7 @@ version = "0.1.0" dependencies = [ "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "netutils 0.1.0 (git+https://github.com/redox-os/netutils.git)", - "rand 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)", "redox_event 0.1.0 (git+https://github.com/redox-os/event.git)", "redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", "smoltcp 0.4.0 (git+https://github.com/m-labs/smoltcp.git)", @@ -48,19 +48,6 @@ dependencies = [ "scopeguard 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "conv" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "custom_derive 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "custom_derive" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "either" version = "1.2.0" @@ -71,6 +58,22 @@ name = "extra" version = "0.1.0" source = "git+https://github.com/redox-os/libextra.git#402932084acd5fef4812945887ceaaa2ddd5f264" +[[package]] +name = "fuchsia-zircon" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "fuchsia-zircon-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "fuchsia-zircon-sys" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "futures" version = "0.1.16" @@ -145,7 +148,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libc" -version = "0.2.31" +version = "0.2.32" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -153,23 +156,6 @@ name = "log" version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "magenta" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "conv 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "magenta-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "magenta-sys" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "managed" version = "0.4.0" @@ -197,7 +183,7 @@ dependencies = [ "extra 0.1.0 (git+https://github.com/redox-os/libextra.git)", "hyper 0.10.13 (registry+https://github.com/rust-lang/crates.io-index)", "hyper-rustls 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", "ntpclient 0.0.1 (git+https://github.com/willem66745/ntpclient-rust)", "pbr 1.0.0 (git+https://github.com/a8m/pb)", "redox_event 0.1.0 (git+https://github.com/redox-os/event.git)", @@ -219,7 +205,7 @@ name = "num_cpus" version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -228,7 +214,7 @@ version = "1.0.0" source = "git+https://github.com/a8m/pb#e9369ed2b94df4f554fe79c2643de41f7338475f" dependencies = [ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -241,11 +227,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "rand" -version = "0.3.16" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)", - "magenta 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "fuchsia-zircon 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -264,9 +250,9 @@ dependencies = [ "coco 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -297,7 +283,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -340,7 +326,7 @@ name = "termion" version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -351,7 +337,7 @@ version = "0.1.38" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -443,10 +429,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855" "checksum byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff81738b726f5d099632ceaffe7fb65b90212e8dce59d518729e7e8634032d3d" "checksum coco 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c06169f5beb7e31c7c67ebf5540b8b472d23e3eade3b2ec7d1f5b504a85f91bd" -"checksum conv 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "78ff10625fd0ac447827aa30ea8b861fead473bb60aeb73af6c1c58caf0d1299" -"checksum custom_derive 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "ef8ae57c4978a2acd8b869ce6b9ca1dfe817bff704c220209fdef2c0b75a01b9" "checksum either 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cbee135e9245416869bf52bd6ccc9b59e2482651510784e089b874272f02a252" "checksum extra 0.1.0 (git+https://github.com/redox-os/libextra.git)" = "" +"checksum fuchsia-zircon 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f6c0581a4e363262e52b87f59ee2afe3415361c6ec35e665924eb08afe8ff159" +"checksum fuchsia-zircon-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "43f3795b4bae048dc6123a6b972cadde2e676f9ded08aef6bb77f5f157684a82" "checksum futures 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "05a23db7bd162d4e8265968602930c476f688f0c180b44bdaf55e0cb2c687558" "checksum gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)" = "5e33ec290da0d127825013597dbdfc28bee4964690c7ce1166cbc2a7bd08b1bb" "checksum httparse 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "af2f2dd97457e8fb1ae7c5a420db346af389926e36f43768b96f101546b04a07" @@ -456,10 +442,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a" "checksum lazy_static 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c9e5e58fa1a4c3b915a561a78a22ee0cac6ab97dca2504428bc1cb074375f8d5" -"checksum libc 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)" = "d1419b2939a0bc44b77feb34661583c7546b532b192feab36249ab584b86856c" +"checksum libc 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)" = "56cce3130fd040c28df6f495c8492e5ec5808fb4c9093c310df02b0c8f030148" "checksum log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "880f77541efa6e5cc74e76910c9884d9859683118839d6a1dc3b11e63512565b" -"checksum magenta 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4bf0336886480e671965f794bc9b6fce88503563013d1bfb7a502c81fe3ac527" -"checksum magenta-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "40d014c7011ac470ae28e2f76a02bfea4a8480f73e701353b49ad7a8d75f4699" "checksum managed 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b5d48e8c30a4363e2981fe4db20527f6ab0f32a243bbc75379dea5a64f60dae4" "checksum matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "100aabe6b8ff4e4a7e32c1c13523379802df0772b82466207ac25b013f193376" "checksum mime 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ba626b8a6de5da682e1caa06bdb42a335aee5a84db8e5046a3e8ab17ba0a3ae0" @@ -468,7 +452,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum num_cpus 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "514f0d73e64be53ff320680ca671b64fe3fb91da01e1ae2ddc99eb51d453b20d" "checksum pbr 1.0.0 (git+https://github.com/a8m/pb)" = "" "checksum percent-encoding 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "de154f638187706bde41d9b4738748933d64e6b37bdbffc0b47a97d16a6ae356" -"checksum rand 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)" = "eb250fd207a4729c976794d03db689c9be1d634ab5a1c9da9492a13d8fecbcdf" +"checksum rand 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)" = "61efcbcd9fa8d8fbb07c84e34a8af18a1ff177b449689ad38a6e9457ecc7b2ae" "checksum rayon 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a77c51c07654ddd93f6cb543c7a849863b03abc7e82591afda6dc8ad4ac3ac4a" "checksum rayon-core 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7febc28567082c345f10cddc3612c6ea020fc3297a1977d472cf9fdb73e6e493" "checksum redox_event 0.1.0 (git+https://github.com/redox-os/event.git)" = "" From b54ead7d773c5737b928ab43db8ff07366f6e81b Mon Sep 17 00:00:00 2001 From: Egor Karavaev Date: Tue, 24 Oct 2017 22:23:03 +0300 Subject: [PATCH 050/155] Support for loopback interface. --- src/smolnetd/arp_cache.rs | 45 +++++++++++++++++++++++++++++++++++++ src/smolnetd/buffer_pool.rs | 21 ++++++++++++----- src/smolnetd/device.rs | 36 +++++++++++++++++++++++++---- src/smolnetd/main.rs | 1 + src/smolnetd/scheme/mod.rs | 28 ++++++++++++++++------- 5 files changed, 113 insertions(+), 18 deletions(-) create mode 100644 src/smolnetd/arp_cache.rs diff --git a/src/smolnetd/arp_cache.rs b/src/smolnetd/arp_cache.rs new file mode 100644 index 0000000000..2585c75e41 --- /dev/null +++ b/src/smolnetd/arp_cache.rs @@ -0,0 +1,45 @@ +use smoltcp::iface::{ArpCache, SliceArpCache}; +use smoltcp::wire::{EthernetAddress, IpAddress}; +use std::collections::BTreeSet; +use std::iter::FromIterator; + +//TODO: move to EthernetAddress::LOCAL (?) +pub const LOOPBACK_HWADDR: EthernetAddress = EthernetAddress([0; 6]); + +pub struct LoArpCache { + arp_cache: SliceArpCache<'static>, + local_ips: BTreeSet, +} + +impl LoArpCache { + pub fn new(local_ips: I) -> LoArpCache + where + I: IntoIterator, + { + LoArpCache { + arp_cache: SliceArpCache::new(vec![Default::default(); 16]), + local_ips: BTreeSet::from_iter(local_ips), + } + } +} + +impl ArpCache for LoArpCache { + fn fill(&mut self, protocol_addr: &IpAddress, hardware_addr: &EthernetAddress) { + self.arp_cache.fill(protocol_addr, hardware_addr) + } + + fn lookup(&mut self, protocol_addr: &IpAddress) -> Option { + //TODO: use IpAddress::is_loopback + if let &IpAddress::Ipv4(ipv4_addr) = protocol_addr { + if ipv4_addr.is_loopback() { + return Some(LOOPBACK_HWADDR); + } + } + + if self.local_ips.contains(protocol_addr) { + return Some(LOOPBACK_HWADDR); + } + + self.arp_cache.lookup(protocol_addr) + } +} diff --git a/src/smolnetd/buffer_pool.rs b/src/smolnetd/buffer_pool.rs index c96baea781..790c3e7995 100644 --- a/src/smolnetd/buffer_pool.rs +++ b/src/smolnetd/buffer_pool.rs @@ -1,7 +1,7 @@ use std::ops::{Deref, DerefMut, Drop}; use std::rc::Rc; use std::cell::RefCell; -use std::mem::swap; +use std::mem::{replace, swap}; type BufferStack = Rc>>>; @@ -14,6 +14,13 @@ impl Buffer { pub fn resize(&mut self, new_len: usize) { self.buffer.resize(new_len, 0u8); } + + pub fn move_out(&mut self) -> Buffer { + Buffer { + buffer: replace(&mut self.buffer, vec![]), + stack: self.stack.clone(), + } + } } impl AsRef<[u8]> for Buffer { @@ -44,11 +51,13 @@ impl DerefMut for Buffer { impl Drop for Buffer { fn drop(&mut self) { - let mut tmp = vec![]; - swap(&mut tmp, &mut self.buffer); - { - let mut stack = self.stack.borrow_mut(); - stack.push(tmp); + if self.buffer.capacity() > 0 { + let mut tmp = vec![]; + swap(&mut tmp, &mut self.buffer); + { + let mut stack = self.stack.borrow_mut(); + stack.push(tmp); + } } } } diff --git a/src/smolnetd/device.rs b/src/smolnetd/device.rs index a572c56ef6..a62d3741b1 100644 --- a/src/smolnetd/device.rs +++ b/src/smolnetd/device.rs @@ -5,11 +5,14 @@ use std::fs::File; use std::io::Write; use std::rc::Rc; -use buffer_pool::Buffer; +use buffer_pool::{Buffer, BufferPool}; +use arp_cache::LOOPBACK_HWADDR; pub struct NetworkDevice { network_file: Rc>, input_queue: Rc>>, + local_hwaddr: smoltcp::wire::EthernetAddress, + buffer_pool: Rc>, } impl NetworkDevice { @@ -18,17 +21,23 @@ impl NetworkDevice { pub fn new( network_file: Rc>, input_queue: Rc>>, + local_hwaddr: smoltcp::wire::EthernetAddress, + buffer_pool: Rc>, ) -> NetworkDevice { NetworkDevice { network_file, input_queue, + local_hwaddr, + buffer_pool, } } } pub struct TxBuffer { - buffer: Vec, + buffer: Buffer, network_file: Rc>, + input_queue: Rc>>, + local_hwaddr: smoltcp::wire::EthernetAddress, } impl AsRef<[u8]> for TxBuffer { @@ -45,7 +54,22 @@ impl AsMut<[u8]> for TxBuffer { impl Drop for TxBuffer { fn drop(&mut self) { - let _ = self.network_file.borrow_mut().write(&self.buffer); + let mut loopback = false; + + if let Ok(mut frame) = smoltcp::wire::EthernetFrame::new_checked(&mut self.buffer) { + if frame.dst_addr() == LOOPBACK_HWADDR { + frame.set_dst_addr(self.local_hwaddr); + loopback = true; + } + } + + if loopback { + self.input_queue + .borrow_mut() + .push_back(self.buffer.move_out()); + } else { + let _ = self.network_file.borrow_mut().write(&self.buffer); + } } } @@ -68,9 +92,13 @@ impl smoltcp::phy::Device for NetworkDevice { } fn transmit(&mut self, _timestamp: u64, length: usize) -> smoltcp::Result { + let mut buffer = self.buffer_pool.borrow_mut().get_buffer(); + buffer.resize(length); Ok(TxBuffer { network_file: Rc::clone(&self.network_file), - buffer: vec![0; length], + buffer, + input_queue: Rc::clone(&self.input_queue), + local_hwaddr: self.local_hwaddr, }) } } diff --git a/src/smolnetd/main.rs b/src/smolnetd/main.rs index 3ff7a568cd..e6f2131a4c 100644 --- a/src/smolnetd/main.rs +++ b/src/smolnetd/main.rs @@ -23,6 +23,7 @@ mod error; mod logger; mod port_set; mod scheme; +mod arp_cache; fn run() -> Result<()> { use syscall::flag::*; diff --git a/src/smolnetd/scheme/mod.rs b/src/smolnetd/scheme/mod.rs index a65296521b..ff6de1df43 100644 --- a/src/smolnetd/scheme/mod.rs +++ b/src/smolnetd/scheme/mod.rs @@ -1,5 +1,5 @@ use netutils::getcfg; -use smoltcp::iface::{ArpCache, EthernetInterface, SliceArpCache}; +use smoltcp::iface::{ArpCache, EthernetInterface}; use smoltcp::socket::SocketSet as SmoltcpSocketSet; use smoltcp::wire::{EthernetAddress, IpAddress, IpCidr, IpEndpoint, Ipv4Address}; use std::cell::RefCell; @@ -16,6 +16,7 @@ use syscall; use buffer_pool::{Buffer, BufferPool}; use device::NetworkDevice; use error::{Error, Result}; +use arp_cache::LoArpCache; use self::ip::IpScheme; use self::tcp::TcpScheme; use self::udp::UdpScheme; @@ -41,11 +42,11 @@ pub struct Smolnetd { tcp_scheme: TcpScheme, input_queue: Rc>>, - input_buffer_pool: BufferPool, + buffer_pool: Rc>, } impl Smolnetd { - const INGRESS_PACKET_SIZE: usize = 2048; + const MAX_PACKET_SIZE: usize = 2048; const SOCKET_BUFFER_SIZE: usize = 128; //packets const MIN_CHECK_TIMEOUT_MS: i64 = 10; const MAX_CHECK_TIMEOUT_MS: i64 = 500; @@ -57,17 +58,28 @@ impl Smolnetd { tcp_file: File, time_file: File, ) -> Smolnetd { - let arp_cache = SliceArpCache::new(vec![Default::default(); 8]); let hardware_addr = EthernetAddress::from_str(getcfg("mac").unwrap().trim()) .expect("Can't parse the 'mac' cfg"); let local_ip = IpAddress::from_str(getcfg("ip").unwrap().trim()).expect("Can't parse the 'ip' cfg."); - let protocol_addrs = [IpCidr::new(local_ip, 24)]; + let protocol_addrs = [ + IpCidr::new(local_ip, 24), + IpCidr::new(IpAddress::v4(127, 0, 0, 1), 8), + ]; let default_gw = Ipv4Address::from_str(getcfg("ip_router").unwrap().trim()) .expect("Can't parse the 'ip_router' cfg."); + + + let buffer_pool = Rc::new(RefCell::new(BufferPool::new(Self::MAX_PACKET_SIZE))); let input_queue = Rc::new(RefCell::new(VecDeque::new())); let network_file = Rc::new(RefCell::new(network_file)); - let network_device = NetworkDevice::new(Rc::clone(&network_file), Rc::clone(&input_queue)); + let network_device = NetworkDevice::new( + Rc::clone(&network_file), + Rc::clone(&input_queue), + hardware_addr, + buffer_pool.clone(), + ); + let arp_cache = LoArpCache::new(protocol_addrs.iter().map(IpCidr::address)); let iface = EthernetInterface::new( Box::new(network_device), Box::new(arp_cache) as Box, @@ -86,7 +98,7 @@ impl Smolnetd { tcp_scheme: TcpScheme::new(Rc::clone(&socket_set), tcp_file), input_queue, network_file, - input_buffer_pool: BufferPool::new(Self::INGRESS_PACKET_SIZE), + buffer_pool, } } @@ -173,7 +185,7 @@ impl Smolnetd { fn read_frames(&mut self) -> Result { let mut total_frames = 0; loop { - let mut buffer = self.input_buffer_pool.get_buffer(); + let mut buffer = self.buffer_pool.borrow_mut().get_buffer(); let count = self.network_file .borrow_mut() .read(&mut buffer) From 077673d9e5e65b37f0f9e15e12005f381f306744 Mon Sep 17 00:00:00 2001 From: Egor Karavaev Date: Wed, 25 Oct 2017 21:18:24 +0300 Subject: [PATCH 051/155] Update smoltcp. --- Cargo.lock | 20 ++++++------ Cargo.toml | 2 +- src/smolnetd/arp_cache.rs | 2 +- src/smolnetd/buffer_pool.rs | 2 +- src/smolnetd/scheme/ip.rs | 7 ++++ src/smolnetd/scheme/mod.rs | 2 +- src/smolnetd/scheme/socket.rs | 60 +++++++++++++++++++++++++---------- src/smolnetd/scheme/tcp.rs | 8 +++++ src/smolnetd/scheme/udp.rs | 8 +++++ 9 files changed, 80 insertions(+), 31 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9591875b51..019cc2f008 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13,7 +13,7 @@ dependencies = [ [[package]] name = "arg_parser" version = "0.1.0" -source = "git+https://github.com/redox-os/arg-parser.git#288d2fd9ae27ed2c7a3aaf5a77cf07e2b2bd356c" +source = "git+https://github.com/redox-os/arg-parser.git#d16e2d02e87996bbe2bce4a201c66c0df4a1e866" [[package]] name = "base64" @@ -44,13 +44,13 @@ name = "coco" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "either 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "scopeguard 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "either 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "either" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -177,7 +177,7 @@ dependencies = [ [[package]] name = "netutils" version = "0.1.0" -source = "git+https://github.com/redox-os/netutils.git#29b8efd41d8c56b33c619db78e5b019934dbb7a3" +source = "git+https://github.com/redox-os/netutils.git#2c082a38814922125ca402103a1a50d5531f6330" dependencies = [ "arg_parser 0.1.0 (git+https://github.com/redox-os/arg-parser.git)", "extra 0.1.0 (git+https://github.com/redox-os/libextra.git)", @@ -258,7 +258,7 @@ dependencies = [ [[package]] name = "redox_event" version = "0.1.0" -source = "git+https://github.com/redox-os/event.git#42d552e4765efbfb4ec39ce174900d3f48548a70" +source = "git+https://github.com/redox-os/event.git#bb96d9cd6dd01d4118deae84722a522b8328fa9f" dependencies = [ "redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -308,13 +308,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "scopeguard" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "smoltcp" version = "0.4.0" -source = "git+https://github.com/m-labs/smoltcp.git#096ce02ac4c935c4df485a79107fb26b5897065d" +source = "git+https://github.com/m-labs/smoltcp.git#f64a99a4e6d744c3a6f3d9a54a0fb3f94e4b0ec8" dependencies = [ "byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -429,7 +429,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855" "checksum byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff81738b726f5d099632ceaffe7fb65b90212e8dce59d518729e7e8634032d3d" "checksum coco 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c06169f5beb7e31c7c67ebf5540b8b472d23e3eade3b2ec7d1f5b504a85f91bd" -"checksum either 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cbee135e9245416869bf52bd6ccc9b59e2482651510784e089b874272f02a252" +"checksum either 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e311a7479512fbdf858fb54d91ec59f3b9f85bc0113659f46bba12b199d273ce" "checksum extra 0.1.0 (git+https://github.com/redox-os/libextra.git)" = "" "checksum fuchsia-zircon 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f6c0581a4e363262e52b87f59ee2afe3415361c6ec35e665924eb08afe8ff159" "checksum fuchsia-zircon-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "43f3795b4bae048dc6123a6b972cadde2e676f9ded08aef6bb77f5f157684a82" @@ -461,7 +461,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum ring 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1f2a6dc7fc06a05e6de183c5b97058582e9da2de0c136eafe49609769c507724" "checksum rustls 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "17727f4b991294da2c84d75a43c003151ff58072212768800f66c56ee46dca43" "checksum safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e27a8b19b835f7aea908818e871f5cc3a5a186550c30773be987e155e8163d8f" -"checksum scopeguard 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c79eb2c3ac4bc2507cda80e7f3ac5b88bd8eae4c0914d5663e6a8933994be918" +"checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" "checksum smoltcp 0.4.0 (git+https://github.com/m-labs/smoltcp.git)" = "" "checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" "checksum time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)" = "d5d788d3aa77bc0ef3e9621256885555368b47bd495c13dd2e7413c89f845520" diff --git a/Cargo.toml b/Cargo.toml index ba9b58d6eb..f838a1c8b0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,4 +40,4 @@ features = ["release_max_level_off"] [dependencies.smoltcp] git = "https://github.com/m-labs/smoltcp.git" default-features = false -features = ["std", "log", "socket-raw", "socket-udp", "socket-tcp"] +features = ["std", "log", "proto-raw", "proto-udp", "proto-tcp"] diff --git a/src/smolnetd/arp_cache.rs b/src/smolnetd/arp_cache.rs index 2585c75e41..d546b439ad 100644 --- a/src/smolnetd/arp_cache.rs +++ b/src/smolnetd/arp_cache.rs @@ -30,7 +30,7 @@ impl ArpCache for LoArpCache { fn lookup(&mut self, protocol_addr: &IpAddress) -> Option { //TODO: use IpAddress::is_loopback - if let &IpAddress::Ipv4(ipv4_addr) = protocol_addr { + if let IpAddress::Ipv4(ipv4_addr) = *protocol_addr { if ipv4_addr.is_loopback() { return Some(LOOPBACK_HWADDR); } diff --git a/src/smolnetd/buffer_pool.rs b/src/smolnetd/buffer_pool.rs index 790c3e7995..38f971bd7f 100644 --- a/src/smolnetd/buffer_pool.rs +++ b/src/smolnetd/buffer_pool.rs @@ -18,7 +18,7 @@ impl Buffer { pub fn move_out(&mut self) -> Buffer { Buffer { buffer: replace(&mut self.buffer, vec![]), - stack: self.stack.clone(), + stack: Rc::clone(&self.stack), } } } diff --git a/src/smolnetd/scheme/ip.rs b/src/smolnetd/scheme/ip.rs index be014679a4..0fcbe07ef0 100644 --- a/src/smolnetd/scheme/ip.rs +++ b/src/smolnetd/scheme/ip.rs @@ -43,6 +43,13 @@ impl<'a, 'b> SchemeSocket for RawSocket<'a, 'b> { Ok(0) } + fn ttl(&self) -> u8 { + 0 + } + + fn set_ttl(&mut self, _ttl: u8) { + } + fn new_socket( socket_set: &mut SocketSet, path: &str, diff --git a/src/smolnetd/scheme/mod.rs b/src/smolnetd/scheme/mod.rs index ff6de1df43..de6787519f 100644 --- a/src/smolnetd/scheme/mod.rs +++ b/src/smolnetd/scheme/mod.rs @@ -77,7 +77,7 @@ impl Smolnetd { Rc::clone(&network_file), Rc::clone(&input_queue), hardware_addr, - buffer_pool.clone(), + Rc::clone(&buffer_pool), ); let arp_cache = LoArpCache::new(protocol_addrs.iter().map(IpCidr::address)); let iface = EthernetInterface::new( diff --git a/src/smolnetd/scheme/socket.rs b/src/smolnetd/scheme/socket.rs index b36af6e1d7..5d312be188 100644 --- a/src/smolnetd/scheme/socket.rs +++ b/src/smolnetd/scheme/socket.rs @@ -112,6 +112,9 @@ where fn can_send(&self) -> bool; fn can_recv(&self) -> bool; + fn ttl(&self) -> u8; + fn set_ttl(&mut self, u8); + fn get_setting(&SocketFile, Self::SettingT, &mut [u8]) -> SyscallResult; fn set_setting(&mut SocketFile, Self::SettingT, &[u8]) -> SyscallResult; @@ -362,24 +365,38 @@ where } }; - if let Setting::Other(setting) = setting { - SocketT::get_setting(file, setting, buf) - } else { - let timespec = match (setting, file.read_timeout, file.write_timeout) { - (Setting::ReadTimeout, Some(read_timeout), _) => read_timeout, - (Setting::WriteTimeout, _, Some(write_timeout)) => write_timeout, - _ => { - return Ok(0); + match setting { + Setting::Other(setting) => { + SocketT::get_setting(file, setting, buf) + }, + Setting::Ttl => { + if let Some(ttl) = buf.get_mut(0) { + let mut socket_set = self.socket_set.borrow_mut(); + let socket = socket_set.get::(file.socket_handle); + *ttl = socket.ttl(); + Ok(1) + } else { + Err(SyscallError::new(syscall::EIO)) } - }; + }, + Setting::ReadTimeout | + Setting::WriteTimeout => { + let timespec = match (setting, file.read_timeout, file.write_timeout) { + (Setting::ReadTimeout, Some(read_timeout), _) => read_timeout, + (Setting::WriteTimeout, _, Some(write_timeout)) => write_timeout, + _ => { + return Ok(0); + } + }; - if buf.len() < mem::size_of::() { - Ok(0) - } else { - let count = timespec.deref().read(buf).map_err(|err| { - SyscallError::new(err.raw_os_error().unwrap_or(syscall::EIO)) - })?; - Ok(count) + if buf.len() < mem::size_of::() { + Ok(0) + } else { + let count = timespec.deref().read(buf).map_err(|err| { + SyscallError::new(err.raw_os_error().unwrap_or(syscall::EIO)) + })?; + Ok(count) + } } } } @@ -423,7 +440,16 @@ where }; Ok(count) } - Setting::Ttl => Ok(0), + Setting::Ttl => { + if let Some(ttl) = buf.get(0) { + let mut socket_set = self.socket_set.borrow_mut(); + let mut socket = socket_set.get::(file.socket_handle); + socket.set_ttl(*ttl); + Ok(1) + } else { + Err(SyscallError::new(syscall::EIO)) + } + } Setting::Other(setting) => SocketT::set_setting(file, setting, buf), } } diff --git a/src/smolnetd/scheme/tcp.rs b/src/smolnetd/scheme/tcp.rs index 1ce10f3020..195525689a 100644 --- a/src/smolnetd/scheme/tcp.rs +++ b/src/smolnetd/scheme/tcp.rs @@ -26,6 +26,14 @@ impl<'a> SchemeSocket for TcpSocket<'a> { self.can_recv() } + fn ttl(&self) -> u8 { + self.ttl().unwrap_or(64) + } + + fn set_ttl(&mut self, ttl: u8) { + self.set_ttl(Some(ttl)); + } + fn get_setting( _file: &SocketFile, _setting: Self::SettingT, diff --git a/src/smolnetd/scheme/udp.rs b/src/smolnetd/scheme/udp.rs index 87f65b9bdb..9227bb4f77 100644 --- a/src/smolnetd/scheme/udp.rs +++ b/src/smolnetd/scheme/udp.rs @@ -28,6 +28,14 @@ impl<'a, 'b> SchemeSocket for UdpSocket<'a, 'b> { self.can_recv() } + fn ttl(&self) -> u8 { + self.ttl().unwrap_or(64) + } + + fn set_ttl(&mut self, ttl: u8) { + self.set_ttl(Some(ttl)); + } + fn get_setting( _file: &SocketFile, _setting: Self::SettingT, From 29e3c38c1dc8e5d9e3a403a58c690ffbc88df329 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sun, 29 Oct 2017 20:39:53 -0600 Subject: [PATCH 052/155] Remove old schemes, use patched smoltcp, remove log feature --- Cargo.lock | 51 +- Cargo.toml | 20 +- src/ethernetd/main.rs | 112 ---- src/ethernetd/scheme.rs | 169 ------ src/ipd/interface/ethernet.rs | 155 ------ src/ipd/interface/loopback.rs | 50 -- src/ipd/interface/mod.rs | 19 - src/ipd/main.rs | 348 ------------ src/tcpd/main.rs | 982 ---------------------------------- src/udpd/main.rs | 588 -------------------- 10 files changed, 27 insertions(+), 2467 deletions(-) delete mode 100644 src/ethernetd/main.rs delete mode 100644 src/ethernetd/scheme.rs delete mode 100644 src/ipd/interface/ethernet.rs delete mode 100644 src/ipd/interface/loopback.rs delete mode 100644 src/ipd/interface/mod.rs delete mode 100644 src/ipd/main.rs delete mode 100644 src/tcpd/main.rs delete mode 100644 src/udpd/main.rs diff --git a/Cargo.lock b/Cargo.lock index 019cc2f008..cbb61bcc90 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,15 +1,3 @@ -[root] -name = "redox_netstack" -version = "0.1.0" -dependencies = [ - "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", - "netutils 0.1.0 (git+https://github.com/redox-os/netutils.git)", - "rand 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_event 0.1.0 (git+https://github.com/redox-os/event.git)", - "redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", - "smoltcp 0.4.0 (git+https://github.com/m-labs/smoltcp.git)", -] - [[package]] name = "arg_parser" version = "0.1.0" @@ -148,7 +136,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libc" -version = "0.2.32" +version = "0.2.33" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -177,13 +165,13 @@ dependencies = [ [[package]] name = "netutils" version = "0.1.0" -source = "git+https://github.com/redox-os/netutils.git#2c082a38814922125ca402103a1a50d5531f6330" +source = "git+https://github.com/redox-os/netutils.git#a719fa50b065840ffacc81d989e47f258b3e5170" dependencies = [ "arg_parser 0.1.0 (git+https://github.com/redox-os/arg-parser.git)", "extra 0.1.0 (git+https://github.com/redox-os/libextra.git)", "hyper 0.10.13 (registry+https://github.com/rust-lang/crates.io-index)", "hyper-rustls 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", "ntpclient 0.0.1 (git+https://github.com/willem66745/ntpclient-rust)", "pbr 1.0.0 (git+https://github.com/a8m/pb)", "redox_event 0.1.0 (git+https://github.com/redox-os/event.git)", @@ -205,7 +193,7 @@ name = "num_cpus" version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -214,7 +202,7 @@ version = "1.0.0" source = "git+https://github.com/a8m/pb#e9369ed2b94df4f554fe79c2643de41f7338475f" dependencies = [ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -231,7 +219,7 @@ version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "fuchsia-zircon 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -250,7 +238,7 @@ dependencies = [ "coco 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -263,6 +251,18 @@ dependencies = [ "redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "redox_netstack" +version = "0.1.0" +dependencies = [ + "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "netutils 0.1.0 (git+https://github.com/redox-os/netutils.git)", + "rand 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_event 0.1.0 (git+https://github.com/redox-os/event.git)", + "redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", + "smoltcp 0.4.0 (git+https://github.com/redox-os/smoltcp.git)", +] + [[package]] name = "redox_syscall" version = "0.1.31" @@ -283,7 +283,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -314,10 +314,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "smoltcp" version = "0.4.0" -source = "git+https://github.com/m-labs/smoltcp.git#f64a99a4e6d744c3a6f3d9a54a0fb3f94e4b0ec8" +source = "git+https://github.com/redox-os/smoltcp.git#a6fc036ad65e07523e271304bb96d99a9f9a2707" dependencies = [ "byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "managed 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -326,7 +325,7 @@ name = "termion" version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -337,7 +336,7 @@ version = "0.1.38" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -442,7 +441,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a" "checksum lazy_static 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c9e5e58fa1a4c3b915a561a78a22ee0cac6ab97dca2504428bc1cb074375f8d5" -"checksum libc 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)" = "56cce3130fd040c28df6f495c8492e5ec5808fb4c9093c310df02b0c8f030148" +"checksum libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "5ba3df4dcb460b9dfbd070d41c94c19209620c191b0340b929ce748a2bcd42d2" "checksum log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "880f77541efa6e5cc74e76910c9884d9859683118839d6a1dc3b11e63512565b" "checksum managed 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b5d48e8c30a4363e2981fe4db20527f6ab0f32a243bbc75379dea5a64f60dae4" "checksum matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "100aabe6b8ff4e4a7e32c1c13523379802df0772b82466207ac25b013f193376" @@ -462,7 +461,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum rustls 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "17727f4b991294da2c84d75a43c003151ff58072212768800f66c56ee46dca43" "checksum safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e27a8b19b835f7aea908818e871f5cc3a5a186550c30773be987e155e8163d8f" "checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" -"checksum smoltcp 0.4.0 (git+https://github.com/m-labs/smoltcp.git)" = "" +"checksum smoltcp 0.4.0 (git+https://github.com/redox-os/smoltcp.git)" = "" "checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" "checksum time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)" = "d5d788d3aa77bc0ef3e9621256885555368b47bd495c13dd2e7413c89f845520" "checksum traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079" diff --git a/Cargo.toml b/Cargo.toml index f838a1c8b0..1b5fa8329e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,22 +2,6 @@ name = "redox_netstack" version = "0.1.0" -[[bin]] -name = "ethernetd" -path = "src/ethernetd/main.rs" - -[[bin]] -name = "ipd" -path = "src/ipd/main.rs" - -[[bin]] -name = "tcpd" -path = "src/tcpd/main.rs" - -[[bin]] -name = "udpd" -path = "src/udpd/main.rs" - [[bin]] name = "icmpd" path = "src/icmpd/main.rs" @@ -38,6 +22,6 @@ default-features = false features = ["release_max_level_off"] [dependencies.smoltcp] -git = "https://github.com/m-labs/smoltcp.git" +git = "https://github.com/redox-os/smoltcp.git" default-features = false -features = ["std", "log", "proto-raw", "proto-udp", "proto-tcp"] +features = ["std", "proto-raw", "proto-udp", "proto-tcp"] diff --git a/src/ethernetd/main.rs b/src/ethernetd/main.rs deleted file mode 100644 index c6e6efa008..0000000000 --- a/src/ethernetd/main.rs +++ /dev/null @@ -1,112 +0,0 @@ -extern crate event; -extern crate netutils; -extern crate syscall; - -use event::EventQueue; -use std::cell::RefCell; -use std::fs::File; -use std::io::{Result, Read, Write}; -use std::os::unix::io::{RawFd, FromRawFd}; -use std::process; -use std::rc::Rc; - -use syscall::{Packet, SchemeMut, EWOULDBLOCK}; - -use scheme::EthernetScheme; - -mod scheme; - -fn daemon(network_fd: RawFd, socket_fd: RawFd) { - let network = unsafe { File::from_raw_fd(network_fd) }; - let socket = Rc::new(RefCell::new(unsafe { File::from_raw_fd(socket_fd) })); - let scheme = Rc::new(RefCell::new(EthernetScheme::new(network))); - let todo = Rc::new(RefCell::new(Vec::::new())); - - let mut event_queue = EventQueue::<()>::new().expect("ethernetd: failed to create event queue"); - - let socket_net = socket.clone(); - let scheme_net = scheme.clone(); - let todo_net = todo.clone(); - event_queue.add(network_fd, move |_count: usize| -> Result> { - if scheme_net.borrow_mut().input()? > 0 { - let mut todo = todo_net.borrow_mut(); - let mut i = 0; - while i < todo.len() { - let a = todo[i].a; - scheme_net.borrow_mut().handle(&mut todo[i]); - if todo[i].a == (-EWOULDBLOCK) as usize { - todo[i].a = a; - i += 1; - } else { - socket_net.borrow_mut().write(&mut todo[i])?; - todo.remove(i); - } - } - - for (id, handle) in scheme_net.borrow_mut().handles.iter() { - if let Some(frame) = handle.frames.get(0) { - socket_net.borrow_mut().write(&Packet { - id: 0, - pid: 0, - uid: 0, - gid: 0, - a: syscall::number::SYS_FEVENT, - b: *id, - c: syscall::flag::EVENT_READ, - d: frame.data.len() - })?; - } - } - } - Ok(None) - }).expect("ethernetd: failed to listen for network events"); - - event_queue.add(socket_fd, move |_count: usize| -> Result> { - loop { - let mut packet = Packet::default(); - if socket.borrow_mut().read(&mut packet)? == 0 { - break; - } - - let a = packet.a; - scheme.borrow_mut().handle(&mut packet); - if packet.a == (-EWOULDBLOCK) as usize { - packet.a = a; - todo.borrow_mut().push(packet); - } else { - socket.borrow_mut().write(&mut packet)?; - } - } - - Ok(None) - }).expect("ethernetd: failed to listen for scheme events"); - - event_queue.trigger_all(0).expect("ethernetd: failed to trigger events"); - - event_queue.run().expect("ethernetd: failed to run event loop"); -} - -fn main() { - println!("ethernetd: opening network:"); - match syscall::open("network:", syscall::O_RDWR | syscall::O_NONBLOCK) { - Ok(network_fd) => { - // Daemonize - if unsafe { syscall::clone(0).unwrap() } == 0 { - println!("ethernetd: providing ethernet:"); - match syscall::open(":ethernet", syscall::O_RDWR | syscall::O_CREAT | syscall::O_NONBLOCK) { - Ok(socket_fd) => { - daemon(network_fd as RawFd, socket_fd as RawFd); - }, - Err(err) => { - println!("ethernetd: failed to create ethernet scheme: {}", err); - process::exit(1); - } - } - } - }, - Err(err) => { - println!("ethernetd: failed to open network: {}", err); - process::exit(1); - } - } -} diff --git a/src/ethernetd/scheme.rs b/src/ethernetd/scheme.rs deleted file mode 100644 index 1286d9e5e4..0000000000 --- a/src/ethernetd/scheme.rs +++ /dev/null @@ -1,169 +0,0 @@ -use std::collections::{BTreeMap, VecDeque}; -use std::fs::File; -use std::io::{self, Read, Write}; -use std::os::unix::io::AsRawFd; -use std::{cmp, str, u16}; - -use netutils::{getcfg, MacAddr, EthernetII}; -use syscall; -use syscall::error::{Error, Result, EACCES, EBADF, EINVAL, EIO, EWOULDBLOCK}; -use syscall::flag::O_NONBLOCK; -use syscall::scheme::SchemeMut; - -#[derive(Clone)] -pub struct Handle { - /// The flags this handle was opened with - flags: usize, - /// The Host's MAC address - pub host_addr: MacAddr, - /// The ethernet type - pub ethertype: u16, - /// The data - pub frames: VecDeque, -} - -pub struct EthernetScheme { - network: File, - next_id: usize, - pub handles: BTreeMap -} - -impl EthernetScheme { - pub fn new(network: File) -> EthernetScheme { - EthernetScheme { - network: network, - next_id: 1, - handles: BTreeMap::new(), - } - } - - //TODO: Minimize allocation - //TODO: Reduce iteration cost (use BTreeMap of ethertype to handle?) - pub fn input(&mut self) -> io::Result { - let mut total = 0; - loop { - let mut bytes = [0; 65536]; - let count = self.network.read(&mut bytes)?; - if count == 0 { - break; - } - if let Some(frame) = EthernetII::from_bytes(&bytes[.. count]) { - for (_id, handle) in self.handles.iter_mut() { - if frame.header.ethertype.get() == handle.ethertype { - handle.frames.push_back(frame.clone()); - } - } - total += count; - } - } - Ok(total) - } -} - -impl SchemeMut for EthernetScheme { - fn open(&mut self, url: &[u8], flags: usize, uid: u32, _gid: u32) -> Result { - if uid == 0 { - let mac_str = getcfg("mac").map_err(|err| Error::new(err.raw_os_error().unwrap_or(EIO)))?; - let mac_addr = MacAddr::from_str(mac_str.trim()); - let path = try!(str::from_utf8(url).or(Err(Error::new(EINVAL)))); - - let ethertype = u16::from_str_radix(path, 16).unwrap_or(0); - - let next_id = self.next_id; - self.next_id += 1; - - self.handles.insert(next_id, Handle { - flags: flags, - host_addr: mac_addr, - ethertype: ethertype, - frames: VecDeque::new() - }); - - Ok(next_id) - } else { - Err(Error::new(EACCES)) - } - } - - fn dup(&mut self, id: usize, buf: &[u8]) -> Result { - if ! buf.is_empty() { - return Err(Error::new(EINVAL)); - } - - let next_id = self.next_id; - self.next_id += 1; - - let handle = { - let handle = self.handles.get(&id).ok_or(Error::new(EBADF))?; - handle.clone() - }; - - self.handles.insert(next_id, handle); - - Ok(next_id) - } - - fn read(&mut self, id: usize, buf: &mut [u8]) -> Result { - let handle = self.handles.get_mut(&id).ok_or(Error::new(EBADF))?; - - if let Some(frame) = handle.frames.pop_front() { - let data = frame.to_bytes(); - for (b, d) in buf.iter_mut().zip(data.iter()) { - *b = *d; - } - - Ok(cmp::min(buf.len(), data.len())) - } else if handle.flags & O_NONBLOCK == O_NONBLOCK { - Ok(0) - } else { - Err(Error::new(EWOULDBLOCK)) - } - } - - fn write(&mut self, id: usize, buf: &[u8]) -> Result { - let handle = self.handles.get(&id).ok_or(Error::new(EBADF))?; - - if let Some(mut frame) = EthernetII::from_bytes(buf) { - frame.header.src = handle.host_addr; - frame.header.ethertype.set(handle.ethertype); - self.network.write(&frame.to_bytes()).map_err(|err| Error::new(err.raw_os_error().unwrap_or(EIO))) - } else { - Err(Error::new(EINVAL)) - } - } - - fn fevent(&mut self, id: usize, _flags: usize) -> Result { - let _handle = self.handles.get(&id).ok_or(Error::new(EBADF))?; - - Ok(id) - } - - fn fpath(&mut self, id: usize, buf: &mut [u8]) -> Result { - let handle = self.handles.get(&id).ok_or(Error::new(EBADF))?; - - let path_string = format!("ethernet:{:X}", handle.ethertype); - let path = path_string.as_bytes(); - - let mut i = 0; - while i < buf.len() && i < path.len() { - buf[i] = path[i]; - i += 1; - } - - Ok(i) - } - - fn fsync(&mut self, id: usize) -> Result { - let _handle = self.handles.get(&id).ok_or(Error::new(EBADF))?; - - syscall::fsync(self.network.as_raw_fd() as usize) - } - - fn close(&mut self, id: usize) -> Result { - let handle = self.handles.remove(&id).ok_or(Error::new(EBADF))?; - - drop(handle); - - Ok(0) - } -} diff --git a/src/ipd/interface/ethernet.rs b/src/ipd/interface/ethernet.rs deleted file mode 100644 index 28e561bc66..0000000000 --- a/src/ipd/interface/ethernet.rs +++ /dev/null @@ -1,155 +0,0 @@ -use netutils::{getcfg, n16, Ipv4Addr, MacAddr, Ipv4, EthernetII, EthernetIIHeader, Arp}; -use std::collections::BTreeMap; -use std::fs::File; -use std::io::{Result, Read, Write}; -use std::os::unix::io::{RawFd, FromRawFd}; - -use interface::Interface; - -pub struct EthernetInterface { - mac: MacAddr, - ip: Ipv4Addr, - router: Ipv4Addr, - subnet: Ipv4Addr, - arp_file: File, - ip_file: File, - arp: BTreeMap, - rarp: BTreeMap, -} - -impl EthernetInterface { - pub fn new(arp_fd: RawFd, ip_fd: RawFd) -> Self { - EthernetInterface { - mac: MacAddr::from_str(&getcfg("mac").unwrap().trim()), - ip: Ipv4Addr::from_str(&getcfg("ip").unwrap().trim()), - router: Ipv4Addr::from_str(&getcfg("ip_router").unwrap().trim()), - subnet: Ipv4Addr::from_str(&getcfg("ip_subnet").unwrap().trim()), - arp_file: unsafe { File::from_raw_fd(arp_fd) }, - ip_file: unsafe { File::from_raw_fd(ip_fd) }, - arp: BTreeMap::new(), - rarp: BTreeMap::new(), - } - } -} - -impl Interface for EthernetInterface { - fn ip(&self) -> Ipv4Addr { - self.ip - } - - fn routable(&self, dst: Ipv4Addr) -> bool { - dst != Ipv4Addr::LOOPBACK - } - - fn arp_event(&mut self) -> Result<()> { - loop { - let mut bytes = [0; 65536]; - let count = self.arp_file.read(&mut bytes)?; - if count == 0 { - break; - } - if let Some(frame) = EthernetII::from_bytes(&bytes[.. count]) { - if let Some(packet) = Arp::from_bytes(&frame.data) { - if packet.header.oper.get() == 1 { - if packet.header.dst_ip == self.ip { - if packet.header.src_ip != Ipv4Addr::BROADCAST && frame.header.src != MacAddr::BROADCAST { - self.arp.insert(packet.header.src_ip, frame.header.src); - self.rarp.insert(frame.header.src, packet.header.src_ip); - } - - let mut response = Arp { - header: packet.header, - data: packet.data.clone(), - }; - response.header.oper.set(2); - response.header.dst_mac = packet.header.src_mac; - response.header.dst_ip = packet.header.src_ip; - response.header.src_mac = self.mac; - response.header.src_ip = self.ip; - - let mut response_frame = EthernetII { - header: frame.header, - data: response.to_bytes() - }; - - response_frame.header.dst = response_frame.header.src; - response_frame.header.src = self.mac; - - self.arp_file.write(&response_frame.to_bytes())?; - } - } - } - } - } - - Ok(()) - } - - fn recv(&mut self) -> Result> { - let mut ips = Vec::new(); - - loop { - let mut bytes = [0; 65536]; - let count = self.ip_file.read(&mut bytes)?; - if count == 0 { - break; - } - if let Some(frame) = EthernetII::from_bytes(&bytes[.. count]) { - if let Some(ip) = Ipv4::from_bytes(&frame.data) { - if ip.header.dst == self.ip || ip.header.dst == Ipv4Addr::BROADCAST { - //TODO: Handle ping here - - if ip.header.src != Ipv4Addr::BROADCAST && frame.header.src != MacAddr::BROADCAST { - self.arp.insert(ip.header.src, frame.header.src); - self.rarp.insert(frame.header.src, ip.header.src); - } - - ips.push(ip); - } - } - } - } - - Ok(ips) - } - - fn send(&mut self, ip: Ipv4) -> Result { - let mut dst = MacAddr::BROADCAST; - if ip.header.dst != Ipv4Addr::BROADCAST { - let mut needs_routing = false; - - for octet in 0..4 { - let me = self.ip.bytes[octet]; - let mask = self.subnet.bytes[octet]; - let them = ip.header.dst.bytes[octet]; - if me & mask != them & mask { - needs_routing = true; - break; - } - } - - let route_addr = if needs_routing { - self.router - } else { - ip.header.dst - }; - - if let Some(mac) = self.arp.get(&route_addr) { - dst = *mac; - } else { - println!("ipd: need to arp {}", route_addr.to_string()); - } - } - - let frame = EthernetII { - header: EthernetIIHeader { - dst: dst, - src: self.mac, - ethertype: n16::new(0x800), - }, - data: ip.to_bytes() - }; - - self.ip_file.write(&frame.to_bytes()) - } -} diff --git a/src/ipd/interface/loopback.rs b/src/ipd/interface/loopback.rs deleted file mode 100644 index a957ef8818..0000000000 --- a/src/ipd/interface/loopback.rs +++ /dev/null @@ -1,50 +0,0 @@ -use netutils::{Ipv4Addr, Ipv4}; -use std::io::Result; - -use interface::Interface; - -pub struct LoopbackInterface { - packets: Vec -} - -impl LoopbackInterface { - pub fn new() -> Self { - LoopbackInterface { - packets: Vec::new() - } - } -} - -impl Interface for LoopbackInterface { - fn ip(&self) -> Ipv4Addr { - Ipv4Addr::LOOPBACK - } - - fn routable(&self, dst: Ipv4Addr) -> bool { - dst == Ipv4Addr::LOOPBACK - } - - fn recv(&mut self) -> Result> { - let mut ips = Vec::new(); - - for ip in self.packets.drain(..) { - ips.push(ip); - } - - Ok(ips) - } - - fn send(&mut self, ip: Ipv4) -> Result { - self.packets.push(ip); - - Ok(0) - } - - fn arp_event(&mut self) -> Result<()> { - Ok(()) - } - - fn has_loopback_data(&self) -> bool { - ! self.packets.is_empty() - } -} diff --git a/src/ipd/interface/mod.rs b/src/ipd/interface/mod.rs deleted file mode 100644 index 2fa89d9d2e..0000000000 --- a/src/ipd/interface/mod.rs +++ /dev/null @@ -1,19 +0,0 @@ -use netutils::{Ipv4, Ipv4Addr}; -use std::io::Result; - -pub use self::ethernet::EthernetInterface; -pub use self::loopback::LoopbackInterface; - -mod ethernet; -mod loopback; - -pub trait Interface { - fn ip(&self) -> Ipv4Addr; - fn routable(&self, dst: Ipv4Addr) -> bool; - fn recv(&mut self) -> Result>; - fn send(&mut self, ip: Ipv4) -> Result; - - fn arp_event(&mut self) -> Result<()>; - - fn has_loopback_data(&self) -> bool { false } -} diff --git a/src/ipd/main.rs b/src/ipd/main.rs deleted file mode 100644 index 43b3909338..0000000000 --- a/src/ipd/main.rs +++ /dev/null @@ -1,348 +0,0 @@ -extern crate event; -extern crate netutils; -extern crate syscall; - -use event::EventQueue; -use netutils::{Ipv4Addr, Ipv4}; -use netutils::tcp::Tcp; -use std::cell::RefCell; -use std::collections::{BTreeMap, VecDeque}; -use std::fs::File; -use std::io::{self, Read, Write}; -use std::os::unix::io::{RawFd, FromRawFd}; -use std::{process, slice, str}; -use std::rc::Rc; -use syscall::data::Packet; -use syscall::error::{Error, Result, EACCES, EADDRNOTAVAIL, EBADF, EIO, EINVAL, ENOENT, EWOULDBLOCK}; -use syscall::flag::{EVENT_READ, O_NONBLOCK}; -use syscall::scheme::SchemeMut; - -use interface::{Interface, EthernetInterface, LoopbackInterface}; - -mod interface; - -struct Handle { - proto: u8, - flags: usize, - events: usize, - data: VecDeque>, - todo: VecDeque, -} - -struct Ipd { - scheme_file: File, - interfaces: Vec>, - next_id: usize, - handles: BTreeMap, -} - -impl Ipd { - fn new(scheme_file: File) -> Self { - Ipd { - scheme_file: scheme_file, - interfaces: Vec::new(), - next_id: 1, - handles: BTreeMap::new(), - } - } - - fn scheme_event(&mut self) -> io::Result<()> { - loop { - let mut packet = Packet::default(); - if self.scheme_file.read(&mut packet)? == 0 { - break; - } - - let a = packet.a; - self.handle(&mut packet); - if packet.a == (-EWOULDBLOCK) as usize { - packet.a = a; - if let Some(mut handle) = self.handles.get_mut(&packet.b) { - handle.todo.push_back(packet); - } - } else { - self.scheme_file.write(&packet)?; - } - } - - Ok(()) - } - - fn ip_event(&mut self, if_id: usize) -> io::Result<()> { - if let Some(mut interface) = self.interfaces.get_mut(if_id) { - for ip in interface.recv()? { - for (id, handle) in self.handles.iter_mut() { - if ip.header.proto == handle.proto { - handle.data.push_back(ip.to_bytes()); - - while ! handle.todo.is_empty() && ! handle.data.is_empty() { - let mut packet = handle.todo.pop_front().unwrap(); - let buf = unsafe { slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) }; - let data = handle.data.pop_front().unwrap(); - - let mut i = 0; - while i < buf.len() && i < data.len() { - buf[i] = data[i]; - i += 1; - } - packet.a = i; - - self.scheme_file.write(&packet)?; - } - - if handle.events & EVENT_READ == EVENT_READ { - if let Some(data) = handle.data.get(0) { - self.scheme_file.write(&Packet { - id: 0, - pid: 0, - uid: 0, - gid: 0, - a: syscall::number::SYS_FEVENT, - b: *id, - c: EVENT_READ, - d: data.len() - })?; - } - } - } - } - } - } - - Ok(()) - } - - fn loopback_event(&mut self, loopback_id: usize) -> io::Result<()> { - let handle_loopback = if let Some(interface) = self.interfaces.get(loopback_id) { - interface.has_loopback_data() - } else { - false - }; - - if handle_loopback { - self.ip_event(loopback_id)?; - } - - Ok(()) - } -} - -impl SchemeMut for Ipd { - fn open(&mut self, url: &[u8], flags: usize, uid: u32, _gid: u32) -> Result { - if uid == 0 { - let path = str::from_utf8(url).or(Err(Error::new(EINVAL)))?; - - let proto = u8::from_str_radix(path, 16).or(Err(Error::new(ENOENT)))?; - - let id = self.next_id; - self.next_id += 1; - - self.handles.insert(id, Handle { - proto: proto, - flags: flags, - events: 0, - data: VecDeque::new(), - todo: VecDeque::new(), - }); - - Ok(id) - } else { - Err(Error::new(EACCES)) - } - } - - fn dup(&mut self, file: usize, buf: &[u8]) -> Result { - if ! buf.is_empty() { - return Err(Error::new(EINVAL)); - } - - let handle = { - let handle = self.handles.get(&file).ok_or(Error::new(EBADF))?; - Handle { - proto: handle.proto, - flags: handle.flags, - events: 0, - data: handle.data.clone(), - todo: VecDeque::new(), - } - }; - - let id = self.next_id; - self.next_id += 1; - - self.handles.insert(id, handle); - - Ok(id) - } - - fn read(&mut self, file: usize, buf: &mut [u8]) -> Result { - let mut handle = self.handles.get_mut(&file).ok_or(Error::new(EBADF))?; - - if let Some(data) = handle.data.pop_front() { - let mut i = 0; - while i < buf.len() && i < data.len() { - buf[i] = data[i]; - i += 1; - } - - Ok(i) - } else if handle.flags & O_NONBLOCK == O_NONBLOCK { - Ok(0) - } else { - Err(Error::new(EWOULDBLOCK)) - } - } - - fn write(&mut self, file: usize, buf: &[u8]) -> Result { - let handle = self.handles.get(&file).ok_or(Error::new(EBADF))?; - - if let Some(mut ip) = Ipv4::from_bytes(buf) { - for mut interface in self.interfaces.iter_mut() { - let if_ip = interface.ip(); - if ip.header.src == if_ip || (ip.header.src == Ipv4Addr::NULL && interface.routable(ip.header.dst)) { - ip.header.src = if_ip; - ip.header.proto = handle.proto; - - if let Some(mut tcp) = Tcp::from_bytes(&ip.data) { - tcp.checksum(&ip.header.src, &ip.header.dst); - ip.data = tcp.to_bytes(); - } - - ip.checksum(); - - interface.send(ip).map_err(|err| Error::new(err.raw_os_error().unwrap_or(EIO)))?; - - return Ok(buf.len()); - } - } - - Err(Error::new(EADDRNOTAVAIL)) - } else { - Err(Error::new(EINVAL)) - } - } - - fn fevent(&mut self, file: usize, flags: usize) -> Result { - let mut handle = self.handles.get_mut(&file).ok_or(Error::new(EBADF))?; - - handle.events = flags; - - Ok(file) - } - - fn fpath(&mut self, id: usize, buf: &mut [u8]) -> Result { - let handle = self.handles.get(&id).ok_or(Error::new(EBADF))?; - - let path_string = format!("ip:{:X}", handle.proto); - let path = path_string.as_bytes(); - - let mut i = 0; - while i < buf.len() && i < path.len() { - buf[i] = path[i]; - i += 1; - } - - Ok(i) - } - - fn fsync(&mut self, file: usize) -> Result { - let _handle = self.handles.get(&file).ok_or(Error::new(EBADF))?; - - Ok(0) - } - - fn close(&mut self, file: usize) -> Result { - let handle = self.handles.remove(&file).ok_or(Error::new(EBADF))?; - - drop(handle); - - Ok(0) - } -} - -fn daemon(arp_fd: RawFd, ip_fd: RawFd, scheme_fd: RawFd) { - let scheme_file = unsafe { File::from_raw_fd(scheme_fd) }; - - let ipd = Rc::new(RefCell::new(Ipd::new(scheme_file))); - - let mut event_queue = EventQueue::<()>::new().expect("ipd: failed to create event queue"); - - //TODO: Multiple interfaces - { - let if_id = { - let mut ipd = ipd.borrow_mut(); - let if_id = ipd.interfaces.len(); - ipd.interfaces.push(Box::new(EthernetInterface::new(arp_fd, ip_fd))); - if_id - }; - - let arp_ipd = ipd.clone(); - event_queue.add(arp_fd, move |_count: usize| -> io::Result> { - if let Some(mut interface) = arp_ipd.borrow_mut().interfaces.get_mut(if_id) { - interface.arp_event()?; - } - - Ok(None) - }).expect("ipd: failed to listen to events on ethernet:806"); - - let ip_ipd = ipd.clone(); - event_queue.add(ip_fd, move |_count: usize| -> io::Result> { - ip_ipd.borrow_mut().ip_event(if_id)?; - - Ok(None) - }).expect("ipd: failed to listen to events on ethernet:800"); - } - - let loopback_id = { - let mut ipd = ipd.borrow_mut(); - let if_id = ipd.interfaces.len(); - ipd.interfaces.push(Box::new(LoopbackInterface::new())); - if_id - }; - - event_queue.add(scheme_fd, move |_count: usize| -> io::Result> { - let mut ipd = ipd.borrow_mut(); - - ipd.loopback_event(loopback_id)?; - ipd.scheme_event()?; - ipd.loopback_event(loopback_id)?; - - Ok(None) - }).expect("ipd: failed to listen to events on :ip"); - - // Make sure that all descriptors are at EOF - event_queue.trigger_all(0).expect("ipd: failed to trigger event queue"); - - event_queue.run().expect("ipd: failed to run event queue"); -} - -fn main() { - println!("ipd: opening ethernet:806"); - match syscall::open("ethernet:806", syscall::O_RDWR | syscall::O_NONBLOCK) { - Ok(arp_fd) => match syscall::open("ethernet:800", syscall::O_RDWR | syscall::O_NONBLOCK) { - Ok(ip_fd) => { - // Daemonize - if unsafe { syscall::clone(0).unwrap() } == 0 { - println!("ipd: providing ip:"); - match syscall::open(":ip", syscall::O_RDWR | syscall::O_CREAT | syscall::O_NONBLOCK) { - Ok(scheme_fd) => { - daemon(arp_fd as RawFd, ip_fd as RawFd, scheme_fd as RawFd); - }, - Err(err) => { - println!("ipd: failed to create ip scheme: {}", err); - process::exit(1); - } - } - } - }, - Err(err) => { - println!("ipd: failed to open ethernet:800: {}", err); - process::exit(1); - } - }, - Err(err) => { - println!("ipd: failed to open ethernet:806: {}", err); - process::exit(1); - } - } -} diff --git a/src/tcpd/main.rs b/src/tcpd/main.rs deleted file mode 100644 index fb11257778..0000000000 --- a/src/tcpd/main.rs +++ /dev/null @@ -1,982 +0,0 @@ -extern crate event; -extern crate netutils; -extern crate rand; -extern crate syscall; - -use rand::{Rng, OsRng}; -use std::collections::{BTreeMap, VecDeque}; -use std::cell::RefCell; -use std::fs::File; -use std::io::{self, Read, Write}; -use std::{mem, process, slice, str}; -use std::ops::{Deref, DerefMut}; -use std::os::unix::io::{RawFd, FromRawFd}; -use std::rc::Rc; - -use event::EventQueue; -use netutils::{n16, n32, Ipv4, Ipv4Addr, Ipv4Header, Checksum}; -use netutils::tcp::{Tcp, TcpHeader, TCP_FIN, TCP_SYN, TCP_RST, TCP_PSH, TCP_ACK}; -use syscall::data::{Packet, TimeSpec}; -use syscall::error::{Error, Result, EACCES, EADDRINUSE, EBADF, EIO, EINVAL, EISCONN, EMSGSIZE, ENOTCONN, ETIMEDOUT, EWOULDBLOCK}; -use syscall::flag::{CLOCK_MONOTONIC, EVENT_READ, F_GETFL, F_SETFL, O_ACCMODE, O_CREAT, O_RDWR, O_NONBLOCK}; -use syscall::scheme::SchemeMut; - -fn add_time(a: &TimeSpec, b: &TimeSpec) -> TimeSpec { - let mut secs = a.tv_sec + b.tv_sec; - - let mut nsecs = a.tv_nsec + b.tv_nsec; - while nsecs >= 1000000000 { - nsecs -= 1000000000; - secs += 1; - } - - TimeSpec { - tv_sec: secs, - tv_nsec: nsecs - } -} - -fn parse_socket(socket: &str) -> (Ipv4Addr, u16) { - let mut socket_parts = socket.split(":"); - let host = Ipv4Addr::from_str(socket_parts.next().unwrap_or("")); - let port = socket_parts.next().unwrap_or("").parse::().unwrap_or(0); - (host, port) -} - -#[derive(Debug)] -struct EmptyHandle { - privileged: bool, - flags: usize -} - -#[derive(Copy, Clone, Debug, Eq, PartialEq)] -enum State { - Listen, - SynSent, - SynReceived, - Established, - FinWait1, - FinWait2, - CloseWait, - Closing, - LastAck, - TimeWait, - Closed -} - -#[derive(Debug)] -struct TcpHandle { - local: (Ipv4Addr, u16), - remote: (Ipv4Addr, u16), - flags: usize, - events: usize, - read_timeout: Option, - write_timeout: Option, - ttl: u8, - state: State, - seq: u32, - ack: u32, - data: VecDeque<(Ipv4, Tcp)>, - todo_dup: VecDeque, - todo_read: VecDeque<(Option, Packet)>, - todo_write: VecDeque<(Option, Packet)>, -} - -impl TcpHandle { - fn is_connected(&self) -> bool { - self.remote.0 != Ipv4Addr::NULL && self.remote.1 != 0 - } - - fn read_closed(&self) -> bool { - self.state == State::CloseWait || self.state == State::LastAck || self.state == State::TimeWait || self.state == State::Closed - } - - fn matches(&self, ip: &Ipv4, tcp: &Tcp) -> bool { - // Local address not set or IP dst matches or is broadcast - (self.local.0 == Ipv4Addr::NULL || ip.header.dst == self.local.0 || ip.header.dst == Ipv4Addr::BROADCAST) - // Local port matches UDP dst - && tcp.header.dst.get() == self.local.1 - // Remote address not set or is broadcast, or IP src matches - && (self.remote.0 == Ipv4Addr::NULL || self.remote.0 == Ipv4Addr::BROADCAST || ip.header.src == self.remote.0) - // Remote port not set or UDP src matches - && (self.remote.1 == 0 || tcp.header.src.get() == self.remote.1) - } - - fn create_tcp(&self, flags: u16, data: Vec) -> Tcp { - Tcp { - header: TcpHeader { - src: n16::new(self.local.1), - dst: n16::new(self.remote.1), - sequence: n32::new(self.seq), - ack_num: n32::new(self.ack), - flags: n16::new(((mem::size_of::() << 10) & 0xF000) as u16 | (flags & 0xFFF)), - window_size: n16::new(8192), - checksum: Checksum { data: 0 }, - urgent_pointer: n16::new(0), - }, - options: Vec::new(), - data: data - } - } - - fn create_ip(&self, id: u16, data: Vec) -> Ipv4 { - Ipv4 { - header: Ipv4Header { - ver_hlen: 0x45, - services: 0, - len: n16::new((data.len() + mem::size_of::()) as u16), - id: n16::new(id), - flags_fragment: n16::new(0), - ttl: self.ttl, - proto: 0x06, - checksum: Checksum { data: 0 }, - src: self.local.0, - dst: self.remote.0 - }, - options: Vec::new(), - data: data - } - } -} - -#[derive(Copy, Clone, Debug)] -enum SettingKind { - Ttl, - ReadTimeout, - WriteTimeout -} - -#[derive(Debug)] -enum Handle { - Empty(EmptyHandle), - Tcp(TcpHandle), - Setting(usize, SettingKind), -} - -struct Tcpd { - scheme_file: File, - tcp_file: File, - time_file: File, - ports: BTreeMap, - next_id: usize, - handles: BTreeMap, - rng: OsRng, -} - -impl Tcpd { - fn new(scheme_file: File, tcp_file: File, time_file: File) -> Self { - Tcpd { - scheme_file: scheme_file, - tcp_file: tcp_file, - time_file: time_file, - ports: BTreeMap::new(), - next_id: 1, - handles: BTreeMap::new(), - rng: OsRng::new().expect("tcpd: failed to open RNG") - } - } - - fn scheme_event(&mut self) -> io::Result<()> { - loop { - let mut packet = Packet::default(); - if self.scheme_file.read(&mut packet)? == 0 { - break; - } - - let a = packet.a; - self.handle(&mut packet); - if packet.a == (-EWOULDBLOCK) as usize { - if let Some(mut handle) = self.handles.get_mut(&packet.b) { - if let Handle::Tcp(ref mut handle) = *handle { - match a { - syscall::number::SYS_DUP => { - packet.a = a; - handle.todo_dup.push_back(packet); - }, - syscall::number::SYS_READ => { - packet.a = a; - - let timeout = match handle.read_timeout { - Some(read_timeout) => { - let mut time = TimeSpec::default(); - syscall::clock_gettime(CLOCK_MONOTONIC, &mut time).map_err(|err| io::Error::from_raw_os_error(err.errno))?; - - let timeout = add_time(&time, &read_timeout); - self.time_file.write(&timeout)?; - Some(timeout) - }, - None => None - }; - - handle.todo_read.push_back((timeout, packet)); - }, - syscall::number::SYS_WRITE => { - packet.a = a; - - let timeout = match handle.write_timeout { - Some(write_timeout) => { - let mut time = TimeSpec::default(); - syscall::clock_gettime(CLOCK_MONOTONIC, &mut time).map_err(|err| io::Error::from_raw_os_error(err.errno))?; - - let timeout = add_time(&time, &write_timeout); - self.time_file.write(&timeout)?; - Some(timeout) - }, - None => None - }; - - handle.todo_write.push_back((timeout, packet)); - }, - _ => { - self.scheme_file.write(&packet)?; - } - } - } - } - } else { - self.scheme_file.write(&packet)?; - } - } - - Ok(()) - } - - fn tcp_event(&mut self) -> io::Result<()> { - loop { - let mut bytes = [0; 65536]; - let count = self.tcp_file.read(&mut bytes)?; - if count == 0 { - break; - } - if let Some(ip) = Ipv4::from_bytes(&bytes[.. count]) { - if let Some(tcp) = Tcp::from_bytes(&ip.data) { - let mut closing = Vec::new(); - let mut found_connection = false; - for (id, handle) in self.handles.iter_mut() { - if let Handle::Tcp(ref mut handle) = *handle { - if handle.state != State::Listen && handle.matches(&ip, &tcp) { - found_connection = true; - - match handle.state { - State::SynReceived => if tcp.header.flags.get() & (TCP_SYN | TCP_ACK) == TCP_ACK && tcp.header.ack_num.get() == handle.seq { - handle.state = State::Established; - }, - State::SynSent => if tcp.header.flags.get() & (TCP_SYN | TCP_ACK) == TCP_SYN | TCP_ACK && tcp.header.ack_num.get() == handle.seq { - handle.state = State::Established; - handle.ack = tcp.header.sequence.get() + 1; - - let tcp = handle.create_tcp(TCP_ACK, Vec::new()); - let ip = handle.create_ip(self.rng.gen(), tcp.to_bytes()); - self.tcp_file.write(&ip.to_bytes())?; - }, - State::Established => if tcp.header.flags.get() & (TCP_SYN | TCP_ACK) == TCP_ACK && tcp.header.ack_num.get() == handle.seq { - handle.ack = tcp.header.sequence.get(); - - if ! tcp.data.is_empty() { - handle.data.push_back((ip.clone(), tcp.clone())); - handle.ack += tcp.data.len() as u32; - - let tcp = handle.create_tcp(TCP_ACK, Vec::new()); - let ip = handle.create_ip(self.rng.gen(), tcp.to_bytes()); - self.tcp_file.write(&ip.to_bytes())?; - } else if tcp.header.flags.get() & TCP_FIN == TCP_FIN { - handle.state = State::CloseWait; - - handle.ack += 1; - - let tcp = handle.create_tcp(TCP_ACK, Vec::new()); - let ip = handle.create_ip(self.rng.gen(), tcp.to_bytes()); - self.tcp_file.write(&ip.to_bytes())?; - } - }, - //TODO: Time wait - State::FinWait1 => if tcp.header.flags.get() & (TCP_SYN | TCP_ACK) == TCP_ACK && tcp.header.ack_num.get() == handle.seq { - handle.ack = tcp.header.sequence.get() + 1; - - if tcp.header.flags.get() & TCP_FIN == TCP_FIN { - handle.state = State::TimeWait; - - let tcp = handle.create_tcp(TCP_ACK, Vec::new()); - let ip = handle.create_ip(self.rng.gen(), tcp.to_bytes()); - self.tcp_file.write(&ip.to_bytes())?; - - closing.push(*id); - } else { - handle.state = State::FinWait2; - } - }, - State::FinWait2 => if tcp.header.flags.get() & (TCP_SYN | TCP_ACK | TCP_FIN) == TCP_ACK | TCP_FIN && tcp.header.ack_num.get() == handle.seq { - handle.ack = tcp.header.sequence.get() + 1; - - handle.state = State::TimeWait; - - let tcp = handle.create_tcp(TCP_ACK, Vec::new()); - let ip = handle.create_ip(self.rng.gen(), tcp.to_bytes()); - self.tcp_file.write(&ip.to_bytes())?; - - closing.push(*id); - }, - State::LastAck => if tcp.header.flags.get() & (TCP_SYN | TCP_ACK) == TCP_ACK && tcp.header.ack_num.get() == handle.seq { - handle.state = State::Closed; - closing.push(*id); - }, - _ => () - } - - while ! handle.todo_read.is_empty() && (! handle.data.is_empty() || handle.read_closed()) { - let (_timeout, mut packet) = handle.todo_read.pop_front().unwrap(); - let buf = unsafe { slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) }; - if let Some((ip, mut tcp)) = handle.data.pop_front() { - let len = std::cmp::min(buf.len(), tcp.data.len()); - for (i, c) in tcp.data.drain(0..len).enumerate() { - buf[i] = c; - } - if !tcp.data.is_empty() { - handle.data.push_front((ip, tcp)); - } - packet.a = len; - } else { - packet.a = 0; - } - - self.scheme_file.write(&packet)?; - } - - if ! handle.todo_write.is_empty() && handle.state == State::Established { - let (_timeout, mut packet) = handle.todo_write.pop_front().unwrap(); - let buf = unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }; - - let tcp = handle.create_tcp(TCP_ACK | TCP_PSH, buf.to_vec()); - let ip = handle.create_ip(self.rng.gen(), tcp.to_bytes()); - let result = self.tcp_file.write(&ip.to_bytes()).map_err(|err| Error::new(err.raw_os_error().unwrap_or(EIO))); - if result.is_ok() { - handle.seq += buf.len() as u32; - } - packet.a = Error::mux(result.and(Ok(buf.len()))); - - self.scheme_file.write(&packet)?; - } - - if handle.events & EVENT_READ == EVENT_READ { - if let Some(&(ref _ip, ref tcp)) = handle.data.get(0) { - self.scheme_file.write(&Packet { - id: 0, - pid: 0, - uid: 0, - gid: 0, - a: syscall::number::SYS_FEVENT, - b: *id, - c: EVENT_READ, - d: tcp.data.len() - })?; - } - } - } - } - } - - for file in closing { - if let Handle::Tcp(handle) = self.handles.remove(&file).unwrap() { - let remove = if let Some(mut port) = self.ports.get_mut(&handle.local.1) { - *port = *port + 1; - *port == 0 - } else { - false - }; - - if remove { - self.ports.remove(&handle.local.1); - } - } - } - - if ! found_connection && tcp.header.flags.get() & (TCP_SYN | TCP_ACK) == TCP_SYN { - let mut new_handles = Vec::new(); - - for (id, handle) in self.handles.iter_mut() { - if let Handle::Tcp(ref mut handle) = *handle { - if handle.state == State::Listen && handle.matches(&ip, &tcp) { - handle.data.push_back((ip.clone(), tcp.clone())); - - while ! handle.todo_dup.is_empty() && ! handle.data.is_empty() { - let mut packet = handle.todo_dup.pop_front().unwrap(); - let (ip, tcp) = handle.data.pop_front().unwrap(); - - let mut new_handle = TcpHandle { - local: handle.local, - remote: (ip.header.src, tcp.header.src.get()), - flags: handle.flags, - events: 0, - read_timeout: handle.read_timeout, - write_timeout: handle.write_timeout, - ttl: handle.ttl, - state: State::SynReceived, - seq: self.rng.gen(), - ack: tcp.header.sequence.get() + 1, - data: VecDeque::new(), - todo_dup: VecDeque::new(), - todo_read: VecDeque::new(), - todo_write: VecDeque::new(), - }; - - let tcp = new_handle.create_tcp(TCP_SYN | TCP_ACK, Vec::new()); - let ip = new_handle.create_ip(self.rng.gen(), tcp.to_bytes()); - self.tcp_file.write(&ip.to_bytes())?; - - new_handle.seq += 1; - - handle.data.retain(|&(ref ip, ref tcp)| { - if new_handle.matches(ip, tcp) { - false - } else { - true - } - }); - - if let Some(mut port) = self.ports.get_mut(&handle.local.1) { - *port = *port + 1; - } - - let id = self.next_id; - self.next_id += 1; - - packet.a = id; - - new_handles.push((packet, Handle::Tcp(new_handle))); - } - - if handle.events & EVENT_READ == EVENT_READ { - if let Some(&(ref _ip, ref tcp)) = handle.data.get(0) { - self.scheme_file.write(&Packet { - id: 0, - pid: 0, - uid: 0, - gid: 0, - a: syscall::number::SYS_FEVENT, - b: *id, - c: EVENT_READ, - d: tcp.data.len() - })?; - } - } - } - } - } - - for (packet, new_handle) in new_handles { - self.handles.insert(packet.a, new_handle); - self.scheme_file.write(&packet)?; - } - } - } - } - } - - Ok(()) - } - - fn time_event(&mut self) -> io::Result<()> { - let mut time = TimeSpec::default(); - if self.time_file.read(&mut time)? < mem::size_of::() { - return Err(io::Error::from_raw_os_error(EINVAL)); - } - - for (_id, handle) in self.handles.iter_mut() { - if let Handle::Tcp(ref mut handle) = *handle { - let mut i = 0; - while i < handle.todo_read.len() { - if let Some(timeout) = handle.todo_read.get(i).map(|e| e.0.clone()).unwrap_or(None) { - if time.tv_sec > timeout.tv_sec || (time.tv_sec == timeout.tv_sec && time.tv_nsec >= timeout.tv_nsec) { - let (_timeout, mut packet) = handle.todo_read.remove(i).unwrap(); - packet.a = (-ETIMEDOUT) as usize; - self.scheme_file.write(&packet)?; - } else { - i += 1; - } - } else { - i += 1; - } - } - - let mut i = 0; - while i < handle.todo_write.len() { - if let Some(timeout) = handle.todo_write.get(i).map(|e| e.0.clone()).unwrap_or(None) { - if time.tv_sec > timeout.tv_sec || (time.tv_sec == timeout.tv_sec && time.tv_nsec >= timeout.tv_nsec) { - let (_timeout, mut packet) = handle.todo_write.remove(i).unwrap(); - packet.a = (-ETIMEDOUT) as usize; - self.scheme_file.write(&packet)?; - } else { - i += 1; - } - } else { - i += 1; - } - } - } - } - - Ok(()) - } - - fn inner_dup(&mut self, file: usize, path: &str) -> Result { - Ok(match *self.handles.get_mut(&file).ok_or(Error::new(EBADF))? { - Handle::Empty(ref handle) => { - if path.is_empty() { - Handle::Empty(EmptyHandle { - privileged: handle.privileged, - flags: handle.flags - }) - } else { - let mut parts = path.split("/"); - let remote = parse_socket(parts.next().unwrap_or("")); - let mut local = parse_socket(parts.next().unwrap_or("")); - - if local.1 == 0 { - local.1 = self.rng.gen_range(32768, 65535); - } - - if local.1 <= 1024 && ! handle.privileged { - return Err(Error::new(EACCES)); - } - - if self.ports.contains_key(&local.1) { - return Err(Error::new(EADDRINUSE)); - } - - let mut new_handle = TcpHandle { - local: local, - remote: remote, - flags: handle.flags, - events: 0, - read_timeout: None, - write_timeout: None, - ttl: 64, - state: State::Listen, - seq: 0, - ack: 0, - data: VecDeque::new(), - todo_dup: VecDeque::new(), - todo_read: VecDeque::new(), - todo_write: VecDeque::new(), - }; - - if new_handle.is_connected() { - new_handle.seq = self.rng.gen(); - new_handle.ack = 0; - new_handle.state = State::SynSent; - - let tcp = new_handle.create_tcp(TCP_SYN, Vec::new()); - let ip = new_handle.create_ip(self.rng.gen(), tcp.to_bytes()); - self.tcp_file.write(&ip.to_bytes()).map_err(|err| Error::new(err.raw_os_error().unwrap_or(EIO)))?; - - new_handle.seq += 1; - } - - self.ports.insert(new_handle.local.1, 1); - - Handle::Tcp(new_handle) - } - }, - Handle::Tcp(ref mut handle) => { - let mut new_handle = TcpHandle { - local: handle.local, - remote: handle.remote, - flags: handle.flags, - events: 0, - read_timeout: handle.read_timeout, - write_timeout: handle.write_timeout, - ttl: handle.ttl, - state: handle.state, - seq: handle.seq, - ack: handle.ack, - data: VecDeque::new(), - todo_dup: VecDeque::new(), - todo_read: VecDeque::new(), - todo_write: VecDeque::new(), - }; - - if path == "ttl" { - Handle::Setting(file, SettingKind::Ttl) - } else if path == "read_timeout" { - Handle::Setting(file, SettingKind::ReadTimeout) - } else if path == "write_timeout" { - Handle::Setting(file, SettingKind::WriteTimeout) - } else if path == "listen" { - if handle.is_connected() { - return Err(Error::new(EISCONN)); - } else if let Some((ip, tcp)) = handle.data.pop_front() { - new_handle.remote = (ip.header.src, tcp.header.src.get()); - - new_handle.seq = self.rng.gen(); - new_handle.ack = tcp.header.sequence.get() + 1; - new_handle.state = State::SynReceived; - - let tcp = new_handle.create_tcp(TCP_SYN | TCP_ACK, Vec::new()); - let ip = new_handle.create_ip(self.rng.gen(), tcp.to_bytes()); - self.tcp_file.write(&ip.to_bytes()).map_err(|err| Error::new(err.raw_os_error().unwrap_or(EIO)))?; - - new_handle.seq += 1; - } else { - return Err(Error::new(EWOULDBLOCK)); - } - - handle.data.retain(|&(ref ip, ref tcp)| { - if new_handle.matches(ip, tcp) { - false - } else { - true - } - }); - - Handle::Tcp(new_handle) - } else if path.is_empty() { - new_handle.data = handle.data.clone(); - - Handle::Tcp(new_handle) - } else { - return Err(Error::new(EINVAL)); - } - }, - Handle::Setting(file, kind) => { - Handle::Setting(file, kind) - } - }) - } -} - -impl SchemeMut for Tcpd { - fn open(&mut self, url: &[u8], flags: usize, uid: u32, _gid: u32) -> Result { - let path = str::from_utf8(url).or(Err(Error::new(EINVAL)))?; - - let id = self.next_id; - self.next_id += 1; - - self.handles.insert(id, Handle::Empty(EmptyHandle { - privileged: uid == 0, - flags: flags - })); - - match self.inner_dup(id, path) { - Ok(handle) => { - self.handles.insert(id, handle); - Ok(id) - }, - Err(err) => { - self.handles.remove(&id); - Err(err) - } - } - } - - fn dup(&mut self, file: usize, buf: &[u8]) -> Result { - let path = str::from_utf8(buf).or(Err(Error::new(EINVAL)))?; - - let handle = self.inner_dup(file, path)?; - - let id = self.next_id; - self.next_id += 1; - - self.handles.insert(id, handle); - - Ok(id) - } - - fn read(&mut self, file: usize, buf: &mut [u8]) -> Result { - let (file, kind) = match *self.handles.get_mut(&file).ok_or(Error::new(EBADF))? { - Handle::Empty(ref _handle) => { - return Err(Error::new(EBADF)); - }, - Handle::Tcp(ref mut handle) => { - if ! handle.is_connected() { - return Err(Error::new(ENOTCONN)); - } else if let Some((ip, mut tcp)) = handle.data.pop_front() { - let len = std::cmp::min(buf.len(), tcp.data.len()); - for (i, c) in tcp.data.drain(0..len).enumerate() { - buf[i] = c; - } - if !tcp.data.is_empty() { - handle.data.push_front((ip, tcp)); - } - - return Ok(len); - } else if handle.flags & O_NONBLOCK == O_NONBLOCK || handle.read_closed() { - return Ok(0); - } else { - return Err(Error::new(EWOULDBLOCK)); - } - }, - Handle::Setting(file, kind) => { - (file, kind) - } - }; - - if let Handle::Tcp(ref mut handle) = *self.handles.get_mut(&file).ok_or(Error::new(EBADF))? { - let get_timeout = |timeout: &Option, buf: &mut [u8]| -> Result { - if let Some(ref timespec) = *timeout { - timespec.deref().read(buf).map_err(|err| Error::new(err.raw_os_error().unwrap_or(EIO))) - } else { - Ok(0) - } - }; - - match kind { - SettingKind::Ttl => { - if let Some(mut ttl) = buf.get_mut(0) { - *ttl = handle.ttl; - Ok(1) - } else { - Ok(0) - } - }, - SettingKind::ReadTimeout => { - get_timeout(&handle.read_timeout, buf) - }, - SettingKind::WriteTimeout => { - get_timeout(&handle.write_timeout, buf) - } - } - } else { - Err(Error::new(EBADF)) - } - } - - fn write(&mut self, file: usize, buf: &[u8]) -> Result { - let (file, kind) = match *self.handles.get_mut(&file).ok_or(Error::new(EBADF))? { - Handle::Empty(ref _handle) => { - return Err(Error::new(EBADF)); - }, - Handle::Tcp(ref mut handle) => { - if ! handle.is_connected() { - return Err(Error::new(ENOTCONN)); - } else if buf.len() >= 65507 { - return Err(Error::new(EMSGSIZE)); - } else { - match handle.state { - State::Established => { - let tcp = handle.create_tcp(TCP_ACK | TCP_PSH, buf.to_vec()); - let ip = handle.create_ip(self.rng.gen(), tcp.to_bytes()); - self.tcp_file.write(&ip.to_bytes()).map_err(|err| Error::new(err.raw_os_error().unwrap_or(EIO)))?; - handle.seq += buf.len() as u32; - return Ok(buf.len()); - }, - _ => { - return Err(Error::new(EWOULDBLOCK)); - } - } - } - }, - Handle::Setting(file, kind) => { - (file, kind) - } - }; - - if let Handle::Tcp(ref mut handle) = *self.handles.get_mut(&file).ok_or(Error::new(EBADF))? { - let set_timeout = |timeout: &mut Option, buf: &[u8]| -> Result { - if buf.len() >= mem::size_of::() { - let mut timespec = TimeSpec::default(); - let count = timespec.deref_mut().write(buf).map_err(|err| Error::new(err.raw_os_error().unwrap_or(EIO)))?; - *timeout = Some(timespec); - Ok(count) - } else { - *timeout = None; - Ok(0) - } - }; - - match kind { - SettingKind::Ttl => { - if let Some(ttl) = buf.get(0) { - handle.ttl = *ttl; - Ok(1) - } else { - Ok(0) - } - }, - SettingKind::ReadTimeout => { - set_timeout(&mut handle.read_timeout, buf) - }, - SettingKind::WriteTimeout => { - set_timeout(&mut handle.write_timeout, buf) - } - } - } else { - Err(Error::new(EBADF)) - } - } - - fn fcntl(&mut self, file: usize, cmd: usize, arg: usize) -> Result { - match *self.handles.get_mut(&file).ok_or(Error::new(EBADF))? { - Handle::Empty(ref mut handle) => { - match cmd { - F_GETFL => Ok(handle.flags), - F_SETFL => { - handle.flags = arg & ! O_ACCMODE; - Ok(0) - }, - _ => Err(Error::new(EINVAL)) - } - }, - Handle::Tcp(ref mut handle) => { - match cmd { - F_GETFL => Ok(handle.flags), - F_SETFL => { - handle.flags = arg & ! O_ACCMODE; - Ok(0) - }, - _ => Err(Error::new(EINVAL)) - } - } - _ => Err(Error::new(EBADF)) - } - } - - fn fevent(&mut self, file: usize, flags: usize) -> Result { - if let Handle::Tcp(ref mut handle) = *self.handles.get_mut(&file).ok_or(Error::new(EBADF))? { - handle.events = flags; - Ok(file) - } else { - Err(Error::new(EBADF)) - } - } - - fn fpath(&mut self, file: usize, buf: &mut [u8]) -> Result { - if let Handle::Tcp(ref mut handle) = *self.handles.get_mut(&file).ok_or(Error::new(EBADF))? { - let path_string = format!("tcp:{}:{}/{}:{}", handle.remote.0.to_string(), handle.remote.1, handle.local.0.to_string(), handle.local.1); - let path = path_string.as_bytes(); - - let mut i = 0; - while i < buf.len() && i < path.len() { - buf[i] = path[i]; - i += 1; - } - - Ok(i) - } else { - Err(Error::new(EBADF)) - } - } - - fn fsync(&mut self, file: usize) -> Result { - let _handle = self.handles.get(&file).ok_or(Error::new(EBADF))?; - - Ok(0) - } - - fn close(&mut self, file: usize) -> Result { - let closed = { - if let Handle::Tcp(ref mut handle) = *self.handles.get_mut(&file).ok_or(Error::new(EBADF))? { - handle.data.clear(); - - match handle.state { - State::SynReceived | State::Established => { - handle.state = State::FinWait1; - - let tcp = handle.create_tcp(TCP_FIN | TCP_ACK, Vec::new()); - let ip = handle.create_ip(self.rng.gen(), tcp.to_bytes()); - self.tcp_file.write(&ip.to_bytes()).map_err(|err| Error::new(err.raw_os_error().unwrap_or(EIO)))?; - - handle.seq += 1; - - false - }, - State::CloseWait => { - handle.state = State::LastAck; - - let tcp = handle.create_tcp(TCP_FIN | TCP_ACK, Vec::new()); - let ip = handle.create_ip(self.rng.gen(), tcp.to_bytes()); - self.tcp_file.write(&ip.to_bytes()).map_err(|err| Error::new(err.raw_os_error().unwrap_or(EIO)))?; - - handle.seq += 1; - - false - }, - _ => true - } - } else { - true - } - }; - - if closed { - if let Handle::Tcp(handle) = self.handles.remove(&file).ok_or(Error::new(EBADF))? { - let remove = if let Some(mut port) = self.ports.get_mut(&handle.local.1) { - *port = *port + 1; - *port == 0 - } else { - false - }; - - if remove { - self.ports.remove(&handle.local.1); - } - } - } - - Ok(0) - } -} - -fn daemon(scheme_fd: RawFd, tcp_fd: RawFd, time_fd: RawFd) { - let scheme_file = unsafe { File::from_raw_fd(scheme_fd) }; - let tcp_file = unsafe { File::from_raw_fd(tcp_fd) }; - let time_file = unsafe { File::from_raw_fd(time_fd) }; - - let tcpd = Rc::new(RefCell::new(Tcpd::new(scheme_file, tcp_file, time_file))); - - let mut event_queue = EventQueue::<()>::new().expect("tcpd: failed to create event queue"); - - let time_tcpd = tcpd.clone(); - event_queue.add(time_fd, move |_count: usize| -> io::Result> { - time_tcpd.borrow_mut().time_event()?; - Ok(None) - }).expect("tcpd: failed to listen to events on time:"); - - let tcp_tcpd = tcpd.clone(); - event_queue.add(tcp_fd, move |_count: usize| -> io::Result> { - tcp_tcpd.borrow_mut().tcp_event()?; - Ok(None) - }).expect("tcpd: failed to listen to events on ip:6"); - - event_queue.add(scheme_fd, move |_count: usize| -> io::Result> { - tcpd.borrow_mut().scheme_event()?; - Ok(None) - }).expect("tcpd: failed to listen to events on :tcp"); - - event_queue.trigger_all(0).expect("tcpd: failed to trigger event queue"); - - event_queue.run().expect("tcpd: failed to run event queue"); -} - -fn main() { - let time_path = format!("time:{}", CLOCK_MONOTONIC); - match syscall::open(&time_path, O_RDWR) { - Ok(time_fd) => { - println!("tcpd: opening ip:6"); - match syscall::open("ip:6", O_RDWR | O_NONBLOCK) { - Ok(tcp_fd) => { - // Daemonize - if unsafe { syscall::clone(0).unwrap() } == 0 { - println!("tcpd: providing tcp:"); - match syscall::open(":tcp", O_RDWR | O_CREAT | O_NONBLOCK) { - Ok(scheme_fd) => { - daemon(scheme_fd as RawFd, tcp_fd as RawFd, time_fd as RawFd); - }, - Err(err) => { - println!("tcpd: failed to create tcp scheme: {}", err); - process::exit(1); - } - } - } - }, - Err(err) => { - println!("tcpd: failed to open ip:6: {}", err); - process::exit(1); - } - } - }, - Err(err) => { - println!("tcpd: failed to open {}: {}", time_path, err); - process::exit(1); - } - } -} diff --git a/src/udpd/main.rs b/src/udpd/main.rs deleted file mode 100644 index cfcf4d94d0..0000000000 --- a/src/udpd/main.rs +++ /dev/null @@ -1,588 +0,0 @@ -extern crate event; -extern crate netutils; -extern crate rand; -extern crate syscall; - -use rand::{Rng, OsRng}; -use std::collections::{BTreeMap, VecDeque}; -use std::cell::RefCell; -use std::fs::File; -use std::io::{self, Read, Write}; -use std::{mem, process, slice, str}; -use std::ops::{Deref, DerefMut}; -use std::os::unix::io::{RawFd, FromRawFd}; -use std::rc::Rc; - -use event::EventQueue; -use netutils::{n16, Ipv4, Ipv4Addr, Ipv4Header, Checksum}; -use netutils::udp::{Udp, UdpHeader}; -use syscall::data::{Packet, TimeSpec}; -use syscall::error::{Error, Result, EACCES, EADDRINUSE, EBADF, EIO, EINVAL, EMSGSIZE, ENOTCONN, ETIMEDOUT, EWOULDBLOCK}; -use syscall::flag::{CLOCK_MONOTONIC, EVENT_READ, F_GETFL, F_SETFL, O_ACCMODE, O_CREAT, O_RDWR, O_NONBLOCK}; -use syscall::number::{SYS_READ, SYS_WRITE}; -use syscall::scheme::SchemeMut; - -fn add_time(a: &TimeSpec, b: &TimeSpec) -> TimeSpec { - let mut secs = a.tv_sec + b.tv_sec; - - let mut nsecs = a.tv_nsec + b.tv_nsec; - while nsecs >= 1000000000 { - nsecs -= 1000000000; - secs += 1; - } - - TimeSpec { - tv_sec: secs, - tv_nsec: nsecs - } -} - -fn parse_socket(socket: &str) -> (Ipv4Addr, u16) { - let mut socket_parts = socket.split(":"); - let host = Ipv4Addr::from_str(socket_parts.next().unwrap_or("")); - let port = socket_parts.next().unwrap_or("").parse::().unwrap_or(0); - (host, port) -} - -struct UdpHandle { - local: (Ipv4Addr, u16), - remote: (Ipv4Addr, u16), - flags: usize, - events: usize, - read_timeout: Option, - write_timeout: Option, - ttl: u8, - data: VecDeque>, - todo: VecDeque<(Option, Packet)>, -} - -#[derive(Copy, Clone)] -enum SettingKind { - Ttl, - ReadTimeout, - WriteTimeout -} - -enum Handle { - Udp(UdpHandle), - Setting(usize, SettingKind), -} - -struct Udpd { - scheme_file: File, - udp_file: File, - time_file: File, - ports: BTreeMap, - next_id: usize, - handles: BTreeMap, - rng: OsRng, -} - -impl Udpd { - fn new(scheme_file: File, udp_file: File, time_file: File) -> Self { - Udpd { - scheme_file: scheme_file, - udp_file: udp_file, - time_file: time_file, - ports: BTreeMap::new(), - next_id: 1, - handles: BTreeMap::new(), - rng: OsRng::new().expect("udpd: failed to open RNG") - } - } - - fn scheme_event(&mut self) -> io::Result<()> { - loop { - let mut packet = Packet::default(); - if self.scheme_file.read(&mut packet)? == 0 { - break; - } - - let a = packet.a; - self.handle(&mut packet); - if packet.a == (-EWOULDBLOCK) as usize { - packet.a = a; - if let Some(mut handle) = self.handles.get_mut(&packet.b) { - if let Handle::Udp(ref mut handle) = *handle { - let timeout = match packet.a { - SYS_READ => match handle.read_timeout { - Some(read_timeout) => { - let mut time = TimeSpec::default(); - syscall::clock_gettime(CLOCK_MONOTONIC, &mut time).map_err(|err| io::Error::from_raw_os_error(err.errno))?; - - let timeout = add_time(&time, &read_timeout); - self.time_file.write(&timeout)?; - Some(timeout) - }, - None => None - }, - SYS_WRITE => match handle.write_timeout { - Some(write_timeout) => { - let mut time = TimeSpec::default(); - syscall::clock_gettime(CLOCK_MONOTONIC, &mut time).map_err(|err| io::Error::from_raw_os_error(err.errno))?; - - let timeout = add_time(&time, &write_timeout); - self.time_file.write(&timeout)?; - Some(timeout) - }, - None => None - }, - _ => None - }; - - handle.todo.push_back((timeout, packet)); - } - } - } else { - self.scheme_file.write(&packet)?; - } - } - - Ok(()) - } - - fn udp_event(&mut self) -> io::Result<()> { - loop { - let mut bytes = [0; 65536]; - let count = self.udp_file.read(&mut bytes)?; - if count == 0 { - break; - } - if let Some(ip) = Ipv4::from_bytes(&bytes[.. count]) { - if let Some(udp) = Udp::from_bytes(&ip.data) { - for (id, handle) in self.handles.iter_mut() { - if let Handle::Udp(ref mut handle) = *handle { - // Local address not set or IP dst matches or is broadcast - if (handle.local.0 == Ipv4Addr::NULL || ip.header.dst == handle.local.0 || ip.header.dst == Ipv4Addr::BROADCAST) - // Local port matches UDP dst - && udp.header.dst.get() == handle.local.1 - // Remote address not set or is broadcast, or IP src matches - && (handle.remote.0 == Ipv4Addr::NULL || handle.remote.0 == Ipv4Addr::BROADCAST || ip.header.src == handle.remote.0) - // Remote port not set or UDP src matches - && (handle.remote.1 == 0 || udp.header.src.get() == handle.remote.1) - { - handle.data.push_back(udp.data.clone()); - - while ! handle.todo.is_empty() && ! handle.data.is_empty() { - let (_timeout, mut packet) = handle.todo.pop_front().unwrap(); - let buf = unsafe { slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) }; - let data = handle.data.pop_front().unwrap(); - - let mut i = 0; - while i < buf.len() && i < data.len() { - buf[i] = data[i]; - i += 1; - } - packet.a = i; - - self.scheme_file.write(&packet)?; - } - - if handle.events & EVENT_READ == EVENT_READ { - if let Some(data) = handle.data.get(0) { - self.scheme_file.write(&Packet { - id: 0, - pid: 0, - uid: 0, - gid: 0, - a: syscall::number::SYS_FEVENT, - b: *id, - c: EVENT_READ, - d: data.len() - })?; - } - } - } - } - } - } - } - } - - Ok(()) - } - - fn time_event(&mut self) -> io::Result<()> { - let mut time = TimeSpec::default(); - if self.time_file.read(&mut time)? < mem::size_of::() { - return Err(io::Error::from_raw_os_error(EINVAL)); - } - - for (_id, handle) in self.handles.iter_mut() { - if let Handle::Udp(ref mut handle) = *handle { - let mut i = 0; - while i < handle.todo.len() { - if let Some(timeout) = handle.todo.get(i).map(|e| e.0.clone()).unwrap_or(None) { - if time.tv_sec > timeout.tv_sec || (time.tv_sec == timeout.tv_sec && time.tv_nsec >= timeout.tv_nsec) { - let (_timeout, mut packet) = handle.todo.remove(i).unwrap(); - packet.a = (-ETIMEDOUT) as usize; - self.scheme_file.write(&packet)?; - } else { - i += 1; - } - } else { - i += 1; - } - } - } - } - - Ok(()) - } -} - -impl SchemeMut for Udpd { - fn open(&mut self, url: &[u8], flags: usize, uid: u32, _gid: u32) -> Result { - let path = str::from_utf8(url).or(Err(Error::new(EINVAL)))?; - - let mut parts = path.split("/"); - let remote = parse_socket(parts.next().unwrap_or("")); - let mut local = parse_socket(parts.next().unwrap_or("")); - - if local.1 == 0 { - local.1 = self.rng.gen_range(32768, 65535); - } - - if local.1 <= 1024 && uid != 0 { - return Err(Error::new(EACCES)); - } - - if self.ports.contains_key(&local.1) { - return Err(Error::new(EADDRINUSE)); - } - - self.ports.insert(local.1, 1); - - let id = self.next_id; - self.next_id += 1; - - self.handles.insert(id, Handle::Udp(UdpHandle { - local: local, - remote: remote, - flags: flags, - events: 0, - ttl: 64, - read_timeout: None, - write_timeout: None, - data: VecDeque::new(), - todo: VecDeque::new(), - })); - - Ok(id) - } - - fn dup(&mut self, file: usize, buf: &[u8]) -> Result { - let handle = match *self.handles.get(&file).ok_or(Error::new(EBADF))? { - Handle::Udp(ref handle) => { - let mut handle = UdpHandle { - local: handle.local, - remote: handle.remote, - flags: handle.flags, - events: 0, - ttl: handle.ttl, - read_timeout: handle.read_timeout, - write_timeout: handle.write_timeout, - data: handle.data.clone(), - todo: VecDeque::new(), - }; - - let path = str::from_utf8(buf).or(Err(Error::new(EINVAL)))?; - - if path == "ttl" { - Handle::Setting(file, SettingKind::Ttl) - } else if path == "read_timeout" { - Handle::Setting(file, SettingKind::ReadTimeout) - } else if path == "write_timeout" { - Handle::Setting(file, SettingKind::WriteTimeout) - } else { - if handle.remote.0 == Ipv4Addr::NULL || handle.remote.1 == 0 { - handle.remote = parse_socket(path); - } - - if let Some(mut port) = self.ports.get_mut(&handle.local.1) { - *port = *port + 1; - } - - Handle::Udp(handle) - } - }, - Handle::Setting(file, kind) => { - Handle::Setting(file, kind) - } - }; - - let id = self.next_id; - self.next_id += 1; - - self.handles.insert(id, handle); - - Ok(id) - } - - fn read(&mut self, file: usize, buf: &mut [u8]) -> Result { - let (file, kind) = match *self.handles.get_mut(&file).ok_or(Error::new(EBADF))? { - Handle::Udp(ref mut handle) => { - if handle.remote.0 == Ipv4Addr::NULL || handle.remote.1 == 0 { - return Err(Error::new(ENOTCONN)); - } else if let Some(data) = handle.data.pop_front() { - let mut i = 0; - while i < buf.len() && i < data.len() { - buf[i] = data[i]; - i += 1; - } - - return Ok(i); - } else if handle.flags & O_NONBLOCK == O_NONBLOCK { - return Ok(0); - } else { - return Err(Error::new(EWOULDBLOCK)); - } - }, - Handle::Setting(file, kind) => { - (file, kind) - } - }; - - if let Handle::Udp(ref mut handle) = *self.handles.get_mut(&file).ok_or(Error::new(EBADF))? { - let get_timeout = |timeout: &Option, buf: &mut [u8]| -> Result { - if let Some(ref timespec) = *timeout { - timespec.deref().read(buf).map_err(|err| Error::new(err.raw_os_error().unwrap_or(EIO))) - } else { - Ok(0) - } - }; - - match kind { - SettingKind::Ttl => { - if let Some(mut ttl) = buf.get_mut(0) { - *ttl = handle.ttl; - Ok(1) - } else { - Ok(0) - } - }, - SettingKind::ReadTimeout => { - get_timeout(&handle.read_timeout, buf) - }, - SettingKind::WriteTimeout => { - get_timeout(&handle.write_timeout, buf) - } - } - } else { - Err(Error::new(EBADF)) - } - } - - fn write(&mut self, file: usize, buf: &[u8]) -> Result { - let (file, kind) = match *self.handles.get(&file).ok_or(Error::new(EBADF))? { - Handle::Udp(ref handle) => { - if handle.remote.0 == Ipv4Addr::NULL || handle.remote.1 == 0 { - return Err(Error::new(ENOTCONN)); - } else if buf.len() >= 65507 { - return Err(Error::new(EMSGSIZE)); - } else { - let udp_data = buf.to_vec(); - - let udp = Udp { - header: UdpHeader { - src: n16::new(handle.local.1), - dst: n16::new(handle.remote.1), - len: n16::new((udp_data.len() + mem::size_of::()) as u16), - checksum: Checksum { data: 0 } - }, - data: udp_data - }; - - let ip_data = udp.to_bytes(); - - let ip = Ipv4 { - header: Ipv4Header { - ver_hlen: 0x45, - services: 0, - len: n16::new((ip_data.len() + mem::size_of::()) as u16), - id: n16::new(self.rng.gen()), - flags_fragment: n16::new(0), - ttl: handle.ttl, - proto: 0x11, - checksum: Checksum { data: 0 }, - src: handle.local.0, - dst: handle.remote.0 - }, - options: Vec::new(), - data: ip_data - }; - - return self.udp_file.write(&ip.to_bytes()).map_err(|err| Error::new(err.raw_os_error().unwrap_or(EIO))).and(Ok(buf.len())); - } - }, - Handle::Setting(file, kind) => { - (file, kind) - } - }; - - if let Handle::Udp(ref mut handle) = *self.handles.get_mut(&file).ok_or(Error::new(EBADF))? { - let set_timeout = |timeout: &mut Option, buf: &[u8]| -> Result { - if buf.len() >= mem::size_of::() { - let mut timespec = TimeSpec::default(); - let count = timespec.deref_mut().write(buf).map_err(|err| Error::new(err.raw_os_error().unwrap_or(EIO)))?; - *timeout = Some(timespec); - Ok(count) - } else { - *timeout = None; - Ok(0) - } - }; - - match kind { - SettingKind::Ttl => { - if let Some(ttl) = buf.get(0) { - handle.ttl = *ttl; - Ok(1) - } else { - Ok(0) - } - }, - SettingKind::ReadTimeout => { - set_timeout(&mut handle.read_timeout, buf) - }, - SettingKind::WriteTimeout => { - set_timeout(&mut handle.write_timeout, buf) - } - } - } else { - Err(Error::new(EBADF)) - } - } - - fn fcntl(&mut self, file: usize, cmd: usize, arg: usize) -> Result { - if let Handle::Udp(ref mut handle) = *self.handles.get_mut(&file).ok_or(Error::new(EBADF))? { - match cmd { - F_GETFL => Ok(handle.flags), - F_SETFL => { - handle.flags = arg & ! O_ACCMODE; - Ok(0) - }, - _ => Err(Error::new(EINVAL)) - } - } else { - Err(Error::new(EBADF)) - } - } - - fn fevent(&mut self, file: usize, flags: usize) -> Result { - if let Handle::Udp(ref mut handle) = *self.handles.get_mut(&file).ok_or(Error::new(EBADF))? { - handle.events = flags; - Ok(file) - } else { - Err(Error::new(EBADF)) - } - } - - fn fpath(&mut self, file: usize, buf: &mut [u8]) -> Result { - if let Handle::Udp(ref mut handle) = *self.handles.get_mut(&file).ok_or(Error::new(EBADF))? { - let path_string = format!("udp:{}:{}/{}:{}", handle.remote.0.to_string(), handle.remote.1, handle.local.0.to_string(), handle.local.1); - let path = path_string.as_bytes(); - - let mut i = 0; - while i < buf.len() && i < path.len() { - buf[i] = path[i]; - i += 1; - } - - Ok(i) - } else { - Err(Error::new(EBADF)) - } - } - - fn fsync(&mut self, file: usize) -> Result { - let _handle = self.handles.get(&file).ok_or(Error::new(EBADF))?; - - Ok(0) - } - - fn close(&mut self, file: usize) -> Result { - let handle = self.handles.remove(&file).ok_or(Error::new(EBADF))?; - - if let Handle::Udp(ref handle) = handle { - let remove = if let Some(mut port) = self.ports.get_mut(&handle.local.1) { - *port = *port + 1; - *port == 0 - } else { - false - }; - - if remove { - drop(self.ports.remove(&handle.local.1)); - } - } - - drop(handle); - - Ok(0) - } -} -fn daemon(scheme_fd: RawFd, udp_fd: RawFd, time_fd: RawFd) { - let scheme_file = unsafe { File::from_raw_fd(scheme_fd) }; - let udp_file = unsafe { File::from_raw_fd(udp_fd) }; - let time_file = unsafe { File::from_raw_fd(time_fd) }; - - let udpd = Rc::new(RefCell::new(Udpd::new(scheme_file, udp_file, time_file))); - - let mut event_queue = EventQueue::<()>::new().expect("udpd: failed to create event queue"); - - let time_udpd = udpd.clone(); - event_queue.add(time_fd, move |_count: usize| -> io::Result> { - time_udpd.borrow_mut().time_event()?; - Ok(None) - }).expect("udpd: failed to listen to events on time:"); - - let udp_udpd = udpd.clone(); - event_queue.add(udp_fd, move |_count: usize| -> io::Result> { - udp_udpd.borrow_mut().udp_event()?; - Ok(None) - }).expect("udpd: failed to listen to events on ip:11"); - - event_queue.add(scheme_fd, move |_count: usize| -> io::Result> { - udpd.borrow_mut().scheme_event()?; - Ok(None) - }).expect("udpd: failed to listen to events on :udp"); - - event_queue.trigger_all(0).expect("udpd: failed to trigger event queue"); - - event_queue.run().expect("udpd: failed to run event queue"); -} - -fn main() { - let time_path = format!("time:{}", CLOCK_MONOTONIC); - match syscall::open(&time_path, O_RDWR) { - Ok(time_fd) => { - println!("udpd: opening ip:11"); - match syscall::open("ip:11", O_RDWR | O_NONBLOCK) { - Ok(udp_fd) => { - // Daemonize - if unsafe { syscall::clone(0).unwrap() } == 0 { - println!("udpd: providing udp:"); - match syscall::open(":udp", O_RDWR | O_CREAT | O_NONBLOCK) { - Ok(scheme_fd) => { - daemon(scheme_fd as RawFd, udp_fd as RawFd, time_fd as RawFd); - }, - Err(err) => { - println!("udpd: failed to create udp scheme: {}", err); - process::exit(1); - } - } - } - }, - Err(err) => { - println!("udpd: failed to open ip:11: {}", err); - process::exit(1); - } - } - }, - Err(err) => { - println!("udpd: failed to open {}: {}", time_path, err); - process::exit(1); - } - } -} From e4fef618653607f8e33658bf13b64549fcc415b6 Mon Sep 17 00:00:00 2001 From: Egor Karavaev Date: Sat, 4 Nov 2017 15:44:55 +0300 Subject: [PATCH 053/155] Update for new Device trait. --- Cargo.lock | 6 +-- Cargo.toml | 2 +- src/smolnetd/device.rs | 100 ++++++++++++++++++++++++----------------- 3 files changed, 63 insertions(+), 45 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cbb61bcc90..07d2ef2b3f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -260,7 +260,7 @@ dependencies = [ "rand 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)", "redox_event 0.1.0 (git+https://github.com/redox-os/event.git)", "redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", - "smoltcp 0.4.0 (git+https://github.com/redox-os/smoltcp.git)", + "smoltcp 0.4.0 (git+https://github.com/m-labs/smoltcp.git)", ] [[package]] @@ -314,7 +314,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "smoltcp" version = "0.4.0" -source = "git+https://github.com/redox-os/smoltcp.git#a6fc036ad65e07523e271304bb96d99a9f9a2707" +source = "git+https://github.com/m-labs/smoltcp.git#fd7109b2e4352db6e1ad919780c770c4fdb7a72d" dependencies = [ "byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "managed 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -461,7 +461,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum rustls 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "17727f4b991294da2c84d75a43c003151ff58072212768800f66c56ee46dca43" "checksum safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e27a8b19b835f7aea908818e871f5cc3a5a186550c30773be987e155e8163d8f" "checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" -"checksum smoltcp 0.4.0 (git+https://github.com/redox-os/smoltcp.git)" = "" +"checksum smoltcp 0.4.0 (git+https://github.com/m-labs/smoltcp.git)" = "" "checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" "checksum time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)" = "d5d788d3aa77bc0ef3e9621256885555368b47bd495c13dd2e7413c89f845520" "checksum traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079" diff --git a/Cargo.toml b/Cargo.toml index 1b5fa8329e..7a979767f9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,6 +22,6 @@ default-features = false features = ["release_max_level_off"] [dependencies.smoltcp] -git = "https://github.com/redox-os/smoltcp.git" +git = "https://github.com/m-labs/smoltcp.git" default-features = false features = ["std", "proto-raw", "proto-udp", "proto-tcp"] diff --git a/src/smolnetd/device.rs b/src/smolnetd/device.rs index a62d3741b1..08ab9228f6 100644 --- a/src/smolnetd/device.rs +++ b/src/smolnetd/device.rs @@ -8,13 +8,17 @@ use std::rc::Rc; use buffer_pool::{Buffer, BufferPool}; use arp_cache::LOOPBACK_HWADDR; -pub struct NetworkDevice { +struct NetworkDeviceData { network_file: Rc>, input_queue: Rc>>, local_hwaddr: smoltcp::wire::EthernetAddress, buffer_pool: Rc>, } +pub struct NetworkDevice { + data: Rc>, +} + impl NetworkDevice { pub const MTU: usize = 1520; @@ -25,57 +29,67 @@ impl NetworkDevice { buffer_pool: Rc>, ) -> NetworkDevice { NetworkDevice { - network_file, - input_queue, - local_hwaddr, - buffer_pool, + data: Rc::new(RefCell::new(NetworkDeviceData { + network_file, + input_queue, + local_hwaddr, + buffer_pool, + })), } } } -pub struct TxBuffer { +pub struct RxToken { buffer: Buffer, - network_file: Rc>, - input_queue: Rc>>, - local_hwaddr: smoltcp::wire::EthernetAddress, } -impl AsRef<[u8]> for TxBuffer { - fn as_ref(&self) -> &[u8] { - self.buffer.as_ref() +impl smoltcp::phy::RxToken for RxToken { + fn consume(self, _timestamp: u64, f: F) -> smoltcp::Result + where + F: FnOnce(&[u8]) -> smoltcp::Result, + { + f(&self.buffer) } } -impl AsMut<[u8]> for TxBuffer { - fn as_mut(&mut self) -> &mut [u8] { - self.buffer.as_mut() - } +pub struct TxToken { + data: Rc>, } -impl Drop for TxBuffer { - fn drop(&mut self) { +impl smoltcp::phy::TxToken for TxToken { + fn consume(self, _timestamp: u64, len: usize, f: F) -> smoltcp::Result + where + F: FnOnce(&mut [u8]) -> smoltcp::Result, + { + let data = self.data.borrow_mut(); + let mut buffer = data.buffer_pool.borrow_mut().get_buffer(); + buffer.resize(len); + let res = f(&mut buffer)?; + let mut loopback = false; - - if let Ok(mut frame) = smoltcp::wire::EthernetFrame::new_checked(&mut self.buffer) { + if let Ok(mut frame) = smoltcp::wire::EthernetFrame::new_checked(&mut buffer) { if frame.dst_addr() == LOOPBACK_HWADDR { - frame.set_dst_addr(self.local_hwaddr); + frame.set_dst_addr(data.local_hwaddr); loopback = true; } } if loopback { - self.input_queue - .borrow_mut() - .push_back(self.buffer.move_out()); + data.input_queue.borrow_mut().push_back(buffer.move_out()); } else { - let _ = self.network_file.borrow_mut().write(&self.buffer); + data.network_file + .borrow_mut() + .write(&buffer) + .map_err(|_| smoltcp::Error::Dropped)?; } + + Ok(res) } } -impl smoltcp::phy::Device for NetworkDevice { - type RxBuffer = Buffer; - type TxBuffer = TxBuffer; +impl<'a> smoltcp::phy::Device<'a> for NetworkDevice { + type RxToken = RxToken; + type TxToken = TxToken; fn capabilities(&self) -> smoltcp::phy::DeviceCapabilities { let mut limits = smoltcp::phy::DeviceCapabilities::default(); @@ -84,21 +98,25 @@ impl smoltcp::phy::Device for NetworkDevice { limits } - fn receive(&mut self, _timestamp: u64) -> smoltcp::Result { - self.input_queue - .borrow_mut() - .pop_front() - .ok_or(smoltcp::Error::Exhausted) + fn receive(&'a mut self) -> Option<(Self::RxToken, Self::TxToken)> { + let data = self.data.borrow_mut(); + let buffer = data.input_queue.borrow_mut().pop_front(); + + if let Some(buffer) = buffer { + Some(( + RxToken { buffer }, + TxToken { + data: Rc::clone(&self.data), + }, + )) + } else { + None + } } - fn transmit(&mut self, _timestamp: u64, length: usize) -> smoltcp::Result { - let mut buffer = self.buffer_pool.borrow_mut().get_buffer(); - buffer.resize(length); - Ok(TxBuffer { - network_file: Rc::clone(&self.network_file), - buffer, - input_queue: Rc::clone(&self.input_queue), - local_hwaddr: self.local_hwaddr, + fn transmit(&'a mut self) -> Option { + Some(TxToken { + data: Rc::clone(&self.data), }) } } From 7b9b15c37fc6d1d7d6b97c797f234b4536feafc0 Mon Sep 17 00:00:00 2001 From: Egor Karavaev Date: Fri, 10 Nov 2017 22:26:58 +0300 Subject: [PATCH 054/155] Updating upstream smoltcp. --- Cargo.lock | 29 +++++++++++------------------ Cargo.toml | 5 ++++- src/smolnetd/device.rs | 2 +- src/smolnetd/scheme/mod.rs | 4 ++-- 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 07d2ef2b3f..78529cd399 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -62,11 +62,6 @@ dependencies = [ "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "futures" -version = "0.1.16" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "gcc" version = "0.3.54" @@ -92,7 +87,7 @@ dependencies = [ "traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "typeable 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "unicase 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "url 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -215,7 +210,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "rand" -version = "0.3.17" +version = "0.3.18" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "fuchsia-zircon 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -227,20 +222,19 @@ name = "rayon" version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "rayon-core 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rayon-core 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rayon-core" -version = "1.2.1" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "coco 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -257,7 +251,7 @@ version = "0.1.0" dependencies = [ "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "netutils 0.1.0 (git+https://github.com/redox-os/netutils.git)", - "rand 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)", "redox_event 0.1.0 (git+https://github.com/redox-os/event.git)", "redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", "smoltcp 0.4.0 (git+https://github.com/m-labs/smoltcp.git)", @@ -314,7 +308,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "smoltcp" version = "0.4.0" -source = "git+https://github.com/m-labs/smoltcp.git#fd7109b2e4352db6e1ad919780c770c4fdb7a72d" +source = "git+https://github.com/m-labs/smoltcp.git#ef4af850e0981b2b200605bb1b7b526017fd2cd9" dependencies = [ "byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "managed 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -379,7 +373,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "url" -version = "1.5.1" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "idna 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -432,7 +426,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum extra 0.1.0 (git+https://github.com/redox-os/libextra.git)" = "" "checksum fuchsia-zircon 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f6c0581a4e363262e52b87f59ee2afe3415361c6ec35e665924eb08afe8ff159" "checksum fuchsia-zircon-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "43f3795b4bae048dc6123a6b972cadde2e676f9ded08aef6bb77f5f157684a82" -"checksum futures 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "05a23db7bd162d4e8265968602930c476f688f0c180b44bdaf55e0cb2c687558" "checksum gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)" = "5e33ec290da0d127825013597dbdfc28bee4964690c7ce1166cbc2a7bd08b1bb" "checksum httparse 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "af2f2dd97457e8fb1ae7c5a420db346af389926e36f43768b96f101546b04a07" "checksum hyper 0.10.13 (registry+https://github.com/rust-lang/crates.io-index)" = "368cb56b2740ebf4230520e2b90ebb0461e69034d85d1945febd9b3971426db2" @@ -451,9 +444,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum num_cpus 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "514f0d73e64be53ff320680ca671b64fe3fb91da01e1ae2ddc99eb51d453b20d" "checksum pbr 1.0.0 (git+https://github.com/a8m/pb)" = "" "checksum percent-encoding 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "de154f638187706bde41d9b4738748933d64e6b37bdbffc0b47a97d16a6ae356" -"checksum rand 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)" = "61efcbcd9fa8d8fbb07c84e34a8af18a1ff177b449689ad38a6e9457ecc7b2ae" +"checksum rand 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)" = "6475140dfd8655aeb72e1fd4b7a1cc1c202be65d71669476e392fe62532b9edd" "checksum rayon 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a77c51c07654ddd93f6cb543c7a849863b03abc7e82591afda6dc8ad4ac3ac4a" -"checksum rayon-core 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7febc28567082c345f10cddc3612c6ea020fc3297a1977d472cf9fdb73e6e493" +"checksum rayon-core 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e64b609139d83da75902f88fd6c01820046840a18471e4dfcd5ac7c0f46bea53" "checksum redox_event 0.1.0 (git+https://github.com/redox-os/event.git)" = "" "checksum redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)" = "8dde11f18c108289bef24469638a04dce49da56084f2d50618b226e47eb04509" "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" @@ -470,7 +463,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" "checksum unicode-normalization 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "51ccda9ef9efa3f7ef5d91e8f9b83bbe6955f9bf86aec89d5cce2c874625920f" "checksum untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f392d7819dbe58833e26872f5f6f0d68b7bbbe90fc3667e98731c4a15ad9a7ae" -"checksum url 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "eeb819346883532a271eb626deb43c4a1bb4c4dd47c519bd78137c3e72a4fe27" +"checksum url 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fa35e768d4daf1d85733418a49fb42e10d7f633e394fccab4ab7aba897053fe2" "checksum version_check 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6b772017e347561807c1aa192438c5fd74242a670a6cffacc40f2defd1dc069d" "checksum webpki 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e499345fc4c6b7c79a5b8756d4592c4305510a13512e79efafe00dfbd67bbac6" "checksum webpki-roots 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5bfb3f50499f21ad2317f442845e3b5805b007f1e728f59885c99e61b8c181a7" diff --git a/Cargo.toml b/Cargo.toml index 7a979767f9..8add68a1b9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,4 +24,7 @@ features = ["release_max_level_off"] [dependencies.smoltcp] git = "https://github.com/m-labs/smoltcp.git" default-features = false -features = ["std", "proto-raw", "proto-udp", "proto-tcp"] +features = ["std", "socket-raw", "socket-udp", "socket-tcp", "socket-icmp"] + +[profile.release] +lto = true diff --git a/src/smolnetd/device.rs b/src/smolnetd/device.rs index 08ab9228f6..092df0c598 100644 --- a/src/smolnetd/device.rs +++ b/src/smolnetd/device.rs @@ -94,7 +94,7 @@ impl<'a> smoltcp::phy::Device<'a> for NetworkDevice { fn capabilities(&self) -> smoltcp::phy::DeviceCapabilities { let mut limits = smoltcp::phy::DeviceCapabilities::default(); limits.max_transmission_unit = Self::MTU; - limits.max_burst_size = Some(5); + limits.max_burst_size = Some(20); limits } diff --git a/src/smolnetd/scheme/mod.rs b/src/smolnetd/scheme/mod.rs index de6787519f..9a15d7dc58 100644 --- a/src/smolnetd/scheme/mod.rs +++ b/src/smolnetd/scheme/mod.rs @@ -32,7 +32,7 @@ pub struct Smolnetd { network_file: Rc>, time_file: File, - iface: EthernetInterface<'static, 'static, 'static, NetworkDevice>, + iface: EthernetInterface<'static, 'static, NetworkDevice>, socket_set: Rc>, startup_time: Instant, @@ -81,7 +81,7 @@ impl Smolnetd { ); let arp_cache = LoArpCache::new(protocol_addrs.iter().map(IpCidr::address)); let iface = EthernetInterface::new( - Box::new(network_device), + network_device, Box::new(arp_cache) as Box, hardware_addr, protocol_addrs, From 337f318f6f352503b0c8f2f8492ba6fe315b19ab Mon Sep 17 00:00:00 2001 From: Egor Karavaev Date: Sun, 12 Nov 2017 12:52:21 +0300 Subject: [PATCH 055/155] Implement `icmp:` schema in smolnetd, remove icmpd. --- Cargo.lock | 15 +- Cargo.toml | 7 +- src/icmpd/error.rs | 92 ---------- src/icmpd/main.rs | 79 --------- src/icmpd/packet.rs | 212 ----------------------- src/icmpd/scheme.rs | 309 ---------------------------------- src/smolnetd/main.rs | 19 ++- src/smolnetd/scheme/icmp.rs | 225 +++++++++++++++++++++++++ src/smolnetd/scheme/ip.rs | 3 +- src/smolnetd/scheme/mod.rs | 15 +- src/smolnetd/scheme/socket.rs | 43 ++--- 11 files changed, 286 insertions(+), 733 deletions(-) delete mode 100644 src/icmpd/error.rs delete mode 100644 src/icmpd/main.rs delete mode 100644 src/icmpd/packet.rs delete mode 100644 src/icmpd/scheme.rs create mode 100644 src/smolnetd/scheme/icmp.rs diff --git a/Cargo.lock b/Cargo.lock index 78529cd399..f65b98584f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -205,7 +205,7 @@ dependencies = [ [[package]] name = "percent-encoding" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -251,12 +251,16 @@ version = "0.1.0" dependencies = [ "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "netutils 0.1.0 (git+https://github.com/redox-os/netutils.git)", - "rand 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)", "redox_event 0.1.0 (git+https://github.com/redox-os/event.git)", - "redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.31 (git+https://github.com/redox-os/syscall.git)", "smoltcp 0.4.0 (git+https://github.com/m-labs/smoltcp.git)", ] +[[package]] +name = "redox_syscall" +version = "0.1.31" +source = "git+https://github.com/redox-os/syscall.git#71c51bdbbbac3500074a8ed15a2912f38ee7a0f6" + [[package]] name = "redox_syscall" version = "0.1.31" @@ -378,7 +382,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "idna 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "percent-encoding 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -443,11 +447,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum ntpclient 0.0.1 (git+https://github.com/willem66745/ntpclient-rust)" = "" "checksum num_cpus 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "514f0d73e64be53ff320680ca671b64fe3fb91da01e1ae2ddc99eb51d453b20d" "checksum pbr 1.0.0 (git+https://github.com/a8m/pb)" = "" -"checksum percent-encoding 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "de154f638187706bde41d9b4738748933d64e6b37bdbffc0b47a97d16a6ae356" +"checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" "checksum rand 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)" = "6475140dfd8655aeb72e1fd4b7a1cc1c202be65d71669476e392fe62532b9edd" "checksum rayon 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a77c51c07654ddd93f6cb543c7a849863b03abc7e82591afda6dc8ad4ac3ac4a" "checksum rayon-core 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e64b609139d83da75902f88fd6c01820046840a18471e4dfcd5ac7c0f46bea53" "checksum redox_event 0.1.0 (git+https://github.com/redox-os/event.git)" = "" +"checksum redox_syscall 0.1.31 (git+https://github.com/redox-os/syscall.git)" = "" "checksum redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)" = "8dde11f18c108289bef24469638a04dce49da56084f2d50618b226e47eb04509" "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" "checksum ring 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1f2a6dc7fc06a05e6de183c5b97058582e9da2de0c136eafe49609769c507724" diff --git a/Cargo.toml b/Cargo.toml index 8add68a1b9..c35391d816 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,19 +2,14 @@ name = "redox_netstack" version = "0.1.0" -[[bin]] -name = "icmpd" -path = "src/icmpd/main.rs" - [[bin]] name = "smolnetd" path = "src/smolnetd/main.rs" [dependencies] netutils = { git = "https://github.com/redox-os/netutils.git" } -rand = "0.3" redox_event = { git = "https://github.com/redox-os/event.git" } -redox_syscall = "0.1" +redox_syscall = { git = "https://github.com/redox-os/syscall.git" } [dependencies.log] version = "0.3" diff --git a/src/icmpd/error.rs b/src/icmpd/error.rs deleted file mode 100644 index 8c94e2af8c..0000000000 --- a/src/icmpd/error.rs +++ /dev/null @@ -1,92 +0,0 @@ -use std::convert; -use std::fmt; -use std::io::Error as IOError; -use std::result; -use syscall::error::Error as SyscallError; - -pub enum PacketError { - NotEnoughData, - IncorrectChecksum, - NoEchoHeader, - SubheaderAlreadPresent, -} - -enum ErrorType { - Syscall(SyscallError), - IOError(IOError), - PacketError(PacketError), -} - -pub struct Error { - error_type: ErrorType, - descr: String, -} - -impl Error { - pub fn from_parsing_error>(parsing_error: PacketError, descr: S) -> Error { - Error { - error_type: ErrorType::PacketError(parsing_error), - descr: descr.into(), - } - } - pub fn from_syscall_error>(syscall_error: SyscallError, descr: S) -> Error { - Error { - error_type: ErrorType::Syscall(syscall_error), - descr: descr.into(), - } - } - - pub fn from_io_error>(io_error: IOError, descr: S) -> Error { - Error { - error_type: ErrorType::IOError(io_error), - descr: descr.into(), - } - } - - pub fn is_unrecoverable(&self) -> bool { - match self.error_type { - ErrorType::PacketError(_) => false, - ErrorType::IOError(_) | - ErrorType::Syscall(_) => true, - } - } -} - -impl fmt::Display for PacketError { - fn fmt(&self, f: &mut fmt::Formatter) -> result::Result<(), fmt::Error> { - write!(f, "{}", match *self { - PacketError::NotEnoughData => "not enough data", - PacketError::IncorrectChecksum => "checksum error", - PacketError::NoEchoHeader => "echo header is missing", - PacketError::SubheaderAlreadPresent => "subheader is already present", - }) - } -} - -impl fmt::Display for Error { - fn fmt(&self, f: &mut fmt::Formatter) -> result::Result<(), fmt::Error> { - match self.error_type { - ErrorType::Syscall(ref syscall_error) => { - write!(f, "{} : syscall error: {}", self.descr, syscall_error) - } - ErrorType::IOError(ref io_error) => { - write!(f, "{} : io error : {}", self.descr, io_error) - } - ErrorType::PacketError(ref parsign_error) => { - write!(f, - "{} : packet parsing error : {}", - self.descr, - parsign_error) - } - } - } -} - -impl convert::From for Error { - fn from(e: IOError) -> Self { - Error::from_io_error(e, "") - } -} - -pub type Result = result::Result; -pub type PacketResult = result::Result; diff --git a/src/icmpd/main.rs b/src/icmpd/main.rs deleted file mode 100644 index 4d5cb96728..0000000000 --- a/src/icmpd/main.rs +++ /dev/null @@ -1,79 +0,0 @@ -extern crate event; -extern crate syscall; -extern crate netutils; - -use error::{Result, Error}; -use event::EventQueue; -use scheme::Icmpd; -use std::cell::RefCell; -use std::fs::File; -use std::os::unix::io::{RawFd, FromRawFd}; -use std::process; -use std::rc::Rc; - -mod error; -mod packet; -mod scheme; - -fn run() -> Result<()> { - use syscall::flag::*; - - // if unsafe { syscall::clone(0).unwrap() } != 0 { - // return Ok(()); - // } - - println!("icmpd: opening ip:1:"); - let icmp_fd = syscall::open("ip:1", O_RDWR | O_NONBLOCK) - .map_err(|e| Error::from_syscall_error(e, "failed to open ip:1"))? as - RawFd; - - println!("icmpd: prividing icmp:"); - let scheme_fd = syscall::open(":icmp", O_RDWR | O_CREAT | O_NONBLOCK) - .map_err(|e| Error::from_syscall_error(e, "failed to open :icmp"))? as - RawFd; - - let icmpd = Rc::new(RefCell::new(Icmpd::new(unsafe { File::from_raw_fd(icmp_fd) }, - unsafe { File::from_raw_fd(scheme_fd) }))); - - let mut event_queue = - EventQueue::<(), Error>::new() - .map_err(|e| Error::from_io_error(e, "failed to create event queue"))?; - - let icmpd_ = icmpd.clone(); - - event_queue - .add(icmp_fd, move |_fd| { - if let Err(err) = icmpd_.borrow_mut().on_icmp_packet() { - if err.is_unrecoverable() { - return Err(err); - } else { - println!("icmpd: network error: {}", err); - } - } - Ok(None) - }) - .map_err(|e| Error::from_io_error(e, "failed to listen to events on ip:1"))?; - - event_queue - .add(scheme_fd, move |_fd| { - if let Err(err) = icmpd.borrow_mut().on_scheme_event() { - if err.is_unrecoverable() { - return Err(err); - } else { - println!("icmpd: scheme error: {}", err); - } - } - Ok(None) - }) - .map_err(|e| Error::from_io_error(e, "failed to listen to events on icmp"))?; - - event_queue.run() -} - -fn main() { - if let Err(err) = run() { - println!("icmpd: {}", err); - process::exit(1); - } - process::exit(0); -} diff --git a/src/icmpd/packet.rs b/src/icmpd/packet.rs deleted file mode 100644 index 0426d61d90..0000000000 --- a/src/icmpd/packet.rs +++ /dev/null @@ -1,212 +0,0 @@ -use error::{PacketResult, PacketError}; -use netutils::Checksum; -use std::mem; - -const ECHO_REQUEST_TYPE: u8 = 8; -const ECHO_REQUEST_CODE: u8 = 0; -const ECHO_RESPONSE_TYPE: u8 = 0; -const ECHO_RESPONSE_CODE: u8 = 0; -const UNREACHABLE_TYPE: u8 = 3; -const UNREACHABLE_HOST_CODE: u8 = 1; -const UNREACHABLE_PROTO_CODE: u8 = 2; -const UNREACHABLE_PORT_CODE: u8 = 3; - -#[repr(packed)] -pub struct Header { - icmp_type: u8, - icmp_code: u8, - crc: u16, -} - -#[derive(Copy, Clone)] -#[repr(packed)] -pub struct EchoHeader { - id: u16, - //Seq is set by the caller -} - -pub enum SubHeader<'a> { - Echo(&'a EchoHeader), - None, -} - -pub struct Packet<'a> { - header: &'a Header, - payload: &'a [u8], - subheader: SubHeader<'a>, -} - -pub struct MutPacket<'a> { - header: &'a mut Header, - payload: &'a mut [u8], - subheader: SubHeader<'a>, -} - -pub enum PacketKind { - EchoRequest, - EchoResponse, - HostUnreachable, - PortUnreachable, - ProtoUnreachable, - Unknown, -} - -impl EchoHeader { - pub fn new(id: u16) -> EchoHeader { - EchoHeader { id: id.to_be() } - } - - pub fn get_id(&self) -> u16 { - u16::from_be(self.id) - } -} - -impl<'a> SubHeader<'a> { - pub fn get_size(&self) -> usize { - match *self { - SubHeader::None => 0, - SubHeader::Echo(_) => mem::size_of::(), - } - } -} - -impl<'a> Packet<'a> { - pub fn from_bytes<'b>(bytes: &'b [u8]) -> PacketResult> - where 'b: 'a - { - if bytes.len() < mem::size_of::
() { - Err(PacketError::NotEnoughData) - } else { - let (header_bytes, payload_bytes) = bytes.split_at(mem::size_of::
()); - let mut packet = Packet { - header: unsafe { &*(header_bytes.as_ptr() as *const Header) }, - payload: payload_bytes, - subheader: SubHeader::None, - }; - if !packet.is_checksum_ok() { - return Err(PacketError::IncorrectChecksum); - } - match packet.get_kind() { - PacketKind::EchoResponse => { - if packet.payload.len() < mem::size_of::() { - return Err(PacketError::NoEchoHeader); - } - let (echo_header_payload, payload) = - packet.payload.split_at(mem::size_of::()); - packet.subheader = SubHeader::Echo(unsafe { - &*(echo_header_payload.as_ptr() as - *const EchoHeader) - }); - packet.payload = payload; - Ok(packet) - } - _ => Ok(packet), - } - } - } - - fn is_checksum_ok(&self) -> bool { - let header_ptr = self.header as *const Header as usize; - let total_size = self.get_total_data_size(); - let mut crc = unsafe { Checksum::sum(header_ptr, total_size) }; - crc -= u16::from_be(self.header.crc) as usize; - let crc = Checksum::compile(crc); - crc == u16::from_be(self.header.crc) - } - - pub fn get_kind(&self) -> PacketKind { - match (self.header.icmp_type, self.header.icmp_code) { - (ECHO_REQUEST_TYPE, ECHO_REQUEST_CODE) => PacketKind::EchoRequest, - (ECHO_RESPONSE_TYPE, ECHO_RESPONSE_CODE) => PacketKind::EchoResponse, - (UNREACHABLE_TYPE, UNREACHABLE_HOST_CODE) => PacketKind::HostUnreachable, - (UNREACHABLE_TYPE, UNREACHABLE_PROTO_CODE) => PacketKind::ProtoUnreachable, - (UNREACHABLE_TYPE, UNREACHABLE_PORT_CODE) => PacketKind::PortUnreachable, - _ => PacketKind::Unknown, - } - } - - pub fn get_payload(&self) -> &[u8] { - self.payload - } - - pub fn get_total_data_size(&self) -> usize { - mem::size_of::
() + self.subheader.get_size() + self.payload.len() - } - - pub fn get_subheader(&self) -> &SubHeader<'a> { - &self.subheader - } -} - -impl<'a> MutPacket<'a> { - pub fn from_bytes<'b>(bytes: &'b mut [u8]) -> PacketResult> - where 'b: 'a - { - if bytes.len() < mem::size_of::
() { - Err(PacketError::NotEnoughData) - } else { - let (header_bytes, payload_bytes) = bytes.split_at_mut(mem::size_of::
()); - Ok(MutPacket { - header: unsafe { &mut *(header_bytes.as_ptr() as *mut Header) }, - payload: payload_bytes, - subheader: SubHeader::None, - }) - } - } - - pub fn set_subheader(self, subheader: &SubHeader) -> PacketResult> { - match self.subheader { - SubHeader::None => {} - _ => return Err(PacketError::SubheaderAlreadPresent), - }; - - if self.payload.len() < subheader.get_size() { - return Err(PacketError::NotEnoughData); - } - - let (subheader_bytes, new_payload) = self.payload.split_at_mut(subheader.get_size()); - let new_subheader = match *subheader { - SubHeader::Echo(echo_sub_header) => { - let echo_sub_header_mut: &mut EchoHeader = - unsafe { &mut *(subheader_bytes.as_ptr() as *mut EchoHeader) }; - *echo_sub_header_mut = *echo_sub_header; - SubHeader::Echo(echo_sub_header_mut) - } - SubHeader::None => SubHeader::None, - }; - Ok(MutPacket { - header: self.header, - payload: new_payload, - subheader: new_subheader, - }) - } - - pub fn set_kind(&mut self, packet_type: PacketKind) { - let (new_type, new_code) = match packet_type { - PacketKind::EchoRequest => (ECHO_REQUEST_TYPE, ECHO_REQUEST_CODE), - PacketKind::EchoResponse => (ECHO_RESPONSE_TYPE, ECHO_RESPONSE_CODE), - PacketKind::HostUnreachable => (UNREACHABLE_TYPE, UNREACHABLE_HOST_CODE), - PacketKind::PortUnreachable => (UNREACHABLE_TYPE, UNREACHABLE_PORT_CODE), - PacketKind::ProtoUnreachable => (UNREACHABLE_TYPE, UNREACHABLE_PROTO_CODE), - PacketKind::Unknown => (self.header.icmp_type, self.header.icmp_code), - }; - self.header.icmp_type = new_type; - self.header.icmp_code = new_code; - } - - pub fn compute_checksum(&mut self) { - self.header.crc = 0; - let header_ptr = self.header as *mut Header as usize; - let total_size = Self::get_total_header_size(&self.subheader) + self.payload.len(); - let crc = Checksum::compile(unsafe { Checksum::sum(header_ptr, total_size) }); - self.header.crc = crc - } - - pub fn get_payload(&mut self) -> &mut [u8] { - self.payload - } - - pub fn get_total_header_size(subheader: &SubHeader) -> usize { - mem::size_of::
() + subheader.get_size() - } -} diff --git a/src/icmpd/scheme.rs b/src/icmpd/scheme.rs deleted file mode 100644 index 4f42e9a47f..0000000000 --- a/src/icmpd/scheme.rs +++ /dev/null @@ -1,309 +0,0 @@ -use error::{Result, Error, PacketError}; -use netutils::{Ipv4, Ipv4Header, Checksum, n16}; -use netutils; -use packet::{Packet, MutPacket, PacketKind, SubHeader, EchoHeader}; -use std::collections::{BTreeMap, HashSet, VecDeque}; -use std::fs::File; -use std::io::{Read, Write}; -use std::mem; -use std::net::Ipv4Addr; -use syscall::SchemeMut; -use syscall; - -//Some reasonable limits, 65k is a waste of memory -const MAX_PACKET_SIZE: usize = 2048; -const MAX_ICMP_PAYLOAD_SIZE: usize = 2000; - -enum HandleType { - Echo, -} - -struct Handle { - handle_type: HandleType, - events: usize, - flags: usize, - ip_addr: Ipv4Addr, - payload_queue: VecDeque>, -} - -impl Handle { - pub fn new(handle_type: HandleType, ip_addr: Ipv4Addr, flags: usize) -> Handle { - Handle { - handle_type, - events: 0, - ip_addr, - payload_queue: VecDeque::new(), - flags, - } - } -} - -pub struct Icmpd { - icmp_file: File, - scheme_file: File, - next_fd: usize, - echo_ips: BTreeMap>, - handles: BTreeMap, -} - -impl Icmpd { - pub fn new(icmp_file: File, scheme_file: File) -> Icmpd { - Icmpd { - icmp_file, - scheme_file, - next_fd: 0, - echo_ips: BTreeMap::new(), - handles: BTreeMap::new(), - } - } - - pub fn on_scheme_event(&mut self) -> Result> { - loop { - let mut packet = syscall::Packet::default(); - if self.scheme_file.read(&mut packet)? == 0 { - break; - } - self.handle(&mut packet); - self.scheme_file.write_all(&packet)?; - } - Ok(None) - } - - pub fn on_icmp_packet(&mut self) -> Result> { - let mut packet_buffer = [0; MAX_PACKET_SIZE]; - loop { - let bytes_readed = - self.icmp_file - .read(&mut packet_buffer) - .map_err(|e| Error::from_io_error(e, "failed to read a packet from ip:1"))?; - if bytes_readed == 0 { - break; - } - let ip_packet = Ipv4::from_bytes(&packet_buffer[..bytes_readed]) - .ok_or_else(|| { - Error::from_parsing_error(PacketError::NotEnoughData, - "failed to parse ip header") - })?; - let icmp_packet = - Packet::from_bytes(&ip_packet.data) - .map_err(|e| Error::from_parsing_error(e, "failed to parse ICMP packet"))?; - - match icmp_packet.get_kind() { - PacketKind::EchoRequest => self.on_echo_request(&ip_packet, &icmp_packet)?, - PacketKind::EchoResponse => self.on_echo_response(&ip_packet, &icmp_packet)?, - _ => (), - } - } - Ok(None) - } - - fn on_echo_request(&mut self, ip_packet: &Ipv4, icmp_packet: &Packet) -> Result<()> { - let echo_response = produce_icmp_packet(Ipv4Addr::from(ip_packet.header.src.bytes), - PacketKind::EchoResponse, - &SubHeader::None, - icmp_packet.get_payload())?; - self.icmp_file - .write(&echo_response) - .map_err(|e| Error::from_io_error(e, " can't send an echo response packet")) - .map(|_| ()) - } - - fn on_echo_response(&mut self, ip_packet: &Ipv4, icmp_packet: &Packet) -> Result<()> { - if let SubHeader::Echo(echo_subheader) = *icmp_packet.get_subheader() { - if let Some(fd_set) = self.echo_ips - .get_mut(&Ipv4Addr::from(ip_packet.header.src.bytes)) { - for fd in fd_set.iter() { - if let Some(handle) = self.handles.get_mut(fd) { - if echo_subheader.get_id() == *fd as u16 { - handle - .payload_queue - .push_back(Vec::from(icmp_packet.get_payload())); - - if handle.events & syscall::EVENT_READ == syscall::EVENT_READ { - post_fevent(&mut self.scheme_file, - *fd, - syscall::EVENT_READ, - icmp_packet.get_payload().len())?; - } - } - } - } - } - } - Ok(()) - } - - fn open_echo(&mut self, ip_addr: Ipv4Addr, flags: usize) -> syscall::Result { - let fd = self.next_fd; - self.next_fd += 1; - let handle = Handle::new(HandleType::Echo, ip_addr, flags); - self.handles.insert(fd, handle); - self.echo_ips - .entry(ip_addr) - .or_insert_with(HashSet::new) - .insert(fd); - Ok(fd) - } - - fn read_echo(handle: &mut Handle, buf: &mut [u8]) -> syscall::Result { - if let Some(payload) = handle.payload_queue.pop_front() { - //TODO replace with a proper memcpy - let mut i = 0; - while i < buf.len() && i < payload.len() { - buf[i] = payload[i]; - i += 1; - } - Ok(i) - } else { - Ok(0) - } - } -} - -impl SchemeMut for Icmpd { - fn open(&mut self, url: &[u8], flags: usize, _uid: u32, _gid: u32) -> syscall::Result { - use std::str; - use std::str::FromStr; - - let path = str::from_utf8(url) - .or_else(|_| Err(syscall::Error::new(syscall::EINVAL)))?; - let mut parts = path.split('/'); - let method = parts - .next() - .ok_or_else(|| syscall::Error::new(syscall::EINVAL))?; - match method { - "echo" => { - let addr = parts - .next() - .ok_or_else(|| syscall::Error::new(syscall::EINVAL))?; - let addr = Ipv4Addr::from_str(addr) - .map_err(|_| syscall::Error::new(syscall::EINVAL))?; - self.open_echo(addr, flags) - } - _ => Err(syscall::Error::new(syscall::EINVAL)), - } - } - - fn close(&mut self, fd: usize) -> syscall::Result { - let (ip, ip_set) = { - let handle = self.handles - .get_mut(&fd) - .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; - match handle.handle_type { - HandleType::Echo => (handle.ip_addr, &mut self.echo_ips), - } - }; - self.handles.remove(&fd); - let remove_ip = if let Some(fd_set) = ip_set.get_mut(&ip) { - fd_set.remove(&fd); - fd_set.is_empty() - } else { - false - }; - - if remove_ip { - ip_set.remove(&ip); - } - - Ok(0) - } - - fn write(&mut self, fd: usize, buf: &[u8]) -> syscall::Result { - if buf.len() > MAX_ICMP_PAYLOAD_SIZE { - return Err(syscall::Error::new(syscall::EMSGSIZE)); - } - let handle = self.handles - .get_mut(&fd) - .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; - match handle.handle_type { - HandleType::Echo => { - let echo_request = produce_icmp_packet(handle.ip_addr, - PacketKind::EchoRequest, - &SubHeader::Echo(&EchoHeader::new(fd as - u16)), - buf) - .map_err(|_| syscall::Error::new(syscall::EPROTO))?; - self.icmp_file - .write(&echo_request) - .map_err(|_| syscall::Error::new(syscall::EPROTO)) - } - } - } - - fn read(&mut self, fd: usize, buf: &mut [u8]) -> syscall::Result { - let handle = self.handles - .get_mut(&fd) - .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; - match handle.handle_type { - HandleType::Echo => Icmpd::read_echo(handle, buf), - } - } - - fn fevent(&mut self, fd: usize, events: usize) -> syscall::Result { - let handle = self.handles - .get_mut(&fd) - .ok_or_else(|| syscall::Error::new(syscall::EBADF))?; - handle.events = events; - Ok(fd) - } -} - -fn produce_icmp_packet(to_ip: Ipv4Addr, - kind: PacketKind, - subheader: &SubHeader, - payload: &[u8]) - -> Result> { - let mut ip_data = vec![0; MutPacket::get_total_header_size(subheader) + payload.len()]; - { - let mut out_icmp_packet = - MutPacket::from_bytes(&mut ip_data) - .map_err(|e| Error::from_parsing_error(e, "can't parse empty icmp header"))?; - out_icmp_packet = out_icmp_packet - .set_subheader(subheader) - .map_err(|e| Error::from_parsing_error(e, "can't set subheader"))?; - out_icmp_packet.set_kind(kind); - { - let out_payload = out_icmp_packet.get_payload(); - if out_payload.len() != payload.len() { - return Err(Error::from_parsing_error(PacketError::NotEnoughData, - " can't copy icmp payload to echo response")); - } - //WARNING: copy_from_slice can panic if the slices' lengths are different - out_payload.copy_from_slice(payload); - } - out_icmp_packet.compute_checksum(); - } - let out_ip_packet = Ipv4 { - header: Ipv4Header { - ver_hlen: 0x45, - services: 0, - len: n16::new((ip_data.len() + mem::size_of::()) as u16), - id: n16::new(0), - flags_fragment: n16::new(0), - ttl: 64, - proto: 1, - checksum: Checksum { data: 0 }, - src: netutils::Ipv4Addr::NULL, - dst: netutils::Ipv4Addr { bytes: to_ip.octets() }, - }, - options: Vec::new(), - data: ip_data, - }; - Ok(out_ip_packet.to_bytes()) -} - -fn post_fevent(scheme_file: &mut File, fd: usize, event: usize, data_len: usize) -> Result<()> { - scheme_file - .write(&syscall::Packet { - id: 0, - pid: 0, - uid: 0, - gid: 0, - a: syscall::number::SYS_FEVENT, - b: fd, - c: event, - d: data_len, - }) - .map(|_| ()) - .map_err(|e| Error::from_io_error(e, "failed to post fevent")) -} diff --git a/src/smolnetd/main.rs b/src/smolnetd/main.rs index e6f2131a4c..486da5e71b 100644 --- a/src/smolnetd/main.rs +++ b/src/smolnetd/main.rs @@ -47,18 +47,24 @@ fn run() -> Result<()> { .map_err(|e| Error::from_syscall_error(e, "failed to open :tcp"))? as RawFd; + trace!("opening :icmp"); + let icmp_fd = syscall::open(":icmp", O_RDWR | O_CREAT | O_NONBLOCK) + .map_err(|e| Error::from_syscall_error(e, "failed to open :icmp"))? + as RawFd; + let time_path = format!("time:{}", syscall::CLOCK_MONOTONIC); let time_fd = syscall::open(&time_path, syscall::O_RDWR) .map_err(|e| Error::from_syscall_error(e, "failed to open time:"))? as RawFd; - let (network_file, ip_file, time_file, udp_file, tcp_file) = unsafe { + let (network_file, ip_file, time_file, udp_file, tcp_file, icmp_file) = unsafe { ( File::from_raw_fd(network_fd), File::from_raw_fd(ip_fd), File::from_raw_fd(time_fd), File::from_raw_fd(udp_fd), File::from_raw_fd(tcp_fd), + File::from_raw_fd(icmp_fd), ) }; @@ -67,6 +73,7 @@ fn run() -> Result<()> { ip_file, udp_file, tcp_file, + icmp_file, time_file, ))); @@ -113,6 +120,16 @@ fn run() -> Result<()> { Error::from_io_error(e, "failed to listen to tcp events") })?; + let smolnetd_ = Rc::clone(&smolnetd); + + event_queue + .add(icmp_fd, move |_| { + smolnetd_.borrow_mut().on_icmp_scheme_event() + }) + .map_err(|e| { + Error::from_io_error(e, "failed to listen to icmp events") + })?; + event_queue .add(time_fd, move |_| smolnetd.borrow_mut().on_time_event()) .map_err(|e| { diff --git a/src/smolnetd/scheme/icmp.rs b/src/smolnetd/scheme/icmp.rs new file mode 100644 index 0000000000..5ccc4320e4 --- /dev/null +++ b/src/smolnetd/scheme/icmp.rs @@ -0,0 +1,225 @@ +use smoltcp::socket::{IcmpEndpoint, IcmpPacketBuffer, IcmpSocket, IcmpSocketBuffer, SocketHandle}; +use smoltcp::wire::{Icmpv4Packet, Icmpv4Repr, IpAddress}; +use std::mem; +use std::str; +use syscall::{Error as SyscallError, Result as SyscallResult}; +use syscall; + +use device::NetworkDevice; +use port_set::PortSet; +use super::socket::{DupResult, SchemeFile, SchemeSocket, SocketFile, SocketScheme}; +use super::{Smolnetd, SocketSet}; + +pub type IcmpScheme = SocketScheme>; + +enum IcmpSocketType { + Echo, +} + +pub struct IcmpData { + socket_type: IcmpSocketType, + ip: IpAddress, + ident: u16, +} + +impl<'a, 'b> SchemeSocket for IcmpSocket<'a, 'b> { + type SchemeDataT = PortSet; + type DataT = IcmpData; + type SettingT = (); + + fn new_scheme_data() -> Self::SchemeDataT { + PortSet::new(1u16, 0xffffu16).expect("Wrong ICMP ident values") + } + + fn can_send(&self) -> bool { + self.can_send() + } + + fn can_recv(&self) -> bool { + self.can_recv() + } + + fn get_setting( + _file: &SocketFile, + _setting: Self::SettingT, + _buf: &mut [u8], + ) -> SyscallResult { + Ok(0) + } + + fn set_setting( + _file: &mut SocketFile, + _setting: Self::SettingT, + _buf: &[u8], + ) -> SyscallResult { + Ok(0) + } + + fn ttl(&self) -> u8 { + self.ttl().unwrap_or(64) + } + + fn set_ttl(&mut self, ttl: u8) { + self.set_ttl(Some(ttl)); + } + + fn new_socket( + socket_set: &mut SocketSet, + path: &str, + _uid: u32, + ident_set: &mut Self::SchemeDataT, + ) -> SyscallResult<(SocketHandle, Self::DataT)> { + use std::str::FromStr; + + let mut parts = path.split('/'); + let method = parts + .next() + .ok_or_else(|| syscall::Error::new(syscall::EINVAL))?; + + match method { + "echo" => { + let addr = parts + .next() + .ok_or_else(|| syscall::Error::new(syscall::EINVAL))?; + let ip = + IpAddress::from_str(addr).map_err(|_| syscall::Error::new(syscall::EINVAL))?; + + let mut rx_packets = Vec::with_capacity(Smolnetd::SOCKET_BUFFER_SIZE); + let mut tx_packets = Vec::with_capacity(Smolnetd::SOCKET_BUFFER_SIZE); + for _ in 0..Smolnetd::SOCKET_BUFFER_SIZE { + rx_packets.push(IcmpPacketBuffer::new(vec![0; NetworkDevice::MTU])); + tx_packets.push(IcmpPacketBuffer::new(vec![0; NetworkDevice::MTU])); + } + + let socket = IcmpSocket::new(IcmpSocketBuffer::new(rx_packets), + IcmpSocketBuffer::new(tx_packets)); + let handle = socket_set.add(socket); + let mut icmp_socket = socket_set.get::(handle); + let ident = ident_set + .get_port() + .ok_or_else(|| SyscallError::new(syscall::EINVAL))?; + icmp_socket + .bind(IcmpEndpoint::Ident(ident)) + .map_err(|_| syscall::Error::new(syscall::EINVAL))?; + let socket_data = IcmpData { + socket_type: IcmpSocketType::Echo, + ident, + ip, + }; + Ok((handle, socket_data)) + } + _ => Err(syscall::Error::new(syscall::EINVAL)), + } + } + + fn close_file( + &self, + file: &SchemeFile, + ident_set: &mut Self::SchemeDataT, + ) -> SyscallResult<()> { + if let SchemeFile::Socket(ref file) = *file { + ident_set.release_port(file.data.ident); + } + Ok(()) + } + + fn write_buf( + &mut self, + file: &mut SocketFile, + buf: &[u8], + ) -> SyscallResult { + if self.can_send() { + match file.data.socket_type { + IcmpSocketType::Echo => { + if buf.len() < mem::size_of::() { + return Err(SyscallError::new(syscall::EINVAL)); + } + let (seq_buf, payload) = buf.split_at(mem::size_of::()); + // Don't really care about endianness here as long as it's consistent with read + let seq_no: u16 = u16::from(seq_buf[0]) | (u16::from(seq_buf[1]) << 8); + let icmp_repr = Icmpv4Repr::EchoRequest { + ident: file.data.ident, + seq_no, + data: payload, + }; + + let icmp_payload = self.send(icmp_repr.buffer_len(), file.data.ip) + .map_err(|_| syscall::Error::new(syscall::EINVAL))?; + let mut icmp_packet = Icmpv4Packet::new(icmp_payload); + //TODO: replace Default with actual caps + icmp_repr.emit(&mut icmp_packet, &Default::default()); + Ok(buf.len()) + } + } + } else if file.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { + Ok(0) + } else { + Err(SyscallError::new(syscall::EWOULDBLOCK)) + } + } + + fn read_buf( + &mut self, + file: &mut SocketFile, + buf: &mut [u8], + ) -> SyscallResult { + while self.can_recv() { + let (payload, _) = self.recv().expect("Can't recv icmp packet"); + let icmp_packet = Icmpv4Packet::new(&payload); + //TODO: replace default with actual caps + let icmp_repr = Icmpv4Repr::parse(&icmp_packet, &Default::default()).unwrap(); + + if let Icmpv4Repr::EchoReply { seq_no, data, .. } = icmp_repr { + if buf.len() < mem::size_of::() + data.len() { + return Err(SyscallError::new(syscall::EINVAL)); + } + + // Don't really care about endianness here as long as it's consistent with read + buf[0] = (seq_no & 0xff) as u8; + buf[1] = (seq_no >> 8) as u8; + + for i in 0..data.len() { + buf[mem::size_of::() + i] = data[i]; + } + + return Ok(mem::size_of::() + data.len()); + } + } + + if file.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { + Ok(0) + } else { + Err(SyscallError::new(syscall::EWOULDBLOCK)) + } + } + + fn dup( + _socket_set: &mut SocketSet, + _file: &mut SchemeFile, + _path: &str, + _: &mut Self::SchemeDataT, + ) -> SyscallResult> { + Err(SyscallError::new(syscall::EBADF)) + } + + fn fpath(&self, file: &SchemeFile, buf: &mut [u8]) -> SyscallResult { + if let SchemeFile::Socket(ref socket_file) = *file { + match socket_file.data.socket_type { + IcmpSocketType::Echo => { + let path = format!("icmp:echo/{}", socket_file.data.ip); + let path = path.as_bytes(); + + let mut i = 0; + while i < buf.len() && i < path.len() { + buf[i] = path[i]; + i += 1; + } + + Ok(i) + } + } + } else { + Err(SyscallError::new(syscall::EBADF)) + } + } +} diff --git a/src/smolnetd/scheme/ip.rs b/src/smolnetd/scheme/ip.rs index 0fcbe07ef0..220341628e 100644 --- a/src/smolnetd/scheme/ip.rs +++ b/src/smolnetd/scheme/ip.rs @@ -47,8 +47,7 @@ impl<'a, 'b> SchemeSocket for RawSocket<'a, 'b> { 0 } - fn set_ttl(&mut self, _ttl: u8) { - } + fn set_ttl(&mut self, _ttl: u8) {} fn new_socket( socket_set: &mut SocketSet, diff --git a/src/smolnetd/scheme/mod.rs b/src/smolnetd/scheme/mod.rs index 9a15d7dc58..ce83756de6 100644 --- a/src/smolnetd/scheme/mod.rs +++ b/src/smolnetd/scheme/mod.rs @@ -20,11 +20,13 @@ use arp_cache::LoArpCache; use self::ip::IpScheme; use self::tcp::TcpScheme; use self::udp::UdpScheme; +use self::icmp::IcmpScheme; mod ip; mod socket; mod tcp; mod udp; +mod icmp; type SocketSet = SmoltcpSocketSet<'static, 'static, 'static>; @@ -40,6 +42,7 @@ pub struct Smolnetd { ip_scheme: IpScheme, udp_scheme: UdpScheme, tcp_scheme: TcpScheme, + icmp_scheme: IcmpScheme, input_queue: Rc>>, buffer_pool: Rc>, @@ -56,6 +59,7 @@ impl Smolnetd { ip_file: File, udp_file: File, tcp_file: File, + icmp_file: File, time_file: File, ) -> Smolnetd { let hardware_addr = EthernetAddress::from_str(getcfg("mac").unwrap().trim()) @@ -69,7 +73,6 @@ impl Smolnetd { let default_gw = Ipv4Address::from_str(getcfg("ip_router").unwrap().trim()) .expect("Can't parse the 'ip_router' cfg."); - let buffer_pool = Rc::new(RefCell::new(BufferPool::new(Self::MAX_PACKET_SIZE))); let input_queue = Rc::new(RefCell::new(VecDeque::new())); let network_file = Rc::new(RefCell::new(network_file)); @@ -96,6 +99,7 @@ impl Smolnetd { ip_scheme: IpScheme::new(Rc::clone(&socket_set), ip_file), udp_scheme: UdpScheme::new(Rc::clone(&socket_set), udp_file), tcp_scheme: TcpScheme::new(Rc::clone(&socket_set), tcp_file), + icmp_scheme: IcmpScheme::new(Rc::clone(&socket_set), icmp_file), input_queue, network_file, buffer_pool, @@ -127,6 +131,12 @@ impl Smolnetd { Ok(None) } + pub fn on_icmp_scheme_event(&mut self) -> Result> { + self.icmp_scheme.on_scheme_event()?; + let _ = self.poll()?; + Ok(None) + } + pub fn on_time_event(&mut self) -> Result> { let timeout = self.poll()?; self.schedule_time_event(timeout)?; @@ -210,7 +220,8 @@ impl Smolnetd { fn notify_sockets(&mut self) -> Result<()> { self.ip_scheme.notify_sockets()?; self.udp_scheme.notify_sockets()?; - self.tcp_scheme.notify_sockets() + self.tcp_scheme.notify_sockets()?; + self.icmp_scheme.notify_sockets() } } diff --git a/src/smolnetd/scheme/socket.rs b/src/smolnetd/scheme/socket.rs index 5d312be188..376cd0756f 100644 --- a/src/smolnetd/scheme/socket.rs +++ b/src/smolnetd/scheme/socket.rs @@ -14,7 +14,7 @@ use syscall::{Error as SyscallError, Packet as SyscallPacket, Result as SyscallR use syscall; use error::{Error, Result}; -use super::{SocketSet, post_fevent}; +use super::{post_fevent, SocketSet}; pub struct SocketFile { pub flags: usize, @@ -366,21 +366,16 @@ where }; match setting { - Setting::Other(setting) => { - SocketT::get_setting(file, setting, buf) + Setting::Other(setting) => SocketT::get_setting(file, setting, buf), + Setting::Ttl => if let Some(ttl) = buf.get_mut(0) { + let mut socket_set = self.socket_set.borrow_mut(); + let socket = socket_set.get::(file.socket_handle); + *ttl = socket.ttl(); + Ok(1) + } else { + Err(SyscallError::new(syscall::EIO)) }, - Setting::Ttl => { - if let Some(ttl) = buf.get_mut(0) { - let mut socket_set = self.socket_set.borrow_mut(); - let socket = socket_set.get::(file.socket_handle); - *ttl = socket.ttl(); - Ok(1) - } else { - Err(SyscallError::new(syscall::EIO)) - } - }, - Setting::ReadTimeout | - Setting::WriteTimeout => { + Setting::ReadTimeout | Setting::WriteTimeout => { let timespec = match (setting, file.read_timeout, file.write_timeout) { (Setting::ReadTimeout, Some(read_timeout), _) => read_timeout, (Setting::WriteTimeout, _, Some(write_timeout)) => write_timeout, @@ -440,16 +435,14 @@ where }; Ok(count) } - Setting::Ttl => { - if let Some(ttl) = buf.get(0) { - let mut socket_set = self.socket_set.borrow_mut(); - let mut socket = socket_set.get::(file.socket_handle); - socket.set_ttl(*ttl); - Ok(1) - } else { - Err(SyscallError::new(syscall::EIO)) - } - } + Setting::Ttl => if let Some(ttl) = buf.get(0) { + let mut socket_set = self.socket_set.borrow_mut(); + let mut socket = socket_set.get::(file.socket_handle); + socket.set_ttl(*ttl); + Ok(1) + } else { + Err(SyscallError::new(syscall::EIO)) + }, Setting::Other(setting) => SocketT::set_setting(file, setting, buf), } } From 2242ad90f97b00beb16f286c3026edb5f2d8d421 Mon Sep 17 00:00:00 2001 From: Egor Karavaev Date: Mon, 13 Nov 2017 20:05:09 +0300 Subject: [PATCH 056/155] Poll timeout calculation fix. --- Cargo.lock | 10 +++++----- src/smolnetd/scheme/mod.rs | 15 ++++++++------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f65b98584f..c90dbd4960 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -126,7 +126,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "lazy_static" -version = "0.2.9" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -231,7 +231,7 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "coco 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)", @@ -280,7 +280,7 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -312,7 +312,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "smoltcp" version = "0.4.0" -source = "git+https://github.com/m-labs/smoltcp.git#ef4af850e0981b2b200605bb1b7b526017fd2cd9" +source = "git+https://github.com/m-labs/smoltcp.git#907f3659a43a1c1e1bbce68e8b9de9ab0ce6dac3" dependencies = [ "byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "managed 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -437,7 +437,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum idna 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "014b298351066f1512874135335d62a789ffe78a9974f94b43ed5621951eaf7d" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a" -"checksum lazy_static 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c9e5e58fa1a4c3b915a561a78a22ee0cac6ab97dca2504428bc1cb074375f8d5" +"checksum lazy_static 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "236eb37a62591d4a41a89b7763d7de3e06ca02d5ab2815446a8bae5d2f8c2d57" "checksum libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "5ba3df4dcb460b9dfbd070d41c94c19209620c191b0340b929ce748a2bcd42d2" "checksum log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "880f77541efa6e5cc74e76910c9884d9859683118839d6a1dc3b11e63512565b" "checksum managed 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b5d48e8c30a4363e2981fe4db20527f6ab0f32a243bbc75379dea5a64f60dae4" diff --git a/src/smolnetd/scheme/mod.rs b/src/smolnetd/scheme/mod.rs index ce83756de6..c80ca20251 100644 --- a/src/smolnetd/scheme/mod.rs +++ b/src/smolnetd/scheme/mod.rs @@ -176,18 +176,19 @@ impl Smolnetd { error!("poll error: {}", err); break 0; } - Ok(None) => { - break ::std::u64::MAX; - } - Ok(Some(n)) if n > 0 => { - break n; - } + Ok(wait_till) if self.input_queue.borrow().is_empty() => match wait_till { + None => break ::std::i64::MAX, + Some(n) if n > timestamp => { + break ::std::cmp::min(::std::i64::MAX as u64, n - timestamp) as i64 + } + _ => {} + }, _ => {} } }; self.notify_sockets()?; Ok(::std::cmp::min( - ::std::cmp::max(Smolnetd::MIN_CHECK_TIMEOUT_MS, timeout as i64), + ::std::cmp::max(Smolnetd::MIN_CHECK_TIMEOUT_MS, timeout), Smolnetd::MAX_CHECK_TIMEOUT_MS, )) } From 34abddb2f0cbd46658594e7c5923e47269da6c8b Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Tue, 14 Nov 2017 19:49:32 -0700 Subject: [PATCH 057/155] Update Cargo.lock --- Cargo.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c90dbd4960..5d30a24aa1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -32,13 +32,13 @@ name = "coco" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "either 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "either 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "either" -version = "1.3.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -312,7 +312,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "smoltcp" version = "0.4.0" -source = "git+https://github.com/m-labs/smoltcp.git#907f3659a43a1c1e1bbce68e8b9de9ab0ce6dac3" +source = "git+https://github.com/m-labs/smoltcp.git#5e2ae22302d36cea2cc3e1caa4f098e20dc7f612" dependencies = [ "byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "managed 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -426,7 +426,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855" "checksum byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff81738b726f5d099632ceaffe7fb65b90212e8dce59d518729e7e8634032d3d" "checksum coco 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c06169f5beb7e31c7c67ebf5540b8b472d23e3eade3b2ec7d1f5b504a85f91bd" -"checksum either 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e311a7479512fbdf858fb54d91ec59f3b9f85bc0113659f46bba12b199d273ce" +"checksum either 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "740178ddf48b1a9e878e6d6509a1442a2d42fd2928aae8e7a6f8a36fb01981b3" "checksum extra 0.1.0 (git+https://github.com/redox-os/libextra.git)" = "" "checksum fuchsia-zircon 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f6c0581a4e363262e52b87f59ee2afe3415361c6ec35e665924eb08afe8ff159" "checksum fuchsia-zircon-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "43f3795b4bae048dc6123a6b972cadde2e676f9ded08aef6bb77f5f157684a82" From 5e65afb7691a97a174acec8ced5953c8e710d9b9 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Thu, 16 Nov 2017 19:43:13 -0700 Subject: [PATCH 058/155] Implement null file that can only be duped or closed. --- src/smolnetd/scheme/socket.rs | 61 +++++++++++++++++++++++++++-------- 1 file changed, 47 insertions(+), 14 deletions(-) diff --git a/src/smolnetd/scheme/socket.rs b/src/smolnetd/scheme/socket.rs index 376cd0756f..b4f39e479c 100644 --- a/src/smolnetd/scheme/socket.rs +++ b/src/smolnetd/scheme/socket.rs @@ -16,6 +16,12 @@ use syscall; use error::{Error, Result}; use super::{post_fevent, SocketSet}; +pub struct NullFile { + pub flags: usize, + pub uid: u32, + pub gid: u32, +} + pub struct SocketFile { pub flags: usize, pub data: DataT, @@ -146,6 +152,7 @@ where SocketT: SchemeSocket + AnySocket<'static, 'static>, { next_fd: usize, + nulls: BTreeMap, files: BTreeMap>, socket_set: Rc>, scheme_file: File, @@ -161,6 +168,7 @@ where pub fn new(socket_set: Rc>, scheme_file: File) -> SocketScheme { SocketScheme { next_fd: 1, + nulls: BTreeMap::new(), files: BTreeMap::new(), socket_set, scheme_data: SocketT::new_scheme_data(), @@ -455,31 +463,50 @@ where fn open(&mut self, url: &[u8], flags: usize, uid: u32, _gid: u32) -> SyscallResult { let path = str::from_utf8(url).or_else(|_| Err(SyscallError::new(syscall::EINVAL)))?; - let (socket_handle, data) = SocketT::new_socket( - &mut self.socket_set.borrow_mut(), - path, - uid, - &mut self.scheme_data, - )?; + if path.is_empty() { + let null = NullFile { + flags: flags, + uid: uid, + gid: _gid, + }; - let id = self.next_fd; + let id = self.next_fd; + self.next_fd += 1; - self.files.insert( - id, - SchemeFile::Socket(SocketFile { + self.nulls.insert(id, null); + + Ok(id) + } else { + let (socket_handle, data) = SocketT::new_socket( + &mut self.socket_set.borrow_mut(), + path, + uid, + &mut self.scheme_data, + )?; + + let file = SchemeFile::Socket(SocketFile { flags, events: 0, socket_handle, write_timeout: None, read_timeout: None, data, - }), - ); - self.next_fd += 1; - Ok(id) + }); + + let id = self.next_fd; + self.next_fd += 1; + + self.files.insert(id, file); + + Ok(id) + } } fn close(&mut self, fd: usize) -> SyscallResult { + if let Some(_null) = self.nulls.remove(&fd) { + return Ok(0); + } + let socket_handle = { let file = self.files .get(&fd) @@ -553,6 +580,12 @@ where } fn dup(&mut self, fd: usize, buf: &[u8]) -> SyscallResult { + if let Some((flags, uid, gid)) = self.nulls.get(&fd).map(|null| { + (null.flags, null.uid, null.gid) + }) { + return self.open(buf, flags, uid, gid); + } + let path = str::from_utf8(buf).or_else(|_| Err(SyscallError::new(syscall::EINVAL)))?; let new_file = { From 5d3a830ce79eabd6a8d651c433458833509105c7 Mon Sep 17 00:00:00 2001 From: Dan Robertson Date: Wed, 20 Dec 2017 00:37:54 +0000 Subject: [PATCH 059/155] Sync with smoltcp updates - Use EthernetInterfaceBuilder instead of EthernetInterface::new - smoltcp removed the ArpCache trait in favor of ManagedMap. NB: This breaks the use of loopback and sending packets to yourself. --- Cargo.lock | 72 +++++++++++++++++------------------ src/smolnetd/arp_cache.rs | 45 ---------------------- src/smolnetd/device.rs | 4 +- src/smolnetd/main.rs | 1 - src/smolnetd/scheme/icmp.rs | 8 ++-- src/smolnetd/scheme/ip.rs | 4 +- src/smolnetd/scheme/mod.rs | 19 ++++----- src/smolnetd/scheme/socket.rs | 14 +++---- src/smolnetd/scheme/tcp.rs | 8 ++-- src/smolnetd/scheme/udp.rs | 8 ++-- 10 files changed, 67 insertions(+), 116 deletions(-) delete mode 100644 src/smolnetd/arp_cache.rs diff --git a/Cargo.lock b/Cargo.lock index 5d30a24aa1..22725df47c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,14 +1,14 @@ [[package]] name = "arg_parser" version = "0.1.0" -source = "git+https://github.com/redox-os/arg-parser.git#d16e2d02e87996bbe2bce4a201c66c0df4a1e866" +source = "git+https://github.com/redox-os/arg-parser.git#7503531821b0c111f9fac77a5d2536ea221105fe" [[package]] name = "base64" version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -24,7 +24,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "byteorder" -version = "1.1.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -44,7 +44,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "extra" version = "0.1.0" -source = "git+https://github.com/redox-os/libextra.git#402932084acd5fef4812945887ceaaa2ddd5f264" +source = "git+https://github.com/redox-os/libextra.git#f38608acd9cc00e1c8bd41a1a96d31becf239913" [[package]] name = "fuchsia-zircon" @@ -126,12 +126,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "lazy_static" -version = "0.2.10" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libc" -version = "0.2.33" +version = "0.2.34" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -142,7 +142,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "managed" version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" +source = "git+https://github.com/m-labs/rust-managed.git?rev=629a6786a1cf1692015f464ed16c04eafa5cb8d1#629a6786a1cf1692015f464ed16c04eafa5cb8d1" [[package]] name = "matches" @@ -166,11 +166,11 @@ dependencies = [ "extra 0.1.0 (git+https://github.com/redox-os/libextra.git)", "hyper 0.10.13 (registry+https://github.com/rust-lang/crates.io-index)", "hyper-rustls 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)", "ntpclient 0.0.1 (git+https://github.com/willem66745/ntpclient-rust)", "pbr 1.0.0 (git+https://github.com/a8m/pb)", "redox_event 0.1.0 (git+https://github.com/redox-os/event.git)", - "redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -188,16 +188,16 @@ name = "num_cpus" version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "pbr" version = "1.0.0" -source = "git+https://github.com/a8m/pb#e9369ed2b94df4f554fe79c2643de41f7338475f" +source = "git+https://github.com/a8m/pb#c63c36895b2989c721e6db70dd4cb9c8dfe52e76" dependencies = [ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)", "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -214,7 +214,7 @@ version = "0.3.18" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "fuchsia-zircon 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -231,8 +231,8 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "coco 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -242,7 +242,7 @@ name = "redox_event" version = "0.1.0" source = "git+https://github.com/redox-os/event.git#bb96d9cd6dd01d4118deae84722a522b8328fa9f" dependencies = [ - "redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -252,18 +252,18 @@ dependencies = [ "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "netutils 0.1.0 (git+https://github.com/redox-os/netutils.git)", "redox_event 0.1.0 (git+https://github.com/redox-os/event.git)", - "redox_syscall 0.1.31 (git+https://github.com/redox-os/syscall.git)", + "redox_syscall 0.1.32 (git+https://github.com/redox-os/syscall.git)", "smoltcp 0.4.0 (git+https://github.com/m-labs/smoltcp.git)", ] [[package]] name = "redox_syscall" -version = "0.1.31" -source = "git+https://github.com/redox-os/syscall.git#71c51bdbbbac3500074a8ed15a2912f38ee7a0f6" +version = "0.1.32" +source = "git+https://github.com/redox-os/syscall.git#3c765737a5e9146ffb241c67050c1be9bf28aab7" [[package]] name = "redox_syscall" -version = "0.1.31" +version = "0.1.32" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -271,7 +271,7 @@ name = "redox_termios" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -280,8 +280,8 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -312,10 +312,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "smoltcp" version = "0.4.0" -source = "git+https://github.com/m-labs/smoltcp.git#5e2ae22302d36cea2cc3e1caa4f098e20dc7f612" +source = "git+https://github.com/m-labs/smoltcp.git#960b0012a09d37dde1d86b28bb5531316f606bfd" dependencies = [ - "byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "managed 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "managed 0.4.0 (git+https://github.com/m-labs/rust-managed.git?rev=629a6786a1cf1692015f464ed16c04eafa5cb8d1)", ] [[package]] @@ -323,8 +323,8 @@ name = "termion" version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -334,8 +334,8 @@ version = "0.1.38" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -424,7 +424,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum base64 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "96434f987501f0ed4eb336a411e0631ecd1afa11574fe148587adc4ff96143c9" "checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d" "checksum byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855" -"checksum byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff81738b726f5d099632ceaffe7fb65b90212e8dce59d518729e7e8634032d3d" +"checksum byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "652805b7e73fada9d85e9a6682a4abd490cb52d96aeecc12e33a0de34dfd0d23" "checksum coco 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c06169f5beb7e31c7c67ebf5540b8b472d23e3eade3b2ec7d1f5b504a85f91bd" "checksum either 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "740178ddf48b1a9e878e6d6509a1442a2d42fd2928aae8e7a6f8a36fb01981b3" "checksum extra 0.1.0 (git+https://github.com/redox-os/libextra.git)" = "" @@ -437,10 +437,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum idna 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "014b298351066f1512874135335d62a789ffe78a9974f94b43ed5621951eaf7d" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a" -"checksum lazy_static 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "236eb37a62591d4a41a89b7763d7de3e06ca02d5ab2815446a8bae5d2f8c2d57" -"checksum libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "5ba3df4dcb460b9dfbd070d41c94c19209620c191b0340b929ce748a2bcd42d2" +"checksum lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "76f033c7ad61445c5b347c7382dd1237847eb1bce590fe50365dcb33d546be73" +"checksum libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)" = "36fbc8a8929c632868295d0178dd8f63fc423fd7537ad0738372bd010b3ac9b0" "checksum log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "880f77541efa6e5cc74e76910c9884d9859683118839d6a1dc3b11e63512565b" -"checksum managed 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b5d48e8c30a4363e2981fe4db20527f6ab0f32a243bbc75379dea5a64f60dae4" +"checksum managed 0.4.0 (git+https://github.com/m-labs/rust-managed.git?rev=629a6786a1cf1692015f464ed16c04eafa5cb8d1)" = "" "checksum matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "100aabe6b8ff4e4a7e32c1c13523379802df0772b82466207ac25b013f193376" "checksum mime 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ba626b8a6de5da682e1caa06bdb42a335aee5a84db8e5046a3e8ab17ba0a3ae0" "checksum netutils 0.1.0 (git+https://github.com/redox-os/netutils.git)" = "" @@ -452,8 +452,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum rayon 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a77c51c07654ddd93f6cb543c7a849863b03abc7e82591afda6dc8ad4ac3ac4a" "checksum rayon-core 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e64b609139d83da75902f88fd6c01820046840a18471e4dfcd5ac7c0f46bea53" "checksum redox_event 0.1.0 (git+https://github.com/redox-os/event.git)" = "" -"checksum redox_syscall 0.1.31 (git+https://github.com/redox-os/syscall.git)" = "" -"checksum redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)" = "8dde11f18c108289bef24469638a04dce49da56084f2d50618b226e47eb04509" +"checksum redox_syscall 0.1.32 (git+https://github.com/redox-os/syscall.git)" = "" +"checksum redox_syscall 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)" = "ab105df655884ede59d45b7070c8a65002d921461ee813a024558ca16030eea0" "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" "checksum ring 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1f2a6dc7fc06a05e6de183c5b97058582e9da2de0c136eafe49609769c507724" "checksum rustls 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "17727f4b991294da2c84d75a43c003151ff58072212768800f66c56ee46dca43" diff --git a/src/smolnetd/arp_cache.rs b/src/smolnetd/arp_cache.rs deleted file mode 100644 index d546b439ad..0000000000 --- a/src/smolnetd/arp_cache.rs +++ /dev/null @@ -1,45 +0,0 @@ -use smoltcp::iface::{ArpCache, SliceArpCache}; -use smoltcp::wire::{EthernetAddress, IpAddress}; -use std::collections::BTreeSet; -use std::iter::FromIterator; - -//TODO: move to EthernetAddress::LOCAL (?) -pub const LOOPBACK_HWADDR: EthernetAddress = EthernetAddress([0; 6]); - -pub struct LoArpCache { - arp_cache: SliceArpCache<'static>, - local_ips: BTreeSet, -} - -impl LoArpCache { - pub fn new(local_ips: I) -> LoArpCache - where - I: IntoIterator, - { - LoArpCache { - arp_cache: SliceArpCache::new(vec![Default::default(); 16]), - local_ips: BTreeSet::from_iter(local_ips), - } - } -} - -impl ArpCache for LoArpCache { - fn fill(&mut self, protocol_addr: &IpAddress, hardware_addr: &EthernetAddress) { - self.arp_cache.fill(protocol_addr, hardware_addr) - } - - fn lookup(&mut self, protocol_addr: &IpAddress) -> Option { - //TODO: use IpAddress::is_loopback - if let IpAddress::Ipv4(ipv4_addr) = *protocol_addr { - if ipv4_addr.is_loopback() { - return Some(LOOPBACK_HWADDR); - } - } - - if self.local_ips.contains(protocol_addr) { - return Some(LOOPBACK_HWADDR); - } - - self.arp_cache.lookup(protocol_addr) - } -} diff --git a/src/smolnetd/device.rs b/src/smolnetd/device.rs index 092df0c598..950f35ff9d 100644 --- a/src/smolnetd/device.rs +++ b/src/smolnetd/device.rs @@ -5,8 +5,8 @@ use std::fs::File; use std::io::Write; use std::rc::Rc; +use smoltcp::wire::EthernetAddress; use buffer_pool::{Buffer, BufferPool}; -use arp_cache::LOOPBACK_HWADDR; struct NetworkDeviceData { network_file: Rc>, @@ -68,7 +68,7 @@ impl smoltcp::phy::TxToken for TxToken { let mut loopback = false; if let Ok(mut frame) = smoltcp::wire::EthernetFrame::new_checked(&mut buffer) { - if frame.dst_addr() == LOOPBACK_HWADDR { + if frame.dst_addr() == EthernetAddress::default() { frame.set_dst_addr(data.local_hwaddr); loopback = true; } diff --git a/src/smolnetd/main.rs b/src/smolnetd/main.rs index 486da5e71b..59e39841e6 100644 --- a/src/smolnetd/main.rs +++ b/src/smolnetd/main.rs @@ -23,7 +23,6 @@ mod error; mod logger; mod port_set; mod scheme; -mod arp_cache; fn run() -> Result<()> { use syscall::flag::*; diff --git a/src/smolnetd/scheme/icmp.rs b/src/smolnetd/scheme/icmp.rs index 5ccc4320e4..412666ca35 100644 --- a/src/smolnetd/scheme/icmp.rs +++ b/src/smolnetd/scheme/icmp.rs @@ -55,12 +55,12 @@ impl<'a, 'b> SchemeSocket for IcmpSocket<'a, 'b> { Ok(0) } - fn ttl(&self) -> u8 { - self.ttl().unwrap_or(64) + fn hop_limit(&self) -> u8 { + self.hop_limit().unwrap_or(64) } - fn set_ttl(&mut self, ttl: u8) { - self.set_ttl(Some(ttl)); + fn set_hop_limit(&mut self, hop_limit: u8) { + self.set_hop_limit(Some(hop_limit)); } fn new_socket( diff --git a/src/smolnetd/scheme/ip.rs b/src/smolnetd/scheme/ip.rs index 220341628e..d862125dc7 100644 --- a/src/smolnetd/scheme/ip.rs +++ b/src/smolnetd/scheme/ip.rs @@ -43,11 +43,11 @@ impl<'a, 'b> SchemeSocket for RawSocket<'a, 'b> { Ok(0) } - fn ttl(&self) -> u8 { + fn hop_limit(&self) -> u8 { 0 } - fn set_ttl(&mut self, _ttl: u8) {} + fn set_hop_limit(&mut self, _hop_limit: u8) {} fn new_socket( socket_set: &mut SocketSet, diff --git a/src/smolnetd/scheme/mod.rs b/src/smolnetd/scheme/mod.rs index c80ca20251..f83a1c5e44 100644 --- a/src/smolnetd/scheme/mod.rs +++ b/src/smolnetd/scheme/mod.rs @@ -1,9 +1,9 @@ use netutils::getcfg; -use smoltcp::iface::{ArpCache, EthernetInterface}; +use smoltcp::iface::{NeighborCache, EthernetInterface, EthernetInterfaceBuilder}; use smoltcp::socket::SocketSet as SmoltcpSocketSet; use smoltcp::wire::{EthernetAddress, IpAddress, IpCidr, IpEndpoint, Ipv4Address}; use std::cell::RefCell; -use std::collections::VecDeque; +use std::collections::{VecDeque, BTreeMap}; use std::fs::File; use std::io::{Read, Write}; use std::mem::size_of; @@ -16,7 +16,6 @@ use syscall; use buffer_pool::{Buffer, BufferPool}; use device::NetworkDevice; use error::{Error, Result}; -use arp_cache::LoArpCache; use self::ip::IpScheme; use self::tcp::TcpScheme; use self::udp::UdpScheme; @@ -82,14 +81,12 @@ impl Smolnetd { hardware_addr, Rc::clone(&buffer_pool), ); - let arp_cache = LoArpCache::new(protocol_addrs.iter().map(IpCidr::address)); - let iface = EthernetInterface::new( - network_device, - Box::new(arp_cache) as Box, - hardware_addr, - protocol_addrs, - Some(default_gw), - ); + let iface = EthernetInterfaceBuilder::new(network_device) + .neighbor_cache(NeighborCache::new(BTreeMap::new())) + .ethernet_addr(hardware_addr) + .ip_addrs(protocol_addrs) + .ipv4_gateway(default_gw) + .finalize(); let socket_set = Rc::new(RefCell::new(SocketSet::new(vec![]))); Smolnetd { iface, diff --git a/src/smolnetd/scheme/socket.rs b/src/smolnetd/scheme/socket.rs index b4f39e479c..90e120491e 100644 --- a/src/smolnetd/scheme/socket.rs +++ b/src/smolnetd/scheme/socket.rs @@ -118,8 +118,8 @@ where fn can_send(&self) -> bool; fn can_recv(&self) -> bool; - fn ttl(&self) -> u8; - fn set_ttl(&mut self, u8); + fn hop_limit(&self) -> u8; + fn set_hop_limit(&mut self, u8); fn get_setting(&SocketFile, Self::SettingT, &mut [u8]) -> SyscallResult; fn set_setting(&mut SocketFile, Self::SettingT, &[u8]) -> SyscallResult; @@ -375,10 +375,10 @@ where match setting { Setting::Other(setting) => SocketT::get_setting(file, setting, buf), - Setting::Ttl => if let Some(ttl) = buf.get_mut(0) { + Setting::Ttl => if let Some(hop_limit) = buf.get_mut(0) { let mut socket_set = self.socket_set.borrow_mut(); let socket = socket_set.get::(file.socket_handle); - *ttl = socket.ttl(); + *hop_limit = socket.hop_limit(); Ok(1) } else { Err(SyscallError::new(syscall::EIO)) @@ -443,10 +443,10 @@ where }; Ok(count) } - Setting::Ttl => if let Some(ttl) = buf.get(0) { + Setting::Ttl => if let Some(hop_limit) = buf.get(0) { let mut socket_set = self.socket_set.borrow_mut(); let mut socket = socket_set.get::(file.socket_handle); - socket.set_ttl(*ttl); + socket.set_hop_limit(*hop_limit); Ok(1) } else { Err(SyscallError::new(syscall::EIO)) @@ -596,7 +596,7 @@ where let socket_handle = file.socket_handle(); let (new_handle, update_with) = match path { - "ttl" => ( + "hop_limit" => ( SchemeFile::Setting(SettingFile { socket_handle, fd, diff --git a/src/smolnetd/scheme/tcp.rs b/src/smolnetd/scheme/tcp.rs index 195525689a..7896c22948 100644 --- a/src/smolnetd/scheme/tcp.rs +++ b/src/smolnetd/scheme/tcp.rs @@ -26,12 +26,12 @@ impl<'a> SchemeSocket for TcpSocket<'a> { self.can_recv() } - fn ttl(&self) -> u8 { - self.ttl().unwrap_or(64) + fn hop_limit(&self) -> u8 { + self.hop_limit().unwrap_or(64) } - fn set_ttl(&mut self, ttl: u8) { - self.set_ttl(Some(ttl)); + fn set_hop_limit(&mut self, hop_limit: u8) { + self.set_hop_limit(Some(hop_limit)); } fn get_setting( diff --git a/src/smolnetd/scheme/udp.rs b/src/smolnetd/scheme/udp.rs index 9227bb4f77..fcf4d03936 100644 --- a/src/smolnetd/scheme/udp.rs +++ b/src/smolnetd/scheme/udp.rs @@ -28,12 +28,12 @@ impl<'a, 'b> SchemeSocket for UdpSocket<'a, 'b> { self.can_recv() } - fn ttl(&self) -> u8 { - self.ttl().unwrap_or(64) + fn hop_limit(&self) -> u8 { + self.hop_limit().unwrap_or(64) } - fn set_ttl(&mut self, ttl: u8) { - self.set_ttl(Some(ttl)); + fn set_hop_limit(&mut self, hop_limit: u8) { + self.set_hop_limit(Some(hop_limit)); } fn get_setting( From 372d688de9d5cc4b688d027766255b8c0ed845ad Mon Sep 17 00:00:00 2001 From: Dan Robertson Date: Mon, 25 Dec 2017 03:46:36 +0000 Subject: [PATCH 060/155] Updates to sync with upstream changes polling API for EthernetInterface has changed. --- Cargo.lock | 32 +++++++++++++++++++++++++------- Cargo.toml | 2 +- src/smolnetd/scheme/mod.rs | 28 ++++++++++++++-------------- 3 files changed, 40 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 22725df47c..827586960d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -27,6 +27,11 @@ name = "byteorder" version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "cfg-if" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "coco" version = "0.1.1" @@ -80,7 +85,7 @@ dependencies = [ "base64 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "httparse 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "mime 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)", @@ -136,8 +141,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "log" -version = "0.3.8" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "log 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "log" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", +] [[package]] name = "managed" @@ -154,7 +170,7 @@ name = "mime" version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -249,7 +265,7 @@ dependencies = [ name = "redox_netstack" version = "0.1.0" dependencies = [ - "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "netutils 0.1.0 (git+https://github.com/redox-os/netutils.git)", "redox_event 0.1.0 (git+https://github.com/redox-os/event.git)", "redox_syscall 0.1.32 (git+https://github.com/redox-os/syscall.git)", @@ -292,7 +308,7 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "base64 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "ring 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)", "untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -312,7 +328,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "smoltcp" version = "0.4.0" -source = "git+https://github.com/m-labs/smoltcp.git#960b0012a09d37dde1d86b28bb5531316f606bfd" +source = "git+https://github.com/m-labs/smoltcp.git#da8e7dceb8c0f1f475224fb9897b402fc1ec89a1" dependencies = [ "byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "managed 0.4.0 (git+https://github.com/m-labs/rust-managed.git?rev=629a6786a1cf1692015f464ed16c04eafa5cb8d1)", @@ -425,6 +441,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d" "checksum byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855" "checksum byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "652805b7e73fada9d85e9a6682a4abd490cb52d96aeecc12e33a0de34dfd0d23" +"checksum cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c819a1287eb618df47cc647173c5c4c66ba19d888a6e50d605672aed3140de" "checksum coco 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c06169f5beb7e31c7c67ebf5540b8b472d23e3eade3b2ec7d1f5b504a85f91bd" "checksum either 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "740178ddf48b1a9e878e6d6509a1442a2d42fd2928aae8e7a6f8a36fb01981b3" "checksum extra 0.1.0 (git+https://github.com/redox-os/libextra.git)" = "" @@ -439,7 +456,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a" "checksum lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "76f033c7ad61445c5b347c7382dd1237847eb1bce590fe50365dcb33d546be73" "checksum libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)" = "36fbc8a8929c632868295d0178dd8f63fc423fd7537ad0738372bd010b3ac9b0" -"checksum log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "880f77541efa6e5cc74e76910c9884d9859683118839d6a1dc3b11e63512565b" +"checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" +"checksum log 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b3a89a0c46ba789b8a247d4c567aed4d7c68e624672d238b45cc3ec20dc9f940" "checksum managed 0.4.0 (git+https://github.com/m-labs/rust-managed.git?rev=629a6786a1cf1692015f464ed16c04eafa5cb8d1)" = "" "checksum matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "100aabe6b8ff4e4a7e32c1c13523379802df0772b82466207ac25b013f193376" "checksum mime 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ba626b8a6de5da682e1caa06bdb42a335aee5a84db8e5046a3e8ab17ba0a3ae0" diff --git a/Cargo.toml b/Cargo.toml index c35391d816..25cc10c017 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ features = ["release_max_level_off"] [dependencies.smoltcp] git = "https://github.com/m-labs/smoltcp.git" default-features = false -features = ["std", "socket-raw", "socket-udp", "socket-tcp", "socket-icmp"] +features = ["std", "socket-raw", "proto-ipv4", "socket-udp", "socket-tcp", "socket-icmp"] [profile.release] lto = true diff --git a/src/smolnetd/scheme/mod.rs b/src/smolnetd/scheme/mod.rs index f83a1c5e44..0020dcfd29 100644 --- a/src/smolnetd/scheme/mod.rs +++ b/src/smolnetd/scheme/mod.rs @@ -1,4 +1,5 @@ use netutils::getcfg; +use smoltcp; use smoltcp::iface::{NeighborCache, EthernetInterface, EthernetInterfaceBuilder}; use smoltcp::socket::SocketSet as SmoltcpSocketSet; use smoltcp::wire::{EthernetAddress, IpAddress, IpCidr, IpEndpoint, Ipv4Address}; @@ -166,24 +167,23 @@ impl Smolnetd { break 0; } let timestamp = self.get_timestamp(); - match self.iface - .poll(&mut *self.socket_set.borrow_mut(), timestamp) - { - Err(err) => { - error!("poll error: {}", err); - break 0; + match self.iface.poll(&mut *self.socket_set.borrow_mut(), timestamp) { + Ok(_) => (), + Err(smoltcp::Error::Unrecognized) => (), + Err(e) => { + error!("poll error: {}", e); + break 0 } - Ok(wait_till) if self.input_queue.borrow().is_empty() => match wait_till { - None => break ::std::i64::MAX, - Some(n) if n > timestamp => { - break ::std::cmp::min(::std::i64::MAX as u64, n - timestamp) as i64 - } - _ => {} + } + self.notify_sockets()?; + match self.iface.poll_at(&*self.socket_set.borrow(), timestamp) { + Some(n) if n > timestamp => { + break ::std::cmp::min(::std::i64::MAX as u64, n - timestamp) as i64 }, - _ => {} + Some(_) => {}, + None => break ::std::i64::MAX } }; - self.notify_sockets()?; Ok(::std::cmp::min( ::std::cmp::max(Smolnetd::MIN_CHECK_TIMEOUT_MS, timeout), Smolnetd::MAX_CHECK_TIMEOUT_MS, From b3812568feaf8e8e0d68e7f0240b85a0c909e741 Mon Sep 17 00:00:00 2001 From: Dan Robertson Date: Tue, 23 Jan 2018 23:26:53 +0000 Subject: [PATCH 061/155] Use byteorder to improve readability Use byteorder instead of using less readable bitmasks and shifts. --- Cargo.lock | 1 + Cargo.toml | 1 + src/smolnetd/main.rs | 1 + src/smolnetd/scheme/icmp.rs | 9 +++------ 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 827586960d..44751d42fc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -265,6 +265,7 @@ dependencies = [ name = "redox_netstack" version = "0.1.0" dependencies = [ + "byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "netutils 0.1.0 (git+https://github.com/redox-os/netutils.git)", "redox_event 0.1.0 (git+https://github.com/redox-os/event.git)", diff --git a/Cargo.toml b/Cargo.toml index 25cc10c017..3f6b71053e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ path = "src/smolnetd/main.rs" netutils = { git = "https://github.com/redox-os/netutils.git" } redox_event = { git = "https://github.com/redox-os/event.git" } redox_syscall = { git = "https://github.com/redox-os/syscall.git" } +byteorder = { version = "1.0", default-features = false } [dependencies.log] version = "0.3" diff --git a/src/smolnetd/main.rs b/src/smolnetd/main.rs index 59e39841e6..fa51bf27ea 100644 --- a/src/smolnetd/main.rs +++ b/src/smolnetd/main.rs @@ -6,6 +6,7 @@ extern crate log; extern crate netutils; extern crate smoltcp; extern crate syscall; +extern crate byteorder; use std::cell::RefCell; use std::fs::File; diff --git a/src/smolnetd/scheme/icmp.rs b/src/smolnetd/scheme/icmp.rs index 412666ca35..bccb75a3b0 100644 --- a/src/smolnetd/scheme/icmp.rs +++ b/src/smolnetd/scheme/icmp.rs @@ -4,6 +4,7 @@ use std::mem; use std::str; use syscall::{Error as SyscallError, Result as SyscallResult}; use syscall; +use byteorder::{ByteOrder, NetworkEndian}; use device::NetworkDevice; use port_set::PortSet; @@ -135,8 +136,7 @@ impl<'a, 'b> SchemeSocket for IcmpSocket<'a, 'b> { return Err(SyscallError::new(syscall::EINVAL)); } let (seq_buf, payload) = buf.split_at(mem::size_of::()); - // Don't really care about endianness here as long as it's consistent with read - let seq_no: u16 = u16::from(seq_buf[0]) | (u16::from(seq_buf[1]) << 8); + let seq_no = NetworkEndian::read_u16(seq_buf); let icmp_repr = Icmpv4Repr::EchoRequest { ident: file.data.ident, seq_no, @@ -173,10 +173,7 @@ impl<'a, 'b> SchemeSocket for IcmpSocket<'a, 'b> { if buf.len() < mem::size_of::() + data.len() { return Err(SyscallError::new(syscall::EINVAL)); } - - // Don't really care about endianness here as long as it's consistent with read - buf[0] = (seq_no & 0xff) as u8; - buf[1] = (seq_no >> 8) as u8; + NetworkEndian::write_u16(&mut buf[0..2], seq_no); for i in 0..data.len() { buf[mem::size_of::() + i] = data[i]; From 5fba32282305885c08c189a7c8864ac1f2cae96f Mon Sep 17 00:00:00 2001 From: Egor Karavaev Date: Mon, 15 Jan 2018 22:51:45 +0300 Subject: [PATCH 062/155] Add dnds bin. --- Cargo.toml | 11 ++- src/dnsd/main.rs | 69 +++++++++++++++++ src/dnsd/scheme.rs | 126 ++++++++++++++++++++++++++++++++ src/{smolnetd => lib}/error.rs | 0 src/lib/lib.rs | 5 ++ src/{smolnetd => lib}/logger.rs | 0 src/smolnetd/main.rs | 6 +- src/smolnetd/scheme/mod.rs | 2 +- src/smolnetd/scheme/socket.rs | 2 +- 9 files changed, 215 insertions(+), 6 deletions(-) create mode 100644 src/dnsd/main.rs create mode 100644 src/dnsd/scheme.rs rename src/{smolnetd => lib}/error.rs (100%) create mode 100644 src/lib/lib.rs rename src/{smolnetd => lib}/logger.rs (100%) diff --git a/Cargo.toml b/Cargo.toml index 3f6b71053e..a995df1da1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,15 +2,24 @@ name = "redox_netstack" version = "0.1.0" +[[bin]] +name = "dnsd" +path = "src/dnsd/main.rs" + [[bin]] name = "smolnetd" path = "src/smolnetd/main.rs" +[lib] +name = "redox_netstack" +path = "src/lib/lib.rs" + [dependencies] netutils = { git = "https://github.com/redox-os/netutils.git" } -redox_event = { git = "https://github.com/redox-os/event.git" } +redox_event = { git = "https://github.com/batonius/event.git", branch = "default_callback" } redox_syscall = { git = "https://github.com/redox-os/syscall.git" } byteorder = { version = "1.0", default-features = false } +dns-parser = "0.7.1" [dependencies.log] version = "0.3" diff --git a/src/dnsd/main.rs b/src/dnsd/main.rs new file mode 100644 index 0000000000..1fed3df821 --- /dev/null +++ b/src/dnsd/main.rs @@ -0,0 +1,69 @@ +#![feature(nll)] + +extern crate dns_parser; +extern crate event; +#[macro_use] +extern crate log; +extern crate redox_netstack; +extern crate syscall; + +use event::EventQueue; +use redox_netstack::error::{Error, Result}; +use redox_netstack::logger; +use scheme::Dnsd; +use std::cell::RefCell; +use std::fs::File; +use std::os::unix::io::{FromRawFd, RawFd}; +use std::process; +use std::rc::Rc; + +mod scheme; + +fn run() -> Result<()> { + use syscall::flag::*; + + let dns_fd = syscall::open(":dns", O_RDWR | O_CREAT | O_NONBLOCK) + .map_err(|e| Error::from_syscall_error(e, "failed to open :dns"))? + as RawFd; + + let time_path = format!("time:{}", syscall::CLOCK_MONOTONIC); + let time_fd = syscall::open(&time_path, syscall::O_RDWR) + .map_err(|e| Error::from_syscall_error(e, "failed to open time:"))? + as RawFd; + + let (dns_file, time_file) = unsafe { (File::from_raw_fd(dns_fd), File::from_raw_fd(time_fd)) }; + + let dnsd = Rc::new(RefCell::new(Dnsd::new(dns_file, time_file))); + + let mut event_queue = EventQueue::<(), Error>::new() + .map_err(|e| Error::from_io_error(e, "failed to create event queue"))?; + + let dnsd_ = Rc::clone(&dnsd); + + event_queue + .add(dns_fd, move |_| dnsd_.borrow_mut().on_dns_file_event()) + .map_err(|e| Error::from_io_error(e, "failed to listen to time events"))?; + + let dnsd_ = Rc::clone(&dnsd); + + event_queue + .set_default_callback(move |fd, _| dnsd_.borrow_mut().on_unknown_fd_event(fd)); + + event_queue + .add(time_fd, move |_| dnsd.borrow_mut().on_time_event()) + .map_err(|e| Error::from_io_error(e, "failed to listen to time events"))?; + + event_queue.trigger_all(0)?; + + event_queue.run() +} + +fn main() { + if unsafe { syscall::clone(0).unwrap() } == 0 { + logger::init_logger(); + if let Err(err) = run() { + error!("dnsd: {}", err); + process::exit(1); + } + } +} diff --git a/src/dnsd/scheme.rs b/src/dnsd/scheme.rs new file mode 100644 index 0000000000..849153894f --- /dev/null +++ b/src/dnsd/scheme.rs @@ -0,0 +1,126 @@ +use redox_netstack::error::{Error, Result}; +use std::collections::BTreeMap; +use std::fs::File; +use std::io::{Read, Write}; +use std::os::unix::io::RawFd; +use std::str; +use std::rc::Rc; +use syscall::{Error as SyscallError, Packet as SyscallPacket, Result as SyscallResult, SchemeMut}; +use syscall; + +enum DnsFile { + Resolved { data: Rc<[u8]>, pos: usize }, + Waiting { domain: String }, +} + +enum Domain { + Resolved { data: Rc<[u8]> }, + Requested { waiting_fds: Vec }, +} + +pub struct Dnsd { + dns_file: File, + time_file: File, + files: BTreeMap, + domains: BTreeMap, + next_fd: usize, +} + +impl Dnsd { + pub fn new(dns_file: File, time_file: File) -> Dnsd { + Dnsd { + dns_file, + time_file, + files: BTreeMap::new(), + domains: BTreeMap::new(), + next_fd: 1, + } + } + + pub fn on_time_event(&mut self) -> Result> { + Ok(None) + } + + pub fn on_dns_file_event(&mut self) -> Result> { + loop { + let mut packet = SyscallPacket::default(); + if self.dns_file.read(&mut packet)? == 0 { + break; + } + let a = packet.a; + self.handle(&mut packet); + if packet.a != (-syscall::EWOULDBLOCK) as usize { + self.dns_file.write_all(&packet)?; + } else { + packet.a = a; + self.handle_block(packet)?; + } + } + Ok(None) + } + + pub fn on_unknown_fd_event(&mut self, fd: RawFd) -> Result> { + Ok(None) + } + + fn handle_block(&mut self, mut packet: SyscallPacket) -> Result<()> { + Ok(()) + } + + fn request_domain(&mut self, domain: &str, fd: usize) {} +} + +impl SchemeMut for Dnsd { + fn open(&mut self, url: &[u8], flags: usize, _uid: u32, _gid: u32) -> SyscallResult { + let domain : String = str::from_utf8(url) + .or_else(|_| Err(SyscallError::new(syscall::EINVAL)))? + .into(); + if domain.is_empty() { + return Err(SyscallError::new(syscall::EINVAL)); + } + let fd = self.next_fd; + self.next_fd += 1; + let dns_file = if let Some(mut domain_data) = self.domains.get_mut(&domain) { + match *domain_data { + Domain::Resolved { ref data } => DnsFile::Resolved { + data: Rc::clone(data), + pos: 0, + }, + Domain::Requested { + ref mut waiting_fds, + } => { + waiting_fds.push(fd); + DnsFile::Waiting { domain } + } + } + } else { + self.request_domain(&domain, fd); + DnsFile::Waiting { domain } + }; + self.files.insert(fd, dns_file); + Ok(fd) + } + + fn close(&mut self, fd: usize) -> SyscallResult { + self.files.remove(&fd); + Ok(0) + } + + fn write(&mut self, fd: usize, buf: &[u8]) -> SyscallResult { + Err(SyscallError::new(syscall::EINVAL)) + } + + fn read(&mut self, fd: usize, buf: &mut [u8]) -> SyscallResult { + let file = self.files.get_mut(&fd) + .ok_or_else(|| SyscallError::new(syscall::EBADF))?; + Ok(0) + } + + fn fevent(&mut self, fd: usize, events: usize) -> SyscallResult { + Ok(0) + } + + fn fsync(&mut self, fd: usize) -> SyscallResult { + Ok(0) + } +} diff --git a/src/smolnetd/error.rs b/src/lib/error.rs similarity index 100% rename from src/smolnetd/error.rs rename to src/lib/error.rs diff --git a/src/lib/lib.rs b/src/lib/lib.rs new file mode 100644 index 0000000000..1f328082fb --- /dev/null +++ b/src/lib/lib.rs @@ -0,0 +1,5 @@ +extern crate log; +extern crate syscall; + +pub mod logger; +pub mod error; diff --git a/src/smolnetd/logger.rs b/src/lib/logger.rs similarity index 100% rename from src/smolnetd/logger.rs rename to src/lib/logger.rs diff --git a/src/smolnetd/main.rs b/src/smolnetd/main.rs index fa51bf27ea..420a818381 100644 --- a/src/smolnetd/main.rs +++ b/src/smolnetd/main.rs @@ -4,6 +4,7 @@ extern crate event; #[macro_use] extern crate log; extern crate netutils; +extern crate redox_netstack; extern crate smoltcp; extern crate syscall; extern crate byteorder; @@ -14,14 +15,13 @@ use std::os::unix::io::{FromRawFd, RawFd}; use std::process; use std::rc::Rc; -use error::{Error, Result}; +use redox_netstack::error::{Error, Result}; +use redox_netstack::logger; use event::EventQueue; use scheme::Smolnetd; mod buffer_pool; mod device; -mod error; -mod logger; mod port_set; mod scheme; diff --git a/src/smolnetd/scheme/mod.rs b/src/smolnetd/scheme/mod.rs index 0020dcfd29..6ba011acaf 100644 --- a/src/smolnetd/scheme/mod.rs +++ b/src/smolnetd/scheme/mod.rs @@ -16,7 +16,7 @@ use syscall; use buffer_pool::{Buffer, BufferPool}; use device::NetworkDevice; -use error::{Error, Result}; +use redox_netstack::error::{Error, Result}; use self::ip::IpScheme; use self::tcp::TcpScheme; use self::udp::UdpScheme; diff --git a/src/smolnetd/scheme/socket.rs b/src/smolnetd/scheme/socket.rs index 90e120491e..a94f16ac24 100644 --- a/src/smolnetd/scheme/socket.rs +++ b/src/smolnetd/scheme/socket.rs @@ -13,7 +13,7 @@ use syscall::data::TimeSpec; use syscall::{Error as SyscallError, Packet as SyscallPacket, Result as SyscallResult, SchemeMut}; use syscall; -use error::{Error, Result}; +use redox_netstack::error::{Error, Result}; use super::{post_fevent, SocketSet}; pub struct NullFile { From e6dfb7f5b2e29c62b559c56887560c36d771024b Mon Sep 17 00:00:00 2001 From: Egor Karavaev Date: Fri, 19 Jan 2018 22:37:13 +0300 Subject: [PATCH 063/155] Implement the `dns:` schema. --- Cargo.lock | 170 ++++++++++++++++++----------- Cargo.toml | 5 +- src/dnsd/main.rs | 6 +- src/dnsd/scheme.rs | 247 +++++++++++++++++++++++++++++++++++++------ src/smolnetd/main.rs | 34 ++---- 5 files changed, 341 insertions(+), 121 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 44751d42fc..c124457bc4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14,7 +14,7 @@ dependencies = [ [[package]] name = "bitflags" -version = "0.7.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -41,6 +41,15 @@ dependencies = [ "scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "dns-parser" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "quick-error 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "either" version = "1.4.0" @@ -53,19 +62,17 @@ source = "git+https://github.com/redox-os/libextra.git#f38608acd9cc00e1c8bd41a1a [[package]] name = "fuchsia-zircon" -version = "0.2.1" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "fuchsia-zircon-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "fuchsia-zircon-sys" -version = "0.2.0" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", -] [[package]] name = "gcc" @@ -74,7 +81,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "httparse" -version = "1.2.3" +version = "1.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -83,12 +90,12 @@ version = "0.10.13" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "base64 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "httparse 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "httparse 1.2.4 (registry+https://github.com/rust-lang/crates.io-index)", "language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "mime 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", - "num_cpus 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", "traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "typeable 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "unicase 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -136,7 +143,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libc" -version = "0.2.34" +version = "0.2.36" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -144,12 +151,12 @@ name = "log" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "log 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "log" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -157,8 +164,8 @@ dependencies = [ [[package]] name = "managed" -version = "0.4.0" -source = "git+https://github.com/m-labs/rust-managed.git?rev=629a6786a1cf1692015f464ed16c04eafa5cb8d1#629a6786a1cf1692015f464ed16c04eafa5cb8d1" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "matches" @@ -182,11 +189,11 @@ dependencies = [ "extra 0.1.0 (git+https://github.com/redox-os/libextra.git)", "hyper 0.10.13 (registry+https://github.com/rust-lang/crates.io-index)", "hyper-rustls 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", "ntpclient 0.0.1 (git+https://github.com/willem66745/ntpclient-rust)", "pbr 1.0.0 (git+https://github.com/a8m/pb)", "redox_event 0.1.0 (git+https://github.com/redox-os/event.git)", - "redox_syscall 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -196,26 +203,26 @@ version = "0.0.1" source = "git+https://github.com/willem66745/ntpclient-rust#7e3bdf60eb940825789a8da5181025320e3050b0" dependencies = [ "byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", - "time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "num_cpus" -version = "1.7.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "pbr" version = "1.0.0" -source = "git+https://github.com/a8m/pb#c63c36895b2989c721e6db70dd4cb9c8dfe52e76" +source = "git+https://github.com/a8m/pb#d077b49ac6ea18ef63a9bb9f0f0b58abc29580f3" dependencies = [ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -224,13 +231,18 @@ name = "percent-encoding" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "quick-error" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "rand" -version = "0.3.18" +version = "0.3.20" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "fuchsia-zircon 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)", + "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -248,9 +260,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "coco 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)", - "num_cpus 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.3.20 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "redox_event" +version = "0.1.0" +source = "git+https://github.com/batonius/event.git?branch=default_callback#494aefad323a8f683c074b8b8e10dfa933f50efe" +dependencies = [ + "redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -258,29 +278,29 @@ name = "redox_event" version = "0.1.0" source = "git+https://github.com/redox-os/event.git#bb96d9cd6dd01d4118deae84722a522b8328fa9f" dependencies = [ - "redox_syscall 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "redox_netstack" version = "0.1.0" dependencies = [ - "byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "dns-parser 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "netutils 0.1.0 (git+https://github.com/redox-os/netutils.git)", - "redox_event 0.1.0 (git+https://github.com/redox-os/event.git)", - "redox_syscall 0.1.32 (git+https://github.com/redox-os/syscall.git)", - "smoltcp 0.4.0 (git+https://github.com/m-labs/smoltcp.git)", + "redox_event 0.1.0 (git+https://github.com/batonius/event.git?branch=default_callback)", + "redox_syscall 0.1.37 (git+https://github.com/redox-os/syscall.git)", + "smoltcp 0.4.0", ] [[package]] name = "redox_syscall" -version = "0.1.32" -source = "git+https://github.com/redox-os/syscall.git#3c765737a5e9146ffb241c67050c1be9bf28aab7" +version = "0.1.37" +source = "git+https://github.com/redox-os/syscall.git#7dc00e7ea4162f8886412d936f14ea5b7d834d41" [[package]] name = "redox_syscall" -version = "0.1.32" +version = "0.1.37" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -288,7 +308,7 @@ name = "redox_termios" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "redox_syscall 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -298,7 +318,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -311,7 +331,7 @@ dependencies = [ "base64 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "ring 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", - "time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", "untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "webpki 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -329,10 +349,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "smoltcp" version = "0.4.0" -source = "git+https://github.com/m-labs/smoltcp.git#da8e7dceb8c0f1f475224fb9897b402fc1ec89a1" dependencies = [ "byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "managed 0.4.0 (git+https://github.com/m-labs/rust-managed.git?rev=629a6786a1cf1692015f464ed16c04eafa5cb8d1)", + "managed 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -340,20 +359,19 @@ name = "termion" version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "time" -version = "0.1.38" +version = "0.1.39" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -413,7 +431,7 @@ version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "ring 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", - "time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", "untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -431,56 +449,77 @@ name = "winapi" version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "winapi" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "winapi-build" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [metadata] "checksum arg_parser 0.1.0 (git+https://github.com/redox-os/arg-parser.git)" = "" "checksum base64 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "96434f987501f0ed4eb336a411e0631ecd1afa11574fe148587adc4ff96143c9" -"checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d" +"checksum bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b3c30d3802dfb7281680d6285f2ccdaa8c2d8fee41f93805dba5c4cf50dc23cf" "checksum byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855" "checksum byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "652805b7e73fada9d85e9a6682a4abd490cb52d96aeecc12e33a0de34dfd0d23" "checksum cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c819a1287eb618df47cc647173c5c4c66ba19d888a6e50d605672aed3140de" "checksum coco 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c06169f5beb7e31c7c67ebf5540b8b472d23e3eade3b2ec7d1f5b504a85f91bd" +"checksum dns-parser 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f7020f6760aea312d43d23cb83bf6c0c49f162541db8b02bf95209ac51dc253d" "checksum either 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "740178ddf48b1a9e878e6d6509a1442a2d42fd2928aae8e7a6f8a36fb01981b3" "checksum extra 0.1.0 (git+https://github.com/redox-os/libextra.git)" = "" -"checksum fuchsia-zircon 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f6c0581a4e363262e52b87f59ee2afe3415361c6ec35e665924eb08afe8ff159" -"checksum fuchsia-zircon-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "43f3795b4bae048dc6123a6b972cadde2e676f9ded08aef6bb77f5f157684a82" +"checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" +"checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" "checksum gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)" = "5e33ec290da0d127825013597dbdfc28bee4964690c7ce1166cbc2a7bd08b1bb" -"checksum httparse 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "af2f2dd97457e8fb1ae7c5a420db346af389926e36f43768b96f101546b04a07" +"checksum httparse 1.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "c2f407128745b78abc95c0ffbe4e5d37427fdc0d45470710cfef8c44522a2e37" "checksum hyper 0.10.13 (registry+https://github.com/rust-lang/crates.io-index)" = "368cb56b2740ebf4230520e2b90ebb0461e69034d85d1945febd9b3971426db2" "checksum hyper-rustls 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "04535774f79684c99528944ebdb89756c945c027e55ce52faa245879d836c8fb" "checksum idna 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "014b298351066f1512874135335d62a789ffe78a9974f94b43ed5621951eaf7d" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a" "checksum lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "76f033c7ad61445c5b347c7382dd1237847eb1bce590fe50365dcb33d546be73" -"checksum libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)" = "36fbc8a8929c632868295d0178dd8f63fc423fd7537ad0738372bd010b3ac9b0" +"checksum libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)" = "1e5d97d6708edaa407429faa671b942dc0f2727222fb6b6539bf1db936e4b121" "checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" -"checksum log 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b3a89a0c46ba789b8a247d4c567aed4d7c68e624672d238b45cc3ec20dc9f940" -"checksum managed 0.4.0 (git+https://github.com/m-labs/rust-managed.git?rev=629a6786a1cf1692015f464ed16c04eafa5cb8d1)" = "" +"checksum log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "89f010e843f2b1a31dbd316b3b8d443758bc634bed37aabade59c686d644e0a2" +"checksum managed 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "43e2737ecabe4ae36a68061398bf27d2bfd0763f4c3c837a398478459494c4b7" "checksum matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "100aabe6b8ff4e4a7e32c1c13523379802df0772b82466207ac25b013f193376" "checksum mime 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ba626b8a6de5da682e1caa06bdb42a335aee5a84db8e5046a3e8ab17ba0a3ae0" "checksum netutils 0.1.0 (git+https://github.com/redox-os/netutils.git)" = "" "checksum ntpclient 0.0.1 (git+https://github.com/willem66745/ntpclient-rust)" = "" -"checksum num_cpus 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "514f0d73e64be53ff320680ca671b64fe3fb91da01e1ae2ddc99eb51d453b20d" +"checksum num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c51a3322e4bca9d212ad9a158a02abc6934d005490c054a2778df73a70aa0a30" "checksum pbr 1.0.0 (git+https://github.com/a8m/pb)" = "" "checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" -"checksum rand 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)" = "6475140dfd8655aeb72e1fd4b7a1cc1c202be65d71669476e392fe62532b9edd" +"checksum quick-error 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "eda5fe9b71976e62bc81b781206aaa076401769b2143379d3eb2118388babac4" +"checksum rand 0.3.20 (registry+https://github.com/rust-lang/crates.io-index)" = "512870020642bb8c221bf68baa1b2573da814f6ccfe5c9699b1c303047abe9b1" "checksum rayon 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a77c51c07654ddd93f6cb543c7a849863b03abc7e82591afda6dc8ad4ac3ac4a" "checksum rayon-core 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e64b609139d83da75902f88fd6c01820046840a18471e4dfcd5ac7c0f46bea53" +"checksum redox_event 0.1.0 (git+https://github.com/batonius/event.git?branch=default_callback)" = "" "checksum redox_event 0.1.0 (git+https://github.com/redox-os/event.git)" = "" -"checksum redox_syscall 0.1.32 (git+https://github.com/redox-os/syscall.git)" = "" -"checksum redox_syscall 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)" = "ab105df655884ede59d45b7070c8a65002d921461ee813a024558ca16030eea0" +"checksum redox_syscall 0.1.37 (git+https://github.com/redox-os/syscall.git)" = "" +"checksum redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "0d92eecebad22b767915e4d529f89f28ee96dbbf5a4810d2b844373f136417fd" "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" "checksum ring 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1f2a6dc7fc06a05e6de183c5b97058582e9da2de0c136eafe49609769c507724" "checksum rustls 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "17727f4b991294da2c84d75a43c003151ff58072212768800f66c56ee46dca43" "checksum safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e27a8b19b835f7aea908818e871f5cc3a5a186550c30773be987e155e8163d8f" "checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" -"checksum smoltcp 0.4.0 (git+https://github.com/m-labs/smoltcp.git)" = "" "checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" -"checksum time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)" = "d5d788d3aa77bc0ef3e9621256885555368b47bd495c13dd2e7413c89f845520" +"checksum time 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "a15375f1df02096fb3317256ce2cee6a1f42fc84ea5ad5fc8c421cfe40c73098" "checksum traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079" "checksum typeable 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1410f6f91f21d1612654e7cc69193b0334f909dcf2c790c4826254fbb86f8887" "checksum unicase 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7f4765f83163b74f957c797ad9253caf97f103fb064d3999aea9568d09fc8a33" @@ -492,4 +531,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum webpki 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e499345fc4c6b7c79a5b8756d4592c4305510a13512e79efafe00dfbd67bbac6" "checksum webpki-roots 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5bfb3f50499f21ad2317f442845e3b5805b007f1e728f59885c99e61b8c181a7" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" +"checksum winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "04e3bd221fcbe8a271359c04f21a76db7d0c6028862d1bb5512d85e1e2eb5bb3" "checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" +"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml index a995df1da1..8c2b6743d3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,10 @@ default-features = false features = ["release_max_level_off"] [dependencies.smoltcp] -git = "https://github.com/m-labs/smoltcp.git" +path = "../smoltcp" +# git = "https://github.com/m-labs/smoltcp.git" +# git = "https://github.com/batonius/smoltcp.git" +branch = "unspecified_src" default-features = false features = ["std", "socket-raw", "proto-ipv4", "socket-udp", "socket-tcp", "socket-icmp"] diff --git a/src/dnsd/main.rs b/src/dnsd/main.rs index 1fed3df821..5b97211707 100644 --- a/src/dnsd/main.rs +++ b/src/dnsd/main.rs @@ -46,8 +46,7 @@ fn run() -> Result<()> { let dnsd_ = Rc::clone(&dnsd); - event_queue - .set_default_callback(move |fd, _| dnsd_.borrow_mut().on_unknown_fd_event(fd)); + event_queue.set_default_callback(move |fd, _| dnsd_.borrow_mut().on_unknown_fd_event(fd)); event_queue .add(time_fd, move |_| dnsd.borrow_mut().on_time_event()) @@ -59,7 +58,8 @@ fn run() -> Result<()> { } fn main() { - if unsafe { syscall::clone(0).unwrap() } == 0 { + // if unsafe { syscall::clone(0).unwrap() } == 0 + { logger::init_logger(); if let Err(err) = run() { error!("dnsd: {}", err); diff --git a/src/dnsd/scheme.rs b/src/dnsd/scheme.rs index 849153894f..0e76bc7e5d 100644 --- a/src/dnsd/scheme.rs +++ b/src/dnsd/scheme.rs @@ -1,28 +1,185 @@ use redox_netstack::error::{Error, Result}; -use std::collections::BTreeMap; +use event::{subscribe_to_fd, unsubscribe_from_fd}; +use std::borrow::ToOwned; +use std::collections::{BTreeMap, BTreeSet}; +use std::collections::btree_map::Entry; use std::fs::File; use std::io::{Read, Write}; +use std::mem; use std::os::unix::io::RawFd; use std::str; use std::rc::Rc; use syscall::{Error as SyscallError, Packet as SyscallPacket, Result as SyscallResult, SchemeMut}; use syscall; +use dns_parser::{Builder, Packet as DNSPacket, RRData, ResponseCode}; +use dns_parser::{QueryClass, QueryType}; + enum DnsFile { Resolved { data: Rc<[u8]>, pos: usize }, Waiting { domain: String }, } enum Domain { - Resolved { data: Rc<[u8]> }, - Requested { waiting_fds: Vec }, + Resolved { + data: Rc<[u8]>, + }, + Requested { + waiting_fds: BTreeSet, + socket_fd: RawFd, + }, +} + +struct Domains { + domains: BTreeMap, + requests: BTreeMap, +} + +impl Domains { + fn new() -> Domains { + Domains { + domains: BTreeMap::new(), + requests: BTreeMap::new(), + } + } + + fn request_domain(&mut self, domain: &str) -> Option { + trace!("Requesting domain {}", domain); + let mut builder = Builder::new_query(1, true); + builder.add_question(domain, QueryType::A, QueryClass::IN); + let packet = match builder.build() { + Ok(packet) => packet, + _ => return None, + }; + let udp_fd = match syscall::open( + "udp:8.8.8.8:53", + syscall::O_RDWR | syscall::O_CREAT | syscall::O_NONBLOCK, + ) { + Ok(fd) => fd as RawFd, + _ => return None, + }; + if syscall::write(udp_fd as usize, &packet) != Ok(packet.len()) { + syscall::close(udp_fd as usize); + return None; + } + trace!("Requesting domain {} fd {}", domain, udp_fd); + subscribe_to_fd(udp_fd); + self.requests.insert(udp_fd, domain.to_owned()); + Some(udp_fd) + } + + fn on_fd_event(&mut self, fd: RawFd) -> Option> { + trace!("On FD event {}", fd); + let e = match self.requests.entry(fd) { + Entry::Vacant(_) => { + return None; + } + Entry::Occupied(e) => e, + }; + let mut buf = [0u8; 4096]; + let readed = match syscall::read(fd as usize, &mut buf) { + Ok(readed) => readed, + _ => { + return None; + } + }; + let pkt = match DNSPacket::parse(&buf) { + Ok(pkt) => pkt, + _ => { + return None; + } + }; + if pkt.header.response_code != ResponseCode::NoError || pkt.answers.len() == 0 { + return None; + } + let mut result = String::new(); + for answer in pkt.answers { + match answer.data { + RRData::A(ip) => { + result += &format!("{}\n", ip); + } + _ => {} // ignore + } + } + if result.is_empty() { + return None; + } + let data = Rc::from(result.into_bytes()); + syscall::close(fd as usize); + unsubscribe_from_fd(fd); + let domain = e.remove(); + let mut domain_data = Domain::Resolved { data }; + trace!("On FD event {} {} resolved", fd, domain); + match self.domains.entry(domain) { + Entry::Vacant(e) => { + e.insert(domain_data); + None + } + Entry::Occupied(mut e) => { + mem::swap(e.get_mut(), &mut domain_data); + if let Domain::Requested { waiting_fds, .. } = domain_data { + Some(waiting_fds) + } else { + None + } + } + } + } + + fn file_from_domain(&mut self, domain: &str, fd: usize) -> DnsFile { + if let Some(mut domain_data) = self.domains.get_mut(domain) { + match *domain_data { + Domain::Resolved { ref data } => DnsFile::Resolved { + data: Rc::clone(data), + pos: 0, + }, + Domain::Requested { + ref mut waiting_fds, + .. + } => { + waiting_fds.insert(fd); + DnsFile::Waiting { + domain: domain.to_owned(), + } + } + } + } else { + if let Some(socket_fd) = self.request_domain(domain) { + let mut waiting_fds = BTreeSet::new(); + waiting_fds.insert(fd); + self.domains.insert( + domain.to_owned(), + Domain::Requested { + waiting_fds, + socket_fd, + }, + ); + } + DnsFile::Waiting { + domain: domain.to_owned(), + } + } + } + + fn unwait_fd(&mut self, domain: &str, fd: usize) { + if let Some(mut domain_data) = self.domains.get_mut(domain) { + if let Domain::Requested { + ref mut waiting_fds, + .. + } = *domain_data + { + waiting_fds.remove(&fd); + } + } + } } pub struct Dnsd { dns_file: File, time_file: File, files: BTreeMap, - domains: BTreeMap, + domains: Domains, + wait_map: BTreeMap, next_fd: usize, } @@ -32,7 +189,8 @@ impl Dnsd { dns_file, time_file, files: BTreeMap::new(), - domains: BTreeMap::new(), + domains: Domains::new(), + wait_map: BTreeMap::new(), next_fd: 1, } } @@ -60,48 +218,56 @@ impl Dnsd { } pub fn on_unknown_fd_event(&mut self, fd: RawFd) -> Result> { + trace!("Unknown fd event {}", fd); + if let Some(fds_to_wakeup) = self.domains.on_fd_event(fd) { + let mut syscall_packets = vec![]; + for fd in &fds_to_wakeup { + if let Some(packet) = self.wait_map.remove(&fd) { + syscall_packets.push(packet); + } + } + + for mut packet in syscall_packets.drain(..) { + self.handle(&mut packet); + let _ = self.dns_file.write_all(&packet); + } + } Ok(None) } - fn handle_block(&mut self, mut packet: SyscallPacket) -> Result<()> { + fn handle_block(&mut self, packet: SyscallPacket) -> Result<()> { + let fd = packet.b; + self.wait_map.insert(fd, packet); Ok(()) } - - fn request_domain(&mut self, domain: &str, fd: usize) {} } impl SchemeMut for Dnsd { fn open(&mut self, url: &[u8], flags: usize, _uid: u32, _gid: u32) -> SyscallResult { - let domain : String = str::from_utf8(url) - .or_else(|_| Err(SyscallError::new(syscall::EINVAL)))? - .into(); + trace!("Open"); + let domain = str::from_utf8(url).or_else(|_| Err(SyscallError::new(syscall::EINVAL)))?; + trace!("Open {}", &domain); if domain.is_empty() { return Err(SyscallError::new(syscall::EINVAL)); } let fd = self.next_fd; self.next_fd += 1; - let dns_file = if let Some(mut domain_data) = self.domains.get_mut(&domain) { - match *domain_data { - Domain::Resolved { ref data } => DnsFile::Resolved { - data: Rc::clone(data), - pos: 0, - }, - Domain::Requested { - ref mut waiting_fds, - } => { - waiting_fds.push(fd); - DnsFile::Waiting { domain } - } - } - } else { - self.request_domain(&domain, fd); - DnsFile::Waiting { domain } - }; + let dns_file = self.domains.file_from_domain(domain, fd); self.files.insert(fd, dns_file); + trace!("Open {} {}", &domain, fd); Ok(fd) } fn close(&mut self, fd: usize) -> SyscallResult { + trace!("Close {}", fd); + let mut file = self.files + .get_mut(&fd) + .ok_or_else(|| SyscallError::new(syscall::EBADF))?; + + if let DnsFile::Waiting { ref domain } = *file { + self.domains.unwait_fd(domain, fd); + } + self.files.remove(&fd); Ok(0) } @@ -111,9 +277,30 @@ impl SchemeMut for Dnsd { } fn read(&mut self, fd: usize, buf: &mut [u8]) -> SyscallResult { - let file = self.files.get_mut(&fd) + trace!("Read {}", fd); + let mut file = self.files + .get_mut(&fd) .ok_or_else(|| SyscallError::new(syscall::EBADF))?; - Ok(0) + + if let DnsFile::Waiting { ref domain } = *file { + *file = self.domains.file_from_domain(domain, fd) + } + + match *file { + DnsFile::Resolved { + ref data, + ref mut pos, + } => { + let mut i = 0; + while i < buf.len() && *pos < data.len() { + buf[i] = data[*pos]; + i += 1; + *pos += 1; + } + Ok(i) + } + DnsFile::Waiting { .. } => Err(SyscallError::new(syscall::EWOULDBLOCK)), + } } fn fevent(&mut self, fd: usize, events: usize) -> SyscallResult { diff --git a/src/smolnetd/main.rs b/src/smolnetd/main.rs index 420a818381..673a1b02cc 100644 --- a/src/smolnetd/main.rs +++ b/src/smolnetd/main.rs @@ -88,9 +88,7 @@ fn run() -> Result<()> { .add(network_fd, move |_| { smolnetd_.borrow_mut().on_network_scheme_event() }) - .map_err(|e| { - Error::from_io_error(e, "failed to listen to network events") - })?; + .map_err(|e| Error::from_io_error(e, "failed to listen to network events"))?; let smolnetd_ = Rc::clone(&smolnetd); @@ -101,24 +99,18 @@ fn run() -> Result<()> { let smolnetd_ = Rc::clone(&smolnetd); event_queue - .add( - udp_fd, - move |_| smolnetd_.borrow_mut().on_udp_scheme_event(), - ) - .map_err(|e| { - Error::from_io_error(e, "failed to listen to udp events") - })?; + .add(udp_fd, move |_| { + smolnetd_.borrow_mut().on_udp_scheme_event() + }) + .map_err(|e| Error::from_io_error(e, "failed to listen to udp events"))?; let smolnetd_ = Rc::clone(&smolnetd); event_queue - .add( - tcp_fd, - move |_| smolnetd_.borrow_mut().on_tcp_scheme_event(), - ) - .map_err(|e| { - Error::from_io_error(e, "failed to listen to tcp events") - })?; + .add(tcp_fd, move |_| { + smolnetd_.borrow_mut().on_tcp_scheme_event() + }) + .map_err(|e| Error::from_io_error(e, "failed to listen to tcp events"))?; let smolnetd_ = Rc::clone(&smolnetd); @@ -126,15 +118,11 @@ fn run() -> Result<()> { .add(icmp_fd, move |_| { smolnetd_.borrow_mut().on_icmp_scheme_event() }) - .map_err(|e| { - Error::from_io_error(e, "failed to listen to icmp events") - })?; + .map_err(|e| Error::from_io_error(e, "failed to listen to icmp events"))?; event_queue .add(time_fd, move |_| smolnetd.borrow_mut().on_time_event()) - .map_err(|e| { - Error::from_io_error(e, "failed to listen to time events") - })?; + .map_err(|e| Error::from_io_error(e, "failed to listen to time events"))?; event_queue.trigger_all(0)?; From 32c673d814866cad4dab1e4a8cbcca8176951688 Mon Sep 17 00:00:00 2001 From: Egor Karavaev Date: Sun, 28 Jan 2018 22:44:33 +0300 Subject: [PATCH 064/155] dnsd timeouts --- Cargo.lock | 18 +-- Cargo.toml | 7 +- src/dnsd/main.rs | 3 +- src/dnsd/scheme.rs | 272 ++++++++++++++++++++++++++++++++++----------- 4 files changed, 217 insertions(+), 83 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c124457bc4..ba97aa7ca1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -268,15 +268,7 @@ dependencies = [ [[package]] name = "redox_event" version = "0.1.0" -source = "git+https://github.com/batonius/event.git?branch=default_callback#494aefad323a8f683c074b8b8e10dfa933f50efe" -dependencies = [ - "redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "redox_event" -version = "0.1.0" -source = "git+https://github.com/redox-os/event.git#bb96d9cd6dd01d4118deae84722a522b8328fa9f" +source = "git+https://github.com/redox-os/event.git#68f4c7e55615ecede98f2085c81801a3dc4b74e0" dependencies = [ "redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -285,12 +277,13 @@ dependencies = [ name = "redox_netstack" version = "0.1.0" dependencies = [ + "byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "dns-parser 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "netutils 0.1.0 (git+https://github.com/redox-os/netutils.git)", - "redox_event 0.1.0 (git+https://github.com/batonius/event.git?branch=default_callback)", + "redox_event 0.1.0 (git+https://github.com/redox-os/event.git)", "redox_syscall 0.1.37 (git+https://github.com/redox-os/syscall.git)", - "smoltcp 0.4.0", + "smoltcp 0.4.0 (git+https://github.com/m-labs/smoltcp.git)", ] [[package]] @@ -349,6 +342,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "smoltcp" version = "0.4.0" +source = "git+https://github.com/m-labs/smoltcp.git#c2d18ec071a2cd68aee2724ce13eefa6ccf1f0c1" dependencies = [ "byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "managed 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -509,7 +503,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum rand 0.3.20 (registry+https://github.com/rust-lang/crates.io-index)" = "512870020642bb8c221bf68baa1b2573da814f6ccfe5c9699b1c303047abe9b1" "checksum rayon 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a77c51c07654ddd93f6cb543c7a849863b03abc7e82591afda6dc8ad4ac3ac4a" "checksum rayon-core 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e64b609139d83da75902f88fd6c01820046840a18471e4dfcd5ac7c0f46bea53" -"checksum redox_event 0.1.0 (git+https://github.com/batonius/event.git?branch=default_callback)" = "" "checksum redox_event 0.1.0 (git+https://github.com/redox-os/event.git)" = "" "checksum redox_syscall 0.1.37 (git+https://github.com/redox-os/syscall.git)" = "" "checksum redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "0d92eecebad22b767915e4d529f89f28ee96dbbf5a4810d2b844373f136417fd" @@ -518,6 +511,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum rustls 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "17727f4b991294da2c84d75a43c003151ff58072212768800f66c56ee46dca43" "checksum safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e27a8b19b835f7aea908818e871f5cc3a5a186550c30773be987e155e8163d8f" "checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" +"checksum smoltcp 0.4.0 (git+https://github.com/m-labs/smoltcp.git)" = "" "checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" "checksum time 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "a15375f1df02096fb3317256ce2cee6a1f42fc84ea5ad5fc8c421cfe40c73098" "checksum traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079" diff --git a/Cargo.toml b/Cargo.toml index 8c2b6743d3..ecf958647a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ path = "src/lib/lib.rs" [dependencies] netutils = { git = "https://github.com/redox-os/netutils.git" } -redox_event = { git = "https://github.com/batonius/event.git", branch = "default_callback" } +redox_event = { git = "https://github.com/redox-os/event.git" } redox_syscall = { git = "https://github.com/redox-os/syscall.git" } byteorder = { version = "1.0", default-features = false } dns-parser = "0.7.1" @@ -27,10 +27,7 @@ default-features = false features = ["release_max_level_off"] [dependencies.smoltcp] -path = "../smoltcp" -# git = "https://github.com/m-labs/smoltcp.git" -# git = "https://github.com/batonius/smoltcp.git" -branch = "unspecified_src" +git = "https://github.com/m-labs/smoltcp.git" default-features = false features = ["std", "socket-raw", "proto-ipv4", "socket-udp", "socket-tcp", "socket-icmp"] diff --git a/src/dnsd/main.rs b/src/dnsd/main.rs index 5b97211707..73babd05fd 100644 --- a/src/dnsd/main.rs +++ b/src/dnsd/main.rs @@ -58,8 +58,7 @@ fn run() -> Result<()> { } fn main() { - // if unsafe { syscall::clone(0).unwrap() } == 0 - { + if unsafe { syscall::clone(0).unwrap() } == 0 { logger::init_logger(); if let Err(err) = run() { error!("dnsd: {}", err); diff --git a/src/dnsd/scheme.rs b/src/dnsd/scheme.rs index 0e76bc7e5d..3be32c1d8d 100644 --- a/src/dnsd/scheme.rs +++ b/src/dnsd/scheme.rs @@ -2,6 +2,7 @@ use redox_netstack::error::{Error, Result}; use event::{subscribe_to_fd, unsubscribe_from_fd}; use std::borrow::ToOwned; use std::collections::{BTreeMap, BTreeSet}; +use std::collections::VecDeque; use std::collections::btree_map::Entry; use std::fs::File; use std::io::{Read, Write}; @@ -9,6 +10,7 @@ use std::mem; use std::os::unix::io::RawFd; use std::str; use std::rc::Rc; +use syscall::data::TimeSpec; use syscall::{Error as SyscallError, Packet as SyscallPacket, Result as SyscallResult, SchemeMut}; use syscall; @@ -18,6 +20,8 @@ use dns_parser::{QueryClass, QueryType}; enum DnsFile { Resolved { data: Rc<[u8]>, pos: usize }, Waiting { domain: String }, + Timeout, + Failed, } enum Domain { @@ -30,9 +34,16 @@ enum Domain { }, } +enum DnsParsingResult { + WakeUpFiles(BTreeSet), + FailFiles(BTreeSet), +} + struct Domains { - domains: BTreeMap, - requests: BTreeMap, + domains: BTreeMap, Domain>, + requests: BTreeMap>, + resolved_timeouts: VecDeque<(TimeSpec, Rc)>, + requested_timeouts: VecDeque<(TimeSpec, Rc)>, } impl Domains { @@ -40,6 +51,8 @@ impl Domains { Domains { domains: BTreeMap::new(), requests: BTreeMap::new(), + resolved_timeouts: VecDeque::new(), + requested_timeouts: VecDeque::new(), } } @@ -47,29 +60,71 @@ impl Domains { trace!("Requesting domain {}", domain); let mut builder = Builder::new_query(1, true); builder.add_question(domain, QueryType::A, QueryClass::IN); - let packet = match builder.build() { - Ok(packet) => packet, - _ => return None, - }; - let udp_fd = match syscall::open( + let packet = builder.build().ok()?; + let udp_fd = syscall::open( "udp:8.8.8.8:53", syscall::O_RDWR | syscall::O_CREAT | syscall::O_NONBLOCK, - ) { - Ok(fd) => fd as RawFd, - _ => return None, - }; + ).ok()? as RawFd; if syscall::write(udp_fd as usize, &packet) != Ok(packet.len()) { - syscall::close(udp_fd as usize); + syscall::close(udp_fd as usize).ok()?; return None; } - trace!("Requesting domain {} fd {}", domain, udp_fd); - subscribe_to_fd(udp_fd); - self.requests.insert(udp_fd, domain.to_owned()); + subscribe_to_fd(udp_fd).ok()?; + self.requests.insert(udp_fd, domain.to_owned().into()); Some(udp_fd) } - fn on_fd_event(&mut self, fd: RawFd) -> Option> { - trace!("On FD event {}", fd); + fn on_time_event(&mut self, cur_time: &TimeSpec) -> BTreeSet { + while let Some((timeout, domain)) = self.resolved_timeouts.pop_front() { + if timeout.tv_sec > cur_time.tv_sec + || (timeout.tv_sec == cur_time.tv_sec && timeout.tv_nsec > cur_time.tv_nsec) + { + self.resolved_timeouts.push_front((timeout, domain)); + break; + } + trace!("Timing out resolved domain {:?}", domain); + match self.domains.entry(domain) { + Entry::Vacant(_) => {} + Entry::Occupied(e) => { + if let Domain::Resolved { .. } = *e.get() { + e.remove(); + } + } + } + } + + let mut fds_to_wakeup = BTreeSet::new(); + + while let Some((timeout, domain)) = self.requested_timeouts.pop_front() { + if timeout.tv_sec > cur_time.tv_sec + || (timeout.tv_sec == cur_time.tv_sec && timeout.tv_nsec > cur_time.tv_nsec) + { + self.requested_timeouts.push_front((timeout, domain)); + break; + } + trace!("Timing out requested domain {:?}", domain); + match self.domains.entry(domain) { + Entry::Vacant(_) => {} + Entry::Occupied(e) => { + if let Domain::Requested { .. } = *e.get() { + if let Domain::Requested { + mut waiting_fds, + socket_fd, + } = e.remove() + { + fds_to_wakeup.append(&mut waiting_fds); + let _ = unsubscribe_from_fd(socket_fd); + let _ = syscall::close(socket_fd as usize); + } + } + } + } + } + + fds_to_wakeup + } + + fn on_fd_event(&mut self, fd: RawFd, cur_time: &TimeSpec) -> Option { let e = match self.requests.entry(fd) { Entry::Vacant(_) => { return None; @@ -77,39 +132,59 @@ impl Domains { Entry::Occupied(e) => e, }; let mut buf = [0u8; 4096]; - let readed = match syscall::read(fd as usize, &mut buf) { - Ok(readed) => readed, - _ => { - return None; - } - }; - let pkt = match DNSPacket::parse(&buf) { - Ok(pkt) => pkt, - _ => { - return None; - } - }; + let readed = syscall::read(fd as usize, &mut buf).ok()?; + if readed == 0 { + return None; + } + let pkt = DNSPacket::parse(&buf).ok()?; if pkt.header.response_code != ResponseCode::NoError || pkt.answers.len() == 0 { + if let Some(query) = pkt.questions.iter().next() { + if query.qname.to_string().to_lowercase() == e.get().as_ref() { + unsubscribe_from_fd(fd).ok()?; + syscall::close(fd as usize).ok()?; + let domain = e.remove(); + self.requested_timeouts + .retain(|&(_, ref d)| d.as_ref() != domain.as_ref()); + if let Entry::Occupied(mut e) = self.domains.entry(domain) { + let domain_data = e.remove(); + return if let Domain::Requested { waiting_fds, .. } = domain_data { + Some(DnsParsingResult::FailFiles(waiting_fds)) + } else { + None + }; + } + } + } return None; } let mut result = String::new(); for answer in pkt.answers { - match answer.data { - RRData::A(ip) => { - result += &format!("{}\n", ip); - } - _ => {} // ignore + if answer.name.to_string().to_lowercase() != e.get().as_ref() { + continue; + } + if let RRData::A(ip) = answer.data { + result += &format!("{}\n", ip); } } if result.is_empty() { return None; } let data = Rc::from(result.into_bytes()); - syscall::close(fd as usize); - unsubscribe_from_fd(fd); + unsubscribe_from_fd(fd).ok()?; + syscall::close(fd as usize).ok()?; let domain = e.remove(); let mut domain_data = Domain::Resolved { data }; trace!("On FD event {} {} resolved", fd, domain); + + let mut resolved_timeout = *cur_time; + resolved_timeout.tv_sec += Dnsd::RESOLVED_TIMEOUT_S; + + self.resolved_timeouts + .push_back((resolved_timeout, Rc::clone(&domain))); + + self.requested_timeouts + .retain(|&(_, ref d)| d.as_ref() != domain.as_ref()); + match self.domains.entry(domain) { Entry::Vacant(e) => { e.insert(domain_data); @@ -118,7 +193,7 @@ impl Domains { Entry::Occupied(mut e) => { mem::swap(e.get_mut(), &mut domain_data); if let Domain::Requested { waiting_fds, .. } = domain_data { - Some(waiting_fds) + Some(DnsParsingResult::WakeUpFiles(waiting_fds)) } else { None } @@ -126,8 +201,8 @@ impl Domains { } } - fn file_from_domain(&mut self, domain: &str, fd: usize) -> DnsFile { - if let Some(mut domain_data) = self.domains.get_mut(domain) { + fn file_from_domain(&mut self, domain: &str, fd: usize, cur_time: &TimeSpec) -> DnsFile { + if let Some(domain_data) = self.domains.get_mut(domain) { match *domain_data { Domain::Resolved { ref data } => DnsFile::Resolved { data: Rc::clone(data), @@ -146,14 +221,18 @@ impl Domains { } else { if let Some(socket_fd) = self.request_domain(domain) { let mut waiting_fds = BTreeSet::new(); + let domain = domain.to_owned().into(); waiting_fds.insert(fd); self.domains.insert( - domain.to_owned(), + Rc::clone(&domain), Domain::Requested { waiting_fds, socket_fd, }, ); + let mut timeout = *cur_time; + timeout.tv_sec += Dnsd::REQUEST_TIMEOUT_S; + self.requested_timeouts.push_back((timeout, domain)); } DnsFile::Waiting { domain: domain.to_owned(), @@ -162,7 +241,7 @@ impl Domains { } fn unwait_fd(&mut self, domain: &str, fd: usize) { - if let Some(mut domain_data) = self.domains.get_mut(domain) { + if let Some(domain_data) = self.domains.get_mut(domain) { if let Domain::Requested { ref mut waiting_fds, .. @@ -184,6 +263,10 @@ pub struct Dnsd { } impl Dnsd { + const RESOLVED_TIMEOUT_S: i64 = 5 * 60; + const REQUEST_TIMEOUT_S: i64 = 30; + const TIME_EVENT_TIMEOUT_S: i64 = 5; + pub fn new(dns_file: File, time_file: File) -> Dnsd { Dnsd { dns_file, @@ -196,6 +279,28 @@ impl Dnsd { } pub fn on_time_event(&mut self) -> Result> { + let mut time = TimeSpec::default(); + if self.time_file.read(&mut time)? < mem::size_of::() { + return Err(Error::from_syscall_error( + syscall::Error::new(syscall::EBADF), + "Can't read current time", + )); + } + + let fds_to_wakeup = self.domains.on_time_event(&time); + if !fds_to_wakeup.is_empty() { + for fd in &fds_to_wakeup { + if let Some(file) = self.files.get_mut(&fd) { + *file = DnsFile::Timeout; + } + } + self.wakeup_fds(fds_to_wakeup); + } + + time.tv_sec += Dnsd::TIME_EVENT_TIMEOUT_S; + self.time_file + .write_all(&time) + .map_err(|e| Error::from_io_error(e, "Failed to write to time file"))?; Ok(None) } @@ -218,41 +323,75 @@ impl Dnsd { } pub fn on_unknown_fd_event(&mut self, fd: RawFd) -> Result> { - trace!("Unknown fd event {}", fd); - if let Some(fds_to_wakeup) = self.domains.on_fd_event(fd) { - let mut syscall_packets = vec![]; - for fd in &fds_to_wakeup { - if let Some(packet) = self.wait_map.remove(&fd) { - syscall_packets.push(packet); - } - } + let mut cur_time = TimeSpec::default(); + syscall::clock_gettime(syscall::CLOCK_MONOTONIC, &mut cur_time) + .map_err(|e| Error::from_syscall_error(e, "Can't get time"))?; - for mut packet in syscall_packets.drain(..) { - self.handle(&mut packet); - let _ = self.dns_file.write_all(&packet); + match self.domains.on_fd_event(fd, &cur_time) { + Some(DnsParsingResult::FailFiles(fds_to_fail)) => { + for fd in &fds_to_fail { + if let Some(file) = self.files.get_mut(&fd) { + *file = DnsFile::Failed; + } + } + self.wakeup_fds(fds_to_fail); } + Some(DnsParsingResult::WakeUpFiles(fds_to_wakeup)) => { + self.wakeup_fds(fds_to_wakeup); + } + None => {} } Ok(None) } + fn wakeup_fds(&mut self, fds_to_wakeup: BTreeSet) { + let mut syscall_packets = vec![]; + for fd in &fds_to_wakeup { + if let Some(packet) = self.wait_map.remove(&fd) { + syscall_packets.push(packet); + } + } + + for mut packet in syscall_packets.drain(..) { + self.handle(&mut packet); + let _ = self.dns_file.write_all(&packet); + } + } + fn handle_block(&mut self, packet: SyscallPacket) -> Result<()> { let fd = packet.b; self.wait_map.insert(fd, packet); Ok(()) } + + fn validate_domain(domain: &str) -> bool { + if domain.len() > 256 { + return false; + } + + for part in domain.split('.') { + if part.len() >= 63 { + return false; + } + } + + return true; + } } impl SchemeMut for Dnsd { - fn open(&mut self, url: &[u8], flags: usize, _uid: u32, _gid: u32) -> SyscallResult { - trace!("Open"); - let domain = str::from_utf8(url).or_else(|_| Err(SyscallError::new(syscall::EINVAL)))?; - trace!("Open {}", &domain); - if domain.is_empty() { + fn open(&mut self, url: &[u8], _flags: usize, _uid: u32, _gid: u32) -> SyscallResult { + let domain = str::from_utf8(url) + .or_else(|_| Err(SyscallError::new(syscall::EINVAL)))? + .to_lowercase(); + if domain.is_empty() || !Dnsd::validate_domain(&domain) { return Err(SyscallError::new(syscall::EINVAL)); } let fd = self.next_fd; self.next_fd += 1; - let dns_file = self.domains.file_from_domain(domain, fd); + let mut cur_time = TimeSpec::default(); + syscall::clock_gettime(syscall::CLOCK_MONOTONIC, &mut cur_time)?; + let dns_file = self.domains.file_from_domain(&domain, fd, &cur_time); self.files.insert(fd, dns_file); trace!("Open {} {}", &domain, fd); Ok(fd) @@ -260,7 +399,7 @@ impl SchemeMut for Dnsd { fn close(&mut self, fd: usize) -> SyscallResult { trace!("Close {}", fd); - let mut file = self.files + let file = self.files .get_mut(&fd) .ok_or_else(|| SyscallError::new(syscall::EBADF))?; @@ -272,18 +411,21 @@ impl SchemeMut for Dnsd { Ok(0) } - fn write(&mut self, fd: usize, buf: &[u8]) -> SyscallResult { + fn write(&mut self, _fd: usize, _buf: &[u8]) -> SyscallResult { Err(SyscallError::new(syscall::EINVAL)) } fn read(&mut self, fd: usize, buf: &mut [u8]) -> SyscallResult { trace!("Read {}", fd); - let mut file = self.files + let file = self.files .get_mut(&fd) .ok_or_else(|| SyscallError::new(syscall::EBADF))?; + let mut cur_time = TimeSpec::default(); + syscall::clock_gettime(syscall::CLOCK_MONOTONIC, &mut cur_time)?; + if let DnsFile::Waiting { ref domain } = *file { - *file = self.domains.file_from_domain(domain, fd) + *file = self.domains.file_from_domain(domain, fd, &cur_time); } match *file { @@ -300,14 +442,16 @@ impl SchemeMut for Dnsd { Ok(i) } DnsFile::Waiting { .. } => Err(SyscallError::new(syscall::EWOULDBLOCK)), + DnsFile::Timeout => Err(SyscallError::new(syscall::ETIMEDOUT)), + DnsFile::Failed => Err(SyscallError::new(syscall::ENODATA)), } } - fn fevent(&mut self, fd: usize, events: usize) -> SyscallResult { + fn fevent(&mut self, _fd: usize, _events: usize) -> SyscallResult { Ok(0) } - fn fsync(&mut self, fd: usize) -> SyscallResult { + fn fsync(&mut self, _fd: usize) -> SyscallResult { Ok(0) } } From a7f365d96cb99a8c046c3d60c74a06a745c4b6e9 Mon Sep 17 00:00:00 2001 From: Egor Karavaev Date: Wed, 10 Jan 2018 01:38:23 +0300 Subject: [PATCH 065/155] Add the `netcfg` schema. --- src/smolnetd/main.rs | 19 ++- src/smolnetd/scheme/mod.rs | 78 +++++---- src/smolnetd/scheme/netcfg.rs | 292 ++++++++++++++++++++++++++++++++++ 3 files changed, 355 insertions(+), 34 deletions(-) create mode 100644 src/smolnetd/scheme/netcfg.rs diff --git a/src/smolnetd/main.rs b/src/smolnetd/main.rs index 673a1b02cc..62233cf90d 100644 --- a/src/smolnetd/main.rs +++ b/src/smolnetd/main.rs @@ -52,12 +52,17 @@ fn run() -> Result<()> { .map_err(|e| Error::from_syscall_error(e, "failed to open :icmp"))? as RawFd; + trace!("opening :netcfg"); + let netcfg_fd = syscall::open(":netcfg", O_RDWR | O_CREAT | O_NONBLOCK) + .map_err(|e| Error::from_syscall_error(e, "failed to open :netcfg"))? + as RawFd; + let time_path = format!("time:{}", syscall::CLOCK_MONOTONIC); let time_fd = syscall::open(&time_path, syscall::O_RDWR) .map_err(|e| Error::from_syscall_error(e, "failed to open time:"))? as RawFd; - let (network_file, ip_file, time_file, udp_file, tcp_file, icmp_file) = unsafe { + let (network_file, ip_file, time_file, udp_file, tcp_file, icmp_file, netcfg_file) = unsafe { ( File::from_raw_fd(network_fd), File::from_raw_fd(ip_fd), @@ -65,6 +70,7 @@ fn run() -> Result<()> { File::from_raw_fd(udp_fd), File::from_raw_fd(tcp_fd), File::from_raw_fd(icmp_fd), + File::from_raw_fd(netcfg_fd), ) }; @@ -75,6 +81,7 @@ fn run() -> Result<()> { tcp_file, icmp_file, time_file, + netcfg_file, ))); let mut event_queue = EventQueue::<(), Error>::new() @@ -120,10 +127,18 @@ fn run() -> Result<()> { }) .map_err(|e| Error::from_io_error(e, "failed to listen to icmp events"))?; + let smolnetd_ = Rc::clone(&smolnetd); + event_queue - .add(time_fd, move |_| smolnetd.borrow_mut().on_time_event()) + .add(time_fd, move |_| smolnetd_.borrow_mut().on_time_event()) .map_err(|e| Error::from_io_error(e, "failed to listen to time events"))?; + event_queue + .add(netcfg_fd, move |_| { + smolnetd.borrow_mut().on_netcfg_scheme_event() + }) + .map_err(|e| Error::from_io_error(e, "failed to listen to netcfg events"))?; + event_queue.trigger_all(0)?; event_queue.run() diff --git a/src/smolnetd/scheme/mod.rs b/src/smolnetd/scheme/mod.rs index 6ba011acaf..611e41810d 100644 --- a/src/smolnetd/scheme/mod.rs +++ b/src/smolnetd/scheme/mod.rs @@ -1,10 +1,10 @@ use netutils::getcfg; use smoltcp; -use smoltcp::iface::{NeighborCache, EthernetInterface, EthernetInterfaceBuilder}; +use smoltcp::iface::{EthernetInterface, EthernetInterfaceBuilder, NeighborCache}; use smoltcp::socket::SocketSet as SmoltcpSocketSet; use smoltcp::wire::{EthernetAddress, IpAddress, IpCidr, IpEndpoint, Ipv4Address}; use std::cell::RefCell; -use std::collections::{VecDeque, BTreeMap}; +use std::collections::{BTreeMap, VecDeque}; use std::fs::File; use std::io::{Read, Write}; use std::mem::size_of; @@ -21,20 +21,23 @@ use self::ip::IpScheme; use self::tcp::TcpScheme; use self::udp::UdpScheme; use self::icmp::IcmpScheme; +use self::netcfg::NetCfgScheme; mod ip; mod socket; mod tcp; mod udp; mod icmp; +mod netcfg; type SocketSet = SmoltcpSocketSet<'static, 'static, 'static>; +type Interface = Rc>>; pub struct Smolnetd { network_file: Rc>, time_file: File, - iface: EthernetInterface<'static, 'static, NetworkDevice>, + iface: Interface, socket_set: Rc>, startup_time: Instant, @@ -43,6 +46,7 @@ pub struct Smolnetd { udp_scheme: UdpScheme, tcp_scheme: TcpScheme, icmp_scheme: IcmpScheme, + netcfg_scheme: NetCfgScheme, input_queue: Rc>>, buffer_pool: Rc>, @@ -61,6 +65,7 @@ impl Smolnetd { tcp_file: File, icmp_file: File, time_file: File, + netcfg_file: File, ) -> Smolnetd { let hardware_addr = EthernetAddress::from_str(getcfg("mac").unwrap().trim()) .expect("Can't parse the 'mac' cfg"); @@ -83,14 +88,15 @@ impl Smolnetd { Rc::clone(&buffer_pool), ); let iface = EthernetInterfaceBuilder::new(network_device) - .neighbor_cache(NeighborCache::new(BTreeMap::new())) - .ethernet_addr(hardware_addr) - .ip_addrs(protocol_addrs) - .ipv4_gateway(default_gw) - .finalize(); + .neighbor_cache(NeighborCache::new(BTreeMap::new())) + .ethernet_addr(hardware_addr) + .ip_addrs(protocol_addrs) + .ipv4_gateway(default_gw) + .finalize(); + let iface = Rc::new(RefCell::new(iface)); let socket_set = Rc::new(RefCell::new(SocketSet::new(vec![]))); Smolnetd { - iface, + iface: Rc::clone(&iface), socket_set: Rc::clone(&socket_set), startup_time: Instant::now(), time_file, @@ -98,6 +104,7 @@ impl Smolnetd { udp_scheme: UdpScheme::new(Rc::clone(&socket_set), udp_file), tcp_scheme: TcpScheme::new(Rc::clone(&socket_set), tcp_file), icmp_scheme: IcmpScheme::new(Rc::clone(&socket_set), icmp_file), + netcfg_scheme: NetCfgScheme::new(Rc::clone(&iface), netcfg_file), input_queue, network_file, buffer_pool, @@ -141,6 +148,11 @@ impl Smolnetd { Ok(None) } + pub fn on_netcfg_scheme_event(&mut self) -> Result> { + self.netcfg_scheme.on_scheme_event()?; + Ok(None) + } + fn schedule_time_event(&mut self, timeout: i64) -> Result<()> { let mut time = TimeSpec::default(); if self.time_file.read(&mut time)? < size_of::() { @@ -160,30 +172,34 @@ impl Smolnetd { } fn poll(&mut self) -> Result { - let mut iter_limit = 10usize; - let timeout = loop { - iter_limit -= 1; - if iter_limit == 0 { - break 0; - } + let timeout = { + let mut iter_limit = 10usize; + let mut iface = self.iface.borrow_mut(); + let mut socket_set = self.socket_set.borrow_mut(); let timestamp = self.get_timestamp(); - match self.iface.poll(&mut *self.socket_set.borrow_mut(), timestamp) { - Ok(_) => (), - Err(smoltcp::Error::Unrecognized) => (), - Err(e) => { - error!("poll error: {}", e); - break 0 + loop { + if iter_limit == 0 { + break 0; + } + iter_limit -= 1; + match iface.poll(&mut socket_set, timestamp) { + Ok(_) => (), + Err(smoltcp::Error::Unrecognized) => (), + Err(e) => { + error!("poll error: {}", e); + break 0 + } + } + match iface.poll_at(&socket_set, timestamp) { + Some(n) if n > timestamp => { + break ::std::cmp::min(::std::i64::MAX as u64, n - timestamp) as i64 + }, + Some(_) => {}, + None => break ::std::i64::MAX } } - self.notify_sockets()?; - match self.iface.poll_at(&*self.socket_set.borrow(), timestamp) { - Some(n) if n > timestamp => { - break ::std::cmp::min(::std::i64::MAX as u64, n - timestamp) as i64 - }, - Some(_) => {}, - None => break ::std::i64::MAX - } }; + self.notify_sockets()?; Ok(::std::cmp::min( ::std::cmp::max(Smolnetd::MIN_CHECK_TIMEOUT_MS, timeout), Smolnetd::MAX_CHECK_TIMEOUT_MS, @@ -197,9 +213,7 @@ impl Smolnetd { let count = self.network_file .borrow_mut() .read(&mut buffer) - .map_err(|e| { - Error::from_io_error(e, "Failed to read from network file") - })?; + .map_err(|e| Error::from_io_error(e, "Failed to read from network file"))?; if count == 0 { break; } diff --git a/src/smolnetd/scheme/netcfg.rs b/src/smolnetd/scheme/netcfg.rs new file mode 100644 index 0000000000..8e4833fec1 --- /dev/null +++ b/src/smolnetd/scheme/netcfg.rs @@ -0,0 +1,292 @@ +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::fs::File; +use std::io::{Read, Write}; +use std::str; +use std::rc::Rc; +use std::iter::FromIterator; +use syscall::data::Stat; +use syscall::flag::{MODE_DIR, MODE_FILE}; +use syscall::{Error as SyscallError, Packet as SyscallPacket, Result as SyscallResult, SchemeMut}; +use syscall; + +use error::Result; +use super::Interface; + +type CfgNodeRef = Rc>; + +trait CfgNode { + fn is_dir(&self) -> bool { + false + } + + fn is_writable(&self) -> bool { + false + } + + fn is_readable(&self) -> bool { + true + } + + fn read(&self) -> Vec { + vec![] + } + + fn write(&mut self, _buf: &[u8]) -> Option { + None + } + + fn open(&self, _file: &str) -> Option { + None + } + + fn close(&mut self) {} +} + +struct RONode +where + F: Fn() -> Vec, +{ + read_fun: F, +} + +impl CfgNode for RONode +where + F: Fn() -> Vec, +{ + fn read(&self) -> Vec { + (self.read_fun)() + } +} + +impl RONode +where + F: 'static + Fn() -> Vec, +{ + fn new(read_fun: F) -> CfgNodeRef { + Rc::new(RefCell::new(RONode { read_fun })) + } +} + +struct StaticDirNode { + child_nodes: BTreeMap, +} + +impl CfgNode for StaticDirNode { + fn is_dir(&self) -> bool { + true + } + + fn read(&self) -> Vec { + let mut files = vec![]; + for child in self.child_nodes.keys() { + if !files.is_empty() { + files.push(b'\n'); + } + files.extend(child.bytes()); + } + files + } + + fn open(&self, file: &str) -> Option { + self.child_nodes.get(file).map(|node| Rc::clone(node)) + } +} + +impl StaticDirNode { + pub fn new(child_nodes: BTreeMap) -> CfgNodeRef { + Rc::new(RefCell::new(StaticDirNode { child_nodes })) + } +} + +struct RootNode { + route_node: CfgNodeRef, + iface_nodes: BTreeMap, +} + +impl RootNode { + pub fn new(iface: Interface) -> RootNode { + let route_list_node = RONode::new(move || { + let default_route = if let Some(ip) = iface.borrow().ipv4_gateway() { + format!("default via {}\n", ip) + } else { + String::new() + }; + Vec::from_iter(default_route.bytes()) + }); + let mut route_child_nodes = BTreeMap::new(); + route_child_nodes.insert("list".to_owned(), route_list_node); + let route_node = StaticDirNode::new(route_child_nodes); + let iface_nodes = BTreeMap::new(); + // let eth0_node: CfgNodeRef = Rc::new(RefCell::new(IfaceNode::new(iface))); + // iface_nodes.insert("eth0".to_owned(), eth0_node); + RootNode { + route_node, + iface_nodes, + } + } +} + +impl CfgNode for RootNode { + fn is_dir(&self) -> bool { + true + } + + fn open(&self, file: &str) -> Option { + match file { + "route" => Some(Rc::clone(&self.route_node)), + _ => self.iface_nodes.get(file).map(|node| Rc::clone(node)), + } + } + + fn read(&self) -> Vec { + let mut files = vec![]; + files.extend_from_slice(b"route"); + for iface in self.iface_nodes.keys() { + files.push(b'\n'); + files.extend(iface.bytes()); + } + files + } +} + +struct NetCfgFile { + cfg_node: CfgNodeRef, + data: Option>, + pos: usize, + uid: u32, +} + +pub struct NetCfgScheme { + scheme_file: File, + next_fd: usize, + files: BTreeMap, + root_node: CfgNodeRef, +} + +impl NetCfgScheme { + pub fn new(iface: Interface, scheme_file: File) -> NetCfgScheme { + NetCfgScheme { + scheme_file, + next_fd: 1, + files: BTreeMap::new(), + root_node: Rc::new(RefCell::new(RootNode::new(iface))), + } + } + + pub fn on_scheme_event(&mut self) -> Result> { + loop { + let mut packet = SyscallPacket::default(); + if self.scheme_file.read(&mut packet)? == 0 { + break; + } + self.handle(&mut packet); + self.scheme_file.write_all(&packet)?; + } + Ok(None) + } +} + +impl SchemeMut for NetCfgScheme { + fn open(&mut self, url: &[u8], _flags: usize, uid: u32, _gid: u32) -> SyscallResult { + let path = str::from_utf8(url).or_else(|_| Err(SyscallError::new(syscall::EINVAL)))?; + let mut current_node = Rc::clone(&self.root_node); + for part in path.split('/') { + if part.is_empty() { + continue; + } + let next_node = current_node + .borrow_mut() + .open(part) + .ok_or_else(|| SyscallError::new(syscall::EINVAL))?; + current_node = next_node; + } + let fd = self.next_fd; + self.next_fd += 1; + self.files.insert( + fd, + NetCfgFile { + cfg_node: current_node, + uid, + pos: 0, + data: None, + }, + ); + Ok(fd) + } + + fn close(&mut self, fd: usize) -> SyscallResult { + self.files + .get(&fd) + .ok_or_else(|| SyscallError::new(syscall::EBADF))? + .cfg_node + .borrow_mut() + .close(); + self.files.remove(&fd); + Ok(0) + } + + fn write(&mut self, fd: usize, buf: &[u8]) -> SyscallResult { + let file = self.files + .get(&fd) + .ok_or_else(|| SyscallError::new(syscall::EBADF))?; + if file.uid != 0 { + return Err(SyscallError::new(syscall::EACCES)); + } + file.cfg_node + .borrow_mut() + .write(buf) + .ok_or_else(|| SyscallError::new(syscall::EINVAL)) + } + + fn read(&mut self, fd: usize, buf: &mut [u8]) -> SyscallResult { + let file = self.files + .get_mut(&fd) + .ok_or_else(|| SyscallError::new(syscall::EBADF))?; + if file.data.is_none() { + file.data = Some(file.cfg_node.borrow().read()) + } + if let Some(ref data) = file.data { + let mut i = 0; + while i < buf.len() && file.pos < data.len() { + buf[i] = data[file.pos]; + i += 1; + file.pos += 1; + } + return Ok(i); + } + Err(SyscallError::new(syscall::EINVAL)) + } + + fn fstat(&mut self, fd: usize, stat: &mut Stat) -> SyscallResult { + let file = self.files + .get_mut(&fd) + .ok_or_else(|| SyscallError::new(syscall::EBADF))?; + let cfg_node = file.cfg_node.borrow(); + + stat.st_mode = if cfg_node.is_dir() { + MODE_DIR + } else { + MODE_FILE + }; + if cfg_node.is_writable() { + stat.st_mode |= 0o222; + } + if cfg_node.is_readable() { + stat.st_mode |= 0o444; + } + stat.st_uid = 0; + stat.st_gid = 0; + + if file.data.is_none() { + file.data = Some(file.cfg_node.borrow().read()) + } + if let Some(ref data) = file.data { + stat.st_size = data.len() as u64; + } else { + stat.st_size = 0; + } + + Ok(0) + } +} From 1e9580824252aae98d1c09985cbadf6bba873b33 Mon Sep 17 00:00:00 2001 From: Egor Karavaev Date: Thu, 11 Jan 2018 00:57:18 +0300 Subject: [PATCH 066/155] netcfg write nodes --- src/smolnetd/scheme/icmp.rs | 6 +- src/smolnetd/scheme/mod.rs | 8 +- src/smolnetd/scheme/netcfg.rs | 262 +++++++++++++++++++++++----------- src/smolnetd/scheme/socket.rs | 11 +- 4 files changed, 193 insertions(+), 94 deletions(-) diff --git a/src/smolnetd/scheme/icmp.rs b/src/smolnetd/scheme/icmp.rs index bccb75a3b0..cacb9f6605 100644 --- a/src/smolnetd/scheme/icmp.rs +++ b/src/smolnetd/scheme/icmp.rs @@ -92,8 +92,10 @@ impl<'a, 'b> SchemeSocket for IcmpSocket<'a, 'b> { tx_packets.push(IcmpPacketBuffer::new(vec![0; NetworkDevice::MTU])); } - let socket = IcmpSocket::new(IcmpSocketBuffer::new(rx_packets), - IcmpSocketBuffer::new(tx_packets)); + let socket = IcmpSocket::new( + IcmpSocketBuffer::new(rx_packets), + IcmpSocketBuffer::new(tx_packets), + ); let handle = socket_set.add(socket); let mut icmp_socket = socket_set.get::(handle); let ident = ident_set diff --git a/src/smolnetd/scheme/mod.rs b/src/smolnetd/scheme/mod.rs index 611e41810d..9a0d4742ab 100644 --- a/src/smolnetd/scheme/mod.rs +++ b/src/smolnetd/scheme/mod.rs @@ -187,15 +187,15 @@ impl Smolnetd { Err(smoltcp::Error::Unrecognized) => (), Err(e) => { error!("poll error: {}", e); - break 0 + break 0; } } match iface.poll_at(&socket_set, timestamp) { Some(n) if n > timestamp => { break ::std::cmp::min(::std::i64::MAX as u64, n - timestamp) as i64 - }, - Some(_) => {}, - None => break ::std::i64::MAX + } + Some(_) => {} + None => break ::std::i64::MAX, } } }; diff --git a/src/smolnetd/scheme/netcfg.rs b/src/smolnetd/scheme/netcfg.rs index 8e4833fec1..7bf9049657 100644 --- a/src/smolnetd/scheme/netcfg.rs +++ b/src/smolnetd/scheme/netcfg.rs @@ -3,8 +3,10 @@ use std::collections::BTreeMap; use std::fs::File; use std::io::{Read, Write}; use std::str; +use std::str::FromStr; use std::rc::Rc; use std::iter::FromIterator; +use smoltcp::wire::{EthernetAddress, Ipv4Address}; use syscall::data::Stat; use syscall::flag::{MODE_DIR, MODE_FILE}; use syscall::{Error as SyscallError, Packet as SyscallPacket, Result as SyscallResult, SchemeMut}; @@ -13,6 +15,8 @@ use syscall; use error::Result; use super::Interface; +const WRITE_BUFFER_MAX_SIZE: usize = 0xffff; + type CfgNodeRef = Rc>; trait CfgNode { @@ -32,15 +36,13 @@ trait CfgNode { vec![] } - fn write(&mut self, _buf: &[u8]) -> Option { - None + fn write(&self, _buf: &[u8]) -> SyscallResult { + Ok(0) } fn open(&self, _file: &str) -> Option { None } - - fn close(&mut self) {} } struct RONode @@ -68,6 +70,75 @@ where } } +struct WONode +where + F: Fn(&[u8]) -> SyscallResult, +{ + write_fun: F, +} + +impl CfgNode for WONode +where + F: Fn(&[u8]) -> SyscallResult, +{ + fn write(&self, buf: &[u8]) -> SyscallResult { + (self.write_fun)(buf) + } + + fn is_writable(&self) -> bool { + true + } +} + +impl WONode +where + F: 'static + Fn(&[u8]) -> SyscallResult, +{ + fn new(write_fun: F) -> CfgNodeRef { + Rc::new(RefCell::new(WONode { write_fun })) + } +} + +struct RWNode +where + F: Fn() -> Vec, + G: Fn(&[u8]) -> SyscallResult, +{ + read_fun: F, + write_fun: G, +} + +impl CfgNode for RWNode +where + F: Fn() -> Vec, + G: Fn(&[u8]) -> SyscallResult, +{ + fn read(&self) -> Vec { + (self.read_fun)() + } + + fn write(&self, buf: &[u8]) -> SyscallResult { + (self.write_fun)(buf) + } + + fn is_writable(&self) -> bool { + true + } +} + +impl RWNode +where + F: 'static + Fn() -> Vec, + G: 'static + Fn(&[u8]) -> SyscallResult, +{ + fn new(read_fun: F, write_fun: G) -> CfgNodeRef { + Rc::new(RefCell::new(RWNode { + read_fun, + write_fun, + })) + } +} + struct StaticDirNode { child_nodes: BTreeMap, } @@ -99,60 +170,97 @@ impl StaticDirNode { } } -struct RootNode { - route_node: CfgNodeRef, - iface_nodes: BTreeMap, +fn parse_default_gw(buf: &[u8]) -> SyscallResult { + let value = str::from_utf8(buf).or_else(|_| Err(SyscallError::new(syscall::EINVAL)))?; + let mut routes = value.lines(); + if let Some(route) = routes.next() { + if !routes.next().is_none() { + return Err(SyscallError::new(syscall::EINVAL)); + } + let mut words = route.split_whitespace(); + if let Some("default") = words.next() { + if let Some("via") = words.next() { + if let Some(ip) = words.next() { + return Ipv4Address::from_str(ip) + .map_err(|_| SyscallError::new(syscall::EINVAL)); + } + } + } + } + Err(SyscallError::new(syscall::EINVAL)) } -impl RootNode { - pub fn new(iface: Interface) -> RootNode { - let route_list_node = RONode::new(move || { - let default_route = if let Some(ip) = iface.borrow().ipv4_gateway() { - format!("default via {}\n", ip) - } else { - String::new() - }; - Vec::from_iter(default_route.bytes()) - }); - let mut route_child_nodes = BTreeMap::new(); - route_child_nodes.insert("list".to_owned(), route_list_node); - let route_node = StaticDirNode::new(route_child_nodes); - let iface_nodes = BTreeMap::new(); - // let eth0_node: CfgNodeRef = Rc::new(RefCell::new(IfaceNode::new(iface))); - // iface_nodes.insert("eth0".to_owned(), eth0_node); - RootNode { - route_node, - iface_nodes, +fn mk_route_node(iface: &Interface) -> CfgNodeRef { + let iface_ = Rc::clone(iface); + let route_list_node = RONode::new(move || { + let default_route = if let Some(ip) = iface_.borrow().ipv4_gateway() { + format!("default via {}\n", ip) + } else { + String::new() + }; + Vec::from_iter(default_route.bytes()) + }); + let iface_ = Rc::clone(iface); + let route_add_node = WONode::new(move |buf: &[u8]| -> SyscallResult { + let default_gw = parse_default_gw(buf)?; + iface_.borrow_mut().set_ipv4_gateway(Some(default_gw)); + Ok(0) + }); + let iface_ = Rc::clone(iface); + let route_rm_node = WONode::new(move |buf: &[u8]| -> SyscallResult { + let default_gw = parse_default_gw(buf)?; + let mut iface = iface_.borrow_mut(); + if iface.ipv4_gateway() != Some(default_gw) { + return Err(SyscallError::new(syscall::EINVAL)); } - } + iface.set_ipv4_gateway(None); + Ok(0) + }); + let mut route_child_nodes = BTreeMap::new(); + route_child_nodes.insert("list".to_owned(), route_list_node); + route_child_nodes.insert("add".to_owned(), route_add_node); + route_child_nodes.insert("rm".to_owned(), route_rm_node); + StaticDirNode::new(route_child_nodes) } -impl CfgNode for RootNode { - fn is_dir(&self) -> bool { - true - } +fn mk_iface_node(iface: &Interface) -> CfgNodeRef { + let iface_ = Rc::clone(iface); + let iface__ = Rc::clone(iface); + let iface_mac_node = RWNode::new( + move || Vec::from_iter(format!("{}\n", iface_.borrow().ethernet_addr()).bytes()), + move |buf: &[u8]| -> SyscallResult { + let value = str::from_utf8(buf).or_else(|_| Err(SyscallError::new(syscall::EINVAL)))?; + let mac = + EthernetAddress::from_str(value).map_err(|_| SyscallError::new(syscall::EINVAL))?; + if !mac.is_unicast() { + return Err(SyscallError::new(syscall::EINVAL)); + } + iface__.borrow_mut().set_ethernet_addr(mac); + Ok(0) + }, + ); + let mut iface_child_nodes = BTreeMap::new(); + iface_child_nodes.insert("mac".to_owned(), iface_mac_node); + StaticDirNode::new(iface_child_nodes) +} - fn open(&self, file: &str) -> Option { - match file { - "route" => Some(Rc::clone(&self.route_node)), - _ => self.iface_nodes.get(file).map(|node| Rc::clone(node)), - } - } +fn mk_root_node(iface: Interface) -> CfgNodeRef { + let route_node = mk_route_node(&iface); + let mut ifaces_nodes = BTreeMap::new(); - fn read(&self) -> Vec { - let mut files = vec![]; - files.extend_from_slice(b"route"); - for iface in self.iface_nodes.keys() { - files.push(b'\n'); - files.extend(iface.bytes()); - } - files - } + ifaces_nodes.insert("eth0".to_owned(), mk_iface_node(&iface)); + let ifaces_node = StaticDirNode::new(ifaces_nodes); + + let mut root_child_nodes = BTreeMap::new(); + root_child_nodes.insert("route".to_owned(), route_node); + root_child_nodes.insert("ifaces".to_owned(), ifaces_node); + StaticDirNode::new(root_child_nodes) } struct NetCfgFile { cfg_node: CfgNodeRef, - data: Option>, + read_buf: Vec, + write_buf: Vec, pos: usize, uid: u32, } @@ -170,7 +278,7 @@ impl NetCfgScheme { scheme_file, next_fd: 1, files: BTreeMap::new(), - root_node: Rc::new(RefCell::new(RootNode::new(iface))), + root_node: mk_root_node(iface), } } @@ -201,6 +309,7 @@ impl SchemeMut for NetCfgScheme { .ok_or_else(|| SyscallError::new(syscall::EINVAL))?; current_node = next_node; } + let read_buf = current_node.borrow().read(); let fd = self.next_fd; self.next_fd += 1; self.files.insert( @@ -209,53 +318,48 @@ impl SchemeMut for NetCfgScheme { cfg_node: current_node, uid, pos: 0, - data: None, + read_buf, + write_buf: vec![], }, ); Ok(fd) } fn close(&mut self, fd: usize) -> SyscallResult { - self.files - .get(&fd) - .ok_or_else(|| SyscallError::new(syscall::EBADF))? - .cfg_node - .borrow_mut() - .close(); - self.files.remove(&fd); - Ok(0) + let file = self.files + .get_mut(&fd) + .ok_or_else(|| SyscallError::new(syscall::EBADF))?; + file.cfg_node.borrow().write(&file.write_buf) } fn write(&mut self, fd: usize, buf: &[u8]) -> SyscallResult { let file = self.files - .get(&fd) + .get_mut(&fd) .ok_or_else(|| SyscallError::new(syscall::EBADF))?; + if file.uid != 0 { return Err(SyscallError::new(syscall::EACCES)); } - file.cfg_node - .borrow_mut() - .write(buf) - .ok_or_else(|| SyscallError::new(syscall::EINVAL)) + + if (WRITE_BUFFER_MAX_SIZE - file.write_buf.len()) < buf.len() { + return Err(SyscallError::new(syscall::EMSGSIZE)); + } + file.write_buf.extend_from_slice(buf); + Ok(buf.len()) } fn read(&mut self, fd: usize, buf: &mut [u8]) -> SyscallResult { let file = self.files .get_mut(&fd) .ok_or_else(|| SyscallError::new(syscall::EBADF))?; - if file.data.is_none() { - file.data = Some(file.cfg_node.borrow().read()) + + let mut i = 0; + while i < buf.len() && file.pos < file.read_buf.len() { + buf[i] = file.read_buf[file.pos]; + i += 1; + file.pos += 1; } - if let Some(ref data) = file.data { - let mut i = 0; - while i < buf.len() && file.pos < data.len() { - buf[i] = data[file.pos]; - i += 1; - file.pos += 1; - } - return Ok(i); - } - Err(SyscallError::new(syscall::EINVAL)) + Ok(i) } fn fstat(&mut self, fd: usize, stat: &mut Stat) -> SyscallResult { @@ -277,15 +381,7 @@ impl SchemeMut for NetCfgScheme { } stat.st_uid = 0; stat.st_gid = 0; - - if file.data.is_none() { - file.data = Some(file.cfg_node.borrow().read()) - } - if let Some(ref data) = file.data { - stat.st_size = data.len() as u64; - } else { - stat.st_size = 0; - } + stat.st_size = file.read_buf.len() as u64; Ok(0) } diff --git a/src/smolnetd/scheme/socket.rs b/src/smolnetd/scheme/socket.rs index a94f16ac24..d6723964ab 100644 --- a/src/smolnetd/scheme/socket.rs +++ b/src/smolnetd/scheme/socket.rs @@ -84,8 +84,8 @@ where { pub fn socket_handle(&self) -> SocketHandle { match *self { - SchemeFile::Socket(SocketFile { socket_handle, .. }) | - SchemeFile::Setting(SettingFile { socket_handle, .. }) => socket_handle, + SchemeFile::Socket(SocketFile { socket_handle, .. }) + | SchemeFile::Setting(SettingFile { socket_handle, .. }) => socket_handle, } } } @@ -580,9 +580,10 @@ where } fn dup(&mut self, fd: usize, buf: &[u8]) -> SyscallResult { - if let Some((flags, uid, gid)) = self.nulls.get(&fd).map(|null| { - (null.flags, null.uid, null.gid) - }) { + if let Some((flags, uid, gid)) = self.nulls + .get(&fd) + .map(|null| (null.flags, null.uid, null.gid)) + { return self.open(buf, flags, uid, gid); } From ae7d9b40f8e3de3e8889c8a16d5fee4206b03697 Mon Sep 17 00:00:00 2001 From: Egor Karavaev Date: Fri, 12 Jan 2018 01:22:53 +0300 Subject: [PATCH 067/155] netcfg: interface addr node. --- src/smolnetd/scheme/mod.rs | 2 +- src/smolnetd/scheme/netcfg.rs | 264 ++++++++++++++++++++++------------ 2 files changed, 172 insertions(+), 94 deletions(-) diff --git a/src/smolnetd/scheme/mod.rs b/src/smolnetd/scheme/mod.rs index 9a0d4742ab..e03eed4b7b 100644 --- a/src/smolnetd/scheme/mod.rs +++ b/src/smolnetd/scheme/mod.rs @@ -71,7 +71,7 @@ impl Smolnetd { .expect("Can't parse the 'mac' cfg"); let local_ip = IpAddress::from_str(getcfg("ip").unwrap().trim()).expect("Can't parse the 'ip' cfg."); - let protocol_addrs = [ + let protocol_addrs = vec![ IpCidr::new(local_ip, 24), IpCidr::new(IpAddress::v4(127, 0, 0, 1), 8), ]; diff --git a/src/smolnetd/scheme/netcfg.rs b/src/smolnetd/scheme/netcfg.rs index 7bf9049657..d629431fac 100644 --- a/src/smolnetd/scheme/netcfg.rs +++ b/src/smolnetd/scheme/netcfg.rs @@ -1,3 +1,4 @@ +// use managed::ManagedSlice; use std::cell::RefCell; use std::collections::BTreeMap; use std::fs::File; @@ -5,8 +6,7 @@ use std::io::{Read, Write}; use std::str; use std::str::FromStr; use std::rc::Rc; -use std::iter::FromIterator; -use smoltcp::wire::{EthernetAddress, Ipv4Address}; +use smoltcp::wire::{EthernetAddress, IpCidr, Ipv4Address}; use syscall::data::Stat; use syscall::flag::{MODE_DIR, MODE_FILE}; use syscall::{Error as SyscallError, Packet as SyscallPacket, Result as SyscallResult, SchemeMut}; @@ -32,11 +32,11 @@ trait CfgNode { true } - fn read(&self) -> Vec { - vec![] + fn read(&self) -> String { + String::new() } - fn write(&self, _buf: &[u8]) -> SyscallResult { + fn write(&self, _buf: &str) -> SyscallResult { Ok(0) } @@ -47,23 +47,23 @@ trait CfgNode { struct RONode where - F: Fn() -> Vec, + F: Fn() -> String, { read_fun: F, } impl CfgNode for RONode where - F: Fn() -> Vec, + F: Fn() -> String, { - fn read(&self) -> Vec { + fn read(&self) -> String { (self.read_fun)() } } impl RONode where - F: 'static + Fn() -> Vec, + F: 'static + Fn() -> String, { fn new(read_fun: F) -> CfgNodeRef { Rc::new(RefCell::new(RONode { read_fun })) @@ -72,16 +72,16 @@ where struct WONode where - F: Fn(&[u8]) -> SyscallResult, + F: Fn(&str) -> SyscallResult, { write_fun: F, } impl CfgNode for WONode where - F: Fn(&[u8]) -> SyscallResult, + F: Fn(&str) -> SyscallResult, { - fn write(&self, buf: &[u8]) -> SyscallResult { + fn write(&self, buf: &str) -> SyscallResult { (self.write_fun)(buf) } @@ -92,7 +92,7 @@ where impl WONode where - F: 'static + Fn(&[u8]) -> SyscallResult, + F: 'static + Fn(&str) -> SyscallResult, { fn new(write_fun: F) -> CfgNodeRef { Rc::new(RefCell::new(WONode { write_fun })) @@ -101,8 +101,8 @@ where struct RWNode where - F: Fn() -> Vec, - G: Fn(&[u8]) -> SyscallResult, + F: Fn() -> String, + G: Fn(&str) -> SyscallResult, { read_fun: F, write_fun: G, @@ -110,14 +110,14 @@ where impl CfgNode for RWNode where - F: Fn() -> Vec, - G: Fn(&[u8]) -> SyscallResult, + F: Fn() -> String, + G: Fn(&str) -> SyscallResult, { - fn read(&self) -> Vec { + fn read(&self) -> String { (self.read_fun)() } - fn write(&self, buf: &[u8]) -> SyscallResult { + fn write(&self, buf: &str) -> SyscallResult { (self.write_fun)(buf) } @@ -128,8 +128,8 @@ where impl RWNode where - F: 'static + Fn() -> Vec, - G: 'static + Fn(&[u8]) -> SyscallResult, + F: 'static + Fn() -> String, + G: 'static + Fn(&str) -> SyscallResult, { fn new(read_fun: F, write_fun: G) -> CfgNodeRef { Rc::new(RefCell::new(RWNode { @@ -148,13 +148,13 @@ impl CfgNode for StaticDirNode { true } - fn read(&self) -> Vec { - let mut files = vec![]; + fn read(&self) -> String { + let mut files = String::new(); for child in self.child_nodes.keys() { if !files.is_empty() { - files.push(b'\n'); + files.push('\n'); } - files.extend(child.bytes()); + files += child; } files } @@ -170,8 +170,45 @@ impl StaticDirNode { } } -fn parse_default_gw(buf: &[u8]) -> SyscallResult { - let value = str::from_utf8(buf).or_else(|_| Err(SyscallError::new(syscall::EINVAL)))?; +macro_rules! cfg_node { + (val $e:expr) => { + $e + }; + (ro [ $($c:ident)* ] || $b:block ) => { + { + $(let $c = $c.clone();)* + RONode::new(move|| $b) + } + }; + (wo [ $($c:ident)* ] |$i:ident| $b:block ) => { + { + $(let $c = $c.clone();)* + WONode::new(move |$i: &str| $b) + } + }; + (rw [ $($c:ident)* ] || $rb:block |$i:ident| $wb:block ) => { + { + let read_fun = { + $(let $c = $c.clone();)* + move || $rb + }; + let write_fun = { + $(let $c = $c.clone();)* + move |$i: &str| $wb + }; + RWNode::new(read_fun, write_fun) + } + }; + ($($e:expr => { $($t:tt)* }),* $(,)*) => { + { + let mut children = BTreeMap::new(); + $(children.insert($e.into(), cfg_node!($($t)*));)* + StaticDirNode::new(children) + } + }; +} + +fn parse_default_gw(value: &str) -> SyscallResult { let mut routes = value.lines(); if let Some(route) = routes.next() { if !routes.next().is_none() { @@ -190,71 +227,110 @@ fn parse_default_gw(buf: &[u8]) -> SyscallResult { Err(SyscallError::new(syscall::EINVAL)) } -fn mk_route_node(iface: &Interface) -> CfgNodeRef { - let iface_ = Rc::clone(iface); - let route_list_node = RONode::new(move || { - let default_route = if let Some(ip) = iface_.borrow().ipv4_gateway() { - format!("default via {}\n", ip) - } else { - String::new() - }; - Vec::from_iter(default_route.bytes()) - }); - let iface_ = Rc::clone(iface); - let route_add_node = WONode::new(move |buf: &[u8]| -> SyscallResult { - let default_gw = parse_default_gw(buf)?; - iface_.borrow_mut().set_ipv4_gateway(Some(default_gw)); - Ok(0) - }); - let iface_ = Rc::clone(iface); - let route_rm_node = WONode::new(move |buf: &[u8]| -> SyscallResult { - let default_gw = parse_default_gw(buf)?; - let mut iface = iface_.borrow_mut(); - if iface.ipv4_gateway() != Some(default_gw) { - return Err(SyscallError::new(syscall::EINVAL)); - } - iface.set_ipv4_gateway(None); - Ok(0) - }); - let mut route_child_nodes = BTreeMap::new(); - route_child_nodes.insert("list".to_owned(), route_list_node); - route_child_nodes.insert("add".to_owned(), route_add_node); - route_child_nodes.insert("rm".to_owned(), route_rm_node); - StaticDirNode::new(route_child_nodes) -} - -fn mk_iface_node(iface: &Interface) -> CfgNodeRef { - let iface_ = Rc::clone(iface); - let iface__ = Rc::clone(iface); - let iface_mac_node = RWNode::new( - move || Vec::from_iter(format!("{}\n", iface_.borrow().ethernet_addr()).bytes()), - move |buf: &[u8]| -> SyscallResult { - let value = str::from_utf8(buf).or_else(|_| Err(SyscallError::new(syscall::EINVAL)))?; - let mac = - EthernetAddress::from_str(value).map_err(|_| SyscallError::new(syscall::EINVAL))?; - if !mac.is_unicast() { - return Err(SyscallError::new(syscall::EINVAL)); - } - iface__.borrow_mut().set_ethernet_addr(mac); - Ok(0) - }, - ); - let mut iface_child_nodes = BTreeMap::new(); - iface_child_nodes.insert("mac".to_owned(), iface_mac_node); - StaticDirNode::new(iface_child_nodes) -} - fn mk_root_node(iface: Interface) -> CfgNodeRef { - let route_node = mk_route_node(&iface); - let mut ifaces_nodes = BTreeMap::new(); - - ifaces_nodes.insert("eth0".to_owned(), mk_iface_node(&iface)); - let ifaces_node = StaticDirNode::new(ifaces_nodes); - - let mut root_child_nodes = BTreeMap::new(); - root_child_nodes.insert("route".to_owned(), route_node); - root_child_nodes.insert("ifaces".to_owned(), ifaces_node); - StaticDirNode::new(root_child_nodes) + cfg_node!{ + "route" => { + "list" => { + ro [iface] || { + if let Some(ip) = iface.borrow().ipv4_gateway() { + format!("default via {}\n", ip) + } else { + String::new() + } + } + }, + "add" => { + wo [iface] |routes| { + let default_gw = parse_default_gw(routes)?; + iface.borrow_mut().set_ipv4_gateway(Some(default_gw)); + Ok(0) + } + }, + "rm" => { + wo [iface] |routes| { + let default_gw = parse_default_gw(routes)?; + let mut iface = iface.borrow_mut(); + if iface.ipv4_gateway() != Some(default_gw) { + return Err(SyscallError::new(syscall::EINVAL)); + } + iface.set_ipv4_gateway(None); + Ok(0) + } + } + }, + "ifaces" => { + "eth0" => { + "mac" => { + rw [iface] + || { + format!("{}\n", iface.borrow().ethernet_addr()) + } + |mac| { + let mac = mac.lines().next() + .ok_or_else(|| SyscallError::new(syscall::EINVAL))?; + let mac = EthernetAddress::from_str(mac). + map_err(|_| SyscallError::new(syscall::EINVAL))?; + if !mac.is_unicast() { + return Err(SyscallError::new(syscall::EINVAL)); + } + iface.borrow_mut().set_ethernet_addr(mac); + Ok(0) + } + }, + "addr" => { + "list" => { + ro [iface] || { + let mut ips = String::new(); + for cidr in iface.borrow().ip_addrs() { + ips += &format!("{}\n", cidr); + } + ips + } + }, + "add" => { + wo [iface] |input| { + let mut iface = iface.borrow_mut(); + let mut cidrs = iface.ip_addrs().iter().cloned().collect::>(); + for cidr in input.lines() { + let cidr = IpCidr::from_str(cidr) + .map_err(|_| SyscallError::new(syscall::EINVAL))?; + if !cidr.address().is_unicast() { + return Err(SyscallError::new(syscall::EINVAL)); + } + cidrs.insert(0, cidr); + } + iface.update_ip_addrs(|s| { + *s = From::from(cidrs); + }); + Ok(0) + } + }, + "rm" => { + wo [iface] |input| { + let mut iface = iface.borrow_mut(); + let mut cidrs = iface.ip_addrs().iter().cloned().collect::>(); + for cidr in input.lines() { + let cidr = IpCidr::from_str(cidr) + .map_err(|_| SyscallError::new(syscall::EINVAL))?; + if !cidr.address().is_unicast() { + return Err(SyscallError::new(syscall::EINVAL)); + } + let pre_retain_len = cidrs.len(); + cidrs.retain(|&c| c != cidr); + if pre_retain_len == cidrs.len() { + return Err(SyscallError::new(syscall::EINVAL)); + } + } + iface.update_ip_addrs(|s| { + *s = From::from(cidrs); + }); + Ok(0) + } + }, + } + } + } + } } struct NetCfgFile { @@ -309,7 +385,7 @@ impl SchemeMut for NetCfgScheme { .ok_or_else(|| SyscallError::new(syscall::EINVAL))?; current_node = next_node; } - let read_buf = current_node.borrow().read(); + let read_buf = Vec::from(current_node.borrow().read()); let fd = self.next_fd; self.next_fd += 1; self.files.insert( @@ -329,7 +405,9 @@ impl SchemeMut for NetCfgScheme { let file = self.files .get_mut(&fd) .ok_or_else(|| SyscallError::new(syscall::EBADF))?; - file.cfg_node.borrow().write(&file.write_buf) + let value = + str::from_utf8(&file.write_buf).or_else(|_| Err(SyscallError::new(syscall::EINVAL)))?; + file.cfg_node.borrow().write(&value) } fn write(&mut self, fd: usize, buf: &[u8]) -> SyscallResult { From eea72fcef3b616e9c1b3bd1cd18bc1ca0a991945 Mon Sep 17 00:00:00 2001 From: Egor Karavaev Date: Fri, 12 Jan 2018 22:10:46 +0300 Subject: [PATCH 068/155] Remove closed fd. --- src/smolnetd/scheme/netcfg.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/smolnetd/scheme/netcfg.rs b/src/smolnetd/scheme/netcfg.rs index d629431fac..22a7479a88 100644 --- a/src/smolnetd/scheme/netcfg.rs +++ b/src/smolnetd/scheme/netcfg.rs @@ -402,12 +402,13 @@ impl SchemeMut for NetCfgScheme { } fn close(&mut self, fd: usize) -> SyscallResult { - let file = self.files - .get_mut(&fd) - .ok_or_else(|| SyscallError::new(syscall::EBADF))?; - let value = - str::from_utf8(&file.write_buf).or_else(|_| Err(SyscallError::new(syscall::EINVAL)))?; - file.cfg_node.borrow().write(&value) + if let Some(file) = self.files.remove(&fd) { + let value = str::from_utf8(&file.write_buf) + .or_else(|_| Err(SyscallError::new(syscall::EINVAL)))?; + file.cfg_node.borrow().write(&value) + } else { + Err(SyscallError::new(syscall::EBADF)) + } } fn write(&mut self, fd: usize, buf: &[u8]) -> SyscallResult { From 1eeec8eae0e66400d92dd28f0a6101c77f025043 Mon Sep 17 00:00:00 2001 From: Egor Karavaev Date: Tue, 30 Jan 2018 00:47:49 +0300 Subject: [PATCH 069/155] Netcfg notifications. --- src/dnsd/main.rs | 19 +- src/dnsd/scheme.rs | 52 ++- src/lib/logger.rs | 2 +- src/smolnetd/scheme/mod.rs | 3 +- .../scheme/{netcfg.rs => netcfg/mod.rs} | 297 ++++++------------ src/smolnetd/scheme/netcfg/nodes.rs | 199 ++++++++++++ src/smolnetd/scheme/netcfg/notifier.rs | 62 ++++ src/smolnetd/scheme/tcp.rs | 8 +- 8 files changed, 412 insertions(+), 230 deletions(-) rename src/smolnetd/scheme/{netcfg.rs => netcfg/mod.rs} (66%) create mode 100644 src/smolnetd/scheme/netcfg/nodes.rs create mode 100644 src/smolnetd/scheme/netcfg/notifier.rs diff --git a/src/dnsd/main.rs b/src/dnsd/main.rs index 73babd05fd..6a1b67c9ef 100644 --- a/src/dnsd/main.rs +++ b/src/dnsd/main.rs @@ -31,7 +31,18 @@ fn run() -> Result<()> { .map_err(|e| Error::from_syscall_error(e, "failed to open time:"))? as RawFd; - let (dns_file, time_file) = unsafe { (File::from_raw_fd(dns_fd), File::from_raw_fd(time_fd)) }; + let nameserver_fd = syscall::open( + "netcfg:resolv/nameserver", + syscall::O_RDWR | syscall::O_CREAT | syscall::O_NONBLOCK, + ).map_err(|e| Error::from_syscall_error(e, "failed to open nameserver:"))? + as RawFd; + + let (dns_file, time_file) = unsafe { + ( + File::from_raw_fd(dns_fd), + File::from_raw_fd(time_fd), + ) + }; let dnsd = Rc::new(RefCell::new(Dnsd::new(dns_file, time_file))); @@ -46,6 +57,12 @@ fn run() -> Result<()> { let dnsd_ = Rc::clone(&dnsd); + event_queue + .add(nameserver_fd, move |_| dnsd_.borrow_mut().on_nameserver_event()) + .map_err(|e| Error::from_io_error(e, "failed to listen to nameserver"))?; + + let dnsd_ = Rc::clone(&dnsd); + event_queue.set_default_callback(move |fd, _| dnsd_.borrow_mut().on_unknown_fd_event(fd)); event_queue diff --git a/src/dnsd/scheme.rs b/src/dnsd/scheme.rs index 3be32c1d8d..d32e562736 100644 --- a/src/dnsd/scheme.rs +++ b/src/dnsd/scheme.rs @@ -9,7 +9,9 @@ use std::io::{Read, Write}; use std::mem; use std::os::unix::io::RawFd; use std::str; +use std::str::FromStr; use std::rc::Rc; +use std::net::Ipv4Addr; use syscall::data::TimeSpec; use syscall::{Error as SyscallError, Packet as SyscallPacket, Result as SyscallResult, SchemeMut}; use syscall; @@ -40,6 +42,7 @@ enum DnsParsingResult { } struct Domains { + nameserver: Ipv4Addr, domains: BTreeMap, Domain>, requests: BTreeMap>, resolved_timeouts: VecDeque<(TimeSpec, Rc)>, @@ -48,11 +51,28 @@ struct Domains { impl Domains { fn new() -> Domains { - Domains { + let mut domains = Domains { + nameserver: Ipv4Addr::new(8, 8, 8, 8), domains: BTreeMap::new(), requests: BTreeMap::new(), resolved_timeouts: VecDeque::new(), requested_timeouts: VecDeque::new(), + }; + domains.update_nameserver(); + domains + } + + pub fn update_nameserver(&mut self) { + if let Ok(mut file) = File::open("netcfg:resolv/nameserver") { + let mut nameserver = String::new(); + if let Ok(_) = file.read_to_string(&mut nameserver) { + if let Some(line) = nameserver.lines().next() { + if let Ok(ip) = Ipv4Addr::from_str(&line) { + trace!("Changing nameserver to {}", ip); + self.nameserver = ip; + } + } + } } } @@ -62,7 +82,7 @@ impl Domains { builder.add_question(domain, QueryType::A, QueryClass::IN); let packet = builder.build().ok()?; let udp_fd = syscall::open( - "udp:8.8.8.8:53", + &format!("udp:{}:53", self.nameserver), syscall::O_RDWR | syscall::O_CREAT | syscall::O_NONBLOCK, ).ok()? as RawFd; if syscall::write(udp_fd as usize, &packet) != Ok(packet.len()) { @@ -131,13 +151,13 @@ impl Domains { } Entry::Occupied(e) => e, }; - let mut buf = [0u8; 4096]; + let mut buf = [0u8; 0x1000]; let readed = syscall::read(fd as usize, &mut buf).ok()?; if readed == 0 { return None; } let pkt = DNSPacket::parse(&buf).ok()?; - if pkt.header.response_code != ResponseCode::NoError || pkt.answers.len() == 0 { + if pkt.header.response_code != ResponseCode::NoError || pkt.answers.is_empty() { if let Some(query) = pkt.questions.iter().next() { if query.qname.to_string().to_lowercase() == e.get().as_ref() { unsubscribe_from_fd(fd).ok()?; @@ -290,11 +310,11 @@ impl Dnsd { let fds_to_wakeup = self.domains.on_time_event(&time); if !fds_to_wakeup.is_empty() { for fd in &fds_to_wakeup { - if let Some(file) = self.files.get_mut(&fd) { + if let Some(file) = self.files.get_mut(fd) { *file = DnsFile::Timeout; } } - self.wakeup_fds(fds_to_wakeup); + self.wakeup_fds(&fds_to_wakeup); } time.tv_sec += Dnsd::TIME_EVENT_TIMEOUT_S; @@ -323,6 +343,7 @@ impl Dnsd { } pub fn on_unknown_fd_event(&mut self, fd: RawFd) -> Result> { + trace!("Unknown fd event {}", fd); let mut cur_time = TimeSpec::default(); syscall::clock_gettime(syscall::CLOCK_MONOTONIC, &mut cur_time) .map_err(|e| Error::from_syscall_error(e, "Can't get time"))?; @@ -330,24 +351,29 @@ impl Dnsd { match self.domains.on_fd_event(fd, &cur_time) { Some(DnsParsingResult::FailFiles(fds_to_fail)) => { for fd in &fds_to_fail { - if let Some(file) = self.files.get_mut(&fd) { + if let Some(file) = self.files.get_mut(fd) { *file = DnsFile::Failed; } } - self.wakeup_fds(fds_to_fail); + self.wakeup_fds(&fds_to_fail); } Some(DnsParsingResult::WakeUpFiles(fds_to_wakeup)) => { - self.wakeup_fds(fds_to_wakeup); + self.wakeup_fds(&fds_to_wakeup); } None => {} } Ok(None) } - fn wakeup_fds(&mut self, fds_to_wakeup: BTreeSet) { + pub fn on_nameserver_event(&mut self) -> Result> { + self.domains.update_nameserver(); + Ok(None) + } + + fn wakeup_fds(&mut self, fds_to_wakeup: &BTreeSet) { let mut syscall_packets = vec![]; - for fd in &fds_to_wakeup { - if let Some(packet) = self.wait_map.remove(&fd) { + for fd in fds_to_wakeup { + if let Some(packet) = self.wait_map.remove(fd) { syscall_packets.push(packet); } } @@ -375,7 +401,7 @@ impl Dnsd { } } - return true; + true } } diff --git a/src/lib/logger.rs b/src/lib/logger.rs index 0fd36d9b1b..90ed1f8306 100644 --- a/src/lib/logger.rs +++ b/src/lib/logger.rs @@ -8,7 +8,7 @@ impl Log for Logger { } fn log(&self, record: &LogRecord) { - println!("{}: {}", record.level(), record.args()); + println!("{}: {}", record.target(), record.args()); } } diff --git a/src/smolnetd/scheme/mod.rs b/src/smolnetd/scheme/mod.rs index e03eed4b7b..22ad873c48 100644 --- a/src/smolnetd/scheme/mod.rs +++ b/src/smolnetd/scheme/mod.rs @@ -183,8 +183,7 @@ impl Smolnetd { } iter_limit -= 1; match iface.poll(&mut socket_set, timestamp) { - Ok(_) => (), - Err(smoltcp::Error::Unrecognized) => (), + Ok(_) | Err(smoltcp::Error::Unrecognized) => (), Err(e) => { error!("poll error: {}", e); break 0; diff --git a/src/smolnetd/scheme/netcfg.rs b/src/smolnetd/scheme/netcfg/mod.rs similarity index 66% rename from src/smolnetd/scheme/netcfg.rs rename to src/smolnetd/scheme/netcfg/mod.rs index 22a7479a88..a77a1a5d20 100644 --- a/src/smolnetd/scheme/netcfg.rs +++ b/src/smolnetd/scheme/netcfg/mod.rs @@ -1,213 +1,27 @@ -// use managed::ManagedSlice; +#[macro_use] +mod nodes; +mod notifier; + +use smoltcp::wire::{EthernetAddress, IpCidr, Ipv4Address}; use std::cell::RefCell; use std::collections::BTreeMap; use std::fs::File; use std::io::{Read, Write}; -use std::str; -use std::str::FromStr; use std::rc::Rc; -use smoltcp::wire::{EthernetAddress, IpCidr, Ipv4Address}; +use std::str::FromStr; +use std::str; use syscall::data::Stat; use syscall::flag::{MODE_DIR, MODE_FILE}; use syscall::{Error as SyscallError, Packet as SyscallPacket, Result as SyscallResult, SchemeMut}; use syscall; -use error::Result; -use super::Interface; +use self::nodes::*; +use self::notifier::*; +use redox_netstack::error::Result; +use super::{post_fevent, Interface}; const WRITE_BUFFER_MAX_SIZE: usize = 0xffff; -type CfgNodeRef = Rc>; - -trait CfgNode { - fn is_dir(&self) -> bool { - false - } - - fn is_writable(&self) -> bool { - false - } - - fn is_readable(&self) -> bool { - true - } - - fn read(&self) -> String { - String::new() - } - - fn write(&self, _buf: &str) -> SyscallResult { - Ok(0) - } - - fn open(&self, _file: &str) -> Option { - None - } -} - -struct RONode -where - F: Fn() -> String, -{ - read_fun: F, -} - -impl CfgNode for RONode -where - F: Fn() -> String, -{ - fn read(&self) -> String { - (self.read_fun)() - } -} - -impl RONode -where - F: 'static + Fn() -> String, -{ - fn new(read_fun: F) -> CfgNodeRef { - Rc::new(RefCell::new(RONode { read_fun })) - } -} - -struct WONode -where - F: Fn(&str) -> SyscallResult, -{ - write_fun: F, -} - -impl CfgNode for WONode -where - F: Fn(&str) -> SyscallResult, -{ - fn write(&self, buf: &str) -> SyscallResult { - (self.write_fun)(buf) - } - - fn is_writable(&self) -> bool { - true - } -} - -impl WONode -where - F: 'static + Fn(&str) -> SyscallResult, -{ - fn new(write_fun: F) -> CfgNodeRef { - Rc::new(RefCell::new(WONode { write_fun })) - } -} - -struct RWNode -where - F: Fn() -> String, - G: Fn(&str) -> SyscallResult, -{ - read_fun: F, - write_fun: G, -} - -impl CfgNode for RWNode -where - F: Fn() -> String, - G: Fn(&str) -> SyscallResult, -{ - fn read(&self) -> String { - (self.read_fun)() - } - - fn write(&self, buf: &str) -> SyscallResult { - (self.write_fun)(buf) - } - - fn is_writable(&self) -> bool { - true - } -} - -impl RWNode -where - F: 'static + Fn() -> String, - G: 'static + Fn(&str) -> SyscallResult, -{ - fn new(read_fun: F, write_fun: G) -> CfgNodeRef { - Rc::new(RefCell::new(RWNode { - read_fun, - write_fun, - })) - } -} - -struct StaticDirNode { - child_nodes: BTreeMap, -} - -impl CfgNode for StaticDirNode { - fn is_dir(&self) -> bool { - true - } - - fn read(&self) -> String { - let mut files = String::new(); - for child in self.child_nodes.keys() { - if !files.is_empty() { - files.push('\n'); - } - files += child; - } - files - } - - fn open(&self, file: &str) -> Option { - self.child_nodes.get(file).map(|node| Rc::clone(node)) - } -} - -impl StaticDirNode { - pub fn new(child_nodes: BTreeMap) -> CfgNodeRef { - Rc::new(RefCell::new(StaticDirNode { child_nodes })) - } -} - -macro_rules! cfg_node { - (val $e:expr) => { - $e - }; - (ro [ $($c:ident)* ] || $b:block ) => { - { - $(let $c = $c.clone();)* - RONode::new(move|| $b) - } - }; - (wo [ $($c:ident)* ] |$i:ident| $b:block ) => { - { - $(let $c = $c.clone();)* - WONode::new(move |$i: &str| $b) - } - }; - (rw [ $($c:ident)* ] || $rb:block |$i:ident| $wb:block ) => { - { - let read_fun = { - $(let $c = $c.clone();)* - move || $rb - }; - let write_fun = { - $(let $c = $c.clone();)* - move |$i: &str| $wb - }; - RWNode::new(read_fun, write_fun) - } - }; - ($($e:expr => { $($t:tt)* }),* $(,)*) => { - { - let mut children = BTreeMap::new(); - $(children.insert($e.into(), cfg_node!($($t)*));)* - StaticDirNode::new(children) - } - }; -} - fn parse_default_gw(value: &str) -> SyscallResult { let mut routes = value.lines(); if let Some(route) = routes.next() { @@ -227,8 +41,26 @@ fn parse_default_gw(value: &str) -> SyscallResult { Err(SyscallError::new(syscall::EINVAL)) } -fn mk_root_node(iface: Interface) -> CfgNodeRef { +fn mk_root_node(iface: Interface, notifier: NotifierRef, dns_config: DNSConfigRef) -> CfgNodeRef { cfg_node!{ + "resolv" => { + "nameserver" => { + rw [dns_config, notifier] + || { + format!("{}\n", dns_config.borrow().name_server) + } + |name_server| { + let ip = Ipv4Address::from_str(name_server.trim()) + .map_err(|_| SyscallError::new(syscall::EINVAL))?; + if !ip.is_unicast() { + return Err(SyscallError::new(syscall::EINVAL)); + } + dns_config.borrow_mut().name_server = ip; + notifier.borrow_mut().schedule_notify("resolv/nameserver"); + Ok(0) + } + } + }, "route" => { "list" => { ro [iface] || { @@ -240,20 +72,22 @@ fn mk_root_node(iface: Interface) -> CfgNodeRef { } }, "add" => { - wo [iface] |routes| { + wo [iface, notifier] |routes| { let default_gw = parse_default_gw(routes)?; iface.borrow_mut().set_ipv4_gateway(Some(default_gw)); + notifier.borrow_mut().schedule_notify("route/list"); Ok(0) } }, "rm" => { - wo [iface] |routes| { + wo [iface, notifier] |routes| { let default_gw = parse_default_gw(routes)?; let mut iface = iface.borrow_mut(); if iface.ipv4_gateway() != Some(default_gw) { return Err(SyscallError::new(syscall::EINVAL)); } iface.set_ipv4_gateway(None); + notifier.borrow_mut().schedule_notify("route/list"); Ok(0) } } @@ -261,7 +95,7 @@ fn mk_root_node(iface: Interface) -> CfgNodeRef { "ifaces" => { "eth0" => { "mac" => { - rw [iface] + rw [iface, notifier] || { format!("{}\n", iface.borrow().ethernet_addr()) } @@ -274,6 +108,7 @@ fn mk_root_node(iface: Interface) -> CfgNodeRef { return Err(SyscallError::new(syscall::EINVAL)); } iface.borrow_mut().set_ethernet_addr(mac); + notifier.borrow_mut().schedule_notify("ifaces/eth0/mac"); Ok(0) } }, @@ -288,9 +123,9 @@ fn mk_root_node(iface: Interface) -> CfgNodeRef { } }, "add" => { - wo [iface] |input| { + wo [iface, notifier] |input| { let mut iface = iface.borrow_mut(); - let mut cidrs = iface.ip_addrs().iter().cloned().collect::>(); + let mut cidrs = iface.ip_addrs().to_vec(); for cidr in input.lines() { let cidr = IpCidr::from_str(cidr) .map_err(|_| SyscallError::new(syscall::EINVAL))?; @@ -302,13 +137,14 @@ fn mk_root_node(iface: Interface) -> CfgNodeRef { iface.update_ip_addrs(|s| { *s = From::from(cidrs); }); + notifier.borrow_mut().schedule_notify("ifaces/eth0/addr/list"); Ok(0) } }, "rm" => { - wo [iface] |input| { + wo [iface, notifier] |input| { let mut iface = iface.borrow_mut(); - let mut cidrs = iface.ip_addrs().iter().cloned().collect::>(); + let mut cidrs = iface.ip_addrs().to_vec(); for cidr in input.lines() { let cidr = IpCidr::from_str(cidr) .map_err(|_| SyscallError::new(syscall::EINVAL))?; @@ -324,6 +160,7 @@ fn mk_root_node(iface: Interface) -> CfgNodeRef { iface.update_ip_addrs(|s| { *s = From::from(cidrs); }); + notifier.borrow_mut().schedule_notify("ifaces/eth0/addr/list"); Ok(0) } }, @@ -333,7 +170,14 @@ fn mk_root_node(iface: Interface) -> CfgNodeRef { } } +struct DNSConfig { + name_server: Ipv4Address, +} + +type DNSConfigRef = Rc>; + struct NetCfgFile { + path: String, cfg_node: CfgNodeRef, read_buf: Vec, write_buf: Vec, @@ -346,15 +190,21 @@ pub struct NetCfgScheme { next_fd: usize, files: BTreeMap, root_node: CfgNodeRef, + notifier: NotifierRef, } impl NetCfgScheme { pub fn new(iface: Interface, scheme_file: File) -> NetCfgScheme { + let notifier = Notifier::new_ref(); + let dns_config = Rc::new(RefCell::new(DNSConfig { + name_server: Ipv4Address::new(8, 8, 8, 8), + })); NetCfgScheme { scheme_file, next_fd: 1, files: BTreeMap::new(), - root_node: mk_root_node(iface), + root_node: mk_root_node(iface, Rc::clone(¬ifier), dns_config), + notifier, } } @@ -367,8 +217,16 @@ impl NetCfgScheme { self.handle(&mut packet); self.scheme_file.write_all(&packet)?; } + self.notify_scheduled_fds(); Ok(None) } + + fn notify_scheduled_fds(&mut self) { + let fds_to_notify = self.notifier.borrow_mut().get_notified_fds(); + for fd in fds_to_notify { + let _ = post_fevent(&mut self.scheme_file, fd, syscall::EVENT_READ, 1); + } + } } impl SchemeMut for NetCfgScheme { @@ -387,10 +245,12 @@ impl SchemeMut for NetCfgScheme { } let read_buf = Vec::from(current_node.borrow().read()); let fd = self.next_fd; + trace!("open {} {}", fd, path); self.next_fd += 1; self.files.insert( fd, NetCfgFile { + path: path.to_owned(), cfg_node: current_node, uid, pos: 0, @@ -402,10 +262,17 @@ impl SchemeMut for NetCfgScheme { } fn close(&mut self, fd: usize) -> SyscallResult { + trace!("close {}", fd); if let Some(file) = self.files.remove(&fd) { - let value = str::from_utf8(&file.write_buf) - .or_else(|_| Err(SyscallError::new(syscall::EINVAL)))?; - file.cfg_node.borrow().write(&value) + self.notifier.borrow_mut().unsubscribe(&file.path, fd); + let node = file.cfg_node.borrow(); + if node.is_writable() { + let value = str::from_utf8(&file.write_buf) + .or_else(|_| Err(SyscallError::new(syscall::EINVAL)))?; + node.write(value) + } else { + Ok(0) + } } else { Err(SyscallError::new(syscall::EBADF)) } @@ -464,4 +331,16 @@ impl SchemeMut for NetCfgScheme { Ok(0) } + + fn fevent(&mut self, fd: usize, events: usize) -> SyscallResult { + let file = self.files + .get_mut(&fd) + .ok_or_else(|| SyscallError::new(syscall::EBADF))?; + if events & syscall::EVENT_READ == syscall::EVENT_READ { + self.notifier.borrow_mut().subscribe(&file.path, fd); + } else { + self.notifier.borrow_mut().unsubscribe(&file.path, fd); + } + Ok(fd) + } } diff --git a/src/smolnetd/scheme/netcfg/nodes.rs b/src/smolnetd/scheme/netcfg/nodes.rs new file mode 100644 index 0000000000..4b9fe17401 --- /dev/null +++ b/src/smolnetd/scheme/netcfg/nodes.rs @@ -0,0 +1,199 @@ +use std::cell::RefCell; +use std::rc::Rc; +use std::collections::BTreeMap; +use syscall::Result as SyscallResult; + +pub type CfgNodeRef = Rc>; + +pub trait CfgNode { + fn is_dir(&self) -> bool { + false + } + + fn is_writable(&self) -> bool { + false + } + + fn is_readable(&self) -> bool { + true + } + + fn read(&self) -> String { + String::new() + } + + fn write(&self, _buf: &str) -> SyscallResult { + Ok(0) + } + + fn open(&self, _file: &str) -> Option { + None + } +} + +pub struct RONode +where + F: Fn() -> String, +{ + read_fun: F, +} + +impl CfgNode for RONode +where + F: Fn() -> String, +{ + fn read(&self) -> String { + (self.read_fun)() + } +} + +impl RONode +where + F: 'static + Fn() -> String, +{ + pub fn new_ref(read_fun: F) -> CfgNodeRef { + Rc::new(RefCell::new(RONode { read_fun })) + } +} + +pub struct WONode +where + F: Fn(&str) -> SyscallResult, +{ + write_fun: F, +} + +impl CfgNode for WONode +where + F: Fn(&str) -> SyscallResult, +{ + fn write(&self, buf: &str) -> SyscallResult { + (self.write_fun)(buf) + } + + fn is_readable(&self) -> bool { + false + } + + fn is_writable(&self) -> bool { + true + } +} + +impl WONode +where + F: 'static + Fn(&str) -> SyscallResult, +{ + pub fn new_ref(write_fun: F) -> CfgNodeRef { + Rc::new(RefCell::new(WONode { write_fun })) + } +} + +pub struct RWNode +where + F: Fn() -> String, + G: Fn(&str) -> SyscallResult, +{ + read_fun: F, + write_fun: G, +} + +impl CfgNode for RWNode +where + F: Fn() -> String, + G: Fn(&str) -> SyscallResult, +{ + fn read(&self) -> String { + (self.read_fun)() + } + + fn write(&self, buf: &str) -> SyscallResult { + (self.write_fun)(buf) + } + + fn is_writable(&self) -> bool { + true + } +} + +impl RWNode +where + F: 'static + Fn() -> String, + G: 'static + Fn(&str) -> SyscallResult, +{ + pub fn new_ref(read_fun: F, write_fun: G) -> CfgNodeRef { + Rc::new(RefCell::new(RWNode { + read_fun, + write_fun, + })) + } +} + +pub struct StaticDirNode { + child_nodes: BTreeMap, +} + +impl CfgNode for StaticDirNode { + fn is_dir(&self) -> bool { + true + } + + fn read(&self) -> String { + let mut files = String::new(); + for child in self.child_nodes.keys() { + if !files.is_empty() { + files.push('\n'); + } + files += child; + } + files + } + + fn open(&self, file: &str) -> Option { + self.child_nodes.get(file).map(|node| Rc::clone(node)) + } +} + +impl StaticDirNode { + pub fn new_ref(child_nodes: BTreeMap) -> CfgNodeRef { + Rc::new(RefCell::new(StaticDirNode { child_nodes })) + } +} + +macro_rules! cfg_node { + (val $e:expr) => { + $e + }; + (ro [ $($c:ident),* ] || $b:block ) => { + { + $(let $c = $c.clone();)* + RONode::new_ref(move|| $b) + } + }; + (wo [ $($c:ident),* ] |$i:ident| $b:block ) => { + { + $(let $c = $c.clone();)* + WONode::new_ref(move |$i: &str| $b) + } + }; + (rw [ $($c:ident),* ] || $rb:block |$i:ident| $wb:block ) => { + { + let read_fun = { + $(#[allow(unused_variables)] let $c = $c.clone();)* + move || $rb + }; + let write_fun = { + $(#[allow(unused_variables)] let $c = $c.clone();)* + move |$i: &str| $wb + }; + RWNode::new_ref(read_fun, write_fun) + } + }; + ($($e:expr => { $($t:tt)* }),* $(,)*) => { + { + let mut children = BTreeMap::new(); + $(children.insert($e.into(), cfg_node!($($t)*));)* + StaticDirNode::new_ref(children) + } + }; +} diff --git a/src/smolnetd/scheme/netcfg/notifier.rs b/src/smolnetd/scheme/netcfg/notifier.rs new file mode 100644 index 0000000000..24b0a66fcb --- /dev/null +++ b/src/smolnetd/scheme/netcfg/notifier.rs @@ -0,0 +1,62 @@ +use std::rc::Rc; +use std::cell::RefCell; +use std::collections::{BTreeMap, BTreeSet}; +use std::collections::btree_map::Entry; + +pub struct Notifier { + listeners: BTreeMap>, + notified: BTreeSet, +} + +pub type NotifierRef = Rc>; + +impl Notifier { + pub fn new_ref() -> NotifierRef { + Rc::new(RefCell::new(Notifier { + listeners: BTreeMap::new(), + notified: BTreeSet::new(), + })) + } + + pub fn subscribe(&mut self, path: &str, fd: usize) { + trace!("Sub fd {} to {}", fd, path); + match self.listeners.entry(path.to_owned()) { + Entry::Occupied(mut e) => { + e.get_mut().insert(fd); + } + Entry::Vacant(e) => { + let mut fds = BTreeSet::new(); + fds.insert(fd); + e.insert(fds); + } + } + } + + pub fn unsubscribe(&mut self, path: &str, fd: usize) { + let empty = if let Some(fds) = self.listeners.get_mut(path) { + if fds.remove(&fd) { + trace!("Unsub fd {} from {}", fd, path); + } + fds.is_empty() + } else { + false + }; + if empty { + self.listeners.remove(path); + } + } + + pub fn schedule_notify(&mut self, path: &str) { + trace!("Notifying {}", path); + if let Some(fds) = self.listeners.get(path) { + self.notified.extend(fds); + } + } + + pub fn get_notified_fds(&mut self) -> BTreeSet { + use std::mem::swap; + let mut notified = BTreeSet::new(); + swap(&mut self.notified, &mut notified); + notified + } +} diff --git a/src/smolnetd/scheme/tcp.rs b/src/smolnetd/scheme/tcp.rs index 7896c22948..a7cbf99c35 100644 --- a/src/smolnetd/scheme/tcp.rs +++ b/src/smolnetd/scheme/tcp.rs @@ -65,8 +65,8 @@ impl<'a> SchemeSocket for TcpSocket<'a> { return Err(SyscallError::new(syscall::EACCES)); } - let rx_packets = vec![0; 65_535]; - let tx_packets = vec![0; 65_535]; + let rx_packets = vec![0; 0xffff]; + let tx_packets = vec![0; 0xffff]; let rx_buffer = TcpSocketBuffer::new(rx_packets); let tx_buffer = TcpSocketBuffer::new(tx_packets); let socket = TcpSocket::new(rx_buffer, tx_buffer); @@ -164,8 +164,8 @@ impl<'a> SchemeSocket for TcpSocket<'a> { trace!("TCP creating new listening socket"); let new_handle = SchemeFile::Socket(tcp_handle.clone_with_data(())); - let rx_packets = vec![0; 65_535]; - let tx_packets = vec![0; 65_535]; + let rx_packets = vec![0; 0xffff]; + let tx_packets = vec![0; 0xffff]; let rx_buffer = TcpSocketBuffer::new(rx_packets); let tx_buffer = TcpSocketBuffer::new(tx_packets); let socket = TcpSocket::new(rx_buffer, tx_buffer); From 44e1d6943f1c79891cc8de3e35d3ca539fc140ac Mon Sep 17 00:00:00 2001 From: Tommie Levy Date: Wed, 31 Jan 2018 10:16:54 -0800 Subject: [PATCH 070/155] Add license and readme --- LICENSE | 22 ++++++++++++++++++++++ README.md | 3 +++ 2 files changed, 25 insertions(+) create mode 100644 LICENSE create mode 100644 README.md diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000..401759bf97 --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ +Copyright (c) 2018 Redox OS Developers + +MIT License + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000000..b5c71c0b76 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# Redox OS userspace networking stack + +This repository contains the networking stack for Redox OS. It makes use of [smoltcp](https://github.com/m-labs/smoltcp). From cf78d85d647a735dae5702d9371f3501aaa93f82 Mon Sep 17 00:00:00 2001 From: Egor Karavaev Date: Sat, 3 Feb 2018 00:40:30 +0300 Subject: [PATCH 071/155] netcfg commits on fsync --- src/dnsd/scheme.rs | 4 +- src/smolnetd/scheme/netcfg/mod.rs | 275 +++++++++++++++++++++------- src/smolnetd/scheme/netcfg/nodes.rs | 159 +++++++++++----- 3 files changed, 326 insertions(+), 112 deletions(-) diff --git a/src/dnsd/scheme.rs b/src/dnsd/scheme.rs index d32e562736..0c19472ae5 100644 --- a/src/dnsd/scheme.rs +++ b/src/dnsd/scheme.rs @@ -65,9 +65,9 @@ impl Domains { pub fn update_nameserver(&mut self) { if let Ok(mut file) = File::open("netcfg:resolv/nameserver") { let mut nameserver = String::new(); - if let Ok(_) = file.read_to_string(&mut nameserver) { + if file.read_to_string(&mut nameserver).is_ok() { if let Some(line) = nameserver.lines().next() { - if let Ok(ip) = Ipv4Addr::from_str(&line) { + if let Ok(ip) = Ipv4Addr::from_str(line) { trace!("Changing nameserver to {}", ip); self.nameserver = ip; } diff --git a/src/smolnetd/scheme/netcfg/mod.rs b/src/smolnetd/scheme/netcfg/mod.rs index a77a1a5d20..4a350bd0f1 100644 --- a/src/smolnetd/scheme/netcfg/mod.rs +++ b/src/smolnetd/scheme/netcfg/mod.rs @@ -8,6 +8,7 @@ use std::collections::BTreeMap; use std::fs::File; use std::io::{Read, Write}; use std::rc::Rc; +use std::mem; use std::str::FromStr; use std::str; use syscall::data::Stat; @@ -45,19 +46,31 @@ fn mk_root_node(iface: Interface, notifier: NotifierRef, dns_config: DNSConfigRe cfg_node!{ "resolv" => { "nameserver" => { - rw [dns_config, notifier] + rw [dns_config, notifier] (Option, None) || { format!("{}\n", dns_config.borrow().name_server) } - |name_server| { - let ip = Ipv4Address::from_str(name_server.trim()) - .map_err(|_| SyscallError::new(syscall::EINVAL))?; - if !ip.is_unicast() { - return Err(SyscallError::new(syscall::EINVAL)); + |cur_value, line| { + if cur_value.is_none() { + let ip = Ipv4Address::from_str(line.trim()) + .map_err(|_| SyscallError::new(syscall::EINVAL))?; + if !ip.is_unicast() { + return Err(SyscallError::new(syscall::EINVAL)); + } + *cur_value = Some(ip); + Ok(()) + } else { + Err(SyscallError::new(syscall::EINVAL)) + } + } + |cur_value| { + if let Some(ip) = *cur_value { + dns_config.borrow_mut().name_server = ip; + notifier.borrow_mut().schedule_notify("resolv/nameserver"); + Ok(()) + } else { + Err(SyscallError::new(syscall::EINVAL)) } - dns_config.borrow_mut().name_server = ip; - notifier.borrow_mut().schedule_notify("resolv/nameserver"); - Ok(0) } } }, @@ -72,44 +85,86 @@ fn mk_root_node(iface: Interface, notifier: NotifierRef, dns_config: DNSConfigRe } }, "add" => { - wo [iface, notifier] |routes| { - let default_gw = parse_default_gw(routes)?; - iface.borrow_mut().set_ipv4_gateway(Some(default_gw)); - notifier.borrow_mut().schedule_notify("route/list"); - Ok(0) + wo [iface, notifier] (Option, None) + |cur_value, line| { + if cur_value.is_none() { + let default_gw = parse_default_gw(line)?; + if !default_gw.is_unicast() { + return Err(SyscallError::new(syscall::EINVAL)); + } + *cur_value = Some(default_gw); + Ok(()) + } else { + Err(SyscallError::new(syscall::EINVAL)) + } + } + |cur_value| { + if let Some(default_gw) = *cur_value { + iface.borrow_mut().set_ipv4_gateway(Some(default_gw)); + notifier.borrow_mut().schedule_notify("route/list"); + Ok(()) + } else { + Err(SyscallError::new(syscall::EINVAL)) + } } }, "rm" => { - wo [iface, notifier] |routes| { - let default_gw = parse_default_gw(routes)?; - let mut iface = iface.borrow_mut(); - if iface.ipv4_gateway() != Some(default_gw) { - return Err(SyscallError::new(syscall::EINVAL)); + wo [iface, notifier] (Option, None) + |cur_value, line| { + if cur_value.is_none() { + let default_gw = parse_default_gw(line)?; + if !default_gw.is_unicast() { + return Err(SyscallError::new(syscall::EINVAL)); + } + *cur_value = Some(default_gw); + Ok(()) + } else { + Err(SyscallError::new(syscall::EINVAL)) } - iface.set_ipv4_gateway(None); - notifier.borrow_mut().schedule_notify("route/list"); - Ok(0) } - } + |cur_value| { + if let Some(default_gw) = *cur_value { + let mut iface = iface.borrow_mut(); + if iface.ipv4_gateway() != Some(default_gw) { + return Err(SyscallError::new(syscall::EINVAL)); + } + iface.set_ipv4_gateway(None); + notifier.borrow_mut().schedule_notify("route/list"); + Ok(()) + } else { + Err(SyscallError::new(syscall::EINVAL)) + } + } + }, }, "ifaces" => { "eth0" => { "mac" => { - rw [iface, notifier] + rw [iface, notifier] (Option, None) || { format!("{}\n", iface.borrow().ethernet_addr()) } - |mac| { - let mac = mac.lines().next() - .ok_or_else(|| SyscallError::new(syscall::EINVAL))?; - let mac = EthernetAddress::from_str(mac). - map_err(|_| SyscallError::new(syscall::EINVAL))?; - if !mac.is_unicast() { - return Err(SyscallError::new(syscall::EINVAL)); + |cur_value, line| { + if cur_value.is_none() { + let mac = EthernetAddress::from_str(line). + map_err(|_| SyscallError::new(syscall::EINVAL))?; + if !mac.is_unicast() { + return Err(SyscallError::new(syscall::EINVAL)); + } + *cur_value = Some(mac); + Ok(()) + } else { + Err(SyscallError::new(syscall::EINVAL)) + } + } + |cur_value| { + if let Some(mac) = *cur_value { + iface.borrow_mut().set_ethernet_addr(mac); + notifier.borrow_mut().schedule_notify("ifaces/eth0/mac"); + Ok(()) + } else { + Err(SyscallError::new(syscall::EINVAL)) } - iface.borrow_mut().set_ethernet_addr(mac); - notifier.borrow_mut().schedule_notify("ifaces/eth0/mac"); - Ok(0) } }, "addr" => { @@ -123,36 +178,46 @@ fn mk_root_node(iface: Interface, notifier: NotifierRef, dns_config: DNSConfigRe } }, "add" => { - wo [iface, notifier] |input| { + wo [iface, notifier] (Vec, Vec::new()) + |cur_value, line| { + let cidr = IpCidr::from_str(line) + .map_err(|_| SyscallError::new(syscall::EINVAL))?; + if !cidr.address().is_unicast() { + return Err(SyscallError::new(syscall::EINVAL)); + } + cur_value.push(cidr); + Ok(()) + } + |cur_value| { let mut iface = iface.borrow_mut(); let mut cidrs = iface.ip_addrs().to_vec(); - for cidr in input.lines() { - let cidr = IpCidr::from_str(cidr) - .map_err(|_| SyscallError::new(syscall::EINVAL))?; - if !cidr.address().is_unicast() { - return Err(SyscallError::new(syscall::EINVAL)); - } - cidrs.insert(0, cidr); + for cidr in cur_value { + cidrs.insert(0, *cidr); } iface.update_ip_addrs(|s| { *s = From::from(cidrs); }); notifier.borrow_mut().schedule_notify("ifaces/eth0/addr/list"); - Ok(0) + Ok(()) } }, "rm" => { - wo [iface, notifier] |input| { + wo [iface, notifier] (Vec, Vec::new()) + |cur_value, line| { + let cidr = IpCidr::from_str(line) + .map_err(|_| SyscallError::new(syscall::EINVAL))?; + if !cidr.address().is_unicast() { + return Err(SyscallError::new(syscall::EINVAL)); + } + cur_value.push(cidr); + Ok(()) + } + |cur_value| { let mut iface = iface.borrow_mut(); let mut cidrs = iface.ip_addrs().to_vec(); - for cidr in input.lines() { - let cidr = IpCidr::from_str(cidr) - .map_err(|_| SyscallError::new(syscall::EINVAL))?; - if !cidr.address().is_unicast() { - return Err(SyscallError::new(syscall::EINVAL)); - } + for cidr in cur_value { let pre_retain_len = cidrs.len(); - cidrs.retain(|&c| c != cidr); + cidrs.retain(|&c| c != *cidr); if pre_retain_len == cidrs.len() { return Err(SyscallError::new(syscall::EINVAL)); } @@ -161,7 +226,7 @@ fn mk_root_node(iface: Interface, notifier: NotifierRef, dns_config: DNSConfigRe *s = From::from(cidrs); }); notifier.borrow_mut().schedule_notify("ifaces/eth0/addr/list"); - Ok(0) + Ok(()) } }, } @@ -178,11 +243,62 @@ type DNSConfigRef = Rc>; struct NetCfgFile { path: String, - cfg_node: CfgNodeRef, + is_dir: bool, + is_writable: bool, + is_readable: bool, + node_writer: Option>, read_buf: Vec, write_buf: Vec, pos: usize, uid: u32, + done: bool, +} + +impl NetCfgFile { + fn commit(&mut self) -> SyscallResult<()> { + if let Some(ref mut node_writer) = self.node_writer { + if !self.write_buf.is_empty() { + let line = str::from_utf8(&self.write_buf) + .or_else(|_| Err(SyscallError::new(syscall::EINVAL)))?; + node_writer.write_line(line)?; + } + node_writer.commit()?; + self.write_buf.clear(); + } + Ok(()) + } + + fn consume_lines(&mut self) -> SyscallResult<()> { + if let Some(ref mut node_writer) = self.node_writer { + let mut swap_with = { + let mut lines = self.write_buf.split(|&c| c == b'\n'); + if let Some(mut cur_line) = lines.next() { + let mut consumed = false; + for next_line in lines { + let line = str::from_utf8(cur_line) + .or_else(|_| Err(SyscallError::new(syscall::EINVAL)))?; + trace!("writing line {}", line); + node_writer.write_line(line)?; + cur_line = next_line; + consumed = true; + } + if consumed { + Some(From::from(cur_line)) + } else { + None + } + } else { + None + } + }; + if let Some(ref mut new_vec) = swap_with { + mem::swap(&mut self.write_buf, new_vec); + } + Ok(()) + } else { + Err(SyscallError::new(syscall::EBADF)) + } + } } pub struct NetCfgScheme { @@ -243,7 +359,8 @@ impl SchemeMut for NetCfgScheme { .ok_or_else(|| SyscallError::new(syscall::EINVAL))?; current_node = next_node; } - let read_buf = Vec::from(current_node.borrow().read()); + let current_node = current_node.borrow(); + let read_buf = Vec::from(current_node.read()); let fd = self.next_fd; trace!("open {} {}", fd, path); self.next_fd += 1; @@ -251,11 +368,15 @@ impl SchemeMut for NetCfgScheme { fd, NetCfgFile { path: path.to_owned(), - cfg_node: current_node, + is_dir: current_node.is_dir(), + is_writable: current_node.is_writable(), + is_readable: current_node.is_readable(), + node_writer: if current_node.is_writable() { current_node.new_writer() } else { None }, uid, pos: 0, read_buf, write_buf: vec![], + done: false, }, ); Ok(fd) @@ -263,15 +384,12 @@ impl SchemeMut for NetCfgScheme { fn close(&mut self, fd: usize) -> SyscallResult { trace!("close {}", fd); - if let Some(file) = self.files.remove(&fd) { + if let Some(mut file) = self.files.remove(&fd) { self.notifier.borrow_mut().unsubscribe(&file.path, fd); - let node = file.cfg_node.borrow(); - if node.is_writable() { - let value = str::from_utf8(&file.write_buf) - .or_else(|_| Err(SyscallError::new(syscall::EINVAL)))?; - node.write(value) + if !file.done { + file.commit().map(|_| 0) } else { - Ok(0) + Err(SyscallError::new(syscall::EBADF)) } } else { Err(SyscallError::new(syscall::EBADF)) @@ -283,6 +401,10 @@ impl SchemeMut for NetCfgScheme { .get_mut(&fd) .ok_or_else(|| SyscallError::new(syscall::EBADF))?; + if file.done { + return Err(SyscallError::new(syscall::EBADF)); + } + if file.uid != 0 { return Err(SyscallError::new(syscall::EACCES)); } @@ -290,7 +412,15 @@ impl SchemeMut for NetCfgScheme { if (WRITE_BUFFER_MAX_SIZE - file.write_buf.len()) < buf.len() { return Err(SyscallError::new(syscall::EMSGSIZE)); } + file.write_buf.extend_from_slice(buf); + + if let Err(e) = file.consume_lines() { + trace!("Failed write {} {}", fd, e); + file.done = true; + return Err(e); + } + Ok(buf.len()) } @@ -312,17 +442,16 @@ impl SchemeMut for NetCfgScheme { let file = self.files .get_mut(&fd) .ok_or_else(|| SyscallError::new(syscall::EBADF))?; - let cfg_node = file.cfg_node.borrow(); - stat.st_mode = if cfg_node.is_dir() { + stat.st_mode = if file.is_dir { MODE_DIR } else { MODE_FILE }; - if cfg_node.is_writable() { + if file.is_writable { stat.st_mode |= 0o222; } - if cfg_node.is_readable() { + if file.is_readable { stat.st_mode |= 0o444; } stat.st_uid = 0; @@ -343,4 +472,18 @@ impl SchemeMut for NetCfgScheme { } Ok(fd) } + + fn fsync(&mut self, fd: usize) -> SyscallResult { + let file = self.files + .get_mut(&fd) + .ok_or_else(|| SyscallError::new(syscall::EBADF))?; + + if !file.done { + let res = file.commit().map(|_| 0); + file.done = true; + res + } else { + Err(SyscallError::new(syscall::EBADF)) + } + } } diff --git a/src/smolnetd/scheme/netcfg/nodes.rs b/src/smolnetd/scheme/netcfg/nodes.rs index 4b9fe17401..398a4e7c38 100644 --- a/src/smolnetd/scheme/netcfg/nodes.rs +++ b/src/smolnetd/scheme/netcfg/nodes.rs @@ -5,6 +5,54 @@ use syscall::Result as SyscallResult; pub type CfgNodeRef = Rc>; +pub trait NodeWriter { + fn write_line(&mut self, &str) -> SyscallResult<()> { + Ok(()) + } + + fn commit(&mut self) -> SyscallResult<()> { + Ok(()) + } +} + +pub struct SimpleWriter +where + WL: 'static + Fn(&mut T, &str) -> SyscallResult<()>, + C: 'static + Fn(&mut T) -> SyscallResult<()>, +{ + data: T, + write_line: WL, + commit: C, +} + +impl NodeWriter for SimpleWriter +where + WL: 'static + Fn(&mut T, &str) -> SyscallResult<()>, + C: 'static + Fn(&mut T) -> SyscallResult<()>, +{ + fn write_line(&mut self, line: &str) -> SyscallResult<()> { + (self.write_line)(&mut self.data, line) + } + + fn commit(&mut self) -> SyscallResult<()> { + (self.commit)(&mut self.data) + } +} + +impl SimpleWriter +where + WL: 'static + Fn(&mut T, &str) -> SyscallResult<()>, + C: 'static + Fn(&mut T) -> SyscallResult<()>, +{ + pub fn new_boxed(data: T, write_line: WL, commit: C) -> Box { + Box::new(SimpleWriter { + data, + write_line, + commit, + }) + } +} + pub trait CfgNode { fn is_dir(&self) -> bool { false @@ -22,11 +70,11 @@ pub trait CfgNode { String::new() } - fn write(&self, _buf: &str) -> SyscallResult { - Ok(0) + fn open(&self, _file: &str) -> Option { + None } - fn open(&self, _file: &str) -> Option { + fn new_writer(&self) -> Option> { None } } @@ -56,21 +104,17 @@ where } } -pub struct WONode +pub struct WONode where - F: Fn(&str) -> SyscallResult, + W: 'static + Fn() -> Box, { - write_fun: F, + new_writer: W, } -impl CfgNode for WONode +impl CfgNode for WONode where - F: Fn(&str) -> SyscallResult, + W: 'static + Fn() -> Box, { - fn write(&self, buf: &str) -> SyscallResult { - (self.write_fun)(buf) - } - fn is_readable(&self) -> bool { false } @@ -78,53 +122,57 @@ where fn is_writable(&self) -> bool { true } -} -impl WONode -where - F: 'static + Fn(&str) -> SyscallResult, -{ - pub fn new_ref(write_fun: F) -> CfgNodeRef { - Rc::new(RefCell::new(WONode { write_fun })) + fn new_writer(&self) -> Option> { + Some((self.new_writer)()) } } -pub struct RWNode +impl WONode where - F: Fn() -> String, - G: Fn(&str) -> SyscallResult, + W: 'static + Fn() -> Box, { - read_fun: F, - write_fun: G, + pub fn new_ref(new_writer: W) -> CfgNodeRef { + Rc::new(RefCell::new(WONode { new_writer })) + } } -impl CfgNode for RWNode +pub struct RWNode where F: Fn() -> String, - G: Fn(&str) -> SyscallResult, + W: 'static + Fn() -> Box, +{ + read_fun: F, + new_writer: W, +} + +impl CfgNode for RWNode +where + F: Fn() -> String, + W: 'static + Fn() -> Box, { fn read(&self) -> String { (self.read_fun)() } - fn write(&self, buf: &str) -> SyscallResult { - (self.write_fun)(buf) - } - fn is_writable(&self) -> bool { true } + + fn new_writer(&self) -> Option> { + Some((self.new_writer)()) + } } -impl RWNode +impl RWNode where F: 'static + Fn() -> String, - G: 'static + Fn(&str) -> SyscallResult, + W: 'static + Fn() -> Box, { - pub fn new_ref(read_fun: F, write_fun: G) -> CfgNodeRef { + pub fn new_ref(read_fun: F, new_writer: W) -> CfgNodeRef { Rc::new(RefCell::new(RWNode { read_fun, - write_fun, + new_writer, })) } } @@ -170,23 +218,46 @@ macro_rules! cfg_node { RONode::new_ref(move|| $b) } }; - (wo [ $($c:ident),* ] |$i:ident| $b:block ) => { + (wo [ $($c:ident),* ] ( $et:ty , $e:expr ) |$data_i:ident, $line_i:ident| + $write_line:block |$data_i2:ident| $commit:block) => { { - $(let $c = $c.clone();)* - WONode::new_ref(move |$i: &str| $b) + $(#[allow(unused_variables)] let $c = $c.clone();)*; + let new_writer = move || -> Box { + let write_line = { + $(#[allow(unused_variables)] let $c = $c.clone();)*; + move |$data_i: &mut $et, $line_i: &str| $write_line + }; + let commit = { + $(#[allow(unused_variables)] let $c = $c.clone();)*; + move |$data_i2: &mut $et| $commit + }; + let data: $et = $e; + SimpleWriter::new_boxed(data, write_line, commit) + }; + WONode::new_ref(new_writer) } }; - (rw [ $($c:ident),* ] || $rb:block |$i:ident| $wb:block ) => { + (rw [ $($c:ident),* ] ( $et:ty , $e:expr ) || $read_fun:block |$data_i:ident, $line_i:ident| + $write_line:block |$data_i2:ident| $commit:block) => { { let read_fun = { - $(#[allow(unused_variables)] let $c = $c.clone();)* - move || $rb + $(#[allow(unused_variables)] let $c = $c.clone();)*; + move || $read_fun }; - let write_fun = { - $(#[allow(unused_variables)] let $c = $c.clone();)* - move |$i: &str| $wb + $(#[allow(unused_variables)] let $c = $c.clone();)*; + let new_writer = move || -> Box { + let write_line = { + $(#[allow(unused_variables)] let $c = $c.clone();)*; + move |$data_i: &mut $et, $line_i: &str| $write_line + }; + let commit = { + $(#[allow(unused_variables)] let $c = $c.clone();)*; + move |$data_i2: &mut $et| $commit + }; + let data: $et = $e; + SimpleWriter::new_boxed(data, write_line, commit) }; - RWNode::new_ref(read_fun, write_fun) + RWNode::new_ref(read_fun, new_writer) } }; ($($e:expr => { $($t:tt)* }),* $(,)*) => { From 67a2d7900a7684e18f4c38b476472b151fb997ec Mon Sep 17 00:00:00 2001 From: Egor Karavaev Date: Sat, 3 Feb 2018 15:33:55 +0300 Subject: [PATCH 072/155] netcfg adds/set method --- src/smolnetd/scheme/netcfg/mod.rs | 48 +++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/src/smolnetd/scheme/netcfg/mod.rs b/src/smolnetd/scheme/netcfg/mod.rs index 4a350bd0f1..03a1b716c3 100644 --- a/src/smolnetd/scheme/netcfg/mod.rs +++ b/src/smolnetd/scheme/netcfg/mod.rs @@ -67,10 +67,8 @@ fn mk_root_node(iface: Interface, notifier: NotifierRef, dns_config: DNSConfigRe if let Some(ip) = *cur_value { dns_config.borrow_mut().name_server = ip; notifier.borrow_mut().schedule_notify("resolv/nameserver"); - Ok(()) - } else { - Err(SyscallError::new(syscall::EINVAL)) } + Ok(()) } } }, @@ -161,15 +159,14 @@ fn mk_root_node(iface: Interface, notifier: NotifierRef, dns_config: DNSConfigRe if let Some(mac) = *cur_value { iface.borrow_mut().set_ethernet_addr(mac); notifier.borrow_mut().schedule_notify("ifaces/eth0/mac"); - Ok(()) - } else { - Err(SyscallError::new(syscall::EINVAL)) } + Ok(()) } }, "addr" => { "list" => { - ro [iface] || { + ro [iface] + || { let mut ips = String::new(); for cidr in iface.borrow().ip_addrs() { ips += &format!("{}\n", cidr); @@ -177,6 +174,30 @@ fn mk_root_node(iface: Interface, notifier: NotifierRef, dns_config: DNSConfigRe ips } }, + "set" => { + wo [iface, notifier] (Vec, Vec::new()) + |cur_value, line| { + let cidr = IpCidr::from_str(line) + .map_err(|_| SyscallError::new(syscall::EINVAL))?; + if !cidr.address().is_unicast() { + return Err(SyscallError::new(syscall::EINVAL)); + } + cur_value.push(cidr); + Ok(()) + } + |cur_value| { + if !cur_value.is_empty() { + let mut iface = iface.borrow_mut(); + let mut cidrs = vec![]; + mem::swap(cur_value, &mut cidrs); + iface.update_ip_addrs(|s| { + *s = From::from(cidrs); + }); + notifier.borrow_mut().schedule_notify("ifaces/eth0/addr/list"); + } + Ok(()) + } + }, "add" => { wo [iface, notifier] (Vec, Vec::new()) |cur_value, line| { @@ -270,7 +291,8 @@ impl NetCfgFile { fn consume_lines(&mut self) -> SyscallResult<()> { if let Some(ref mut node_writer) = self.node_writer { - let mut swap_with = { + let mut swap_with = None; + { let mut lines = self.write_buf.split(|&c| c == b'\n'); if let Some(mut cur_line) = lines.next() { let mut consumed = false; @@ -283,14 +305,10 @@ impl NetCfgFile { consumed = true; } if consumed { - Some(From::from(cur_line)) - } else { - None + swap_with = Some(From::from(cur_line)) } - } else { - None } - }; + } if let Some(ref mut new_vec) = swap_with { mem::swap(&mut self.write_buf, new_vec); } @@ -389,7 +407,7 @@ impl SchemeMut for NetCfgScheme { if !file.done { file.commit().map(|_| 0) } else { - Err(SyscallError::new(syscall::EBADF)) + Ok(0) } } else { Err(SyscallError::new(syscall::EBADF)) From 76d8feae8d043693059f3db08dc748f961e55ffa Mon Sep 17 00:00:00 2001 From: Dan Robertson Date: Sat, 10 Feb 2018 20:43:58 +0000 Subject: [PATCH 073/155] Use smoltcp::time types instead of u64 timestamps smoltcp is moving towards using time::Duration and time::Instant instead of a u64 timestamp. --- Cargo.lock | 86 +++++++++++++++++++++++++++++--------- src/smolnetd/device.rs | 5 ++- src/smolnetd/scheme/mod.rs | 45 ++++++++++---------- 3 files changed, 90 insertions(+), 46 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ba97aa7ca1..dc2d5eae74 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3,6 +3,14 @@ name = "arg_parser" version = "0.1.0" source = "git+https://github.com/redox-os/arg-parser.git#7503531821b0c111f9fac77a5d2536ea221105fe" +[[package]] +name = "arrayvec" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "base64" version = "0.6.0" @@ -33,14 +41,36 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] -name = "coco" -version = "0.1.1" +name = "crossbeam-deque" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "either 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-epoch 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", "scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "crossbeam-utils" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "dns-parser" version = "0.7.1" @@ -50,11 +80,6 @@ dependencies = [ "quick-error 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "either" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "extra" version = "0.1.0" @@ -141,6 +166,11 @@ name = "lazy_static" version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "lazy_static" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "libc" version = "0.2.36" @@ -172,6 +202,11 @@ name = "matches" version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "memoffset" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "mime" version = "0.2.6" @@ -183,7 +218,7 @@ dependencies = [ [[package]] name = "netutils" version = "0.1.0" -source = "git+https://github.com/redox-os/netutils.git#a719fa50b065840ffacc81d989e47f258b3e5170" +source = "git+https://github.com/redox-os/netutils.git#a85c2af76fdfd0522d0fb31bebbe04f4b4e7e4b6" dependencies = [ "arg_parser 0.1.0 (git+https://github.com/redox-os/arg-parser.git)", "extra 0.1.0 (git+https://github.com/redox-os/libextra.git)", @@ -197,6 +232,11 @@ dependencies = [ "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "nodrop" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "ntpclient" version = "0.0.1" @@ -238,11 +278,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "rand" -version = "0.3.20" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -250,19 +291,19 @@ name = "rayon" version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "rayon-core 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rayon-core 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rayon-core" -version = "1.3.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "coco 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.3.20 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -342,7 +383,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "smoltcp" version = "0.4.0" -source = "git+https://github.com/m-labs/smoltcp.git#c2d18ec071a2cd68aee2724ce13eefa6ccf1f0c1" +source = "git+https://github.com/m-labs/smoltcp.git#c418b60b5db93753999ae51d33ec4dc1d1631c69" dependencies = [ "byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "managed 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -469,14 +510,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [metadata] "checksum arg_parser 0.1.0 (git+https://github.com/redox-os/arg-parser.git)" = "" +"checksum arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)" = "a1e964f9e24d588183fcb43503abda40d288c8657dfc27311516ce2f05675aef" "checksum base64 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "96434f987501f0ed4eb336a411e0631ecd1afa11574fe148587adc4ff96143c9" "checksum bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b3c30d3802dfb7281680d6285f2ccdaa8c2d8fee41f93805dba5c4cf50dc23cf" "checksum byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855" "checksum byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "652805b7e73fada9d85e9a6682a4abd490cb52d96aeecc12e33a0de34dfd0d23" "checksum cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c819a1287eb618df47cc647173c5c4c66ba19d888a6e50d605672aed3140de" -"checksum coco 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c06169f5beb7e31c7c67ebf5540b8b472d23e3eade3b2ec7d1f5b504a85f91bd" +"checksum crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f739f8c5363aca78cfb059edf753d8f0d36908c348f3d8d1503f03d8b75d9cf3" +"checksum crossbeam-epoch 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "59796cc6cbbdc6bb319161349db0c3250ec73ec7fcb763a51065ec4e2e158552" +"checksum crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2760899e32a1d58d5abb31129f8fae5de75220bc2176e77ff7c627ae45c918d9" "checksum dns-parser 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f7020f6760aea312d43d23cb83bf6c0c49f162541db8b02bf95209ac51dc253d" -"checksum either 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "740178ddf48b1a9e878e6d6509a1442a2d42fd2928aae8e7a6f8a36fb01981b3" "checksum extra 0.1.0 (git+https://github.com/redox-os/libextra.git)" = "" "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" "checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" @@ -488,21 +531,24 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a" "checksum lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "76f033c7ad61445c5b347c7382dd1237847eb1bce590fe50365dcb33d546be73" +"checksum lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c8f31047daa365f19be14b47c29df4f7c3b581832407daabe6ae77397619237d" "checksum libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)" = "1e5d97d6708edaa407429faa671b942dc0f2727222fb6b6539bf1db936e4b121" "checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" "checksum log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "89f010e843f2b1a31dbd316b3b8d443758bc634bed37aabade59c686d644e0a2" "checksum managed 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "43e2737ecabe4ae36a68061398bf27d2bfd0763f4c3c837a398478459494c4b7" "checksum matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "100aabe6b8ff4e4a7e32c1c13523379802df0772b82466207ac25b013f193376" +"checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3" "checksum mime 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ba626b8a6de5da682e1caa06bdb42a335aee5a84db8e5046a3e8ab17ba0a3ae0" "checksum netutils 0.1.0 (git+https://github.com/redox-os/netutils.git)" = "" +"checksum nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "9a2228dca57108069a5262f2ed8bd2e82496d2e074a06d1ccc7ce1687b6ae0a2" "checksum ntpclient 0.0.1 (git+https://github.com/willem66745/ntpclient-rust)" = "" "checksum num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c51a3322e4bca9d212ad9a158a02abc6934d005490c054a2778df73a70aa0a30" "checksum pbr 1.0.0 (git+https://github.com/a8m/pb)" = "" "checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" "checksum quick-error 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "eda5fe9b71976e62bc81b781206aaa076401769b2143379d3eb2118388babac4" -"checksum rand 0.3.20 (registry+https://github.com/rust-lang/crates.io-index)" = "512870020642bb8c221bf68baa1b2573da814f6ccfe5c9699b1c303047abe9b1" +"checksum rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "eba5f8cb59cc50ed56be8880a5c7b496bfd9bd26394e176bc67884094145c2c5" "checksum rayon 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a77c51c07654ddd93f6cb543c7a849863b03abc7e82591afda6dc8ad4ac3ac4a" -"checksum rayon-core 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e64b609139d83da75902f88fd6c01820046840a18471e4dfcd5ac7c0f46bea53" +"checksum rayon-core 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9d24ad214285a7729b174ed6d3bcfcb80177807f959d95fafd5bfc5c4f201ac8" "checksum redox_event 0.1.0 (git+https://github.com/redox-os/event.git)" = "" "checksum redox_syscall 0.1.37 (git+https://github.com/redox-os/syscall.git)" = "" "checksum redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "0d92eecebad22b767915e4d529f89f28ee96dbbf5a4810d2b844373f136417fd" diff --git a/src/smolnetd/device.rs b/src/smolnetd/device.rs index 950f35ff9d..dbb6eefe4d 100644 --- a/src/smolnetd/device.rs +++ b/src/smolnetd/device.rs @@ -5,6 +5,7 @@ use std::fs::File; use std::io::Write; use std::rc::Rc; +use smoltcp::time::Instant; use smoltcp::wire::EthernetAddress; use buffer_pool::{Buffer, BufferPool}; @@ -44,7 +45,7 @@ pub struct RxToken { } impl smoltcp::phy::RxToken for RxToken { - fn consume(self, _timestamp: u64, f: F) -> smoltcp::Result + fn consume(self, _timestamp: Instant, f: F) -> smoltcp::Result where F: FnOnce(&[u8]) -> smoltcp::Result, { @@ -57,7 +58,7 @@ pub struct TxToken { } impl smoltcp::phy::TxToken for TxToken { - fn consume(self, _timestamp: u64, len: usize, f: F) -> smoltcp::Result + fn consume(self, _timestamp: Instant, len: usize, f: F) -> smoltcp::Result where F: FnOnce(&mut [u8]) -> smoltcp::Result, { diff --git a/src/smolnetd/scheme/mod.rs b/src/smolnetd/scheme/mod.rs index 22ad873c48..1afb129605 100644 --- a/src/smolnetd/scheme/mod.rs +++ b/src/smolnetd/scheme/mod.rs @@ -2,6 +2,7 @@ use netutils::getcfg; use smoltcp; use smoltcp::iface::{EthernetInterface, EthernetInterfaceBuilder, NeighborCache}; use smoltcp::socket::SocketSet as SmoltcpSocketSet; +use smoltcp::time::{Duration, Instant}; use smoltcp::wire::{EthernetAddress, IpAddress, IpCidr, IpEndpoint, Ipv4Address}; use std::cell::RefCell; use std::collections::{BTreeMap, VecDeque}; @@ -10,7 +11,6 @@ use std::io::{Read, Write}; use std::mem::size_of; use std::rc::Rc; use std::str::FromStr; -use std::time::Instant; use syscall::data::TimeSpec; use syscall; @@ -33,14 +33,16 @@ mod netcfg; type SocketSet = SmoltcpSocketSet<'static, 'static, 'static>; type Interface = Rc>>; +const MAX_DURATION: Duration = Duration { millis: ::std::u64::MAX }; +const MIN_DURATION: Duration = Duration { millis: 0 }; + pub struct Smolnetd { network_file: Rc>, time_file: File, iface: Interface, socket_set: Rc>, - - startup_time: Instant, + timer: ::std::time::Instant, ip_scheme: IpScheme, udp_scheme: UdpScheme, @@ -55,8 +57,8 @@ pub struct Smolnetd { impl Smolnetd { const MAX_PACKET_SIZE: usize = 2048; const SOCKET_BUFFER_SIZE: usize = 128; //packets - const MIN_CHECK_TIMEOUT_MS: i64 = 10; - const MAX_CHECK_TIMEOUT_MS: i64 = 500; + const MIN_CHECK_TIMEOUT: Duration = Duration { millis: 10 }; + const MAX_CHECK_TIMEOUT: Duration = Duration { millis: 500 }; pub fn new( network_file: File, @@ -98,7 +100,7 @@ impl Smolnetd { Smolnetd { iface: Rc::clone(&iface), socket_set: Rc::clone(&socket_set), - startup_time: Instant::now(), + timer: ::std::time::Instant::now(), time_file, ip_scheme: IpScheme::new(Rc::clone(&socket_set), ip_file), udp_scheme: UdpScheme::new(Rc::clone(&socket_set), udp_file), @@ -153,7 +155,7 @@ impl Smolnetd { Ok(None) } - fn schedule_time_event(&mut self, timeout: i64) -> Result<()> { + fn schedule_time_event(&mut self, timeout: Duration) -> Result<()> { let mut time = TimeSpec::default(); if self.time_file.read(&mut time)? < size_of::() { return Err(Error::from_syscall_error( @@ -162,7 +164,7 @@ impl Smolnetd { )); } let mut time_ms = time.tv_sec * 1000i64 + i64::from(time.tv_nsec) / 1_000_000i64; - time_ms += timeout; + time_ms += timeout.total_millis() as i64; time.tv_sec = time_ms / 1000; time.tv_nsec = ((time_ms % 1000) * 1_000_000) as i32; self.time_file @@ -171,37 +173,37 @@ impl Smolnetd { Ok(()) } - fn poll(&mut self) -> Result { + fn poll(&mut self) -> Result { let timeout = { let mut iter_limit = 10usize; let mut iface = self.iface.borrow_mut(); let mut socket_set = self.socket_set.borrow_mut(); - let timestamp = self.get_timestamp(); + let timestamp = Instant::from(self.timer); loop { if iter_limit == 0 { - break 0; + break MIN_DURATION; } iter_limit -= 1; match iface.poll(&mut socket_set, timestamp) { Ok(_) | Err(smoltcp::Error::Unrecognized) => (), Err(e) => { error!("poll error: {}", e); - break 0; + break MIN_DURATION; } } - match iface.poll_at(&socket_set, timestamp) { - Some(n) if n > timestamp => { - break ::std::cmp::min(::std::i64::MAX as u64, n - timestamp) as i64 + match iface.poll_delay(&socket_set, timestamp) { + Some(Duration { millis: 0 }) => { } + Some(delay) => { + break ::std::cmp::min(MAX_DURATION, delay) } - Some(_) => {} - None => break ::std::i64::MAX, + None => break MAX_DURATION } } }; self.notify_sockets()?; Ok(::std::cmp::min( - ::std::cmp::max(Smolnetd::MIN_CHECK_TIMEOUT_MS, timeout), - Smolnetd::MAX_CHECK_TIMEOUT_MS, + ::std::cmp::max(Smolnetd::MIN_CHECK_TIMEOUT, timeout), + Smolnetd::MAX_CHECK_TIMEOUT, )) } @@ -223,11 +225,6 @@ impl Smolnetd { Ok(total_frames) } - fn get_timestamp(&self) -> u64 { - let duration = Instant::now().duration_since(self.startup_time); - (duration.as_secs() * 1000) + u64::from(duration.subsec_nanos() / 1_000_000) - } - fn notify_sockets(&mut self) -> Result<()> { self.ip_scheme.notify_sockets()?; self.udp_scheme.notify_sockets()?; From f6450412930878c197079d91904bb3c34c6f3734 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sat, 19 May 2018 19:33:41 -0600 Subject: [PATCH 074/155] dnsd: enter null namespace --- src/dnsd/main.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/dnsd/main.rs b/src/dnsd/main.rs index 6a1b67c9ef..8ca831dd2d 100644 --- a/src/dnsd/main.rs +++ b/src/dnsd/main.rs @@ -49,6 +49,8 @@ fn run() -> Result<()> { let mut event_queue = EventQueue::<(), Error>::new() .map_err(|e| Error::from_io_error(e, "failed to create event queue"))?; + syscall::setrens(0, 0).expect("dnsd: failed to enter null namespace"); + let dnsd_ = Rc::clone(&dnsd); event_queue From 7d181f5e680f811c23fa8b2faff421ae8cea9b08 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sun, 20 May 2018 11:31:37 -0600 Subject: [PATCH 075/155] Update to new event --- Cargo.lock | 100 +++++++++++++++++++++---------------------- Cargo.toml | 1 + src/dnsd/main.rs | 13 +++--- src/dnsd/scheme.rs | 30 +++++++------ src/smolnetd/main.rs | 5 ++- 5 files changed, 79 insertions(+), 70 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dc2d5eae74..da8b36e32f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -16,13 +16,13 @@ name = "base64" version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "bitflags" -version = "1.0.1" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -32,12 +32,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "byteorder" -version = "1.2.1" +version = "1.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "cfg-if" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -45,19 +45,19 @@ name = "crossbeam-deque" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "crossbeam-epoch 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-epoch 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "crossbeam-epoch" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", "scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -68,7 +68,7 @@ name = "crossbeam-utils" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -76,7 +76,7 @@ name = "dns-parser" version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "quick-error 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -90,7 +90,7 @@ name = "fuchsia-zircon" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -120,11 +120,11 @@ dependencies = [ "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "mime 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "time 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", "traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "typeable 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "unicase 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "url 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -144,7 +144,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-normalization 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-normalization 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -173,7 +173,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libc" -version = "0.2.36" +version = "0.2.40" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -189,7 +189,7 @@ name = "log" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -218,15 +218,15 @@ dependencies = [ [[package]] name = "netutils" version = "0.1.0" -source = "git+https://github.com/redox-os/netutils.git#a85c2af76fdfd0522d0fb31bebbe04f4b4e7e4b6" +source = "git+https://github.com/redox-os/netutils.git#7eda176e6b4e2edbcc0616247598ec5e87bfe8e8" dependencies = [ "arg_parser 0.1.0 (git+https://github.com/redox-os/arg-parser.git)", "extra 0.1.0 (git+https://github.com/redox-os/libextra.git)", "hyper 0.10.13 (registry+https://github.com/rust-lang/crates.io-index)", "hyper-rustls 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", "ntpclient 0.0.1 (git+https://github.com/willem66745/ntpclient-rust)", - "pbr 1.0.0 (git+https://github.com/a8m/pb)", + "pbr 1.0.1 (git+https://github.com/a8m/pb)", "redox_event 0.1.0 (git+https://github.com/redox-os/event.git)", "redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -243,7 +243,7 @@ version = "0.0.1" source = "git+https://github.com/willem66745/ntpclient-rust#7e3bdf60eb940825789a8da5181025320e3050b0" dependencies = [ "byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", - "time 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -251,18 +251,18 @@ name = "num_cpus" version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "pbr" -version = "1.0.0" -source = "git+https://github.com/a8m/pb#d077b49ac6ea18ef63a9bb9f0f0b58abc29580f3" +version = "1.0.1" +source = "git+https://github.com/a8m/pb#e1df7361a08e2c7e210a3e483e3086bfe62dfe71" dependencies = [ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "time 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -282,7 +282,7 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -301,7 +301,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -309,7 +309,7 @@ dependencies = [ [[package]] name = "redox_event" version = "0.1.0" -source = "git+https://github.com/redox-os/event.git#68f4c7e55615ecede98f2085c81801a3dc4b74e0" +source = "git+https://github.com/redox-os/event.git#f2448cdafefa5a8deb304d7ea09faf3feb5ff328" dependencies = [ "redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -318,13 +318,13 @@ dependencies = [ name = "redox_netstack" version = "0.1.0" dependencies = [ - "byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "dns-parser 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "netutils 0.1.0 (git+https://github.com/redox-os/netutils.git)", "redox_event 0.1.0 (git+https://github.com/redox-os/event.git)", "redox_syscall 0.1.37 (git+https://github.com/redox-os/syscall.git)", - "smoltcp 0.4.0 (git+https://github.com/m-labs/smoltcp.git)", + "smoltcp 0.4.0 (git+https://github.com/m-labs/smoltcp.git?rev=c418b60b5db93753999ae51d33ec4dc1d1631c69)", ] [[package]] @@ -352,7 +352,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -365,7 +365,7 @@ dependencies = [ "base64 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "ring 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", - "time 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", "untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "webpki 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -383,9 +383,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "smoltcp" version = "0.4.0" -source = "git+https://github.com/m-labs/smoltcp.git#c418b60b5db93753999ae51d33ec4dc1d1631c69" +source = "git+https://github.com/m-labs/smoltcp.git?rev=c418b60b5db93753999ae51d33ec4dc1d1631c69#c418b60b5db93753999ae51d33ec4dc1d1631c69" dependencies = [ - "byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "managed 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -394,17 +394,17 @@ name = "termion" version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "time" -version = "0.1.39" +version = "0.1.40" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -437,7 +437,7 @@ dependencies = [ [[package]] name = "unicode-normalization" -version = "0.1.5" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -447,7 +447,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "url" -version = "1.6.0" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "idna 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -466,7 +466,7 @@ version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "ring 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", - "time 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", "untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -512,12 +512,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum arg_parser 0.1.0 (git+https://github.com/redox-os/arg-parser.git)" = "" "checksum arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)" = "a1e964f9e24d588183fcb43503abda40d288c8657dfc27311516ce2f05675aef" "checksum base64 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "96434f987501f0ed4eb336a411e0631ecd1afa11574fe148587adc4ff96143c9" -"checksum bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b3c30d3802dfb7281680d6285f2ccdaa8c2d8fee41f93805dba5c4cf50dc23cf" +"checksum bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d0c54bb8f454c567f21197eefcdbf5679d0bd99f2ddbe52e84c77061952e6789" "checksum byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855" -"checksum byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "652805b7e73fada9d85e9a6682a4abd490cb52d96aeecc12e33a0de34dfd0d23" -"checksum cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c819a1287eb618df47cc647173c5c4c66ba19d888a6e50d605672aed3140de" +"checksum byteorder 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "74c0b906e9446b0a2e4f760cdb3fa4b2c48cdc6db8766a845c54b6ff063fd2e9" +"checksum cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "405216fd8fe65f718daa7102ea808a946b6ce40c742998fbfd3463645552de18" "checksum crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f739f8c5363aca78cfb059edf753d8f0d36908c348f3d8d1503f03d8b75d9cf3" -"checksum crossbeam-epoch 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "59796cc6cbbdc6bb319161349db0c3250ec73ec7fcb763a51065ec4e2e158552" +"checksum crossbeam-epoch 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "927121f5407de9956180ff5e936fe3cf4324279280001cd56b669d28ee7e9150" "checksum crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2760899e32a1d58d5abb31129f8fae5de75220bc2176e77ff7c627ae45c918d9" "checksum dns-parser 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f7020f6760aea312d43d23cb83bf6c0c49f162541db8b02bf95209ac51dc253d" "checksum extra 0.1.0 (git+https://github.com/redox-os/libextra.git)" = "" @@ -532,7 +532,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a" "checksum lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "76f033c7ad61445c5b347c7382dd1237847eb1bce590fe50365dcb33d546be73" "checksum lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c8f31047daa365f19be14b47c29df4f7c3b581832407daabe6ae77397619237d" -"checksum libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)" = "1e5d97d6708edaa407429faa671b942dc0f2727222fb6b6539bf1db936e4b121" +"checksum libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)" = "6fd41f331ac7c5b8ac259b8bf82c75c0fb2e469bbf37d2becbba9a6a2221965b" "checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" "checksum log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "89f010e843f2b1a31dbd316b3b8d443758bc634bed37aabade59c686d644e0a2" "checksum managed 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "43e2737ecabe4ae36a68061398bf27d2bfd0763f4c3c837a398478459494c4b7" @@ -543,7 +543,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "9a2228dca57108069a5262f2ed8bd2e82496d2e074a06d1ccc7ce1687b6ae0a2" "checksum ntpclient 0.0.1 (git+https://github.com/willem66745/ntpclient-rust)" = "" "checksum num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c51a3322e4bca9d212ad9a158a02abc6934d005490c054a2778df73a70aa0a30" -"checksum pbr 1.0.0 (git+https://github.com/a8m/pb)" = "" +"checksum pbr 1.0.1 (git+https://github.com/a8m/pb)" = "" "checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" "checksum quick-error 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "eda5fe9b71976e62bc81b781206aaa076401769b2143379d3eb2118388babac4" "checksum rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "eba5f8cb59cc50ed56be8880a5c7b496bfd9bd26394e176bc67884094145c2c5" @@ -557,16 +557,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum rustls 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "17727f4b991294da2c84d75a43c003151ff58072212768800f66c56ee46dca43" "checksum safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e27a8b19b835f7aea908818e871f5cc3a5a186550c30773be987e155e8163d8f" "checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" -"checksum smoltcp 0.4.0 (git+https://github.com/m-labs/smoltcp.git)" = "" +"checksum smoltcp 0.4.0 (git+https://github.com/m-labs/smoltcp.git?rev=c418b60b5db93753999ae51d33ec4dc1d1631c69)" = "" "checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" -"checksum time 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "a15375f1df02096fb3317256ce2cee6a1f42fc84ea5ad5fc8c421cfe40c73098" +"checksum time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "d825be0eb33fda1a7e68012d51e9c7f451dc1a69391e7fdc197060bb8c56667b" "checksum traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079" "checksum typeable 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1410f6f91f21d1612654e7cc69193b0334f909dcf2c790c4826254fbb86f8887" "checksum unicase 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7f4765f83163b74f957c797ad9253caf97f103fb064d3999aea9568d09fc8a33" "checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" -"checksum unicode-normalization 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "51ccda9ef9efa3f7ef5d91e8f9b83bbe6955f9bf86aec89d5cce2c874625920f" +"checksum unicode-normalization 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "6a0180bc61fc5a987082bfa111f4cc95c4caff7f9799f3e46df09163a937aa25" "checksum untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f392d7819dbe58833e26872f5f6f0d68b7bbbe90fc3667e98731c4a15ad9a7ae" -"checksum url 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fa35e768d4daf1d85733418a49fb42e10d7f633e394fccab4ab7aba897053fe2" +"checksum url 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f808aadd8cfec6ef90e4a14eb46f24511824d1ac596b9682703c87056c8678b7" "checksum version_check 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6b772017e347561807c1aa192438c5fd74242a670a6cffacc40f2defd1dc069d" "checksum webpki 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e499345fc4c6b7c79a5b8756d4592c4305510a13512e79efafe00dfbd67bbac6" "checksum webpki-roots 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5bfb3f50499f21ad2317f442845e3b5805b007f1e728f59885c99e61b8c181a7" diff --git a/Cargo.toml b/Cargo.toml index ecf958647a..c8083edbe8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,6 +28,7 @@ features = ["release_max_level_off"] [dependencies.smoltcp] git = "https://github.com/m-labs/smoltcp.git" +rev = "c418b60b5db93753999ae51d33ec4dc1d1631c69" default-features = false features = ["std", "socket-raw", "proto-ipv4", "socket-udp", "socket-tcp", "socket-icmp"] diff --git a/src/dnsd/main.rs b/src/dnsd/main.rs index 8ca831dd2d..7bb3fd773b 100644 --- a/src/dnsd/main.rs +++ b/src/dnsd/main.rs @@ -13,7 +13,7 @@ use redox_netstack::logger; use scheme::Dnsd; use std::cell::RefCell; use std::fs::File; -use std::os::unix::io::{FromRawFd, RawFd}; +use std::os::unix::io::{AsRawFd, FromRawFd, RawFd}; use std::process; use std::rc::Rc; @@ -44,11 +44,11 @@ fn run() -> Result<()> { ) }; - let dnsd = Rc::new(RefCell::new(Dnsd::new(dns_file, time_file))); - let mut event_queue = EventQueue::<(), Error>::new() .map_err(|e| Error::from_io_error(e, "failed to create event queue"))?; + let dnsd = Rc::new(RefCell::new(Dnsd::new(dns_file, time_file, event_queue.file.as_raw_fd()))); + syscall::setrens(0, 0).expect("dnsd: failed to enter null namespace"); let dnsd_ = Rc::clone(&dnsd); @@ -65,13 +65,16 @@ fn run() -> Result<()> { let dnsd_ = Rc::clone(&dnsd); - event_queue.set_default_callback(move |fd, _| dnsd_.borrow_mut().on_unknown_fd_event(fd)); + event_queue.set_default_callback(move |event| dnsd_.borrow_mut().on_unknown_fd_event(event.fd)); event_queue .add(time_fd, move |_| dnsd.borrow_mut().on_time_event()) .map_err(|e| Error::from_io_error(e, "failed to listen to time events"))?; - event_queue.trigger_all(0)?; + event_queue.trigger_all(event::Event { + fd: 0, + flags: 0, + })?; event_queue.run() } diff --git a/src/dnsd/scheme.rs b/src/dnsd/scheme.rs index 0c19472ae5..1bcf69e1f6 100644 --- a/src/dnsd/scheme.rs +++ b/src/dnsd/scheme.rs @@ -76,7 +76,7 @@ impl Domains { } } - fn request_domain(&mut self, domain: &str) -> Option { + fn request_domain(&mut self, domain: &str, queue_fd: RawFd) -> Option { trace!("Requesting domain {}", domain); let mut builder = Builder::new_query(1, true); builder.add_question(domain, QueryType::A, QueryClass::IN); @@ -89,12 +89,12 @@ impl Domains { syscall::close(udp_fd as usize).ok()?; return None; } - subscribe_to_fd(udp_fd).ok()?; + subscribe_to_fd(queue_fd, udp_fd, 0xFFFFFFFF).ok()?; self.requests.insert(udp_fd, domain.to_owned().into()); Some(udp_fd) } - fn on_time_event(&mut self, cur_time: &TimeSpec) -> BTreeSet { + fn on_time_event(&mut self, cur_time: &TimeSpec, queue_fd: RawFd) -> BTreeSet { while let Some((timeout, domain)) = self.resolved_timeouts.pop_front() { if timeout.tv_sec > cur_time.tv_sec || (timeout.tv_sec == cur_time.tv_sec && timeout.tv_nsec > cur_time.tv_nsec) @@ -133,7 +133,7 @@ impl Domains { } = e.remove() { fds_to_wakeup.append(&mut waiting_fds); - let _ = unsubscribe_from_fd(socket_fd); + let _ = unsubscribe_from_fd(queue_fd, socket_fd, 0xFFFFFFFF); let _ = syscall::close(socket_fd as usize); } } @@ -144,7 +144,7 @@ impl Domains { fds_to_wakeup } - fn on_fd_event(&mut self, fd: RawFd, cur_time: &TimeSpec) -> Option { + fn on_fd_event(&mut self, fd: RawFd, cur_time: &TimeSpec, queue_fd: RawFd) -> Option { let e = match self.requests.entry(fd) { Entry::Vacant(_) => { return None; @@ -160,7 +160,7 @@ impl Domains { if pkt.header.response_code != ResponseCode::NoError || pkt.answers.is_empty() { if let Some(query) = pkt.questions.iter().next() { if query.qname.to_string().to_lowercase() == e.get().as_ref() { - unsubscribe_from_fd(fd).ok()?; + unsubscribe_from_fd(queue_fd, fd, 0xFFFFFFFF).ok()?; syscall::close(fd as usize).ok()?; let domain = e.remove(); self.requested_timeouts @@ -190,7 +190,7 @@ impl Domains { return None; } let data = Rc::from(result.into_bytes()); - unsubscribe_from_fd(fd).ok()?; + unsubscribe_from_fd(queue_fd, fd, 0xFFFFFFFF).ok()?; syscall::close(fd as usize).ok()?; let domain = e.remove(); let mut domain_data = Domain::Resolved { data }; @@ -221,7 +221,7 @@ impl Domains { } } - fn file_from_domain(&mut self, domain: &str, fd: usize, cur_time: &TimeSpec) -> DnsFile { + fn file_from_domain(&mut self, domain: &str, fd: usize, cur_time: &TimeSpec, queue_fd: RawFd) -> DnsFile { if let Some(domain_data) = self.domains.get_mut(domain) { match *domain_data { Domain::Resolved { ref data } => DnsFile::Resolved { @@ -239,7 +239,7 @@ impl Domains { } } } else { - if let Some(socket_fd) = self.request_domain(domain) { + if let Some(socket_fd) = self.request_domain(domain, queue_fd) { let mut waiting_fds = BTreeSet::new(); let domain = domain.to_owned().into(); waiting_fds.insert(fd); @@ -276,6 +276,7 @@ impl Domains { pub struct Dnsd { dns_file: File, time_file: File, + queue_fd: RawFd, files: BTreeMap, domains: Domains, wait_map: BTreeMap, @@ -287,10 +288,11 @@ impl Dnsd { const REQUEST_TIMEOUT_S: i64 = 30; const TIME_EVENT_TIMEOUT_S: i64 = 5; - pub fn new(dns_file: File, time_file: File) -> Dnsd { + pub fn new(dns_file: File, time_file: File, queue_fd: RawFd) -> Dnsd { Dnsd { dns_file, time_file, + queue_fd, files: BTreeMap::new(), domains: Domains::new(), wait_map: BTreeMap::new(), @@ -307,7 +309,7 @@ impl Dnsd { )); } - let fds_to_wakeup = self.domains.on_time_event(&time); + let fds_to_wakeup = self.domains.on_time_event(&time, self.queue_fd); if !fds_to_wakeup.is_empty() { for fd in &fds_to_wakeup { if let Some(file) = self.files.get_mut(fd) { @@ -348,7 +350,7 @@ impl Dnsd { syscall::clock_gettime(syscall::CLOCK_MONOTONIC, &mut cur_time) .map_err(|e| Error::from_syscall_error(e, "Can't get time"))?; - match self.domains.on_fd_event(fd, &cur_time) { + match self.domains.on_fd_event(fd, &cur_time, self.queue_fd) { Some(DnsParsingResult::FailFiles(fds_to_fail)) => { for fd in &fds_to_fail { if let Some(file) = self.files.get_mut(fd) { @@ -417,7 +419,7 @@ impl SchemeMut for Dnsd { self.next_fd += 1; let mut cur_time = TimeSpec::default(); syscall::clock_gettime(syscall::CLOCK_MONOTONIC, &mut cur_time)?; - let dns_file = self.domains.file_from_domain(&domain, fd, &cur_time); + let dns_file = self.domains.file_from_domain(&domain, fd, &cur_time, self.queue_fd); self.files.insert(fd, dns_file); trace!("Open {} {}", &domain, fd); Ok(fd) @@ -451,7 +453,7 @@ impl SchemeMut for Dnsd { syscall::clock_gettime(syscall::CLOCK_MONOTONIC, &mut cur_time)?; if let DnsFile::Waiting { ref domain } = *file { - *file = self.domains.file_from_domain(domain, fd, &cur_time); + *file = self.domains.file_from_domain(domain, fd, &cur_time, self.queue_fd); } match *file { diff --git a/src/smolnetd/main.rs b/src/smolnetd/main.rs index 62233cf90d..39683c3959 100644 --- a/src/smolnetd/main.rs +++ b/src/smolnetd/main.rs @@ -139,7 +139,10 @@ fn run() -> Result<()> { }) .map_err(|e| Error::from_io_error(e, "failed to listen to netcfg events"))?; - event_queue.trigger_all(0)?; + event_queue.trigger_all(event::Event { + fd: 0, + flags: 0 + })?; event_queue.run() } From a2a534f137ab34d04852ded81db1dbd4f33e91a4 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sun, 20 May 2018 15:20:05 -0600 Subject: [PATCH 076/155] Update event crate --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index da8b36e32f..e071ed130b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -218,7 +218,7 @@ dependencies = [ [[package]] name = "netutils" version = "0.1.0" -source = "git+https://github.com/redox-os/netutils.git#7eda176e6b4e2edbcc0616247598ec5e87bfe8e8" +source = "git+https://github.com/redox-os/netutils.git#f1861a0caa73c5351a3594cc39a677af709b8cbe" dependencies = [ "arg_parser 0.1.0 (git+https://github.com/redox-os/arg-parser.git)", "extra 0.1.0 (git+https://github.com/redox-os/libextra.git)", @@ -309,7 +309,7 @@ dependencies = [ [[package]] name = "redox_event" version = "0.1.0" -source = "git+https://github.com/redox-os/event.git#f2448cdafefa5a8deb304d7ea09faf3feb5ff328" +source = "git+https://github.com/redox-os/event.git#e9bf8ee4622cb82af2a10032ed711174b2188afd" dependencies = [ "redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", ] From 3a92b2c466062751dd9bc8a08ac916f9728e0b6d Mon Sep 17 00:00:00 2001 From: Romeo Disca Date: Mon, 21 May 2018 21:12:24 +0200 Subject: [PATCH 077/155] add udp support (#26) * icmp.rs add udp branches to read and write * add write_buf implementation to icmp udp port unreachable * add udp port support --- src/dnsd/scheme.rs | 2 +- src/smolnetd/scheme/icmp.rs | 51 ++++++++++++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/src/dnsd/scheme.rs b/src/dnsd/scheme.rs index 1bcf69e1f6..b8fe1edf10 100644 --- a/src/dnsd/scheme.rs +++ b/src/dnsd/scheme.rs @@ -165,7 +165,7 @@ impl Domains { let domain = e.remove(); self.requested_timeouts .retain(|&(_, ref d)| d.as_ref() != domain.as_ref()); - if let Entry::Occupied(mut e) = self.domains.entry(domain) { + if let Entry::Occupied(e) = self.domains.entry(domain) { let domain_data = e.remove(); return if let Domain::Requested { waiting_fds, .. } = domain_data { Some(DnsParsingResult::FailFiles(waiting_fds)) diff --git a/src/smolnetd/scheme/icmp.rs b/src/smolnetd/scheme/icmp.rs index cacb9f6605..0e33c21c8c 100644 --- a/src/smolnetd/scheme/icmp.rs +++ b/src/smolnetd/scheme/icmp.rs @@ -1,5 +1,5 @@ use smoltcp::socket::{IcmpEndpoint, IcmpPacketBuffer, IcmpSocket, IcmpSocketBuffer, SocketHandle}; -use smoltcp::wire::{Icmpv4Packet, Icmpv4Repr, IpAddress}; +use smoltcp::wire::{Icmpv4Packet, Icmpv4Repr, IpAddress, IpEndpoint}; use std::mem; use std::str; use syscall::{Error as SyscallError, Result as SyscallResult}; @@ -15,6 +15,7 @@ pub type IcmpScheme = SocketScheme>; enum IcmpSocketType { Echo, + Udp, } pub struct IcmpData { @@ -111,6 +112,38 @@ impl<'a, 'b> SchemeSocket for IcmpSocket<'a, 'b> { }; Ok((handle, socket_data)) } + "udp" => { + let addr = parts + .next() + .ok_or_else(|| syscall::Error::new(syscall::EINVAL))?; + let ip = + IpAddress::from_str(addr).map_err(|_| syscall::Error::new(syscall::EINVAL))?; + + let mut rx_packets = Vec::with_capacity(Smolnetd::SOCKET_BUFFER_SIZE); + let mut tx_packets = Vec::with_capacity(Smolnetd::SOCKET_BUFFER_SIZE); + for _ in 0..Smolnetd::SOCKET_BUFFER_SIZE { + rx_packets.push(IcmpPacketBuffer::new(vec![0; NetworkDevice::MTU])); + } + + let socket = IcmpSocket::new( + IcmpSocketBuffer::new(rx_packets), + IcmpSocketBuffer::new(tx_packets), + ); + let handle = socket_set.add(socket); + let mut icmp_socket = socket_set.get::(handle); + let ident = ident_set + .get_port() + .ok_or_else(|| SyscallError::new(syscall::EINVAL))?; + icmp_socket + .bind(IcmpEndpoint::Udp(IpEndpoint::from(ident))) + .map_err(|_| syscall::Error::new(syscall::EINVAL))?; + let socket_data = IcmpData { + socket_type: IcmpSocketType::Udp, + ident, + ip, + }; + Ok((handle, socket_data)) + } _ => Err(syscall::Error::new(syscall::EINVAL)), } } @@ -152,6 +185,9 @@ impl<'a, 'b> SchemeSocket for IcmpSocket<'a, 'b> { icmp_repr.emit(&mut icmp_packet, &Default::default()); Ok(buf.len()) } + IcmpSocketType::Udp => { + Err(SyscallError::new(syscall::EINVAL)) + } } } else if file.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { Ok(0) @@ -214,6 +250,18 @@ impl<'a, 'b> SchemeSocket for IcmpSocket<'a, 'b> { i += 1; } + Ok(i) + } + IcmpSocketType::Udp => { + let path = format!("icmp:udp/{}", socket_file.data.ip); + let path = path.as_bytes(); + + let mut i = 0; + while i < buf.len() && i < path.len() { + buf[i] = path[i]; + i += 1; + } + Ok(i) } } @@ -222,3 +270,4 @@ impl<'a, 'b> SchemeSocket for IcmpSocket<'a, 'b> { } } } + From 6ffe32798968bcdef2b0da866e2f76aab32d829c Mon Sep 17 00:00:00 2001 From: jD91mZM2 Date: Wed, 30 May 2018 17:25:57 +0200 Subject: [PATCH 078/155] Switch to an edge-triggered event system (#28) --- src/smolnetd/scheme/socket.rs | 30 ++++++++++++++++++++++++++---- src/smolnetd/scheme/tcp.rs | 10 +++++++--- src/smolnetd/scheme/udp.rs | 4 ++-- 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/src/smolnetd/scheme/socket.rs b/src/smolnetd/scheme/socket.rs index d6723964ab..0f20037095 100644 --- a/src/smolnetd/scheme/socket.rs +++ b/src/smolnetd/scheme/socket.rs @@ -28,6 +28,8 @@ pub struct SocketFile { events: usize, socket_handle: SocketHandle, + read_notified: bool, + write_notified: bool, read_timeout: Option, write_timeout: Option, } @@ -37,6 +39,8 @@ impl SocketFile { SocketFile { flags: self.flags, events: self.events, + read_notified: false, // we still want to notify about this new socket + write_notified: false, read_timeout: self.read_timeout, write_timeout: self.write_timeout, socket_handle: self.socket_handle, @@ -48,6 +52,8 @@ impl SocketFile { SocketFile { flags: 0, events: 0, + read_notified: false, + write_notified: false, read_timeout: None, write_timeout: None, socket_handle, @@ -198,10 +204,12 @@ where pub fn notify_sockets(&mut self) -> Result<()> { // Notify non-blocking sockets - for (&fd, file) in &self.files { - if let SchemeFile::Socket(SocketFile { + for (&fd, ref mut file) in &mut self.files { + if let &mut SchemeFile::Socket(SocketFile { socket_handle, events, + ref mut read_notified, + ref mut write_notified, .. }) = *file { @@ -209,11 +217,21 @@ where let socket = socket_set.get::(socket_handle); if events & syscall::EVENT_READ == syscall::EVENT_READ && socket.can_recv() { - post_fevent(&mut self.scheme_file, fd, syscall::EVENT_READ, 1)?; + if !*read_notified { + post_fevent(&mut self.scheme_file, fd, syscall::EVENT_READ, 1)?; + *read_notified = true; + } + } else { + *read_notified = false; } if events & syscall::EVENT_WRITE == syscall::EVENT_WRITE && socket.can_send() { - post_fevent(&mut self.scheme_file, fd, syscall::EVENT_WRITE, 1)?; + if !*write_notified { + post_fevent(&mut self.scheme_file, fd, syscall::EVENT_WRITE, 1)?; + *write_notified = true; + } + } else { + *write_notified = false; } } } @@ -488,6 +506,8 @@ where flags, events: 0, socket_handle, + read_notified: false, + write_notified: false, write_timeout: None, read_timeout: None, data, @@ -663,6 +683,8 @@ where SchemeFile::Setting(_) => Err(SyscallError::new(syscall::EBADF)), SchemeFile::Socket(ref mut file) => { file.events = events; + file.read_notified = false; // resend missed events + file.write_notified = false; Ok(fd) } } diff --git a/src/smolnetd/scheme/tcp.rs b/src/smolnetd/scheme/tcp.rs index a7cbf99c35..72dfca25fd 100644 --- a/src/smolnetd/scheme/tcp.rs +++ b/src/smolnetd/scheme/tcp.rs @@ -120,7 +120,7 @@ impl<'a> SchemeSocket for TcpSocket<'a> { self.send_slice(buf).expect("Can't send slice"); Ok(buf.len()) } else if file.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { - Ok(0) + Err(SyscallError::new(syscall::EAGAIN)) } else { Err(SyscallError::new(syscall::EWOULDBLOCK)) } @@ -137,7 +137,7 @@ impl<'a> SchemeSocket for TcpSocket<'a> { let length = self.recv_slice(buf).expect("Can't receive slice"); Ok(length) } else if file.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { - Ok(0) + Err(SyscallError::new(syscall::EAGAIN)) } else { Err(SyscallError::new(syscall::EWOULDBLOCK)) } @@ -159,7 +159,11 @@ impl<'a> SchemeSocket for TcpSocket<'a> { let file = match path { "listen" => if let SchemeFile::Socket(ref tcp_handle) = *file { if !is_active { - return Err(SyscallError::new(syscall::EWOULDBLOCK)); + if tcp_handle.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { + return Err(SyscallError::new(syscall::EAGAIN)); + } else { + return Err(SyscallError::new(syscall::EWOULDBLOCK)); + } } trace!("TCP creating new listening socket"); let new_handle = SchemeFile::Socket(tcp_handle.clone_with_data(())); diff --git a/src/smolnetd/scheme/udp.rs b/src/smolnetd/scheme/udp.rs index fcf4d03936..a59089bd0d 100644 --- a/src/smolnetd/scheme/udp.rs +++ b/src/smolnetd/scheme/udp.rs @@ -117,7 +117,7 @@ impl<'a, 'b> SchemeSocket for UdpSocket<'a, 'b> { self.send_slice(buf, file.data).expect("Can't send slice"); Ok(buf.len()) } else if file.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { - Ok(0) + Err(SyscallError::new(syscall::EAGAIN)) } else { Err(SyscallError::new(syscall::EWOULDBLOCK)) } @@ -132,7 +132,7 @@ impl<'a, 'b> SchemeSocket for UdpSocket<'a, 'b> { let (length, _) = self.recv_slice(buf).expect("Can't receive slice"); Ok(length) } else if file.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { - Ok(0) + Err(SyscallError::new(syscall::EAGAIN)) } else { Err(SyscallError::new(syscall::EWOULDBLOCK)) } From 7fe9c67a533cfeda8edeb3163cf043f4b668947b Mon Sep 17 00:00:00 2001 From: jD91mZM2 Date: Wed, 30 May 2018 18:55:05 +0200 Subject: [PATCH 079/155] Use new SchemeBlock trait (#29) * Use new SchemeBlock trait * Use EAGAIN over EWOULDBLOCK --- Cargo.lock | 58 +++++++++++++++---------------- src/smolnetd/scheme/icmp.rs | 16 ++++----- src/smolnetd/scheme/ip.rs | 16 ++++----- src/smolnetd/scheme/socket.rs | 64 +++++++++++++++++------------------ src/smolnetd/scheme/tcp.rs | 14 ++++---- src/smolnetd/scheme/udp.rs | 12 +++---- 6 files changed, 89 insertions(+), 91 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e071ed130b..4a9d348565 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -57,7 +57,7 @@ dependencies = [ "arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", "cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", "scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -77,7 +77,7 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "byteorder 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "quick-error 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -168,12 +168,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "lazy_static" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libc" -version = "0.2.40" +version = "0.2.41" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -218,17 +218,17 @@ dependencies = [ [[package]] name = "netutils" version = "0.1.0" -source = "git+https://github.com/redox-os/netutils.git#f1861a0caa73c5351a3594cc39a677af709b8cbe" +source = "git+https://github.com/redox-os/netutils.git#f1187fae0a1a02f532e72e1126dcb17bde64bd00" dependencies = [ "arg_parser 0.1.0 (git+https://github.com/redox-os/arg-parser.git)", "extra 0.1.0 (git+https://github.com/redox-os/libextra.git)", "hyper 0.10.13 (registry+https://github.com/rust-lang/crates.io-index)", "hyper-rustls 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)", "ntpclient 0.0.1 (git+https://github.com/willem66745/ntpclient-rust)", "pbr 1.0.1 (git+https://github.com/a8m/pb)", "redox_event 0.1.0 (git+https://github.com/redox-os/event.git)", - "redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -251,7 +251,7 @@ name = "num_cpus" version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -260,7 +260,7 @@ version = "1.0.1" source = "git+https://github.com/a8m/pb#e1df7361a08e2c7e210a3e483e3086bfe62dfe71" dependencies = [ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)", "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -273,7 +273,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "quick-error" -version = "1.2.1" +version = "1.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -282,7 +282,7 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -300,8 +300,8 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -311,7 +311,7 @@ name = "redox_event" version = "0.1.0" source = "git+https://github.com/redox-os/event.git#e9bf8ee4622cb82af2a10032ed711174b2188afd" dependencies = [ - "redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -323,18 +323,18 @@ dependencies = [ "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "netutils 0.1.0 (git+https://github.com/redox-os/netutils.git)", "redox_event 0.1.0 (git+https://github.com/redox-os/event.git)", - "redox_syscall 0.1.37 (git+https://github.com/redox-os/syscall.git)", + "redox_syscall 0.1.40 (git+https://github.com/redox-os/syscall.git)", "smoltcp 0.4.0 (git+https://github.com/m-labs/smoltcp.git?rev=c418b60b5db93753999ae51d33ec4dc1d1631c69)", ] [[package]] name = "redox_syscall" -version = "0.1.37" -source = "git+https://github.com/redox-os/syscall.git#7dc00e7ea4162f8886412d936f14ea5b7d834d41" +version = "0.1.40" +source = "git+https://github.com/redox-os/syscall.git#0ab552da9a9587b360b5d9991ed9921300e5667b" [[package]] name = "redox_syscall" -version = "0.1.37" +version = "0.1.40" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -342,7 +342,7 @@ name = "redox_termios" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -352,7 +352,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -394,8 +394,8 @@ name = "termion" version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -404,8 +404,8 @@ name = "time" version = "0.1.40" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -531,8 +531,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a" "checksum lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "76f033c7ad61445c5b347c7382dd1237847eb1bce590fe50365dcb33d546be73" -"checksum lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c8f31047daa365f19be14b47c29df4f7c3b581832407daabe6ae77397619237d" -"checksum libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)" = "6fd41f331ac7c5b8ac259b8bf82c75c0fb2e469bbf37d2becbba9a6a2221965b" +"checksum lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e6412c5e2ad9584b0b8e979393122026cdd6d2a80b933f890dcd694ddbe73739" +"checksum libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)" = "ac8ebf8343a981e2fa97042b14768f02ed3e1d602eac06cae6166df3c8ced206" "checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" "checksum log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "89f010e843f2b1a31dbd316b3b8d443758bc634bed37aabade59c686d644e0a2" "checksum managed 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "43e2737ecabe4ae36a68061398bf27d2bfd0763f4c3c837a398478459494c4b7" @@ -545,13 +545,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c51a3322e4bca9d212ad9a158a02abc6934d005490c054a2778df73a70aa0a30" "checksum pbr 1.0.1 (git+https://github.com/a8m/pb)" = "" "checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" -"checksum quick-error 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "eda5fe9b71976e62bc81b781206aaa076401769b2143379d3eb2118388babac4" +"checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0" "checksum rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "eba5f8cb59cc50ed56be8880a5c7b496bfd9bd26394e176bc67884094145c2c5" "checksum rayon 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a77c51c07654ddd93f6cb543c7a849863b03abc7e82591afda6dc8ad4ac3ac4a" "checksum rayon-core 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9d24ad214285a7729b174ed6d3bcfcb80177807f959d95fafd5bfc5c4f201ac8" "checksum redox_event 0.1.0 (git+https://github.com/redox-os/event.git)" = "" -"checksum redox_syscall 0.1.37 (git+https://github.com/redox-os/syscall.git)" = "" -"checksum redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "0d92eecebad22b767915e4d529f89f28ee96dbbf5a4810d2b844373f136417fd" +"checksum redox_syscall 0.1.40 (git+https://github.com/redox-os/syscall.git)" = "" +"checksum redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "c214e91d3ecf43e9a4e41e578973adeb14b474f2bee858742d127af75a0112b1" "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" "checksum ring 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1f2a6dc7fc06a05e6de183c5b97058582e9da2de0c136eafe49609769c507724" "checksum rustls 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "17727f4b991294da2c84d75a43c003151ff58072212768800f66c56ee46dca43" diff --git a/src/smolnetd/scheme/icmp.rs b/src/smolnetd/scheme/icmp.rs index 0e33c21c8c..cbd21e0d3e 100644 --- a/src/smolnetd/scheme/icmp.rs +++ b/src/smolnetd/scheme/icmp.rs @@ -163,7 +163,7 @@ impl<'a, 'b> SchemeSocket for IcmpSocket<'a, 'b> { &mut self, file: &mut SocketFile, buf: &[u8], - ) -> SyscallResult { + ) -> SyscallResult> { if self.can_send() { match file.data.socket_type { IcmpSocketType::Echo => { @@ -183,16 +183,16 @@ impl<'a, 'b> SchemeSocket for IcmpSocket<'a, 'b> { let mut icmp_packet = Icmpv4Packet::new(icmp_payload); //TODO: replace Default with actual caps icmp_repr.emit(&mut icmp_packet, &Default::default()); - Ok(buf.len()) + Ok(Some(buf.len())) } IcmpSocketType::Udp => { Err(SyscallError::new(syscall::EINVAL)) } } } else if file.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { - Ok(0) + Err(SyscallError::new(syscall::EAGAIN)) } else { - Err(SyscallError::new(syscall::EWOULDBLOCK)) + Ok(None) // internally scheduled to re-read } } @@ -200,7 +200,7 @@ impl<'a, 'b> SchemeSocket for IcmpSocket<'a, 'b> { &mut self, file: &mut SocketFile, buf: &mut [u8], - ) -> SyscallResult { + ) -> SyscallResult> { while self.can_recv() { let (payload, _) = self.recv().expect("Can't recv icmp packet"); let icmp_packet = Icmpv4Packet::new(&payload); @@ -217,14 +217,14 @@ impl<'a, 'b> SchemeSocket for IcmpSocket<'a, 'b> { buf[mem::size_of::() + i] = data[i]; } - return Ok(mem::size_of::() + data.len()); + return Ok(Some(mem::size_of::() + data.len())); } } if file.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { - Ok(0) + Err(SyscallError::new(syscall::EAGAIN)) } else { - Err(SyscallError::new(syscall::EWOULDBLOCK)) + Ok(None) // internally scheduled to re-read } } diff --git a/src/smolnetd/scheme/ip.rs b/src/smolnetd/scheme/ip.rs index d862125dc7..0b889f8250 100644 --- a/src/smolnetd/scheme/ip.rs +++ b/src/smolnetd/scheme/ip.rs @@ -88,14 +88,14 @@ impl<'a, 'b> SchemeSocket for RawSocket<'a, 'b> { &mut self, file: &mut SocketFile, buf: &[u8], - ) -> SyscallResult { + ) -> SyscallResult> { if self.can_send() { self.send_slice(buf).expect("Can't send slice"); - Ok(buf.len()) + Ok(Some(buf.len())) } else if file.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { - Ok(0) + Err(SyscallError::new(syscall::EAGAIN)) } else { - Err(SyscallError::new(syscall::EWOULDBLOCK)) + Ok(None) // internally scheduled to re-read } } @@ -103,14 +103,14 @@ impl<'a, 'b> SchemeSocket for RawSocket<'a, 'b> { &mut self, file: &mut SocketFile, buf: &mut [u8], - ) -> SyscallResult { + ) -> SyscallResult> { if self.can_recv() { let length = self.recv_slice(buf).expect("Can't receive slice"); - Ok(length) + Ok(Some(length)) } else if file.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { - Ok(0) + Err(SyscallError::new(syscall::EAGAIN)) } else { - Err(SyscallError::new(syscall::EWOULDBLOCK)) + Ok(None) // internally scheduled to re-read } } diff --git a/src/smolnetd/scheme/socket.rs b/src/smolnetd/scheme/socket.rs index 0f20037095..88ef59c961 100644 --- a/src/smolnetd/scheme/socket.rs +++ b/src/smolnetd/scheme/socket.rs @@ -10,7 +10,7 @@ use std::ops::DerefMut; use std::rc::Rc; use std::str; use syscall::data::TimeSpec; -use syscall::{Error as SyscallError, Packet as SyscallPacket, Result as SyscallResult, SchemeMut}; +use syscall::{Error as SyscallError, Packet as SyscallPacket, Result as SyscallResult, SchemeBlockMut}; use syscall; use redox_netstack::error::{Error, Result}; @@ -139,9 +139,9 @@ where fn close_file(&self, &SchemeFile, &mut Self::SchemeDataT) -> SyscallResult<()>; - fn write_buf(&mut self, &mut SocketFile, buf: &[u8]) -> SyscallResult; + fn write_buf(&mut self, &mut SocketFile, buf: &[u8]) -> SyscallResult>; - fn read_buf(&mut self, &mut SocketFile, buf: &mut [u8]) -> SyscallResult; + fn read_buf(&mut self, &mut SocketFile, buf: &mut [u8]) -> SyscallResult>; fn fpath(&self, &SchemeFile, &mut [u8]) -> SyscallResult; @@ -190,12 +190,10 @@ where if self.scheme_file.read(&mut packet)? == 0 { break; } - let a = packet.a; - self.handle(&mut packet); - if packet.a != (-syscall::EWOULDBLOCK) as usize { + if let Some(a) = self.handle(&mut packet) { + packet.a = a; self.scheme_file.write_all(&packet)?; } else { - packet.a = a; self.handle_block(packet)?; } } @@ -271,8 +269,10 @@ where for wait_handle in input_queue.drain(..) { let mut packet = wait_handle.packet; - self.handle(&mut packet); - if packet.a == (-syscall::EWOULDBLOCK) as usize { + if let Some(a) = self.handle(&mut packet) { + packet.a = a; + self.scheme_file.write_all(&packet)?; + } else { match wait_handle.until { Some(until) if (until.tv_sec < cur_time.tv_sec @@ -286,8 +286,6 @@ where to_retain.push(wait_handle); } } - } else { - self.scheme_file.write_all(&packet)?; } } @@ -474,11 +472,11 @@ where } } -impl syscall::SchemeMut for SocketScheme +impl syscall::SchemeBlockMut for SocketScheme where SocketT: SchemeSocket + AnySocket<'static, 'static>, { - fn open(&mut self, url: &[u8], flags: usize, uid: u32, _gid: u32) -> SyscallResult { + fn open(&mut self, url: &[u8], flags: usize, uid: u32, _gid: u32) -> SyscallResult> { let path = str::from_utf8(url).or_else(|_| Err(SyscallError::new(syscall::EINVAL)))?; if path.is_empty() { @@ -493,7 +491,7 @@ where self.nulls.insert(id, null); - Ok(id) + Ok(Some(id)) } else { let (socket_handle, data) = SocketT::new_socket( &mut self.socket_set.borrow_mut(), @@ -518,13 +516,13 @@ where self.files.insert(id, file); - Ok(id) + Ok(Some(id)) } } - fn close(&mut self, fd: usize) -> SyscallResult { + fn close(&mut self, fd: usize) -> SyscallResult> { if let Some(_null) = self.nulls.remove(&fd) { - return Ok(0); + return Ok(Some(0)); } let socket_handle = { @@ -557,10 +555,10 @@ where socket_set.release(socket_handle); //TODO: removing sockets in release should make prune unnecessary socket_set.prune(); - Ok(0) + Ok(Some(0)) } - fn write(&mut self, fd: usize, buf: &[u8]) -> SyscallResult { + fn write(&mut self, fd: usize, buf: &[u8]) -> SyscallResult> { let (fd, setting) = { let file = self.files .get_mut(&fd) @@ -577,10 +575,10 @@ where } } }; - self.update_setting(fd, setting, buf) + self.update_setting(fd, setting, buf).map(Some) } - fn read(&mut self, fd: usize, buf: &mut [u8]) -> SyscallResult { + fn read(&mut self, fd: usize, buf: &mut [u8]) -> SyscallResult> { let (fd, setting) = { let file = self.files .get_mut(&fd) @@ -596,10 +594,10 @@ where } } }; - self.get_setting(fd, setting, buf) + self.get_setting(fd, setting, buf).map(Some) } - fn dup(&mut self, fd: usize, buf: &[u8]) -> SyscallResult { + fn dup(&mut self, fd: usize, buf: &[u8]) -> SyscallResult> { if let Some((flags, uid, gid)) = self.nulls .get(&fd) .map(|null| (null.flags, null.uid, null.gid)) @@ -672,10 +670,10 @@ where self.files.insert(id, new_file); self.next_fd += 1; - Ok(id) + Ok(Some(id)) } - fn fevent(&mut self, fd: usize, events: usize) -> SyscallResult { + fn fevent(&mut self, fd: usize, events: usize) -> SyscallResult> { let file = self.files .get_mut(&fd) .ok_or_else(|| SyscallError::new(syscall::EBADF))?; @@ -685,23 +683,23 @@ where file.events = events; file.read_notified = false; // resend missed events file.write_notified = false; - Ok(fd) + Ok(Some(fd)) } } } - fn fsync(&mut self, fd: usize) -> SyscallResult { + fn fsync(&mut self, fd: usize) -> SyscallResult> { { let _file = self.files .get_mut(&fd) .ok_or_else(|| SyscallError::new(syscall::EBADF))?; } - Ok(0) + Ok(Some(0)) // TODO Implement fsyncing // self.0.network_fsync() } - fn fpath(&mut self, fd: usize, buf: &mut [u8]) -> SyscallResult { + fn fpath(&mut self, fd: usize, buf: &mut [u8]) -> SyscallResult> { let file = self.files .get_mut(&fd) .ok_or_else(|| SyscallError::new(syscall::EBADF))?; @@ -709,20 +707,20 @@ where let mut socket_set = self.socket_set.borrow_mut(); let socket = socket_set.get::(file.socket_handle()); - socket.fpath(file, buf) + socket.fpath(file, buf).map(Some) } - fn fcntl(&mut self, fd: usize, cmd: usize, arg: usize) -> SyscallResult { + fn fcntl(&mut self, fd: usize, cmd: usize, arg: usize) -> SyscallResult> { let file = self.files .get_mut(&fd) .ok_or_else(|| SyscallError::new(syscall::EBADF))?; if let SchemeFile::Socket(ref mut socket_file) = *file { match cmd { - syscall::F_GETFL => Ok(socket_file.flags), + syscall::F_GETFL => Ok(Some(socket_file.flags)), syscall::F_SETFL => { socket_file.flags = arg & !syscall::O_ACCMODE; - Ok(0) + Ok(Some(0)) } _ => Err(SyscallError::new(syscall::EINVAL)), } diff --git a/src/smolnetd/scheme/tcp.rs b/src/smolnetd/scheme/tcp.rs index 72dfca25fd..a67aa09dd5 100644 --- a/src/smolnetd/scheme/tcp.rs +++ b/src/smolnetd/scheme/tcp.rs @@ -113,16 +113,16 @@ impl<'a> SchemeSocket for TcpSocket<'a> { &mut self, file: &mut SocketFile, buf: &[u8], - ) -> SyscallResult { + ) -> SyscallResult> { if !self.is_active() { Err(SyscallError::new(syscall::ENOTCONN)) } else if self.can_send() { self.send_slice(buf).expect("Can't send slice"); - Ok(buf.len()) + Ok(Some(buf.len())) } else if file.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { Err(SyscallError::new(syscall::EAGAIN)) } else { - Err(SyscallError::new(syscall::EWOULDBLOCK)) + Ok(None) // internally scheduled to re-read } } @@ -130,16 +130,16 @@ impl<'a> SchemeSocket for TcpSocket<'a> { &mut self, file: &mut SocketFile, buf: &mut [u8], - ) -> SyscallResult { + ) -> SyscallResult> { if !self.is_active() { Err(SyscallError::new(syscall::ENOTCONN)) } else if self.can_recv() { let length = self.recv_slice(buf).expect("Can't receive slice"); - Ok(length) + Ok(Some(length)) } else if file.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { Err(SyscallError::new(syscall::EAGAIN)) } else { - Err(SyscallError::new(syscall::EWOULDBLOCK)) + Ok(None) // internally scheduled to re-read } } @@ -162,7 +162,7 @@ impl<'a> SchemeSocket for TcpSocket<'a> { if tcp_handle.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { return Err(SyscallError::new(syscall::EAGAIN)); } else { - return Err(SyscallError::new(syscall::EWOULDBLOCK)); + return Err(SyscallError::new(syscall::EAGAIN)); } } trace!("TCP creating new listening socket"); diff --git a/src/smolnetd/scheme/udp.rs b/src/smolnetd/scheme/udp.rs index a59089bd0d..ae9853cb3c 100644 --- a/src/smolnetd/scheme/udp.rs +++ b/src/smolnetd/scheme/udp.rs @@ -109,17 +109,17 @@ impl<'a, 'b> SchemeSocket for UdpSocket<'a, 'b> { &mut self, file: &mut SocketFile, buf: &[u8], - ) -> SyscallResult { + ) -> SyscallResult> { if !file.data.is_specified() { return Err(SyscallError::new(syscall::EADDRNOTAVAIL)); } if self.can_send() { self.send_slice(buf, file.data).expect("Can't send slice"); - Ok(buf.len()) + Ok(Some(buf.len())) } else if file.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { Err(SyscallError::new(syscall::EAGAIN)) } else { - Err(SyscallError::new(syscall::EWOULDBLOCK)) + Ok(None) // internally scheduled to re-read } } @@ -127,14 +127,14 @@ impl<'a, 'b> SchemeSocket for UdpSocket<'a, 'b> { &mut self, file: &mut SocketFile, buf: &mut [u8], - ) -> SyscallResult { + ) -> SyscallResult> { if self.can_recv() { let (length, _) = self.recv_slice(buf).expect("Can't receive slice"); - Ok(length) + Ok(Some(length)) } else if file.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { Err(SyscallError::new(syscall::EAGAIN)) } else { - Err(SyscallError::new(syscall::EWOULDBLOCK)) + Ok(None) // internally scheduled to re-read } } From 40a8cb7dbb459e4b0e951cf281d69a1f5b7bfef0 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Tue, 12 Jun 2018 12:30:44 -0600 Subject: [PATCH 080/155] Update links to gitlab --- Cargo.lock | 32 ++++++++++++++++---------------- Cargo.toml | 6 +++--- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4a9d348565..655b71106f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,7 +1,7 @@ [[package]] name = "arg_parser" version = "0.1.0" -source = "git+https://github.com/redox-os/arg-parser.git#7503531821b0c111f9fac77a5d2536ea221105fe" +source = "git+https://gitlab.redox-os.org/redox-os/arg-parser.git#7503531821b0c111f9fac77a5d2536ea221105fe" [[package]] name = "arrayvec" @@ -83,7 +83,7 @@ dependencies = [ [[package]] name = "extra" version = "0.1.0" -source = "git+https://github.com/redox-os/libextra.git#f38608acd9cc00e1c8bd41a1a96d31becf239913" +source = "git+https://gitlab.redox-os.org/redox-os/libextra.git#f38608acd9cc00e1c8bd41a1a96d31becf239913" [[package]] name = "fuchsia-zircon" @@ -218,16 +218,16 @@ dependencies = [ [[package]] name = "netutils" version = "0.1.0" -source = "git+https://github.com/redox-os/netutils.git#f1187fae0a1a02f532e72e1126dcb17bde64bd00" +source = "git+https://gitlab.redox-os.org/redox-os/netutils.git#f1187fae0a1a02f532e72e1126dcb17bde64bd00" dependencies = [ - "arg_parser 0.1.0 (git+https://github.com/redox-os/arg-parser.git)", - "extra 0.1.0 (git+https://github.com/redox-os/libextra.git)", + "arg_parser 0.1.0 (git+https://gitlab.redox-os.org/redox-os/arg-parser.git)", + "extra 0.1.0 (git+https://gitlab.redox-os.org/redox-os/libextra.git)", "hyper 0.10.13 (registry+https://github.com/rust-lang/crates.io-index)", "hyper-rustls 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)", "ntpclient 0.0.1 (git+https://github.com/willem66745/ntpclient-rust)", "pbr 1.0.1 (git+https://github.com/a8m/pb)", - "redox_event 0.1.0 (git+https://github.com/redox-os/event.git)", + "redox_event 0.1.0 (git+https://gitlab.redox-os.org/redox-os/event.git)", "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -309,7 +309,7 @@ dependencies = [ [[package]] name = "redox_event" version = "0.1.0" -source = "git+https://github.com/redox-os/event.git#e9bf8ee4622cb82af2a10032ed711174b2188afd" +source = "git+https://gitlab.redox-os.org/redox-os/event.git#e9bf8ee4622cb82af2a10032ed711174b2188afd" dependencies = [ "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -321,16 +321,16 @@ dependencies = [ "byteorder 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "dns-parser 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", - "netutils 0.1.0 (git+https://github.com/redox-os/netutils.git)", - "redox_event 0.1.0 (git+https://github.com/redox-os/event.git)", - "redox_syscall 0.1.40 (git+https://github.com/redox-os/syscall.git)", + "netutils 0.1.0 (git+https://gitlab.redox-os.org/redox-os/netutils.git)", + "redox_event 0.1.0 (git+https://gitlab.redox-os.org/redox-os/event.git)", + "redox_syscall 0.1.40 (git+https://gitlab.redox-os.org/redox-os/syscall.git)", "smoltcp 0.4.0 (git+https://github.com/m-labs/smoltcp.git?rev=c418b60b5db93753999ae51d33ec4dc1d1631c69)", ] [[package]] name = "redox_syscall" version = "0.1.40" -source = "git+https://github.com/redox-os/syscall.git#0ab552da9a9587b360b5d9991ed9921300e5667b" +source = "git+https://gitlab.redox-os.org/redox-os/syscall.git#0ab552da9a9587b360b5d9991ed9921300e5667b" [[package]] name = "redox_syscall" @@ -509,7 +509,7 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" [metadata] -"checksum arg_parser 0.1.0 (git+https://github.com/redox-os/arg-parser.git)" = "" +"checksum arg_parser 0.1.0 (git+https://gitlab.redox-os.org/redox-os/arg-parser.git)" = "" "checksum arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)" = "a1e964f9e24d588183fcb43503abda40d288c8657dfc27311516ce2f05675aef" "checksum base64 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "96434f987501f0ed4eb336a411e0631ecd1afa11574fe148587adc4ff96143c9" "checksum bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d0c54bb8f454c567f21197eefcdbf5679d0bd99f2ddbe52e84c77061952e6789" @@ -520,7 +520,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum crossbeam-epoch 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "927121f5407de9956180ff5e936fe3cf4324279280001cd56b669d28ee7e9150" "checksum crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2760899e32a1d58d5abb31129f8fae5de75220bc2176e77ff7c627ae45c918d9" "checksum dns-parser 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f7020f6760aea312d43d23cb83bf6c0c49f162541db8b02bf95209ac51dc253d" -"checksum extra 0.1.0 (git+https://github.com/redox-os/libextra.git)" = "" +"checksum extra 0.1.0 (git+https://gitlab.redox-os.org/redox-os/libextra.git)" = "" "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" "checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" "checksum gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)" = "5e33ec290da0d127825013597dbdfc28bee4964690c7ce1166cbc2a7bd08b1bb" @@ -539,7 +539,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "100aabe6b8ff4e4a7e32c1c13523379802df0772b82466207ac25b013f193376" "checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3" "checksum mime 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ba626b8a6de5da682e1caa06bdb42a335aee5a84db8e5046a3e8ab17ba0a3ae0" -"checksum netutils 0.1.0 (git+https://github.com/redox-os/netutils.git)" = "" +"checksum netutils 0.1.0 (git+https://gitlab.redox-os.org/redox-os/netutils.git)" = "" "checksum nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "9a2228dca57108069a5262f2ed8bd2e82496d2e074a06d1ccc7ce1687b6ae0a2" "checksum ntpclient 0.0.1 (git+https://github.com/willem66745/ntpclient-rust)" = "" "checksum num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c51a3322e4bca9d212ad9a158a02abc6934d005490c054a2778df73a70aa0a30" @@ -549,8 +549,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "eba5f8cb59cc50ed56be8880a5c7b496bfd9bd26394e176bc67884094145c2c5" "checksum rayon 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a77c51c07654ddd93f6cb543c7a849863b03abc7e82591afda6dc8ad4ac3ac4a" "checksum rayon-core 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9d24ad214285a7729b174ed6d3bcfcb80177807f959d95fafd5bfc5c4f201ac8" -"checksum redox_event 0.1.0 (git+https://github.com/redox-os/event.git)" = "" -"checksum redox_syscall 0.1.40 (git+https://github.com/redox-os/syscall.git)" = "" +"checksum redox_event 0.1.0 (git+https://gitlab.redox-os.org/redox-os/event.git)" = "" +"checksum redox_syscall 0.1.40 (git+https://gitlab.redox-os.org/redox-os/syscall.git)" = "" "checksum redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "c214e91d3ecf43e9a4e41e578973adeb14b474f2bee858742d127af75a0112b1" "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" "checksum ring 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1f2a6dc7fc06a05e6de183c5b97058582e9da2de0c136eafe49609769c507724" diff --git a/Cargo.toml b/Cargo.toml index c8083edbe8..10ae41e949 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,9 +15,9 @@ name = "redox_netstack" path = "src/lib/lib.rs" [dependencies] -netutils = { git = "https://github.com/redox-os/netutils.git" } -redox_event = { git = "https://github.com/redox-os/event.git" } -redox_syscall = { git = "https://github.com/redox-os/syscall.git" } +netutils = { git = "https://gitlab.redox-os.org/redox-os/netutils.git" } +redox_event = { git = "https://gitlab.redox-os.org/redox-os/event.git" } +redox_syscall = { git = "https://gitlab.redox-os.org/redox-os/syscall.git" } byteorder = { version = "1.0", default-features = false } dns-parser = "0.7.1" From f9d6f5d87f1f5903d301c6205b9b5637c8ad1512 Mon Sep 17 00:00:00 2001 From: jD91mZM2 Date: Tue, 19 Jun 2018 14:08:32 +0200 Subject: [PATCH 081/155] Update smoltcp --- Cargo.lock | 299 +++++++++++++++++++++++++++--- Cargo.toml | 2 +- src/smolnetd/scheme/icmp.rs | 35 ++-- src/smolnetd/scheme/ip.rs | 18 +- src/smolnetd/scheme/mod.rs | 8 +- src/smolnetd/scheme/netcfg/mod.rs | 27 ++- src/smolnetd/scheme/udp.rs | 18 +- 7 files changed, 334 insertions(+), 73 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 655b71106f..967f67a826 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -35,6 +35,15 @@ name = "byteorder" version = "1.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "bytes" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "byteorder 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "cfg-if" version = "0.1.3" @@ -49,6 +58,15 @@ dependencies = [ "crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "crossbeam-deque" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "crossbeam-epoch 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "crossbeam-epoch" version = "0.3.1" @@ -63,6 +81,19 @@ dependencies = [ "scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "crossbeam-epoch" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "crossbeam-utils" version = "0.2.2" @@ -71,6 +102,14 @@ dependencies = [ "cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "crossbeam-utils" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "dns-parser" version = "0.7.1" @@ -83,7 +122,7 @@ dependencies = [ [[package]] name = "extra" version = "0.1.0" -source = "git+https://gitlab.redox-os.org/redox-os/libextra.git#f38608acd9cc00e1c8bd41a1a96d31becf239913" +source = "git+https://gitlab.redox-os.org/redox-os/libextra.git#0b50f3f2127fa62b1fe74090feffbae357266eac" [[package]] name = "fuchsia-zircon" @@ -99,6 +138,11 @@ name = "fuchsia-zircon-sys" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "futures" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "gcc" version = "0.3.54" @@ -147,6 +191,15 @@ dependencies = [ "unicode-normalization 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "iovec" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "kernel32-sys" version = "0.2.2" @@ -171,9 +224,14 @@ name = "lazy_static" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "lazycell" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "libc" -version = "0.2.41" +version = "0.2.42" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -181,12 +239,12 @@ name = "log" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "log" -version = "0.4.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -194,7 +252,7 @@ dependencies = [ [[package]] name = "managed" -version = "0.5.1" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -215,21 +273,62 @@ dependencies = [ "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "mio" +version = "0.6.14" +source = "git+https://gitlab.redox-os.org/redox-os/mio#1339f362be63592de538a4ea52367e820e846988" +dependencies = [ + "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "lazycell 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "miow 0.3.1 (git+https://gitlab.redox-os.org/redox-os/miow?rev=5b10500)", + "net2 0.2.32 (git+https://gitlab.redox-os.org/redox-os/net2-rs)", + "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", + "slab 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "miow" +version = "0.3.1" +source = "git+https://gitlab.redox-os.org/redox-os/miow?rev=5b10500#5b10500df2c560245d532e77c54a8b8b2d15cfd5" +dependencies = [ + "socket2 0.3.7 (git+https://github.com/redox-os/socket2-rs)", + "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "net2" +version = "0.2.32" +source = "git+https://gitlab.redox-os.org/redox-os/net2-rs#0eae9193ba04270a4ded81c0d3c76d918c3bbcc6" +dependencies = [ + "cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "netutils" version = "0.1.0" -source = "git+https://gitlab.redox-os.org/redox-os/netutils.git#f1187fae0a1a02f532e72e1126dcb17bde64bd00" +source = "git+https://gitlab.redox-os.org/redox-os/netutils.git#c728870d6a1d9d8938117798e6caab22b09c37a6" dependencies = [ "arg_parser 0.1.0 (git+https://gitlab.redox-os.org/redox-os/arg-parser.git)", "extra 0.1.0 (git+https://gitlab.redox-os.org/redox-os/libextra.git)", "hyper 0.10.13 (registry+https://github.com/rust-lang/crates.io-index)", "hyper-rustls 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.14 (git+https://gitlab.redox-os.org/redox-os/mio)", "ntpclient 0.0.1 (git+https://github.com/willem66745/ntpclient-rust)", "pbr 1.0.1 (git+https://github.com/a8m/pb)", "redox_event 0.1.0 (git+https://gitlab.redox-os.org/redox-os/event.git)", "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio 0.1.6 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-reactor 0.1.1 (git+https://gitlab.redox-os.org/redox-os/tokio)", ] [[package]] @@ -251,16 +350,16 @@ name = "num_cpus" version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "pbr" version = "1.0.1" -source = "git+https://github.com/a8m/pb#e1df7361a08e2c7e210a3e483e3086bfe62dfe71" +source = "git+https://github.com/a8m/pb#bff135f7eed7931a1103e593c74160d28fdd2314" dependencies = [ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -282,8 +381,8 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -301,7 +400,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -309,7 +408,7 @@ dependencies = [ [[package]] name = "redox_event" version = "0.1.0" -source = "git+https://gitlab.redox-os.org/redox-os/event.git#e9bf8ee4622cb82af2a10032ed711174b2188afd" +source = "git+https://gitlab.redox-os.org/redox-os/event.git#c31e3d3d5f44d60ff9fec2b1ee58b982e72c0d77" dependencies = [ "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -324,13 +423,13 @@ dependencies = [ "netutils 0.1.0 (git+https://gitlab.redox-os.org/redox-os/netutils.git)", "redox_event 0.1.0 (git+https://gitlab.redox-os.org/redox-os/event.git)", "redox_syscall 0.1.40 (git+https://gitlab.redox-os.org/redox-os/syscall.git)", - "smoltcp 0.4.0 (git+https://github.com/m-labs/smoltcp.git?rev=c418b60b5db93753999ae51d33ec4dc1d1631c69)", + "smoltcp 0.4.0 (git+https://github.com/m-labs/smoltcp.git?rev=d23aee483f2dc78e8070d2ad53e400cd0dcb9ae1)", ] [[package]] name = "redox_syscall" version = "0.1.40" -source = "git+https://gitlab.redox-os.org/redox-os/syscall.git#0ab552da9a9587b360b5d9991ed9921300e5667b" +source = "git+https://gitlab.redox-os.org/redox-os/syscall.git#495b09740a6ffbe01d10097aac4cf333dd392e69" [[package]] name = "redox_syscall" @@ -352,7 +451,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -380,13 +479,30 @@ name = "scopeguard" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "slab" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "smoltcp" version = "0.4.0" -source = "git+https://github.com/m-labs/smoltcp.git?rev=c418b60b5db93753999ae51d33ec4dc1d1631c69#c418b60b5db93753999ae51d33ec4dc1d1631c69" +source = "git+https://github.com/m-labs/smoltcp.git?rev=d23aee483f2dc78e8070d2ad53e400cd0dcb9ae1#d23aee483f2dc78e8070d2ad53e400cd0dcb9ae1" dependencies = [ + "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "managed 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "managed 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "socket2" +version = "0.3.7" +source = "git+https://github.com/redox-os/socket2-rs#3543915f09e41f6e010d4d9e2d5217b27faf5e70" +dependencies = [ + "cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -394,7 +510,7 @@ name = "termion" version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -404,9 +520,115 @@ name = "time" version = "0.1.40" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "tokio" +version = "0.1.6" +source = "git+https://gitlab.redox-os.org/redox-os/tokio#4db6ce75b5059c42cbbad56d7c441da19fe18c1a" +dependencies = [ + "futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.14 (git+https://gitlab.redox-os.org/redox-os/mio)", + "tokio-executor 0.1.2 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-fs 0.1.0 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-io 0.1.6 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-reactor 0.1.1 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-tcp 0.1.0 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-threadpool 0.1.3 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-timer 0.2.3 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-udp 0.1.0 (git+https://gitlab.redox-os.org/redox-os/tokio)", +] + +[[package]] +name = "tokio-executor" +version = "0.1.2" +source = "git+https://gitlab.redox-os.org/redox-os/tokio#4db6ce75b5059c42cbbad56d7c441da19fe18c1a" +dependencies = [ + "futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "tokio-fs" +version = "0.1.0" +source = "git+https://gitlab.redox-os.org/redox-os/tokio#4db6ce75b5059c42cbbad56d7c441da19fe18c1a" +dependencies = [ + "futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-io 0.1.6 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-threadpool 0.1.3 (git+https://gitlab.redox-os.org/redox-os/tokio)", +] + +[[package]] +name = "tokio-io" +version = "0.1.6" +source = "git+https://gitlab.redox-os.org/redox-os/tokio#4db6ce75b5059c42cbbad56d7c441da19fe18c1a" +dependencies = [ + "bytes 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "tokio-reactor" +version = "0.1.1" +source = "git+https://gitlab.redox-os.org/redox-os/tokio#4db6ce75b5059c42cbbad56d7c441da19fe18c1a" +dependencies = [ + "futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.14 (git+https://gitlab.redox-os.org/redox-os/mio)", + "slab 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-executor 0.1.2 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-io 0.1.6 (git+https://gitlab.redox-os.org/redox-os/tokio)", +] + +[[package]] +name = "tokio-tcp" +version = "0.1.0" +source = "git+https://gitlab.redox-os.org/redox-os/tokio#4db6ce75b5059c42cbbad56d7c441da19fe18c1a" +dependencies = [ + "bytes 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", + "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.14 (git+https://gitlab.redox-os.org/redox-os/mio)", + "tokio-io 0.1.6 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-reactor 0.1.1 (git+https://gitlab.redox-os.org/redox-os/tokio)", +] + +[[package]] +name = "tokio-threadpool" +version = "0.1.3" +source = "git+https://gitlab.redox-os.org/redox-os/tokio#4db6ce75b5059c42cbbad56d7c441da19fe18c1a" +dependencies = [ + "crossbeam-deque 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-executor 0.1.2 (git+https://gitlab.redox-os.org/redox-os/tokio)", +] + +[[package]] +name = "tokio-timer" +version = "0.2.3" +source = "git+https://gitlab.redox-os.org/redox-os/tokio#4db6ce75b5059c42cbbad56d7c441da19fe18c1a" +dependencies = [ + "futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-executor 0.1.2 (git+https://gitlab.redox-os.org/redox-os/tokio)", +] + +[[package]] +name = "tokio-udp" +version = "0.1.0" +source = "git+https://gitlab.redox-os.org/redox-os/tokio#4db6ce75b5059c42cbbad56d7c441da19fe18c1a" +dependencies = [ + "bytes 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.14 (git+https://gitlab.redox-os.org/redox-os/mio)", + "tokio-io 0.1.6 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-reactor 0.1.1 (git+https://gitlab.redox-os.org/redox-os/tokio)", ] [[package]] @@ -486,7 +708,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "winapi" -version = "0.3.4" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -515,30 +737,40 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d0c54bb8f454c567f21197eefcdbf5679d0bd99f2ddbe52e84c77061952e6789" "checksum byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855" "checksum byteorder 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "74c0b906e9446b0a2e4f760cdb3fa4b2c48cdc6db8766a845c54b6ff063fd2e9" +"checksum bytes 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7dd32989a66957d3f0cba6588f15d4281a733f4e9ffc43fcd2385f57d3bf99ff" "checksum cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "405216fd8fe65f718daa7102ea808a946b6ce40c742998fbfd3463645552de18" "checksum crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f739f8c5363aca78cfb059edf753d8f0d36908c348f3d8d1503f03d8b75d9cf3" +"checksum crossbeam-deque 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fe8153ef04a7594ded05b427ffad46ddeaf22e63fd48d42b3e1e3bb4db07cae7" "checksum crossbeam-epoch 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "927121f5407de9956180ff5e936fe3cf4324279280001cd56b669d28ee7e9150" +"checksum crossbeam-epoch 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2af0e75710d6181e234c8ecc79f14a97907850a541b13b0be1dd10992f2e4620" "checksum crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2760899e32a1d58d5abb31129f8fae5de75220bc2176e77ff7c627ae45c918d9" +"checksum crossbeam-utils 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d636a8b3bcc1b409d7ffd3facef8f21dcb4009626adbd0c5e6c4305c07253c7b" "checksum dns-parser 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f7020f6760aea312d43d23cb83bf6c0c49f162541db8b02bf95209ac51dc253d" "checksum extra 0.1.0 (git+https://gitlab.redox-os.org/redox-os/libextra.git)" = "" "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" "checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" +"checksum futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)" = "1a70b146671de62ec8c8ed572219ca5d594d9b06c0b364d5e67b722fc559b48c" "checksum gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)" = "5e33ec290da0d127825013597dbdfc28bee4964690c7ce1166cbc2a7bd08b1bb" "checksum httparse 1.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "c2f407128745b78abc95c0ffbe4e5d37427fdc0d45470710cfef8c44522a2e37" "checksum hyper 0.10.13 (registry+https://github.com/rust-lang/crates.io-index)" = "368cb56b2740ebf4230520e2b90ebb0461e69034d85d1945febd9b3971426db2" "checksum hyper-rustls 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "04535774f79684c99528944ebdb89756c945c027e55ce52faa245879d836c8fb" "checksum idna 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "014b298351066f1512874135335d62a789ffe78a9974f94b43ed5621951eaf7d" +"checksum iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dbe6e417e7d0975db6512b90796e8ce223145ac4e33c377e4a42882a0e88bb08" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a" "checksum lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "76f033c7ad61445c5b347c7382dd1237847eb1bce590fe50365dcb33d546be73" "checksum lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e6412c5e2ad9584b0b8e979393122026cdd6d2a80b933f890dcd694ddbe73739" -"checksum libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)" = "ac8ebf8343a981e2fa97042b14768f02ed3e1d602eac06cae6166df3c8ced206" +"checksum lazycell 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a6f08839bc70ef4a3fe1d566d5350f519c5912ea86be0df1740a7d247c7fc0ef" +"checksum libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)" = "b685088df2b950fccadf07a7187c8ef846a959c142338a48f9dc0b94517eb5f1" "checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" -"checksum log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "89f010e843f2b1a31dbd316b3b8d443758bc634bed37aabade59c686d644e0a2" -"checksum managed 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "43e2737ecabe4ae36a68061398bf27d2bfd0763f4c3c837a398478459494c4b7" +"checksum log 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6fddaa003a65722a7fb9e26b0ce95921fe4ba590542ced664d8ce2fa26f9f3ac" +"checksum managed 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ba6713e624266d7600e9feae51b1926c6a6a6bebb18ec5a8e11a5f1d5661baba" "checksum matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "100aabe6b8ff4e4a7e32c1c13523379802df0772b82466207ac25b013f193376" "checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3" "checksum mime 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ba626b8a6de5da682e1caa06bdb42a335aee5a84db8e5046a3e8ab17ba0a3ae0" +"checksum mio 0.6.14 (git+https://gitlab.redox-os.org/redox-os/mio)" = "" +"checksum miow 0.3.1 (git+https://gitlab.redox-os.org/redox-os/miow?rev=5b10500)" = "" +"checksum net2 0.2.32 (git+https://gitlab.redox-os.org/redox-os/net2-rs)" = "" "checksum netutils 0.1.0 (git+https://gitlab.redox-os.org/redox-os/netutils.git)" = "" "checksum nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "9a2228dca57108069a5262f2ed8bd2e82496d2e074a06d1ccc7ce1687b6ae0a2" "checksum ntpclient 0.0.1 (git+https://github.com/willem66745/ntpclient-rust)" = "" @@ -557,9 +789,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum rustls 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "17727f4b991294da2c84d75a43c003151ff58072212768800f66c56ee46dca43" "checksum safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e27a8b19b835f7aea908818e871f5cc3a5a186550c30773be987e155e8163d8f" "checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" -"checksum smoltcp 0.4.0 (git+https://github.com/m-labs/smoltcp.git?rev=c418b60b5db93753999ae51d33ec4dc1d1631c69)" = "" +"checksum slab 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fdeff4cd9ecff59ec7e3744cbca73dfe5ac35c2aedb2cfba8a1c715a18912e9d" +"checksum smoltcp 0.4.0 (git+https://github.com/m-labs/smoltcp.git?rev=d23aee483f2dc78e8070d2ad53e400cd0dcb9ae1)" = "" +"checksum socket2 0.3.7 (git+https://github.com/redox-os/socket2-rs)" = "" "checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" "checksum time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "d825be0eb33fda1a7e68012d51e9c7f451dc1a69391e7fdc197060bb8c56667b" +"checksum tokio 0.1.6 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" +"checksum tokio-executor 0.1.2 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" +"checksum tokio-fs 0.1.0 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" +"checksum tokio-io 0.1.6 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" +"checksum tokio-reactor 0.1.1 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" +"checksum tokio-tcp 0.1.0 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" +"checksum tokio-threadpool 0.1.3 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" +"checksum tokio-timer 0.2.3 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" +"checksum tokio-udp 0.1.0 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" "checksum traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079" "checksum typeable 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1410f6f91f21d1612654e7cc69193b0334f909dcf2c790c4826254fbb86f8887" "checksum unicase 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7f4765f83163b74f957c797ad9253caf97f103fb064d3999aea9568d09fc8a33" @@ -571,7 +814,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum webpki 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e499345fc4c6b7c79a5b8756d4592c4305510a13512e79efafe00dfbd67bbac6" "checksum webpki-roots 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5bfb3f50499f21ad2317f442845e3b5805b007f1e728f59885c99e61b8c181a7" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" -"checksum winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "04e3bd221fcbe8a271359c04f21a76db7d0c6028862d1bb5512d85e1e2eb5bb3" +"checksum winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "773ef9dcc5f24b7d850d0ff101e542ff24c3b090a9768e03ff889fdef41f00fd" "checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml index 10ae41e949..9e8bf0685a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,7 @@ features = ["release_max_level_off"] [dependencies.smoltcp] git = "https://github.com/m-labs/smoltcp.git" -rev = "c418b60b5db93753999ae51d33ec4dc1d1631c69" +rev = "d23aee483f2dc78e8070d2ad53e400cd0dcb9ae1" default-features = false features = ["std", "socket-raw", "proto-ipv4", "socket-udp", "socket-tcp", "socket-icmp"] diff --git a/src/smolnetd/scheme/icmp.rs b/src/smolnetd/scheme/icmp.rs index cbd21e0d3e..b022ca2bb6 100644 --- a/src/smolnetd/scheme/icmp.rs +++ b/src/smolnetd/scheme/icmp.rs @@ -1,4 +1,4 @@ -use smoltcp::socket::{IcmpEndpoint, IcmpPacketBuffer, IcmpSocket, IcmpSocketBuffer, SocketHandle}; +use smoltcp::socket::{IcmpEndpoint, IcmpPacketMetadata, IcmpSocket, IcmpSocketBuffer, SocketHandle}; use smoltcp::wire::{Icmpv4Packet, Icmpv4Repr, IpAddress, IpEndpoint}; use std::mem; use std::str; @@ -86,16 +86,15 @@ impl<'a, 'b> SchemeSocket for IcmpSocket<'a, 'b> { let ip = IpAddress::from_str(addr).map_err(|_| syscall::Error::new(syscall::EINVAL))?; - let mut rx_packets = Vec::with_capacity(Smolnetd::SOCKET_BUFFER_SIZE); - let mut tx_packets = Vec::with_capacity(Smolnetd::SOCKET_BUFFER_SIZE); - for _ in 0..Smolnetd::SOCKET_BUFFER_SIZE { - rx_packets.push(IcmpPacketBuffer::new(vec![0; NetworkDevice::MTU])); - tx_packets.push(IcmpPacketBuffer::new(vec![0; NetworkDevice::MTU])); - } - let socket = IcmpSocket::new( - IcmpSocketBuffer::new(rx_packets), - IcmpSocketBuffer::new(tx_packets), + IcmpSocketBuffer::new( + vec![IcmpPacketMetadata::EMPTY; Smolnetd::SOCKET_BUFFER_SIZE], + vec![0; NetworkDevice::MTU * Smolnetd::SOCKET_BUFFER_SIZE] + ), + IcmpSocketBuffer::new( + vec![IcmpPacketMetadata::EMPTY; Smolnetd::SOCKET_BUFFER_SIZE], + vec![0; NetworkDevice::MTU * Smolnetd::SOCKET_BUFFER_SIZE] + ) ); let handle = socket_set.add(socket); let mut icmp_socket = socket_set.get::(handle); @@ -119,15 +118,15 @@ impl<'a, 'b> SchemeSocket for IcmpSocket<'a, 'b> { let ip = IpAddress::from_str(addr).map_err(|_| syscall::Error::new(syscall::EINVAL))?; - let mut rx_packets = Vec::with_capacity(Smolnetd::SOCKET_BUFFER_SIZE); - let mut tx_packets = Vec::with_capacity(Smolnetd::SOCKET_BUFFER_SIZE); - for _ in 0..Smolnetd::SOCKET_BUFFER_SIZE { - rx_packets.push(IcmpPacketBuffer::new(vec![0; NetworkDevice::MTU])); - } - let socket = IcmpSocket::new( - IcmpSocketBuffer::new(rx_packets), - IcmpSocketBuffer::new(tx_packets), + IcmpSocketBuffer::new( + vec![IcmpPacketMetadata::EMPTY; Smolnetd::SOCKET_BUFFER_SIZE], + vec![0; NetworkDevice::MTU * Smolnetd::SOCKET_BUFFER_SIZE] + ), + IcmpSocketBuffer::new( + vec![IcmpPacketMetadata::EMPTY; Smolnetd::SOCKET_BUFFER_SIZE], + vec![0; NetworkDevice::MTU * Smolnetd::SOCKET_BUFFER_SIZE] + ) ); let handle = socket_set.add(socket); let mut icmp_socket = socket_set.get::(handle); diff --git a/src/smolnetd/scheme/ip.rs b/src/smolnetd/scheme/ip.rs index 0b889f8250..5cea1b9110 100644 --- a/src/smolnetd/scheme/ip.rs +++ b/src/smolnetd/scheme/ip.rs @@ -1,4 +1,4 @@ -use smoltcp::socket::{RawPacketBuffer, RawSocket, RawSocketBuffer, SocketHandle}; +use smoltcp::socket::{RawPacketMetadata, RawSocket, RawSocketBuffer, SocketHandle}; use smoltcp::wire::{IpProtocol, IpVersion}; use std::str; use syscall::{Error as SyscallError, Result as SyscallResult}; @@ -61,14 +61,14 @@ impl<'a, 'b> SchemeSocket for RawSocket<'a, 'b> { let proto = u8::from_str_radix(path, 16).or_else(|_| Err(SyscallError::new(syscall::ENOENT)))?; - let mut rx_packets = Vec::with_capacity(Smolnetd::SOCKET_BUFFER_SIZE); - let mut tx_packets = Vec::with_capacity(Smolnetd::SOCKET_BUFFER_SIZE); - for _ in 0..Smolnetd::SOCKET_BUFFER_SIZE { - rx_packets.push(RawPacketBuffer::new(vec![0; NetworkDevice::MTU])); - tx_packets.push(RawPacketBuffer::new(vec![0; NetworkDevice::MTU])); - } - let rx_buffer = RawSocketBuffer::new(rx_packets); - let tx_buffer = RawSocketBuffer::new(tx_packets); + let rx_buffer = RawSocketBuffer::new( + vec![RawPacketMetadata::EMPTY; Smolnetd::SOCKET_BUFFER_SIZE], + vec![0; NetworkDevice::MTU * Smolnetd::SOCKET_BUFFER_SIZE] + ); + let tx_buffer = RawSocketBuffer::new( + vec![RawPacketMetadata::EMPTY; Smolnetd::SOCKET_BUFFER_SIZE], + vec![0; NetworkDevice::MTU * Smolnetd::SOCKET_BUFFER_SIZE] + ); let ip_socket = RawSocket::new( IpVersion::Ipv4, IpProtocol::from(proto), diff --git a/src/smolnetd/scheme/mod.rs b/src/smolnetd/scheme/mod.rs index 1afb129605..eb563afa94 100644 --- a/src/smolnetd/scheme/mod.rs +++ b/src/smolnetd/scheme/mod.rs @@ -1,6 +1,6 @@ use netutils::getcfg; use smoltcp; -use smoltcp::iface::{EthernetInterface, EthernetInterfaceBuilder, NeighborCache}; +use smoltcp::iface::{EthernetInterface, EthernetInterfaceBuilder, NeighborCache, Routes}; use smoltcp::socket::SocketSet as SmoltcpSocketSet; use smoltcp::time::{Duration, Instant}; use smoltcp::wire::{EthernetAddress, IpAddress, IpCidr, IpEndpoint, Ipv4Address}; @@ -31,7 +31,7 @@ mod icmp; mod netcfg; type SocketSet = SmoltcpSocketSet<'static, 'static, 'static>; -type Interface = Rc>>; +type Interface = Rc>>; const MAX_DURATION: Duration = Duration { millis: ::std::u64::MAX }; const MIN_DURATION: Duration = Duration { millis: 0 }; @@ -89,11 +89,13 @@ impl Smolnetd { hardware_addr, Rc::clone(&buffer_pool), ); + let mut routes = Routes::new(BTreeMap::new()); + routes.add_default_ipv4_route(default_gw).expect("Failed to add default gateway"); let iface = EthernetInterfaceBuilder::new(network_device) .neighbor_cache(NeighborCache::new(BTreeMap::new())) .ethernet_addr(hardware_addr) .ip_addrs(protocol_addrs) - .ipv4_gateway(default_gw) + .routes(routes) .finalize(); let iface = Rc::new(RefCell::new(iface)); let socket_set = Rc::new(RefCell::new(SocketSet::new(vec![]))); diff --git a/src/smolnetd/scheme/netcfg/mod.rs b/src/smolnetd/scheme/netcfg/mod.rs index 03a1b716c3..37de40b31f 100644 --- a/src/smolnetd/scheme/netcfg/mod.rs +++ b/src/smolnetd/scheme/netcfg/mod.rs @@ -2,7 +2,7 @@ mod nodes; mod notifier; -use smoltcp::wire::{EthernetAddress, IpCidr, Ipv4Address}; +use smoltcp::wire::{IpAddress, EthernetAddress, IpCidr, Ipv4Address}; use std::cell::RefCell; use std::collections::BTreeMap; use std::fs::File; @@ -23,6 +23,11 @@ use super::{post_fevent, Interface}; const WRITE_BUFFER_MAX_SIZE: usize = 0xffff; +fn gateway_cidr() -> IpCidr { + // TODO: const fn + IpCidr::new(IpAddress::v4(0, 0, 0, 0), 0) +} + fn parse_default_gw(value: &str) -> SyscallResult { let mut routes = value.lines(); if let Some(route) = routes.next() { @@ -75,7 +80,11 @@ fn mk_root_node(iface: Interface, notifier: NotifierRef, dns_config: DNSConfigRe "route" => { "list" => { ro [iface] || { - if let Some(ip) = iface.borrow().ipv4_gateway() { + let mut gateway = None; + iface.borrow_mut().routes_mut().update(|map| { + gateway = map.get(&gateway_cidr()).map(|route| route.via_router); + }); + if let Some(ip) = gateway { format!("default via {}\n", ip) } else { String::new() @@ -98,7 +107,9 @@ fn mk_root_node(iface: Interface, notifier: NotifierRef, dns_config: DNSConfigRe } |cur_value| { if let Some(default_gw) = *cur_value { - iface.borrow_mut().set_ipv4_gateway(Some(default_gw)); + if iface.borrow_mut().routes_mut().add_default_ipv4_route(default_gw).is_err() { + return Err(SyscallError::new(syscall::EINVAL)); + } notifier.borrow_mut().schedule_notify("route/list"); Ok(()) } else { @@ -123,10 +134,16 @@ fn mk_root_node(iface: Interface, notifier: NotifierRef, dns_config: DNSConfigRe |cur_value| { if let Some(default_gw) = *cur_value { let mut iface = iface.borrow_mut(); - if iface.ipv4_gateway() != Some(default_gw) { + let mut gateway = None; + iface.routes_mut().update(|map| { + gateway = map.get(&gateway_cidr()).map(|route| route.via_router); + }); + if gateway != Some(IpAddress::Ipv4(default_gw)) { return Err(SyscallError::new(syscall::EINVAL)); } - iface.set_ipv4_gateway(None); + iface.routes_mut().update(|map| { + map.remove(&gateway_cidr()); + }); notifier.borrow_mut().schedule_notify("route/list"); Ok(()) } else { diff --git a/src/smolnetd/scheme/udp.rs b/src/smolnetd/scheme/udp.rs index ae9853cb3c..d78695806e 100644 --- a/src/smolnetd/scheme/udp.rs +++ b/src/smolnetd/scheme/udp.rs @@ -1,4 +1,4 @@ -use smoltcp::socket::{SocketHandle, UdpPacketBuffer, UdpSocket, UdpSocketBuffer}; +use smoltcp::socket::{SocketHandle, UdpPacketMetadata, UdpSocket, UdpSocketBuffer}; use smoltcp::wire::IpEndpoint; use std::str; use syscall::{Error as SyscallError, Result as SyscallResult}; @@ -66,14 +66,14 @@ impl<'a, 'b> SchemeSocket for UdpSocket<'a, 'b> { return Err(SyscallError::new(syscall::EACCES)); } - let mut rx_packets = Vec::with_capacity(Smolnetd::SOCKET_BUFFER_SIZE); - let mut tx_packets = Vec::with_capacity(Smolnetd::SOCKET_BUFFER_SIZE); - for _ in 0..Smolnetd::SOCKET_BUFFER_SIZE { - rx_packets.push(UdpPacketBuffer::new(vec![0; NetworkDevice::MTU])); - tx_packets.push(UdpPacketBuffer::new(vec![0; NetworkDevice::MTU])); - } - let rx_buffer = UdpSocketBuffer::new(rx_packets); - let tx_buffer = UdpSocketBuffer::new(tx_packets); + let rx_buffer = UdpSocketBuffer::new( + vec![UdpPacketMetadata::EMPTY; Smolnetd::SOCKET_BUFFER_SIZE], + vec![0; NetworkDevice::MTU * Smolnetd::SOCKET_BUFFER_SIZE] + ); + let tx_buffer = UdpSocketBuffer::new( + vec![UdpPacketMetadata::EMPTY; Smolnetd::SOCKET_BUFFER_SIZE], + vec![0; NetworkDevice::MTU * Smolnetd::SOCKET_BUFFER_SIZE] + ); let udp_socket = UdpSocket::new(rx_buffer, tx_buffer); if local_endpoint.port == 0 { From 8edf468f3319fbc2c0c86ef6de8591904e6fb132 Mon Sep 17 00:00:00 2001 From: Dan Robertson Date: Thu, 21 Jun 2018 13:44:18 +0000 Subject: [PATCH 082/155] Bump smoltcp version Fixed packet buffer logic error in smoltcp --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 9e8bf0685a..e61f25a864 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,7 @@ features = ["release_max_level_off"] [dependencies.smoltcp] git = "https://github.com/m-labs/smoltcp.git" -rev = "d23aee483f2dc78e8070d2ad53e400cd0dcb9ae1" +rev = "682fc3078229a4fc06b5f021af058c45b9f3bc02" default-features = false features = ["std", "socket-raw", "proto-ipv4", "socket-udp", "socket-tcp", "socket-icmp"] From b90aa2c66356fe4c0b9802a6448f55b99114f8ef Mon Sep 17 00:00:00 2001 From: Paul Sajna Date: Thu, 5 Jul 2018 14:35:17 -0700 Subject: [PATCH 083/155] cargo update --- Cargo.lock | 115 +++++++++++++++++++++++++++-------------------------- 1 file changed, 58 insertions(+), 57 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 967f67a826..a5a1d3821a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -46,7 +46,7 @@ dependencies = [ [[package]] name = "cfg-if" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -73,7 +73,7 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -87,7 +87,7 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-utils 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -99,7 +99,7 @@ name = "crossbeam-utils" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -107,7 +107,7 @@ name = "crossbeam-utils" version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -150,7 +150,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "httparse" -version = "1.2.4" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -159,7 +159,7 @@ version = "0.10.13" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "base64 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "httparse 1.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "httparse 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "mime 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -239,15 +239,15 @@ name = "log" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "log 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "log" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -275,37 +275,40 @@ dependencies = [ [[package]] name = "mio" -version = "0.6.14" -source = "git+https://gitlab.redox-os.org/redox-os/mio#1339f362be63592de538a4ea52367e820e846988" +version = "0.6.15" +source = "git+https://gitlab.redox-os.org/redox-os/mio#94485d62a91ac728f9ffc358319aeb8e15becab0" dependencies = [ "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazycell 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "miow 0.3.1 (git+https://gitlab.redox-os.org/redox-os/miow?rev=5b10500)", - "net2 0.2.32 (git+https://gitlab.redox-os.org/redox-os/net2-rs)", + "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", "slab 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "miow" -version = "0.3.1" -source = "git+https://gitlab.redox-os.org/redox-os/miow?rev=5b10500#5b10500df2c560245d532e77c54a8b8b2d15cfd5" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "socket2 0.3.7 (git+https://github.com/redox-os/socket2-rs)", - "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "net2" -version = "0.2.32" -source = "git+https://gitlab.redox-os.org/redox-os/net2-rs#0eae9193ba04270a4ded81c0d3c76d918c3bbcc6" +version = "0.2.33" +source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -320,7 +323,7 @@ dependencies = [ "hyper 0.10.13 (registry+https://github.com/rust-lang/crates.io-index)", "hyper-rustls 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.14 (git+https://gitlab.redox-os.org/redox-os/mio)", + "mio 0.6.15 (git+https://gitlab.redox-os.org/redox-os/mio)", "ntpclient 0.0.1 (git+https://github.com/willem66745/ntpclient-rust)", "pbr 1.0.1 (git+https://github.com/a8m/pb)", "redox_event 0.1.0 (git+https://gitlab.redox-os.org/redox-os/event.git)", @@ -423,13 +426,13 @@ dependencies = [ "netutils 0.1.0 (git+https://gitlab.redox-os.org/redox-os/netutils.git)", "redox_event 0.1.0 (git+https://gitlab.redox-os.org/redox-os/event.git)", "redox_syscall 0.1.40 (git+https://gitlab.redox-os.org/redox-os/syscall.git)", - "smoltcp 0.4.0 (git+https://github.com/m-labs/smoltcp.git?rev=d23aee483f2dc78e8070d2ad53e400cd0dcb9ae1)", + "smoltcp 0.4.0 (git+https://github.com/m-labs/smoltcp.git?rev=682fc3078229a4fc06b5f021af058c45b9f3bc02)", ] [[package]] name = "redox_syscall" version = "0.1.40" -source = "git+https://gitlab.redox-os.org/redox-os/syscall.git#495b09740a6ffbe01d10097aac4cf333dd392e69" +source = "git+https://gitlab.redox-os.org/redox-os/syscall.git#e7e212960095d3e79f902807bb6b811f51eb62b6" [[package]] name = "redox_syscall" @@ -487,24 +490,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "smoltcp" version = "0.4.0" -source = "git+https://github.com/m-labs/smoltcp.git?rev=d23aee483f2dc78e8070d2ad53e400cd0dcb9ae1#d23aee483f2dc78e8070d2ad53e400cd0dcb9ae1" +source = "git+https://github.com/m-labs/smoltcp.git?rev=682fc3078229a4fc06b5f021af058c45b9f3bc02#682fc3078229a4fc06b5f021af058c45b9f3bc02" dependencies = [ "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "managed 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "socket2" -version = "0.3.7" -source = "git+https://github.com/redox-os/socket2-rs#3543915f09e41f6e010d4d9e2d5217b27faf5e70" -dependencies = [ - "cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "termion" version = "1.5.1" @@ -531,7 +523,7 @@ version = "0.1.6" source = "git+https://gitlab.redox-os.org/redox-os/tokio#4db6ce75b5059c42cbbad56d7c441da19fe18c1a" dependencies = [ "futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.14 (git+https://gitlab.redox-os.org/redox-os/mio)", + "mio 0.6.15 (git+https://gitlab.redox-os.org/redox-os/mio)", "tokio-executor 0.1.2 (git+https://gitlab.redox-os.org/redox-os/tokio)", "tokio-fs 0.1.0 (git+https://gitlab.redox-os.org/redox-os/tokio)", "tokio-io 0.1.6 (git+https://gitlab.redox-os.org/redox-os/tokio)", @@ -567,7 +559,7 @@ source = "git+https://gitlab.redox-os.org/redox-os/tokio#4db6ce75b5059c42cbbad56 dependencies = [ "bytes 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -576,8 +568,8 @@ version = "0.1.1" source = "git+https://gitlab.redox-os.org/redox-os/tokio#4db6ce75b5059c42cbbad56d7c441da19fe18c1a" dependencies = [ "futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.14 (git+https://gitlab.redox-os.org/redox-os/mio)", + "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.15 (git+https://gitlab.redox-os.org/redox-os/mio)", "slab 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-executor 0.1.2 (git+https://gitlab.redox-os.org/redox-os/tokio)", "tokio-io 0.1.6 (git+https://gitlab.redox-os.org/redox-os/tokio)", @@ -591,7 +583,7 @@ dependencies = [ "bytes 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.14 (git+https://gitlab.redox-os.org/redox-os/mio)", + "mio 0.6.15 (git+https://gitlab.redox-os.org/redox-os/mio)", "tokio-io 0.1.6 (git+https://gitlab.redox-os.org/redox-os/tokio)", "tokio-reactor 0.1.1 (git+https://gitlab.redox-os.org/redox-os/tokio)", ] @@ -603,7 +595,7 @@ source = "git+https://gitlab.redox-os.org/redox-os/tokio#4db6ce75b5059c42cbbad56 dependencies = [ "crossbeam-deque 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-executor 0.1.2 (git+https://gitlab.redox-os.org/redox-os/tokio)", @@ -625,8 +617,8 @@ source = "git+https://gitlab.redox-os.org/redox-os/tokio#4db6ce75b5059c42cbbad56 dependencies = [ "bytes 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.14 (git+https://gitlab.redox-os.org/redox-os/mio)", + "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.15 (git+https://gitlab.redox-os.org/redox-os/mio)", "tokio-io 0.1.6 (git+https://gitlab.redox-os.org/redox-os/tokio)", "tokio-reactor 0.1.1 (git+https://gitlab.redox-os.org/redox-os/tokio)", ] @@ -646,7 +638,7 @@ name = "unicase" version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "version_check 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "version_check 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -679,7 +671,7 @@ dependencies = [ [[package]] name = "version_check" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -730,6 +722,15 @@ name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "ws2_32-sys" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [metadata] "checksum arg_parser 0.1.0 (git+https://gitlab.redox-os.org/redox-os/arg-parser.git)" = "" "checksum arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)" = "a1e964f9e24d588183fcb43503abda40d288c8657dfc27311516ce2f05675aef" @@ -738,7 +739,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855" "checksum byteorder 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "74c0b906e9446b0a2e4f760cdb3fa4b2c48cdc6db8766a845c54b6ff063fd2e9" "checksum bytes 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7dd32989a66957d3f0cba6588f15d4281a733f4e9ffc43fcd2385f57d3bf99ff" -"checksum cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "405216fd8fe65f718daa7102ea808a946b6ce40c742998fbfd3463645552de18" +"checksum cfg-if 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "efe5c877e17a9c717a0bf3613b2709f723202c4e4675cc8f12926ded29bcb17e" "checksum crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f739f8c5363aca78cfb059edf753d8f0d36908c348f3d8d1503f03d8b75d9cf3" "checksum crossbeam-deque 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fe8153ef04a7594ded05b427ffad46ddeaf22e63fd48d42b3e1e3bb4db07cae7" "checksum crossbeam-epoch 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "927121f5407de9956180ff5e936fe3cf4324279280001cd56b669d28ee7e9150" @@ -751,7 +752,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" "checksum futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)" = "1a70b146671de62ec8c8ed572219ca5d594d9b06c0b364d5e67b722fc559b48c" "checksum gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)" = "5e33ec290da0d127825013597dbdfc28bee4964690c7ce1166cbc2a7bd08b1bb" -"checksum httparse 1.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "c2f407128745b78abc95c0ffbe4e5d37427fdc0d45470710cfef8c44522a2e37" +"checksum httparse 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7b6288d7db100340ca12873fd4d08ad1b8f206a9457798dfb17c018a33fee540" "checksum hyper 0.10.13 (registry+https://github.com/rust-lang/crates.io-index)" = "368cb56b2740ebf4230520e2b90ebb0461e69034d85d1945febd9b3971426db2" "checksum hyper-rustls 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "04535774f79684c99528944ebdb89756c945c027e55ce52faa245879d836c8fb" "checksum idna 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "014b298351066f1512874135335d62a789ffe78a9974f94b43ed5621951eaf7d" @@ -763,14 +764,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum lazycell 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a6f08839bc70ef4a3fe1d566d5350f519c5912ea86be0df1740a7d247c7fc0ef" "checksum libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)" = "b685088df2b950fccadf07a7187c8ef846a959c142338a48f9dc0b94517eb5f1" "checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" -"checksum log 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6fddaa003a65722a7fb9e26b0ce95921fe4ba590542ced664d8ce2fa26f9f3ac" +"checksum log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "61bd98ae7f7b754bc53dca7d44b604f733c6bba044ea6f41bc8d89272d8161d2" "checksum managed 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ba6713e624266d7600e9feae51b1926c6a6a6bebb18ec5a8e11a5f1d5661baba" "checksum matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "100aabe6b8ff4e4a7e32c1c13523379802df0772b82466207ac25b013f193376" "checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3" "checksum mime 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ba626b8a6de5da682e1caa06bdb42a335aee5a84db8e5046a3e8ab17ba0a3ae0" -"checksum mio 0.6.14 (git+https://gitlab.redox-os.org/redox-os/mio)" = "" -"checksum miow 0.3.1 (git+https://gitlab.redox-os.org/redox-os/miow?rev=5b10500)" = "" -"checksum net2 0.2.32 (git+https://gitlab.redox-os.org/redox-os/net2-rs)" = "" +"checksum mio 0.6.15 (git+https://gitlab.redox-os.org/redox-os/mio)" = "" +"checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919" +"checksum net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "42550d9fb7b6684a6d404d9fa7250c2eb2646df731d1c06afc06dcee9e1bcf88" "checksum netutils 0.1.0 (git+https://gitlab.redox-os.org/redox-os/netutils.git)" = "" "checksum nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "9a2228dca57108069a5262f2ed8bd2e82496d2e074a06d1ccc7ce1687b6ae0a2" "checksum ntpclient 0.0.1 (git+https://github.com/willem66745/ntpclient-rust)" = "" @@ -790,8 +791,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e27a8b19b835f7aea908818e871f5cc3a5a186550c30773be987e155e8163d8f" "checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" "checksum slab 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fdeff4cd9ecff59ec7e3744cbca73dfe5ac35c2aedb2cfba8a1c715a18912e9d" -"checksum smoltcp 0.4.0 (git+https://github.com/m-labs/smoltcp.git?rev=d23aee483f2dc78e8070d2ad53e400cd0dcb9ae1)" = "" -"checksum socket2 0.3.7 (git+https://github.com/redox-os/socket2-rs)" = "" +"checksum smoltcp 0.4.0 (git+https://github.com/m-labs/smoltcp.git?rev=682fc3078229a4fc06b5f021af058c45b9f3bc02)" = "" "checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" "checksum time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "d825be0eb33fda1a7e68012d51e9c7f451dc1a69391e7fdc197060bb8c56667b" "checksum tokio 0.1.6 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" @@ -810,7 +810,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum unicode-normalization 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "6a0180bc61fc5a987082bfa111f4cc95c4caff7f9799f3e46df09163a937aa25" "checksum untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f392d7819dbe58833e26872f5f6f0d68b7bbbe90fc3667e98731c4a15ad9a7ae" "checksum url 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f808aadd8cfec6ef90e4a14eb46f24511824d1ac596b9682703c87056c8678b7" -"checksum version_check 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6b772017e347561807c1aa192438c5fd74242a670a6cffacc40f2defd1dc069d" +"checksum version_check 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "7716c242968ee87e5542f8021178248f267f295a5c4803beae8b8b7fd9bc6051" "checksum webpki 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e499345fc4c6b7c79a5b8756d4592c4305510a13512e79efafe00dfbd67bbac6" "checksum webpki-roots 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5bfb3f50499f21ad2317f442845e3b5805b007f1e728f59885c99e61b8c181a7" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" @@ -818,3 +818,4 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +"checksum ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" From 4a2b8500e4a5b195387efa5ad2b6d00b67f24263 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Thu, 12 Jul 2018 07:25:52 -0600 Subject: [PATCH 084/155] Update Cargo.lock --- Cargo.lock | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a5a1d3821a..238a677d0a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -140,7 +140,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "futures" -version = "0.1.21" +version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -168,7 +168,7 @@ dependencies = [ "traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "typeable 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "unicase 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "url 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -183,7 +183,7 @@ dependencies = [ [[package]] name = "idna" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -252,7 +252,7 @@ dependencies = [ [[package]] name = "managed" -version = "0.7.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -276,7 +276,7 @@ dependencies = [ [[package]] name = "mio" version = "0.6.15" -source = "git+https://gitlab.redox-os.org/redox-os/mio#94485d62a91ac728f9ffc358319aeb8e15becab0" +source = "git+https://gitlab.redox-os.org/redox-os/mio#58cc19074dad2380e474917656bc14b0d63657d3" dependencies = [ "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -494,7 +494,7 @@ source = "git+https://github.com/m-labs/smoltcp.git?rev=682fc3078229a4fc06b5f021 dependencies = [ "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "managed 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "managed 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -522,7 +522,7 @@ name = "tokio" version = "0.1.6" source = "git+https://gitlab.redox-os.org/redox-os/tokio#4db6ce75b5059c42cbbad56d7c441da19fe18c1a" dependencies = [ - "futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.6.15 (git+https://gitlab.redox-os.org/redox-os/mio)", "tokio-executor 0.1.2 (git+https://gitlab.redox-os.org/redox-os/tokio)", "tokio-fs 0.1.0 (git+https://gitlab.redox-os.org/redox-os/tokio)", @@ -539,7 +539,7 @@ name = "tokio-executor" version = "0.1.2" source = "git+https://gitlab.redox-os.org/redox-os/tokio#4db6ce75b5059c42cbbad56d7c441da19fe18c1a" dependencies = [ - "futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -547,7 +547,7 @@ name = "tokio-fs" version = "0.1.0" source = "git+https://gitlab.redox-os.org/redox-os/tokio#4db6ce75b5059c42cbbad56d7c441da19fe18c1a" dependencies = [ - "futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.6 (git+https://gitlab.redox-os.org/redox-os/tokio)", "tokio-threadpool 0.1.3 (git+https://gitlab.redox-os.org/redox-os/tokio)", ] @@ -558,7 +558,7 @@ version = "0.1.6" source = "git+https://gitlab.redox-os.org/redox-os/tokio#4db6ce75b5059c42cbbad56d7c441da19fe18c1a" dependencies = [ "bytes 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -567,7 +567,7 @@ name = "tokio-reactor" version = "0.1.1" source = "git+https://gitlab.redox-os.org/redox-os/tokio#4db6ce75b5059c42cbbad56d7c441da19fe18c1a" dependencies = [ - "futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.6.15 (git+https://gitlab.redox-os.org/redox-os/mio)", "slab 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -581,7 +581,7 @@ version = "0.1.0" source = "git+https://gitlab.redox-os.org/redox-os/tokio#4db6ce75b5059c42cbbad56d7c441da19fe18c1a" dependencies = [ "bytes 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.6.15 (git+https://gitlab.redox-os.org/redox-os/mio)", "tokio-io 0.1.6 (git+https://gitlab.redox-os.org/redox-os/tokio)", @@ -594,7 +594,7 @@ version = "0.1.3" source = "git+https://gitlab.redox-os.org/redox-os/tokio#4db6ce75b5059c42cbbad56d7c441da19fe18c1a" dependencies = [ "crossbeam-deque 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -606,7 +606,7 @@ name = "tokio-timer" version = "0.2.3" source = "git+https://gitlab.redox-os.org/redox-os/tokio#4db6ce75b5059c42cbbad56d7c441da19fe18c1a" dependencies = [ - "futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-executor 0.1.2 (git+https://gitlab.redox-os.org/redox-os/tokio)", ] @@ -616,7 +616,7 @@ version = "0.1.0" source = "git+https://gitlab.redox-os.org/redox-os/tokio#4db6ce75b5059c42cbbad56d7c441da19fe18c1a" dependencies = [ "bytes 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.6.15 (git+https://gitlab.redox-os.org/redox-os/mio)", "tokio-io 0.1.6 (git+https://gitlab.redox-os.org/redox-os/tokio)", @@ -661,10 +661,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "url" -version = "1.7.0" +version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "idna 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -750,12 +750,12 @@ dependencies = [ "checksum extra 0.1.0 (git+https://gitlab.redox-os.org/redox-os/libextra.git)" = "" "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" "checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" -"checksum futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)" = "1a70b146671de62ec8c8ed572219ca5d594d9b06c0b364d5e67b722fc559b48c" +"checksum futures 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)" = "80599c995ed197a276e27c27f94a6346446538adde3b87c1ab384f6f8cabfed4" "checksum gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)" = "5e33ec290da0d127825013597dbdfc28bee4964690c7ce1166cbc2a7bd08b1bb" "checksum httparse 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7b6288d7db100340ca12873fd4d08ad1b8f206a9457798dfb17c018a33fee540" "checksum hyper 0.10.13 (registry+https://github.com/rust-lang/crates.io-index)" = "368cb56b2740ebf4230520e2b90ebb0461e69034d85d1945febd9b3971426db2" "checksum hyper-rustls 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "04535774f79684c99528944ebdb89756c945c027e55ce52faa245879d836c8fb" -"checksum idna 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "014b298351066f1512874135335d62a789ffe78a9974f94b43ed5621951eaf7d" +"checksum idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e" "checksum iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dbe6e417e7d0975db6512b90796e8ce223145ac4e33c377e4a42882a0e88bb08" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a" @@ -765,7 +765,7 @@ dependencies = [ "checksum libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)" = "b685088df2b950fccadf07a7187c8ef846a959c142338a48f9dc0b94517eb5f1" "checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" "checksum log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "61bd98ae7f7b754bc53dca7d44b604f733c6bba044ea6f41bc8d89272d8161d2" -"checksum managed 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ba6713e624266d7600e9feae51b1926c6a6a6bebb18ec5a8e11a5f1d5661baba" +"checksum managed 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fdcec5e97041c7f0f1c5b7d93f12e57293c831c646f4cc7a5db59460c7ea8de6" "checksum matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "100aabe6b8ff4e4a7e32c1c13523379802df0772b82466207ac25b013f193376" "checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3" "checksum mime 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ba626b8a6de5da682e1caa06bdb42a335aee5a84db8e5046a3e8ab17ba0a3ae0" @@ -809,7 +809,7 @@ dependencies = [ "checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" "checksum unicode-normalization 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "6a0180bc61fc5a987082bfa111f4cc95c4caff7f9799f3e46df09163a937aa25" "checksum untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f392d7819dbe58833e26872f5f6f0d68b7bbbe90fc3667e98731c4a15ad9a7ae" -"checksum url 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f808aadd8cfec6ef90e4a14eb46f24511824d1ac596b9682703c87056c8678b7" +"checksum url 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2a321979c09843d272956e73700d12c4e7d3d92b2ee112b31548aef0d4efc5a6" "checksum version_check 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "7716c242968ee87e5542f8021178248f267f295a5c4803beae8b8b7fd9bc6051" "checksum webpki 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e499345fc4c6b7c79a5b8756d4592c4305510a13512e79efafe00dfbd67bbac6" "checksum webpki-roots 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5bfb3f50499f21ad2317f442845e3b5805b007f1e728f59885c99e61b8c181a7" From ea90c7ae7bbabc4f8ba903f59287aac359f30222 Mon Sep 17 00:00:00 2001 From: Robin Randhawa Date: Wed, 25 Jul 2018 18:13:10 +0100 Subject: [PATCH 085/155] Update Cargo.lock A 'precise' cargo update of tokio is needed for the build to succeed. --- Cargo.lock | 215 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 126 insertions(+), 89 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 238a677d0a..bdc929968c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -37,7 +37,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "bytes" -version = "0.4.8" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "byteorder 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -49,6 +49,14 @@ name = "cfg-if" version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "cloudabi" +version = "0.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "crossbeam-deque" version = "0.2.0" @@ -60,11 +68,11 @@ dependencies = [ [[package]] name = "crossbeam-deque" -version = "0.3.1" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "crossbeam-epoch 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam-utils 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-epoch 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -75,7 +83,7 @@ dependencies = [ "arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", "cfg-if 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", "scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -83,13 +91,13 @@ dependencies = [ [[package]] name = "crossbeam-epoch" -version = "0.4.3" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", "cfg-if 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam-utils 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -104,11 +112,8 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.3.2" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cfg-if 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", -] [[package]] name = "dns-parser" @@ -140,7 +145,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "futures" -version = "0.1.22" +version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -186,7 +191,7 @@ name = "idna" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "matches 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-normalization 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -221,12 +226,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "lazy_static" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "lazycell" -version = "0.6.0" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -257,7 +262,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "matches" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -276,13 +281,13 @@ dependencies = [ [[package]] name = "mio" version = "0.6.15" -source = "git+https://gitlab.redox-os.org/redox-os/mio#58cc19074dad2380e474917656bc14b0d63657d3" +source = "git+https://gitlab.redox-os.org/redox-os/mio#cc0fc26c55b0005da1c275dc4a0115420ecfb14c" dependencies = [ "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "lazycell 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazycell 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -330,8 +335,8 @@ dependencies = [ "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio 0.1.6 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-reactor 0.1.1 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio 0.1.7 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-reactor 0.1.2 (git+https://gitlab.redox-os.org/redox-os/tokio)", ] [[package]] @@ -359,7 +364,7 @@ dependencies = [ [[package]] name = "pbr" version = "1.0.1" -source = "git+https://github.com/a8m/pb#bff135f7eed7931a1103e593c74160d28fdd2314" +source = "git+https://github.com/a8m/pb#e0ab10be58c79d58dcdda9b79a82d28c54b3b4e3" dependencies = [ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", @@ -380,32 +385,38 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "rand" -version = "0.4.2" +version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ + "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rand_core" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "rayon" version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "rayon-core 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rayon-core 1.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rayon-core" -version = "1.4.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -519,108 +530,130 @@ dependencies = [ [[package]] name = "tokio" -version = "0.1.6" -source = "git+https://gitlab.redox-os.org/redox-os/tokio#4db6ce75b5059c42cbbad56d7c441da19fe18c1a" +version = "0.1.7" +source = "git+https://gitlab.redox-os.org/redox-os/tokio#12c80a60c2ac2f7c3ff62d0fd2dc98f99c91b378" dependencies = [ - "futures 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.6.15 (git+https://gitlab.redox-os.org/redox-os/mio)", + "tokio-current-thread 0.1.0 (git+https://gitlab.redox-os.org/redox-os/tokio)", "tokio-executor 0.1.2 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-fs 0.1.0 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-io 0.1.6 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-reactor 0.1.1 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-fs 0.1.2 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-io 0.1.7 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-reactor 0.1.2 (git+https://gitlab.redox-os.org/redox-os/tokio)", "tokio-tcp 0.1.0 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-threadpool 0.1.3 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-timer 0.2.3 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-udp 0.1.0 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-threadpool 0.1.5 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-timer 0.2.4 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-udp 0.1.1 (git+https://gitlab.redox-os.org/redox-os/tokio)", +] + +[[package]] +name = "tokio-codec" +version = "0.1.0" +source = "git+https://gitlab.redox-os.org/redox-os/tokio#12c80a60c2ac2f7c3ff62d0fd2dc98f99c91b378" +dependencies = [ + "bytes 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-io 0.1.7 (git+https://gitlab.redox-os.org/redox-os/tokio)", +] + +[[package]] +name = "tokio-current-thread" +version = "0.1.0" +source = "git+https://gitlab.redox-os.org/redox-os/tokio#12c80a60c2ac2f7c3ff62d0fd2dc98f99c91b378" +dependencies = [ + "futures 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-executor 0.1.2 (git+https://gitlab.redox-os.org/redox-os/tokio)", ] [[package]] name = "tokio-executor" version = "0.1.2" -source = "git+https://gitlab.redox-os.org/redox-os/tokio#4db6ce75b5059c42cbbad56d7c441da19fe18c1a" +source = "git+https://gitlab.redox-os.org/redox-os/tokio#12c80a60c2ac2f7c3ff62d0fd2dc98f99c91b378" dependencies = [ - "futures 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "tokio-fs" -version = "0.1.0" -source = "git+https://gitlab.redox-os.org/redox-os/tokio#4db6ce75b5059c42cbbad56d7c441da19fe18c1a" +version = "0.1.2" +source = "git+https://gitlab.redox-os.org/redox-os/tokio#12c80a60c2ac2f7c3ff62d0fd2dc98f99c91b378" dependencies = [ - "futures 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-io 0.1.6 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-threadpool 0.1.3 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "futures 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-io 0.1.7 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-threadpool 0.1.5 (git+https://gitlab.redox-os.org/redox-os/tokio)", ] [[package]] name = "tokio-io" -version = "0.1.6" -source = "git+https://gitlab.redox-os.org/redox-os/tokio#4db6ce75b5059c42cbbad56d7c441da19fe18c1a" +version = "0.1.7" +source = "git+https://gitlab.redox-os.org/redox-os/tokio#12c80a60c2ac2f7c3ff62d0fd2dc98f99c91b378" dependencies = [ - "bytes 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "tokio-reactor" -version = "0.1.1" -source = "git+https://gitlab.redox-os.org/redox-os/tokio#4db6ce75b5059c42cbbad56d7c441da19fe18c1a" +version = "0.1.2" +source = "git+https://gitlab.redox-os.org/redox-os/tokio#12c80a60c2ac2f7c3ff62d0fd2dc98f99c91b378" dependencies = [ - "futures 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.6.15 (git+https://gitlab.redox-os.org/redox-os/mio)", "slab 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-executor 0.1.2 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-io 0.1.6 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-io 0.1.7 (git+https://gitlab.redox-os.org/redox-os/tokio)", ] [[package]] name = "tokio-tcp" version = "0.1.0" -source = "git+https://gitlab.redox-os.org/redox-os/tokio#4db6ce75b5059c42cbbad56d7c441da19fe18c1a" +source = "git+https://gitlab.redox-os.org/redox-os/tokio#12c80a60c2ac2f7c3ff62d0fd2dc98f99c91b378" dependencies = [ - "bytes 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)", "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.6.15 (git+https://gitlab.redox-os.org/redox-os/mio)", - "tokio-io 0.1.6 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-reactor 0.1.1 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-io 0.1.7 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-reactor 0.1.2 (git+https://gitlab.redox-os.org/redox-os/tokio)", ] [[package]] name = "tokio-threadpool" -version = "0.1.3" -source = "git+https://gitlab.redox-os.org/redox-os/tokio#4db6ce75b5059c42cbbad56d7c441da19fe18c1a" +version = "0.1.5" +source = "git+https://gitlab.redox-os.org/redox-os/tokio#12c80a60c2ac2f7c3ff62d0fd2dc98f99c91b378" dependencies = [ - "crossbeam-deque 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-deque 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-executor 0.1.2 (git+https://gitlab.redox-os.org/redox-os/tokio)", ] [[package]] name = "tokio-timer" -version = "0.2.3" -source = "git+https://gitlab.redox-os.org/redox-os/tokio#4db6ce75b5059c42cbbad56d7c441da19fe18c1a" +version = "0.2.4" +source = "git+https://gitlab.redox-os.org/redox-os/tokio#12c80a60c2ac2f7c3ff62d0fd2dc98f99c91b378" dependencies = [ - "futures 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-executor 0.1.2 (git+https://gitlab.redox-os.org/redox-os/tokio)", ] [[package]] name = "tokio-udp" -version = "0.1.0" -source = "git+https://gitlab.redox-os.org/redox-os/tokio#4db6ce75b5059c42cbbad56d7c441da19fe18c1a" +version = "0.1.1" +source = "git+https://gitlab.redox-os.org/redox-os/tokio#12c80a60c2ac2f7c3ff62d0fd2dc98f99c91b378" dependencies = [ - "bytes 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.6.15 (git+https://gitlab.redox-os.org/redox-os/mio)", - "tokio-io 0.1.6 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-reactor 0.1.1 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-codec 0.1.0 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-io 0.1.7 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-reactor 0.1.2 (git+https://gitlab.redox-os.org/redox-os/tokio)", ] [[package]] @@ -646,7 +679,7 @@ name = "unicode-bidi" version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "matches 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -665,7 +698,7 @@ version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "matches 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -738,19 +771,20 @@ dependencies = [ "checksum bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d0c54bb8f454c567f21197eefcdbf5679d0bd99f2ddbe52e84c77061952e6789" "checksum byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855" "checksum byteorder 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "74c0b906e9446b0a2e4f760cdb3fa4b2c48cdc6db8766a845c54b6ff063fd2e9" -"checksum bytes 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7dd32989a66957d3f0cba6588f15d4281a733f4e9ffc43fcd2385f57d3bf99ff" +"checksum bytes 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e178b8e0e239e844b083d5a0d4a156b2654e67f9f80144d48398fcd736a24fb8" "checksum cfg-if 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "efe5c877e17a9c717a0bf3613b2709f723202c4e4675cc8f12926ded29bcb17e" +"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" "checksum crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f739f8c5363aca78cfb059edf753d8f0d36908c348f3d8d1503f03d8b75d9cf3" -"checksum crossbeam-deque 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fe8153ef04a7594ded05b427ffad46ddeaf22e63fd48d42b3e1e3bb4db07cae7" +"checksum crossbeam-deque 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ce1357a7a2ad69ff9f090ee8641b5b94c622138bb2c3eae16ad7917a8e35a801" "checksum crossbeam-epoch 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "927121f5407de9956180ff5e936fe3cf4324279280001cd56b669d28ee7e9150" -"checksum crossbeam-epoch 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2af0e75710d6181e234c8ecc79f14a97907850a541b13b0be1dd10992f2e4620" +"checksum crossbeam-epoch 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "285987a59c4d91388e749850e3cb7b3a92299668528caaacd08005b8f238c0ea" "checksum crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2760899e32a1d58d5abb31129f8fae5de75220bc2176e77ff7c627ae45c918d9" -"checksum crossbeam-utils 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d636a8b3bcc1b409d7ffd3facef8f21dcb4009626adbd0c5e6c4305c07253c7b" +"checksum crossbeam-utils 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ea52fab26a99d96cdff39d0ca75c9716125937f5dba2ab83923aaaf5928f684a" "checksum dns-parser 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f7020f6760aea312d43d23cb83bf6c0c49f162541db8b02bf95209ac51dc253d" "checksum extra 0.1.0 (git+https://gitlab.redox-os.org/redox-os/libextra.git)" = "" "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" "checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" -"checksum futures 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)" = "80599c995ed197a276e27c27f94a6346446538adde3b87c1ab384f6f8cabfed4" +"checksum futures 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)" = "884dbe32a6ae4cd7da5c6db9b78114449df9953b8d490c9d7e1b51720b922c62" "checksum gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)" = "5e33ec290da0d127825013597dbdfc28bee4964690c7ce1166cbc2a7bd08b1bb" "checksum httparse 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7b6288d7db100340ca12873fd4d08ad1b8f206a9457798dfb17c018a33fee540" "checksum hyper 0.10.13 (registry+https://github.com/rust-lang/crates.io-index)" = "368cb56b2740ebf4230520e2b90ebb0461e69034d85d1945febd9b3971426db2" @@ -760,13 +794,13 @@ dependencies = [ "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a" "checksum lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "76f033c7ad61445c5b347c7382dd1237847eb1bce590fe50365dcb33d546be73" -"checksum lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e6412c5e2ad9584b0b8e979393122026cdd6d2a80b933f890dcd694ddbe73739" -"checksum lazycell 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a6f08839bc70ef4a3fe1d566d5350f519c5912ea86be0df1740a7d247c7fc0ef" +"checksum lazy_static 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "fb497c35d362b6a331cfd94956a07fc2c78a4604cdbee844a81170386b996dd3" +"checksum lazycell 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d33a48d0365c96081958cc663eef834975cb1e8d8bea3378513fc72bdbf11e50" "checksum libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)" = "b685088df2b950fccadf07a7187c8ef846a959c142338a48f9dc0b94517eb5f1" "checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" "checksum log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "61bd98ae7f7b754bc53dca7d44b604f733c6bba044ea6f41bc8d89272d8161d2" "checksum managed 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fdcec5e97041c7f0f1c5b7d93f12e57293c831c646f4cc7a5db59460c7ea8de6" -"checksum matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "100aabe6b8ff4e4a7e32c1c13523379802df0772b82466207ac25b013f193376" +"checksum matches 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "835511bab37c34c47da5cb44844bea2cfde0236db0b506f90ea4224482c9774a" "checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3" "checksum mime 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ba626b8a6de5da682e1caa06bdb42a335aee5a84db8e5046a3e8ab17ba0a3ae0" "checksum mio 0.6.15 (git+https://gitlab.redox-os.org/redox-os/mio)" = "" @@ -779,9 +813,10 @@ dependencies = [ "checksum pbr 1.0.1 (git+https://github.com/a8m/pb)" = "" "checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" "checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0" -"checksum rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "eba5f8cb59cc50ed56be8880a5c7b496bfd9bd26394e176bc67884094145c2c5" +"checksum rand 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "12397506224b2f93e6664ffc4f664b29be8208e5157d3d90b44f09b5fae470ea" +"checksum rand_core 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "edecf0f94da5551fc9b492093e30b041a891657db7940ee221f9d2f66e82eef2" "checksum rayon 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a77c51c07654ddd93f6cb543c7a849863b03abc7e82591afda6dc8ad4ac3ac4a" -"checksum rayon-core 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9d24ad214285a7729b174ed6d3bcfcb80177807f959d95fafd5bfc5c4f201ac8" +"checksum rayon-core 1.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b055d1e92aba6877574d8fe604a63c8b5df60f60e5982bf7ccbb1338ea527356" "checksum redox_event 0.1.0 (git+https://gitlab.redox-os.org/redox-os/event.git)" = "" "checksum redox_syscall 0.1.40 (git+https://gitlab.redox-os.org/redox-os/syscall.git)" = "" "checksum redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "c214e91d3ecf43e9a4e41e578973adeb14b474f2bee858742d127af75a0112b1" @@ -794,15 +829,17 @@ dependencies = [ "checksum smoltcp 0.4.0 (git+https://github.com/m-labs/smoltcp.git?rev=682fc3078229a4fc06b5f021af058c45b9f3bc02)" = "" "checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" "checksum time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "d825be0eb33fda1a7e68012d51e9c7f451dc1a69391e7fdc197060bb8c56667b" -"checksum tokio 0.1.6 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" +"checksum tokio 0.1.7 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" +"checksum tokio-codec 0.1.0 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" +"checksum tokio-current-thread 0.1.0 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" "checksum tokio-executor 0.1.2 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" -"checksum tokio-fs 0.1.0 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" -"checksum tokio-io 0.1.6 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" -"checksum tokio-reactor 0.1.1 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" +"checksum tokio-fs 0.1.2 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" +"checksum tokio-io 0.1.7 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" +"checksum tokio-reactor 0.1.2 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" "checksum tokio-tcp 0.1.0 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" -"checksum tokio-threadpool 0.1.3 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" -"checksum tokio-timer 0.2.3 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" -"checksum tokio-udp 0.1.0 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" +"checksum tokio-threadpool 0.1.5 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" +"checksum tokio-timer 0.2.4 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" +"checksum tokio-udp 0.1.1 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" "checksum traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079" "checksum typeable 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1410f6f91f21d1612654e7cc69193b0334f909dcf2c790c4826254fbb86f8887" "checksum unicase 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7f4765f83163b74f957c797ad9253caf97f103fb064d3999aea9568d09fc8a33" From 2214442a64a85b85a2fd2a3a51ee9b4655ae19f6 Mon Sep 17 00:00:00 2001 From: jD91mZM2 Date: Sun, 26 Aug 2018 13:03:36 +0200 Subject: [PATCH 086/155] Update Cargo.lock --- Cargo.lock | 253 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 189 insertions(+), 64 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bdc929968c..26eec8947e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -68,11 +68,11 @@ dependencies = [ [[package]] name = "crossbeam-deque" -version = "0.5.1" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crossbeam-epoch 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam-utils 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -115,6 +115,11 @@ name = "crossbeam-utils" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "crossbeam-utils" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "dns-parser" version = "0.7.1" @@ -239,6 +244,15 @@ name = "libc" version = "0.2.42" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "lock_api" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "log" version = "0.3.9" @@ -281,7 +295,7 @@ dependencies = [ [[package]] name = "mio" version = "0.6.15" -source = "git+https://gitlab.redox-os.org/redox-os/mio#cc0fc26c55b0005da1c275dc4a0115420ecfb14c" +source = "git+https://gitlab.redox-os.org/redox-os/mio#2092161d53366c07a064888ccb0d41d359383701" dependencies = [ "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -293,10 +307,20 @@ dependencies = [ "miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", - "slab 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "slab 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "mio-uds" +version = "0.6.6" +source = "git+https://gitlab.redox-os.org/redox-os/mio-uds#2936ef82070ea0c4aa8a7360455b8c512d8c88c0" +dependencies = [ + "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.15 (git+https://gitlab.redox-os.org/redox-os/mio)", +] + [[package]] name = "miow" version = "0.2.1" @@ -335,8 +359,8 @@ dependencies = [ "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio 0.1.7 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-reactor 0.1.2 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio 0.1.8 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-reactor 0.1.4 (git+https://gitlab.redox-os.org/redox-os/tokio)", ] [[package]] @@ -361,6 +385,34 @@ dependencies = [ "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "owning_ref" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "parking_lot" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "lock_api 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot_core 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "parking_lot_core" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "pbr" version = "1.0.1" @@ -383,6 +435,16 @@ name = "quick-error" version = "1.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "rand" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "rand" version = "0.5.4" @@ -495,9 +557,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "slab" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "smallvec" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "smoltcp" version = "0.4.0" @@ -508,6 +578,11 @@ dependencies = [ "managed 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "stable_deref_trait" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "termion" version = "1.5.1" @@ -530,63 +605,66 @@ dependencies = [ [[package]] name = "tokio" -version = "0.1.7" -source = "git+https://gitlab.redox-os.org/redox-os/tokio#12c80a60c2ac2f7c3ff62d0fd2dc98f99c91b378" +version = "0.1.8" +source = "git+https://gitlab.redox-os.org/redox-os/tokio#1a12087013a68747f6f59460ea95bd597b898dab" dependencies = [ + "bytes 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.6.15 (git+https://gitlab.redox-os.org/redox-os/mio)", - "tokio-current-thread 0.1.0 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-executor 0.1.2 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-fs 0.1.2 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-io 0.1.7 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-reactor 0.1.2 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-tcp 0.1.0 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-threadpool 0.1.5 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-timer 0.2.4 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-udp 0.1.1 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-codec 0.1.0 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-current-thread 0.1.1 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-executor 0.1.4 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-fs 0.1.3 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-io 0.1.8 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-reactor 0.1.4 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-tcp 0.1.1 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-threadpool 0.1.6 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-timer 0.2.6 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-udp 0.1.2 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-uds 0.2.1 (git+https://gitlab.redox-os.org/redox-os/tokio)", ] [[package]] name = "tokio-codec" version = "0.1.0" -source = "git+https://gitlab.redox-os.org/redox-os/tokio#12c80a60c2ac2f7c3ff62d0fd2dc98f99c91b378" +source = "git+https://gitlab.redox-os.org/redox-os/tokio#1a12087013a68747f6f59460ea95bd597b898dab" dependencies = [ "bytes 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-io 0.1.7 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-io 0.1.8 (git+https://gitlab.redox-os.org/redox-os/tokio)", ] [[package]] name = "tokio-current-thread" -version = "0.1.0" -source = "git+https://gitlab.redox-os.org/redox-os/tokio#12c80a60c2ac2f7c3ff62d0fd2dc98f99c91b378" +version = "0.1.1" +source = "git+https://gitlab.redox-os.org/redox-os/tokio#1a12087013a68747f6f59460ea95bd597b898dab" dependencies = [ "futures 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-executor 0.1.2 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-executor 0.1.4 (git+https://gitlab.redox-os.org/redox-os/tokio)", ] [[package]] name = "tokio-executor" -version = "0.1.2" -source = "git+https://gitlab.redox-os.org/redox-os/tokio#12c80a60c2ac2f7c3ff62d0fd2dc98f99c91b378" +version = "0.1.4" +source = "git+https://gitlab.redox-os.org/redox-os/tokio#1a12087013a68747f6f59460ea95bd597b898dab" dependencies = [ "futures 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "tokio-fs" -version = "0.1.2" -source = "git+https://gitlab.redox-os.org/redox-os/tokio#12c80a60c2ac2f7c3ff62d0fd2dc98f99c91b378" +version = "0.1.3" +source = "git+https://gitlab.redox-os.org/redox-os/tokio#1a12087013a68747f6f59460ea95bd597b898dab" dependencies = [ "futures 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-io 0.1.7 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-threadpool 0.1.5 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-io 0.1.8 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-threadpool 0.1.6 (git+https://gitlab.redox-os.org/redox-os/tokio)", ] [[package]] name = "tokio-io" -version = "0.1.7" -source = "git+https://gitlab.redox-os.org/redox-os/tokio#12c80a60c2ac2f7c3ff62d0fd2dc98f99c91b378" +version = "0.1.8" +source = "git+https://gitlab.redox-os.org/redox-os/tokio#1a12087013a68747f6f59460ea95bd597b898dab" dependencies = [ "bytes 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)", @@ -595,65 +673,87 @@ dependencies = [ [[package]] name = "tokio-reactor" -version = "0.1.2" -source = "git+https://gitlab.redox-os.org/redox-os/tokio#12c80a60c2ac2f7c3ff62d0fd2dc98f99c91b378" +version = "0.1.4" +source = "git+https://gitlab.redox-os.org/redox-os/tokio#1a12087013a68747f6f59460ea95bd597b898dab" dependencies = [ + "crossbeam-utils 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.6.15 (git+https://gitlab.redox-os.org/redox-os/mio)", - "slab 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-executor 0.1.2 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-io 0.1.7 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", + "slab 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-executor 0.1.4 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-io 0.1.8 (git+https://gitlab.redox-os.org/redox-os/tokio)", ] [[package]] name = "tokio-tcp" -version = "0.1.0" -source = "git+https://gitlab.redox-os.org/redox-os/tokio#12c80a60c2ac2f7c3ff62d0fd2dc98f99c91b378" +version = "0.1.1" +source = "git+https://gitlab.redox-os.org/redox-os/tokio#1a12087013a68747f6f59460ea95bd597b898dab" dependencies = [ "bytes 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)", "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.6.15 (git+https://gitlab.redox-os.org/redox-os/mio)", - "tokio-io 0.1.7 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-reactor 0.1.2 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-io 0.1.8 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-reactor 0.1.4 (git+https://gitlab.redox-os.org/redox-os/tokio)", ] [[package]] name = "tokio-threadpool" -version = "0.1.5" -source = "git+https://gitlab.redox-os.org/redox-os/tokio#12c80a60c2ac2f7c3ff62d0fd2dc98f99c91b378" +version = "0.1.6" +source = "git+https://gitlab.redox-os.org/redox-os/tokio#1a12087013a68747f6f59460ea95bd597b898dab" dependencies = [ - "crossbeam-deque 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam-utils 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-deque 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-executor 0.1.2 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-executor 0.1.4 (git+https://gitlab.redox-os.org/redox-os/tokio)", ] [[package]] name = "tokio-timer" -version = "0.2.4" -source = "git+https://gitlab.redox-os.org/redox-os/tokio#12c80a60c2ac2f7c3ff62d0fd2dc98f99c91b378" +version = "0.2.6" +source = "git+https://gitlab.redox-os.org/redox-os/tokio#1a12087013a68747f6f59460ea95bd597b898dab" dependencies = [ + "crossbeam-utils 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-executor 0.1.2 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "slab 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-executor 0.1.4 (git+https://gitlab.redox-os.org/redox-os/tokio)", ] [[package]] name = "tokio-udp" -version = "0.1.1" -source = "git+https://gitlab.redox-os.org/redox-os/tokio#12c80a60c2ac2f7c3ff62d0fd2dc98f99c91b378" +version = "0.1.2" +source = "git+https://gitlab.redox-os.org/redox-os/tokio#1a12087013a68747f6f59460ea95bd597b898dab" dependencies = [ "bytes 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.6.15 (git+https://gitlab.redox-os.org/redox-os/mio)", "tokio-codec 0.1.0 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-io 0.1.7 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-reactor 0.1.2 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-io 0.1.8 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-reactor 0.1.4 (git+https://gitlab.redox-os.org/redox-os/tokio)", +] + +[[package]] +name = "tokio-uds" +version = "0.2.1" +source = "git+https://gitlab.redox-os.org/redox-os/tokio#1a12087013a68747f6f59460ea95bd597b898dab" +dependencies = [ + "bytes 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)", + "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.15 (git+https://gitlab.redox-os.org/redox-os/mio)", + "mio-uds 0.6.6 (git+https://gitlab.redox-os.org/redox-os/mio-uds)", + "tokio-io 0.1.8 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-reactor 0.1.4 (git+https://gitlab.redox-os.org/redox-os/tokio)", ] [[package]] @@ -687,6 +787,14 @@ name = "unicode-normalization" version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "unreachable" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "untrusted" version = "0.5.1" @@ -707,6 +815,11 @@ name = "version_check" version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "void" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "webpki" version = "0.14.0" @@ -775,11 +888,12 @@ dependencies = [ "checksum cfg-if 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "efe5c877e17a9c717a0bf3613b2709f723202c4e4675cc8f12926ded29bcb17e" "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" "checksum crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f739f8c5363aca78cfb059edf753d8f0d36908c348f3d8d1503f03d8b75d9cf3" -"checksum crossbeam-deque 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ce1357a7a2ad69ff9f090ee8641b5b94c622138bb2c3eae16ad7917a8e35a801" +"checksum crossbeam-deque 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3486aefc4c0487b9cb52372c97df0a48b8c249514af1ee99703bf70d2f2ceda1" "checksum crossbeam-epoch 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "927121f5407de9956180ff5e936fe3cf4324279280001cd56b669d28ee7e9150" "checksum crossbeam-epoch 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "285987a59c4d91388e749850e3cb7b3a92299668528caaacd08005b8f238c0ea" "checksum crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2760899e32a1d58d5abb31129f8fae5de75220bc2176e77ff7c627ae45c918d9" "checksum crossbeam-utils 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ea52fab26a99d96cdff39d0ca75c9716125937f5dba2ab83923aaaf5928f684a" +"checksum crossbeam-utils 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "677d453a17e8bd2b913fa38e8b9cf04bcdbb5be790aa294f2389661d72036015" "checksum dns-parser 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f7020f6760aea312d43d23cb83bf6c0c49f162541db8b02bf95209ac51dc253d" "checksum extra 0.1.0 (git+https://gitlab.redox-os.org/redox-os/libextra.git)" = "" "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" @@ -797,6 +911,7 @@ dependencies = [ "checksum lazy_static 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "fb497c35d362b6a331cfd94956a07fc2c78a4604cdbee844a81170386b996dd3" "checksum lazycell 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d33a48d0365c96081958cc663eef834975cb1e8d8bea3378513fc72bdbf11e50" "checksum libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)" = "b685088df2b950fccadf07a7187c8ef846a959c142338a48f9dc0b94517eb5f1" +"checksum lock_api 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "949826a5ccf18c1b3a7c3d57692778d21768b79e46eb9dd07bfc4c2160036c54" "checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" "checksum log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "61bd98ae7f7b754bc53dca7d44b604f733c6bba044ea6f41bc8d89272d8161d2" "checksum managed 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fdcec5e97041c7f0f1c5b7d93f12e57293c831c646f4cc7a5db59460c7ea8de6" @@ -804,15 +919,20 @@ dependencies = [ "checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3" "checksum mime 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ba626b8a6de5da682e1caa06bdb42a335aee5a84db8e5046a3e8ab17ba0a3ae0" "checksum mio 0.6.15 (git+https://gitlab.redox-os.org/redox-os/mio)" = "" +"checksum mio-uds 0.6.6 (git+https://gitlab.redox-os.org/redox-os/mio-uds)" = "" "checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919" "checksum net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "42550d9fb7b6684a6d404d9fa7250c2eb2646df731d1c06afc06dcee9e1bcf88" "checksum netutils 0.1.0 (git+https://gitlab.redox-os.org/redox-os/netutils.git)" = "" "checksum nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "9a2228dca57108069a5262f2ed8bd2e82496d2e074a06d1ccc7ce1687b6ae0a2" "checksum ntpclient 0.0.1 (git+https://github.com/willem66745/ntpclient-rust)" = "" "checksum num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c51a3322e4bca9d212ad9a158a02abc6934d005490c054a2778df73a70aa0a30" +"checksum owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cdf84f41639e037b484f93433aa3897863b561ed65c6e59c7073d7c561710f37" +"checksum parking_lot 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "69376b761943787ebd5cc85a5bc95958651a22609c5c1c2b65de21786baec72b" +"checksum parking_lot_core 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "4db1a8ccf734a7bce794cc19b3df06ed87ab2f3907036b693c68f56b4d4537fa" "checksum pbr 1.0.1 (git+https://github.com/a8m/pb)" = "" "checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" "checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0" +"checksum rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8356f47b32624fef5b3301c1be97e5944ecdd595409cc5da11d05f211db6cfbd" "checksum rand 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "12397506224b2f93e6664ffc4f664b29be8208e5157d3d90b44f09b5fae470ea" "checksum rand_core 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "edecf0f94da5551fc9b492093e30b041a891657db7940ee221f9d2f66e82eef2" "checksum rayon 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a77c51c07654ddd93f6cb543c7a849863b03abc7e82591afda6dc8ad4ac3ac4a" @@ -825,29 +945,34 @@ dependencies = [ "checksum rustls 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "17727f4b991294da2c84d75a43c003151ff58072212768800f66c56ee46dca43" "checksum safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e27a8b19b835f7aea908818e871f5cc3a5a186550c30773be987e155e8163d8f" "checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" -"checksum slab 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fdeff4cd9ecff59ec7e3744cbca73dfe5ac35c2aedb2cfba8a1c715a18912e9d" +"checksum slab 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5f9776d6b986f77b35c6cf846c11ad986ff128fe0b2b63a3628e3755e8d3102d" +"checksum smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "153ffa32fd170e9944f7e0838edf824a754ec4c1fc64746fcc9fe1f8fa602e5d" "checksum smoltcp 0.4.0 (git+https://github.com/m-labs/smoltcp.git?rev=682fc3078229a4fc06b5f021af058c45b9f3bc02)" = "" +"checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" "checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" "checksum time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "d825be0eb33fda1a7e68012d51e9c7f451dc1a69391e7fdc197060bb8c56667b" -"checksum tokio 0.1.7 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" +"checksum tokio 0.1.8 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" "checksum tokio-codec 0.1.0 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" -"checksum tokio-current-thread 0.1.0 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" -"checksum tokio-executor 0.1.2 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" -"checksum tokio-fs 0.1.2 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" -"checksum tokio-io 0.1.7 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" -"checksum tokio-reactor 0.1.2 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" -"checksum tokio-tcp 0.1.0 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" -"checksum tokio-threadpool 0.1.5 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" -"checksum tokio-timer 0.2.4 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" -"checksum tokio-udp 0.1.1 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" +"checksum tokio-current-thread 0.1.1 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" +"checksum tokio-executor 0.1.4 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" +"checksum tokio-fs 0.1.3 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" +"checksum tokio-io 0.1.8 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" +"checksum tokio-reactor 0.1.4 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" +"checksum tokio-tcp 0.1.1 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" +"checksum tokio-threadpool 0.1.6 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" +"checksum tokio-timer 0.2.6 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" +"checksum tokio-udp 0.1.2 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" +"checksum tokio-uds 0.2.1 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" "checksum traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079" "checksum typeable 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1410f6f91f21d1612654e7cc69193b0334f909dcf2c790c4826254fbb86f8887" "checksum unicase 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7f4765f83163b74f957c797ad9253caf97f103fb064d3999aea9568d09fc8a33" "checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" "checksum unicode-normalization 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "6a0180bc61fc5a987082bfa111f4cc95c4caff7f9799f3e46df09163a937aa25" +"checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56" "checksum untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f392d7819dbe58833e26872f5f6f0d68b7bbbe90fc3667e98731c4a15ad9a7ae" "checksum url 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2a321979c09843d272956e73700d12c4e7d3d92b2ee112b31548aef0d4efc5a6" "checksum version_check 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "7716c242968ee87e5542f8021178248f267f295a5c4803beae8b8b7fd9bc6051" +"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" "checksum webpki 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e499345fc4c6b7c79a5b8756d4592c4305510a13512e79efafe00dfbd67bbac6" "checksum webpki-roots 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5bfb3f50499f21ad2317f442845e3b5805b007f1e728f59885c99e61b8c181a7" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" From 4dd40fa37338e78934485146b249a70542972f41 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Thu, 20 Sep 2018 14:22:30 -0700 Subject: [PATCH 087/155] Implement fgetfl, fsetfl for null --- src/smolnetd/scheme/socket.rs | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/smolnetd/scheme/socket.rs b/src/smolnetd/scheme/socket.rs index 88ef59c961..70e3e5251d 100644 --- a/src/smolnetd/scheme/socket.rs +++ b/src/smolnetd/scheme/socket.rs @@ -711,21 +711,32 @@ where } fn fcntl(&mut self, fd: usize, cmd: usize, arg: usize) -> SyscallResult> { - let file = self.files - .get_mut(&fd) - .ok_or_else(|| SyscallError::new(syscall::EBADF))?; - - if let SchemeFile::Socket(ref mut socket_file) = *file { + if let Some(ref mut null) = self.nulls.get_mut(&fd) { match cmd { - syscall::F_GETFL => Ok(Some(socket_file.flags)), + syscall::F_GETFL => Ok(Some(null.flags)), syscall::F_SETFL => { - socket_file.flags = arg & !syscall::O_ACCMODE; + null.flags = arg & !syscall::O_ACCMODE; Ok(Some(0)) } _ => Err(SyscallError::new(syscall::EINVAL)), } } else { - Err(SyscallError::new(syscall::EBADF)) + let file = self.files + .get_mut(&fd) + .ok_or_else(|| SyscallError::new(syscall::EBADF))?; + + if let SchemeFile::Socket(ref mut socket_file) = *file { + match cmd { + syscall::F_GETFL => Ok(Some(socket_file.flags)), + syscall::F_SETFL => { + socket_file.flags = arg & !syscall::O_ACCMODE; + Ok(Some(0)) + } + _ => Err(SyscallError::new(syscall::EINVAL)), + } + } else { + Err(SyscallError::new(syscall::EBADF)) + } } } } From 3f7bf2a687df70a4ded699d59144146b71fbe755 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sun, 14 Oct 2018 19:56:35 -0600 Subject: [PATCH 088/155] Update Cargo.lock --- Cargo.lock | 424 ++++++++++++++++++++++++++--------------------------- 1 file changed, 204 insertions(+), 220 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 26eec8947e..4bb03d94b7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -16,13 +16,22 @@ name = "base64" version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "byteorder 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "base64" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "safemem 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "bitflags" -version = "1.0.3" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -32,21 +41,26 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "byteorder" -version = "1.2.3" +version = "1.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "bytes" -version = "0.4.9" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "byteorder 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "cc" +version = "1.0.25" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "cfg-if" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -54,16 +68,7 @@ name = "cloudabi" version = "0.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "crossbeam-deque" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "crossbeam-epoch 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -71,50 +76,23 @@ name = "crossbeam-deque" version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "crossbeam-epoch 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-epoch 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-utils 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "crossbeam-epoch" -version = "0.3.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "crossbeam-epoch" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam-utils 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "crossbeam-utils" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cfg-if 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "crossbeam-utils" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "crossbeam-utils" version = "0.5.0" @@ -125,7 +103,7 @@ name = "dns-parser" version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "byteorder 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -139,7 +117,7 @@ name = "fuchsia-zircon" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -150,17 +128,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "futures" -version = "0.1.23" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "gcc" -version = "0.3.54" +version = "0.1.25" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "httparse" -version = "1.3.2" +version = "1.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -169,7 +142,7 @@ version = "0.10.13" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "base64 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "httparse 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "httparse 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "mime 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -183,12 +156,13 @@ dependencies = [ [[package]] name = "hyper-rustls" -version = "0.6.1" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "hyper 0.10.13 (registry+https://github.com/rust-lang/crates.io-index)", - "rustls 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "webpki-roots 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustls 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)", + "webpki 0.18.1 (registry+https://github.com/rust-lang/crates.io-index)", + "webpki-roots 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -196,7 +170,7 @@ name = "idna" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "matches 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-normalization 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -206,7 +180,7 @@ name = "iovec" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -226,27 +200,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "lazy_static" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "lazy_static" -version = "1.0.2" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", +] [[package]] name = "lazycell" -version = "1.0.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libc" -version = "0.2.42" +version = "0.2.43" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "lock_api" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -258,15 +230,15 @@ name = "log" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "log" -version = "0.4.3" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -276,7 +248,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "matches" -version = "0.1.7" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -295,15 +267,15 @@ dependencies = [ [[package]] name = "mio" version = "0.6.15" -source = "git+https://gitlab.redox-os.org/redox-os/mio#2092161d53366c07a064888ccb0d41d359383701" +source = "git+https://gitlab.redox-os.org/redox-os/mio#8a4c08faee0483976bd345b6d88d2455e4c1a4db" dependencies = [ "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "lazycell 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "lazycell 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", @@ -317,7 +289,7 @@ version = "0.6.6" source = "git+https://gitlab.redox-os.org/redox-os/mio-uds#2936ef82070ea0c4aa8a7360455b8c512d8c88c0" dependencies = [ "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.6.15 (git+https://gitlab.redox-os.org/redox-os/mio)", ] @@ -337,21 +309,21 @@ name = "net2" version = "0.2.33" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "netutils" version = "0.1.0" -source = "git+https://gitlab.redox-os.org/redox-os/netutils.git#c728870d6a1d9d8938117798e6caab22b09c37a6" +source = "git+https://gitlab.redox-os.org/redox-os/netutils.git#2dee37719bd1bf1fbe3d0fdd33e350d32dda1330" dependencies = [ "arg_parser 0.1.0 (git+https://gitlab.redox-os.org/redox-os/arg-parser.git)", "extra 0.1.0 (git+https://gitlab.redox-os.org/redox-os/libextra.git)", "hyper 0.10.13 (registry+https://github.com/rust-lang/crates.io-index)", - "hyper-rustls 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", + "hyper-rustls 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.6.15 (git+https://gitlab.redox-os.org/redox-os/mio)", "ntpclient 0.0.1 (git+https://github.com/willem66745/ntpclient-rust)", "pbr 1.0.1 (git+https://github.com/a8m/pb)", @@ -382,7 +354,7 @@ name = "num_cpus" version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -395,31 +367,32 @@ dependencies = [ [[package]] name = "parking_lot" -version = "0.6.3" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "lock_api 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot_core 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", + "lock_api 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "parking_lot_core" -version = "0.2.14" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "pbr" version = "1.0.1" -source = "git+https://github.com/a8m/pb#e0ab10be58c79d58dcdda9b79a82d28c54b3b4e3" +source = "git+https://github.com/a8m/pb#8774a4627dabfacb1d0c80f409232c4f82231119" dependencies = [ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -437,49 +410,28 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "rand" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "rand" -version = "0.5.4" +version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_core 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rand_core" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "rayon" -version = "0.7.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "rayon-core 1.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] -name = "rayon-core" -version = "1.4.1" +name = "rand_core" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", - "num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", -] [[package]] name = "redox_event" @@ -493,7 +445,7 @@ dependencies = [ name = "redox_netstack" version = "0.1.0" dependencies = [ - "byteorder 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "dns-parser 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "netutils 0.1.0 (git+https://gitlab.redox-os.org/redox-os/netutils.git)", @@ -505,7 +457,7 @@ dependencies = [ [[package]] name = "redox_syscall" version = "0.1.40" -source = "git+https://gitlab.redox-os.org/redox-os/syscall.git#e7e212960095d3e79f902807bb6b811f51eb62b6" +source = "git+https://gitlab.redox-os.org/redox-os/syscall.git#85598a1c33adc772974a7059f3c303ab4391e9f3" [[package]] name = "redox_syscall" @@ -522,27 +474,34 @@ dependencies = [ [[package]] name = "ring" -version = "0.11.0" +version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", - "rayon 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", + "untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rustc_version" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rustls" -version = "0.9.0" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "base64 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", - "ring 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", - "time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", - "untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "webpki 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", + "base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", + "ring 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)", + "sct 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "webpki 0.18.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -550,11 +509,38 @@ name = "safemem" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "safemem" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "scopeguard" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "sct" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "ring 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)", + "untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "semver" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "semver-parser" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "slab" version = "0.4.1" @@ -573,8 +559,8 @@ name = "smoltcp" version = "0.4.0" source = "git+https://github.com/m-labs/smoltcp.git?rev=682fc3078229a4fc06b5f021af058c45b9f3bc02#682fc3078229a4fc06b5f021af058c45b9f3bc02" dependencies = [ - "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "byteorder 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "managed 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -588,7 +574,7 @@ name = "termion" version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -598,9 +584,9 @@ name = "time" version = "0.1.40" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -608,8 +594,8 @@ name = "tokio" version = "0.1.8" source = "git+https://gitlab.redox-os.org/redox-os/tokio#1a12087013a68747f6f59460ea95bd597b898dab" dependencies = [ - "bytes 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.6.15 (git+https://gitlab.redox-os.org/redox-os/mio)", "tokio-codec 0.1.0 (git+https://gitlab.redox-os.org/redox-os/tokio)", "tokio-current-thread 0.1.1 (git+https://gitlab.redox-os.org/redox-os/tokio)", @@ -629,8 +615,8 @@ name = "tokio-codec" version = "0.1.0" source = "git+https://gitlab.redox-os.org/redox-os/tokio#1a12087013a68747f6f59460ea95bd597b898dab" dependencies = [ - "bytes 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.8 (git+https://gitlab.redox-os.org/redox-os/tokio)", ] @@ -639,7 +625,7 @@ name = "tokio-current-thread" version = "0.1.1" source = "git+https://gitlab.redox-os.org/redox-os/tokio#1a12087013a68747f6f59460ea95bd597b898dab" dependencies = [ - "futures 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-executor 0.1.4 (git+https://gitlab.redox-os.org/redox-os/tokio)", ] @@ -648,7 +634,7 @@ name = "tokio-executor" version = "0.1.4" source = "git+https://gitlab.redox-os.org/redox-os/tokio#1a12087013a68747f6f59460ea95bd597b898dab" dependencies = [ - "futures 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -656,7 +642,7 @@ name = "tokio-fs" version = "0.1.3" source = "git+https://gitlab.redox-os.org/redox-os/tokio#1a12087013a68747f6f59460ea95bd597b898dab" dependencies = [ - "futures 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.8 (git+https://gitlab.redox-os.org/redox-os/tokio)", "tokio-threadpool 0.1.6 (git+https://gitlab.redox-os.org/redox-os/tokio)", ] @@ -666,9 +652,9 @@ name = "tokio-io" version = "0.1.8" source = "git+https://gitlab.redox-os.org/redox-os/tokio#1a12087013a68747f6f59460ea95bd597b898dab" dependencies = [ - "bytes 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -677,12 +663,12 @@ version = "0.1.4" source = "git+https://gitlab.redox-os.org/redox-os/tokio#1a12087013a68747f6f59460ea95bd597b898dab" dependencies = [ "crossbeam-utils 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.6.15 (git+https://gitlab.redox-os.org/redox-os/mio)", "num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", "slab 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-executor 0.1.4 (git+https://gitlab.redox-os.org/redox-os/tokio)", "tokio-io 0.1.8 (git+https://gitlab.redox-os.org/redox-os/tokio)", @@ -693,8 +679,8 @@ name = "tokio-tcp" version = "0.1.1" source = "git+https://gitlab.redox-os.org/redox-os/tokio#1a12087013a68747f6f59460ea95bd597b898dab" dependencies = [ - "bytes 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.6.15 (git+https://gitlab.redox-os.org/redox-os/mio)", "tokio-io 0.1.8 (git+https://gitlab.redox-os.org/redox-os/tokio)", @@ -708,10 +694,10 @@ source = "git+https://gitlab.redox-os.org/redox-os/tokio#1a12087013a68747f6f5946 dependencies = [ "crossbeam-deque 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-utils 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-executor 0.1.4 (git+https://gitlab.redox-os.org/redox-os/tokio)", ] @@ -721,7 +707,7 @@ version = "0.2.6" source = "git+https://gitlab.redox-os.org/redox-os/tokio#1a12087013a68747f6f59460ea95bd597b898dab" dependencies = [ "crossbeam-utils 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "slab 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-executor 0.1.4 (git+https://gitlab.redox-os.org/redox-os/tokio)", ] @@ -731,9 +717,9 @@ name = "tokio-udp" version = "0.1.2" source = "git+https://gitlab.redox-os.org/redox-os/tokio#1a12087013a68747f6f59460ea95bd597b898dab" dependencies = [ - "bytes 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.6.15 (git+https://gitlab.redox-os.org/redox-os/mio)", "tokio-codec 0.1.0 (git+https://gitlab.redox-os.org/redox-os/tokio)", "tokio-io 0.1.8 (git+https://gitlab.redox-os.org/redox-os/tokio)", @@ -745,11 +731,11 @@ name = "tokio-uds" version = "0.2.1" source = "git+https://gitlab.redox-os.org/redox-os/tokio#1a12087013a68747f6f59460ea95bd597b898dab" dependencies = [ - "bytes 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.6.15 (git+https://gitlab.redox-os.org/redox-os/mio)", "mio-uds 0.6.6 (git+https://gitlab.redox-os.org/redox-os/mio-uds)", "tokio-io 0.1.8 (git+https://gitlab.redox-os.org/redox-os/tokio)", @@ -771,7 +757,7 @@ name = "unicase" version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "version_check 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -779,7 +765,7 @@ name = "unicode-bidi" version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "matches 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -797,7 +783,7 @@ dependencies = [ [[package]] name = "untrusted" -version = "0.5.1" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -806,13 +792,13 @@ version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "matches 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "version_check" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -822,21 +808,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "webpki" -version = "0.14.0" +version = "0.18.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "ring 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", - "time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", - "untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "ring 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)", + "untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "webpki-roots" -version = "0.11.0" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "webpki 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", + "untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "webpki 0.18.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -846,7 +831,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "winapi" -version = "0.3.5" +version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -881,41 +866,37 @@ dependencies = [ "checksum arg_parser 0.1.0 (git+https://gitlab.redox-os.org/redox-os/arg-parser.git)" = "" "checksum arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)" = "a1e964f9e24d588183fcb43503abda40d288c8657dfc27311516ce2f05675aef" "checksum base64 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "96434f987501f0ed4eb336a411e0631ecd1afa11574fe148587adc4ff96143c9" -"checksum bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d0c54bb8f454c567f21197eefcdbf5679d0bd99f2ddbe52e84c77061952e6789" +"checksum base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)" = "489d6c0ed21b11d038c31b6ceccca973e65d73ba3bd8ecb9a2babf5546164643" +"checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12" "checksum byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855" -"checksum byteorder 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "74c0b906e9446b0a2e4f760cdb3fa4b2c48cdc6db8766a845c54b6ff063fd2e9" -"checksum bytes 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e178b8e0e239e844b083d5a0d4a156b2654e67f9f80144d48398fcd736a24fb8" -"checksum cfg-if 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "efe5c877e17a9c717a0bf3613b2709f723202c4e4675cc8f12926ded29bcb17e" +"checksum byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "90492c5858dd7d2e78691cfb89f90d273a2800fc11d98f60786e5d87e2f83781" +"checksum bytes 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "0ce55bd354b095246fc34caf4e9e242f5297a7fd938b090cadfea6eee614aa62" +"checksum cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)" = "f159dfd43363c4d08055a07703eb7a3406b0dac4d0584d96965a3262db3c9d16" +"checksum cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0c4e7bb64a8ebb0d856483e1e682ea3422f883c5f5615a90d51a2c82fe87fdd3" "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" -"checksum crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f739f8c5363aca78cfb059edf753d8f0d36908c348f3d8d1503f03d8b75d9cf3" "checksum crossbeam-deque 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3486aefc4c0487b9cb52372c97df0a48b8c249514af1ee99703bf70d2f2ceda1" -"checksum crossbeam-epoch 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "927121f5407de9956180ff5e936fe3cf4324279280001cd56b669d28ee7e9150" -"checksum crossbeam-epoch 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "285987a59c4d91388e749850e3cb7b3a92299668528caaacd08005b8f238c0ea" -"checksum crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2760899e32a1d58d5abb31129f8fae5de75220bc2176e77ff7c627ae45c918d9" -"checksum crossbeam-utils 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ea52fab26a99d96cdff39d0ca75c9716125937f5dba2ab83923aaaf5928f684a" +"checksum crossbeam-epoch 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "30fecfcac6abfef8771151f8be4abc9e4edc112c2bcb233314cafde2680536e9" "checksum crossbeam-utils 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "677d453a17e8bd2b913fa38e8b9cf04bcdbb5be790aa294f2389661d72036015" "checksum dns-parser 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f7020f6760aea312d43d23cb83bf6c0c49f162541db8b02bf95209ac51dc253d" "checksum extra 0.1.0 (git+https://gitlab.redox-os.org/redox-os/libextra.git)" = "" "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" "checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" -"checksum futures 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)" = "884dbe32a6ae4cd7da5c6db9b78114449df9953b8d490c9d7e1b51720b922c62" -"checksum gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)" = "5e33ec290da0d127825013597dbdfc28bee4964690c7ce1166cbc2a7bd08b1bb" -"checksum httparse 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7b6288d7db100340ca12873fd4d08ad1b8f206a9457798dfb17c018a33fee540" +"checksum futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)" = "49e7653e374fe0d0c12de4250f0bdb60680b8c80eed558c5c7538eec9c89e21b" +"checksum httparse 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e8734b0cfd3bc3e101ec59100e101c2eecd19282202e87808b3037b442777a83" "checksum hyper 0.10.13 (registry+https://github.com/rust-lang/crates.io-index)" = "368cb56b2740ebf4230520e2b90ebb0461e69034d85d1945febd9b3971426db2" -"checksum hyper-rustls 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "04535774f79684c99528944ebdb89756c945c027e55ce52faa245879d836c8fb" +"checksum hyper-rustls 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "71f7b2e5858ab9e19771dc361159f09ee5031734a6f7471fe0947db0238d92b7" "checksum idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e" "checksum iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dbe6e417e7d0975db6512b90796e8ce223145ac4e33c377e4a42882a0e88bb08" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a" -"checksum lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "76f033c7ad61445c5b347c7382dd1237847eb1bce590fe50365dcb33d546be73" -"checksum lazy_static 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "fb497c35d362b6a331cfd94956a07fc2c78a4604cdbee844a81170386b996dd3" -"checksum lazycell 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d33a48d0365c96081958cc663eef834975cb1e8d8bea3378513fc72bdbf11e50" -"checksum libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)" = "b685088df2b950fccadf07a7187c8ef846a959c142338a48f9dc0b94517eb5f1" -"checksum lock_api 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "949826a5ccf18c1b3a7c3d57692778d21768b79e46eb9dd07bfc4c2160036c54" +"checksum lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca488b89a5657b0a2ecd45b95609b3e848cf1755da332a0da46e2b2b1cb371a7" +"checksum lazycell 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ddba4c30a78328befecec92fc94970e53b3ae385827d28620f0f5bb2493081e0" +"checksum libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)" = "76e3a3ef172f1a0b9a9ff0dd1491ae5e6c948b94479a3021819ba7d860c8645d" +"checksum lock_api 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "775751a3e69bde4df9b38dd00a1b5d6ac13791e4223d4a0506577f0dd27cfb7a" "checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" -"checksum log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "61bd98ae7f7b754bc53dca7d44b604f733c6bba044ea6f41bc8d89272d8161d2" +"checksum log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "d4fcce5fa49cc693c312001daf1d13411c4a5283796bac1084299ea3e567113f" "checksum managed 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fdcec5e97041c7f0f1c5b7d93f12e57293c831c646f4cc7a5db59460c7ea8de6" -"checksum matches 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "835511bab37c34c47da5cb44844bea2cfde0236db0b506f90ea4224482c9774a" +"checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" "checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3" "checksum mime 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ba626b8a6de5da682e1caa06bdb42a335aee5a84db8e5046a3e8ab17ba0a3ae0" "checksum mio 0.6.15 (git+https://gitlab.redox-os.org/redox-os/mio)" = "" @@ -927,24 +908,27 @@ dependencies = [ "checksum ntpclient 0.0.1 (git+https://github.com/willem66745/ntpclient-rust)" = "" "checksum num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c51a3322e4bca9d212ad9a158a02abc6934d005490c054a2778df73a70aa0a30" "checksum owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cdf84f41639e037b484f93433aa3897863b561ed65c6e59c7073d7c561710f37" -"checksum parking_lot 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "69376b761943787ebd5cc85a5bc95958651a22609c5c1c2b65de21786baec72b" -"checksum parking_lot_core 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "4db1a8ccf734a7bce794cc19b3df06ed87ab2f3907036b693c68f56b4d4537fa" +"checksum parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "f0802bff09003b291ba756dc7e79313e51cc31667e94afbe847def490424cde5" +"checksum parking_lot_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ad7f7e6ebdc79edff6fdcb87a55b620174f7a989e3eb31b65231f4af57f00b8c" "checksum pbr 1.0.1 (git+https://github.com/a8m/pb)" = "" "checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" "checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0" -"checksum rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8356f47b32624fef5b3301c1be97e5944ecdd595409cc5da11d05f211db6cfbd" -"checksum rand 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "12397506224b2f93e6664ffc4f664b29be8208e5157d3d90b44f09b5fae470ea" -"checksum rand_core 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "edecf0f94da5551fc9b492093e30b041a891657db7940ee221f9d2f66e82eef2" -"checksum rayon 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a77c51c07654ddd93f6cb543c7a849863b03abc7e82591afda6dc8ad4ac3ac4a" -"checksum rayon-core 1.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b055d1e92aba6877574d8fe604a63c8b5df60f60e5982bf7ccbb1338ea527356" +"checksum rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e464cd887e869cddcae8792a4ee31d23c7edd516700695608f5b98c67ee0131c" +"checksum rand_core 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1961a422c4d189dfb50ffa9320bf1f2a9bd54ecb92792fb9477f99a1045f3372" +"checksum rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0905b6b7079ec73b314d4c748701f6931eb79fd97c668caa3f1899b22b32c6db" "checksum redox_event 0.1.0 (git+https://gitlab.redox-os.org/redox-os/event.git)" = "" "checksum redox_syscall 0.1.40 (git+https://gitlab.redox-os.org/redox-os/syscall.git)" = "" "checksum redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "c214e91d3ecf43e9a4e41e578973adeb14b474f2bee858742d127af75a0112b1" "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" -"checksum ring 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1f2a6dc7fc06a05e6de183c5b97058582e9da2de0c136eafe49609769c507724" -"checksum rustls 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "17727f4b991294da2c84d75a43c003151ff58072212768800f66c56ee46dca43" +"checksum ring 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dbe642b9dd1ba0038d78c4a3999d1ee56178b4d415c1e1fbaba83b06dce012f0" +"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" +"checksum rustls 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)" = "942b71057b31981152970d57399c25f72e27a6ee0d207a669d8304cabf44705b" "checksum safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e27a8b19b835f7aea908818e871f5cc3a5a186550c30773be987e155e8163d8f" +"checksum safemem 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dca453248a96cb0749e36ccdfe2b0b4e54a61bfef89fb97ec621eb8e0a93dd9" "checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" +"checksum sct 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cb8f61f9e6eadd062a71c380043d28036304a4706b3c4dd001ff3387ed00745a" +"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" +"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" "checksum slab 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5f9776d6b986f77b35c6cf846c11ad986ff128fe0b2b63a3628e3755e8d3102d" "checksum smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "153ffa32fd170e9944f7e0838edf824a754ec4c1fc64746fcc9fe1f8fa602e5d" "checksum smoltcp 0.4.0 (git+https://github.com/m-labs/smoltcp.git?rev=682fc3078229a4fc06b5f021af058c45b9f3bc02)" = "" @@ -969,14 +953,14 @@ dependencies = [ "checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" "checksum unicode-normalization 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "6a0180bc61fc5a987082bfa111f4cc95c4caff7f9799f3e46df09163a937aa25" "checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56" -"checksum untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f392d7819dbe58833e26872f5f6f0d68b7bbbe90fc3667e98731c4a15ad9a7ae" +"checksum untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "55cd1f4b4e96b46aeb8d4855db4a7a9bd96eeeb5c6a1ab54593328761642ce2f" "checksum url 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2a321979c09843d272956e73700d12c4e7d3d92b2ee112b31548aef0d4efc5a6" -"checksum version_check 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "7716c242968ee87e5542f8021178248f267f295a5c4803beae8b8b7fd9bc6051" +"checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd" "checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" -"checksum webpki 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e499345fc4c6b7c79a5b8756d4592c4305510a13512e79efafe00dfbd67bbac6" -"checksum webpki-roots 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5bfb3f50499f21ad2317f442845e3b5805b007f1e728f59885c99e61b8c181a7" +"checksum webpki 0.18.1 (registry+https://github.com/rust-lang/crates.io-index)" = "17d7967316d8411ca3b01821ee6c332bde138ba4363becdb492f12e514daa17f" +"checksum webpki-roots 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "85d1f408918fd590908a70d36b7ac388db2edc221470333e4d6e5b598e44cabf" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" -"checksum winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "773ef9dcc5f24b7d850d0ff101e542ff24c3b090a9768e03ff889fdef41f00fd" +"checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0" "checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" From 6a9fa0060356731e19203b8cb0c1946a4361c3df Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Mon, 29 Oct 2018 19:54:53 -0600 Subject: [PATCH 089/155] Update smolnetd --- Cargo.lock | 81 +++++++++++++++---------------------- Cargo.toml | 3 +- src/smolnetd/scheme/icmp.rs | 5 +-- 3 files changed, 36 insertions(+), 53 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4bb03d94b7..e823e030cc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,21 +11,12 @@ dependencies = [ "nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "base64" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", - "safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "base64" version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", "safemem 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -41,7 +32,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "byteorder" -version = "1.2.6" +version = "1.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -49,7 +40,7 @@ name = "bytes" version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -60,7 +51,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "cfg-if" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -86,7 +77,7 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-utils 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -103,7 +94,7 @@ name = "dns-parser" version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", "quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -138,10 +129,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "hyper" -version = "0.10.13" +version = "0.10.15" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "base64 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)", "httparse 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", @@ -159,7 +150,7 @@ name = "hyper-rustls" version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "hyper 0.10.13 (registry+https://github.com/rust-lang/crates.io-index)", + "hyper 0.10.15 (registry+https://github.com/rust-lang/crates.io-index)", "rustls 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)", "webpki 0.18.1 (registry+https://github.com/rust-lang/crates.io-index)", "webpki-roots 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -230,15 +221,15 @@ name = "log" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "log" -version = "0.4.5" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -275,7 +266,7 @@ dependencies = [ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazycell 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", @@ -309,7 +300,7 @@ name = "net2" version = "0.2.33" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -317,11 +308,11 @@ dependencies = [ [[package]] name = "netutils" version = "0.1.0" -source = "git+https://gitlab.redox-os.org/redox-os/netutils.git#2dee37719bd1bf1fbe3d0fdd33e350d32dda1330" +source = "git+https://gitlab.redox-os.org/redox-os/netutils.git#a5109b810ce7abffe4736aa3d5836d6321a13a9d" dependencies = [ "arg_parser 0.1.0 (git+https://gitlab.redox-os.org/redox-os/arg-parser.git)", "extra 0.1.0 (git+https://gitlab.redox-os.org/redox-os/libextra.git)", - "hyper 0.10.13 (registry+https://github.com/rust-lang/crates.io-index)", + "hyper 0.10.15 (registry+https://github.com/rust-lang/crates.io-index)", "hyper-rustls 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.6.15 (git+https://gitlab.redox-os.org/redox-os/mio)", @@ -333,6 +324,7 @@ dependencies = [ "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio 0.1.8 (git+https://gitlab.redox-os.org/redox-os/tokio)", "tokio-reactor 0.1.4 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "url 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -445,13 +437,13 @@ dependencies = [ name = "redox_netstack" version = "0.1.0" dependencies = [ - "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", "dns-parser 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "netutils 0.1.0 (git+https://gitlab.redox-os.org/redox-os/netutils.git)", "redox_event 0.1.0 (git+https://gitlab.redox-os.org/redox-os/event.git)", "redox_syscall 0.1.40 (git+https://gitlab.redox-os.org/redox-os/syscall.git)", - "smoltcp 0.4.0 (git+https://github.com/m-labs/smoltcp.git?rev=682fc3078229a4fc06b5f021af058c45b9f3bc02)", + "smoltcp 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -497,18 +489,13 @@ version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "ring 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)", "sct 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "webpki 0.18.1 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "safemem" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "safemem" version = "0.3.0" @@ -556,11 +543,11 @@ dependencies = [ [[package]] name = "smoltcp" -version = "0.4.0" -source = "git+https://github.com/m-labs/smoltcp.git?rev=682fc3078229a4fc06b5f021af058c45b9f3bc02#682fc3078229a4fc06b5f021af058c45b9f3bc02" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", "managed 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -654,7 +641,7 @@ source = "git+https://gitlab.redox-os.org/redox-os/tokio#1a12087013a68747f6f5946 dependencies = [ "bytes 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -665,7 +652,7 @@ dependencies = [ "crossbeam-utils 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.6.15 (git+https://gitlab.redox-os.org/redox-os/mio)", "num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -695,7 +682,7 @@ dependencies = [ "crossbeam-deque 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-utils 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-executor 0.1.4 (git+https://gitlab.redox-os.org/redox-os/tokio)", @@ -719,7 +706,7 @@ source = "git+https://gitlab.redox-os.org/redox-os/tokio#1a12087013a68747f6f5946 dependencies = [ "bytes 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.6.15 (git+https://gitlab.redox-os.org/redox-os/mio)", "tokio-codec 0.1.0 (git+https://gitlab.redox-os.org/redox-os/tokio)", "tokio-io 0.1.8 (git+https://gitlab.redox-os.org/redox-os/tokio)", @@ -735,7 +722,7 @@ dependencies = [ "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.6.15 (git+https://gitlab.redox-os.org/redox-os/mio)", "mio-uds 0.6.6 (git+https://gitlab.redox-os.org/redox-os/mio-uds)", "tokio-io 0.1.8 (git+https://gitlab.redox-os.org/redox-os/tokio)", @@ -865,14 +852,13 @@ dependencies = [ [metadata] "checksum arg_parser 0.1.0 (git+https://gitlab.redox-os.org/redox-os/arg-parser.git)" = "" "checksum arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)" = "a1e964f9e24d588183fcb43503abda40d288c8657dfc27311516ce2f05675aef" -"checksum base64 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "96434f987501f0ed4eb336a411e0631ecd1afa11574fe148587adc4ff96143c9" "checksum base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)" = "489d6c0ed21b11d038c31b6ceccca973e65d73ba3bd8ecb9a2babf5546164643" "checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12" "checksum byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855" -"checksum byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "90492c5858dd7d2e78691cfb89f90d273a2800fc11d98f60786e5d87e2f83781" +"checksum byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "94f88df23a25417badc922ab0f5716cc1330e87f71ddd9203b3a3ccd9cedf75d" "checksum bytes 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "0ce55bd354b095246fc34caf4e9e242f5297a7fd938b090cadfea6eee614aa62" "checksum cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)" = "f159dfd43363c4d08055a07703eb7a3406b0dac4d0584d96965a3262db3c9d16" -"checksum cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0c4e7bb64a8ebb0d856483e1e682ea3422f883c5f5615a90d51a2c82fe87fdd3" +"checksum cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "082bb9b28e00d3c9d39cc03e64ce4cea0f1bb9b3fde493f0cbc008472d22bdf4" "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" "checksum crossbeam-deque 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3486aefc4c0487b9cb52372c97df0a48b8c249514af1ee99703bf70d2f2ceda1" "checksum crossbeam-epoch 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "30fecfcac6abfef8771151f8be4abc9e4edc112c2bcb233314cafde2680536e9" @@ -883,7 +869,7 @@ dependencies = [ "checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" "checksum futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)" = "49e7653e374fe0d0c12de4250f0bdb60680b8c80eed558c5c7538eec9c89e21b" "checksum httparse 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e8734b0cfd3bc3e101ec59100e101c2eecd19282202e87808b3037b442777a83" -"checksum hyper 0.10.13 (registry+https://github.com/rust-lang/crates.io-index)" = "368cb56b2740ebf4230520e2b90ebb0461e69034d85d1945febd9b3971426db2" +"checksum hyper 0.10.15 (registry+https://github.com/rust-lang/crates.io-index)" = "df0caae6b71d266b91b4a83111a61d2b94ed2e2bea024c532b933dcff867e58c" "checksum hyper-rustls 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "71f7b2e5858ab9e19771dc361159f09ee5031734a6f7471fe0947db0238d92b7" "checksum idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e" "checksum iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dbe6e417e7d0975db6512b90796e8ce223145ac4e33c377e4a42882a0e88bb08" @@ -894,7 +880,7 @@ dependencies = [ "checksum libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)" = "76e3a3ef172f1a0b9a9ff0dd1491ae5e6c948b94479a3021819ba7d860c8645d" "checksum lock_api 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "775751a3e69bde4df9b38dd00a1b5d6ac13791e4223d4a0506577f0dd27cfb7a" "checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" -"checksum log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "d4fcce5fa49cc693c312001daf1d13411c4a5283796bac1084299ea3e567113f" +"checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6" "checksum managed 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fdcec5e97041c7f0f1c5b7d93f12e57293c831c646f4cc7a5db59460c7ea8de6" "checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" "checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3" @@ -923,7 +909,6 @@ dependencies = [ "checksum ring 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dbe642b9dd1ba0038d78c4a3999d1ee56178b4d415c1e1fbaba83b06dce012f0" "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" "checksum rustls 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)" = "942b71057b31981152970d57399c25f72e27a6ee0d207a669d8304cabf44705b" -"checksum safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e27a8b19b835f7aea908818e871f5cc3a5a186550c30773be987e155e8163d8f" "checksum safemem 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dca453248a96cb0749e36ccdfe2b0b4e54a61bfef89fb97ec621eb8e0a93dd9" "checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" "checksum sct 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cb8f61f9e6eadd062a71c380043d28036304a4706b3c4dd001ff3387ed00745a" @@ -931,7 +916,7 @@ dependencies = [ "checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" "checksum slab 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5f9776d6b986f77b35c6cf846c11ad986ff128fe0b2b63a3628e3755e8d3102d" "checksum smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "153ffa32fd170e9944f7e0838edf824a754ec4c1fc64746fcc9fe1f8fa602e5d" -"checksum smoltcp 0.4.0 (git+https://github.com/m-labs/smoltcp.git?rev=682fc3078229a4fc06b5f021af058c45b9f3bc02)" = "" +"checksum smoltcp 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fef582369edb298c6c41319a544ca9c4e83622f226055ccfcb35974fbb55ed34" "checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" "checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" "checksum time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "d825be0eb33fda1a7e68012d51e9c7f451dc1a69391e7fdc197060bb8c56667b" diff --git a/Cargo.toml b/Cargo.toml index e61f25a864..a4107f1349 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,8 +27,7 @@ default-features = false features = ["release_max_level_off"] [dependencies.smoltcp] -git = "https://github.com/m-labs/smoltcp.git" -rev = "682fc3078229a4fc06b5f021af058c45b9f3bc02" +version = "0.5.0" default-features = false features = ["std", "socket-raw", "proto-ipv4", "socket-udp", "socket-tcp", "socket-icmp"] diff --git a/src/smolnetd/scheme/icmp.rs b/src/smolnetd/scheme/icmp.rs index b022ca2bb6..54a5ca6665 100644 --- a/src/smolnetd/scheme/icmp.rs +++ b/src/smolnetd/scheme/icmp.rs @@ -179,7 +179,7 @@ impl<'a, 'b> SchemeSocket for IcmpSocket<'a, 'b> { let icmp_payload = self.send(icmp_repr.buffer_len(), file.data.ip) .map_err(|_| syscall::Error::new(syscall::EINVAL))?; - let mut icmp_packet = Icmpv4Packet::new(icmp_payload); + let mut icmp_packet = Icmpv4Packet::new_unchecked(icmp_payload); //TODO: replace Default with actual caps icmp_repr.emit(&mut icmp_packet, &Default::default()); Ok(Some(buf.len())) @@ -202,7 +202,7 @@ impl<'a, 'b> SchemeSocket for IcmpSocket<'a, 'b> { ) -> SyscallResult> { while self.can_recv() { let (payload, _) = self.recv().expect("Can't recv icmp packet"); - let icmp_packet = Icmpv4Packet::new(&payload); + let icmp_packet = Icmpv4Packet::new_unchecked(&payload); //TODO: replace default with actual caps let icmp_repr = Icmpv4Repr::parse(&icmp_packet, &Default::default()).unwrap(); @@ -269,4 +269,3 @@ impl<'a, 'b> SchemeSocket for IcmpSocket<'a, 'b> { } } } - From 01b6f9b98c614db35f73ba73aab5072b506211c1 Mon Sep 17 00:00:00 2001 From: Colleen Date: Thu, 6 Dec 2018 17:45:38 +0000 Subject: [PATCH 090/155] fix return statement of else block in dup function --- Cargo.lock | 81 ++++++++++++++++++++++--------------- Cargo.toml | 3 +- src/smolnetd/scheme/icmp.rs | 5 ++- src/smolnetd/scheme/tcp.rs | 2 +- 4 files changed, 54 insertions(+), 37 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e823e030cc..4bb03d94b7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,12 +11,21 @@ dependencies = [ "nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "base64" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "base64" version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "safemem 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -32,7 +41,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "byteorder" -version = "1.2.7" +version = "1.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -40,7 +49,7 @@ name = "bytes" version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -51,7 +60,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "cfg-if" -version = "0.1.6" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -77,7 +86,7 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-utils 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -94,7 +103,7 @@ name = "dns-parser" version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -129,10 +138,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "hyper" -version = "0.10.15" +version = "0.10.13" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)", + "base64 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "httparse 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", @@ -150,7 +159,7 @@ name = "hyper-rustls" version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "hyper 0.10.15 (registry+https://github.com/rust-lang/crates.io-index)", + "hyper 0.10.13 (registry+https://github.com/rust-lang/crates.io-index)", "rustls 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)", "webpki 0.18.1 (registry+https://github.com/rust-lang/crates.io-index)", "webpki-roots 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -221,15 +230,15 @@ name = "log" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "log" -version = "0.4.6" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -266,7 +275,7 @@ dependencies = [ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazycell 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", @@ -300,7 +309,7 @@ name = "net2" version = "0.2.33" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -308,11 +317,11 @@ dependencies = [ [[package]] name = "netutils" version = "0.1.0" -source = "git+https://gitlab.redox-os.org/redox-os/netutils.git#a5109b810ce7abffe4736aa3d5836d6321a13a9d" +source = "git+https://gitlab.redox-os.org/redox-os/netutils.git#2dee37719bd1bf1fbe3d0fdd33e350d32dda1330" dependencies = [ "arg_parser 0.1.0 (git+https://gitlab.redox-os.org/redox-os/arg-parser.git)", "extra 0.1.0 (git+https://gitlab.redox-os.org/redox-os/libextra.git)", - "hyper 0.10.15 (registry+https://github.com/rust-lang/crates.io-index)", + "hyper 0.10.13 (registry+https://github.com/rust-lang/crates.io-index)", "hyper-rustls 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.6.15 (git+https://gitlab.redox-os.org/redox-os/mio)", @@ -324,7 +333,6 @@ dependencies = [ "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio 0.1.8 (git+https://gitlab.redox-os.org/redox-os/tokio)", "tokio-reactor 0.1.4 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "url 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -437,13 +445,13 @@ dependencies = [ name = "redox_netstack" version = "0.1.0" dependencies = [ - "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "dns-parser 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "netutils 0.1.0 (git+https://gitlab.redox-os.org/redox-os/netutils.git)", "redox_event 0.1.0 (git+https://gitlab.redox-os.org/redox-os/event.git)", "redox_syscall 0.1.40 (git+https://gitlab.redox-os.org/redox-os/syscall.git)", - "smoltcp 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "smoltcp 0.4.0 (git+https://github.com/m-labs/smoltcp.git?rev=682fc3078229a4fc06b5f021af058c45b9f3bc02)", ] [[package]] @@ -489,13 +497,18 @@ version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "ring 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)", "sct 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "webpki 0.18.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "safemem" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "safemem" version = "0.3.0" @@ -543,11 +556,11 @@ dependencies = [ [[package]] name = "smoltcp" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" +version = "0.4.0" +source = "git+https://github.com/m-labs/smoltcp.git?rev=682fc3078229a4fc06b5f021af058c45b9f3bc02#682fc3078229a4fc06b5f021af058c45b9f3bc02" dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "managed 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -641,7 +654,7 @@ source = "git+https://gitlab.redox-os.org/redox-os/tokio#1a12087013a68747f6f5946 dependencies = [ "bytes 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -652,7 +665,7 @@ dependencies = [ "crossbeam-utils 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.6.15 (git+https://gitlab.redox-os.org/redox-os/mio)", "num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -682,7 +695,7 @@ dependencies = [ "crossbeam-deque 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-utils 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-executor 0.1.4 (git+https://gitlab.redox-os.org/redox-os/tokio)", @@ -706,7 +719,7 @@ source = "git+https://gitlab.redox-os.org/redox-os/tokio#1a12087013a68747f6f5946 dependencies = [ "bytes 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.6.15 (git+https://gitlab.redox-os.org/redox-os/mio)", "tokio-codec 0.1.0 (git+https://gitlab.redox-os.org/redox-os/tokio)", "tokio-io 0.1.8 (git+https://gitlab.redox-os.org/redox-os/tokio)", @@ -722,7 +735,7 @@ dependencies = [ "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.6.15 (git+https://gitlab.redox-os.org/redox-os/mio)", "mio-uds 0.6.6 (git+https://gitlab.redox-os.org/redox-os/mio-uds)", "tokio-io 0.1.8 (git+https://gitlab.redox-os.org/redox-os/tokio)", @@ -852,13 +865,14 @@ dependencies = [ [metadata] "checksum arg_parser 0.1.0 (git+https://gitlab.redox-os.org/redox-os/arg-parser.git)" = "" "checksum arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)" = "a1e964f9e24d588183fcb43503abda40d288c8657dfc27311516ce2f05675aef" +"checksum base64 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "96434f987501f0ed4eb336a411e0631ecd1afa11574fe148587adc4ff96143c9" "checksum base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)" = "489d6c0ed21b11d038c31b6ceccca973e65d73ba3bd8ecb9a2babf5546164643" "checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12" "checksum byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855" -"checksum byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "94f88df23a25417badc922ab0f5716cc1330e87f71ddd9203b3a3ccd9cedf75d" +"checksum byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "90492c5858dd7d2e78691cfb89f90d273a2800fc11d98f60786e5d87e2f83781" "checksum bytes 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "0ce55bd354b095246fc34caf4e9e242f5297a7fd938b090cadfea6eee614aa62" "checksum cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)" = "f159dfd43363c4d08055a07703eb7a3406b0dac4d0584d96965a3262db3c9d16" -"checksum cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "082bb9b28e00d3c9d39cc03e64ce4cea0f1bb9b3fde493f0cbc008472d22bdf4" +"checksum cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0c4e7bb64a8ebb0d856483e1e682ea3422f883c5f5615a90d51a2c82fe87fdd3" "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" "checksum crossbeam-deque 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3486aefc4c0487b9cb52372c97df0a48b8c249514af1ee99703bf70d2f2ceda1" "checksum crossbeam-epoch 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "30fecfcac6abfef8771151f8be4abc9e4edc112c2bcb233314cafde2680536e9" @@ -869,7 +883,7 @@ dependencies = [ "checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" "checksum futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)" = "49e7653e374fe0d0c12de4250f0bdb60680b8c80eed558c5c7538eec9c89e21b" "checksum httparse 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e8734b0cfd3bc3e101ec59100e101c2eecd19282202e87808b3037b442777a83" -"checksum hyper 0.10.15 (registry+https://github.com/rust-lang/crates.io-index)" = "df0caae6b71d266b91b4a83111a61d2b94ed2e2bea024c532b933dcff867e58c" +"checksum hyper 0.10.13 (registry+https://github.com/rust-lang/crates.io-index)" = "368cb56b2740ebf4230520e2b90ebb0461e69034d85d1945febd9b3971426db2" "checksum hyper-rustls 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "71f7b2e5858ab9e19771dc361159f09ee5031734a6f7471fe0947db0238d92b7" "checksum idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e" "checksum iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dbe6e417e7d0975db6512b90796e8ce223145ac4e33c377e4a42882a0e88bb08" @@ -880,7 +894,7 @@ dependencies = [ "checksum libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)" = "76e3a3ef172f1a0b9a9ff0dd1491ae5e6c948b94479a3021819ba7d860c8645d" "checksum lock_api 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "775751a3e69bde4df9b38dd00a1b5d6ac13791e4223d4a0506577f0dd27cfb7a" "checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" -"checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6" +"checksum log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "d4fcce5fa49cc693c312001daf1d13411c4a5283796bac1084299ea3e567113f" "checksum managed 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fdcec5e97041c7f0f1c5b7d93f12e57293c831c646f4cc7a5db59460c7ea8de6" "checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" "checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3" @@ -909,6 +923,7 @@ dependencies = [ "checksum ring 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dbe642b9dd1ba0038d78c4a3999d1ee56178b4d415c1e1fbaba83b06dce012f0" "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" "checksum rustls 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)" = "942b71057b31981152970d57399c25f72e27a6ee0d207a669d8304cabf44705b" +"checksum safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e27a8b19b835f7aea908818e871f5cc3a5a186550c30773be987e155e8163d8f" "checksum safemem 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dca453248a96cb0749e36ccdfe2b0b4e54a61bfef89fb97ec621eb8e0a93dd9" "checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" "checksum sct 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cb8f61f9e6eadd062a71c380043d28036304a4706b3c4dd001ff3387ed00745a" @@ -916,7 +931,7 @@ dependencies = [ "checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" "checksum slab 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5f9776d6b986f77b35c6cf846c11ad986ff128fe0b2b63a3628e3755e8d3102d" "checksum smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "153ffa32fd170e9944f7e0838edf824a754ec4c1fc64746fcc9fe1f8fa602e5d" -"checksum smoltcp 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fef582369edb298c6c41319a544ca9c4e83622f226055ccfcb35974fbb55ed34" +"checksum smoltcp 0.4.0 (git+https://github.com/m-labs/smoltcp.git?rev=682fc3078229a4fc06b5f021af058c45b9f3bc02)" = "" "checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" "checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" "checksum time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "d825be0eb33fda1a7e68012d51e9c7f451dc1a69391e7fdc197060bb8c56667b" diff --git a/Cargo.toml b/Cargo.toml index a4107f1349..e61f25a864 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,8 @@ default-features = false features = ["release_max_level_off"] [dependencies.smoltcp] -version = "0.5.0" +git = "https://github.com/m-labs/smoltcp.git" +rev = "682fc3078229a4fc06b5f021af058c45b9f3bc02" default-features = false features = ["std", "socket-raw", "proto-ipv4", "socket-udp", "socket-tcp", "socket-icmp"] diff --git a/src/smolnetd/scheme/icmp.rs b/src/smolnetd/scheme/icmp.rs index 54a5ca6665..b022ca2bb6 100644 --- a/src/smolnetd/scheme/icmp.rs +++ b/src/smolnetd/scheme/icmp.rs @@ -179,7 +179,7 @@ impl<'a, 'b> SchemeSocket for IcmpSocket<'a, 'b> { let icmp_payload = self.send(icmp_repr.buffer_len(), file.data.ip) .map_err(|_| syscall::Error::new(syscall::EINVAL))?; - let mut icmp_packet = Icmpv4Packet::new_unchecked(icmp_payload); + let mut icmp_packet = Icmpv4Packet::new(icmp_payload); //TODO: replace Default with actual caps icmp_repr.emit(&mut icmp_packet, &Default::default()); Ok(Some(buf.len())) @@ -202,7 +202,7 @@ impl<'a, 'b> SchemeSocket for IcmpSocket<'a, 'b> { ) -> SyscallResult> { while self.can_recv() { let (payload, _) = self.recv().expect("Can't recv icmp packet"); - let icmp_packet = Icmpv4Packet::new_unchecked(&payload); + let icmp_packet = Icmpv4Packet::new(&payload); //TODO: replace default with actual caps let icmp_repr = Icmpv4Repr::parse(&icmp_packet, &Default::default()).unwrap(); @@ -269,3 +269,4 @@ impl<'a, 'b> SchemeSocket for IcmpSocket<'a, 'b> { } } } + diff --git a/src/smolnetd/scheme/tcp.rs b/src/smolnetd/scheme/tcp.rs index a67aa09dd5..770f632987 100644 --- a/src/smolnetd/scheme/tcp.rs +++ b/src/smolnetd/scheme/tcp.rs @@ -162,7 +162,7 @@ impl<'a> SchemeSocket for TcpSocket<'a> { if tcp_handle.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { return Err(SyscallError::new(syscall::EAGAIN)); } else { - return Err(SyscallError::new(syscall::EAGAIN)); + Ok(None); } } trace!("TCP creating new listening socket"); From 4d537dbd577dbf62f862448438cc28cdb486cfa8 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Thu, 6 Dec 2018 17:55:51 -0700 Subject: [PATCH 091/155] Fix compilation --- src/smolnetd/scheme/icmp.rs | 1 - src/smolnetd/scheme/socket.rs | 11 +++++++---- src/smolnetd/scheme/tcp.rs | 6 +++--- src/smolnetd/scheme/udp.rs | 2 +- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/smolnetd/scheme/icmp.rs b/src/smolnetd/scheme/icmp.rs index b022ca2bb6..08546a256b 100644 --- a/src/smolnetd/scheme/icmp.rs +++ b/src/smolnetd/scheme/icmp.rs @@ -269,4 +269,3 @@ impl<'a, 'b> SchemeSocket for IcmpSocket<'a, 'b> { } } } - diff --git a/src/smolnetd/scheme/socket.rs b/src/smolnetd/scheme/socket.rs index 70e3e5251d..f1d07c4d16 100644 --- a/src/smolnetd/scheme/socket.rs +++ b/src/smolnetd/scheme/socket.rs @@ -106,10 +106,10 @@ type WaitQueue = Vec; type WaitQueueMap = BTreeMap; -pub type DupResult = ( +pub type DupResult = Option<( SchemeFile, Option<(SocketHandle, ::DataT)>, -); +)>; pub trait SchemeSocket where @@ -639,12 +639,15 @@ where }), None, ), - _ => SocketT::dup( + _ => match SocketT::dup( &mut self.socket_set.borrow_mut(), file, path, &mut self.scheme_data, - )?, + )? { + Some(some) => some, + None => return Ok(None), + }, }; if let Some((socket_handle, data)) = update_with { diff --git a/src/smolnetd/scheme/tcp.rs b/src/smolnetd/scheme/tcp.rs index 770f632987..20f69b9f56 100644 --- a/src/smolnetd/scheme/tcp.rs +++ b/src/smolnetd/scheme/tcp.rs @@ -162,7 +162,7 @@ impl<'a> SchemeSocket for TcpSocket<'a> { if tcp_handle.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { return Err(SyscallError::new(syscall::EAGAIN)); } else { - Ok(None); + return Ok(None); } } trace!("TCP creating new listening socket"); @@ -181,7 +181,7 @@ impl<'a> SchemeSocket for TcpSocket<'a> { .expect("Can't listen on local endpoint"); } port_set.acquire_port(local_endpoint.port); - return Ok((new_handle, Some((new_socket_handle, ())))); + return Ok(Some((new_handle, Some((new_socket_handle, ()))))); } else { return Err(SyscallError::new(syscall::EBADF)); }, @@ -199,7 +199,7 @@ impl<'a> SchemeSocket for TcpSocket<'a> { port_set.acquire_port(local_endpoint.port); } - Ok((file, None)) + Ok(Some((file, None))) } fn fpath(&self, _: &SchemeFile, buf: &mut [u8]) -> SyscallResult { diff --git a/src/smolnetd/scheme/udp.rs b/src/smolnetd/scheme/udp.rs index d78695806e..f58ad285bd 100644 --- a/src/smolnetd/scheme/udp.rs +++ b/src/smolnetd/scheme/udp.rs @@ -171,7 +171,7 @@ impl<'a, 'b> SchemeSocket for UdpSocket<'a, 'b> { port_set.acquire_port(endpoint.port); } - Ok((file, None)) + Ok(Some((file, None))) } fn fpath(&self, file: &SchemeFile, buf: &mut [u8]) -> SyscallResult { From 3fcafeed852f8ebee85197ac1c7f11bfc4d1ce19 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Tue, 1 Jan 2019 18:29:29 -0700 Subject: [PATCH 092/155] Update smolnetd --- Cargo.lock | 498 +++++++++++++++++++----------------- Cargo.toml | 3 +- src/smolnetd/scheme/icmp.rs | 4 +- 3 files changed, 264 insertions(+), 241 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4bb03d94b7..f825bcadbd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5,19 +5,10 @@ source = "git+https://gitlab.redox-os.org/redox-os/arg-parser.git#7503531821b0c1 [[package]] name = "arrayvec" -version = "0.4.7" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "base64" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", - "safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -25,7 +16,7 @@ name = "base64" version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", "safemem 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -41,26 +32,26 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "byteorder" -version = "1.2.6" +version = "1.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "bytes" -version = "0.4.10" +version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "cc" -version = "1.0.25" +version = "1.0.28" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "cfg-if" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -73,37 +64,40 @@ dependencies = [ [[package]] name = "crossbeam-deque" -version = "0.6.1" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "crossbeam-epoch 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam-utils 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-epoch 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "crossbeam-epoch" -version = "0.5.2" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam-utils 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "crossbeam-utils" -version = "0.5.0" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", +] [[package]] name = "dns-parser" version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", "quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -138,20 +132,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "hyper" -version = "0.10.13" +version = "0.10.15" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "base64 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)", "httparse 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "mime 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", - "num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", "traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "typeable 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "unicase 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "url 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -159,7 +153,7 @@ name = "hyper-rustls" version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "hyper 0.10.13 (registry+https://github.com/rust-lang/crates.io-index)", + "hyper 0.10.15 (registry+https://github.com/rust-lang/crates.io-index)", "rustls 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)", "webpki 0.18.1 (registry+https://github.com/rust-lang/crates.io-index)", "webpki-roots 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -180,7 +174,7 @@ name = "iovec" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -200,28 +194,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "lazy_static" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "lazycell" version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libc" -version = "0.2.43" +version = "0.2.45" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "lock_api" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "owning_ref 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -230,15 +216,15 @@ name = "log" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "log" -version = "0.4.5" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -266,19 +252,18 @@ dependencies = [ [[package]] name = "mio" -version = "0.6.15" -source = "git+https://gitlab.redox-os.org/redox-os/mio#8a4c08faee0483976bd345b6d88d2455e4c1a4db" +version = "0.6.16" +source = "git+https://gitlab.redox-os.org/redox-os/mio#493d2b65c12b269c4481fd1dc2cd7d3670a880c9" dependencies = [ "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "lazycell 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.50 (registry+https://github.com/rust-lang/crates.io-index)", "slab 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -289,8 +274,8 @@ version = "0.6.6" source = "git+https://gitlab.redox-os.org/redox-os/mio-uds#2936ef82070ea0c4aa8a7360455b8c512d8c88c0" dependencies = [ "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.15 (git+https://gitlab.redox-os.org/redox-os/mio)", + "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.16 (git+https://gitlab.redox-os.org/redox-os/mio)", ] [[package]] @@ -309,35 +294,36 @@ name = "net2" version = "0.2.33" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "netutils" version = "0.1.0" -source = "git+https://gitlab.redox-os.org/redox-os/netutils.git#2dee37719bd1bf1fbe3d0fdd33e350d32dda1330" +source = "git+https://gitlab.redox-os.org/redox-os/netutils.git#03d76ff3b5c4a42e300e3016f42fd632193bbc9d" dependencies = [ "arg_parser 0.1.0 (git+https://gitlab.redox-os.org/redox-os/arg-parser.git)", "extra 0.1.0 (git+https://gitlab.redox-os.org/redox-os/libextra.git)", - "hyper 0.10.13 (registry+https://github.com/rust-lang/crates.io-index)", + "hyper 0.10.15 (registry+https://github.com/rust-lang/crates.io-index)", "hyper-rustls 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.15 (git+https://gitlab.redox-os.org/redox-os/mio)", + "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.16 (git+https://gitlab.redox-os.org/redox-os/mio)", "ntpclient 0.0.1 (git+https://github.com/willem66745/ntpclient-rust)", "pbr 1.0.1 (git+https://github.com/a8m/pb)", "redox_event 0.1.0 (git+https://gitlab.redox-os.org/redox-os/event.git)", - "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.50 (registry+https://github.com/rust-lang/crates.io-index)", "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio 0.1.8 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-reactor 0.1.4 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio 0.1.13 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-reactor 0.1.7 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "nodrop" -version = "0.1.12" +version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -346,20 +332,20 @@ version = "0.0.1" source = "git+https://github.com/willem66745/ntpclient-rust#7e3bdf60eb940825789a8da5181025320e3050b0" dependencies = [ "byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", - "time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "num_cpus" -version = "1.8.0" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "owning_ref" -version = "0.3.3" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -367,35 +353,34 @@ dependencies = [ [[package]] name = "parking_lot" -version = "0.6.4" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "lock_api 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "lock_api 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "parking_lot_core" -version = "0.3.1" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "pbr" version = "1.0.1" -source = "git+https://github.com/a8m/pb#8774a4627dabfacb1d0c80f409232c4f82231119" +source = "git+https://github.com/a8m/pb#b9792c9fe37343234316e23c263874cf383b208d" dependencies = [ - "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -410,22 +395,29 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "rand" -version = "0.5.5" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_core 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_chacha 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_pcg 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_xorshift 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] -name = "rand_core" -version = "0.2.2" +name = "rand_chacha" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -433,35 +425,68 @@ name = "rand_core" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "rand_hc" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_isaac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_pcg" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_xorshift" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "redox_event" version = "0.1.0" source = "git+https://gitlab.redox-os.org/redox-os/event.git#c31e3d3d5f44d60ff9fec2b1ee58b982e72c0d77" dependencies = [ - "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.50 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "redox_netstack" version = "0.1.0" dependencies = [ - "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", "dns-parser 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "netutils 0.1.0 (git+https://gitlab.redox-os.org/redox-os/netutils.git)", "redox_event 0.1.0 (git+https://gitlab.redox-os.org/redox-os/event.git)", - "redox_syscall 0.1.40 (git+https://gitlab.redox-os.org/redox-os/syscall.git)", - "smoltcp 0.4.0 (git+https://github.com/m-labs/smoltcp.git?rev=682fc3078229a4fc06b5f021af058c45b9f3bc02)", + "redox_syscall 0.1.50 (git+https://gitlab.redox-os.org/redox-os/syscall.git)", + "smoltcp 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "redox_syscall" -version = "0.1.40" -source = "git+https://gitlab.redox-os.org/redox-os/syscall.git#85598a1c33adc772974a7059f3c303ab4391e9f3" +version = "0.1.50" +source = "git+https://gitlab.redox-os.org/redox-os/syscall.git#9a3734c41ac452bc3f8fe6d9a6b687c96cc3ca15" [[package]] name = "redox_syscall" -version = "0.1.40" +version = "0.1.50" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -469,17 +494,17 @@ name = "redox_termios" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.50 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "ring" -version = "0.13.2" +version = "0.13.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.28 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", "untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -497,18 +522,13 @@ version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", - "ring 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "ring 0.13.5 (registry+https://github.com/rust-lang/crates.io-index)", "sct 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "webpki 0.18.1 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "safemem" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "safemem" version = "0.3.0" @@ -524,7 +544,7 @@ name = "sct" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "ring 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ring 0.13.5 (registry+https://github.com/rust-lang/crates.io-index)", "untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -548,7 +568,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "smallvec" -version = "0.6.5" +version = "0.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -556,11 +576,12 @@ dependencies = [ [[package]] name = "smoltcp" -version = "0.4.0" -source = "git+https://github.com/m-labs/smoltcp.git?rev=682fc3078229a4fc06b5f021af058c45b9f3bc02#682fc3078229a4fc06b5f021af058c45b9f3bc02" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "managed 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -574,172 +595,174 @@ name = "termion" version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.50 (registry+https://github.com/rust-lang/crates.io-index)", "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "time" -version = "0.1.40" +version = "0.1.41" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.50 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "tokio" -version = "0.1.8" -source = "git+https://gitlab.redox-os.org/redox-os/tokio#1a12087013a68747f6f59460ea95bd597b898dab" +version = "0.1.13" +source = "git+https://gitlab.redox-os.org/redox-os/tokio#e90845fe8a0e259eeb569d0424f27e276851dced" dependencies = [ - "bytes 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.15 (git+https://gitlab.redox-os.org/redox-os/mio)", - "tokio-codec 0.1.0 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-current-thread 0.1.1 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-executor 0.1.4 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-fs 0.1.3 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-io 0.1.8 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-reactor 0.1.4 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-tcp 0.1.1 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-threadpool 0.1.6 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-timer 0.2.6 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-udp 0.1.2 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-uds 0.2.1 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "mio 0.6.16 (git+https://gitlab.redox-os.org/redox-os/mio)", + "num_cpus 1.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-codec 0.1.1 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-current-thread 0.1.4 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-executor 0.1.5 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-fs 0.1.4 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-io 0.1.10 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-reactor 0.1.7 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-tcp 0.1.2 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-threadpool 0.1.9 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-timer 0.2.8 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-udp 0.1.3 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-uds 0.2.4 (git+https://gitlab.redox-os.org/redox-os/tokio)", ] [[package]] name = "tokio-codec" -version = "0.1.0" -source = "git+https://gitlab.redox-os.org/redox-os/tokio#1a12087013a68747f6f59460ea95bd597b898dab" +version = "0.1.1" +source = "git+https://gitlab.redox-os.org/redox-os/tokio#e90845fe8a0e259eeb569d0424f27e276851dced" dependencies = [ - "bytes 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-io 0.1.8 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-io 0.1.10 (git+https://gitlab.redox-os.org/redox-os/tokio)", ] [[package]] name = "tokio-current-thread" -version = "0.1.1" -source = "git+https://gitlab.redox-os.org/redox-os/tokio#1a12087013a68747f6f59460ea95bd597b898dab" +version = "0.1.4" +source = "git+https://gitlab.redox-os.org/redox-os/tokio#e90845fe8a0e259eeb569d0424f27e276851dced" dependencies = [ "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-executor 0.1.4 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-executor 0.1.5 (git+https://gitlab.redox-os.org/redox-os/tokio)", ] [[package]] name = "tokio-executor" -version = "0.1.4" -source = "git+https://gitlab.redox-os.org/redox-os/tokio#1a12087013a68747f6f59460ea95bd597b898dab" +version = "0.1.5" +source = "git+https://gitlab.redox-os.org/redox-os/tokio#e90845fe8a0e259eeb569d0424f27e276851dced" dependencies = [ "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "tokio-fs" -version = "0.1.3" -source = "git+https://gitlab.redox-os.org/redox-os/tokio#1a12087013a68747f6f59460ea95bd597b898dab" +version = "0.1.4" +source = "git+https://gitlab.redox-os.org/redox-os/tokio#e90845fe8a0e259eeb569d0424f27e276851dced" dependencies = [ "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-io 0.1.8 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-threadpool 0.1.6 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-io 0.1.10 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-threadpool 0.1.9 (git+https://gitlab.redox-os.org/redox-os/tokio)", ] [[package]] name = "tokio-io" -version = "0.1.8" -source = "git+https://gitlab.redox-os.org/redox-os/tokio#1a12087013a68747f6f59460ea95bd597b898dab" +version = "0.1.10" +source = "git+https://gitlab.redox-os.org/redox-os/tokio#e90845fe8a0e259eeb569d0424f27e276851dced" dependencies = [ - "bytes 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "tokio-reactor" -version = "0.1.4" -source = "git+https://gitlab.redox-os.org/redox-os/tokio#1a12087013a68747f6f59460ea95bd597b898dab" +version = "0.1.7" +source = "git+https://gitlab.redox-os.org/redox-os/tokio#e90845fe8a0e259eeb569d0424f27e276851dced" dependencies = [ - "crossbeam-utils 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.15 (git+https://gitlab.redox-os.org/redox-os/mio)", - "num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.16 (git+https://gitlab.redox-os.org/redox-os/mio)", + "num_cpus 1.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "slab 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-executor 0.1.4 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-io 0.1.8 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-executor 0.1.5 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-io 0.1.10 (git+https://gitlab.redox-os.org/redox-os/tokio)", ] [[package]] name = "tokio-tcp" -version = "0.1.1" -source = "git+https://gitlab.redox-os.org/redox-os/tokio#1a12087013a68747f6f59460ea95bd597b898dab" +version = "0.1.2" +source = "git+https://gitlab.redox-os.org/redox-os/tokio#e90845fe8a0e259eeb569d0424f27e276851dced" dependencies = [ - "bytes 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.15 (git+https://gitlab.redox-os.org/redox-os/mio)", - "tokio-io 0.1.8 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-reactor 0.1.4 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "mio 0.6.16 (git+https://gitlab.redox-os.org/redox-os/mio)", + "tokio-io 0.1.10 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-reactor 0.1.7 (git+https://gitlab.redox-os.org/redox-os/tokio)", ] [[package]] name = "tokio-threadpool" -version = "0.1.6" -source = "git+https://gitlab.redox-os.org/redox-os/tokio#1a12087013a68747f6f59460ea95bd597b898dab" +version = "0.1.9" +source = "git+https://gitlab.redox-os.org/redox-os/tokio#e90845fe8a0e259eeb569d0424f27e276851dced" dependencies = [ - "crossbeam-deque 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam-utils 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-deque 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", - "num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-executor 0.1.4 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-executor 0.1.5 (git+https://gitlab.redox-os.org/redox-os/tokio)", ] [[package]] name = "tokio-timer" -version = "0.2.6" -source = "git+https://gitlab.redox-os.org/redox-os/tokio#1a12087013a68747f6f59460ea95bd597b898dab" +version = "0.2.8" +source = "git+https://gitlab.redox-os.org/redox-os/tokio#e90845fe8a0e259eeb569d0424f27e276851dced" dependencies = [ - "crossbeam-utils 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "slab 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-executor 0.1.4 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-executor 0.1.5 (git+https://gitlab.redox-os.org/redox-os/tokio)", ] [[package]] name = "tokio-udp" -version = "0.1.2" -source = "git+https://gitlab.redox-os.org/redox-os/tokio#1a12087013a68747f6f59460ea95bd597b898dab" +version = "0.1.3" +source = "git+https://gitlab.redox-os.org/redox-os/tokio#e90845fe8a0e259eeb569d0424f27e276851dced" dependencies = [ - "bytes 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.15 (git+https://gitlab.redox-os.org/redox-os/mio)", - "tokio-codec 0.1.0 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-io 0.1.8 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-reactor 0.1.4 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.16 (git+https://gitlab.redox-os.org/redox-os/mio)", + "tokio-codec 0.1.1 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-io 0.1.10 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-reactor 0.1.7 (git+https://gitlab.redox-os.org/redox-os/tokio)", ] [[package]] name = "tokio-uds" -version = "0.2.1" -source = "git+https://gitlab.redox-os.org/redox-os/tokio#1a12087013a68747f6f59460ea95bd597b898dab" +version = "0.2.4" +source = "git+https://gitlab.redox-os.org/redox-os/tokio#e90845fe8a0e259eeb569d0424f27e276851dced" dependencies = [ - "bytes 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.15 (git+https://gitlab.redox-os.org/redox-os/mio)", + "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.16 (git+https://gitlab.redox-os.org/redox-os/mio)", "mio-uds 0.6.6 (git+https://gitlab.redox-os.org/redox-os/mio-uds)", - "tokio-io 0.1.8 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-reactor 0.1.4 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-codec 0.1.1 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-io 0.1.10 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "tokio-reactor 0.1.7 (git+https://gitlab.redox-os.org/redox-os/tokio)", ] [[package]] @@ -788,7 +811,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "url" -version = "1.7.1" +version = "1.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -811,7 +834,7 @@ name = "webpki" version = "0.18.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "ring 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ring 0.13.5 (registry+https://github.com/rust-lang/crates.io-index)", "untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -864,89 +887,90 @@ dependencies = [ [metadata] "checksum arg_parser 0.1.0 (git+https://gitlab.redox-os.org/redox-os/arg-parser.git)" = "" -"checksum arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)" = "a1e964f9e24d588183fcb43503abda40d288c8657dfc27311516ce2f05675aef" -"checksum base64 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "96434f987501f0ed4eb336a411e0631ecd1afa11574fe148587adc4ff96143c9" +"checksum arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "92c7fb76bc8826a8b33b4ee5bb07a247a81e76764ab4d55e8f73e3a4d8808c71" "checksum base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)" = "489d6c0ed21b11d038c31b6ceccca973e65d73ba3bd8ecb9a2babf5546164643" "checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12" "checksum byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855" -"checksum byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "90492c5858dd7d2e78691cfb89f90d273a2800fc11d98f60786e5d87e2f83781" -"checksum bytes 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "0ce55bd354b095246fc34caf4e9e242f5297a7fd938b090cadfea6eee614aa62" -"checksum cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)" = "f159dfd43363c4d08055a07703eb7a3406b0dac4d0584d96965a3262db3c9d16" -"checksum cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0c4e7bb64a8ebb0d856483e1e682ea3422f883c5f5615a90d51a2c82fe87fdd3" +"checksum byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "94f88df23a25417badc922ab0f5716cc1330e87f71ddd9203b3a3ccd9cedf75d" +"checksum bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)" = "40ade3d27603c2cb345eb0912aec461a6dec7e06a4ae48589904e808335c7afa" +"checksum cc 1.0.28 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4a8b715cb4597106ea87c7c84b2f1d452c7492033765df7f32651e66fcf749" +"checksum cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "082bb9b28e00d3c9d39cc03e64ce4cea0f1bb9b3fde493f0cbc008472d22bdf4" "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" -"checksum crossbeam-deque 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3486aefc4c0487b9cb52372c97df0a48b8c249514af1ee99703bf70d2f2ceda1" -"checksum crossbeam-epoch 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "30fecfcac6abfef8771151f8be4abc9e4edc112c2bcb233314cafde2680536e9" -"checksum crossbeam-utils 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "677d453a17e8bd2b913fa38e8b9cf04bcdbb5be790aa294f2389661d72036015" +"checksum crossbeam-deque 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "05e44b8cf3e1a625844d1750e1f7820da46044ff6d28f4d43e455ba3e5bb2c13" +"checksum crossbeam-epoch 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f10a4f8f409aaac4b16a5474fb233624238fcdeefb9ba50d5ea059aab63ba31c" +"checksum crossbeam-utils 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "41ee4864f4797060e52044376f7d107429ce1fb43460021b126424b7180ee21a" "checksum dns-parser 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f7020f6760aea312d43d23cb83bf6c0c49f162541db8b02bf95209ac51dc253d" "checksum extra 0.1.0 (git+https://gitlab.redox-os.org/redox-os/libextra.git)" = "" "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" "checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" "checksum futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)" = "49e7653e374fe0d0c12de4250f0bdb60680b8c80eed558c5c7538eec9c89e21b" "checksum httparse 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e8734b0cfd3bc3e101ec59100e101c2eecd19282202e87808b3037b442777a83" -"checksum hyper 0.10.13 (registry+https://github.com/rust-lang/crates.io-index)" = "368cb56b2740ebf4230520e2b90ebb0461e69034d85d1945febd9b3971426db2" +"checksum hyper 0.10.15 (registry+https://github.com/rust-lang/crates.io-index)" = "df0caae6b71d266b91b4a83111a61d2b94ed2e2bea024c532b933dcff867e58c" "checksum hyper-rustls 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "71f7b2e5858ab9e19771dc361159f09ee5031734a6f7471fe0947db0238d92b7" "checksum idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e" "checksum iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dbe6e417e7d0975db6512b90796e8ce223145ac4e33c377e4a42882a0e88bb08" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a" -"checksum lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca488b89a5657b0a2ecd45b95609b3e848cf1755da332a0da46e2b2b1cb371a7" -"checksum lazycell 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ddba4c30a78328befecec92fc94970e53b3ae385827d28620f0f5bb2493081e0" -"checksum libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)" = "76e3a3ef172f1a0b9a9ff0dd1491ae5e6c948b94479a3021819ba7d860c8645d" -"checksum lock_api 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "775751a3e69bde4df9b38dd00a1b5d6ac13791e4223d4a0506577f0dd27cfb7a" +"checksum lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a374c89b9db55895453a74c1e38861d9deec0b01b405a82516e9d5de4820dea1" +"checksum libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)" = "2d2857ec59fadc0773853c664d2d18e7198e83883e7060b63c924cb077bd5c74" +"checksum lock_api 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "62ebf1391f6acad60e5c8b43706dde4582df75c06698ab44511d15016bc2442c" "checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" -"checksum log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "d4fcce5fa49cc693c312001daf1d13411c4a5283796bac1084299ea3e567113f" +"checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6" "checksum managed 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fdcec5e97041c7f0f1c5b7d93f12e57293c831c646f4cc7a5db59460c7ea8de6" "checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" "checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3" "checksum mime 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ba626b8a6de5da682e1caa06bdb42a335aee5a84db8e5046a3e8ab17ba0a3ae0" -"checksum mio 0.6.15 (git+https://gitlab.redox-os.org/redox-os/mio)" = "" +"checksum mio 0.6.16 (git+https://gitlab.redox-os.org/redox-os/mio)" = "" "checksum mio-uds 0.6.6 (git+https://gitlab.redox-os.org/redox-os/mio-uds)" = "" "checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919" "checksum net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "42550d9fb7b6684a6d404d9fa7250c2eb2646df731d1c06afc06dcee9e1bcf88" "checksum netutils 0.1.0 (git+https://gitlab.redox-os.org/redox-os/netutils.git)" = "" -"checksum nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "9a2228dca57108069a5262f2ed8bd2e82496d2e074a06d1ccc7ce1687b6ae0a2" +"checksum nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9667ddcc6cc8a43afc9b7917599d7216aa09c463919ea32c59ed6cac8bc945" "checksum ntpclient 0.0.1 (git+https://github.com/willem66745/ntpclient-rust)" = "" -"checksum num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c51a3322e4bca9d212ad9a158a02abc6934d005490c054a2778df73a70aa0a30" -"checksum owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cdf84f41639e037b484f93433aa3897863b561ed65c6e59c7073d7c561710f37" -"checksum parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "f0802bff09003b291ba756dc7e79313e51cc31667e94afbe847def490424cde5" -"checksum parking_lot_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ad7f7e6ebdc79edff6fdcb87a55b620174f7a989e3eb31b65231f4af57f00b8c" +"checksum num_cpus 1.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5a69d464bdc213aaaff628444e99578ede64e9c854025aa43b9796530afa9238" +"checksum owning_ref 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "49a4b8ea2179e6a2e27411d3bca09ca6dd630821cf6894c6c7c8467a8ee7ef13" +"checksum parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ab41b4aed082705d1056416ae4468b6ea99d52599ecf3169b00088d43113e337" +"checksum parking_lot_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "94c8c7923936b28d546dfd14d4472eaf34c99b14e1c973a32b3e6d4eb04298c9" "checksum pbr 1.0.1 (git+https://github.com/a8m/pb)" = "" "checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" "checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0" -"checksum rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e464cd887e869cddcae8792a4ee31d23c7edd516700695608f5b98c67ee0131c" -"checksum rand_core 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1961a422c4d189dfb50ffa9320bf1f2a9bd54ecb92792fb9477f99a1045f3372" +"checksum rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ae9d223d52ae411a33cf7e54ec6034ec165df296ccd23533d671a28252b6f66a" +"checksum rand_chacha 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "771b009e3a508cb67e8823dda454aaa5368c7bc1c16829fb77d3e980440dd34a" "checksum rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0905b6b7079ec73b314d4c748701f6931eb79fd97c668caa3f1899b22b32c6db" +"checksum rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" +"checksum rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" +"checksum rand_pcg 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "086bd09a33c7044e56bb44d5bdde5a60e7f119a9e95b0775f545de759a32fe05" +"checksum rand_xorshift 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "effa3fcaa47e18db002bdde6060944b6d2f9cfd8db471c30e873448ad9187be3" "checksum redox_event 0.1.0 (git+https://gitlab.redox-os.org/redox-os/event.git)" = "" -"checksum redox_syscall 0.1.40 (git+https://gitlab.redox-os.org/redox-os/syscall.git)" = "" -"checksum redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "c214e91d3ecf43e9a4e41e578973adeb14b474f2bee858742d127af75a0112b1" +"checksum redox_syscall 0.1.50 (git+https://gitlab.redox-os.org/redox-os/syscall.git)" = "" +"checksum redox_syscall 0.1.50 (registry+https://github.com/rust-lang/crates.io-index)" = "52ee9a534dc1301776eff45b4fa92d2c39b1d8c3d3357e6eb593e0d795506fc2" "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" -"checksum ring 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dbe642b9dd1ba0038d78c4a3999d1ee56178b4d415c1e1fbaba83b06dce012f0" +"checksum ring 0.13.5 (registry+https://github.com/rust-lang/crates.io-index)" = "2c4db68a2e35f3497146b7e4563df7d4773a2433230c5e4b448328e31740458a" "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" "checksum rustls 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)" = "942b71057b31981152970d57399c25f72e27a6ee0d207a669d8304cabf44705b" -"checksum safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e27a8b19b835f7aea908818e871f5cc3a5a186550c30773be987e155e8163d8f" "checksum safemem 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dca453248a96cb0749e36ccdfe2b0b4e54a61bfef89fb97ec621eb8e0a93dd9" "checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" "checksum sct 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cb8f61f9e6eadd062a71c380043d28036304a4706b3c4dd001ff3387ed00745a" "checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" "checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" "checksum slab 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5f9776d6b986f77b35c6cf846c11ad986ff128fe0b2b63a3628e3755e8d3102d" -"checksum smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "153ffa32fd170e9944f7e0838edf824a754ec4c1fc64746fcc9fe1f8fa602e5d" -"checksum smoltcp 0.4.0 (git+https://github.com/m-labs/smoltcp.git?rev=682fc3078229a4fc06b5f021af058c45b9f3bc02)" = "" +"checksum smallvec 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)" = "b73ea3738b47563803ef814925e69be00799a8c07420be8b996f8e98fb2336db" +"checksum smoltcp 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fef582369edb298c6c41319a544ca9c4e83622f226055ccfcb35974fbb55ed34" "checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" "checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" -"checksum time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "d825be0eb33fda1a7e68012d51e9c7f451dc1a69391e7fdc197060bb8c56667b" -"checksum tokio 0.1.8 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" -"checksum tokio-codec 0.1.0 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" -"checksum tokio-current-thread 0.1.1 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" -"checksum tokio-executor 0.1.4 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" -"checksum tokio-fs 0.1.3 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" -"checksum tokio-io 0.1.8 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" -"checksum tokio-reactor 0.1.4 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" -"checksum tokio-tcp 0.1.1 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" -"checksum tokio-threadpool 0.1.6 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" -"checksum tokio-timer 0.2.6 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" -"checksum tokio-udp 0.1.2 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" -"checksum tokio-uds 0.2.1 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" +"checksum time 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)" = "847da467bf0db05882a9e2375934a8a55cffdc9db0d128af1518200260ba1f6c" +"checksum tokio 0.1.13 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" +"checksum tokio-codec 0.1.1 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" +"checksum tokio-current-thread 0.1.4 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" +"checksum tokio-executor 0.1.5 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" +"checksum tokio-fs 0.1.4 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" +"checksum tokio-io 0.1.10 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" +"checksum tokio-reactor 0.1.7 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" +"checksum tokio-tcp 0.1.2 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" +"checksum tokio-threadpool 0.1.9 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" +"checksum tokio-timer 0.2.8 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" +"checksum tokio-udp 0.1.3 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" +"checksum tokio-uds 0.2.4 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" "checksum traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079" "checksum typeable 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1410f6f91f21d1612654e7cc69193b0334f909dcf2c790c4826254fbb86f8887" "checksum unicase 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7f4765f83163b74f957c797ad9253caf97f103fb064d3999aea9568d09fc8a33" @@ -954,7 +978,7 @@ dependencies = [ "checksum unicode-normalization 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "6a0180bc61fc5a987082bfa111f4cc95c4caff7f9799f3e46df09163a937aa25" "checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56" "checksum untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "55cd1f4b4e96b46aeb8d4855db4a7a9bd96eeeb5c6a1ab54593328761642ce2f" -"checksum url 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2a321979c09843d272956e73700d12c4e7d3d92b2ee112b31548aef0d4efc5a6" +"checksum url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dd4e7c0d531266369519a4aa4f399d748bd37043b00bde1e4ff1f60a120b355a" "checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd" "checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" "checksum webpki 0.18.1 (registry+https://github.com/rust-lang/crates.io-index)" = "17d7967316d8411ca3b01821ee6c332bde138ba4363becdb492f12e514daa17f" diff --git a/Cargo.toml b/Cargo.toml index e61f25a864..350c8e278c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,8 +27,7 @@ default-features = false features = ["release_max_level_off"] [dependencies.smoltcp] -git = "https://github.com/m-labs/smoltcp.git" -rev = "682fc3078229a4fc06b5f021af058c45b9f3bc02" +version = "0.5" default-features = false features = ["std", "socket-raw", "proto-ipv4", "socket-udp", "socket-tcp", "socket-icmp"] diff --git a/src/smolnetd/scheme/icmp.rs b/src/smolnetd/scheme/icmp.rs index 08546a256b..54a5ca6665 100644 --- a/src/smolnetd/scheme/icmp.rs +++ b/src/smolnetd/scheme/icmp.rs @@ -179,7 +179,7 @@ impl<'a, 'b> SchemeSocket for IcmpSocket<'a, 'b> { let icmp_payload = self.send(icmp_repr.buffer_len(), file.data.ip) .map_err(|_| syscall::Error::new(syscall::EINVAL))?; - let mut icmp_packet = Icmpv4Packet::new(icmp_payload); + let mut icmp_packet = Icmpv4Packet::new_unchecked(icmp_payload); //TODO: replace Default with actual caps icmp_repr.emit(&mut icmp_packet, &Default::default()); Ok(Some(buf.len())) @@ -202,7 +202,7 @@ impl<'a, 'b> SchemeSocket for IcmpSocket<'a, 'b> { ) -> SyscallResult> { while self.can_recv() { let (payload, _) = self.recv().expect("Can't recv icmp packet"); - let icmp_packet = Icmpv4Packet::new(&payload); + let icmp_packet = Icmpv4Packet::new_unchecked(&payload); //TODO: replace default with actual caps let icmp_repr = Icmpv4Repr::parse(&icmp_packet, &Default::default()).unwrap(); From 51446652a187f2b2312a79930da9b5f6a889ce26 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Tue, 1 Jan 2019 20:23:21 -0700 Subject: [PATCH 093/155] Update smoltcp --- Cargo.lock | 15 ++++----------- Cargo.toml | 5 +++-- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f825bcadbd..54538ecc39 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -475,15 +475,10 @@ dependencies = [ "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "netutils 0.1.0 (git+https://gitlab.redox-os.org/redox-os/netutils.git)", "redox_event 0.1.0 (git+https://gitlab.redox-os.org/redox-os/event.git)", - "redox_syscall 0.1.50 (git+https://gitlab.redox-os.org/redox-os/syscall.git)", - "smoltcp 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.50 (registry+https://github.com/rust-lang/crates.io-index)", + "smoltcp 0.5.0 (git+https://github.com/m-labs/smoltcp.git?rev=ed8dce015c45ee6e37c8d671f290a6d9b7fb49ac)", ] -[[package]] -name = "redox_syscall" -version = "0.1.50" -source = "git+https://gitlab.redox-os.org/redox-os/syscall.git#9a3734c41ac452bc3f8fe6d9a6b687c96cc3ca15" - [[package]] name = "redox_syscall" version = "0.1.50" @@ -577,11 +572,10 @@ dependencies = [ [[package]] name = "smoltcp" version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" +source = "git+https://github.com/m-labs/smoltcp.git?rev=ed8dce015c45ee6e37c8d671f290a6d9b7fb49ac#ed8dce015c45ee6e37c8d671f290a6d9b7fb49ac" dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "managed 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -942,7 +936,6 @@ dependencies = [ "checksum rand_pcg 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "086bd09a33c7044e56bb44d5bdde5a60e7f119a9e95b0775f545de759a32fe05" "checksum rand_xorshift 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "effa3fcaa47e18db002bdde6060944b6d2f9cfd8db471c30e873448ad9187be3" "checksum redox_event 0.1.0 (git+https://gitlab.redox-os.org/redox-os/event.git)" = "" -"checksum redox_syscall 0.1.50 (git+https://gitlab.redox-os.org/redox-os/syscall.git)" = "" "checksum redox_syscall 0.1.50 (registry+https://github.com/rust-lang/crates.io-index)" = "52ee9a534dc1301776eff45b4fa92d2c39b1d8c3d3357e6eb593e0d795506fc2" "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" "checksum ring 0.13.5 (registry+https://github.com/rust-lang/crates.io-index)" = "2c4db68a2e35f3497146b7e4563df7d4773a2433230c5e4b448328e31740458a" @@ -955,7 +948,7 @@ dependencies = [ "checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" "checksum slab 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5f9776d6b986f77b35c6cf846c11ad986ff128fe0b2b63a3628e3755e8d3102d" "checksum smallvec 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)" = "b73ea3738b47563803ef814925e69be00799a8c07420be8b996f8e98fb2336db" -"checksum smoltcp 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fef582369edb298c6c41319a544ca9c4e83622f226055ccfcb35974fbb55ed34" +"checksum smoltcp 0.5.0 (git+https://github.com/m-labs/smoltcp.git?rev=ed8dce015c45ee6e37c8d671f290a6d9b7fb49ac)" = "" "checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" "checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" "checksum time 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)" = "847da467bf0db05882a9e2375934a8a55cffdc9db0d128af1518200260ba1f6c" diff --git a/Cargo.toml b/Cargo.toml index 350c8e278c..c34d1e8901 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ path = "src/lib/lib.rs" [dependencies] netutils = { git = "https://gitlab.redox-os.org/redox-os/netutils.git" } redox_event = { git = "https://gitlab.redox-os.org/redox-os/event.git" } -redox_syscall = { git = "https://gitlab.redox-os.org/redox-os/syscall.git" } +redox_syscall = "0.1" byteorder = { version = "1.0", default-features = false } dns-parser = "0.7.1" @@ -27,7 +27,8 @@ default-features = false features = ["release_max_level_off"] [dependencies.smoltcp] -version = "0.5" +git = "https://github.com/m-labs/smoltcp.git" +rev = "ed8dce015c45ee6e37c8d671f290a6d9b7fb49ac" default-features = false features = ["std", "socket-raw", "proto-ipv4", "socket-udp", "socket-tcp", "socket-icmp"] From 1ea5e3158b4c9b1e1babf00339b1accc2354efdf Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Thu, 3 Jan 2019 21:23:59 -0700 Subject: [PATCH 094/155] Use smoltcp submodule --- .gitmodules | 3 +++ Cargo.lock | 5 ++--- Cargo.toml | 3 +-- smoltcp | 1 + 4 files changed, 7 insertions(+), 5 deletions(-) create mode 100644 .gitmodules create mode 160000 smoltcp diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000000..28922f40c6 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "smoltcp"] + path = smoltcp + url = https://gitlab.redox-os.org/redox-os/smoltcp.git diff --git a/Cargo.lock b/Cargo.lock index 54538ecc39..f68f998555 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -476,7 +476,7 @@ dependencies = [ "netutils 0.1.0 (git+https://gitlab.redox-os.org/redox-os/netutils.git)", "redox_event 0.1.0 (git+https://gitlab.redox-os.org/redox-os/event.git)", "redox_syscall 0.1.50 (registry+https://github.com/rust-lang/crates.io-index)", - "smoltcp 0.5.0 (git+https://github.com/m-labs/smoltcp.git?rev=ed8dce015c45ee6e37c8d671f290a6d9b7fb49ac)", + "smoltcp 0.5.0", ] [[package]] @@ -572,10 +572,10 @@ dependencies = [ [[package]] name = "smoltcp" version = "0.5.0" -source = "git+https://github.com/m-labs/smoltcp.git?rev=ed8dce015c45ee6e37c8d671f290a6d9b7fb49ac#ed8dce015c45ee6e37c8d671f290a6d9b7fb49ac" dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "managed 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -948,7 +948,6 @@ dependencies = [ "checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" "checksum slab 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5f9776d6b986f77b35c6cf846c11ad986ff128fe0b2b63a3628e3755e8d3102d" "checksum smallvec 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)" = "b73ea3738b47563803ef814925e69be00799a8c07420be8b996f8e98fb2336db" -"checksum smoltcp 0.5.0 (git+https://github.com/m-labs/smoltcp.git?rev=ed8dce015c45ee6e37c8d671f290a6d9b7fb49ac)" = "" "checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" "checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" "checksum time 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)" = "847da467bf0db05882a9e2375934a8a55cffdc9db0d128af1518200260ba1f6c" diff --git a/Cargo.toml b/Cargo.toml index c34d1e8901..e9c64b4307 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,8 +27,7 @@ default-features = false features = ["release_max_level_off"] [dependencies.smoltcp] -git = "https://github.com/m-labs/smoltcp.git" -rev = "ed8dce015c45ee6e37c8d671f290a6d9b7fb49ac" +path = "smoltcp" default-features = false features = ["std", "socket-raw", "proto-ipv4", "socket-udp", "socket-tcp", "socket-icmp"] diff --git a/smoltcp b/smoltcp new file mode 160000 index 0000000000..30793fc901 --- /dev/null +++ b/smoltcp @@ -0,0 +1 @@ +Subproject commit 30793fc901dc3a836e3177cc2b1e782389748fd5 From 880c107dd3cba43293903a986fd73ffdc5961256 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sat, 5 Jan 2019 07:54:45 -0700 Subject: [PATCH 095/155] Enable debugging --- Cargo.toml | 4 ++-- src/smolnetd/scheme/mod.rs | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e9c64b4307..3d19c751f1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,12 +24,12 @@ dns-parser = "0.7.1" [dependencies.log] version = "0.3" default-features = false -features = ["release_max_level_off"] +features = [] [dependencies.smoltcp] path = "smoltcp" default-features = false -features = ["std", "socket-raw", "proto-ipv4", "socket-udp", "socket-tcp", "socket-icmp"] +features = ["log", "verbose", "std", "socket-raw", "proto-ipv4", "socket-udp", "socket-tcp", "socket-icmp"] [profile.release] lto = true diff --git a/src/smolnetd/scheme/mod.rs b/src/smolnetd/scheme/mod.rs index eb563afa94..517f9c0541 100644 --- a/src/smolnetd/scheme/mod.rs +++ b/src/smolnetd/scheme/mod.rs @@ -1,6 +1,7 @@ use netutils::getcfg; use smoltcp; use smoltcp::iface::{EthernetInterface, EthernetInterfaceBuilder, NeighborCache, Routes}; +use smoltcp::phy::EthernetTracer; use smoltcp::socket::SocketSet as SmoltcpSocketSet; use smoltcp::time::{Duration, Instant}; use smoltcp::wire::{EthernetAddress, IpAddress, IpCidr, IpEndpoint, Ipv4Address}; @@ -31,7 +32,7 @@ mod icmp; mod netcfg; type SocketSet = SmoltcpSocketSet<'static, 'static, 'static>; -type Interface = Rc>>; +type Interface = Rc>>>; const MAX_DURATION: Duration = Duration { millis: ::std::u64::MAX }; const MIN_DURATION: Duration = Duration { millis: 0 }; @@ -83,12 +84,14 @@ impl Smolnetd { let buffer_pool = Rc::new(RefCell::new(BufferPool::new(Self::MAX_PACKET_SIZE))); let input_queue = Rc::new(RefCell::new(VecDeque::new())); let network_file = Rc::new(RefCell::new(network_file)); - let network_device = NetworkDevice::new( + let network_device = EthernetTracer::new(NetworkDevice::new( Rc::clone(&network_file), Rc::clone(&input_queue), hardware_addr, Rc::clone(&buffer_pool), - ); + ), |_timestamp, printer| { + trace!("{}", printer) + }); let mut routes = Routes::new(BTreeMap::new()); routes.add_default_ipv4_route(default_gw).expect("Failed to add default gateway"); let iface = EthernetInterfaceBuilder::new(network_device) From dba4db694ce013ea0fb3efbb464dd6716560733f Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sat, 2 Feb 2019 13:58:19 -0700 Subject: [PATCH 096/155] Use WouldBlock with network file --- src/smolnetd/scheme/mod.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/smolnetd/scheme/mod.rs b/src/smolnetd/scheme/mod.rs index 517f9c0541..d09051a584 100644 --- a/src/smolnetd/scheme/mod.rs +++ b/src/smolnetd/scheme/mod.rs @@ -8,7 +8,7 @@ use smoltcp::wire::{EthernetAddress, IpAddress, IpCidr, IpEndpoint, Ipv4Address} use std::cell::RefCell; use std::collections::{BTreeMap, VecDeque}; use std::fs::File; -use std::io::{Read, Write}; +use std::io::{self, Read, Write}; use std::mem::size_of; use std::rc::Rc; use std::str::FromStr; @@ -216,13 +216,15 @@ impl Smolnetd { let mut total_frames = 0; loop { let mut buffer = self.buffer_pool.borrow_mut().get_buffer(); - let count = self.network_file - .borrow_mut() - .read(&mut buffer) - .map_err(|e| Error::from_io_error(e, "Failed to read from network file"))?; - if count == 0 { - break; - } + let count = match self.network_file.borrow_mut().read(&mut buffer) { + Ok(count) => count, + Err(err) => match err.kind() { + io::ErrorKind::WouldBlock => break, + _ => return Err( + Error::from_io_error(err, "Failed to read from network file") + ) + } + }; buffer.resize(count); self.input_queue.borrow_mut().push_back(buffer); total_frames += 1; From 19aabd5e666a1e03a8c9e4c830e15969e667c8fb Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sun, 17 Feb 2019 20:19:35 -0700 Subject: [PATCH 097/155] Fix hangs when a tcp stream is closed --- src/smolnetd/scheme/tcp.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/smolnetd/scheme/tcp.rs b/src/smolnetd/scheme/tcp.rs index 20f69b9f56..bc18754618 100644 --- a/src/smolnetd/scheme/tcp.rs +++ b/src/smolnetd/scheme/tcp.rs @@ -122,7 +122,7 @@ impl<'a> SchemeSocket for TcpSocket<'a> { } else if file.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { Err(SyscallError::new(syscall::EAGAIN)) } else { - Ok(None) // internally scheduled to re-read + Ok(None) // internally scheduled to re-write } } @@ -136,6 +136,8 @@ impl<'a> SchemeSocket for TcpSocket<'a> { } else if self.can_recv() { let length = self.recv_slice(buf).expect("Can't receive slice"); Ok(Some(length)) + } else if !self.may_recv() { + Ok(Some(0)) } else if file.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { Err(SyscallError::new(syscall::EAGAIN)) } else { From dca4ea500d67b93cdf6f19a3dd1320bc6968985e Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sun, 17 Feb 2019 20:31:13 -0700 Subject: [PATCH 098/155] Post read fevent at EOF --- src/smolnetd/scheme/icmp.rs | 4 ++++ src/smolnetd/scheme/ip.rs | 4 ++++ src/smolnetd/scheme/socket.rs | 3 ++- src/smolnetd/scheme/tcp.rs | 4 ++++ src/smolnetd/scheme/udp.rs | 4 ++++ 5 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/smolnetd/scheme/icmp.rs b/src/smolnetd/scheme/icmp.rs index 54a5ca6665..ddb31bc030 100644 --- a/src/smolnetd/scheme/icmp.rs +++ b/src/smolnetd/scheme/icmp.rs @@ -41,6 +41,10 @@ impl<'a, 'b> SchemeSocket for IcmpSocket<'a, 'b> { self.can_recv() } + fn may_recv(&self) -> bool { + true + } + fn get_setting( _file: &SocketFile, _setting: Self::SettingT, diff --git a/src/smolnetd/scheme/ip.rs b/src/smolnetd/scheme/ip.rs index 5cea1b9110..97a83cad32 100644 --- a/src/smolnetd/scheme/ip.rs +++ b/src/smolnetd/scheme/ip.rs @@ -27,6 +27,10 @@ impl<'a, 'b> SchemeSocket for RawSocket<'a, 'b> { self.can_recv() } + fn may_recv(&self) -> bool { + true + } + fn get_setting( _file: &SocketFile, _setting: Self::SettingT, diff --git a/src/smolnetd/scheme/socket.rs b/src/smolnetd/scheme/socket.rs index f1d07c4d16..18e690d0d9 100644 --- a/src/smolnetd/scheme/socket.rs +++ b/src/smolnetd/scheme/socket.rs @@ -123,6 +123,7 @@ where fn can_send(&self) -> bool; fn can_recv(&self) -> bool; + fn may_recv(&self) -> bool; fn hop_limit(&self) -> u8; fn set_hop_limit(&mut self, u8); @@ -214,7 +215,7 @@ where let mut socket_set = self.socket_set.borrow_mut(); let socket = socket_set.get::(socket_handle); - if events & syscall::EVENT_READ == syscall::EVENT_READ && socket.can_recv() { + if events & syscall::EVENT_READ == syscall::EVENT_READ && (socket.can_recv() || !socket.may_recv()) { if !*read_notified { post_fevent(&mut self.scheme_file, fd, syscall::EVENT_READ, 1)?; *read_notified = true; diff --git a/src/smolnetd/scheme/tcp.rs b/src/smolnetd/scheme/tcp.rs index bc18754618..ab33ff3c9f 100644 --- a/src/smolnetd/scheme/tcp.rs +++ b/src/smolnetd/scheme/tcp.rs @@ -26,6 +26,10 @@ impl<'a> SchemeSocket for TcpSocket<'a> { self.can_recv() } + fn may_recv(&self) -> bool { + self.may_recv() + } + fn hop_limit(&self) -> u8 { self.hop_limit().unwrap_or(64) } diff --git a/src/smolnetd/scheme/udp.rs b/src/smolnetd/scheme/udp.rs index f58ad285bd..d253e1aa10 100644 --- a/src/smolnetd/scheme/udp.rs +++ b/src/smolnetd/scheme/udp.rs @@ -28,6 +28,10 @@ impl<'a, 'b> SchemeSocket for UdpSocket<'a, 'b> { self.can_recv() } + fn may_recv(&self) -> bool { + true + } + fn hop_limit(&self) -> u8 { self.hop_limit().unwrap_or(64) } From 370b11fbf36999ea07066d8327761c0e68a6f88b Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Mon, 11 Mar 2019 20:03:11 -0600 Subject: [PATCH 099/155] Cleanup of wait queue --- src/smolnetd/scheme/mod.rs | 2 +- src/smolnetd/scheme/socket.rs | 160 ++++++++++------------------------ 2 files changed, 45 insertions(+), 117 deletions(-) diff --git a/src/smolnetd/scheme/mod.rs b/src/smolnetd/scheme/mod.rs index d09051a584..dc5eafbbc5 100644 --- a/src/smolnetd/scheme/mod.rs +++ b/src/smolnetd/scheme/mod.rs @@ -120,7 +120,7 @@ impl Smolnetd { pub fn on_network_scheme_event(&mut self) -> Result> { if self.read_frames()? > 0 { - self.poll().map(Some)?; + self.poll()?; } Ok(None) } diff --git a/src/smolnetd/scheme/socket.rs b/src/smolnetd/scheme/socket.rs index 18e690d0d9..b716b8ee17 100644 --- a/src/smolnetd/scheme/socket.rs +++ b/src/smolnetd/scheme/socket.rs @@ -104,8 +104,6 @@ struct WaitHandle { type WaitQueue = Vec; -type WaitQueueMap = BTreeMap; - pub type DupResult = Option<( SchemeFile, Option<(SocketHandle, ::DataT)>, @@ -163,7 +161,7 @@ where files: BTreeMap>, socket_set: Rc>, scheme_file: File, - wait_queue_map: WaitQueueMap, + wait_queue: WaitQueue, scheme_data: SocketT::SchemeDataT, _phantom_socket: PhantomData, } @@ -180,7 +178,7 @@ where socket_set, scheme_data: SocketT::new_scheme_data(), scheme_file, - wait_queue_map: BTreeMap::new(), + wait_queue: Vec::new(), _phantom_socket: PhantomData, } } @@ -195,13 +193,32 @@ where packet.a = a; self.scheme_file.write_all(&packet)?; } else { - self.handle_block(packet)?; + match self.handle_block(&mut packet) { + Ok(timeout) => { + self.wait_queue.push(WaitHandle { + until: timeout, + packet: packet, + }); + }, + Err(err) => { + packet.a = (-err.errno) as usize; + self.scheme_file.write_all(&packet)?; + return Err(Error::from_syscall_error( + err, + "Can't handle blocked socket", + )); + } + } } } Ok(None) } pub fn notify_sockets(&mut self) -> Result<()> { + let mut cur_time = TimeSpec::default(); + syscall::clock_gettime(syscall::CLOCK_MONOTONIC, &mut cur_time) + .map_err(|e| Error::from_syscall_error(e, "Can't get time"))?; + // Notify non-blocking sockets for (&fd, ref mut file) in &mut self.files { if let &mut SchemeFile::Socket(SocketFile { @@ -236,112 +253,43 @@ where } // Wake up blocking queue - self.wake_up_queues()?; - - Ok(()) - } - - fn wake_up_queues(&mut self) -> Result<()> { - let mut cur_time = TimeSpec::default(); - syscall::clock_gettime(syscall::CLOCK_MONOTONIC, &mut cur_time) - .map_err(|e| Error::from_syscall_error(e, "Can't get time"))?; - - let socket_handles: Vec<_> = self.wait_queue_map.keys().cloned().collect(); - - for socket_handle in socket_handles { - self.wake_up_wait_queue(socket_handle, cur_time)?; - } - Ok(()) - } - - fn wake_up_wait_queue( - &mut self, - socket_handle: SocketHandle, - cur_time: syscall::TimeSpec, - ) -> Result<()> { - let mut input_queue = if let Some(wait_queue) = self.wait_queue_map.get_mut(&socket_handle) - { - ::std::mem::replace(wait_queue, vec![]) - } else { - vec![] - }; - - let mut to_retain = vec![]; - - for wait_handle in input_queue.drain(..) { - let mut packet = wait_handle.packet; - if let Some(a) = self.handle(&mut packet) { + let mut i = 0; + while i < self.wait_queue.len() { + let mut packet = self.wait_queue[i].packet; + if let Some(a) = self.handle(&packet) { + self.wait_queue.remove(i); packet.a = a; self.scheme_file.write_all(&packet)?; } else { - match wait_handle.until { + match self.wait_queue[i].until { Some(until) if (until.tv_sec < cur_time.tv_sec || (until.tv_sec == cur_time.tv_sec && until.tv_nsec < cur_time.tv_nsec)) => { + self.wait_queue.remove(i); packet.a = (-syscall::ETIMEDOUT) as usize; self.scheme_file.write_all(&packet)?; - } + }, _ => { - to_retain.push(wait_handle); + i += 1; } } } } - if let Some(wait_queue) = self.wait_queue_map.get_mut(&socket_handle) { - wait_queue.extend(to_retain); - } - Ok(()) } - fn move_file_to_new_socket_handle( - wait_queue_map: &mut WaitQueueMap, - fd: usize, - from: SocketHandle, - to: SocketHandle, - ) -> SyscallResult<()> { - let mut to_move = vec![]; - - if let Some(wait_queue) = wait_queue_map.get_mut(&from) { - to_move = wait_queue - .drain_filter(|wh| wh.packet.b == fd) - .collect::>(); - } - - wait_queue_map - .entry(to) - .or_insert_with(|| vec![]) - .extend(to_move); - Ok(()) - } - - fn handle_block(&mut self, mut packet: SyscallPacket) -> Result<()> { - let syscall_result = self.try_handle_block(&mut packet); - if let Err(syscall_error) = syscall_result { - packet.a = (-syscall_error.errno) as usize; - self.scheme_file.write_all(&packet)?; - Err(Error::from_syscall_error( - syscall_error, - "Can't handle blocked socket", - )) - } else { - Ok(()) - } - } - - fn try_handle_block(&mut self, packet: &mut SyscallPacket) -> SyscallResult<()> { + fn handle_block(&mut self, packet: &mut SyscallPacket) -> SyscallResult> { let fd = packet.b; - let (socket_handle, read_timeout, write_timeout) = { + let (read_timeout, write_timeout) = { let file = self.files .get(&fd) .ok_or_else(|| SyscallError::new(syscall::EBADF))?; if let SchemeFile::Socket(ref scheme_file) = *file { Ok(( - scheme_file.socket_handle, scheme_file.read_timeout, scheme_file.write_timeout, )) @@ -362,16 +310,7 @@ where *timeout = add_time(timeout, &cur_time) } - let wait_queue = self.wait_queue_map - .entry(socket_handle) - .or_insert_with(|| vec![]); - - wait_queue.push(WaitHandle { - until: timeout, - packet: *packet, - }); - - Ok(()) + Ok(timeout) } fn get_setting( @@ -538,21 +477,14 @@ where let socket = socket_set.get::(socket_handle); socket.close_file(&scheme_file, &mut self.scheme_data)?; } - let remove_wq = - if let Some(ref mut wait_queue) = self.wait_queue_map.get_mut(&socket_handle) { - wait_queue.retain( - |&WaitHandle { - packet: SyscallPacket { a, .. }, - .. - }| a != fd, - ); - wait_queue.is_empty() - } else { - false - }; - if remove_wq { - self.wait_queue_map.remove(&socket_handle); - } + + self.wait_queue.retain( + |&WaitHandle { + packet: SyscallPacket { a, .. }, + .. + }| a != fd, + ); + socket_set.release(socket_handle); //TODO: removing sockets in release should make prune unnecessary socket_set.prune(); @@ -560,6 +492,7 @@ where } fn write(&mut self, fd: usize, buf: &[u8]) -> SyscallResult> { + println!("write({}, {:p}, {})", fd, buf.as_ptr(), buf.len()); let (fd, setting) = { let file = self.files .get_mut(&fd) @@ -580,6 +513,7 @@ where } fn read(&mut self, fd: usize, buf: &mut [u8]) -> SyscallResult> { + println!("read({}, {:p}, {})", fd, buf.as_ptr(), buf.len()); let (fd, setting) = { let file = self.files .get_mut(&fd) @@ -653,12 +587,6 @@ where if let Some((socket_handle, data)) = update_with { if let SchemeFile::Socket(ref mut file) = *file { - Self::move_file_to_new_socket_handle( - &mut self.wait_queue_map, - fd, - file.socket_handle, - socket_handle, - )?; file.socket_handle = socket_handle; file.data = data; } else { From 4384a16d4fe5aaa506433b533d1c6b6c1834932a Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Tue, 12 Mar 2019 20:31:02 -0600 Subject: [PATCH 100/155] Ensure that missing network events do not hang the network stack --- src/smolnetd/scheme/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/smolnetd/scheme/mod.rs b/src/smolnetd/scheme/mod.rs index dc5eafbbc5..3a194410cf 100644 --- a/src/smolnetd/scheme/mod.rs +++ b/src/smolnetd/scheme/mod.rs @@ -152,7 +152,8 @@ impl Smolnetd { pub fn on_time_event(&mut self) -> Result> { let timeout = self.poll()?; self.schedule_time_event(timeout)?; - Ok(None) + //TODO: Fix network scheme to ensure events are not missed + self.on_network_scheme_event() } pub fn on_netcfg_scheme_event(&mut self) -> Result> { From 00ad7e74abb6d8102454e91b554cb1323dd8d518 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Tue, 12 Mar 2019 20:32:14 -0600 Subject: [PATCH 101/155] Remove debugging --- Cargo.lock | 1 - Cargo.toml | 5 +++-- src/smolnetd/scheme/socket.rs | 2 -- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f68f998555..51be9a289d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -575,7 +575,6 @@ version = "0.5.0" dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "managed 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/Cargo.toml b/Cargo.toml index 3d19c751f1..fff752a710 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,12 +24,13 @@ dns-parser = "0.7.1" [dependencies.log] version = "0.3" default-features = false -features = [] +features = ["release_max_level_warn"] [dependencies.smoltcp] path = "smoltcp" default-features = false -features = ["log", "verbose", "std", "socket-raw", "proto-ipv4", "socket-udp", "socket-tcp", "socket-icmp"] +features = ["std", "socket-raw", "proto-ipv4", "socket-udp", "socket-tcp", "socket-icmp"] +#For debugging: "log", "verbose" [profile.release] lto = true diff --git a/src/smolnetd/scheme/socket.rs b/src/smolnetd/scheme/socket.rs index b716b8ee17..6e59fc5862 100644 --- a/src/smolnetd/scheme/socket.rs +++ b/src/smolnetd/scheme/socket.rs @@ -492,7 +492,6 @@ where } fn write(&mut self, fd: usize, buf: &[u8]) -> SyscallResult> { - println!("write({}, {:p}, {})", fd, buf.as_ptr(), buf.len()); let (fd, setting) = { let file = self.files .get_mut(&fd) @@ -513,7 +512,6 @@ where } fn read(&mut self, fd: usize, buf: &mut [u8]) -> SyscallResult> { - println!("read({}, {:p}, {})", fd, buf.as_ptr(), buf.len()); let (fd, setting) = { let file = self.files .get_mut(&fd) From 2079856d97ae218d01f32be4b881360765b2b51d Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Wed, 13 Mar 2019 14:11:38 -0600 Subject: [PATCH 102/155] Update to new fevent --- src/smolnetd/scheme/netcfg/mod.rs | 2 +- src/smolnetd/scheme/socket.rs | 76 ++++++++++++++++++------------- 2 files changed, 46 insertions(+), 32 deletions(-) diff --git a/src/smolnetd/scheme/netcfg/mod.rs b/src/smolnetd/scheme/netcfg/mod.rs index 37de40b31f..d5c3abe31d 100644 --- a/src/smolnetd/scheme/netcfg/mod.rs +++ b/src/smolnetd/scheme/netcfg/mod.rs @@ -505,7 +505,7 @@ impl SchemeMut for NetCfgScheme { } else { self.notifier.borrow_mut().unsubscribe(&file.path, fd); } - Ok(fd) + Ok(0) } fn fsync(&mut self, fd: usize) -> SyscallResult { diff --git a/src/smolnetd/scheme/socket.rs b/src/smolnetd/scheme/socket.rs index 6e59fc5862..58f9d9c2ca 100644 --- a/src/smolnetd/scheme/socket.rs +++ b/src/smolnetd/scheme/socket.rs @@ -9,9 +9,10 @@ use std::ops::Deref; use std::ops::DerefMut; use std::rc::Rc; use std::str; -use syscall::data::TimeSpec; -use syscall::{Error as SyscallError, Packet as SyscallPacket, Result as SyscallResult, SchemeBlockMut}; use syscall; +use syscall::{Error as SyscallError, Packet as SyscallPacket, Result as SyscallResult, SchemeBlockMut}; +use syscall::data::TimeSpec; +use syscall::flag::{EVENT_READ, EVENT_WRITE}; use redox_netstack::error::{Error, Result}; use super::{post_fevent, SocketSet}; @@ -94,6 +95,39 @@ where | SchemeFile::Setting(SettingFile { socket_handle, .. }) => socket_handle, } } + + pub fn events(&mut self, socket_set: &mut SocketSet) -> usize where SocketT: AnySocket<'static, 'static> { + let mut revents = 0; + if let &mut SchemeFile::Socket(SocketFile { + socket_handle, + events, + ref mut read_notified, + ref mut write_notified, + .. + }) = self + { + let socket = socket_set.get::(socket_handle); + + if events & syscall::EVENT_READ == syscall::EVENT_READ && (socket.can_recv() || !socket.may_recv()) { + if !*read_notified { + *read_notified = true; + revents |= EVENT_READ; + } + } else { + *read_notified = false; + } + + if events & syscall::EVENT_WRITE == syscall::EVENT_WRITE && socket.can_send() { + if !*write_notified { + *write_notified = true; + revents |= EVENT_WRITE; + } + } else { + *write_notified = false; + } + } + revents + } } #[derive(Default, Clone)] @@ -221,34 +255,12 @@ where // Notify non-blocking sockets for (&fd, ref mut file) in &mut self.files { - if let &mut SchemeFile::Socket(SocketFile { - socket_handle, - events, - ref mut read_notified, - ref mut write_notified, - .. - }) = *file - { + let events = { let mut socket_set = self.socket_set.borrow_mut(); - let socket = socket_set.get::(socket_handle); - - if events & syscall::EVENT_READ == syscall::EVENT_READ && (socket.can_recv() || !socket.may_recv()) { - if !*read_notified { - post_fevent(&mut self.scheme_file, fd, syscall::EVENT_READ, 1)?; - *read_notified = true; - } - } else { - *read_notified = false; - } - - if events & syscall::EVENT_WRITE == syscall::EVENT_WRITE && socket.can_send() { - if !*write_notified { - post_fevent(&mut self.scheme_file, fd, syscall::EVENT_WRITE, 1)?; - *write_notified = true; - } - } else { - *write_notified = false; - } + file.events(&mut socket_set) + }; + if events > 0 { + post_fevent(&mut self.scheme_file, fd, events, 1)?; } } @@ -608,14 +620,16 @@ where .get_mut(&fd) .ok_or_else(|| SyscallError::new(syscall::EBADF))?; match *file { - SchemeFile::Setting(_) => Err(SyscallError::new(syscall::EBADF)), + SchemeFile::Setting(_) => return Err(SyscallError::new(syscall::EBADF)), SchemeFile::Socket(ref mut file) => { file.events = events; file.read_notified = false; // resend missed events file.write_notified = false; - Ok(Some(fd)) } } + let mut socket_set = self.socket_set.borrow_mut(); + let revents = file.events(&mut socket_set); + Ok(Some(revents)) } fn fsync(&mut self, fd: usize) -> SyscallResult> { From 438691c241c203857117223ee04852540e71e268 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Wed, 24 Apr 2019 20:41:27 -0600 Subject: [PATCH 103/155] Patches for Redox as part of the unix target family --- Cargo.lock | 733 +++++------------------------------------------------ Cargo.toml | 9 +- 2 files changed, 76 insertions(+), 666 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 51be9a289d..83dcf8883d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,25 +1,10 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. [[package]] name = "arg_parser" version = "0.1.0" source = "git+https://gitlab.redox-os.org/redox-os/arg-parser.git#7503531821b0c111f9fac77a5d2536ea221105fe" -[[package]] -name = "arrayvec" -version = "0.4.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "base64" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", - "safemem 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "bitflags" version = "1.0.4" @@ -32,72 +17,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "byteorder" -version = "1.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "bytes" -version = "0.4.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", - "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "cc" -version = "1.0.28" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "cfg-if" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "cloudabi" -version = "0.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "crossbeam-deque" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "crossbeam-epoch 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam-utils 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "crossbeam-epoch" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam-utils 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "crossbeam-utils" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "dns-parser" version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -120,45 +53,6 @@ name = "fuchsia-zircon-sys" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "futures" -version = "0.1.25" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "httparse" -version = "1.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "hyper" -version = "0.10.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)", - "httparse 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", - "mime 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", - "num_cpus 1.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "time 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", - "traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "typeable 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "unicase 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "hyper-rustls" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "hyper 0.10.15 (registry+https://github.com/rust-lang/crates.io-index)", - "rustls 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)", - "webpki 0.18.1 (registry+https://github.com/rust-lang/crates.io-index)", - "webpki-roots 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "idna" version = "0.1.5" @@ -166,7 +60,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-normalization 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-normalization 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -174,7 +68,7 @@ name = "iovec" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (git+https://gitlab.redox-os.org/redox-os/liblibc.git?branch=redox-unix)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -187,29 +81,10 @@ dependencies = [ "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "language-tags" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "lazy_static" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "libc" -version = "0.2.45" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "lock_api" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "owning_ref 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", -] +version = "0.2.51" +source = "git+https://gitlab.redox-os.org/redox-os/liblibc.git?branch=redox-unix#f3c352801a999bef700cd05b67e77adfc46cb45d" [[package]] name = "log" @@ -224,7 +99,7 @@ name = "log" version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -237,54 +112,31 @@ name = "matches" version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "memoffset" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "mime" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "mio" version = "0.6.16" -source = "git+https://gitlab.redox-os.org/redox-os/mio#493d2b65c12b269c4481fd1dc2cd7d3670a880c9" +source = "git+https://gitlab.redox-os.org/redox-os/mio.git#439a559b2aa734e0970d37b3375889a57a465360" dependencies = [ "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (git+https://gitlab.redox-os.org/redox-os/liblibc.git?branch=redox-unix)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.50 (registry+https://github.com/rust-lang/crates.io-index)", - "slab 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "net2 0.2.33 (git+https://gitlab.redox-os.org/redox-os/net2-rs.git?branch=redox-unix)", + "redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)", + "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "mio-uds" -version = "0.6.6" -source = "git+https://gitlab.redox-os.org/redox-os/mio-uds#2936ef82070ea0c4aa8a7360455b8c512d8c88c0" -dependencies = [ - "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.16 (git+https://gitlab.redox-os.org/redox-os/mio)", -] - [[package]] name = "miow" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", + "net2 0.2.33 (git+https://gitlab.redox-os.org/redox-os/net2-rs.git?branch=redox-unix)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -292,95 +144,53 @@ dependencies = [ [[package]] name = "net2" version = "0.2.33" -source = "registry+https://github.com/rust-lang/crates.io-index" +source = "git+https://gitlab.redox-os.org/redox-os/net2-rs.git?branch=redox-unix#b2c7c1e7773f13eebd9b4421172d9e4b5b806ce6" dependencies = [ - "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (git+https://gitlab.redox-os.org/redox-os/liblibc.git?branch=redox-unix)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "netutils" version = "0.1.0" -source = "git+https://gitlab.redox-os.org/redox-os/netutils.git#03d76ff3b5c4a42e300e3016f42fd632193bbc9d" +source = "git+https://gitlab.redox-os.org/redox-os/netutils.git?branch=redox-unix#482c8285faa70c592d235336faaf7223f195b5d7" dependencies = [ "arg_parser 0.1.0 (git+https://gitlab.redox-os.org/redox-os/arg-parser.git)", "extra 0.1.0 (git+https://gitlab.redox-os.org/redox-os/libextra.git)", - "hyper 0.10.15 (registry+https://github.com/rust-lang/crates.io-index)", - "hyper-rustls 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.16 (git+https://gitlab.redox-os.org/redox-os/mio)", + "libc 0.2.51 (git+https://gitlab.redox-os.org/redox-os/liblibc.git?branch=redox-unix)", + "mio 0.6.16 (git+https://gitlab.redox-os.org/redox-os/mio.git)", "ntpclient 0.0.1 (git+https://github.com/willem66745/ntpclient-rust)", - "pbr 1.0.1 (git+https://github.com/a8m/pb)", + "pbr 1.0.1 (git+https://gitlab.redox-os.org/redox-os/pb.git?branch=redox-unix)", "redox_event 0.1.0 (git+https://gitlab.redox-os.org/redox-os/event.git)", - "redox_syscall 0.1.50 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)", "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio 0.1.13 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-reactor 0.1.7 (git+https://gitlab.redox-os.org/redox-os/tokio)", + "termion 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "nodrop" -version = "0.1.13" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "ntpclient" version = "0.0.1" source = "git+https://github.com/willem66745/ntpclient-rust#7e3bdf60eb940825789a8da5181025320e3050b0" dependencies = [ "byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", - "time 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.42 (git+https://gitlab.redox-os.org/redox-os/time.git?branch=redox-unix)", ] [[package]] -name = "num_cpus" -version = "1.9.0" +name = "numtoa" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "owning_ref" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "parking_lot" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "lock_api 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "parking_lot_core" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "smallvec 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", -] [[package]] name = "pbr" version = "1.0.1" -source = "git+https://github.com/a8m/pb#b9792c9fe37343234316e23c263874cf383b208d" +source = "git+https://gitlab.redox-os.org/redox-os/pb.git?branch=redox-unix#743300cf9566f77962a5b550db1ba27cc922b6a5" dependencies = [ - "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", - "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "time 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (git+https://gitlab.redox-os.org/redox-os/liblibc.git?branch=redox-unix)", + "time 0.1.42 (git+https://gitlab.redox-os.org/redox-os/time.git?branch=redox-unix)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -393,95 +203,30 @@ name = "quick-error" version = "1.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "rand" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_chacha 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_pcg 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_xorshift 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "rand_chacha" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "rand_core" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "rand_hc" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "rand_isaac" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "rand_pcg" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "rand_xorshift" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "redox_event" version = "0.1.0" source = "git+https://gitlab.redox-os.org/redox-os/event.git#c31e3d3d5f44d60ff9fec2b1ee58b982e72c0d77" dependencies = [ - "redox_syscall 0.1.50 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "redox_netstack" version = "0.1.0" dependencies = [ - "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "dns-parser 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", - "netutils 0.1.0 (git+https://gitlab.redox-os.org/redox-os/netutils.git)", + "netutils 0.1.0 (git+https://gitlab.redox-os.org/redox-os/netutils.git?branch=redox-unix)", "redox_event 0.1.0 (git+https://gitlab.redox-os.org/redox-os/event.git)", - "redox_syscall 0.1.50 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)", "smoltcp 0.5.0", ] [[package]] name = "redox_syscall" -version = "0.1.50" +version = "0.1.54" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -489,291 +234,46 @@ name = "redox_termios" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "redox_syscall 0.1.50 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "ring" -version = "0.13.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cc 1.0.28 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", - "untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "rustc_version" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "rustls" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "ring 0.13.5 (registry+https://github.com/rust-lang/crates.io-index)", - "sct 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", - "webpki 0.18.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "safemem" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "scopeguard" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "sct" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "ring 0.13.5 (registry+https://github.com/rust-lang/crates.io-index)", - "untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "semver" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "semver-parser" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "slab" -version = "0.4.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "smallvec" -version = "0.6.7" +version = "0.6.9" source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", -] [[package]] name = "smoltcp" version = "0.5.0" dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "managed 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "stable_deref_trait" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "termion" -version = "1.5.1" +version = "1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (git+https://gitlab.redox-os.org/redox-os/liblibc.git?branch=redox-unix)", + "numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)", "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "time" -version = "0.1.41" -source = "registry+https://github.com/rust-lang/crates.io-index" +version = "0.1.42" +source = "git+https://gitlab.redox-os.org/redox-os/time.git?branch=redox-unix#fc118e5752aaac833808a25f0850606b675b32ec" dependencies = [ - "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.50 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "tokio" -version = "0.1.13" -source = "git+https://gitlab.redox-os.org/redox-os/tokio#e90845fe8a0e259eeb569d0424f27e276851dced" -dependencies = [ - "bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.16 (git+https://gitlab.redox-os.org/redox-os/mio)", - "num_cpus 1.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-codec 0.1.1 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-current-thread 0.1.4 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-executor 0.1.5 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-fs 0.1.4 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-io 0.1.10 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-reactor 0.1.7 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-tcp 0.1.2 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-threadpool 0.1.9 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-timer 0.2.8 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-udp 0.1.3 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-uds 0.2.4 (git+https://gitlab.redox-os.org/redox-os/tokio)", -] - -[[package]] -name = "tokio-codec" -version = "0.1.1" -source = "git+https://gitlab.redox-os.org/redox-os/tokio#e90845fe8a0e259eeb569d0424f27e276851dced" -dependencies = [ - "bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-io 0.1.10 (git+https://gitlab.redox-os.org/redox-os/tokio)", -] - -[[package]] -name = "tokio-current-thread" -version = "0.1.4" -source = "git+https://gitlab.redox-os.org/redox-os/tokio#e90845fe8a0e259eeb569d0424f27e276851dced" -dependencies = [ - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-executor 0.1.5 (git+https://gitlab.redox-os.org/redox-os/tokio)", -] - -[[package]] -name = "tokio-executor" -version = "0.1.5" -source = "git+https://gitlab.redox-os.org/redox-os/tokio#e90845fe8a0e259eeb569d0424f27e276851dced" -dependencies = [ - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "tokio-fs" -version = "0.1.4" -source = "git+https://gitlab.redox-os.org/redox-os/tokio#e90845fe8a0e259eeb569d0424f27e276851dced" -dependencies = [ - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-io 0.1.10 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-threadpool 0.1.9 (git+https://gitlab.redox-os.org/redox-os/tokio)", -] - -[[package]] -name = "tokio-io" -version = "0.1.10" -source = "git+https://gitlab.redox-os.org/redox-os/tokio#e90845fe8a0e259eeb569d0424f27e276851dced" -dependencies = [ - "bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "tokio-reactor" -version = "0.1.7" -source = "git+https://gitlab.redox-os.org/redox-os/tokio#e90845fe8a0e259eeb569d0424f27e276851dced" -dependencies = [ - "crossbeam-utils 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.16 (git+https://gitlab.redox-os.org/redox-os/mio)", - "num_cpus 1.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "slab 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-executor 0.1.5 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-io 0.1.10 (git+https://gitlab.redox-os.org/redox-os/tokio)", -] - -[[package]] -name = "tokio-tcp" -version = "0.1.2" -source = "git+https://gitlab.redox-os.org/redox-os/tokio#e90845fe8a0e259eeb569d0424f27e276851dced" -dependencies = [ - "bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.16 (git+https://gitlab.redox-os.org/redox-os/mio)", - "tokio-io 0.1.10 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-reactor 0.1.7 (git+https://gitlab.redox-os.org/redox-os/tokio)", -] - -[[package]] -name = "tokio-threadpool" -version = "0.1.9" -source = "git+https://gitlab.redox-os.org/redox-os/tokio#e90845fe8a0e259eeb569d0424f27e276851dced" -dependencies = [ - "crossbeam-deque 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam-utils 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "num_cpus 1.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-executor 0.1.5 (git+https://gitlab.redox-os.org/redox-os/tokio)", -] - -[[package]] -name = "tokio-timer" -version = "0.2.8" -source = "git+https://gitlab.redox-os.org/redox-os/tokio#e90845fe8a0e259eeb569d0424f27e276851dced" -dependencies = [ - "crossbeam-utils 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "slab 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-executor 0.1.5 (git+https://gitlab.redox-os.org/redox-os/tokio)", -] - -[[package]] -name = "tokio-udp" -version = "0.1.3" -source = "git+https://gitlab.redox-os.org/redox-os/tokio#e90845fe8a0e259eeb569d0424f27e276851dced" -dependencies = [ - "bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.16 (git+https://gitlab.redox-os.org/redox-os/mio)", - "tokio-codec 0.1.1 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-io 0.1.10 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-reactor 0.1.7 (git+https://gitlab.redox-os.org/redox-os/tokio)", -] - -[[package]] -name = "tokio-uds" -version = "0.2.4" -source = "git+https://gitlab.redox-os.org/redox-os/tokio#e90845fe8a0e259eeb569d0424f27e276851dced" -dependencies = [ - "bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.16 (git+https://gitlab.redox-os.org/redox-os/mio)", - "mio-uds 0.6.6 (git+https://gitlab.redox-os.org/redox-os/mio-uds)", - "tokio-codec 0.1.1 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-io 0.1.10 (git+https://gitlab.redox-os.org/redox-os/tokio)", - "tokio-reactor 0.1.7 (git+https://gitlab.redox-os.org/redox-os/tokio)", -] - -[[package]] -name = "traitobject" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "typeable" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "unicase" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (git+https://gitlab.redox-os.org/redox-os/liblibc.git?branch=redox-unix)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -786,22 +286,12 @@ dependencies = [ [[package]] name = "unicode-normalization" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "unreachable" -version = "1.0.0" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "untrusted" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "url" version = "1.7.2" @@ -812,34 +302,6 @@ dependencies = [ "percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "version_check" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "void" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "webpki" -version = "0.18.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "ring 0.13.5 (registry+https://github.com/rust-lang/crates.io-index)", - "untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "webpki-roots" -version = "0.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", - "webpki 0.18.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "winapi" version = "0.2.8" @@ -847,7 +309,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "winapi" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -880,102 +342,43 @@ dependencies = [ [metadata] "checksum arg_parser 0.1.0 (git+https://gitlab.redox-os.org/redox-os/arg-parser.git)" = "" -"checksum arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "92c7fb76bc8826a8b33b4ee5bb07a247a81e76764ab4d55e8f73e3a4d8808c71" -"checksum base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)" = "489d6c0ed21b11d038c31b6ceccca973e65d73ba3bd8ecb9a2babf5546164643" "checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12" "checksum byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855" -"checksum byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "94f88df23a25417badc922ab0f5716cc1330e87f71ddd9203b3a3ccd9cedf75d" -"checksum bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)" = "40ade3d27603c2cb345eb0912aec461a6dec7e06a4ae48589904e808335c7afa" -"checksum cc 1.0.28 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4a8b715cb4597106ea87c7c84b2f1d452c7492033765df7f32651e66fcf749" -"checksum cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "082bb9b28e00d3c9d39cc03e64ce4cea0f1bb9b3fde493f0cbc008472d22bdf4" -"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" -"checksum crossbeam-deque 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "05e44b8cf3e1a625844d1750e1f7820da46044ff6d28f4d43e455ba3e5bb2c13" -"checksum crossbeam-epoch 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f10a4f8f409aaac4b16a5474fb233624238fcdeefb9ba50d5ea059aab63ba31c" -"checksum crossbeam-utils 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "41ee4864f4797060e52044376f7d107429ce1fb43460021b126424b7180ee21a" +"checksum byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a019b10a2a7cdeb292db131fc8113e57ea2a908f6e7894b0c3c671893b65dbeb" +"checksum cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "11d43355396e872eefb45ce6342e4374ed7bc2b3a502d1b28e36d6e23c05d1f4" "checksum dns-parser 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f7020f6760aea312d43d23cb83bf6c0c49f162541db8b02bf95209ac51dc253d" "checksum extra 0.1.0 (git+https://gitlab.redox-os.org/redox-os/libextra.git)" = "" "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" "checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" -"checksum futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)" = "49e7653e374fe0d0c12de4250f0bdb60680b8c80eed558c5c7538eec9c89e21b" -"checksum httparse 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e8734b0cfd3bc3e101ec59100e101c2eecd19282202e87808b3037b442777a83" -"checksum hyper 0.10.15 (registry+https://github.com/rust-lang/crates.io-index)" = "df0caae6b71d266b91b4a83111a61d2b94ed2e2bea024c532b933dcff867e58c" -"checksum hyper-rustls 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "71f7b2e5858ab9e19771dc361159f09ee5031734a6f7471fe0947db0238d92b7" "checksum idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e" "checksum iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dbe6e417e7d0975db6512b90796e8ce223145ac4e33c377e4a42882a0e88bb08" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" -"checksum language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a" -"checksum lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a374c89b9db55895453a74c1e38861d9deec0b01b405a82516e9d5de4820dea1" -"checksum libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)" = "2d2857ec59fadc0773853c664d2d18e7198e83883e7060b63c924cb077bd5c74" -"checksum lock_api 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "62ebf1391f6acad60e5c8b43706dde4582df75c06698ab44511d15016bc2442c" +"checksum libc 0.2.51 (git+https://gitlab.redox-os.org/redox-os/liblibc.git?branch=redox-unix)" = "" "checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" "checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6" "checksum managed 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fdcec5e97041c7f0f1c5b7d93f12e57293c831c646f4cc7a5db59460c7ea8de6" "checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" -"checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3" -"checksum mime 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ba626b8a6de5da682e1caa06bdb42a335aee5a84db8e5046a3e8ab17ba0a3ae0" -"checksum mio 0.6.16 (git+https://gitlab.redox-os.org/redox-os/mio)" = "" -"checksum mio-uds 0.6.6 (git+https://gitlab.redox-os.org/redox-os/mio-uds)" = "" +"checksum mio 0.6.16 (git+https://gitlab.redox-os.org/redox-os/mio.git)" = "" "checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919" -"checksum net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "42550d9fb7b6684a6d404d9fa7250c2eb2646df731d1c06afc06dcee9e1bcf88" -"checksum netutils 0.1.0 (git+https://gitlab.redox-os.org/redox-os/netutils.git)" = "" -"checksum nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9667ddcc6cc8a43afc9b7917599d7216aa09c463919ea32c59ed6cac8bc945" +"checksum net2 0.2.33 (git+https://gitlab.redox-os.org/redox-os/net2-rs.git?branch=redox-unix)" = "" +"checksum netutils 0.1.0 (git+https://gitlab.redox-os.org/redox-os/netutils.git?branch=redox-unix)" = "" "checksum ntpclient 0.0.1 (git+https://github.com/willem66745/ntpclient-rust)" = "" -"checksum num_cpus 1.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5a69d464bdc213aaaff628444e99578ede64e9c854025aa43b9796530afa9238" -"checksum owning_ref 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "49a4b8ea2179e6a2e27411d3bca09ca6dd630821cf6894c6c7c8467a8ee7ef13" -"checksum parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ab41b4aed082705d1056416ae4468b6ea99d52599ecf3169b00088d43113e337" -"checksum parking_lot_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "94c8c7923936b28d546dfd14d4472eaf34c99b14e1c973a32b3e6d4eb04298c9" -"checksum pbr 1.0.1 (git+https://github.com/a8m/pb)" = "" +"checksum numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef" +"checksum pbr 1.0.1 (git+https://gitlab.redox-os.org/redox-os/pb.git?branch=redox-unix)" = "" "checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" "checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0" -"checksum rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ae9d223d52ae411a33cf7e54ec6034ec165df296ccd23533d671a28252b6f66a" -"checksum rand_chacha 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "771b009e3a508cb67e8823dda454aaa5368c7bc1c16829fb77d3e980440dd34a" -"checksum rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0905b6b7079ec73b314d4c748701f6931eb79fd97c668caa3f1899b22b32c6db" -"checksum rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" -"checksum rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" -"checksum rand_pcg 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "086bd09a33c7044e56bb44d5bdde5a60e7f119a9e95b0775f545de759a32fe05" -"checksum rand_xorshift 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "effa3fcaa47e18db002bdde6060944b6d2f9cfd8db471c30e873448ad9187be3" "checksum redox_event 0.1.0 (git+https://gitlab.redox-os.org/redox-os/event.git)" = "" -"checksum redox_syscall 0.1.50 (registry+https://github.com/rust-lang/crates.io-index)" = "52ee9a534dc1301776eff45b4fa92d2c39b1d8c3d3357e6eb593e0d795506fc2" +"checksum redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)" = "12229c14a0f65c4f1cb046a3b52047cdd9da1f4b30f8a39c5063c8bae515e252" "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" -"checksum ring 0.13.5 (registry+https://github.com/rust-lang/crates.io-index)" = "2c4db68a2e35f3497146b7e4563df7d4773a2433230c5e4b448328e31740458a" -"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" -"checksum rustls 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)" = "942b71057b31981152970d57399c25f72e27a6ee0d207a669d8304cabf44705b" -"checksum safemem 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dca453248a96cb0749e36ccdfe2b0b4e54a61bfef89fb97ec621eb8e0a93dd9" -"checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" -"checksum sct 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cb8f61f9e6eadd062a71c380043d28036304a4706b3c4dd001ff3387ed00745a" -"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" -"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" -"checksum slab 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5f9776d6b986f77b35c6cf846c11ad986ff128fe0b2b63a3628e3755e8d3102d" -"checksum smallvec 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)" = "b73ea3738b47563803ef814925e69be00799a8c07420be8b996f8e98fb2336db" -"checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" -"checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" -"checksum time 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)" = "847da467bf0db05882a9e2375934a8a55cffdc9db0d128af1518200260ba1f6c" -"checksum tokio 0.1.13 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" -"checksum tokio-codec 0.1.1 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" -"checksum tokio-current-thread 0.1.4 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" -"checksum tokio-executor 0.1.5 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" -"checksum tokio-fs 0.1.4 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" -"checksum tokio-io 0.1.10 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" -"checksum tokio-reactor 0.1.7 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" -"checksum tokio-tcp 0.1.2 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" -"checksum tokio-threadpool 0.1.9 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" -"checksum tokio-timer 0.2.8 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" -"checksum tokio-udp 0.1.3 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" -"checksum tokio-uds 0.2.4 (git+https://gitlab.redox-os.org/redox-os/tokio)" = "" -"checksum traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079" -"checksum typeable 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1410f6f91f21d1612654e7cc69193b0334f909dcf2c790c4826254fbb86f8887" -"checksum unicase 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7f4765f83163b74f957c797ad9253caf97f103fb064d3999aea9568d09fc8a33" +"checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" +"checksum smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c4488ae950c49d403731982257768f48fada354a5203fe81f9bb6f43ca9002be" +"checksum termion 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dde0593aeb8d47accea5392b39350015b5eccb12c0d98044d856983d89548dea" +"checksum time 0.1.42 (git+https://gitlab.redox-os.org/redox-os/time.git?branch=redox-unix)" = "" "checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" -"checksum unicode-normalization 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "6a0180bc61fc5a987082bfa111f4cc95c4caff7f9799f3e46df09163a937aa25" -"checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56" -"checksum untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "55cd1f4b4e96b46aeb8d4855db4a7a9bd96eeeb5c6a1ab54593328761642ce2f" +"checksum unicode-normalization 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "141339a08b982d942be2ca06ff8b076563cbe223d1befd5450716790d44e2426" "checksum url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dd4e7c0d531266369519a4aa4f399d748bd37043b00bde1e4ff1f60a120b355a" -"checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd" -"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" -"checksum webpki 0.18.1 (registry+https://github.com/rust-lang/crates.io-index)" = "17d7967316d8411ca3b01821ee6c332bde138ba4363becdb492f12e514daa17f" -"checksum webpki-roots 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "85d1f408918fd590908a70d36b7ac388db2edc221470333e4d6e5b598e44cabf" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" -"checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0" +"checksum winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "f10e386af2b13e47c89e7236a7a14a086791a2b88ebad6df9bf42040195cf770" "checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml index fff752a710..d23a54a8f1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ name = "redox_netstack" path = "src/lib/lib.rs" [dependencies] -netutils = { git = "https://gitlab.redox-os.org/redox-os/netutils.git" } +netutils = { git = "https://gitlab.redox-os.org/redox-os/netutils.git", branch = "redox-unix" } redox_event = { git = "https://gitlab.redox-os.org/redox-os/event.git" } redox_syscall = "0.1" byteorder = { version = "1.0", default-features = false } @@ -34,3 +34,10 @@ features = ["std", "socket-raw", "proto-ipv4", "socket-udp", "socket-tcp", "sock [profile.release] lto = true + +[patch.crates-io] +libc = { git = "https://gitlab.redox-os.org/redox-os/liblibc.git", branch = "redox-unix" } +mio = { git = "https://gitlab.redox-os.org/redox-os/mio.git" } +net2 = { git = "https://gitlab.redox-os.org/redox-os/net2-rs.git", branch = "redox-unix" } +pbr = { git = "https://gitlab.redox-os.org/redox-os/pb.git", branch = "redox-unix" } +time = { git = "https://gitlab.redox-os.org/redox-os/time.git", branch = "redox-unix" } From 131659dcde4e658aef42f16e02257adddefd8d52 Mon Sep 17 00:00:00 2001 From: jD91mZM2 Date: Sun, 16 Jun 2019 14:29:29 +0200 Subject: [PATCH 104/155] Remove unneeded patches, they're now global --- Cargo.lock | 56 ++++++++++++++++++++++++++++-------------------------- Cargo.toml | 7 ------- 2 files changed, 29 insertions(+), 34 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 83dcf8883d..84c3478a29 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -68,7 +68,7 @@ name = "iovec" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.51 (git+https://gitlab.redox-os.org/redox-os/liblibc.git?branch=redox-unix)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -83,8 +83,8 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.51" -source = "git+https://gitlab.redox-os.org/redox-os/liblibc.git?branch=redox-unix#f3c352801a999bef700cd05b67e77adfc46cb45d" +version = "0.2.58" +source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "log" @@ -114,18 +114,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "mio" -version = "0.6.16" -source = "git+https://gitlab.redox-os.org/redox-os/mio.git#439a559b2aa734e0970d37b3375889a57a465360" +version = "0.6.19" +source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.51 (git+https://gitlab.redox-os.org/redox-os/liblibc.git?branch=redox-unix)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "net2 0.2.33 (git+https://gitlab.redox-os.org/redox-os/net2-rs.git?branch=redox-unix)", - "redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)", + "net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -136,7 +135,7 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "net2 0.2.33 (git+https://gitlab.redox-os.org/redox-os/net2-rs.git?branch=redox-unix)", + "net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -144,10 +143,10 @@ dependencies = [ [[package]] name = "net2" version = "0.2.33" -source = "git+https://gitlab.redox-os.org/redox-os/net2-rs.git?branch=redox-unix#b2c7c1e7773f13eebd9b4421172d9e4b5b806ce6" +source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.51 (git+https://gitlab.redox-os.org/redox-os/liblibc.git?branch=redox-unix)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -158,10 +157,10 @@ source = "git+https://gitlab.redox-os.org/redox-os/netutils.git?branch=redox-uni dependencies = [ "arg_parser 0.1.0 (git+https://gitlab.redox-os.org/redox-os/arg-parser.git)", "extra 0.1.0 (git+https://gitlab.redox-os.org/redox-os/libextra.git)", - "libc 0.2.51 (git+https://gitlab.redox-os.org/redox-os/liblibc.git?branch=redox-unix)", - "mio 0.6.16 (git+https://gitlab.redox-os.org/redox-os/mio.git)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", "ntpclient 0.0.1 (git+https://github.com/willem66745/ntpclient-rust)", - "pbr 1.0.1 (git+https://gitlab.redox-os.org/redox-os/pb.git?branch=redox-unix)", + "pbr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "redox_event 0.1.0 (git+https://gitlab.redox-os.org/redox-os/event.git)", "redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)", "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -175,7 +174,7 @@ version = "0.0.1" source = "git+https://github.com/willem66745/ntpclient-rust#7e3bdf60eb940825789a8da5181025320e3050b0" dependencies = [ "byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", - "time 0.1.42 (git+https://gitlab.redox-os.org/redox-os/time.git?branch=redox-unix)", + "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -186,11 +185,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "pbr" version = "1.0.1" -source = "git+https://gitlab.redox-os.org/redox-os/pb.git?branch=redox-unix#743300cf9566f77962a5b550db1ba27cc922b6a5" +source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.51 (git+https://gitlab.redox-os.org/redox-os/liblibc.git?branch=redox-unix)", - "time 0.1.42 (git+https://gitlab.redox-os.org/redox-os/time.git?branch=redox-unix)", - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", + "termion 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -261,7 +262,7 @@ name = "termion" version = "1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.51 (git+https://gitlab.redox-os.org/redox-os/liblibc.git?branch=redox-unix)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", "numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)", "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -270,9 +271,10 @@ dependencies = [ [[package]] name = "time" version = "0.1.42" -source = "git+https://gitlab.redox-os.org/redox-os/time.git?branch=redox-unix#fc118e5752aaac833808a25f0850606b675b32ec" +source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.51 (git+https://gitlab.redox-os.org/redox-os/liblibc.git?branch=redox-unix)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -353,18 +355,18 @@ dependencies = [ "checksum idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e" "checksum iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dbe6e417e7d0975db6512b90796e8ce223145ac4e33c377e4a42882a0e88bb08" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" -"checksum libc 0.2.51 (git+https://gitlab.redox-os.org/redox-os/liblibc.git?branch=redox-unix)" = "" +"checksum libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)" = "6281b86796ba5e4366000be6e9e18bf35580adf9e63fbe2294aadb587613a319" "checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" "checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6" "checksum managed 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fdcec5e97041c7f0f1c5b7d93f12e57293c831c646f4cc7a5db59460c7ea8de6" "checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" -"checksum mio 0.6.16 (git+https://gitlab.redox-os.org/redox-os/mio.git)" = "" +"checksum mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)" = "83f51996a3ed004ef184e16818edc51fadffe8e7ca68be67f9dee67d84d0ff23" "checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919" -"checksum net2 0.2.33 (git+https://gitlab.redox-os.org/redox-os/net2-rs.git?branch=redox-unix)" = "" +"checksum net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "42550d9fb7b6684a6d404d9fa7250c2eb2646df731d1c06afc06dcee9e1bcf88" "checksum netutils 0.1.0 (git+https://gitlab.redox-os.org/redox-os/netutils.git?branch=redox-unix)" = "" "checksum ntpclient 0.0.1 (git+https://github.com/willem66745/ntpclient-rust)" = "" "checksum numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef" -"checksum pbr 1.0.1 (git+https://gitlab.redox-os.org/redox-os/pb.git?branch=redox-unix)" = "" +"checksum pbr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "deb73390ab68d81992bd994d145f697451bb0b54fd39738e72eef32458ad6907" "checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" "checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0" "checksum redox_event 0.1.0 (git+https://gitlab.redox-os.org/redox-os/event.git)" = "" @@ -373,7 +375,7 @@ dependencies = [ "checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" "checksum smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c4488ae950c49d403731982257768f48fada354a5203fe81f9bb6f43ca9002be" "checksum termion 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dde0593aeb8d47accea5392b39350015b5eccb12c0d98044d856983d89548dea" -"checksum time 0.1.42 (git+https://gitlab.redox-os.org/redox-os/time.git?branch=redox-unix)" = "" +"checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f" "checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" "checksum unicode-normalization 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "141339a08b982d942be2ca06ff8b076563cbe223d1befd5450716790d44e2426" "checksum url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dd4e7c0d531266369519a4aa4f399d748bd37043b00bde1e4ff1f60a120b355a" diff --git a/Cargo.toml b/Cargo.toml index d23a54a8f1..f8b92891e8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,10 +34,3 @@ features = ["std", "socket-raw", "proto-ipv4", "socket-udp", "socket-tcp", "sock [profile.release] lto = true - -[patch.crates-io] -libc = { git = "https://gitlab.redox-os.org/redox-os/liblibc.git", branch = "redox-unix" } -mio = { git = "https://gitlab.redox-os.org/redox-os/mio.git" } -net2 = { git = "https://gitlab.redox-os.org/redox-os/net2-rs.git", branch = "redox-unix" } -pbr = { git = "https://gitlab.redox-os.org/redox-os/pb.git", branch = "redox-unix" } -time = { git = "https://gitlab.redox-os.org/redox-os/time.git", branch = "redox-unix" } From 0c665a30a177f1e91cf6f770416a6926ea805b31 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Thu, 18 Jul 2019 21:33:23 -0600 Subject: [PATCH 105/155] Handle scheme EOF --- src/dnsd/scheme.rs | 21 +++++++++++++++------ src/smolnetd/scheme/netcfg/mod.rs | 23 ++++++++++++++++------- src/smolnetd/scheme/socket.rs | 21 +++++++++++++++------ 3 files changed, 46 insertions(+), 19 deletions(-) diff --git a/src/dnsd/scheme.rs b/src/dnsd/scheme.rs index b8fe1edf10..7642d0e67b 100644 --- a/src/dnsd/scheme.rs +++ b/src/dnsd/scheme.rs @@ -5,7 +5,7 @@ use std::collections::{BTreeMap, BTreeSet}; use std::collections::VecDeque; use std::collections::btree_map::Entry; use std::fs::File; -use std::io::{Read, Write}; +use std::io::{ErrorKind, Read, Write}; use std::mem; use std::os::unix::io::RawFd; use std::str; @@ -327,10 +327,19 @@ impl Dnsd { } pub fn on_dns_file_event(&mut self) -> Result> { - loop { + let result = loop { let mut packet = SyscallPacket::default(); - if self.dns_file.read(&mut packet)? == 0 { - break; + match self.dns_file.read(&mut packet) { + Ok(0) => { + //TODO: Cleanup must occur + break Some(()); + }, + Ok(_) => (), + Err(err) => if err.kind() == ErrorKind::WouldBlock { + break None; + } else { + return Err(Error::from(err)); + } } let a = packet.a; self.handle(&mut packet); @@ -340,8 +349,8 @@ impl Dnsd { packet.a = a; self.handle_block(packet)?; } - } - Ok(None) + }; + Ok(result) } pub fn on_unknown_fd_event(&mut self, fd: RawFd) -> Result> { diff --git a/src/smolnetd/scheme/netcfg/mod.rs b/src/smolnetd/scheme/netcfg/mod.rs index d5c3abe31d..e3f73b009b 100644 --- a/src/smolnetd/scheme/netcfg/mod.rs +++ b/src/smolnetd/scheme/netcfg/mod.rs @@ -6,7 +6,7 @@ use smoltcp::wire::{IpAddress, EthernetAddress, IpCidr, Ipv4Address}; use std::cell::RefCell; use std::collections::BTreeMap; use std::fs::File; -use std::io::{Read, Write}; +use std::io::{ErrorKind, Read, Write}; use std::rc::Rc; use std::mem; use std::str::FromStr; @@ -18,7 +18,7 @@ use syscall; use self::nodes::*; use self::notifier::*; -use redox_netstack::error::Result; +use redox_netstack::error::{Error, Result}; use super::{post_fevent, Interface}; const WRITE_BUFFER_MAX_SIZE: usize = 0xffff; @@ -360,16 +360,25 @@ impl NetCfgScheme { } pub fn on_scheme_event(&mut self) -> Result> { - loop { + let result = loop { let mut packet = SyscallPacket::default(); - if self.scheme_file.read(&mut packet)? == 0 { - break; + match self.scheme_file.read(&mut packet) { + Ok(0) => { + //TODO: Cleanup must occur + break Some(()); + }, + Ok(_) => (), + Err(err) => if err.kind() == ErrorKind::WouldBlock { + break None; + } else { + return Err(Error::from(err)); + } } self.handle(&mut packet); self.scheme_file.write_all(&packet)?; - } + }; self.notify_scheduled_fds(); - Ok(None) + Ok(result) } fn notify_scheduled_fds(&mut self) { diff --git a/src/smolnetd/scheme/socket.rs b/src/smolnetd/scheme/socket.rs index 58f9d9c2ca..46c3dd5665 100644 --- a/src/smolnetd/scheme/socket.rs +++ b/src/smolnetd/scheme/socket.rs @@ -2,7 +2,7 @@ use smoltcp::socket::{AnySocket, SocketHandle}; use std::cell::RefCell; use std::collections::BTreeMap; use std::fs::File; -use std::io::{Read, Write}; +use std::io::{ErrorKind, Read, Write}; use std::marker::PhantomData; use std::mem; use std::ops::Deref; @@ -218,10 +218,19 @@ where } pub fn on_scheme_event(&mut self) -> Result> { - loop { + let result = loop { let mut packet = SyscallPacket::default(); - if self.scheme_file.read(&mut packet)? == 0 { - break; + match self.scheme_file.read(&mut packet) { + Ok(0) => { + //TODO: Cleanup must occur + break Some(()); + }, + Ok(_) => (), + Err(err) => if err.kind() == ErrorKind::WouldBlock { + break None; + } else { + return Err(Error::from(err)); + } } if let Some(a) = self.handle(&mut packet) { packet.a = a; @@ -244,8 +253,8 @@ where } } } - } - Ok(None) + }; + Ok(result) } pub fn notify_sockets(&mut self) -> Result<()> { From ac5da3935b23f04fc655bf9d1f6d3e2e00c39486 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sat, 19 Oct 2019 20:37:35 -0600 Subject: [PATCH 106/155] Update dependencies --- Cargo.lock | 110 ++++++++++++++++++++++++++--------------------------- 1 file changed, 54 insertions(+), 56 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 84c3478a29..49605d27f5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3,11 +3,11 @@ [[package]] name = "arg_parser" version = "0.1.0" -source = "git+https://gitlab.redox-os.org/redox-os/arg-parser.git#7503531821b0c111f9fac77a5d2536ea221105fe" +source = "git+https://gitlab.redox-os.org/redox-os/arg-parser.git#1c434b55f3e1a0375ebcca85b3e88db7378e82fa" [[package]] name = "bitflags" -version = "1.0.4" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -17,12 +17,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "byteorder" -version = "1.3.1" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "cfg-if" -version = "0.1.7" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -30,7 +30,7 @@ name = "dns-parser" version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -44,7 +44,7 @@ name = "fuchsia-zircon" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -65,11 +65,10 @@ dependencies = [ [[package]] name = "iovec" -version = "0.1.2" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -83,7 +82,7 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.58" +version = "0.2.65" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -91,15 +90,15 @@ name = "log" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "log" -version = "0.4.6" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -119,10 +118,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -145,26 +144,26 @@ name = "net2" version = "0.2.33" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "netutils" version = "0.1.0" -source = "git+https://gitlab.redox-os.org/redox-os/netutils.git?branch=redox-unix#482c8285faa70c592d235336faaf7223f195b5d7" +source = "git+https://gitlab.redox-os.org/redox-os/netutils.git?branch=redox-unix#71626e302aef8f611c17a314e2749a3cc10854e4" dependencies = [ "arg_parser 0.1.0 (git+https://gitlab.redox-os.org/redox-os/arg-parser.git)", "extra 0.1.0 (git+https://gitlab.redox-os.org/redox-os/libextra.git)", - "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", "ntpclient 0.0.1 (git+https://github.com/willem66745/ntpclient-rust)", - "pbr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "pbr 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "redox_event 0.1.0 (git+https://gitlab.redox-os.org/redox-os/event.git)", - "redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "termion 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "termion 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -184,14 +183,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "pbr" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", - "termion 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", + "termion 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -209,25 +207,25 @@ name = "redox_event" version = "0.1.0" source = "git+https://gitlab.redox-os.org/redox-os/event.git#c31e3d3d5f44d60ff9fec2b1ee58b982e72c0d77" dependencies = [ - "redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "redox_netstack" version = "0.1.0" dependencies = [ - "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "dns-parser 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "netutils 0.1.0 (git+https://gitlab.redox-os.org/redox-os/netutils.git?branch=redox-unix)", "redox_event 0.1.0 (git+https://gitlab.redox-os.org/redox-os/event.git)", - "redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", "smoltcp 0.5.0", ] [[package]] name = "redox_syscall" -version = "0.1.54" +version = "0.1.56" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -235,7 +233,7 @@ name = "redox_termios" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -245,26 +243,26 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "smallvec" -version = "0.6.9" +version = "0.6.10" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "smoltcp" version = "0.5.0" dependencies = [ - "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "managed 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "termion" -version = "1.5.2" +version = "1.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -273,9 +271,9 @@ name = "time" version = "0.1.42" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -291,7 +289,7 @@ name = "unicode-normalization" version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -311,7 +309,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "winapi" -version = "0.3.7" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -344,20 +342,20 @@ dependencies = [ [metadata] "checksum arg_parser 0.1.0 (git+https://gitlab.redox-os.org/redox-os/arg-parser.git)" = "" -"checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12" +"checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" "checksum byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855" -"checksum byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a019b10a2a7cdeb292db131fc8113e57ea2a908f6e7894b0c3c671893b65dbeb" -"checksum cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "11d43355396e872eefb45ce6342e4374ed7bc2b3a502d1b28e36d6e23c05d1f4" +"checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5" +"checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" "checksum dns-parser 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f7020f6760aea312d43d23cb83bf6c0c49f162541db8b02bf95209ac51dc253d" "checksum extra 0.1.0 (git+https://gitlab.redox-os.org/redox-os/libextra.git)" = "" "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" "checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" "checksum idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e" -"checksum iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dbe6e417e7d0975db6512b90796e8ce223145ac4e33c377e4a42882a0e88bb08" +"checksum iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" -"checksum libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)" = "6281b86796ba5e4366000be6e9e18bf35580adf9e63fbe2294aadb587613a319" +"checksum libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)" = "1a31a0627fdf1f6a39ec0dd577e101440b7db22672c0901fe00a9a6fbb5c24e8" "checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" -"checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6" +"checksum log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" "checksum managed 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fdcec5e97041c7f0f1c5b7d93f12e57293c831c646f4cc7a5db59460c7ea8de6" "checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" "checksum mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)" = "83f51996a3ed004ef184e16818edc51fadffe8e7ca68be67f9dee67d84d0ff23" @@ -366,21 +364,21 @@ dependencies = [ "checksum netutils 0.1.0 (git+https://gitlab.redox-os.org/redox-os/netutils.git?branch=redox-unix)" = "" "checksum ntpclient 0.0.1 (git+https://github.com/willem66745/ntpclient-rust)" = "" "checksum numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef" -"checksum pbr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "deb73390ab68d81992bd994d145f697451bb0b54fd39738e72eef32458ad6907" +"checksum pbr 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4403eb718d70c03ee279e51737782902c68cca01e870a33b6a2f9dfb50b9cd83" "checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" "checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0" "checksum redox_event 0.1.0 (git+https://gitlab.redox-os.org/redox-os/event.git)" = "" -"checksum redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)" = "12229c14a0f65c4f1cb046a3b52047cdd9da1f4b30f8a39c5063c8bae515e252" +"checksum redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)" = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" "checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" -"checksum smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c4488ae950c49d403731982257768f48fada354a5203fe81f9bb6f43ca9002be" -"checksum termion 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dde0593aeb8d47accea5392b39350015b5eccb12c0d98044d856983d89548dea" +"checksum smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "ab606a9c5e214920bb66c458cd7be8ef094f813f20fe77a54cc7dbfff220d4b7" +"checksum termion 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6a8fb22f7cde82c8220e5aeacb3258ed7ce996142c77cba193f203515e26c330" "checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f" "checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" "checksum unicode-normalization 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "141339a08b982d942be2ca06ff8b076563cbe223d1befd5450716790d44e2426" "checksum url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dd4e7c0d531266369519a4aa4f399d748bd37043b00bde1e4ff1f60a120b355a" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" -"checksum winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "f10e386af2b13e47c89e7236a7a14a086791a2b88ebad6df9bf42040195cf770" +"checksum winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" "checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" From 01f30577c1a25a3c2eb2bdc6a1ebf4a23a8d0e70 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Fri, 29 Nov 2019 18:54:09 -0700 Subject: [PATCH 107/155] Update smoltcp --- Cargo.toml | 7 ++++++- smoltcp | 2 +- src/smolnetd/device.rs | 6 +++--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f8b92891e8..a6f751c46c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,7 +29,12 @@ features = ["release_max_level_warn"] [dependencies.smoltcp] path = "smoltcp" default-features = false -features = ["std", "socket-raw", "proto-ipv4", "socket-udp", "socket-tcp", "socket-icmp"] +features = [ + "std", + "ethernet", + "proto-ipv4", + "socket-raw", "socket-icmp", "socket-udp", "socket-tcp" +] #For debugging: "log", "verbose" [profile.release] diff --git a/smoltcp b/smoltcp index 30793fc901..9eae8d296b 160000 --- a/smoltcp +++ b/smoltcp @@ -1 +1 @@ -Subproject commit 30793fc901dc3a836e3177cc2b1e782389748fd5 +Subproject commit 9eae8d296b96f95c352ec0df14d899df4790f780 diff --git a/src/smolnetd/device.rs b/src/smolnetd/device.rs index dbb6eefe4d..9385a6c93a 100644 --- a/src/smolnetd/device.rs +++ b/src/smolnetd/device.rs @@ -45,11 +45,11 @@ pub struct RxToken { } impl smoltcp::phy::RxToken for RxToken { - fn consume(self, _timestamp: Instant, f: F) -> smoltcp::Result + fn consume(mut self, _timestamp: Instant, f: F) -> smoltcp::Result where - F: FnOnce(&[u8]) -> smoltcp::Result, + F: FnOnce(&mut [u8]) -> smoltcp::Result, { - f(&self.buffer) + f(&mut self.buffer) } } From 1fe52ea0f23efd9f445a9dd415215fb25bd4880e Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Thu, 21 May 2020 14:07:07 -0600 Subject: [PATCH 108/155] Add patches --- Cargo.lock | 134 +++++++++++++++++++++++++++++++++++------------------ Cargo.toml | 5 ++ 2 files changed, 95 insertions(+), 44 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 49605d27f5..b93de23aca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5,6 +5,11 @@ name = "arg_parser" version = "0.1.0" source = "git+https://gitlab.redox-os.org/redox-os/arg-parser.git#1c434b55f3e1a0375ebcca85b3e88db7378e82fa" +[[package]] +name = "autocfg" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "bitflags" version = "1.2.1" @@ -17,7 +22,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "byteorder" -version = "1.3.2" +version = "1.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -25,13 +30,32 @@ name = "cfg-if" version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "crossbeam-channel" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "crossbeam-utils 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", + "maybe-uninit 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "crossbeam-utils" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "dns-parser" version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "quick-error 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -60,7 +84,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-normalization 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-normalization 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -68,7 +92,7 @@ name = "iovec" version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.70 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -80,9 +104,19 @@ dependencies = [ "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "lazycell" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "libc" -version = "0.2.65" +version = "0.2.70" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -112,18 +146,24 @@ version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] -name = "mio" -version = "0.6.19" +name = "maybe-uninit" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "mio" +version = "0.6.14" +source = "git+https://gitlab.redox-os.org/redox-os/mio.git?branch=redox-unix#c9a70849ced97387e2607c9c466d23b130ec8901" dependencies = [ "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", + "lazycell 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.70 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", + "net2 0.2.33 (git+https://gitlab.redox-os.org/redox-os/net2-rs.git?branch=redox-unix)", "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -134,7 +174,7 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", + "net2 0.2.33 (git+https://gitlab.redox-os.org/redox-os/net2-rs.git?branch=redox-unix)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -142,28 +182,29 @@ dependencies = [ [[package]] name = "net2" version = "0.2.33" -source = "registry+https://github.com/rust-lang/crates.io-index" +source = "git+https://gitlab.redox-os.org/redox-os/net2-rs.git?branch=redox-unix#be7b855982e63770753a81ffc4bedf66d7f66506" dependencies = [ "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.70 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "netutils" version = "0.1.0" -source = "git+https://gitlab.redox-os.org/redox-os/netutils.git?branch=redox-unix#71626e302aef8f611c17a314e2749a3cc10854e4" +source = "git+https://gitlab.redox-os.org/redox-os/netutils.git?branch=redox-unix#6f81f874f2015d82e811102160808db581f585a5" dependencies = [ "arg_parser 0.1.0 (git+https://gitlab.redox-os.org/redox-os/arg-parser.git)", "extra 0.1.0 (git+https://gitlab.redox-os.org/redox-os/libextra.git)", - "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.70 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.14 (git+https://gitlab.redox-os.org/redox-os/mio.git?branch=redox-unix)", + "net2 0.2.33 (git+https://gitlab.redox-os.org/redox-os/net2-rs.git?branch=redox-unix)", "ntpclient 0.0.1 (git+https://github.com/willem66745/ntpclient-rust)", - "pbr 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "pbr 1.0.2 (git+https://github.com/jackpot51/pb.git)", "redox_event 0.1.0 (git+https://gitlab.redox-os.org/redox-os/event.git)", "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "termion 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)", + "termion 1.5.5 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -173,7 +214,7 @@ version = "0.0.1" source = "git+https://github.com/willem66745/ntpclient-rust#7e3bdf60eb940825789a8da5181025320e3050b0" dependencies = [ "byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", - "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -184,11 +225,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "pbr" version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" +source = "git+https://github.com/jackpot51/pb.git#ae1c429f9eb980ac6fe67aebd88db293815d42b0" dependencies = [ - "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", - "termion 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)", - "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-channel 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.70 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -199,7 +240,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "quick-error" -version = "1.2.2" +version = "1.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -214,7 +255,7 @@ dependencies = [ name = "redox_netstack" version = "0.1.0" dependencies = [ - "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "dns-parser 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "netutils 0.1.0 (git+https://gitlab.redox-os.org/redox-os/netutils.git?branch=redox-unix)", @@ -243,7 +284,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "smallvec" -version = "0.6.10" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -251,16 +292,16 @@ name = "smoltcp" version = "0.5.0" dependencies = [ "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "managed 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "termion" -version = "1.5.3" +version = "1.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.70 (registry+https://github.com/rust-lang/crates.io-index)", "numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -268,11 +309,10 @@ dependencies = [ [[package]] name = "time" -version = "0.1.42" +version = "0.1.43" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.70 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -286,10 +326,10 @@ dependencies = [ [[package]] name = "unicode-normalization" -version = "0.1.8" +version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -342,10 +382,13 @@ dependencies = [ [metadata] "checksum arg_parser 0.1.0 (git+https://gitlab.redox-os.org/redox-os/arg-parser.git)" = "" +"checksum autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" "checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" "checksum byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855" -"checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5" +"checksum byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" "checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" +"checksum crossbeam-channel 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "cced8691919c02aac3cb0a1bc2e9b73d89e832bf9a06fc579d4e71b68a2da061" +"checksum crossbeam-utils 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8" "checksum dns-parser 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f7020f6760aea312d43d23cb83bf6c0c49f162541db8b02bf95209ac51dc253d" "checksum extra 0.1.0 (git+https://gitlab.redox-os.org/redox-os/libextra.git)" = "" "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" @@ -353,29 +396,32 @@ dependencies = [ "checksum idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e" "checksum iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" -"checksum libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)" = "1a31a0627fdf1f6a39ec0dd577e101440b7db22672c0901fe00a9a6fbb5c24e8" +"checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +"checksum lazycell 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a6f08839bc70ef4a3fe1d566d5350f519c5912ea86be0df1740a7d247c7fc0ef" +"checksum libc 0.2.70 (registry+https://github.com/rust-lang/crates.io-index)" = "3baa92041a6fec78c687fa0cc2b3fae8884f743d672cf551bed1d6dac6988d0f" "checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" "checksum log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" "checksum managed 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fdcec5e97041c7f0f1c5b7d93f12e57293c831c646f4cc7a5db59460c7ea8de6" "checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" -"checksum mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)" = "83f51996a3ed004ef184e16818edc51fadffe8e7ca68be67f9dee67d84d0ff23" +"checksum maybe-uninit 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00" +"checksum mio 0.6.14 (git+https://gitlab.redox-os.org/redox-os/mio.git?branch=redox-unix)" = "" "checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919" -"checksum net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "42550d9fb7b6684a6d404d9fa7250c2eb2646df731d1c06afc06dcee9e1bcf88" +"checksum net2 0.2.33 (git+https://gitlab.redox-os.org/redox-os/net2-rs.git?branch=redox-unix)" = "" "checksum netutils 0.1.0 (git+https://gitlab.redox-os.org/redox-os/netutils.git?branch=redox-unix)" = "" "checksum ntpclient 0.0.1 (git+https://github.com/willem66745/ntpclient-rust)" = "" "checksum numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef" -"checksum pbr 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4403eb718d70c03ee279e51737782902c68cca01e870a33b6a2f9dfb50b9cd83" +"checksum pbr 1.0.2 (git+https://github.com/jackpot51/pb.git)" = "" "checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" -"checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0" +"checksum quick-error 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" "checksum redox_event 0.1.0 (git+https://gitlab.redox-os.org/redox-os/event.git)" = "" "checksum redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)" = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" "checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" -"checksum smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "ab606a9c5e214920bb66c458cd7be8ef094f813f20fe77a54cc7dbfff220d4b7" -"checksum termion 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6a8fb22f7cde82c8220e5aeacb3258ed7ce996142c77cba193f203515e26c330" -"checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f" +"checksum smallvec 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c7cb5678e1615754284ec264d9bb5b4c27d2018577fd90ac0ceb578591ed5ee4" +"checksum termion 1.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "c22cec9d8978d906be5ac94bceb5a010d885c626c4c8855721a4dbd20e3ac905" +"checksum time 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)" = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" "checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" -"checksum unicode-normalization 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "141339a08b982d942be2ca06ff8b076563cbe223d1befd5450716790d44e2426" +"checksum unicode-normalization 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "5479532badd04e128284890390c1e876ef7a993d0570b3597ae43dfa1d59afa4" "checksum url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dd4e7c0d531266369519a4aa4f399d748bd37043b00bde1e4ff1f60a120b355a" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" "checksum winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" diff --git a/Cargo.toml b/Cargo.toml index a6f751c46c..d57a554483 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,3 +39,8 @@ features = [ [profile.release] lto = true + +[patch.crates-io] +mio = { git = "https://gitlab.redox-os.org/redox-os/mio.git", branch = "redox-unix" } +net2 = { git = "https://gitlab.redox-os.org/redox-os/net2-rs.git", branch = "redox-unix" } +pbr = { git = "https://github.com/jackpot51/pb.git" } From 538475a81366643671d43c926b69e14be8118825 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Thu, 28 May 2020 11:57:39 -0600 Subject: [PATCH 109/155] Remove pbr patch --- Cargo.lock | 28 ++++++++++++++-------------- Cargo.toml | 1 - 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b93de23aca..59f40952e1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -92,7 +92,7 @@ name = "iovec" version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.70 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -116,7 +116,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libc" -version = "0.2.70" +version = "0.2.71" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -160,7 +160,7 @@ dependencies = [ "iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazycell 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.70 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "net2 0.2.33 (git+https://gitlab.redox-os.org/redox-os/net2-rs.git?branch=redox-unix)", @@ -185,22 +185,22 @@ version = "0.2.33" source = "git+https://gitlab.redox-os.org/redox-os/net2-rs.git?branch=redox-unix#be7b855982e63770753a81ffc4bedf66d7f66506" dependencies = [ "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.70 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "netutils" version = "0.1.0" -source = "git+https://gitlab.redox-os.org/redox-os/netutils.git?branch=redox-unix#6f81f874f2015d82e811102160808db581f585a5" +source = "git+https://gitlab.redox-os.org/redox-os/netutils.git?branch=redox-unix#a66c155fa4bb248151100c2ac861a913df7c75cd" dependencies = [ "arg_parser 0.1.0 (git+https://gitlab.redox-os.org/redox-os/arg-parser.git)", "extra 0.1.0 (git+https://gitlab.redox-os.org/redox-os/libextra.git)", - "libc 0.2.70 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.6.14 (git+https://gitlab.redox-os.org/redox-os/mio.git?branch=redox-unix)", "net2 0.2.33 (git+https://gitlab.redox-os.org/redox-os/net2-rs.git?branch=redox-unix)", "ntpclient 0.0.1 (git+https://github.com/willem66745/ntpclient-rust)", - "pbr 1.0.2 (git+https://github.com/jackpot51/pb.git)", + "pbr 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "redox_event 0.1.0 (git+https://gitlab.redox-os.org/redox-os/event.git)", "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -224,11 +224,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "pbr" -version = "1.0.2" -source = "git+https://github.com/jackpot51/pb.git#ae1c429f9eb980ac6fe67aebd88db293815d42b0" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crossbeam-channel 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.70 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -301,7 +301,7 @@ name = "termion" version = "1.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.70 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", "numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -312,7 +312,7 @@ name = "time" version = "0.1.43" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.70 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -398,7 +398,7 @@ dependencies = [ "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" "checksum lazycell 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a6f08839bc70ef4a3fe1d566d5350f519c5912ea86be0df1740a7d247c7fc0ef" -"checksum libc 0.2.70 (registry+https://github.com/rust-lang/crates.io-index)" = "3baa92041a6fec78c687fa0cc2b3fae8884f743d672cf551bed1d6dac6988d0f" +"checksum libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)" = "9457b06509d27052635f90d6466700c65095fdf75409b3fbdd903e988b886f49" "checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" "checksum log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" "checksum managed 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fdcec5e97041c7f0f1c5b7d93f12e57293c831c646f4cc7a5db59460c7ea8de6" @@ -410,7 +410,7 @@ dependencies = [ "checksum netutils 0.1.0 (git+https://gitlab.redox-os.org/redox-os/netutils.git?branch=redox-unix)" = "" "checksum ntpclient 0.0.1 (git+https://github.com/willem66745/ntpclient-rust)" = "" "checksum numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef" -"checksum pbr 1.0.2 (git+https://github.com/jackpot51/pb.git)" = "" +"checksum pbr 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "74333e3d1d8bced07fd0b8599304825684bcdb4a1fcc6fa6a470e6e08cefd254" "checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" "checksum quick-error 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" "checksum redox_event 0.1.0 (git+https://gitlab.redox-os.org/redox-os/event.git)" = "" diff --git a/Cargo.toml b/Cargo.toml index d57a554483..009e0f5d97 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,4 +43,3 @@ lto = true [patch.crates-io] mio = { git = "https://gitlab.redox-os.org/redox-os/mio.git", branch = "redox-unix" } net2 = { git = "https://gitlab.redox-os.org/redox-os/net2-rs.git", branch = "redox-unix" } -pbr = { git = "https://github.com/jackpot51/pb.git" } From f6b0ef229adca2cf66939a7e399c6c9de23a4732 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sun, 2 Aug 2020 16:05:05 -0600 Subject: [PATCH 110/155] Update redox_syscall --- Cargo.lock | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 59f40952e1..1f1f1152c3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -202,7 +202,7 @@ dependencies = [ "ntpclient 0.0.1 (git+https://github.com/willem66745/ntpclient-rust)", "pbr 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "redox_event 0.1.0 (git+https://gitlab.redox-os.org/redox-os/event.git)", - "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.57 (registry+https://github.com/rust-lang/crates.io-index)", "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "termion 1.5.5 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -248,7 +248,7 @@ name = "redox_event" version = "0.1.0" source = "git+https://gitlab.redox-os.org/redox-os/event.git#c31e3d3d5f44d60ff9fec2b1ee58b982e72c0d77" dependencies = [ - "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.57 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -260,13 +260,13 @@ dependencies = [ "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "netutils 0.1.0 (git+https://gitlab.redox-os.org/redox-os/netutils.git?branch=redox-unix)", "redox_event 0.1.0 (git+https://gitlab.redox-os.org/redox-os/event.git)", - "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.57 (registry+https://github.com/rust-lang/crates.io-index)", "smoltcp 0.5.0", ] [[package]] name = "redox_syscall" -version = "0.1.56" +version = "0.1.57" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -274,7 +274,7 @@ name = "redox_termios" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.57 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -303,7 +303,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", "numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.57 (registry+https://github.com/rust-lang/crates.io-index)", "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -414,7 +414,7 @@ dependencies = [ "checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" "checksum quick-error 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" "checksum redox_event 0.1.0 (git+https://gitlab.redox-os.org/redox-os/event.git)" = "" -"checksum redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)" = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" +"checksum redox_syscall 0.1.57 (registry+https://github.com/rust-lang/crates.io-index)" = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" "checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" "checksum smallvec 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c7cb5678e1615754284ec264d9bb5b4c27d2018577fd90ac0ceb578591ed5ee4" From 47f62378ed103f2cc7756ef98a612d6b7d39946c Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sun, 2 Aug 2020 16:07:21 -0600 Subject: [PATCH 111/155] Update smoltcp --- smoltcp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/smoltcp b/smoltcp index 9eae8d296b..9fbcf5cfcb 160000 --- a/smoltcp +++ b/smoltcp @@ -1 +1 @@ -Subproject commit 9eae8d296b96f95c352ec0df14d899df4790f780 +Subproject commit 9fbcf5cfcb3b0d3e8ca77da2bc0f56c4d3c3b412 From 8f7d7595087b98aa6574e269915d048ccbab975a Mon Sep 17 00:00:00 2001 From: 4lDO2 <4lDO2@protonmail.com> Date: Thu, 17 Jun 2021 18:15:31 +0200 Subject: [PATCH 112/155] Update dependencies. --- Cargo.lock | 206 ++++++++++++++++-------------- Cargo.toml | 4 +- src/dnsd/main.rs | 6 +- src/dnsd/scheme.rs | 12 +- src/smolnetd/main.rs | 6 +- src/smolnetd/scheme/netcfg/mod.rs | 13 +- src/smolnetd/scheme/socket.rs | 30 ++--- 7 files changed, 145 insertions(+), 132 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1f1f1152c3..f29f61c0c7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5,11 +5,6 @@ name = "arg_parser" version = "0.1.0" source = "git+https://gitlab.redox-os.org/redox-os/arg-parser.git#1c434b55f3e1a0375ebcca85b3e88db7378e82fa" -[[package]] -name = "autocfg" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "bitflags" version = "1.2.1" @@ -22,7 +17,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "byteorder" -version = "1.3.4" +version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -30,22 +25,26 @@ name = "cfg-if" version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "crossbeam-channel" -version = "0.4.2" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "crossbeam-utils 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", - "maybe-uninit 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.8.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "crossbeam-utils" -version = "0.7.2" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -54,14 +53,14 @@ name = "dns-parser" version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "quick-error 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "extra" version = "0.1.0" -source = "git+https://gitlab.redox-os.org/redox-os/libextra.git#0b50f3f2127fa62b1fe74090feffbae357266eac" +source = "git+https://gitlab.redox-os.org/redox-os/libextra.git#cf213969493db8667052a591e32a1e26d43c4234" [[package]] name = "fuchsia-zircon" @@ -83,8 +82,8 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-normalization 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-bidi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-normalization 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -92,7 +91,7 @@ name = "iovec" version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.97 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -116,7 +115,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libc" -version = "0.2.71" +version = "0.2.97" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -124,20 +123,20 @@ name = "log" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.14 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "log" -version = "0.4.8" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "managed" -version = "0.7.1" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -145,11 +144,6 @@ name = "matches" version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "maybe-uninit" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "mio" version = "0.6.14" @@ -160,51 +154,51 @@ dependencies = [ "iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazycell 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "net2 0.2.33 (git+https://gitlab.redox-os.org/redox-os/net2-rs.git?branch=redox-unix)", - "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.97 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.14 (registry+https://github.com/rust-lang/crates.io-index)", + "miow 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "net2 0.2.37 (git+https://gitlab.redox-os.org/redox-os/net2-rs.git?branch=master)", + "slab 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "miow" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "net2 0.2.33 (git+https://gitlab.redox-os.org/redox-os/net2-rs.git?branch=redox-unix)", + "net2 0.2.37 (git+https://gitlab.redox-os.org/redox-os/net2-rs.git?branch=master)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "net2" -version = "0.2.33" -source = "git+https://gitlab.redox-os.org/redox-os/net2-rs.git?branch=redox-unix#be7b855982e63770753a81ffc4bedf66d7f66506" +version = "0.2.37" +source = "git+https://gitlab.redox-os.org/redox-os/net2-rs.git?branch=master#db0604dcb0a355e6b2fa5bcaad8f175bd6aeb5aa" dependencies = [ "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.97 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "netutils" version = "0.1.0" -source = "git+https://gitlab.redox-os.org/redox-os/netutils.git?branch=redox-unix#a66c155fa4bb248151100c2ac861a913df7c75cd" +source = "git+https://gitlab.redox-os.org/redox-os/netutils.git?branch=redox-unix#c5d6d20900fd4da9cbf1f3ec04bd752c3d5d3e04" dependencies = [ "arg_parser 0.1.0 (git+https://gitlab.redox-os.org/redox-os/arg-parser.git)", "extra 0.1.0 (git+https://gitlab.redox-os.org/redox-os/libextra.git)", - "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.97 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.6.14 (git+https://gitlab.redox-os.org/redox-os/mio.git?branch=redox-unix)", - "net2 0.2.33 (git+https://gitlab.redox-os.org/redox-os/net2-rs.git?branch=redox-unix)", + "net2 0.2.37 (git+https://gitlab.redox-os.org/redox-os/net2-rs.git?branch=master)", "ntpclient 0.0.1 (git+https://github.com/willem66745/ntpclient-rust)", - "pbr 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "pbr 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "redox_event 0.1.0 (git+https://gitlab.redox-os.org/redox-os/event.git)", - "redox_syscall 0.1.57 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "termion 1.5.5 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_termios 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "termion 1.5.6 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -214,7 +208,7 @@ version = "0.0.1" source = "git+https://github.com/willem66745/ntpclient-rust#7e3bdf60eb940825789a8da5181025320e3050b0" dependencies = [ "byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", - "time 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.44 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -224,13 +218,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "pbr" -version = "1.0.3" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "crossbeam-channel 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", - "time 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-channel 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.97 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.44 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -246,45 +240,43 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "redox_event" version = "0.1.0" -source = "git+https://gitlab.redox-os.org/redox-os/event.git#c31e3d3d5f44d60ff9fec2b1ee58b982e72c0d77" +source = "git+https://gitlab.redox-os.org/redox-os/event.git#228eb0719c4424357012c6aad71cf26976048990" dependencies = [ - "redox_syscall 0.1.57 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "redox_netstack" version = "0.1.0" dependencies = [ - "byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "dns-parser 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "netutils 0.1.0 (git+https://gitlab.redox-os.org/redox-os/netutils.git?branch=redox-unix)", "redox_event 0.1.0 (git+https://gitlab.redox-os.org/redox-os/event.git)", - "redox_syscall 0.1.57 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", "smoltcp 0.5.0", ] [[package]] name = "redox_syscall" -version = "0.1.57" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", +] [[package]] name = "redox_termios" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "redox_syscall 0.1.57 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "slab" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "smallvec" -version = "1.4.0" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -292,33 +284,47 @@ name = "smoltcp" version = "0.5.0" dependencies = [ "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "managed 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "managed 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "termion" -version = "1.5.5" +version = "1.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.97 (registry+https://github.com/rust-lang/crates.io-index)", "numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.57 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_termios 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "time" -version = "0.1.43" +version = "0.1.44" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.97 (registry+https://github.com/rust-lang/crates.io-index)", + "wasi 0.10.0+wasi-snapshot-preview1 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "tinyvec" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "tinyvec_macros 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "unicode-bidi" -version = "0.3.4" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -326,10 +332,10 @@ dependencies = [ [[package]] name = "unicode-normalization" -version = "0.1.12" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "smallvec 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "tinyvec 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -342,6 +348,11 @@ dependencies = [ "percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "wasi" +version = "0.10.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "winapi" version = "0.2.8" @@ -349,7 +360,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "winapi" -version = "0.3.8" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -382,13 +393,13 @@ dependencies = [ [metadata] "checksum arg_parser 0.1.0 (git+https://gitlab.redox-os.org/redox-os/arg-parser.git)" = "" -"checksum autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" "checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" "checksum byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855" -"checksum byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" +"checksum byteorder 1.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" "checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" -"checksum crossbeam-channel 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "cced8691919c02aac3cb0a1bc2e9b73d89e832bf9a06fc579d4e71b68a2da061" -"checksum crossbeam-utils 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8" +"checksum cfg-if 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +"checksum crossbeam-channel 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "06ed27e177f16d65f0f0c22a213e17c696ace5dd64b14258b52f9417ccb52db4" +"checksum crossbeam-utils 0.8.5 (registry+https://github.com/rust-lang/crates.io-index)" = "d82cfc11ce7f2c3faef78d8a684447b40d503d9681acebed6cb728d45940c4db" "checksum dns-parser 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f7020f6760aea312d43d23cb83bf6c0c49f162541db8b02bf95209ac51dc253d" "checksum extra 0.1.0 (git+https://gitlab.redox-os.org/redox-os/libextra.git)" = "" "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" @@ -398,33 +409,34 @@ dependencies = [ "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" "checksum lazycell 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a6f08839bc70ef4a3fe1d566d5350f519c5912ea86be0df1740a7d247c7fc0ef" -"checksum libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)" = "9457b06509d27052635f90d6466700c65095fdf75409b3fbdd903e988b886f49" +"checksum libc 0.2.97 (registry+https://github.com/rust-lang/crates.io-index)" = "12b8adadd720df158f4d70dfe7ccc6adb0472d7c55ca83445f6a5ab3e36f8fb6" "checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" -"checksum log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" -"checksum managed 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fdcec5e97041c7f0f1c5b7d93f12e57293c831c646f4cc7a5db59460c7ea8de6" +"checksum log 0.4.14 (registry+https://github.com/rust-lang/crates.io-index)" = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" +"checksum managed 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c75de51135344a4f8ed3cfe2720dc27736f7711989703a0b43aadf3753c55577" "checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" -"checksum maybe-uninit 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00" "checksum mio 0.6.14 (git+https://gitlab.redox-os.org/redox-os/mio.git?branch=redox-unix)" = "" -"checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919" -"checksum net2 0.2.33 (git+https://gitlab.redox-os.org/redox-os/net2-rs.git?branch=redox-unix)" = "" +"checksum miow 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ebd808424166322d4a38da87083bfddd3ac4c131334ed55856112eb06d46944d" +"checksum net2 0.2.37 (git+https://gitlab.redox-os.org/redox-os/net2-rs.git?branch=master)" = "" "checksum netutils 0.1.0 (git+https://gitlab.redox-os.org/redox-os/netutils.git?branch=redox-unix)" = "" "checksum ntpclient 0.0.1 (git+https://github.com/willem66745/ntpclient-rust)" = "" "checksum numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef" -"checksum pbr 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "74333e3d1d8bced07fd0b8599304825684bcdb4a1fcc6fa6a470e6e08cefd254" +"checksum pbr 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "ff5751d87f7c00ae6403eb1fcbba229b9c76c9a30de8c1cf87182177b168cea2" "checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" "checksum quick-error 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" "checksum redox_event 0.1.0 (git+https://gitlab.redox-os.org/redox-os/event.git)" = "" -"checksum redox_syscall 0.1.57 (registry+https://github.com/rust-lang/crates.io-index)" = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" -"checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" -"checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" -"checksum smallvec 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c7cb5678e1615754284ec264d9bb5b4c27d2018577fd90ac0ceb578591ed5ee4" -"checksum termion 1.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "c22cec9d8978d906be5ac94bceb5a010d885c626c4c8855721a4dbd20e3ac905" -"checksum time 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)" = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" -"checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" -"checksum unicode-normalization 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "5479532badd04e128284890390c1e876ef7a993d0570b3597ae43dfa1d59afa4" +"checksum redox_syscall 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)" = "5ab49abadf3f9e1c4bc499e8845e152ad87d2ad2d30371841171169e9d75feee" +"checksum redox_termios 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8440d8acb4fd3d277125b4bd01a6f38aee8d814b3b5fc09b3f2b825d37d3fe8f" +"checksum slab 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "f173ac3d1a7e3b28003f40de0b5ce7fe2710f9b9dc3fc38664cebee46b3b6527" +"checksum termion 1.5.6 (registry+https://github.com/rust-lang/crates.io-index)" = "077185e2eac69c3f8379a4298e1e07cd36beb962290d4a51199acf0fdc10607e" +"checksum time 0.1.44 (registry+https://github.com/rust-lang/crates.io-index)" = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" +"checksum tinyvec 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5b5220f05bb7de7f3f53c7c065e1199b3172696fe2db9f9c4d8ad9b4ee74c342" +"checksum tinyvec_macros 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" +"checksum unicode-bidi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "eeb8be209bb1c96b7c177c7420d26e04eccacb0eeae6b980e35fcb74678107e0" +"checksum unicode-normalization 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)" = "d54590932941a9e9266f0832deed84ebe1bf2e4c9e4a3554d393d18f5e854bf9" "checksum url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dd4e7c0d531266369519a4aa4f399d748bd37043b00bde1e4ff1f60a120b355a" +"checksum wasi 0.10.0+wasi-snapshot-preview1 (registry+https://github.com/rust-lang/crates.io-index)" = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" -"checksum winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" +"checksum winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" "checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml index 009e0f5d97..989d3da697 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ path = "src/lib/lib.rs" [dependencies] netutils = { git = "https://gitlab.redox-os.org/redox-os/netutils.git", branch = "redox-unix" } redox_event = { git = "https://gitlab.redox-os.org/redox-os/event.git" } -redox_syscall = "0.1" +redox_syscall = "0.2.9" byteorder = { version = "1.0", default-features = false } dns-parser = "0.7.1" @@ -42,4 +42,4 @@ lto = true [patch.crates-io] mio = { git = "https://gitlab.redox-os.org/redox-os/mio.git", branch = "redox-unix" } -net2 = { git = "https://gitlab.redox-os.org/redox-os/net2-rs.git", branch = "redox-unix" } +net2 = { git = "https://gitlab.redox-os.org/redox-os/net2-rs.git", branch = "master" } diff --git a/src/dnsd/main.rs b/src/dnsd/main.rs index 7bb3fd773b..eef8ea9517 100644 --- a/src/dnsd/main.rs +++ b/src/dnsd/main.rs @@ -17,6 +17,8 @@ use std::os::unix::io::{AsRawFd, FromRawFd, RawFd}; use std::process; use std::rc::Rc; +use syscall::{CloneFlags, EventFlags}; + mod scheme; fn run() -> Result<()> { @@ -73,14 +75,14 @@ fn run() -> Result<()> { event_queue.trigger_all(event::Event { fd: 0, - flags: 0, + flags: EventFlags::empty(), })?; event_queue.run() } fn main() { - if unsafe { syscall::clone(0).unwrap() } == 0 { + if unsafe { syscall::clone(CloneFlags::empty()).unwrap() } == 0 { logger::init_logger(); if let Err(err) = run() { error!("dnsd: {}", err); diff --git a/src/dnsd/scheme.rs b/src/dnsd/scheme.rs index 7642d0e67b..b7935ded5f 100644 --- a/src/dnsd/scheme.rs +++ b/src/dnsd/scheme.rs @@ -13,7 +13,7 @@ use std::str::FromStr; use std::rc::Rc; use std::net::Ipv4Addr; use syscall::data::TimeSpec; -use syscall::{Error as SyscallError, Packet as SyscallPacket, Result as SyscallResult, SchemeMut}; +use syscall::{Error as SyscallError, EventFlags as SyscallEventFlags, Packet as SyscallPacket, Result as SyscallResult, SchemeMut}; use syscall; use dns_parser::{Builder, Packet as DNSPacket, RRData, ResponseCode}; @@ -417,10 +417,8 @@ impl Dnsd { } impl SchemeMut for Dnsd { - fn open(&mut self, url: &[u8], _flags: usize, _uid: u32, _gid: u32) -> SyscallResult { - let domain = str::from_utf8(url) - .or_else(|_| Err(SyscallError::new(syscall::EINVAL)))? - .to_lowercase(); + fn open(&mut self, url: &str, _flags: usize, _uid: u32, _gid: u32) -> SyscallResult { + let domain = url.to_lowercase(); if domain.is_empty() || !Dnsd::validate_domain(&domain) { return Err(SyscallError::new(syscall::EINVAL)); } @@ -484,8 +482,8 @@ impl SchemeMut for Dnsd { } } - fn fevent(&mut self, _fd: usize, _events: usize) -> SyscallResult { - Ok(0) + fn fevent(&mut self, _fd: usize, _events: SyscallEventFlags) -> SyscallResult { + Ok(SyscallEventFlags::empty()) } fn fsync(&mut self, _fd: usize) -> SyscallResult { diff --git a/src/smolnetd/main.rs b/src/smolnetd/main.rs index 39683c3959..3a6241b320 100644 --- a/src/smolnetd/main.rs +++ b/src/smolnetd/main.rs @@ -15,6 +15,8 @@ use std::os::unix::io::{FromRawFd, RawFd}; use std::process; use std::rc::Rc; +use syscall::flag::{CloneFlags, EventFlags}; + use redox_netstack::error::{Error, Result}; use redox_netstack::logger; use event::EventQueue; @@ -141,14 +143,14 @@ fn run() -> Result<()> { event_queue.trigger_all(event::Event { fd: 0, - flags: 0 + flags: EventFlags::empty() })?; event_queue.run() } fn main() { - if unsafe { syscall::clone(0).unwrap() } == 0 { + if unsafe { syscall::clone(CloneFlags::empty()).unwrap() } == 0 { logger::init_logger(); if let Err(err) = run() { diff --git a/src/smolnetd/scheme/netcfg/mod.rs b/src/smolnetd/scheme/netcfg/mod.rs index e3f73b009b..7e91303322 100644 --- a/src/smolnetd/scheme/netcfg/mod.rs +++ b/src/smolnetd/scheme/netcfg/mod.rs @@ -13,7 +13,7 @@ use std::str::FromStr; use std::str; use syscall::data::Stat; use syscall::flag::{MODE_DIR, MODE_FILE}; -use syscall::{Error as SyscallError, Packet as SyscallPacket, Result as SyscallResult, SchemeMut}; +use syscall::{Error as SyscallError, EventFlags as SyscallEventFlags, Packet as SyscallPacket, Result as SyscallResult, SchemeMut}; use syscall; use self::nodes::*; @@ -384,14 +384,13 @@ impl NetCfgScheme { fn notify_scheduled_fds(&mut self) { let fds_to_notify = self.notifier.borrow_mut().get_notified_fds(); for fd in fds_to_notify { - let _ = post_fevent(&mut self.scheme_file, fd, syscall::EVENT_READ, 1); + let _ = post_fevent(&mut self.scheme_file, fd, syscall::EVENT_READ.bits(), 1); } } } impl SchemeMut for NetCfgScheme { - fn open(&mut self, url: &[u8], _flags: usize, uid: u32, _gid: u32) -> SyscallResult { - let path = str::from_utf8(url).or_else(|_| Err(SyscallError::new(syscall::EINVAL)))?; + fn open(&mut self, path: &str, _flags: usize, uid: u32, _gid: u32) -> SyscallResult { let mut current_node = Rc::clone(&self.root_node); for part in path.split('/') { if part.is_empty() { @@ -505,16 +504,16 @@ impl SchemeMut for NetCfgScheme { Ok(0) } - fn fevent(&mut self, fd: usize, events: usize) -> SyscallResult { + fn fevent(&mut self, fd: usize, events: SyscallEventFlags) -> SyscallResult { let file = self.files .get_mut(&fd) .ok_or_else(|| SyscallError::new(syscall::EBADF))?; - if events & syscall::EVENT_READ == syscall::EVENT_READ { + if events.contains(syscall::EVENT_READ) { self.notifier.borrow_mut().subscribe(&file.path, fd); } else { self.notifier.borrow_mut().unsubscribe(&file.path, fd); } - Ok(0) + Ok(SyscallEventFlags::empty()) } fn fsync(&mut self, fd: usize) -> SyscallResult { diff --git a/src/smolnetd/scheme/socket.rs b/src/smolnetd/scheme/socket.rs index 46c3dd5665..7dd3d665f1 100644 --- a/src/smolnetd/scheme/socket.rs +++ b/src/smolnetd/scheme/socket.rs @@ -1,4 +1,3 @@ -use smoltcp::socket::{AnySocket, SocketHandle}; use std::cell::RefCell; use std::collections::BTreeMap; use std::fs::File; @@ -9,12 +8,15 @@ use std::ops::Deref; use std::ops::DerefMut; use std::rc::Rc; use std::str; + use syscall; -use syscall::{Error as SyscallError, Packet as SyscallPacket, Result as SyscallResult, SchemeBlockMut}; +use syscall::{Error as SyscallError, EventFlags as SyscallEventFlags, Packet as SyscallPacket, Result as SyscallResult, SchemeBlockMut}; use syscall::data::TimeSpec; use syscall::flag::{EVENT_READ, EVENT_WRITE}; use redox_netstack::error::{Error, Result}; +use smoltcp::socket::{AnySocket, SocketHandle}; + use super::{post_fevent, SocketSet}; pub struct NullFile { @@ -108,19 +110,19 @@ where { let socket = socket_set.get::(socket_handle); - if events & syscall::EVENT_READ == syscall::EVENT_READ && (socket.can_recv() || !socket.may_recv()) { + if events & syscall::EVENT_READ.bits() == syscall::EVENT_READ.bits() && (socket.can_recv() || !socket.may_recv()) { if !*read_notified { *read_notified = true; - revents |= EVENT_READ; + revents |= EVENT_READ.bits(); } } else { *read_notified = false; } - if events & syscall::EVENT_WRITE == syscall::EVENT_WRITE && socket.can_send() { + if events & syscall::EVENT_WRITE.bits() == syscall::EVENT_WRITE.bits() && socket.can_send() { if !*write_notified { *write_notified = true; - revents |= EVENT_WRITE; + revents |= EVENT_WRITE.bits(); } } else { *write_notified = false; @@ -437,9 +439,7 @@ impl syscall::SchemeBlockMut for SocketScheme where SocketT: SchemeSocket + AnySocket<'static, 'static>, { - fn open(&mut self, url: &[u8], flags: usize, uid: u32, _gid: u32) -> SyscallResult> { - let path = str::from_utf8(url).or_else(|_| Err(SyscallError::new(syscall::EINVAL)))?; - + fn open(&mut self, path: &str, flags: usize, uid: u32, _gid: u32) -> SyscallResult> { if path.is_empty() { let null = NullFile { flags: flags, @@ -552,15 +552,15 @@ where } fn dup(&mut self, fd: usize, buf: &[u8]) -> SyscallResult> { + let path = str::from_utf8(buf).or_else(|_| Err(SyscallError::new(syscall::EINVAL)))?; + if let Some((flags, uid, gid)) = self.nulls .get(&fd) .map(|null| (null.flags, null.uid, null.gid)) { - return self.open(buf, flags, uid, gid); + return self.open(path, flags, uid, gid); } - let path = str::from_utf8(buf).or_else(|_| Err(SyscallError::new(syscall::EINVAL)))?; - let new_file = { let file = self.files .get_mut(&fd) @@ -624,20 +624,20 @@ where Ok(Some(id)) } - fn fevent(&mut self, fd: usize, events: usize) -> SyscallResult> { + fn fevent(&mut self, fd: usize, events: SyscallEventFlags) -> SyscallResult> { let file = self.files .get_mut(&fd) .ok_or_else(|| SyscallError::new(syscall::EBADF))?; match *file { SchemeFile::Setting(_) => return Err(SyscallError::new(syscall::EBADF)), SchemeFile::Socket(ref mut file) => { - file.events = events; + file.events = events.bits(); file.read_notified = false; // resend missed events file.write_notified = false; } } let mut socket_set = self.socket_set.borrow_mut(); - let revents = file.events(&mut socket_set); + let revents = SyscallEventFlags::from_bits_truncate(file.events(&mut socket_set)); Ok(Some(revents)) } From 8669516ecd33c27a223120fd7b46cfbc4b7a237c Mon Sep 17 00:00:00 2001 From: 4lDO2 <4lDO2@protonmail.com> Date: Fri, 25 Mar 2022 15:23:27 +0100 Subject: [PATCH 113/155] Update syscall --- Cargo.lock | 280 ++++++++++++++++++++++++++--------------------------- Cargo.toml | 2 +- smoltcp | 2 +- 3 files changed, 137 insertions(+), 147 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f29f61c0c7..192a3f6e54 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,5 +1,7 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] name = "arg_parser" version = "0.1.0" @@ -7,54 +9,62 @@ source = "git+https://gitlab.redox-os.org/redox-os/arg-parser.git#1c434b55f3e1a0 [[package]] name = "bitflags" -version = "1.2.1" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "byteorder" version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855" [[package]] name = "byteorder" version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] name = "cfg-if" version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "crossbeam-channel" -version = "0.5.1" +version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aaa7bd5fb665c6864b5f963dd9097905c54125909c7aa94c9e18507cdbe6c53" dependencies = [ - "cfg-if 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam-utils 0.8.5 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 1.0.0", + "crossbeam-utils", ] [[package]] name = "crossbeam-utils" -version = "0.8.5" +version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf124c720b7686e3c2663cf54062ab0f68a88af2fb6a030e87e30bf721fcb38" dependencies = [ - "cfg-if 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 1.0.0", + "lazy_static", ] [[package]] name = "dns-parser" version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7020f6760aea312d43d23cb83bf6c0c49f162541db8b02bf95209ac51dc253d" dependencies = [ - "byteorder 1.4.3 (registry+https://github.com/rust-lang/crates.io-index)", - "quick-error 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.4.3", + "quick-error", ] [[package]] @@ -66,111 +76,124 @@ source = "git+https://gitlab.redox-os.org/redox-os/libextra.git#cf213969493db866 name = "fuchsia-zircon" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" dependencies = [ - "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags", + "fuchsia-zircon-sys", ] [[package]] name = "fuchsia-zircon-sys" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" [[package]] name = "idna" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e" dependencies = [ - "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-bidi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-normalization 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)", + "matches", + "unicode-bidi", + "unicode-normalization", ] [[package]] name = "iovec" version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" dependencies = [ - "libc 0.2.97 (registry+https://github.com/rust-lang/crates.io-index)", + "libc", ] [[package]] name = "kernel32-sys" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" dependencies = [ - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.2.8", + "winapi-build", ] [[package]] name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "lazycell" version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6f08839bc70ef4a3fe1d566d5350f519c5912ea86be0df1740a7d247c7fc0ef" [[package]] name = "libc" -version = "0.2.97" +version = "0.2.121" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "efaa7b300f3b5fe8eb6bf21ce3895e1751d9665086af2d64b42f19701015ff4f" [[package]] name = "log" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" dependencies = [ - "log 0.4.14 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.16", ] [[package]] name = "log" -version = "0.4.14" +version = "0.4.16" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6389c490849ff5bc16be905ae24bc913a9c8892e19b2341dbc175e14c341c2b8" dependencies = [ - "cfg-if 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 1.0.0", ] [[package]] name = "managed" version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c75de51135344a4f8ed3cfe2720dc27736f7711989703a0b43aadf3753c55577" [[package]] name = "matches" -version = "0.1.8" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" [[package]] name = "mio" version = "0.6.14" source = "git+https://gitlab.redox-os.org/redox-os/mio.git?branch=redox-unix#c9a70849ced97387e2607c9c466d23b130ec8901" dependencies = [ - "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "lazycell 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.97 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.14 (registry+https://github.com/rust-lang/crates.io-index)", - "miow 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "net2 0.2.37 (git+https://gitlab.redox-os.org/redox-os/net2-rs.git?branch=master)", - "slab 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "fuchsia-zircon", + "fuchsia-zircon-sys", + "iovec", + "kernel32-sys", + "lazycell", + "libc", + "log 0.4.16", + "miow", + "net2", + "slab", + "winapi 0.2.8", ] [[package]] name = "miow" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebd808424166322d4a38da87083bfddd3ac4c131334ed55856112eb06d46944d" dependencies = [ - "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "net2 0.2.37 (git+https://gitlab.redox-os.org/redox-os/net2-rs.git?branch=master)", - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "kernel32-sys", + "net2", + "winapi 0.2.8", + "ws2_32-sys", ] [[package]] @@ -178,9 +201,9 @@ name = "net2" version = "0.2.37" source = "git+https://gitlab.redox-os.org/redox-os/net2-rs.git?branch=master#db0604dcb0a355e6b2fa5bcaad8f175bd6aeb5aa" dependencies = [ - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.97 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10", + "libc", + "winapi 0.3.9", ] [[package]] @@ -188,18 +211,18 @@ name = "netutils" version = "0.1.0" source = "git+https://gitlab.redox-os.org/redox-os/netutils.git?branch=redox-unix#c5d6d20900fd4da9cbf1f3ec04bd752c3d5d3e04" dependencies = [ - "arg_parser 0.1.0 (git+https://gitlab.redox-os.org/redox-os/arg-parser.git)", - "extra 0.1.0 (git+https://gitlab.redox-os.org/redox-os/libextra.git)", - "libc 0.2.97 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.14 (git+https://gitlab.redox-os.org/redox-os/mio.git?branch=redox-unix)", - "net2 0.2.37 (git+https://gitlab.redox-os.org/redox-os/net2-rs.git?branch=master)", - "ntpclient 0.0.1 (git+https://github.com/willem66745/ntpclient-rust)", - "pbr 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_event 0.1.0 (git+https://gitlab.redox-os.org/redox-os/event.git)", - "redox_syscall 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_termios 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "termion 1.5.6 (registry+https://github.com/rust-lang/crates.io-index)", - "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", + "arg_parser", + "extra", + "libc", + "mio", + "net2", + "ntpclient", + "pbr", + "redox_event", + "redox_syscall", + "redox_termios", + "termion", + "url", ] [[package]] @@ -207,237 +230,204 @@ name = "ntpclient" version = "0.0.1" source = "git+https://github.com/willem66745/ntpclient-rust#7e3bdf60eb940825789a8da5181025320e3050b0" dependencies = [ - "byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", - "time 0.1.44 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 0.5.3", + "time", ] [[package]] name = "numtoa" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef" [[package]] name = "pbr" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff5751d87f7c00ae6403eb1fcbba229b9c76c9a30de8c1cf87182177b168cea2" dependencies = [ - "crossbeam-channel 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.97 (registry+https://github.com/rust-lang/crates.io-index)", - "time 0.1.44 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-channel", + "libc", + "time", + "winapi 0.3.9", ] [[package]] name = "percent-encoding" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" [[package]] name = "quick-error" version = "1.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" [[package]] name = "redox_event" version = "0.1.0" source = "git+https://gitlab.redox-os.org/redox-os/event.git#228eb0719c4424357012c6aad71cf26976048990" dependencies = [ - "redox_syscall 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall", ] [[package]] name = "redox_netstack" version = "0.1.0" dependencies = [ - "byteorder 1.4.3 (registry+https://github.com/rust-lang/crates.io-index)", - "dns-parser 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", - "netutils 0.1.0 (git+https://gitlab.redox-os.org/redox-os/netutils.git?branch=redox-unix)", - "redox_event 0.1.0 (git+https://gitlab.redox-os.org/redox-os/event.git)", - "redox_syscall 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", - "smoltcp 0.5.0", + "byteorder 1.4.3", + "dns-parser", + "log 0.3.9", + "netutils", + "redox_event", + "redox_syscall", + "smoltcp", ] [[package]] name = "redox_syscall" -version = "0.2.9" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ae183fc1b06c149f0c1793e1eb447c8b04bfe46d48e9e48bfb8d2d7ed64ecf0" dependencies = [ - "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags", ] [[package]] name = "redox_termios" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8440d8acb4fd3d277125b4bd01a6f38aee8d814b3b5fc09b3f2b825d37d3fe8f" dependencies = [ - "redox_syscall 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall", ] [[package]] name = "slab" -version = "0.4.3" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9def91fd1e018fe007022791f865d0ccc9b3a0d5001e01aabb8b40e46000afb5" [[package]] name = "smoltcp" version = "0.5.0" dependencies = [ - "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "byteorder 1.4.3 (registry+https://github.com/rust-lang/crates.io-index)", - "managed 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags", + "byteorder 1.4.3", + "managed", ] [[package]] name = "termion" version = "1.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "077185e2eac69c3f8379a4298e1e07cd36beb962290d4a51199acf0fdc10607e" dependencies = [ - "libc 0.2.97 (registry+https://github.com/rust-lang/crates.io-index)", - "numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_termios 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc", + "numtoa", + "redox_syscall", + "redox_termios", ] [[package]] name = "time" version = "0.1.44" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" dependencies = [ - "libc 0.2.97 (registry+https://github.com/rust-lang/crates.io-index)", - "wasi 0.10.0+wasi-snapshot-preview1 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", + "libc", + "wasi", + "winapi 0.3.9", ] [[package]] name = "tinyvec" -version = "1.2.0" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c1c1d5a42b6245520c249549ec267180beaffcc0615401ac8e31853d4b6d8d2" dependencies = [ - "tinyvec_macros 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "tinyvec_macros", ] [[package]] name = "tinyvec_macros" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "unicode-bidi" -version = "0.3.5" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", -] +checksum = "1a01404663e3db436ed2746d9fefef640d868edae3cceb81c3b8d5732fda678f" [[package]] name = "unicode-normalization" version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d54590932941a9e9266f0832deed84ebe1bf2e4c9e4a3554d393d18f5e854bf9" dependencies = [ - "tinyvec 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "tinyvec", ] [[package]] name = "url" version = "1.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd4e7c0d531266369519a4aa4f399d748bd37043b00bde1e4ff1f60a120b355a" dependencies = [ - "idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", - "percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "idna", + "matches", + "percent-encoding", ] [[package]] name = "wasi" version = "0.10.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" [[package]] name = "winapi" version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" [[package]] name = "winapi" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" dependencies = [ - "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", ] [[package]] name = "winapi-build" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "ws2_32-sys" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" dependencies = [ - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.2.8", + "winapi-build", ] - -[metadata] -"checksum arg_parser 0.1.0 (git+https://gitlab.redox-os.org/redox-os/arg-parser.git)" = "" -"checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" -"checksum byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855" -"checksum byteorder 1.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" -"checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" -"checksum cfg-if 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -"checksum crossbeam-channel 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "06ed27e177f16d65f0f0c22a213e17c696ace5dd64b14258b52f9417ccb52db4" -"checksum crossbeam-utils 0.8.5 (registry+https://github.com/rust-lang/crates.io-index)" = "d82cfc11ce7f2c3faef78d8a684447b40d503d9681acebed6cb728d45940c4db" -"checksum dns-parser 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f7020f6760aea312d43d23cb83bf6c0c49f162541db8b02bf95209ac51dc253d" -"checksum extra 0.1.0 (git+https://gitlab.redox-os.org/redox-os/libextra.git)" = "" -"checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" -"checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" -"checksum idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e" -"checksum iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" -"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" -"checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" -"checksum lazycell 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a6f08839bc70ef4a3fe1d566d5350f519c5912ea86be0df1740a7d247c7fc0ef" -"checksum libc 0.2.97 (registry+https://github.com/rust-lang/crates.io-index)" = "12b8adadd720df158f4d70dfe7ccc6adb0472d7c55ca83445f6a5ab3e36f8fb6" -"checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" -"checksum log 0.4.14 (registry+https://github.com/rust-lang/crates.io-index)" = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" -"checksum managed 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c75de51135344a4f8ed3cfe2720dc27736f7711989703a0b43aadf3753c55577" -"checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" -"checksum mio 0.6.14 (git+https://gitlab.redox-os.org/redox-os/mio.git?branch=redox-unix)" = "" -"checksum miow 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ebd808424166322d4a38da87083bfddd3ac4c131334ed55856112eb06d46944d" -"checksum net2 0.2.37 (git+https://gitlab.redox-os.org/redox-os/net2-rs.git?branch=master)" = "" -"checksum netutils 0.1.0 (git+https://gitlab.redox-os.org/redox-os/netutils.git?branch=redox-unix)" = "" -"checksum ntpclient 0.0.1 (git+https://github.com/willem66745/ntpclient-rust)" = "" -"checksum numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef" -"checksum pbr 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "ff5751d87f7c00ae6403eb1fcbba229b9c76c9a30de8c1cf87182177b168cea2" -"checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" -"checksum quick-error 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" -"checksum redox_event 0.1.0 (git+https://gitlab.redox-os.org/redox-os/event.git)" = "" -"checksum redox_syscall 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)" = "5ab49abadf3f9e1c4bc499e8845e152ad87d2ad2d30371841171169e9d75feee" -"checksum redox_termios 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8440d8acb4fd3d277125b4bd01a6f38aee8d814b3b5fc09b3f2b825d37d3fe8f" -"checksum slab 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "f173ac3d1a7e3b28003f40de0b5ce7fe2710f9b9dc3fc38664cebee46b3b6527" -"checksum termion 1.5.6 (registry+https://github.com/rust-lang/crates.io-index)" = "077185e2eac69c3f8379a4298e1e07cd36beb962290d4a51199acf0fdc10607e" -"checksum time 0.1.44 (registry+https://github.com/rust-lang/crates.io-index)" = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" -"checksum tinyvec 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5b5220f05bb7de7f3f53c7c065e1199b3172696fe2db9f9c4d8ad9b4ee74c342" -"checksum tinyvec_macros 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" -"checksum unicode-bidi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "eeb8be209bb1c96b7c177c7420d26e04eccacb0eeae6b980e35fcb74678107e0" -"checksum unicode-normalization 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)" = "d54590932941a9e9266f0832deed84ebe1bf2e4c9e4a3554d393d18f5e854bf9" -"checksum url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dd4e7c0d531266369519a4aa4f399d748bd37043b00bde1e4ff1f60a120b355a" -"checksum wasi 0.10.0+wasi-snapshot-preview1 (registry+https://github.com/rust-lang/crates.io-index)" = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" -"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" -"checksum winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -"checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" -"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" -"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -"checksum ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" diff --git a/Cargo.toml b/Cargo.toml index 989d3da697..689cf03236 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ path = "src/lib/lib.rs" [dependencies] netutils = { git = "https://gitlab.redox-os.org/redox-os/netutils.git", branch = "redox-unix" } redox_event = { git = "https://gitlab.redox-os.org/redox-os/event.git" } -redox_syscall = "0.2.9" +redox_syscall = "0.2.12" byteorder = { version = "1.0", default-features = false } dns-parser = "0.7.1" diff --git a/smoltcp b/smoltcp index 9fbcf5cfcb..be52c19154 160000 --- a/smoltcp +++ b/smoltcp @@ -1 +1 @@ -Subproject commit 9fbcf5cfcb3b0d3e8ca77da2bc0f56c4d3c3b412 +Subproject commit be52c19154231c553766be9efc434c3b9bc3ab05 From ec22a4f3932ba63ccbe7648c53080cbccd6cc565 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Tue, 26 Jul 2022 17:32:02 -0600 Subject: [PATCH 114/155] Update Cargo.lock --- Cargo.lock | 65 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 28 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 192a3f6e54..5b70b8051a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7,6 +7,12 @@ name = "arg_parser" version = "0.1.0" source = "git+https://gitlab.redox-os.org/redox-os/arg-parser.git#1c434b55f3e1a0375ebcca85b3e88db7378e82fa" +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + [[package]] name = "bitflags" version = "1.3.2" @@ -39,9 +45,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "crossbeam-channel" -version = "0.5.4" +version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aaa7bd5fb665c6864b5f963dd9097905c54125909c7aa94c9e18507cdbe6c53" +checksum = "c2dd04ddaf88237dc3b8d8f9a3c1004b506b54b3313403944054d23c0870c521" dependencies = [ "cfg-if 1.0.0", "crossbeam-utils", @@ -49,12 +55,12 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.8" +version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bf124c720b7686e3c2663cf54062ab0f68a88af2fb6a030e87e30bf721fcb38" +checksum = "51887d4adc7b564537b15adcfb307936f8075dfcd5f00dde9a9f1d29383682bc" dependencies = [ "cfg-if 1.0.0", - "lazy_static", + "once_cell", ] [[package]] @@ -118,12 +124,6 @@ dependencies = [ "winapi-build", ] -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - [[package]] name = "lazycell" version = "0.6.0" @@ -132,9 +132,9 @@ checksum = "a6f08839bc70ef4a3fe1d566d5350f519c5912ea86be0df1740a7d247c7fc0ef" [[package]] name = "libc" -version = "0.2.121" +version = "0.2.126" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efaa7b300f3b5fe8eb6bf21ce3895e1751d9665086af2d64b42f19701015ff4f" +checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" [[package]] name = "log" @@ -142,14 +142,14 @@ version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" dependencies = [ - "log 0.4.16", + "log 0.4.17", ] [[package]] name = "log" -version = "0.4.16" +version = "0.4.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6389c490849ff5bc16be905ae24bc913a9c8892e19b2341dbc175e14c341c2b8" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" dependencies = [ "cfg-if 1.0.0", ] @@ -177,7 +177,7 @@ dependencies = [ "kernel32-sys", "lazycell", "libc", - "log 0.4.16", + "log 0.4.17", "miow", "net2", "slab", @@ -209,7 +209,7 @@ dependencies = [ [[package]] name = "netutils" version = "0.1.0" -source = "git+https://gitlab.redox-os.org/redox-os/netutils.git?branch=redox-unix#c5d6d20900fd4da9cbf1f3ec04bd752c3d5d3e04" +source = "git+https://gitlab.redox-os.org/redox-os/netutils.git?branch=redox-unix#55c55eb6452ee886dfd81f1cbb7f9ec45012d95e" dependencies = [ "arg_parser", "extra", @@ -240,6 +240,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef" +[[package]] +name = "once_cell" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1" + [[package]] name = "pbr" version = "1.0.4" @@ -287,9 +293,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.2.12" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ae183fc1b06c149f0c1793e1eb447c8b04bfe46d48e9e48bfb8d2d7ed64ecf0" +checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" dependencies = [ "bitflags", ] @@ -305,9 +311,12 @@ dependencies = [ [[package]] name = "slab" -version = "0.4.5" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9def91fd1e018fe007022791f865d0ccc9b3a0d5001e01aabb8b40e46000afb5" +checksum = "4614a76b2a8be0058caa9dbbaf66d988527d86d003c11a94fbd335d7661edcef" +dependencies = [ + "autocfg", +] [[package]] name = "smoltcp" @@ -343,9 +352,9 @@ dependencies = [ [[package]] name = "tinyvec" -version = "1.5.1" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c1c1d5a42b6245520c249549ec267180beaffcc0615401ac8e31853d4b6d8d2" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" dependencies = [ "tinyvec_macros", ] @@ -358,15 +367,15 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "unicode-bidi" -version = "0.3.7" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a01404663e3db436ed2746d9fefef640d868edae3cceb81c3b8d5732fda678f" +checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" [[package]] name = "unicode-normalization" -version = "0.1.19" +version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d54590932941a9e9266f0832deed84ebe1bf2e4c9e4a3554d393d18f5e854bf9" +checksum = "854cbdc4f7bc6ae19c820d44abdc3277ac3e1b2b93db20a636825d9322fb60e6" dependencies = [ "tinyvec", ] From 54d64d6ecb16b303a7dd7afd2ca8fc756f1cb069 Mon Sep 17 00:00:00 2001 From: 4lDO2 <4lDO2@protonmail.com> Date: Mon, 18 Jul 2022 16:21:21 +0200 Subject: [PATCH 115/155] Use redox-daemon --- Cargo.lock | 11 +++++++++++ Cargo.toml | 1 + src/dnsd/main.rs | 11 +++++++---- src/smolnetd/main.rs | 11 +++++++---- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5b70b8051a..d085d13a57 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -270,6 +270,16 @@ version = "1.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" +[[package]] +name = "redox-daemon" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21e31c834277709c7ff3eb74959fe62be4b45b1189ba9d41fd3744cd3a9c554f" +dependencies = [ + "libc", + "redox_syscall", +] + [[package]] name = "redox_event" version = "0.1.0" @@ -286,6 +296,7 @@ dependencies = [ "dns-parser", "log 0.3.9", "netutils", + "redox-daemon", "redox_event", "redox_syscall", "smoltcp", diff --git a/Cargo.toml b/Cargo.toml index 689cf03236..a44597032c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,6 +17,7 @@ path = "src/lib/lib.rs" [dependencies] netutils = { git = "https://gitlab.redox-os.org/redox-os/netutils.git", branch = "redox-unix" } redox_event = { git = "https://gitlab.redox-os.org/redox-os/event.git" } +redox-daemon = "0.1" redox_syscall = "0.2.12" byteorder = { version = "1.0", default-features = false } dns-parser = "0.7.1" diff --git a/src/dnsd/main.rs b/src/dnsd/main.rs index eef8ea9517..b52090b3a5 100644 --- a/src/dnsd/main.rs +++ b/src/dnsd/main.rs @@ -21,7 +21,7 @@ use syscall::{CloneFlags, EventFlags}; mod scheme; -fn run() -> Result<()> { +fn run(daemon: redox_daemon::Daemon) -> Result<()> { use syscall::flag::*; let dns_fd = syscall::open(":dns", O_RDWR | O_CREAT | O_NONBLOCK) @@ -53,6 +53,8 @@ fn run() -> Result<()> { syscall::setrens(0, 0).expect("dnsd: failed to enter null namespace"); + daemon.ready().expect("dnsd: failed to notify parent"); + let dnsd_ = Rc::clone(&dnsd); event_queue @@ -82,11 +84,12 @@ fn run() -> Result<()> { } fn main() { - if unsafe { syscall::clone(CloneFlags::empty()).unwrap() } == 0 { + redox_daemon::Daemon::new(move |daemon| { logger::init_logger(); - if let Err(err) = run() { + if let Err(err) = run(daemon) { error!("dnsd: {}", err); process::exit(1); } - } + process::exit(0); + }).expect("dnsd: failed to daemonize"); } diff --git a/src/smolnetd/main.rs b/src/smolnetd/main.rs index 3a6241b320..79da5ee7f7 100644 --- a/src/smolnetd/main.rs +++ b/src/smolnetd/main.rs @@ -27,7 +27,7 @@ mod device; mod port_set; mod scheme; -fn run() -> Result<()> { +fn run(daemon: redox_daemon::Daemon) -> Result<()> { use syscall::flag::*; trace!("opening network:"); @@ -91,6 +91,8 @@ fn run() -> Result<()> { syscall::setrens(0, 0).expect("smolnetd: failed to enter null namespace"); + daemon.ready().expect("smolnetd: failed to notify parent"); + let smolnetd_ = Rc::clone(&smolnetd); event_queue @@ -150,12 +152,13 @@ fn run() -> Result<()> { } fn main() { - if unsafe { syscall::clone(CloneFlags::empty()).unwrap() } == 0 { + redox_daemon::Daemon::new(move |daemon| { logger::init_logger(); - if let Err(err) = run() { + if let Err(err) = run(daemon) { error!("smoltcpd: {}", err); process::exit(1); } - } + process::exit(0); + }).expect("smoltcp: failed to daemonize"); } From 74cfc428dc9c6178f598819de12a340f3d5bc544 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sat, 11 Feb 2023 14:43:04 -0700 Subject: [PATCH 116/155] Update libc crate --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d085d13a57..f0d0b8313d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -132,9 +132,9 @@ checksum = "a6f08839bc70ef4a3fe1d566d5350f519c5912ea86be0df1740a7d247c7fc0ef" [[package]] name = "libc" -version = "0.2.126" +version = "0.2.139" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" +checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" [[package]] name = "log" From c0a108ca11021fe799ffad2ef9191d4126fcdab5 Mon Sep 17 00:00:00 2001 From: Gartox Date: Sun, 27 Aug 2023 15:04:44 +0200 Subject: [PATCH 117/155] Fix warnings and bump Rust edition to 2021 --- Cargo.toml | 1 + src/dnsd/main.rs | 4 --- src/smolnetd/device.rs | 2 +- src/smolnetd/main.rs | 2 -- src/smolnetd/scheme/icmp.rs | 4 +-- src/smolnetd/scheme/ip.rs | 2 +- src/smolnetd/scheme/mod.rs | 4 +-- src/smolnetd/scheme/netcfg/mod.rs | 2 +- src/smolnetd/scheme/netcfg/nodes.rs | 40 ++++++++++++++--------------- src/smolnetd/scheme/socket.rs | 36 +++++++++++++------------- src/smolnetd/scheme/tcp.rs | 2 +- src/smolnetd/scheme/udp.rs | 4 +-- 12 files changed, 49 insertions(+), 54 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a44597032c..b667e55a2d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,7 @@ [package] name = "redox_netstack" version = "0.1.0" +edition = "2021" [[bin]] name = "dnsd" diff --git a/src/dnsd/main.rs b/src/dnsd/main.rs index b52090b3a5..0fb01f491b 100644 --- a/src/dnsd/main.rs +++ b/src/dnsd/main.rs @@ -1,5 +1,3 @@ -#![feature(nll)] - extern crate dns_parser; extern crate event; #[macro_use] @@ -17,8 +15,6 @@ use std::os::unix::io::{AsRawFd, FromRawFd, RawFd}; use std::process; use std::rc::Rc; -use syscall::{CloneFlags, EventFlags}; - mod scheme; fn run(daemon: redox_daemon::Daemon) -> Result<()> { diff --git a/src/smolnetd/device.rs b/src/smolnetd/device.rs index 9385a6c93a..63919c2be4 100644 --- a/src/smolnetd/device.rs +++ b/src/smolnetd/device.rs @@ -7,7 +7,7 @@ use std::rc::Rc; use smoltcp::time::Instant; use smoltcp::wire::EthernetAddress; -use buffer_pool::{Buffer, BufferPool}; +use crate::buffer_pool::{Buffer, BufferPool}; struct NetworkDeviceData { network_file: Rc>, diff --git a/src/smolnetd/main.rs b/src/smolnetd/main.rs index 79da5ee7f7..b359245ec3 100644 --- a/src/smolnetd/main.rs +++ b/src/smolnetd/main.rs @@ -15,8 +15,6 @@ use std::os::unix::io::{FromRawFd, RawFd}; use std::process; use std::rc::Rc; -use syscall::flag::{CloneFlags, EventFlags}; - use redox_netstack::error::{Error, Result}; use redox_netstack::logger; use event::EventQueue; diff --git a/src/smolnetd/scheme/icmp.rs b/src/smolnetd/scheme/icmp.rs index ddb31bc030..cd65926f81 100644 --- a/src/smolnetd/scheme/icmp.rs +++ b/src/smolnetd/scheme/icmp.rs @@ -6,8 +6,8 @@ use syscall::{Error as SyscallError, Result as SyscallResult}; use syscall; use byteorder::{ByteOrder, NetworkEndian}; -use device::NetworkDevice; -use port_set::PortSet; +use crate::device::NetworkDevice; +use crate::port_set::PortSet; use super::socket::{DupResult, SchemeFile, SchemeSocket, SocketFile, SocketScheme}; use super::{Smolnetd, SocketSet}; diff --git a/src/smolnetd/scheme/ip.rs b/src/smolnetd/scheme/ip.rs index 97a83cad32..b13cbc2720 100644 --- a/src/smolnetd/scheme/ip.rs +++ b/src/smolnetd/scheme/ip.rs @@ -4,7 +4,7 @@ use std::str; use syscall::{Error as SyscallError, Result as SyscallResult}; use syscall; -use device::NetworkDevice; +use crate::device::NetworkDevice; use super::{Smolnetd, SocketSet}; use super::socket::{DupResult, SchemeFile, SchemeSocket, SocketFile, SocketScheme}; diff --git a/src/smolnetd/scheme/mod.rs b/src/smolnetd/scheme/mod.rs index 3a194410cf..eab5942b29 100644 --- a/src/smolnetd/scheme/mod.rs +++ b/src/smolnetd/scheme/mod.rs @@ -15,8 +15,8 @@ use std::str::FromStr; use syscall::data::TimeSpec; use syscall; -use buffer_pool::{Buffer, BufferPool}; -use device::NetworkDevice; +use crate::buffer_pool::{Buffer, BufferPool}; +use crate::device::NetworkDevice; use redox_netstack::error::{Error, Result}; use self::ip::IpScheme; use self::tcp::TcpScheme; diff --git a/src/smolnetd/scheme/netcfg/mod.rs b/src/smolnetd/scheme/netcfg/mod.rs index 7e91303322..c64b310092 100644 --- a/src/smolnetd/scheme/netcfg/mod.rs +++ b/src/smolnetd/scheme/netcfg/mod.rs @@ -284,7 +284,7 @@ struct NetCfgFile { is_dir: bool, is_writable: bool, is_readable: bool, - node_writer: Option>, + node_writer: Option>, read_buf: Vec, write_buf: Vec, pos: usize, diff --git a/src/smolnetd/scheme/netcfg/nodes.rs b/src/smolnetd/scheme/netcfg/nodes.rs index 398a4e7c38..16bacb6242 100644 --- a/src/smolnetd/scheme/netcfg/nodes.rs +++ b/src/smolnetd/scheme/netcfg/nodes.rs @@ -3,10 +3,10 @@ use std::rc::Rc; use std::collections::BTreeMap; use syscall::Result as SyscallResult; -pub type CfgNodeRef = Rc>; +pub type CfgNodeRef = Rc>; pub trait NodeWriter { - fn write_line(&mut self, &str) -> SyscallResult<()> { + fn write_line(&mut self, _: &str) -> SyscallResult<()> { Ok(()) } @@ -74,7 +74,7 @@ pub trait CfgNode { None } - fn new_writer(&self) -> Option> { + fn new_writer(&self) -> Option> { None } } @@ -106,14 +106,14 @@ where pub struct WONode where - W: 'static + Fn() -> Box, + W: 'static + Fn() -> Box, { new_writer: W, } impl CfgNode for WONode where - W: 'static + Fn() -> Box, + W: 'static + Fn() -> Box, { fn is_readable(&self) -> bool { false @@ -123,14 +123,14 @@ where true } - fn new_writer(&self) -> Option> { + fn new_writer(&self) -> Option> { Some((self.new_writer)()) } } impl WONode where - W: 'static + Fn() -> Box, + W: 'static + Fn() -> Box, { pub fn new_ref(new_writer: W) -> CfgNodeRef { Rc::new(RefCell::new(WONode { new_writer })) @@ -140,7 +140,7 @@ where pub struct RWNode where F: Fn() -> String, - W: 'static + Fn() -> Box, + W: 'static + Fn() -> Box, { read_fun: F, new_writer: W, @@ -149,7 +149,7 @@ where impl CfgNode for RWNode where F: Fn() -> String, - W: 'static + Fn() -> Box, + W: 'static + Fn() -> Box, { fn read(&self) -> String { (self.read_fun)() @@ -159,7 +159,7 @@ where true } - fn new_writer(&self) -> Option> { + fn new_writer(&self) -> Option> { Some((self.new_writer)()) } } @@ -167,7 +167,7 @@ where impl RWNode where F: 'static + Fn() -> String, - W: 'static + Fn() -> Box, + W: 'static + Fn() -> Box, { pub fn new_ref(read_fun: F, new_writer: W) -> CfgNodeRef { Rc::new(RefCell::new(RWNode { @@ -221,14 +221,14 @@ macro_rules! cfg_node { (wo [ $($c:ident),* ] ( $et:ty , $e:expr ) |$data_i:ident, $line_i:ident| $write_line:block |$data_i2:ident| $commit:block) => { { - $(#[allow(unused_variables)] let $c = $c.clone();)*; - let new_writer = move || -> Box { + $(#[allow(unused_variables)] let $c = $c.clone();)* + let new_writer = move || -> Box { let write_line = { - $(#[allow(unused_variables)] let $c = $c.clone();)*; + $(#[allow(unused_variables)] let $c = $c.clone();)* move |$data_i: &mut $et, $line_i: &str| $write_line }; let commit = { - $(#[allow(unused_variables)] let $c = $c.clone();)*; + $(#[allow(unused_variables)] let $c = $c.clone();)* move |$data_i2: &mut $et| $commit }; let data: $et = $e; @@ -241,17 +241,17 @@ macro_rules! cfg_node { $write_line:block |$data_i2:ident| $commit:block) => { { let read_fun = { - $(#[allow(unused_variables)] let $c = $c.clone();)*; + $(#[allow(unused_variables)] let $c = $c.clone();)* move || $read_fun }; - $(#[allow(unused_variables)] let $c = $c.clone();)*; - let new_writer = move || -> Box { + $(#[allow(unused_variables)] let $c = $c.clone();)* + let new_writer = move || -> Box { let write_line = { - $(#[allow(unused_variables)] let $c = $c.clone();)*; + $(#[allow(unused_variables)] let $c = $c.clone();)* move |$data_i: &mut $et, $line_i: &str| $write_line }; let commit = { - $(#[allow(unused_variables)] let $c = $c.clone();)*; + $(#[allow(unused_variables)] let $c = $c.clone();)* move |$data_i2: &mut $et| $commit }; let data: $et = $e; diff --git a/src/smolnetd/scheme/socket.rs b/src/smolnetd/scheme/socket.rs index 7dd3d665f1..b61ee1ce23 100644 --- a/src/smolnetd/scheme/socket.rs +++ b/src/smolnetd/scheme/socket.rs @@ -160,31 +160,31 @@ where fn may_recv(&self) -> bool; fn hop_limit(&self) -> u8; - fn set_hop_limit(&mut self, u8); + fn set_hop_limit(&mut self, hop_limit: u8); - fn get_setting(&SocketFile, Self::SettingT, &mut [u8]) -> SyscallResult; - fn set_setting(&mut SocketFile, Self::SettingT, &[u8]) -> SyscallResult; + fn get_setting(file: &SocketFile, setting: Self::SettingT, buf: &mut [u8]) -> SyscallResult; + fn set_setting(file: &mut SocketFile, setting: Self::SettingT, buf: &[u8]) -> SyscallResult; fn new_socket( - &mut SocketSet, - &str, - u32, - &mut Self::SchemeDataT, + sockets: &mut SocketSet, + path: &str, + uid: u32, + data: &mut Self::SchemeDataT, ) -> SyscallResult<(SocketHandle, Self::DataT)>; - fn close_file(&self, &SchemeFile, &mut Self::SchemeDataT) -> SyscallResult<()>; + fn close_file(&self, file: &SchemeFile, data: &mut Self::SchemeDataT) -> SyscallResult<()>; - fn write_buf(&mut self, &mut SocketFile, buf: &[u8]) -> SyscallResult>; + fn write_buf(&mut self, file: &mut SocketFile, buf: &[u8]) -> SyscallResult>; - fn read_buf(&mut self, &mut SocketFile, buf: &mut [u8]) -> SyscallResult>; + fn read_buf(&mut self, file: &mut SocketFile, buf: &mut [u8]) -> SyscallResult>; - fn fpath(&self, &SchemeFile, &mut [u8]) -> SyscallResult; + fn fpath(&self, file: &SchemeFile, buf: &mut [u8]) -> SyscallResult; fn dup( - &mut SocketSet, - &mut SchemeFile, - &str, - &mut Self::SchemeDataT, + sockets: &mut SocketSet, + file: &mut SchemeFile, + path: &str, + data: &mut Self::SchemeDataT, ) -> SyscallResult>; } @@ -242,7 +242,7 @@ where Ok(timeout) => { self.wait_queue.push(WaitHandle { until: timeout, - packet: packet, + packet, }); }, Err(err) => { @@ -442,8 +442,8 @@ where fn open(&mut self, path: &str, flags: usize, uid: u32, _gid: u32) -> SyscallResult> { if path.is_empty() { let null = NullFile { - flags: flags, - uid: uid, + flags, + uid, gid: _gid, }; diff --git a/src/smolnetd/scheme/tcp.rs b/src/smolnetd/scheme/tcp.rs index ab33ff3c9f..200ba42aa4 100644 --- a/src/smolnetd/scheme/tcp.rs +++ b/src/smolnetd/scheme/tcp.rs @@ -3,7 +3,7 @@ use std::str; use syscall::{Error as SyscallError, Result as SyscallResult}; use syscall; -use port_set::PortSet; +use crate::port_set::PortSet; use super::socket::{DupResult, SchemeFile, SchemeSocket, SocketFile, SocketScheme}; use super::{parse_endpoint, SocketSet}; diff --git a/src/smolnetd/scheme/udp.rs b/src/smolnetd/scheme/udp.rs index d253e1aa10..646821f625 100644 --- a/src/smolnetd/scheme/udp.rs +++ b/src/smolnetd/scheme/udp.rs @@ -4,8 +4,8 @@ use std::str; use syscall::{Error as SyscallError, Result as SyscallResult}; use syscall; -use device::NetworkDevice; -use port_set::PortSet; +use crate::device::NetworkDevice; +use crate::port_set::PortSet; use super::socket::{DupResult, SchemeFile, SchemeSocket, SocketFile, SocketScheme}; use super::{parse_endpoint, Smolnetd, SocketSet}; From dec8ed1a505fa56e3a8f9eaedc995c15755e288f Mon Sep 17 00:00:00 2001 From: 4lDO2 <4lDO2@protonmail.com> Date: Thu, 31 Aug 2023 21:11:41 +0200 Subject: [PATCH 118/155] Update dependencies. --- Cargo.lock | 89 +++++++++++++++++++++++++++--------------------------- Cargo.toml | 4 +-- 2 files changed, 46 insertions(+), 47 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f0d0b8313d..ee733098ef 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -45,9 +45,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "crossbeam-channel" -version = "0.5.6" +version = "0.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2dd04ddaf88237dc3b8d8f9a3c1004b506b54b3313403944054d23c0870c521" +checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200" dependencies = [ "cfg-if 1.0.0", "crossbeam-utils", @@ -55,12 +55,11 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.11" +version = "0.8.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51887d4adc7b564537b15adcfb307936f8075dfcd5f00dde9a9f1d29383682bc" +checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294" dependencies = [ "cfg-if 1.0.0", - "once_cell", ] [[package]] @@ -132,9 +131,9 @@ checksum = "a6f08839bc70ef4a3fe1d566d5350f519c5912ea86be0df1740a7d247c7fc0ef" [[package]] name = "libc" -version = "0.2.139" +version = "0.2.147" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" +checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" [[package]] name = "log" @@ -142,17 +141,14 @@ version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" dependencies = [ - "log 0.4.17", + "log 0.4.20", ] [[package]] name = "log" -version = "0.4.17" +version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" -dependencies = [ - "cfg-if 1.0.0", -] +checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" [[package]] name = "managed" @@ -162,9 +158,9 @@ checksum = "c75de51135344a4f8ed3cfe2720dc27736f7711989703a0b43aadf3753c55577" [[package]] name = "matches" -version = "0.1.9" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" +checksum = "2532096657941c2fea9c289d370a250971c689d4f143798ff67113ec042024a5" [[package]] name = "mio" @@ -177,7 +173,7 @@ dependencies = [ "kernel32-sys", "lazycell", "libc", - "log 0.4.17", + "log 0.4.20", "miow", "net2", "slab", @@ -209,7 +205,7 @@ dependencies = [ [[package]] name = "netutils" version = "0.1.0" -source = "git+https://gitlab.redox-os.org/redox-os/netutils.git?branch=redox-unix#55c55eb6452ee886dfd81f1cbb7f9ec45012d95e" +source = "git+https://gitlab.redox-os.org/redox-os/netutils.git?branch=redox-unix#105ed1ea43413a91152b289fbe76e7efc996e933" dependencies = [ "arg_parser", "extra", @@ -218,8 +214,9 @@ dependencies = [ "net2", "ntpclient", "pbr", + "redox-daemon", "redox_event", - "redox_syscall", + "redox_syscall 0.2.16", "redox_termios", "termion", "url", @@ -240,21 +237,14 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef" -[[package]] -name = "once_cell" -version = "1.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1" - [[package]] name = "pbr" -version = "1.0.4" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff5751d87f7c00ae6403eb1fcbba229b9c76c9a30de8c1cf87182177b168cea2" +checksum = "ed5827dfa0d69b6c92493d6c38e633bbaa5937c153d0d7c28bf12313f8c6d514" dependencies = [ "crossbeam-channel", "libc", - "time", "winapi 0.3.9", ] @@ -272,20 +262,20 @@ checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" [[package]] name = "redox-daemon" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21e31c834277709c7ff3eb74959fe62be4b45b1189ba9d41fd3744cd3a9c554f" +checksum = "811fd0d382a70c9e9192166ee794567b65ef34cc7309c86a49b071779ca9b5f3" dependencies = [ "libc", - "redox_syscall", + "redox_syscall 0.3.5", ] [[package]] name = "redox_event" version = "0.1.0" -source = "git+https://gitlab.redox-os.org/redox-os/event.git#228eb0719c4424357012c6aad71cf26976048990" +source = "git+https://gitlab.redox-os.org/redox-os/event.git#f7db3d25ca5e282c12ded12bf6c720087b570132" dependencies = [ - "redox_syscall", + "redox_syscall 0.3.5", ] [[package]] @@ -298,7 +288,7 @@ dependencies = [ "netutils", "redox-daemon", "redox_event", - "redox_syscall", + "redox_syscall 0.3.5", "smoltcp", ] @@ -311,20 +301,29 @@ dependencies = [ "bitflags", ] +[[package]] +name = "redox_syscall" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" +dependencies = [ + "bitflags", +] + [[package]] name = "redox_termios" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8440d8acb4fd3d277125b4bd01a6f38aee8d814b3b5fc09b3f2b825d37d3fe8f" dependencies = [ - "redox_syscall", + "redox_syscall 0.2.16", ] [[package]] name = "slab" -version = "0.4.7" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4614a76b2a8be0058caa9dbbaf66d988527d86d003c11a94fbd335d7661edcef" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" dependencies = [ "autocfg", ] @@ -346,15 +345,15 @@ checksum = "077185e2eac69c3f8379a4298e1e07cd36beb962290d4a51199acf0fdc10607e" dependencies = [ "libc", "numtoa", - "redox_syscall", + "redox_syscall 0.2.16", "redox_termios", ] [[package]] name = "time" -version = "0.1.44" +version = "0.1.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" +checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a" dependencies = [ "libc", "wasi", @@ -372,21 +371,21 @@ dependencies = [ [[package]] name = "tinyvec_macros" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "unicode-bidi" -version = "0.3.8" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" +checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" [[package]] name = "unicode-normalization" -version = "0.1.21" +version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "854cbdc4f7bc6ae19c820d44abdc3277ac3e1b2b93db20a636825d9322fb60e6" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" dependencies = [ "tinyvec", ] diff --git a/Cargo.toml b/Cargo.toml index b667e55a2d..abcc920098 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,8 +18,8 @@ path = "src/lib/lib.rs" [dependencies] netutils = { git = "https://gitlab.redox-os.org/redox-os/netutils.git", branch = "redox-unix" } redox_event = { git = "https://gitlab.redox-os.org/redox-os/event.git" } -redox-daemon = "0.1" -redox_syscall = "0.2.12" +redox-daemon = "0.1.1" +redox_syscall = "0.3" byteorder = { version = "1.0", default-features = false } dns-parser = "0.7.1" From 2f1443b925553012ac6c75e6e1afa5519fd61268 Mon Sep 17 00:00:00 2001 From: Gartox Date: Fri, 1 Sep 2023 11:09:54 +0200 Subject: [PATCH 119/155] Fix netutils deps --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index abcc920098..2b69b83462 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ name = "redox_netstack" path = "src/lib/lib.rs" [dependencies] -netutils = { git = "https://gitlab.redox-os.org/redox-os/netutils.git", branch = "redox-unix" } +netutils = { git = "https://gitlab.redox-os.org/redox-os/netutils.git" } redox_event = { git = "https://gitlab.redox-os.org/redox-os/event.git" } redox-daemon = "0.1.1" redox_syscall = "0.3" From 035bcf1d69dd17245ae62cd9266dcac05ec995a2 Mon Sep 17 00:00:00 2001 From: Gartox Date: Mon, 28 Aug 2023 18:11:08 +0200 Subject: [PATCH 120/155] Migrating to smoltcp 0.10 --- Cargo.toml | 10 ++-- src/dnsd/main.rs | 2 +- src/lib/logger.rs | 32 +++++------ src/smolnetd/device.rs | 26 ++++----- src/smolnetd/main.rs | 2 +- src/smolnetd/scheme/icmp.rs | 18 ++++--- src/smolnetd/scheme/ip.rs | 10 ++-- src/smolnetd/scheme/mod.rs | 77 +++++++++++++------------- src/smolnetd/scheme/netcfg/mod.rs | 29 +++++----- src/smolnetd/scheme/socket.rs | 64 ++++++++++++++++------ src/smolnetd/scheme/tcp.rs | 89 +++++++++++++++++++------------ src/smolnetd/scheme/udp.rs | 21 +++++--- 12 files changed, 217 insertions(+), 163 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2b69b83462..e6d2d024d1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,22 +20,24 @@ netutils = { git = "https://gitlab.redox-os.org/redox-os/netutils.git" } redox_event = { git = "https://gitlab.redox-os.org/redox-os/event.git" } redox-daemon = "0.1.1" redox_syscall = "0.3" +redox-log = "0.1" byteorder = { version = "1.0", default-features = false } dns-parser = "0.7.1" [dependencies.log] -version = "0.3" +version = "0.4" default-features = false features = ["release_max_level_warn"] [dependencies.smoltcp] -path = "smoltcp" +version = "0.10.0" default-features = false features = [ "std", - "ethernet", + "medium-ethernet", "proto-ipv4", - "socket-raw", "socket-icmp", "socket-udp", "socket-tcp" + "socket-raw", "socket-icmp", "socket-udp", "socket-tcp", + "log" ] #For debugging: "log", "verbose" diff --git a/src/dnsd/main.rs b/src/dnsd/main.rs index 0fb01f491b..3ba52906f8 100644 --- a/src/dnsd/main.rs +++ b/src/dnsd/main.rs @@ -81,7 +81,7 @@ fn run(daemon: redox_daemon::Daemon) -> Result<()> { fn main() { redox_daemon::Daemon::new(move |daemon| { - logger::init_logger(); + logger::init_logger("dnsd"); if let Err(err) = run(daemon) { error!("dnsd: {}", err); process::exit(1); diff --git a/src/lib/logger.rs b/src/lib/logger.rs index 90ed1f8306..e2952e98db 100644 --- a/src/lib/logger.rs +++ b/src/lib/logger.rs @@ -1,22 +1,16 @@ -use log::{set_logger_raw, Log, LogLevelFilter, LogMetadata, LogRecord}; +use redox_log::{OutputBuilder, RedoxLogger}; -struct Logger; - -impl Log for Logger { - fn enabled(&self, _: &LogMetadata) -> bool { - true - } - - fn log(&self, record: &LogRecord) { - println!("{}: {}", record.target(), record.args()); - } -} - -pub fn init_logger() { - unsafe { - set_logger_raw(|max_log_level| { - max_log_level.set(LogLevelFilter::Trace); - &Logger - }).expect("Can't initialize logger"); +pub fn init_logger(process_name: &str) { + if let Err(_) = RedoxLogger::new() + .with_output( + OutputBuilder::stdout() + .with_ansi_escape_codes() + .flush_on_newline(true) + .with_filter(log::LevelFilter::Trace) + .build(), + ) + .with_process_name(process_name.into()) + .enable() { + eprintln!("{process_name}: Failed to init logger") } } diff --git a/src/smolnetd/device.rs b/src/smolnetd/device.rs index 63919c2be4..3c276fe558 100644 --- a/src/smolnetd/device.rs +++ b/src/smolnetd/device.rs @@ -45,9 +45,9 @@ pub struct RxToken { } impl smoltcp::phy::RxToken for RxToken { - fn consume(mut self, _timestamp: Instant, f: F) -> smoltcp::Result + fn consume(mut self, f: F) -> R where - F: FnOnce(&mut [u8]) -> smoltcp::Result, + F: FnOnce(&mut [u8]) -> R, { f(&mut self.buffer) } @@ -58,14 +58,14 @@ pub struct TxToken { } impl smoltcp::phy::TxToken for TxToken { - fn consume(self, _timestamp: Instant, len: usize, f: F) -> smoltcp::Result + fn consume(self, len: usize, f: F) -> R where - F: FnOnce(&mut [u8]) -> smoltcp::Result, + F: FnOnce(&mut [u8]) -> R, { let data = self.data.borrow_mut(); let mut buffer = data.buffer_pool.borrow_mut().get_buffer(); buffer.resize(len); - let res = f(&mut buffer)?; + let res = f(&mut buffer); let mut loopback = false; if let Ok(mut frame) = smoltcp::wire::EthernetFrame::new_checked(&mut buffer) { @@ -78,19 +78,19 @@ impl smoltcp::phy::TxToken for TxToken { if loopback { data.input_queue.borrow_mut().push_back(buffer.move_out()); } else { + // TODO: Handle error data.network_file .borrow_mut() - .write(&buffer) - .map_err(|_| smoltcp::Error::Dropped)?; + .write(&buffer); } - Ok(res) + res } } -impl<'a> smoltcp::phy::Device<'a> for NetworkDevice { - type RxToken = RxToken; - type TxToken = TxToken; +impl smoltcp::phy::Device for NetworkDevice { + type RxToken<'a> = RxToken; + type TxToken<'a> = TxToken; fn capabilities(&self) -> smoltcp::phy::DeviceCapabilities { let mut limits = smoltcp::phy::DeviceCapabilities::default(); @@ -99,7 +99,7 @@ impl<'a> smoltcp::phy::Device<'a> for NetworkDevice { limits } - fn receive(&'a mut self) -> Option<(Self::RxToken, Self::TxToken)> { + fn receive(&mut self, _timestamp: Instant) -> Option<(Self::RxToken<'_>, Self::TxToken<'_>)> { let data = self.data.borrow_mut(); let buffer = data.input_queue.borrow_mut().pop_front(); @@ -115,7 +115,7 @@ impl<'a> smoltcp::phy::Device<'a> for NetworkDevice { } } - fn transmit(&'a mut self) -> Option { + fn transmit(&mut self, _timestamp: Instant) -> Option> { Some(TxToken { data: Rc::clone(&self.data), }) diff --git a/src/smolnetd/main.rs b/src/smolnetd/main.rs index b359245ec3..b1b6ebb8ce 100644 --- a/src/smolnetd/main.rs +++ b/src/smolnetd/main.rs @@ -151,7 +151,7 @@ fn run(daemon: redox_daemon::Daemon) -> Result<()> { fn main() { redox_daemon::Daemon::new(move |daemon| { - logger::init_logger(); + logger::init_logger("smolnetd"); if let Err(err) = run(daemon) { error!("smoltcpd: {}", err); diff --git a/src/smolnetd/scheme/icmp.rs b/src/smolnetd/scheme/icmp.rs index cd65926f81..5ecd94fc8c 100644 --- a/src/smolnetd/scheme/icmp.rs +++ b/src/smolnetd/scheme/icmp.rs @@ -1,5 +1,6 @@ -use smoltcp::socket::{IcmpEndpoint, IcmpPacketMetadata, IcmpSocket, IcmpSocketBuffer, SocketHandle}; -use smoltcp::wire::{Icmpv4Packet, Icmpv4Repr, IpAddress, IpEndpoint}; +use smoltcp::socket::icmp::{Endpoint as IcmpEndpoint, PacketMetadata as IcmpPacketMetadata, Socket as IcmpSocket, PacketBuffer as IcmpSocketBuffer}; +use smoltcp::iface::SocketHandle; +use smoltcp::wire::{Icmpv4Packet, Icmpv4Repr, IpAddress, IpListenEndpoint}; use std::mem; use std::str; use syscall::{Error as SyscallError, Result as SyscallResult}; @@ -9,9 +10,9 @@ use byteorder::{ByteOrder, NetworkEndian}; use crate::device::NetworkDevice; use crate::port_set::PortSet; use super::socket::{DupResult, SchemeFile, SchemeSocket, SocketFile, SocketScheme}; -use super::{Smolnetd, SocketSet}; +use super::{Smolnetd, SocketSet, Interface}; -pub type IcmpScheme = SocketScheme>; +pub type IcmpScheme = SocketScheme>; enum IcmpSocketType { Echo, @@ -24,7 +25,7 @@ pub struct IcmpData { ident: u16, } -impl<'a, 'b> SchemeSocket for IcmpSocket<'a, 'b> { +impl<'a> SchemeSocket for IcmpSocket<'a> { type SchemeDataT = PortSet; type DataT = IcmpData; type SettingT = (); @@ -74,6 +75,7 @@ impl<'a, 'b> SchemeSocket for IcmpSocket<'a, 'b> { path: &str, _uid: u32, ident_set: &mut Self::SchemeDataT, + iface: &Interface ) -> SyscallResult<(SocketHandle, Self::DataT)> { use std::str::FromStr; @@ -101,7 +103,7 @@ impl<'a, 'b> SchemeSocket for IcmpSocket<'a, 'b> { ) ); let handle = socket_set.add(socket); - let mut icmp_socket = socket_set.get::(handle); + let icmp_socket = socket_set.get_mut::(handle); let ident = ident_set .get_port() .ok_or_else(|| SyscallError::new(syscall::EINVAL))?; @@ -133,12 +135,12 @@ impl<'a, 'b> SchemeSocket for IcmpSocket<'a, 'b> { ) ); let handle = socket_set.add(socket); - let mut icmp_socket = socket_set.get::(handle); + let icmp_socket = socket_set.get_mut::(handle); let ident = ident_set .get_port() .ok_or_else(|| SyscallError::new(syscall::EINVAL))?; icmp_socket - .bind(IcmpEndpoint::Udp(IpEndpoint::from(ident))) + .bind(IcmpEndpoint::Udp(IpListenEndpoint::from(ident))) .map_err(|_| syscall::Error::new(syscall::EINVAL))?; let socket_data = IcmpData { socket_type: IcmpSocketType::Udp, diff --git a/src/smolnetd/scheme/ip.rs b/src/smolnetd/scheme/ip.rs index b13cbc2720..4f0d0d3254 100644 --- a/src/smolnetd/scheme/ip.rs +++ b/src/smolnetd/scheme/ip.rs @@ -1,16 +1,17 @@ -use smoltcp::socket::{RawPacketMetadata, RawSocket, RawSocketBuffer, SocketHandle}; +use smoltcp::socket::raw::{PacketMetadata as RawPacketMetadata, Socket as RawSocket, PacketBuffer as RawSocketBuffer}; +use smoltcp::iface::SocketHandle; use smoltcp::wire::{IpProtocol, IpVersion}; use std::str; use syscall::{Error as SyscallError, Result as SyscallResult}; use syscall; use crate::device::NetworkDevice; -use super::{Smolnetd, SocketSet}; +use super::{Smolnetd, SocketSet, Interface}; use super::socket::{DupResult, SchemeFile, SchemeSocket, SocketFile, SocketScheme}; -pub type IpScheme = SocketScheme>; +pub type IpScheme = SocketScheme>; -impl<'a, 'b> SchemeSocket for RawSocket<'a, 'b> { +impl<'a> SchemeSocket for RawSocket<'a> { type SchemeDataT = (); type DataT = (); type SettingT = (); @@ -58,6 +59,7 @@ impl<'a, 'b> SchemeSocket for RawSocket<'a, 'b> { path: &str, uid: u32, _: &mut Self::SchemeDataT, + iface: &Interface ) -> SyscallResult<(SocketHandle, Self::DataT)> { if uid != 0 { return Err(SyscallError::new(syscall::EACCES)); diff --git a/src/smolnetd/scheme/mod.rs b/src/smolnetd/scheme/mod.rs index eab5942b29..fdf60b012c 100644 --- a/src/smolnetd/scheme/mod.rs +++ b/src/smolnetd/scheme/mod.rs @@ -1,12 +1,12 @@ use netutils::getcfg; use smoltcp; -use smoltcp::iface::{EthernetInterface, EthernetInterfaceBuilder, NeighborCache, Routes}; -use smoltcp::phy::EthernetTracer; -use smoltcp::socket::SocketSet as SmoltcpSocketSet; +use smoltcp::iface::{Interface as SmoltcpInterface, Routes, Config}; +use smoltcp::phy::Tracer; +use crate::scheme::smoltcp::iface::SocketSet as SmoltcpSocketSet; use smoltcp::time::{Duration, Instant}; -use smoltcp::wire::{EthernetAddress, IpAddress, IpCidr, IpEndpoint, Ipv4Address}; +use smoltcp::wire::{EthernetAddress, IpAddress, IpCidr, Ipv4Address, IpListenEndpoint, HardwareAddress}; use std::cell::RefCell; -use std::collections::{BTreeMap, VecDeque}; +use std::collections::VecDeque; use std::fs::File; use std::io::{self, Read, Write}; use std::mem::size_of; @@ -31,14 +31,15 @@ mod udp; mod icmp; mod netcfg; -type SocketSet = SmoltcpSocketSet<'static, 'static, 'static>; -type Interface = Rc>>>; +type SocketSet = SmoltcpSocketSet<'static>; +type Interface = Rc>; -const MAX_DURATION: Duration = Duration { millis: ::std::u64::MAX }; -const MIN_DURATION: Duration = Duration { millis: 0 }; +const MAX_DURATION: Duration = Duration::from_millis(u64::MAX); +const MIN_DURATION: Duration = Duration::from_millis(0); pub struct Smolnetd { network_file: Rc>, + network_device: Tracer, time_file: File, iface: Interface, @@ -58,8 +59,8 @@ pub struct Smolnetd { impl Smolnetd { const MAX_PACKET_SIZE: usize = 2048; const SOCKET_BUFFER_SIZE: usize = 128; //packets - const MIN_CHECK_TIMEOUT: Duration = Duration { millis: 10 }; - const MAX_CHECK_TIMEOUT: Duration = Duration { millis: 500 }; + const MIN_CHECK_TIMEOUT: Duration = Duration::from_millis(10); + const MAX_CHECK_TIMEOUT: Duration = Duration::from_millis(500); pub fn new( network_file: File, @@ -84,7 +85,7 @@ impl Smolnetd { let buffer_pool = Rc::new(RefCell::new(BufferPool::new(Self::MAX_PACKET_SIZE))); let input_queue = Rc::new(RefCell::new(VecDeque::new())); let network_file = Rc::new(RefCell::new(network_file)); - let network_device = EthernetTracer::new(NetworkDevice::new( + let mut network_device = Tracer::new(NetworkDevice::new( Rc::clone(&network_file), Rc::clone(&input_queue), hardware_addr, @@ -92,25 +93,23 @@ impl Smolnetd { ), |_timestamp, printer| { trace!("{}", printer) }); - let mut routes = Routes::new(BTreeMap::new()); - routes.add_default_ipv4_route(default_gw).expect("Failed to add default gateway"); - let iface = EthernetInterfaceBuilder::new(network_device) - .neighbor_cache(NeighborCache::new(BTreeMap::new())) - .ethernet_addr(hardware_addr) - .ip_addrs(protocol_addrs) - .routes(routes) - .finalize(); + let config = Config::new(HardwareAddress::Ethernet(hardware_addr)); + let mut iface = SmoltcpInterface::new(config, &mut network_device, Instant::now()); + iface.update_ip_addrs(|ip_addrs| ip_addrs.extend(protocol_addrs)); + iface.routes_mut().add_default_ipv4_route(default_gw).expect("Failed to add default gateway"); + let iface = Rc::new(RefCell::new(iface)); let socket_set = Rc::new(RefCell::new(SocketSet::new(vec![]))); Smolnetd { iface: Rc::clone(&iface), + network_device, socket_set: Rc::clone(&socket_set), timer: ::std::time::Instant::now(), time_file, - ip_scheme: IpScheme::new(Rc::clone(&socket_set), ip_file), - udp_scheme: UdpScheme::new(Rc::clone(&socket_set), udp_file), - tcp_scheme: TcpScheme::new(Rc::clone(&socket_set), tcp_file), - icmp_scheme: IcmpScheme::new(Rc::clone(&socket_set), icmp_file), + ip_scheme: IpScheme::new(Rc::clone(&iface), Rc::clone(&socket_set), ip_file), + udp_scheme: UdpScheme::new(Rc::clone(&iface), Rc::clone(&socket_set), udp_file), + tcp_scheme: TcpScheme::new(Rc::clone(&iface), Rc::clone(&socket_set), tcp_file), + icmp_scheme: IcmpScheme::new(Rc::clone(&iface), Rc::clone(&socket_set), icmp_file), netcfg_scheme: NetCfgScheme::new(Rc::clone(&iface), netcfg_file), input_queue, network_file, @@ -190,23 +189,22 @@ impl Smolnetd { break MIN_DURATION; } iter_limit -= 1; - match iface.poll(&mut socket_set, timestamp) { - Ok(_) | Err(smoltcp::Error::Unrecognized) => (), - Err(e) => { - error!("poll error: {}", e); - break MIN_DURATION; - } - } - match iface.poll_delay(&socket_set, timestamp) { - Some(Duration { millis: 0 }) => { } + + // TODO: Check what if the bool returned by poll can be useful + iface.poll(timestamp, &mut self.network_device, &mut socket_set); + + match iface.poll_delay(timestamp, &socket_set) { + Some(delay) if delay == Duration::ZERO => { } Some(delay) => { break ::std::cmp::min(MAX_DURATION, delay) } None => break MAX_DURATION - } + }; } }; + self.notify_sockets()?; + Ok(::std::cmp::min( ::std::cmp::max(Smolnetd::MIN_CHECK_TIMEOUT, timeout), Smolnetd::MAX_CHECK_TIMEOUT, @@ -257,17 +255,16 @@ fn post_fevent(scheme_file: &mut File, fd: usize, event: usize, data_len: usize) .map_err(|e| Error::from_io_error(e, "failed to post fevent")) } -fn parse_endpoint(socket: &str) -> IpEndpoint { +fn parse_endpoint(socket: &str) -> IpListenEndpoint { let mut socket_parts = socket.split(':'); - let host = IpAddress::Ipv4( - Ipv4Address::from_str(socket_parts.next().unwrap_or("")) - .unwrap_or_else(|_| Ipv4Address::new(0, 0, 0, 0)), - ); + let host = + Ipv4Address::from_str(socket_parts.next().unwrap_or("")).ok().filter(|addr| !addr.is_unspecified()).map(IpAddress::Ipv4); + let port = socket_parts .next() .unwrap_or("") .parse::() .unwrap_or(0); - IpEndpoint::new(host, port) + IpListenEndpoint{ addr: host, port} } diff --git a/src/smolnetd/scheme/netcfg/mod.rs b/src/smolnetd/scheme/netcfg/mod.rs index c64b310092..d41dee0a44 100644 --- a/src/smolnetd/scheme/netcfg/mod.rs +++ b/src/smolnetd/scheme/netcfg/mod.rs @@ -82,7 +82,7 @@ fn mk_root_node(iface: Interface, notifier: NotifierRef, dns_config: DNSConfigRe ro [iface] || { let mut gateway = None; iface.borrow_mut().routes_mut().update(|map| { - gateway = map.get(&gateway_cidr()).map(|route| route.via_router); + gateway = map.iter().find(|route| route.cidr == gateway_cidr()).map(|route| route.via_router) }); if let Some(ip) = gateway { format!("default via {}\n", ip) @@ -136,16 +136,17 @@ fn mk_root_node(iface: Interface, notifier: NotifierRef, dns_config: DNSConfigRe let mut iface = iface.borrow_mut(); let mut gateway = None; iface.routes_mut().update(|map| { - gateway = map.get(&gateway_cidr()).map(|route| route.via_router); + gateway = map.iter().find(|route| route.cidr == gateway_cidr()).map(|route| route.via_router) }); - if gateway != Some(IpAddress::Ipv4(default_gw)) { - return Err(SyscallError::new(syscall::EINVAL)); + match gateway { + None => Err(SyscallError::new(syscall::EINVAL)), + Some(addr) if addr != IpAddress::Ipv4(default_gw) => Err(SyscallError::new(syscall::EINVAL)), + Some(_) => { + iface.routes_mut().remove_default_ipv4_route(); + notifier.borrow_mut().schedule_notify("route/list"); + Ok(()) + } } - iface.routes_mut().update(|map| { - map.remove(&gateway_cidr()); - }); - notifier.borrow_mut().schedule_notify("route/list"); - Ok(()) } else { Err(SyscallError::new(syscall::EINVAL)) } @@ -157,7 +158,7 @@ fn mk_root_node(iface: Interface, notifier: NotifierRef, dns_config: DNSConfigRe "mac" => { rw [iface, notifier] (Option, None) || { - format!("{}\n", iface.borrow().ethernet_addr()) + format!("{}\n", iface.borrow().hardware_addr()) } |cur_value, line| { if cur_value.is_none() { @@ -174,7 +175,7 @@ fn mk_root_node(iface: Interface, notifier: NotifierRef, dns_config: DNSConfigRe } |cur_value| { if let Some(mac) = *cur_value { - iface.borrow_mut().set_ethernet_addr(mac); + iface.borrow_mut().set_hardware_addr(smoltcp::wire::HardwareAddress::Ethernet(mac)); notifier.borrow_mut().schedule_notify("ifaces/eth0/mac"); } Ok(()) @@ -208,7 +209,7 @@ fn mk_root_node(iface: Interface, notifier: NotifierRef, dns_config: DNSConfigRe let mut cidrs = vec![]; mem::swap(cur_value, &mut cidrs); iface.update_ip_addrs(|s| { - *s = From::from(cidrs); + *s = cidrs.into_iter().collect(); }); notifier.borrow_mut().schedule_notify("ifaces/eth0/addr/list"); } @@ -233,7 +234,7 @@ fn mk_root_node(iface: Interface, notifier: NotifierRef, dns_config: DNSConfigRe cidrs.insert(0, *cidr); } iface.update_ip_addrs(|s| { - *s = From::from(cidrs); + *s = cidrs.into_iter().collect(); }); notifier.borrow_mut().schedule_notify("ifaces/eth0/addr/list"); Ok(()) @@ -261,7 +262,7 @@ fn mk_root_node(iface: Interface, notifier: NotifierRef, dns_config: DNSConfigRe } } iface.update_ip_addrs(|s| { - *s = From::from(cidrs); + *s = cidrs.into_iter().collect(); }); notifier.borrow_mut().schedule_notify("ifaces/eth0/addr/list"); Ok(()) diff --git a/src/smolnetd/scheme/socket.rs b/src/smolnetd/scheme/socket.rs index b61ee1ce23..df7cbfe8f3 100644 --- a/src/smolnetd/scheme/socket.rs +++ b/src/smolnetd/scheme/socket.rs @@ -1,10 +1,11 @@ use std::cell::RefCell; use std::collections::BTreeMap; +use std::collections::btree_map::Entry; use std::fs::File; use std::io::{ErrorKind, Read, Write}; use std::marker::PhantomData; use std::mem; -use std::ops::Deref; +use std::ops::{Deref, SubAssign}; use std::ops::DerefMut; use std::rc::Rc; use std::str; @@ -15,7 +16,9 @@ use syscall::data::TimeSpec; use syscall::flag::{EVENT_READ, EVENT_WRITE}; use redox_netstack::error::{Error, Result}; -use smoltcp::socket::{AnySocket, SocketHandle}; +use smoltcp::socket::AnySocket; +use crate::scheme::smoltcp::iface::SocketHandle; +use super::Interface; use super::{post_fevent, SocketSet}; @@ -98,7 +101,7 @@ where } } - pub fn events(&mut self, socket_set: &mut SocketSet) -> usize where SocketT: AnySocket<'static, 'static> { + pub fn events(&mut self, socket_set: &mut SocketSet) -> usize where SocketT: AnySocket<'static> { let mut revents = 0; if let &mut SchemeFile::Socket(SocketFile { socket_handle, @@ -170,6 +173,7 @@ where path: &str, uid: u32, data: &mut Self::SchemeDataT, + iface: &Interface ) -> SyscallResult<(SocketHandle, Self::DataT)>; fn close_file(&self, file: &SchemeFile, data: &mut Self::SchemeDataT) -> SyscallResult<()>; @@ -190,11 +194,13 @@ where pub struct SocketScheme where - SocketT: SchemeSocket + AnySocket<'static, 'static>, + SocketT: SchemeSocket + AnySocket<'static>, { next_fd: usize, nulls: BTreeMap, files: BTreeMap>, + ref_counts: BTreeMap, + iface: Interface, socket_set: Rc>, scheme_file: File, wait_queue: WaitQueue, @@ -204,13 +210,15 @@ where impl SocketScheme where - SocketT: SchemeSocket + AnySocket<'static, 'static>, + SocketT: SchemeSocket + AnySocket<'static>, { - pub fn new(socket_set: Rc>, scheme_file: File) -> SocketScheme { + pub fn new(iface: Interface, socket_set: Rc>, scheme_file: File) -> SocketScheme { SocketScheme { next_fd: 1, nulls: BTreeMap::new(), + iface, files: BTreeMap::new(), + ref_counts: BTreeMap::new(), socket_set, scheme_data: SocketT::new_scheme_data(), scheme_file, @@ -424,7 +432,7 @@ where } Setting::Ttl => if let Some(hop_limit) = buf.get(0) { let mut socket_set = self.socket_set.borrow_mut(); - let mut socket = socket_set.get::(file.socket_handle); + let socket = socket_set.get_mut::(file.socket_handle); socket.set_hop_limit(*hop_limit); Ok(1) } else { @@ -437,7 +445,7 @@ where impl syscall::SchemeBlockMut for SocketScheme where - SocketT: SchemeSocket + AnySocket<'static, 'static>, + SocketT: SchemeSocket + AnySocket<'static>, { fn open(&mut self, path: &str, flags: usize, uid: u32, _gid: u32) -> SyscallResult> { if path.is_empty() { @@ -459,6 +467,7 @@ where path, uid, &mut self.scheme_data, + &self.iface )?; let file = SchemeFile::Socket(SocketFile { @@ -475,6 +484,7 @@ where let id = self.next_fd; self.next_fd += 1; + self.ref_counts.insert(socket_handle, 1); self.files.insert(id, file); Ok(Some(id)) @@ -506,9 +516,29 @@ where }| a != fd, ); - socket_set.release(socket_handle); - //TODO: removing sockets in release should make prune unnecessary - socket_set.prune(); + let remove = match self.ref_counts.entry(socket_handle) { + Entry::Vacant(_) => { + warn!("Closing a socket_handle with no ref"); + true + }, + Entry::Occupied(mut e) => if *e.get() == 0 { + warn!("Closing a socket_handle with no ref"); + e.remove(); + true + } else { + *e.get_mut() -= 1; + if *e.get() == 0 { + e.remove(); + true + } else { + false + } + }, + }; + + if remove { + socket_set.remove(socket_handle); + } Ok(Some(0)) } @@ -524,8 +554,8 @@ where } SchemeFile::Socket(ref mut file) => { let mut socket_set = self.socket_set.borrow_mut(); - let mut socket = socket_set.get::(file.socket_handle); - return SocketT::write_buf(&mut socket, file, buf); + let socket = socket_set.get_mut::(file.socket_handle); + return SocketT::write_buf(socket, file, buf); } } }; @@ -543,8 +573,8 @@ where } SchemeFile::Socket(ref mut file) => { let mut socket_set = self.socket_set.borrow_mut(); - let mut socket = socket_set.get::(file.socket_handle); - return SocketT::read_buf(&mut socket, file, buf); + let socket = socket_set.get_mut::(file.socket_handle); + return SocketT::read_buf(socket, file, buf); } } }; @@ -609,10 +639,10 @@ where file.socket_handle = socket_handle; file.data = data; } else { - self.socket_set.borrow_mut().retain(file.socket_handle()); + *self.ref_counts.entry(file.socket_handle()).or_insert(0) += 1; } } else { - self.socket_set.borrow_mut().retain(file.socket_handle()); + *self.ref_counts.entry(file.socket_handle()).or_insert(0) += 1; } new_handle }; diff --git a/src/smolnetd/scheme/tcp.rs b/src/smolnetd/scheme/tcp.rs index 200ba42aa4..65bcfb190c 100644 --- a/src/smolnetd/scheme/tcp.rs +++ b/src/smolnetd/scheme/tcp.rs @@ -1,11 +1,13 @@ -use smoltcp::socket::{SocketHandle, TcpSocket, TcpSocketBuffer}; +use smoltcp::iface::SocketHandle; +use smoltcp::socket::tcp::{Socket as TcpSocket, SocketBuffer as TcpSocketBuffer}; +use smoltcp::wire::IpEndpoint; use std::str; -use syscall::{Error as SyscallError, Result as SyscallResult}; use syscall; +use syscall::{Error as SyscallError, Result as SyscallResult}; -use crate::port_set::PortSet; use super::socket::{DupResult, SchemeFile, SchemeSocket, SocketFile, SocketScheme}; -use super::{parse_endpoint, SocketSet}; +use super::{parse_endpoint, SocketSet, Interface}; +use crate::port_set::PortSet; pub type TcpScheme = SocketScheme>; @@ -59,6 +61,7 @@ impl<'a> SchemeSocket for TcpSocket<'a> { path: &str, uid: u32, port_set: &mut Self::SchemeDataT, + iface: &Interface ) -> SyscallResult<(SocketHandle, Self::DataT)> { trace!("TCP open {}", path); let mut parts = path.split('/'); @@ -85,12 +88,12 @@ impl<'a> SchemeSocket for TcpSocket<'a> { let socket_handle = socket_set.add(socket); - let mut tcp_socket = socket_set.get::(socket_handle); + let tcp_socket = socket_set.get_mut::(socket_handle); if remote_endpoint.is_specified() { trace!("Connecting tcp {} {}", local_endpoint, remote_endpoint); tcp_socket - .connect(remote_endpoint, local_endpoint) + .connect(iface.borrow_mut().context(), IpEndpoint::new(remote_endpoint.addr.unwrap(), remote_endpoint.port), local_endpoint) .expect("Can't connect tcp socket "); } else { trace!("Listening tcp {}", local_endpoint); @@ -108,7 +111,9 @@ impl<'a> SchemeSocket for TcpSocket<'a> { port_set: &mut Self::SchemeDataT, ) -> SyscallResult<()> { if let SchemeFile::Socket(_) = *file { - port_set.release_port(self.local_endpoint().port); + if let Some(endpoint) = self.local_endpoint() { + port_set.release_port(endpoint.port); + } } Ok(()) } @@ -163,34 +168,43 @@ impl<'a> SchemeSocket for TcpSocket<'a> { }; let file = match path { - "listen" => if let SchemeFile::Socket(ref tcp_handle) = *file { - if !is_active { - if tcp_handle.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { - return Err(SyscallError::new(syscall::EAGAIN)); - } else { - return Ok(None); + "listen" => { + if let SchemeFile::Socket(ref tcp_handle) = *file { + if !is_active { + if tcp_handle.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { + return Err(SyscallError::new(syscall::EAGAIN)); + } else { + return Ok(None); + } } - } - trace!("TCP creating new listening socket"); - let new_handle = SchemeFile::Socket(tcp_handle.clone_with_data(())); + trace!("TCP creating new listening socket"); + let new_handle = SchemeFile::Socket(tcp_handle.clone_with_data(())); - let rx_packets = vec![0; 0xffff]; - let tx_packets = vec![0; 0xffff]; - let rx_buffer = TcpSocketBuffer::new(rx_packets); - let tx_buffer = TcpSocketBuffer::new(tx_packets); - let socket = TcpSocket::new(rx_buffer, tx_buffer); - let new_socket_handle = socket_set.add(socket); - { - let mut tcp_socket = socket_set.get::(new_socket_handle); - tcp_socket - .listen(local_endpoint) - .expect("Can't listen on local endpoint"); + let rx_packets = vec![0; 0xffff]; + let tx_packets = vec![0; 0xffff]; + let rx_buffer = TcpSocketBuffer::new(rx_packets); + let tx_buffer = TcpSocketBuffer::new(tx_packets); + let socket = TcpSocket::new(rx_buffer, tx_buffer); + let new_socket_handle = socket_set.add(socket); + { + let tcp_socket = socket_set.get_mut::(new_socket_handle); + tcp_socket + .listen( + local_endpoint + .expect("Socket was active so local endpoint must be set"), + ) + .expect("Can't listen on local endpoint"); + } + port_set.acquire_port( + local_endpoint + .expect("Socket was active so local endpoint must be set") + .port, + ); + return Ok(Some((new_handle, Some((new_socket_handle, ()))))); + } else { + return Err(SyscallError::new(syscall::EBADF)); } - port_set.acquire_port(local_endpoint.port); - return Ok(Some((new_handle, Some((new_socket_handle, ()))))); - } else { - return Err(SyscallError::new(syscall::EBADF)); - }, + } _ => { trace!("TCP dup unknown {}", path); if let SchemeFile::Socket(ref tcp_handle) = *file { @@ -202,14 +216,21 @@ impl<'a> SchemeSocket for TcpSocket<'a> { }; if let SchemeFile::Socket(_) = file { - port_set.acquire_port(local_endpoint.port); + if let Some(local_endpoint) = local_endpoint { + port_set.acquire_port(local_endpoint.port); + } } Ok(Some((file, None))) } fn fpath(&self, _: &SchemeFile, buf: &mut [u8]) -> SyscallResult { - let path = format!("tcp:{}/{}", self.remote_endpoint(), self.local_endpoint()); + let path = match (self.remote_endpoint(), self.local_endpoint()) { + (Some(remote_endpoint), Some(local_endpoint)) => format!("tcp:{}/{}", remote_endpoint, local_endpoint), + (Some(remote_endpoint), None) => format!("tcp:{}/none", remote_endpoint), + (None, Some(local_endpoint)) => format!("tcp:none/{}", local_endpoint), + (None, None) => "tcp:none/none".into(), + }; let path = path.as_bytes(); let mut i = 0; diff --git a/src/smolnetd/scheme/udp.rs b/src/smolnetd/scheme/udp.rs index 646821f625..4f0ce8ccd8 100644 --- a/src/smolnetd/scheme/udp.rs +++ b/src/smolnetd/scheme/udp.rs @@ -1,5 +1,6 @@ -use smoltcp::socket::{SocketHandle, UdpPacketMetadata, UdpSocket, UdpSocketBuffer}; -use smoltcp::wire::IpEndpoint; +use smoltcp::socket::udp::{PacketMetadata as UdpPacketMetadata, Socket as UdpSocket, PacketBuffer as UdpSocketBuffer}; +use smoltcp::iface::SocketHandle; +use smoltcp::wire::{IpEndpoint, IpListenEndpoint}; use std::str; use syscall::{Error as SyscallError, Result as SyscallResult}; use syscall; @@ -7,13 +8,13 @@ use syscall; use crate::device::NetworkDevice; use crate::port_set::PortSet; use super::socket::{DupResult, SchemeFile, SchemeSocket, SocketFile, SocketScheme}; -use super::{parse_endpoint, Smolnetd, SocketSet}; +use super::{parse_endpoint, Smolnetd, SocketSet, Interface}; -pub type UdpScheme = SocketScheme>; +pub type UdpScheme = SocketScheme>; -impl<'a, 'b> SchemeSocket for UdpSocket<'a, 'b> { +impl<'a> SchemeSocket for UdpSocket<'a> { type SchemeDataT = PortSet; - type DataT = IpEndpoint; + type DataT = IpListenEndpoint; type SettingT = (); fn new_scheme_data() -> Self::SchemeDataT { @@ -61,6 +62,7 @@ impl<'a, 'b> SchemeSocket for UdpSocket<'a, 'b> { path: &str, uid: u32, port_set: &mut Self::SchemeDataT, + _iface: &Interface ) -> SyscallResult<(SocketHandle, Self::DataT)> { let mut parts = path.split('/'); let remote_endpoint = parse_endpoint(parts.next().unwrap_or("")); @@ -90,11 +92,12 @@ impl<'a, 'b> SchemeSocket for UdpSocket<'a, 'b> { let socket_handle = socket_set.add(udp_socket); - let mut udp_socket = socket_set.get::(socket_handle); + let udp_socket = socket_set.get_mut::(socket_handle); udp_socket .bind(local_endpoint) .expect("Can't bind udp socket to local endpoint"); + Ok((socket_handle, remote_endpoint)) } @@ -118,7 +121,9 @@ impl<'a, 'b> SchemeSocket for UdpSocket<'a, 'b> { return Err(SyscallError::new(syscall::EADDRNOTAVAIL)); } if self.can_send() { - self.send_slice(buf, file.data).expect("Can't send slice"); + let endpoint = file.data; + let endpoint = IpEndpoint::new(endpoint.addr.expect("If we can send, this should be specified"), endpoint.port); + self.send_slice(buf, endpoint).expect("Can't send slice"); Ok(Some(buf.len())) } else if file.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { Err(SyscallError::new(syscall::EAGAIN)) From d47cdbf1fec6372244f21611020cc8d08404ab8f Mon Sep 17 00:00:00 2001 From: Gartox Date: Tue, 29 Aug 2023 17:24:25 +0200 Subject: [PATCH 121/155] Fix TCP listening endpoint, fpath formatting, port release while listening: Now TCPListenEndpoint is stored in the SchemeFile because the TcpSocket::endpoint() only store endpoints for connected sockets, not listening ones --- src/smolnetd/scheme/socket.rs | 215 ++++++++++++++++++++++------------ src/smolnetd/scheme/tcp.rs | 81 +++++++++---- 2 files changed, 204 insertions(+), 92 deletions(-) diff --git a/src/smolnetd/scheme/socket.rs b/src/smolnetd/scheme/socket.rs index df7cbfe8f3..c40dda1406 100644 --- a/src/smolnetd/scheme/socket.rs +++ b/src/smolnetd/scheme/socket.rs @@ -1,24 +1,27 @@ use std::cell::RefCell; -use std::collections::BTreeMap; use std::collections::btree_map::Entry; +use std::collections::BTreeMap; use std::fs::File; use std::io::{ErrorKind, Read, Write}; use std::marker::PhantomData; use std::mem; -use std::ops::{Deref, SubAssign}; +use std::ops::Deref; use std::ops::DerefMut; use std::rc::Rc; use std::str; use syscall; -use syscall::{Error as SyscallError, EventFlags as SyscallEventFlags, Packet as SyscallPacket, Result as SyscallResult, SchemeBlockMut}; use syscall::data::TimeSpec; use syscall::flag::{EVENT_READ, EVENT_WRITE}; +use syscall::{ + Error as SyscallError, EventFlags as SyscallEventFlags, Packet as SyscallPacket, + Result as SyscallResult, SchemeBlockMut, +}; +use super::Interface; +use crate::scheme::smoltcp::iface::SocketHandle; use redox_netstack::error::{Error, Result}; use smoltcp::socket::AnySocket; -use crate::scheme::smoltcp::iface::SocketHandle; -use super::Interface; use super::{post_fevent, SocketSet}; @@ -73,7 +76,8 @@ enum Setting { Ttl, ReadTimeout, WriteTimeout, - #[allow(dead_code)] Other(SettingT), + #[allow(dead_code)] + Other(SettingT), } pub struct SettingFile { @@ -101,7 +105,10 @@ where } } - pub fn events(&mut self, socket_set: &mut SocketSet) -> usize where SocketT: AnySocket<'static> { + pub fn events(&mut self, socket_set: &mut SocketSet) -> usize + where + SocketT: AnySocket<'static>, + { let mut revents = 0; if let &mut SchemeFile::Socket(SocketFile { socket_handle, @@ -113,7 +120,9 @@ where { let socket = socket_set.get::(socket_handle); - if events & syscall::EVENT_READ.bits() == syscall::EVENT_READ.bits() && (socket.can_recv() || !socket.may_recv()) { + if events & syscall::EVENT_READ.bits() == syscall::EVENT_READ.bits() + && (socket.can_recv() || !socket.may_recv()) + { if !*read_notified { *read_notified = true; revents |= EVENT_READ.bits(); @@ -122,7 +131,9 @@ where *read_notified = false; } - if events & syscall::EVENT_WRITE.bits() == syscall::EVENT_WRITE.bits() && socket.can_send() { + if events & syscall::EVENT_WRITE.bits() == syscall::EVENT_WRITE.bits() + && socket.can_send() + { if !*write_notified { *write_notified = true; revents |= EVENT_WRITE.bits(); @@ -165,22 +176,42 @@ where fn hop_limit(&self) -> u8; fn set_hop_limit(&mut self, hop_limit: u8); - fn get_setting(file: &SocketFile, setting: Self::SettingT, buf: &mut [u8]) -> SyscallResult; - fn set_setting(file: &mut SocketFile, setting: Self::SettingT, buf: &[u8]) -> SyscallResult; + fn get_setting( + file: &SocketFile, + setting: Self::SettingT, + buf: &mut [u8], + ) -> SyscallResult; + fn set_setting( + file: &mut SocketFile, + setting: Self::SettingT, + buf: &[u8], + ) -> SyscallResult; fn new_socket( sockets: &mut SocketSet, path: &str, uid: u32, data: &mut Self::SchemeDataT, - iface: &Interface + iface: &Interface, ) -> SyscallResult<(SocketHandle, Self::DataT)>; - fn close_file(&self, file: &SchemeFile, data: &mut Self::SchemeDataT) -> SyscallResult<()>; + fn close_file( + &self, + file: &SchemeFile, + data: &mut Self::SchemeDataT, + ) -> SyscallResult<()>; - fn write_buf(&mut self, file: &mut SocketFile, buf: &[u8]) -> SyscallResult>; + fn write_buf( + &mut self, + file: &mut SocketFile, + buf: &[u8], + ) -> SyscallResult>; - fn read_buf(&mut self, file: &mut SocketFile, buf: &mut [u8]) -> SyscallResult>; + fn read_buf( + &mut self, + file: &mut SocketFile, + buf: &mut [u8], + ) -> SyscallResult>; fn fpath(&self, file: &SchemeFile, buf: &mut [u8]) -> SyscallResult; @@ -212,7 +243,11 @@ impl SocketScheme where SocketT: SchemeSocket + AnySocket<'static>, { - pub fn new(iface: Interface, socket_set: Rc>, scheme_file: File) -> SocketScheme { + pub fn new( + iface: Interface, + socket_set: Rc>, + scheme_file: File, + ) -> SocketScheme { SocketScheme { next_fd: 1, nulls: BTreeMap::new(), @@ -234,12 +269,14 @@ where Ok(0) => { //TODO: Cleanup must occur break Some(()); - }, + } Ok(_) => (), - Err(err) => if err.kind() == ErrorKind::WouldBlock { - break None; - } else { - return Err(Error::from(err)); + Err(err) => { + if err.kind() == ErrorKind::WouldBlock { + break None; + } else { + return Err(Error::from(err)); + } } } if let Some(a) = self.handle(&mut packet) { @@ -252,7 +289,7 @@ where until: timeout, packet, }); - }, + } Err(err) => { packet.a = (-err.errno) as usize; self.scheme_file.write_all(&packet)?; @@ -301,7 +338,7 @@ where self.wait_queue.remove(i); packet.a = (-syscall::ETIMEDOUT) as usize; self.scheme_file.write_all(&packet)?; - }, + } _ => { i += 1; } @@ -315,15 +352,13 @@ where fn handle_block(&mut self, packet: &mut SyscallPacket) -> SyscallResult> { let fd = packet.b; let (read_timeout, write_timeout) = { - let file = self.files + let file = self + .files .get(&fd) .ok_or_else(|| SyscallError::new(syscall::EBADF))?; if let SchemeFile::Socket(ref scheme_file) = *file { - Ok(( - scheme_file.read_timeout, - scheme_file.write_timeout, - )) + Ok((scheme_file.read_timeout, scheme_file.write_timeout)) } else { Err(SyscallError::new(syscall::EBADF)) } @@ -350,7 +385,8 @@ where setting: Setting, buf: &mut [u8], ) -> SyscallResult { - let file = self.files + let file = self + .files .get_mut(&fd) .ok_or_else(|| SyscallError::new(syscall::EBADF))?; let file = match *file { @@ -362,14 +398,16 @@ where match setting { Setting::Other(setting) => SocketT::get_setting(file, setting, buf), - Setting::Ttl => if let Some(hop_limit) = buf.get_mut(0) { - let mut socket_set = self.socket_set.borrow_mut(); - let socket = socket_set.get::(file.socket_handle); - *hop_limit = socket.hop_limit(); - Ok(1) - } else { - Err(SyscallError::new(syscall::EIO)) - }, + Setting::Ttl => { + if let Some(hop_limit) = buf.get_mut(0) { + let socket_set = self.socket_set.borrow(); + let socket = socket_set.get::(file.socket_handle); + *hop_limit = socket.hop_limit(); + Ok(1) + } else { + Err(SyscallError::new(syscall::EIO)) + } + } Setting::ReadTimeout | Setting::WriteTimeout => { let timespec = match (setting, file.read_timeout, file.write_timeout) { (Setting::ReadTimeout, Some(read_timeout), _) => read_timeout, @@ -397,7 +435,8 @@ where setting: Setting, buf: &[u8], ) -> SyscallResult { - let file = self.files + let file = self + .files .get_mut(&fd) .ok_or_else(|| SyscallError::new(syscall::EBADF))?; let file = match *file { @@ -430,14 +469,16 @@ where }; Ok(count) } - Setting::Ttl => if let Some(hop_limit) = buf.get(0) { - let mut socket_set = self.socket_set.borrow_mut(); - let socket = socket_set.get_mut::(file.socket_handle); - socket.set_hop_limit(*hop_limit); - Ok(1) - } else { - Err(SyscallError::new(syscall::EIO)) - }, + Setting::Ttl => { + if let Some(hop_limit) = buf.get(0) { + let mut socket_set = self.socket_set.borrow_mut(); + let socket = socket_set.get_mut::(file.socket_handle); + socket.set_hop_limit(*hop_limit); + Ok(1) + } else { + Err(SyscallError::new(syscall::EIO)) + } + } Setting::Other(setting) => SocketT::set_setting(file, setting, buf), } } @@ -447,7 +488,13 @@ impl syscall::SchemeBlockMut for SocketScheme where SocketT: SchemeSocket + AnySocket<'static>, { - fn open(&mut self, path: &str, flags: usize, uid: u32, _gid: u32) -> SyscallResult> { + fn open( + &mut self, + path: &str, + flags: usize, + uid: u32, + _gid: u32, + ) -> SyscallResult> { if path.is_empty() { let null = NullFile { flags, @@ -467,7 +514,7 @@ where path, uid, &mut self.scheme_data, - &self.iface + &self.iface, )?; let file = SchemeFile::Socket(SocketFile { @@ -497,7 +544,8 @@ where } let socket_handle = { - let file = self.files + let file = self + .files .get(&fd) .ok_or_else(|| SyscallError::new(syscall::EBADF))?; file.socket_handle() @@ -520,20 +568,22 @@ where Entry::Vacant(_) => { warn!("Closing a socket_handle with no ref"); true - }, - Entry::Occupied(mut e) => if *e.get() == 0 { - warn!("Closing a socket_handle with no ref"); - e.remove(); - true - } else { - *e.get_mut() -= 1; + } + Entry::Occupied(mut e) => { if *e.get() == 0 { + warn!("Closing a socket_handle with no ref"); e.remove(); true } else { - false + *e.get_mut() -= 1; + if *e.get() == 0 { + e.remove(); + true + } else { + false + } } - }, + } }; if remove { @@ -544,7 +594,8 @@ where fn write(&mut self, fd: usize, buf: &[u8]) -> SyscallResult> { let (fd, setting) = { - let file = self.files + let file = self + .files .get_mut(&fd) .ok_or_else(|| SyscallError::new(syscall::EBADF))?; @@ -564,7 +615,8 @@ where fn read(&mut self, fd: usize, buf: &mut [u8]) -> SyscallResult> { let (fd, setting) = { - let file = self.files + let file = self + .files .get_mut(&fd) .ok_or_else(|| SyscallError::new(syscall::EBADF))?; match *file { @@ -584,7 +636,8 @@ where fn dup(&mut self, fd: usize, buf: &[u8]) -> SyscallResult> { let path = str::from_utf8(buf).or_else(|_| Err(SyscallError::new(syscall::EINVAL)))?; - if let Some((flags, uid, gid)) = self.nulls + if let Some((flags, uid, gid)) = self + .nulls .get(&fd) .map(|null| (null.flags, null.uid, null.gid)) { @@ -592,7 +645,8 @@ where } let new_file = { - let file = self.files + let file = self + .files .get_mut(&fd) .ok_or_else(|| SyscallError::new(syscall::EBADF))?; @@ -636,14 +690,23 @@ where if let Some((socket_handle, data)) = update_with { if let SchemeFile::Socket(ref mut file) = *file { + // We replace the socket_handle pointed by file so update the ref_counts + // accordingly + self.ref_counts + .entry(file.socket_handle) + .and_modify(|e| *e = e.saturating_sub(1)) + .or_insert(0); + + *self.ref_counts.entry(socket_handle).or_insert(0) += 1; + file.socket_handle = socket_handle; file.data = data; - } else { - *self.ref_counts.entry(file.socket_handle()).or_insert(0) += 1; } - } else { - *self.ref_counts.entry(file.socket_handle()).or_insert(0) += 1; } + *self + .ref_counts + .entry(new_handle.socket_handle()) + .or_insert(0) += 1; new_handle }; @@ -654,8 +717,13 @@ where Ok(Some(id)) } - fn fevent(&mut self, fd: usize, events: SyscallEventFlags) -> SyscallResult> { - let file = self.files + fn fevent( + &mut self, + fd: usize, + events: SyscallEventFlags, + ) -> SyscallResult> { + let file = self + .files .get_mut(&fd) .ok_or_else(|| SyscallError::new(syscall::EBADF))?; match *file { @@ -673,7 +741,8 @@ where fn fsync(&mut self, fd: usize) -> SyscallResult> { { - let _file = self.files + let _file = self + .files .get_mut(&fd) .ok_or_else(|| SyscallError::new(syscall::EBADF))?; } @@ -683,11 +752,12 @@ where } fn fpath(&mut self, fd: usize, buf: &mut [u8]) -> SyscallResult> { - let file = self.files + let file = self + .files .get_mut(&fd) .ok_or_else(|| SyscallError::new(syscall::EBADF))?; - let mut socket_set = self.socket_set.borrow_mut(); + let socket_set = self.socket_set.borrow(); let socket = socket_set.get::(file.socket_handle()); socket.fpath(file, buf).map(Some) @@ -704,7 +774,8 @@ where _ => Err(SyscallError::new(syscall::EINVAL)), } } else { - let file = self.files + let file = self + .files .get_mut(&fd) .ok_or_else(|| SyscallError::new(syscall::EBADF))?; diff --git a/src/smolnetd/scheme/tcp.rs b/src/smolnetd/scheme/tcp.rs index 65bcfb190c..e5cf327dfe 100644 --- a/src/smolnetd/scheme/tcp.rs +++ b/src/smolnetd/scheme/tcp.rs @@ -1,19 +1,20 @@ use smoltcp::iface::SocketHandle; use smoltcp::socket::tcp::{Socket as TcpSocket, SocketBuffer as TcpSocketBuffer}; -use smoltcp::wire::IpEndpoint; +use smoltcp::wire::{IpEndpoint, IpListenEndpoint}; +use std::fmt::Write; use std::str; use syscall; use syscall::{Error as SyscallError, Result as SyscallResult}; use super::socket::{DupResult, SchemeFile, SchemeSocket, SocketFile, SocketScheme}; -use super::{parse_endpoint, SocketSet, Interface}; +use super::{parse_endpoint, Interface, SocketSet}; use crate::port_set::PortSet; pub type TcpScheme = SocketScheme>; impl<'a> SchemeSocket for TcpSocket<'a> { type SchemeDataT = PortSet; - type DataT = (); + type DataT = Option; type SettingT = (); fn new_scheme_data() -> Self::SchemeDataT { @@ -61,7 +62,7 @@ impl<'a> SchemeSocket for TcpSocket<'a> { path: &str, uid: u32, port_set: &mut Self::SchemeDataT, - iface: &Interface + iface: &Interface, ) -> SyscallResult<(SocketHandle, Self::DataT)> { trace!("TCP open {}", path); let mut parts = path.split('/'); @@ -90,19 +91,25 @@ impl<'a> SchemeSocket for TcpSocket<'a> { let tcp_socket = socket_set.get_mut::(socket_handle); - if remote_endpoint.is_specified() { + let listen_enpoint = if remote_endpoint.is_specified() { trace!("Connecting tcp {} {}", local_endpoint, remote_endpoint); tcp_socket - .connect(iface.borrow_mut().context(), IpEndpoint::new(remote_endpoint.addr.unwrap(), remote_endpoint.port), local_endpoint) + .connect( + iface.borrow_mut().context(), + IpEndpoint::new(remote_endpoint.addr.unwrap(), remote_endpoint.port), + local_endpoint, + ) .expect("Can't connect tcp socket "); + None } else { trace!("Listening tcp {}", local_endpoint); tcp_socket .listen(local_endpoint) .expect("Can't listen on local endpoint"); - } + Some(local_endpoint) + }; - Ok((socket_handle, ())) + Ok((socket_handle, listen_enpoint)) } fn close_file( @@ -110,8 +117,12 @@ impl<'a> SchemeSocket for TcpSocket<'a> { file: &SchemeFile, port_set: &mut Self::SchemeDataT, ) -> SyscallResult<()> { - if let SchemeFile::Socket(_) = *file { + if let SchemeFile::Socket(SocketFile { data, .. }) = *file { if let Some(endpoint) = self.local_endpoint() { + // Socket was connected on some port + port_set.release_port(endpoint.port); + } else if let Some(endpoint) = data { + // Socket was listening on some port port_set.release_port(endpoint.port); } } @@ -170,7 +181,13 @@ impl<'a> SchemeSocket for TcpSocket<'a> { let file = match path { "listen" => { if let SchemeFile::Socket(ref tcp_handle) = *file { + let Some(listen_enpoint) = tcp_handle.data else { + // This socket is not listening so we can't accept a connection + return Err(SyscallError::new(syscall::EINVAL)); + }; + if !is_active { + // Socket listening but no connection received if tcp_handle.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { return Err(SyscallError::new(syscall::EAGAIN)); } else { @@ -178,8 +195,11 @@ impl<'a> SchemeSocket for TcpSocket<'a> { } } trace!("TCP creating new listening socket"); - let new_handle = SchemeFile::Socket(tcp_handle.clone_with_data(())); + // We pass None as data because this new handle is to the active connection so + // not a listening socket + let new_handle = SchemeFile::Socket(tcp_handle.clone_with_data(None)); + // Creating a socket to continue listening let rx_packets = vec![0; 0xffff]; let tx_packets = vec![0; 0xffff]; let rx_buffer = TcpSocketBuffer::new(rx_packets); @@ -195,12 +215,16 @@ impl<'a> SchemeSocket for TcpSocket<'a> { ) .expect("Can't listen on local endpoint"); } + // We got a new connection to the socket so acquire the port port_set.acquire_port( local_endpoint .expect("Socket was active so local endpoint must be set") .port, ); - return Ok(Some((new_handle, Some((new_socket_handle, ()))))); + return Ok(Some(( + new_handle, + Some((new_socket_handle, Some(listen_enpoint))), + ))); } else { return Err(SyscallError::new(syscall::EBADF)); } @@ -208,9 +232,9 @@ impl<'a> SchemeSocket for TcpSocket<'a> { _ => { trace!("TCP dup unknown {}", path); if let SchemeFile::Socket(ref tcp_handle) = *file { - SchemeFile::Socket(tcp_handle.clone_with_data(())) + SchemeFile::Socket(tcp_handle.clone_with_data(tcp_handle.data)) } else { - SchemeFile::Socket(SocketFile::new_with_data(socket_handle, ())) + SchemeFile::Socket(SocketFile::new_with_data(socket_handle, None)) } } }; @@ -224,13 +248,30 @@ impl<'a> SchemeSocket for TcpSocket<'a> { Ok(Some((file, None))) } - fn fpath(&self, _: &SchemeFile, buf: &mut [u8]) -> SyscallResult { - let path = match (self.remote_endpoint(), self.local_endpoint()) { - (Some(remote_endpoint), Some(local_endpoint)) => format!("tcp:{}/{}", remote_endpoint, local_endpoint), - (Some(remote_endpoint), None) => format!("tcp:{}/none", remote_endpoint), - (None, Some(local_endpoint)) => format!("tcp:none/{}", local_endpoint), - (None, None) => "tcp:none/none".into(), - }; + fn fpath(&self, file: &SchemeFile, buf: &mut [u8]) -> SyscallResult { + let unspecified = "0.0.0.0:0"; + let mut path = String::from("tcp:"); + match self.remote_endpoint() { + Some(endpoint) => write!(&mut path, "{}", endpoint).unwrap(), + None => path.push_str(unspecified), + } + path.push('/'); + match (self.local_endpoint(), file) { + (Some(endpoint), _) => write!(&mut path, "{}", endpoint).unwrap(), + ( + None, + SchemeFile::Socket(SocketFile { + data: Some(endpoint), + .. + }), + ) => if endpoint.is_specified() { + write!(&mut path, "{}", endpoint).unwrap() + } else { + write!(&mut path, "0.0.0.0:{}", endpoint.port).unwrap() + }, + _ => path.push_str(unspecified), + } + trace!("fpath: {}", path); let path = path.as_bytes(); let mut i = 0; From 0b2b4e41c326c409eee39207b9c8f72c28ccb525 Mon Sep 17 00:00:00 2001 From: Gartox Date: Mon, 4 Sep 2023 10:11:02 +0200 Subject: [PATCH 122/155] Add support for multiple interfaces - Smoltcp now talk to a IP device that does the routing - Add RouteTable - Add trait LinkDevice representing devices (eth0, loopback...) - Remove old device --- Cargo.lock | 532 +++++++++++++++++++++++------ Cargo.toml | 5 +- src/smolnetd/device.rs | 123 ------- src/smolnetd/link/ethernet.rs | 355 +++++++++++++++++++ src/smolnetd/link/loopback.rs | 45 +++ src/smolnetd/link/mod.rs | 57 ++++ src/smolnetd/main.rs | 12 +- src/smolnetd/router/mod.rs | 187 ++++++++++ src/smolnetd/router/route_table.rs | 55 +++ src/smolnetd/scheme/icmp.rs | 16 +- src/smolnetd/scheme/ip.rs | 13 +- src/smolnetd/scheme/mod.rs | 187 ++++++---- src/smolnetd/scheme/netcfg/mod.rs | 5 +- src/smolnetd/scheme/socket.rs | 31 +- src/smolnetd/scheme/tcp.rs | 37 +- src/smolnetd/scheme/udp.rs | 10 +- 16 files changed, 1337 insertions(+), 333 deletions(-) delete mode 100644 src/smolnetd/device.rs create mode 100644 src/smolnetd/link/ethernet.rs create mode 100644 src/smolnetd/link/loopback.rs create mode 100644 src/smolnetd/link/mod.rs create mode 100644 src/smolnetd/router/mod.rs create mode 100644 src/smolnetd/router/route_table.rs diff --git a/Cargo.lock b/Cargo.lock index ee733098ef..bbeab0af36 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,11 +2,35 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + [[package]] name = "arg_parser" version = "0.1.0" source = "git+https://gitlab.redox-os.org/redox-os/arg-parser.git#1c434b55f3e1a0375ebcca85b3e88db7378e82fa" +[[package]] +name = "atomic-polyfill" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3ff7eb3f316534d83a8a2c3d1674ace8a5a71198eba31e2e2b597833f699b28" +dependencies = [ + "critical-section", +] + [[package]] name = "autocfg" version = "1.1.0" @@ -19,6 +43,12 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bumpalo" +version = "3.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1" + [[package]] name = "byteorder" version = "0.5.3" @@ -31,6 +61,15 @@ version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" +[[package]] +name = "cc" +version = "1.0.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" +dependencies = [ + "libc", +] + [[package]] name = "cfg-if" version = "0.1.10" @@ -43,6 +82,33 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chrono" +version = "0.4.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95ed24df0632f708f5f6d8082675bef2596f7084dee3dd55f632290bf35bfe0f" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "js-sys", + "num-traits", + "time", + "wasm-bindgen", + "windows-targets", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" + +[[package]] +name = "critical-section" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7059fff8937831a9ae6f0fe4d658ffabf58f2ca96aa9dec1c889f936f705f216" + [[package]] name = "crossbeam-channel" version = "0.5.8" @@ -62,6 +128,38 @@ dependencies = [ "cfg-if 1.0.0", ] +[[package]] +name = "defmt" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8a2d011b2fee29fb7d659b83c43fce9a2cb4df453e16d441a51448e448f3f98" +dependencies = [ + "bitflags", + "defmt-macros", +] + +[[package]] +name = "defmt-macros" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54f0216f6c5acb5ae1a47050a6645024e6edafc2ee32d421955eccfef12ef92e" +dependencies = [ + "defmt-parser", + "proc-macro-error", + "proc-macro2", + "quote", + "syn 2.0.29", +] + +[[package]] +name = "defmt-parser" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "269924c02afd7f94bc4cecbfa5c379f6ffcf9766b3408fe63d22c728654eccd0" +dependencies = [ + "thiserror", +] + [[package]] name = "dns-parser" version = "0.7.1" @@ -73,25 +171,49 @@ dependencies = [ ] [[package]] -name = "extra" -version = "0.1.0" -source = "git+https://gitlab.redox-os.org/redox-os/libextra.git#cf213969493db8667052a591e32a1e26d43c4234" - -[[package]] -name = "fuchsia-zircon" -version = "0.3.3" +name = "hash32" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" +checksum = "b0c35f58762feb77d74ebe43bdbc3210f09be9fe6742234d573bacc26ed92b67" dependencies = [ - "bitflags", - "fuchsia-zircon-sys", + "byteorder 1.4.3", ] [[package]] -name = "fuchsia-zircon-sys" -version = "0.3.3" +name = "heapless" +version = "0.7.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" +checksum = "db04bc24a18b9ea980628ecf00e6c0264f3c1426dac36c00cb49b6fbad8b0743" +dependencies = [ + "atomic-polyfill", + "hash32", + "rustc_version", + "spin", + "stable_deref_trait", +] + +[[package]] +name = "iana-time-zone" +version = "0.1.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fad5b825842d2b38bd206f3e81d6957625fd7f0a361e345c30e01a0ae2dd613" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] [[package]] name = "idna" @@ -105,30 +227,14 @@ dependencies = [ ] [[package]] -name = "iovec" -version = "0.1.4" +name = "js-sys" +version = "0.3.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" +checksum = "c5f195fe497f702db0f318b07fdd68edb16955aed830df8363d837542f8f935a" dependencies = [ - "libc", + "wasm-bindgen", ] -[[package]] -name = "kernel32-sys" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" -dependencies = [ - "winapi 0.2.8", - "winapi-build", -] - -[[package]] -name = "lazycell" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6f08839bc70ef4a3fe1d566d5350f519c5912ea86be0df1740a7d247c7fc0ef" - [[package]] name = "libc" version = "0.2.147" @@ -136,12 +242,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" [[package]] -name = "log" -version = "0.3.9" +name = "lock_api" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" +checksum = "c1cc9717a20b1bb222f333e6a92fd32f7d8a18ddc5a3191a11af45dcbf4dcd16" dependencies = [ - "log 0.4.20", + "autocfg", + "scopeguard", ] [[package]] @@ -152,9 +259,9 @@ checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" [[package]] name = "managed" -version = "0.7.2" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c75de51135344a4f8ed3cfe2720dc27736f7711989703a0b43aadf3753c55577" +checksum = "0ca88d725a0a943b096803bd34e73a4437208b6077654cc4ecb2947a5f91618d" [[package]] name = "matches" @@ -162,36 +269,6 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2532096657941c2fea9c289d370a250971c689d4f143798ff67113ec042024a5" -[[package]] -name = "mio" -version = "0.6.14" -source = "git+https://gitlab.redox-os.org/redox-os/mio.git?branch=redox-unix#c9a70849ced97387e2607c9c466d23b130ec8901" -dependencies = [ - "fuchsia-zircon", - "fuchsia-zircon-sys", - "iovec", - "kernel32-sys", - "lazycell", - "libc", - "log 0.4.20", - "miow", - "net2", - "slab", - "winapi 0.2.8", -] - -[[package]] -name = "miow" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebd808424166322d4a38da87083bfddd3ac4c131334ed55856112eb06d46944d" -dependencies = [ - "kernel32-sys", - "net2", - "winapi 0.2.8", - "ws2_32-sys", -] - [[package]] name = "net2" version = "0.2.37" @@ -199,24 +276,22 @@ source = "git+https://gitlab.redox-os.org/redox-os/net2-rs.git?branch=master#db0 dependencies = [ "cfg-if 0.1.10", "libc", - "winapi 0.3.9", + "winapi", ] [[package]] name = "netutils" version = "0.1.0" -source = "git+https://gitlab.redox-os.org/redox-os/netutils.git?branch=redox-unix#105ed1ea43413a91152b289fbe76e7efc996e933" +source = "git+https://gitlab.redox-os.org/redox-os/netutils.git#fc11b9bb3c1f5eefccb93ae670e4ec8b3d6fad4f" dependencies = [ "arg_parser", - "extra", "libc", - "mio", "net2", "ntpclient", "pbr", "redox-daemon", "redox_event", - "redox_syscall 0.2.16", + "redox_syscall 0.3.5", "redox_termios", "termion", "url", @@ -231,12 +306,27 @@ dependencies = [ "time", ] +[[package]] +name = "num-traits" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f30b0abd723be7e2ffca1272140fac1a2f084c77ec3e123c192b66af1ee9e6c2" +dependencies = [ + "autocfg", +] + [[package]] name = "numtoa" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef" +[[package]] +name = "once_cell" +version = "1.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" + [[package]] name = "pbr" version = "1.1.1" @@ -245,7 +335,7 @@ checksum = "ed5827dfa0d69b6c92493d6c38e633bbaa5937c153d0d7c28bf12313f8c6d514" dependencies = [ "crossbeam-channel", "libc", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -254,12 +344,54 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn 1.0.109", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + +[[package]] +name = "proc-macro2" +version = "1.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" +dependencies = [ + "unicode-ident", +] + [[package]] name = "quick-error" version = "1.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" +[[package]] +name = "quote" +version = "1.0.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +dependencies = [ + "proc-macro2", +] + [[package]] name = "redox-daemon" version = "0.1.1" @@ -270,6 +402,18 @@ dependencies = [ "redox_syscall 0.3.5", ] +[[package]] +name = "redox-log" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbf6d33a003a5c0b94ec11f10c7c797303f236592964ddb1bfb93e1b438a1557" +dependencies = [ + "chrono", + "log", + "smallvec", + "termion", +] + [[package]] name = "redox_event" version = "0.1.0" @@ -284,9 +428,10 @@ version = "0.1.0" dependencies = [ "byteorder 1.4.3", "dns-parser", - "log 0.3.9", + "log", "netutils", "redox-daemon", + "redox-log", "redox_event", "redox_syscall 0.3.5", "smoltcp", @@ -320,23 +465,83 @@ dependencies = [ ] [[package]] -name = "slab" -version = "0.4.9" +name = "rustc_version" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" dependencies = [ - "autocfg", + "semver", ] +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "semver" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918" + +[[package]] +name = "smallvec" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" + [[package]] name = "smoltcp" -version = "0.5.0" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d2e3a36ac8fea7b94e666dfa3871063d6e0a5c9d5d4fec9a1a6b7b6760f0229" dependencies = [ "bitflags", "byteorder 1.4.3", + "cfg-if 1.0.0", + "defmt", + "heapless", + "log", "managed", ] +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +dependencies = [ + "lock_api", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c324c494eba9d92503e6f1ef2e6df781e78f6a7705a0202d9801b198807d518a" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "termion" version = "1.5.6" @@ -349,6 +554,26 @@ dependencies = [ "redox_termios", ] +[[package]] +name = "thiserror" +version = "1.0.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97a802ec30afc17eee47b2855fc72e0c4cd62be9b4efe6591edde0ec5bd68d8f" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bb623b56e39ab7dcd4b1b98bb6c8f8d907ed255b18de254088016b27a8ee19b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.29", +] + [[package]] name = "time" version = "0.1.45" @@ -357,7 +582,7 @@ checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a" dependencies = [ "libc", "wasi", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -381,6 +606,12 @@ version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" +[[package]] +name = "unicode-ident" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" + [[package]] name = "unicode-normalization" version = "0.1.22" @@ -401,6 +632,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + [[package]] name = "wasi" version = "0.10.0+wasi-snapshot-preview1" @@ -408,10 +645,58 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" [[package]] -name = "winapi" -version = "0.2.8" +name = "wasm-bindgen" +version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" +checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342" +dependencies = [ + "cfg-if 1.0.0", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn 2.0.29", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.29", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" [[package]] name = "winapi" @@ -423,12 +708,6 @@ dependencies = [ "winapi-x86_64-pc-windows-gnu", ] -[[package]] -name = "winapi-build" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" - [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" @@ -442,11 +721,72 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] -name = "ws2_32-sys" -version = "0.2.1" +name = "windows" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" +checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" dependencies = [ - "winapi 0.2.8", - "winapi-build", + "windows-targets", ] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[patch.unused]] +name = "mio" +version = "0.6.14" +source = "git+https://gitlab.redox-os.org/redox-os/mio.git?branch=redox-unix#c9a70849ced97387e2607c9c466d23b130ec8901" diff --git a/Cargo.toml b/Cargo.toml index e6d2d024d1..50e95a2aa1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,16 +27,17 @@ dns-parser = "0.7.1" [dependencies.log] version = "0.4" default-features = false -features = ["release_max_level_warn"] +features = ["release_max_level_debug"] [dependencies.smoltcp] version = "0.10.0" default-features = false features = [ "std", - "medium-ethernet", + "medium-ethernet", "medium-ip", "proto-ipv4", "socket-raw", "socket-icmp", "socket-udp", "socket-tcp", + "iface-max-addr-count-8", "log" ] #For debugging: "log", "verbose" diff --git a/src/smolnetd/device.rs b/src/smolnetd/device.rs deleted file mode 100644 index 3c276fe558..0000000000 --- a/src/smolnetd/device.rs +++ /dev/null @@ -1,123 +0,0 @@ -use smoltcp; -use std::cell::RefCell; -use std::collections::VecDeque; -use std::fs::File; -use std::io::Write; -use std::rc::Rc; - -use smoltcp::time::Instant; -use smoltcp::wire::EthernetAddress; -use crate::buffer_pool::{Buffer, BufferPool}; - -struct NetworkDeviceData { - network_file: Rc>, - input_queue: Rc>>, - local_hwaddr: smoltcp::wire::EthernetAddress, - buffer_pool: Rc>, -} - -pub struct NetworkDevice { - data: Rc>, -} - -impl NetworkDevice { - pub const MTU: usize = 1520; - - pub fn new( - network_file: Rc>, - input_queue: Rc>>, - local_hwaddr: smoltcp::wire::EthernetAddress, - buffer_pool: Rc>, - ) -> NetworkDevice { - NetworkDevice { - data: Rc::new(RefCell::new(NetworkDeviceData { - network_file, - input_queue, - local_hwaddr, - buffer_pool, - })), - } - } -} - -pub struct RxToken { - buffer: Buffer, -} - -impl smoltcp::phy::RxToken for RxToken { - fn consume(mut self, f: F) -> R - where - F: FnOnce(&mut [u8]) -> R, - { - f(&mut self.buffer) - } -} - -pub struct TxToken { - data: Rc>, -} - -impl smoltcp::phy::TxToken for TxToken { - fn consume(self, len: usize, f: F) -> R - where - F: FnOnce(&mut [u8]) -> R, - { - let data = self.data.borrow_mut(); - let mut buffer = data.buffer_pool.borrow_mut().get_buffer(); - buffer.resize(len); - let res = f(&mut buffer); - - let mut loopback = false; - if let Ok(mut frame) = smoltcp::wire::EthernetFrame::new_checked(&mut buffer) { - if frame.dst_addr() == EthernetAddress::default() { - frame.set_dst_addr(data.local_hwaddr); - loopback = true; - } - } - - if loopback { - data.input_queue.borrow_mut().push_back(buffer.move_out()); - } else { - // TODO: Handle error - data.network_file - .borrow_mut() - .write(&buffer); - } - - res - } -} - -impl smoltcp::phy::Device for NetworkDevice { - type RxToken<'a> = RxToken; - type TxToken<'a> = TxToken; - - fn capabilities(&self) -> smoltcp::phy::DeviceCapabilities { - let mut limits = smoltcp::phy::DeviceCapabilities::default(); - limits.max_transmission_unit = Self::MTU; - limits.max_burst_size = Some(20); - limits - } - - fn receive(&mut self, _timestamp: Instant) -> Option<(Self::RxToken<'_>, Self::TxToken<'_>)> { - let data = self.data.borrow_mut(); - let buffer = data.input_queue.borrow_mut().pop_front(); - - if let Some(buffer) = buffer { - Some(( - RxToken { buffer }, - TxToken { - data: Rc::clone(&self.data), - }, - )) - } else { - None - } - } - - fn transmit(&mut self, _timestamp: Instant) -> Option> { - Some(TxToken { - data: Rc::clone(&self.data), - }) - } -} diff --git a/src/smolnetd/link/ethernet.rs b/src/smolnetd/link/ethernet.rs new file mode 100644 index 0000000000..13e916cc25 --- /dev/null +++ b/src/smolnetd/link/ethernet.rs @@ -0,0 +1,355 @@ +use std::collections::btree_map::Entry; +use std::collections::BTreeMap; +use std::fs::File; +use std::io::{ErrorKind, Read, Write}; +use std::rc::Rc; + +use smoltcp::storage::PacketMetadata; +use smoltcp::time::{Duration, Instant}; +use smoltcp::wire::{ + ArpOperation, ArpPacket, ArpRepr, EthernetAddress, EthernetFrame, EthernetProtocol, + EthernetRepr, IpAddress, Ipv4Address, Ipv4Cidr, +}; + +use super::LinkDevice; + +struct Neighbor { + hardware_address: EthernetAddress, + expires_at: Instant, +} + +#[derive(Debug, Default)] +enum ArpState { + #[default] + Discovered, + Discovering { + target: Ipv4Address, + tries: u32, + silent_until: Instant, + }, +} + +type PacketBuffer = smoltcp::storage::PacketBuffer<'static, IpAddress>; + +pub struct EthernetLink { + name: Rc, + neighbor_cache: BTreeMap, + arp_state: ArpState, + waiting_packets: PacketBuffer, + input_buffer: Vec, + output_buffer: Vec, + network_file: File, + hardware_address: EthernetAddress, + ip_address: Ipv4Cidr, +} + +impl EthernetLink { + // TODO: Review these constants + const MAX_WAITING_PACKET_COUNT: usize = 10; + const MTU: usize = 1500; + const WAITING_PACKET_BUFFER_SIZE: usize = Self::MTU * Self::MAX_WAITING_PACKET_COUNT; + + const NEIGHBOR_LIVE_TIME: Duration = Duration::from_secs(60); + const ARP_SILENCE_TIME: Duration = Duration::from_secs(1); + + pub fn new( + name: &str, + network_file: File, + hardware_address: EthernetAddress, + ip_address: Ipv4Cidr, + ) -> Self { + let waiting_packets = PacketBuffer::new( + vec![PacketMetadata::EMPTY; Self::MAX_WAITING_PACKET_COUNT], + vec![0u8; Self::WAITING_PACKET_BUFFER_SIZE], + ); + + Self { + name: name.into(), + network_file, + waiting_packets, + hardware_address, + ip_address, + input_buffer: vec![0u8; Self::MTU], + output_buffer: Vec::with_capacity(Self::MTU), + arp_state: Default::default(), + neighbor_cache: Default::default(), + } + } + + fn send_to(&mut self, dst: EthernetAddress, size: usize, f: F, proto: EthernetProtocol) + where + F: FnOnce(&mut [u8]), + { + let repr = EthernetRepr { + src_addr: self.hardware_address, + dst_addr: dst, + ethertype: proto, + }; + + self.output_buffer.clear(); + self.output_buffer.resize(repr.buffer_len() + size, 0); + let mut frame = EthernetFrame::new_unchecked(&mut self.output_buffer); + repr.emit(&mut frame); + + f(frame.payload_mut()); + + if let Err(_) = self.network_file.write_all(&self.output_buffer) { + error!( + "Dropped outboud packet on {} (failed to write to network file)", + self.name + ) + } + } + + fn process_arp(&mut self, packet: &[u8], now: Instant) { + let Ok(repr) = ArpPacket::new_checked(packet).and_then(|packet| ArpRepr::parse(&packet)) else { + debug!("Dropped incomming arp packet on {} (Malformed)", self.name); + return; + }; + + match repr { + ArpRepr::EthernetIpv4 { + operation, + source_hardware_addr, + source_protocol_addr, + target_hardware_addr, + target_protocol_addr, + } => { + if self.hardware_address != target_hardware_addr { + // Only process packet that are for us + return; + } + + if let ArpOperation::Unknown(_) = operation { + return; + } + + if !source_hardware_addr.is_unicast() || !source_protocol_addr.is_unicast() { + return; + } + + if !self.ip_address.contains_addr(&target_protocol_addr) { + return; + } + + self.neighbor_cache.insert( + IpAddress::Ipv4(source_protocol_addr), + Neighbor { + hardware_address: source_hardware_addr, + expires_at: now + Self::NEIGHBOR_LIVE_TIME, + }, + ); + + if let ArpOperation::Request = operation { + let response = ArpRepr::EthernetIpv4 { + operation: ArpOperation::Reply, + source_hardware_addr: self.hardware_address, + source_protocol_addr: self.ip_address.address(), + target_hardware_addr: source_hardware_addr, + target_protocol_addr: source_protocol_addr, + }; + + self.send_to( + source_hardware_addr, + response.buffer_len(), + |buf| response.emit(&mut ArpPacket::new_unchecked(buf)), + EthernetProtocol::Arp, + ); + } + self.check_waiting_packets(source_protocol_addr, source_hardware_addr, now); + } + _ => {} + } + } + + fn check_waiting_packets(&mut self, ip: Ipv4Address, mac: EthernetAddress, now: Instant) { + let mut waiting_packets = + std::mem::replace(&mut self.waiting_packets, PacketBuffer::new(vec![], vec![])); + loop { + match waiting_packets.peek() { + Ok((IpAddress::Ipv4(dst), _)) if dst == &ip => {} + Ok((IpAddress::Ipv4(dst), _)) => { + self.arp_state = ArpState::Discovering { + target: *dst, + tries: 0, + silent_until: Instant::ZERO, + }; + self.send_arp(now); + break; + } + Err(_) => { + self.arp_state = ArpState::Discovered; + break; + } + } + + let (_, packet) = waiting_packets.dequeue().unwrap(); + self.send_to( + mac, + packet.len(), + |buf| buf.copy_from_slice(packet), + EthernetProtocol::Ipv4, + ); + } + + self.waiting_packets = waiting_packets; + } + + fn drop_waiting_packets(&mut self, ip: Ipv4Address, now: Instant) { + loop { + match self.waiting_packets.peek() { + Ok((IpAddress::Ipv4(dst), _)) if dst == &ip => {} + Ok((IpAddress::Ipv4(dst), _)) => { + self.arp_state = ArpState::Discovering { + target: *dst, + tries: 0, + silent_until: Instant::ZERO, + }; + + self.send_arp(now); + + return; + } + Err(_) => { + self.arp_state = ArpState::Discovered; + return; + } + } + + let _ = self.waiting_packets.dequeue(); + debug!( + "Dropped packet on {} because neighbor was not found", + self.name + ) + } + } + + fn handle_missing_neighbor(&mut self, next_hop: IpAddress, packet: &[u8], now: Instant) { + let Ok(buf) = self.waiting_packets.enqueue(packet.len(), next_hop) else { + warn!("Dropped packet on {} because waiting queue was full", self.name); + return; + }; + buf.copy_from_slice(packet); + + let IpAddress::Ipv4(next_hop) = next_hop; + if let ArpState::Discovered = self.arp_state { + self.arp_state = ArpState::Discovering { + target: next_hop, + tries: 0, + silent_until: Instant::ZERO, + }; + + self.send_arp(now) + } + } + + fn send_arp(&mut self, now: Instant) { + match self.arp_state { + ArpState::Discovered => {} + ArpState::Discovering { silent_until, .. } if silent_until > now => {} + ArpState::Discovering { target, tries, .. } if tries >= 3 => { + self.drop_waiting_packets(target, now) + } + ArpState::Discovering { + target, + ref mut tries, + ref mut silent_until, + } => { + let arp_repr = ArpRepr::EthernetIpv4 { + operation: ArpOperation::Request, + source_hardware_addr: self.hardware_address, + source_protocol_addr: self.ip_address.address(), + target_hardware_addr: EthernetAddress::BROADCAST, + target_protocol_addr: target, + }; + + *tries += 1; + *silent_until = now + Self::ARP_SILENCE_TIME; + + self.send_to( + EthernetAddress::BROADCAST, + arp_repr.buffer_len(), + |buf| arp_repr.emit(&mut ArpPacket::new_unchecked(buf)), + EthernetProtocol::Arp, + ); + } + } + } +} + +impl LinkDevice for EthernetLink { + fn send(&mut self, next_hop: IpAddress, packet: &[u8], now: Instant) { + + let local_broadcast = match self.ip_address.broadcast() { + Some(addr) => IpAddress::Ipv4(addr) == next_hop, + None => false + }; + + if local_broadcast || next_hop.is_broadcast() { + self.send_to( + EthernetAddress::BROADCAST, + packet.len(), + |buf| buf.copy_from_slice(packet), + EthernetProtocol::Ipv4, + ); + return; + } + + match self.neighbor_cache.entry(next_hop) { + Entry::Vacant(_) => self.handle_missing_neighbor(next_hop, packet, now), + Entry::Occupied(e) => { + if e.get().expires_at < now { + e.remove(); + self.handle_missing_neighbor(next_hop, packet, now) + } else { + let mac = e.get().hardware_address; + self.send_to( + mac, + packet.len(), + |buf| buf.copy_from_slice(packet), + EthernetProtocol::Ipv4, + ) + } + } + } + } + + fn recv(&mut self, now: Instant) -> Option<&[u8]> { + let mut input_buffer = std::mem::replace(&mut self.input_buffer, Vec::new()); + loop { + if let Err(e) = self.network_file.read(&mut input_buffer) { + if e.kind() != ErrorKind::WouldBlock { + error!("Failed to read ethernet device on link {}", self.name); + } else { + // No packet to read but we check if we have arp to send + self.send_arp(now); + } + self.input_buffer = input_buffer; + return None; + } + let packet = EthernetFrame::new_unchecked(&input_buffer[..]); + let Ok(repr) = EthernetRepr::parse(&packet) else { + debug!("Dropped incomming frame on {} (Malformed)", self.name); + continue; + }; + + if !repr.dst_addr.is_broadcast() && repr.dst_addr != self.hardware_address { + // Drop packets which are not for us + continue; + } + + match repr.ethertype { + EthernetProtocol::Ipv4 => { + self.input_buffer = input_buffer; + return Some(EthernetFrame::new_unchecked(&self.input_buffer[..]).payload()); + } + EthernetProtocol::Arp => self.process_arp(packet.payload(), now), + _ => continue, + } + } + } + + fn name(&self) -> &Rc { + &self.name + } +} diff --git a/src/smolnetd/link/loopback.rs b/src/smolnetd/link/loopback.rs new file mode 100644 index 0000000000..ff2bf019bf --- /dev/null +++ b/src/smolnetd/link/loopback.rs @@ -0,0 +1,45 @@ +use std::rc::Rc; + +use smoltcp::storage::PacketMetadata; +use smoltcp::time::Instant; + +use crate::scheme::Smolnetd; + +use super::LinkDevice; + +pub type PacketBuffer = smoltcp::storage::PacketBuffer<'static, ()>; + +pub struct LoopbackDevice { + name: Rc, + buffer: PacketBuffer, +} + +impl Default for LoopbackDevice { + fn default() -> Self { + let buffer = PacketBuffer::new( + vec![PacketMetadata::EMPTY; Smolnetd::SOCKET_BUFFER_SIZE], + vec![0u8; 1500 * Smolnetd::SOCKET_BUFFER_SIZE], + ); + LoopbackDevice { + name: "loopback".into(), + buffer, + } + } +} + +impl LinkDevice for LoopbackDevice { + fn send(&mut self, _next_hop: smoltcp::wire::IpAddress, packet: &[u8], _now: Instant) { + match self.buffer.enqueue(packet.len(), ()) { + Err(_) => warn!("loopback dropped packet because buffer was full"), + Ok(buf) => buf.copy_from_slice(packet), + } + } + + fn recv(&mut self, _now: Instant) -> Option<&[u8]> { + self.buffer.dequeue().ok().map(|((), buf)| &*buf) + } + + fn name(&self) -> &std::rc::Rc { + &self.name + } +} diff --git a/src/smolnetd/link/mod.rs b/src/smolnetd/link/mod.rs new file mode 100644 index 0000000000..e550ef1b6e --- /dev/null +++ b/src/smolnetd/link/mod.rs @@ -0,0 +1,57 @@ +pub mod loopback; +pub mod ethernet; + +use std::rc::Rc; + +use smoltcp::time::Instant; +use smoltcp::wire::IpAddress; + +/// Represent a link layer device (eth0, loopback...) +pub trait LinkDevice { + + /// Send the given packet to the machine with the `next_hop` ip address + /// This method cannot fail so it's the implementor responsability + /// to buffer packets which can't be sent immediatly or decide to + /// drop them if necessary + fn send(&mut self, next_hop: IpAddress, packet: &[u8], now: Instant); + + /// Returns None if nothing is received. + /// Returns an Ip packet otherwise + fn recv(&mut self, now: Instant) -> Option<&[u8]>; + + /// Returns the LinkDevice display name used to refer to it and for lookups + fn name(&self) -> &Rc; +} + +#[derive(Default)] +pub struct DeviceList { + inner: Vec>, +} + +impl DeviceList { + pub fn push(&mut self, dev: T) { + self.inner.push(Box::new(dev)) + } + + pub fn get(&self, device_name: &str) -> Option<&dyn LinkDevice> { + self.inner + .iter() + .find(|dev| dev.name().as_ref() == device_name) + .map(|device| device.as_ref()) + } + + pub fn get_mut(&mut self, device_name: &str) -> Option<&mut (dyn LinkDevice + 'static)> { + self.inner + .iter_mut() + .find(|dev| dev.name().as_ref() == device_name) + .map(|device| device.as_mut()) + } + + pub fn iter(&self) -> impl Iterator { + self.inner.iter().map(|b| b.as_ref()) + } + + pub fn iter_mut(&mut self) -> impl Iterator { + self.inner.iter_mut().map(|b| b.as_mut()) + } +} diff --git a/src/smolnetd/main.rs b/src/smolnetd/main.rs index b1b6ebb8ce..3f1ac9c2d3 100644 --- a/src/smolnetd/main.rs +++ b/src/smolnetd/main.rs @@ -3,11 +3,11 @@ extern crate event; #[macro_use] extern crate log; +extern crate byteorder; extern crate netutils; extern crate redox_netstack; extern crate smoltcp; extern crate syscall; -extern crate byteorder; use std::cell::RefCell; use std::fs::File; @@ -15,14 +15,15 @@ use std::os::unix::io::{FromRawFd, RawFd}; use std::process; use std::rc::Rc; +use event::EventQueue; use redox_netstack::error::{Error, Result}; use redox_netstack::logger; -use event::EventQueue; use scheme::Smolnetd; mod buffer_pool; -mod device; +mod link; mod port_set; +mod router; mod scheme; fn run(daemon: redox_daemon::Daemon) -> Result<()> { @@ -143,7 +144,7 @@ fn run(daemon: redox_daemon::Daemon) -> Result<()> { event_queue.trigger_all(event::Event { fd: 0, - flags: EventFlags::empty() + flags: EventFlags::empty(), })?; event_queue.run() @@ -158,5 +159,6 @@ fn main() { process::exit(1); } process::exit(0); - }).expect("smoltcp: failed to daemonize"); + }) + .expect("smoltcp: failed to daemonize"); } diff --git a/src/smolnetd/router/mod.rs b/src/smolnetd/router/mod.rs new file mode 100644 index 0000000000..c72331948d --- /dev/null +++ b/src/smolnetd/router/mod.rs @@ -0,0 +1,187 @@ +use std::cell::RefCell; +use std::rc::Rc; + +use smoltcp::phy::{Device, DeviceCapabilities, Medium}; +use smoltcp::storage::PacketMetadata; +use smoltcp::time::Instant; +use smoltcp::wire::IpAddress; + +use self::route_table::RouteTable; +use crate::link::DeviceList; +use crate::scheme::Smolnetd; + +pub mod route_table; + +pub type PacketBuffer = smoltcp::storage::PacketBuffer<'static, ()>; + +pub struct Router { + rx_buffer: PacketBuffer, + tx_buffer: PacketBuffer, + devices: Rc>, + route_table: Rc>, +} + +impl Router { + pub fn new(devices: Rc>, route_table: Rc>) -> Self { + let rx_buffer = PacketBuffer::new( + vec![PacketMetadata::EMPTY; Smolnetd::SOCKET_BUFFER_SIZE], + vec![0u8; Router::MTU * Smolnetd::SOCKET_BUFFER_SIZE], + ); + let tx_buffer = PacketBuffer::new( + vec![PacketMetadata::EMPTY; Smolnetd::SOCKET_BUFFER_SIZE], + vec![0u8; Router::MTU * Smolnetd::SOCKET_BUFFER_SIZE], + ); + Self { + rx_buffer, + tx_buffer, + devices, + route_table, + } + } + + pub const MTU: usize = 1486; + + pub fn poll(&mut self, now: Instant) { + self.dispatch_outgoing(now); + self.process_incoming(now); + } + + fn process_incoming(&mut self, now: Instant) { + for dev in self.devices.borrow_mut().iter_mut() { + if self.rx_buffer.is_full() { + break; + } + + loop { + if self.rx_buffer.is_full() { + break; + } + + let Some(buf) = dev.recv(now) else { + break; + }; + + self.rx_buffer + .enqueue(buf.len(), ()) + .expect("We checked if it was full") + .copy_from_slice(buf); + } + } + } + + fn dispatch_outgoing(&mut self, now: Instant) { + while let Ok(((), packet)) = self.tx_buffer.dequeue() { + if let Ok(mut packet) = smoltcp::wire::Ipv4Packet::new_checked(packet) { + let dst_addr = IpAddress::Ipv4(packet.dst_addr()); + if packet.dst_addr().is_broadcast() { + let buf = packet.into_inner(); + for dev in self.devices.borrow_mut().iter_mut() { + dev.send(dst_addr, buf, now) + } + } else { + let route_table = self.route_table.borrow(); + let Some(rule) = route_table.lookup_rule(&dst_addr) else { + warn!("No route found for destination: {}", dst_addr); + continue; + }; + + let next_hop = match rule.via { + Some(via) => via, + None => dst_addr, + }; + + let mut devices = self.devices.borrow_mut(); + let Some(dev) = devices.get_mut(&rule.dev) else { + warn!("Device {} not found", rule.dev); + // TODO: Remove route if device doesn't exist anymore ? + continue; + }; + + let IpAddress::Ipv4(src) = rule.src; + if src != packet.src_addr() { + packet.set_src_addr(src); + packet.fill_checksum() + } + + dev.send(next_hop, packet.into_inner(), now); + } + } + } + } +} + +impl Device for Router { + type RxToken<'a> = RxToken<'a>; + + type TxToken<'a> = TxToken<'a>; + + fn receive( + &mut self, + _timestamp: smoltcp::time::Instant, + ) -> Option<(Self::RxToken<'_>, Self::TxToken<'_>)> { + if self.rx_buffer.is_empty() || self.tx_buffer.is_full() { + None + } else { + Some(( + RxToken { + rx_buffer: &mut self.rx_buffer, + }, + TxToken { + tx_buffer: &mut self.tx_buffer, + }, + )) + } + } + + fn transmit(&mut self, _timestamp: smoltcp::time::Instant) -> Option> { + if self.tx_buffer.is_full() { + None + } else { + Some(TxToken { + tx_buffer: &mut self.tx_buffer, + }) + } + } + + fn capabilities(&self) -> smoltcp::phy::DeviceCapabilities { + let mut caps = DeviceCapabilities::default(); + caps.medium = Medium::Ip; + caps.max_transmission_unit = Router::MTU; + caps.max_burst_size = Some(Smolnetd::SOCKET_BUFFER_SIZE); + caps + } +} + +pub struct TxToken<'a> { + tx_buffer: &'a mut PacketBuffer, +} + +impl smoltcp::phy::TxToken for TxToken<'_> { + fn consume(self, len: usize, f: F) -> R + where + F: FnOnce(&mut [u8]) -> R, + { + f(self + .tx_buffer + .enqueue(len, ()) + .expect("This was checked before creating the TxToken")) + } +} + +pub struct RxToken<'a> { + rx_buffer: &'a mut PacketBuffer, +} + +impl<'a> smoltcp::phy::RxToken for RxToken<'a> { + fn consume(self, f: F) -> R + where + F: FnOnce(&mut [u8]) -> R, + { + let ((), buf) = self + .rx_buffer + .dequeue() + .expect("This was checked before creating the RxToken"); + + f(buf) + } +} diff --git a/src/smolnetd/router/route_table.rs b/src/smolnetd/router/route_table.rs new file mode 100644 index 0000000000..e51127720a --- /dev/null +++ b/src/smolnetd/router/route_table.rs @@ -0,0 +1,55 @@ +use std::rc::Rc; + +use smoltcp::wire::{IpAddress, IpCidr}; + +#[derive(Debug)] +pub struct Rule { + pub filter: IpCidr, + pub via: Option, + pub dev: Rc, + pub src: IpAddress, +} + +impl Rule { + pub fn new(filter: IpCidr, via: Option, dev: Rc, src: IpAddress) -> Self { + Self { + filter, + via, + dev, + src, + } + } +} + +#[derive(Debug, Default)] +pub struct RouteTable { + rules: Vec, +} + +impl RouteTable { + pub fn lookup_rule(&self, dst: &IpAddress) -> Option<&Rule> { + self.rules + .iter() + .rev() + .find(|rule| rule.filter.contains_addr(dst)) + } + + pub fn lookup_src_addr(&self, dst: &IpAddress) -> Option { + Some(self.lookup_rule(dst)?.src) + } + + pub fn lookup_gateway(&self, dst: &IpAddress) -> Option { + self.lookup_rule(dst)?.via + } + + pub fn insert_rule(&mut self, new_rule: Rule) { + let i = match self + .rules + .binary_search_by_key(&new_rule.filter.prefix_len(), |rule| { + rule.filter.prefix_len() + }) { + Ok(i) | Err(i) => i, + }; + self.rules.insert(i, new_rule); + } +} diff --git a/src/smolnetd/scheme/icmp.rs b/src/smolnetd/scheme/icmp.rs index 5ecd94fc8c..2f2fc680fe 100644 --- a/src/smolnetd/scheme/icmp.rs +++ b/src/smolnetd/scheme/icmp.rs @@ -7,10 +7,10 @@ use syscall::{Error as SyscallError, Result as SyscallResult}; use syscall; use byteorder::{ByteOrder, NetworkEndian}; -use crate::device::NetworkDevice; use crate::port_set::PortSet; -use super::socket::{DupResult, SchemeFile, SchemeSocket, SocketFile, SocketScheme}; -use super::{Smolnetd, SocketSet, Interface}; +use crate::router::Router; +use super::socket::{DupResult, SchemeFile, SchemeSocket, SocketFile, SocketScheme, Context}; +use super::{Smolnetd, SocketSet}; pub type IcmpScheme = SocketScheme>; @@ -75,7 +75,7 @@ impl<'a> SchemeSocket for IcmpSocket<'a> { path: &str, _uid: u32, ident_set: &mut Self::SchemeDataT, - iface: &Interface + _context: &Context ) -> SyscallResult<(SocketHandle, Self::DataT)> { use std::str::FromStr; @@ -95,11 +95,11 @@ impl<'a> SchemeSocket for IcmpSocket<'a> { let socket = IcmpSocket::new( IcmpSocketBuffer::new( vec![IcmpPacketMetadata::EMPTY; Smolnetd::SOCKET_BUFFER_SIZE], - vec![0; NetworkDevice::MTU * Smolnetd::SOCKET_BUFFER_SIZE] + vec![0; Router::MTU * Smolnetd::SOCKET_BUFFER_SIZE] ), IcmpSocketBuffer::new( vec![IcmpPacketMetadata::EMPTY; Smolnetd::SOCKET_BUFFER_SIZE], - vec![0; NetworkDevice::MTU * Smolnetd::SOCKET_BUFFER_SIZE] + vec![0; Router::MTU * Smolnetd::SOCKET_BUFFER_SIZE] ) ); let handle = socket_set.add(socket); @@ -127,11 +127,11 @@ impl<'a> SchemeSocket for IcmpSocket<'a> { let socket = IcmpSocket::new( IcmpSocketBuffer::new( vec![IcmpPacketMetadata::EMPTY; Smolnetd::SOCKET_BUFFER_SIZE], - vec![0; NetworkDevice::MTU * Smolnetd::SOCKET_BUFFER_SIZE] + vec![0; Router::MTU * Smolnetd::SOCKET_BUFFER_SIZE] ), IcmpSocketBuffer::new( vec![IcmpPacketMetadata::EMPTY; Smolnetd::SOCKET_BUFFER_SIZE], - vec![0; NetworkDevice::MTU * Smolnetd::SOCKET_BUFFER_SIZE] + vec![0; Router::MTU * Smolnetd::SOCKET_BUFFER_SIZE] ) ); let handle = socket_set.add(socket); diff --git a/src/smolnetd/scheme/ip.rs b/src/smolnetd/scheme/ip.rs index 4f0d0d3254..149b173599 100644 --- a/src/smolnetd/scheme/ip.rs +++ b/src/smolnetd/scheme/ip.rs @@ -5,9 +5,10 @@ use std::str; use syscall::{Error as SyscallError, Result as SyscallResult}; use syscall; -use crate::device::NetworkDevice; -use super::{Smolnetd, SocketSet, Interface}; -use super::socket::{DupResult, SchemeFile, SchemeSocket, SocketFile, SocketScheme}; +use crate::router::Router; + +use super::{Smolnetd, SocketSet}; +use super::socket::{DupResult, SchemeFile, SchemeSocket, SocketFile, SocketScheme, Context}; pub type IpScheme = SocketScheme>; @@ -59,7 +60,7 @@ impl<'a> SchemeSocket for RawSocket<'a> { path: &str, uid: u32, _: &mut Self::SchemeDataT, - iface: &Interface + _context: &Context ) -> SyscallResult<(SocketHandle, Self::DataT)> { if uid != 0 { return Err(SyscallError::new(syscall::EACCES)); @@ -69,11 +70,11 @@ impl<'a> SchemeSocket for RawSocket<'a> { let rx_buffer = RawSocketBuffer::new( vec![RawPacketMetadata::EMPTY; Smolnetd::SOCKET_BUFFER_SIZE], - vec![0; NetworkDevice::MTU * Smolnetd::SOCKET_BUFFER_SIZE] + vec![0; Router::MTU * Smolnetd::SOCKET_BUFFER_SIZE] ); let tx_buffer = RawSocketBuffer::new( vec![RawPacketMetadata::EMPTY; Smolnetd::SOCKET_BUFFER_SIZE], - vec![0; NetworkDevice::MTU * Smolnetd::SOCKET_BUFFER_SIZE] + vec![0; Router::MTU * Smolnetd::SOCKET_BUFFER_SIZE] ); let ip_socket = RawSocket::new( IpVersion::Ipv4, diff --git a/src/smolnetd/scheme/mod.rs b/src/smolnetd/scheme/mod.rs index fdf60b012c..b0e01f9ddd 100644 --- a/src/smolnetd/scheme/mod.rs +++ b/src/smolnetd/scheme/mod.rs @@ -1,35 +1,41 @@ +use crate::link::ethernet::EthernetLink; +use crate::link::LinkDevice; +use crate::link::{loopback::LoopbackDevice, DeviceList}; +use crate::router::route_table::{RouteTable, Rule}; +use crate::router::Router; +use crate::scheme::smoltcp::iface::SocketSet as SmoltcpSocketSet; use netutils::getcfg; use smoltcp; -use smoltcp::iface::{Interface as SmoltcpInterface, Routes, Config}; +use smoltcp::iface::{Config, Interface as SmoltcpInterface}; use smoltcp::phy::Tracer; -use crate::scheme::smoltcp::iface::SocketSet as SmoltcpSocketSet; use smoltcp::time::{Duration, Instant}; -use smoltcp::wire::{EthernetAddress, IpAddress, IpCidr, Ipv4Address, IpListenEndpoint, HardwareAddress}; +use smoltcp::wire::{ + EthernetAddress, HardwareAddress, IpAddress, IpCidr, IpListenEndpoint, Ipv4Address, Ipv4Cidr, +}; use std::cell::RefCell; use std::collections::VecDeque; use std::fs::File; -use std::io::{self, Read, Write}; +use std::io::{Read, Write}; use std::mem::size_of; use std::rc::Rc; use std::str::FromStr; -use syscall::data::TimeSpec; use syscall; +use syscall::data::TimeSpec; -use crate::buffer_pool::{Buffer, BufferPool}; -use crate::device::NetworkDevice; -use redox_netstack::error::{Error, Result}; +use self::icmp::IcmpScheme; use self::ip::IpScheme; +use self::netcfg::NetCfgScheme; use self::tcp::TcpScheme; use self::udp::UdpScheme; -use self::icmp::IcmpScheme; -use self::netcfg::NetCfgScheme; +use crate::buffer_pool::{Buffer, BufferPool}; +use redox_netstack::error::{Error, Result}; +mod icmp; mod ip; +mod netcfg; mod socket; mod tcp; mod udp; -mod icmp; -mod netcfg; type SocketSet = SmoltcpSocketSet<'static>; type Interface = Rc>; @@ -38,11 +44,12 @@ const MAX_DURATION: Duration = Duration::from_millis(u64::MAX); const MIN_DURATION: Duration = Duration::from_millis(0); pub struct Smolnetd { - network_file: Rc>, - network_device: Tracer, + router_device: Tracer, + iface: Interface, + link_devices: Rc>, + route_table: Rc>, time_file: File, - iface: Interface, socket_set: Rc>, timer: ::std::time::Instant, @@ -57,10 +64,10 @@ pub struct Smolnetd { } impl Smolnetd { - const MAX_PACKET_SIZE: usize = 2048; - const SOCKET_BUFFER_SIZE: usize = 128; //packets - const MIN_CHECK_TIMEOUT: Duration = Duration::from_millis(10); - const MAX_CHECK_TIMEOUT: Duration = Duration::from_millis(500); + pub const MAX_PACKET_SIZE: usize = 2048; + pub const SOCKET_BUFFER_SIZE: usize = 128; //packets + pub const MIN_CHECK_TIMEOUT: Duration = Duration::from_millis(10); + pub const MAX_CHECK_TIMEOUT: Duration = Duration::from_millis(500); pub fn new( network_file: File, @@ -79,48 +86,104 @@ impl Smolnetd { IpCidr::new(local_ip, 24), IpCidr::new(IpAddress::v4(127, 0, 0, 1), 8), ]; + let default_gw = Ipv4Address::from_str(getcfg("ip_router").unwrap().trim()) .expect("Can't parse the 'ip_router' cfg."); let buffer_pool = Rc::new(RefCell::new(BufferPool::new(Self::MAX_PACKET_SIZE))); let input_queue = Rc::new(RefCell::new(VecDeque::new())); - let network_file = Rc::new(RefCell::new(network_file)); - let mut network_device = Tracer::new(NetworkDevice::new( - Rc::clone(&network_file), - Rc::clone(&input_queue), - hardware_addr, - Rc::clone(&buffer_pool), - ), |_timestamp, printer| { - trace!("{}", printer) - }); - let config = Config::new(HardwareAddress::Ethernet(hardware_addr)); + + let devices = Rc::new(RefCell::new(DeviceList::default())); + let route_table = Rc::new(RefCell::new(RouteTable::default())); + let mut network_device = Tracer::new( + Router::new(Rc::clone(&devices), Rc::clone(&route_table)), + |_timestamp, printer| trace!("{}", printer), + ); + + let config = Config::new(HardwareAddress::Ip); let mut iface = SmoltcpInterface::new(config, &mut network_device, Instant::now()); iface.update_ip_addrs(|ip_addrs| ip_addrs.extend(protocol_addrs)); - iface.routes_mut().add_default_ipv4_route(default_gw).expect("Failed to add default gateway"); + iface + .routes_mut() + .add_default_ipv4_route(default_gw) + .expect("Failed to add default gateway"); let iface = Rc::new(RefCell::new(iface)); let socket_set = Rc::new(RefCell::new(SocketSet::new(vec![]))); + + let loopback = LoopbackDevice::default(); + route_table.borrow_mut().insert_rule(Rule::new( + "127.0.0.0/8".parse().unwrap(), + None, + Rc::clone(loopback.name()), + "127.0.0.1".parse().unwrap(), + )); + + let IpAddress::Ipv4(local_ip) = local_ip; + let eth0 = EthernetLink::new( + "eth0", + network_file, + hardware_addr, + Ipv4Cidr::new(local_ip, 24), + ); + + route_table.borrow_mut().insert_rule(Rule::new( + IpCidr::new(IpAddress::Ipv4(local_ip), 24), + None, + Rc::clone(eth0.name()), + IpAddress::Ipv4(local_ip), + )); + + route_table.borrow_mut().insert_rule(Rule::new( + "0.0.0.0/0".parse().unwrap(), + Some(IpAddress::Ipv4(default_gw)), + Rc::clone(eth0.name()), + IpAddress::Ipv4(local_ip), + )); + + devices.borrow_mut().push(loopback); + devices.borrow_mut().push(eth0); + Smolnetd { iface: Rc::clone(&iface), - network_device, + router_device: network_device, + route_table: Rc::clone(&route_table), socket_set: Rc::clone(&socket_set), timer: ::std::time::Instant::now(), + link_devices: devices, time_file, - ip_scheme: IpScheme::new(Rc::clone(&iface), Rc::clone(&socket_set), ip_file), - udp_scheme: UdpScheme::new(Rc::clone(&iface), Rc::clone(&socket_set), udp_file), - tcp_scheme: TcpScheme::new(Rc::clone(&iface), Rc::clone(&socket_set), tcp_file), - icmp_scheme: IcmpScheme::new(Rc::clone(&iface), Rc::clone(&socket_set), icmp_file), + ip_scheme: IpScheme::new( + Rc::clone(&iface), + Rc::clone(&route_table), + Rc::clone(&socket_set), + ip_file, + ), + udp_scheme: UdpScheme::new( + Rc::clone(&iface), + Rc::clone(&route_table), + Rc::clone(&socket_set), + udp_file, + ), + tcp_scheme: TcpScheme::new( + Rc::clone(&iface), + Rc::clone(&route_table), + Rc::clone(&socket_set), + tcp_file, + ), + icmp_scheme: IcmpScheme::new( + Rc::clone(&iface), + Rc::clone(&route_table), + Rc::clone(&socket_set), + icmp_file, + ), netcfg_scheme: NetCfgScheme::new(Rc::clone(&iface), netcfg_file), input_queue, - network_file, buffer_pool, } } pub fn on_network_scheme_event(&mut self) -> Result> { - if self.read_frames()? > 0 { - self.poll()?; - } + self.poll()?; Ok(None) } @@ -183,22 +246,23 @@ impl Smolnetd { let mut iter_limit = 10usize; let mut iface = self.iface.borrow_mut(); let mut socket_set = self.socket_set.borrow_mut(); - let timestamp = Instant::from(self.timer); + loop { + let timestamp = Instant::from(self.timer); if iter_limit == 0 { break MIN_DURATION; } iter_limit -= 1; - // TODO: Check what if the bool returned by poll can be useful - iface.poll(timestamp, &mut self.network_device, &mut socket_set); + self.router_device.get_mut().poll(timestamp); + + // TODO: Check what if the bool returned by poll can be useful + iface.poll(timestamp, &mut self.router_device, &mut socket_set); match iface.poll_delay(timestamp, &socket_set) { - Some(delay) if delay == Duration::ZERO => { } - Some(delay) => { - break ::std::cmp::min(MAX_DURATION, delay) - } - None => break MAX_DURATION + Some(delay) if delay == Duration::ZERO => {} + Some(delay) => break ::std::cmp::min(MAX_DURATION, delay), + None => break MAX_DURATION, }; } }; @@ -211,26 +275,6 @@ impl Smolnetd { )) } - fn read_frames(&mut self) -> Result { - let mut total_frames = 0; - loop { - let mut buffer = self.buffer_pool.borrow_mut().get_buffer(); - let count = match self.network_file.borrow_mut().read(&mut buffer) { - Ok(count) => count, - Err(err) => match err.kind() { - io::ErrorKind::WouldBlock => break, - _ => return Err( - Error::from_io_error(err, "Failed to read from network file") - ) - } - }; - buffer.resize(count); - self.input_queue.borrow_mut().push_back(buffer); - total_frames += 1; - } - Ok(total_frames) - } - fn notify_sockets(&mut self) -> Result<()> { self.ip_scheme.notify_sockets()?; self.udp_scheme.notify_sockets()?; @@ -257,14 +301,15 @@ fn post_fevent(scheme_file: &mut File, fd: usize, event: usize, data_len: usize) fn parse_endpoint(socket: &str) -> IpListenEndpoint { let mut socket_parts = socket.split(':'); - let host = - Ipv4Address::from_str(socket_parts.next().unwrap_or("")).ok().filter(|addr| !addr.is_unspecified()).map(IpAddress::Ipv4); - + let host = Ipv4Address::from_str(socket_parts.next().unwrap_or("")) + .ok() + .filter(|addr| !addr.is_unspecified()) + .map(IpAddress::Ipv4); let port = socket_parts .next() .unwrap_or("") .parse::() .unwrap_or(0); - IpListenEndpoint{ addr: host, port} + IpListenEndpoint { addr: host, port } } diff --git a/src/smolnetd/scheme/netcfg/mod.rs b/src/smolnetd/scheme/netcfg/mod.rs index d41dee0a44..888f4830e9 100644 --- a/src/smolnetd/scheme/netcfg/mod.rs +++ b/src/smolnetd/scheme/netcfg/mod.rs @@ -158,7 +158,8 @@ fn mk_root_node(iface: Interface, notifier: NotifierRef, dns_config: DNSConfigRe "mac" => { rw [iface, notifier] (Option, None) || { - format!("{}\n", iface.borrow().hardware_addr()) + // format!("{}\n", iface.borrow().hardware_addr()) + String::new() } |cur_value, line| { if cur_value.is_none() { @@ -175,7 +176,7 @@ fn mk_root_node(iface: Interface, notifier: NotifierRef, dns_config: DNSConfigRe } |cur_value| { if let Some(mac) = *cur_value { - iface.borrow_mut().set_hardware_addr(smoltcp::wire::HardwareAddress::Ethernet(mac)); + // iface.borrow_mut().set_hardware_addr(smoltcp::wire::HardwareAddress::Ethernet(mac)); notifier.borrow_mut().schedule_notify("ifaces/eth0/mac"); } Ok(()) diff --git a/src/smolnetd/scheme/socket.rs b/src/smolnetd/scheme/socket.rs index c40dda1406..45c64cfeeb 100644 --- a/src/smolnetd/scheme/socket.rs +++ b/src/smolnetd/scheme/socket.rs @@ -19,12 +19,18 @@ use syscall::{ }; use super::Interface; +use crate::router::route_table::RouteTable; use crate::scheme::smoltcp::iface::SocketHandle; use redox_netstack::error::{Error, Result}; use smoltcp::socket::AnySocket; use super::{post_fevent, SocketSet}; +pub struct Context { + pub iface: Interface, + pub route_table: Rc>, +} + pub struct NullFile { pub flags: usize, pub uid: u32, @@ -192,7 +198,7 @@ where path: &str, uid: u32, data: &mut Self::SchemeDataT, - iface: &Interface, + context: &Context, ) -> SyscallResult<(SocketHandle, Self::DataT)>; fn close_file( @@ -231,7 +237,7 @@ where nulls: BTreeMap, files: BTreeMap>, ref_counts: BTreeMap, - iface: Interface, + context: Context, socket_set: Rc>, scheme_file: File, wait_queue: WaitQueue, @@ -245,13 +251,13 @@ where { pub fn new( iface: Interface, + route_table: Rc>, socket_set: Rc>, scheme_file: File, ) -> SocketScheme { SocketScheme { next_fd: 1, nulls: BTreeMap::new(), - iface, files: BTreeMap::new(), ref_counts: BTreeMap::new(), socket_set, @@ -259,6 +265,7 @@ where scheme_file, wait_queue: Vec::new(), _phantom_socket: PhantomData, + context: Context { iface, route_table }, } } @@ -514,7 +521,7 @@ where path, uid, &mut self.scheme_data, - &self.iface, + &self.context, )?; let file = SchemeFile::Socket(SocketFile { @@ -606,7 +613,12 @@ where SchemeFile::Socket(ref mut file) => { let mut socket_set = self.socket_set.borrow_mut(); let socket = socket_set.get_mut::(file.socket_handle); - return SocketT::write_buf(socket, file, buf); + let ret = SocketT::write_buf(socket, file, buf); + match ret { + Ok(None) => {} + _ => file.write_notified = false, + } + return ret; } } }; @@ -626,7 +638,14 @@ where SchemeFile::Socket(ref mut file) => { let mut socket_set = self.socket_set.borrow_mut(); let socket = socket_set.get_mut::(file.socket_handle); - return SocketT::read_buf(socket, file, buf); + + let ret = SocketT::read_buf(socket, file, buf); + match ret { + Ok(None) => {} + _ => file.read_notified = false + } + + return ret; } } }; diff --git a/src/smolnetd/scheme/tcp.rs b/src/smolnetd/scheme/tcp.rs index e5cf327dfe..5f9f9a3c26 100644 --- a/src/smolnetd/scheme/tcp.rs +++ b/src/smolnetd/scheme/tcp.rs @@ -6,8 +6,8 @@ use std::str; use syscall; use syscall::{Error as SyscallError, Result as SyscallResult}; -use super::socket::{DupResult, SchemeFile, SchemeSocket, SocketFile, SocketScheme}; -use super::{parse_endpoint, Interface, SocketSet}; +use super::socket::{Context, DupResult, SchemeFile, SchemeSocket, SocketFile, SocketScheme}; +use super::{parse_endpoint, SocketSet}; use crate::port_set::PortSet; pub type TcpScheme = SocketScheme>; @@ -62,7 +62,7 @@ impl<'a> SchemeSocket for TcpSocket<'a> { path: &str, uid: u32, port_set: &mut Self::SchemeDataT, - iface: &Interface, + context: &Context, ) -> SyscallResult<(SocketHandle, Self::DataT)> { trace!("TCP open {}", path); let mut parts = path.split('/'); @@ -92,10 +92,27 @@ impl<'a> SchemeSocket for TcpSocket<'a> { let tcp_socket = socket_set.get_mut::(socket_handle); let listen_enpoint = if remote_endpoint.is_specified() { + let local_endpoint_addr = match local_endpoint.addr { + Some(addr) if !addr.is_unspecified() => Some(addr), + _ => { + let route_table = context.route_table.borrow(); + let addr = route_table + .lookup_src_addr(&remote_endpoint.addr.expect("Checked in is_specified")); + if matches!(addr, None) { + error!("Opening a TCP connection with a probably invalid source IP as no route have been found for destination: {}", remote_endpoint); + } + addr + } + }; + let local_endpoint = IpListenEndpoint { + addr: local_endpoint_addr, + port: local_endpoint.port, + }; + trace!("Connecting tcp {} {}", local_endpoint, remote_endpoint); tcp_socket .connect( - iface.borrow_mut().context(), + context.iface.borrow_mut().context(), IpEndpoint::new(remote_endpoint.addr.unwrap(), remote_endpoint.port), local_endpoint, ) @@ -264,11 +281,13 @@ impl<'a> SchemeSocket for TcpSocket<'a> { data: Some(endpoint), .. }), - ) => if endpoint.is_specified() { - write!(&mut path, "{}", endpoint).unwrap() - } else { - write!(&mut path, "0.0.0.0:{}", endpoint.port).unwrap() - }, + ) => { + if endpoint.is_specified() { + write!(&mut path, "{}", endpoint).unwrap() + } else { + write!(&mut path, "0.0.0.0:{}", endpoint.port).unwrap() + } + } _ => path.push_str(unspecified), } trace!("fpath: {}", path); diff --git a/src/smolnetd/scheme/udp.rs b/src/smolnetd/scheme/udp.rs index 4f0ce8ccd8..a36636b029 100644 --- a/src/smolnetd/scheme/udp.rs +++ b/src/smolnetd/scheme/udp.rs @@ -5,9 +5,9 @@ use std::str; use syscall::{Error as SyscallError, Result as SyscallResult}; use syscall; -use crate::device::NetworkDevice; use crate::port_set::PortSet; -use super::socket::{DupResult, SchemeFile, SchemeSocket, SocketFile, SocketScheme}; +use crate::router::Router; +use super::socket::{DupResult, SchemeFile, SchemeSocket, SocketFile, SocketScheme, Context}; use super::{parse_endpoint, Smolnetd, SocketSet, Interface}; pub type UdpScheme = SocketScheme>; @@ -62,7 +62,7 @@ impl<'a> SchemeSocket for UdpSocket<'a> { path: &str, uid: u32, port_set: &mut Self::SchemeDataT, - _iface: &Interface + _context: &Context ) -> SyscallResult<(SocketHandle, Self::DataT)> { let mut parts = path.split('/'); let remote_endpoint = parse_endpoint(parts.next().unwrap_or("")); @@ -74,11 +74,11 @@ impl<'a> SchemeSocket for UdpSocket<'a> { let rx_buffer = UdpSocketBuffer::new( vec![UdpPacketMetadata::EMPTY; Smolnetd::SOCKET_BUFFER_SIZE], - vec![0; NetworkDevice::MTU * Smolnetd::SOCKET_BUFFER_SIZE] + vec![0; Router::MTU * Smolnetd::SOCKET_BUFFER_SIZE] ); let tx_buffer = UdpSocketBuffer::new( vec![UdpPacketMetadata::EMPTY; Smolnetd::SOCKET_BUFFER_SIZE], - vec![0; NetworkDevice::MTU * Smolnetd::SOCKET_BUFFER_SIZE] + vec![0; Router::MTU * Smolnetd::SOCKET_BUFFER_SIZE] ); let udp_socket = UdpSocket::new(rx_buffer, tx_buffer); From 270419f82c5cce5e2ebedcd802ed396eb19661b7 Mon Sep 17 00:00:00 2001 From: Gartox Date: Mon, 4 Sep 2023 11:37:43 +0200 Subject: [PATCH 123/155] Fix ping latency --- src/smolnetd/router/mod.rs | 7 +------ src/smolnetd/scheme/mod.rs | 2 ++ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/smolnetd/router/mod.rs b/src/smolnetd/router/mod.rs index c72331948d..50e8fd84c1 100644 --- a/src/smolnetd/router/mod.rs +++ b/src/smolnetd/router/mod.rs @@ -42,11 +42,6 @@ impl Router { pub const MTU: usize = 1486; pub fn poll(&mut self, now: Instant) { - self.dispatch_outgoing(now); - self.process_incoming(now); - } - - fn process_incoming(&mut self, now: Instant) { for dev in self.devices.borrow_mut().iter_mut() { if self.rx_buffer.is_full() { break; @@ -69,7 +64,7 @@ impl Router { } } - fn dispatch_outgoing(&mut self, now: Instant) { + pub fn dispatch(&mut self, now: Instant) { while let Ok(((), packet)) = self.tx_buffer.dequeue() { if let Ok(mut packet) = smoltcp::wire::Ipv4Packet::new_checked(packet) { let dst_addr = IpAddress::Ipv4(packet.dst_addr()); diff --git a/src/smolnetd/scheme/mod.rs b/src/smolnetd/scheme/mod.rs index b0e01f9ddd..8fc8ff52b0 100644 --- a/src/smolnetd/scheme/mod.rs +++ b/src/smolnetd/scheme/mod.rs @@ -259,6 +259,8 @@ impl Smolnetd { // TODO: Check what if the bool returned by poll can be useful iface.poll(timestamp, &mut self.router_device, &mut socket_set); + self.router_device.get_mut().dispatch(timestamp); + match iface.poll_delay(timestamp, &socket_set) { Some(delay) if delay == Duration::ZERO => {} Some(delay) => break ::std::cmp::min(MAX_DURATION, delay), From c89d82100cc335ca919c6a99d26928c1e8b0001e Mon Sep 17 00:00:00 2001 From: Gartox Date: Mon, 4 Sep 2023 11:55:54 +0200 Subject: [PATCH 124/155] Add `can_recv` to LinkDevice This allow polling faster when there is still packets to be received --- src/smolnetd/link/ethernet.rs | 5 +++++ src/smolnetd/link/loopback.rs | 4 ++++ src/smolnetd/link/mod.rs | 3 +++ src/smolnetd/router/mod.rs | 8 ++++++++ src/smolnetd/scheme/mod.rs | 12 +++++++----- 5 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/smolnetd/link/ethernet.rs b/src/smolnetd/link/ethernet.rs index 13e916cc25..69732fa935 100644 --- a/src/smolnetd/link/ethernet.rs +++ b/src/smolnetd/link/ethernet.rs @@ -352,4 +352,9 @@ impl LinkDevice for EthernetLink { fn name(&self) -> &Rc { &self.name } + + fn can_recv(&self) -> bool { + // We don't buffer any packets so we can't receive immediatly + false + } } diff --git a/src/smolnetd/link/loopback.rs b/src/smolnetd/link/loopback.rs index ff2bf019bf..6e9ff4450d 100644 --- a/src/smolnetd/link/loopback.rs +++ b/src/smolnetd/link/loopback.rs @@ -42,4 +42,8 @@ impl LinkDevice for LoopbackDevice { fn name(&self) -> &std::rc::Rc { &self.name } + + fn can_recv(&self) -> bool { + !self.buffer.is_empty() + } } diff --git a/src/smolnetd/link/mod.rs b/src/smolnetd/link/mod.rs index e550ef1b6e..8c4a9095a4 100644 --- a/src/smolnetd/link/mod.rs +++ b/src/smolnetd/link/mod.rs @@ -21,6 +21,9 @@ pub trait LinkDevice { /// Returns the LinkDevice display name used to refer to it and for lookups fn name(&self) -> &Rc; + + /// Returns wether this device have packets pending + fn can_recv(&self) -> bool; } #[derive(Default)] diff --git a/src/smolnetd/router/mod.rs b/src/smolnetd/router/mod.rs index 50e8fd84c1..40a360ecf0 100644 --- a/src/smolnetd/router/mod.rs +++ b/src/smolnetd/router/mod.rs @@ -41,6 +41,14 @@ impl Router { pub const MTU: usize = 1486; + pub fn can_recv(&self) -> bool { + let mut can_recv = false; + for dev in self.devices.borrow().iter() { + can_recv |= dev.can_recv(); + } + can_recv + } + pub fn poll(&mut self, now: Instant) { for dev in self.devices.borrow_mut().iter_mut() { if self.rx_buffer.is_full() { diff --git a/src/smolnetd/scheme/mod.rs b/src/smolnetd/scheme/mod.rs index 8fc8ff52b0..f610879f50 100644 --- a/src/smolnetd/scheme/mod.rs +++ b/src/smolnetd/scheme/mod.rs @@ -261,11 +261,13 @@ impl Smolnetd { self.router_device.get_mut().dispatch(timestamp); - match iface.poll_delay(timestamp, &socket_set) { - Some(delay) if delay == Duration::ZERO => {} - Some(delay) => break ::std::cmp::min(MAX_DURATION, delay), - None => break MAX_DURATION, - }; + if !self.router_device.get_ref().can_recv() { + match iface.poll_delay(timestamp, &socket_set) { + Some(delay) if delay == Duration::ZERO => {} + Some(delay) => break ::std::cmp::min(MAX_DURATION, delay), + None => break MAX_DURATION, + }; + } } }; From 78a035f0eadb837392f5aff34b6644d1d04a51cb Mon Sep 17 00:00:00 2001 From: Gartox Date: Mon, 4 Sep 2023 12:22:55 +0200 Subject: [PATCH 125/155] Fix TCP accept and accept packet from null mac address --- src/smolnetd/link/ethernet.rs | 7 ++++++- src/smolnetd/scheme/tcp.rs | 5 +---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/smolnetd/link/ethernet.rs b/src/smolnetd/link/ethernet.rs index 69732fa935..b008c01434 100644 --- a/src/smolnetd/link/ethernet.rs +++ b/src/smolnetd/link/ethernet.rs @@ -31,6 +31,8 @@ enum ArpState { type PacketBuffer = smoltcp::storage::PacketBuffer<'static, IpAddress>; +const EMPTY_MAC: EthernetAddress = EthernetAddress([0;6]); + pub struct EthernetLink { name: Rc, neighbor_cache: BTreeMap, @@ -333,11 +335,14 @@ impl LinkDevice for EthernetLink { continue; }; - if !repr.dst_addr.is_broadcast() && repr.dst_addr != self.hardware_address { + // We let EMPTY_MAC pass because somehow this is the mac used when net=redir is used + if !repr.dst_addr.is_broadcast() && repr.dst_addr != EMPTY_MAC && repr.dst_addr != self.hardware_address { // Drop packets which are not for us continue; } + error!("Incomming packet {}, {}", repr.dst_addr, repr.ethertype); + match repr.ethertype { EthernetProtocol::Ipv4 => { self.input_buffer = input_buffer; diff --git a/src/smolnetd/scheme/tcp.rs b/src/smolnetd/scheme/tcp.rs index 5f9f9a3c26..9d3dbb0425 100644 --- a/src/smolnetd/scheme/tcp.rs +++ b/src/smolnetd/scheme/tcp.rs @@ -226,10 +226,7 @@ impl<'a> SchemeSocket for TcpSocket<'a> { { let tcp_socket = socket_set.get_mut::(new_socket_handle); tcp_socket - .listen( - local_endpoint - .expect("Socket was active so local endpoint must be set"), - ) + .listen(listen_enpoint) .expect("Can't listen on local endpoint"); } // We got a new connection to the socket so acquire the port From c03a446b7abf25899a4ed1528a3c265d789f4efe Mon Sep 17 00:00:00 2001 From: Gartox Date: Mon, 4 Sep 2023 12:24:29 +0200 Subject: [PATCH 126/155] Change log level --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 50e95a2aa1..4f4ef1b4b5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,7 @@ dns-parser = "0.7.1" [dependencies.log] version = "0.4" default-features = false -features = ["release_max_level_debug"] +features = ["release_max_level_warn"] [dependencies.smoltcp] version = "0.10.0" From f1f170835e36a44dc42eead3163e68a0b9b0f842 Mon Sep 17 00:00:00 2001 From: Gartox Date: Mon, 4 Sep 2023 12:27:00 +0200 Subject: [PATCH 127/155] Remove debug print --- src/smolnetd/link/ethernet.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/smolnetd/link/ethernet.rs b/src/smolnetd/link/ethernet.rs index b008c01434..4d057956aa 100644 --- a/src/smolnetd/link/ethernet.rs +++ b/src/smolnetd/link/ethernet.rs @@ -341,8 +341,6 @@ impl LinkDevice for EthernetLink { continue; } - error!("Incomming packet {}, {}", repr.dst_addr, repr.ethertype); - match repr.ethertype { EthernetProtocol::Ipv4 => { self.input_buffer = input_buffer; From 2645eeadb4464bc0d644ed9bc64bd3abf066b523 Mon Sep 17 00:00:00 2001 From: Gartox Date: Thu, 7 Sep 2023 22:03:13 +0200 Subject: [PATCH 128/155] Change netcfg to adapt to the new router --- src/smolnetd/link/ethernet.rs | 86 +++++--- src/smolnetd/link/loopback.rs | 17 ++ src/smolnetd/link/mod.rs | 8 +- src/smolnetd/router/mod.rs | 1 + src/smolnetd/router/route_table.rs | 44 ++++ src/smolnetd/scheme/mod.rs | 35 +-- src/smolnetd/scheme/netcfg/mod.rs | 329 +++++++++++++++-------------- 7 files changed, 309 insertions(+), 211 deletions(-) diff --git a/src/smolnetd/link/ethernet.rs b/src/smolnetd/link/ethernet.rs index 4d057956aa..111569aee9 100644 --- a/src/smolnetd/link/ethernet.rs +++ b/src/smolnetd/link/ethernet.rs @@ -8,7 +8,7 @@ use smoltcp::storage::PacketMetadata; use smoltcp::time::{Duration, Instant}; use smoltcp::wire::{ ArpOperation, ArpPacket, ArpRepr, EthernetAddress, EthernetFrame, EthernetProtocol, - EthernetRepr, IpAddress, Ipv4Address, Ipv4Cidr, + EthernetRepr, IpAddress, IpCidr, Ipv4Address, Ipv4Cidr, }; use super::LinkDevice; @@ -31,7 +31,7 @@ enum ArpState { type PacketBuffer = smoltcp::storage::PacketBuffer<'static, IpAddress>; -const EMPTY_MAC: EthernetAddress = EthernetAddress([0;6]); +const EMPTY_MAC: EthernetAddress = EthernetAddress([0; 6]); pub struct EthernetLink { name: Rc, @@ -41,8 +41,8 @@ pub struct EthernetLink { input_buffer: Vec, output_buffer: Vec, network_file: File, - hardware_address: EthernetAddress, - ip_address: Ipv4Cidr, + hardware_address: Option, + ip_address: Option, } impl EthernetLink { @@ -54,12 +54,7 @@ impl EthernetLink { const NEIGHBOR_LIVE_TIME: Duration = Duration::from_secs(60); const ARP_SILENCE_TIME: Duration = Duration::from_secs(1); - pub fn new( - name: &str, - network_file: File, - hardware_address: EthernetAddress, - ip_address: Ipv4Cidr, - ) -> Self { + pub fn new(name: &str, network_file: File) -> Self { let waiting_packets = PacketBuffer::new( vec![PacketMetadata::EMPTY; Self::MAX_WAITING_PACKET_COUNT], vec![0u8; Self::WAITING_PACKET_BUFFER_SIZE], @@ -69,8 +64,8 @@ impl EthernetLink { name: name.into(), network_file, waiting_packets, - hardware_address, - ip_address, + hardware_address: None, + ip_address: None, input_buffer: vec![0u8; Self::MTU], output_buffer: Vec::with_capacity(Self::MTU), arp_state: Default::default(), @@ -82,8 +77,12 @@ impl EthernetLink { where F: FnOnce(&mut [u8]), { + let Some(hardware_address) = self.hardware_address else { + return; + }; + let repr = EthernetRepr { - src_addr: self.hardware_address, + src_addr: hardware_address, dst_addr: dst, ethertype: proto, }; @@ -104,6 +103,14 @@ impl EthernetLink { } fn process_arp(&mut self, packet: &[u8], now: Instant) { + let Some(hardware_address) = self.hardware_address else { + return; + }; + + let Some(ip_addr) = self.ip_address else { + return; + }; + let Ok(repr) = ArpPacket::new_checked(packet).and_then(|packet| ArpRepr::parse(&packet)) else { debug!("Dropped incomming arp packet on {} (Malformed)", self.name); return; @@ -117,7 +124,7 @@ impl EthernetLink { target_hardware_addr, target_protocol_addr, } => { - if self.hardware_address != target_hardware_addr { + if hardware_address != target_hardware_addr { // Only process packet that are for us return; } @@ -129,8 +136,8 @@ impl EthernetLink { if !source_hardware_addr.is_unicast() || !source_protocol_addr.is_unicast() { return; } - - if !self.ip_address.contains_addr(&target_protocol_addr) { + + if !ip_addr.contains_addr(&target_protocol_addr) { return; } @@ -145,8 +152,8 @@ impl EthernetLink { if let ArpOperation::Request = operation { let response = ArpRepr::EthernetIpv4 { operation: ArpOperation::Reply, - source_hardware_addr: self.hardware_address, - source_protocol_addr: self.ip_address.address(), + source_hardware_addr: hardware_address, + source_protocol_addr: ip_addr.address(), target_hardware_addr: source_hardware_addr, target_protocol_addr: source_protocol_addr, }; @@ -246,6 +253,14 @@ impl EthernetLink { } fn send_arp(&mut self, now: Instant) { + let Some(hardware_address) = self.hardware_address else { + return; + }; + + let Some(ip_address) = self.ip_address else { + return; + }; + match self.arp_state { ArpState::Discovered => {} ArpState::Discovering { silent_until, .. } if silent_until > now => {} @@ -259,8 +274,8 @@ impl EthernetLink { } => { let arp_repr = ArpRepr::EthernetIpv4 { operation: ArpOperation::Request, - source_hardware_addr: self.hardware_address, - source_protocol_addr: self.ip_address.address(), + source_hardware_addr: hardware_address, + source_protocol_addr: ip_address.address(), target_hardware_addr: EthernetAddress::BROADCAST, target_protocol_addr: target, }; @@ -281,10 +296,9 @@ impl EthernetLink { impl LinkDevice for EthernetLink { fn send(&mut self, next_hop: IpAddress, packet: &[u8], now: Instant) { - - let local_broadcast = match self.ip_address.broadcast() { + let local_broadcast = match self.ip_address.and_then(|cidr| cidr.broadcast()) { Some(addr) => IpAddress::Ipv4(addr) == next_hop, - None => false + None => false, }; if local_broadcast || next_hop.is_broadcast() { @@ -317,6 +331,10 @@ impl LinkDevice for EthernetLink { } fn recv(&mut self, now: Instant) -> Option<&[u8]> { + let Some(hardware_address) = self.hardware_address else { + return None; + }; + let mut input_buffer = std::mem::replace(&mut self.input_buffer, Vec::new()); loop { if let Err(e) = self.network_file.read(&mut input_buffer) { @@ -336,7 +354,10 @@ impl LinkDevice for EthernetLink { }; // We let EMPTY_MAC pass because somehow this is the mac used when net=redir is used - if !repr.dst_addr.is_broadcast() && repr.dst_addr != EMPTY_MAC && repr.dst_addr != self.hardware_address { + if !repr.dst_addr.is_broadcast() + && repr.dst_addr != EMPTY_MAC + && repr.dst_addr != hardware_address + { // Drop packets which are not for us continue; } @@ -360,4 +381,21 @@ impl LinkDevice for EthernetLink { // We don't buffer any packets so we can't receive immediatly false } + + fn mac_address(&self) -> Option { + self.hardware_address + } + + fn set_mac_address(&mut self, addr: EthernetAddress) { + self.hardware_address = Some(addr) + } + + fn ip_address(&self) -> Option { + Some(IpCidr::Ipv4(self.ip_address?)) + } + + fn set_ip_address(&mut self, addr: IpCidr) { + let IpCidr::Ipv4(addr) = addr; + self.ip_address = Some(addr); + } } diff --git a/src/smolnetd/link/loopback.rs b/src/smolnetd/link/loopback.rs index 6e9ff4450d..e0cc8c0aff 100644 --- a/src/smolnetd/link/loopback.rs +++ b/src/smolnetd/link/loopback.rs @@ -46,4 +46,21 @@ impl LinkDevice for LoopbackDevice { fn can_recv(&self) -> bool { !self.buffer.is_empty() } + + fn mac_address(&self) -> Option { + None + } + + fn set_mac_address(&mut self, _addr: smoltcp::wire::EthernetAddress) { + } + + fn ip_address(&self) -> Option { + Some("127.0.0.1/8".parse().unwrap()) + } + + fn set_ip_address(&mut self, _addr: smoltcp::wire::IpCidr) { + todo!() + } + + } diff --git a/src/smolnetd/link/mod.rs b/src/smolnetd/link/mod.rs index 8c4a9095a4..bf135a36a3 100644 --- a/src/smolnetd/link/mod.rs +++ b/src/smolnetd/link/mod.rs @@ -4,7 +4,7 @@ pub mod ethernet; use std::rc::Rc; use smoltcp::time::Instant; -use smoltcp::wire::IpAddress; +use smoltcp::wire::{IpAddress, EthernetAddress, IpCidr}; /// Represent a link layer device (eth0, loopback...) pub trait LinkDevice { @@ -24,6 +24,12 @@ pub trait LinkDevice { /// Returns wether this device have packets pending fn can_recv(&self) -> bool; + + fn mac_address(&self) -> Option; + fn set_mac_address(&mut self, addr: EthernetAddress); + + fn ip_address(&self) -> Option; + fn set_ip_address(&mut self, addr: IpCidr); } #[derive(Default)] diff --git a/src/smolnetd/router/mod.rs b/src/smolnetd/router/mod.rs index 40a360ecf0..d639edbe4e 100644 --- a/src/smolnetd/router/mod.rs +++ b/src/smolnetd/router/mod.rs @@ -102,6 +102,7 @@ impl Router { let IpAddress::Ipv4(src) = rule.src; if src != packet.src_addr() { + error!("Changed packet source {} -> {}", packet.src_addr(), src); packet.set_src_addr(src); packet.fill_checksum() } diff --git a/src/smolnetd/router/route_table.rs b/src/smolnetd/router/route_table.rs index e51127720a..51943c932f 100644 --- a/src/smolnetd/router/route_table.rs +++ b/src/smolnetd/router/route_table.rs @@ -1,3 +1,4 @@ +use std::fmt::Display; use std::rc::Rc; use smoltcp::wire::{IpAddress, IpCidr}; @@ -21,6 +22,25 @@ impl Rule { } } +impl Display for Rule { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + if self.filter.prefix_len() == 0 { + write!(f, "default")?; + } else { + write!(f, "{} ", self.filter)?; + } + + if let Some(via) = self.via { + write!(f, " via {}", via)?; + } + + write!(f, " dev {}", self.dev)?; + write!(f, " src {}", self.src)?; + + Ok(()) + } +} + #[derive(Debug, Default)] pub struct RouteTable { rules: Vec, @@ -42,6 +62,10 @@ impl RouteTable { self.lookup_rule(dst)?.via } + pub fn lookup_device(&self, dst: &IpAddress) -> Option> { + Some(self.lookup_rule(dst)?.dev.clone()) + } + pub fn insert_rule(&mut self, new_rule: Rule) { let i = match self .rules @@ -52,4 +76,24 @@ impl RouteTable { }; self.rules.insert(i, new_rule); } + + pub fn remove_rule(&mut self, filter: IpCidr) { + self.rules.retain(|rule| rule.filter != filter); + } + + pub fn change_src(&mut self, old_src: IpAddress, new_src: IpAddress) { + for rule in self.rules.iter_mut().filter(|rule| rule.src == old_src) { + rule.src = new_src; + } + } +} + +impl Display for RouteTable { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + for rule in self.rules.iter() { + writeln!(f, "{}", rule)?; + } + + Ok(()) + } } diff --git a/src/smolnetd/scheme/mod.rs b/src/smolnetd/scheme/mod.rs index f610879f50..1637b51e4e 100644 --- a/src/smolnetd/scheme/mod.rs +++ b/src/smolnetd/scheme/mod.rs @@ -80,10 +80,7 @@ impl Smolnetd { ) -> Smolnetd { let hardware_addr = EthernetAddress::from_str(getcfg("mac").unwrap().trim()) .expect("Can't parse the 'mac' cfg"); - let local_ip = - IpAddress::from_str(getcfg("ip").unwrap().trim()).expect("Can't parse the 'ip' cfg."); let protocol_addrs = vec![ - IpCidr::new(local_ip, 24), IpCidr::new(IpAddress::v4(127, 0, 0, 1), 8), ]; @@ -119,27 +116,12 @@ impl Smolnetd { "127.0.0.1".parse().unwrap(), )); - let IpAddress::Ipv4(local_ip) = local_ip; - let eth0 = EthernetLink::new( + + let mut eth0 = EthernetLink::new( "eth0", network_file, - hardware_addr, - Ipv4Cidr::new(local_ip, 24), ); - - route_table.borrow_mut().insert_rule(Rule::new( - IpCidr::new(IpAddress::Ipv4(local_ip), 24), - None, - Rc::clone(eth0.name()), - IpAddress::Ipv4(local_ip), - )); - - route_table.borrow_mut().insert_rule(Rule::new( - "0.0.0.0/0".parse().unwrap(), - Some(IpAddress::Ipv4(default_gw)), - Rc::clone(eth0.name()), - IpAddress::Ipv4(local_ip), - )); + eth0.set_mac_address(hardware_addr); devices.borrow_mut().push(loopback); devices.borrow_mut().push(eth0); @@ -150,7 +132,7 @@ impl Smolnetd { route_table: Rc::clone(&route_table), socket_set: Rc::clone(&socket_set), timer: ::std::time::Instant::now(), - link_devices: devices, + link_devices: Rc::clone(&devices), time_file, ip_scheme: IpScheme::new( Rc::clone(&iface), @@ -176,7 +158,12 @@ impl Smolnetd { Rc::clone(&socket_set), icmp_file, ), - netcfg_scheme: NetCfgScheme::new(Rc::clone(&iface), netcfg_file), + netcfg_scheme: NetCfgScheme::new( + Rc::clone(&iface), + netcfg_file, + Rc::clone(&route_table), + Rc::clone(&devices), + ), input_queue, buffer_pool, } @@ -267,7 +254,7 @@ impl Smolnetd { Some(delay) => break ::std::cmp::min(MAX_DURATION, delay), None => break MAX_DURATION, }; - } + } } }; diff --git a/src/smolnetd/scheme/netcfg/mod.rs b/src/smolnetd/scheme/netcfg/mod.rs index 888f4830e9..d95b24a9f9 100644 --- a/src/smolnetd/scheme/netcfg/mod.rs +++ b/src/smolnetd/scheme/netcfg/mod.rs @@ -2,24 +2,30 @@ mod nodes; mod notifier; -use smoltcp::wire::{IpAddress, EthernetAddress, IpCidr, Ipv4Address}; +use smoltcp::wire::{EthernetAddress, IpAddress, IpCidr, Ipv4Address, Ipv4Cidr}; use std::cell::RefCell; use std::collections::BTreeMap; use std::fs::File; use std::io::{ErrorKind, Read, Write}; -use std::rc::Rc; use std::mem; -use std::str::FromStr; +use std::rc::Rc; use std::str; +use std::str::FromStr; +use syscall; use syscall::data::Stat; use syscall::flag::{MODE_DIR, MODE_FILE}; -use syscall::{Error as SyscallError, EventFlags as SyscallEventFlags, Packet as SyscallPacket, Result as SyscallResult, SchemeMut}; -use syscall; +use syscall::{ + Error as SyscallError, EventFlags as SyscallEventFlags, Packet as SyscallPacket, + Result as SyscallResult, SchemeMut, +}; + +use crate::link::DeviceList; +use crate::router::route_table::{self, RouteTable, Rule}; use self::nodes::*; use self::notifier::*; -use redox_netstack::error::{Error, Result}; use super::{post_fevent, Interface}; +use redox_netstack::error::{Error, Result}; const WRITE_BUFFER_MAX_SIZE: usize = 0xffff; @@ -28,27 +34,44 @@ fn gateway_cidr() -> IpCidr { IpCidr::new(IpAddress::v4(0, 0, 0, 0), 0) } -fn parse_default_gw(value: &str) -> SyscallResult { - let mut routes = value.lines(); - if let Some(route) = routes.next() { - if !routes.next().is_none() { - return Err(SyscallError::new(syscall::EINVAL)); - } - let mut words = route.split_whitespace(); - if let Some("default") = words.next() { - if let Some("via") = words.next() { - if let Some(ip) = words.next() { - return Ipv4Address::from_str(ip) - .map_err(|_| SyscallError::new(syscall::EINVAL)); - } - } - } +fn parse_route(value: &str, route_table: &RouteTable) -> SyscallResult { + let mut parts = value.split_whitespace(); + let cidr_str = parts.next().ok_or(SyscallError::new(syscall::EINVAL))?; + let cidr = match cidr_str { + "default" => gateway_cidr(), + cidr_str => cidr_str + .parse() + .map_err(|_| SyscallError::new(syscall::EINVAL))?, + }; + + let via: IpAddress = match parts.next().ok_or(SyscallError::new(syscall::EINVAL))? { + "via" => parts + .next() + .ok_or(SyscallError::new(syscall::EINVAL))? + .parse() + .map_err(|_| SyscallError::new(syscall::EINVAL))?, + _ => return Err(SyscallError::new(syscall::EINVAL)), + }; + + if !via.is_unicast() { + return Err(SyscallError::new(syscall::EINVAL)); } - Err(SyscallError::new(syscall::EINVAL)) + + let rule = route_table + .lookup_rule(&via) + .ok_or(SyscallError::new(syscall::EINVAL))?; + + Ok(Rule::new(cidr, Some(via), rule.dev.clone(), rule.src)) } -fn mk_root_node(iface: Interface, notifier: NotifierRef, dns_config: DNSConfigRef) -> CfgNodeRef { - cfg_node!{ +fn mk_root_node( + iface: Interface, + notifier: NotifierRef, + dns_config: DNSConfigRef, + route_table: Rc>, + devices: Rc>, +) -> CfgNodeRef { + cfg_node! { "resolv" => { "nameserver" => { rw [dns_config, notifier] (Option, None) @@ -79,37 +102,24 @@ fn mk_root_node(iface: Interface, notifier: NotifierRef, dns_config: DNSConfigRe }, "route" => { "list" => { - ro [iface] || { - let mut gateway = None; - iface.borrow_mut().routes_mut().update(|map| { - gateway = map.iter().find(|route| route.cidr == gateway_cidr()).map(|route| route.via_router) - }); - if let Some(ip) = gateway { - format!("default via {}\n", ip) - } else { - String::new() - } + ro [route_table] || { + format!("{}", route_table.borrow()) } }, "add" => { - wo [iface, notifier] (Option, None) + wo [iface, notifier, route_table] (Option, None) |cur_value, line| { if cur_value.is_none() { - let default_gw = parse_default_gw(line)?; - if !default_gw.is_unicast() { - return Err(SyscallError::new(syscall::EINVAL)); - } - *cur_value = Some(default_gw); + let route = parse_route(line, &route_table.borrow())?; + *cur_value = Some(route); Ok(()) } else { Err(SyscallError::new(syscall::EINVAL)) } } |cur_value| { - if let Some(default_gw) = *cur_value { - if iface.borrow_mut().routes_mut().add_default_ipv4_route(default_gw).is_err() { - return Err(SyscallError::new(syscall::EINVAL)); - } + if let Some(route) = cur_value.take() { + route_table.borrow_mut().insert_rule(route); notifier.borrow_mut().schedule_notify("route/list"); Ok(()) } else { @@ -118,35 +128,25 @@ fn mk_root_node(iface: Interface, notifier: NotifierRef, dns_config: DNSConfigRe } }, "rm" => { - wo [iface, notifier] (Option, None) + wo [iface, notifier, route_table] (Option, None) |cur_value, line| { if cur_value.is_none() { - let default_gw = parse_default_gw(line)?; - if !default_gw.is_unicast() { - return Err(SyscallError::new(syscall::EINVAL)); + match line.parse() { + Ok(cidr) => { + *cur_value = Some(cidr); + Ok(()) + } + Err(_) => Err(SyscallError::new(syscall::EINVAL)) } - *cur_value = Some(default_gw); - Ok(()) } else { Err(SyscallError::new(syscall::EINVAL)) } } |cur_value| { - if let Some(default_gw) = *cur_value { - let mut iface = iface.borrow_mut(); - let mut gateway = None; - iface.routes_mut().update(|map| { - gateway = map.iter().find(|route| route.cidr == gateway_cidr()).map(|route| route.via_router) - }); - match gateway { - None => Err(SyscallError::new(syscall::EINVAL)), - Some(addr) if addr != IpAddress::Ipv4(default_gw) => Err(SyscallError::new(syscall::EINVAL)), - Some(_) => { - iface.routes_mut().remove_default_ipv4_route(); - notifier.borrow_mut().schedule_notify("route/list"); - Ok(()) - } - } + if let Some(cidr) = *cur_value { + route_table.borrow_mut().remove_rule(cidr); + notifier.borrow_mut().schedule_notify("route/list"); + Ok(()) } else { Err(SyscallError::new(syscall::EINVAL)) } @@ -156,10 +156,17 @@ fn mk_root_node(iface: Interface, notifier: NotifierRef, dns_config: DNSConfigRe "ifaces" => { "eth0" => { "mac" => { - rw [iface, notifier] (Option, None) + rw [iface, notifier, devices] (Option, None) || { - // format!("{}\n", iface.borrow().hardware_addr()) - String::new() + match devices.borrow().get("eth0") { + Some(dev) => { + match dev.mac_address() { + Some(addr) => format!("{addr}\n"), + None => "Not configured\n".into(), + } + } + None => "Device not found\n".into(), + } } |cur_value, line| { if cur_value.is_none() { @@ -176,96 +183,76 @@ fn mk_root_node(iface: Interface, notifier: NotifierRef, dns_config: DNSConfigRe } |cur_value| { if let Some(mac) = *cur_value { - // iface.borrow_mut().set_hardware_addr(smoltcp::wire::HardwareAddress::Ethernet(mac)); - notifier.borrow_mut().schedule_notify("ifaces/eth0/mac"); + if let Some(dev) = devices.borrow_mut().get_mut("eth0") { + dev.set_mac_address(mac); + notifier.borrow_mut().schedule_notify("ifaces/eth0/mac"); + } } Ok(()) } }, "addr" => { "list" => { - ro [iface] + ro [devices] || { - let mut ips = String::new(); - for cidr in iface.borrow().ip_addrs() { - ips += &format!("{}\n", cidr); - } - ips + let res = match devices.borrow().get("eth0") { + Some(dev) => { + match dev.ip_address() { + Some(addr) => format!("{addr}\n"), + None => "Not configured\n".into(), + } + } + None => "Device not found\n".into(), + }; + res } }, "set" => { - wo [iface, notifier] (Vec, Vec::new()) + wo [iface, notifier, devices, route_table] (Option, None) |cur_value, line| { - let cidr = IpCidr::from_str(line) - .map_err(|_| SyscallError::new(syscall::EINVAL))?; - if !cidr.address().is_unicast() { - return Err(SyscallError::new(syscall::EINVAL)); - } - cur_value.push(cidr); - Ok(()) - } - |cur_value| { - if !cur_value.is_empty() { - let mut iface = iface.borrow_mut(); - let mut cidrs = vec![]; - mem::swap(cur_value, &mut cidrs); - iface.update_ip_addrs(|s| { - *s = cidrs.into_iter().collect(); - }); - notifier.borrow_mut().schedule_notify("ifaces/eth0/addr/list"); - } - Ok(()) - } - }, - "add" => { - wo [iface, notifier] (Vec, Vec::new()) - |cur_value, line| { - let cidr = IpCidr::from_str(line) - .map_err(|_| SyscallError::new(syscall::EINVAL))?; - if !cidr.address().is_unicast() { - return Err(SyscallError::new(syscall::EINVAL)); - } - cur_value.push(cidr); - Ok(()) - } - |cur_value| { - let mut iface = iface.borrow_mut(); - let mut cidrs = iface.ip_addrs().to_vec(); - for cidr in cur_value { - cidrs.insert(0, *cidr); - } - iface.update_ip_addrs(|s| { - *s = cidrs.into_iter().collect(); - }); - notifier.borrow_mut().schedule_notify("ifaces/eth0/addr/list"); - Ok(()) - } - }, - "rm" => { - wo [iface, notifier] (Vec, Vec::new()) - |cur_value, line| { - let cidr = IpCidr::from_str(line) - .map_err(|_| SyscallError::new(syscall::EINVAL))?; - if !cidr.address().is_unicast() { - return Err(SyscallError::new(syscall::EINVAL)); - } - cur_value.push(cidr); - Ok(()) - } - |cur_value| { - let mut iface = iface.borrow_mut(); - let mut cidrs = iface.ip_addrs().to_vec(); - for cidr in cur_value { - let pre_retain_len = cidrs.len(); - cidrs.retain(|&c| c != *cidr); - if pre_retain_len == cidrs.len() { + if cur_value.is_none() { + let cidr = IpCidr::from_str(line) + .map_err(|_| SyscallError::new(syscall::EINVAL))?; + if !cidr.address().is_unicast() { return Err(SyscallError::new(syscall::EINVAL)); } + *cur_value = Some(cidr); + Ok(()) + } else { + Err(SyscallError::new(syscall::EINVAL)) + } + } + |cur_value| { + // TODO: Multiple IPs + if let Some(cidr) = cur_value.take() { + if let Some(dev) = devices.borrow_mut().get_mut("eth0") { + + let mut route_table = route_table.borrow_mut(); + if let Some(old_addr) = dev.ip_address() { + let IpCidr::Ipv4(old_v4_cidr) = old_addr; + let old_network = IpCidr::Ipv4(old_v4_cidr.network()); + + route_table.remove_rule(old_network); + route_table.change_src(old_addr.address(), cidr.address()); + iface.borrow_mut().update_ip_addrs(|addrs| addrs.retain(|addr| *addr != old_addr)) + } + + dev.set_ip_address(cidr); + // FIXME: Here, the insert 0 is a workaround to let UDP sockets + // work with this interface only. + // Smoltcp takes the first ip address when looking for a source + // ip address when sending UDP packets. + // This behavior will have to be fixed as it's our route table + // job to find give this source. + iface.borrow_mut().update_ip_addrs(|addrs| addrs.insert(0, cidr).unwrap()); + + let IpCidr::Ipv4(v4_cidr) = cidr; + let network_cidr = IpCidr::Ipv4(v4_cidr.network()); + route_table.insert_rule(Rule::new(network_cidr, None, dev.name().clone(), cidr.address())) + } + notifier.borrow_mut().schedule_notify("ifaces/eth0/addr/list"); + notifier.borrow_mut().schedule_notify("route/list"); } - iface.update_ip_addrs(|s| { - *s = cidrs.into_iter().collect(); - }); - notifier.borrow_mut().schedule_notify("ifaces/eth0/addr/list"); Ok(()) } }, @@ -347,7 +334,12 @@ pub struct NetCfgScheme { } impl NetCfgScheme { - pub fn new(iface: Interface, scheme_file: File) -> NetCfgScheme { + pub fn new( + iface: Interface, + scheme_file: File, + route_table: Rc>, + devices: Rc>, + ) -> NetCfgScheme { let notifier = Notifier::new_ref(); let dns_config = Rc::new(RefCell::new(DNSConfig { name_server: Ipv4Address::new(8, 8, 8, 8), @@ -356,7 +348,13 @@ impl NetCfgScheme { scheme_file, next_fd: 1, files: BTreeMap::new(), - root_node: mk_root_node(iface, Rc::clone(¬ifier), dns_config), + root_node: mk_root_node( + iface, + Rc::clone(¬ifier), + dns_config, + route_table, + devices, + ), notifier, } } @@ -368,12 +366,14 @@ impl NetCfgScheme { Ok(0) => { //TODO: Cleanup must occur break Some(()); - }, + } Ok(_) => (), - Err(err) => if err.kind() == ErrorKind::WouldBlock { - break None; - } else { - return Err(Error::from(err)); + Err(err) => { + if err.kind() == ErrorKind::WouldBlock { + break None; + } else { + return Err(Error::from(err)); + } } } self.handle(&mut packet); @@ -416,7 +416,11 @@ impl SchemeMut for NetCfgScheme { is_dir: current_node.is_dir(), is_writable: current_node.is_writable(), is_readable: current_node.is_readable(), - node_writer: if current_node.is_writable() { current_node.new_writer() } else { None }, + node_writer: if current_node.is_writable() { + current_node.new_writer() + } else { + None + }, uid, pos: 0, read_buf, @@ -442,7 +446,8 @@ impl SchemeMut for NetCfgScheme { } fn write(&mut self, fd: usize, buf: &[u8]) -> SyscallResult { - let file = self.files + let file = self + .files .get_mut(&fd) .ok_or_else(|| SyscallError::new(syscall::EBADF))?; @@ -470,7 +475,8 @@ impl SchemeMut for NetCfgScheme { } fn read(&mut self, fd: usize, buf: &mut [u8]) -> SyscallResult { - let file = self.files + let file = self + .files .get_mut(&fd) .ok_or_else(|| SyscallError::new(syscall::EBADF))?; @@ -484,15 +490,12 @@ impl SchemeMut for NetCfgScheme { } fn fstat(&mut self, fd: usize, stat: &mut Stat) -> SyscallResult { - let file = self.files + let file = self + .files .get_mut(&fd) .ok_or_else(|| SyscallError::new(syscall::EBADF))?; - stat.st_mode = if file.is_dir { - MODE_DIR - } else { - MODE_FILE - }; + stat.st_mode = if file.is_dir { MODE_DIR } else { MODE_FILE }; if file.is_writable { stat.st_mode |= 0o222; } @@ -507,7 +510,8 @@ impl SchemeMut for NetCfgScheme { } fn fevent(&mut self, fd: usize, events: SyscallEventFlags) -> SyscallResult { - let file = self.files + let file = self + .files .get_mut(&fd) .ok_or_else(|| SyscallError::new(syscall::EBADF))?; if events.contains(syscall::EVENT_READ) { @@ -519,7 +523,8 @@ impl SchemeMut for NetCfgScheme { } fn fsync(&mut self, fd: usize) -> SyscallResult { - let file = self.files + let file = self + .files .get_mut(&fd) .ok_or_else(|| SyscallError::new(syscall::EBADF))?; From 07431ef9df1d430cb392f5de7253b924348b918c Mon Sep 17 00:00:00 2001 From: Gartox Date: Thu, 7 Sep 2023 22:15:00 +0200 Subject: [PATCH 129/155] Fix warnings --- src/smolnetd/scheme/mod.rs | 16 +--------------- src/smolnetd/scheme/netcfg/mod.rs | 4 ++-- src/smolnetd/scheme/udp.rs | 2 +- 3 files changed, 4 insertions(+), 18 deletions(-) diff --git a/src/smolnetd/scheme/mod.rs b/src/smolnetd/scheme/mod.rs index 1637b51e4e..d27f611fef 100644 --- a/src/smolnetd/scheme/mod.rs +++ b/src/smolnetd/scheme/mod.rs @@ -10,10 +10,9 @@ use smoltcp::iface::{Config, Interface as SmoltcpInterface}; use smoltcp::phy::Tracer; use smoltcp::time::{Duration, Instant}; use smoltcp::wire::{ - EthernetAddress, HardwareAddress, IpAddress, IpCidr, IpListenEndpoint, Ipv4Address, Ipv4Cidr, + EthernetAddress, HardwareAddress, IpAddress, IpCidr, IpListenEndpoint, Ipv4Address, }; use std::cell::RefCell; -use std::collections::VecDeque; use std::fs::File; use std::io::{Read, Write}; use std::mem::size_of; @@ -27,7 +26,6 @@ use self::ip::IpScheme; use self::netcfg::NetCfgScheme; use self::tcp::TcpScheme; use self::udp::UdpScheme; -use crate::buffer_pool::{Buffer, BufferPool}; use redox_netstack::error::{Error, Result}; mod icmp; @@ -46,8 +44,6 @@ const MIN_DURATION: Duration = Duration::from_millis(0); pub struct Smolnetd { router_device: Tracer, iface: Interface, - link_devices: Rc>, - route_table: Rc>, time_file: File, socket_set: Rc>, @@ -58,9 +54,6 @@ pub struct Smolnetd { tcp_scheme: TcpScheme, icmp_scheme: IcmpScheme, netcfg_scheme: NetCfgScheme, - - input_queue: Rc>>, - buffer_pool: Rc>, } impl Smolnetd { @@ -87,9 +80,6 @@ impl Smolnetd { let default_gw = Ipv4Address::from_str(getcfg("ip_router").unwrap().trim()) .expect("Can't parse the 'ip_router' cfg."); - let buffer_pool = Rc::new(RefCell::new(BufferPool::new(Self::MAX_PACKET_SIZE))); - let input_queue = Rc::new(RefCell::new(VecDeque::new())); - let devices = Rc::new(RefCell::new(DeviceList::default())); let route_table = Rc::new(RefCell::new(RouteTable::default())); let mut network_device = Tracer::new( @@ -129,10 +119,8 @@ impl Smolnetd { Smolnetd { iface: Rc::clone(&iface), router_device: network_device, - route_table: Rc::clone(&route_table), socket_set: Rc::clone(&socket_set), timer: ::std::time::Instant::now(), - link_devices: Rc::clone(&devices), time_file, ip_scheme: IpScheme::new( Rc::clone(&iface), @@ -164,8 +152,6 @@ impl Smolnetd { Rc::clone(&route_table), Rc::clone(&devices), ), - input_queue, - buffer_pool, } } diff --git a/src/smolnetd/scheme/netcfg/mod.rs b/src/smolnetd/scheme/netcfg/mod.rs index d95b24a9f9..76cb8f5b80 100644 --- a/src/smolnetd/scheme/netcfg/mod.rs +++ b/src/smolnetd/scheme/netcfg/mod.rs @@ -2,7 +2,7 @@ mod nodes; mod notifier; -use smoltcp::wire::{EthernetAddress, IpAddress, IpCidr, Ipv4Address, Ipv4Cidr}; +use smoltcp::wire::{EthernetAddress, IpAddress, IpCidr, Ipv4Address}; use std::cell::RefCell; use std::collections::BTreeMap; use std::fs::File; @@ -20,7 +20,7 @@ use syscall::{ }; use crate::link::DeviceList; -use crate::router::route_table::{self, RouteTable, Rule}; +use crate::router::route_table::{RouteTable, Rule}; use self::nodes::*; use self::notifier::*; diff --git a/src/smolnetd/scheme/udp.rs b/src/smolnetd/scheme/udp.rs index a36636b029..0ed4209446 100644 --- a/src/smolnetd/scheme/udp.rs +++ b/src/smolnetd/scheme/udp.rs @@ -8,7 +8,7 @@ use syscall; use crate::port_set::PortSet; use crate::router::Router; use super::socket::{DupResult, SchemeFile, SchemeSocket, SocketFile, SocketScheme, Context}; -use super::{parse_endpoint, Smolnetd, SocketSet, Interface}; +use super::{parse_endpoint, Smolnetd, SocketSet}; pub type UdpScheme = SocketScheme>; From ebd229ae6c4e7bec7d42a0beedb7a049b72c8fe7 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Thu, 7 Sep 2023 20:04:57 -0600 Subject: [PATCH 130/155] Update for new rust --- src/smolnetd/main.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/smolnetd/main.rs b/src/smolnetd/main.rs index 3f1ac9c2d3..9deed0e034 100644 --- a/src/smolnetd/main.rs +++ b/src/smolnetd/main.rs @@ -1,5 +1,3 @@ -#![feature(drain_filter)] - extern crate event; #[macro_use] extern crate log; From 2dcc57863cb73b85397c8e8dfb71e08f953441f7 Mon Sep 17 00:00:00 2001 From: Gartox Date: Mon, 11 Sep 2023 19:54:07 +0200 Subject: [PATCH 131/155] Remove debug log --- src/smolnetd/router/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/smolnetd/router/mod.rs b/src/smolnetd/router/mod.rs index d639edbe4e..40a360ecf0 100644 --- a/src/smolnetd/router/mod.rs +++ b/src/smolnetd/router/mod.rs @@ -102,7 +102,6 @@ impl Router { let IpAddress::Ipv4(src) = rule.src; if src != packet.src_addr() { - error!("Changed packet source {} -> {}", packet.src_addr(), src); packet.set_src_addr(src); packet.fill_checksum() } From 9d5c8207db83ce5ccc0f1961b887658b40a1e56a Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 7 Jan 2024 15:38:15 +0100 Subject: [PATCH 132/155] Try fetching the mac address directly from the network driver --- src/smolnetd/main.rs | 11 +++++++++++ src/smolnetd/scheme/mod.rs | 5 ++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/smolnetd/main.rs b/src/smolnetd/main.rs index 9deed0e034..2651a8c3e8 100644 --- a/src/smolnetd/main.rs +++ b/src/smolnetd/main.rs @@ -12,11 +12,14 @@ use std::fs::File; use std::os::unix::io::{FromRawFd, RawFd}; use std::process; use std::rc::Rc; +use std::str::FromStr; use event::EventQueue; +use netutils::getcfg; use redox_netstack::error::{Error, Result}; use redox_netstack::logger; use scheme::Smolnetd; +use smoltcp::wire::EthernetAddress; mod buffer_pool; mod link; @@ -32,6 +35,13 @@ fn run(daemon: redox_daemon::Daemon) -> Result<()> { .map_err(|e| Error::from_syscall_error(e, "failed to open network:"))? as RawFd; + let hardware_addr = std::fs::read("network:mac") + .map(|mac_address| EthernetAddress::from_bytes(&mac_address)) + .unwrap_or_else(|_| { + EthernetAddress::from_str(getcfg("mac").unwrap().trim()) + .expect("Can't parse the 'mac' cfg") + }); + trace!("opening :ip"); let ip_fd = syscall::open(":ip", O_RDWR | O_CREAT | O_NONBLOCK) .map_err(|e| Error::from_syscall_error(e, "failed to open :ip"))? as RawFd; @@ -75,6 +85,7 @@ fn run(daemon: redox_daemon::Daemon) -> Result<()> { let smolnetd = Rc::new(RefCell::new(Smolnetd::new( network_file, + hardware_addr, ip_file, udp_file, tcp_file, diff --git a/src/smolnetd/scheme/mod.rs b/src/smolnetd/scheme/mod.rs index d27f611fef..2efffc0eea 100644 --- a/src/smolnetd/scheme/mod.rs +++ b/src/smolnetd/scheme/mod.rs @@ -10,7 +10,7 @@ use smoltcp::iface::{Config, Interface as SmoltcpInterface}; use smoltcp::phy::Tracer; use smoltcp::time::{Duration, Instant}; use smoltcp::wire::{ - EthernetAddress, HardwareAddress, IpAddress, IpCidr, IpListenEndpoint, Ipv4Address, + EthernetAddress, HardwareAddress, IpAddress, IpCidr, IpListenEndpoint, Ipv4Address, }; use std::cell::RefCell; use std::fs::File; @@ -64,6 +64,7 @@ impl Smolnetd { pub fn new( network_file: File, + hardware_addr: EthernetAddress, ip_file: File, udp_file: File, tcp_file: File, @@ -71,8 +72,6 @@ impl Smolnetd { time_file: File, netcfg_file: File, ) -> Smolnetd { - let hardware_addr = EthernetAddress::from_str(getcfg("mac").unwrap().trim()) - .expect("Can't parse the 'mac' cfg"); let protocol_addrs = vec![ IpCidr::new(IpAddress::v4(127, 0, 0, 1), 8), ]; From e12a74854c42cb54537d737b6326d51cdbcfdb4f Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 8 Jan 2024 14:10:49 +0100 Subject: [PATCH 133/155] Allow dnsd to create udp sockets This is essential for the functioning of dnsd. --- src/dnsd/main.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/dnsd/main.rs b/src/dnsd/main.rs index 3ba52906f8..ce21854cde 100644 --- a/src/dnsd/main.rs +++ b/src/dnsd/main.rs @@ -47,7 +47,9 @@ fn run(daemon: redox_daemon::Daemon) -> Result<()> { let dnsd = Rc::new(RefCell::new(Dnsd::new(dns_file, time_file, event_queue.file.as_raw_fd()))); - syscall::setrens(0, 0).expect("dnsd: failed to enter null namespace"); + let new_ns = syscall::mkns(&[["udp".as_ptr() as usize, "udp".len()]]) + .expect("dnsd: failed to create namespace"); + syscall::setrens(new_ns, new_ns).expect("dnsd: failed to enter namespace"); daemon.ready().expect("dnsd: failed to notify parent"); From 674f5b6d772c3d292420016d06eedab96e28f06e Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 28 Feb 2024 09:39:19 +0100 Subject: [PATCH 134/155] Always use the mac handle of the network scheme instead of the mac config --- src/smolnetd/main.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/smolnetd/main.rs b/src/smolnetd/main.rs index 2651a8c3e8..36a34dffbd 100644 --- a/src/smolnetd/main.rs +++ b/src/smolnetd/main.rs @@ -12,10 +12,8 @@ use std::fs::File; use std::os::unix::io::{FromRawFd, RawFd}; use std::process; use std::rc::Rc; -use std::str::FromStr; use event::EventQueue; -use netutils::getcfg; use redox_netstack::error::{Error, Result}; use redox_netstack::logger; use scheme::Smolnetd; @@ -37,10 +35,7 @@ fn run(daemon: redox_daemon::Daemon) -> Result<()> { let hardware_addr = std::fs::read("network:mac") .map(|mac_address| EthernetAddress::from_bytes(&mac_address)) - .unwrap_or_else(|_| { - EthernetAddress::from_str(getcfg("mac").unwrap().trim()) - .expect("Can't parse the 'mac' cfg") - }); + .expect("failed to get mac address from network adapter"); trace!("opening :ip"); let ip_fd = syscall::open(":ip", O_RDWR | O_CREAT | O_NONBLOCK) From f9b3170f0ec4ad390285c8c77b31782c0cac226a Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 28 Feb 2024 10:44:18 +0100 Subject: [PATCH 135/155] Allow network adapters to be named This will be necessary in the future to support multiple network adapters in a single system. --- src/lib/error.rs | 11 +++++++++++ src/smolnetd/main.rs | 45 ++++++++++++++++++++++++++++++++++++++------ 2 files changed, 50 insertions(+), 6 deletions(-) diff --git a/src/lib/error.rs b/src/lib/error.rs index 5ab5ba3071..0c5191e146 100644 --- a/src/lib/error.rs +++ b/src/lib/error.rs @@ -7,6 +7,7 @@ use syscall::error::Error as SyscallError; enum ErrorType { Syscall(SyscallError), IOError(IOError), + Other, } pub struct Error { @@ -28,6 +29,13 @@ impl Error { descr: descr.into(), } } + + pub fn other_error>(descr: S) -> Error { + Error { + error_type: ErrorType::Other, + descr: descr.into() + } + } } impl fmt::Display for Error { @@ -39,6 +47,9 @@ impl fmt::Display for Error { ErrorType::IOError(ref io_error) => { write!(f, "{} : io error : {}", self.descr, io_error) } + ErrorType::Other => { + write!(f, "{}", self.descr) + } } } } diff --git a/src/smolnetd/main.rs b/src/smolnetd/main.rs index 36a34dffbd..d750abbbc1 100644 --- a/src/smolnetd/main.rs +++ b/src/smolnetd/main.rs @@ -18,6 +18,7 @@ use redox_netstack::error::{Error, Result}; use redox_netstack::logger; use scheme::Smolnetd; use smoltcp::wire::EthernetAddress; +use syscall::flag::*; mod buffer_pool; mod link; @@ -25,15 +26,47 @@ mod port_set; mod router; mod scheme; -fn run(daemon: redox_daemon::Daemon) -> Result<()> { - use syscall::flag::*; +fn get_network_adapter() -> Result { + use std::fs; - trace!("opening network:"); - let network_fd = syscall::open("network:", O_RDWR | O_NONBLOCK) - .map_err(|e| Error::from_syscall_error(e, "failed to open network:"))? + let mut adapters = vec![]; + + for entry_res in fs::read_dir("/scheme")? { + let Ok(entry) = entry_res else { + continue; + }; + + let Ok(scheme) = entry.file_name().into_string() else { + continue; + }; + + if !scheme.starts_with("network") { + continue; + } + + adapters.push(scheme); + } + + if adapters.is_empty() { + Err(Error::other_error("no network adapter found")) + } else { + let adapter = adapters.remove(0); + if !adapters.is_empty() { + // FIXME allow using multiple network adapters at the same time + warn!("Multiple network adapters found. Only {adapter} will be used"); + } + Ok(adapter) + } +} + +fn run(daemon: redox_daemon::Daemon) -> Result<()> { + let adapter = get_network_adapter()?; + trace!("opening {adapter}:"); + let network_fd = syscall::open(format!("{adapter}:"), O_RDWR | O_NONBLOCK) + .map_err(|e| Error::from_syscall_error(e, format!("failed to open {adapter}:")))? as RawFd; - let hardware_addr = std::fs::read("network:mac") + let hardware_addr = std::fs::read(format!("{adapter}:mac")) .map(|mac_address| EthernetAddress::from_bytes(&mac_address)) .expect("failed to get mac address from network adapter"); From 8e2d02232f441ec9697c020ca5630eada558aaa2 Mon Sep 17 00:00:00 2001 From: 4lDO2 <4lDO2@protonmail.com> Date: Mon, 18 Mar 2024 17:10:07 +0100 Subject: [PATCH 136/155] Switch to libredox and redox-event. --- Cargo.lock | 345 +++++++++++++++++++++------------- Cargo.toml | 9 +- src/dnsd/main.rs | 107 ++++++----- src/dnsd/scheme.rs | 102 +++++----- src/lib/error.rs | 3 + src/smolnetd/main.rs | 173 ++++++++--------- src/smolnetd/scheme/mod.rs | 56 +++--- src/smolnetd/scheme/socket.rs | 20 +- 8 files changed, 447 insertions(+), 368 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bbeab0af36..28723fb7c2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,6 +17,12 @@ dependencies = [ "libc", ] +[[package]] +name = "anyhow" +version = "1.0.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0952808a6c2afd1aa8947271f3a60f1a6763c7b912d210184c5149b5cf147247" + [[package]] name = "arg_parser" version = "0.1.0" @@ -24,9 +30,9 @@ source = "git+https://gitlab.redox-os.org/redox-os/arg-parser.git#1c434b55f3e1a0 [[package]] name = "atomic-polyfill" -version = "0.1.11" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3ff7eb3f316534d83a8a2c3d1674ace8a5a71198eba31e2e2b597833f699b28" +checksum = "8cf2bce30dfe09ef0bfaef228b9d414faaf7e563035494d7fe092dba54b300f4" dependencies = [ "critical-section", ] @@ -44,10 +50,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] -name = "bumpalo" -version = "3.13.0" +name = "bitflags" +version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1" +checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" + +[[package]] +name = "bumpalo" +version = "3.15.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ff69b9dd49fd426c69a0db9fc04dd934cdb6645ff000864d98f7e2af8830eaa" [[package]] name = "byteorder" @@ -57,18 +69,15 @@ checksum = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855" [[package]] name = "byteorder" -version = "1.4.3" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "cc" -version = "1.0.83" +version = "1.0.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" -dependencies = [ - "libc", -] +checksum = "8cd6604a82acf3039f1144f54b8eb34e91ffba622051189e71b781822d5ee1f5" [[package]] name = "cfg-if" @@ -84,24 +93,23 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.28" +version = "0.4.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95ed24df0632f708f5f6d8082675bef2596f7084dee3dd55f632290bf35bfe0f" +checksum = "8eaf5903dcbc0a39312feb77df2ff4c76387d591b9fc7b04a238dcf8bb62639a" dependencies = [ "android-tzdata", "iana-time-zone", "js-sys", "num-traits", - "time", "wasm-bindgen", "windows-targets", ] [[package]] name = "core-foundation-sys" -version = "0.8.4" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" +checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" [[package]] name = "critical-section" @@ -111,51 +119,47 @@ checksum = "7059fff8937831a9ae6f0fe4d658ffabf58f2ca96aa9dec1c889f936f705f216" [[package]] name = "crossbeam-channel" -version = "0.5.8" +version = "0.5.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200" +checksum = "ab3db02a9c5b5121e1e42fbdb1aeb65f5e02624cc58c43f2884c6ccac0b82f95" dependencies = [ - "cfg-if 1.0.0", "crossbeam-utils", ] [[package]] name = "crossbeam-utils" -version = "0.8.16" +version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294" -dependencies = [ - "cfg-if 1.0.0", -] +checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" [[package]] name = "defmt" -version = "0.3.5" +version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8a2d011b2fee29fb7d659b83c43fce9a2cb4df453e16d441a51448e448f3f98" +checksum = "3939552907426de152b3c2c6f51ed53f98f448babd26f28694c95f5906194595" dependencies = [ - "bitflags", + "bitflags 1.3.2", "defmt-macros", ] [[package]] name = "defmt-macros" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54f0216f6c5acb5ae1a47050a6645024e6edafc2ee32d421955eccfef12ef92e" +checksum = "18bdc7a7b92ac413e19e95240e75d3a73a8d8e78aa24a594c22cbb4d44b4bbda" dependencies = [ "defmt-parser", "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.29", + "syn 2.0.53", ] [[package]] name = "defmt-parser" -version = "0.3.3" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "269924c02afd7f94bc4cecbfa5c379f6ffcf9766b3408fe63d22c728654eccd0" +checksum = "ff4a5fefe330e8d7f31b16a318f9ce81000d8e35e69b93eae154d16d2278f70f" dependencies = [ "thiserror", ] @@ -166,7 +170,7 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7020f6760aea312d43d23cb83bf6c0c49f162541db8b02bf95209ac51dc253d" dependencies = [ - "byteorder 1.4.3", + "byteorder 1.5.0", "quick-error", ] @@ -176,14 +180,14 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b0c35f58762feb77d74ebe43bdbc3210f09be9fe6742234d573bacc26ed92b67" dependencies = [ - "byteorder 1.4.3", + "byteorder 1.5.0", ] [[package]] name = "heapless" -version = "0.7.16" +version = "0.7.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db04bc24a18b9ea980628ecf00e6c0264f3c1426dac36c00cb49b6fbad8b0743" +checksum = "cdc6457c0eb62c71aac4bc17216026d8410337c4126773b9c5daba343f17964f" dependencies = [ "atomic-polyfill", "hash32", @@ -194,16 +198,16 @@ dependencies = [ [[package]] name = "iana-time-zone" -version = "0.1.57" +version = "0.1.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fad5b825842d2b38bd206f3e81d6957625fd7f0a361e345c30e01a0ae2dd613" +checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" dependencies = [ "android_system_properties", "core-foundation-sys", "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "windows", + "windows-core", ] [[package]] @@ -227,25 +231,69 @@ dependencies = [ ] [[package]] -name = "js-sys" -version = "0.3.64" +name = "ioslice" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5f195fe497f702db0f318b07fdd68edb16955aed830df8363d837542f8f935a" +checksum = "5e571352c8a3b89074d12e3ee5173ffe162159105352aaaf1fc5764da747e31b" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "js-sys" +version = "0.3.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" dependencies = [ "wasm-bindgen", ] [[package]] name = "libc" -version = "0.2.147" +version = "0.2.153" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" +checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" + +[[package]] +name = "libredox" +version = "0.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3af92c55d7d839293953fcd0fda5ecfe93297cfde6ffbdec13b41d99c0ba6607" +dependencies = [ + "bitflags 2.4.2", + "libc", + "redox_syscall 0.4.1", +] + +[[package]] +name = "libredox" +version = "0.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86b5213a34db3434d9c562c16af0d4da82653193805009da815cbc020e8b39df" +dependencies = [ + "bitflags 2.4.2", + "libc", + "redox_syscall 0.4.1", +] + +[[package]] +name = "libredox" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" +dependencies = [ + "bitflags 2.4.2", + "ioslice", + "libc", + "redox_syscall 0.5.1", +] [[package]] name = "lock_api" -version = "0.4.10" +version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1cc9717a20b1bb222f333e6a92fd32f7d8a18ddc5a3191a11af45dcbf4dcd16" +checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" dependencies = [ "autocfg", "scopeguard", @@ -253,9 +301,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.20" +version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" +checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" [[package]] name = "managed" @@ -282,18 +330,19 @@ dependencies = [ [[package]] name = "netutils" version = "0.1.0" -source = "git+https://gitlab.redox-os.org/redox-os/netutils.git#fc11b9bb3c1f5eefccb93ae670e4ec8b3d6fad4f" +source = "git+https://gitlab.redox-os.org/redox-os/netutils.git#c78177b7d7a694511d88a6b04df3e9d04ed7c78e" dependencies = [ + "anyhow", "arg_parser", "libc", + "libredox 0.0.4", "net2", "ntpclient", "pbr", "redox-daemon", - "redox_event", - "redox_syscall 0.3.5", + "redox_event 0.3.0", "redox_termios", - "termion", + "termion 2.0.3", "url", ] @@ -308,9 +357,9 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.16" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f30b0abd723be7e2ffca1272140fac1a2f084c77ec3e123c192b66af1ee9e6c2" +checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" dependencies = [ "autocfg", ] @@ -323,9 +372,9 @@ checksum = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef" [[package]] name = "once_cell" -version = "1.18.0" +version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "pbr" @@ -370,9 +419,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.66" +version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" +checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e" dependencies = [ "unicode-ident", ] @@ -385,21 +434,21 @@ checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" [[package]] name = "quote" -version = "1.0.33" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] [[package]] name = "redox-daemon" -version = "0.1.1" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "811fd0d382a70c9e9192166ee794567b65ef34cc7309c86a49b071779ca9b5f3" +checksum = "7fbdeffdb03cf2961b211a2023e683d71f2c225ea93404da5dc34b0dc94f0341" dependencies = [ "libc", - "redox_syscall 0.3.5", + "libredox 0.1.3", ] [[package]] @@ -411,29 +460,45 @@ dependencies = [ "chrono", "log", "smallvec", - "termion", + "termion 1.5.6", ] [[package]] name = "redox_event" -version = "0.1.0" -source = "git+https://gitlab.redox-os.org/redox-os/event.git#f7db3d25ca5e282c12ded12bf6c720087b570132" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35eb92c4487aacb8d4326ae0d4d443237528a42f41b95d62858d95c6a42f0272" dependencies = [ - "redox_syscall 0.3.5", + "bitflags 2.4.2", + "libredox 0.0.4", + "redox_syscall 0.4.1", +] + +[[package]] +name = "redox_event" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69609faa5d5992247a4ef379917bb3e39be281405d6a0ccd4f942429400b956f" +dependencies = [ + "bitflags 2.4.2", + "libredox 0.1.3", ] [[package]] name = "redox_netstack" version = "0.1.0" dependencies = [ - "byteorder 1.4.3", + "anyhow", + "byteorder 1.5.0", "dns-parser", + "ioslice", + "libredox 0.1.3", "log", "netutils", "redox-daemon", "redox-log", - "redox_event", - "redox_syscall 0.3.5", + "redox_event 0.4.1", + "redox_syscall 0.5.1", "smoltcp", ] @@ -443,26 +508,32 @@ version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" dependencies = [ - "bitflags", + "bitflags 1.3.2", ] [[package]] name = "redox_syscall" -version = "0.3.5" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" dependencies = [ - "bitflags", + "bitflags 1.3.2", +] + +[[package]] +name = "redox_syscall" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" +dependencies = [ + "bitflags 2.4.2", ] [[package]] name = "redox_termios" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8440d8acb4fd3d277125b4bd01a6f38aee8d814b3b5fc09b3f2b825d37d3fe8f" -dependencies = [ - "redox_syscall 0.2.16", -] +checksum = "20145670ba436b55d91fc92d25e71160fbfbdd57831631c8d7d36377a476f1cb" [[package]] name = "rustc_version" @@ -481,15 +552,15 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "semver" -version = "1.0.18" +version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918" +checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca" [[package]] name = "smallvec" -version = "1.11.0" +version = "1.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" +checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" [[package]] name = "smoltcp" @@ -497,8 +568,8 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8d2e3a36ac8fea7b94e666dfa3871063d6e0a5c9d5d4fec9a1a6b7b6760f0229" dependencies = [ - "bitflags", - "byteorder 1.4.3", + "bitflags 1.3.2", + "byteorder 1.5.0", "cfg-if 1.0.0", "defmt", "heapless", @@ -533,9 +604,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.29" +version = "2.0.53" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c324c494eba9d92503e6f1ef2e6df781e78f6a7705a0202d9801b198807d518a" +checksum = "7383cd0e49fff4b6b90ca5670bfd3e9d6a733b3f90c686605aa7eec8c4996032" dependencies = [ "proc-macro2", "quote", @@ -555,23 +626,35 @@ dependencies = [ ] [[package]] -name = "thiserror" -version = "1.0.47" +name = "termion" +version = "2.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97a802ec30afc17eee47b2855fc72e0c4cd62be9b4efe6591edde0ec5bd68d8f" +checksum = "c4648c7def6f2043b2568617b9f9b75eae88ca185dbc1f1fda30e95a85d49d7d" +dependencies = [ + "libc", + "libredox 0.0.2", + "numtoa", + "redox_termios", +] + +[[package]] +name = "thiserror" +version = "1.0.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.47" +version = "1.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6bb623b56e39ab7dcd4b1b98bb6c8f8d907ed255b18de254088016b27a8ee19b" +checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.29", + "syn 2.0.53", ] [[package]] @@ -602,21 +685,21 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "unicode-bidi" -version = "0.3.13" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" +checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" [[package]] name = "unicode-ident" -version = "1.0.11" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unicode-normalization" -version = "0.1.22" +version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" dependencies = [ "tinyvec", ] @@ -646,9 +729,9 @@ checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" [[package]] name = "wasm-bindgen" -version = "0.2.87" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342" +checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" dependencies = [ "cfg-if 1.0.0", "wasm-bindgen-macro", @@ -656,24 +739,24 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.87" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd" +checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" dependencies = [ "bumpalo", "log", "once_cell", "proc-macro2", "quote", - "syn 2.0.29", + "syn 2.0.53", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-macro" -version = "0.2.87" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d" +checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -681,22 +764,22 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.87" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" +checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.29", + "syn 2.0.53", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.87" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" +checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" [[package]] name = "winapi" @@ -721,19 +804,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] -name = "windows" -version = "0.48.0" +name = "windows-core" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" dependencies = [ "windows-targets", ] [[package]] name = "windows-targets" -version = "0.48.5" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b" dependencies = [ "windows_aarch64_gnullvm", "windows_aarch64_msvc", @@ -746,45 +829,45 @@ dependencies = [ [[package]] name = "windows_aarch64_gnullvm" -version = "0.48.5" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" +checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9" [[package]] name = "windows_aarch64_msvc" -version = "0.48.5" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" +checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675" [[package]] name = "windows_i686_gnu" -version = "0.48.5" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" +checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3" [[package]] name = "windows_i686_msvc" -version = "0.48.5" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" +checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02" [[package]] name = "windows_x86_64_gnu" -version = "0.48.5" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" +checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03" [[package]] name = "windows_x86_64_gnullvm" -version = "0.48.5" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" +checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177" [[package]] name = "windows_x86_64_msvc" -version = "0.48.5" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" +checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" [[patch.unused]] name = "mio" diff --git a/Cargo.toml b/Cargo.toml index 4f4ef1b4b5..9113191568 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,12 +17,15 @@ path = "src/lib/lib.rs" [dependencies] netutils = { git = "https://gitlab.redox-os.org/redox-os/netutils.git" } -redox_event = { git = "https://gitlab.redox-os.org/redox-os/event.git" } -redox-daemon = "0.1.1" -redox_syscall = "0.3" +redox_event = "0.4.1" +redox-daemon = "0.1.2" +redox_syscall = "0.5" redox-log = "0.1" byteorder = { version = "1.0", default-features = false } dns-parser = "0.7.1" +libredox = { version = "0.1.3", features = ["mkns"] } +anyhow = "1.0.81" +ioslice = "0.6.0" [dependencies.log] version = "0.4" diff --git a/src/dnsd/main.rs b/src/dnsd/main.rs index ce21854cde..7a6becfd0c 100644 --- a/src/dnsd/main.rs +++ b/src/dnsd/main.rs @@ -1,84 +1,74 @@ -extern crate dns_parser; -extern crate event; #[macro_use] extern crate log; -extern crate redox_netstack; -extern crate syscall; +use anyhow::{Error, Result, Context}; use event::EventQueue; -use redox_netstack::error::{Error, Result}; +use ioslice::IoSlice; +use libredox::Fd; use redox_netstack::logger; use scheme::Dnsd; -use std::cell::RefCell; use std::fs::File; -use std::os::unix::io::{AsRawFd, FromRawFd, RawFd}; +use std::os::unix::io::{FromRawFd, RawFd}; use std::process; -use std::rc::Rc; mod scheme; fn run(daemon: redox_daemon::Daemon) -> Result<()> { - use syscall::flag::*; + use libredox::flag::*; - let dns_fd = syscall::open(":dns", O_RDWR | O_CREAT | O_NONBLOCK) - .map_err(|e| Error::from_syscall_error(e, "failed to open :dns"))? - as RawFd; + let dns_fd = Fd::open(":dns", O_RDWR | O_CREAT | O_NONBLOCK, 0) + .context("failed to open :dns")?; - let time_path = format!("time:{}", syscall::CLOCK_MONOTONIC); - let time_fd = syscall::open(&time_path, syscall::O_RDWR) - .map_err(|e| Error::from_syscall_error(e, "failed to open time:"))? - as RawFd; + let time_path = format!("time:{}", CLOCK_MONOTONIC); + let time_fd = Fd::open(&time_path, O_RDWR, 0) + .context("failed to open time")?; - let nameserver_fd = syscall::open( + let nameserver_fd = Fd::open( "netcfg:resolv/nameserver", - syscall::O_RDWR | syscall::O_CREAT | syscall::O_NONBLOCK, - ).map_err(|e| Error::from_syscall_error(e, "failed to open nameserver:"))? - as RawFd; + O_RDWR | O_CREAT | O_NONBLOCK, + 0, + ).context("failed to open nameserver")?; + + let event_queue = EventQueue::::new() + .context("failed to create event queue")?; + + event_queue + .subscribe(dns_fd.raw(), EventSource::DnsScheme, event::EventFlags::READ) + .context("failed to listen to time events")?; + event_queue + .subscribe(nameserver_fd.raw(), EventSource::NameserverScheme, event::EventFlags::READ) + .context("failed to listen to nameserver socket events")?; + event_queue + .subscribe(time_fd.raw(), EventSource::Timer, event::EventFlags::READ) + .context("failed to listen to timer events")?; let (dns_file, time_file) = unsafe { ( - File::from_raw_fd(dns_fd), - File::from_raw_fd(time_fd), + File::from_raw_fd(dns_fd.into_raw() as RawFd), + File::from_raw_fd(time_fd.into_raw() as RawFd), ) }; - let mut event_queue = EventQueue::<(), Error>::new() - .map_err(|e| Error::from_io_error(e, "failed to create event queue"))?; + let mut dnsd = Dnsd::new(dns_file, time_file, &event_queue); - let dnsd = Rc::new(RefCell::new(Dnsd::new(dns_file, time_file, event_queue.file.as_raw_fd()))); - - let new_ns = syscall::mkns(&[["udp".as_ptr() as usize, "udp".len()]]) + let new_ns = libredox::call::mkns(&[IoSlice::new(b"dns")]) .expect("dnsd: failed to create namespace"); - syscall::setrens(new_ns, new_ns).expect("dnsd: failed to enter namespace"); + libredox::call::setrens(new_ns, new_ns).expect("dnsd: failed to enter namespace"); daemon.ready().expect("dnsd: failed to notify parent"); - let dnsd_ = Rc::clone(&dnsd); - - event_queue - .add(dns_fd, move |_| dnsd_.borrow_mut().on_dns_file_event()) - .map_err(|e| Error::from_io_error(e, "failed to listen to time events"))?; - - let dnsd_ = Rc::clone(&dnsd); - - event_queue - .add(nameserver_fd, move |_| dnsd_.borrow_mut().on_nameserver_event()) - .map_err(|e| Error::from_io_error(e, "failed to listen to nameserver"))?; - - let dnsd_ = Rc::clone(&dnsd); - - event_queue.set_default_callback(move |event| dnsd_.borrow_mut().on_unknown_fd_event(event.fd)); - - event_queue - .add(time_fd, move |_| dnsd.borrow_mut().on_time_event()) - .map_err(|e| Error::from_io_error(e, "failed to listen to time events"))?; - - event_queue.trigger_all(event::Event { - fd: 0, - flags: EventFlags::empty(), - })?; - - event_queue.run() + for event_res in event_queue.iter() { + let event = event_res.context("failed to read from event queue")?; + match event.user_data { + EventSource::DnsScheme => if !dnsd.on_dns_file_event()? { + break + }, + EventSource::NameserverScheme => dnsd.on_nameserver_event()?, + EventSource::Timer => dnsd.on_time_event()?, + EventSource::Other => dnsd.on_unknown_fd_event(event.fd as RawFd)?, + } + } + Ok(()) } fn main() { @@ -91,3 +81,12 @@ fn main() { process::exit(0); }).expect("dnsd: failed to daemonize"); } + +event::user_data! { + enum EventSource { + DnsScheme, + NameserverScheme, + Timer, + Other, + } +} diff --git a/src/dnsd/scheme.rs b/src/dnsd/scheme.rs index b7935ded5f..b2ec78c17e 100644 --- a/src/dnsd/scheme.rs +++ b/src/dnsd/scheme.rs @@ -1,5 +1,3 @@ -use redox_netstack::error::{Error, Result}; -use event::{subscribe_to_fd, unsubscribe_from_fd}; use std::borrow::ToOwned; use std::collections::{BTreeMap, BTreeSet}; use std::collections::VecDeque; @@ -12,13 +10,19 @@ use std::str; use std::str::FromStr; use std::rc::Rc; use std::net::Ipv4Addr; + use syscall::data::TimeSpec; use syscall::{Error as SyscallError, EventFlags as SyscallEventFlags, Packet as SyscallPacket, Result as SyscallResult, SchemeMut}; use syscall; +use event::EventQueue; +use redox_netstack::error::{Error, Result}; + use dns_parser::{Builder, Packet as DNSPacket, RRData, ResponseCode}; use dns_parser::{QueryClass, QueryType}; +use crate::EventSource; + enum DnsFile { Resolved { data: Rc<[u8]>, pos: usize }, Waiting { domain: String }, @@ -76,25 +80,26 @@ impl Domains { } } - fn request_domain(&mut self, domain: &str, queue_fd: RawFd) -> Option { + fn request_domain(&mut self, domain: &str, queue: &EventQueue) -> Option { trace!("Requesting domain {}", domain); let mut builder = Builder::new_query(1, true); builder.add_question(domain, QueryType::A, QueryClass::IN); let packet = builder.build().ok()?; - let udp_fd = syscall::open( + let udp_fd = libredox::call::open( &format!("udp:{}:53", self.nameserver), - syscall::O_RDWR | syscall::O_CREAT | syscall::O_NONBLOCK, - ).ok()? as RawFd; - if syscall::write(udp_fd as usize, &packet) != Ok(packet.len()) { - syscall::close(udp_fd as usize).ok()?; + libredox::flag::O_RDWR | libredox::flag::O_CREAT | libredox::flag::O_NONBLOCK, + 0, + ).ok()?; + if libredox::call::write(udp_fd, &packet) != Ok(packet.len()) { + libredox::call::close(udp_fd).ok()?; return None; } - subscribe_to_fd(queue_fd, udp_fd, 0xFFFFFFFF).ok()?; - self.requests.insert(udp_fd, domain.to_owned().into()); - Some(udp_fd) + queue.subscribe(udp_fd, EventSource::Other, event::EventFlags::READ).ok()?; + self.requests.insert(udp_fd as RawFd, domain.to_owned().into()); + Some(udp_fd as RawFd) } - fn on_time_event(&mut self, cur_time: &TimeSpec, queue_fd: RawFd) -> BTreeSet { + fn on_time_event(&mut self, cur_time: &TimeSpec, queue: &EventQueue) -> Result> { while let Some((timeout, domain)) = self.resolved_timeouts.pop_front() { if timeout.tv_sec > cur_time.tv_sec || (timeout.tv_sec == cur_time.tv_sec && timeout.tv_nsec > cur_time.tv_nsec) @@ -133,18 +138,18 @@ impl Domains { } = e.remove() { fds_to_wakeup.append(&mut waiting_fds); - let _ = unsubscribe_from_fd(queue_fd, socket_fd, 0xFFFFFFFF); - let _ = syscall::close(socket_fd as usize); + queue.unsubscribe(socket_fd as usize).map_err(|e| Error::from_syscall_error(e.into(), "unsubscribe failure"))?; + let _ = libredox::call::close(socket_fd as usize); } } } } } - fds_to_wakeup + Ok(fds_to_wakeup) } - fn on_fd_event(&mut self, fd: RawFd, cur_time: &TimeSpec, queue_fd: RawFd) -> Option { + fn on_fd_event(&mut self, fd: RawFd, cur_time: &TimeSpec, queue: &EventQueue) -> Option { let e = match self.requests.entry(fd) { Entry::Vacant(_) => { return None; @@ -152,7 +157,7 @@ impl Domains { Entry::Occupied(e) => e, }; let mut buf = [0u8; 0x1000]; - let readed = syscall::read(fd as usize, &mut buf).ok()?; + let readed = libredox::call::read(fd as usize, &mut buf).ok()?; if readed == 0 { return None; } @@ -160,8 +165,8 @@ impl Domains { if pkt.header.response_code != ResponseCode::NoError || pkt.answers.is_empty() { if let Some(query) = pkt.questions.iter().next() { if query.qname.to_string().to_lowercase() == e.get().as_ref() { - unsubscribe_from_fd(queue_fd, fd, 0xFFFFFFFF).ok()?; - syscall::close(fd as usize).ok()?; + queue.unsubscribe(fd as usize).ok()?; + libredox::call::close(fd as usize).ok()?; let domain = e.remove(); self.requested_timeouts .retain(|&(_, ref d)| d.as_ref() != domain.as_ref()); @@ -190,8 +195,8 @@ impl Domains { return None; } let data = Rc::from(result.into_bytes()); - unsubscribe_from_fd(queue_fd, fd, 0xFFFFFFFF).ok()?; - syscall::close(fd as usize).ok()?; + queue.unsubscribe(fd as usize).ok()?; + libredox::call::close(fd as usize).ok()?; let domain = e.remove(); let mut domain_data = Domain::Resolved { data }; trace!("On FD event {} {} resolved", fd, domain); @@ -221,7 +226,7 @@ impl Domains { } } - fn file_from_domain(&mut self, domain: &str, fd: usize, cur_time: &TimeSpec, queue_fd: RawFd) -> DnsFile { + fn file_from_domain(&mut self, domain: &str, fd: usize, cur_time: &TimeSpec, queue: &EventQueue) -> DnsFile { if let Some(domain_data) = self.domains.get_mut(domain) { match *domain_data { Domain::Resolved { ref data } => DnsFile::Resolved { @@ -239,7 +244,7 @@ impl Domains { } } } else { - if let Some(socket_fd) = self.request_domain(domain, queue_fd) { + if let Some(socket_fd) = self.request_domain(domain, queue) { let mut waiting_fds = BTreeSet::new(); let domain = domain.to_owned().into(); waiting_fds.insert(fd); @@ -273,26 +278,26 @@ impl Domains { } } -pub struct Dnsd { +pub struct Dnsd<'q> { dns_file: File, time_file: File, - queue_fd: RawFd, + queue: &'q EventQueue, files: BTreeMap, domains: Domains, wait_map: BTreeMap, next_fd: usize, } -impl Dnsd { +impl<'q> Dnsd<'q> { const RESOLVED_TIMEOUT_S: i64 = 5 * 60; const REQUEST_TIMEOUT_S: i64 = 30; const TIME_EVENT_TIMEOUT_S: i64 = 5; - pub fn new(dns_file: File, time_file: File, queue_fd: RawFd) -> Dnsd { + pub fn new(dns_file: File, time_file: File, queue: &'q EventQueue) -> Dnsd { Dnsd { dns_file, time_file, - queue_fd, + queue, files: BTreeMap::new(), domains: Domains::new(), wait_map: BTreeMap::new(), @@ -300,7 +305,7 @@ impl Dnsd { } } - pub fn on_time_event(&mut self) -> Result> { + pub fn on_time_event(&mut self) -> Result<()> { let mut time = TimeSpec::default(); if self.time_file.read(&mut time)? < mem::size_of::() { return Err(Error::from_syscall_error( @@ -309,7 +314,7 @@ impl Dnsd { )); } - let fds_to_wakeup = self.domains.on_time_event(&time, self.queue_fd); + let fds_to_wakeup = self.domains.on_time_event(&time, self.queue)?; if !fds_to_wakeup.is_empty() { for fd in &fds_to_wakeup { if let Some(file) = self.files.get_mut(fd) { @@ -323,24 +328,25 @@ impl Dnsd { self.time_file .write_all(&time) .map_err(|e| Error::from_io_error(e, "Failed to write to time file"))?; - Ok(None) + Ok(()) } - pub fn on_dns_file_event(&mut self) -> Result> { - let result = loop { + pub fn on_dns_file_event(&mut self) -> Result { + loop { let mut packet = SyscallPacket::default(); match self.dns_file.read(&mut packet) { Ok(0) => { //TODO: Cleanup must occur - break Some(()); + return Ok(false); }, Ok(_) => (), Err(err) => if err.kind() == ErrorKind::WouldBlock { - break None; + return Ok(true); } else { return Err(Error::from(err)); } } + // TODO: implement cancellation let a = packet.a; self.handle(&mut packet); if packet.a != (-syscall::EWOULDBLOCK) as usize { @@ -349,17 +355,17 @@ impl Dnsd { packet.a = a; self.handle_block(packet)?; } - }; - Ok(result) + } } - pub fn on_unknown_fd_event(&mut self, fd: RawFd) -> Result> { + pub fn on_unknown_fd_event(&mut self, fd: RawFd) -> Result<()> { trace!("Unknown fd event {}", fd); - let mut cur_time = TimeSpec::default(); - syscall::clock_gettime(syscall::CLOCK_MONOTONIC, &mut cur_time) - .map_err(|e| Error::from_syscall_error(e, "Can't get time"))?; + let cur_time = libredox::call::clock_gettime(libredox::flag::CLOCK_MONOTONIC) + .map_err(|e| Error::from_syscall_error(e.into(), "Can't get time"))?; + // TODO + let cur_time = TimeSpec { tv_sec: cur_time.tv_sec, tv_nsec: cur_time.tv_nsec as _ }; - match self.domains.on_fd_event(fd, &cur_time, self.queue_fd) { + match self.domains.on_fd_event(fd, &cur_time, self.queue) { Some(DnsParsingResult::FailFiles(fds_to_fail)) => { for fd in &fds_to_fail { if let Some(file) = self.files.get_mut(fd) { @@ -373,12 +379,12 @@ impl Dnsd { } None => {} } - Ok(None) + Ok(()) } - pub fn on_nameserver_event(&mut self) -> Result> { + pub fn on_nameserver_event(&mut self) -> Result<()> { self.domains.update_nameserver(); - Ok(None) + Ok(()) } fn wakeup_fds(&mut self, fds_to_wakeup: &BTreeSet) { @@ -416,7 +422,7 @@ impl Dnsd { } } -impl SchemeMut for Dnsd { +impl SchemeMut for Dnsd<'_> { fn open(&mut self, url: &str, _flags: usize, _uid: u32, _gid: u32) -> SyscallResult { let domain = url.to_lowercase(); if domain.is_empty() || !Dnsd::validate_domain(&domain) { @@ -426,7 +432,7 @@ impl SchemeMut for Dnsd { self.next_fd += 1; let mut cur_time = TimeSpec::default(); syscall::clock_gettime(syscall::CLOCK_MONOTONIC, &mut cur_time)?; - let dns_file = self.domains.file_from_domain(&domain, fd, &cur_time, self.queue_fd); + let dns_file = self.domains.file_from_domain(&domain, fd, &cur_time, self.queue); self.files.insert(fd, dns_file); trace!("Open {} {}", &domain, fd); Ok(fd) @@ -460,7 +466,7 @@ impl SchemeMut for Dnsd { syscall::clock_gettime(syscall::CLOCK_MONOTONIC, &mut cur_time)?; if let DnsFile::Waiting { ref domain } = *file { - *file = self.domains.file_from_domain(domain, fd, &cur_time, self.queue_fd); + *file = self.domains.file_from_domain(domain, fd, &cur_time, self.queue); } match *file { diff --git a/src/lib/error.rs b/src/lib/error.rs index 0c5191e146..3f4cc46630 100644 --- a/src/lib/error.rs +++ b/src/lib/error.rs @@ -4,12 +4,14 @@ use std::result; use std::io::Error as IOError; use syscall::error::Error as SyscallError; +#[derive(Debug)] enum ErrorType { Syscall(SyscallError), IOError(IOError), Other, } +#[derive(Debug)] pub struct Error { error_type: ErrorType, descr: String, @@ -53,6 +55,7 @@ impl fmt::Display for Error { } } } +impl std::error::Error for Error {} impl convert::From for Error { fn from(e: IOError) -> Self { diff --git a/src/smolnetd/main.rs b/src/smolnetd/main.rs index d750abbbc1..d16fcf3be7 100644 --- a/src/smolnetd/main.rs +++ b/src/smolnetd/main.rs @@ -13,12 +13,14 @@ use std::os::unix::io::{FromRawFd, RawFd}; use std::process; use std::rc::Rc; -use event::EventQueue; -use redox_netstack::error::{Error, Result}; +use event::{EventQueue, EventFlags}; +use libredox::Fd; +use libredox::flag::{O_RDWR, O_NONBLOCK, O_CREAT}; +use anyhow::{Result, anyhow, bail, Context}; + use redox_netstack::logger; use scheme::Smolnetd; use smoltcp::wire::EthernetAddress; -use syscall::flag::*; mod buffer_pool; mod link; @@ -48,7 +50,7 @@ fn get_network_adapter() -> Result { } if adapters.is_empty() { - Err(Error::other_error("no network adapter found")) + bail!("no network adapter found"); } else { let adapter = adapters.remove(0); if !adapters.is_empty() { @@ -62,129 +64,106 @@ fn get_network_adapter() -> Result { fn run(daemon: redox_daemon::Daemon) -> Result<()> { let adapter = get_network_adapter()?; trace!("opening {adapter}:"); - let network_fd = syscall::open(format!("{adapter}:"), O_RDWR | O_NONBLOCK) - .map_err(|e| Error::from_syscall_error(e, format!("failed to open {adapter}:")))? - as RawFd; + let network_fd = Fd::open(&format!("{adapter}:"), O_RDWR | O_NONBLOCK, 0) + .map_err(|e| anyhow!("failed to open {adapter}: {e}"))?; let hardware_addr = std::fs::read(format!("{adapter}:mac")) .map(|mac_address| EthernetAddress::from_bytes(&mac_address)) - .expect("failed to get mac address from network adapter"); + .context("failed to get mac address from network adapter")?; trace!("opening :ip"); - let ip_fd = syscall::open(":ip", O_RDWR | O_CREAT | O_NONBLOCK) - .map_err(|e| Error::from_syscall_error(e, "failed to open :ip"))? as RawFd; + let ip_fd = Fd::open(":ip", O_RDWR | O_CREAT | O_NONBLOCK, 0) + .context("failed to open :ip")?; trace!("opening :udp"); - let udp_fd = syscall::open(":udp", O_RDWR | O_CREAT | O_NONBLOCK) - .map_err(|e| Error::from_syscall_error(e, "failed to open :udp"))? - as RawFd; + let udp_fd = Fd::open(":udp", O_RDWR | O_CREAT | O_NONBLOCK, 0) + .context("failed to open :udp")?; trace!("opening :tcp"); - let tcp_fd = syscall::open(":tcp", O_RDWR | O_CREAT | O_NONBLOCK) - .map_err(|e| Error::from_syscall_error(e, "failed to open :tcp"))? - as RawFd; + let tcp_fd = Fd::open(":tcp", O_RDWR | O_CREAT | O_NONBLOCK, 0) + .context("failed to open :tcp")?; trace!("opening :icmp"); - let icmp_fd = syscall::open(":icmp", O_RDWR | O_CREAT | O_NONBLOCK) - .map_err(|e| Error::from_syscall_error(e, "failed to open :icmp"))? - as RawFd; + let icmp_fd = Fd::open(":icmp", O_RDWR | O_CREAT | O_NONBLOCK, 0) + .context("failed to open :icmp")?; trace!("opening :netcfg"); - let netcfg_fd = syscall::open(":netcfg", O_RDWR | O_CREAT | O_NONBLOCK) - .map_err(|e| Error::from_syscall_error(e, "failed to open :netcfg"))? - as RawFd; + let netcfg_fd = Fd::open(":netcfg", O_RDWR | O_CREAT | O_NONBLOCK, 0) + .context("failed to open :netcfg")?; let time_path = format!("time:{}", syscall::CLOCK_MONOTONIC); - let time_fd = syscall::open(&time_path, syscall::O_RDWR) - .map_err(|e| Error::from_syscall_error(e, "failed to open time:"))? - as RawFd; + let time_fd = Fd::open(&time_path, O_RDWR, 0) + .context("failed to open time:")?; - let (network_file, ip_file, time_file, udp_file, tcp_file, icmp_file, netcfg_file) = unsafe { - ( - File::from_raw_fd(network_fd), - File::from_raw_fd(ip_fd), - File::from_raw_fd(time_fd), - File::from_raw_fd(udp_fd), - File::from_raw_fd(tcp_fd), - File::from_raw_fd(icmp_fd), - File::from_raw_fd(netcfg_fd), - ) - }; + event::user_data! { + enum EventSource { + Network, + Time, + IpScheme, + UdpScheme, + TcpScheme, + IcmpScheme, + NetcfgScheme, + } + } - let smolnetd = Rc::new(RefCell::new(Smolnetd::new( - network_file, - hardware_addr, - ip_file, - udp_file, - tcp_file, - icmp_file, - time_file, - netcfg_file, - ))); - - let mut event_queue = EventQueue::<(), Error>::new() - .map_err(|e| Error::from_io_error(e, "failed to create event queue"))?; - - syscall::setrens(0, 0).expect("smolnetd: failed to enter null namespace"); + let event_queue = EventQueue::::new() + .context("failed to create event queue")?; daemon.ready().expect("smolnetd: failed to notify parent"); - let smolnetd_ = Rc::clone(&smolnetd); + event_queue.subscribe(network_fd.raw(), EventSource::Network, EventFlags::READ) + .context("failed to listen to network events")?; - event_queue - .add(network_fd, move |_| { - smolnetd_.borrow_mut().on_network_scheme_event() - }) - .map_err(|e| Error::from_io_error(e, "failed to listen to network events"))?; + event_queue.subscribe(time_fd.raw(), EventSource::Time, EventFlags::READ) + .context("failed to listen to timer events")?; - let smolnetd_ = Rc::clone(&smolnetd); + event_queue.subscribe(ip_fd.raw(), EventSource::IpScheme, EventFlags::READ) + .context("failed to listen to ip scheme events")?; - event_queue - .add(ip_fd, move |_| smolnetd_.borrow_mut().on_ip_scheme_event()) - .map_err(|e| Error::from_io_error(e, "failed to listen to ip events"))?; + event_queue.subscribe(udp_fd.raw(), EventSource::UdpScheme, EventFlags::READ) + .context("failed to listen to udp scheme events")?; - let smolnetd_ = Rc::clone(&smolnetd); + event_queue.subscribe(tcp_fd.raw(), EventSource::TcpScheme, EventFlags::READ) + .context("failed to listen to tcp scheme events")?; - event_queue - .add(udp_fd, move |_| { - smolnetd_.borrow_mut().on_udp_scheme_event() - }) - .map_err(|e| Error::from_io_error(e, "failed to listen to udp events"))?; + event_queue.subscribe(icmp_fd.raw(), EventSource::IcmpScheme, EventFlags::READ) + .context("failed to listen to icmp scheme events")?; - let smolnetd_ = Rc::clone(&smolnetd); + event_queue.subscribe(netcfg_fd.raw(), EventSource::NetcfgScheme, EventFlags::READ) + .context("failed to listen to netcfg scheme events")?; - event_queue - .add(tcp_fd, move |_| { - smolnetd_.borrow_mut().on_tcp_scheme_event() - }) - .map_err(|e| Error::from_io_error(e, "failed to listen to tcp events"))?; + let mut smolnetd = Smolnetd::new( + network_fd, + hardware_addr, + ip_fd, + udp_fd, + tcp_fd, + icmp_fd, + time_fd, + netcfg_fd, + ); - let smolnetd_ = Rc::clone(&smolnetd); + libredox::call::setrens(0, 0) + .context("smolnetd: failed to enter null namespace")?; - event_queue - .add(icmp_fd, move |_| { - smolnetd_.borrow_mut().on_icmp_scheme_event() - }) - .map_err(|e| Error::from_io_error(e, "failed to listen to icmp events"))?; + let all = { + use EventSource::*; + [Network, Time, IpScheme, UdpScheme, IcmpScheme, NetcfgScheme].map(Ok) + }; - let smolnetd_ = Rc::clone(&smolnetd); - - event_queue - .add(time_fd, move |_| smolnetd_.borrow_mut().on_time_event()) - .map_err(|e| Error::from_io_error(e, "failed to listen to time events"))?; - - event_queue - .add(netcfg_fd, move |_| { - smolnetd.borrow_mut().on_netcfg_scheme_event() - }) - .map_err(|e| Error::from_io_error(e, "failed to listen to netcfg events"))?; - - event_queue.trigger_all(event::Event { - fd: 0, - flags: EventFlags::empty(), - })?; - - event_queue.run() + for event_res in all.into_iter().chain(event_queue.map(|r| r.map(|e| e.user_data))) { + match event_res? { + EventSource::Network => smolnetd.on_network_scheme_event()?, + EventSource::Time => smolnetd.on_time_event()?, + EventSource::IpScheme => smolnetd.on_ip_scheme_event()?, + EventSource::UdpScheme => smolnetd.on_udp_scheme_event()?, + EventSource::TcpScheme => smolnetd.on_tcp_scheme_event()?, + EventSource::IcmpScheme => smolnetd.on_icmp_scheme_event()?, + EventSource::NetcfgScheme => smolnetd.on_netcfg_scheme_event()?, + } + } + Ok(()) } fn main() { diff --git a/src/smolnetd/scheme/mod.rs b/src/smolnetd/scheme/mod.rs index 2efffc0eea..32795bcefc 100644 --- a/src/smolnetd/scheme/mod.rs +++ b/src/smolnetd/scheme/mod.rs @@ -4,6 +4,7 @@ use crate::link::{loopback::LoopbackDevice, DeviceList}; use crate::router::route_table::{RouteTable, Rule}; use crate::router::Router; use crate::scheme::smoltcp::iface::SocketSet as SmoltcpSocketSet; +use libredox::Fd; use netutils::getcfg; use smoltcp; use smoltcp::iface::{Config, Interface as SmoltcpInterface}; @@ -16,6 +17,7 @@ use std::cell::RefCell; use std::fs::File; use std::io::{Read, Write}; use std::mem::size_of; +use std::os::fd::{FromRawFd, RawFd}; use std::rc::Rc; use std::str::FromStr; use syscall; @@ -63,14 +65,14 @@ impl Smolnetd { pub const MAX_CHECK_TIMEOUT: Duration = Duration::from_millis(500); pub fn new( - network_file: File, + network_file: Fd, hardware_addr: EthernetAddress, - ip_file: File, - udp_file: File, - tcp_file: File, - icmp_file: File, - time_file: File, - netcfg_file: File, + ip_file: Fd, + udp_file: Fd, + tcp_file: Fd, + icmp_file: Fd, + time_file: Fd, + netcfg_file: Fd, ) -> Smolnetd { let protocol_addrs = vec![ IpCidr::new(IpAddress::v4(127, 0, 0, 1), 8), @@ -108,7 +110,7 @@ impl Smolnetd { let mut eth0 = EthernetLink::new( "eth0", - network_file, + unsafe { File::from_raw_fd(network_file.into_raw() as RawFd) }, ); eth0.set_mac_address(hardware_addr); @@ -120,79 +122,79 @@ impl Smolnetd { router_device: network_device, socket_set: Rc::clone(&socket_set), timer: ::std::time::Instant::now(), - time_file, + time_file: unsafe { File::from_raw_fd(time_file.into_raw() as RawFd) }, ip_scheme: IpScheme::new( Rc::clone(&iface), Rc::clone(&route_table), Rc::clone(&socket_set), - ip_file, + unsafe { File::from_raw_fd(ip_file.into_raw() as RawFd) }, ), udp_scheme: UdpScheme::new( Rc::clone(&iface), Rc::clone(&route_table), Rc::clone(&socket_set), - udp_file, + unsafe { File::from_raw_fd(udp_file.into_raw() as RawFd) }, ), tcp_scheme: TcpScheme::new( Rc::clone(&iface), Rc::clone(&route_table), Rc::clone(&socket_set), - tcp_file, + unsafe { File::from_raw_fd(tcp_file.into_raw() as RawFd) }, ), icmp_scheme: IcmpScheme::new( Rc::clone(&iface), Rc::clone(&route_table), Rc::clone(&socket_set), - icmp_file, + unsafe { File::from_raw_fd(icmp_file.into_raw() as RawFd) }, ), netcfg_scheme: NetCfgScheme::new( Rc::clone(&iface), - netcfg_file, + unsafe { File::from_raw_fd(netcfg_file.into_raw() as RawFd) }, Rc::clone(&route_table), Rc::clone(&devices), ), } } - pub fn on_network_scheme_event(&mut self) -> Result> { + pub fn on_network_scheme_event(&mut self) -> Result<()> { self.poll()?; - Ok(None) + Ok(()) } - pub fn on_ip_scheme_event(&mut self) -> Result> { + pub fn on_ip_scheme_event(&mut self) -> Result<()> { self.ip_scheme.on_scheme_event()?; let _ = self.poll()?; - Ok(None) + Ok(()) } - pub fn on_udp_scheme_event(&mut self) -> Result> { + pub fn on_udp_scheme_event(&mut self) -> Result<()> { self.udp_scheme.on_scheme_event()?; let _ = self.poll()?; - Ok(None) + Ok(()) } - pub fn on_tcp_scheme_event(&mut self) -> Result> { + pub fn on_tcp_scheme_event(&mut self) -> Result<()> { self.tcp_scheme.on_scheme_event()?; let _ = self.poll()?; - Ok(None) + Ok(()) } - pub fn on_icmp_scheme_event(&mut self) -> Result> { + pub fn on_icmp_scheme_event(&mut self) -> Result<()> { self.icmp_scheme.on_scheme_event()?; let _ = self.poll()?; - Ok(None) + Ok(()) } - pub fn on_time_event(&mut self) -> Result> { + pub fn on_time_event(&mut self) -> Result<()> { let timeout = self.poll()?; self.schedule_time_event(timeout)?; //TODO: Fix network scheme to ensure events are not missed self.on_network_scheme_event() } - pub fn on_netcfg_scheme_event(&mut self) -> Result> { + pub fn on_netcfg_scheme_event(&mut self) -> Result<()> { self.netcfg_scheme.on_scheme_event()?; - Ok(None) + Ok(()) } fn schedule_time_event(&mut self, timeout: Duration) -> Result<()> { diff --git a/src/smolnetd/scheme/socket.rs b/src/smolnetd/scheme/socket.rs index 45c64cfeeb..ec47f167cc 100644 --- a/src/smolnetd/scheme/socket.rs +++ b/src/smolnetd/scheme/socket.rs @@ -10,7 +10,8 @@ use std::ops::DerefMut; use std::rc::Rc; use std::str; -use syscall; +use libredox::flag::CLOCK_MONOTONIC; +use syscall::{self, KSMSG_CANCEL}; use syscall::data::TimeSpec; use syscall::flag::{EVENT_READ, EVENT_WRITE}; use syscall::{ @@ -286,6 +287,10 @@ where } } } + if packet.a == KSMSG_CANCEL { + println!("smolnetd: todo: handle cancellation"); + continue; + } if let Some(a) = self.handle(&mut packet) { packet.a = a; self.scheme_file.write_all(&packet)?; @@ -372,15 +377,14 @@ where }?; let mut timeout = match packet.a { - syscall::SYS_WRITE => Ok(write_timeout), - syscall::SYS_READ => Ok(read_timeout), - _ => Ok(None), - }?; + syscall::SYS_WRITE => write_timeout, + syscall::SYS_READ => read_timeout, + _ => None, + }; if let Some(ref mut timeout) = timeout { - let mut cur_time = TimeSpec::default(); - syscall::clock_gettime(syscall::CLOCK_MONOTONIC, &mut cur_time)?; - *timeout = add_time(timeout, &cur_time) + let cur_time = libredox::call::clock_gettime(CLOCK_MONOTONIC)?; + *timeout = add_time(timeout, &TimeSpec { tv_sec: cur_time.tv_sec, tv_nsec: cur_time.tv_nsec as i32 }) } Ok(timeout) From 1981fa86bd56717597f2e1e71987621e5b2d669a Mon Sep 17 00:00:00 2001 From: 4lDO2 <4lDO2@protonmail.com> Date: Wed, 20 Mar 2024 16:39:57 +0100 Subject: [PATCH 137/155] Switch remaining clock_gettimes to libredox. --- Cargo.lock | 45 ++++++++++------------------------- src/dnsd/scheme.rs | 11 ++++----- src/smolnetd/scheme/socket.rs | 9 ++++--- 3 files changed, 21 insertions(+), 44 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 28723fb7c2..19a878c531 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -51,9 +51,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.4.2" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" [[package]] name = "bumpalo" @@ -261,7 +261,7 @@ version = "0.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3af92c55d7d839293953fcd0fda5ecfe93297cfde6ffbdec13b41d99c0ba6607" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "libc", "redox_syscall 0.4.1", ] @@ -272,7 +272,7 @@ version = "0.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "86b5213a34db3434d9c562c16af0d4da82653193805009da815cbc020e8b39df" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "libc", "redox_syscall 0.4.1", ] @@ -283,7 +283,7 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "ioslice", "libc", "redox_syscall 0.5.1", @@ -342,7 +342,7 @@ dependencies = [ "redox-daemon", "redox_event 0.3.0", "redox_termios", - "termion 2.0.3", + "termion", "url", ] @@ -453,14 +453,14 @@ dependencies = [ [[package]] name = "redox-log" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbf6d33a003a5c0b94ec11f10c7c797303f236592964ddb1bfb93e1b438a1557" +checksum = "dbd7c67eb2d8e610a74a8f1e67eecd3042f87b1aebfa620de4b40257265a54f2" dependencies = [ "chrono", "log", "smallvec", - "termion 1.5.6", + "termion", ] [[package]] @@ -469,7 +469,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "35eb92c4487aacb8d4326ae0d4d443237528a42f41b95d62858d95c6a42f0272" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "libredox 0.0.4", "redox_syscall 0.4.1", ] @@ -480,7 +480,7 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "69609faa5d5992247a4ef379917bb3e39be281405d6a0ccd4f942429400b956f" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "libredox 0.1.3", ] @@ -502,15 +502,6 @@ dependencies = [ "smoltcp", ] -[[package]] -name = "redox_syscall" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" -dependencies = [ - "bitflags 1.3.2", -] - [[package]] name = "redox_syscall" version = "0.4.1" @@ -526,7 +517,7 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", ] [[package]] @@ -613,18 +604,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "termion" -version = "1.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "077185e2eac69c3f8379a4298e1e07cd36beb962290d4a51199acf0fdc10607e" -dependencies = [ - "libc", - "numtoa", - "redox_syscall 0.2.16", - "redox_termios", -] - [[package]] name = "termion" version = "2.0.3" diff --git a/src/dnsd/scheme.rs b/src/dnsd/scheme.rs index b2ec78c17e..93a6ea7126 100644 --- a/src/dnsd/scheme.rs +++ b/src/dnsd/scheme.rs @@ -11,6 +11,7 @@ use std::str::FromStr; use std::rc::Rc; use std::net::Ipv4Addr; +use libredox::flag; use syscall::data::TimeSpec; use syscall::{Error as SyscallError, EventFlags as SyscallEventFlags, Packet as SyscallPacket, Result as SyscallResult, SchemeMut}; use syscall; @@ -430,9 +431,8 @@ impl SchemeMut for Dnsd<'_> { } let fd = self.next_fd; self.next_fd += 1; - let mut cur_time = TimeSpec::default(); - syscall::clock_gettime(syscall::CLOCK_MONOTONIC, &mut cur_time)?; - let dns_file = self.domains.file_from_domain(&domain, fd, &cur_time, self.queue); + let cur_time = libredox::call::clock_gettime(flag::CLOCK_MONOTONIC)?; + let dns_file = self.domains.file_from_domain(&domain, fd, &TimeSpec { tv_sec: cur_time.tv_sec, tv_nsec: cur_time.tv_nsec as i32 }, self.queue); self.files.insert(fd, dns_file); trace!("Open {} {}", &domain, fd); Ok(fd) @@ -462,11 +462,10 @@ impl SchemeMut for Dnsd<'_> { .get_mut(&fd) .ok_or_else(|| SyscallError::new(syscall::EBADF))?; - let mut cur_time = TimeSpec::default(); - syscall::clock_gettime(syscall::CLOCK_MONOTONIC, &mut cur_time)?; + let cur_time = libredox::call::clock_gettime(flag::CLOCK_MONOTONIC)?; if let DnsFile::Waiting { ref domain } = *file { - *file = self.domains.file_from_domain(domain, fd, &cur_time, self.queue); + *file = self.domains.file_from_domain(domain, fd, &TimeSpec { tv_sec: cur_time.tv_sec, tv_nsec: cur_time.tv_nsec as i32 }, self.queue); } match *file { diff --git a/src/smolnetd/scheme/socket.rs b/src/smolnetd/scheme/socket.rs index ec47f167cc..da5cebd9dd 100644 --- a/src/smolnetd/scheme/socket.rs +++ b/src/smolnetd/scheme/socket.rs @@ -10,7 +10,7 @@ use std::ops::DerefMut; use std::rc::Rc; use std::str; -use libredox::flag::CLOCK_MONOTONIC; +use libredox::flag::{self, CLOCK_MONOTONIC}; use syscall::{self, KSMSG_CANCEL}; use syscall::data::TimeSpec; use syscall::flag::{EVENT_READ, EVENT_WRITE}; @@ -317,9 +317,8 @@ where } pub fn notify_sockets(&mut self) -> Result<()> { - let mut cur_time = TimeSpec::default(); - syscall::clock_gettime(syscall::CLOCK_MONOTONIC, &mut cur_time) - .map_err(|e| Error::from_syscall_error(e, "Can't get time"))?; + let cur_time = libredox::call::clock_gettime(flag::CLOCK_MONOTONIC) + .map_err(|e| Error::from_syscall_error(e.into(), "Can't get time"))?; // Notify non-blocking sockets for (&fd, ref mut file) in &mut self.files { @@ -345,7 +344,7 @@ where Some(until) if (until.tv_sec < cur_time.tv_sec || (until.tv_sec == cur_time.tv_sec - && until.tv_nsec < cur_time.tv_nsec)) => + && i64::from(until.tv_nsec) < cur_time.tv_nsec)) => { self.wait_queue.remove(i); packet.a = (-syscall::ETIMEDOUT) as usize; From 9ac5184964a016874d96084e26cbda3e11c67984 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Mon, 25 Mar 2024 14:20:44 -0600 Subject: [PATCH 138/155] Fix i686 build --- src/smolnetd/scheme/socket.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/smolnetd/scheme/socket.rs b/src/smolnetd/scheme/socket.rs index da5cebd9dd..5b5f904793 100644 --- a/src/smolnetd/scheme/socket.rs +++ b/src/smolnetd/scheme/socket.rs @@ -344,7 +344,7 @@ where Some(until) if (until.tv_sec < cur_time.tv_sec || (until.tv_sec == cur_time.tv_sec - && i64::from(until.tv_nsec) < cur_time.tv_nsec)) => + && i64::from(until.tv_nsec) < i64::from(cur_time.tv_nsec))) => { self.wait_queue.remove(i); packet.a = (-syscall::ETIMEDOUT) as usize; From bafdb3b66a50ff77528421618764067ec2d55740 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 11 Jul 2024 21:08:12 +0200 Subject: [PATCH 139/155] Use the new scheme format --- src/dnsd/main.rs | 6 +++--- src/dnsd/scheme.rs | 2 +- src/smolnetd/main.rs | 28 ++++++++++++++-------------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/dnsd/main.rs b/src/dnsd/main.rs index 7a6becfd0c..41ce75854e 100644 --- a/src/dnsd/main.rs +++ b/src/dnsd/main.rs @@ -16,15 +16,15 @@ mod scheme; fn run(daemon: redox_daemon::Daemon) -> Result<()> { use libredox::flag::*; - let dns_fd = Fd::open(":dns", O_RDWR | O_CREAT | O_NONBLOCK, 0) + let dns_fd = Fd::open("/scheme/dns", O_RDWR | O_CREAT | O_NONBLOCK, 0) .context("failed to open :dns")?; - let time_path = format!("time:{}", CLOCK_MONOTONIC); + let time_path = format!("/scheme/time/{}", CLOCK_MONOTONIC); let time_fd = Fd::open(&time_path, O_RDWR, 0) .context("failed to open time")?; let nameserver_fd = Fd::open( - "netcfg:resolv/nameserver", + "/scheme/netcfg/resolv/nameserver", O_RDWR | O_CREAT | O_NONBLOCK, 0, ).context("failed to open nameserver")?; diff --git a/src/dnsd/scheme.rs b/src/dnsd/scheme.rs index 93a6ea7126..5d7ae5454f 100644 --- a/src/dnsd/scheme.rs +++ b/src/dnsd/scheme.rs @@ -68,7 +68,7 @@ impl Domains { } pub fn update_nameserver(&mut self) { - if let Ok(mut file) = File::open("netcfg:resolv/nameserver") { + if let Ok(mut file) = File::open("/scheme/netcfg/resolv/nameserver") { let mut nameserver = String::new(); if file.read_to_string(&mut nameserver).is_ok() { if let Some(line) = nameserver.lines().next() { diff --git a/src/smolnetd/main.rs b/src/smolnetd/main.rs index d16fcf3be7..1e41dab4c7 100644 --- a/src/smolnetd/main.rs +++ b/src/smolnetd/main.rs @@ -64,36 +64,36 @@ fn get_network_adapter() -> Result { fn run(daemon: redox_daemon::Daemon) -> Result<()> { let adapter = get_network_adapter()?; trace!("opening {adapter}:"); - let network_fd = Fd::open(&format!("{adapter}:"), O_RDWR | O_NONBLOCK, 0) + let network_fd = Fd::open(&format!("/scheme/{adapter}"), O_RDWR | O_NONBLOCK, 0) .map_err(|e| anyhow!("failed to open {adapter}: {e}"))?; - let hardware_addr = std::fs::read(format!("{adapter}:mac")) + let hardware_addr = std::fs::read(format!("/scheme/{adapter}/mac")) .map(|mac_address| EthernetAddress::from_bytes(&mac_address)) .context("failed to get mac address from network adapter")?; - trace!("opening :ip"); - let ip_fd = Fd::open(":ip", O_RDWR | O_CREAT | O_NONBLOCK, 0) + trace!("opening /scheme/ip"); + let ip_fd = Fd::open("/scheme/ip", O_RDWR | O_CREAT | O_NONBLOCK, 0) .context("failed to open :ip")?; - trace!("opening :udp"); - let udp_fd = Fd::open(":udp", O_RDWR | O_CREAT | O_NONBLOCK, 0) + trace!("opening /scheme/udp"); + let udp_fd = Fd::open("/scheme/udp", O_RDWR | O_CREAT | O_NONBLOCK, 0) .context("failed to open :udp")?; - trace!("opening :tcp"); - let tcp_fd = Fd::open(":tcp", O_RDWR | O_CREAT | O_NONBLOCK, 0) + trace!("opening /scheme/tcp"); + let tcp_fd = Fd::open("/scheme/tcp", O_RDWR | O_CREAT | O_NONBLOCK, 0) .context("failed to open :tcp")?; - trace!("opening :icmp"); - let icmp_fd = Fd::open(":icmp", O_RDWR | O_CREAT | O_NONBLOCK, 0) + trace!("opening /scheme/icmp"); + let icmp_fd = Fd::open("/scheme/icmp", O_RDWR | O_CREAT | O_NONBLOCK, 0) .context("failed to open :icmp")?; - trace!("opening :netcfg"); - let netcfg_fd = Fd::open(":netcfg", O_RDWR | O_CREAT | O_NONBLOCK, 0) + trace!("opening /scheme/netcfg"); + let netcfg_fd = Fd::open("/scheme/netcfg", O_RDWR | O_CREAT | O_NONBLOCK, 0) .context("failed to open :netcfg")?; - let time_path = format!("time:{}", syscall::CLOCK_MONOTONIC); + let time_path = format!("/scheme/time/{}", syscall::CLOCK_MONOTONIC); let time_fd = Fd::open(&time_path, O_RDWR, 0) - .context("failed to open time:")?; + .context("failed to open /scheme/time")?; event::user_data! { enum EventSource { From 6274b0767474fd4f159f7aaccc800d4d6feb1ee6 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 12 Jul 2024 11:58:12 +0200 Subject: [PATCH 140/155] Fix things I broke --- src/dnsd/main.rs | 2 +- src/smolnetd/main.rs | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/dnsd/main.rs b/src/dnsd/main.rs index 41ce75854e..6b44f2817f 100644 --- a/src/dnsd/main.rs +++ b/src/dnsd/main.rs @@ -16,7 +16,7 @@ mod scheme; fn run(daemon: redox_daemon::Daemon) -> Result<()> { use libredox::flag::*; - let dns_fd = Fd::open("/scheme/dns", O_RDWR | O_CREAT | O_NONBLOCK, 0) + let dns_fd = Fd::open(":dns", O_RDWR | O_CREAT | O_NONBLOCK, 0) .context("failed to open :dns")?; let time_path = format!("/scheme/time/{}", CLOCK_MONOTONIC); diff --git a/src/smolnetd/main.rs b/src/smolnetd/main.rs index 1e41dab4c7..d937c0383d 100644 --- a/src/smolnetd/main.rs +++ b/src/smolnetd/main.rs @@ -71,24 +71,24 @@ fn run(daemon: redox_daemon::Daemon) -> Result<()> { .map(|mac_address| EthernetAddress::from_bytes(&mac_address)) .context("failed to get mac address from network adapter")?; - trace!("opening /scheme/ip"); - let ip_fd = Fd::open("/scheme/ip", O_RDWR | O_CREAT | O_NONBLOCK, 0) + trace!("opening :ip"); + let ip_fd = Fd::open(":ip", O_RDWR | O_CREAT | O_NONBLOCK, 0) .context("failed to open :ip")?; - trace!("opening /scheme/udp"); - let udp_fd = Fd::open("/scheme/udp", O_RDWR | O_CREAT | O_NONBLOCK, 0) + trace!("opening :udp"); + let udp_fd = Fd::open(":udp", O_RDWR | O_CREAT | O_NONBLOCK, 0) .context("failed to open :udp")?; - trace!("opening /scheme/tcp"); - let tcp_fd = Fd::open("/scheme/tcp", O_RDWR | O_CREAT | O_NONBLOCK, 0) + trace!("opening :tcp"); + let tcp_fd = Fd::open(":tcp", O_RDWR | O_CREAT | O_NONBLOCK, 0) .context("failed to open :tcp")?; - trace!("opening /scheme/icmp"); - let icmp_fd = Fd::open("/scheme/icmp", O_RDWR | O_CREAT | O_NONBLOCK, 0) + trace!("opening :icmp"); + let icmp_fd = Fd::open(":icmp", O_RDWR | O_CREAT | O_NONBLOCK, 0) .context("failed to open :icmp")?; - trace!("opening /scheme/netcfg"); - let netcfg_fd = Fd::open("/scheme/netcfg", O_RDWR | O_CREAT | O_NONBLOCK, 0) + trace!("opening :netcfg"); + let netcfg_fd = Fd::open(":netcfg", O_RDWR | O_CREAT | O_NONBLOCK, 0) .context("failed to open :netcfg")?; let time_path = format!("/scheme/time/{}", syscall::CLOCK_MONOTONIC); From 640e5489722bb19aad310675c959b157128b416c Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Wed, 4 Sep 2024 14:55:48 -0600 Subject: [PATCH 141/155] Use 0.0.0.0 as default IP to fix DHCP on real system --- src/smolnetd/scheme/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/smolnetd/scheme/mod.rs b/src/smolnetd/scheme/mod.rs index 32795bcefc..4adcc55313 100644 --- a/src/smolnetd/scheme/mod.rs +++ b/src/smolnetd/scheme/mod.rs @@ -75,7 +75,8 @@ impl Smolnetd { netcfg_file: Fd, ) -> Smolnetd { let protocol_addrs = vec![ - IpCidr::new(IpAddress::v4(127, 0, 0, 1), 8), + //This is a placeholder IP for DHCP + IpCidr::new(IpAddress::v4(0, 0, 0, 0), 8), ]; let default_gw = Ipv4Address::from_str(getcfg("ip_router").unwrap().trim()) From 2a3fb788dfe0bf76476ed8332b3f9f551e045c97 Mon Sep 17 00:00:00 2001 From: Andrey Turkin Date: Thu, 17 Oct 2024 08:11:02 +0300 Subject: [PATCH 142/155] Bump dependencies --- Cargo.lock | 289 ++++++++++++++++++++++++----------------------------- 1 file changed, 132 insertions(+), 157 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 19a878c531..e7b167276b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19,9 +19,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.81" +version = "1.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0952808a6c2afd1aa8947271f3a60f1a6763c7b912d210184c5149b5cf147247" +checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" [[package]] name = "arg_parser" @@ -39,9 +39,9 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.1.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" [[package]] name = "bitflags" @@ -51,15 +51,15 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.5.0" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "bumpalo" -version = "3.15.4" +version = "3.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ff69b9dd49fd426c69a0db9fc04dd934cdb6645ff000864d98f7e2af8830eaa" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" [[package]] name = "byteorder" @@ -75,9 +75,12 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "cc" -version = "1.0.90" +version = "1.1.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cd6604a82acf3039f1144f54b8eb34e91ffba622051189e71b781822d5ee1f5" +checksum = "b16803a61b81d9eabb7eae2588776c4c1e584b738ede45fdbb4c972cec1e9945" +dependencies = [ + "shlex", +] [[package]] name = "cfg-if" @@ -93,9 +96,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.35" +version = "0.4.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8eaf5903dcbc0a39312feb77df2ff4c76387d591b9fc7b04a238dcf8bb62639a" +checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" dependencies = [ "android-tzdata", "iana-time-zone", @@ -107,36 +110,36 @@ dependencies = [ [[package]] name = "core-foundation-sys" -version = "0.8.6" +version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" [[package]] name = "critical-section" -version = "1.1.2" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7059fff8937831a9ae6f0fe4d658ffabf58f2ca96aa9dec1c889f936f705f216" +checksum = "790eea4361631c5e7d22598ecd5723ff611904e3344ce8720784c93e3d83d40b" [[package]] name = "crossbeam-channel" -version = "0.5.12" +version = "0.5.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab3db02a9c5b5121e1e42fbdb1aeb65f5e02624cc58c43f2884c6ccac0b82f95" +checksum = "33480d6946193aa8033910124896ca395333cae7e2d1113d1fef6c3272217df2" dependencies = [ "crossbeam-utils", ] [[package]] name = "crossbeam-utils" -version = "0.8.19" +version = "0.8.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" +checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" [[package]] name = "defmt" -version = "0.3.6" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3939552907426de152b3c2c6f51ed53f98f448babd26f28694c95f5906194595" +checksum = "a99dd22262668b887121d4672af5a64b238f026099f1a2a1b322066c9ecfe9e0" dependencies = [ "bitflags 1.3.2", "defmt-macros", @@ -144,15 +147,15 @@ dependencies = [ [[package]] name = "defmt-macros" -version = "0.3.7" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18bdc7a7b92ac413e19e95240e75d3a73a8d8e78aa24a594c22cbb4d44b4bbda" +checksum = "e3a9f309eff1f79b3ebdf252954d90ae440599c26c2c553fe87a2d17195f2dcb" dependencies = [ "defmt-parser", "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.53", + "syn 2.0.79", ] [[package]] @@ -198,9 +201,9 @@ dependencies = [ [[package]] name = "iana-time-zone" -version = "0.1.60" +version = "0.1.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" +checksum = "235e081f3925a06703c2d0117ea8b91f042756fd6e7a6e5d901e8ca1a996b220" dependencies = [ "android_system_properties", "core-foundation-sys", @@ -242,40 +245,18 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.69" +version = "0.3.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" +checksum = "6a88f1bda2bd75b0452a14784937d796722fdebfe50df998aeb3f0b7603019a9" dependencies = [ "wasm-bindgen", ] [[package]] name = "libc" -version = "0.2.153" +version = "0.2.160" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" - -[[package]] -name = "libredox" -version = "0.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3af92c55d7d839293953fcd0fda5ecfe93297cfde6ffbdec13b41d99c0ba6607" -dependencies = [ - "bitflags 2.5.0", - "libc", - "redox_syscall 0.4.1", -] - -[[package]] -name = "libredox" -version = "0.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86b5213a34db3434d9c562c16af0d4da82653193805009da815cbc020e8b39df" -dependencies = [ - "bitflags 2.5.0", - "libc", - "redox_syscall 0.4.1", -] +checksum = "f0b21006cd1874ae9e650973c565615676dc4a274c965bb0a73796dac838ce4f" [[package]] name = "libredox" @@ -283,17 +264,17 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" dependencies = [ - "bitflags 2.5.0", + "bitflags 2.6.0", "ioslice", "libc", - "redox_syscall 0.5.1", + "redox_syscall", ] [[package]] name = "lock_api" -version = "0.4.11" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ "autocfg", "scopeguard", @@ -301,9 +282,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.21" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" [[package]] name = "managed" @@ -330,17 +311,17 @@ dependencies = [ [[package]] name = "netutils" version = "0.1.0" -source = "git+https://gitlab.redox-os.org/redox-os/netutils.git#c78177b7d7a694511d88a6b04df3e9d04ed7c78e" +source = "git+https://gitlab.redox-os.org/redox-os/netutils.git#197e0ed0a0ce637653b33f6076c08afeac8cda16" dependencies = [ "anyhow", "arg_parser", "libc", - "libredox 0.0.4", + "libredox", "net2", "ntpclient", "pbr", "redox-daemon", - "redox_event 0.3.0", + "redox_event", "redox_termios", "termion", "url", @@ -357,24 +338,24 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.18" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] [[package]] name = "numtoa" -version = "0.1.0" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef" +checksum = "6aa2c4e539b869820a2b82e1aef6ff40aa85e65decdd5185e83fb4b1249cd00f" [[package]] name = "once_cell" -version = "1.19.0" +version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" [[package]] name = "pbr" @@ -419,9 +400,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.79" +version = "1.0.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e" +checksum = "7c3a7fc5db1e57d5a779a352c8cdb57b29aa4c40cc69c3a68a7fedc815fbf2f9" dependencies = [ "unicode-ident", ] @@ -434,9 +415,9 @@ checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" [[package]] name = "quote" -version = "1.0.35" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -448,14 +429,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7fbdeffdb03cf2961b211a2023e683d71f2c225ea93404da5dc34b0dc94f0341" dependencies = [ "libc", - "libredox 0.1.3", + "libredox", ] [[package]] name = "redox-log" -version = "0.1.2" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbd7c67eb2d8e610a74a8f1e67eecd3042f87b1aebfa620de4b40257265a54f2" +checksum = "81460b1526438123d16f0c968dbe42ba7f61e99645109b70e57864a8b66710fb" dependencies = [ "chrono", "log", @@ -463,25 +444,14 @@ dependencies = [ "termion", ] -[[package]] -name = "redox_event" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35eb92c4487aacb8d4326ae0d4d443237528a42f41b95d62858d95c6a42f0272" -dependencies = [ - "bitflags 2.5.0", - "libredox 0.0.4", - "redox_syscall 0.4.1", -] - [[package]] name = "redox_event" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "69609faa5d5992247a4ef379917bb3e39be281405d6a0ccd4f942429400b956f" dependencies = [ - "bitflags 2.5.0", - "libredox 0.1.3", + "bitflags 2.6.0", + "libredox", ] [[package]] @@ -492,32 +462,23 @@ dependencies = [ "byteorder 1.5.0", "dns-parser", "ioslice", - "libredox 0.1.3", + "libredox", "log", "netutils", "redox-daemon", "redox-log", - "redox_event 0.4.1", - "redox_syscall 0.5.1", + "redox_event", + "redox_syscall", "smoltcp", ] [[package]] name = "redox_syscall" -version = "0.4.1" +version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" dependencies = [ - "bitflags 1.3.2", -] - -[[package]] -name = "redox_syscall" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" -dependencies = [ - "bitflags 2.5.0", + "bitflags 2.6.0", ] [[package]] @@ -528,9 +489,9 @@ checksum = "20145670ba436b55d91fc92d25e71160fbfbdd57831631c8d7d36377a476f1cb" [[package]] name = "rustc_version" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" dependencies = [ "semver", ] @@ -543,15 +504,21 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "semver" -version = "1.0.22" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca" +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" [[package]] name = "smallvec" -version = "1.13.1" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "smoltcp" @@ -595,9 +562,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.53" +version = "2.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7383cd0e49fff4b6b90ca5670bfd3e9d6a733b3f90c686605aa7eec8c4996032" +checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" dependencies = [ "proc-macro2", "quote", @@ -606,34 +573,34 @@ dependencies = [ [[package]] name = "termion" -version = "2.0.3" +version = "4.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4648c7def6f2043b2568617b9f9b75eae88ca185dbc1f1fda30e95a85d49d7d" +checksum = "7eaa98560e51a2cf4f0bb884d8b2098a9ea11ecf3b7078e9c68242c74cc923a7" dependencies = [ "libc", - "libredox 0.0.2", + "libredox", "numtoa", "redox_termios", ] [[package]] name = "thiserror" -version = "1.0.58" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297" +checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.58" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" +checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.53", + "syn 2.0.79", ] [[package]] @@ -649,9 +616,9 @@ dependencies = [ [[package]] name = "tinyvec" -version = "1.6.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" dependencies = [ "tinyvec_macros", ] @@ -664,21 +631,21 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "unicode-bidi" -version = "0.3.15" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" +checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" [[package]] name = "unicode-ident" -version = "1.0.12" +version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" [[package]] name = "unicode-normalization" -version = "0.1.23" +version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" dependencies = [ "tinyvec", ] @@ -696,9 +663,9 @@ dependencies = [ [[package]] name = "version_check" -version = "0.9.4" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" [[package]] name = "wasi" @@ -708,34 +675,35 @@ checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" [[package]] name = "wasm-bindgen" -version = "0.2.92" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" +checksum = "128d1e363af62632b8eb57219c8fd7877144af57558fb2ef0368d0087bddeb2e" dependencies = [ "cfg-if 1.0.0", + "once_cell", "wasm-bindgen-macro", ] [[package]] name = "wasm-bindgen-backend" -version = "0.2.92" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" +checksum = "cb6dd4d3ca0ddffd1dd1c9c04f94b868c37ff5fac97c30b97cff2d74fce3a358" dependencies = [ "bumpalo", "log", "once_cell", "proc-macro2", "quote", - "syn 2.0.53", + "syn 2.0.79", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-macro" -version = "0.2.92" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" +checksum = "e79384be7f8f5a9dd5d7167216f022090cf1f9ec128e6e6a482a2cb5c5422c56" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -743,22 +711,22 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.92" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" +checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68" dependencies = [ "proc-macro2", "quote", - "syn 2.0.53", + "syn 2.0.79", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.92" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" +checksum = "65fc09f10666a9f147042251e0dda9c18f166ff7de300607007e96bdebc1068d" [[package]] name = "winapi" @@ -793,13 +761,14 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.52.4" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ "windows_aarch64_gnullvm", "windows_aarch64_msvc", "windows_i686_gnu", + "windows_i686_gnullvm", "windows_i686_msvc", "windows_x86_64_gnu", "windows_x86_64_gnullvm", @@ -808,45 +777,51 @@ dependencies = [ [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.4" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" [[package]] name = "windows_aarch64_msvc" -version = "0.52.4" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" [[package]] name = "windows_i686_gnu" -version = "0.52.4" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" [[package]] name = "windows_i686_msvc" -version = "0.52.4" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" [[package]] name = "windows_x86_64_gnu" -version = "0.52.4" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.4" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" [[package]] name = "windows_x86_64_msvc" -version = "0.52.4" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[patch.unused]] name = "mio" From 49abe218ab79140b233d21a1c8097a727f9a5950 Mon Sep 17 00:00:00 2001 From: Steffen Butzer Date: Tue, 26 Nov 2024 19:02:21 +0000 Subject: [PATCH 143/155] Respond only to ARP requests addressed to device via either broadcast or unicast Previous behavior would reply to other IPs that only match the subnet with our (IP, MAC) pair but not respond to unicast requests addressed with an unknown (all zeroes) MAC or broadcast requests. --- src/smolnetd/link/ethernet.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/smolnetd/link/ethernet.rs b/src/smolnetd/link/ethernet.rs index 111569aee9..4f3a2dfb3a 100644 --- a/src/smolnetd/link/ethernet.rs +++ b/src/smolnetd/link/ethernet.rs @@ -124,7 +124,9 @@ impl EthernetLink { target_hardware_addr, target_protocol_addr, } => { - if hardware_address != target_hardware_addr { + let is_unicast_mac = target_hardware_addr != EMPTY_MAC && !target_hardware_addr.is_broadcast(); + + if is_unicast_mac && hardware_address != target_hardware_addr { // Only process packet that are for us return; } @@ -137,7 +139,7 @@ impl EthernetLink { return; } - if !ip_addr.contains_addr(&target_protocol_addr) { + if ip_addr.address() != target_protocol_addr { return; } From b53fb068f5216b356a5634db28681728c2d43fc2 Mon Sep 17 00:00:00 2001 From: Josh Megnauth Date: Sat, 21 Dec 2024 01:41:05 -0500 Subject: [PATCH 144/155] fix: MAX_DURATION overflows on init Closes: #33 `Duration` is stored as microseconds internally. The original code caused an overflow by... ```rust Duration::from_millis(u64::MAX); ``` ...which caused `u64::MAX` to be multiplied by 1000 and overflow. --- src/smolnetd/scheme/mod.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/smolnetd/scheme/mod.rs b/src/smolnetd/scheme/mod.rs index 4adcc55313..789efc07c1 100644 --- a/src/smolnetd/scheme/mod.rs +++ b/src/smolnetd/scheme/mod.rs @@ -40,8 +40,8 @@ mod udp; type SocketSet = SmoltcpSocketSet<'static>; type Interface = Rc>; -const MAX_DURATION: Duration = Duration::from_millis(u64::MAX); -const MIN_DURATION: Duration = Duration::from_millis(0); +const MAX_DURATION: Duration = Duration::from_micros(u64::MAX); +const MIN_DURATION: Duration = Duration::from_micros(0); pub struct Smolnetd { router_device: Tracer, @@ -108,11 +108,9 @@ impl Smolnetd { "127.0.0.1".parse().unwrap(), )); - - let mut eth0 = EthernetLink::new( - "eth0", - unsafe { File::from_raw_fd(network_file.into_raw() as RawFd) }, - ); + let mut eth0 = EthernetLink::new("eth0", unsafe { + File::from_raw_fd(network_file.into_raw() as RawFd) + }); eth0.set_mac_address(hardware_addr); devices.borrow_mut().push(loopback); From 9c7c874cbcfbca23e33cdb2309bdc8a0a45f64a0 Mon Sep 17 00:00:00 2001 From: Ribbon Date: Thu, 9 Jan 2025 11:58:27 +0000 Subject: [PATCH 145/155] Document how to contribute and do developpment in the README --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index b5c71c0b76..633dd04a1e 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,19 @@ # Redox OS userspace networking stack This repository contains the networking stack for Redox OS. It makes use of [smoltcp](https://github.com/m-labs/smoltcp). + +## How To Contribute + +To learn how to contribute to this system component you need to read the following document: + +- [CONTRIBUTING.md](https://gitlab.redox-os.org/redox-os/redox/-/blob/master/CONTRIBUTING.md) + +## Development + +To learn how to do development with this system component inside the Redox build system you need to read the [Build System](https://doc.redox-os.org/book/build-system-reference.html) and [Coding and Building](https://doc.redox-os.org/book/coding-and-building.html) pages. + +### How To Build + +To build this system component you need to download the Redox build system, you can learn how to do it on the [Building Redox](https://doc.redox-os.org/book/podman-build.html) page. + +This is necessary because they only work with cross-compilation to a Redox virtual machine, but you can do some testing from Linux. From da0b2846469ed2c9e51c9eceef09dddae20ae1ae Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 9 Mar 2025 17:46:15 +0100 Subject: [PATCH 146/155] Remove unused smoltcp submodule --- smoltcp | 1 - 1 file changed, 1 deletion(-) delete mode 160000 smoltcp diff --git a/smoltcp b/smoltcp deleted file mode 160000 index be52c19154..0000000000 --- a/smoltcp +++ /dev/null @@ -1 +0,0 @@ -Subproject commit be52c19154231c553766be9efc434c3b9bc3ab05 From 023459391cd8a31fa6570babefd0f6dcaf028a59 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 9 Mar 2025 17:46:33 +0100 Subject: [PATCH 147/155] Remove unused dependency patch --- Cargo.lock | 7 +------ Cargo.toml | 1 - 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e7b167276b..50f827ab8b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "android-tzdata" @@ -822,8 +822,3 @@ name = "windows_x86_64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" - -[[patch.unused]] -name = "mio" -version = "0.6.14" -source = "git+https://gitlab.redox-os.org/redox-os/mio.git?branch=redox-unix#c9a70849ced97387e2607c9c466d23b130ec8901" diff --git a/Cargo.toml b/Cargo.toml index 9113191568..232c5b730c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -49,5 +49,4 @@ features = [ lto = true [patch.crates-io] -mio = { git = "https://gitlab.redox-os.org/redox-os/mio.git", branch = "redox-unix" } net2 = { git = "https://gitlab.redox-os.org/redox-os/net2-rs.git", branch = "master" } From 576136d01c5a679518f09048df717687a1f73677 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 9 Mar 2025 17:47:42 +0100 Subject: [PATCH 148/155] Rustfmt --- src/dnsd/main.rs | 42 ++++++----- src/dnsd/scheme.rs | 99 +++++++++++++++++++------- src/lib/error.rs | 4 +- src/lib/lib.rs | 2 +- src/lib/logger.rs | 19 ++--- src/smolnetd/buffer_pool.rs | 4 +- src/smolnetd/link/ethernet.rs | 11 ++- src/smolnetd/link/loopback.rs | 5 +- src/smolnetd/link/mod.rs | 5 +- src/smolnetd/main.rs | 60 +++++++++------- src/smolnetd/scheme/icmp.rs | 34 ++++----- src/smolnetd/scheme/ip.rs | 14 ++-- src/smolnetd/scheme/netcfg/mod.rs | 2 +- src/smolnetd/scheme/netcfg/nodes.rs | 2 +- src/smolnetd/scheme/netcfg/notifier.rs | 4 +- src/smolnetd/scheme/socket.rs | 14 ++-- src/smolnetd/scheme/tcp.rs | 2 +- src/smolnetd/scheme/udp.rs | 24 ++++--- 18 files changed, 216 insertions(+), 131 deletions(-) diff --git a/src/dnsd/main.rs b/src/dnsd/main.rs index 6b44f2817f..5a4392a82a 100644 --- a/src/dnsd/main.rs +++ b/src/dnsd/main.rs @@ -1,7 +1,7 @@ #[macro_use] extern crate log; -use anyhow::{Error, Result, Context}; +use anyhow::{Context, Error, Result}; use event::EventQueue; use ioslice::IoSlice; use libredox::Fd; @@ -16,27 +16,34 @@ mod scheme; fn run(daemon: redox_daemon::Daemon) -> Result<()> { use libredox::flag::*; - let dns_fd = Fd::open(":dns", O_RDWR | O_CREAT | O_NONBLOCK, 0) - .context("failed to open :dns")?; + let dns_fd = + Fd::open(":dns", O_RDWR | O_CREAT | O_NONBLOCK, 0).context("failed to open :dns")?; let time_path = format!("/scheme/time/{}", CLOCK_MONOTONIC); - let time_fd = Fd::open(&time_path, O_RDWR, 0) - .context("failed to open time")?; + let time_fd = Fd::open(&time_path, O_RDWR, 0).context("failed to open time")?; let nameserver_fd = Fd::open( "/scheme/netcfg/resolv/nameserver", O_RDWR | O_CREAT | O_NONBLOCK, 0, - ).context("failed to open nameserver")?; + ) + .context("failed to open nameserver")?; - let event_queue = EventQueue::::new() - .context("failed to create event queue")?; + let event_queue = EventQueue::::new().context("failed to create event queue")?; event_queue - .subscribe(dns_fd.raw(), EventSource::DnsScheme, event::EventFlags::READ) + .subscribe( + dns_fd.raw(), + EventSource::DnsScheme, + event::EventFlags::READ, + ) .context("failed to listen to time events")?; event_queue - .subscribe(nameserver_fd.raw(), EventSource::NameserverScheme, event::EventFlags::READ) + .subscribe( + nameserver_fd.raw(), + EventSource::NameserverScheme, + event::EventFlags::READ, + ) .context("failed to listen to nameserver socket events")?; event_queue .subscribe(time_fd.raw(), EventSource::Timer, event::EventFlags::READ) @@ -51,8 +58,8 @@ fn run(daemon: redox_daemon::Daemon) -> Result<()> { let mut dnsd = Dnsd::new(dns_file, time_file, &event_queue); - let new_ns = libredox::call::mkns(&[IoSlice::new(b"dns")]) - .expect("dnsd: failed to create namespace"); + let new_ns = + libredox::call::mkns(&[IoSlice::new(b"dns")]).expect("dnsd: failed to create namespace"); libredox::call::setrens(new_ns, new_ns).expect("dnsd: failed to enter namespace"); daemon.ready().expect("dnsd: failed to notify parent"); @@ -60,9 +67,11 @@ fn run(daemon: redox_daemon::Daemon) -> Result<()> { for event_res in event_queue.iter() { let event = event_res.context("failed to read from event queue")?; match event.user_data { - EventSource::DnsScheme => if !dnsd.on_dns_file_event()? { - break - }, + EventSource::DnsScheme => { + if !dnsd.on_dns_file_event()? { + break; + } + } EventSource::NameserverScheme => dnsd.on_nameserver_event()?, EventSource::Timer => dnsd.on_time_event()?, EventSource::Other => dnsd.on_unknown_fd_event(event.fd as RawFd)?, @@ -79,7 +88,8 @@ fn main() { process::exit(1); } process::exit(0); - }).expect("dnsd: failed to daemonize"); + }) + .expect("dnsd: failed to daemonize"); } event::user_data! { diff --git a/src/dnsd/scheme.rs b/src/dnsd/scheme.rs index 5d7ae5454f..1c9a432605 100644 --- a/src/dnsd/scheme.rs +++ b/src/dnsd/scheme.rs @@ -1,20 +1,23 @@ use std::borrow::ToOwned; -use std::collections::{BTreeMap, BTreeSet}; -use std::collections::VecDeque; use std::collections::btree_map::Entry; +use std::collections::VecDeque; +use std::collections::{BTreeMap, BTreeSet}; use std::fs::File; use std::io::{ErrorKind, Read, Write}; use std::mem; +use std::net::Ipv4Addr; use std::os::unix::io::RawFd; +use std::rc::Rc; use std::str; use std::str::FromStr; -use std::rc::Rc; -use std::net::Ipv4Addr; use libredox::flag; -use syscall::data::TimeSpec; -use syscall::{Error as SyscallError, EventFlags as SyscallEventFlags, Packet as SyscallPacket, Result as SyscallResult, SchemeMut}; use syscall; +use syscall::data::TimeSpec; +use syscall::{ + Error as SyscallError, EventFlags as SyscallEventFlags, Packet as SyscallPacket, + Result as SyscallResult, SchemeMut, +}; use event::EventQueue; use redox_netstack::error::{Error, Result}; @@ -90,17 +93,25 @@ impl Domains { &format!("udp:{}:53", self.nameserver), libredox::flag::O_RDWR | libredox::flag::O_CREAT | libredox::flag::O_NONBLOCK, 0, - ).ok()?; + ) + .ok()?; if libredox::call::write(udp_fd, &packet) != Ok(packet.len()) { libredox::call::close(udp_fd).ok()?; return None; } - queue.subscribe(udp_fd, EventSource::Other, event::EventFlags::READ).ok()?; - self.requests.insert(udp_fd as RawFd, domain.to_owned().into()); + queue + .subscribe(udp_fd, EventSource::Other, event::EventFlags::READ) + .ok()?; + self.requests + .insert(udp_fd as RawFd, domain.to_owned().into()); Some(udp_fd as RawFd) } - fn on_time_event(&mut self, cur_time: &TimeSpec, queue: &EventQueue) -> Result> { + fn on_time_event( + &mut self, + cur_time: &TimeSpec, + queue: &EventQueue, + ) -> Result> { while let Some((timeout, domain)) = self.resolved_timeouts.pop_front() { if timeout.tv_sec > cur_time.tv_sec || (timeout.tv_sec == cur_time.tv_sec && timeout.tv_nsec > cur_time.tv_nsec) @@ -139,7 +150,9 @@ impl Domains { } = e.remove() { fds_to_wakeup.append(&mut waiting_fds); - queue.unsubscribe(socket_fd as usize).map_err(|e| Error::from_syscall_error(e.into(), "unsubscribe failure"))?; + queue.unsubscribe(socket_fd as usize).map_err(|e| { + Error::from_syscall_error(e.into(), "unsubscribe failure") + })?; let _ = libredox::call::close(socket_fd as usize); } } @@ -150,7 +163,12 @@ impl Domains { Ok(fds_to_wakeup) } - fn on_fd_event(&mut self, fd: RawFd, cur_time: &TimeSpec, queue: &EventQueue) -> Option { + fn on_fd_event( + &mut self, + fd: RawFd, + cur_time: &TimeSpec, + queue: &EventQueue, + ) -> Option { let e = match self.requests.entry(fd) { Entry::Vacant(_) => { return None; @@ -227,7 +245,13 @@ impl Domains { } } - fn file_from_domain(&mut self, domain: &str, fd: usize, cur_time: &TimeSpec, queue: &EventQueue) -> DnsFile { + fn file_from_domain( + &mut self, + domain: &str, + fd: usize, + cur_time: &TimeSpec, + queue: &EventQueue, + ) -> DnsFile { if let Some(domain_data) = self.domains.get_mut(domain) { match *domain_data { Domain::Resolved { ref data } => DnsFile::Resolved { @@ -339,12 +363,14 @@ impl<'q> Dnsd<'q> { Ok(0) => { //TODO: Cleanup must occur return Ok(false); - }, + } Ok(_) => (), - Err(err) => if err.kind() == ErrorKind::WouldBlock { - return Ok(true); - } else { - return Err(Error::from(err)); + Err(err) => { + if err.kind() == ErrorKind::WouldBlock { + return Ok(true); + } else { + return Err(Error::from(err)); + } } } // TODO: implement cancellation @@ -364,7 +390,10 @@ impl<'q> Dnsd<'q> { let cur_time = libredox::call::clock_gettime(libredox::flag::CLOCK_MONOTONIC) .map_err(|e| Error::from_syscall_error(e.into(), "Can't get time"))?; // TODO - let cur_time = TimeSpec { tv_sec: cur_time.tv_sec, tv_nsec: cur_time.tv_nsec as _ }; + let cur_time = TimeSpec { + tv_sec: cur_time.tv_sec, + tv_nsec: cur_time.tv_nsec as _, + }; match self.domains.on_fd_event(fd, &cur_time, self.queue) { Some(DnsParsingResult::FailFiles(fds_to_fail)) => { @@ -432,7 +461,15 @@ impl SchemeMut for Dnsd<'_> { let fd = self.next_fd; self.next_fd += 1; let cur_time = libredox::call::clock_gettime(flag::CLOCK_MONOTONIC)?; - let dns_file = self.domains.file_from_domain(&domain, fd, &TimeSpec { tv_sec: cur_time.tv_sec, tv_nsec: cur_time.tv_nsec as i32 }, self.queue); + let dns_file = self.domains.file_from_domain( + &domain, + fd, + &TimeSpec { + tv_sec: cur_time.tv_sec, + tv_nsec: cur_time.tv_nsec as i32, + }, + self.queue, + ); self.files.insert(fd, dns_file); trace!("Open {} {}", &domain, fd); Ok(fd) @@ -440,7 +477,8 @@ impl SchemeMut for Dnsd<'_> { fn close(&mut self, fd: usize) -> SyscallResult { trace!("Close {}", fd); - let file = self.files + let file = self + .files .get_mut(&fd) .ok_or_else(|| SyscallError::new(syscall::EBADF))?; @@ -458,14 +496,23 @@ impl SchemeMut for Dnsd<'_> { fn read(&mut self, fd: usize, buf: &mut [u8]) -> SyscallResult { trace!("Read {}", fd); - let file = self.files + let file = self + .files .get_mut(&fd) .ok_or_else(|| SyscallError::new(syscall::EBADF))?; let cur_time = libredox::call::clock_gettime(flag::CLOCK_MONOTONIC)?; if let DnsFile::Waiting { ref domain } = *file { - *file = self.domains.file_from_domain(domain, fd, &TimeSpec { tv_sec: cur_time.tv_sec, tv_nsec: cur_time.tv_nsec as i32 }, self.queue); + *file = self.domains.file_from_domain( + domain, + fd, + &TimeSpec { + tv_sec: cur_time.tv_sec, + tv_nsec: cur_time.tv_nsec as i32, + }, + self.queue, + ); } match *file { @@ -487,7 +534,11 @@ impl SchemeMut for Dnsd<'_> { } } - fn fevent(&mut self, _fd: usize, _events: SyscallEventFlags) -> SyscallResult { + fn fevent( + &mut self, + _fd: usize, + _events: SyscallEventFlags, + ) -> SyscallResult { Ok(SyscallEventFlags::empty()) } diff --git a/src/lib/error.rs b/src/lib/error.rs index 3f4cc46630..f21d3860ea 100644 --- a/src/lib/error.rs +++ b/src/lib/error.rs @@ -1,7 +1,7 @@ use std::convert; use std::fmt; -use std::result; use std::io::Error as IOError; +use std::result; use syscall::error::Error as SyscallError; #[derive(Debug)] @@ -35,7 +35,7 @@ impl Error { pub fn other_error>(descr: S) -> Error { Error { error_type: ErrorType::Other, - descr: descr.into() + descr: descr.into(), } } } diff --git a/src/lib/lib.rs b/src/lib/lib.rs index 1f328082fb..1dddb0da53 100644 --- a/src/lib/lib.rs +++ b/src/lib/lib.rs @@ -1,5 +1,5 @@ extern crate log; extern crate syscall; -pub mod logger; pub mod error; +pub mod logger; diff --git a/src/lib/logger.rs b/src/lib/logger.rs index e2952e98db..d854b4c773 100644 --- a/src/lib/logger.rs +++ b/src/lib/logger.rs @@ -2,15 +2,16 @@ use redox_log::{OutputBuilder, RedoxLogger}; pub fn init_logger(process_name: &str) { if let Err(_) = RedoxLogger::new() - .with_output( - OutputBuilder::stdout() - .with_ansi_escape_codes() - .flush_on_newline(true) - .with_filter(log::LevelFilter::Trace) - .build(), - ) - .with_process_name(process_name.into()) - .enable() { + .with_output( + OutputBuilder::stdout() + .with_ansi_escape_codes() + .flush_on_newline(true) + .with_filter(log::LevelFilter::Trace) + .build(), + ) + .with_process_name(process_name.into()) + .enable() + { eprintln!("{process_name}: Failed to init logger") } } diff --git a/src/smolnetd/buffer_pool.rs b/src/smolnetd/buffer_pool.rs index 38f971bd7f..5991f9ece3 100644 --- a/src/smolnetd/buffer_pool.rs +++ b/src/smolnetd/buffer_pool.rs @@ -1,7 +1,7 @@ -use std::ops::{Deref, DerefMut, Drop}; -use std::rc::Rc; use std::cell::RefCell; use std::mem::{replace, swap}; +use std::ops::{Deref, DerefMut, Drop}; +use std::rc::Rc; type BufferStack = Rc>>>; diff --git a/src/smolnetd/link/ethernet.rs b/src/smolnetd/link/ethernet.rs index 4f3a2dfb3a..58dfab3d13 100644 --- a/src/smolnetd/link/ethernet.rs +++ b/src/smolnetd/link/ethernet.rs @@ -111,7 +111,8 @@ impl EthernetLink { return; }; - let Ok(repr) = ArpPacket::new_checked(packet).and_then(|packet| ArpRepr::parse(&packet)) else { + let Ok(repr) = ArpPacket::new_checked(packet).and_then(|packet| ArpRepr::parse(&packet)) + else { debug!("Dropped incomming arp packet on {} (Malformed)", self.name); return; }; @@ -124,7 +125,8 @@ impl EthernetLink { target_hardware_addr, target_protocol_addr, } => { - let is_unicast_mac = target_hardware_addr != EMPTY_MAC && !target_hardware_addr.is_broadcast(); + let is_unicast_mac = + target_hardware_addr != EMPTY_MAC && !target_hardware_addr.is_broadcast(); if is_unicast_mac && hardware_address != target_hardware_addr { // Only process packet that are for us @@ -237,7 +239,10 @@ impl EthernetLink { fn handle_missing_neighbor(&mut self, next_hop: IpAddress, packet: &[u8], now: Instant) { let Ok(buf) = self.waiting_packets.enqueue(packet.len(), next_hop) else { - warn!("Dropped packet on {} because waiting queue was full", self.name); + warn!( + "Dropped packet on {} because waiting queue was full", + self.name + ); return; }; buf.copy_from_slice(packet); diff --git a/src/smolnetd/link/loopback.rs b/src/smolnetd/link/loopback.rs index e0cc8c0aff..24bdb74eba 100644 --- a/src/smolnetd/link/loopback.rs +++ b/src/smolnetd/link/loopback.rs @@ -51,8 +51,7 @@ impl LinkDevice for LoopbackDevice { None } - fn set_mac_address(&mut self, _addr: smoltcp::wire::EthernetAddress) { - } + fn set_mac_address(&mut self, _addr: smoltcp::wire::EthernetAddress) {} fn ip_address(&self) -> Option { Some("127.0.0.1/8".parse().unwrap()) @@ -61,6 +60,4 @@ impl LinkDevice for LoopbackDevice { fn set_ip_address(&mut self, _addr: smoltcp::wire::IpCidr) { todo!() } - - } diff --git a/src/smolnetd/link/mod.rs b/src/smolnetd/link/mod.rs index bf135a36a3..e36e331ffd 100644 --- a/src/smolnetd/link/mod.rs +++ b/src/smolnetd/link/mod.rs @@ -1,14 +1,13 @@ -pub mod loopback; pub mod ethernet; +pub mod loopback; use std::rc::Rc; use smoltcp::time::Instant; -use smoltcp::wire::{IpAddress, EthernetAddress, IpCidr}; +use smoltcp::wire::{EthernetAddress, IpAddress, IpCidr}; /// Represent a link layer device (eth0, loopback...) pub trait LinkDevice { - /// Send the given packet to the machine with the `next_hop` ip address /// This method cannot fail so it's the implementor responsability /// to buffer packets which can't be sent immediatly or decide to diff --git a/src/smolnetd/main.rs b/src/smolnetd/main.rs index d937c0383d..b838e984ef 100644 --- a/src/smolnetd/main.rs +++ b/src/smolnetd/main.rs @@ -13,10 +13,10 @@ use std::os::unix::io::{FromRawFd, RawFd}; use std::process; use std::rc::Rc; -use event::{EventQueue, EventFlags}; +use anyhow::{anyhow, bail, Context, Result}; +use event::{EventFlags, EventQueue}; +use libredox::flag::{O_CREAT, O_NONBLOCK, O_RDWR}; use libredox::Fd; -use libredox::flag::{O_RDWR, O_NONBLOCK, O_CREAT}; -use anyhow::{Result, anyhow, bail, Context}; use redox_netstack::logger; use scheme::Smolnetd; @@ -72,28 +72,26 @@ fn run(daemon: redox_daemon::Daemon) -> Result<()> { .context("failed to get mac address from network adapter")?; trace!("opening :ip"); - let ip_fd = Fd::open(":ip", O_RDWR | O_CREAT | O_NONBLOCK, 0) - .context("failed to open :ip")?; + let ip_fd = Fd::open(":ip", O_RDWR | O_CREAT | O_NONBLOCK, 0).context("failed to open :ip")?; trace!("opening :udp"); - let udp_fd = Fd::open(":udp", O_RDWR | O_CREAT | O_NONBLOCK, 0) - .context("failed to open :udp")?; + let udp_fd = + Fd::open(":udp", O_RDWR | O_CREAT | O_NONBLOCK, 0).context("failed to open :udp")?; trace!("opening :tcp"); - let tcp_fd = Fd::open(":tcp", O_RDWR | O_CREAT | O_NONBLOCK, 0) - .context("failed to open :tcp")?; + let tcp_fd = + Fd::open(":tcp", O_RDWR | O_CREAT | O_NONBLOCK, 0).context("failed to open :tcp")?; trace!("opening :icmp"); - let icmp_fd = Fd::open(":icmp", O_RDWR | O_CREAT | O_NONBLOCK, 0) - .context("failed to open :icmp")?; + let icmp_fd = + Fd::open(":icmp", O_RDWR | O_CREAT | O_NONBLOCK, 0).context("failed to open :icmp")?; trace!("opening :netcfg"); - let netcfg_fd = Fd::open(":netcfg", O_RDWR | O_CREAT | O_NONBLOCK, 0) - .context("failed to open :netcfg")?; + let netcfg_fd = + Fd::open(":netcfg", O_RDWR | O_CREAT | O_NONBLOCK, 0).context("failed to open :netcfg")?; let time_path = format!("/scheme/time/{}", syscall::CLOCK_MONOTONIC); - let time_fd = Fd::open(&time_path, O_RDWR, 0) - .context("failed to open /scheme/time")?; + let time_fd = Fd::open(&time_path, O_RDWR, 0).context("failed to open /scheme/time")?; event::user_data! { enum EventSource { @@ -107,30 +105,36 @@ fn run(daemon: redox_daemon::Daemon) -> Result<()> { } } - let event_queue = EventQueue::::new() - .context("failed to create event queue")?; + let event_queue = EventQueue::::new().context("failed to create event queue")?; daemon.ready().expect("smolnetd: failed to notify parent"); - event_queue.subscribe(network_fd.raw(), EventSource::Network, EventFlags::READ) + event_queue + .subscribe(network_fd.raw(), EventSource::Network, EventFlags::READ) .context("failed to listen to network events")?; - event_queue.subscribe(time_fd.raw(), EventSource::Time, EventFlags::READ) + event_queue + .subscribe(time_fd.raw(), EventSource::Time, EventFlags::READ) .context("failed to listen to timer events")?; - event_queue.subscribe(ip_fd.raw(), EventSource::IpScheme, EventFlags::READ) + event_queue + .subscribe(ip_fd.raw(), EventSource::IpScheme, EventFlags::READ) .context("failed to listen to ip scheme events")?; - event_queue.subscribe(udp_fd.raw(), EventSource::UdpScheme, EventFlags::READ) + event_queue + .subscribe(udp_fd.raw(), EventSource::UdpScheme, EventFlags::READ) .context("failed to listen to udp scheme events")?; - event_queue.subscribe(tcp_fd.raw(), EventSource::TcpScheme, EventFlags::READ) + event_queue + .subscribe(tcp_fd.raw(), EventSource::TcpScheme, EventFlags::READ) .context("failed to listen to tcp scheme events")?; - event_queue.subscribe(icmp_fd.raw(), EventSource::IcmpScheme, EventFlags::READ) + event_queue + .subscribe(icmp_fd.raw(), EventSource::IcmpScheme, EventFlags::READ) .context("failed to listen to icmp scheme events")?; - event_queue.subscribe(netcfg_fd.raw(), EventSource::NetcfgScheme, EventFlags::READ) + event_queue + .subscribe(netcfg_fd.raw(), EventSource::NetcfgScheme, EventFlags::READ) .context("failed to listen to netcfg scheme events")?; let mut smolnetd = Smolnetd::new( @@ -144,15 +148,17 @@ fn run(daemon: redox_daemon::Daemon) -> Result<()> { netcfg_fd, ); - libredox::call::setrens(0, 0) - .context("smolnetd: failed to enter null namespace")?; + libredox::call::setrens(0, 0).context("smolnetd: failed to enter null namespace")?; let all = { use EventSource::*; [Network, Time, IpScheme, UdpScheme, IcmpScheme, NetcfgScheme].map(Ok) }; - for event_res in all.into_iter().chain(event_queue.map(|r| r.map(|e| e.user_data))) { + for event_res in all + .into_iter() + .chain(event_queue.map(|r| r.map(|e| e.user_data))) + { match event_res? { EventSource::Network => smolnetd.on_network_scheme_event()?, EventSource::Time => smolnetd.on_time_event()?, diff --git a/src/smolnetd/scheme/icmp.rs b/src/smolnetd/scheme/icmp.rs index 2f2fc680fe..df2aaa49ad 100644 --- a/src/smolnetd/scheme/icmp.rs +++ b/src/smolnetd/scheme/icmp.rs @@ -1,16 +1,19 @@ -use smoltcp::socket::icmp::{Endpoint as IcmpEndpoint, PacketMetadata as IcmpPacketMetadata, Socket as IcmpSocket, PacketBuffer as IcmpSocketBuffer}; +use byteorder::{ByteOrder, NetworkEndian}; use smoltcp::iface::SocketHandle; +use smoltcp::socket::icmp::{ + Endpoint as IcmpEndpoint, PacketBuffer as IcmpSocketBuffer, + PacketMetadata as IcmpPacketMetadata, Socket as IcmpSocket, +}; use smoltcp::wire::{Icmpv4Packet, Icmpv4Repr, IpAddress, IpListenEndpoint}; use std::mem; use std::str; -use syscall::{Error as SyscallError, Result as SyscallResult}; use syscall; -use byteorder::{ByteOrder, NetworkEndian}; +use syscall::{Error as SyscallError, Result as SyscallResult}; +use super::socket::{Context, DupResult, SchemeFile, SchemeSocket, SocketFile, SocketScheme}; +use super::{Smolnetd, SocketSet}; use crate::port_set::PortSet; use crate::router::Router; -use super::socket::{DupResult, SchemeFile, SchemeSocket, SocketFile, SocketScheme, Context}; -use super::{Smolnetd, SocketSet}; pub type IcmpScheme = SocketScheme>; @@ -75,7 +78,7 @@ impl<'a> SchemeSocket for IcmpSocket<'a> { path: &str, _uid: u32, ident_set: &mut Self::SchemeDataT, - _context: &Context + _context: &Context, ) -> SyscallResult<(SocketHandle, Self::DataT)> { use std::str::FromStr; @@ -95,12 +98,12 @@ impl<'a> SchemeSocket for IcmpSocket<'a> { let socket = IcmpSocket::new( IcmpSocketBuffer::new( vec![IcmpPacketMetadata::EMPTY; Smolnetd::SOCKET_BUFFER_SIZE], - vec![0; Router::MTU * Smolnetd::SOCKET_BUFFER_SIZE] + vec![0; Router::MTU * Smolnetd::SOCKET_BUFFER_SIZE], ), IcmpSocketBuffer::new( vec![IcmpPacketMetadata::EMPTY; Smolnetd::SOCKET_BUFFER_SIZE], - vec![0; Router::MTU * Smolnetd::SOCKET_BUFFER_SIZE] - ) + vec![0; Router::MTU * Smolnetd::SOCKET_BUFFER_SIZE], + ), ); let handle = socket_set.add(socket); let icmp_socket = socket_set.get_mut::(handle); @@ -127,12 +130,12 @@ impl<'a> SchemeSocket for IcmpSocket<'a> { let socket = IcmpSocket::new( IcmpSocketBuffer::new( vec![IcmpPacketMetadata::EMPTY; Smolnetd::SOCKET_BUFFER_SIZE], - vec![0; Router::MTU * Smolnetd::SOCKET_BUFFER_SIZE] + vec![0; Router::MTU * Smolnetd::SOCKET_BUFFER_SIZE], ), IcmpSocketBuffer::new( vec![IcmpPacketMetadata::EMPTY; Smolnetd::SOCKET_BUFFER_SIZE], - vec![0; Router::MTU * Smolnetd::SOCKET_BUFFER_SIZE] - ) + vec![0; Router::MTU * Smolnetd::SOCKET_BUFFER_SIZE], + ), ); let handle = socket_set.add(socket); let icmp_socket = socket_set.get_mut::(handle); @@ -183,16 +186,15 @@ impl<'a> SchemeSocket for IcmpSocket<'a> { data: payload, }; - let icmp_payload = self.send(icmp_repr.buffer_len(), file.data.ip) + let icmp_payload = self + .send(icmp_repr.buffer_len(), file.data.ip) .map_err(|_| syscall::Error::new(syscall::EINVAL))?; let mut icmp_packet = Icmpv4Packet::new_unchecked(icmp_payload); //TODO: replace Default with actual caps icmp_repr.emit(&mut icmp_packet, &Default::default()); Ok(Some(buf.len())) } - IcmpSocketType::Udp => { - Err(SyscallError::new(syscall::EINVAL)) - } + IcmpSocketType::Udp => Err(SyscallError::new(syscall::EINVAL)), } } else if file.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { Err(SyscallError::new(syscall::EAGAIN)) diff --git a/src/smolnetd/scheme/ip.rs b/src/smolnetd/scheme/ip.rs index 149b173599..231e22862a 100644 --- a/src/smolnetd/scheme/ip.rs +++ b/src/smolnetd/scheme/ip.rs @@ -1,14 +1,16 @@ -use smoltcp::socket::raw::{PacketMetadata as RawPacketMetadata, Socket as RawSocket, PacketBuffer as RawSocketBuffer}; use smoltcp::iface::SocketHandle; +use smoltcp::socket::raw::{ + PacketBuffer as RawSocketBuffer, PacketMetadata as RawPacketMetadata, Socket as RawSocket, +}; use smoltcp::wire::{IpProtocol, IpVersion}; use std::str; -use syscall::{Error as SyscallError, Result as SyscallResult}; use syscall; +use syscall::{Error as SyscallError, Result as SyscallResult}; use crate::router::Router; +use super::socket::{Context, DupResult, SchemeFile, SchemeSocket, SocketFile, SocketScheme}; use super::{Smolnetd, SocketSet}; -use super::socket::{DupResult, SchemeFile, SchemeSocket, SocketFile, SocketScheme, Context}; pub type IpScheme = SocketScheme>; @@ -60,7 +62,7 @@ impl<'a> SchemeSocket for RawSocket<'a> { path: &str, uid: u32, _: &mut Self::SchemeDataT, - _context: &Context + _context: &Context, ) -> SyscallResult<(SocketHandle, Self::DataT)> { if uid != 0 { return Err(SyscallError::new(syscall::EACCES)); @@ -70,11 +72,11 @@ impl<'a> SchemeSocket for RawSocket<'a> { let rx_buffer = RawSocketBuffer::new( vec![RawPacketMetadata::EMPTY; Smolnetd::SOCKET_BUFFER_SIZE], - vec![0; Router::MTU * Smolnetd::SOCKET_BUFFER_SIZE] + vec![0; Router::MTU * Smolnetd::SOCKET_BUFFER_SIZE], ); let tx_buffer = RawSocketBuffer::new( vec![RawPacketMetadata::EMPTY; Smolnetd::SOCKET_BUFFER_SIZE], - vec![0; Router::MTU * Smolnetd::SOCKET_BUFFER_SIZE] + vec![0; Router::MTU * Smolnetd::SOCKET_BUFFER_SIZE], ); let ip_socket = RawSocket::new( IpVersion::Ipv4, diff --git a/src/smolnetd/scheme/netcfg/mod.rs b/src/smolnetd/scheme/netcfg/mod.rs index 76cb8f5b80..95492838ef 100644 --- a/src/smolnetd/scheme/netcfg/mod.rs +++ b/src/smolnetd/scheme/netcfg/mod.rs @@ -240,7 +240,7 @@ fn mk_root_node( dev.set_ip_address(cidr); // FIXME: Here, the insert 0 is a workaround to let UDP sockets // work with this interface only. - // Smoltcp takes the first ip address when looking for a source + // Smoltcp takes the first ip address when looking for a source // ip address when sending UDP packets. // This behavior will have to be fixed as it's our route table // job to find give this source. diff --git a/src/smolnetd/scheme/netcfg/nodes.rs b/src/smolnetd/scheme/netcfg/nodes.rs index 16bacb6242..4183da73cd 100644 --- a/src/smolnetd/scheme/netcfg/nodes.rs +++ b/src/smolnetd/scheme/netcfg/nodes.rs @@ -1,6 +1,6 @@ use std::cell::RefCell; -use std::rc::Rc; use std::collections::BTreeMap; +use std::rc::Rc; use syscall::Result as SyscallResult; pub type CfgNodeRef = Rc>; diff --git a/src/smolnetd/scheme/netcfg/notifier.rs b/src/smolnetd/scheme/netcfg/notifier.rs index 24b0a66fcb..8f05a92d1f 100644 --- a/src/smolnetd/scheme/netcfg/notifier.rs +++ b/src/smolnetd/scheme/netcfg/notifier.rs @@ -1,7 +1,7 @@ -use std::rc::Rc; use std::cell::RefCell; -use std::collections::{BTreeMap, BTreeSet}; use std::collections::btree_map::Entry; +use std::collections::{BTreeMap, BTreeSet}; +use std::rc::Rc; pub struct Notifier { listeners: BTreeMap>, diff --git a/src/smolnetd/scheme/socket.rs b/src/smolnetd/scheme/socket.rs index 5b5f904793..4ba2a27d6e 100644 --- a/src/smolnetd/scheme/socket.rs +++ b/src/smolnetd/scheme/socket.rs @@ -11,9 +11,9 @@ use std::rc::Rc; use std::str; use libredox::flag::{self, CLOCK_MONOTONIC}; -use syscall::{self, KSMSG_CANCEL}; use syscall::data::TimeSpec; use syscall::flag::{EVENT_READ, EVENT_WRITE}; +use syscall::{self, KSMSG_CANCEL}; use syscall::{ Error as SyscallError, EventFlags as SyscallEventFlags, Packet as SyscallPacket, Result as SyscallResult, SchemeBlockMut, @@ -383,7 +383,13 @@ where if let Some(ref mut timeout) = timeout { let cur_time = libredox::call::clock_gettime(CLOCK_MONOTONIC)?; - *timeout = add_time(timeout, &TimeSpec { tv_sec: cur_time.tv_sec, tv_nsec: cur_time.tv_nsec as i32 }) + *timeout = add_time( + timeout, + &TimeSpec { + tv_sec: cur_time.tv_sec, + tv_nsec: cur_time.tv_nsec as i32, + }, + ) } Ok(timeout) @@ -641,11 +647,11 @@ where SchemeFile::Socket(ref mut file) => { let mut socket_set = self.socket_set.borrow_mut(); let socket = socket_set.get_mut::(file.socket_handle); - + let ret = SocketT::read_buf(socket, file, buf); match ret { Ok(None) => {} - _ => file.read_notified = false + _ => file.read_notified = false, } return ret; diff --git a/src/smolnetd/scheme/tcp.rs b/src/smolnetd/scheme/tcp.rs index 9d3dbb0425..3dcd13425f 100644 --- a/src/smolnetd/scheme/tcp.rs +++ b/src/smolnetd/scheme/tcp.rs @@ -199,7 +199,7 @@ impl<'a> SchemeSocket for TcpSocket<'a> { "listen" => { if let SchemeFile::Socket(ref tcp_handle) = *file { let Some(listen_enpoint) = tcp_handle.data else { - // This socket is not listening so we can't accept a connection + // This socket is not listening so we can't accept a connection return Err(SyscallError::new(syscall::EINVAL)); }; diff --git a/src/smolnetd/scheme/udp.rs b/src/smolnetd/scheme/udp.rs index 0ed4209446..e02a513d0c 100644 --- a/src/smolnetd/scheme/udp.rs +++ b/src/smolnetd/scheme/udp.rs @@ -1,14 +1,16 @@ -use smoltcp::socket::udp::{PacketMetadata as UdpPacketMetadata, Socket as UdpSocket, PacketBuffer as UdpSocketBuffer}; use smoltcp::iface::SocketHandle; +use smoltcp::socket::udp::{ + PacketBuffer as UdpSocketBuffer, PacketMetadata as UdpPacketMetadata, Socket as UdpSocket, +}; use smoltcp::wire::{IpEndpoint, IpListenEndpoint}; use std::str; -use syscall::{Error as SyscallError, Result as SyscallResult}; use syscall; +use syscall::{Error as SyscallError, Result as SyscallResult}; +use super::socket::{Context, DupResult, SchemeFile, SchemeSocket, SocketFile, SocketScheme}; +use super::{parse_endpoint, Smolnetd, SocketSet}; use crate::port_set::PortSet; use crate::router::Router; -use super::socket::{DupResult, SchemeFile, SchemeSocket, SocketFile, SocketScheme, Context}; -use super::{parse_endpoint, Smolnetd, SocketSet}; pub type UdpScheme = SocketScheme>; @@ -62,7 +64,7 @@ impl<'a> SchemeSocket for UdpSocket<'a> { path: &str, uid: u32, port_set: &mut Self::SchemeDataT, - _context: &Context + _context: &Context, ) -> SyscallResult<(SocketHandle, Self::DataT)> { let mut parts = path.split('/'); let remote_endpoint = parse_endpoint(parts.next().unwrap_or("")); @@ -74,11 +76,11 @@ impl<'a> SchemeSocket for UdpSocket<'a> { let rx_buffer = UdpSocketBuffer::new( vec![UdpPacketMetadata::EMPTY; Smolnetd::SOCKET_BUFFER_SIZE], - vec![0; Router::MTU * Smolnetd::SOCKET_BUFFER_SIZE] + vec![0; Router::MTU * Smolnetd::SOCKET_BUFFER_SIZE], ); let tx_buffer = UdpSocketBuffer::new( vec![UdpPacketMetadata::EMPTY; Smolnetd::SOCKET_BUFFER_SIZE], - vec![0; Router::MTU * Smolnetd::SOCKET_BUFFER_SIZE] + vec![0; Router::MTU * Smolnetd::SOCKET_BUFFER_SIZE], ); let udp_socket = UdpSocket::new(rx_buffer, tx_buffer); @@ -97,7 +99,6 @@ impl<'a> SchemeSocket for UdpSocket<'a> { .bind(local_endpoint) .expect("Can't bind udp socket to local endpoint"); - Ok((socket_handle, remote_endpoint)) } @@ -122,7 +123,12 @@ impl<'a> SchemeSocket for UdpSocket<'a> { } if self.can_send() { let endpoint = file.data; - let endpoint = IpEndpoint::new(endpoint.addr.expect("If we can send, this should be specified"), endpoint.port); + let endpoint = IpEndpoint::new( + endpoint + .addr + .expect("If we can send, this should be specified"), + endpoint.port, + ); self.send_slice(buf, endpoint).expect("Can't send slice"); Ok(Some(buf.len())) } else if file.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK { From 26cf9bc961c91eedfc7edbb9b20f08c07c98cef4 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 9 Mar 2025 18:23:32 +0100 Subject: [PATCH 149/155] Fix a couple of warnings --- src/dnsd/main.rs | 2 +- src/dnsd/scheme.rs | 2 +- src/smolnetd/main.rs | 4 ---- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/dnsd/main.rs b/src/dnsd/main.rs index 5a4392a82a..d47c240084 100644 --- a/src/dnsd/main.rs +++ b/src/dnsd/main.rs @@ -1,7 +1,7 @@ #[macro_use] extern crate log; -use anyhow::{Context, Error, Result}; +use anyhow::{Context, Result}; use event::EventQueue; use ioslice::IoSlice; use libredox::Fd; diff --git a/src/dnsd/scheme.rs b/src/dnsd/scheme.rs index 1c9a432605..dc766d366b 100644 --- a/src/dnsd/scheme.rs +++ b/src/dnsd/scheme.rs @@ -318,7 +318,7 @@ impl<'q> Dnsd<'q> { const REQUEST_TIMEOUT_S: i64 = 30; const TIME_EVENT_TIMEOUT_S: i64 = 5; - pub fn new(dns_file: File, time_file: File, queue: &'q EventQueue) -> Dnsd { + pub fn new(dns_file: File, time_file: File, queue: &'q EventQueue) -> Self { Dnsd { dns_file, time_file, diff --git a/src/smolnetd/main.rs b/src/smolnetd/main.rs index b838e984ef..e1d9a87655 100644 --- a/src/smolnetd/main.rs +++ b/src/smolnetd/main.rs @@ -7,11 +7,7 @@ extern crate redox_netstack; extern crate smoltcp; extern crate syscall; -use std::cell::RefCell; -use std::fs::File; -use std::os::unix::io::{FromRawFd, RawFd}; use std::process; -use std::rc::Rc; use anyhow::{anyhow, bail, Context, Result}; use event::{EventFlags, EventQueue}; From 5d2742813b13df11f27437f79d0818b121dee907 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 9 Mar 2025 18:24:44 +0100 Subject: [PATCH 150/155] Remove no longer necessary extern crate --- src/lib/lib.rs | 3 --- src/smolnetd/main.rs | 7 ------- 2 files changed, 10 deletions(-) diff --git a/src/lib/lib.rs b/src/lib/lib.rs index 1dddb0da53..f83f3f3f1c 100644 --- a/src/lib/lib.rs +++ b/src/lib/lib.rs @@ -1,5 +1,2 @@ -extern crate log; -extern crate syscall; - pub mod error; pub mod logger; diff --git a/src/smolnetd/main.rs b/src/smolnetd/main.rs index e1d9a87655..57d13e725c 100644 --- a/src/smolnetd/main.rs +++ b/src/smolnetd/main.rs @@ -1,12 +1,5 @@ -extern crate event; #[macro_use] extern crate log; -extern crate byteorder; -extern crate netutils; -extern crate redox_netstack; -extern crate smoltcp; -extern crate syscall; - use std::process; use anyhow::{anyhow, bail, Context, Result}; From f4243538b32dbaee73ef6d63b5c3925f67b6a088 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 9 Mar 2025 18:29:12 +0100 Subject: [PATCH 151/155] Remove dependency on byteorder --- Cargo.lock | 1 - Cargo.toml | 1 - src/smolnetd/scheme/icmp.rs | 7 +++---- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 50f827ab8b..79ec928a66 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -459,7 +459,6 @@ name = "redox_netstack" version = "0.1.0" dependencies = [ "anyhow", - "byteorder 1.5.0", "dns-parser", "ioslice", "libredox", diff --git a/Cargo.toml b/Cargo.toml index 232c5b730c..221b2ec6a3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,6 @@ redox_event = "0.4.1" redox-daemon = "0.1.2" redox_syscall = "0.5" redox-log = "0.1" -byteorder = { version = "1.0", default-features = false } dns-parser = "0.7.1" libredox = { version = "0.1.3", features = ["mkns"] } anyhow = "1.0.81" diff --git a/src/smolnetd/scheme/icmp.rs b/src/smolnetd/scheme/icmp.rs index df2aaa49ad..242c1fef5a 100644 --- a/src/smolnetd/scheme/icmp.rs +++ b/src/smolnetd/scheme/icmp.rs @@ -1,4 +1,3 @@ -use byteorder::{ByteOrder, NetworkEndian}; use smoltcp::iface::SocketHandle; use smoltcp::socket::icmp::{ Endpoint as IcmpEndpoint, PacketBuffer as IcmpSocketBuffer, @@ -178,8 +177,8 @@ impl<'a> SchemeSocket for IcmpSocket<'a> { if buf.len() < mem::size_of::() { return Err(SyscallError::new(syscall::EINVAL)); } - let (seq_buf, payload) = buf.split_at(mem::size_of::()); - let seq_no = NetworkEndian::read_u16(seq_buf); + let (&seq_buf, payload) = buf.split_first_chunk::<2>().unwrap(); + let seq_no = u16::from_be_bytes(seq_buf); let icmp_repr = Icmpv4Repr::EchoRequest { ident: file.data.ident, seq_no, @@ -218,7 +217,7 @@ impl<'a> SchemeSocket for IcmpSocket<'a> { if buf.len() < mem::size_of::() + data.len() { return Err(SyscallError::new(syscall::EINVAL)); } - NetworkEndian::write_u16(&mut buf[0..2], seq_no); + buf[0..2].copy_from_slice(&seq_no.to_be_bytes()); for i in 0..data.len() { buf[mem::size_of::() + i] = data[i]; From 44e3cb0f816cc3362f31a9c26b996f01b0d8f4e2 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 9 Mar 2025 19:15:51 +0100 Subject: [PATCH 152/155] Remove .gitmodules Forgot to remove this in the last MR. --- .gitmodules | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 .gitmodules diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 28922f40c6..0000000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "smoltcp"] - path = smoltcp - url = https://gitlab.redox-os.org/redox-os/smoltcp.git From c56cf43d221997798ab1371691162aeebc2f42dd Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 9 Mar 2025 19:57:56 +0100 Subject: [PATCH 153/155] Update to smoltcp 0.11 --- Cargo.lock | 70 +++++------------------------------------------------- Cargo.toml | 2 +- 2 files changed, 7 insertions(+), 65 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 79ec928a66..f1d09d3248 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -28,15 +28,6 @@ name = "arg_parser" version = "0.1.0" source = "git+https://gitlab.redox-os.org/redox-os/arg-parser.git#1c434b55f3e1a0375ebcca85b3e88db7378e82fa" -[[package]] -name = "atomic-polyfill" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cf2bce30dfe09ef0bfaef228b9d414faaf7e563035494d7fe092dba54b300f4" -dependencies = [ - "critical-section", -] - [[package]] name = "autocfg" version = "1.4.0" @@ -114,12 +105,6 @@ version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" -[[package]] -name = "critical-section" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "790eea4361631c5e7d22598ecd5723ff611904e3344ce8720784c93e3d83d40b" - [[package]] name = "crossbeam-channel" version = "0.5.13" @@ -179,23 +164,20 @@ dependencies = [ [[package]] name = "hash32" -version = "0.2.1" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0c35f58762feb77d74ebe43bdbc3210f09be9fe6742234d573bacc26ed92b67" +checksum = "47d60b12902ba28e2730cd37e95b8c9223af2808df9e902d4df49588d1470606" dependencies = [ "byteorder 1.5.0", ] [[package]] name = "heapless" -version = "0.7.17" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdc6457c0eb62c71aac4bc17216026d8410337c4126773b9c5daba343f17964f" +checksum = "0bfb9eb618601c89945a70e254898da93b13be0388091d42117462b265bb3fad" dependencies = [ - "atomic-polyfill", "hash32", - "rustc_version", - "spin", "stable_deref_trait", ] @@ -270,16 +252,6 @@ dependencies = [ "redox_syscall", ] -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - [[package]] name = "log" version = "0.4.22" @@ -486,27 +458,6 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "20145670ba436b55d91fc92d25e71160fbfbdd57831631c8d7d36377a476f1cb" -[[package]] -name = "rustc_version" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" -dependencies = [ - "semver", -] - -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "semver" -version = "1.0.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" - [[package]] name = "shlex" version = "1.3.0" @@ -521,9 +472,9 @@ checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "smoltcp" -version = "0.10.0" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d2e3a36ac8fea7b94e666dfa3871063d6e0a5c9d5d4fec9a1a6b7b6760f0229" +checksum = "5a1a996951e50b5971a2c8c0fa05a381480d70a933064245c4a223ddc87ccc97" dependencies = [ "bitflags 1.3.2", "byteorder 1.5.0", @@ -534,15 +485,6 @@ dependencies = [ "managed", ] -[[package]] -name = "spin" -version = "0.9.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" -dependencies = [ - "lock_api", -] - [[package]] name = "stable_deref_trait" version = "1.2.0" diff --git a/Cargo.toml b/Cargo.toml index 221b2ec6a3..73e9390b05 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,7 +32,7 @@ default-features = false features = ["release_max_level_warn"] [dependencies.smoltcp] -version = "0.10.0" +version = "0.11.0" default-features = false features = [ "std", From b92be2e7d96dbff0f24043ce2bad031c491b2d3c Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 9 Mar 2025 20:07:19 +0100 Subject: [PATCH 154/155] Update to smoltcp 0.12 --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- src/smolnetd/link/ethernet.rs | 6 +++++- src/smolnetd/router/mod.rs | 2 +- src/smolnetd/scheme/netcfg/mod.rs | 2 +- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f1d09d3248..e12d606f91 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -472,9 +472,9 @@ checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "smoltcp" -version = "0.11.0" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a1a996951e50b5971a2c8c0fa05a381480d70a933064245c4a223ddc87ccc97" +checksum = "dad095989c1533c1c266d9b1e8d70a1329dd3723c3edac6d03bbd67e7bf6f4bb" dependencies = [ "bitflags 1.3.2", "byteorder 1.5.0", diff --git a/Cargo.toml b/Cargo.toml index 73e9390b05..24da1df44b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,7 +32,7 @@ default-features = false features = ["release_max_level_warn"] [dependencies.smoltcp] -version = "0.11.0" +version = "0.12.0" default-features = false features = [ "std", diff --git a/src/smolnetd/link/ethernet.rs b/src/smolnetd/link/ethernet.rs index 58dfab3d13..5f32a479dd 100644 --- a/src/smolnetd/link/ethernet.rs +++ b/src/smolnetd/link/ethernet.rs @@ -137,7 +137,11 @@ impl EthernetLink { return; } - if !source_hardware_addr.is_unicast() || !source_protocol_addr.is_unicast() { + if !source_hardware_addr.is_unicast() + || source_protocol_addr.is_broadcast() + || source_protocol_addr.is_multicast() + || source_protocol_addr.is_unspecified() + { return; } diff --git a/src/smolnetd/router/mod.rs b/src/smolnetd/router/mod.rs index 40a360ecf0..3cfd0a2fea 100644 --- a/src/smolnetd/router/mod.rs +++ b/src/smolnetd/router/mod.rs @@ -178,7 +178,7 @@ pub struct RxToken<'a> { impl<'a> smoltcp::phy::RxToken for RxToken<'a> { fn consume(self, f: F) -> R where - F: FnOnce(&mut [u8]) -> R, + F: FnOnce(&[u8]) -> R, { let ((), buf) = self .rx_buffer diff --git a/src/smolnetd/scheme/netcfg/mod.rs b/src/smolnetd/scheme/netcfg/mod.rs index 95492838ef..846bcddfdb 100644 --- a/src/smolnetd/scheme/netcfg/mod.rs +++ b/src/smolnetd/scheme/netcfg/mod.rs @@ -82,7 +82,7 @@ fn mk_root_node( if cur_value.is_none() { let ip = Ipv4Address::from_str(line.trim()) .map_err(|_| SyscallError::new(syscall::EINVAL))?; - if !ip.is_unicast() { + if ip.is_broadcast() || ip.is_multicast() || ip.is_unspecified() { return Err(SyscallError::new(syscall::EINVAL)); } *cur_value = Some(ip); From d7c128684d8e030e678bab8277653bb6e2c2e908 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 9 Mar 2025 20:12:37 +0100 Subject: [PATCH 155/155] Use CUBIC as TCP congestion controller Support for TCP congestion control has been introduced in smoltcp 0.12. Smoltcp supports Reno and CUBIC. Of the two CUBIC has higher throughput. Enabling the socket-tcp-cubic feature is enough to default to CUBIC. With this change pkg install libgcc is about 35% faster than previously without congestion control. (5.5MiB/s vs 4MiB/s previously) --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 24da1df44b..a1efb585eb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,7 +38,7 @@ features = [ "std", "medium-ethernet", "medium-ip", "proto-ipv4", - "socket-raw", "socket-icmp", "socket-udp", "socket-tcp", + "socket-raw", "socket-icmp", "socket-udp", "socket-tcp", "socket-tcp-cubic", "iface-max-addr-count-8", "log" ]