Skip to content

Commit

Permalink
Remove ASPA / rfc8210bis support
Browse files Browse the repository at this point in the history
Spring cleaning. This code is not compatible with other implementations
nor the rfc8210bis specification.
  • Loading branch information
job committed Sep 6, 2024
1 parent 353d1a5 commit cb54b62
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 399 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Special thanks for support to the Route Server Support Foundation [RSSF](https:/

## Features of the server

* Dissemination of validated ROA, BGPsec, and ASPA payloads
* Dissemination of validated ROA and BGPsec payloads
* Refreshes a JSON list of prefixes
* Automatic expiration of outdated information (when using JSON produced by [rpki-client](https://www.rpki-client.org))
* Prometheus metrics
Expand Down
15 changes: 0 additions & 15 deletions cmd/rtrdump/rtrdump.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,21 +109,6 @@ func (c *Client) HandlePDU(cs *rtr.ClientSession, pdu rtr.PDU) {
}
c.Data.BgpSecKeys = append(c.Data.BgpSecKeys, rj)

if *LogDataPDU {
log.Debugf("Received: %v", pdu)
}

case *rtr.PDUASPA:
if c.Data.ASPA == nil {
c.Data.ASPA = make([]prefixfile.VAPJson, 0)
}
aj := prefixfile.VAPJson{
CustomerAsid: pdu.CustomerASNumber,
Providers: pdu.ProviderASNumbers,
}

c.Data.ASPA = append(c.Data.ASPA, aj)

if *LogDataPDU {
log.Debugf("Received: %v", pdu)
}
Expand Down
72 changes: 18 additions & 54 deletions cmd/stayrtr/stayrtr.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ var (
SendNotifs = flag.Bool("notifications", true, "Send notifications to clients (disable with -notifications=false)")
EnforceVersion = flag.Bool("enforce.version", false, "Disable version negotiation")
DisableBGPSec = flag.Bool("disable.bgpsec", false, "Disable sending out BGPSEC Router Keys")
DisableASPA = flag.Bool("disable.aspa", false, "Disable sending out ASPA objects")
EnableNODELAY = flag.Bool("enable.nodelay", false, "Force enable TCP NODELAY (Likely increases CPU)")


Expand Down Expand Up @@ -207,10 +206,9 @@ func isValidPrefixLength(prefix netip.Prefix, maxLength uint8) bool {
// 1 - The prefix is a valid prefix
// 2 - The ASN is a valid ASN
// 3 - The MaxLength is valid
// Will return a deduped slice, as well as total VRPs, IPv4 VRPs, IPv6 VRPs, BGPsec Keys and ASPA records
// Will return a deduped slice, as well as total VRPs, IPv4 VRPs, IPv6 VRPs and BGPsec Keys
func processData(vrplistjson []prefixfile.VRPJson,
brklistjson []prefixfile.BgpSecKeyJson,
aspajson []prefixfile.VAPJson) /*Export*/ ([]rtr.VRP, []rtr.BgpsecKey, []rtr.VAP, int, int) {
brklistjson []prefixfile.BgpSecKeyJson) /*Export*/ ([]rtr.VRP, []rtr.BgpsecKey, int, int) {
filterDuplicates := make(map[string]struct{})

// It may be tempting to change this to a simple time.Since() but that will
Expand All @@ -221,7 +219,6 @@ func processData(vrplistjson []prefixfile.VRPJson,

var vrplist []rtr.VRP
var brklist = make([]rtr.BgpsecKey, 0)
var aspalist = make([]rtr.VAP, 0)
var countv4 int
var countv6 int

Expand Down Expand Up @@ -322,26 +319,7 @@ func processData(vrplistjson []prefixfile.VRPJson,
})
}

for _, v := range aspajson {
if v.Expires != nil {
if NowUnix > *v.Expires {
continue
}
}

// Ensure that these are sorted, otherwise they
// don't hash right.
sort.Slice(v.Providers, func(i, j int) bool {
return v.Providers[i] < v.Providers[j]
})

aspalist = append(aspalist, rtr.VAP{
CustomerASN: v.CustomerAsid,
Providers: v.Providers,
})
}

return vrplist, brklist, aspalist, countv4, countv6
return vrplist, brklist, countv4, countv6
}

type IdenticalFile struct {
Expand All @@ -364,10 +342,6 @@ func (s *state) updateFromNewState() error {
if bgpsecjson == nil {
bgpsecjson = make([]prefixfile.BgpSecKeyJson, 0)
}
aspajson := s.lastdata.ASPA
if aspajson == nil {
aspajson = make([]prefixfile.VAPJson, 0)
}

buildtime, err := time.Parse(time.RFC3339, s.lastdata.Metadata.Buildtime)
if s.lastdata.Metadata.GeneratedUnix != nil {
Expand All @@ -385,14 +359,14 @@ func (s *state) updateFromNewState() error {
}

if s.slurm != nil {
vrpsjson, aspajson, bgpsecjson = s.slurm.FilterAssert(vrpsjson, aspajson, bgpsecjson, log.StandardLogger())
vrpsjson, bgpsecjson = s.slurm.FilterAssert(vrpsjson, bgpsecjson, log.StandardLogger())
}

vrps, brks, vaps, countv4, countv6 := processData(vrpsjson, bgpsecjson, aspajson)
count := len(vrps) + len(brks) + len(vaps)
vrps, brks, countv4, countv6 := processData(vrpsjson, bgpsecjson)
count := len(vrps) + len(brks)

log.Infof("New update (%v uniques, %v total prefixes, %v vaps, %v router keys).", len(vrps), count, len(vaps), len(brks))
return s.applyUpdateFromNewState(vrps, brks, vaps, vrpsjson, bgpsecjson, aspajson, countv4, countv6)
log.Infof("New update (%v uniques, %v total prefixes, %v router keys).", len(vrps), count, len(brks))
return s.applyUpdateFromNewState(vrps, brks, vrpsjson, bgpsecjson, countv4, countv6)
}

// Update the state based on the currently loaded files
Expand All @@ -405,10 +379,6 @@ func (s *state) reloadFromCurrentState() error {
if bgpsecjson == nil {
bgpsecjson = make([]prefixfile.BgpSecKeyJson, 0)
}
aspajson := s.lastdata.ASPA
if aspajson == nil {
aspajson = make([]prefixfile.VAPJson, 0)
}

buildtime, err := time.Parse(time.RFC3339, s.lastdata.Metadata.Buildtime)
if s.lastdata.Metadata.GeneratedUnix != nil {
Expand All @@ -426,32 +396,29 @@ func (s *state) reloadFromCurrentState() error {
}

if s.slurm != nil {
vrpsjson, aspajson, bgpsecjson = s.slurm.FilterAssert(vrpsjson, aspajson, bgpsecjson, log.StandardLogger())
vrpsjson, bgpsecjson = s.slurm.FilterAssert(vrpsjson, bgpsecjson, log.StandardLogger())
}

vrps, brks, vaps, countv4, countv6 := processData(vrpsjson, bgpsecjson, aspajson)
count := len(vrps) + len(brks) + len(vaps)
vrps, brks, countv4, countv6 := processData(vrpsjson, bgpsecjson)
count := len(vrps) + len(brks)
if s.server.CountSDs() != count {
log.Infof("New update to old state (%v uniques, %v total prefixes). (old %v - new %v)", len(vrps), count, s.server.CountSDs(), count)
return s.applyUpdateFromNewState(vrps, brks, vaps, vrpsjson, bgpsecjson, aspajson, countv4, countv6)
return s.applyUpdateFromNewState(vrps, brks, vrpsjson, bgpsecjson, countv4, countv6)
}
return nil
}

func (s *state) applyUpdateFromNewState(vrps []rtr.VRP, brks []rtr.BgpsecKey, vaps []rtr.VAP,
vrpsjson []prefixfile.VRPJson, brksjson []prefixfile.BgpSecKeyJson, aspajson []prefixfile.VAPJson,
func (s *state) applyUpdateFromNewState(vrps []rtr.VRP, brks []rtr.BgpsecKey,
vrpsjson []prefixfile.VRPJson, brksjson []prefixfile.BgpSecKeyJson,
countv4 int, countv6 int) error {

SDs := make([]rtr.SendableData, 0, len(vrps)+len(brks)+len(vaps))
SDs := make([]rtr.SendableData, 0, len(vrps) + len(brks))
for _, v := range vrps {
SDs = append(SDs, v.Copy())
}
for _, v := range brks {
SDs = append(SDs, v.Copy())
}
for _, v := range vaps {
SDs = append(SDs, v.Copy())
}
if !s.server.AddData(SDs) {
log.Info("No difference to current cache")
return nil
Expand All @@ -473,7 +440,6 @@ func (s *state) applyUpdateFromNewState(vrps []rtr.VRP, brks []rtr.BgpsecKey, va
},
ROA: vrpsjson,
BgpSecKeys: brksjson,
ASPA: aspajson,
}
s.lockJson.Unlock()

Expand All @@ -487,7 +453,7 @@ func (s *state) applyUpdateFromNewState(vrps []rtr.VRP, brks []rtr.BgpsecKey, va
countv6_dup++
}
}
s.metricsEvent.UpdateMetrics(countv4, countv6, countv4_dup, countv6_dup, s.lastchange, s.lastts, *CacheBin, len(brks), len(vaps))
s.metricsEvent.UpdateMetrics(countv4, countv6, countv4_dup, countv6_dup, s.lastchange, s.lastts, *CacheBin, len(brks))
}

return nil
Expand Down Expand Up @@ -707,8 +673,7 @@ func (m *metricsEvent) HandlePDU(c *rtr.Client, pdu rtr.PDU) {
"_", -1))).Inc()
}

func (m *metricsEvent) UpdateMetrics(numIPv4 int, numIPv6 int, numIPv4filtered int, numIPv6filtered int, changed time.Time, refreshed time.Time, file string, brkCount int, aspaCount int) {
NumberOfObjects.WithLabelValues("vaps").Set(float64(aspaCount))
func (m *metricsEvent) UpdateMetrics(numIPv4 int, numIPv6 int, numIPv4filtered int, numIPv6filtered int, changed time.Time, refreshed time.Time, file string, brkCount int) {
NumberOfObjects.WithLabelValues("bgpsec_pubkeys").Set(float64(brkCount))
NumberOfObjects.WithLabelValues("vrps").Set(float64(numIPv4 + numIPv6))
NumberOfObjects.WithLabelValues("effective_vrps").Set(float64(numIPv4filtered + numIPv6filtered))
Expand Down Expand Up @@ -763,8 +728,7 @@ func run() error {

EnforceVersion: *EnforceVersion,
DisableBGPSec: *DisableBGPSec,
DisableASPA: *DisableASPA,
EnableNODELAY: *EnableNODELAY,
EnableNODELAY: *EnableNODELAY,
}

var me *metricsEvent
Expand Down
2 changes: 1 addition & 1 deletion cmd/stayrtr/stayrtr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func TestProcessData(t *testing.T) {
Expires: &ExpiredTime,
},
)
got, _, _, v4count, v6count := processData(stuff, nil, nil)
got, _, v4count, v6count := processData(stuff, nil)
want := []rtr.VRP{
{
Prefix: netip.MustParsePrefix("2001:db8::/32"),
Expand Down
27 changes: 0 additions & 27 deletions lib/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,30 +126,3 @@ func TestRouterKeyEncodeDecode(t *testing.T) {
t.FailNow()
}
}

func TestASPAEncodeDecode(t *testing.T) {
p := &PDUASPA{
Version: 1,
Flags: 1,
AFIFlags: 1,
ProviderASCount: 2,
CustomerASNumber: 64497,
ProviderASNumbers: []uint32{64498, 64499},
}

buf := bytes.NewBuffer(nil)
p.Write(buf)

outputPdu, err := Decode(buf)

if err != nil {
t.FailNow()
}

orig := fmt.Sprintf("%#v", p)
decode := fmt.Sprintf("%#v", outputPdu)
if orig != decode {
t.Fatalf("%s\n is not\n%s", orig, decode)
t.FailNow()
}
}
Loading

0 comments on commit cb54b62

Please sign in to comment.