Auto-configure device tunnel name, remove from daemon.yml
This commit is contained in:
parent
6c8d37a054
commit
9545f77cce
@ -6,6 +6,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"isle/bootstrap"
|
"isle/bootstrap"
|
||||||
"isle/daemon/daecommon"
|
"isle/daemon/daecommon"
|
||||||
|
"isle/nebula"
|
||||||
"isle/toolkit"
|
"isle/toolkit"
|
||||||
"net"
|
"net"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -116,7 +117,7 @@ func nebulaConfig(
|
|||||||
"respond": true,
|
"respond": true,
|
||||||
},
|
},
|
||||||
"tun": map[string]any{
|
"tun": map[string]any{
|
||||||
"dev": networkConfig.VPN.Tun.Device,
|
"dev": nebula.GetDeviceName(hostBootstrap.NetworkCreationParams.ID),
|
||||||
},
|
},
|
||||||
"firewall": firewall,
|
"firewall": firewall,
|
||||||
}
|
}
|
||||||
|
@ -24,10 +24,6 @@ const (
|
|||||||
//go:embed daemon.yml
|
//go:embed daemon.yml
|
||||||
var defaultConfigB []byte
|
var defaultConfigB []byte
|
||||||
|
|
||||||
type ConfigTun struct {
|
|
||||||
Device string `yaml:"device"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ConfigFirewall struct {
|
type ConfigFirewall struct {
|
||||||
Outbound []ConfigFirewallRule `yaml:"outbound"`
|
Outbound []ConfigFirewallRule `yaml:"outbound"`
|
||||||
Inbound []ConfigFirewallRule `yaml:"inbound"`
|
Inbound []ConfigFirewallRule `yaml:"inbound"`
|
||||||
@ -74,7 +70,6 @@ type NetworkConfig struct {
|
|||||||
VPN struct {
|
VPN struct {
|
||||||
PublicAddr string `yaml:"public_addr"`
|
PublicAddr string `yaml:"public_addr"`
|
||||||
Firewall ConfigFirewall `yaml:"firewall"`
|
Firewall ConfigFirewall `yaml:"firewall"`
|
||||||
Tun ConfigTun `yaml:"tun"`
|
|
||||||
} `yaml:"vpn"`
|
} `yaml:"vpn"`
|
||||||
Storage struct {
|
Storage struct {
|
||||||
Allocations []ConfigStorageAllocation `yaml:"allocations"`
|
Allocations []ConfigStorageAllocation `yaml:"allocations"`
|
||||||
@ -121,12 +116,6 @@ func (c *NetworkConfig) fillDefaults() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.VPN.Tun.Device == "" {
|
|
||||||
// TODO if there are multiple Networks then each one needs a unique
|
|
||||||
// device name.
|
|
||||||
c.VPN.Tun.Device = "isle-tun"
|
|
||||||
}
|
|
||||||
|
|
||||||
nextRPCPort := 3900
|
nextRPCPort := 3900
|
||||||
|
|
||||||
for i := range c.Storage.Allocations {
|
for i := range c.Storage.Allocations {
|
||||||
|
@ -47,10 +47,6 @@
|
|||||||
# # If any storage allocations are declared below, the ports used will be
|
# # If any storage allocations are declared below, the ports used will be
|
||||||
# # allowed here automatically.
|
# # allowed here automatically.
|
||||||
|
|
||||||
#tun:
|
|
||||||
# Name of the tun network device which will route VPN traffic.
|
|
||||||
#device: isle-tun
|
|
||||||
|
|
||||||
#storage:
|
#storage:
|
||||||
|
|
||||||
# Allocations defined here are used to store data in the distributed storage
|
# Allocations defined here are used to store data in the distributed storage
|
||||||
|
@ -127,7 +127,7 @@ func TestNew(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
networkConfigB = daecommon.NewNetworkConfig(func(c *daecommon.NetworkConfig) {
|
networkConfigB = daecommon.NewNetworkConfig(func(c *daecommon.NetworkConfig) {
|
||||||
c.VPN.Tun.Device = "bar"
|
c.VPN.PublicAddr = "1.2.3.4:5"
|
||||||
})
|
})
|
||||||
|
|
||||||
networkConfigC = daecommon.NewNetworkConfig(func(c *daecommon.NetworkConfig) {
|
networkConfigC = daecommon.NewNetworkConfig(func(c *daecommon.NetworkConfig) {
|
||||||
@ -189,7 +189,7 @@ func TestDaemon_SetConfig(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
networkConfig = daecommon.NewNetworkConfig(func(c *daecommon.NetworkConfig) {
|
networkConfig = daecommon.NewNetworkConfig(func(c *daecommon.NetworkConfig) {
|
||||||
c.VPN.Tun.Device = "foo"
|
c.VPN.PublicAddr = "1.2.3.4:5"
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -220,7 +220,7 @@ func TestDaemon_SetConfig(t *testing.T) {
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
networkConfig.VPN.Tun.Device = "foo"
|
networkConfig.VPN.PublicAddr = "1.2.3.4:5"
|
||||||
err := h.daemon.SetConfig(h.ctx, networkConfig)
|
err := h.daemon.SetConfig(h.ctx, networkConfig)
|
||||||
assert.ErrorIs(t, err, ErrManagedNetworkConfig)
|
assert.ErrorIs(t, err, ErrManagedNetworkConfig)
|
||||||
})
|
})
|
||||||
|
@ -32,7 +32,6 @@ var (
|
|||||||
|
|
||||||
ipNetCounter uint64 = 0
|
ipNetCounter uint64 = 0
|
||||||
publicAddrPortCounter uint64 = 1024
|
publicAddrPortCounter uint64 = 1024
|
||||||
tunDeviceCounter uint64 = 0
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func newIPNet() nebula.IPNet {
|
func newIPNet() nebula.IPNet {
|
||||||
@ -56,10 +55,6 @@ func newPublicAddr() string {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTunDevice() string {
|
|
||||||
return fmt.Sprintf("isle-test-%d", atomic.AddUint64(&tunDeviceCounter, 1))
|
|
||||||
}
|
|
||||||
|
|
||||||
type integrationHarness struct {
|
type integrationHarness struct {
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
logger *mlog.Logger
|
logger *mlog.Logger
|
||||||
@ -129,8 +124,6 @@ func (h *integrationHarness) mkNetworkConfig(
|
|||||||
c.VPN.PublicAddr = newPublicAddr()
|
c.VPN.PublicAddr = newPublicAddr()
|
||||||
}
|
}
|
||||||
|
|
||||||
c.VPN.Tun.Device = newTunDevice()
|
|
||||||
|
|
||||||
c.Storage.Allocations = make(
|
c.Storage.Allocations = make(
|
||||||
[]daecommon.ConfigStorageAllocation, opts.numStorageAllocs,
|
[]daecommon.ConfigStorageAllocation, opts.numStorageAllocs,
|
||||||
)
|
)
|
||||||
|
18
go/nebula/device.go
Normal file
18
go/nebula/device.go
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package nebula
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"sync/atomic"
|
||||||
|
)
|
||||||
|
|
||||||
|
var deviceCounter = new(atomic.Uint64)
|
||||||
|
|
||||||
|
// GetDeviceName returns the network device name to use for a particular
|
||||||
|
// network. Each returns name is gauranteed to be unique for the lifetime of the
|
||||||
|
// process.
|
||||||
|
func GetDeviceName(networkID string) string {
|
||||||
|
i := deviceCounter.Add(1) - 1
|
||||||
|
// the returned string will be too long for linux, but it will get
|
||||||
|
// automatically truncated.
|
||||||
|
return fmt.Sprintf("isle%d-%s", i, networkID)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user