From d3ad131ee838f5a2dae74a868f339a2f514b5333 Mon Sep 17 00:00:00 2001 From: Sam Tannous Date: Thu, 2 Jul 2015 17:10:04 -0400 Subject: [PATCH] Make ifupdown2 print meaningful error when interface name length exceeds 15 characters Ticket: CM-5882 Reviewed By: gospo Testing Done: unit tested When a user enters an interface name longer than 15 characters, the error message is not clear about what the problem is. warning: netlink: Numerical result out of range <<<<<<<<<<<<<<<< This patch catches the error before netlink gets the call and prints error: the following interface names are too long: bond-xconnect.1006 --- ifupdown/ifupdownmain.py | 13 +++++++++++++ ifupdown/utils.py | 8 ++++++++ 2 files changed, 21 insertions(+) diff --git a/ifupdown/ifupdownmain.py b/ifupdown/ifupdownmain.py index f7ea7f4..ef0392e 100644 --- a/ifupdown/ifupdownmain.py +++ b/ifupdown/ifupdownmain.py @@ -754,6 +754,7 @@ class ifupdownMain(ifupdownBase): """ new_ifacenames = [] err_iface = '' + ifnamsiz_error = '' for i in ifacenames: ifaceobjs = self.get_ifaceobjs(i) if not ifaceobjs: @@ -765,13 +766,19 @@ class ifupdownMain(ifupdownBase): if not ifaceobjs: err_iface += ' ' + ri else: + if utils.check_ifname_size_invalid(ri): + ifnamsiz_error += ' ' + ri new_ifacenames.append(ri) else: err_iface += ' ' + i else: + if utils.check_ifname_size_invalid(i): + ifnamsiz_error += ' ' + i new_ifacenames.append(i) if err_iface: raise Exception('cannot find interfaces:%s' %err_iface) + if ifnamsiz_error: + raise Exception('the following interface names are too long:%s' %ifnamsiz_error) return new_ifacenames def _iface_whitelisted(self, auto, allow_classes, excludepats, ifacename): @@ -936,6 +943,8 @@ class ifupdownMain(ifupdownBase): else: self.populate_dependency_info(ops) + if filtered_ifacenames: + filtered_ifacenames = self._preprocess_ifacenames(filtered_ifacenames) try: self._sched_ifaces(filtered_ifacenames, ops, skipupperifaces=skipupperifaces, @@ -1065,6 +1074,8 @@ class ifupdownMain(ifupdownBase): elif ops[0] == 'query-raw': return self.print_ifaceobjs_raw(filtered_ifacenames) + if filtered_ifacenames: + filtered_ifacenames = self._preprocess_ifacenames(filtered_ifacenames) self._sched_ifaces(filtered_ifacenames, ops, followdependents=True if self.WITH_DEPENDS else False) @@ -1149,6 +1160,7 @@ class ifupdownMain(ifupdownBase): return self.logger.info('reload: scheduling up on interfaces: %s' %str(interfaces_to_up)) + interfaces_to_up = self._preprocess_ifacenames(interfaces_to_up) self._sched_ifaces(interfaces_to_up, upops, followdependents=True if self.WITH_DEPENDS else False) if self.DRYRUN: @@ -1266,6 +1278,7 @@ class ifupdownMain(ifupdownBase): self.logger.info('reload: scheduling up on interfaces: %s' %str(filtered_ifacenames)) + filtered_ifacenames = self._preprocess_ifacenames(filtered_ifacenames) try: self._sched_ifaces(filtered_ifacenames, upops, followdependents=True if self.WITH_DEPENDS else False) diff --git a/ifupdown/utils.py b/ifupdown/utils.py index caf6583..970ee03 100644 --- a/ifupdown/utils.py +++ b/ifupdown/utils.py @@ -49,4 +49,12 @@ class utils(): ifacenames.append('%s-%d' %(iface_range[0], i)) return ifacenames + @classmethod + def check_ifname_size_invalid(cls, name=''): + """ IFNAMSIZ in include/linux/if.h is 16 so we check this """ + IFNAMSIZ = 16 + if len(name) > IFNAMSIZ - 1: + return True + else: + return False