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

Suggestion: calculating aggregated prefix list with "holes"/exceptions #18

Open
toreanderson opened this issue Dec 8, 2022 · 1 comment

Comments

@toreanderson
Copy link

In case you're taking feature requests, it would be useful to generate an aggregated prefix list but with some sub-prefixes removed:

Mock-up to explain what I mean:

$ echo 192.0.2.0/25 192.0.2.128/26 192.0.2.192/27 192.0.2.224/27 > prefixes.txt
$ echo 192.0.2.3/32 192.0.2.128/30 > exceptions.txt
$ aggregate6 -e exceptions.txt prefixes.txt
192.0.2.0/31
192.0.2.2/32
192.0.2.4/30
192.0.2.8/29
192.0.2.16/28
192.0.2.32/27
192.0.2.64/26
192.0.2.132/30
192.0.2.136/29
192.0.2.144/28
192.0.2.160/27
192.0.2.192/26

If on the other hand you're not taking feature requests, feel free to close this issue. In any case, thank you for this very useful tool!

@movatica
Copy link
Contributor

I use this:

def remove_prefix(aggregated_tree, prefix):
    # simple case: prefix itself or children of it are in the tree
    # those can simply be deleted
    # this will also include the prefix itself
    children = aggregated_tree.search_covered(prefix)

    if children:
        for child in children:
            aggregated_tree.delete(child.prefix)

    # complex case: a supernet is contained in the tree
    # this has to be split up
    parent = aggregated_tree.search_worst(parent)

    if parent:
        aggregated_tree.delete(parent.prefix)
        siblings = ip_network(parent.prefix).address_exclude(ip_network(prefix))

        for sibling in siblings:
            aggregated_tree.add(str(sibling))

First, you run aggregate for both prefixes.txt, and exceptions.txt, then for all entries in exceptions.txt you run the remove_prefix function on prefixes.txt.
Could be integrated into aggregate6, or added as a second script.

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

No branches or pull requests

2 participants