/
opt
/
imh-python
/
lib
/
python3.9
/
site-packages
/
pyroute2
/
netlink
/
rtnl
/
tcmsg
/
/opt/imh-python/lib/python3.9/site-packages/pyroute2/netlink/rtnl/tcmsg
mkdir
upload
Name
Size
Mode
Actions
__pycache__/
-
0755
rm
act_bpf.py
979
0644
edit
dl
rm
act_connmark.py
1234
0644
edit
dl
rm
act_gact.py
709
0644
edit
dl
rm
act_mirred.py
1725
0644
edit
dl
rm
act_police.py
1866
0644
edit
dl
rm
act_skbedit.py
3337
0644
edit
dl
rm
act_vlan.py
1465
0644
edit
dl
rm
cls_basic.py
8478
0644
edit
dl
rm
cls_flow.py
4613
0644
edit
dl
rm
cls_fw.py
1427
0644
edit
dl
rm
cls_matchall.py
986
0644
edit
dl
rm
cls_u32.py
8034
0644
edit
dl
rm
common.py
10728
0644
edit
dl
rm
common_act.py
2063
0644
edit
dl
rm
common_ematch.py
3148
0644
edit
dl
rm
em_cmp.py
2776
0644
edit
dl
rm
em_ipset.py
1741
0644
edit
dl
rm
em_meta.py
5933
0644
edit
dl
rm
sched_bpf.py
2571
0644
edit
dl
rm
sched_cake.py
12833
0644
edit
dl
rm
sched_choke.py
3432
0644
edit
dl
rm
sched_clsact.py
1011
0644
edit
dl
rm
sched_codel.py
1607
0644
edit
dl
rm
sched_drr.py
755
0644
edit
dl
rm
sched_fq_codel.py
2658
0644
edit
dl
rm
sched_hfsc.py
2353
0644
edit
dl
rm
sched_htb.py
5739
0644
edit
dl
rm
sched_ingress.py
214
0644
edit
dl
rm
sched_netem.py
5142
0644
edit
dl
rm
sched_pfifo.py
196
0644
edit
dl
rm
sched_pfifo_fast.py
215
0644
edit
dl
rm
sched_plug.py
446
0644
edit
dl
rm
sched_sfq.py
2717
0644
edit
dl
rm
sched_tbf.py
1087
0644
edit
dl
rm
sched_template.py
1250
0644
edit
dl
rm
__init__.py
2743
0644
edit
dl
rm
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
Save
cmd:
run