Repository navigation
cli: keep the mask of inverted --filter arguments - #2182
thomas0829 wants to merge 1 commit into
Conversation
_CanFilterAction ANDed the mask of "<can_id>~<can_mask>" with CAN_ERR_FLAG instead of ~CAN_ERR_FLAG, so the mask was always 0 and the inverted SocketCAN filter blocked every frame. Clear only the error flag, as candump does. Fixes hardbyte#2181
AI Review: cli: keep the mask of inverted --filter argumentsThe mask fix is correct for SocketCAN: Findings
Verdictrequest changes |
|
The socketcan side looks right to me, candump does the same One thing I noticed on non socketcan interfaces though. Those use the software filter in BusABC._matches_filters, which doesn't know about CAN_INV_FILTER. I tried
So on those interfaces the inverted filter now acts like a normal |
Summary of Changes
CAN_ERR_FLAGfrom the mask of an inverted--filter <can_id>~<can_mask>argument instead of keeping only that bit, so123~7FFgivescan_mask=0x7FFinstead of0.test/test_cli.pyandtest/test_viewer.py, which asserted the old value (0x7F0 & 0x20000000, that is, 0).doc/changelog.d/2181.fixed.rst.Why
With
can_mask=0, the Linux kernel stores the inverted filter ascan_id & 0and never delivers a frame, because(rx_id & 0) != 0is never true.candumpparses the same syntax withcan_mask &= ~CAN_ERR_FLAG, and the--filterhelp text describes the!=match.Validation
python -csnippet from cli: inverted --filter <can_id>~<can_mask> drops the mask #2181 prints0x20000123 0x0onmain(86e70bc) and0x20000123 0x7ffwith this changepytest test/test_cli.py test/test_viewer.py: the updatedtest_add_bus_arguments,test_add_bus_arguments_no_prefixandtest_parse_argsfail onmain(0 != 2032,2047 != 0) and pass herepytest: same results as onmain(885 tests; the 35 that fail in this environment fail identically onmain, and pass when run on their own)black --check .,ruff check can examples doc,pylint can/cli.py can/logger.py can/viewer.py: cleanmypy --python-version 3.12 .: no new errors (the 7 incan/io/mf4.pyalso show onmain)Related Issues / Pull Requests
Type of Change
Checklist
tox).Additional Notes
Tested by parsing only; no SocketCAN device was available. Software filtering in
BusABC._matches_filtersdoes not handleCAN_INV_FILTER, which this change leaves as is.