Skip to content

Commit

Permalink
autoygg-server: bugfix: on startup, make sure that Yggdrasil has the
Browse files Browse the repository at this point in the history
correct remote subnet configuration for all active client leases.
  • Loading branch information
cure committed Sep 14, 2020
1 parent 445b086 commit f1ab101
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions internal/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,36 @@ type configChange struct {

var configChanges []configChange

// loadLeases loads the valid leases from the database and makes sure that
// Yggdrasil has the correct remote subnets configured. loadLeases is called
// when autoygg-server starts up. It is not strictly necessary when
// autoygg-server is restarted, but it is required when Yggdrasil is restarted,
// e.g. after a reboot of the machine.
func loadLeases(db *gorm.DB) (err error) {
var registrations []registration

result := db.Model(&registration{}).Where("state = 'success' and lease_expires > ?", time.Now()).Find(&registrations)
if result.Error != nil {
err = result.Error
return
}
debug("Found %d valid leases to load\n", result.RowsAffected)

// These leases are still valid, make sure everything is configured properly
for _, r := range registrations {
r.State = "open"
if result := db.Save(&r); result.Error != nil {
incErrorCount("internal")
log.Println("Internal error, unable to execute query:", result.Error)
return
}
debug("re-enabling lease for registration %+v\n", r)
queueAddRemoteSubnet(db, r.ID)
}

return
}

func setup() {
log.Printf("Set up firewall rule Forwarding Out")
err := firewallRulesWorker("Up", "FirewallRuleForwardingOut")
Expand Down Expand Up @@ -870,6 +900,11 @@ func ServerMain() {

setup()

err := loadLeases(db)
if err != nil {
Fatal(err)
}

sig := make(chan os.Signal, 1)
signal.Notify(sig, os.Interrupt, syscall.SIGTERM)

Expand Down

0 comments on commit f1ab101

Please sign in to comment.