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

Fix in KNXnet/IP layer (KNX addresses handling) #4663

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

claire-lex
Copy link
Contributor

This PR introduces a few changes to the KNXnet/IP layer, last updated in 2021:

  • Fix validation and support issues on KNX individual addresses and KNX group addresses (see below)
  • Add a few recognized KNX codes and supported types for MultipleTypeFields in complex packets
  • Add basic and KNX address-related unit tests

I made the PR mainly to fix issues when building packets containing individual address (format 1.1.1) or group address (format 1/1/1) fields. The layer only supported either individual address or group address in a field, but some fields (for instance, in cEMI blocks) can take both formats. For instance, the code below used to raise a ValueError and is now valid.

test_addr = CEMI(message_code=0x11) # L_Data.req
test_addr.cemi_data.address_type = 0 # Individual address
test_addr.cemi_data.destination_address = "1.1.1"

@guedou
Copy link
Member

guedou commented Feb 16, 2025

Thanks for the PR. Could you fix the flake8 issues at https://github.com/secdev/scapy/actions/runs/13262979518/job/37023594039?pr=4663 ?

Copy link

codecov bot commented Mar 17, 2025

Codecov Report

Attention: Patch coverage is 71.87500% with 9 lines in your changes missing coverage. Please review.

Project coverage is 82.14%. Comparing base (c15a670) to head (ebb4e97).
Report is 17 commits behind head on master.

Files with missing lines Patch % Lines
scapy/contrib/knx.py 71.87% 9 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4663      +/-   ##
==========================================
+ Coverage   81.55%   82.14%   +0.59%     
==========================================
  Files         359      361       +2     
  Lines       86557    86820     +263     
==========================================
+ Hits        70592    71321     +729     
+ Misses      15965    15499     -466     
Files with missing lines Coverage Δ
scapy/contrib/knx.py 90.52% <71.87%> (+8.02%) ⬆️

... and 39 files with indirect coverage changes

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@claire-lex
Copy link
Contributor Author

Done, it should be ok now! Sorry for the delay.
Thank you :)

Comment on lines -200 to +207
if self.structure_length is None:
p = struct.pack("!B", len(p)) + p[1:]
p = (len(p)).to_bytes(1, byteorder='big') + p[1:]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why those changes?
I think I disagree.

Comment on lines -253 to +256
if self.structure_length is None:
p = struct.pack("!B", len(p)) + p[1:]
p = (len(p)).to_bytes(1, byteorder='big') + p[1:]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same.

Comment on lines -287 to +288
if self.structure_length is None:
p = struct.pack("!B", len(p)) + p[1:]
p = (len(p)).to_bytes(1, byteorder='big') + p[1:]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same (and in all following post_build)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants