/opt/imh-python/lib/python3.9/site-packages/pyroute2/netlink/rtnl/tcmsg
NameSizeModeActions
__pycache__/-0755rm
act_bpf.py9790644editdlrm
act_connmark.py12340644editdlrm
act_gact.py7090644editdlrm
act_mirred.py17250644editdlrm
act_police.py18660644editdlrm
act_skbedit.py33370644editdlrm
act_vlan.py14650644editdlrm
cls_basic.py84780644editdlrm
cls_flow.py46130644editdlrm
cls_fw.py14270644editdlrm
cls_matchall.py9860644editdlrm
cls_u32.py80340644editdlrm
common.py107280644editdlrm
common_act.py20630644editdlrm
common_ematch.py31480644editdlrm
em_cmp.py27760644editdlrm
em_ipset.py17410644editdlrm
em_meta.py59330644editdlrm
sched_bpf.py25710644editdlrm
sched_cake.py128330644editdlrm
sched_choke.py34320644editdlrm
sched_clsact.py10110644editdlrm
sched_codel.py16070644editdlrm
sched_drr.py7550644editdlrm
sched_fq_codel.py26580644editdlrm
sched_hfsc.py23530644editdlrm
sched_htb.py57390644editdlrm
sched_ingress.py2140644editdlrm
sched_netem.py51420644editdlrm
sched_pfifo.py1960644editdlrm
sched_pfifo_fast.py2150644editdlrm
sched_plug.py4460644editdlrm
sched_sfq.py27170644editdlrm
sched_tbf.py10870644editdlrm
sched_template.py12500644editdlrm
__init__.py27430644editdlrm
Edit: /opt/imh-python/lib/python3.9/site-packages/pyroute2/netlink/rtnl/tcmsg/cls_flow.py (4613B)
''' flow ++++ Flow filter supports two types of modes:: - map - hash # Prepare a Qdisc with fq-codel ip.tc("add", "fq_codel", ifb0, parent=0x10001, handle=0x10010) # Create flow filter with hash mode # Single: keys = "src" # Multi (comma separated list of keys): keys = "src,nfct-src" ip.tc("add-filter", "flow", ifb0, mode="hash", keys=keys, divisor=1024, perturb=60, handle=0x10, baseclass=0x10010, parent=0x10001) # Create flow filter with map mode # Simple map dst with no OP: ip.tc("add-filter", "flow", ifb0, mode="map", key="dst", divisor=1024, handle=10 baseclass=0x10010) # Same filter with xor OP: ops = [{"op": "xor", "num": 0xFF}] ip.tc("add-filter", "flow", ifb0, mode="map", key="dst", divisor=1024, handle=10 baseclass=0x10010, ops=ops) # Complex one with addend OP (incl. minus support): ops = [{"op": "addend", "num": '-192.168.0.0'}] ip.tc("add-filter", "flow", ifb0, mode="map", key="dst", divisor=1024, handle=10 baseclass=0x10010, ops=ops) # Example with multiple OPS: ops = [{"op": "and", "num": 0xFF}, {"op": "rshift", "num": 4}] ip.tc("add-filter", "flow", ifb0, mode="map", key="dst", divisor=1024, handle=10 baseclass=0x10010, ops=ops) NOTES: When using `map` mode, use the keyword `key` to pass a key. When using `hash` mode, use the keyword `keys` to pass a key even if there is only one key. In `map` mode, the `num` parameter in `OPS` is always an integer unless if you use the OP `addend`, which can be a string IPv4 address. You can also add a minus sign at the beginning of the `num` value even if it is an IPv4 address. ''' from socket import htons from pyroute2 import protocols from pyroute2.netlink import nla from pyroute2.netlink.rtnl.tcmsg.common import ( get_tca_keys, get_tca_mode, get_tca_ops, tc_flow_keys, tc_flow_modes, ) from pyroute2.netlink.rtnl.tcmsg.common_act import get_tca_action, tca_act_prio def fix_msg(msg, kwarg): msg['info'] = htons( kwarg.get('protocol', protocols.ETH_P_ALL) & 0xFFFF ) | ((kwarg.get('prio', 0) << 16) & 0xFFFF0000) def get_parameters(kwarg): ret = {'attrs': []} attrs_map = ( ('baseclass', 'TCA_FLOW_BASECLASS'), ('divisor', 'TCA_FLOW_DIVISOR'), ('perturb', 'TCA_FLOW_PERTURB'), ) if kwarg.get('mode'): ret['attrs'].append(['TCA_FLOW_MODE', get_tca_mode(kwarg)]) if kwarg.get('mode') == 'hash': ret['attrs'].append(['TCA_FLOW_KEYS', get_tca_keys(kwarg, 'keys')]) if kwarg.get('mode') == 'map': ret['attrs'].append(['TCA_FLOW_KEYS', get_tca_keys(kwarg, 'key')]) # Check for OPS presence if 'ops' in kwarg: get_tca_ops(kwarg, ret['attrs']) if kwarg.get('action'): ret['attrs'].append(['TCA_FLOW_ACT', get_tca_action(kwarg)]) for k, v in attrs_map: r = kwarg.get(k, None) if r is not None: ret['attrs'].append([v, r]) return ret class options(nla): nla_map = ( ('TCA_FLOW_UNSPEC', 'none'), ('TCA_FLOW_KEYS', 'tca_parse_keys'), ('TCA_FLOW_MODE', 'tca_parse_mode'), ('TCA_FLOW_BASECLASS', 'uint32'), ('TCA_FLOW_RSHIFT', 'uint32'), ('TCA_FLOW_ADDEND', 'uint32'), ('TCA_FLOW_MASK', 'uint32'), ('TCA_FLOW_XOR', 'uint32'), ('TCA_FLOW_DIVISOR', 'uint32'), ('TCA_FLOW_ACT', 'tca_act_prio'), ('TCA_FLOW_POLICE', 'hex'), ('TCA_FLOW_EMATCHES', 'hex'), ('TCA_FLOW_PERTURB', 'uint32'), ) class tca_parse_mode(nla): fields = (('flow_mode', 'I'),) def decode(self): nla.decode(self) for key, value in tc_flow_modes.items(): if self['flow_mode'] == value: self['flow_mode'] = key break def encode(self): self['flow_mode'] = self['value'] nla.encode(self) class tca_parse_keys(nla): fields = (('flow_keys', 'I'),) def decode(self): nla.decode(self) keys = '' for key, value in tc_flow_keys.items(): if value & self['flow_keys']: keys = '{0},{1}'.format(keys, key) self['flow_keys'] = keys.strip(',') def encode(self): self['flow_keys'] = self['value'] nla.encode(self) tca_act_prio = tca_act_prio