Skip to content

Backward compatibility: Add Deprecated fields #1983

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

Merged
merged 6 commits into from
Jun 27, 2019
Merged

Conversation

gpotter2
Copy link
Member

@gpotter2 gpotter2 commented Apr 12, 2019

Rationale: Scapy is pretty bad at keeping things backward compatible. Fields are renamed often for consistency, therefore breaking older stuff. Moreover, because the release schedule is so slow, people aren't warned of changes.

This PR is an attempt to improve this by:

Not sure how this affects performance. Adding stuff to get_field & co never is great

@codecov
Copy link

codecov bot commented Apr 12, 2019

Codecov Report

Merging #1983 into master will decrease coverage by 0.74%.
The diff coverage is 92%.

@@            Coverage Diff             @@
##           master    #1983      +/-   ##
==========================================
- Coverage   87.18%   86.44%   -0.75%     
==========================================
  Files         197      197              
  Lines       44486    44507      +21     
==========================================
- Hits        38787    38472     -315     
- Misses       5699     6035     +336
Impacted Files Coverage Δ
scapy/layers/dot11.py 90.46% <100%> (+0.02%) ⬆️
scapy/main.py 73.92% <100%> (+0.21%) ⬆️
scapy/packet.py 79.87% <88.88%> (+0.19%) ⬆️
scapy/arch/bpf/supersocket.py 27.9% <0%> (-50.24%) ⬇️
scapy/layers/dhcp6.py 63.38% <0%> (-21.76%) ⬇️
scapy/pton_ntop.py 89.04% <0%> (-8.22%) ⬇️
scapy/contrib/isotp.py 82.03% <0%> (-6.3%) ⬇️
scapy/arch/bpf/core.py 81.37% <0%> (-5.89%) ⬇️
scapy/arch/pcapdnet.py 65.51% <0%> (-4.14%) ⬇️
scapy/automaton.py 85.44% <0%> (-0.55%) ⬇️
... and 4 more

@@ -84,7 +85,11 @@ def _read_config_file(cf, _globals=globals(), _locals=locals(), interactive=True
"""
log_loading.debug("Loading config file [%s]", cf)
try:
exec(compile(open(cf).read(), cf, 'exec'), _globals, _locals)
Copy link
Member Author

Choose a reason for hiding this comment

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

Random unclosed file triggered by the new detection

Copy link
Member

Choose a reason for hiding this comment

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

ACK

@gpotter2 gpotter2 changed the title Add AliasField Backward compatibility: Add AliasField Apr 13, 2019
@gpotter2
Copy link
Member Author

Also ready despite the failing codecov test

@guedou
Copy link
Member

guedou commented Apr 16, 2019

I like this idea but I have some comments:

  • maybe you could implement the boolean self.has_alias and test it before doing the isinstance() calls. I think that this test won't impact the performance
  • AliasField could be named `DeprecatedField``
  • another alternative could be to implement this feature outside of fields_desc

@gpotter2
Copy link
Member Author

Thanks for the suggestions, I've updated the PR.

So you think that we should allow alias_fields not to throw DeprecationWarnings (as currently: it's optional), or should we just replace it with deprecation_fields and always throw the deprecation ?

@guedou
Copy link
Member

guedou commented Apr 17, 2019 via email

@gpotter2
Copy link
Member Author

Got it, updated

(Please squash when merging)

@gpotter2
Copy link
Member Author

@guedou This is ready for review !

@@ -247,6 +247,11 @@ def guess_payload_class(self, pay):

class RadioTap(Packet):
name = "RadioTap dummy"
deprecated_fields = {
"Channel": "ChannelFrequency", # 2.4.3
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if the version should be part of the deprecation API. It might ease our future selves while debugging issues =)

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea, will do

guedou
guedou previously approved these changes Jun 25, 2019
Copy link
Member

@p-l- p-l- left a comment

Choose a reason for hiding this comment

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

I have to think about it, but the idea is nice. Here is a change suggestion to make the code simpler.

Co-Authored-By: Pierre Lalet <[email protected]>
@gpotter2 gpotter2 changed the title Backward compatibility: Add AliasField Backward compatibility: Add Deprecated fields Jun 27, 2019
@gpotter2 gpotter2 requested a review from p-l- June 27, 2019 11:41
@p-l- p-l- merged commit f7f0e31 into secdev:master Jun 27, 2019
@gpotter2 gpotter2 deleted the aliasbranch branch June 29, 2019 11:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RadioTap Dummy Channel vs. Frequency confusion
3 participants