diff options
author | HimbeerserverDE <himbeerserverde@gmail.com> | 2023-07-28 15:33:04 +0200 |
---|---|---|
committer | HimbeerserverDE <himbeerserverde@gmail.com> | 2023-07-28 15:33:04 +0200 |
commit | 3e1544871f8909bace68d45cacd7c78007222b49 (patch) | |
tree | 6b3e74968ee60ccc3cea0ee78f0b5b556451f87f | |
parent | 60310d9cda0a35cfe6ea88a085654b2c6cf22bae (diff) |
fix padi deadlock
-rw-r--r-- | src/main.rs | 88 |
1 files changed, 45 insertions, 43 deletions
diff --git a/src/main.rs b/src/main.rs index d287c52..72ae288 100644 --- a/src/main.rs +++ b/src/main.rs @@ -41,51 +41,53 @@ fn connect(interface: &str) -> Result<()> { ); loop { - let mut pppoe_state = pppoe_state.lock().expect("pppoe state mutex is poisoned"); - match *pppoe_state { - Pppoe::Init => { - PppoePkt::new_padi( - local_mac, - vec![ - PppoeVal::ServiceName("".into()).into(), - PppoeVal::HostUniq(rand::random::<[u8; 16]>().into()).into(), - ], - ) - .serialize(&mut sock_w)?; - sock_w.flush()?; - - println!(" -> [{}] padi", MacAddr::BROADCAST); - } - Pppoe::Requesting(remote_mac, ref ac_cookie, attempt) => { - if attempt >= MAX_ATTEMPTS { - *pppoe_state = Pppoe::Init; - continue; - } - - PppoePkt::new_padr( - remote_mac, - local_mac, - if let Some(ac_cookie) = ac_cookie { + { + let mut pppoe_state = pppoe_state.lock().expect("pppoe state mutex is poisoned"); + match *pppoe_state { + Pppoe::Init => { + PppoePkt::new_padi( + local_mac, vec![ PppoeVal::ServiceName("".into()).into(), - PppoeVal::AcCookie(ac_cookie.to_owned()).into(), - ] - } else { - vec![PppoeVal::ServiceName("".into()).into()] - }, - ) - .serialize(&mut sock_w)?; - sock_w.flush()?; - - println!(" -> [{}] padr {}/{}", remote_mac, attempt, MAX_ATTEMPTS); - *pppoe_state = Pppoe::Requesting(remote_mac, ac_cookie.to_owned(), attempt + 1); - } - Pppoe::Active => {} - Pppoe::Err => { - return Err(recv_disc - .join() - .expect("recv_discovery panic") - .expect_err("Pppoe::Err state entered without an error")); + PppoeVal::HostUniq(rand::random::<[u8; 16]>().into()).into(), + ], + ) + .serialize(&mut sock_w)?; + sock_w.flush()?; + + println!(" -> [{}] padi", MacAddr::BROADCAST); + } + Pppoe::Requesting(remote_mac, ref ac_cookie, attempt) => { + if attempt >= MAX_ATTEMPTS { + *pppoe_state = Pppoe::Init; + continue; + } + + PppoePkt::new_padr( + remote_mac, + local_mac, + if let Some(ac_cookie) = ac_cookie { + vec![ + PppoeVal::ServiceName("".into()).into(), + PppoeVal::AcCookie(ac_cookie.to_owned()).into(), + ] + } else { + vec![PppoeVal::ServiceName("".into()).into()] + }, + ) + .serialize(&mut sock_w)?; + sock_w.flush()?; + + println!(" -> [{}] padr {}/{}", remote_mac, attempt, MAX_ATTEMPTS); + *pppoe_state = Pppoe::Requesting(remote_mac, ac_cookie.to_owned(), attempt + 1); + } + Pppoe::Active => {} + Pppoe::Err => { + return Err(recv_disc + .join() + .expect("recv_discovery panic") + .expect_err("Pppoe::Err state entered without an error")); + } } } |