PPPoE session
PPP over Ethernet, RFC 2516: the link that a fibre or xDSL subscriber's router keeps with the provider's access concentrator, and that carries all of the subscriber's IP traffic. Up to 11.5.0 its session stage, EtherType 0x8864, was only named, and the IP packets inside had no internet layer; since 11.6.0 the session is peeled (#172, #173). The module is packet_parser::parse::data_link::pppoe. The session is not a layer of PacketFlow: like a VLAN tag, it is consumed by the Ethernet decoder and kept in the Ethernet view, DataLink::pppoe.
Peeled like a VLAN tag
There is no port, no probe and no Decode As: the EtherType announces the session, and the Ethernet decoder takes its word, as it does for a TPID. DataLink::try_from reads the EtherType after the two MAC addresses; a TPID sends the frame through the VLAN stack first, and parse_tagged makes the same test on the EtherType that follows the last tag. A session is therefore peeled under any number of tags, or none:
#![allow(unused)] fn main() { // DataLink::try_from, after the two MAC addresses. let raw_ethertype = u16::from_be_bytes([packets[12], packets[13]]); if VlanTag::is_tpid(raw_ethertype) { return Self::parse_tagged(packets, destination_mac, source_mac, raw_ethertype); } if raw_ethertype == PPPOE_SESSION_ETHERTYPE { return Ok(Self::parse_pppoe( destination_mac, source_mac, None, VlanStack::default(), &packets[DATALINK_HEADER_LEN..], )); } }
parse_pppoe then decides what ethertype and payload become:
#![allow(unused)] fn main() { #[inline(never)] fn parse_pppoe( destination_mac: MacAddress, source_mac: MacAddress, vlan: Option<VlanTag>, vlan_stack: VlanStack<'a>, payload: &'a [u8], ) -> Self { let (pppoe, ethertype, payload) = match peel_session(payload) { Some((session, inner)) => ( Some(session), session.inner_ethertype().unwrap_or(PPPOE_SESSION_ETHERTYPE), inner, ), None => (None, PPPOE_SESSION_ETHERTYPE, payload), }; DataLink { destination_mac, source_mac, vlan, vlan_stack, pppoe, ethertype: Ethertype::from(ethertype), payload, } } }
Three outcomes, then:
After EtherType 0x8864 | pppoe | ethertype | payload | Internet layer |
|---|---|---|---|---|
a session carrying PPP IPv4 (0x0021) or IPv6 (0x0057) | Some(session) | 0x0800 or 0x86DD | the IP packet | IPv4 or IPv6, then transport and application as usual |
| a session carrying any other PPP protocol (LCP, IPCP, IPv6CP, PAP, CHAP...) | Some(session) | 0x8864 | the PPP packet, after its protocol field | None, nothing in corrupted |
| no well-formed session data frame | None | 0x8864 | all the bytes after the EtherType | None, nothing in corrupted |
inner_ethertype (crate-internal) maps 0x0021 to 0x0800 and 0x0057 to 0x86DD, and nothing else. From there on, the layers above see what they would see without PPPoE: network_protocol() is Ipv4 or Ipv6, network_payload() is the packet, and the internet layer dispatches on it as on any other. Tags, when there are any, are kept as they were read: vlan.inner_ethertype still says 0x8864, the value that follows the tag on the wire. Like the tag stack, the session is unwrapped in a separate #[inline(never)] function, off the straight line of an untagged frame.
Since the peeling lives in DataLink::try_from, it happens wherever the crate reads an Ethernet frame: LINKTYPE 1, an 802.3br express mPacket, and the inner frame of a VXLAN tunnel or of a GRE or Geneve one announcing 0x6558 (tunnels).
An IPv4 session under two VLAN tags, then an IPv6 one under a single tag that reaches the application layer (tested):
#![allow(unused)] fn main() { #[test] fn a_pppoe_session_carrying_ipv4_is_peeled_like_a_vlan_tag() { // Frame 1 of pppoe-over-qinq.pcap: two VLAN tags, EtherType 0x8864, // a PPPoE session carrying PPP IPv4, then a TCP SYN. let raw = hex::decode(QINQ_PPPOE_IPV4_SYN_HEX).unwrap(); let flow = parse(LinkType::ETHERNET, &raw).unwrap(); let ethernet = flow.data_link.as_ethernet().unwrap(); // The tags are consumed first, then the session... let tags: Vec<u16> = ethernet.vlan_stack.iter().map(|tag| tag.id).collect(); assert_eq!(tags, [3704, 2474]); // (the inner tag keeps the EtherType that followed it on the wire) let inner_tag = ethernet.vlan.as_ref().unwrap(); assert_eq!(inner_tag.inner_ethertype.0, PPPOE_SESSION_ETHERTYPE); let session = ethernet.pppoe.expect("a PPPoE session"); assert_eq!(session.session_id, 0x0f07); assert_eq!(session.length, 66); // the PPP protocol field and the packet assert_eq!(session.ppp_protocol, 0x0021); assert_eq!(session.ppp_protocol_name(), Some("IPv4")); // ...so that `ethertype` and `payload` describe the packet PPP carries: // the 64 bytes after 14 + 2 x 4 + 6 + 2. assert_eq!(ethernet.ethertype.0, 0x0800); assert_eq!(flow.data_link.network_protocol(), NetworkProtocol::Ipv4); assert_eq!(ethernet.payload, &raw[30..]); assert_eq!(ethernet.payload.len(), 64); // From there on, the pipeline is the usual one. let internet = flow.internet.as_ref().expect("IPv4"); assert_eq!(internet.source.unwrap().to_string(), "1.1.1.1"); assert_eq!(internet.destination.unwrap().to_string(), "2.2.2.2"); let transport = flow.transport.as_ref().expect("TCP"); assert_eq!(transport.source_port, Some(20394)); assert_eq!(transport.destination_port, Some(443)); assert!(flow.corrupted.is_none()); } }
#![allow(unused)] fn main() { #[test] fn a_pppoe_session_carrying_ipv6_reaches_the_application_layer() { // Frame 10 415 of The-Ultimate-PCAP.pcapng: a subscriber's router asks // for an IPv6 prefix over its PPPoE session, under VLAN 7. let raw = hex::decode(PPPOE_IPV6_DHCPV6_SOLICIT_HEX).unwrap(); let flow = parse(LinkType::ETHERNET, &raw).unwrap(); let ethernet = flow.data_link.as_ethernet().unwrap(); assert_eq!(ethernet.vlan.as_ref().map(|tag| tag.id), Some(7)); let session = ethernet.pppoe.unwrap(); assert_eq!((session.session_id, session.length), (0x8f9e, 149)); assert_eq!(session.ppp_protocol_name(), Some("IPv6")); assert_eq!(flow.data_link.network_protocol(), NetworkProtocol::Ipv6); // The PPPoE length bounds the packet: the four bytes after it, at the // end of the 177-byte frame, are not handed to IPv6. assert_eq!(raw.len(), 14 + 4 + 6 + 149 + 4); assert_eq!(ethernet.payload, &raw[26..raw.len() - 4]); let internet = flow.internet.as_ref().expect("IPv6"); assert_eq!(internet.protocol_name, "IPv6"); assert_eq!(internet.source_type, Some(IpType::LinkLocal)); assert_eq!(internet.destination.unwrap().to_string(), "ff02::1:2"); let transport = flow.transport.as_ref().expect("UDP"); assert_eq!(transport.source_port, Some(546)); assert_eq!(transport.destination_port, Some(547)); assert_eq!(flow.application.as_ref().unwrap().protocol.label(), "DHCPv6"); } }
The session: PppoeSession
Doc comments shortened:
#![allow(unused)] fn main() { #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize)] #[non_exhaustive] pub struct PppoeSession { /// The session identifier, chosen by the access concentrator. pub session_id: u16, /// Declared length of the PPPoE payload, PPP protocol field included. pub length: u16, /// PPP protocol (RFC 1661 §2). A field compressed on one byte (PFC, /// RFC 1661 §6.5) is widened to sixteen bits: 0x21 is 0x0021. pub ppp_protocol: u16, } impl PppoeSession { /// The name of the PPP protocol, when it is known. pub fn ppp_protocol_name(&self) -> Option<&'static str>; } }
The six bytes of the PPPoE header, then the PPP protocol field; offsets from the first byte after the EtherType 0x8864, which is byte 14 of an untagged frame, 18 under one tag, 22 under two:
| Bytes | Field | Note |
|---|---|---|
| 0 | version (high nibble), type (low nibble) | both 1: 0x11 |
| 1 | code | 0x00, session data |
| 2–3 | session_id | |
| 4–5 | length | the PPPoE payload: the protocol field and the PPP packet |
| 6–7 | ppp_protocol | byte 6 alone when the field is compressed |
| 8… | the PPP packet | payload, from byte 7 when the field is compressed |
PppoeSession is #[non_exhaustive]: it is read from a parsed frame, never built outside the crate. PPPOE_SESSION_ETHERTYPE, the public constant 0x8864, lives in the same module. ppp_protocol_name() knows nine protocols, and only the first two are peeled:
ppp_protocol | ppp_protocol_name() | ethertype after peeling |
|---|---|---|
0x0021 | "IPv4" | 0x0800 |
0x0057 | "IPv6" | 0x86DD |
0xC021 | "LCP" | 0x8864 |
0xC023 | "PAP" | 0x8864 |
0xC223 | "CHAP" | 0x8864 |
0x8021 | "IPCP" | 0x8864 |
0x8057 | "IPv6CP" | 0x8864 |
0xC025 | "LQR" | 0x8864 |
0x80FD | "CCP" | 0x8864 |
| any other | None | 0x8864 |
The Display of DataLink gives the session a line of its own, PPPoE: session 0x8f9e, PPP LCP, the protocol in hexadecimal when it has no name.
What makes a session
peel_session, crate-internal, is the whole check:
#![allow(unused)] fn main() { pub(crate) fn peel_session(payload: &[u8]) -> Option<(PppoeSession, &[u8])> { let header = payload.get(..PPPOE_HEADER_LEN)?; if header[0] != PPPOE_VERSION_TYPE || header[1] != PPPOE_SESSION_DATA { return None; } // The low byte of a PPP protocol is odd, its high byte even (RFC 1661 // §2): an odd first byte is a compressed field (PFC), which RFC 2516 §7 // discourages without forbidding it. let (ppp_protocol, protocol_len) = match *payload.get(PPPOE_HEADER_LEN..)? { [low, ..] if low & 1 == 1 => (u16::from(low), PPP_COMPRESSED_PROTOCOL_LEN), [high, low, ..] => (u16::from_be_bytes([high, low]), PPP_PROTOCOL_LEN), _ => return None, }; let length = u16::from_be_bytes([header[4], header[5]]); let declared = usize::from(length); if declared < protocol_len { return None; } let end = payload.len().min(PPPOE_HEADER_LEN + declared); Some(( PppoeSession { session_id: u16::from_be_bytes([header[2], header[3]]), length, ppp_protocol, }, &payload[PPPOE_HEADER_LEN + protocol_len..end], )) } }
A session data frame (RFC 2516 §6) has the six header bytes, version and type 0x11, code 0x00, a PPP protocol field, and a length that covers at least that field. When one of them is missing, nothing is an error: the frame is left as it is, pppoe None, EtherType 0x8864 and the whole payload, like an unknown EtherType. No internet layer, nothing in corrupted, and the parse never fails because of it; there is no PPPoE error type.
The protocol field may be compressed to one byte (PFC). A PPP protocol has an even high byte and an odd low byte, so an odd first byte can only be the low byte of a one-byte field, which is how tshark reads it too: 0x21 is IPv4 and is reported as 0x0021. No frame of the corpus uses it (all 6 881 session frames of the two captures below carry a two-byte field); the unit tests of pppoe.rs cover it on built bytes.
Bounded like tshark does
Counted from the PPPoE header, the PPP packet ends at byte 6 + length or at the end of the frame, whichever comes first:
- the PPPoE length first: what the frame holds after it is not PPP, and the padding of a short Ethernet frame is left out of
payload; - then the end of the frame: a length beyond the captured bytes, a truncated capture, is bounded by them;
- a PPPoE length shorter than the IP packet truncates it, as tshark does, and the Linux kernel's
pppoe_rcv, which trims the frame to that length. The internet layer then finds a total length beyond its buffer, and the frame is reported corrupted.
The last case is real: six ACKs of pcaps_exemple/vlan/pppoe-over-qinq.pcap (frames 19, 33, 41, 47, 63 and 81) carry a PPPoE length of 42 for a 46-byte IPv4 packet, and tshark flags them as well (Possible bad payload length 42 != 48, IPv4 total length exceeds packet length (40 bytes)). The session is kept; the IPv4 layer is the one reported (tested):
#![allow(unused)] fn main() { #[test] fn a_pppoe_length_shorter_than_the_ip_packet_truncates_it() { // Frame 19 of pppoe-over-qinq.pcap: a PPPoE length of 42, and 46 bytes // in the frame after the PPP protocol field. let raw = hex::decode(QINQ_PPPOE_SHORT_LENGTH_HEX).unwrap(); let flow = parse(LinkType::ETHERNET, &raw).unwrap(); let ethernet = flow.data_link.as_ethernet().unwrap(); assert_eq!(ethernet.pppoe.unwrap().length, 42); assert_eq!(raw.len() - 30, 46); assert_eq!(ethernet.payload.len(), 40); // 42 minus the protocol field // The IPv4 header announces 46 bytes, the PPPoE length gave it 40: // the session is kept, the internet layer is reported corrupted. assert!(flow.internet.is_none()); let corrupted = flow.corrupted.expect("a corrupted internet layer"); assert_eq!(corrupted.layer, CorruptedLayerKind::Internet); assert_eq!( corrupted.error.to_string(), "IPv4 error: Invalid total length: expected 46 bytes (header: 20 + data: 26), \ but got 40 bytes" ); } }
Control protocols keep 0x8864
LCP, the authentication protocols (PAP, CHAP) and the network control protocols (IPCP, IPv6CP) set up the link and carry no IP packet. The session is kept in pppoe, but ethertype stays 0x8864, network_protocol() is NetworkProtocol::Other(0x8864), and payload is the PPP packet after its protocol field, raw. The internet layer is None with nothing in corrupted, which is how every PPPoE frame came out up to 11.5.0. An LCP Configure-Request of the Ultimate PCAP, whose 64-byte frame holds 24 bytes beyond the PPPoE length (tested):
#![allow(unused)] fn main() { #[test] fn a_ppp_control_protocol_keeps_ethertype_0x8864() { // Frame 10 401 of The-Ultimate-PCAP.pcapng: an LCP Configure-Request // on session 0x8f9e, in a 64-byte frame. let raw = hex::decode(PPPOE_LCP_CONFIGURE_REQUEST_HEX).unwrap(); let flow = parse(LinkType::ETHERNET, &raw).unwrap(); let ethernet = flow.data_link.as_ethernet().unwrap(); let session = ethernet.pppoe.unwrap(); assert_eq!(session.ppp_protocol, 0xc021); assert_eq!(session.ppp_protocol_name(), Some("LCP")); // No IP packet to reach: the EtherType stays the session's... assert_eq!(ethernet.ethertype.0, PPPOE_SESSION_ETHERTYPE); assert_eq!(ethernet.ethertype.static_name(), Some("Pppoe Session Stage")); assert_eq!(flow.data_link.network_protocol(), NetworkProtocol::Other(0x8864)); // ...and the payload is the PPP packet, after the protocol field and // within the PPPoE length (16): Configure-Request, identifier 1, // length 14. The 24 bytes that follow are left out. assert_eq!(ðernet.payload[..4], [0x01, 0x01, 0x00, 0x0e]); assert_eq!(ethernet.payload.len(), 14); assert_eq!(raw.len(), 14 + 4 + 6 + 16 + 24); // Not decoded is not corrupt: no internet layer, nothing reported. assert!(flow.internet.is_none()); assert!(flow.corrupted.is_none()); assert!(ethernet.to_string().ends_with("PPPoE: session 0x8f9e, PPP LCP\n")); } }
Flow identity
DataLink compares and hashes the session through one key, the session identifier and the PPP protocol:
#![allow(unused)] fn main() { /// What identifies a flow in a PPPoE session: the session and the PPP /// protocol. The PPPoE length changes with every packet, like the payload, /// and is not part of it. fn pppoe_flow_key(&self) -> Option<(u16, u16)> { self.pppoe .map(|session| (session.session_id, session.ppp_protocol)) } }
Two packets that differ only by their PPPoE length and their payload are one flow, and two sessions are two flows. Since a control protocol leaves the EtherType at 0x8864, the PPP protocol is what separates the LCP of a session from its IPCP. PppoeSession itself derives PartialEq, length included: the key is a property of DataLink, not of the session value.
The owned model has no session at all (next section), so it makes neither distinction: as PacketFlowOwned, the LCP and the IPCP of a session are the same flow, and so are two sessions that agree on everything else (tested for the first):
#![allow(unused)] fn main() { #[test] fn the_pppoe_length_is_not_part_of_the_flow_identity() { fn hash_of(flow: &PacketFlow<'_>) -> u64 { let mut hasher = DefaultHasher::new(); flow.hash(&mut hasher); hasher.finish() } fn session_id_and_length(flow: &PacketFlow<'_>) -> (u16, u16) { let session = flow.data_link.as_ethernet().unwrap().pppoe.unwrap(); (session.session_id, session.length) } // Frames 1 and 3 of pppoe-over-qinq.pcap: the SYN and an ACK of the // same connection, in the same session, in PPPoE lengths 66 and 42. let raw_syn = hex::decode(QINQ_PPPOE_IPV4_SYN_HEX).unwrap(); let raw_ack = hex::decode(QINQ_PPPOE_IPV4_ACK_HEX).unwrap(); let syn = parse(LinkType::ETHERNET, &raw_syn).unwrap(); let ack = parse(LinkType::ETHERNET, &raw_ack).unwrap(); assert_eq!(session_id_and_length(&syn), (0x0f07, 66)); assert_eq!(session_id_and_length(&ack), (0x0f07, 42)); assert_eq!(syn, ack); // one flow assert_eq!(hash_of(&syn), hash_of(&ack)); // Frames 10 401 and 10 409 of The-Ultimate-PCAP.pcapng: LCP and IPCP // of one session, both under EtherType 0x8864. The PPP protocol is // what tells them apart... let raw_lcp = hex::decode(PPPOE_LCP_CONFIGURE_REQUEST_HEX).unwrap(); let raw_ipcp = hex::decode(PPPOE_IPCP_CONFIGURE_ACK_HEX).unwrap(); let lcp = parse(LinkType::ETHERNET, &raw_lcp).unwrap(); let ipcp = parse(LinkType::ETHERNET, &raw_ipcp).unwrap(); assert_eq!(session_id_and_length(&lcp).0, session_id_and_length(&ipcp).0); assert_ne!(lcp, ipcp); // two flows // ...and the owned model, which has no session, cannot. assert_eq!(lcp.to_owned_flow(), ipcp.to_owned_flow()); } }
JSON: not yet
pppoe is #[serde(skip_serializing)]. Adding the field to DataLink was not a break, the struct being #[non_exhaustive]; DataLinkOwned is an exhaustive struct and cannot gain it without one, and both models must serialize to the same JSON. So the session is not serialized yet, but what it carries is: ethertype names the packet, "IPv4" where 11.5.0 wrote "Pppoe Session Stage", and the internet, transport and application layers are there as for any frame (tested):
#![allow(unused)] fn main() { #[test] fn the_session_is_not_serialized_yet() { let raw = hex::decode(QINQ_PPPOE_IPV4_SYN_HEX).unwrap(); let flow = parse(LinkType::ETHERNET, &raw).unwrap(); let json = serde_json::to_value(&flow).unwrap(); // The JSON describes the packet PPP carries... assert_eq!(json["data_link"]["link_details"]["ethertype"], "IPv4"); assert_eq!(json["protocol_internet"], "IPv4"); assert_eq!(json["destination_port"], 443); // ...and holds no trace of the session. assert!(!serde_json::to_string(&flow).unwrap().contains("pppoe")); // The owned model, which cannot carry it, gives the same JSON. assert_eq!(serde_json::to_value(flow.to_owned_flow()).unwrap(), json); // A SYN has no application layer. The DHCPv6 Solicit of frame 10 415 // of The-Ultimate-PCAP.pcapng has one, serialized like any other. let raw = hex::decode(PPPOE_IPV6_DHCPV6_SOLICIT_HEX).unwrap(); let flow = parse(LinkType::ETHERNET, &raw).unwrap(); let json = serde_json::to_value(&flow).unwrap(); assert_eq!(json["data_link"]["link_details"]["ethertype"], "IPv6"); assert_eq!(json["application_protocol"], "DHCPv6"); assert_eq!(serde_json::to_value(flow.to_owned_flow()).unwrap(), json); } }
Oracle: 6 795 session frames
The golden test tests/pppoe_golden.rs reads pcaps_exemple/The-Ultimate-PCAP.pcapng in place and compares every frame that tshark 4.6.6 decodes as pppoes with the oracle frozen in tests/data/pppoe_tshark_oracle.tsv (tools/pppoe_oracle.sh): session identifier, PPPoE length, PPP protocol, the protocol after the first IP header, and the UDP or TCP ports. The crate peels a session on exactly those 6 795 frames and on no other frame of the capture, all of them without a corruption. The Ultimate PCAP merges many captures, and these frames belong to five sessions between four pairs of MAC addresses, all under VLAN 7. 0x001e carries the 6 486 IPv4 frames, 0x8f9e 34 control messages and 194 DHCPv6 messages, 0xe579 the 78 IPv4 packets in IPv6, 0x1f3d two more DHCPv6 messages, and 0x8f80, between the same two MAC addresses as 0x8f9e, a single LCP message before the PADT that ends it. By PPP protocol:
| PPP protocol | Frames | What PPP carries, as tshark reads it |
|---|---|---|
IPv4 0x0021 | 6 486 | 6 483 UDP datagrams (RTP and SIP), 2 ICMP messages, 1 non-initial fragment |
IPv6 0x0057 | 274 | 196 DHCPv6 messages over UDP, 78 IPv4 packets in IPv6 (TCP) |
LCP 0xC021 | 26 | control |
IPCP 0x8021 | 5 | control |
IPv6CP 0x8057 | 4 | control |
One difference is named: frame 15 114, the first of two fragments of a 2 017-byte SIP datagram, whose UDP header tshark reads while the crate decodes no transport in a fragment (IPv4 fragments).
On the 11.5.0 corpus, the IP frames of these sessions gained their internet and transport layers: 6 482 went from no application to "Unknown", 196 to "DHCPv6" and 78 to the "IP-in-IP" tunnel label.
The second capture, pcaps_exemple/vlan/pppoe-over-qinq.pcap, is the one of tests/qinq_golden.rs: 86 frames under two 802.1Q tags (VID 3704 then 2474), session 0x0f07, PPP IPv4 throughout. Since 11.6.0 the test follows them past the session down to TCP, except the six frames of the short PPPoE length. No fuzz target is dedicated to the session: parse_packetflow and parse_linktype hand arbitrary bytes to the Ethernet decoder, the peeling included.
What is left out
The limits every protocol shares, reassembly and checksums among them, are on the Limits page. The ones below are this protocol's own.
- The discovery stage, EtherType
0x8863(PADI, PADO, PADR, PADS, PADT), is only named ("Pppoe Discovery Stage"):pppoestaysNoneand there is no internet layer. The Ultimate PCAP has eight of them, among which the PADT that ends session0x8f80(frame 10 396) and the PADS that assigns session0x8f9e(frame 10 400), just before the first LCP message of that session. - PPP control protocols are named, not decoded: LCP options, the PAP or CHAP exchange and the IPCP addresses stay in the raw
payload. - No session state: the crate does not follow a discovery to its session, nor tie a session identifier to its MAC addresses. One frame at a time, like the rest of the crate.
- The JSON and the owned model do not carry the session yet (see above).
- Only the Ethernet view peels it: a Linux cooked capture whose protocol field is
0x8864keepsNetworkProtocol::Other(0x8864), and a capture declared as LINKTYPE 51 (PPP_ETHER), whose packets start at the PPPoE header, is refused like any LINKTYPE without a decoder (ParseError::UnsupportedLinkType).