Skip to content

Commit

Permalink
Add length checks
Browse files Browse the repository at this point in the history
  • Loading branch information
job committed Jul 28, 2021
1 parent f82e338 commit 447cb2f
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion cmd/stayrtr/stayrtr.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"flag"
"fmt"
"io/ioutil"
"net"
"net/http"
"os"
"os/signal"
Expand Down Expand Up @@ -180,6 +181,16 @@ func decodeJSON(data []byte) (*prefixfile.VRPList, error) {
return &vrplistjson, err
}

func checkPrefixLengths(prefix *net.IPNet, maxLength uint8) (bool) {
plen, max := net.IPMask.Size(prefix.Mask)

if (uint8(plen) > maxLength || maxLength > uint8(max)) {
log.Errorf("%s Maxlength wrong: %d - %d", prefix, plen, maxLength)
return false
}
return true
}

func processData(vrplistjson []prefixfile.VRPJson) ([]rtr.VRP, int, int, int) {
filterDuplicates := make(map[string]bool)

Expand All @@ -200,12 +211,16 @@ func processData(vrplistjson []prefixfile.VRPJson) ([]rtr.VRP, int, int, int) {
continue
}

count++
if !checkPrefixLengths(prefix, v.Length) {
continue
}

if prefix.IP.To4() != nil {
countv4++
} else if prefix.IP.To16() != nil {
countv6++
}
count++

key := fmt.Sprintf("%s,%d,%d", prefix, asn, v.Length)
_, exists := filterDuplicates[key]
Expand Down

0 comments on commit 447cb2f

Please sign in to comment.