private byte[] doAXFR(Name name, Message query, TSIG tsig, TSIGRecord qtsig, Socket s) {
boolean first = true;
Zone zone = this.findBestZone(name);
if (zone == null) {
return errorMessage(query, Rcode.REFUSED);
}
// Check that the IP requesting the AXFR is present as a NS in this zone
boolean axfrAllowed = false;
Iterator<?> nsIterator = zone.getNS().rrs();
while (nsIterator.hasNext()) {
NSRecord record = (NSRecord) nsIterator.next();
try {
String nsIP = InetAddress.getByName(record.getTarget().toString()).getHostAddress();
if (s.getInetAddress().getHostAddress().equals(nsIP)) {
axfrAllowed = true;
break;
}
} catch (UnknownHostException e) {
log.warn("Unable to resolve hostname of nameserver " + record.getTarget() + " in zone " + zone.getOrigin() + " while processing AXFR request from " + s.getRemoteSocketAddress());
}
}
if (!axfrAllowed) {
log.warn("AXFR request of zone " + zone.getOrigin() + " from " + s.getRemoteSocketAddress() + " refused!");
return errorMessage(query, Rcode.REFUSED);
}
Iterator<?> it = zone.AXFR();
try {
DataOutputStream dataOut;
dataOut = new DataOutputStream(s.getOutputStream());
int id = query.getHeader().getID();