|
1 |
| -# prefix-aggregator |
2 |
| -A command-line tool for aggregating IPv4 prefixes |
| 1 | +# Prefix Aggregator |
3 | 2 |
|
4 |
| -# How to use |
5 |
| -## Aggregate to the largest prefix possible |
| 3 | +A command-line tool for efficiently aggregating IPv4 prefixes into the smallest possible set of CIDR blocks. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- Aggregates adjacent and overlapping IPv4 CIDR blocks |
| 8 | +- Optimizes for the smallest number of resulting prefixes |
| 9 | +- Works with standard input/output for easy integration with other tools |
| 10 | +- Cross-platform support (Linux, macOS, Windows) |
| 11 | + |
| 12 | +## Installation |
| 13 | + |
| 14 | +### Download Binary |
| 15 | + |
| 16 | +Pre-built binaries are available for various platforms on the [Releases page](https://github.com/ugwis/prefix-aggregator/releases). |
| 17 | + |
| 18 | +1. Download the appropriate binary for your platform: |
| 19 | + - Linux: `prefix-aggregator-x86_64-unknown-linux-gnu.zip` |
| 20 | + - Windows: `prefix-aggregator-x86_64-pc-windows-gnu.zip` |
| 21 | + - macOS (Intel): `prefix-aggregator-x86_64-apple-darwin.zip` |
| 22 | + - macOS (Apple Silicon): `prefix-aggregator-aarch64-apple-darwin.zip` |
| 23 | + |
| 24 | +2. Extract the ZIP file and place the binary in a directory included in your PATH. |
| 25 | + |
| 26 | +### macOS Security Warning |
| 27 | + |
| 28 | +When running the application on macOS, you might see a security warning: "Apple could not verify this app is free from malware." |
| 29 | + |
| 30 | +To resolve this: |
| 31 | + |
| 32 | +1. Right-click (or Control-click) on the `prefix-aggregator` binary |
| 33 | +2. Select "Open" from the context menu |
| 34 | +3. Click "Open" in the dialog that appears |
| 35 | +4. The app will now be saved as an exception to your security settings |
| 36 | + |
| 37 | +### Building from Source |
| 38 | + |
| 39 | +If you have Rust installed, you can build from source: |
| 40 | + |
| 41 | +```bash |
| 42 | +git clone https://github.com/ugwis/prefix-aggregator.git |
| 43 | +cd prefix-aggregator |
| 44 | +cargo build --release |
| 45 | +``` |
| 46 | + |
| 47 | +The binary will be available at `target/release/prefix-aggregator`. |
| 48 | + |
| 49 | +## Usage |
| 50 | + |
| 51 | +### Basic Usage |
| 52 | + |
| 53 | +Provide a list of IP prefixes via standard input: |
| 54 | + |
| 55 | +```bash |
| 56 | +prefix-aggregator < list_of_prefixes.txt |
| 57 | +``` |
| 58 | + |
| 59 | +Or use a here document: |
| 60 | + |
| 61 | +```bash |
| 62 | +prefix-aggregator << EOF |
| 63 | +192.168.1.0/24 |
| 64 | +192.168.2.0/24 |
| 65 | +192.168.3.0/24 |
| 66 | +EOF |
| 67 | +``` |
| 68 | + |
| 69 | +### Examples |
| 70 | + |
| 71 | +#### Example 1: Aggregate Adjacent Prefixes |
| 72 | + |
| 73 | +Input: |
6 | 74 | ```
|
7 |
| -$ prefix-aggregator << EOS |
8 | 75 | 10.0.0.0/24
|
9 | 76 | 10.0.1.0/24
|
10 | 77 | 10.0.2.0/24
|
11 |
| -EOS |
12 | 78 | ```
|
13 |
| -Expected to |
| 79 | + |
| 80 | +Output: |
14 | 81 | ```
|
15 | 82 | 10.0.0.0/23
|
16 | 83 | 10.0.2.0/24
|
17 | 84 | ```
|
18 |
| - |
19 |
| -## The bigger, the better. |
| 85 | + |
| 86 | +The tool automatically combines `10.0.0.0/24` and `10.0.1.0/24` into `10.0.0.0/23`. |
| 87 | + |
| 88 | +#### Example 2: Handle Overlapping Prefixes |
| 89 | + |
| 90 | +Input: |
20 | 91 | ```
|
21 |
| -$ prefix-aggregator << EOS |
22 | 92 | 10.0.0.0/8
|
23 | 93 | 10.0.0.0/16
|
24 | 94 | 10.0.1.0/16
|
25 |
| -EOS |
26 | 95 | ```
|
27 |
| -Expected to |
| 96 | + |
| 97 | +Output: |
28 | 98 | ```
|
29 | 99 | 10.0.0.0/8
|
30 | 100 | ```
|
31 | 101 |
|
32 |
| -## Focus only on your goal |
33 |
| -``` |
34 |
| -$ curl -s https://ip-ranges.amazonaws.com/ip-ranges.json | jq -r '.prefixes[].ip_prefix' | sort -V | uniq | wc -l |
35 |
| -4314 |
36 |
| -$ curl -s https://ip-ranges.amazonaws.com/ip-ranges.json | jq -r '.prefixes[].ip_prefix' | sort -V | uniq | prefix-aggregator | wc -l |
37 |
| -1101 |
| 102 | +The tool recognizes that `10.0.0.0/8` already includes the other prefixes. |
| 103 | + |
| 104 | +#### Example 3: Real-world Application |
| 105 | + |
| 106 | +Aggregating AWS IP ranges: |
| 107 | + |
| 108 | +```bash |
| 109 | +curl -s https://ip-ranges.amazonaws.com/ip-ranges.json | jq -r '.prefixes[].ip_prefix' | sort -V | uniq | wc -l |
| 110 | +# 4314 prefixes before aggregation |
| 111 | + |
| 112 | +curl -s https://ip-ranges.amazonaws.com/ip-ranges.json | jq -r '.prefixes[].ip_prefix' | sort -V | uniq | prefix-aggregator | wc -l |
| 113 | +# 1101 prefixes after aggregation |
38 | 114 | ```
|
| 115 | + |
| 116 | +This example shows how the tool can reduce 4314 AWS IP prefixes to just 1101 prefixes. |
| 117 | + |
| 118 | +## How It Works |
| 119 | + |
| 120 | +The prefix-aggregator uses an algorithm that: |
| 121 | + |
| 122 | +1. Sorts the input prefixes |
| 123 | +2. Identifies adjacent prefixes that can be combined |
| 124 | +3. Merges overlapping prefixes |
| 125 | +4. Recursively applies these operations until no further aggregation is possible |
| 126 | + |
| 127 | +## License |
| 128 | + |
| 129 | +[MIT License](LICENSE) |
0 commit comments