Documentation
¶
Overview ¶
Package ldp decodes LDP (Label Distribution Protocol) PDUs per RFC 5036. LDP runs on TCP/646 (session messages) and UDP/646 (Hello discovery). It distributes MPLS label bindings between Label Switching Routers (LSRs), forming the control plane of MPLS networks.
LDP is the **MPLS control plane** — it distributes label bindings that govern packet forwarding at the MPLS switching layer. Without LDP, MPLS forwarding tables remain empty and traffic cannot traverse the MPLS core.
Security relevance:
**No default authentication** — LDP TCP/646 sessions are unauthenticated. TCP MD5 authentication (RFC 2385) is optional and often omitted. An attacker that can inject TCP segments can manipulate the label space.
**LDP session hijacking** allows label manipulation — traffic redirection at the MPLS layer without touching IP routing.
**Hello messages on UDP/646** disclose LSR IDs (router loopback IPs) and transport addresses — the full LSR topology is visible passively.
**Label Mapping messages** disclose FEC-to-label bindings — the complete MPLS forwarding topology is exposed.
**LDP is the signalling protocol for MPLS VPNs** (L3VPN, L2VPN, VPLS). Compromising LDP = compromising the MPLS switching plane, enabling traffic interception across provider VPNs.
**LSR IDs** are router loopback addresses — reachable loopbacks are implicit LDP transport endpoints.
Wrap-vs-native judgement
Native. RFC 5036 is publicly available. The LDP PDU header is a tight 10-byte binary header followed by messages, each with a 4-byte header plus TLV parameters. No crypto at the parse layer.
What this package covers
**10-byte LDP PDU header**: version (must be 1), pdu_length, lsr_id (dotted-quad), label_space.
**LDP message header**: message_type (15-bit, with unknown_bit), message_length, message_id. First message only.
**13-entry message type name table**: Notification (0x0001), Hello (0x0100), Initialization (0x0200), KeepAlive (0x0201), Address (0x0300), Address Withdraw (0x0301), Label Mapping (0x0400), Label Request (0x0401), Label Withdraw (0x0402), Label Release (0x0403), Label Abort Request (0x0404).
**TLV walker**: unknown_bit(1) + forward_bit(1) + type(14 bits) + length(2 BE) + value for all TLVs in the first message; surfaces tlv_count.
**Common Hello Parameters TLV (0x0500)**: hold_time, targeted, request_targeted.
**IPv4 Transport Address TLV (0x0501)**: transport_address (dotted-quad).
**Common Session Parameters TLV (0x0600)**: keepalive_time, max_pdu_length, receiver_lsr_id (dotted-quad).
**Generic Label TLV (0x0300)**: label value (for Label Mapping).
**Classification flags**: is_hello, is_initialization, is_keepalive, is_label_mapping, is_notification.
What this package does NOT cover (deliberately out of scope)
**FEC TLV (0x0001)**: FEC element type dispatch, prefix length, and address bytes.
**Address List TLV (0x0100)**: address-family and address list.
**Status TLV (0x0400) in Notification messages**: status code, E/F bits, message ID.
**ATM Label / Frame Relay Label TLVs**: legacy label encoding.
**Path Vector / Hop Count TLVs**: loop-detection parameters.
**Multiple PDUs** per buffer: only the first PDU and its first message are decoded.
**TCP MD5 authentication**: the authentication is at the TCP layer, not within LDP PDU bytes.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Result ¶
type Result struct {
TotalBytes int `json:"total_bytes"`
// PDU header fields
Version int `json:"version"`
PDULength int `json:"pdu_length"`
LSRID string `json:"lsr_id"`
LabelSpace int `json:"label_space"`
// First message header
MessageType int `json:"message_type"`
MessageTypeName string `json:"message_type_name"`
MessageLength int `json:"message_length"`
MessageID uint32 `json:"message_id"`
// Classification
IsHello bool `json:"is_hello"`
IsInitialization bool `json:"is_initialization"`
IsKeepalive bool `json:"is_keepalive"`
IsLabelMapping bool `json:"is_label_mapping"`
IsNotification bool `json:"is_notification"`
// TLV summary
TLVCount int `json:"tlv_count"`
// Common Hello Parameters TLV (0x0500)
HasHelloParams bool `json:"has_hello_params"`
HoldTime int `json:"hold_time,omitempty"`
Targeted bool `json:"targeted,omitempty"`
RequestTargeted bool `json:"request_targeted,omitempty"`
// IPv4 Transport Address TLV (0x0501)
HasTransportAddress bool `json:"has_transport_address"`
TransportAddress string `json:"transport_address,omitempty"`
// Common Session Parameters TLV (0x0600)
HasSessionParams bool `json:"has_session_params"`
KeepaliveTime int `json:"keepalive_time,omitempty"`
MaxPDULength int `json:"max_pdu_length,omitempty"`
ReceiverLSRID string `json:"receiver_lsr_id,omitempty"`
// Generic Label TLV (0x0300)
HasGenericLabel bool `json:"has_generic_label"`
LabelValue uint32 `json:"label_value,omitempty"`
}
Result is the structured decode of an LDP PDU.