// SPDX-License-Identifier: GPL-2.0-only // Copyright (C) 2020 Michael Crute . All rights reserved. // // Use of this source code is governed by a license that can be found in the // LICENSE file. package six import ( "net" "time" ) // IP protocol version number type IPVersion int const ( IPv6 IPVersion = 6 IPv4 = 4 ) // IPv4 and IPv6 union type, contains a full network for IPv4 and IPv6 // addresses type Addresses struct { IPv4 *net.IPNet IPv6 *net.IPNet } // IRR statistical data. Contains the counts of various IRR data for a // participant. type IRRData struct { PrefixCount int ASNCount int ASSetCount int } // Set of prefixes, optionally with an AS-SET name that a participant has // registered with the exchange. type PrefixSet struct { Timestamp time.Time ASSet *string Prefixes []net.IPNet } // Set of AS numbers with an AS-SET that the participant has registered with // the exchange. type ASSet struct { Timestamp time.Time Name string ASNumbers []int } // Set of ROA record summaries that have been parsed from the raw ROA data for // a participant. type ROASet struct { Timestamp time.Time ROAS []ROA } // Individual ROA summary type ROA struct { TrustAnchor string ASN int MaxLength int Prefix net.IPNet } // A SIX participant is a record of an organization's connection to the Seattle // Internet Exchange. It contains information about their connect, the prefixes // and ASes that they have registered with the exchange, and their usage of the // route server. // // Not all data exists for all participants, and the data that does exist isn't // always in a nice clean format. The parsers attempt to make sense of whatever // is available but some data may be missing or inconsistent. // // The default contains summary data for the participant and more detailed data // can be fetched with the methods attached to this struct as well as to the // RouteServer structs, if the participant is using the route server. type SIXParticipant struct { Organization string URL string ASN int Speed int // Connection speed in Mbit/s Switch string // Connected Switch or Location Contact string // Contact Email Comment string IsConnected bool IsVoter bool Update *time.Time Options []string // Currently: IPv6 and MTU9k PeeringPolicy string ROACount int PeeringDBPrefixCountv4 int PeeringDBPrefixCountv6 int Addresses Addresses JumboAddresses *Addresses IRRv4 IRRData IRRv6 IRRData RouteServer2 *RouteServer RouteServer3 *RouteServer } // Get the set of prefixes that the participant has registered. // // This does an HTTP fetch to get the detailed file. func (p *SIXParticipant) GetPrefixes(ip IPVersion) (*PrefixSet, error) { return fetchParsePrefixList(p.ASN, ip, false) } // Get the prefix to AS associations that the participant has registered. // // This does an HTTP fetch to get the detailed file. func (p *SIXParticipant) GetASPrefixes(ip IPVersion) (*PrefixSet, error) { return fetchParsePrefixList(p.ASN, ip, true) } // Get the AS sets that the participant has registered // // This does an HTTP fetch to get the detailed file. func (p *SIXParticipant) GetASSet(ip IPVersion) (*ASSet, error) { return fetchParseASSet(p.ASN, ip) } // Get the ROA set and more detailed records for the ROAs that the participant // has registered. This does not fetch the raw ROAs, just the summary that the // exchange has computed. // // This does an HTTP fetch to get the detailed file. func (p *SIXParticipant) GetROASet() (*ROASet, error) { return fetchParseROAFile(p.ASN) } // List of lines from the file containing route data dumped from the route // server type RouteFile struct { Timestamp time.Time Lines []string } // Lists of errors that the route server has exported. These are parsed for // more details if possible, but if that fails the attached ErrorRecords object // contains a list of un-parsable lines for consumption. type Errors struct { IPv4 *ErrorRecords IPv6 *ErrorRecords IPv4Jumbo *ErrorRecords IPv6Jumbo *ErrorRecords } // List of error records for route server errors. Also contains a list of lines // that could not be parsed by the parser. type ErrorRecords struct { Records []ErrorRecord UnparsableLines []string } // Create a new ErrorRecords struct func NewErrorRecords() *ErrorRecords { return &ErrorRecords{ Records: []ErrorRecord{}, UnparsableLines: []string{}, } } // Contains the parsed data for a route server error. type ErrorRecord struct { Timestamp time.Time ASN int MTU int Version IPVersion NetworkName string Network net.IPNet Router net.IP Path []int Message string } // Data about the participant's connection to a route server. If the // participant is making use of the route servers this will always contain some // basic statistics about their connection. More detailed information can be // obtained by calling the methods attached to this struct. type RouteServer struct { Number int IPv4 RouteServerStats IPv6 RouteServerStats IPv4Jumbo RouteServerStats IPv6Jumbo RouteServerStats asn int } // Route server statistics. Contains the counts of various types of route // server entries. type RouteServerStats struct { Prefixes int Errors int TransitErrors int } // Gets the list of routes being advertised by the participant. Note that this // file is the raw lines from the route server and no attempt has been made to // parse these lines. The lines are in BIRD format. // // This does an HTTP fetch to get the detailed file. func (s *RouteServer) GetRoutes(ip IPVersion, jumbo bool) (*RouteFile, error) { return fetchParseRoutes(s.Number, s.asn, ip, jumbo) } // Gets the errors returned by the route server for all IP protocols and all // VLANs to which the participant is connected. If the participant is using // multiple route servers, this data is scoped to the current route server. // // This does an HTTP fetch to get the detailed file. func (s *RouteServer) GetErrors() (*Errors, error) { return fetchParseRSErrors(s.Number, s.asn, false), nil } // Get a list of transit errors from the route server. Otherwise return value // and behavior is identical to GetErrors. // // This does an HTTP fetch to get the detailed file. func (s *RouteServer) GetTransitErrors() (*Errors, error) { return fetchParseRSErrors(s.Number, s.asn, true), nil }