Compare commits

..

1 Commits
1.4.3 ... 1.4.4

Author SHA1 Message Date
Owen
2969f9d2d6 Ensure backward compatability with --docker-socket 2025-09-02 14:08:24 -07:00
2 changed files with 26 additions and 12 deletions

View File

@@ -73,8 +73,11 @@ func parseDockerHost(raw string) (dockerHost, error) {
s = strings.TrimPrefix(s, "http://") s = strings.TrimPrefix(s, "http://")
s = strings.TrimPrefix(s, "https://") s = strings.TrimPrefix(s, "https://")
return dockerHost{"tcp", s}, nil return dockerHost{"tcp", s}, nil
case strings.HasPrefix(raw, "/"):
// Absolute path without scheme - treat as unix socket
return dockerHost{"unix", raw}, nil
default: default:
// default fallback to unix // For relative paths or other formats, also default to unix
return dockerHost{"unix", raw}, nil return dockerHost{"unix", raw}, nil
} }
} }
@@ -85,6 +88,13 @@ func CheckSocket(socketPath string) bool {
if socketPath == "" { if socketPath == "" {
socketPath = "unix:///var/run/docker.sock" socketPath = "unix:///var/run/docker.sock"
} }
// Ensure the socket path is properly formatted
if !strings.Contains(socketPath, "://") {
// If no scheme provided, assume unix socket
socketPath = "unix://" + socketPath
}
host, err := parseDockerHost(socketPath) host, err := parseDockerHost(socketPath)
if err != nil { if err != nil {
logger.Debug("Invalid Docker socket path '%s': %v", socketPath, err) logger.Debug("Invalid Docker socket path '%s': %v", socketPath, err)
@@ -149,7 +159,13 @@ func IsWithinHostNetwork(socketPath string, targetAddress string, targetPort int
func ListContainers(socketPath string, enforceNetworkValidation bool) ([]Container, error) { func ListContainers(socketPath string, enforceNetworkValidation bool) ([]Container, error) {
// Use the provided socket path or default to standard location // Use the provided socket path or default to standard location
if socketPath == "" { if socketPath == "" {
socketPath = "/var/run/docker.sock" socketPath = "unix:///var/run/docker.sock"
}
// Ensure the socket path is properly formatted for the Docker client
if !strings.Contains(socketPath, "://") {
// If no scheme provided, assume unix socket
socketPath = "unix://" + socketPath
} }
// Used to filter down containers returned to Pangolin // Used to filter down containers returned to Pangolin

View File

@@ -325,11 +325,9 @@ func (pm *ProxyManager) handleUDPProxy(conn *gonet.UDPConn, targetAddr string) {
continue continue
} }
// Use only the client IP as the key, not IP:port clientKey := remoteAddr.String()
// This ensures all packets from the same client reuse the same target connection
clientIP := remoteAddr.(*net.UDPAddr).IP.String()
clientsMutex.RLock() clientsMutex.RLock()
targetConn, exists := clientConns[clientIP] targetConn, exists := clientConns[clientKey]
clientsMutex.RUnlock() clientsMutex.RUnlock()
if !exists { if !exists {
@@ -346,15 +344,15 @@ func (pm *ProxyManager) handleUDPProxy(conn *gonet.UDPConn, targetAddr string) {
} }
clientsMutex.Lock() clientsMutex.Lock()
clientConns[clientIP] = targetConn clientConns[clientKey] = targetConn
clientsMutex.Unlock() clientsMutex.Unlock()
go func(clientIP string, targetConn *net.UDPConn, remoteAddr net.Addr) { go func(clientKey string, targetConn *net.UDPConn, remoteAddr net.Addr) {
defer func() { defer func() {
// Always clean up when this goroutine exits // Always clean up when this goroutine exits
clientsMutex.Lock() clientsMutex.Lock()
if storedConn, exists := clientConns[clientIP]; exists && storedConn == targetConn { if storedConn, exists := clientConns[clientKey]; exists && storedConn == targetConn {
delete(clientConns, clientIP) delete(clientConns, clientKey)
targetConn.Close() targetConn.Close()
} }
clientsMutex.Unlock() clientsMutex.Unlock()
@@ -374,7 +372,7 @@ func (pm *ProxyManager) handleUDPProxy(conn *gonet.UDPConn, targetAddr string) {
return // defer will handle cleanup return // defer will handle cleanup
} }
} }
}(clientIP, targetConn, remoteAddr) }(clientKey, targetConn, remoteAddr)
} }
_, err = targetConn.Write(buffer[:n]) _, err = targetConn.Write(buffer[:n])
@@ -382,7 +380,7 @@ func (pm *ProxyManager) handleUDPProxy(conn *gonet.UDPConn, targetAddr string) {
logger.Error("Error writing to target: %v", err) logger.Error("Error writing to target: %v", err)
targetConn.Close() targetConn.Close()
clientsMutex.Lock() clientsMutex.Lock()
delete(clientConns, clientIP) delete(clientConns, clientKey)
clientsMutex.Unlock() clientsMutex.Unlock()
} }
} }