Fix configuration reloading support

This commit is contained in:
Neil Alexander 2019-05-17 22:29:52 +01:00
parent 71ccaf753e
commit ae2cc13d14
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944
4 changed files with 71 additions and 66 deletions

View file

@ -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