From 19a7d4da5821fb62acefaab0a3870dd5853d8b86 Mon Sep 17 00:00:00 2001 From: Peter Saveliev Date: Fri, 13 Dec 2024 23:57:58 +0100 Subject: [PATCH] requests.tc: root parent for kind without plugin --- pyroute2/requests/tc.py | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/pyroute2/requests/tc.py b/pyroute2/requests/tc.py index 49ea54819..7eb798646 100644 --- a/pyroute2/requests/tc.py +++ b/pyroute2/requests/tc.py @@ -1,3 +1,4 @@ +from pyroute2.netlink.rtnl import TC_H_ROOT from pyroute2.netlink.rtnl.tcmsg import plugins as tc_plugins from .common import IPRouteFilter @@ -39,20 +40,25 @@ def finalize(self, context): context['handle'] = 0 # get & run the plugin - if 'kind' in context and context['kind'] in tc_plugins: - plugin = tc_plugins[context['kind']] - context['parent'] = context.get( - 'parent', getattr(plugin, 'parent', 0) - ) - if set(context.keys()) > set(('kind', 'index', 'handle')): - get_parameters = None - if self.command[-5:] == 'class': - get_parameters = getattr( - plugin, 'get_class_parameters', None - ) - else: - get_parameters = getattr(plugin, 'get_parameters', None) - if get_parameters is not None: - context['options'] = get_parameters(dict(context)) - if hasattr(plugin, 'fix_request'): - plugin.fix_request(context) + if 'kind' in context: + if context['kind'] in tc_plugins: + plugin = tc_plugins[context['kind']] + context['parent'] = context.get( + 'parent', getattr(plugin, 'parent', 0) + ) + if set(context.keys()) > set(('kind', 'index', 'handle')): + get_parameters = None + if self.command[-5:] == 'class': + get_parameters = getattr( + plugin, 'get_class_parameters', None + ) + else: + get_parameters = getattr( + plugin, 'get_parameters', None + ) + if get_parameters is not None: + context['options'] = get_parameters(dict(context)) + if hasattr(plugin, 'fix_request'): + plugin.fix_request(context) + else: + context['parent'] = TC_H_ROOT