Expand description
A Generic Routing Encapsulation (GRE) protocol parser. Given bytes and a
sawp::parser::Direction
, it will attempt to parse the bytes and return a Message
. The
parser will inform the caller about what went wrong if no message is returned (see
sawp::parser::Parse
for details on possible return types).
The following protocol references were used to create this module:
[CURRENT GRE RFC2784] https://tools.ietf.org/html/rfc2784 [DEPRECATED GRE RFC1701] https://tools.ietf.org/html/rfc1701 [POINT TO POINT TUNNELING RFC2637] https://tools.ietf.org/html/rfc2637
Example
use sawp::parser::{Direction, Parse};
use sawp::error::Error;
use sawp::error::ErrorKind;
use sawp_gre::{Gre, Message};
fn parse_bytes(input: &[u8]) -> std::result::Result<&[u8], Error> {
let gre = Gre {};
let mut bytes = input;
while bytes.len() > 0 {
match gre.parse(bytes, Direction::Unknown) {
// The parser succeeded and returned the remaining bytes and the parsed gre message.
Ok((rest, Some(message))) => {
println!("Gre message: {:?}", message);
bytes = rest;
}
// The parser recognized that this might be gre and made some progress,
// but more bytes are needed.
Ok((rest, None)) => return Ok(rest),
// The parser was unable to determine whether this was gre or not and more bytes are
// needed.
Err(Error { kind: ErrorKind::Incomplete(_) }) => return Ok(bytes),
// The parser determined that this was not gre
Err(e) => return Err(e)
}
}
Ok(bytes)
}
Structs
Storage type for handling flags
Breakdown of the parsed GRE bytes
Source Route Entries are present in deprecated GRE and need to be handled. See https://tools.ietf.org/html/rfc1701 for implementation in GRE headers and https://tools.ietf.org/html/rfc1702 for further details.
Enums
Enum for handling the different GRE headers supported. GRE Versions supported: Current GRE: https://tools.ietf.org/html/rfc2784 Deprecated GRE: https://tools.ietf.org/html/rfc1701 Point-to-Point Tunneling Protocol (Enhanced GRE Header): https://tools.ietf.org/html/rfc2637
Flags which identify messages which parse as Gre but contain invalid data. The caller can use the message’s error flags to see if and what errors were in the pack of bytes and take action using this information.
Flags for handling the first 2 octets of data containing GRE flags (and PPTP specific flags) 0 1 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |C|R|K|S|s|Recur|A| Flags | Ver | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Traits
A trait implemented by all flag enums.