diff options
-rw-r--r-- | src/proto.rs | 16 | ||||
-rw-r--r-- | src/supervisor.rs | 16 |
2 files changed, 26 insertions, 6 deletions
diff --git a/src/proto.rs b/src/proto.rs index 1fd0929..39fa0d6 100644 --- a/src/proto.rs +++ b/src/proto.rs @@ -491,6 +491,22 @@ impl<O: ProtocolOption> NegotiationProtocol<O> { self.lower_status_rx.clone() } + /// Sends a Protocol-Reject for the specified protocol ID to the peer. + pub fn reject(&self, id: u16) { + if self.state != ProtocolState::Opened { + return; + } + + self.output_tx + .send(Packet { + ty: PacketType::ProtocolReject, + options: Vec::default(), + rejected_code: PacketType::Unknown(0), + rejected_protocol: id, + }) + .expect("output channel is closed"); + } + fn timeout_positive(&mut self) -> Option<Packet<O>> { match self.state { ProtocolState::Initial diff --git a/src/supervisor.rs b/src/supervisor.rs index 140e981..ec18774 100644 --- a/src/supervisor.rs +++ b/src/supervisor.rs @@ -603,9 +603,11 @@ impl Client { let mut link_buf = &link_buf[..n]; let mut pkt = PppPkt::default(); - pkt.deserialize(&mut link_buf)?; - - self.handle_ppp(pkt)?; + match pkt.deserialize(&mut link_buf){ + Ok(_) => self.handle_ppp(pkt)?, + Err(ppproperly::Error::InvalidPppProtocol(id)) => self.lcp.reject(id), + Err(e) => return Err(e.into()), + } } else { // Session closed. session_fds = None; } @@ -616,9 +618,11 @@ impl Client { let mut net_buf = &net_buf[..n]; let mut pkt = PppPkt::default(); - pkt.deserialize(&mut net_buf)?; - - self.handle_ppp(pkt)?; + match pkt.deserialize(&mut net_buf) { + Ok(_) => self.handle_ppp(pkt)?, + Err(ppproperly::Error::InvalidPppProtocol(id)) => self.lcp.reject(id), + Err(e) => return Err(e.into()), + } } else { // Session closed. session_fds = None; } |