diff options
author | HimbeerserverDE <himbeerserverde@gmail.com> | 2023-07-29 16:13:17 +0200 |
---|---|---|
committer | HimbeerserverDE <himbeerserverde@gmail.com> | 2023-07-29 16:13:17 +0200 |
commit | 7d5dcfcaa92eefdbc8dea5ed5a2ae5d58de78d92 (patch) | |
tree | e58341de5324f8af796a333ce23a629f85384af5 | |
parent | 8f6c8f09b6de00e4fb5c623e435fdc07598ed29e (diff) |
implement pap authentication
-rw-r--r-- | Cargo.lock | 2 | ||||
-rw-r--r-- | src/main.rs | 44 |
2 files changed, 43 insertions, 3 deletions
@@ -619,7 +619,7 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "ppproperly" version = "0.1.0" -source = "git+https://github.com/rsdsl/ppproperly.git#bdd7501540e9297b38a2cbdd7e05b08b193adf66" +source = "git+https://github.com/rsdsl/ppproperly.git#63edb1e3c35a6001c4dc0dd67806c920a5676f5e" dependencies = [ "bitfield", "ppproperly_macros", diff --git a/src/main.rs b/src/main.rs index 1650bfb..d896873 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,8 +5,8 @@ use std::thread; use std::time::Duration; use ppproperly::{ - AuthProto, Deserialize, LcpData, LcpOpt, LcpPkt, MacAddr, PapPkt, PppData, PppPkt, PppoeData, - PppoePkt, PppoeVal, Serialize, + AuthProto, Deserialize, LcpData, LcpOpt, LcpPkt, MacAddr, PapData, PapPkt, PppData, PppPkt, + PppoeData, PppoePkt, PppoeVal, Serialize, }; use rsdsl_netlinkd::link; use rsdsl_pppoe2::{Ppp, Pppoe, Result}; @@ -440,6 +440,7 @@ fn recv_session(ctl: File, state: Arc<Mutex<Ppp>>) -> Result<()> { match ppp.data { PppData::Lcp(lcp) => handle_lcp(lcp, &mut ctl_w, state.clone(), &mut magic)?, + PppData::Pap(pap) => handle_pap(pap, state.clone())?, _ => println!(" <- unhandled ppp {:?}", ppp), } } @@ -734,3 +735,42 @@ fn handle_lcp( } } } + +fn handle_pap(pap: PapPkt, state: Arc<Mutex<Ppp>>) -> Result<()> { + match *state.lock().expect("ppp state mutex is poisoned") { + Ppp::Auth(Some(AuthProto::Pap), ..) => {} + _ => { + println!(" <- unexpected pap"); + return Ok(()); + } + } + + match pap.data { + PapData::AuthenticateRequest(..) => { + // We never ask the peer to authenticate itself + // so an Authenticate-Request will always be unexpected. + + println!(" <- unexpected pap authenticate-request {}", pap.identifier); + Ok(()) + } + PapData::AuthenticateAck(authenticate_ack) => { + *state.lock().expect("ppp state mutex is poisoned") = Ppp::Active; + + println!( + " <- pap authenticate-ack {}, message: {}", + pap.identifier, authenticate_ack.msg + ); + Ok(()) + } + PapData::AuthenticateNak(authenticate_nak) => { + // The peer should terminate the session + // which is already handled by LCP. + + println!( + " <- pap authenticate-nak {}, reason: {}", + pap.identifier, authenticate_nak.msg + ); + Ok(()) + } + } +} |