-
Notifications
You must be signed in to change notification settings - Fork 7
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
Bogon.py updates #45
base: master
Are you sure you want to change the base?
Bogon.py updates #45
Conversation
using sets instead of lists is a faster lookup. Also, compiling the set with networks at module load time will be faster than casting to an ip_network at every iteration. Finally, wrap the function in a try/except to handle potential errors in creating an ip_network instance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great so far. But I don't think we should handle things gracefully in is_bogon_pfx
, having an invalid network there is almost certainly an developer error and so it should fail loudly.
return True | ||
|
||
return False | ||
try: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, this silences the error. I don't think that's what we want here. Generally such an error shouldn't happen here of course but if it does something has been going really wrong and then this function shouldn't pretend that the network is actually fine and not even a bogon. We would probably run into issue later and have a harder time debugging the later that happens.
return True | ||
if 65552 <= asn <= 131071: | ||
# IANA reserved ASNs, no RFC | ||
special_asns = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: reserved_asns
return True | ||
|
||
special_ranges = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: reserved_asn_ranges
Refactors the
bogon.py
module with some performance and clarity improvements, and adds tests for the module.