Author: vetinari
Date: Thu Jan 24 09:45:09 2008
New Revision: 835

Modified:
   contrib/vetinari/dnswl

Log:
dnswl: - faster lookup for some non matching addresses
       - add dnswl-info connection note with all info of a successful lookup
       - doc update


Modified: contrib/vetinari/dnswl
==============================================================================
--- contrib/vetinari/dnswl      (original)
+++ contrib/vetinari/dnswl      Thu Jan 24 09:45:09 2008
@@ -9,7 +9,7 @@
 =head1 DESCRIPTION
 
 The B<dnswl> plugin uses the whitelist from L<http://www.dnswl.org/> to set
-a connection note based on the score of the result.
+a connection note (C<dnswl>) based on the score of the result.
 
 You need the rsynced generic-dnswl database on disk (or any other file
 with the same format), see L<http://www.dnswl.org/tech#rsync> on how to
@@ -39,6 +39,33 @@
 running a second time with a smaller override list (B<use this for all but the
 first if you're running this plugin more than once>). Defaults to B<false>.
 
+=head1 ACCESSING DNSWL INFO
+
+Other plugins can get the score via
+  
+  my $score = $self->qp->connection->notes('dnswl');
+  $score = defined $score ? $score : -1;
+
+All other dnswl info about the connection can be found in the C<dnswl-info>
+connection note:
+
+  my $info = $self->qp->connection->notes('dnswl-info');
+  if (exists $info->{id}) {
+      # valid keys:
+      #    id (dnswl.org ID), 
+      #    domain (name or hostname), 
+      #    cat_id (category id),
+      #    category (category name),
+      #    score (numerical score),
+      #    mask (32bit netmask)...
+      ## to get dnswl net/mask entry:
+      ## $ip   = $self->qp->connection->remote_ip;
+      ## $net  = join(".", unpack("C4", pack("C4", split(/\./, $ip)) & $mask));
+      ## $mask = index(unpack("B*", $mask), "0", 0);
+      ## $entry = "$net/". (($mask < 0) : 32 : $mask);
+  }
+
+
 =head1 NOTES
 
 This plugin will add a memory footprint of ca. 12 MiB per process for keeping 
@@ -164,9 +191,22 @@
             $score = -1; 
         }
     }
-
-    $self->qp->connection->notes("dnswl", $score)
-      if defined $score; # undef if $self->{_dnswl_ignore} is true and not 
found
+    
+    if (defined $score) {
+        # undef if $self->{_dnswl_ignore} is true and not found
+        $self->qp->connection->notes("dnswl", $score)
+        defined $id
+          and $self->qp->connection->notes("dnswl-info",
+                {
+                    id       => $id,
+                    domain   => $dom,
+                    score    => $score,
+                    cat_id   => $cat,
+                    category => $categories{$cat},
+                    mask     => $mask, 
+                });
+        return (DECLINED, "dnswl score: $score");
+    }
     return (DECLINED);
 }
 
@@ -208,6 +248,9 @@
 
     my @p = split /\./, $ip;
 
+    return (undef, undef, undef, undef, undef)
+      unless exists $dnswl->{$p[0]}->{$p[1]};
+
     return @{$dnswl->{$p[0]}->{$p[1]}->{$p[2]}->{$p[3]}}
       if exists $dnswl->{$p[0]}->{$p[1]}->{$p[2]}->{$p[3]}; # X.X.X.X/32
 

Reply via email to