notify_out.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. # Copyright (C) 2010-2012 Internet Systems Consortium.
  2. #
  3. # Permission to use, copy, modify, and distribute this software for any
  4. # purpose with or without fee is hereby granted, provided that the above
  5. # copyright notice and this permission notice appear in all copies.
  6. #
  7. # THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SYSTEMS CONSORTIUM
  8. # DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
  9. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
  10. # INTERNET SYSTEMS CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
  11. # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
  12. # FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
  13. # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
  14. # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. import select
  16. import sys
  17. import random
  18. import socket
  19. import threading
  20. import time
  21. import errno
  22. from isc.datasrc import sqlite3_ds
  23. from isc.datasrc import DataSourceClient
  24. from isc.net import addr
  25. import isc
  26. from isc.log_messages.notify_out_messages import *
  27. from isc.statistics import Counters
  28. logger = isc.log.Logger("notify_out")
  29. # there used to be a printed message if this import failed, but if
  30. # we can't import we should not start anyway, and logging an error
  31. # is a bad idea since the logging system is most likely not
  32. # initialized yet. see trac ticket #1103
  33. from isc.dns import *
  34. ZONE_NEW_DATA_READY_CMD = 'zone_new_data_ready'
  35. ZONE_XFRIN_FAILED = 'zone_xfrin_failed'
  36. _MAX_NOTIFY_NUM = 30
  37. _MAX_NOTIFY_TRY_NUM = 5
  38. _EVENT_NONE = 0
  39. _EVENT_READ = 1
  40. _EVENT_TIMEOUT = 2
  41. _NOTIFY_TIMEOUT = 1
  42. # define the rcode for parsing notify reply message
  43. _REPLY_OK = 0
  44. _BAD_QUERY_ID = 1
  45. _BAD_QUERY_NAME = 2
  46. _BAD_OPCODE = 3
  47. _BAD_QR = 4
  48. _BAD_REPLY_PACKET = 5
  49. SOCK_DATA = b's'
  50. # borrowed from xfrin.py @ #1298. We should eventually unify it.
  51. def format_zone_str(zone_name, zone_class):
  52. """Helper function to format a zone name and class as a string of
  53. the form '<name>/<class>'.
  54. Parameters:
  55. zone_name (isc.dns.Name) name to format
  56. zone_class (isc.dns.RRClass) class to format
  57. """
  58. return zone_name.to_text() + '/' + str(zone_class)
  59. class NotifyOutDataSourceError(Exception):
  60. """An exception raised when data source error happens within notify out.
  61. This exception is expected to be caught within the notify_out module.
  62. """
  63. pass
  64. class ZoneNotifyInfo:
  65. '''This class keeps track of notify-out information for one zone.'''
  66. def __init__(self, zone_name_, class_):
  67. self._notify_current = None
  68. self._slave_index = 0
  69. self._sock = None
  70. self.notify_slaves = []
  71. self.zone_name = zone_name_
  72. self.zone_class = class_
  73. self.notify_msg_id = 0
  74. # Absolute time for next notify reply. When the zone is preparing for
  75. # sending notify message, notify_timeout_ is set to now, that means
  76. # the first sending is triggered by the 'Timeout' mechanism.
  77. self.notify_timeout = None
  78. self.notify_try_num = 0 # Notify times sending to one target.
  79. def set_next_notify_target(self):
  80. if self._slave_index < (len(self.notify_slaves) - 1):
  81. self._slave_index += 1
  82. self._notify_current = self.notify_slaves[self._slave_index]
  83. else:
  84. self._notify_current = None
  85. def prepare_notify_out(self):
  86. '''Set notify timeout time to now'''
  87. self.notify_timeout = time.time()
  88. self.notify_try_num = 0
  89. self._slave_index = 0
  90. if len(self.notify_slaves) > 0:
  91. self._notify_current = self.notify_slaves[0]
  92. def finish_notify_out(self):
  93. if self._sock:
  94. self._sock.close()
  95. self._sock = None
  96. self.notify_timeout = None
  97. def create_socket(self, dest_addr):
  98. self._sock = socket.socket(addr.IPAddr(dest_addr).family,
  99. socket.SOCK_DGRAM)
  100. return self._sock
  101. def get_socket(self):
  102. return self._sock
  103. def get_current_notify_target(self):
  104. return self._notify_current
  105. class NotifyOut:
  106. '''This class is used to handle notify logic for all zones(sending
  107. notify message to its slaves). notify service can be started by
  108. calling dispatcher(), and it can be stopped by calling shutdown()
  109. in another thread. '''
  110. def __init__(self, datasrc_file, verbose=True):
  111. self._notify_infos = {} # key is (zone_name, zone_class)
  112. self._waiting_zones = []
  113. self._notifying_zones = []
  114. self._serving = False
  115. self._read_sock, self._write_sock = socket.socketpair()
  116. self._read_sock.setblocking(False)
  117. self.notify_num = 0 # the count of in progress notifies
  118. self._verbose = verbose
  119. self._lock = threading.Lock()
  120. self._db_file = datasrc_file
  121. self._init_notify_out(datasrc_file)
  122. # Use nonblock event to eliminate busy loop
  123. # If there are no notifying zones, clear the event bit and wait.
  124. self._nonblock_event = threading.Event()
  125. self._counters = Counters()
  126. def _init_notify_out(self, datasrc_file):
  127. '''Get all the zones name and its notify target's address.
  128. TODO, currently the zones are got by going through the zone
  129. table in database. There should be a better way to get them
  130. and also the setting 'also_notify', and there should be one
  131. mechanism to cover the changed datasrc.
  132. '''
  133. self._db_file = datasrc_file
  134. for zone_name, zone_class in sqlite3_ds.get_zones_info(datasrc_file):
  135. zone_id = (zone_name, zone_class)
  136. self._notify_infos[zone_id] = ZoneNotifyInfo(zone_name, zone_class)
  137. slaves = self._get_notify_slaves_from_ns(Name(zone_name),
  138. RRClass(zone_class))
  139. for item in slaves:
  140. self._notify_infos[zone_id].notify_slaves.append((item, 53))
  141. def add_slave(self, address, port):
  142. for zone_name, zone_class in sqlite3_ds.get_zones_info(self._db_file):
  143. zone_id = (zone_name, zone_class)
  144. if zone_id in self._notify_infos:
  145. self._notify_infos[zone_id].notify_slaves.append((address, port))
  146. def send_notify(self, zone_name, zone_class='IN'):
  147. '''Send notify to one zone's slaves, this function is
  148. the only interface for class NotifyOut which can be called
  149. by other object.
  150. Internally, the function only set the zone's notify-reply
  151. timeout to now, then notify message will be sent out.
  152. Returns False if the zone/class is not known, True if it is
  153. (even if there are no slaves)'''
  154. if zone_name[len(zone_name) - 1] != '.':
  155. zone_name += '.'
  156. zone_id = (zone_name, zone_class)
  157. if zone_id not in self._notify_infos:
  158. return False
  159. # Has no slave servers, skip it.
  160. if (len(self._notify_infos[zone_id].notify_slaves) <= 0):
  161. return True
  162. with self._lock:
  163. if (self.notify_num >= _MAX_NOTIFY_NUM) or (zone_id in self._notifying_zones):
  164. if zone_id not in self._waiting_zones:
  165. self._waiting_zones.append(zone_id)
  166. else:
  167. self._notify_infos[zone_id].prepare_notify_out()
  168. self.notify_num += 1
  169. self._notifying_zones.append(zone_id)
  170. if not self._nonblock_event.isSet():
  171. self._nonblock_event.set()
  172. return True
  173. def _dispatcher(self, started_event):
  174. started_event.set() # Let the master know we are alive already
  175. while self._serving:
  176. replied_zones, not_replied_zones = self._wait_for_notify_reply()
  177. for name_ in replied_zones:
  178. self._zone_notify_handler(replied_zones[name_], _EVENT_READ)
  179. for name_ in not_replied_zones:
  180. if not_replied_zones[name_].notify_timeout <= time.time():
  181. self._zone_notify_handler(not_replied_zones[name_], _EVENT_TIMEOUT)
  182. def dispatcher(self, daemon=False):
  183. """Spawns a thread that will handle notify related events.
  184. If one zone get the notify reply before timeout, call the
  185. handle to process the reply. If one zone can't get the notify
  186. before timeout, call the handler to resend notify or notify
  187. next slave.
  188. The thread can be stopped by calling shutdown().
  189. Returns the thread object to anyone interested.
  190. """
  191. if self._serving:
  192. raise RuntimeError(
  193. 'Dispatcher already running, tried to start twice')
  194. # Prepare for launch
  195. self._serving = True
  196. started_event = threading.Event()
  197. # Start
  198. self._thread = threading.Thread(target=self._dispatcher,
  199. args=[started_event])
  200. if daemon:
  201. self._thread.daemon = daemon
  202. self._thread.start()
  203. # Wait for it to get started
  204. started_event.wait()
  205. # Return it to anyone listening
  206. return self._thread
  207. def shutdown(self):
  208. """Stop the dispatcher() thread. Blocks until the thread stopped."""
  209. if not self._serving:
  210. raise RuntimeError('Tried to stop while not running')
  211. # Ask it to stop
  212. self._serving = False
  213. if not self._nonblock_event.isSet():
  214. # set self._nonblock_event to stop waiting for new notifying zones.
  215. self._nonblock_event.set()
  216. self._write_sock.send(SOCK_DATA) # make self._read_sock be readable.
  217. # Wait for it
  218. self._thread.join()
  219. # Clean up
  220. self._write_sock.close()
  221. self._write_sock = None
  222. self._read_sock.close()
  223. self._read_sock = None
  224. self._thread = None
  225. def _get_rdata_data(self, rr):
  226. return rr[7].strip()
  227. def _get_notify_slaves_from_ns(self, zone_name, zone_class):
  228. '''Get all NS records, then remove the primary master from ns rrset,
  229. then use the name in NS record rdata part to get the a/aaaa records
  230. in the same zone. the targets listed in a/aaaa record rdata are treated
  231. as the notify slaves.
  232. Note: this is the simplest way to get the address of slaves,
  233. but not correct, it can't handle the delegation slaves, or the CNAME
  234. and DNAME logic.
  235. TODO. the function should be provided by one library.
  236. '''
  237. # Prepare data source client. This should eventually be moved to
  238. # an earlier stage of initialization and also support multiple
  239. # data sources.
  240. datasrc_config = '{ "database_file": "' + self._db_file + '"}'
  241. try:
  242. ds_client = DataSourceClient('sqlite3', datasrc_config)
  243. except isc.datasrc.Error as ex:
  244. logger.error(NOTIFY_OUT_DATASRC_ACCESS_FAILURE, ex)
  245. return []
  246. result, finder = ds_client.find_zone(zone_name)
  247. if result is not DataSourceClient.SUCCESS:
  248. logger.error(NOTIFY_OUT_DATASRC_ZONE_NOT_FOUND,
  249. format_zone_str(zone_name, zone_class))
  250. return []
  251. result, ns_rrset, _ = finder.find(zone_name, RRType.NS)
  252. if result is not finder.SUCCESS or ns_rrset is None:
  253. logger.warn(NOTIFY_OUT_ZONE_NO_NS,
  254. format_zone_str(zone_name, zone_class))
  255. return []
  256. result, soa_rrset, _ = finder.find(zone_name, RRType.SOA)
  257. if result is not finder.SUCCESS or soa_rrset is None or \
  258. soa_rrset.get_rdata_count() != 1:
  259. logger.warn(NOTIFY_OUT_ZONE_BAD_SOA,
  260. format_zone_str(zone_name, zone_class))
  261. return [] # broken zone anyway, stop here.
  262. soa_mname = Name(soa_rrset.get_rdata()[0].to_text().split(' ')[0])
  263. addrs = []
  264. for ns_rdata in ns_rrset.get_rdata():
  265. ns_name = Name(ns_rdata.to_text())
  266. if soa_mname == ns_name:
  267. continue
  268. ns_result, ns_finder = ds_client.find_zone(ns_name)
  269. if ns_result is DataSourceClient.SUCCESS or \
  270. ns_result is DataSourceClient.PARTIALMATCH:
  271. result, rrset, _ = ns_finder.find(ns_name, RRType.A)
  272. if result is ns_finder.SUCCESS and rrset is not None:
  273. addrs.extend([a.to_text() for a in rrset.get_rdata()])
  274. result, rrset, _ = ns_finder.find(ns_name, RRType.AAAA)
  275. if result is ns_finder.SUCCESS and rrset is not None:
  276. addrs.extend([aaaa.to_text()
  277. for aaaa in rrset.get_rdata()])
  278. return addrs
  279. def _prepare_select_info(self):
  280. '''
  281. Prepare the information for select(), returned
  282. value is one tuple
  283. (block_timeout, valid_socks, notifying_zones)
  284. block_timeout: the timeout for select()
  285. valid_socks: sockets list for waiting ready reading.
  286. notifying_zones: the zones which have been triggered
  287. for notify.
  288. '''
  289. valid_socks = []
  290. notifying_zones = {}
  291. min_timeout = None
  292. for info in self._notify_infos:
  293. sock = self._notify_infos[info].get_socket()
  294. if sock:
  295. valid_socks.append(sock)
  296. # If a non null timeout is specified notify has been scheduled
  297. # (in which case socket is still None) or sent (with a valid
  298. # socket). In either case we need add the zone to notifying_zones
  299. # so that we can invoke the appropriate event for the zone after
  300. # select.
  301. tmp_timeout = self._notify_infos[info].notify_timeout
  302. if tmp_timeout is not None:
  303. notifying_zones[info] = self._notify_infos[info]
  304. if min_timeout is not None:
  305. if tmp_timeout < min_timeout:
  306. min_timeout = tmp_timeout
  307. else:
  308. min_timeout = tmp_timeout
  309. block_timeout = None
  310. if min_timeout is not None:
  311. block_timeout = min_timeout - time.time()
  312. if block_timeout < 0:
  313. block_timeout = 0
  314. return (block_timeout, valid_socks, notifying_zones)
  315. def _wait_for_notify_reply(self):
  316. '''
  317. Receive notify replies in specified time. returned value
  318. is one tuple:(replied_zones, not_replied_zones). ({}, {}) is
  319. returned if shutdown() was called.
  320. replied_zones: the zones which receive notify reply.
  321. not_replied_zones: the zones which haven't got notify reply.
  322. '''
  323. (block_timeout, valid_socks, notifying_zones) = \
  324. self._prepare_select_info()
  325. # This is None only during some tests
  326. if self._read_sock is not None:
  327. valid_socks.append(self._read_sock)
  328. # Currently, there is no notifying zones, waiting for zones to send notify
  329. if block_timeout is None:
  330. self._nonblock_event.clear()
  331. self._nonblock_event.wait()
  332. # has new notifying zone, check immediately
  333. block_timeout = 0
  334. try:
  335. r_fds, w, e = select.select(valid_socks, [], [], block_timeout)
  336. except select.error as err:
  337. if err.args[0] != errno.EINTR:
  338. return {}, {}
  339. if self._read_sock in r_fds: # user has called shutdown()
  340. try:
  341. # Noone should write anything else than shutdown
  342. assert self._read_sock.recv(len(SOCK_DATA)) == SOCK_DATA
  343. return {}, {}
  344. except socket.error as e: # Workaround around rare linux bug
  345. if e.errno != errno.EAGAIN and e.errno != errno.EWOULDBLOCK:
  346. raise
  347. not_replied_zones = {}
  348. replied_zones = {}
  349. for info in notifying_zones:
  350. if notifying_zones[info].get_socket() in r_fds:
  351. replied_zones[info] = notifying_zones[info]
  352. else:
  353. not_replied_zones[info] = notifying_zones[info]
  354. return replied_zones, not_replied_zones
  355. def _zone_notify_handler(self, zone_notify_info, event_type):
  356. '''Notify handler for one zone. The first notify message is
  357. always triggered by the event "_EVENT_TIMEOUT" since when
  358. one zone prepares to notify its slaves, its notify_timeout
  359. is set to now, which is used to trigger sending notify
  360. message when dispatcher() scanning zones. '''
  361. tgt = zone_notify_info.get_current_notify_target()
  362. if event_type == _EVENT_READ:
  363. reply = self._get_notify_reply(zone_notify_info.get_socket(), tgt)
  364. if reply is not None:
  365. if self._handle_notify_reply(zone_notify_info, reply, tgt):
  366. self._notify_next_target(zone_notify_info)
  367. elif event_type == _EVENT_TIMEOUT and zone_notify_info.notify_try_num > 0:
  368. logger.info(NOTIFY_OUT_TIMEOUT, tgt[0], tgt[1])
  369. tgt = zone_notify_info.get_current_notify_target()
  370. if tgt:
  371. zone_notify_info.notify_try_num += 1
  372. if zone_notify_info.notify_try_num > _MAX_NOTIFY_TRY_NUM:
  373. logger.warn(NOTIFY_OUT_RETRY_EXCEEDED, tgt[0], tgt[1],
  374. _MAX_NOTIFY_TRY_NUM)
  375. self._notify_next_target(zone_notify_info)
  376. else:
  377. # set exponential backoff according rfc1996 section 3.6
  378. retry_timeout = _NOTIFY_TIMEOUT * pow(2, zone_notify_info.notify_try_num)
  379. zone_notify_info.notify_timeout = time.time() + retry_timeout
  380. self._send_notify_message_udp(zone_notify_info, tgt)
  381. def _notify_next_target(self, zone_notify_info):
  382. '''Notify next address for the same zone. If all the targets
  383. has been notified, notify the first zone in waiting list. '''
  384. zone_notify_info.notify_try_num = 0
  385. zone_notify_info.set_next_notify_target()
  386. tgt = zone_notify_info.get_current_notify_target()
  387. if not tgt:
  388. zone_notify_info.finish_notify_out()
  389. with self._lock:
  390. self.notify_num -= 1
  391. self._notifying_zones.remove((zone_notify_info.zone_name,
  392. zone_notify_info.zone_class))
  393. # trigger notify out for waiting zones
  394. if len(self._waiting_zones) > 0:
  395. zone_id = self._waiting_zones.pop(0)
  396. self._notify_infos[zone_id].prepare_notify_out()
  397. self.notify_num += 1
  398. self._notifying_zones.append(zone_id)
  399. if not self._nonblock_event.isSet():
  400. self._nonblock_event.set()
  401. def _send_notify_message_udp(self, zone_notify_info, addrinfo):
  402. msg, qid = self._create_notify_message(
  403. Name(zone_notify_info.zone_name),
  404. RRClass(zone_notify_info.zone_class))
  405. render = MessageRenderer()
  406. render.set_length_limit(512)
  407. msg.to_wire(render)
  408. zone_notify_info.notify_msg_id = qid
  409. try:
  410. sock = zone_notify_info.create_socket(addrinfo[0])
  411. sock.sendto(render.get_data(), 0, addrinfo)
  412. # count notifying by IPv4 or IPv6 for statistics
  413. if zone_notify_info.get_socket().family == socket.AF_INET:
  414. self._counters.inc('zones', zone_notify_info.zone_name,
  415. 'notifyoutv4')
  416. elif zone_notify_info.get_socket().family == socket.AF_INET6:
  417. self._counters.inc('zones', zone_notify_info.zone_name,
  418. 'notifyoutv6')
  419. logger.info(NOTIFY_OUT_SENDING_NOTIFY, addrinfo[0],
  420. addrinfo[1])
  421. except (socket.error, addr.InvalidAddress) as err:
  422. logger.error(NOTIFY_OUT_SOCKET_ERROR, addrinfo[0],
  423. addrinfo[1], err)
  424. return False
  425. except addr.InvalidAddress as iae:
  426. logger.error(NOTIFY_OUT_INVALID_ADDRESS, addrinfo[0],
  427. addrinfo[1], iae)
  428. return False
  429. return True
  430. def _create_notify_message(self, zone_name, zone_class):
  431. msg = Message(Message.RENDER)
  432. qid = random.randint(0, 0xFFFF)
  433. msg.set_qid(qid)
  434. msg.set_opcode(Opcode.NOTIFY)
  435. msg.set_rcode(Rcode.NOERROR)
  436. msg.set_header_flag(Message.HEADERFLAG_AA)
  437. msg.add_question(Question(zone_name, zone_class, RRType.SOA))
  438. msg.add_rrset(Message.SECTION_ANSWER, self._get_zone_soa(zone_name,
  439. zone_class))
  440. return msg, qid
  441. def _get_zone_soa(self, zone_name, zone_class):
  442. # We create (and soon drop) the data source client here because
  443. # clients should be thread specific. We could let the main thread
  444. # loop (_dispatcher) create and retain the client in order to avoid
  445. # the overhead when we generalize the interface (and we may also
  446. # revisit the design of notify_out more substantially anyway).
  447. datasrc_config = '{ "database_file": "' + self._db_file + '"}'
  448. result, finder = DataSourceClient('sqlite3',
  449. datasrc_config).find_zone(zone_name)
  450. if result is not DataSourceClient.SUCCESS:
  451. raise NotifyOutDataSourceError('_get_zone_soa: Zone ' +
  452. zone_name.to_text() + '/' +
  453. zone_class.to_text() + ' not found')
  454. result, soa_rrset, _ = finder.find(zone_name, RRType.SOA)
  455. if result is not finder.SUCCESS or soa_rrset is None or \
  456. soa_rrset.get_rdata_count() != 1:
  457. raise NotifyOutDataSourceError('_get_zone_soa: Zone ' +
  458. zone_name.to_text() + '/' +
  459. zone_class.to_text() +
  460. ' is broken: no valid SOA found')
  461. return soa_rrset
  462. def _handle_notify_reply(self, zone_notify_info, msg_data, from_addr):
  463. '''Parse the notify reply message.
  464. rcode will not checked here, If we get the response
  465. from the slave, it means the slaves has got the notify.'''
  466. msg = Message(Message.PARSE)
  467. try:
  468. msg.from_wire(msg_data)
  469. if not msg.get_header_flag(Message.HEADERFLAG_QR):
  470. logger.warn(NOTIFY_OUT_REPLY_QR_NOT_SET, from_addr[0],
  471. from_addr[1])
  472. return _BAD_QR
  473. if msg.get_qid() != zone_notify_info.notify_msg_id:
  474. logger.warn(NOTIFY_OUT_REPLY_BAD_QID, from_addr[0],
  475. from_addr[1], msg.get_qid(),
  476. zone_notify_info.notify_msg_id)
  477. return _BAD_QUERY_ID
  478. question = msg.get_question()[0]
  479. if question.get_name() != Name(zone_notify_info.zone_name):
  480. logger.warn(NOTIFY_OUT_REPLY_BAD_QUERY_NAME, from_addr[0],
  481. from_addr[1], question.get_name().to_text(),
  482. Name(zone_notify_info.zone_name).to_text())
  483. return _BAD_QUERY_NAME
  484. if msg.get_opcode() != Opcode.NOTIFY:
  485. logger.warn(NOTIFY_OUT_REPLY_BAD_OPCODE, from_addr[0],
  486. from_addr[1], msg.get_opcode().to_text())
  487. return _BAD_OPCODE
  488. except Exception as err:
  489. # We don't care what exception, just report it?
  490. logger.error(NOTIFY_OUT_REPLY_UNCAUGHT_EXCEPTION, err)
  491. return _BAD_REPLY_PACKET
  492. logger.debug(logger.DBGLVL_TRACE_BASIC, NOTIFY_OUT_REPLY_RECEIVED,
  493. zone_notify_info.zone_name, zone_notify_info.zone_class,
  494. from_addr[0], from_addr[1], msg.get_rcode())
  495. return _REPLY_OK
  496. def _get_notify_reply(self, sock, tgt_addr):
  497. try:
  498. msg, addr = sock.recvfrom(512)
  499. except socket.error as err:
  500. logger.error(NOTIFY_OUT_SOCKET_RECV_ERROR, tgt_addr[0],
  501. tgt_addr[1], err)
  502. return None
  503. return msg