You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by si...@apache.org on 2005/10/16 11:37:28 UTC

svn commit: r322462 - in /spamassassin/trunk: lib/Mail/SpamAssassin.pm lib/Mail/SpamAssassin/DnsResolver.pm lib/spamassassin-run.pod spamassassin.raw spamd/spamd.raw

Author: sidney
Date: Sun Oct 16 02:37:20 2005
New Revision: 322462

URL: http://svn.apache.org/viewcvs?rev=322462&view=rev
Log:
Bug 4619 - Disable use of IPv6 for DNS if unable to create INET6 socket and add --ipv4 command line option to use in case there is still a problem

Modified:
    spamassassin/trunk/lib/Mail/SpamAssassin.pm
    spamassassin/trunk/lib/Mail/SpamAssassin/DnsResolver.pm
    spamassassin/trunk/lib/spamassassin-run.pod
    spamassassin/trunk/spamassassin.raw
    spamassassin/trunk/spamd/spamd.raw

Modified: spamassassin/trunk/lib/Mail/SpamAssassin.pm
URL: http://svn.apache.org/viewcvs/spamassassin/trunk/lib/Mail/SpamAssassin.pm?rev=322462&r1=322461&r2=322462&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin.pm Sun Oct 16 02:37:20 2005
@@ -206,6 +206,11 @@
 override the settings for C<rules_filename>, C<site_rules_filename>,
 and C<userprefs_filename>.
 
+=item force_ipv4
+
+If set to 1, DNS tests will not attempt to use IPv6. Use if the existing tests
+for IPv6 availablity produce incorrect results or crashes.
+
 =item languages_filename
 
 If you want to be able to use the language-guessing rule

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/DnsResolver.pm
URL: http://svn.apache.org/viewcvs/spamassassin/trunk/lib/Mail/SpamAssassin/DnsResolver.pm?rev=322462&r1=322461&r2=322462&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/DnsResolver.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/DnsResolver.pm Sun Oct 16 02:37:20 2005
@@ -44,7 +44,7 @@
 use IO::Socket::INET;
 use Errno qw(EINVAL EADDRINUSE);
 
-use constant HAS_SOCKET_INET6 => eval { require IO::Socket::INET6 };
+use constant HAS_SOCKET_INET6 => eval { require IO::Socket::INET6; defined AF_INET6 };
 
 our @ISA = qw();
 
@@ -81,13 +81,26 @@
 
   if (defined $self->{res}) { return 1; }
   $self->{no_resolver} = 1;
-
+  # force only ipv4 if no IO::Socket::INET6 or ipv6 doesn't work
+  my $force_ipv4 = (!HAS_SOCKET_INET6) || $self->{main}->{force_ipv4} ||
+    !eval {
+      my $sock6 = IO::Socket::INET6->new(
+                                         LocalAddr => "::",
+                                         Proto     => 'udp',
+                                         );
+      if ($sock6) {
+        $sock6->close();
+        1;
+      }
+    };
+  
   eval {
     require Net::DNS;
     $self->{res} = Net::DNS::Resolver->new;
     if (defined $self->{res}) {
       $self->{no_resolver} = 0;
-      $self->{retry} = 1;               # retries for non-nackgrounded query
+      $self->{force_ipv4} = $force_ipv4;
+      $self->{retry} = 1;               # retries for non-backgrounded query
       $self->{retrans} = 3;   # initial timeout for "non-backgrounded" query run in background
       $self->{res}->retry(1);           # If it fails, it fails
       $self->{res}->retrans(0);         # If it fails, it fails
@@ -97,10 +110,12 @@
       $self->{res}->udp_timeout(3);     # timeout of 3 seconds only
       $self->{res}->persistent_tcp(0);  # bug 3997
       $self->{res}->persistent_udp(0);  # bug 3997
+      $self->{res}->force_v4($force_ipv4);
     }
     1;
   };   #  or warn "dns: eval failed: $@ $!\n";
 
+  dbg("dns: no ipv6") if $force_ipv4;
   dbg("dns: is Net::DNS::Resolver available? " .
        ($self->{no_resolver} ? "no" : "yes"));
   if (!$self->{no_resolver} && defined $Net::DNS::VERSION) {
@@ -123,7 +138,7 @@
 
 =item $res->nameservers()
 
-Wrapper for Net::DNS::Reslolver->nameservers to get or set list of nameservers
+Wrapper for Net::DNS::Resolver->nameservers to get or set list of nameservers
 
 =cut
 
@@ -156,13 +171,14 @@
   my $ip64 = IP_ADDRESS;
   my $ip4 = IPV4_ADDRESS;
   my $ns = $self->{res}->{nameservers}[0];
-  my $ipv6 = 0;
+  my $ipv6 = 0; # this will be set if we have an ipv6 nameserver
+  my $ipv6opt = !($self->{force_ipv4});
 
   # now, attempt to set the family to AF_INET6 if we can.  Some
   # platforms don't have it (bug 4412 comment 29)...
   # also, only set $ipv6 to true if that succeeds.
   my $family;
-  if (HAS_SOCKET_INET6 && $ns=~/^${ip64}$/o && $ns!~/^${ip4}$/o) {
+  if ($ipv6opt && $ns=~/^${ip64}$/o && $ns!~/^${ip4}$/o) {
     eval '$family = AF_INET6; $ipv6 = 1;';
   }
   if (!defined $family) {
@@ -186,7 +202,7 @@
         Domain => $family,
     );
 
-    if (HAS_SOCKET_INET6) {
+    if ($ipv6opt) {
       $sock = IO::Socket::INET6->new(%args);
     } else {
       $sock = IO::Socket::INET->new(%args);

Modified: spamassassin/trunk/lib/spamassassin-run.pod
URL: http://svn.apache.org/viewcvs/spamassassin/trunk/lib/spamassassin-run.pod?rev=322462&r1=322461&r2=322462&view=diff
==============================================================================
--- spamassassin/trunk/lib/spamassassin-run.pod (original)
+++ spamassassin/trunk/lib/spamassassin-run.pod Sun Oct 16 02:37:20 2005
@@ -59,6 +59,7 @@
  --add-addr-to-whitelist=addr      Add addr to persistent address whitelist
  --add-addr-to-blacklist=addr      Add addr to persistent address blacklist
  --remove-addr-from-whitelist=addr Remove addr from persistent address list
+ --ipv4only, --ipv4-only, --ipv4   Disable attempted use of ipv6 for DNS
  --progress                        Print progress bar
  -D, --debug [area=n,...]          Print debugging messages
  -V, --version                     Print version
@@ -197,6 +198,12 @@
 Remove the named email address from a persistent address whitelist.  Note that
 you must be running C<spamassassin> or C<spamd> with a persistent address
 list plugin enabled for this to work.
+
+=item B< --ipv4only>, B<--ipv4-only>, B<--ipv4>
+
+Do not use IPv6 for DNS tests. Normally, SpamAssassin will try to detect if
+IPv6 is available, using only IPv4 if it is not. Use if the existing tests
+for IPv6 availablity produce incorrect results or crashes.
 
 =item B<-L>, B<--local>
 

Modified: spamassassin/trunk/spamassassin.raw
URL: http://svn.apache.org/viewcvs/spamassassin/trunk/spamassassin.raw?rev=322462&r1=322461&r2=322462&view=diff
==============================================================================
--- spamassassin/trunk/spamassassin.raw (original)
+++ spamassassin/trunk/spamassassin.raw Sun Oct 16 02:37:20 2005
@@ -175,6 +175,7 @@
   'debug|D:s'                               => \$opt{'debug'},
   'error-code|exit-code|e:i'                => \$opt{'error-code'},
   'help|h|?'                                => \$opt{'help'},
+  'ipv4only|ipv4-only|ipv4'                 => \$opt{'force_ipv4'},
   'lint'                                    => \$opt{'lint'},
   'local-only|local|L'                      => \$opt{'local'},
   'mbox'                                    => sub { $opt{'format'} = 'mbox'; },
@@ -240,6 +241,7 @@
     rules_filename      => $opt{'configpath'},
     site_rules_filename => $opt{'siteconfigpath'},
     userprefs_filename  => $opt{'prefspath'},
+    force_ipv4          => $opt{'force_ipv4'},
     local_tests_only    => $opt{'local'},
     debug               => $opt{'debug'},
     dont_copy_prefs     => ( $opt{'create-prefs'} ? 0 : 1 ),

Modified: spamassassin/trunk/spamd/spamd.raw
URL: http://svn.apache.org/viewcvs/spamassassin/trunk/spamd/spamd.raw?rev=322462&r1=322461&r2=322462&view=diff
==============================================================================
--- spamassassin/trunk/spamd/spamd.raw (original)
+++ spamassassin/trunk/spamd/spamd.raw Sun Oct 16 02:37:20 2005
@@ -166,6 +166,7 @@
   'helper-home-dir|H:s'      => \$opt{'home_dir_for_helpers'},
   'help|h'                   => \$opt{'help'},
   'ident-timeout=f'          => \$opt{'ident-timeout'},
+  'ipv4only|ipv4-only|ipv4'  => \$opt{'force_ipv4'},
   'ldap-config!'             => \$opt{'ldap-config'},
   'listen-ip|ip-address|i:s' => \$opt{'listen-ip'},
   'local!'                   => \$opt{'local'},
@@ -685,6 +686,7 @@
     dont_copy_prefs      => $dontcopy,
     rules_filename       => ( $opt{'configpath'} || 0 ),
     site_rules_filename  => ( $opt{'siteconfigpath'} || 0 ),
+    force_ipv4           => ( $opt{'force_ipv4'} || 0 ),
     local_tests_only     => ( $opt{'local'} || 0 ),
     debug                => ( $opt{'debug'} || 0 ),
     paranoid             => ( $opt{'paranoid'} || 0 ),
@@ -2181,6 +2183,7 @@
  -d, --daemonize                    Daemonize
  -h, --help                         Print usage message.
  -i [ipaddr], --listen-ip=ipaddr    Listen on the IP ipaddr
+ --ipv4only, --ipv4-only, --ipv4    Disable attempted use of ipv6 for DNS
  -p port, --port=port               Listen on specified port
  -m num, --max-children=num         Allow maximum num children
  --min-children=num                 Allow minimum num children
@@ -2498,6 +2501,11 @@
 
 Higher priority informational messages that are suitable for logging in normal
 circumstances are available with an area of "info".
+
+=item B< --ipv4only>, B<--ipv4-only>, B<--ipv4>
+
+Do not use IPv6 for DNS tests. Use if the existing tests
+for IPv6 availablity produce incorrect results or crashes.
 
 =item B<-L>, B<--local>