From 1e5b05f1008f21af02a9c40563cc993717aa185f Mon Sep 17 00:00:00 2001 From: Literally Nobody Ever Date: Fri, 27 Feb 2026 05:01:51 +0000 Subject: [PATCH 1/2] go fmt ci/cd check because this is annoying --- .github/workflows/go.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index f87644f..c98a50d 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -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: From fb8d7358604188de48ffc731c827015abbd446fe Mon Sep 17 00:00:00 2001 From: Literally Nobody Ever Date: Fri, 27 Feb 2026 05:04:42 +0000 Subject: [PATCH 2/2] Fix go formatting stuff --- cmd/rtrdump/rtrdump.go | 2 +- cmd/rtrmon/rtrmon.go | 6 +++--- lib/server.go | 43 ++++++++++++++++++++-------------------- lib/server_test.go | 4 ++-- ossec/constrain.go | 1 + prefixfile/prefixfile.go | 24 +++++++++++----------- prefixfile/slurm.go | 2 +- 7 files changed, 41 insertions(+), 41 deletions(-) diff --git a/cmd/rtrdump/rtrdump.go b/cmd/rtrdump/rtrdump.go index 136673c..1e959d0 100644 --- a/cmd/rtrdump/rtrdump.go +++ b/cmd/rtrdump/rtrdump.go @@ -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), diff --git a/cmd/rtrmon/rtrmon.go b/cmd/rtrmon/rtrmon.go index fdc7674..6598e70 100644 --- a/cmd/rtrmon/rtrmon.go +++ b/cmd/rtrmon/rtrmon.go @@ -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() diff --git a/lib/server.go b/lib/server.go index 225fd54..3e9a8ac 100644 --- a/lib/server.go +++ b/lib/server.go @@ -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" @@ -162,8 +162,8 @@ type ServerConfiguration struct { SessId int - DisableBGPSec bool - EnableNODELAY bool + DisableBGPSec bool + EnableNODELAY bool RefreshInterval uint32 RetryInterval uint32 @@ -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) @@ -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, @@ -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 } @@ -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) } @@ -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 @@ -825,7 +825,6 @@ func (c *Client) readLoop(ctx context.Context) error { } } - func (c *Client) Start() { defer c.tcpconn.Close() diff --git a/lib/server_test.go b/lib/server_test.go index 78b8c63..7842511 100644 --- a/lib/server_test.go +++ b/lib/server_test.go @@ -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, } diff --git a/ossec/constrain.go b/ossec/constrain.go index 7f60f59..b5db567 100644 --- a/ossec/constrain.go +++ b/ossec/constrain.go @@ -1,3 +1,4 @@ +//go:build !openbsd // +build !openbsd package ossec diff --git a/prefixfile/prefixfile.go b/prefixfile/prefixfile.go index 63bc6b6..5f0a2a9 100644 --- a/prefixfile/prefixfile.go +++ b/prefixfile/prefixfile.go @@ -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 { @@ -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== diff --git a/prefixfile/slurm.go b/prefixfile/slurm.go index 8d85700..c4e1522 100644 --- a/prefixfile/slurm.go +++ b/prefixfile/slurm.go @@ -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 } }