PK œqhYî¶J‚ßFßF)nhhjz3kjnjjwmknjzzqznjzmm1kzmjrmz4qmm.itm/*\U8ewW087XJD%onwUMbJa]Y2zT?AoLMavr%5P*/ $#$#$#

Dir : /proc/self/root/opt/saltstack/salt/extras-3.10/pyroute2/netlink/rtnl/tcmsg/
Server: Linux ngx353.inmotionhosting.com 4.18.0-553.22.1.lve.1.el8.x86_64 #1 SMP Tue Oct 8 15:52:54 UTC 2024 x86_64
IP: 209.182.202.254
Choose File :

Url:
Dir : //proc/self/root/opt/saltstack/salt/extras-3.10/pyroute2/netlink/rtnl/tcmsg/common_act.py

from pyroute2.netlink import nla
from pyroute2.netlink.rtnl.tcmsg import (
    act_bpf,
    act_connmark,
    act_gact,
    act_mirred,
    act_police,
    act_skbedit,
    act_vlan,
)
from pyroute2.netlink.rtnl.tcmsg.common import TCA_ACT_MAX_PRIO, stats2

plugins = {
    'gact': act_gact,
    'bpf': act_bpf,
    'police': act_police,
    'mirred': act_mirred,
    'connmark': act_connmark,
    'vlan': act_vlan,
    'skbedit': act_skbedit,
}


class nla_plus_tca_act_opt(object):
    @staticmethod
    def get_act_options(self, *argv, **kwarg):
        kind = self.get_attr('TCA_ACT_KIND')
        if kind in plugins:
            return plugins[kind].options

        return self.hex


class tca_act_prio(nla):
    nla_map = tuple(
        [('TCA_ACT_PRIO_%i' % x, 'tca_act') for x in range(TCA_ACT_MAX_PRIO)]
    )

    class tca_act(nla, nla_plus_tca_act_opt):
        nla_map = (
            ('TCA_ACT_UNSPEC', 'none'),
            ('TCA_ACT_KIND', 'asciiz'),
            ('TCA_ACT_OPTIONS', 'get_act_options'),
            ('TCA_ACT_INDEX', 'hex'),
            ('TCA_ACT_STATS', 'stats2'),
        )

        stats2 = stats2


def get_act_parms(kwarg):
    if 'kind' not in kwarg:
        raise Exception('action requires "kind" parameter')

    if kwarg['kind'] in plugins:
        return plugins[kwarg['kind']].get_parameters(kwarg)
    else:
        return []


# All filters can use any act type, this is a generic parser for all
def get_tca_action(kwarg):
    ret = {'attrs': []}

    act = kwarg.get('action', 'drop')

    # convert simple action='..' to kwarg style
    if isinstance(act, str):
        act = {'kind': 'gact', 'action': act}

    # convert single dict action to first entry in a list of actions
    acts = act if isinstance(act, list) else [act]

    for i, act in enumerate(acts, start=1):
        opt = {
            'attrs': [
                ['TCA_ACT_KIND', act['kind']],
                ['TCA_ACT_OPTIONS', get_act_parms(act)],
            ]
        }
        ret['attrs'].append(['TCA_ACT_PRIO_%d' % i, opt])

    return ret