diff --git a/addons/bridge.py b/addons/bridge.py index 2b33a7a..696adb1 100644 --- a/addons/bridge.py +++ b/addons/bridge.py @@ -336,6 +336,15 @@ class bridge(moduleBase): b = list(b) yield b[0][1], b[-1][1] + def _handle_reserved_vlan(self, vlanid): + if vlanid in range(self._resv_vlan_range[0], + self._resv_vlan_range[1]): + self.logger.warn('skipping reserved vlan %d' %vlanid + + ' (reserved vlan range %d-%d)' %(self._resv_vlan_range[0], + self._resv_vlan_range[1])) + return True + return False + def _ranges_to_ints(self, rangelist): """ returns expanded list of integers given set of string ranges example: ['1', '2-4', '6'] returns [1, 2, 3, 4, 6] @@ -345,9 +354,14 @@ class bridge(moduleBase): if '-' in part: a, b = part.split('-') a, b = int(a), int(b) + if (self._handle_reserved_vlan(a) or + self._handle_reserved_vlan(b)): + continue result.extend(range(a, b + 1)) else: a = int(part) + if self._handle_reserved_vlan(a): + continue result.append(a) return result diff --git a/ifupdown/ifupdownmain.py b/ifupdown/ifupdownmain.py index 0521da7..e807267 100644 --- a/ifupdown/ifupdownmain.py +++ b/ifupdown/ifupdownmain.py @@ -625,7 +625,7 @@ class ifupdownMain(ifupdownBase): # continue reading pass - def _sched_ifaces(self, ifacenames, ops): + def _sched_ifaces(self, ifacenames, ops, skipupperifaces=False): self.logger.debug('scheduling \'%s\' for %s' %(str(ops), str(ifacenames))) self._pretty_print_ordered_dict('dependency graph', @@ -635,7 +635,8 @@ class ifupdownMain(ifupdownBase): order=ifaceSchedulerFlags.INORDER if 'down' in ops[0] else ifaceSchedulerFlags.POSTORDER, - followdependents=True if self.WITH_DEPENDS else False) + followdependents=True if self.WITH_DEPENDS else False, + skipupperifaces=skipupperifaces) def _render_ifacename(self, ifacename): new_ifacenames = [] @@ -753,7 +754,7 @@ class ifupdownMain(ifupdownBase): def up(self, ops, auto=False, allow_classes=None, ifacenames=None, excludepats=None, printdependency=None, syntaxcheck=False, - type=None): + type=None, skipupperifaces=False): """This brings the interface(s) up Args: @@ -806,7 +807,8 @@ class ifupdownMain(ifupdownBase): self.populate_dependency_info(ops) try: - self._sched_ifaces(filtered_ifacenames, ops) + self._sched_ifaces(filtered_ifacenames, ops, + skipupperifaces=skipupperifaces) finally: if not self.DRYRUN and self.ADDONS_ENABLE: self._save_state() diff --git a/ifupdown/scheduler.py b/ifupdown/scheduler.py index 1d84a80..448b332 100644 --- a/ifupdown/scheduler.py +++ b/ifupdown/scheduler.py @@ -336,7 +336,7 @@ class ifaceScheduler(): def sched_ifaces(cls, ifupdownobj, ifacenames, ops, dependency_graph=None, indegrees=None, order=ifaceSchedulerFlags.POSTORDER, - followdependents=True): + followdependents=True, skipupperifaces=False): """ runs interface configuration modules on interfaces passed as argument. Runs topological sort on interface dependency graph. @@ -426,7 +426,8 @@ class ifaceScheduler(): if not cls._SCHED_RETVAL: raise Exception() - if (ifupdownobj.config.get('skip_upperifaces', '0') == '0' and + if (not skipupperifaces and + ifupdownobj.config.get('skip_upperifaces', '0') == '0' and ((not ifupdownobj.ALL and followdependents) or followupperifaces) and 'up' in ops[0]): diff --git a/ifupdownaddons/modulebase.py b/ifupdownaddons/modulebase.py index 7d42cd2..50a1e7c 100644 --- a/ifupdownaddons/modulebase.py +++ b/ifupdownaddons/modulebase.py @@ -325,7 +325,9 @@ class moduleBase(object): start = end = 0 get_resvvlan = '/usr/share/python-ifupdown2/get_reserved_vlan_range.sh' try: - (start, end) = self.exec_command(get_resvvlan).split('-') + (s, e) = self.exec_command(get_resvvlan).strip('\n').split('-') + start = int(s) + end = int(e) except: # ignore errors pass diff --git a/sbin/ifupdown b/sbin/ifupdown index b6120b2..13874ac 100755 --- a/sbin/ifupdown +++ b/sbin/ifupdown @@ -51,13 +51,15 @@ def run_up(args): ifupdown_handle.up(['up'], args.all, args.CLASS, iflist, excludepats=args.excludepats, printdependency=args.printdependency, - syntaxcheck=args.syntaxcheck, type=args.type) + syntaxcheck=args.syntaxcheck, type=args.type, + skipupperifaces=args.skipupperifaces) else: ifupdown_handle.up(['pre-up', 'up', 'post-up'], args.all, args.CLASS, iflist, excludepats=args.excludepats, printdependency=args.printdependency, - syntaxcheck=args.syntaxcheck, type=args.type) + syntaxcheck=args.syntaxcheck, type=args.type, + skipupperifaces=args.skipupperifaces) except: raise @@ -260,6 +262,13 @@ def update_ifup_argparser(argparser): argparser.add_argument('-s', '--syntax-check', dest='syntaxcheck', action='store_true', help='Only run the interfaces file parser') + argparser.add_argument('-k', '--skip-upperifaces', dest='skipupperifaces', + action='store_true', + help='ifup by default tries to add newly created interfaces' + + ' into its upper/parent interfaces. Eg. if a bridge port is' + + ' created as a result of ifup on the port, ifup automatically' + + ' adds the port to the bridge. This option can be used to ' + + 'disable this default behaviour') update_ifupdown_argparser(argparser) def update_ifdown_argparser(argparser):