Search in sources :

Example 1 with ZoneTransferException

use of org.xbill.DNS.ZoneTransferException in project opennms by OpenNMS.

the class DNSServer method parseConfiguration.

protected void parseConfiguration(final String conffile) throws ConfigurationException, IOException, ZoneTransferException, UnknownHostException {
    final FileInputStream fs;
    final InputStreamReader isr;
    final BufferedReader br;
    try {
        fs = new FileInputStream(conffile);
        isr = new InputStreamReader(fs);
        br = new BufferedReader(isr);
    } catch (final Exception e) {
        LOG.error("Cannot open {}", conffile, e);
        throw new ConfigurationException("unable to read from " + conffile, e);
    }
    try {
        String line = null;
        while ((line = br.readLine()) != null) {
            final StringTokenizer st = new StringTokenizer(line);
            if (!st.hasMoreTokens()) {
                continue;
            }
            final String keyword = st.nextToken();
            if (!st.hasMoreTokens()) {
                LOG.warn("unable to parse line: {}", line);
                continue;
            }
            if (keyword.charAt(0) == '#') {
                continue;
            }
            if (keyword.equals("primary")) {
                addPrimaryZone(st.nextToken(), st.nextToken());
            } else if (keyword.equals("secondary")) {
                addSecondaryZone(st.nextToken(), st.nextToken());
            } else if (keyword.equals("cache")) {
                final Cache cache = new Cache(st.nextToken());
                m_caches.put(Integer.valueOf(DClass.IN), cache);
            } else if (keyword.equals("key")) {
                final String s1 = st.nextToken();
                final String s2 = st.nextToken();
                if (st.hasMoreTokens()) {
                    addTSIG(s1, s2, st.nextToken());
                } else {
                    addTSIG("hmac-md5", s1, s2);
                }
            } else if (keyword.equals("port")) {
                m_ports.add(Integer.valueOf(st.nextToken()));
            } else if (keyword.equals("address")) {
                final String addr = st.nextToken();
                m_addresses.add(Address.getByAddress(addr));
            } else {
                LOG.warn("unknown keyword: {}", keyword);
            }
        }
    } finally {
        fs.close();
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) FileInputStream(java.io.FileInputStream) ZoneTransferException(org.xbill.DNS.ZoneTransferException) InterruptedIOException(java.io.InterruptedIOException) SocketTimeoutException(java.net.SocketTimeoutException) NameTooLongException(org.xbill.DNS.NameTooLongException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) Cache(org.xbill.DNS.Cache)

Example 2 with ZoneTransferException

use of org.xbill.DNS.ZoneTransferException in project opennms by OpenNMS.

the class DnsRequisitionProvider method getRequisitionFor.

@Override
public Requisition getRequisitionFor(DnsRequisitionRequest request) {
    ZoneTransferIn xfer = null;
    List<Record> records = null;
    LOG.debug("connecting to host {}:{}", request.getHost(), request.getPort());
    try {
        try {
            xfer = ZoneTransferIn.newIXFR(new Name(request.getZone()), request.getSerial(), request.getFallback(), request.getHost(), request.getPort(), null);
            records = getRecords(xfer);
        } catch (ZoneTransferException e) {
            // Fallback to AXFR
            String message = "IXFR not supported trying AXFR: " + e;
            LOG.warn(message, e);
            xfer = ZoneTransferIn.newAXFR(new Name(request.getZone()), request.getHost(), null);
            records = getRecords(xfer);
        }
    } catch (IOException | ZoneTransferException e) {
        throw new RuntimeException(e);
    }
    if (records.size() > 0) {
        // for now, set the foreign source to the specified dns zone
        final Requisition r = new Requisition(request.getForeignSource());
        for (Record rec : records) {
            if (matchingRecord(request, rec)) {
                r.insertNode(createRequisitionNode(request, rec));
            }
        }
        return r;
    }
    return null;
}
Also used : ZoneTransferException(org.xbill.DNS.ZoneTransferException) ZoneTransferIn(org.xbill.DNS.ZoneTransferIn) ARecord(org.xbill.DNS.ARecord) AAAARecord(org.xbill.DNS.AAAARecord) Record(org.xbill.DNS.Record) IOException(java.io.IOException) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) Name(org.xbill.DNS.Name)

Aggregations

IOException (java.io.IOException)2 ZoneTransferException (org.xbill.DNS.ZoneTransferException)2 BufferedReader (java.io.BufferedReader)1 FileInputStream (java.io.FileInputStream)1 InputStreamReader (java.io.InputStreamReader)1 InterruptedIOException (java.io.InterruptedIOException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 UnknownHostException (java.net.UnknownHostException)1 StringTokenizer (java.util.StringTokenizer)1 Requisition (org.opennms.netmgt.provision.persist.requisition.Requisition)1 AAAARecord (org.xbill.DNS.AAAARecord)1 ARecord (org.xbill.DNS.ARecord)1 Cache (org.xbill.DNS.Cache)1 Name (org.xbill.DNS.Name)1 NameTooLongException (org.xbill.DNS.NameTooLongException)1 Record (org.xbill.DNS.Record)1 ZoneTransferIn (org.xbill.DNS.ZoneTransferIn)1