pyroute2 icon indicating copy to clipboard operation
pyroute2 copied to clipboard

Fix TC Cake Plugin

Open HeroesLament opened this issue 6 months ago • 0 comments

Hello pyroute2 team,

This PR was created to propose a solution to a behavior in the cake tc plugin wherein tc pops off the 'parent' key from kwarg and onto msg:

        if kind in tc_plugins:
            p = tc_plugins[kind]
            msg['parent'] = kwarg.pop('parent', getattr(p, 'parent', 0))
            if hasattr(p, 'fix_msg'):
                p.fix_msg(msg, kwarg)
            if kwarg:
                if command in (RTM_NEWTCLASS, RTM_DELTCLASS):
                    opts = p.get_class_parameters(kwarg)
                else:
                    opts = p.get_parameters(kwarg)
        else:
            msg['parent'] = kwarg.get('parent', TC_H_ROOT)

Then, when hasattr(p, 'fix_msg') is evaluated, the kind cake does have a p attribute, which cake does have, and it drops into fix_msg:

def fix_msg(msg, kwarg):
    if 'parent' not in kwarg:
        msg['parent'] = TC_H_ROOT

Which, because it just popped 'parent' from kwarg, it is always not present, causing msg['parent'] to be mangled by TC_H_ROOT. My proposed fix:

        def fix_msg(msg, kwarg):
           if 'parent' not in msg or msg['parent'] == 0:
              msg['parent'] = TC_H_ROOT

Checks msg, and if 'parent' is either not present or is 0, sets the value to TC_H_ROOT. Please let me know if this is in line with the general idea of fix_msg. In my testing this does allow cake qdiscs to be created under a defined parent class.

Thank you.

HeroesLament avatar Aug 21 '24 20:08 HeroesLament