bgpq4

repository·main·Indexed 19 days ago

https://github.com/bgp/bgpq4

A 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.

Tokens
3.5K
Snippets
15
Records
19
Agent score
15%

What's inside bgpq4

  1. Overview of bgpq4

    main
    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.
  2. Control IRR data sources

    main

    To ensure filter accuracy and trust, you can limit which IRR databases are queried. There are two primary methods:

    1. 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.
    2. 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
  3. Build bgpq4 from source

    main

    The project uses autotools. To build from the repository, follow these steps:

    1. Prepare the build system: ./bootstrap
    2. Configure the build: ./configure
    3. Compile: make
    4. Install: make install

    To clean up generated build system files, use make maintainer-clean. To create a distribution archive, use make dist.

    ./bootstrap
    ./configure
    make
    make install
  4. Use bgpq4 via Container Image

    main

    A multi-arch (linux/amd64 and linux/arm64) container image based on Alpine Linux is available on the GitHub Container Registry. You can run bgpq4 without local installation by using docker run.

    docker run --rm ghcr.io/bgp/bgpq4:latest -Jl eltel AS20597
  5. Update test reference data

    main

    The project uses reference text files in tests/reference/ to validate output. If you modify bgpq4 output 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/reference
  6. Understand bgpq4 flag exclusivity rules

    main

    To 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)
  7. Use bgpq4 CLI to generate BGP filters

    main

    bgpq4 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., 12345 or AS-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 EXCEPT to 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
  8. Generate Juniper prefix-filters

    main

    To generate a named Juniper prefix-list for a specific Autonomous System (AS), use the -J flag followed by the name and the AS number. Use -l to specify the name of the generated entry.

    $ bgpq4 -Jl eltel AS20597
    policy-options {
    replace:
     prefix-list eltel {
        81.9.0.0/20;
        ...
     }
    }
  9. Generate advanced Juniper policy-options

    main

    For 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" AS20597
  10. Generate Cisco prefix-lists with aggregation

    main

    By default, bgpq4 generates Cisco-style prefix-lists. You can use the -A flag 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
    ...
  11. Generate IPv6 prefix-lists

    main

    Use the -6 flag 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::/48
  12. Generate as-path access-lists

    main

    Use 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)*$";
       ...
      }
    }