Skip to content
jonreynaPublic

About

Idiomatic Go BGP routing filter generator — library, drop-in bgpq3 CLI, and HTTP service

Topics

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

26 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bgpsieve

Go Version License

bgpsieve is a Go rewrite of bgpq3, the tool that builds BGP router filters from Internet Routing Registry (IRR) data, and it extends bgpq3 with things it never had. It comes in three parts: a core library with no third-party dependencies, a drop-in bgpq3 command (bgpsieve), and an HTTP service (bgpsieved).

Attribution: Derived from and drop-in compatible with bgpq3, originally created and maintained by Alexandre Snarskii (snar@snar.spb.ru, 2007–2026). See LICENSE and NOTICE.

How bgpsieve compares with bgpq3 and bgpq4

bgpsieve keeps bgpq3's design: the same IRR queries, AS-set expansion, aggregation and output for every vendor, and all 39 of its short flags. A differential suite checks this against the C bgpq3 (v0.1.38) on every change (see Migration Notes). bgpq4 is bgpq3's maintained successor, forked in 2019. bgpsieve takes one feature from it and doesn't follow it anywhere else.

bgpq3 bgpq4 bgpsieve
Language C C Go
Output formats Cisco IOS and IOS XR, JunOS, Nokia SR OS, Huawei VRP, BIRD, OpenBGPD, JSON, -F bgpq3's, plus Arista EOS, MikroTik RouterOS 6 and 7, Nokia SR Linux and Huawei XPL bgpq3's, plus your own Go templates (--template-dir)
SOURCE::OBJECT registry pinning No Yes (1.7) Yes
IRRd 4's faster A query No Yes No
JunOS as-path-origins No Yes (-H) No (-H keeps bgpq3's hyper-aggregation)
Go library No No Yes
HTTP service No No Yes
Bogon filtering No No Yes (--strip-bogons)
Prefix-count cap No No Yes (--max-prefixes)
Default IRR server whois.radb.net rr.ntt.net whois.radb.net

What bgpsieve adds, in more detail:

  • A library. The same expansion, aggregation and rendering the command uses, behind one-method interfaces, so a Go program can generate filters without running a separate process.
  • An HTTP service. bgpsieved serves JSON or plain text, generates several filters in one batch request, caches raw IRR expansions, publishes an OpenAPI spec, exports Prometheus metrics and OpenTelemetry traces, and can serve a small web UI. See cmd/bgpsieved/README.md.
  • Bogon filtering. --strip-bogons (strip_bogons in the API) removes RFC 1918, RFC 6598, documentation and default prefixes before refinement and aggregation, so a bad IRR entry can't put them in a filter.
  • A prefix-count cap. --max-prefixes N fails instead of emitting a filter larger than you expect, which catches an AS-set that suddenly grows.
  • Output templates. --template-dir loads extra vendor formats from Go templates at startup, selected with --vendor template:<name>, without rebuilding.
  • Safety under concurrency. All state is per request, connections to IRR servers are pooled, and expansion of large prefix ranges and IRR replies is bounded. The fixes over the C code are listed under Migration Notes.

The comparison reflects bgpq4 1.17 (November 2026), from its README and CHANGES.

Architecture Overview

flowchart LR
    subgraph Entrypoints["Entrypoints & Go kit Service Layer"]
        CLI["cmd/bgpsieve (Drop-in bgpq3 CLI via pborman/getopt/v2)"]
        HTTP["cmd/bgpsieved (Go kit HTTP Transport + otelhttp + Embedded Web UI)"]
        OBS["internal/obs (Go kit Middlewares: slog, kit/metrics/prometheus, OTel)"]
    end

    subgraph Core["Core Go Library (Zero Third-Party Deps)"]
        API["bgpsieve (1-Method Interfaces: Expander, Transformer, Renderer, Generator)"]
        EXP["expander"]
        RADIX["radix (netip.Prefix Trie + Clone)"]
        ASN["asn (Paged uint64 Bitset)"]
        IRRD["irrd (1-Method Querier, Pipeline, Pool & Polite Middleware)"]
        FMT["format (VendorSpec + 1-Method Interface)"]
    end

    CLI --> API
    HTTP --> OBS
    OBS --> API
    API --> EXP
    EXP --> IRRD
    EXP --> RADIX
    EXP --> ASN
    API --> FMT
    RADIX --> FMT
    ASN --> FMT
Loading

See docs/ARCHITECTURE.md for detailed protocol sequence diagrams, radix tree aggregation mechanics, and interface contracts, and cmd/bgpsieved/README.md for HTTP service operations and observability.

Quickstart

1. Drop-In CLI (cmd/bgpsieve)

go install github.com/jonreyna/bgpsieve/cmd/bgpsieve@latest

bgpsieve supports all 39 bgpq3 POSIX short flags (including bundled flags, numeric flags -2/-3/-4/-6, counters -dd/-AA, attached values -f0, IRRD_SOURCES, and EXCEPT stoplists) and can be aliased or symlinked directly as bgpq3:

# Cisco IOS aggregated IPv4 prefix-list
bgpsieve -Al ELTEL-V4 AS-ELTEL

# Juniper JunOS route-filter policy-statement with refinement and match clause
bgpsieve -AJEl eltel/specifics -r 29 -R 32 -M "community blackhole" AS20597

# IPv6 prefix-list with explicit IRRd source priority
bgpsieve -6Al ELTEL-V6 -S RIPE,RADB AS-ELTEL

# 32-bit AS-path filter with route-validated ASNs and stoplist
bgpsieve -J3wf 20597 -l eltel-as AS-ELTEL EXCEPT AS64496

# Custom user-defined format (-F)
bgpsieve -6F "%n/%l;\n" AS20597

2. Core Go Library (github.com/jonreyna/bgpsieve)

The root package and all core subpackages (asn, radix, irrd, expander, format) have zero third-party dependencies:

package main

import (
	"bytes"
	"context"
	"fmt"
	"time"

	"github.com/jonreyna/bgpsieve"
	"github.com/jonreyna/bgpsieve/format"
	"github.com/jonreyna/bgpsieve/irrd"
)

func main() {
	pool := irrd.NewPool(&irrd.PoolConfig{
		MaxIdlePerKey: 4,
		MaxTotalConns: 32,
		DialTimeout:   5 * time.Second,
	})
	defer func() { _ = pool.Close() }()

	reg := format.DefaultRegistry()
	gen := bgpsieve.NewGenerator(
		bgpsieve.NewExpander(pool),
		bgpsieve.DefaultTransformer(),
		bgpsieve.NewRenderer(reg),
		reg,
	)

	req := &bgpsieve.Request{
		Vendor:        bgpsieve.VendorJuniper,
		Generation:    bgpsieve.GenEACL,
		AddressFamily: bgpsieve.IPv4,
		Name:          "eltel/specifics",
		Objects:       []string{"10.0.0.0/24", "10.0.1.0/24", "10.0.0.0/22"},
		Aggregate:     true,
		Match:         "community blackhole",
	}

	var out bytes.Buffer
	if _, err := gen.Generate(context.Background(), req, &out); err != nil {
		panic(err)
	}
	fmt.Print(out.String())
}

3. Production HTTP Service (cmd/bgpsieved)

go install github.com/jonreyna/bgpsieve/cmd/bgpsieved@latest

# Zero-config startup with embedded Web UI (http://localhost:8080) and /docs
bgpsieved --listen :8080 --backend ntt=rr.ntt.net:43 --default-backend ntt

Generate filters via JSON or direct streaming text/plain:

curl -sS -X POST http://localhost:8080/v1/generate \
  -H 'Content-Type: application/json' \
  -H 'Accept: text/plain' \
  -d '{
    "vendor": "juniper",
    "generation": "eacl",
    "name": "eltel/v4",
    "objects": ["RIPE::AS20597"],
    "aggregate": true,
    "strip_bogons": true
  }'

Vendor & Feature Support Matrix

Vendor CLI Flag API Token prefix-list eacl (-E) route-filter-list (-z) as-path (-f) oas-path (-G) as-set (-t) Mixed AF (-x)
Cisco IOS (default) cisco Yes Yes (IPv4) — Yes Yes — —
Cisco IOS XR -X cisco-xr Yes — — Yes Yes — —
Juniper JunOS -J juniper Yes Yes Yes Yes Yes Yes Yes
JSON -j json Yes — — Yes — Yes Yes
BIRD -b bird Yes — — Yes — Yes —
OpenBGPD -B openbgpd Yes Yes — Yes Yes Yes —
Nokia SR OS (Classic) -N nokia Yes Yes — Yes Yes — —
Nokia SR OS (MD-CLI) -n nokia-md Yes Yes — Yes Yes — —
Huawei VRP -U huawei Yes — — Yes Yes — —
Custom Format -F <fmt> format Yes — — — — — Yes
Startup Templates --template-dir template:<name> Yes Yes Yes Yes Yes Yes Yes

Migration Notes from C bgpq3

bgpsieve is verified byte-for-byte against upstream C bgpq3 (v0.1.38) across a 200-case C-oracle differential suite (internal/oracle). A small set of intentional safety and correctness fixes over C bgpq3 are documented and tested:

  1. Zero global mutable state: All expansion, radix tree, and formatter state is request-scoped and race-free.
  2. Safe -F format validation: Malformed trailing % or unknown format specifiers fail cleanly during validation without out-of-bounds reads.
  3. Bounded RPSL range expansion & IRRd framing: Prevents memory exhaustion on malicious or huge A<len> payloads or 0.0.0.0/0^0-32 ranges.
  4. 32-bit ASN & IPv6 safety: Uses Go net/netip.Prefix and a paged uint64 ASN bitset instead of raw pointer arithmetic.
  5. PeeringDB/bgpq4-style SOURCE::OBJECT pinning: Supported natively in both the CLI and HTTP API alongside -S source lists.

Testing, Verification, Benchmarks & Fuzzing

make test              # Run unit tests across all packages
make race              # Run race detector (-race -count=3)
make test-integration  # Run Tier-1 hermetic integration tests (CLI + HTTP + OTLP)
make test-diff         # Build reference C bgpq3 and run C-oracle differential suite
make test-live         # Run Tier-2 polite live IRRd smoke tests (<= 10 small queries)
make test-e2e          # Run Tier-3 Docker Compose E2E (bgpsieved + Prometheus + Jaeger)
make bench             # Run all Go benchmarks with -benchmem
make fuzz              # Run smoke fuzzing (FUZZTIME=10s) across all 7 Fuzz* targets
make lint              # Run golangci-lint v2 across all build tags
make vet               # Run go vet
make vuln              # Run govulncheck vulnerability scan
make doc               # Verify go doc renders cleanly for every package

Credits & License

  • Original bgpq3 design, algorithms, and stewardship: Alexandre Snarskii (snar@snar.spb.ru, 2007–2026).
  • Licensed under the BSD 2-Clause License — see LICENSE and NOTICE.

About

Idiomatic Go BGP routing filter generator — library, drop-in bgpq3 CLI, and HTTP service

Topics

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages