2008-05-24 03:03:22 -04:00
|
|
|
|
|
|
|
USING: kernel vectors sequences combinators random
|
|
|
|
accessors newfx dns dns.cache ;
|
|
|
|
|
|
|
|
IN: dns.resolver
|
|
|
|
|
|
|
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
|
|
|
2008-05-25 06:15:41 -04:00
|
|
|
! Need to cache records even in the case of name error
|
|
|
|
|
2008-05-24 03:03:22 -04:00
|
|
|
: cache-message ( message -- message )
|
|
|
|
dup dup rcode>> NAME-ERROR =
|
|
|
|
[
|
|
|
|
[ question-section>> 1st ]
|
|
|
|
[ authority-section>> [ type>> SOA = ] filter random ttl>> ]
|
|
|
|
bi
|
|
|
|
cache-nx
|
|
|
|
]
|
|
|
|
[
|
|
|
|
{
|
|
|
|
[ answer-section>> cache-add-rrs ]
|
|
|
|
[ authority-section>> cache-add-rrs ]
|
|
|
|
[ additional-section>> cache-add-rrs ]
|
|
|
|
}
|
|
|
|
cleave
|
|
|
|
]
|
|
|
|
if ;
|
|
|
|
|
|
|
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
|
|
|
|
|
|
! Ask and cache the records
|
|
|
|
|
|
|
|
: ask* ( message -- message ) ask cache-message ;
|
|
|
|
|
|
|
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
|
|
|
|
|
|
: canonical/cache ( name -- name )
|
|
|
|
dup CNAME IN query boa cache-get dup vector? ! name result ?
|
|
|
|
[ nip 1st rdata>> ]
|
|
|
|
[ drop ]
|
|
|
|
if ;
|
|
|
|
|
|
|
|
: name->ip/cache ( name -- ip )
|
|
|
|
canonical/cache
|
|
|
|
dup A IN query boa cache-get ! name result
|
|
|
|
{
|
|
|
|
{
|
|
|
|
[ dup NX = ]
|
|
|
|
[ 2drop f ]
|
|
|
|
}
|
|
|
|
{
|
|
|
|
[ dup f = ]
|
|
|
|
[ 2drop f ]
|
|
|
|
}
|
|
|
|
{
|
|
|
|
[ t ]
|
|
|
|
[ nip random rdata>> ]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cond ;
|
|
|
|
|
|
|
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
|
|
|
|
|
|
: canonical/server ( name -- name )
|
2008-05-29 11:11:12 -04:00
|
|
|
dup CNAME IN query boa query->message ask* answer-section>>
|
2008-05-24 03:03:22 -04:00
|
|
|
[ type>> CNAME = ] filter dup empty? not
|
|
|
|
[ nip 1st rdata>> ]
|
|
|
|
[ drop ]
|
|
|
|
if ;
|
|
|
|
|
|
|
|
: name->ip/server ( name -- ip )
|
|
|
|
canonical/server
|
2008-05-29 11:11:54 -04:00
|
|
|
dup A IN query boa query->message ask* answer-section>>
|
2008-05-24 03:03:22 -04:00
|
|
|
[ type>> A = ] filter dup empty? not
|
|
|
|
[ nip random rdata>> ]
|
|
|
|
[ 2drop f ]
|
|
|
|
if ;
|
|
|
|
|
|
|
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
|
|
|
|
|
|
: name->ip ( name -- ip )
|
|
|
|
fully-qualified
|
|
|
|
dup name->ip/cache dup
|
|
|
|
[ nip ]
|
|
|
|
[ drop name->ip/server ]
|
|
|
|
if ;
|