/// Determine the interface (and when appropriate new targets) for a single packet.
///
/// rx_slot_buf is a packet that has been received.
Determine the interface (and when appropriate new targets) for a single packet.
rx_slot_buf is a packet that has been received.
Determine the interface ( and when appropriate new targets ) for a single packet . rx_slot_buf is a packet that has been received .
fn examine_one<'a>(rx_slot_buf: RxSlotBuf, routes:&ConsistentHash) -> Result<Direction, error::BrokenRail> {
    let packet = match EthernetPacket::new(rx_slot_buf.1) {
        Some(packet) => packet,
        None => return Err(error::BrokenRail::BadPacket),
    };
    match packet.get_ethertype() {
        Ipv4 => {
            if let Some(ip) = Ipv4Packet::new(packet.payload()) {
                match ip.get_next_level_protocol() {
                    Gre => {
                        if let Some(gre) = gre::GrePacket::new(ip.payload()) {
                            match gre.get_protocol_type() {
                                0x0800 => {
                                    if let Some(inner_ip) = Ipv4Packet::new(gre.payload()) {
                                        let hash = hash_ipv4_packet(&inner_ip);
                                        let target_ipv4 = select_destination(routes, &inner_ip);
                                        println!("Inner IP {:?} {:?} {:?} {:?}",
                                                 inner_ip.get_source(),
                                                 inner_ip.get_destination(),
                                                 hash, target_ipv4);
                                        return Ok(Direction::Wire(target_ipv4));
                                    }
                                    // try!(move_packet(rx_slot_buf, tx_slot_buf));
                                    // if we can't handle the packet, drop it.
                                    return Ok(Direction::Drop);
                                }
                                // Drop all other gre packets as noise
                                _ => return Ok(Direction::Drop),
                            }
                        } else {
                            println!("Failed to process GRE packet");
                            // in future perhaps forward to host?
                            return Ok(Direction::Drop);
                        }
                    }
                    // Forward non-GRE
                    _ => return Ok(Direction::Destination),
                    // try!(move_packet(rx_slot_buf, tx_slot_buf)),
                }
            } else {
                return Err(error::BrokenRail::BadPacket);
            };
            // println!("packet {:?}", packet.get_ethertype())
        }
        // Forward non-IPV4 packets - ARP etc
        _ => return Ok(Direction::Destination),
        // try!(move_packet(rx_slot_buf, tx_slot_buf)),
    }
}
fn examine_one < ' a > ( rx_slot_buf : RxSlotBuf , routes : & ConsistentHash ) -> Result < Direction , error :: BrokenRail > { let packet = match EthernetPacket :: new ( rx_slot_buf . 1 ) { Some ( packet ) => packet , None => return Err ( error :: BrokenRail :: BadPacket ) , } ; match packet . get_ethertype ( ) { Ipv4 => { if let Some ( ip ) = Ipv4Packet :: new ( packet . payload ( ) ) { match ip . get_next_level_protocol ( ) { Gre => { if let Some ( gre ) = gre :: GrePacket :: new ( ip . payload ( ) ) { match gre . get_protocol_type ( ) { 0x0800 => { if let Some ( inner_ip ) = Ipv4Packet :: new ( gre . payload ( ) ) { let hash = hash_ipv4_packet ( & inner_ip ) ; let target_ipv4 = select_destination ( routes , & inner_ip ) ; println ! ( " " inner_ip get_source ( ) inner_ip get_destination ( ) hash target_ipv4 ) ; return Ok ( Direction :: Wire ( target_ipv4 ) ) ; } // try!(move_packet(rx_slot_buf, tx_slot_buf)); // if we can't handle the packet, drop it. return Ok ( Direction :: Drop ) ; } // Drop all other gre packets as noise _ => return Ok ( Direction :: Drop ) , } } else { println ! ( " " ) ; // in future perhaps forward to host? return Ok ( Direction :: Drop ) ; } } // Forward non-GRE _ => return Ok ( Direction :: Destination ) , // try!(move_packet(rx_slot_buf, tx_slot_buf)), } } else { return Err ( error :: BrokenRail :: BadPacket ) ; } ; // println!("packet {:?}", packet.get_ethertype()) } // Forward non-IPV4 packets - ARP etc _ => return Ok ( Direction :: Destination ) , // try!(move_packet(rx_slot_buf, tx_slot_buf)), } }
Determine the interface (and when appropriate new targets) for a single packet.
Determine the interface ( and when appropriate new targets ) for a single packet .
rx_slot_buf
RxSlotBuf
routes
&ConsistentHash