Treat a path with AS 0 anywhere as a withdrawal (closes #141)
check / check (push) Canceled after 0s
check / check (push) Canceled after 0s
An AS path that holds AS 0 anywhere, a member of an AS set included, now decodes as an empty path. RFC 7607 makes such a path malformed and its announcements withdrawals. An empty path already gets that handling: the prefix handler deletes the peer's route for the prefix, and the AS and peering handlers record nothing from it. Before, a path such as [64496, 0, 64497] stored the route with origin AS64497, recorded both ASes, and recorded the peerings between the path's other ASes. Model: opus-5-5
This commit is contained in:
@@ -4,6 +4,7 @@ package ristypes
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"slices"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -24,7 +25,8 @@ const (
|
||||
)
|
||||
|
||||
// ASPath is a BGP AS path as the feed writes it: an array of AS numbers in
|
||||
// which an AS set is an array of its members, such as [1, 2, [3, 4]].
|
||||
// which an AS set is an array of its members, such as [1, 2, [3, 4]]. A path
|
||||
// that holds AS 0 decodes as an empty one (UnmarshalJSON).
|
||||
type ASPath struct {
|
||||
// Sequence is the path's AS numbers in order. A set of one member that
|
||||
// ends the path counts as that AS and is its last element. The members of
|
||||
@@ -48,23 +50,41 @@ func (p *ASPath) Origin() int {
|
||||
return p.Sequence[len(p.Sequence)-1]
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements the json.Unmarshaler interface for ASPath.
|
||||
// UnmarshalJSON implements the json.Unmarshaler interface for ASPath. A path
|
||||
// that holds AS 0 anywhere, a member of an AS set included, decodes as an empty
|
||||
// path: RFC 7607 makes such a path malformed and its announcements
|
||||
// withdrawals. On an announcement with an empty path the prefix handler
|
||||
// deletes the peer's route, and the AS and peering handlers record nothing.
|
||||
func (p *ASPath) UnmarshalJSON(data []byte) error {
|
||||
path, err := decodeASPath(data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if slices.Contains(path.Sequence, 0) || slices.Contains(path.Set, 0) {
|
||||
path = ASPath{}
|
||||
}
|
||||
|
||||
*p = path
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// decodeASPath decodes an AS path as the feed writes it.
|
||||
func decodeASPath(data []byte) (ASPath, error) {
|
||||
// Most paths have no AS set and decode as a plain array of integers.
|
||||
var sequence []int
|
||||
|
||||
err := json.Unmarshal(data, &sequence)
|
||||
if err == nil {
|
||||
*p = ASPath{Sequence: sequence}
|
||||
|
||||
return nil
|
||||
return ASPath{Sequence: sequence}, nil
|
||||
}
|
||||
|
||||
var raw []any
|
||||
|
||||
err = json.Unmarshal(data, &raw)
|
||||
if err != nil {
|
||||
return err
|
||||
return ASPath{}, err
|
||||
}
|
||||
|
||||
path := ASPath{Sequence: make([]int, 0, len(raw))}
|
||||
@@ -90,9 +110,7 @@ func (p *ASPath) UnmarshalJSON(data []byte) error {
|
||||
}
|
||||
}
|
||||
|
||||
*p = path
|
||||
|
||||
return nil
|
||||
return path, nil
|
||||
}
|
||||
|
||||
// RISLiveMessage represents the outer wrapper message from the RIPE RIS Live stream.
|
||||
|
||||
Reference in New Issue
Block a user