svinota / pyroute2

Python Netlink and PF_ROUTE library — network configuration and monitoring
https://pyroute2.org/
Other
960 stars 248 forks source link

"get_filters" does not provide "priority" information #617

Open ralonsoh opened 5 years ago

ralonsoh commented 5 years ago

Function "pyroute2.iproute.linux.RTNL_API.get_filters" does not contain, in the TC filter information structure, the filter priority information. E.g.:

Filter with priority 49: filter parent ffff: protocol all pref 49 u32 chain 0 filter parent ffff: protocol all pref 49 u32 chain 0 fh 800: ht divisor 1 filter parent ffff: protocol all pref 49 u32 chain 0 fh 800::800 order 2048 key ht 800 bkt 0 flowid :1 not_in_hw match 00000000/00000000 at 0 police 0x1 rate 2560Kbit burst 192000b mtu 1200b action drop overhead 0b ref 1 bind 1

Structure returned: <class 'dict'>: {'family': 0, 'pad1': 0, 'pad2': 0, 'index': 2, 'handle': 2147485696, 'parent': 4294901760, 'info': 3212032, 'attrs': (('TCA_KIND', 'u32'), ('UNKNOWN', {'header': {'length': 8, 'type': 11}}), ('TCA_OPTIONS', {'attrs': (('TCA_U32_SEL', {'flags': 1, 'offshift': 0, 'nkeys': 1, 'align': (), 'offmask': 0, 'off': 0, 'offoff': 0, 'hoff': 0, 'hmask': 0, 'keys': ({'key_mask': 0, 'key_val': 0, 'key_off': 0, 'key_offmask': 0},)}), ('TCA_U32_HASH', 2147483648), ('TCA_U32_CLASSID', 1), ('UNKNOWN', {'header': {'length': 8, 'type': 11}}), ('TCA_U32_POLICE', {'attrs': (('TCA_POLICE_TBF', {'index': 1, 'action': 2, 'limit': 0, 'burst': 9375000, 'mtu': 1200, 'rate_cell_log': 0, 'rate___reserved': 0, 'rate_overhead': 0, 'rate_cell_align': 0, 'rate_mpu': 0, 'rate': 320000, 'peak_celllog': 0, 'peakreserved': 0, 'peak_overhead': 0, 'peak_cell_align': 0, 'peak_mpu': 0, 'peak': 0, 'refcnt': 1, 'bindcnt': 1, 'capab': 0}), ('UNKNOWN', {'header': {'length': 36, 'type': 6}}))}))}), ('TCA_STATS', {'bytes': 0, 'packets': 0, 'drop': 0, 'overlimits': 0, 'bps': 0, 'pps': 0, 'qlen': 0, 'backlog': 0})), 'header': {'length': 260, 'type': 44, 'flags': 2, 'sequence_number': 255, 'pid': 10153, 'error': None, 'stats': (0, 0, 0)}, 'event': 'RTM_NEWTFILTER'}

svinota commented 5 years ago

Thanks, investigating

liske commented 4 years ago

The priority (or preference) is encoded in the higher 16bits of the info field:

$ tc filter show dev enp5s0
filter parent 804c: protocol all pref 49152 matchall chain 0 
filter parent 804c: protocol all pref 49152 matchall chain 0 handle 0x1 
  not_in_hw
    action order 1: mirred (Ingress Mirror to device ifb0) pipe
    index 1 ref 1 bind 1
>>> pprint(ipr.get_filters(index=2))
({'attrs': [('TCA_KIND', 'matchall'),
            ('UNKNOWN', {'header': {'length': 8, 'type': 11}})],
  'event': 'RTM_NEWTFILTER',
  'family': 0,
  'handle': 0,
  'header': {'error': None,
             'flags': 2,
             'length': 60,
             'pid': 30278,
             'sequence_number': 292,
             'stats': Stats(qsize=0, delta=0, delay=0),
             'target': 'localhost',
             'type': 44},
  'index': 2,
  'info': 3221226240,
  'pad1': 0,
  'pad2': 0,
  'parent': 2152464384},
 {'attrs': [('TCA_KIND', 'matchall'),
            ('UNKNOWN', {'header': {'length': 8, 'type': 11}}),
            ('TCA_OPTIONS', {'attrs': [('TCA_MATCHALL_FLAGS', 134217728), ('UNKNOWN', {'header': {'length': 12, 'type': 4}}), ('TCA_MATCHALL_ACT', {'attrs': [('TCA_ACT_PRIO_1', {'attrs': [('TCA_ACT_KIND', 'mirred'), ('TCA_ACT_STATS', {'attrs': [('TCA_STATS_BASIC', {'bytes': 0, 'packets': 0}), ('UNKNOWN', {'header': {'length': 20, 'type': 7}}), ('TCA_STATS_QUEUE', {'qlen': 0, 'backlog': 0, 'drops': 0, 'requeues': 0, 'overlimits': 0})]}), ('TCA_ACT_OPTIONS', {'attrs': [('TCA_MIRRED_PARMS', {'index': 1, 'capab': 0, 'action': 3, 'refcnt': 1, 'bindcnt': 1, 'eaction': 4, 'ifindex': 92}), ('TCA_MIRRED_TM', None)]})]}), ('TCA_ACT_PRIO_2', {'attrs': [('TCA_ACT_KIND', 'mirred'), ('TCA_ACT_STATS', {'attrs': [('TCA_STATS_BASIC', {'bytes': 0, 'packets': 0}), ('UNKNOWN', {'header': {'length': 20, 'type': 7}}), ('TCA_STATS_QUEUE', {'qlen': 0, 'backlog': 0, 'drops': 0, 'requeues': 0, 'overlimits': 0})]}), ('TCA_ACT_OPTIONS', {'attrs': [('TCA_MIRRED_PARMS', {'index': 2, 'capab': 0, 'action': 3, 'refcnt': 1, 'bindcnt': 1, 'eaction': 2, 'ifindex': 93}), ('TCA_MIRRED_TM', None)]})]})]})]})],
  'event': 'RTM_NEWTFILTER',
  'family': 0,
  'handle': 1,
  'header': {'error': None,
             'flags': 2,
             'length': 400,
             'pid': 30278,
             'sequence_number': 292,
             'stats': Stats(qsize=0, delta=0, delay=0),
             'target': 'localhost',
             'type': 44},
  'index': 2,
  'info': 3221226240,
  'pad1': 0,
  'pad2': 0,
  'parent': 2152464384})

To get the priority: 3221226240 >> 16 = 49152