mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-09-04 13:36:35 +02:00
fix: allow intercept fallback for default listener
This commit is contained in:
+11
-1
@@ -1266,7 +1266,7 @@ func tryUpdateListenerConfigIntercept(cfg *ctrld.Config, notifyFunc func(), fata
|
|||||||
return false, true
|
return false, true
|
||||||
}
|
}
|
||||||
|
|
||||||
hasExplicitConfig := lc.IP != "" && lc.IP != "0.0.0.0" && lc.Port != 0
|
hasExplicitConfig := isExplicitInterceptListener(lc.IP, lc.Port)
|
||||||
if !hasExplicitConfig {
|
if !hasExplicitConfig {
|
||||||
// Set defaults for intercept mode
|
// Set defaults for intercept mode
|
||||||
if lc.IP == "" || lc.IP == "0.0.0.0" {
|
if lc.IP == "" || lc.IP == "0.0.0.0" {
|
||||||
@@ -1324,6 +1324,16 @@ func tryUpdateListenerConfigIntercept(cfg *ctrld.Config, notifyFunc func(), fata
|
|||||||
return updated, false
|
return updated, false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isExplicitInterceptListener(ip string, port int) bool {
|
||||||
|
if ip == "" || ip == "0.0.0.0" || port == 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
// 127.0.0.1:53 is the default macOS DNS-intercept listener. It can appear
|
||||||
|
// in generated/custom Control D configs, but it should still be allowed to
|
||||||
|
// fall back to 127.0.0.1:5354 when mDNSResponder already owns port 53.
|
||||||
|
return !(ip == "127.0.0.1" && port == 53)
|
||||||
|
}
|
||||||
|
|
||||||
// tryUpdateListenerConfig tries updating listener config with a working one.
|
// tryUpdateListenerConfig tries updating listener config with a working one.
|
||||||
// If fatal is true, and there's listen address conflicted, the function do
|
// If fatal is true, and there's listen address conflicted, the function do
|
||||||
// fatal error.
|
// fatal error.
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package cli
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestIsExplicitInterceptListener(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
ip string
|
||||||
|
port int
|
||||||
|
want bool
|
||||||
|
}{
|
||||||
|
{name: "empty", ip: "", port: 0, want: false},
|
||||||
|
{name: "wildcard", ip: "0.0.0.0", port: 53, want: false},
|
||||||
|
{name: "zero port", ip: "127.0.0.1", port: 0, want: false},
|
||||||
|
{name: "default intercept listener", ip: "127.0.0.1", port: 53, want: false},
|
||||||
|
{name: "fallback port explicit", ip: "127.0.0.1", port: 5354, want: true},
|
||||||
|
{name: "custom loopback explicit", ip: "127.0.0.2", port: 53, want: true},
|
||||||
|
{name: "custom address explicit", ip: "192.0.2.10", port: 53, want: true},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
if got := isExplicitInterceptListener(tt.ip, tt.port); got != tt.want {
|
||||||
|
t.Fatalf("isExplicitInterceptListener(%q, %d) = %v, want %v", tt.ip, tt.port, got, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user