Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to delete filter of clsact/ingress #928

Closed
jschwinger233 opened this issue Jun 10, 2022 · 4 comments
Closed

Unable to delete filter of clsact/ingress #928

jschwinger233 opened this issue Jun 10, 2022 · 4 comments

Comments

@jschwinger233
Copy link

Reproduce steps:

First let's create the clsact qdisc and a bpf filter.

ipr.tc("add", "clsact", 1) # dev lo
ipr.tc(
    "add-filter",
    "bpf",
    1, # dev lo
    ":1",
    fd=func.fd,
    name=func.name,
    parent='ffff:fff2',
    classid=1,
    direct_action=True,
)

Then we can check the status:

$ tc filter show dev lo parent ffff:fff2
filter protocol all pref 49152 bpf chain 0 
filter protocol all pref 49152 bpf chain 0 handle 0x1 flowid :1 tc_pass direct-action not_in_hw id 329 tag 15858a412926acbb

However the consequent del-filter won't work:

ipr.tc("del-filter", "bpf", iface_idx, ':1', parent='ffff:fff2')

will raise error

Traceback (most recent call last):
  File "basic01-xdp-pass/tc_loader.bcc.py", line 45, in <module>
    ipr.tc("del-filter", "bpf", iface_idx, ':0', parent=parent)
  File "/usr/lib/python3/dist-packages/pyroute2/iproute/linux.py", line 1614, in tc
    return tuple(self.nlm_request(msg, msg_type=command, msg_flags=flags))
  File "/usr/lib/python3/dist-packages/pyroute2/netlink/nlsocket.py", line 376, in nlm_request
    return tuple(self._genlm_request(*argv, **kwarg))
  File "/usr/lib/python3/dist-packages/pyroute2/netlink/nlsocket.py", line 867, in nlm_request
    for msg in self.get(msg_seq=msg_seq,
  File "/usr/lib/python3/dist-packages/pyroute2/netlink/nlsocket.py", line 379, in get
    return tuple(self._genlm_get(*argv, **kwarg))
  File "/usr/lib/python3/dist-packages/pyroute2/netlink/nlsocket.py", line 704, in get
    raise msg['header']['error']
pyroute2.netlink.exceptions.NetlinkError: (2, 'No such file or directory')

I guess it's caused by tcm_info in the request of RTM_DELTFILTER, somehow the parameter is set to 0x300 instead of 0, but I don't know how to make the correction.

@jschwinger233
Copy link
Author

Maybe this issue is interrelated?

@svinota svinota added the bug label Jun 10, 2022
@svinota
Copy link
Owner

svinota commented Jun 10, 2022

Thanks, working on it!

@svinota
Copy link
Owner

svinota commented Jun 10, 2022

The issue caused by incorrect tcm_info encoding.

To mitigate the error, you can use right now:

ipr.tc("del-filter", "bpf", iface_idx, ':1', protocol=0, prio=0xc000, parent='ffff:fff2')

Corresponding code:

def fix_msg(msg, kwarg):
msg['info'] = htons(kwarg.pop('protocol', ETH_P_ALL) & 0xFFFF) | (
(kwarg.pop('prio', 0) << 16) & 0xFFFF0000
)

Tomorrow I'm to fix this. And #745 as well.

svinota added a commit that referenced this issue Jun 11, 2022
Bug-Url: #745
Bug-Url: #928
@svinota
Copy link
Owner

svinota commented Jun 11, 2022

Looks like fixed:

def test_filter_delete(context, bpf):
context.ipr.tc('add', kind='clsact', index=context.default_interface.index)
context.ipr.tc(
'add-filter',
kind='bpf',
index=context.default_interface.index,
fd=bpf,
name='my_func',
parent='ffff:fff2',
classid=1,
direct_action=True,
)
filters = context.ipr.get_filters(
index=context.default_interface.index, parent='ffff:fff2'
)
# len == 2: handles 0 and 1
assert len(filters) == 2
context.ipr.tc(
'del-filter',
kind='bpf',
index=context.default_interface.index,
parent='ffff:fff2',
info=filters[0]['info'],
)
filters = context.ipr.get_filters(
index=context.default_interface.index, parent='ffff:fff2'
)
assert len(filters) == 0

The next release which will include this fix is to be tagged tomorrow

@svinota svinota closed this as completed Jul 10, 2022
@svinota svinota added the fixed label Jul 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants