You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by mm...@apache.org on 2010/12/01 02:29:02 UTC

svn commit: r1040847 - /spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/DNSEval.pm

Author: mmartinec
Date: Wed Dec  1 01:29:01 2010
New Revision: 1040847

URL: http://svn.apache.org/viewvc?rev=1040847&view=rev
Log:
Bug 6519: RBL lookups for IPv6 addresses

Modified:
    spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/DNSEval.pm

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/DNSEval.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/DNSEval.pm?rev=1040847&r1=1040846&r2=1040847&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/DNSEval.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/DNSEval.pm Wed Dec  1 01:29:01 2010
@@ -265,10 +265,27 @@ sub check_rbl_backend {
   dbg("dns: only inspecting the following IPs: ".join(", ", @ips));
 
   eval {
-    foreach my $ip (@ips) {
-      next unless ($ip =~ /(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/);
+    local($1,$2,$3,$4);
+    foreach (@ips) {
+      my $revip;
+      if (/(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/) {
+        $revip = "$4.$3.$2.$1";
+      } elsif (/:/ &&  # triage
+               /^ [0-9a-f]{0,4}
+                  (?: : [0-9a-f]{0,4} | \. [0-9]{1,3} ){2,9} $/xsi) {
+        # could be an IPv6 address, let NetAddr::IP check the details
+        my $ip_obj = NetAddr::IP->new6($_);
+        if (!defined $ip_obj) {
+          # invalid IPv6 address, $revip remains undefined
+        } else {
+          # RFC 5782 section 2.4.
+          $revip = lc $ip_obj->network->full6;  # string in a canonical form
+          $revip =~ s/://g;
+          $revip = join('.', reverse split(//,$revip));
+        }
+      }
       $pms->do_rbl_lookup($rule, $set, $type, $rbl_server,
-			   "$4.$3.$2.$1.$rbl_server", $subtest);
+			   $revip . '.' . $rbl_server, $subtest);
     }
   };