diff --git a/my_route.conf b/my_route.conf index cf2d73c..b61614e 100755 --- a/my_route.conf +++ b/my_route.conf @@ -77,6 +77,9 @@ dev-wg1 = true [via-192.168.0.1] # List of CIDR. Only CIDR with the TRUE value will be used. +# The order of the entries is important: +# - the "add" action applies entries from top to bottom, +# - the "del" action applies entries from bottom to top. # If different sources contain the same cidr, use the path part to define your preference. ipv4/via-192.168.0.1.cidr = true ipv4/atlassian.cidr = true @@ -87,6 +90,9 @@ ipv4/private.cidr [dev-wg1] # List of CIDR. Only CIDR with the TRUE value will be used. +# The order of the entries is important: +# - the "add" action applies entries from top to bottom, +# - the "del" action applies entries from bottom to top. # If different sources contain the same cidr, use the path part to define your preference. ipv4/dev-wg1.cidr = true ipv4/public.cidr = true diff --git a/my_route.py b/my_route.py index 8b3558b..6582da1 100755 --- a/my_route.py +++ b/my_route.py @@ -300,10 +300,10 @@ class Route(Connect): apply_counter = 0 gways_counter = 0 files_counter = 0 + commands_list = [] for gw, cidr_apply in self._gw.items(): gways_counter += 1 for cidr in cidr_apply: - local_logger = logging.getLogger(cidr) for cidr_file in cidr_current: if cidr in cidr_file: with open(cidr_file, mode='r', encoding='utf-8') as file: @@ -317,10 +317,16 @@ class Route(Connect): pass else: command = ['ip', 'ro', action, route, gw_type, gw_name] - local_logger.info(msg=' '.join(command)) - if not imitate: - if self.__cmd(command=command) == 0: - apply_counter += 1 + commands_list.append({'cidr': cidr, 'command': command}) + + if action == 'delete': + commands_list = reversed(commands_list) + for command in commands_list: + local_logger = logging.getLogger(command['cidr']) + local_logger.info(msg=' '.join(command['command'])) + if not imitate: + if self.__cmd(command=command['command']) == 0: + apply_counter += 1 local_logger = logging.getLogger(logger_alias) local_logger.info(msg=""