mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-29 14:45:07 +03:00
Fix configuration reloading support
This commit is contained in:
parent
71ccaf753e
commit
ae2cc13d14
4 changed files with 71 additions and 66 deletions
|
@ -148,6 +148,7 @@ func (tun *TunAdapter) Start() error {
|
|||
tun.mutex.Lock()
|
||||
tun.isOpen = true
|
||||
tun.send = make(chan []byte, 32) // TODO: is this a sensible value?
|
||||
tun.reconfigure = make(chan chan error)
|
||||
tun.mutex.Unlock()
|
||||
if iftapmode {
|
||||
go func() {
|
||||
|
@ -178,6 +179,37 @@ func (tun *TunAdapter) Start() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// UpdateConfig updates the TUN/TAP module with the provided config.NodeConfig
|
||||
// and then signals the various module goroutines to reconfigure themselves if
|
||||
// needed.
|
||||
func (tun *TunAdapter) UpdateConfig(config *config.NodeConfig) {
|
||||
tun.log.Debugln("Reloading TUN/TAP configuration...")
|
||||
|
||||
tun.config.Replace(*config)
|
||||
|
||||
errors := 0
|
||||
|
||||
components := []chan chan error{
|
||||
tun.reconfigure,
|
||||
tun.ckr.reconfigure,
|
||||
}
|
||||
|
||||
for _, component := range components {
|
||||
response := make(chan error)
|
||||
component <- response
|
||||
if err := <-response; err != nil {
|
||||
tun.log.Errorln(err)
|
||||
errors++
|
||||
}
|
||||
}
|
||||
|
||||
if errors > 0 {
|
||||
tun.log.Warnln(errors, "TUN/TAP module(s) reported errors during configuration reload")
|
||||
} else {
|
||||
tun.log.Infoln("TUN/TAP configuration reloaded successfully")
|
||||
}
|
||||
}
|
||||
|
||||
func (tun *TunAdapter) handler() error {
|
||||
for {
|
||||
// Accept the incoming connection
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue