Changeset 599


Ignore:
Timestamp:
03/21/14 16:44:13 (11 years ago)
Author:
Kris Deugau
Message:

/trunk

Prepare for changes to allow any record in either forward or reverse
zones, no matter how silly.

This commit adds a database function to catch errors with CASTing a
column as inet, so that any place we need to sort records based on the
IP value of a column succeeds by treating non-IP values as 0.0.0.0/0.

Location:
trunk
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r597 r599  
    36673667  foreach my $sf (split /,/, $args{sortby}) {
    36683668    $sf = "r.$sf";
    3669     $sf =~ s/r\.val/CAST (r.val AS inet)/
     3669    $sf =~ s/r\.val/inetlazy(r.val)/
    36703670        if $args{revrec} eq 'y' && $args{defrec} eq 'n';
    36713671    $sf =~ s/r\.type/t.alphaorder/;
     
    43414341##fixme?  may need to narrow things down more by octet-chopping and doing text comparisons before casting.
    43424342  my ($revpatt) = $dbh->selectrow_array("SELECT host FROM records ".
    4343         "WHERE (type in (12,65280,65281,65282,65283,65284)) AND rdns_id = ? AND CAST (val AS inet) >>= ? ".
    4344         "ORDER BY CAST (val AS inet) DESC LIMIT 1", undef, ($revid, $cidr) );
     4343        "WHERE (type in (12,65280,65281,65282,65283,65284)) AND rdns_id = ? AND inetlazy(val) >>= ? ".
     4344        "ORDER BY inetlazy(val) DESC LIMIT 1", undef, ($revid, $cidr) );
    43454345  return $revpatt;
    43464346} # end getRevPattern()
     
    51645164  my $recsth = $dbh->prepare("SELECT host,type,val,distance,weight,port,ttl,record_id,location,extract(epoch from stamp),expires,stampactive ".
    51655165        "FROM records WHERE rdns_id=? AND NOT type=6 ".
    5166         "ORDER BY masklen(CAST(val AS inet)) DESC, CAST(val AS inet)");
     5166        "ORDER BY masklen(inetlazy(val)) DESC, inetlazy(val)");
    51675167  my $revsth = $dbh->prepare("SELECT rdns_id,revnet,status,changed FROM revzones WHERE status=1 ".
    51685168        "ORDER BY masklen(revnet) DESC, rdns_id");
  • trunk/dns.sql

    r543 r599  
    66-- SET SESSION AUTHORIZATION 'dnsdb';
    77
     8-- pre-pg8.3, this must be run as a superuser
     9CREATE LANGUAGE plpgsql;
     10-- it's required for:
     11
     12-- Return proper conversion of string to inet, or 0.0.0.0/0 if the string is
     13-- not a valid inet value.  We need to do this to support "funky" records that
     14-- may not actually have valid IP address values.  Used for ORDER BY
     15CREATE OR REPLACE FUNCTION inetlazy (rdata text) RETURNS inet AS $$
     16BEGIN
     17        RETURN CAST(rdata AS inet);
     18EXCEPTION
     19        WHEN OTHERS THEN
     20                RETURN CAST('0.0.0.0/0' AS inet);
     21END;
     22$$ LANGUAGE plpgsql;
     23
     24
    825-- need a handy place to put eg a DB version identifier - useful for auto-upgrading a DB
    926CREATE TABLE misc (
     
    1431
    1532COPY misc (misc_id, key, value) FROM stdin;
    16 1       dbversion       1.2
     331       dbversion       1.2.4
    1734\.
    1835
Note: See TracChangeset for help on using the changeset viewer.