[stack] skeleton for ENTRY_UDP

This commit is contained in:
c0repwn3r 2023-01-12 13:34:46 -05:00
parent 78fb32b253
commit b07895b043
Signed by: core
GPG Key ID: FDBF740DADDCEECF
1 changed files with 24 additions and 0 deletions

View File

@ -3,6 +3,7 @@
use std::error::Error;
use std::net::SocketAddr;
use crate::device::QTInterface;
use crate::drivers::error::DriverError;
use crate::stack::{PacketProcessingStage};
/// The ENTRY stage of the packet processing stack for UDP packets
@ -10,6 +11,29 @@ pub struct UDPPacketEntryStage {}
impl PacketProcessingStage for UDPPacketEntryStage {
fn process_packet(pkt: Vec<u8>, from: &SocketAddr, interface: &QTInterface) -> Result<(), Box<dyn Error>> {
// packet types are determined by the first byte of the packet
// if it is not a known packet type, return an error and drop the packet
match pkt.first().ok_or(DriverError::InvalidPacketTypeRecvOnInterface)? {
1 => Self::handle_new_handshake(pkt, from, interface),
2 => Self::handle_handshake_response(pkt, from, interface),
3 => Self::handle_handshake_cookie_reply(pkt, from, interface),
4 => Self::handle_data_packet(pkt, from, interface),
_ => Err(DriverError::InvalidPacketTypeRecvOnInterface.into())
}
}
}
impl UDPPacketEntryStage {
fn handle_new_handshake(pkt: Vec<u8>, from: &SocketAddr, interface: &QTInterface) -> Result<(), Box<dyn Error>> {
unimplemented!();
}
fn handle_handshake_response(pkt: Vec<u8>, from: &SocketAddr, interface: &QTInterface) -> Result<(), Box<dyn Error>> {
unimplemented!();
}
fn handle_handshake_cookie_reply(pkt: Vec<u8>, from: &SocketAddr, interface: &QTInterface) -> Result<(), Box<dyn Error>> {
unimplemented!();
}
fn handle_data_packet(pkt: Vec<u8>, from: &SocketAddr, interface: &QTInterface) -> Result<(), Box<dyn Error>> {
unimplemented!();
}
}