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

Bogon.py updates #45

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

Bogon.py updates #45

wants to merge 3 commits into from

Conversation

jurraca
Copy link
Contributor

@jurraca jurraca commented Jan 3, 2025

Refactors the bogon.py module with some performance and clarity improvements, and adds tests for the module.

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.
Copy link
Collaborator

@fjahr fjahr left a 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:
Copy link
Collaborator

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 = {
Copy link
Collaborator

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 = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: reserved_asn_ranges

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.

2 participants