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();
}
}
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;
}
Aggregations