@@ -38,6 +38,10 @@ const (
38
38
METHOD_NONE = iota
39
39
METHOD_PASSWORD
40
40
METHOD_KEY
41
+
42
+ USE_SERIAL_DISABLE = iota
43
+ USE_SERIAL_START
44
+ USE_SERIAL_FULL
41
45
)
42
46
43
47
var (
78
82
Verify = flag .Bool ("verify" , true , "Check signature using provided public key (disable by passing -verify=false)" )
79
83
PublicKey = flag .String ("verify.key" , "cf.pub" , "Public key path (PEM file)" )
80
84
81
- CacheBin = flag .String ("cache" , "https://rpki.cloudflare.com/rpki.json" , "URL of the cached JSON data" )
85
+ CacheBin = flag .String ("cache" , "https://rpki.cloudflare.com/rpki.json" , "URL of the cached JSON data" )
86
+ UseSerial = flag .String ("useserial" , "disable" , "Use serial contained in file (disable, startup, full)" )
87
+
82
88
Etag = flag .Bool ("etag" , true , "Enable Etag header" )
83
89
UserAgent = flag .String ("useragent" , fmt .Sprintf ("Cloudflare-%v (+https://github.com/cloudflare/gortr)" , AppVersion ), "User-Agent header" )
84
90
RefreshInterval = flag .Int ("refresh" , 600 , "Refresh interval in seconds" )
@@ -143,6 +149,11 @@ var (
143
149
"password" : METHOD_PASSWORD ,
144
150
//"key": METHOD_KEY,
145
151
}
152
+ serialToId = map [string ]int {
153
+ "disable" : USE_SERIAL_DISABLE ,
154
+ "startup" : USE_SERIAL_START ,
155
+ "full" : USE_SERIAL_FULL ,
156
+ }
146
157
)
147
158
148
159
func initMetrics () {
@@ -331,6 +342,8 @@ func (e IdenticalEtag) Error() string {
331
342
}
332
343
333
344
func (s * state ) updateFile (file string ) error {
345
+ sessid , _ := s .server .GetSessionId (nil )
346
+
334
347
log .Debugf ("Refreshing cache from %s" , file )
335
348
336
349
s .lastts = time .Now ().UTC ()
@@ -354,6 +367,14 @@ func (s *state) updateFile(file string) error {
354
367
return err
355
368
}
356
369
370
+ if s .useSerial == USE_SERIAL_START || s .useSerial == USE_SERIAL_FULL {
371
+ //if serial, _ := s.server.GetCurrentSerial(sessid); roalistjson.Metadata.Serial != 0 && serial != roalistjson.Metadata.Serial {
372
+ if _ , valid := s .server .GetCurrentSerial (sessid ); ! valid || s .useSerial == USE_SERIAL_FULL {
373
+ // Set serial at beginning
374
+ s .server .SetSerial (uint32 (roalistjson .Metadata .Serial ))
375
+ }
376
+ }
377
+
357
378
if s .checktime {
358
379
validtime := time .Unix (int64 (roalistjson .Metadata .Valid ), 0 ).UTC ()
359
380
if time .Now ().UTC ().After (validtime ) {
@@ -383,12 +404,32 @@ func (s *state) updateFile(file string) error {
383
404
log .Infof ("Slurm filtering: %v kept, %v removed, %v asserted" , len (kept ), len (removed ), len (asserted ))
384
405
roasjson = append (kept , asserted ... )
385
406
}
407
+
408
+ roas , count , countv4 , countv6 := processData (roasjson )
409
+ if err != nil {
410
+ return err
411
+ }
412
+
413
+ log .Infof ("New update (%v uniques, %v total prefixes). %v bytes. Updating sha256 hash %x -> %x" ,
414
+ len (roas ), count , len (s .lastconverted ), s .lasthash , hsum )
415
+ s .lasthash = hsum
416
+
417
+ s .server .AddROAs (roas )
418
+
419
+ serial , _ := s .server .GetCurrentSerial (sessid )
420
+ log .Infof ("Updated added, new serial %v" , serial )
421
+ if s .sendNotifs {
422
+ log .Debugf ("Sending notifications to clients" )
423
+ s .server .NotifyClientsLatest ()
424
+ }
425
+
386
426
s .lockJson .Lock ()
387
427
s .exported = prefixfile.ROAList {
388
428
Metadata : prefixfile.MetaData {
389
429
Counts : len (roasjson ),
390
430
Generated : roalistjson .Metadata .Generated ,
391
431
Valid : roalistjson .Metadata .Valid ,
432
+ Serial : int (serial ),
392
433
/*Signature: roalistjson.Metadata.Signature,
393
434
SignatureDate: roalistjson.Metadata.SignatureDate,*/
394
435
},
@@ -406,25 +447,6 @@ func (s *state) updateFile(file string) error {
406
447
407
448
s .lockJson .Unlock ()
408
449
409
- roas , count , countv4 , countv6 := processData (roasjson )
410
- if err != nil {
411
- return err
412
- }
413
-
414
- log .Infof ("New update (%v uniques, %v total prefixes). %v bytes. Updating sha256 hash %x -> %x" ,
415
- len (roas ), count , len (s .lastconverted ), s .lasthash , hsum )
416
- s .lasthash = hsum
417
-
418
- s .server .AddROAs (roas )
419
-
420
- sessid , _ := s .server .GetSessionId (nil )
421
- serial , _ := s .server .GetCurrentSerial (sessid )
422
- log .Infof ("Updated added, new serial %v" , serial )
423
- if s .sendNotifs {
424
- log .Debugf ("Sending notifications to clients" )
425
- s .server .NotifyClientsLatest ()
426
- }
427
-
428
450
if s .metricsEvent != nil {
429
451
var countv4_dup int
430
452
var countv6_dup int
@@ -516,6 +538,7 @@ type state struct {
516
538
userAgent string
517
539
etags map [string ]string
518
540
enableEtags bool
541
+ useSerial int
519
542
520
543
server * rtr.Server
521
544
@@ -655,6 +678,14 @@ func main() {
655
678
lockJson : & sync.RWMutex {},
656
679
}
657
680
681
+ if serialId , ok := serialToId [* UseSerial ]; ok {
682
+ s .useSerial = serialId
683
+ } else {
684
+ log .Fatalf ("Serial configuration %s is unknown" , * UseSerial )
685
+ }
686
+
687
+ server .SetManualSerial (s .useSerial == USE_SERIAL_FULL )
688
+
658
689
if * ExportSign != "" {
659
690
keyFile , err := os .Open (* ExportSign )
660
691
if err != nil {
@@ -683,6 +714,38 @@ func main() {
683
714
log .Fatalf ("Specify at least a bind address" )
684
715
}
685
716
717
+ err := s .updateFile (* CacheBin )
718
+ if err != nil {
719
+ switch err .(type ) {
720
+ case HttpNotModified :
721
+ log .Info (err )
722
+ case IdenticalFile :
723
+ log .Info (err )
724
+ case IdenticalEtag :
725
+ log .Info (err )
726
+ default :
727
+ log .Errorf ("Error updating: %v" , err )
728
+ }
729
+ }
730
+
731
+ slurmFile := * Slurm
732
+ if slurmFile != "" {
733
+ err := s .updateSlurm (slurmFile )
734
+ if err != nil {
735
+ switch err .(type ) {
736
+ case HttpNotModified :
737
+ log .Info (err )
738
+ case IdenticalEtag :
739
+ log .Info (err )
740
+ default :
741
+ log .Errorf ("Slurm: %v" , err )
742
+ }
743
+ }
744
+ if ! * SlurmRefresh {
745
+ slurmFile = ""
746
+ }
747
+ }
748
+
686
749
if * Bind != "" {
687
750
go func () {
688
751
sessid , _ := server .GetSessionId (nil )
@@ -795,37 +858,6 @@ func main() {
795
858
}()
796
859
}
797
860
798
- slurmFile := * Slurm
799
- if slurmFile != "" {
800
- err := s .updateSlurm (slurmFile )
801
- if err != nil {
802
- switch err .(type ) {
803
- case HttpNotModified :
804
- log .Info (err )
805
- case IdenticalEtag :
806
- log .Info (err )
807
- default :
808
- log .Errorf ("Slurm: %v" , err )
809
- }
810
- }
811
- if ! * SlurmRefresh {
812
- slurmFile = ""
813
- }
814
- }
815
-
816
- err := s .updateFile (* CacheBin )
817
- if err != nil {
818
- switch err .(type ) {
819
- case HttpNotModified :
820
- log .Info (err )
821
- case IdenticalFile :
822
- log .Info (err )
823
- case IdenticalEtag :
824
- log .Info (err )
825
- default :
826
- log .Errorf ("Error updating: %v" , err )
827
- }
828
- }
829
861
s .routineUpdate (* CacheBin , * RefreshInterval , slurmFile )
830
862
831
863
}
0 commit comments