mirror of
https://github.com/fosrl/newt.git
synced 2026-03-27 21:16:41 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
595278d455 |
@@ -73,11 +73,8 @@ 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:
|
||||||
// For relative paths or other formats, also default to unix
|
// default fallback to unix
|
||||||
return dockerHost{"unix", raw}, nil
|
return dockerHost{"unix", raw}, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -88,13 +85,6 @@ 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)
|
||||||
@@ -159,13 +149,7 @@ 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 = "unix:///var/run/docker.sock"
|
socketPath = "/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
|
||||||
|
|||||||
@@ -325,9 +325,11 @@ func (pm *ProxyManager) handleUDPProxy(conn *gonet.UDPConn, targetAddr string) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
clientKey := remoteAddr.String()
|
// Use only the client IP as the key, not IP:port
|
||||||
|
// 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[clientKey]
|
targetConn, exists := clientConns[clientIP]
|
||||||
clientsMutex.RUnlock()
|
clientsMutex.RUnlock()
|
||||||
|
|
||||||
if !exists {
|
if !exists {
|
||||||
@@ -344,15 +346,15 @@ func (pm *ProxyManager) handleUDPProxy(conn *gonet.UDPConn, targetAddr string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
clientsMutex.Lock()
|
clientsMutex.Lock()
|
||||||
clientConns[clientKey] = targetConn
|
clientConns[clientIP] = targetConn
|
||||||
clientsMutex.Unlock()
|
clientsMutex.Unlock()
|
||||||
|
|
||||||
go func(clientKey string, targetConn *net.UDPConn, remoteAddr net.Addr) {
|
go func(clientIP 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[clientKey]; exists && storedConn == targetConn {
|
if storedConn, exists := clientConns[clientIP]; exists && storedConn == targetConn {
|
||||||
delete(clientConns, clientKey)
|
delete(clientConns, clientIP)
|
||||||
targetConn.Close()
|
targetConn.Close()
|
||||||
}
|
}
|
||||||
clientsMutex.Unlock()
|
clientsMutex.Unlock()
|
||||||
@@ -372,7 +374,7 @@ func (pm *ProxyManager) handleUDPProxy(conn *gonet.UDPConn, targetAddr string) {
|
|||||||
return // defer will handle cleanup
|
return // defer will handle cleanup
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}(clientKey, targetConn, remoteAddr)
|
}(clientIP, targetConn, remoteAddr)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = targetConn.Write(buffer[:n])
|
_, err = targetConn.Write(buffer[:n])
|
||||||
@@ -380,7 +382,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, clientKey)
|
delete(clientConns, clientIP)
|
||||||
clientsMutex.Unlock()
|
clientsMutex.Unlock()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user