bgpq4
repository·main·Indexed 19 days ago
https://github.com/bgp/bgpq4A command-line utility that automates the generation of BGP filtering configurations, such as prefix-lists and as-path lists, by querying Internet Routing Registry (IRR) databases. It supports multiple vendor formats including Cisco, Juniper, Nokia, Arista, Mikrotik, Huawei, BIRD, and OpenBGPD, and provides options for IPv4 and IPv6 address families.
What's inside bgpq4
- bgpq4 is a BGP filtering automation tool used to generate network configurations such as prefix-lists, extended access-lists, policy-statement terms, and as-path lists based on Internet Routing Registry (IRR) data. It supports various vendor formats including Cisco, Juniper, Nokia, Arista, Mikrotik, and Huawei.
Control IRR data sources
mainTo ensure filter accuracy and trust, you can limit which IRR databases are queried. There are two primary methods:
- The
-S <sources>flag: Limits all queries to specific sources (e.g.,RIPE,ARIN). Note that if an AS-SET contains members from sources not listed in-S, those members might not be fully expanded. - The
::notation: Specify a source directly for an object (e.g.,RIPE::AS-SET-NAME). This tells bgpq4 to query the root of the object from the specified source, but allows members to be queried from the default source list. This is generally recommended for AS-SETs.
Recommended sources:
RPKI,AFRINIC,ARIN,APNIC,LACNIC,RIPE.# Using -S flag $ ./bgpq4 -S RIPE AS-VOSTRON # Using :: notation $ ./bgpq4 RIPE::AS-VOSTRON- The
Build bgpq4 from source
mainThe project uses
autotools. To build from the repository, follow these steps:- Prepare the build system:
./bootstrap - Configure the build:
./configure - Compile:
make - Install:
make install
To clean up generated build system files, use
make maintainer-clean. To create a distribution archive, usemake dist../bootstrap ./configure make make install- Prepare the build system:
Use bgpq4 via Container Image
mainA multi-arch (linux/amd64 and linux/arm64) container image based on Alpine Linux is available on the GitHub Container Registry. You can run
bgpq4without local installation by usingdocker run.docker run --rm ghcr.io/bgp/bgpq4:latest -Jl eltel AS20597Update test reference data
mainThe project uses reference text files in
tests/reference/to validate output. If you modifybgpq4output and need to update the 'known-good' reference data, run the generation script:./tests/generate_outputs.sh ./bgpq4 tests/reference./tests/generate_outputs.sh ./bgpq4 tests/referenceUnderstand bgpq4 flag exclusivity rules
mainTo avoid errors, be aware of the following mutual exclusivity constraints in
bgpq4:Generation Exclusivity: The following flags cannot be used together:
-E(Extended access-lists/route-filters)-F <fmt>(User-defined format)-K(MikroTik)-f <num>(Input as-path access-list)-G <num>(Output as-path access-list)-H <num>(Origin as-lists)-t(As-sets)
Vendor Exclusivity: The following vendor-specific flags are mutually exclusive. You can only pick one:
-b(BIRD)-B(OpenBGPD)-F(Formatted)-J(Juniper)-j(JSON)-K[7](MikroTik)-N(Nokia SR OS Classic)-n(Nokia SR OS MD-CLI)-U(Huawei)-u(Huawei XPL)-e(Arista)-X(Cisco IOS XR)
Use bgpq4 CLI to generate BGP filters
mainbgpq4 is a utility used to generate BGP filter configurations (prefix-lists, as-paths, etc.) for various network vendors by querying IRR (Internet Routing Registry) sources.
Basic Syntax:
bgpq4 [options] <OBJECTS> ... [EXCEPT <OBJECTS> ...]Input Objects:
- AS Numbers: e.g.,
12345orAS-12345. - AS-Sets: e.g.,
AS-12345. - Route Sets: e.g.,
RS-12345. - Prefixes: e.g.,
192.0.2.0/24. - Prefix Ranges: e.g.,
192.0.2.0/24^192.0.2.128/25. - Source Overrides: Use
::to specify a specific source for an object, e.g.,12345::source_name. - Exclusion: Use the keyword
EXCEPTto exclude specific objects from the expansion.
# Example: Generate a Cisco IOS prefix-list for AS 12345 bgpq4 12345 # Example: Generate a Juniper route-filter for AS 12345, excluding prefix 1.1.1.0/24 bgpq4 -J 12345 EXCEPT 1.1.1.0/24- AS Numbers: e.g.,
Generate Juniper prefix-filters
mainTo generate a named Juniper prefix-list for a specific Autonomous System (AS), use the
-Jflag followed by the name and the AS number. Use-lto specify the name of the generated entry.$ bgpq4 -Jl eltel AS20597 policy-options { replace: prefix-list eltel { 81.9.0.0/20; ... } }Generate advanced Juniper policy-options
mainFor complex Juniper configurations, you can combine several flags:
-A: Aggregate prefixes.-J: Juniper format.-E: Generate extended access-lists/policy-statement terms.-l <name>: Name the entry.-r <len>: Allow more specific routes starting with a specified masklen.-R <len>: Allow more specific routes up to a specified masklen.-M <match>: Add extra match conditions (e.g., community strings).
$ bgpq4 -AJEl eltel/specifics -r 29 -R 32 -M "community blackhole" AS20597Generate Cisco prefix-lists with aggregation
mainBy default, bgpq4 generates Cisco-style prefix-lists. You can use the
-Aflag to attempt to aggregate prefix-lists as much as possible to make the output more compact.$ bgpq4 -Al eltel AS20597 no ip prefix-list eltel ip prefix-list eltel permit 81.9.0.0/20 ...Generate IPv6 prefix-lists
mainUse the
-6flag to generate IPv6 prefix/access-lists instead of the default IPv4.$ bgpq4 -6l as-retn-6 AS-RETN6 no ipv6 prefix-list as-retn-6 ipv6 prefix-list as-retn-6 permit 2001:7fb:fe00::/48Generate as-path access-lists
mainUse the
-f <number>or-G <number>flags to generate output as-path access-lists. If your device supports 32-bit ASNs, ensure you use the appropriate flags for your target platform.$ bgpq4 -Jf 112 AS-SPACENET policy-options { replace: as-path-group NN { as-path a0 "^112(112)*$"; ... } }