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 #4431 - Allow DHCP Answering Machine to have multiple namesevers #4638

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

Conversation

mzen17
Copy link

@mzen17 mzen17 commented Jan 10, 2025

Checklist:

  • If you are new to Scapy: I have checked CONTRIBUTING.md (esp. section submitting-pull-requests)
  • I squashed commits belonging together
  • I added unit tests or explained why they are not relevant
  • I executed the regression tests (using cd test && ./run_tests or tox)
  • If the PR is still not finished, please create a Draft Pull Request

This PR allows the DHCP Answering Machine to support multiple nameservers, as specified in RFC 2132 section 3.8. Previously, the program would run into an error if multiple IPs were provided into nameservers due to the way IPFields pack; it uses the entire string as a single IP and sends it through inet_aton to pack.

The summary of the changes are as follows:

  • Create a function in DHCP_am that converts a list of IPs to bytes
  • Use RawVal to pass these bytes to override processing.

Notes

  • List was used to store IPs during packing after a .split from ',' (this shouldn't have any impact on performance since it is only on answering machine, and also users should not put in large amounts of name servers).

fixes #4431

@gpotter2
Copy link
Member

Hi ! Thanks for the PR.
I think that it would be better to simply add support for a list of IPs in the DHCP answering machine, rather than editing the global IPField. This has too many unintended changes as it's used in a lot of places.

@mzen17
Copy link
Author

mzen17 commented Jan 10, 2025

Yeah, that sounds very reasonable.
So the issue is that the nameserver field in Answering Machine is created as an IP Field, and I directly changed the IP field to add support to it (which is bad design choice since so much non-DHCP systems rely on it and it is the only one that needs multiple IPs).

So there are two choices I am considering:

  • Create a type MultiIPField seperate from IPField to make the multi IP feature more reusable + solve it for all DHCP, albeit it probably won't do much since its just for DHCP (but will need more maintaince + tests)

  • Set nameserver to be a raw field and just manually do the IP packing inside the make_reply (will congest the DHCP answering machine make_reply code, unreusable, but easy to maintain)

Which choice do you think will work better?

@gpotter2
Copy link
Member

I think it's simpler and clearer to just add it to make_reply. Thanks a lot

Copy link

codecov bot commented Jan 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.71%. Comparing base (92925da) to head (23f9dfc).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4638      +/-   ##
==========================================
- Coverage   80.71%   78.71%   -2.01%     
==========================================
  Files         359      334      -25     
  Lines       86052    80861    -5191     
==========================================
- Hits        69461    63649    -5812     
- Misses      16591    17212     +621     
Files with missing lines Coverage Δ
scapy/layers/dhcp.py 83.86% <100.00%> (+0.36%) ⬆️

... and 285 files with indirect coverage changes

@mzen17 mzen17 marked this pull request as ready for review January 11, 2025 18:31
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.

Multiple Nameservers on DHCP_am
2 participants