Compare commits

...

2 Commits

6 changed files with 33 additions and 32 deletions

View File

@ -6,6 +6,7 @@ import (
"io"
"isle/bootstrap"
"isle/daemon/daecommon"
"isle/nebula"
"isle/toolkit"
"net"
"path/filepath"
@ -116,7 +117,7 @@ func nebulaConfig(
"respond": true,
},
"tun": map[string]any{
"dev": networkConfig.VPN.Tun.Device,
"dev": nebula.GetDeviceName(hostBootstrap.NetworkCreationParams.ID),
},
"firewall": firewall,
}

View File

@ -24,10 +24,6 @@ const (
//go:embed daemon.yml
var defaultConfigB []byte
type ConfigTun struct {
Device string `yaml:"device"`
}
type ConfigFirewall struct {
Outbound []ConfigFirewallRule `yaml:"outbound"`
Inbound []ConfigFirewallRule `yaml:"inbound"`
@ -74,7 +70,6 @@ type NetworkConfig struct {
VPN struct {
PublicAddr string `yaml:"public_addr"`
Firewall ConfigFirewall `yaml:"firewall"`
Tun ConfigTun `yaml:"tun"`
} `yaml:"vpn"`
Storage struct {
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
for i := range c.Storage.Allocations {

View File

@ -47,10 +47,6 @@
# # If any storage allocations are declared below, the ports used will be
# # allowed here automatically.
#tun:
# Name of the tun network device which will route VPN traffic.
#device: isle-tun
#storage:
# Allocations defined here are used to store data in the distributed storage

View File

@ -127,7 +127,7 @@ func TestNew(t *testing.T) {
})
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) {
@ -189,7 +189,7 @@ func TestDaemon_SetConfig(t *testing.T) {
})
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)
assert.ErrorIs(t, err, ErrManagedNetworkConfig)
})

View File

@ -30,16 +30,19 @@ var (
return filepath.Join(appDirPath, "bin")
})
ipNetCounter uint64 = 0
publicAddrPortCounter uint64 = 1024
tunDeviceCounter uint64 = 0
ipNetCounter = new(atomic.Uint64)
publicAddrPortCounter = func() *atomic.Uint64 {
i := new(atomic.Uint64)
i.Store(1024)
return i
}()
)
func newIPNet() nebula.IPNet {
var (
ipNet nebula.IPNet
ipNetStr = fmt.Sprintf(
"172.16.%d.0/24", atomic.AddUint64(&ipNetCounter, 1),
"172.16.%d.0/24", ipNetCounter.Add(1)-1,
)
)
@ -52,19 +55,15 @@ func newIPNet() nebula.IPNet {
func newPublicAddr() string {
return fmt.Sprintf(
"127.0.0.200:%d", atomic.AddUint64(&publicAddrPortCounter, 1),
"127.0.0.200:%d", publicAddrPortCounter.Add(1)-1,
)
}
func newTunDevice() string {
return fmt.Sprintf("isle-test-%d", atomic.AddUint64(&tunDeviceCounter, 1))
}
type integrationHarness struct {
ctx context.Context
logger *mlog.Logger
rootDir toolkit.Dir
dirCounter uint64
dirCounter atomic.Uint64
}
func newIntegrationHarness(t *testing.T) *integrationHarness {
@ -94,7 +93,7 @@ func newIntegrationHarness(t *testing.T) *integrationHarness {
}
func (h *integrationHarness) mkDir(t *testing.T, name string) toolkit.Dir {
fullName := fmt.Sprintf("%s-%d", name, atomic.AddUint64(&h.dirCounter, 1))
fullName := fmt.Sprintf("%s-%d", name, h.dirCounter.Add(1)-1)
t.Logf("Creating directory %q", fullName)
d, err := h.rootDir.MkChildDir(fullName, false)
@ -129,8 +128,6 @@ func (h *integrationHarness) mkNetworkConfig(
c.VPN.PublicAddr = newPublicAddr()
}
c.VPN.Tun.Device = newTunDevice()
c.Storage.Allocations = make(
[]daecommon.ConfigStorageAllocation, opts.numStorageAllocs,
)

18
go/nebula/device.go Normal file
View 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)
}