Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 4 May 2005 18:37:10 +0200 (CEST)
From:      Peter Much <pmc@citylink.dinoex.sub.org>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   bin/80620: fetch -U does not work
Message-ID:  <200505041637.j44GbAGm003258@edge.oper.dinoex.org>
Resent-Message-ID: <200505041710.j44HA2bF035185@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         80620
>Category:       bin
>Synopsis:       fetch -U does not work
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed May 04 17:10:02 GMT 2005
>Closed-Date:
>Last-Modified:
>Originator:     Peter Much
>Release:        FreeBSD 5.3-RELEASE-p5 i386
>Organization:
n/a
>Environment:
System: FreeBSD edge.oper.dinoex.org 5.3-RELEASE-p5 FreeBSD 5.3-RELEASE-p5 #5: Sun Feb 6 23:26:49 CET 2005 root@edge.oper.dinoex.org:/usr/src/sys/i386/compile/E1R53V1 i386


>Description:

The -U option to fetch command does not have the effect as
described in the fetch manpage (using a low port in passive mode ftp).
Actually it has no effect at all.

  (Background: This feature allows to workarund IP-providers that use
  "port priority" to slow down filesharing programs, so that connections
  using an unpriviledged port on each end get a very low throughput.
  But this slows not only filesharing, but also other services, like
  ftp in passive mode. But since the client can freely choose the local 
  port for connecting to the provided server port for the data
  connection, this one can be made a low, priviledged port.)

Tracking the flaw leads to lib/libfetch/ftp.c:_ftp_transfer(). Here the
option arrives as flag 'l', and this is not even used in passive
mode. It does something when *NOT* using passive mode, but I'm not
sure what could be the intended use of that.

Actually it looks like the implementation has simply been forgotten.



>How-To-Repeat:

disp53# echo $FTP_PASSIVE_MODE
yes
disp53# sysctl -a | grep  net.inet.ip.portrange.low
net.inet.ip.portrange.lowfirst: 1023
net.inet.ip.portrange.lowlast: 600
disp53# fetch -U ftp://ftp3.de.freebsd.org/pub/FreeBSD/ports/distfiles/openoffice1.1/OOo_1.1.2_source.tar.gz &
[1] 94876
disp53# netstat -afinet
Active Internet connections (including servers)
Proto Recv-Q Send-Q  Local Address          Foreign Address        (state)
tcp4       0      0  192.168.98.7.51777     ftp.plusline.net.30545 ESTABLISHED
tcp4       0      0  192.168.98.7.51976     ftp.plusline.net.ftp   ESTABLISHED



>Fix:

*** lib/libfetch/ftp.c.orig     Fri Aug 29 17:56:52 2003
--- lib/libfetch/ftp.c  Wed May  4 18:17:14 2005
***************
*** 27,33 ****
   */
  
  #include <sys/cdefs.h>
! __FBSDID("$FreeBSD: src/lib/libfetch/ftp.c,v 1.90 2003/08/29 15:56:52 des Exp $");
  
  /*
   * Portions of this code were taken from or based on ftpio.c:
--- 27,33 ----
   */
  
  #include <sys/cdefs.h>
! __FBSDID("$FreeBSD: $");
  
  /*
   * Portions of this code were taken from or based on ftpio.c:
***************
*** 489,495 ****
                u_char addr[64];
                char *ln, *p;
                unsigned int i;
!               int port;
  
                /* send PASV command */
                if (verbose)
--- 489,514 ----
                u_char addr[64];
                char *ln, *p;
                unsigned int i;
!               int arg, port;
! 
!               switch (sa.ss_family) {
!               case AF_INET6:
!                       ((struct sockaddr_in6 *)&sa)->sin6_port = 0;
! #ifdef IPV6_PORTRANGE
!                       arg = low ? IPV6_PORTRANGE_LOW : IPV6_PORTRANGE_DEFAULT;
!                       if (setsockopt(sd, IPPROTO_IPV6, IPV6_PORTRANGE,
!                               (char *)&arg, sizeof(arg)) == -1)
!                               goto sysouch;
! #endif
!                       break;
!               case AF_INET:
!                       ((struct sockaddr_in *)&sa)->sin_port = 0;
!                       arg = low ? IP_PORTRANGE_LOW : IP_PORTRANGE_DEFAULT;
!                       if (setsockopt(sd, IPPROTO_IP, IP_PORTRANGE,
!                               (char *)&arg, sizeof(arg)) == -1)
!                               goto sysouch;
!                       break;
!               }
  
                /* send PASV command */
                if (verbose)



After adding this piece of code, the session looks this way:

disp53# netstat -afinet
Active Internet connections (including servers)
Proto Recv-Q Send-Q  Local Address          Foreign Address        (state)
tcp4       0      0  192.168.98.7.984       ftp.plusline.net.43094 ESTABLISHED
tcp4       0      0  192.168.98.7.52402     ftp.plusline.net.ftp   ESTABLISHED
>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200505041637.j44GbAGm003258>