diff --git a/lg.go b/lg.go index cbf6b1b..20d753f 100644 --- a/lg.go +++ b/lg.go @@ -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 { @@ -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 } @@ -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 } diff --git a/prefixes.go b/prefixes.go index fc28f63..599969f 100644 --- a/prefixes.go +++ b/prefixes.go @@ -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{ diff --git a/upstreams.go b/upstreams.go index 8f602bf..63fe3ea 100644 --- a/upstreams.go +++ b/upstreams.go @@ -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" @@ -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) }