Skip to main content

Fast prefix origin pair lookups

Project description

Informational Badges:

PyPI version PyPy PyPI - Python Version Tests Linux macOS Intel macOS ARM

Some Linting Badges (Where I could find them):

Ruff Code style: black Checked with mypy Imports: isort Pylint try/except style: tryceratops

roa_checker

If you like the repo, it would be awesome if you could add a star to it! It really helps out the visibility. Also for any questions at all we'd love to hear from you at jfuruness@gmail.com

This package contains a trie of ROAs for fast prefix-origin pair lookups

Usage

I can expand these if anyone actually uses this repo (lmk @ jfuruness@gmail.com)

def test_tree():
    # TODO: Break up into unit tests
    trie = ROAChecker()
    cidrs = [ip_network(x) for x in ["1.2.0.0/16", "1.2.3.0/24", "1.2.3.4"]]
    routed_origin = 1
    for cidr in cidrs:
        trie.insert(cidr, ROA(cidr, routed_origin, cidr.prefixlen))
    for cidr in cidrs:
        outcome = trie.get_roa_outcome(cidr, routed_origin)
        assert outcome == ROAOutcome(ROAValidity.VALID, ROARouted.ROUTED)
        assert ROAValidity.is_unknown(outcome.validity) is False
        assert ROAValidity.is_invalid(outcome.validity) is False
        assert ROAValidity.is_valid(outcome.validity) is True

    non_routed_cidrs = [ip_network(x) for x in ["2.2.0.0/16", "2.2.3.0/24", "2.2.3.4"]]
    non_routed_origin = 0
    for cidr in non_routed_cidrs:
        trie.insert(cidr, ROA(cidr, non_routed_origin, cidr.prefixlen))
    for cidr in non_routed_cidrs:
        outcome = trie.get_roa_outcome(cidr, routed_origin)
        assert outcome == ROAOutcome(ROAValidity.INVALID_ORIGIN, ROARouted.NON_ROUTED)

    outcome = trie.get_roa_outcome(ip_network("1.0.0.0/8"), routed_origin)
    assert outcome.validity == ROAValidity.UNKNOWN
    assert outcome.routed_status == ROARouted.UNKNOWN
    outcome = trie.get_roa_outcome(ip_network("255.255.255.255"), routed_origin)
    assert outcome.validity == ROAValidity.UNKNOWN
    assert outcome.routed_status == ROARouted.UNKNOWN
    assert ROAValidity.is_unknown(outcome.validity) is True
    assert ROAValidity.is_invalid(outcome.validity) is False
    assert ROAValidity.is_valid(outcome.validity) is False
    outcome = trie.get_roa_outcome(ip_network("1.2.4.0/24"), routed_origin)
    assert outcome.validity == ROAValidity.INVALID_LENGTH
    assert outcome.routed_status == ROARouted.ROUTED
    assert ROAValidity.is_unknown(outcome.validity) is False
    assert ROAValidity.is_invalid(outcome.validity) is True
    assert ROAValidity.is_valid(outcome.validity) is False
    outcome = trie.get_roa_outcome(ip_network("1.2.3.0/24"), routed_origin + 1)
    assert outcome.validity == ROAValidity.INVALID_ORIGIN
    assert outcome.routed_status == ROARouted.ROUTED
    assert ROAValidity.is_unknown(outcome.validity) is False
    assert ROAValidity.is_invalid(outcome.validity) is True
    assert ROAValidity.is_valid(outcome.validity) is False
    outcome = trie.get_roa_outcome(ip_network("1.2.4.0/24"), routed_origin + 1)
    assert outcome.validity == ROAValidity.INVALID_LENGTH_AND_ORIGIN
    assert outcome.routed_status == ROARouted.ROUTED
    assert ROAValidity.is_unknown(outcome.validity) is False
    assert ROAValidity.is_invalid(outcome.validity) is True
    assert ROAValidity.is_valid(outcome.validity) is False
    outcome = trie.get_roa_outcome(ip_network("1.2.0.255"), routed_origin)
    assert outcome.validity == ROAValidity.INVALID_LENGTH
    assert outcome.routed_status == ROARouted.ROUTED
    outcome = trie.get_roa_outcome(ip_network("1.3.0.0/16"), routed_origin)
    assert outcome.validity == ROAValidity.UNKNOWN
    assert outcome.routed_status == ROARouted.UNKNOWN
    outcome = trie.get_roa_outcome(ip_network("1.2.0.255"), routed_origin)
    assert outcome.validity == ROAValidity.INVALID_LENGTH
    assert outcome.routed_status == ROARouted.ROUTED

Installation

Install python and pip if you have not already. Then run:

pip3 install roa_checker

This will install the package and all of it's python dependencies.

If you want to install the project for development:

git clone https://github.com/jfuruness/roa_checker.git
cd roa_checker
pip3 install -e .[test]
pre-commit install

To test the development package: Testing

Testing

After installation for development:

cd roa_checker
python3 -m pytest roa_checker
ruff check roa_checker
ruff format roa_checker

To run all tests:

cd roa_checker
tox --skip-missing-interpreters

Development/Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request
  6. Email me at jfuruness@gmail.com if I don't see it after a while

History

  • roa_checker

  • 3.1.3 Upgrading optional dependencies and supported Python versions

  • 3.1.2 Removed windows from the classifiers in pyproject.toml

  • 3.1.1 Updated dependencies and ruff settings and removed official windows support (since matplotlib doesn't work on windows with pypy in CI/CD)

  • 3.1.0 Added get_roa_outcome_w_prefix_str_cached. It caches everything, don't cause a mem err!

  • 3.0.2 Updated deps, testing, gh actions, etc

  • 3.0.1 Updated dependencies for testing only

  • 3.0.0 Added ta attribute to ROAs for the ROACollector, modified properties in the ROA for BGPy compatibility

  • 2.0.0

    • Previously the ROA checker would only look at the ROAs that were the most specific prefix (and then would check all of those ROAs)
      • This is a problem because if there were two ROAs, one that is less specific and valid, and one that is more specific and invalid, the announcements would be considered invalid incorrectly.
      • Fixing this unfortunately causes some of the public methods to change (they were wrong before anyways) like get_roa (you can't get a ROA for a prefix, you need to get all ROAs for that prefix)
  • 1.1.4 Bug fix for multiple ROA case where multiple ROAs would result in the least valid ROA being selected, rather than the most valid ROA being selected. Thanks for finding this Cameron Morris!

  • 1.1.3 Dependency updates

  • 1.1.2 Added ROA to top level import

  • 1.1.1 mypy and linter fixes

  • 1.1.0 Updated test deps

  • 1.0.0 Updated package structure, typing, linters, etc, made ROAValidity contains multiple invalid types

  • 0.0.1 First working version

License

BSD License (see license file)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

roa_checker-3.1.3.tar.gz (15.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

roa_checker-3.1.3-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file roa_checker-3.1.3.tar.gz.

File metadata

  • Download URL: roa_checker-3.1.3.tar.gz
  • Upload date:
  • Size: 15.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for roa_checker-3.1.3.tar.gz
Algorithm Hash digest
SHA256 5cb6a95ae74bfe70bffe959350ddd26b3caaef8890054e0a48a966d00f6378e3
MD5 ebf174096f4948b2dce64050d7d321e4
BLAKE2b-256 a00a61bd47a93d5285622bb6c3904eb20ae3050dd73cf6fb126205aebad6ec96

See more details on using hashes here.

File details

Details for the file roa_checker-3.1.3-py3-none-any.whl.

File metadata

  • Download URL: roa_checker-3.1.3-py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for roa_checker-3.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 f15b6ef87d734713b2bf204ad88bcfd30d37a60845846987dcee7619e9a91f5a
MD5 a9e90f1e923665d21be863013b772707
BLAKE2b-256 a3b1326c7ffa00a559bb2f022318e231349d974208625b2692c7c29832346882

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page