fix: multi issues - TUN read loop, SDWAN routing for TenantID=0, WS keepalive 10s
This commit is contained in:
@@ -12,13 +12,14 @@ import (
|
||||
)
|
||||
|
||||
type sdwanStore struct {
|
||||
mu sync.RWMutex
|
||||
path string
|
||||
cfg protocol.SDWANConfig
|
||||
mu sync.RWMutex
|
||||
path string
|
||||
cfg protocol.SDWANConfig
|
||||
multi map[int64]protocol.SDWANConfig
|
||||
}
|
||||
|
||||
func newSDWANStore(path string) *sdwanStore {
|
||||
s := &sdwanStore{path: path}
|
||||
s := &sdwanStore{path: path, multi: make(map[int64]protocol.SDWANConfig)}
|
||||
_ = s.load()
|
||||
return s
|
||||
}
|
||||
@@ -33,6 +34,15 @@ func (s *sdwanStore) load() error {
|
||||
}
|
||||
return err
|
||||
}
|
||||
// try multi-tenant first
|
||||
var m map[int64]protocol.SDWANConfig
|
||||
if err := json.Unmarshal(b, &m); err == nil && len(m) > 0 {
|
||||
for k, v := range m {
|
||||
m[k] = normalizeSDWAN(v)
|
||||
}
|
||||
s.multi = m
|
||||
return nil
|
||||
}
|
||||
var c protocol.SDWANConfig
|
||||
if err := json.Unmarshal(b, &c); err != nil {
|
||||
return err
|
||||
@@ -57,12 +67,40 @@ func (s *sdwanStore) save(cfg protocol.SDWANConfig) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *sdwanStore) saveTenant(tenantID int64, cfg protocol.SDWANConfig) error {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
cfg = normalizeSDWAN(cfg)
|
||||
cfg.UpdatedAt = time.Now().Unix()
|
||||
if s.multi == nil {
|
||||
s.multi = make(map[int64]protocol.SDWANConfig)
|
||||
}
|
||||
s.multi[tenantID] = cfg
|
||||
b, err := json.MarshalIndent(s.multi, "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := os.WriteFile(s.path, b, 0644); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *sdwanStore) get() protocol.SDWANConfig {
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
return s.cfg
|
||||
}
|
||||
|
||||
func (s *sdwanStore) getTenant(tenantID int64) protocol.SDWANConfig {
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
if s.multi == nil {
|
||||
return protocol.SDWANConfig{}
|
||||
}
|
||||
return s.multi[tenantID]
|
||||
}
|
||||
|
||||
func normalizeSDWAN(c protocol.SDWANConfig) protocol.SDWANConfig {
|
||||
if c.Mode == "" {
|
||||
c.Mode = "hub"
|
||||
|
||||
Reference in New Issue
Block a user