On Fri, Nov 13, 2009 at 09:26:25AM +0800, Michael Deegan wrote:
> Package: apt-cacher
> Version: 1.6.4
> Severity: normal
> 
> This is something of a followup for #483666. Anyway, on a machine on both
> private and internet-facing networks (with the internal interface the
> defaultroute), I found a couple of problems:
> - the conffile refers to 'interface', whereas the code (and the patch in
>   #483666) refers to 'use_interface'.

Thanks. Manpage also agrees with the conffile. 

> - there is code near the middle of handle_connection() that uses
>   io_socket_inet46() to connect to the remote server briefly. This doesn't use
>   the value of use_interface. Thus every connection always fails.
> 
> I've worked around this for now by commenting out about two dozen lines, 
> namely the
> offending socket code and the 'Host in Absolute URI is this server' check.

Please try this patch (against 1.6.4) and let me know if it is any
better.

You will need to install the libio-interface-perl package

Mark

diff --git a/apt-cacher b/apt-cacher
index 11a9cda..893994b 100755
--- a/apt-cacher2
+++ b/apt-cacher2
@@ -212,6 +212,20 @@ EOM
        }
     }
 
+    if ($cfg->{interface}) {
+       # If we can't resolve item, see if it is an interface name
+       unless (inet_aton($cfg->{interface})) {
+           use IO::Interface::Simple;
+           my $if = IO::Interface::Simple->new($cfg->{interface});
+           if ($if) {
+               $cfg->{interface} = $if->address;
+           }
+           else {
+               $cfg->{interface} = '';
+           }
+       }
+    }
+
     # Ensure config is sane and filesystem is present and readable
     &check_install;
     # Die if it still failed
@@ -452,10 +466,12 @@ sub handle_connection {
        if ($path =~ m!^http://([^/]+)!) { # Absolute URI
            # Check host or proxy
            debug_message("Checking host $1 in absolute URI");
-           my $sock = io_socket_inet46(PeerAddr=> $1, # possibly with port
-                                       PeerPort=> 80, # Default, overridden if
-                                                       # port also in PeerAddr
-                                       Proto   => 'tcp');
+           my %sockopt = (PeerAddr=> $1, # possibly with port
+                          PeerPort=> 80, # Default, overridden if
+                                         # port also in PeerAddr
+                          Proto   => 'tcp');
+           $sockopt{LocalAddr} = $cfg->{interface} if $cfg->{interface};
+           my $sock = io_socket_inet46(%sockopt);
            # proxy may be required to reach host
            if (!defined($sock) && !$cfg->{use_proxy}) {
                info_message("Unable to connect to $1");
@@ -1166,7 +1182,7 @@ sub debug_callback {
        $curl->setopt(CURLOPT_NOSIGNAL, 1);
        $curl->setopt(CURLOPT_LOW_SPEED_LIMIT, 0);
        $curl->setopt(CURLOPT_LOW_SPEED_TIME, $cfg->{fetch_timeout});
-       $curl->setopt(CURLOPT_INTERFACE, $cfg->{use_interface}) if defined 
$cfg->{use_interface};
+       $curl->setopt(CURLOPT_INTERFACE, $cfg->{interface}) if defined 
$cfg->{interface};
 
        # Callbacks
        $curl->setopt(CURLOPT_WRITEFUNCTION, \&body_callback);



-- 
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org

Reply via email to