Search in sources :

Example 1 with A

use of org.minidns.record.A in project minidns by MiniDNS.

the class IterativeDNSClient method queryRecursive.

private DNSMessage queryRecursive(ResolutionState resolutionState, DNSMessage q) throws IOException {
    InetAddress primaryTarget = null, secondaryTarget = null;
    Question question = q.getQuestion();
    DNSName parent = question.name.getParent();
    switch(ipVersionSetting) {
        case v4only:
            for (A a : getCachedIPv4NameserverAddressesFor(parent)) {
                if (primaryTarget == null) {
                    primaryTarget = a.getInetAddress();
                    continue;
                }
                secondaryTarget = a.getInetAddress();
                break;
            }
            break;
        case v6only:
            for (AAAA aaaa : getCachedIPv6NameserverAddressesFor(parent)) {
                if (primaryTarget == null) {
                    primaryTarget = aaaa.getInetAddress();
                    continue;
                }
                secondaryTarget = aaaa.getInetAddress();
                break;
            }
            break;
        case v4v6:
            InetAddress[] v4v6targets = getTargets(getCachedIPv4NameserverAddressesFor(parent), getCachedIPv6NameserverAddressesFor(parent));
            primaryTarget = v4v6targets[0];
            secondaryTarget = v4v6targets[1];
            break;
        case v6v4:
            InetAddress[] v6v4targets = getTargets(getCachedIPv6NameserverAddressesFor(parent), getCachedIPv4NameserverAddressesFor(parent));
            primaryTarget = v6v4targets[0];
            secondaryTarget = v6v4targets[1];
            break;
        default:
            throw new AssertionError();
    }
    DNSName authoritativeZone = parent;
    if (primaryTarget == null) {
        authoritativeZone = DNSName.ROOT;
        switch(ipVersionSetting) {
            case v4only:
                primaryTarget = getRandomIpv4RootServer();
                break;
            case v6only:
                primaryTarget = getRandomIpv6RootServer();
                break;
            case v4v6:
                primaryTarget = getRandomIpv4RootServer();
                secondaryTarget = getRandomIpv6RootServer();
                break;
            case v6v4:
                primaryTarget = getRandomIpv6RootServer();
                secondaryTarget = getRandomIpv4RootServer();
                break;
        }
    }
    List<IOException> ioExceptions = new LinkedList<>();
    try {
        return queryRecursive(resolutionState, q, primaryTarget, authoritativeZone);
    } catch (IOException ioException) {
        abortIfFatal(ioException);
        ioExceptions.add(ioException);
    }
    if (secondaryTarget != null) {
        try {
            return queryRecursive(resolutionState, q, secondaryTarget, authoritativeZone);
        } catch (IOException ioException) {
            ioExceptions.add(ioException);
        }
    }
    MultipleIoException.throwIfRequired(ioExceptions);
    return null;
}
Also used : AAAA(org.minidns.record.AAAA) A(org.minidns.record.A) Question(org.minidns.dnsmessage.Question) IOException(java.io.IOException) DNSName(org.minidns.dnsname.DNSName) InetAddress(java.net.InetAddress) AAAA(org.minidns.record.AAAA) LinkedList(java.util.LinkedList)

Example 2 with A

use of org.minidns.record.A in project minidns by MiniDNS.

the class DNSMessageTest method testALookup.

@Test
public void testALookup() throws Exception {
    DNSMessage m = getMessageFromResource("sun-a");
    assertFalse(m.authoritativeAnswer);
    List<Record<? extends Data>> answers = m.answerSection;
    assertEquals(2, answers.size());
    Record<? extends Data> cname = answers.get(0);
    Record<? extends Data> a = answers.get(1);
    assertTrue(cname.getPayload() instanceof RRWithTarget);
    assertEquals(TYPE.CNAME, cname.getPayload().getType());
    assertCsEquals("legacy-sun.oraclegha.com", ((RRWithTarget) (cname.getPayload())).target);
    assertCsEquals("legacy-sun.oraclegha.com", a.name);
    assertTrue(a.getPayload() instanceof A);
    assertEquals(TYPE.A, a.getPayload().getType());
    assertCsEquals("156.151.59.35", a.getPayload().toString());
}
Also used : AAAA(org.minidns.record.AAAA) SOA(org.minidns.record.SOA) A(org.minidns.record.A) RRWithTarget(org.minidns.record.RRWithTarget) Record(org.minidns.record.Record) Data(org.minidns.record.Data) DNSMessage(org.minidns.dnsmessage.DNSMessage) Test(org.junit.Test)

Example 3 with A

use of org.minidns.record.A in project minidns by MiniDNS.

the class HlaTest method idnSrvTest.

@IntegrationTest
public static void idnSrvTest() throws IOException {
    ResolverResult<SRV> res = ResolverApi.INSTANCE.resolve("_xmpp-client._tcp.im.plä.net", SRV.class);
    Set<SRV> answers = res.getAnswers();
    assertEquals(1, answers.size());
    SRV srv = answers.iterator().next();
    ResolverResult<A> aRes = ResolverApi.INSTANCE.resolve(srv.target, A.class);
    assertTrue(aRes.wasSuccessful());
}
Also used : A(org.minidns.record.A) SRV(org.minidns.record.SRV)

Example 4 with A

use of org.minidns.record.A in project Smack by igniterealtime.

the class MiniDnsResolver method lookupHostAddress0.

@Override
protected List<InetAddress> lookupHostAddress0(final DnsName name, List<RemoteConnectionEndpointLookupFailure> lookupFailures, DnssecMode dnssecMode) {
    final ResolverApi resolver = getResolver(dnssecMode);
    final ResolverResult<A> aResult;
    final ResolverResult<AAAA> aaaaResult;
    try {
        aResult = resolver.resolve(name, A.class);
        aaaaResult = resolver.resolve(name, AAAA.class);
    } catch (IOException e) {
        RemoteConnectionEndpointLookupFailure failure = new RemoteConnectionEndpointLookupFailure.DnsLookupFailure(name, e);
        lookupFailures.add(failure);
        return null;
    }
    if (!aResult.wasSuccessful() && !aaaaResult.wasSuccessful()) {
        // Both results where not successful.
        RemoteConnectionEndpointLookupFailure failureA = new RemoteConnectionEndpointLookupFailure.DnsLookupFailure(name, getExceptionFrom(aResult));
        lookupFailures.add(failureA);
        RemoteConnectionEndpointLookupFailure failureAaaa = new RemoteConnectionEndpointLookupFailure.DnsLookupFailure(name, getExceptionFrom(aaaaResult));
        lookupFailures.add(failureAaaa);
        return null;
    }
    if (shouldAbortIfNotAuthentic(name, dnssecMode, aResult, lookupFailures) || shouldAbortIfNotAuthentic(name, dnssecMode, aaaaResult, lookupFailures)) {
        return null;
    }
    // TODO: Use ResolverResult.getAnswersOrEmptySet() once we updated MiniDNS.
    Set<A> aResults;
    if (aResult.wasSuccessful()) {
        aResults = aResult.getAnswers();
    } else {
        aResults = Collections.emptySet();
    }
    // TODO: Use ResolverResult.getAnswersOrEmptySet() once we updated MiniDNS.
    Set<AAAA> aaaaResults;
    if (aaaaResult.wasSuccessful()) {
        aaaaResults = aaaaResult.getAnswers();
    } else {
        aaaaResults = Collections.emptySet();
    }
    List<InetAddress> inetAddresses = new ArrayList<>(aResults.size() + aaaaResults.size());
    for (A a : aResults) {
        InetAddress inetAddress;
        try {
            inetAddress = InetAddress.getByAddress(a.getIp());
        } catch (UnknownHostException e) {
            continue;
        }
        inetAddresses.add(inetAddress);
    }
    for (AAAA aaaa : aaaaResults) {
        InetAddress inetAddress;
        try {
            inetAddress = InetAddress.getByAddress(name.ace, aaaa.getIp());
        } catch (UnknownHostException e) {
            continue;
        }
        inetAddresses.add(inetAddress);
    }
    return inetAddresses;
}
Also used : AAAA(org.minidns.record.AAAA) A(org.minidns.record.A) UnknownHostException(java.net.UnknownHostException) RemoteConnectionEndpointLookupFailure(org.jivesoftware.smack.util.rce.RemoteConnectionEndpointLookupFailure) DnssecResolverApi(org.minidns.hla.DnssecResolverApi) ResolverApi(org.minidns.hla.ResolverApi) ArrayList(java.util.ArrayList) IOException(java.io.IOException) InetAddress(java.net.InetAddress) AAAA(org.minidns.record.AAAA)

Example 5 with A

use of org.minidns.record.A in project minidns by MiniDNS.

the class SrvResolverResult method getSortedSrvResolvedAddresses.

public List<ResolvedSrvRecord> getSortedSrvResolvedAddresses() throws IOException {
    if (sortedSrvResolvedAddresses != null) {
        return sortedSrvResolvedAddresses;
    }
    throwIseIfErrorResponse();
    List<SRV> srvRecords = SrvUtil.sortSrvRecords(getAnswers());
    List<ResolvedSrvRecord> res = new ArrayList<>(srvRecords.size());
    for (SRV srvRecord : srvRecords) {
        ResolverResult<A> aRecordsResult = null;
        ResolverResult<AAAA> aaaaRecordsResult = null;
        Set<A> aRecords = Collections.emptySet();
        if (ipVersion.v4) {
            aRecordsResult = resolver.resolve(srvRecord.target, A.class);
            if (aRecordsResult.wasSuccessful() && !aRecordsResult.hasUnverifiedReasons()) {
                aRecords = aRecordsResult.getAnswers();
            }
        }
        Set<AAAA> aaaaRecords = Collections.emptySet();
        if (ipVersion.v6) {
            aaaaRecordsResult = resolver.resolve(srvRecord.target, AAAA.class);
            if (aaaaRecordsResult.wasSuccessful() && !aaaaRecordsResult.hasUnverifiedReasons()) {
                aaaaRecords = aaaaRecordsResult.getAnswers();
            }
        }
        if (aRecords.isEmpty() && aaaaRecords.isEmpty()) {
            /*
                ResolverResult<CNAME> cnameRecordResult = resolve(srvRecord.name, CNAME.class);
                if (cnameRecordResult.wasSuccessful()) {
                }
                */
            continue;
        }
        List<InternetAddressRR> srvAddresses = new ArrayList<>(aRecords.size() + aaaaRecords.size());
        switch(ipVersion) {
            case v4only:
                for (A a : aRecords) {
                    srvAddresses.add(a);
                }
                break;
            case v6only:
                for (AAAA aaaa : aaaaRecords) {
                    srvAddresses.add(aaaa);
                }
                break;
            case v4v6:
                for (A a : aRecords) {
                    srvAddresses.add(a);
                }
                for (AAAA aaaa : aaaaRecords) {
                    srvAddresses.add(aaaa);
                }
                break;
            case v6v4:
                for (AAAA aaaa : aaaaRecords) {
                    srvAddresses.add(aaaa);
                }
                for (A a : aRecords) {
                    srvAddresses.add(a);
                }
                break;
        }
        ResolvedSrvRecord resolvedSrvAddresses = new ResolvedSrvRecord(question.name, srvRecord, srvAddresses, aRecordsResult, aaaaRecordsResult);
        res.add(resolvedSrvAddresses);
    }
    sortedSrvResolvedAddresses = res;
    return res;
}
Also used : AAAA(org.minidns.record.AAAA) A(org.minidns.record.A) ArrayList(java.util.ArrayList) SRV(org.minidns.record.SRV) AAAA(org.minidns.record.AAAA) InternetAddressRR(org.minidns.record.InternetAddressRR)

Aggregations

A (org.minidns.record.A)6 AAAA (org.minidns.record.AAAA)4 ArrayList (java.util.ArrayList)3 IOException (java.io.IOException)2 InetAddress (java.net.InetAddress)2 RemoteConnectionEndpointLookupFailure (org.jivesoftware.smack.util.rce.RemoteConnectionEndpointLookupFailure)2 SRV (org.minidns.record.SRV)2 UnknownHostException (java.net.UnknownHostException)1 LinkedList (java.util.LinkedList)1 SmackException (org.jivesoftware.smack.SmackException)1 UInt16 (org.jivesoftware.smack.datatypes.UInt16)1 RemoteConnectionEndpoint (org.jivesoftware.smack.util.rce.RemoteConnectionEndpoint)1 RemoteConnectionException (org.jivesoftware.smack.util.rce.RemoteConnectionException)1 Test (org.junit.Test)1 Test (org.junit.jupiter.api.Test)1 DNSMessage (org.minidns.dnsmessage.DNSMessage)1 Question (org.minidns.dnsmessage.Question)1 DNSName (org.minidns.dnsname.DNSName)1 DnssecResolverApi (org.minidns.hla.DnssecResolverApi)1 ResolverApi (org.minidns.hla.ResolverApi)1