Ignore:
Timestamp:
Aug 25, 2008, 1:27:07 AM (16 years ago)
Author:
y_z
Message:
  • Search for longest-matching domain name instead of first-matching.
  • ns1.prod.xvm.mit.edu (0.0.0.0) is the primary nameserver for the prod zone.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/sipb-xen-dns/code/dnsserver.py

    r913 r922  
    5757        ttl = 900
    5858        name = name.lower()
     59
     60        # XXX hack for the transition to two separate dev/prod clusters
     61        if 'dev.xvm.mit.edu' in self.domains and name.endswith('prod.xvm.mit.edu'):
     62            # import time, sys
     63            # print time.localtime(), 'handling prod request', name
     64            # sys.stdout.flush()
     65
     66            # Point the client in the right direction for prod requests.
     67            authority = dns.RRHeader('prod.xvm.mit.edu', dns.NS, dns.IN, 3600,
     68                    dns.Record_NS(name='ns1.prod.xvm.mit.edu', ttl=3600), auth=True)
     69            additional = dns.RRHeader('ns1.prod.xvm.mit.edu', dns.A, dns.IN, 3600,
     70                    dns.Record_A(address='0.0.0.0', ttl=3600), auth=True)
     71            return defer.succeed(([], [authority], [additional]))
     72
    5973        if name in self.domains:
    6074            domain = name
    6175        else:
    62             # This works because domain will remain bound after breaking out of the loop
     76            # Look for the longest-matching domain.  (This works because domain
     77            # will remain bound after breaking out of the loop.)
     78            best_domain = ''
    6379            for domain in self.domains:
    64                 if name.endswith('.'+domain):
    65                     break
    66             else: #Not us
     80                if name.endswith('.'+domain) and len(domain) > len(best_domain):
     81                    best_domain = domain
     82            if best_domain == '':
    6783                return defer.fail(failure.Failure(dns.DomainError(name)))
     84            domain = best_domain
    6885        results = []
    6986        authority = []
     
    7188        authority.append(dns.RRHeader(domain, dns.NS, dns.IN,
    7289                                      3600, self.ns, auth=True))
     90
    7391        if cls == dns.IN:
    7492            host = name[:-len(domain)-1]
    75             if not host:
     93            if not host: # Request for the domain itself.
    7694                if type in (dns.A, dns.ALL_RECORDS):
    7795                    record = dns.Record_A(config.dns.nameservers[0].ip, ttl)
     
    85103                    results.append(dns.RRHeader(domain, dns.SOA, dns.IN,
    86104                                                ttl, self.soa, auth=True))
    87             else:
     105            else: # Request for a subdomain.
    88106                if 'passup' in dir(config.dns) and host in config.dns.passup:
    89107                    record = dns.Record_CNAME('%s.%s' % (host, config.dns.parent), ttl)
     
    92110                        [], []))
    93111
    94                 if host:
    95                     value = invirt.database.Machine.get_by(name=host)
    96                     if value is None or not value.nics:
    97                         return defer.fail(failure.Failure(dns.AuthoritativeDomainError(name)))
    98                     ip = value.nics[0].ip
    99                     if ip is None:  #Deactivated?
    100                         return defer.fail(failure.Failure(dns.AuthoritativeDomainError(name)))
     112                value = invirt.database.Machine.get_by(name=host)
     113                if value is None or not value.nics:
     114                    return defer.fail(failure.Failure(dns.AuthoritativeDomainError(name)))
     115                ip = value.nics[0].ip
     116                if ip is None:  #Deactivated?
     117                    return defer.fail(failure.Failure(dns.AuthoritativeDomainError(name)))
     118
    101119                if type in (dns.A, dns.ALL_RECORDS):
    102120                    record = dns.Record_A(ip, ttl)
Note: See TracChangeset for help on using the changeset viewer.