Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ jobs:
run: swift build -c release --product cidrwalk

linux-minimum:
name: Linux minimum toolchain (Swift 6.1)
name: Linux minimum toolchain (Swift 6.2)
runs-on: ubuntu-24.04
# swift:6.1-jammy multi-architecture manifest, resolved 2026-07-24.
# swift:6.2-jammy multi-architecture manifest, resolved 2026-11-08.
container: >-
swift:6.1-jammy@sha256:12be34a341945adb64914405ed7b568fcb2d35edbd63a3755007e47dce59456e
swift:6.2-jammy@sha256:7889980d84f47447d109990a6763f3a7997acf2d1059bbd7c56f7e0af6243f73
timeout-minutes: 15

steps:
Expand Down
15 changes: 9 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ jobs:

- name: Verify reviewed dependency boundary
run: |
grep -Fq '.upToNextMinor(from: "0.5.0")' Package.swift
grep -Fq '"version" : "0.5.0"' Package.resolved
grep -Fq '.upToNextMinor(from: "0.9.0")' Package.swift
grep -Fq '"version" : "0.9.0"' Package.resolved
grep -Fq \
'"revision" : "fd5116cef64544dc1f2bab9e93de4e1a7bb57dbb"' \
'"revision" : "a7f661a313d2e9d97516aaeeb4fb0031a229fb02"' \
Package.resolved

- name: Validate version and signed release tag
Expand Down Expand Up @@ -100,6 +100,9 @@ jobs:
needs: metadata
runs-on: ${{ matrix.runner }}
timeout-minutes: 20
env:
# CHANGE: The macOS 15 runner default predates swift-cidr 0.9.0's Swift 6.2 floor.
DEVELOPER_DIR: /Applications/Xcode_26.3.app/Contents/Developer
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -201,19 +204,19 @@ jobs:
EXPECTED_ARCH: ${{ matrix.uname_arch }}
run: test "$(uname -m)" = "${EXPECTED_ARCH}"

- name: Build with Swift 6.1 on Ubuntu 22.04
- name: Build with Swift 6.2 on Ubuntu 22.04
env:
DOCKER_PLATFORM: ${{ matrix.docker_platform }}
run: |
# swift:6.1-jammy multi-architecture manifest, resolved 2026-07-24.
# swift:6.2-jammy multi-architecture manifest, resolved 2026-11-08.
docker run --rm \
--platform "${DOCKER_PLATFORM}" \
--user "$(id -u):$(id -g)" \
--env XDG_CACHE_HOME=/tmp/swift-cache \
--env CLANG_MODULE_CACHE_PATH=/workspace/.build/clang-module-cache \
--volume "${PWD}:/workspace" \
--workdir /workspace \
swift:6.1-jammy@sha256:12be34a341945adb64914405ed7b568fcb2d35edbd63a3755007e47dce59456e \
swift:6.2-jammy@sha256:7889980d84f47447d109990a6763f3a7997acf2d1059bbd7c56f7e0af6243f73 \
bash -c \
'mkdir -p "${XDG_CACHE_HOME}" "${CLANG_MODULE_CACHE_PATH}" &&
swift --version &&
Expand Down
6 changes: 3 additions & 3 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version: 6.1
// swift-tools-version: 6.2

//===----------------------------------------------------------------------===//
//
Expand All @@ -24,10 +24,10 @@ let package = Package(
.executable(name: "cidrwalk", targets: ["cidrwalk"]),
],
dependencies: [
// Keep this pre-1.0 dependency inside the reviewed 0.5 serialization line.
// Keep this pre-1.0 dependency inside the reviewed 0.9 compatibility line.
.package(
url: "https://github.com/RouteObjects/swift-cidr.git",
.upToNextMinor(from: "0.5.0")
.upToNextMinor(from: "0.9.0")
),
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.7.0"),
],
Expand Down
39 changes: 29 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ The command is intentionally narrow and teaching-oriented:
Both inputs must be from the same IP address family. Reversed input order is
normalized at the CLI boundary before calling into `swift-cidr`.

Version 0.2 adopts `swift-cidr` 0.5's RFC 5952 IPv6 spelling for list, tree,
and JSON output. IPv6 values are compressed deterministically, for example
`2001:db8::1/128`, while aggregation semantics and the CLI grammar remain
unchanged.
IPv6 values use deterministic RFC 5952 compressed text in list, tree, and JSON
output, for example `2001:db8::1/128`.

## CIDR Aggregation

Expand All @@ -33,8 +31,9 @@ when the range starts or ends inside a larger boundary.

The `addresses` subcommand requires `/32` for IPv4 and `/128` for IPv6 because
those prefix lengths identify exact host endpoints. The `networks` subcommand
accepts CIDR network prefixes and summarizes the full envelope that covers both
inputs, including adjacent, nested, or reversed networks.
accepts distinct CIDR network prefixes that do not contain one another and
summarizes the full envelope that covers both inputs. Adjacent or separated
networks are accepted in either order.

## Usage

Expand Down Expand Up @@ -79,7 +78,11 @@ cidrwalk addresses 2001:db8::1/128 2001:db8::f/128
### Network Prefixes

Use `networks` when the inputs are CIDR network prefixes. The output covers both
complete input networks, including reversed, nested, or adjacent inputs.
complete input networks and any gap between them. The networks must use the same
address family, be unequal, and neither may contain the other. Equality is checked
after canonicalizing the inputs, so `10.0.0.1/24` and `10.0.0.0/24` are rejected
as the same network. Validation errors are written to stderr with a nonzero exit
status and no summary on stdout.

```bash
cidrwalk networks 192.0.2.0/24 192.0.3.0/24
Expand Down Expand Up @@ -124,6 +127,22 @@ cidrwalk addresses 192.168.1.1/32 192.168.1.189/32 --output json
}
```

In network mode, `rangeStart` is the lowest first address and `rangeEnd` is the
highest last address across the two inputs. With swift-cidr 0.9, each JSON boundary
retains the prefix length of the input network that supplies it. These fields are
contextual address values; their prefix lengths may differ.

| Network inputs | `rangeStart` | `rangeEnd` |
| --- | --- | --- |
| `10.0.0.0/24`, `10.0.2.0/25` | `10.0.0.0/24` | `10.0.2.127/25` |
| `2001:db8::/126`, `2001:db8::8/127` | `2001:db8::/126` | `2001:db8::9/127` |

This intentionally changes the network-mode JSON boundary convention from earlier
releases using swift-cidr 0.5, which emitted host-length prefixes. The `inputs`
array preserves canonical networks in command-line order. Reversing accepted
inputs leaves the boundary values and summarized prefixes unchanged. Address-mode
JSON continues to use its required `/32` or `/128` host endpoints.

### Tree

Tree output is available with `--output tree`. Indentation is based on
Expand Down Expand Up @@ -151,9 +170,9 @@ cd cidrwalk
swift run cidrwalk --help
```

The 0.2 package accepts `swift-cidr` versions in the `0.5.x` line
(`>= 0.5.0` and `< 0.6.0`). This protects the command's tested serialization
contract from an unreviewed pre-1.0 minor update. Building requires Swift 6.1
The package accepts `swift-cidr` versions in the `0.9.x` line
(`>= 0.9.0` and `< 0.10.0`). This protects the command's tested serialization
contract from an unreviewed pre-1.0 minor update. Building requires Swift 6.2
or newer.

## Release Archives
Expand Down
22 changes: 20 additions & 2 deletions Sources/cidrwalk/cidrwalk.swift
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ extension CIDRWalk {
) throws -> String {
switch (firstNetwork, secondNetwork) {
case (.v4(let first), .v4(let second)):
try validateNetworkPair(first, second)
let rangeStart = first.first.address <= second.first.address ? first.first : second.first
let rangeEnd = first.last.address >= second.last.address ? first.last : second.last
return try render(
Expand All @@ -178,6 +179,7 @@ extension CIDRWalk {
output: output
)
case (.v6(let first), .v6(let second)):
try validateNetworkPair(first, second)
let rangeStart = first.first.address <= second.first.address ? first.first : second.first
let rangeEnd = first.last.address >= second.last.address ? first.last : second.last
return try render(
Expand All @@ -193,6 +195,22 @@ extension CIDRWalk {
}
}

// Reject redundant inputs before rendering; retained boundaries keep their input prefixes.
private static func validateNetworkPair<Family: IPAddressFamily>(
_ first: IPNetwork<Family>,
_ second: IPNetwork<Family>
) throws {
guard first != second else {
throw ValidationError("first and second must be different networks (both are \(first)).")
}
if first.contains(subnet: second) {
throw ValidationError("\(first) contains \(second); first and second must not contain one another.")
}
if second.contains(subnet: first) {
throw ValidationError("\(second) contains \(first); first and second must not contain one another.")
}
}

static func printIfNeeded(_ lines: String) {
guard !lines.isEmpty else { return }
print(lines, terminator: lines.hasSuffix("\n") ? "" : "\n")
Expand All @@ -207,7 +225,7 @@ extension CIDRWalk {
output: OutputFormat
) throws -> String
where Prefix: IPPrefix & Encodable,
Input: CIDR & Encodable,
Input: CIDRForm & Encodable,
Input.Family == Prefix.Family {
let prefixDescriptions = prefixes.map(\.description)

Expand Down Expand Up @@ -262,7 +280,7 @@ enum SummaryMode: String, Encodable {

private struct SummaryPayload<Prefix, Input>: Encodable
where Prefix: IPPrefix & Encodable,
Input: CIDR & Encodable,
Input: CIDRForm & Encodable,
Input.Family == Prefix.Family {
var mode: SummaryMode
var family: String
Expand Down
6 changes: 3 additions & 3 deletions THIRD_PARTY_NOTICES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ Swift Argument Parser 1.7.1
Source: https://github.com/apple/swift-argument-parser
License: Apache License 2.0 with Runtime Library Exception

swift-cidr 0.5.0 (CIDR product)
Revision: fd5116cef64544dc1f2bab9e93de4e1a7bb57dbb
swift-cidr 0.9.0 (CIDR product)
Revision: a7f661a313d2e9d97516aaeeb4fb0031a229fb02
Source: https://github.com/RouteObjects/swift-cidr
License: Apache License 2.0

Expand Down Expand Up @@ -55,7 +55,7 @@ Runtime Library Exception to the Apache License 2.0

The Apple packages identified above with the Runtime Library Exception use
the following exception. Linux release binaries are built with the official
Swift 6.1 Ubuntu 22.04 toolchain and statically link portions of the Swift
Swift 6.2 Ubuntu 22.04 toolchain and statically link portions of the Swift
runtime and standard libraries under the same license and exception.

As an exception, if you use this Software to compile your source code and
Expand Down
Loading
Loading