Skip to content

Commit

Permalink
return logic fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ezrizhu committed Oct 31, 2024
1 parent cc834a4 commit a477976
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
17 changes: 9 additions & 8 deletions lg.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ func (p *Prefix) checkLGState() {
upstream2 := ""
offset := 2
if len(asPathSplit) < offset+1 {
return
continue
}
pos := 0
for i, asn := range asPathSplit {
if asn == origin {
pos = i - 1
}
if pos < 0 {
return
continue
}
}
if pos == 0 {
Expand All @@ -106,12 +106,12 @@ func (p *Prefix) checkLGState() {
Str("expected origin", origin).
Msg("correct origin not found, hijack possible")
possibleHijack.Inc()
return
continue
}
upstream = asPathSplit[pos]
if err != nil {
log.Error().Err(err).Msg("atoi fail")
return
continue
}
matched := false
for _, dbUpstream := range dbUpstreams {
Expand All @@ -121,27 +121,28 @@ func (p *Prefix) checkLGState() {
}
}
if !matched {
log.Info().
//change this back to info after stabalizes
log.Debug().
Str("prefix", p.prefix).
Str("upstream", upstream).
Str("path", peer.AsPath).
Int("pos", pos).
Msg("expected upstream not found, hijack possible")
possibleHijack.Inc()
return
continue
}
if !slices.Contains(upstreams, upstream) {
upstreams = append(upstreams, upstream)
}

// second upstream
if len(asPathSplit) < offset+2 {
return
continue
}
upstream2 = asPathSplit[len(asPathSplit)-offset-1]
if err != nil {
log.Error().Err(err).Msg("atoi fail")
return
continue
}
if !slices.Contains(upstreams2, upstream2) {
upstreams2 = append(upstreams2, upstream2)
Expand Down
25 changes: 13 additions & 12 deletions prefixes.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,19 @@ var dbUpstreams = []Upstream{
}

var monitorState = []Prefix{

Prefix{prefix: "104.17.224.0/20", pop: "cf valid4", available: true, origin: 13335},
Prefix{prefix: "2606:4700::/44", pop: "cf valid6", available: true, origin: 13335},

Prefix{prefix: "103.21.244.0/24", pop: "cf invalid4", available: false, origin: 13335},
Prefix{prefix: "2606:4700:7000::/48", pop: "cf invalid6", available: false, origin: 13335},

Prefix{prefix: "1.1.1.0/24", pop: "cf dns 0", available: true, origin: 13335},
Prefix{prefix: "1.0.0.0/24", pop: "cf dns 1", available: true, origin: 13335},

Prefix{prefix: "198.8.58.0/24", pop: "ezri 0", available: true, origin: 206628},
Prefix{prefix: "198.8.59.0/24", pop: "ezri 1", available: true, origin: 206628},

Prefix{prefix: "184.164.250.0/24", pop: "rotate", available: true, origin: 47065},
Prefix{prefix: "184.164.251.0/24", pop: "rotate", available: true, origin: 47065},

Expand Down Expand Up @@ -391,16 +404,4 @@ var monitorState = []Prefix{
Prefix{prefix: "2804:269c:3d::/48", pop: "unknown", available: false, origin: 61574},
Prefix{prefix: "2804:269c:3e::/48", pop: "unknown", available: false, origin: 61574},
Prefix{prefix: "2804:269c:3f::/48", pop: "unknown", available: false, origin: 61574},

Prefix{prefix: "104.17.224.0/20", pop: "cf valid4", available: true, origin: 13335},
Prefix{prefix: "2606:4700::/44", pop: "cf valid6", available: true, origin: 13335},

Prefix{prefix: "103.21.244.0/24", pop: "cf invalid4", available: false, origin: 13335},
Prefix{prefix: "2606:4700:7000::/48", pop: "cf invalid6", available: false, origin: 13335},

Prefix{prefix: "1.1.1.0/24", pop: "cf dns 0", available: true, origin: 13335},
Prefix{prefix: "1.0.0.0/24", pop: "cf dns 1", available: true, origin: 13335},

Prefix{prefix: "198.8.58.0/24", pop: "ezri 0", available: true, origin: 206628},
Prefix{prefix: "198.8.59.0/24", pop: "ezri 1", available: true, origin: 206628},
}

0 comments on commit a477976

Please sign in to comment.