public static SetResponse findRecords( final Message response, final Record queryRecord, final InetAddress source) { final Name name = queryRecord.getName(); final int type = queryRecord.getType(); try { if (!enabled || !Bootstrap.isOperational()) { return SetResponse.ofType(SetResponse.UNKNOWN); } else { final Iterable<DnsResolver> resolverList = DnsResolvers.resolversFor(queryRecord, source); LOG.debug("DnsResolvers.findRecords(): resolvers for " + name + " are: " + resolverList); if (Iterables.isEmpty(resolverList)) { return SetResponse.ofType(SetResponse.UNKNOWN); } else { return DnsResolvers.lookupRecords(response, queryRecord, source); } } } catch (final Exception ex) { LOG.error(ex); LOG.trace(ex, ex); } return SetResponse.ofType(SetResponse.UNKNOWN); }
private static SetResponse lookupRecords( final Message response, final Record query, final InetAddress source) { final Name name = query.getName(); final int type = query.getType(); response.getHeader().setFlag(Flags.RA); // always mark the response w/ the recursion available // bit LOG.debug("DnsResolver: " + RequestType.typeOf(type) + " " + name); for (final DnsResolver r : DnsResolvers.resolversFor(query, source)) { try { final DnsResponse reply = r.lookupRecords(query); if (reply == null) { LOG.debug("DnsResolver: returned null " + name + " using " + r); continue; } if (reply.isAuthoritative()) { // mark response.getHeader().setFlag(Flags.AA); } if (reply.isNxdomain()) { addRRset(name, response, new Record[] {DomainNameRecords.sourceOfAuthority(name)}, type); response.getHeader().setRcode(Rcode.NXDOMAIN); return SetResponse.ofType(SetResponse.NXDOMAIN); } else if (reply.hasAnswer()) { for (ResponseSection s : ResponseSection.values()) { Record[] records = reply.section(s); if (records != null) { addRRset(name, response, records, s.section()); } } return SetResponse.ofType(SetResponse.SUCCESSFUL); } } catch (final Exception ex) { LOG.debug( "DnsResolver: failed for " + name + " using " + r + " because of: " + ex.getMessage(), ex); } } return SetResponse.ofType(SetResponse.UNKNOWN); // no dice, return unknown }
/* (non-Javadoc) * @see com.eucalyptus.dns.Zone#findRecords(org.xbill.DNS.Name, int) */ @Override public SetResponse findRecords(Name name, int type) { if (type == Type.AAAA) return (SetResponse.ofType(SetResponse.SUCCESSFUL)); if (StackConfiguration.USE_INSTANCE_DNS && name.toString().matches("euca-.+{3}-.+{3}-.+{3}-.+{3}\\..*")) { try { String[] tryIp = name.toString() .replaceAll("euca-", "") .replaceAll(VmInstances.INSTANCE_SUBDOMAIN + ".*", "") .split("-"); if (tryIp.length < 4) return super.findRecords(name, type); String ipCandidate = new StringBuffer() .append(tryIp[0]) .append(".") .append(tryIp[1]) .append(".") .append(tryIp[2]) .append(".") .append(tryIp[3]) .toString(); try { VmInstances.lookupByPublicIp(ipCandidate); } catch (Exception e) { try { VmInstances.lookupByPrivateIp(ipCandidate); } catch (Exception e1) { return super.findRecords(name, type); } } InetAddress ip = InetAddress.getByName(ipCandidate); SetResponse resp = new SetResponse(SetResponse.SUCCESSFUL); resp.addRRset(new RRset(new ARecord(name, 1, ttl, ip))); return resp; } catch (Exception e) { return super.findRecords(name, type); } } else if (StackConfiguration.USE_INSTANCE_DNS && name.toString().endsWith(".in-addr.arpa.")) { int index = name.toString().indexOf(".in-addr.arpa."); Name target; if (index > 0) { String ipString = name.toString().substring(0, index); String[] parts = ipString.split("\\."); String ipCandidate; if (parts.length == 4) { ipCandidate = new StringBuffer() .append(parts[3]) .append(".") .append(parts[2]) .append(".") .append(parts[1]) .append(".") .append(parts[0]) .toString(); } else { return super.findRecords(name, type); } try { VmInstance instance = VmInstances.lookupByPublicIp(ipCandidate); target = new Name(instance.getPublicDnsName() + "."); } catch (Exception e) { try { VmInstance instance = VmInstances.lookupByPrivateIp(ipCandidate); target = new Name(instance.getPrivateDnsName() + "."); } catch (Exception e1) { return super.findRecords(name, type); } } SetResponse resp = new SetResponse(SetResponse.SUCCESSFUL); resp.addRRset(new RRset(new PTRRecord(name, DClass.IN, ttl, target))); return resp; } else { return super.findRecords(name, type); } } else { return super.findRecords(name, type); } }