]> git.proxmox.com Git - mirror_ifupdown2.git/commitdiff
nlmanager: use strerror to deal with kernel error
authorJulien Fortin <julien@cumulusnetworks.com>
Fri, 30 Nov 2018 01:14:35 +0000 (17:14 -0800)
committerJulien Fortin <julien@cumulusnetworks.com>
Thu, 13 Dec 2018 23:17:09 +0000 (15:17 -0800)
Signed-off-by: Julien Fortin <julien@cumulusnetworks.com>
ifupdown2/nlmanager/nlmanager.py

index baa0023267386747fcc2d82dbc94dd3c91d17645..cb4962cfa9a2f56b4887d26e1b4c39ec6052cae9 100644 (file)
@@ -274,43 +274,31 @@ class NetlinkManager(object):
 
                     elif msgtype == NLMSG_ERROR:
 
-                        # The error code is a signed negative number.
-                        error_code = abs(unpack('=i', data[header_LEN:header_LEN+4])[0])
                         msg = Error(msgtype, nlpacket.debug)
                         msg.decode_packet(length, flags, seq, pid, data)
 
+                        # The error code is a signed negative number.
+                        error_code = abs(msg.negative_errno)
+
                         # 0 is NLE_SUCCESS...everything else is a true error
                         if error_code:
-                            error_code_str = msg.error_to_string.get(error_code)
-                            if error_code_str:
-                                error_str = 'Operation failed with \'%s\'' % error_code_str
-                            else:
-                                error_str = 'Operation failed with code %s' % error_code
 
-                            log.debug(debug_str)
+                            if self.debug:
+                                msg.dump()
 
-                            if error_code == Error.NLE_NOADDR:
-                                raise NetlinkNoAddressError(error_str)
-                            elif error_code == Error.NLE_INTR:
-                                nle_intr_count += 1
-                                log.debug("%s: RXed NLE_INTR Interrupted system call %d/%d" % (s, nle_intr_count, MAX_ERROR_NLE_INTR))
+                            try:
+                                # os.strerror might raise ValueError
+                                strerror = os.strerror(error_code)
 
-                                if nle_intr_count >= MAX_ERROR_NLE_INTR:
-                                    raise NetlinkInterruptedSystemCall(error_str)
+                                if strerror:
+                                    error_str = "operation failed with '%s' (%s)" % (strerror, error_code)
+                                else:
+                                    error_str = "operation failed with code %s" % error_code
 
-                            else:
-                                msg.dump()
-                                if not error_code_str:
-                                    try:
-                                        # os.strerror might raise ValueError
-                                        strerror = os.strerror(error_code)
-                                        if strerror:
-                                            raise NetlinkError('Operation failed with \'%s\'' % strerror)
-                                        else:
-                                            raise NetlinkError(error_str)
-                                    except ValueError:
-                                        pass
-                                raise NetlinkError(error_str)
+                            except ValueError:
+                                error_str = "operation failed with code %s" % error_code
+
+                            raise NetlinkError(error_str)
                         else:
                             log.debug('%s code NLE_SUCCESS...this is an ACK' % debug_str)
                             return msgs