Skip to content

Commit bf540dd

Browse files
authored
Merge pull request #336 from libfuse/ipv6-connect
ipv6 support for directport connection
2 parents ccb6821 + 882d3a0 commit bf540dd

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,39 @@ On BSD and macOS, to unmount the filesystem:
5555
umount mountpoint
5656
```
5757

58+
### Bypassing SSH
59+
60+
#### Using directport
61+
62+
Using direct connections to sftp-server to bypass SSH for performance is also possible. To do this, start a network service using sftp-server (part of OpenSSH) on a server, then connect directly using `-o directport=PORT` option.
63+
64+
On server (listen on port 1234 using socat):
65+
66+
`socat tcp-listen:1234,reuseaddr,fork exec:/usr/lib/openssh/sftp-server`
67+
68+
On client:
69+
70+
`sshfs -o directport=1234 127.0.0.1:/tmp /tmp/mnt`
71+
72+
Note that this is insecure as connection will happen without encryption. Only use this on localhost or trusted networks. This option is sometimes used by other projects to mount folders inside VMs.
73+
74+
IPv6 is also possible:
75+
76+
`socat tcp6-listen:1234,reuseaddr,fork exec:/usr/lib/openssh/sftp-server`
77+
78+
`sshfs -o directport=1234 [::1]:/tmp /tmp/mnt`
79+
80+
#### Using vsock
81+
82+
Similarly to above, Linux [vsock](https://man7.org/linux/man-pages/man7/vsock.7.html) can be used to connect directly to sockets within VMs using `-o vsock=CID:PORT`.
83+
84+
```
85+
# on the host
86+
socat VSOCK-LISTEN:12345 EXEC:"/usr/lib/openssh/sftp-server",nofork
87+
# on the clientside
88+
sshfs -o vsock=2:12345 unused_host: ./tmp
89+
```
90+
5891
## Installation
5992

6093

sshfs.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,6 +1258,10 @@ static int connect_to(struct conn *conn, char *host, char *port)
12581258

12591259
memset(&hint, 0, sizeof(hint));
12601260
hint.ai_family = PF_INET;
1261+
if (strstr(host, ":") != NULL) { // only ipv6 should have : in it, normal IP and domains do not.
1262+
hint.ai_family = PF_INET6;
1263+
DEBUG("using ipv6 to connect to host %s\n", host);
1264+
}
12611265
hint.ai_socktype = SOCK_STREAM;
12621266
err = getaddrinfo(host, port, &hint, &ai);
12631267
if (err) {

0 commit comments

Comments
 (0)