Cleanup of panics in network schemes
This commit is contained in:
parent
1346d8a181
commit
7785ddd99b
|
@ -7,6 +7,7 @@ use std::cell::RefCell;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{Result, Read, Write};
|
use std::io::{Result, Read, Write};
|
||||||
use std::os::unix::io::FromRawFd;
|
use std::os::unix::io::FromRawFd;
|
||||||
|
use std::process;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
use syscall::{Packet, SchemeMut, EWOULDBLOCK};
|
use syscall::{Packet, SchemeMut, EWOULDBLOCK};
|
||||||
|
@ -15,17 +16,10 @@ use scheme::EthernetScheme;
|
||||||
|
|
||||||
mod scheme;
|
mod scheme;
|
||||||
|
|
||||||
fn main() {
|
fn daemon(network_fd: usize, socket_fd: usize) {
|
||||||
// Daemonize
|
|
||||||
if unsafe { syscall::clone(0).unwrap() } == 0 {
|
|
||||||
let network_fd = syscall::open("network:", syscall::O_RDWR | syscall::O_NONBLOCK).expect("ethernetd: failed to open network");
|
|
||||||
let network = unsafe { File::from_raw_fd(network_fd) };
|
let network = unsafe { File::from_raw_fd(network_fd) };
|
||||||
|
|
||||||
let socket_fd = syscall::open(":ethernet", syscall::O_RDWR | syscall::O_CREAT | syscall::O_NONBLOCK).expect("ethernetd: failed to create ethernet scheme");
|
|
||||||
let socket = Rc::new(RefCell::new(unsafe { File::from_raw_fd(socket_fd) }));
|
let socket = Rc::new(RefCell::new(unsafe { File::from_raw_fd(socket_fd) }));
|
||||||
|
|
||||||
let scheme = Rc::new(RefCell::new(EthernetScheme::new(network)));
|
let scheme = Rc::new(RefCell::new(EthernetScheme::new(network)));
|
||||||
|
|
||||||
let todo = Rc::new(RefCell::new(Vec::<Packet>::new()));
|
let todo = Rc::new(RefCell::new(Vec::<Packet>::new()));
|
||||||
|
|
||||||
let mut event_queue = EventQueue::<()>::new().expect("ethernetd: failed to create event queue");
|
let mut event_queue = EventQueue::<()>::new().expect("ethernetd: failed to create event queue");
|
||||||
|
@ -91,4 +85,24 @@ fn main() {
|
||||||
|
|
||||||
event_queue.run().expect("ethernetd: failed to run event loop");
|
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) => match syscall::open(":ethernet", syscall::O_RDWR | syscall::O_CREAT | syscall::O_NONBLOCK) {
|
||||||
|
Ok(socket_fd) => {
|
||||||
|
// Daemonize
|
||||||
|
if unsafe { syscall::clone(0).unwrap() } == 0 {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,8 @@ use std::collections::{BTreeMap, VecDeque};
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{self, Read, Write};
|
use std::io::{self, Read, Write};
|
||||||
use std::os::unix::io::FromRawFd;
|
use std::os::unix::io::FromRawFd;
|
||||||
|
use std::{process, slice, str};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::{slice, str};
|
|
||||||
use syscall::data::Packet;
|
use syscall::data::Packet;
|
||||||
use syscall::error::{Error, Result, EACCES, EADDRNOTAVAIL, EBADF, EIO, EINVAL, ENOENT, EWOULDBLOCK};
|
use syscall::error::{Error, Result, EACCES, EADDRNOTAVAIL, EBADF, EIO, EINVAL, ENOENT, EWOULDBLOCK};
|
||||||
use syscall::flag::{EVENT_READ, O_NONBLOCK};
|
use syscall::flag::{EVENT_READ, O_NONBLOCK};
|
||||||
|
@ -255,10 +255,7 @@ impl SchemeMut for Ipd {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn daemon(arp_fd: usize, ip_fd: usize, scheme_fd: usize) {
|
||||||
// Daemonize
|
|
||||||
if unsafe { syscall::clone(0).unwrap() } == 0 {
|
|
||||||
let scheme_fd = syscall::open(":ip", syscall::O_RDWR | syscall::O_CREAT | syscall::O_NONBLOCK).expect("ipd: failed to create :ip");
|
|
||||||
let scheme_file = unsafe { File::from_raw_fd(scheme_fd) };
|
let scheme_file = unsafe { File::from_raw_fd(scheme_fd) };
|
||||||
|
|
||||||
let ipd = Rc::new(RefCell::new(Ipd::new(scheme_file)));
|
let ipd = Rc::new(RefCell::new(Ipd::new(scheme_file)));
|
||||||
|
@ -267,8 +264,6 @@ fn main() {
|
||||||
|
|
||||||
//TODO: Multiple interfaces
|
//TODO: Multiple interfaces
|
||||||
{
|
{
|
||||||
let arp_fd = syscall::open("ethernet:806", syscall::O_RDWR | syscall::O_NONBLOCK).expect("ipd: failed to open ethernet:806");
|
|
||||||
let ip_fd = syscall::open("ethernet:800", syscall::O_RDWR | syscall::O_NONBLOCK).expect("ipd: failed to open ethernet:800");
|
|
||||||
let if_id = {
|
let if_id = {
|
||||||
let mut ipd = ipd.borrow_mut();
|
let mut ipd = ipd.borrow_mut();
|
||||||
let if_id = ipd.interfaces.len();
|
let if_id = ipd.interfaces.len();
|
||||||
|
@ -315,4 +310,30 @@ fn main() {
|
||||||
|
|
||||||
event_queue.run().expect("ipd: failed to run 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) => match syscall::open(":ip", syscall::O_RDWR | syscall::O_CREAT | syscall::O_NONBLOCK) {
|
||||||
|
Ok(scheme_fd) => {
|
||||||
|
// Daemonize
|
||||||
|
if unsafe { syscall::clone(0).unwrap() } == 0 {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ use std::collections::{BTreeMap, VecDeque};
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{self, Read, Write};
|
use std::io::{self, Read, Write};
|
||||||
use std::{mem, slice, str};
|
use std::{mem, process, slice, str};
|
||||||
use std::ops::{Deref, DerefMut};
|
use std::ops::{Deref, DerefMut};
|
||||||
use std::os::unix::io::FromRawFd;
|
use std::os::unix::io::FromRawFd;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
@ -783,14 +783,9 @@ impl SchemeMut for Tcpd {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn daemon(tcp_fd: usize, scheme_fd: usize) {
|
||||||
// Daemonize
|
|
||||||
if unsafe { syscall::clone(0).unwrap() } == 0 {
|
|
||||||
let scheme_fd = syscall::open(":tcp", O_RDWR | O_CREAT | O_NONBLOCK).expect("tcpd: failed to create :tcp");
|
|
||||||
let scheme_file = unsafe { File::from_raw_fd(scheme_fd) };
|
|
||||||
|
|
||||||
let tcp_fd = syscall::open("ip:6", O_RDWR | O_NONBLOCK).expect("tcpd: failed to open ip:6");
|
|
||||||
let tcp_file = unsafe { File::from_raw_fd(tcp_fd) };
|
let tcp_file = unsafe { File::from_raw_fd(tcp_fd) };
|
||||||
|
let scheme_file = unsafe { File::from_raw_fd(scheme_fd) };
|
||||||
|
|
||||||
let tcpd = Rc::new(RefCell::new(Tcpd::new(scheme_file, tcp_file)));
|
let tcpd = Rc::new(RefCell::new(Tcpd::new(scheme_file, tcp_file)));
|
||||||
|
|
||||||
|
@ -811,4 +806,24 @@ fn main() {
|
||||||
|
|
||||||
event_queue.run().expect("tcpd: failed to run event queue");
|
event_queue.run().expect("tcpd: failed to run event queue");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
match syscall::open("ip:6", O_RDWR | O_NONBLOCK) {
|
||||||
|
Ok(tcp_fd) => match syscall::open(":tcp", O_RDWR | O_CREAT | O_NONBLOCK) {
|
||||||
|
Ok(scheme_fd) => {
|
||||||
|
// Daemonize
|
||||||
|
if unsafe { syscall::clone(0).unwrap() } == 0 {
|
||||||
|
daemon(tcp_fd, scheme_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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ use std::collections::{BTreeMap, VecDeque};
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{self, Read, Write};
|
use std::io::{self, Read, Write};
|
||||||
use std::{mem, slice, str};
|
use std::{mem, process, slice, str};
|
||||||
use std::ops::{Deref, DerefMut};
|
use std::ops::{Deref, DerefMut};
|
||||||
use std::os::unix::io::FromRawFd;
|
use std::os::unix::io::FromRawFd;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
@ -450,15 +450,9 @@ impl SchemeMut for Udpd {
|
||||||
Ok(0)
|
Ok(0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fn daemon(udp_fd: usize, scheme_fd: usize) {
|
||||||
fn main() {
|
|
||||||
// Daemonize
|
|
||||||
if unsafe { syscall::clone(0).unwrap() } == 0 {
|
|
||||||
let scheme_fd = syscall::open(":udp", O_RDWR | O_CREAT | O_NONBLOCK).expect("udpd: failed to create :udp");
|
|
||||||
let scheme_file = unsafe { File::from_raw_fd(scheme_fd) };
|
|
||||||
|
|
||||||
let udp_fd = syscall::open("ip:11", O_RDWR | O_NONBLOCK).expect("udpd: failed to open ip:11");
|
|
||||||
let udp_file = unsafe { File::from_raw_fd(udp_fd) };
|
let udp_file = unsafe { File::from_raw_fd(udp_fd) };
|
||||||
|
let scheme_file = unsafe { File::from_raw_fd(scheme_fd) };
|
||||||
|
|
||||||
let udpd = Rc::new(RefCell::new(Udpd::new(scheme_file, udp_file)));
|
let udpd = Rc::new(RefCell::new(Udpd::new(scheme_file, udp_file)));
|
||||||
|
|
||||||
|
@ -479,4 +473,24 @@ fn main() {
|
||||||
|
|
||||||
event_queue.run().expect("udpd: failed to run event queue");
|
event_queue.run().expect("udpd: failed to run event queue");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
match syscall::open("ip:11", O_RDWR | O_NONBLOCK) {
|
||||||
|
Ok(udp_fd) => match syscall::open(":udp", O_RDWR | O_CREAT | O_NONBLOCK) {
|
||||||
|
Ok(scheme_fd) => {
|
||||||
|
// Daemonize
|
||||||
|
if unsafe { syscall::clone(0).unwrap() } == 0 {
|
||||||
|
daemon(udp_fd, scheme_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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue