On 2015-06-25T19:25:36+0200, Nils M Holm wrote:
> When logging in via ftpfs, though, I get an empty /n/ftp directory.

Turns out that ftpd on FreeBSD announces a port on localhost for
passive mode connections:

227 Entering Passive Mode (127,0,0,1,247,55)

If I understand QEMU user networking correctly, it sees incoming
traffic as originating from localhost, in which case the above
would make sense.

So I patched ftpfs and added an additional command line option to
ignore the host address part of the above message and substitute
the destination system's address.

The patch works fine for me. I'm not a networking expert, though,
so it may have some subtle side effects that I'm not aware of.

The patch is below in case anybody is interested.

Thanks for your help!

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/sys/src/cmd/ip/ftpfs/ftpfs.c.OLD:32,39 - /sys/src/cmd/ip/ftpfs/ftpfs.c:32,37
  int   kapid = -1;
  int   dying;          /* set when any process decides to die */
  int   dokeepalive;
+ char  *system;
+ int           qemu_hack = 0;
  
  char  *rflush(Fid*), *rnop(Fid*), *rversion(Fid*),
        *rattach(Fid*), *rclone(Fid*), *rwalk(Fid*),
/sys/src/cmd/ip/ftpfs/ftpfs.c.OLD:151,159 - 
/sys/src/cmd/ip/ftpfs/ftpfs.c:149,154
        case 'q':
                quiet = 1;
                break;
+       case 'Q':
+               qemu_hack = 1;
+               break;
        } ARGEND
        if(argc != 1)
                usage();
/sys/src/cmd/ip/ftpfs/ftpfs.c.OLD:165,171 - 
/sys/src/cmd/ip/ftpfs/ftpfs.c:160,165
  
        /* initial handshakes with remote side */
        hello(*argv);
+       system = *argv;
        if(cpassword == 0)
                rlogin(*argv, keyspec);
        else
/sys/src/cmd/ip/ftpfs/proto.c.OLD:1272,1277 - 
/sys/src/cmd/ip/ftpfs/proto.c:1272,1279
        char *p;
        int x, fd;
        TLSconn conn;
+       extern char *system;
+       extern int      qemu_hack;
  
        if(nopassive)
                return Impossible;
/sys/src/cmd/ip/ftpfs/proto.c.OLD:1297,1305 - 
/sys/src/cmd/ip/ftpfs/proto.c:1299,1314
                nopassive = 1;
                return Impossible;
        }
-       snprint(ds, sizeof(ds), "%s!%s.%s.%s.%s!%d", net,
-               f[0], f[1], f[2], f[3],
-               ((atoi(f[4])&0xff)<<8) + (atoi(f[5])&0xff));
+       if (qemu_hack) {
+               snprint(ds, sizeof(ds), "%s!%s!%d", net,
+                       system,
+                       ((atoi(f[4])&0xff)<<8) + (atoi(f[5])&0xff));
+       }
+       else {
+               snprint(ds, sizeof(ds), "%s!%s.%s.%s.%s!%d", net,
+                       f[0], f[1], f[2], f[3],
+                       ((atoi(f[4])&0xff)<<8) + (atoi(f[5])&0xff));
+       }
  
        /* open data connection */
        fd = dial(ds, 0, 0, 0);
/sys/man/4/ftpfs.OLD:4,10 - /sys/man/4/ftpfs:4,10
  .SH SYNOPSIS
  .B ftpfs
  [
- .B -/dqnt
+ .B -/dqntKQ
  ]
  [
  .B -m
/sys/man/4/ftpfs.OLD:96,101 - /sys/man/4/ftpfs:96,107
  option causes ftp to send a NOP command every 15 seconds to attempt
  to keep the connection open.  This command can cause some servers to
  hangup, so you'll have to feel your way.
+ .PP
+ QEMU will see incoming connections as coming from localhost and therefore
+ announce a port for passive mode on 127.0.0.1, which will confuse
+ .I ftpfs.
+ The -Q option ignores the host addresses announced by FTP servers in
+ passive mode negotation and uses the destination address instead.
  .PP
  The
  .B -t
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

-- 
Nils M Holm  < n m h @ t 3 x . o r g >  www.t3x.org

Reply via email to