diff options
author | HimbeerserverDE <himbeerserverde@gmail.com> | 2023-03-11 14:12:27 +0100 |
---|---|---|
committer | HimbeerserverDE <himbeerserverde@gmail.com> | 2023-03-11 14:12:27 +0100 |
commit | 970b44eecab64b46bab93e8e6c8fca025fdeed91 (patch) | |
tree | 12764a074b244b76669f1c25a44be8dc6f97bc2b | |
parent | 640890936238cbe9f4d0413c342a975b48fb3e8b (diff) |
verify session state when receiving PPP traffic
-rw-r--r-- | src/client.rs | 59 | ||||
-rw-r--r-- | src/error.rs | 2 |
2 files changed, 35 insertions, 26 deletions
diff --git a/src/client.rs b/src/client.rs index 4d7947d..f18bbf7 100644 --- a/src/client.rs +++ b/src/client.rs @@ -172,44 +172,51 @@ impl Client { match match code { PPP => { - let ppp = pppoe::ppp::Header::with_buffer(header.payload())?; - let protocol = ppp.protocol(); + if let State::Session(_) = self.state() { + let ppp = pppoe::ppp::Header::with_buffer(header.payload())?; + let protocol = ppp.protocol(); - match protocol { - LCP => { - let lcp = pppoe::lcp::Header::with_buffer(ppp.payload())?; - let lcp_code = lcp.code(); + match protocol { + LCP => { + let lcp = pppoe::lcp::Header::with_buffer(ppp.payload())?; + let lcp_code = lcp.code(); - match lcp_code { - CONFIGURE_REQUEST => { - let opts: Vec<ConfigOption> = - ConfigOptionIterator::new(lcp.payload()).collect(); + match lcp_code { + CONFIGURE_REQUEST => { + let opts: Vec<ConfigOption> = + ConfigOptionIterator::new(lcp.payload()).collect(); - println!("received configuration request, options: {:?}", opts); + println!( + "received configuration request, options: {:?}", + opts + ); - let limit = lcp.payload().len(); + let limit = lcp.payload().len(); - let mut ack = Vec::new(); - ack.resize(14 + 6 + 2 + 4 + limit, 0); + let mut ack = Vec::new(); + ack.resize(14 + 6 + 2 + 4 + limit, 0); - let ack = ack.as_mut_slice(); - ack[26..26 + limit].copy_from_slice(lcp.payload()); + let ack = ack.as_mut_slice(); + ack[26..26 + limit].copy_from_slice(lcp.payload()); - pppoe::lcp::HeaderBuilder::create_configure_ack( - &mut ack[22..26 + limit], - lcp.identifier(), - )?; + pppoe::lcp::HeaderBuilder::create_configure_ack( + &mut ack[22..26 + limit], + lcp.identifier(), + )?; - self.new_lcp_packet(remote_mac, ack)?; - self.send(ack)?; + self.new_lcp_packet(remote_mac, ack)?; + self.send(ack)?; - println!("ackknowledged configuration"); - Ok(()) + println!("ackknowledged configuration"); + Ok(()) + } + _ => Err(Error::InvalidLcpCode(lcp_code)), } - _ => Err(Error::InvalidLcpCode(lcp_code)), } + _ => Err(Error::InvalidProtocol(protocol)), } - _ => Err(Error::InvalidProtocol(protocol)), + } else { + Err(Error::UnexpectedPpp(remote_mac_str.clone())) } } PADO => { diff --git a/src/error.rs b/src/error.rs index 90b27b2..fdb899b 100644 --- a/src/error.rs +++ b/src/error.rs @@ -20,6 +20,8 @@ pub enum Error { Terminated, #[error("session ID is zero")] ZeroSession, + #[error("unexpected PPP session traffic from MAC {0}")] + UnexpectedPpp(String), #[error("invalid PPP sub-protocol {0}")] InvalidProtocol(u16), #[error("invalid LCP code {0}")] |