@@ -23,15 +23,24 @@ type cookieAddr struct {
23
23
24
24
// Format:
25
25
// remote_port:local_address:local_port
26
- var remoteForwardRegex = regexp .MustCompile (`^(\d+):(.+):(\d+)$` )
26
+ var remoteForwardRegexTCP = regexp .MustCompile (`^(\d+):(.+):(\d+)$` )
27
27
28
- func validateRemoteForward (flag string ) bool {
29
- return remoteForwardRegex .MatchString (flag )
28
+ // remote_socket_path:local_socket_path (both absolute paths)
29
+ var remoteForwardRegexUnixSocket = regexp .MustCompile (`^(\\.+):(\\.+)$` )
30
+
31
+ func remoteForwardTCP (flag string ) bool {
32
+ return remoteForwardRegexTCP .MatchString (flag )
30
33
}
31
34
32
- func parseRemoteForward (flag string ) (net.Addr , net.Addr , error ) {
33
- matches := remoteForwardRegex .FindStringSubmatch (flag )
35
+ func remoteForwardUnixSocket (flag string ) bool {
36
+ return remoteForwardRegexUnixSocket .MatchString (flag )
37
+ }
34
38
39
+ func validateRemoteForward (flag string ) bool {
40
+ return remoteForwardTCP (flag ) || remoteForwardUnixSocket (flag )
41
+ }
42
+
43
+ func parseRemoteForwardTCP (matches []string ) (net.Addr , net.Addr , error ) {
35
44
remotePort , err := strconv .Atoi (matches [1 ])
36
45
if err != nil {
37
46
return nil , nil , xerrors .Errorf ("remote port is invalid: %w" , err )
@@ -57,6 +66,37 @@ func parseRemoteForward(flag string) (net.Addr, net.Addr, error) {
57
66
return localAddr , remoteAddr , nil
58
67
}
59
68
69
+ func parseRemoteForwardUnixSocket (matches []string ) (net.Addr , net.Addr , error ) {
70
+ remoteSocket := matches [1 ]
71
+ localSocket := matches [2 ]
72
+
73
+ remoteAddr := & net.UnixAddr {
74
+ Name : remoteSocket ,
75
+ Net : "unix" ,
76
+ }
77
+
78
+ localAddr := & net.UnixAddr {
79
+ Name : localSocket ,
80
+ Net : "unix" ,
81
+ }
82
+ return localAddr , remoteAddr , nil
83
+ }
84
+
85
+ func parseRemoteForward (flag string ) (net.Addr , net.Addr , error ) {
86
+ tcpMatches := remoteForwardRegexTCP .FindStringSubmatch (flag )
87
+
88
+ if len (tcpMatches ) > 0 {
89
+ return parseRemoteForwardTCP (tcpMatches )
90
+ }
91
+
92
+ unixSocketMatches := remoteForwardRegexUnixSocket .FindStringSubmatch (flag )
93
+ if len (unixSocketMatches ) > 0 {
94
+ return parseRemoteForwardUnixSocket (unixSocketMatches )
95
+ }
96
+
97
+ return nil , nil , xerrors .New ("Could not match forward arguments" )
98
+ }
99
+
60
100
// sshRemoteForward starts forwarding connections from a remote listener to a
61
101
// local address via SSH in a goroutine.
62
102
//
0 commit comments