Documentation
¶
Overview ¶
Package mrt reads, decodes, and encodes MRT routing-information records (RFC 6396).
Index ¶
- Constants
- Variables
- func ASPathIsFourByte(mrtType, subtype uint16) bool
- func DecodeMicrosecond(data []byte) (uint32, error)
- func ExtractCommunities(attrs []PathAttribute) []uint32
- func ExtractLargeCommunities(attrs []PathAttribute) [][3]uint32
- func ExtractLocalPref(attrs []PathAttribute) (uint32, bool)
- func ExtractMED(attrs []PathAttribute) (uint32, bool)
- func ExtractNextHop(attrs []PathAttribute) netip.Addr
- func ExtractNextHopRIB(attrs []PathAttribute) netip.Addr
- func ExtractOrigin(attrs []PathAttribute) (uint8, bool)
- func FormatASPath(segments []ASPathSegment) string
- func HasAtomicAggregate(attrs []PathAttribute) bool
- func IsAS4Subtype(subtype uint16) bool
- func IsAddPathBGP4MPSubtype(subtype uint16) bool
- func IsAddPathRIBSubtype(subtype uint16) bool
- func MatchCommunityRegex(attrs []PathAttribute, match func(s string) bool) bool
- func ParseMPReachRIBEntry(value []byte) (netip.Addr, error)
- func ParsePrefixes(data []byte, addPath bool) ([]netip.Prefix, error)
- func ParsePrefixesAFI(data []byte, afi uint16, addPath bool) ([]netip.Prefix, error)
- func RIBSubtypeAFI(subtype uint16) uint16
- func ReadFile(filename string, handler *Handler) error
- func ReadFrom(r io.Reader, handler *Handler) error
- func SniffDecompress(rc io.ReadCloser) (io.ReadCloser, error)
- func UpdateAttributeBytes(body []byte) ([]byte, error)
- func UpdateSections(body []byte) (withdrawn, attrs, nlri []byte, err error)
- func WriteBGP4MPMessage(buf []byte, off int, h *BGP4MPHeader, as4 bool, bgpMsg []byte) int
- func WriteBGP4MPStateChange(buf []byte, off int, h *BGP4MPHeader, as4 bool, oldState, newState uint16) int
- func WriteCommonHeader(buf []byte, off int, timestamp uint32, typ, subtype uint16, msgLen uint32) int
- func WriteExtendedHeader(buf []byte, off int, timestamp, microsecond uint32, typ, subtype uint16, ...) int
- func WritePeerEntry(buf []byte, off int, p *PeerEntry) int
- func WritePeerIndexTable(buf []byte, off int, collectorBGPID [4]byte, viewName string, ...) int
- func WriteRIBEntries(buf []byte, off int, entries []RIBEntry, addPath bool) int
- func WriteRIBEntry(buf []byte, off int, e *RIBEntry) int
- func WriteRIBEntryAddPath(buf []byte, off int, e *RIBEntry) int
- func WriteRIBGenericHeader(buf []byte, off int, seq uint32, afi uint16, safi uint8, nlri []byte) int
- func WriteRIBHeader(buf []byte, off int, seq uint32, prefixLen uint8, prefix []byte) int
- func WriteTableDump(buf []byte, off int, r *TableDumpRecord) int
- type ASPathSegment
- type Aggregator
- type BGP4MPHeader
- type Capability
- type ExtendedCommunity
- type GeoPeerEntry
- type Handler
- type Header
- type MPReach
- type MPUnreach
- type MessageRecord
- type ParsedMessage
- type ParsedNotification
- type ParsedOpen
- type ParsedUpdate
- type PathAttribute
- type PeerEntry
- type PeerIndexTable
- type RIBEntry
- type RIBGenericRecord
- type RIBRecord
- type StateChangeRecord
- type TableDumpRecord
- type Writer
- type WriterOption
Constants ¶
const ( AttrOrigin uint8 = 1 AttrASPath uint8 = 2 AttrNextHop uint8 = 3 AttrMED uint8 = 4 AttrLocalPref uint8 = 5 AttrAtomicAggregate uint8 = 6 AttrAggregator uint8 = 7 AttrCommunity uint8 = 8 AttrOriginatorID uint8 = 9 AttrClusterList uint8 = 10 AttrMPReachNLRI uint8 = 14 AttrMPUnreachNLRI uint8 = 15 AttrExtCommunity uint8 = 16 AttrAS4Path uint8 = 17 AttrAS4Aggregator uint8 = 18 AttrLargeCommunity uint8 = 32 AttrOTC uint8 = 35 // RFC 9234 Only to Customer )
BGP path attribute type codes (IANA "BGP Path Attributes" registry).
const ( TypeOSPFv2 uint16 = 11 TypeTableDump uint16 = 12 TypeTableDumpV2 uint16 = 13 TypeBGP4MP uint16 = 16 TypeBGP4MPET uint16 = 17 TypeISIS uint16 = 32 TypeISISET uint16 = 33 TypeOSPFv3 uint16 = 48 TypeOSPFv3ET uint16 = 49 )
MRT Type codes (RFC 6396 Section 5.3).
const ( TableDumpAFIIPv4 uint16 = 1 TableDumpAFIIPv6 uint16 = 2 )
TABLE_DUMP subtypes (RFC 6396 Section 5.5).
const ( TDV2PeerIndexTable uint16 = 1 TDV2RIBIPv4Unicast uint16 = 2 TDV2RIBIPv4Multicast uint16 = 3 TDV2RIBIPv6Unicast uint16 = 4 TDV2RIBIPv6Multicast uint16 = 5 TDV2RIBGeneric uint16 = 6 TDV2GeoPeerTable uint16 = 7 // RFC 6397 TDV2RIBIPv4UnicastAP uint16 = 8 // RFC 8050 TDV2RIBIPv4MulticastAP uint16 = 9 // RFC 8050 TDV2RIBIPv6UnicastAP uint16 = 10 // RFC 8050 TDV2RIBIPv6MulticastAP uint16 = 11 // RFC 8050 TDV2RIBGenericAP uint16 = 12 // RFC 8050 )
TABLE_DUMP_V2 subtypes (RFC 6396 Section 5.6, RFC 6397, RFC 8050).
const ( BGP4MPStateChange uint16 = 0 BGP4MPMessage uint16 = 1 BGP4MPEntry uint16 = 2 // deprecated BGP4MPSnapshot uint16 = 3 // deprecated BGP4MPMessageAS4 uint16 = 4 BGP4MPStateChangeAS4 uint16 = 5 BGP4MPMessageLocal uint16 = 6 BGP4MPMessageAS4Local uint16 = 7 BGP4MPMessageAP uint16 = 8 // RFC 8050 BGP4MPMessageAS4AP uint16 = 9 // RFC 8050 BGP4MPMessageLocalAP uint16 = 10 // RFC 8050 BGP4MPMessageAS4LocalAP uint16 = 11 // RFC 8050 )
BGP4MP / BGP4MP_ET subtypes (RFC 6396 Section 5.7, RFC 8050).
const ( FSMIdle uint16 = 1 FSMConnect uint16 = 2 FSMActive uint16 = 3 FSMOpenSent uint16 = 4 FSMOpenConfirm uint16 = 5 FSMEstablished uint16 = 6 )
BGP FSM states (RFC 4271 Section 8.2.2).
const ( AFIIPv4 uint16 = 1 AFIIPv6 uint16 = 2 )
Address families for MRT headers.
const ( PeerAS4 byte = 0x02 // bit 6: 1 = 32-bit AS PeerIPv6 byte = 0x01 // bit 7: 1 = IPv6 )
Peer Type bit flags (RFC 6396 Section 4.3.1 Figure 7).
const ( CommonHeaderLen = 12 // Timestamp(4) + Type(2) + Subtype(2) + Length(4) ExtTimestampLen = 4 // Microsecond Timestamp field MaxRecordLen = 16 << 20 // 16 MiB safety cap )
Header sizes.
Variables ¶
var ( // ErrShortData reports input that ends before a field the format requires. ErrShortData = errors.New("mrt: short data") // ErrBadAFI reports an Address Family Identifier this decoder does not handle. ErrBadAFI = errors.New("mrt: unsupported address family") )
Exported so a caller can tell the failure kinds apart with errors.Is instead of matching on message text. internal/analyze needs exactly that: a truncated NLRI (ErrShortData) is a damaged record it should count and keep going on, while an unrecognized address family (ErrBadAFI) means the record is not one it understands at all.
var ErrRecordTooLarge = errors.New("mrt: record length exceeds maximum")
ErrRecordTooLarge is returned when a record's Length exceeds MaxRecordLen.
Functions ¶
func ASPathIsFourByte ¶
ASPathIsFourByte reports whether AS_PATH inside the given MRT record type and subtype uses 4-byte AS numbers.
RFC 6396 fixes the width per record type; it is never inferable from the attribute bytes, because a 2-byte path and a 4-byte path can share a byte count. Callers MUST derive the width from the record, which is what this function is for.
TABLE_DUMP (12) 2-byte (Section 4.2) TABLE_DUMP_V2 (13) 4-byte (Section 4.3.4) BGP4MP_MESSAGE 2-byte (Section 4.4.2) BGP4MP_MESSAGE_AS4 4-byte (Section 4.4.3)
Types that carry no BGP AS_PATH report false (the pre-V2 legacy width).
func DecodeMicrosecond ¶
DecodeMicrosecond reads the 4-byte microsecond timestamp that follows the common header in _ET type records (RFC 6396 Section 3).
func ExtractCommunities ¶
func ExtractCommunities(attrs []PathAttribute) []uint32
ExtractCommunities returns standard communities as (high:low) uint32 pairs.
func ExtractLargeCommunities ¶
func ExtractLargeCommunities(attrs []PathAttribute) [][3]uint32
ExtractLargeCommunities returns large communities (RFC 8092) as (global, local1, local2) triples.
func ExtractLocalPref ¶
func ExtractLocalPref(attrs []PathAttribute) (uint32, bool)
ExtractLocalPref returns the LOCAL_PREF value.
func ExtractMED ¶
func ExtractMED(attrs []PathAttribute) (uint32, bool)
ExtractMED returns the MULTI_EXIT_DISC value.
func ExtractNextHop ¶
func ExtractNextHop(attrs []PathAttribute) netip.Addr
ExtractNextHop returns the next-hop address from path attributes. Checks NEXT_HOP (type 3) first, then MP_REACH_NLRI (type 14).
func ExtractNextHopRIB ¶
func ExtractNextHopRIB(attrs []PathAttribute) netip.Addr
ExtractNextHopRIB returns the next hop for a TABLE_DUMP_V2 RIB entry.
It prefers the plain NEXT_HOP attribute (type 3), which is how IPv4 RIB entries carry the next hop, and otherwise decodes the abbreviated MP_REACH_NLRI defined by RFC 6396 Section 4.3.4.
Use ExtractNextHop instead for attributes taken from a BGP UPDATE message.
func ExtractOrigin ¶
func ExtractOrigin(attrs []PathAttribute) (uint8, bool)
ExtractOrigin returns the ORIGIN value (0=IGP, 1=EGP, 2=INCOMPLETE).
func FormatASPath ¶
func FormatASPath(segments []ASPathSegment) string
FormatASPath renders parsed AS-path segments as a space-separated string. AS_SEQUENCE segments produce space-separated ASNs; AS_SET segments produce {asn,asn}.
func HasAtomicAggregate ¶
func HasAtomicAggregate(attrs []PathAttribute) bool
HasAtomicAggregate reports whether ATOMIC_AGGREGATE (RFC 4271 Section 5.1.6) is present. The attribute is a flag: its value is zero-length by definition.
func IsAS4Subtype ¶
IsAS4Subtype reports whether a BGP4MP subtype uses 4-byte AS numbers.
func IsAddPathBGP4MPSubtype ¶
IsAddPathBGP4MPSubtype reports whether a BGP4MP subtype carries add-path NLRI.
func IsAddPathRIBSubtype ¶
IsAddPathRIBSubtype reports whether a TABLE_DUMP_V2 subtype carries Path Identifiers per RFC 8050.
func MatchCommunityRegex ¶
func MatchCommunityRegex(attrs []PathAttribute, match func(s string) bool) bool
MatchCommunityRegex tests whether any community in the attributes matches the given regex. Checks standard (type 8), large (type 32), and extended (type 16). Returns true on first match.
func ParseMPReachRIBEntry ¶
ParseMPReachRIBEntry decodes the abbreviated MP_REACH_NLRI carried inside a TABLE_DUMP_V2 RIB entry and returns its next hop.
RFC 6396 Section 4.3.4: "only the Next Hop Address Length and Next Hop Address fields are included. The Address Family Identifier, Subsequent AFI, NLRI and Reserved fields are omitted." The AFI/SAFI and prefix already live in the enclosing RIB record header, so the value is exactly:
+---------------------+------------------------+ | Next Hop Length (1) | Next Hop Address (var) | +---------------------+------------------------+
Decoding this with the full-form parser reads the length from the wrong offset and yields a garbage or empty next hop, which is why this is a separate entry point.
func ParsePrefixes ¶
ParsePrefixes parses packed IPv4 NLRI prefixes into netip.Prefix values. Set addPath=true when the NLRI includes a 4-byte Path Identifier per prefix.
The withdrawn-routes and NLRI fields of a BGP UPDATE are always IPv4 (RFC 4271 Section 4.3); IPv6 reachability travels in MP_REACH_NLRI. Use ParsePrefixesAFI for those.
func ParsePrefixesAFI ¶
ParsePrefixesAFI parses packed NLRI prefixes for the given address family.
Malformed input is reported, never silently dropped. A damaged NLRI field returns the prefixes decoded so far together with an error naming the offset and the offending value, so a caller can both salvage the good entries and tell the operator the record is damaged. Returning the short list alone would make "fewer routes than the file contains" indistinguishable from "the file has fewer routes" (ai/rules/evidence.md).
A prefix length beyond the family width is never emitted: netip's zero Prefix reads downstream as a default route.
An unrecognized AFI yields no prefixes and an error, per RFC 6396 Section 4.3.3 ("SHOULD discard the remainder of the MRT record").
func RIBSubtypeAFI ¶
RIBSubtypeAFI returns the AFI for an AFI/SAFI-specific RIB subtype. Returns 0 for non-AFI-specific subtypes (RIB_GENERIC, PEER_INDEX_TABLE, GEO_PEER_TABLE).
func ReadFile ¶
ReadFile opens an MRT file, auto-detects compression by extension (.gz, .bz2), and iterates records through handler callbacks.
func SniffDecompress ¶
func SniffDecompress(rc io.ReadCloser) (io.ReadCloser, error)
SniffDecompress wraps rc with a gzip or bzip2 decompressor when the stream's leading magic bytes indicate compression (gzip 1f 8b, bzip2 "BZh"), otherwise returns rc reading raw. Only the few peeked bytes are buffered, so the stream stays unbuffered for multi-GB inputs. Used for stdin ("-"), which has no filename extension to sniff. The returned ReadCloser owns rc and closes it.
func UpdateAttributeBytes ¶
UpdateAttributeBytes returns the raw Path Attributes section of an UPDATE body, without decoding the individual attributes.
Callers that need the attribute bytes verbatim (to re-pack them, hash them, or hand them to a matcher) use this; callers that want decoded attributes use ParseUpdateBody. Both share one implementation of the field offsets, so the two can never disagree about where the section starts.
func UpdateSections ¶
UpdateSections splits an UPDATE body into its withdrawn-routes, path-attribute and NLRI sections (RFC 4271 Section 4.3).
This is the exported face of the single source of truth for the UPDATE field layout. A caller that needs more than the attribute bytes -- counting the prefixes in all four NLRI locations, for instance -- MUST come through here rather than re-deriving the offsets, because a second copy of the layout is a second thing to get wrong and it will not be wrong in the same way.
func WriteBGP4MPMessage ¶
func WriteBGP4MPStateChange ¶
func WriteCommonHeader ¶
func WriteExtendedHeader ¶
func WritePeerIndexTable ¶
func WriteRIBEntries ¶
func WriteRIBGenericHeader ¶
func WriteRIBHeader ¶
func WriteTableDump ¶
func WriteTableDump(buf []byte, off int, r *TableDumpRecord) int
Types ¶
type ASPathSegment ¶
ASPathSegment is a segment in an AS path (for offline parsing).
func ParseASPath ¶
func ParseASPath(data []byte, fourByte bool) ([]ASPathSegment, error)
ParseASPath parses AS_PATH value bytes into a list of (segType, []asn) pairs. fourByte=true for 4-byte ASN encoding (TABLE_DUMP_V2, BGP4MP_MESSAGE_AS4).
type Aggregator ¶
Aggregator is a decoded AGGREGATOR attribute (RFC 4271 Section 5.1.7).
func ExtractAggregator ¶
func ExtractAggregator(attrs []PathAttribute) (Aggregator, bool)
ExtractAggregator returns the AGGREGATOR attribute (RFC 4271 Section 5.1.7), falling back to AS4_AGGREGATOR (RFC 6793 Section 3) when only that is present.
The AS width is taken from the attribute length, which is unambiguous here: RFC 6793 fixes AGGREGATOR at 6 octets for a 2-byte AS and 8 for a 4-byte AS. (AS_PATH has no such length tell, which is why ParseASPath takes the width as a parameter instead.)
type BGP4MPHeader ¶
type BGP4MPHeader struct {
PeerAS uint32
LocalAS uint32
IfIndex uint16
AFI uint16
PeerIP []byte // 4 or 16 bytes
LocalIP []byte // 4 or 16 bytes
}
BGP4MPHeader represents the common fields of BGP4MP messages.
type Capability ¶
Capability is a single BGP capability from an OPEN message.
type ExtendedCommunity ¶
ExtendedCommunity is one 8-octet extended community (RFC 4360 Section 2).
func ExtractExtendedCommunities ¶
func ExtractExtendedCommunities(attrs []PathAttribute) []ExtendedCommunity
ExtractExtendedCommunities returns the extended communities (RFC 4360 Section 2) as 8-octet records. A value whose length is not a multiple of 8 is malformed and yields none.
type GeoPeerEntry ¶
GeoPeerEntry represents a peer in a GEO_PEER_TABLE (RFC 6397 Section 4.1).
type Handler ¶
type Handler struct {
OnHeader func(h Header, microsecond uint32, data []byte) error
OnPeerIndex func(h Header, pit *PeerIndexTable) error
OnRIB func(h Header, r *RIBRecord) error
OnRIBGeneric func(h Header, r *RIBGenericRecord) error
OnGeoPeer func(h Header, g *geoPeerTable) error
OnMessage func(h Header, microsecond uint32, m *MessageRecord) error
OnStateChange func(h Header, microsecond uint32, s *StateChangeRecord) error
OnTableDump func(h Header, t *TableDumpRecord) error
}
Handler receives decoded MRT records. Set callbacks for the record types you want; nil callbacks are skipped. Return a non-nil error to stop iteration.
type Header ¶
Header is the MRT common header (RFC 6396 Section 2).
func DecodeHeader ¶
DecodeHeader parses a 12-byte MRT common header.
type MPReach ¶
type MPReach struct {
AFI uint16
SAFI uint8
NextHop netip.Addr
LinkLocal netip.Addr // set when the next hop is the 32-byte RFC 2545 form
Prefixes []netip.Prefix
}
MPReach is a decoded MP_REACH_NLRI attribute (RFC 4760 Section 3), the full on-the-wire form carried in a BGP UPDATE message.
RIB entries inside a TABLE_DUMP_V2 record carry an abbreviated form instead; decode those with ParseMPReachRIBEntry, never with this function.
func ParseMPReach ¶
ParseMPReach decodes the full MP_REACH_NLRI attribute (RFC 4760 Section 3): AFI(2) + SAFI(1) + Next Hop Length(1) + Next Hop(var) + Reserved(1) + NLRI(var).
Use ParseMPReachRIBEntry for TABLE_DUMP_V2 RIB entries, which omit every field except the next hop.
A damaged NLRI section returns BOTH the attribute decoded so far (AFI, SAFI, next hop, and the prefixes read before the damage) AND an error, mirroring ParsePrefixesAFI. A caller that wants to render what survived checks the value; a caller that wants correctness checks the error. Returning nil with the error would throw away good prefixes and leave a caller that counts them unable to tell "3 prefixes" from "3 prefixes and the rest is unreadable". A failure BEFORE the NLRI section (a truncated fixed header or an unusable next hop) yields nil, because nothing was decoded.
type MPUnreach ¶
MPUnreach is a decoded MP_UNREACH_NLRI attribute (RFC 4760 Section 4).
func ParseMPUnreach ¶
ParseMPUnreach decodes the MP_UNREACH_NLRI attribute (RFC 4760 Section 4): AFI(2) + SAFI(1) + Withdrawn Routes(var).
Like ParseMPReach, a damaged withdrawn-routes section returns both the prefixes decoded so far and an error.
type MessageRecord ¶
type MessageRecord struct {
BGP4MPHeader
BGPMessage []byte
}
MessageRecord represents a BGP4MP MESSAGE record (RFC 6396 Section 4.4.2).
func DecodeBGP4MPMessage ¶
func DecodeBGP4MPMessage(subtype uint16, data []byte) (*MessageRecord, error)
DecodeBGP4MPMessage parses a BGP4MP MESSAGE variant. Supports subtypes: 1 (MESSAGE), 4 (MESSAGE_AS4), 6 (MESSAGE_LOCAL), 7 (MESSAGE_AS4_LOCAL), and add-path variants 8-11.
type ParsedMessage ¶
type ParsedMessage struct {
Type uint8
Open *ParsedOpen
Update *ParsedUpdate
Notification *ParsedNotification
}
ParsedMessage is a parsed BGP message from an MRT record.
func ParseBGPMessage ¶
func ParseBGPMessage(data []byte) (*ParsedMessage, error)
ParseBGPMessage parses a complete BGP message (including 19-byte header).
For an UPDATE it may return a non-nil message TOGETHER with a non-nil error: the message holds everything that decoded and the error names what did not (see parseUpdate). Callers that only want fully-clean records check err first, as before; callers that render records check the value too.
type ParsedNotification ¶
ParsedNotification contains fields from a BGP NOTIFICATION message.
type ParsedOpen ¶
type ParsedOpen struct {
Version uint8
ASN uint32
HoldTime uint16
RouterID [4]byte
Caps []Capability
}
ParsedOpen contains fields from a BGP OPEN message.
type ParsedUpdate ¶
type ParsedUpdate struct {
WithdrawnPrefixes []netip.Prefix
Attributes []PathAttribute
AnnouncedPrefixes []netip.Prefix
}
ParsedUpdate contains fields from a BGP UPDATE message.
type PathAttribute ¶
PathAttribute is a single parsed path attribute.
func FindAttribute ¶
func FindAttribute(attrs []PathAttribute, code uint8) *PathAttribute
FindAttribute returns the first attribute with the given type code, or nil.
func ParseAttributes ¶
func ParseAttributes(data []byte) []PathAttribute
ParseAttributes extracts path attributes from raw attribute bytes.
type PeerEntry ¶
PeerEntry represents a peer in a PEER_INDEX_TABLE.
type PeerIndexTable ¶
PeerIndexTable represents a TABLE_DUMP_V2 PEER_INDEX_TABLE (RFC 6396 Section 4.3.1).
func DecodePeerIndexTable ¶
func DecodePeerIndexTable(data []byte) (*PeerIndexTable, error)
DecodePeerIndexTable parses a TABLE_DUMP_V2 PEER_INDEX_TABLE message body.
type RIBEntry ¶
type RIBEntry struct {
PeerIndex uint16
OrigTime uint32
PathID uint32 // only for add-path subtypes (RFC 8050)
Attributes []byte
}
RIBEntry represents a single RIB entry within a TABLE_DUMP_V2 RIB record.
type RIBGenericRecord ¶
type RIBGenericRecord struct {
SequenceNumber uint32
AFI uint16
SAFI uint8
NLRI []byte
Entries []RIBEntry
}
RIBGenericRecord represents a TABLE_DUMP_V2 RIB_GENERIC record (RFC 6396 Section 4.3.3).
func DecodeRIBGenericRecord ¶
func DecodeRIBGenericRecord(subtype uint16, data []byte) (*RIBGenericRecord, error)
DecodeRIBGenericRecord parses a TABLE_DUMP_V2 RIB_GENERIC record (subtypes 6 and 12).
type RIBRecord ¶
RIBRecord represents a TABLE_DUMP_V2 AFI/SAFI-specific RIB record (RFC 6396 Section 4.3.2).
type StateChangeRecord ¶
type StateChangeRecord struct {
BGP4MPHeader
OldState uint16
NewState uint16
}
StateChangeRecord represents a BGP4MP STATE_CHANGE record (RFC 6396 Section 4.4.1).
func DecodeBGP4MPStateChange ¶
func DecodeBGP4MPStateChange(subtype uint16, data []byte) (*StateChangeRecord, error)
DecodeBGP4MPStateChange parses a BGP4MP STATE_CHANGE variant (subtypes 0 and 5).
type TableDumpRecord ¶
type TableDumpRecord struct {
ViewNumber uint16
SeqNumber uint16
Prefix []byte // 4 or 16 bytes
PrefixLen uint8
Status uint8
OrigTime uint32
PeerIP []byte // 4 or 16 bytes
PeerAS uint16
Attributes []byte
}
TableDumpRecord represents a TABLE_DUMP (v1) record.
func DecodeTableDump ¶
func DecodeTableDump(subtype uint16, data []byte) (*TableDumpRecord, error)
DecodeTableDump parses a TABLE_DUMP (type 12) message body. Subtype determines IP size: 1 = IPv4 (4 bytes), 2 = IPv6 (16 bytes).
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer writes MRT records to files with strftime-based filename rotation.
func NewWriter ¶
func NewWriter(pattern string, opts ...WriterOption) *Writer
NewWriter creates a Writer that expands strftime codes in pattern for each file it opens. Records are buffered before flushing to disk.
type WriterOption ¶
type WriterOption func(*Writer)
WriterOption configures a Writer.
func WithInterval ¶
func WithInterval(d time.Duration) WriterOption
WithInterval sets the file rotation interval. Zero disables rotation.