mirror of
https://github.com/fosrl/olm.git
synced 2026-03-05 02:06:48 +00:00
@@ -41,6 +41,7 @@ type IPv6Route struct {
|
|||||||
var (
|
var (
|
||||||
networkSettings NetworkSettings
|
networkSettings NetworkSettings
|
||||||
networkSettingsMutex sync.RWMutex
|
networkSettingsMutex sync.RWMutex
|
||||||
|
incrementor int
|
||||||
)
|
)
|
||||||
|
|
||||||
// SetTunnelRemoteAddress sets the tunnel remote address
|
// SetTunnelRemoteAddress sets the tunnel remote address
|
||||||
@@ -48,6 +49,7 @@ func SetTunnelRemoteAddress(address string) {
|
|||||||
networkSettingsMutex.Lock()
|
networkSettingsMutex.Lock()
|
||||||
defer networkSettingsMutex.Unlock()
|
defer networkSettingsMutex.Unlock()
|
||||||
networkSettings.TunnelRemoteAddress = address
|
networkSettings.TunnelRemoteAddress = address
|
||||||
|
incrementor++
|
||||||
logger.Info("Set tunnel remote address: %s", address)
|
logger.Info("Set tunnel remote address: %s", address)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,6 +58,7 @@ func SetMTU(mtu int) {
|
|||||||
networkSettingsMutex.Lock()
|
networkSettingsMutex.Lock()
|
||||||
defer networkSettingsMutex.Unlock()
|
defer networkSettingsMutex.Unlock()
|
||||||
networkSettings.MTU = &mtu
|
networkSettings.MTU = &mtu
|
||||||
|
incrementor++
|
||||||
logger.Info("Set MTU: %d", mtu)
|
logger.Info("Set MTU: %d", mtu)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,6 +67,7 @@ func SetDNSServers(servers []string) {
|
|||||||
networkSettingsMutex.Lock()
|
networkSettingsMutex.Lock()
|
||||||
defer networkSettingsMutex.Unlock()
|
defer networkSettingsMutex.Unlock()
|
||||||
networkSettings.DNSServers = servers
|
networkSettings.DNSServers = servers
|
||||||
|
incrementor++
|
||||||
logger.Info("Set DNS servers: %v", servers)
|
logger.Info("Set DNS servers: %v", servers)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,6 +77,7 @@ func SetIPv4Settings(addresses []string, subnetMasks []string) {
|
|||||||
defer networkSettingsMutex.Unlock()
|
defer networkSettingsMutex.Unlock()
|
||||||
networkSettings.IPv4Addresses = addresses
|
networkSettings.IPv4Addresses = addresses
|
||||||
networkSettings.IPv4SubnetMasks = subnetMasks
|
networkSettings.IPv4SubnetMasks = subnetMasks
|
||||||
|
incrementor++
|
||||||
logger.Info("Set IPv4 addresses: %v, subnet masks: %v", addresses, subnetMasks)
|
logger.Info("Set IPv4 addresses: %v, subnet masks: %v", addresses, subnetMasks)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,6 +86,7 @@ func SetIPv4IncludedRoutes(routes []IPv4Route) {
|
|||||||
networkSettingsMutex.Lock()
|
networkSettingsMutex.Lock()
|
||||||
defer networkSettingsMutex.Unlock()
|
defer networkSettingsMutex.Unlock()
|
||||||
networkSettings.IPv4IncludedRoutes = routes
|
networkSettings.IPv4IncludedRoutes = routes
|
||||||
|
incrementor++
|
||||||
logger.Info("Set IPv4 included routes: %d routes", len(routes))
|
logger.Info("Set IPv4 included routes: %d routes", len(routes))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,6 +103,7 @@ func AddIPv4IncludedRoute(route IPv4Route) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
networkSettings.IPv4IncludedRoutes = append(networkSettings.IPv4IncludedRoutes, route)
|
networkSettings.IPv4IncludedRoutes = append(networkSettings.IPv4IncludedRoutes, route)
|
||||||
|
incrementor++
|
||||||
logger.Info("Added IPv4 included route: %+v", route)
|
logger.Info("Added IPv4 included route: %+v", route)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,6 +118,7 @@ func RemoveIPv4IncludedRoute(route IPv4Route) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
incrementor++
|
||||||
logger.Info("IPv4 included route not found for removal: %+v", route)
|
logger.Info("IPv4 included route not found for removal: %+v", route)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,6 +126,7 @@ func SetIPv4ExcludedRoutes(routes []IPv4Route) {
|
|||||||
networkSettingsMutex.Lock()
|
networkSettingsMutex.Lock()
|
||||||
defer networkSettingsMutex.Unlock()
|
defer networkSettingsMutex.Unlock()
|
||||||
networkSettings.IPv4ExcludedRoutes = routes
|
networkSettings.IPv4ExcludedRoutes = routes
|
||||||
|
incrementor++
|
||||||
logger.Info("Set IPv4 excluded routes: %d routes", len(routes))
|
logger.Info("Set IPv4 excluded routes: %d routes", len(routes))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,6 +136,7 @@ func SetIPv6Settings(addresses []string, networkPrefixes []string) {
|
|||||||
defer networkSettingsMutex.Unlock()
|
defer networkSettingsMutex.Unlock()
|
||||||
networkSettings.IPv6Addresses = addresses
|
networkSettings.IPv6Addresses = addresses
|
||||||
networkSettings.IPv6NetworkPrefixes = networkPrefixes
|
networkSettings.IPv6NetworkPrefixes = networkPrefixes
|
||||||
|
incrementor++
|
||||||
logger.Info("Set IPv6 addresses: %v, network prefixes: %v", addresses, networkPrefixes)
|
logger.Info("Set IPv6 addresses: %v, network prefixes: %v", addresses, networkPrefixes)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,6 +145,7 @@ func SetIPv6IncludedRoutes(routes []IPv6Route) {
|
|||||||
networkSettingsMutex.Lock()
|
networkSettingsMutex.Lock()
|
||||||
defer networkSettingsMutex.Unlock()
|
defer networkSettingsMutex.Unlock()
|
||||||
networkSettings.IPv6IncludedRoutes = routes
|
networkSettings.IPv6IncludedRoutes = routes
|
||||||
|
incrementor++
|
||||||
logger.Info("Set IPv6 included routes: %d routes", len(routes))
|
logger.Info("Set IPv6 included routes: %d routes", len(routes))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,6 +154,7 @@ func SetIPv6ExcludedRoutes(routes []IPv6Route) {
|
|||||||
networkSettingsMutex.Lock()
|
networkSettingsMutex.Lock()
|
||||||
defer networkSettingsMutex.Unlock()
|
defer networkSettingsMutex.Unlock()
|
||||||
networkSettings.IPv6ExcludedRoutes = routes
|
networkSettings.IPv6ExcludedRoutes = routes
|
||||||
|
incrementor++
|
||||||
logger.Info("Set IPv6 excluded routes: %d routes", len(routes))
|
logger.Info("Set IPv6 excluded routes: %d routes", len(routes))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,10 +163,11 @@ func ClearNetworkSettings() {
|
|||||||
networkSettingsMutex.Lock()
|
networkSettingsMutex.Lock()
|
||||||
defer networkSettingsMutex.Unlock()
|
defer networkSettingsMutex.Unlock()
|
||||||
networkSettings = NetworkSettings{}
|
networkSettings = NetworkSettings{}
|
||||||
|
incrementor++
|
||||||
logger.Info("Cleared all network settings")
|
logger.Info("Cleared all network settings")
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetNetworkSettingsJSON() (string, error) {
|
func GetJSON() (string, error) {
|
||||||
networkSettingsMutex.RLock()
|
networkSettingsMutex.RLock()
|
||||||
defer networkSettingsMutex.RUnlock()
|
defer networkSettingsMutex.RUnlock()
|
||||||
data, err := json.MarshalIndent(networkSettings, "", " ")
|
data, err := json.MarshalIndent(networkSettings, "", " ")
|
||||||
@@ -163,3 +176,9 @@ func GetNetworkSettingsJSON() (string, error) {
|
|||||||
}
|
}
|
||||||
return string(data), nil
|
return string(data), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetIncrementor() int {
|
||||||
|
networkSettingsMutex.Lock()
|
||||||
|
defer networkSettingsMutex.Unlock()
|
||||||
|
return incrementor
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/fosrl/newt/logger"
|
"github.com/fosrl/newt/logger"
|
||||||
|
"github.com/fosrl/olm/network"
|
||||||
"github.com/fosrl/olm/websocket"
|
"github.com/fosrl/olm/websocket"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -74,3 +75,11 @@ func keepSendingPing(olm *websocket.Client) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetNetworkSettingsJSON() (string, error) {
|
||||||
|
return network.GetJSON()
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetNetworkSettingsIncrementor() int {
|
||||||
|
return network.GetIncrementor()
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user