Parcourir la source

[1512] logged forwarding (fail) and notauth events separately.

JINMEI Tatuya il y a 13 ans
Parent
commit
5588e70dc9

+ 7 - 1
src/lib/python/isc/ddns/libddns_messages.mes

@@ -15,5 +15,11 @@
 # No namespace declaration - these constants go in the global namespace
 # No namespace declaration - these constants go in the global namespace
 # of the libddns_messages python module.
 # of the libddns_messages python module.
 
 
-% LIBDDNS_UPDATE_ERROR client %1 for zone %2: %3
+% LIBDDNS_UPDATE_ERROR update client %1 for zone %2: %3
+TBD
+
+% LIBDDNS_UPDATE_FORWARD_FAIL update client %1 for zone %2: update forwarding not supported
+TBD
+
+% LIBDDNS_UPDATE_NOTAUTH update client %1 for zone %2: not authoritative for update zone
 TBD
 TBD

+ 32 - 8
src/lib/python/isc/ddns/session.py

@@ -29,12 +29,31 @@ SECTION_ZONE = Message.SECTION_QUESTION
 SECTION_PREREQUISITE = Message.SECTION_ANSWER
 SECTION_PREREQUISITE = Message.SECTION_ANSWER
 SECTION_UPDATE = Message.SECTION_AUTHORITY
 SECTION_UPDATE = Message.SECTION_AUTHORITY
 
 
+# Shortcut
+DBGLVL_TRACE_BASIC = logger.DBGLVL_TRACE_BASIC
+
 class UpdateError(Exception):
 class UpdateError(Exception):
-    def __init__(self, msg, zname, zclass, rcode):
+    '''Exception for general error in update request handling.
+
+    This exception is intended to be used internally within this module.
+    When UpdateSession.handle() encounters an error in handling an update
+    request it can raise this exception to terminate the handling.
+
+    This class is constructed with some information that may be useful for
+    subsequent possible logging:
+    - msg (string) A string explaining the error.
+    - zname (isc.dns.Name) The zone name.  Can be None when not identified.
+    - zclass (isc.dns.RRClass) The zone class.  Like zname, can be None.
+    - rcode (isc.dns.RCode) The RCODE to be set in the response message.
+    - nolog (bool) If True, it indicates there's no more need for logging.
+
+    '''
+    def __init__(self, msg, zname, zclass, rcode, nolog=False):
         Exception.__init__(self, msg)
         Exception.__init__(self, msg)
         self.zname = zname
         self.zname = zname
         self.zclass = zclass
         self.zclass = zclass
         self.rcode = rcode
         self.rcode = rcode
+        self.nolog = nolog
 
 
 class UpdateSession:
 class UpdateSession:
     '''Protocol handling for a single dynamic update request.
     '''Protocol handling for a single dynamic update request.
@@ -84,9 +103,10 @@ class UpdateSession:
             # self.__make_response(Rcode.NOERROR())
             # self.__make_response(Rcode.NOERROR())
             return UPDATE_SUCCESS, zname, zclass
             return UPDATE_SUCCESS, zname, zclass
         except UpdateError as e:
         except UpdateError as e:
-            logger.debug(logger.DBGLVL_TRACE_BASIC, LIBDDNS_UPDATE_ERROR,
-                         ClientFormatter(self.__client_addr),
-                         ZoneFormatter(e.zname, e.zclass), e)
+            if not e.nolog:
+                logger.debug(logger.DBGLVL_TRACE_BASIC, LIBDDNS_UPDATE_ERROR,
+                             ClientFormatter(self.__client_addr),
+                             ZoneFormatter(e.zname, e.zclass), e)
             self.__make_response(e.rcode)
             self.__make_response(e.rcode)
         return UPDATE_ERROR, None, None
         return UPDATE_ERROR, None, None
 
 
@@ -120,11 +140,15 @@ class UpdateSession:
         elif zone_type == isc.ddns.zone_config.ZONE_SECONDARY:
         elif zone_type == isc.ddns.zone_config.ZONE_SECONDARY:
             # We are a secondary server; since we don't yet support update
             # We are a secondary server; since we don't yet support update
             # forwarding, we return 'not implemented'.
             # forwarding, we return 'not implemented'.
-            raise UpdateError('Update forwarding not supported',
-                              zname, zclass, Rcode.NOTIMP())
+            logger.debug(DBGLVL_TRACE_BASIC, LIBDDNS_UPDATE_FORWARD_FAIL,
+                         ClientFormatter(self.__client_addr),
+                         ZoneFormatter(zname, zclass))
+            raise UpdateError('forward', zname, zclass, Rcode.NOTIMP(), True)
         # zone wasn't found
         # zone wasn't found
-        raise UpdateError('not authoritative for update zone',
-                          zname, zclass, Rcode.NOTAUTH())
+        logger.debug(DBGLVL_TRACE_BASIC, LIBDDNS_UPDATE_NOTAUTH,
+                     ClientFormatter(self.__client_addr),
+                     ZoneFormatter(zname, zclass))
+        raise UpdateError('notauth', zname, zclass, Rcode.NOTAUTH(), True)
 
 
     def __make_response(self, rcode):
     def __make_response(self, rcode):
         '''Transform the internal message to the update response.
         '''Transform the internal message to the update response.