1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
|
// SPDX-License-Identifier: GPL-2.0-only
// Copyright (C) 2020 Michael Crute <mike@crute.us>. 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
}
|