Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ jobs:
with:
go-version-file: 'go.mod'

- name: Check formatting
run: |
# gofmt -l recursively checks all .go files when given a directory
unformatted=$(gofmt -l .)
if [ -n "$unformatted" ]; then
echo "The following files are not formatted correctly:"
echo "$unformatted"
echo ""
echo "Please run 'go fmt ./...' to fix formatting"
exit 1
fi

- id: govulncheck
uses: golang/govulncheck-action@v1
with:
Expand Down
2 changes: 1 addition & 1 deletion cmd/rtrdump/rtrdump.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func main() {
client := &Client{
Data: prefixfile.RPKIList{
Metadata: prefixfile.MetaData{},
ROA: make([]prefixfile.VRPJson, 0),
ROA: make([]prefixfile.VRPJson, 0),
},
InitSerial: *InitSerial,
Serial: uint32(*Serial),
Expand Down
6 changes: 3 additions & 3 deletions cmd/rtrmon/rtrmon.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,9 @@ func (c *Client) Start(id int, ch chan int) {

// Build the new vrpMap
// The result:
// * contains all the VRPs in newVRPs
// * keeps the firstSeen value for VRPs already in the old map
// * keeps elements around for GracePeriod after they are not in the input.
// - contains all the VRPs in newVRPs
// - keeps the firstSeen value for VRPs already in the old map
// - keeps elements around for GracePeriod after they are not in the input.
func BuildNewVrpMap(log *log.Entry, currentVrps VRPMap, pfxFile *prefixfile.RPKIList, now time.Time) (VRPMap, int) {
var newVrps = pfxFile.ROA
tCurrentUpdate := now.Unix()
Expand Down
43 changes: 21 additions & 22 deletions lib/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import (
"bytes"
"context"
"crypto/tls"
"encoding/json"
"encoding/json"
"fmt"
"io"
"math"
"math/rand"
"net"
"net/http"
"net/http"
"net/netip"
"sync"

Expand Down Expand Up @@ -162,8 +162,8 @@ type ServerConfiguration struct {

SessId int

DisableBGPSec bool
EnableNODELAY bool
DisableBGPSec bool
EnableNODELAY bool

RefreshInterval uint32
RetryInterval uint32
Expand All @@ -174,10 +174,10 @@ type ServerConfiguration struct {
}

func NewServer(configuration ServerConfiguration, handler RTRServerEventHandler, simpleHandler RTREventHandler) *Server {
sessids := make([]uint16, 0, int(configuration.ProtocolVersion) + 1)
sessids := make([]uint16, 0, int(configuration.ProtocolVersion)+1)
s := GenerateSessionId()
for i := 0; i <= int(configuration.ProtocolVersion); i++ {
sessids = append(sessids, s + uint16(100 * i))
sessids = append(sessids, s+uint16(100*i))
}

refreshInterval := uint32(3600)
Expand All @@ -194,26 +194,26 @@ func NewServer(configuration ServerConfiguration, handler RTRServerEventHandler,
}

return &Server{
sdlock: &sync.RWMutex{},
sdListDiff: make([][]SendableData, 0),
sdCurrent: make([]SendableData, 0),
keepDiff: configuration.KeepDifference,
sdlock: &sync.RWMutex{},
sdListDiff: make([][]SendableData, 0),
sdCurrent: make([]SendableData, 0),
keepDiff: configuration.KeepDifference,

clientlock: &sync.RWMutex{},
clients: make([]*Client, 0),
sessId: sessids,
maxconn: configuration.MaxConn,
baseVersion: configuration.ProtocolVersion,
clientlock: &sync.RWMutex{},
clients: make([]*Client, 0),
sessId: sessids,
maxconn: configuration.MaxConn,
baseVersion: configuration.ProtocolVersion,

enforceVersion: configuration.EnforceVersion,
disableBGPSec: configuration.DisableBGPSec,
disableBGPSec: configuration.DisableBGPSec,

pduRefreshInterval: refreshInterval,
pduRetryInterval: retryInterval,
pduExpireInterval: expireInterval,

handler: handler,
simpleHandler: simpleHandler,
handler: handler,
simpleHandler: simpleHandler,

log: configuration.Log,
logverbose: configuration.LogVerbose,
Expand Down Expand Up @@ -322,7 +322,7 @@ func (s *Server) getSDsSerialDiff(serial uint32) ([]SendableData, bool) {
return nil, false
}

sd := s.sdListDiff[len(s.sdListDiff) - diff]
sd := s.sdListDiff[len(s.sdListDiff)-diff]
return sd, true
}

Expand Down Expand Up @@ -374,7 +374,7 @@ func (s *Server) AddData(new []SendableData) bool {

func (s *Server) AddSDsDiff(diff []SendableData) {
s.sdlock.RLock()
nextDiff := make([][]SendableData, len(s.sdListDiff) + 1)
nextDiff := make([][]SendableData, len(s.sdListDiff)+1)
for i, prevSDs := range s.sdListDiff {
nextDiff[i] = ApplyDiff(diff, prevSDs)
}
Expand All @@ -387,7 +387,7 @@ func (s *Server) AddSDsDiff(diff []SendableData) {

nextDiff = append(nextDiff, diff)
if s.keepDiff > 0 && len(nextDiff) > s.keepDiff {
nextDiff = nextDiff[len(nextDiff) - s.keepDiff:]
nextDiff = nextDiff[len(nextDiff)-s.keepDiff:]
}

s.sdListDiff = nextDiff
Expand Down Expand Up @@ -825,7 +825,6 @@ func (c *Client) readLoop(ctx context.Context) error {
}
}


func (c *Client) Start() {
defer c.tcpconn.Close()

Expand Down
4 changes: 2 additions & 2 deletions lib/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (
func GenerateVrps(size uint32, offset uint32) []SendableData {
vrps := make([]SendableData, size)
for i := uint32(0); i < size; i++ {
ipFinal := i+offset
ipFinal := i + offset
vrps[i] = &VRP{
Prefix: netip.MustParsePrefix(fmt.Sprintf("fd00::%04x:%04x/128", ipFinal >> 16, ipFinal & 0xffff)),
Prefix: netip.MustParsePrefix(fmt.Sprintf("fd00::%04x:%04x/128", ipFinal>>16, ipFinal&0xffff)),
MaxLen: 128,
ASN: 64496,
}
Expand Down
1 change: 1 addition & 0 deletions ossec/constrain.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !openbsd
// +build !openbsd

package ossec
Expand Down
24 changes: 12 additions & 12 deletions prefixfile/prefixfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ import (
)

type RPKIList struct {
Metadata MetaData `json:"metadata,omitempty"`
ROA []VRPJson `json:"roas"` // for historical reasons this is called 'roas', but should've been called vrps
BgpSecKeys []BgpSecKeyJson `json:"bgpsec_keys,omitempty"`
Metadata MetaData `json:"metadata,omitempty"`
ROA []VRPJson `json:"roas"` // for historical reasons this is called 'roas', but should've been called vrps
BgpSecKeys []BgpSecKeyJson `json:"bgpsec_keys,omitempty"`
}

type MetaData struct {
Counts int `json:"vrps"`
CountBgpSecKeys int `json:"bgpsec_pubkeys"`
Buildtime string `json:"buildtime,omitempty"`
GeneratedUnix *int64 `json:"generated,omitempty"`
SessionID int `json:"sessionid,omitempty"`
Serial int `json:"serial"`
Counts int `json:"vrps"`
CountBgpSecKeys int `json:"bgpsec_pubkeys"`
Buildtime string `json:"buildtime,omitempty"`
GeneratedUnix *int64 `json:"generated,omitempty"`
SessionID int `json:"sessionid,omitempty"`
Serial int `json:"serial"`
}

type VRPJson struct {
Expand All @@ -32,9 +32,9 @@ type VRPJson struct {
}

type BgpSecKeyJson struct {
Asn uint32 `json:"asn"`
Expires *int64 `json:"expires,omitempty"`
Ta string `json:"ta,omitempty"`
Asn uint32 `json:"asn"`
Expires *int64 `json:"expires,omitempty"`
Ta string `json:"ta,omitempty"`

// Base64 encoded, but encoding/json handles this for us
// Example: MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE4FxJr0n2bux1uX1Evl+QWwZYvIadPjLuFX2mxqKuAGUhKnr7VLLDgrE++l9p5eH2kWTNVAN22FUU3db/RKpE2w==
Expand Down
2 changes: 1 addition & 1 deletion prefixfile/slurm.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (s *SlurmValidationOutputFilters) FilterOnVRPs(vrps []VRPJson) (added, remo
if match && fPrefix.IsValid() && rPrefix.IsValid() {

if !(fPrefix.Overlaps(rPrefix) &&
fPrefix.Bits() <= rPrefix.Bits()) {
fPrefix.Bits() <= rPrefix.Bits()) {
match = false
}
}
Expand Down
Loading