ddns.py.in 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. #!@PYTHON@
  2. # Copyright (C) 2011 Internet Systems Consortium.
  3. #
  4. # Permission to use, copy, modify, and distribute this software for any
  5. # purpose with or without fee is hereby granted, provided that the above
  6. # copyright notice and this permission notice appear in all copies.
  7. #
  8. # THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SYSTEMS CONSORTIUM
  9. # DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
  10. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
  11. # INTERNET SYSTEMS CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
  12. # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
  13. # FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
  14. # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
  15. # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. import sys; sys.path.append ('@@PYTHONPATH@@')
  17. import isc
  18. from isc.acl.dns import REQUEST_LOADER
  19. import bind10_config
  20. from isc.dns import *
  21. import isc.ddns.session
  22. from isc.ddns.zone_config import ZoneConfig
  23. from isc.ddns.logger import ClientFormatter, ZoneFormatter
  24. from isc.config.ccsession import *
  25. from isc.cc import SessionError, SessionTimeout, ProtocolError
  26. import isc.util.process
  27. import isc.util.cio.socketsession
  28. from isc.notify.notify_out import ZONE_NEW_DATA_READY_CMD
  29. import isc.server_common.tsig_keyring
  30. from isc.datasrc import DataSourceClient
  31. from isc.server_common.auth_command import auth_loadzone_command
  32. import select
  33. import errno
  34. from isc.log_messages.ddns_messages import *
  35. from optparse import OptionParser, OptionValueError
  36. import os
  37. import os.path
  38. import signal
  39. import socket
  40. isc.log.init("b10-ddns")
  41. logger = isc.log.Logger("ddns")
  42. TRACE_BASIC = logger.DBGLVL_TRACE_BASIC
  43. # Well known path settings. We need to define
  44. # SPECFILE_LOCATION: ddns configuration spec file
  45. # SOCKET_FILE: Unix domain socket file to communicate with b10-auth
  46. # AUTH_SPECFILE_LOCATION: b10-auth configuration spec file (tentatively
  47. # necessarily for sqlite3-only-and-older-datasrc-API stuff). This should be
  48. # gone once we migrate to the new API and start using generalized config.
  49. #
  50. # If B10_FROM_SOURCE is set in the environment, we use data files
  51. # from a directory relative to that, otherwise we use the ones
  52. # installed on the system
  53. if "B10_FROM_SOURCE" in os.environ:
  54. SPECFILE_PATH = os.environ["B10_FROM_SOURCE"] + "/src/bin/ddns"
  55. else:
  56. PREFIX = "@prefix@"
  57. DATAROOTDIR = "@datarootdir@"
  58. SPECFILE_PATH = "@datadir@/@PACKAGE@".replace("${datarootdir}", DATAROOTDIR)
  59. SPECFILE_PATH = SPECFILE_PATH.replace("${prefix}", PREFIX)
  60. if "B10_FROM_BUILD" in os.environ:
  61. AUTH_SPECFILE_PATH = os.environ["B10_FROM_BUILD"] + "/src/bin/auth"
  62. if "B10_FROM_SOURCE_LOCALSTATEDIR" in os.environ:
  63. SOCKET_FILE_PATH = os.environ["B10_FROM_SOURCE_LOCALSTATEDIR"]
  64. else:
  65. SOCKET_FILE_PATH = os.environ["B10_FROM_BUILD"]
  66. else:
  67. SOCKET_FILE_PATH = bind10_config.DATA_PATH
  68. AUTH_SPECFILE_PATH = SPECFILE_PATH
  69. SPECFILE_LOCATION = SPECFILE_PATH + "/ddns.spec"
  70. SOCKET_FILE = SOCKET_FILE_PATH + '/ddns_socket'
  71. AUTH_SPECFILE_LOCATION = AUTH_SPECFILE_PATH + '/auth.spec'
  72. isc.util.process.rename()
  73. # Cooperating modules
  74. XFROUT_MODULE_NAME = 'Xfrout'
  75. AUTH_MODULE_NAME = 'Auth'
  76. class DDNSConfigError(Exception):
  77. '''An exception indicating an error in updating ddns configuration.
  78. This exception is raised when the ddns process encounters an error in
  79. handling configuration updates. Not all syntax error can be caught
  80. at the module-CC layer, so ddns needs to (explicitly or implicitly)
  81. validate the given configuration data itself. When it finds an error
  82. it raises this exception (either directly or by converting an exception
  83. from other modules) as a unified error in configuration.
  84. '''
  85. pass
  86. class DDNSSessionError(Exception):
  87. '''An exception raised for some unexpected events during a ddns session.
  88. '''
  89. pass
  90. class DDNSSession:
  91. '''Class to handle one DDNS update'''
  92. def __init__(self):
  93. '''Initialize a DDNS Session'''
  94. pass
  95. def clear_socket():
  96. '''
  97. Removes the socket file, if it exists.
  98. '''
  99. if os.path.exists(SOCKET_FILE):
  100. os.remove(SOCKET_FILE)
  101. def get_datasrc_client(cc_session):
  102. '''Return data source client for update requests.
  103. This is supposed to have a very short lifetime and should soon be replaced
  104. with generic data source configuration framework. Based on that
  105. observation we simply hardcode everything except the SQLite3 database file,
  106. which will be retrieved from the auth server configuration (this behavior
  107. will also be deprecated). When something goes wrong with it this function
  108. still returns a dummy client so that the caller doesn't have to bother
  109. to handle the error (which would also have to be replaced anyway).
  110. The caller will subsequently call its find_zone method via an update
  111. session object, which will result in an exception, and then result in
  112. a SERVFAIL response.
  113. Once we are ready for introducing the general framework, the whole
  114. function will simply be removed.
  115. '''
  116. HARDCODED_DATASRC_CLASS = RRClass.IN()
  117. file, is_default = cc_session.get_remote_config_value("Auth",
  118. "database_file")
  119. # See xfrout.py:get_db_file() for this trick:
  120. if is_default and "B10_FROM_BUILD" in os.environ:
  121. file = os.environ["B10_FROM_BUILD"] + "/bind10_zones.sqlite3"
  122. datasrc_config = '{ "database_file": "' + file + '"}'
  123. try:
  124. return HARDCODED_DATASRC_CLASS, DataSourceClient('sqlite3',
  125. datasrc_config)
  126. except isc.datasrc.Error as ex:
  127. class DummyDataSourceClient:
  128. def __init__(self, ex):
  129. self.__ex = ex
  130. def find_zone(self, zone_name):
  131. raise isc.datasrc.Error(self.__ex)
  132. return HARDCODED_DATASRC_CLASS, DummyDataSourceClient(ex)
  133. class DDNSServer:
  134. def __init__(self, cc_session=None):
  135. '''
  136. Initialize the DDNS Server.
  137. This sets up a ModuleCCSession for the BIND 10 system.
  138. Parameters:
  139. cc_session: If None (default), a new ModuleCCSession will be set up.
  140. If specified, the given session will be used. This is
  141. mainly used for testing.
  142. '''
  143. if cc_session is not None:
  144. self._cc = cc_session
  145. else:
  146. self._cc = isc.config.ModuleCCSession(SPECFILE_LOCATION,
  147. self.config_handler,
  148. self.command_handler)
  149. # Initialize configuration with defaults. Right now 'zones' is the
  150. # only configuration, so we simply directly set it here.
  151. self._config_data = self._cc.get_full_config()
  152. self._zone_config = self.__update_zone_config(
  153. self._cc.get_default_value('zones'))
  154. self._cc.start()
  155. # Get necessary configurations from remote modules.
  156. self._cc.add_remote_config(AUTH_SPECFILE_LOCATION)
  157. isc.server_common.tsig_keyring.init_keyring(self._cc)
  158. self._shutdown = False
  159. # List of the session receivers where we get the requests
  160. self._socksession_receivers = {}
  161. clear_socket()
  162. self._listen_socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
  163. self._listen_socket.bind(SOCKET_FILE)
  164. self._listen_socket.listen(16)
  165. # Create reusable resources
  166. self.__request_msg = Message(Message.PARSE)
  167. self.__response_renderer = MessageRenderer()
  168. # The following attribute(s) are essentially private and constant,
  169. # but defined as "protected" so that test code can customize them.
  170. # They should not be overridden for any other purposes.
  171. #
  172. # DDNS Protocol handling class.
  173. self._UpdateSessionClass = isc.ddns.session.UpdateSession
  174. class InternalError(Exception):
  175. '''Exception for internal errors in an update session.
  176. This exception is expected to be caught within the server class,
  177. only used for controling the code flow.
  178. '''
  179. pass
  180. def config_handler(self, new_config):
  181. '''Update config data.'''
  182. try:
  183. if 'zones' in new_config:
  184. self._zone_config = \
  185. self.__update_zone_config(new_config['zones'])
  186. return create_answer(0)
  187. except Exception as ex:
  188. # We catch any exception here. That includes any syntax error
  189. # against the configuration spec. The config interface is too
  190. # complicated and it's not clear how much validation is performed
  191. # there, so, while assuming it's unlikely to happen, we act
  192. # proactively.
  193. logger.error(DDNS_CONFIG_HANDLER_ERROR, ex)
  194. return create_answer(1, "Failed to handle new configuration: " +
  195. str(ex))
  196. def __update_zone_config(self, new_zones_config):
  197. '''Handle zones configuration update.'''
  198. new_zones = {}
  199. for zone_config in new_zones_config:
  200. origin = Name(zone_config['origin'])
  201. rrclass = RRClass(zone_config['class'])
  202. update_acl = zone_config['update_acl']
  203. new_zones[(origin, rrclass)] = REQUEST_LOADER.load(update_acl)
  204. return new_zones
  205. def command_handler(self, cmd, args):
  206. '''
  207. Handle a CC session command, as sent from bindctl or other
  208. BIND 10 modules.
  209. '''
  210. # TODO: Handle exceptions and turn them to an error response
  211. if cmd == "shutdown":
  212. logger.info(DDNS_RECEIVED_SHUTDOWN_COMMAND)
  213. self.trigger_shutdown()
  214. answer = create_answer(0)
  215. else:
  216. answer = create_answer(1, "Unknown command: " + str(cmd))
  217. return answer
  218. def trigger_shutdown(self):
  219. '''Initiate a shutdown sequence.
  220. This method is expected to be called in various ways including
  221. in the middle of a signal handler, and is designed to be as simple
  222. as possible to minimize side effects. Actual shutdown will take
  223. place in a normal control flow.
  224. '''
  225. logger.info(DDNS_SHUTDOWN)
  226. self._shutdown = True
  227. def shutdown_cleanup(self):
  228. '''
  229. Perform any cleanup that is necessary when shutting down the server.
  230. Do NOT call this to initialize shutdown, use trigger_shutdown().
  231. Currently, it only causes the ModuleCCSession to send a message that
  232. this module is stopping.
  233. '''
  234. self._cc.send_stopping()
  235. def accept(self):
  236. """
  237. Accept another connection and create the session receiver.
  238. """
  239. try:
  240. (sock, remote_addr) = self._listen_socket.accept()
  241. fileno = sock.fileno()
  242. logger.debug(TRACE_BASIC, DDNS_NEW_CONN, fileno,
  243. remote_addr if remote_addr else '<anonymous address>')
  244. receiver = isc.util.cio.socketsession.SocketSessionReceiver(sock)
  245. self._socksession_receivers[fileno] = (sock, receiver)
  246. except (socket.error, isc.util.cio.socketsession.SocketSessionError) \
  247. as e:
  248. # These exceptions mean the connection didn't work, but we can
  249. # continue with the rest
  250. logger.error(DDNS_ACCEPT_FAILURE, e)
  251. def __check_request_tsig(self, msg, req_data):
  252. '''TSIG checker for update requests.
  253. This is a helper method for handle_request() below. It examines
  254. the given update request message to see if it contains a TSIG RR,
  255. and verifies the signature if it does. It returs the TSIG context
  256. used for the verification, or None if the request doesn't contain
  257. a TSIG. If the verification fails it simply raises an exception
  258. as handle_request() assumes it should succeed.
  259. '''
  260. tsig_record = msg.get_tsig_record()
  261. if tsig_record is None:
  262. return None
  263. tsig_ctx = TSIGContext(tsig_record.get_name(),
  264. tsig_record.get_rdata().get_algorithm(),
  265. isc.server_common.tsig_keyring.get_keyring())
  266. tsig_error = tsig_ctx.verify(tsig_record, req_data)
  267. if tsig_error != TSIGError.NOERROR:
  268. raise self.InternalError("Failed to verify request's TSIG: " +
  269. str(tsig_error))
  270. return tsig_ctx
  271. def handle_request(self, req_session):
  272. """
  273. This is the place where the actual DDNS processing is done. Other
  274. methods are either subroutines of this method or methods doing the
  275. uninteresting "accounting" stuff, like accepting socket,
  276. initialization, etc.
  277. It is called with the request being session as received from
  278. SocketSessionReceiver, i.e. tuple
  279. (socket, local_address, remote_address, data).
  280. In general, this method doesn't propagate exceptions outside the
  281. method. Most of protocol or system errors will result in an error
  282. response to the update client or dropping the update request.
  283. The update session class should also ensure this. Critical exceptions
  284. such as memory allocation failure will be propagated, however, and
  285. will subsequently terminate the server process.
  286. Return: True if a response to the request is successfully sent;
  287. False otherwise. The return value wouldn't be useful for the server
  288. itself; it's provided mainly for testing purposes.
  289. """
  290. # give tuple elements intuitive names
  291. (sock, local_addr, remote_addr, req_data) = req_session
  292. # The session sender (b10-auth) should have made sure that this is
  293. # a validly formed DNS message of OPCODE being UPDATE, and if it's
  294. # TSIG signed, its key is known to the system and the signature is
  295. # valid. Messages that don't meet these should have been resopnded
  296. # or dropped by the sender, so if such error is detected we treat it
  297. # as an internal error and don't bother to respond.
  298. try:
  299. if sock.proto == socket.IPPROTO_TCP:
  300. raise self.InternalError('TCP requests are not yet supported')
  301. self.__request_msg.clear(Message.PARSE)
  302. # specify PRESERVE_ORDER as we need to handle each RR separately.
  303. self.__request_msg.from_wire(req_data, Message.PRESERVE_ORDER)
  304. if self.__request_msg.get_opcode() != Opcode.UPDATE():
  305. raise self.InternalError('Update request has unexpected '
  306. 'opcode: ' +
  307. str(self.__request_msg.get_opcode()))
  308. tsig_ctx = self.__check_request_tsig(self.__request_msg, req_data)
  309. except Exception as ex:
  310. logger.error(DDNS_REQUEST_PARSE_FAIL, ex)
  311. return False
  312. # Let an update session object handle the request. Note: things around
  313. # ZoneConfig will soon be substantially revised. For now we don't
  314. # bother to generalize it.
  315. datasrc_class, datasrc_client = get_datasrc_client(self._cc)
  316. zone_cfg = ZoneConfig([], datasrc_class, datasrc_client,
  317. self._zone_config)
  318. update_session = self._UpdateSessionClass(self.__request_msg,
  319. remote_addr, zone_cfg)
  320. result, zname, zclass = update_session.handle()
  321. # If the request should be dropped, we're done; otherwise, send the
  322. # response generated by the session object.
  323. if result == isc.ddns.session.UPDATE_DROP:
  324. return False
  325. msg = update_session.get_message()
  326. self.__response_renderer.clear()
  327. if tsig_ctx is not None:
  328. msg.to_wire(self.__response_renderer, tsig_ctx)
  329. else:
  330. msg.to_wire(self.__response_renderer)
  331. ret = self.__send_response(sock, self.__response_renderer.get_data(),
  332. remote_addr)
  333. if result == isc.ddns.session.UPDATE_SUCCESS:
  334. self.__notify_auth(zname, zclass)
  335. self.__notify_xfrout(zname, zclass)
  336. return ret
  337. def __send_response(self, sock, data, dest):
  338. '''Send DDNS response to the client.
  339. Right now, this is a straightforward subroutine of handle_request(),
  340. but is intended to be extended evetually so that it can handle more
  341. comlicated operations for TCP (which requires asynchronous write).
  342. Further, when we support multiple requests over a single TCP
  343. connection, this method may even be shared by multiple methods.
  344. Parameters:
  345. sock: (python socket) the socket to which the response should be sent.
  346. data: (binary) the response data
  347. dest: (python socket address) the destion address to which the response
  348. should be sent.
  349. Return: True if the send operation succeds; otherwise False.
  350. '''
  351. try:
  352. sock.sendto(data, dest)
  353. except socket.error as ex:
  354. logger.error(DDNS_RESPONSE_SOCKET_ERROR, ClientFormatter(dest), ex)
  355. return False
  356. return True
  357. def __notify_auth(self, zname, zclass):
  358. '''Notify auth of the update, if necessary.'''
  359. msg = auth_loadzone_command(self._cc, zname, zclass)
  360. if msg is not None:
  361. self.__notify_update(AUTH_MODULE_NAME, msg, zname, zclass)
  362. def __notify_xfrout(self, zname, zclass):
  363. '''Notify xfrout of the update.'''
  364. param = {'zone_name': zname.to_text(), 'zone_class': zclass.to_text()}
  365. msg = create_command(ZONE_NEW_DATA_READY_CMD, param)
  366. self.__notify_update(XFROUT_MODULE_NAME, msg, zname, zclass)
  367. def __notify_update(self, modname, msg, zname, zclass):
  368. '''Notify other module of the update.
  369. Note that we use blocking communication here. While the internal
  370. communication bus is generally expected to be pretty responsive and
  371. error free, notable delay can still occur, and in worse cases timeouts
  372. or connection reset can happen. In these cases, even if the trouble
  373. is temporary, the update service will be suspended for a while.
  374. For a longer term we'll need to switch to asynchronous communication,
  375. but for now we rely on the blocking operation.
  376. Note also that we directly refer to the "protected" member of
  377. ccsession (_cc._session) rather than creating a separate channel.
  378. o It's probably not the best practice, but hopefully we can introduce
  379. a cleaner way when we support asynchronous communication.
  380. At the moment we prefer the brevity with the use of internal channel
  381. of the cc session.
  382. '''
  383. try:
  384. seq = self._cc._session.group_sendmsg(msg, modname)
  385. answer, _ = self._cc._session.group_recvmsg(False, seq)
  386. rcode, error_msg = parse_answer(answer)
  387. except (SessionTimeout, SessionError, ProtocolError) as ex:
  388. rcode = 1
  389. error_msg = str(ex)
  390. if rcode == 0:
  391. logger.debug(TRACE_BASIC, DDNS_UPDATE_NOTIFY, modname,
  392. ZoneFormatter(zname, zclass))
  393. else:
  394. logger.error(DDNS_UPDATE_NOTIFY_FAIL, modname,
  395. ZoneFormatter(zname, zclass), error_msg)
  396. def handle_session(self, fileno):
  397. """
  398. Handle incoming session on the socket with given fileno.
  399. """
  400. logger.debug(TRACE_BASIC, DDNS_SESSION, fileno)
  401. (socket, receiver) = self._socksession_receivers[fileno]
  402. try:
  403. self.handle_request(receiver.pop())
  404. except isc.util.cio.socketsession.SocketSessionError as se:
  405. # No matter why this failed, the connection is in unknown, possibly
  406. # broken state. So, we close the socket and remove the receiver.
  407. del self._socksession_receivers[fileno]
  408. socket.close()
  409. logger.warn(DDNS_DROP_CONN, fileno, se)
  410. def run(self):
  411. '''
  412. Get and process all commands sent from cfgmgr or other modules.
  413. This loops waiting for events until self.shutdown() has been called.
  414. '''
  415. logger.info(DDNS_RUNNING)
  416. cc_fileno = self._cc.get_socket().fileno()
  417. listen_fileno = self._listen_socket.fileno()
  418. while not self._shutdown:
  419. # In this event loop, we propagate most of exceptions, which will
  420. # subsequently kill the process. We expect the handling functions
  421. # to catch their own exceptions which they can recover from
  422. # (malformed packets, lost connections, etc). The rationale behind
  423. # this is they know best which exceptions are recoverable there
  424. # and an exception may be recoverable somewhere, but not elsewhere.
  425. try:
  426. (reads, writes, exceptions) = \
  427. select.select([cc_fileno, listen_fileno] +
  428. list(self._socksession_receivers.keys()), [],
  429. [])
  430. except select.error as se:
  431. # In case it is just interrupted, we continue like nothing
  432. # happened
  433. if se.args[0] == errno.EINTR:
  434. (reads, writes, exceptions) = ([], [], [])
  435. else:
  436. raise
  437. for fileno in reads:
  438. if fileno == cc_fileno:
  439. self._cc.check_command(True)
  440. elif fileno == listen_fileno:
  441. self.accept()
  442. else:
  443. self.handle_session(fileno)
  444. self.shutdown_cleanup()
  445. logger.info(DDNS_STOPPED)
  446. def create_signal_handler(ddns_server):
  447. '''
  448. This creates a signal_handler for use in set_signal_handler, which
  449. shuts down the given DDNSServer (or any object that has a shutdown()
  450. method)
  451. '''
  452. def signal_handler(signal, frame):
  453. '''
  454. Handler for process signals. Since only signals to shut down are sent
  455. here, the actual signal is not checked and the server is simply shut
  456. down.
  457. '''
  458. ddns_server.trigger_shutdown()
  459. return signal_handler
  460. def set_signal_handler(signal_handler):
  461. '''
  462. Sets the signal handler(s).
  463. '''
  464. signal.signal(signal.SIGTERM, signal_handler)
  465. signal.signal(signal.SIGINT, signal_handler)
  466. def set_cmd_options(parser):
  467. '''
  468. Helper function to set command-line options
  469. '''
  470. parser.add_option("-v", "--verbose", dest="verbose", action="store_true",
  471. help="display more about what is going on")
  472. def main(ddns_server=None):
  473. '''
  474. The main function.
  475. Parameters:
  476. ddns_server: If None (default), a DDNSServer object is initialized.
  477. If specified, the given DDNSServer will be used. This is
  478. mainly used for testing.
  479. cc_session: If None (default), a new ModuleCCSession will be set up.
  480. If specified, the given session will be used. This is
  481. mainly used for testing.
  482. '''
  483. try:
  484. parser = OptionParser()
  485. set_cmd_options(parser)
  486. (options, args) = parser.parse_args()
  487. if options.verbose:
  488. print("[b10-ddns] Warning: -v verbose option is ignored at this point.")
  489. if ddns_server is None:
  490. ddns_server = DDNSServer()
  491. set_signal_handler(create_signal_handler(ddns_server))
  492. ddns_server.run()
  493. except KeyboardInterrupt:
  494. logger.info(DDNS_STOPPED_BY_KEYBOARD)
  495. except SessionError as e:
  496. logger.error(DDNS_CC_SESSION_ERROR, str(e))
  497. except ModuleCCSessionError as e:
  498. logger.error(DDNS_MODULECC_SESSION_ERROR, str(e))
  499. except DDNSConfigError as e:
  500. logger.error(DDNS_CONFIG_ERROR, str(e))
  501. except SessionTimeout as e:
  502. logger.error(DDNS_CC_SESSION_TIMEOUT_ERROR)
  503. except Exception as e:
  504. logger.error(DDNS_UNCAUGHT_EXCEPTION, type(e).__name__, str(e))
  505. clear_socket()
  506. if '__main__' == __name__:
  507. main()