mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-12-01 23:01:36 +00:00
Reconfigure support for crypto-key routing
This commit is contained in:
parent
28072c9fe2
commit
bd04124e43
@ -45,25 +45,73 @@ func (c *cryptokey) init(core *Core) {
|
|||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case e := <-c.reconfigure:
|
case e := <-c.reconfigure:
|
||||||
e <- nil
|
e <- c.configure()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
if err := c.configure(); err != nil {
|
||||||
|
c.core.log.Println("CKR configuration failed:", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Configure the CKR routes
|
||||||
|
func (c *cryptokey) configure() error {
|
||||||
|
c.core.configMutex.RLock()
|
||||||
|
defer c.core.configMutex.RUnlock()
|
||||||
|
|
||||||
|
// Set enabled/disabled state
|
||||||
|
c.setEnabled(c.core.config.TunnelRouting.Enable)
|
||||||
|
|
||||||
|
// Clear out existing routes
|
||||||
c.mutexroutes.Lock()
|
c.mutexroutes.Lock()
|
||||||
c.ipv4routes = make([]cryptokey_route, 0)
|
|
||||||
c.ipv6routes = make([]cryptokey_route, 0)
|
c.ipv6routes = make([]cryptokey_route, 0)
|
||||||
|
c.ipv4routes = make([]cryptokey_route, 0)
|
||||||
c.mutexroutes.Unlock()
|
c.mutexroutes.Unlock()
|
||||||
|
|
||||||
|
// Add IPv6 routes
|
||||||
|
for ipv6, pubkey := range c.core.config.TunnelRouting.IPv6Destinations {
|
||||||
|
if err := c.addRoute(ipv6, pubkey); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add IPv4 routes
|
||||||
|
for ipv4, pubkey := range c.core.config.TunnelRouting.IPv4Destinations {
|
||||||
|
if err := c.addRoute(ipv4, pubkey); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear out existing sources
|
||||||
|
c.mutexsources.Lock()
|
||||||
|
c.ipv6sources = make([]net.IPNet, 0)
|
||||||
|
c.ipv4sources = make([]net.IPNet, 0)
|
||||||
|
c.mutexsources.Unlock()
|
||||||
|
|
||||||
|
// Add IPv6 sources
|
||||||
|
c.ipv6sources = make([]net.IPNet, 0)
|
||||||
|
for _, source := range c.core.config.TunnelRouting.IPv6Sources {
|
||||||
|
if err := c.addSourceSubnet(source); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add IPv4 sources
|
||||||
|
c.ipv4sources = make([]net.IPNet, 0)
|
||||||
|
for _, source := range c.core.config.TunnelRouting.IPv4Sources {
|
||||||
|
if err := c.addSourceSubnet(source); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wipe the caches
|
||||||
c.mutexcache.Lock()
|
c.mutexcache.Lock()
|
||||||
c.ipv4cache = make(map[address.Address]cryptokey_route, 0)
|
c.ipv4cache = make(map[address.Address]cryptokey_route, 0)
|
||||||
c.ipv6cache = make(map[address.Address]cryptokey_route, 0)
|
c.ipv6cache = make(map[address.Address]cryptokey_route, 0)
|
||||||
c.mutexcache.Unlock()
|
c.mutexcache.Unlock()
|
||||||
|
|
||||||
c.mutexsources.Lock()
|
return nil
|
||||||
c.ipv4sources = make([]net.IPNet, 0)
|
|
||||||
c.ipv6sources = make([]net.IPNet, 0)
|
|
||||||
c.mutexsources.Unlock()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enable or disable crypto-key routing.
|
// Enable or disable crypto-key routing.
|
||||||
|
@ -231,31 +231,6 @@ func (c *Core) Start(nc *config.NodeConfig, log *log.Logger) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
c.router.cryptokey.setEnabled(nc.TunnelRouting.Enable)
|
|
||||||
if c.router.cryptokey.isEnabled() {
|
|
||||||
c.log.Println("Crypto-key routing enabled")
|
|
||||||
for ipv6, pubkey := range nc.TunnelRouting.IPv6Destinations {
|
|
||||||
if err := c.router.cryptokey.addRoute(ipv6, pubkey); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for _, source := range nc.TunnelRouting.IPv6Sources {
|
|
||||||
if err := c.router.cryptokey.addSourceSubnet(source); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for ipv4, pubkey := range nc.TunnelRouting.IPv4Destinations {
|
|
||||||
if err := c.router.cryptokey.addRoute(ipv4, pubkey); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for _, source := range nc.TunnelRouting.IPv4Sources {
|
|
||||||
if err := c.router.cryptokey.addSourceSubnet(source); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := c.admin.start(); err != nil {
|
if err := c.admin.start(); err != nil {
|
||||||
c.log.Println("Failed to start admin socket")
|
c.log.Println("Failed to start admin socket")
|
||||||
return err
|
return err
|
||||||
|
@ -127,6 +127,14 @@ func (r *router) mainLoop() {
|
|||||||
case f := <-r.admin:
|
case f := <-r.admin:
|
||||||
f()
|
f()
|
||||||
case e := <-r.reconfigure:
|
case e := <-r.reconfigure:
|
||||||
|
// Send reconfigure notification to cryptokey
|
||||||
|
response := make(chan error)
|
||||||
|
r.cryptokey.reconfigure <- response
|
||||||
|
if err := <-response; err != nil {
|
||||||
|
e <- err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Anything else to do?
|
||||||
e <- nil
|
e <- nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user