mirror of
https://github.com/fosrl/olm.git
synced 2026-10-23 13:09:08 +02:00
add PreferLocalRoutes option
This commit is contained in:
@@ -47,11 +47,12 @@ type OlmConfig struct {
|
|||||||
PingTimeout string `json:"pingTimeout"`
|
PingTimeout string `json:"pingTimeout"`
|
||||||
|
|
||||||
// Advanced
|
// Advanced
|
||||||
DisableHolepunch bool `json:"disableHolepunch"`
|
DisableHolepunch bool `json:"disableHolepunch"`
|
||||||
TlsClientCert string `json:"tlsClientCert"`
|
TlsClientCert string `json:"tlsClientCert"`
|
||||||
OverrideDNS bool `json:"overrideDNS"`
|
OverrideDNS bool `json:"overrideDNS"`
|
||||||
TunnelDNS bool `json:"tunnelDNS"`
|
TunnelDNS bool `json:"tunnelDNS"`
|
||||||
DisableRelay bool `json:"disableRelay"`
|
DisableRelay bool `json:"disableRelay"`
|
||||||
|
PreferLocalRoutes bool `json:"preferLocalRoutes"`
|
||||||
// DoNotCreateNewClient bool `json:"doNotCreateNewClient"`
|
// DoNotCreateNewClient bool `json:"doNotCreateNewClient"`
|
||||||
|
|
||||||
// Parsed values (not in JSON)
|
// Parsed values (not in JSON)
|
||||||
@@ -118,6 +119,7 @@ func DefaultConfig() *OlmConfig {
|
|||||||
config.sources["overrideDNS"] = string(SourceDefault)
|
config.sources["overrideDNS"] = string(SourceDefault)
|
||||||
config.sources["tunnelDNS"] = string(SourceDefault)
|
config.sources["tunnelDNS"] = string(SourceDefault)
|
||||||
config.sources["disableRelay"] = string(SourceDefault)
|
config.sources["disableRelay"] = string(SourceDefault)
|
||||||
|
config.sources["preferLocalRoutes"] = string(SourceDefault)
|
||||||
// config.sources["doNotCreateNewClient"] = string(SourceDefault)
|
// config.sources["doNotCreateNewClient"] = string(SourceDefault)
|
||||||
|
|
||||||
return config
|
return config
|
||||||
@@ -281,6 +283,10 @@ func loadConfigFromEnv(config *OlmConfig) {
|
|||||||
config.DisableRelay = true
|
config.DisableRelay = true
|
||||||
config.sources["disableRelay"] = string(SourceEnv)
|
config.sources["disableRelay"] = string(SourceEnv)
|
||||||
}
|
}
|
||||||
|
if val := os.Getenv("PREFER_LOCAL_ROUTES"); val == "true" {
|
||||||
|
config.PreferLocalRoutes = true
|
||||||
|
config.sources["preferLocalRoutes"] = string(SourceEnv)
|
||||||
|
}
|
||||||
if val := os.Getenv("TUNNEL_DNS"); val == "true" {
|
if val := os.Getenv("TUNNEL_DNS"); val == "true" {
|
||||||
config.TunnelDNS = true
|
config.TunnelDNS = true
|
||||||
config.sources["tunnelDNS"] = string(SourceEnv)
|
config.sources["tunnelDNS"] = string(SourceEnv)
|
||||||
@@ -297,26 +303,27 @@ func loadConfigFromCLI(config *OlmConfig, args []string) (bool, bool, error) {
|
|||||||
|
|
||||||
// Store original values to detect changes
|
// Store original values to detect changes
|
||||||
origValues := map[string]interface{}{
|
origValues := map[string]interface{}{
|
||||||
"endpoint": config.Endpoint,
|
"endpoint": config.Endpoint,
|
||||||
"id": config.ID,
|
"id": config.ID,
|
||||||
"secret": config.Secret,
|
"secret": config.Secret,
|
||||||
"org": config.OrgID,
|
"org": config.OrgID,
|
||||||
"userToken": config.UserToken,
|
"userToken": config.UserToken,
|
||||||
"mtu": config.MTU,
|
"mtu": config.MTU,
|
||||||
"dns": config.DNS,
|
"dns": config.DNS,
|
||||||
"upstreamDNS": fmt.Sprintf("%v", config.UpstreamDNS),
|
"upstreamDNS": fmt.Sprintf("%v", config.UpstreamDNS),
|
||||||
"matchDomains": fmt.Sprintf("%v", config.MatchDomains),
|
"matchDomains": fmt.Sprintf("%v", config.MatchDomains),
|
||||||
"logLevel": config.LogLevel,
|
"logLevel": config.LogLevel,
|
||||||
"interface": config.InterfaceName,
|
"interface": config.InterfaceName,
|
||||||
"httpAddr": config.HTTPAddr,
|
"httpAddr": config.HTTPAddr,
|
||||||
"socketPath": config.SocketPath,
|
"socketPath": config.SocketPath,
|
||||||
"pingInterval": config.PingInterval,
|
"pingInterval": config.PingInterval,
|
||||||
"pingTimeout": config.PingTimeout,
|
"pingTimeout": config.PingTimeout,
|
||||||
"enableApi": config.EnableAPI,
|
"enableApi": config.EnableAPI,
|
||||||
"disableHolepunch": config.DisableHolepunch,
|
"disableHolepunch": config.DisableHolepunch,
|
||||||
"overrideDNS": config.OverrideDNS,
|
"overrideDNS": config.OverrideDNS,
|
||||||
"disableRelay": config.DisableRelay,
|
"disableRelay": config.DisableRelay,
|
||||||
"tunnelDNS": config.TunnelDNS,
|
"preferLocalRoutes": config.PreferLocalRoutes,
|
||||||
|
"tunnelDNS": config.TunnelDNS,
|
||||||
// "doNotCreateNewClient": config.DoNotCreateNewClient,
|
// "doNotCreateNewClient": config.DoNotCreateNewClient,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -342,6 +349,7 @@ func loadConfigFromCLI(config *OlmConfig, args []string) (bool, bool, error) {
|
|||||||
serviceFlags.BoolVar(&config.DisableHolepunch, "disable-holepunch", config.DisableHolepunch, "Disable hole punching")
|
serviceFlags.BoolVar(&config.DisableHolepunch, "disable-holepunch", config.DisableHolepunch, "Disable hole punching")
|
||||||
serviceFlags.BoolVar(&config.OverrideDNS, "override-dns", config.OverrideDNS, "When enabled, the client uses custom DNS servers to resolve internal resources and aliases. This overrides your system's default DNS settings. Queries that cannot be resolved as a Pangolin resource will be forwarded to your configured Upstream DNS Server. (default false)")
|
serviceFlags.BoolVar(&config.OverrideDNS, "override-dns", config.OverrideDNS, "When enabled, the client uses custom DNS servers to resolve internal resources and aliases. This overrides your system's default DNS settings. Queries that cannot be resolved as a Pangolin resource will be forwarded to your configured Upstream DNS Server. (default false)")
|
||||||
serviceFlags.BoolVar(&config.DisableRelay, "disable-relay", config.DisableRelay, "Disable relay connections")
|
serviceFlags.BoolVar(&config.DisableRelay, "disable-relay", config.DisableRelay, "Disable relay connections")
|
||||||
|
serviceFlags.BoolVar(&config.PreferLocalRoutes, "prefer-local-routes", config.PreferLocalRoutes, "Add tunnel routes with a high metric so overlapping local/connected routes take precedence (default false)")
|
||||||
serviceFlags.BoolVar(&config.TunnelDNS, "tunnel-dns", config.TunnelDNS, "When enabled, DNS queries are routed through the tunnel for remote resolution. To ensure queries are tunneled correctly, you must define the DNS server as a Pangolin resource and enter its address as an Upstream DNS Server. (default false)")
|
serviceFlags.BoolVar(&config.TunnelDNS, "tunnel-dns", config.TunnelDNS, "When enabled, DNS queries are routed through the tunnel for remote resolution. To ensure queries are tunneled correctly, you must define the DNS server as a Pangolin resource and enter its address as an Upstream DNS Server. (default false)")
|
||||||
// serviceFlags.BoolVar(&config.DoNotCreateNewClient, "do-not-create-new-client", config.DoNotCreateNewClient, "Do not create new client")
|
// serviceFlags.BoolVar(&config.DoNotCreateNewClient, "do-not-create-new-client", config.DoNotCreateNewClient, "Do not create new client")
|
||||||
|
|
||||||
@@ -426,6 +434,9 @@ func loadConfigFromCLI(config *OlmConfig, args []string) (bool, bool, error) {
|
|||||||
if config.DisableRelay != origValues["disableRelay"].(bool) {
|
if config.DisableRelay != origValues["disableRelay"].(bool) {
|
||||||
config.sources["disableRelay"] = string(SourceCLI)
|
config.sources["disableRelay"] = string(SourceCLI)
|
||||||
}
|
}
|
||||||
|
if config.PreferLocalRoutes != origValues["preferLocalRoutes"].(bool) {
|
||||||
|
config.sources["preferLocalRoutes"] = string(SourceCLI)
|
||||||
|
}
|
||||||
if config.TunnelDNS != origValues["tunnelDNS"].(bool) {
|
if config.TunnelDNS != origValues["tunnelDNS"].(bool) {
|
||||||
config.sources["tunnelDNS"] = string(SourceCLI)
|
config.sources["tunnelDNS"] = string(SourceCLI)
|
||||||
}
|
}
|
||||||
@@ -557,6 +568,10 @@ func mergeConfigs(dest, src *OlmConfig) {
|
|||||||
dest.DisableRelay = src.DisableRelay
|
dest.DisableRelay = src.DisableRelay
|
||||||
dest.sources["disableRelay"] = string(SourceFile)
|
dest.sources["disableRelay"] = string(SourceFile)
|
||||||
}
|
}
|
||||||
|
if src.PreferLocalRoutes {
|
||||||
|
dest.PreferLocalRoutes = src.PreferLocalRoutes
|
||||||
|
dest.sources["preferLocalRoutes"] = string(SourceFile)
|
||||||
|
}
|
||||||
// if src.DoNotCreateNewClient {
|
// if src.DoNotCreateNewClient {
|
||||||
// dest.DoNotCreateNewClient = src.DoNotCreateNewClient
|
// dest.DoNotCreateNewClient = src.DoNotCreateNewClient
|
||||||
// dest.sources["doNotCreateNewClient"] = string(SourceFile)
|
// dest.sources["doNotCreateNewClient"] = string(SourceFile)
|
||||||
@@ -649,6 +664,7 @@ func (c *OlmConfig) ShowConfig() {
|
|||||||
fmt.Printf(" override-dns = %v [%s]\n", c.OverrideDNS, getSource("overrideDNS"))
|
fmt.Printf(" override-dns = %v [%s]\n", c.OverrideDNS, getSource("overrideDNS"))
|
||||||
fmt.Printf(" tunnel-dns = %v [%s]\n", c.TunnelDNS, getSource("tunnelDNS"))
|
fmt.Printf(" tunnel-dns = %v [%s]\n", c.TunnelDNS, getSource("tunnelDNS"))
|
||||||
fmt.Printf(" disable-relay = %v [%s]\n", c.DisableRelay, getSource("disableRelay"))
|
fmt.Printf(" disable-relay = %v [%s]\n", c.DisableRelay, getSource("disableRelay"))
|
||||||
|
fmt.Printf(" prefer-local-routes = %v [%s]\n", c.PreferLocalRoutes, getSource("preferLocalRoutes"))
|
||||||
// fmt.Printf(" do-not-create-new-client = %v [%s]\n", c.DoNotCreateNewClient, getSource("doNotCreateNewClient"))
|
// fmt.Printf(" do-not-create-new-client = %v [%s]\n", c.DoNotCreateNewClient, getSource("doNotCreateNewClient"))
|
||||||
if c.TlsClientCert != "" {
|
if c.TlsClientCert != "" {
|
||||||
fmt.Printf(" tls-cert = %s [%s]\n", c.TlsClientCert, getSource("tlsClientCert"))
|
fmt.Printf(" tls-cert = %s [%s]\n", c.TlsClientCert, getSource("tlsClientCert"))
|
||||||
|
|||||||
@@ -272,6 +272,7 @@ func runOlmMainWithArgs(ctx context.Context, cancel context.CancelFunc, signalCt
|
|||||||
OrgID: config.OrgID,
|
OrgID: config.OrgID,
|
||||||
OverrideDNS: config.OverrideDNS,
|
OverrideDNS: config.OverrideDNS,
|
||||||
DisableRelay: config.DisableRelay,
|
DisableRelay: config.DisableRelay,
|
||||||
|
PreferLocalRoutes: config.PreferLocalRoutes,
|
||||||
EnableUAPI: true,
|
EnableUAPI: true,
|
||||||
}
|
}
|
||||||
go olm.StartTunnel(tunnelConfig)
|
go olm.StartTunnel(tunnelConfig)
|
||||||
|
|||||||
@@ -398,6 +398,7 @@ func (o *Olm) StartTunnel(config TunnelConfig) {
|
|||||||
|
|
||||||
o.tunnelRunning = true // Also set it here in case it is called externally
|
o.tunnelRunning = true // Also set it here in case it is called externally
|
||||||
o.tunnelConfig = config
|
o.tunnelConfig = config
|
||||||
|
network.PreferLocalRoutes = config.PreferLocalRoutes
|
||||||
|
|
||||||
// Determine whether the system DNS monitor should also manage UpstreamDNS.
|
// Determine whether the system DNS monitor should also manage UpstreamDNS.
|
||||||
// If the caller did not provide an explicit UpstreamDNS (it was defaulted to
|
// If the caller did not provide an explicit UpstreamDNS (it was defaulted to
|
||||||
|
|||||||
@@ -109,4 +109,12 @@ type TunnelConfig struct {
|
|||||||
InitialPostures map[string]any
|
InitialPostures map[string]any
|
||||||
|
|
||||||
DisableRelay bool
|
DisableRelay bool
|
||||||
|
|
||||||
|
// PreferLocalRoutes, when enabled, adds tunnel routes with an explicit
|
||||||
|
// high metric/priority so that an overlapping local/connected route to
|
||||||
|
// the same destination always takes precedence over the VPN route,
|
||||||
|
// rather than the two racing based on insertion order. Defaults to
|
||||||
|
// false, preserving the routing behavior from before this option was
|
||||||
|
// introduced.
|
||||||
|
PreferLocalRoutes bool
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user