Skip to content

Commit

Permalink
draft
Browse files Browse the repository at this point in the history
  • Loading branch information
ezrizhu committed Aug 17, 2024
1 parent 26e4707 commit c25e36e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 34 deletions.
37 changes: 22 additions & 15 deletions lg.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,6 @@ func (p *Prefix) checkLGState() {
availableStr = "n"
}

var UFMGOrigin bool
if p.origin == 61574 {
UFMGOrigin = true
}

if p.origin == 13335 {
return
}

origin := strconv.Itoa(p.origin)

for _, rrc := range ripeStatLookingGlassResp.Data.Rrcs {
Expand All @@ -96,20 +87,35 @@ func (p *Prefix) checkLGState() {
upstream := ""
upstream2 := ""
offset := 2
if UFMGOrigin {
offset += 2
}
if len(asPathSplit) < offset+1 {
return
}
upstream = asPathSplit[len(asPathSplit)-offset]
pos := 0
for i, asn := range asPathSplit {
if asn == origin {
pos = i - 1
}
if pos < 0 {
return
}
}
if pos == 0 {
log.Info().
Str("prefix", p.prefix).
Str("asPath", peer.AsPath).
Str("expected origin", origin).
Msg("correct origin not found, hijack possible")
possibleHijack.Inc()
return
}
upstream = asPathSplit[pos]
if err != nil {
log.Error().Err(err).Msg("atoi fail")
return
}
matched := false
for _, dbUpstream := range dbUpstreams {
if dbUpstream.name == upstream {
if strconv.Itoa(dbUpstream.asn) == upstream {
matched = true
break
}
Expand All @@ -119,7 +125,8 @@ func (p *Prefix) checkLGState() {
Str("prefix", p.prefix).
Str("upstream", upstream).
Str("path", peer.AsPath).
Msg("upstream mismatch, hijack possible")
Int("pos", pos).
Msg("expected upstream not found, hijack possible")
possibleHijack.Inc()
return
}
Expand Down
38 changes: 20 additions & 18 deletions prefixes.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,30 @@ type Prefix struct {
}

type Upstream struct {
asn string
name string
asn int
}

var dbUpstreams = []Upstream{
Upstream{"Northeastern University", "156"},
Upstream{"FABRIC Testbed", "398900"},
Upstream{"GRNet", "5408"},
Upstream{"Bit BV", "12859"},
Upstream{"Netwerkvereniging Coloclue", "8283"},
Upstream{"Stony Brook University", "5719"},
Upstream{"Clemson University", "12148"},
Upstream{"Utah Education Network", "210"},
Upstream{"Georgia Institute of Technology", "2637"},
Upstream{"University of Wisconsin - Madison", "3128"},
Upstream{"Rede Nacional de Ensino e Pesquisa (RNP)", "1916"},
Upstream{"Cornell University", "26"},
Upstream{"psg.com RGNet", "3130"},
Upstream{"Los Nettos Regional Network", "226"},
Upstream{"UW at PNW GigaPoP", "101"},
Upstream{"vultr", "20473"},
Upstream{"HE", "6939"},
Upstream{"Northeastern University", 156},
Upstream{"FABRIC Testbed", 398900},
Upstream{"GRNet", 5408},
Upstream{"Bit BV", 12859},
Upstream{"Netwerkvereniging Coloclue", 8283},
Upstream{"Stony Brook University", 5719},
Upstream{"Clemson University", 12148},
Upstream{"Utah Education Network", 210},
Upstream{"Georgia Institute of Technology", 2637},
Upstream{"University of Wisconsin - Madison", 3128},
Upstream{"Rede Nacional de Ensino e Pesquisa (RNP)", 1916},
Upstream{"Cornell University", 26},
Upstream{"psg.com RGNet", 3130},
Upstream{"Los Nettos Regional Network", 226},
Upstream{"UW at PNW GigaPoP", 101},
Upstream{"vultr", 20473},
Upstream{"HE", 6939},
Upstream{"PEERING", 47065},
Upstream{"1299 cf", 1299},
}

var monitorState = []Prefix{
Expand Down
4 changes: 3 additions & 1 deletion upstreams.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package main

import (
"strconv"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/rs/zerolog/log"
Expand All @@ -17,7 +19,7 @@ func setUpstreamGauge() {
log.Trace().Msg("setting upstreeams gauge")
for _, dbUpstream := range dbUpstreams {
upstreamGauge.WithLabelValues(
dbUpstream.asn,
strconv.Itoa(dbUpstream.asn),
dbUpstream.name,
).Set(1)
}
Expand Down

0 comments on commit c25e36e

Please sign in to comment.