diff options
author | HimbeerserverDE <himbeerserverde@gmail.com> | 2023-04-12 22:01:50 +0200 |
---|---|---|
committer | HimbeerserverDE <himbeerserverde@gmail.com> | 2023-04-12 22:01:50 +0200 |
commit | 4d51a61dc5574df6b60f29dbded9271e80a3ad00 (patch) | |
tree | 9452b34dff7cdc9787649357b5c279bb026a18d2 | |
parent | 3bec836318a546c2bba0480fc7f70b2348227165 (diff) |
error resistance: treat tun device errors as non-fatal
-rw-r--r-- | src/main.rs | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs index c5f7fec..5a7f047 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,7 +25,13 @@ where fn tun2ppp(tx: mpsc::Sender<Option<Vec<u8>>>, tun: Arc<Iface>) -> Result<()> { loop { let mut buf = [0; 4 + 1492]; - let n = tun.recv(&mut buf)?; + let n = match tun.recv(&mut buf) { + Ok(v) => v, + Err(e) => { + println!("[pppoe] tun2ppp warning: {}", e); + continue; + } + }; let buf = &buf[..n]; let ether_type = NE::read_u16(&buf[2..4]); @@ -50,7 +56,13 @@ fn ppp2tun(rx: Arc<Mutex<mpsc::Receiver<Vec<u8>>>>, tun: Arc<Iface>) -> Result<( while let Ok(mut buf) = rx.recv() { buf = prepend(buf, &packet_info); - let n = tun.send(&buf)?; + let n = match tun.send(&buf) { + Ok(v) => v, + Err(e) => { + println!("[pppoe] ppp2tun warning: {}", e); + continue; + } + }; if n != buf.len() { return Err(Error::PartialTransmission); } |