mirror of
https://github.com/bgp/bgpq4
synced 2025-02-28 08:53:11 +00:00
Compare commits
46 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4dd3b92b3c | ||
|
|
a97f7eb4ff | ||
|
|
4ab84255a4 | ||
|
|
424770be0b | ||
|
|
4bac9e7e53 | ||
|
|
2ec0ea3fbd | ||
|
|
0a83c7598d | ||
|
|
f44bf47b1f | ||
|
|
9ffc4f8ec6 | ||
|
|
a89ac75590 | ||
|
|
59f800f31f | ||
|
|
6c8bb871c0 | ||
|
|
26b0827813 | ||
|
|
36a54c9b41 | ||
|
|
e743be94b3 | ||
|
|
b631d43755 | ||
|
|
57a70da5a9 | ||
|
|
95d3a4c12b | ||
|
|
2e06d3c389 | ||
|
|
3d2eed555d | ||
|
|
a28752247c | ||
|
|
26d631b257 | ||
|
|
841840be68 | ||
|
|
8ae08b79b1 | ||
|
|
9fa14cc506 | ||
|
|
92561f43af | ||
|
|
aee7adb698 | ||
|
|
3c201684b6 | ||
|
|
b98ecd5d4d | ||
|
|
d14db9515f | ||
|
|
8883f13b74 | ||
|
|
31ce2e452f | ||
|
|
b85bea6324 | ||
|
|
6fdae48462 | ||
|
|
89ab54454e | ||
|
|
baddc22f15 | ||
|
|
0deb7f224c | ||
|
|
975b577b2e | ||
|
|
b785c02e37 | ||
|
|
017bae280f | ||
|
|
2921348a98 | ||
|
|
233380d4e9 | ||
|
|
509e2f0acf | ||
|
|
a6b41d9352 | ||
|
|
7ac2068879 | ||
|
|
fc79ff9242 |
24
.github/images/alpine:3.Dockerfile
vendored
Normal file
24
.github/images/alpine:3.Dockerfile
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
# to build the image locally tagged with the short commit hash:
|
||||
# docker build -t bgpq4:$(git rev-parse --short HEAD) -f .github/images/alpine:3.Dockerfile .
|
||||
ARG IMAGE=alpine:3
|
||||
FROM $IMAGE as builder
|
||||
|
||||
# Install dependencies
|
||||
RUN apk upgrade
|
||||
RUN apk add autoconf automake file gcc gzip libtool make musl-dev
|
||||
|
||||
# Add source code
|
||||
ADD . /src
|
||||
WORKDIR /src
|
||||
|
||||
# Run steps
|
||||
RUN ./bootstrap
|
||||
RUN ./configure
|
||||
RUN make
|
||||
RUN make check
|
||||
RUN make distcheck
|
||||
|
||||
FROM alpine:3
|
||||
COPY --from=builder /src/bgpq4 /bgp/
|
||||
WORKDIR /bgp
|
||||
ENTRYPOINT [ "./bgpq4" ]
|
||||
4
.github/images/centos.Dockerfile
vendored
4
.github/images/centos.Dockerfile
vendored
@@ -2,8 +2,8 @@ ARG image=centos/centos:latest
|
||||
FROM quay.io/$image
|
||||
|
||||
# Install dependencies
|
||||
RUN yum update -y
|
||||
RUN yum install -y autoconf automake gcc libtool make diffutils file
|
||||
RUN if command -v yum > /dev/null; then dnf=yum; fi; ${dnf:-dnf} update -y
|
||||
RUN if command -v yum > /dev/null; then dnf=yum; fi; ${dnf:-dnf} install -y autoconf automake gcc libtool make diffutils file gzip
|
||||
|
||||
# Add source code
|
||||
ADD . /src
|
||||
|
||||
1
.github/images/debian:trixie.Dockerfile
vendored
Symbolic link
1
.github/images/debian:trixie.Dockerfile
vendored
Symbolic link
@@ -0,0 +1 @@
|
||||
debian.Dockerfile
|
||||
65
.github/workflows/build-container.yml
vendored
Normal file
65
.github/workflows/build-container.yml
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
name: Container build
|
||||
"on":
|
||||
push:
|
||||
tags:
|
||||
- "*" # Push events to any tag
|
||||
branches:
|
||||
- "main"
|
||||
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
tag:
|
||||
description: "Container tag to use for the build"
|
||||
required: true
|
||||
default: "test"
|
||||
|
||||
jobs:
|
||||
test:
|
||||
uses: ./.github/workflows/unit-tests.yml
|
||||
|
||||
build:
|
||||
name: Build container
|
||||
runs-on: ubuntu-22.04
|
||||
needs: test
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- # Add support for more platforms with QEMU
|
||||
# https://github.com/docker/setup-qemu-action
|
||||
name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Docker meta
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: ghcr.io/${{ github.repository_owner }}/bgpq4
|
||||
tags: |
|
||||
# pick up tag provided from workflow_dispatch user's input
|
||||
type=raw,value=${{ inputs.tag }}
|
||||
type=ref,event=tag
|
||||
type=ref,event=branch
|
||||
# git short commit
|
||||
type=sha
|
||||
|
||||
- name: Login to GitHub Container Registry
|
||||
if: github.repository_owner == 'bgp'
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.repository_owner }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Build and push
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
file: .github/images/alpine:3.Dockerfile
|
||||
context: .
|
||||
platforms: linux/amd64,linux/arm64
|
||||
push: ${{ github.repository_owner == 'bgp' }}
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
13
.github/workflows/build.yml
vendored
13
.github/workflows/build.yml
vendored
@@ -1,12 +1,18 @@
|
||||
name: Build and test (single linux distro)
|
||||
name: Build and test (latest Ubuntu/macOS)
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest]
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- uses: actions/checkout@v4
|
||||
- name: install macOS autogen prerequisites
|
||||
run: brew install autoconf automake libtool
|
||||
if: runner.os == 'macOS'
|
||||
- name: bootstrap
|
||||
run: ./bootstrap
|
||||
- name: configure
|
||||
@@ -17,4 +23,5 @@ jobs:
|
||||
run: make check
|
||||
- name: make distcheck
|
||||
run: make distcheck
|
||||
if: runner.os == 'Linux'
|
||||
|
||||
|
||||
38
.github/workflows/codeql-analysis.yml
vendored
Normal file
38
.github/workflows/codeql-analysis.yml
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
name: CodeQL analysis
|
||||
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
schedule:
|
||||
# build the main branch every Tuesday morning
|
||||
- cron: '15 6 * * 2'
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
analyze:
|
||||
name: Analyze
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
actions: read
|
||||
contents: read
|
||||
security-events: write
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
language: [ 'cpp' ]
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v3
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
- name: Build Application using script
|
||||
run: |
|
||||
./bootstrap
|
||||
./configure
|
||||
make
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v3
|
||||
with:
|
||||
category: "/language:${{matrix.language}}"
|
||||
14
.github/workflows/matrixbuild.yml
vendored
14
.github/workflows/matrixbuild.yml
vendored
@@ -9,23 +9,27 @@ jobs:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
dockerenv:
|
||||
- debian:trixie
|
||||
- debian:bookworm
|
||||
- debian:bullseye
|
||||
- debian:buster
|
||||
- ubuntu:jammy
|
||||
- ubuntu:focal
|
||||
- ubuntu:bionic
|
||||
- fedora/fedora:37
|
||||
- fedora/fedora:36
|
||||
- fedora/fedora:35
|
||||
- fedora/fedora:40
|
||||
- fedora/fedora:39
|
||||
- fedora/fedora:38
|
||||
- centos/centos:stream9
|
||||
- centos/centos:stream8
|
||||
- centos/centos:7
|
||||
- rockylinux/rockylinux:9
|
||||
- rockylinux/rockylinux:8
|
||||
- alpine:edge
|
||||
- alpine:3.16
|
||||
- alpine:3.19
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- uses: actions/checkout@v4
|
||||
- name: Work around Docker BuildKit regression
|
||||
# https://github.com/moby/buildkit/issues/2119: `DOCKER_BUILDKIT=1 docker build` fails if Dockerfile is a symlink
|
||||
run: cp --remove-destination $(readlink -f .github/images/${{matrix.dockerenv}}.Dockerfile) .github/images/${{matrix.dockerenv}}.Dockerfile
|
||||
- name: Run build on ${{matrix.dockerenv}}
|
||||
run: docker build . --file .github/images/${{matrix.dockerenv}}.Dockerfile --build-arg image=${{matrix.dockerenv}}
|
||||
|
||||
37
.github/workflows/unit-tests.yml
vendored
Normal file
37
.github/workflows/unit-tests.yml
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
name: basic unit tests
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types:
|
||||
- opened
|
||||
- edited
|
||||
- reopened
|
||||
- ready_for_review
|
||||
- synchronize
|
||||
workflow_call:
|
||||
|
||||
jobs:
|
||||
output-unit-tests:
|
||||
name: output unit tests
|
||||
runs-on: ubuntu-22.04
|
||||
steps:
|
||||
- name: clone repo
|
||||
uses: actions/checkout@v4
|
||||
- name: install pre-reqs
|
||||
run: |
|
||||
sudo apt-get update
|
||||
DEBIAN_FRONTEND=noninteractive sudo apt-get -y --no-install-recommends install autoconf automake libtool make
|
||||
- name: build bgpq4
|
||||
run: |
|
||||
./bootstrap
|
||||
./configure
|
||||
make
|
||||
./bgpq4 -v
|
||||
- name: generate output
|
||||
run: ./tests/generate_outputs.sh ./bgpq4 /tmp
|
||||
- name: check output
|
||||
run: >
|
||||
for file in tests/reference/*.txt;
|
||||
do
|
||||
echo "$(sha256sum "${file}" | awk '{print $1}') /tmp/$(basename "${file}")" | sha256sum --check;
|
||||
done
|
||||
24
CHANGES
24
CHANGES
@@ -1,3 +1,27 @@
|
||||
1.14 (2024-05-14)
|
||||
- Small performance gain: set TCP_NODELAY on the socket
|
||||
|
||||
1.13 (2024-05-01)
|
||||
- Fixed a bug for Mac users by removing sx_maxsockbuf()
|
||||
- Fixed a comma printing bug in IOS XR as-path-set output
|
||||
|
||||
1.12 (2024-02-12)
|
||||
- Fix a bug in the mikrotik printer
|
||||
|
||||
1.11 (2023-06-20)
|
||||
- disallow AS 23456 as origin (can be bypassed via -p)
|
||||
|
||||
1.10 (2023-06-03)
|
||||
- Add support for Nokia SR Linux IP prefix lists / ACL filters
|
||||
- Accept -3 as a no-op for bgpq3 compatibility
|
||||
|
||||
1.9 (2023-03-05)
|
||||
- Bugfix for -S problem (bgpq4#83) by James Bensley
|
||||
|
||||
1.8 (2023-01-20)
|
||||
- Downgrade 'key not found' to DEBUG level to reduce noise
|
||||
- Re-introduce -p for private ASN support option
|
||||
|
||||
1.7 (2022-11-03)
|
||||
- Support SOURCE:: syntax (contributed by James Bensley)
|
||||
|
||||
|
||||
10
Makefile.am
10
Makefile.am
@@ -17,7 +17,6 @@ bgpq4_LDADD += $(top_builddir)/compat/libcompat.la
|
||||
endif
|
||||
|
||||
bgpq4_SOURCES=main.c extern.h printer.c expander.c \
|
||||
sx_maxsockbuf.c \
|
||||
sx_prefix.c sx_prefix.h \
|
||||
sx_report.c sx_report.h \
|
||||
sx_slentry.c
|
||||
@@ -33,3 +32,12 @@ MAINTAINERCLEANFILES=configure aclocal.m4 compile \
|
||||
|
||||
maintainer-clean-local:
|
||||
-rm -rf m4 autom4te.cache
|
||||
|
||||
check:
|
||||
./bgpq4 -v
|
||||
@echo
|
||||
-if [ -s /etc/resolv.conf ]; then \
|
||||
./bgpq4 -ddd -6 AS15562:AS-SNIJDERS ; \
|
||||
else \
|
||||
echo "No or empty /etc/resolv.conf, skipping online test"; \
|
||||
fi
|
||||
|
||||
94
README.md
94
README.md
@@ -1,3 +1,9 @@
|
||||
[](https://github.com/bgp/bgpq4/actions/workflows/unit-tests.yml)
|
||||
|
||||
<a href="https://repology.org/project/bgpq4/versions">
|
||||
<img src="https://repology.org/badge/vertical-allrepos/bgpq4.svg" alt="Packaging status" align="right">
|
||||
</a>
|
||||
|
||||
# NAME
|
||||
|
||||
**bgpq4** - bgp filtering automation tool
|
||||
@@ -13,7 +19,7 @@
|
||||
**-G** *asn*
|
||||
**-H** *asn*
|
||||
**-t**]
|
||||
\[**-46ABbDdJjNnsXU**]
|
||||
\[**-46ABbDdJjNnpsXU**]
|
||||
\[**-a** *asn*]
|
||||
\[**-r** *len*]
|
||||
\[**-R** *len*]
|
||||
@@ -101,7 +107,11 @@ It's options are as follows:
|
||||
|
||||
**-K**
|
||||
|
||||
> generate config for Mikrotik (default: Cisco).
|
||||
> generate config for Mikrotik ROSv6 (default: Cisco).
|
||||
|
||||
**-K7**
|
||||
|
||||
> generate config for Mikrotik ROSv7 (default: Cisco).
|
||||
|
||||
**-l** *name*
|
||||
|
||||
@@ -124,17 +134,18 @@ It's options are as follows:
|
||||
|
||||
> generate config for Nokia SR OS MD-CLI (Cisco IOS by default)
|
||||
|
||||
**-n2**
|
||||
|
||||
> generate config for Nokia SR Linux (Cisco IOS by default)
|
||||
|
||||
**-N**
|
||||
|
||||
> generate config for Nokia SR OS classic CLI (Cisco IOS by default).
|
||||
|
||||
**-p**
|
||||
|
||||
> accept routes registered for private ASNs (default: disabled)
|
||||
|
||||
**-P**
|
||||
|
||||
> generate prefix-list (default, backward compatibility).
|
||||
> emit prefixes where the origin ASN is in the private ASN range
|
||||
> (disabled by default).
|
||||
|
||||
**-r** *len*
|
||||
|
||||
@@ -343,19 +354,19 @@ be in one line (sometimes it makes sense):
|
||||
# NOTES ON SOURCES
|
||||
|
||||
By default *bgpq4* trusts data from all databases mirrored into NTT's IRR service.
|
||||
Unfortunately, not all these databases are equal in how much can we trust their
|
||||
Unfortunately, not all these databases are equal in how much can we trust their
|
||||
data.
|
||||
RIR maintained databases (AFRINIC, ARIN, APNIC, LACNIC and RIPE)
|
||||
shall be trusted more than the others because they have the knowledge about
|
||||
which address space is allocated to each ASN, other databases lack this
|
||||
knowledge and can (and actually do) contain some stale data: nobody but RIRs
|
||||
care to remove outdated route-objects when address space is revoked from one
|
||||
ASN and allocated to another. In order to keep their filters both compact and
|
||||
current, *bgpq4 users* are encouraged to use one of two method to limit
|
||||
shall be trusted more than the others because they have the knowledge about
|
||||
which address space is allocated to each ASN, other databases lack this
|
||||
knowledge and can (and actually do) contain some stale data: nobody but RIRs
|
||||
care to remove outdated route-objects when address space is revoked from one
|
||||
ASN and allocated to another. In order to keep their filters both compact and
|
||||
current, *bgpq4 users* are encouraged to use one of two method to limit
|
||||
database sources to only ones they trust.
|
||||
|
||||
One option is to use the '-S' flag. This limits all queries to a specific data
|
||||
source. For example, the following command tells IIRd to only use data from
|
||||
One option is to use the '-S' flag. This limits all queries to a specific data
|
||||
source. For example, the following command tells IIRd to only use data from
|
||||
the RIPE RIR DB to build the prefix list for the AS-SET:
|
||||
|
||||
$./bgpq4 -S RIPE AS-VOSTRON
|
||||
@@ -364,8 +375,8 @@ the RIPE RIR DB to build the prefix list for the AS-SET:
|
||||
ip prefix-list NN permit 134.0.64.0/21
|
||||
|
||||
Be aware though, than an AS-SET may contain members from other data sources.
|
||||
In this case IRRd won't respond to the bgpq4 query will all the prefixes in the
|
||||
AS-SET tree. Make sure to use the '-S' flag with all the data sources required
|
||||
In this case IRRd won't respond to the bgpq4 query will all the prefixes in the
|
||||
AS-SET tree. Make sure to use the '-S' flag with all the data sources required
|
||||
for the AS-SET being expanded:
|
||||
|
||||
$./bgpq4 -S RIPE,ARIN AS-VOSTRON
|
||||
@@ -377,10 +388,10 @@ for the AS-SET being expanded:
|
||||
ip prefix-list NN permit 208.86.234.0/24
|
||||
ip prefix-list NN permit 208.86.235.0/24
|
||||
|
||||
The other option is to specify a source for an AS-SET or Route Set using the
|
||||
"::" notation. When bgpq4 detects this, it will look for "::" in the specified
|
||||
AS-SET or RS on the CLI, and in all members of the AS-SET/RS, and for each
|
||||
member with a data source specified in "::" format, it will set the IRRd data
|
||||
The other option is to specify a source for an AS-SET or Route Set using the
|
||||
"::" notation. When bgpq4 detects this, it will look for "::" in the specified
|
||||
AS-SET or RS on the CLI, and in all members of the AS-SET/RS, and for each
|
||||
member with a data source specified in "::" format, it will set the IRRd data
|
||||
source to the given value, query the AS-SET/RS, then reset the data sources back
|
||||
to the default list for the next object in the tree.
|
||||
|
||||
@@ -394,9 +405,9 @@ source to the given value, query the AS-SET/RS, then reset the data sources back
|
||||
ip prefix-list NN permit 208.86.234.0/24
|
||||
ip prefix-list NN permit 208.86.235.0/24
|
||||
|
||||
In comparison to the '-S' flag, this method return all the prefixes under the
|
||||
AS-SET, but the root of the tree "AS-VOSTRON" was queries from RIPE only. None
|
||||
of the member objects used the "::" notation so they were queries from the
|
||||
In comparison to the '-S' flag, this method return all the prefixes under the
|
||||
AS-SET, but the root of the tree "AS-VOSTRON" was queries from RIPE only. None
|
||||
of the member objects used the "::" notation so they were queries from the
|
||||
default source list (which is all sources).
|
||||
|
||||
|
||||
@@ -422,7 +433,7 @@ object.
|
||||
ip prefix-list NN permit 45.65.184.0/22
|
||||
[...]
|
||||
|
||||
When known, use the "::" notation to speicy the authortative data source for
|
||||
When known, use the "::" notation to speicy the authortative data source for
|
||||
an AS-SET or RS instead of the -S flag.
|
||||
|
||||
# PERFORMANCE
|
||||
@@ -446,6 +457,31 @@ Linux can be tuned in the following way:
|
||||
|
||||
sysctl -w net.ipv4.tcp_wmem="4096 65536 2097152"
|
||||
|
||||
# CONTAINER IMAGE
|
||||
|
||||
A multi-arch (linux/amd64 and linux/arm64) container image is built automatically for all tagged releases and `main` branch. The image is based on Alpine Linux and is available on [GitHub Container Registry](https://github.com/bgp/bgpq4/pkgs/container/bgpq4).
|
||||
|
||||
Using the image is as simple as:
|
||||
|
||||
```
|
||||
docker run --rm ghcr.io/bgp/bgpq4:latest -Jl eltel AS20597
|
||||
policy-options {
|
||||
replace:
|
||||
prefix-list eltel {
|
||||
81.9.0.0/20;
|
||||
81.9.32.0/20;
|
||||
81.9.96.0/20;
|
||||
81.222.128.0/20;
|
||||
81.222.160.0/20;
|
||||
81.222.192.0/18;
|
||||
85.249.8.0/21;
|
||||
85.249.224.0/19;
|
||||
89.112.0.0/17;
|
||||
217.170.64.0/19;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
# BUILDING
|
||||
|
||||
This project uses autotools. If you are building from the repository,
|
||||
@@ -478,6 +514,12 @@ generates access-list to standard output and exits with status == 0.
|
||||
In case of errors they are printed to stderr and the program exits with
|
||||
non-zero status.
|
||||
|
||||
# TESTS
|
||||
|
||||
The [tests/](tests/) folder contains reference output data in [text files](tests/reference/). The [generate_outputs.sh](tests/generate_outputs.sh) script is used in the [Github workflow](.github/workflows/unit-tests.yml) to generate the same output data, using the latest commit, and compare the output data to the stored "known-good" reference data, and check there are no changes.
|
||||
|
||||
To update the reference data (i.e. if the bgpq4 output is modified), simply run the script again (`./tests/generate_outputs.sh ./bgpq4 tests/reference`) and commit the changes.
|
||||
|
||||
# AUTHORS
|
||||
|
||||
Alexandre Snarskii, Christian David, Claudio Jeker, Job Snijders,
|
||||
|
||||
15
bgpq4.8
15
bgpq4.8
@@ -40,7 +40,7 @@
|
||||
.Fl H Ar asn
|
||||
.Fl t
|
||||
.Oc
|
||||
.Op Fl 46ABbDdJjNnsXU
|
||||
.Op Fl 46ABbDdJjNnpsXU
|
||||
.Op Fl a Ar asn
|
||||
.Op Fl r Ar len
|
||||
.Op Fl R Ar len
|
||||
@@ -95,7 +95,9 @@ generate config for Juniper (default: Cisco).
|
||||
.It Fl j
|
||||
generate output in JSON format (default: Cisco).
|
||||
.It Fl K
|
||||
generate config for Mikrotik (default: Cisco).
|
||||
generate config for Mikrotik ROSv6 (default: Cisco).
|
||||
.It Fl K7
|
||||
generate config for Mikrotik ROSv7 (default: Cisco).
|
||||
.It Fl l Ar name
|
||||
name of generated entry.
|
||||
.It Fl L Ar limit
|
||||
@@ -107,12 +109,13 @@ maximum prefix-length of accepted prefixes (default: 32 for IPv4 and
|
||||
extra match conditions for Juniper route-filters.
|
||||
.It Fl n
|
||||
generate config for Nokia SR OS MD-CLI (Cisco IOS by default)
|
||||
.It Fl n2
|
||||
generate config for Nokia SR Linux (Cisco IOS by default)
|
||||
.It Fl N
|
||||
generate config for Nokia SR OS classic CLI (Cisco IOS by default).
|
||||
.It Fl p
|
||||
accept routes registered for private ASNs (default: disabled)
|
||||
.It Fl P
|
||||
generate prefix-list (default, backward compatibility).
|
||||
emit prefixes where the origin ASN is 23456 or in the private ASN range
|
||||
(disabled by default).
|
||||
.It Fl r Ar len
|
||||
allow more specific routes starting with specified masklen too.
|
||||
.It Fl R Ar len
|
||||
@@ -130,7 +133,7 @@ generate config for Huawei devices (Cisco IOS by default)
|
||||
.It Fl u
|
||||
generate config for Huawei devices in XPL format (Cisco IOS by default)
|
||||
.It Fl W Ar len
|
||||
generate as-path strings of no more than len items (use 0 for inifinity).
|
||||
generate as-path strings of no more than len items (use 0 for infinity).
|
||||
.It Fl X
|
||||
generate config for Cisco IOS XR devices (plain IOS by default).
|
||||
.It Fl z
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
AC_INIT([bgpq4], m4_esyscmd([tr -d '\n' < VERSION]), job@sobornost.net)
|
||||
AC_INIT([bgpq4], m4_esyscmd([tr -d '\n' < VERSION]), [job@sobornost.net])
|
||||
|
||||
AC_CANONICAL_HOST
|
||||
AM_INIT_AUTOMAKE([subdir-objects foreign])
|
||||
@@ -56,9 +56,8 @@ AM_CONDITIONAL([HOST_NETBSD], [test x$HOST_OS = xnetbsd])
|
||||
AM_CONDITIONAL([HOST_SOLARIS], [test x$HOST_OS = xsolaris])
|
||||
|
||||
AC_PROG_CC
|
||||
AC_PROG_CC_STDC
|
||||
AM_PROG_CC_C_O
|
||||
AC_PROG_LIBTOOL
|
||||
LT_INIT
|
||||
AC_PROG_INSTALL
|
||||
|
||||
AC_ARG_ENABLE(warnings,
|
||||
|
||||
224
expander.c
224
expander.c
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2019-2021 Job Snijders <job@sobornost.net>
|
||||
* Copyright (c) 2019-2022 Job Snijders <job@sobornost.net>
|
||||
* Copyright (c) 2018 Peter Schoenmaker <pds@ntt.net>
|
||||
* Copyright (c) 2007-2019 Alexandre Snarskii <snar@snar.spb.ru>
|
||||
* All rights reserved.
|
||||
@@ -29,6 +29,7 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/select.h>
|
||||
#include <netinet/tcp.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
@@ -183,7 +184,7 @@ int
|
||||
bgpq_expander_add_as(struct bgpq_expander *b, char *as)
|
||||
{
|
||||
char *eoa;
|
||||
uint32_t asno = 0;
|
||||
uint32_t asno = 0;
|
||||
struct asn_entry *asne;
|
||||
|
||||
if (!b || !as)
|
||||
@@ -191,19 +192,19 @@ bgpq_expander_add_as(struct bgpq_expander *b, char *as)
|
||||
|
||||
asno = strtoul(as + 2, &eoa, 10);
|
||||
if (eoa && *eoa != 0) {
|
||||
sx_report(SX_ERROR,"Invalid symbol in AS number: '%c' in %s\n",
|
||||
sx_report(SX_ERROR, "Invalid symbol in AS number: '%c' in %s\n",
|
||||
*eoa, as);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!expand_special_asn &&
|
||||
((asno >= 4200000000ul) || (asno >= 64496 && asno <= 65551))) {
|
||||
sx_report(SX_ERROR,"Invalid AS number: %u\n", asno);
|
||||
if (!expand_special_asn && (asno == 23456 || asno >= 4200000000ul
|
||||
|| (asno >= 64496 && asno <= 65551))) {
|
||||
sx_report(SX_ERROR, "Invalid AS number: %u\n", asno);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((asne = malloc(sizeof(struct asn_entry))) == NULL)
|
||||
sx_report(SX_FATAL, "malloc failed for asn\n");
|
||||
err(1, NULL);
|
||||
|
||||
asne->asn = asno;
|
||||
RB_INSERT(asn_tree, &b->asnlist, asne);
|
||||
@@ -243,46 +244,60 @@ bgpq_expander_add_prefix_range(struct bgpq_expander *b, char *prefix)
|
||||
return sx_prefix_range_parse(b->tree, b->family, b->maxlen, prefix);
|
||||
}
|
||||
|
||||
char*
|
||||
bgpq_get_asset(char *object){
|
||||
char *asset, *d;
|
||||
char *
|
||||
bgpq_get_asset(char *object) {
|
||||
char *d, *asset;
|
||||
|
||||
d = strstr(object, "::");
|
||||
if (d){
|
||||
if (d)
|
||||
d += 2;
|
||||
} else {
|
||||
else
|
||||
d = object;
|
||||
}
|
||||
|
||||
if ((asset = calloc(1, 256)) == NULL)
|
||||
sx_report(SX_FATAL, "calloc failed for asset\n");
|
||||
err(1, NULL);
|
||||
|
||||
memcpy(asset, d, strlen(object) - (d - object));
|
||||
|
||||
return asset;
|
||||
}
|
||||
|
||||
char*
|
||||
bgpq_get_rset(char *object){
|
||||
char *d = strstr(object, "::");
|
||||
if (d){
|
||||
d += 2;
|
||||
} else {
|
||||
d = object;
|
||||
}
|
||||
char *
|
||||
bgpq_get_rset(char *object) {
|
||||
char *d, *rset;
|
||||
|
||||
d = strstr(object, "::");
|
||||
|
||||
if (d)
|
||||
d += 2;
|
||||
else
|
||||
d = object;
|
||||
|
||||
if ((rset = calloc(1, 256)) == NULL)
|
||||
err(1, NULL);
|
||||
|
||||
char *rset = (char*)calloc(1, 256);
|
||||
memcpy(rset, d, strlen(object) - (d - object));
|
||||
|
||||
return rset;
|
||||
}
|
||||
|
||||
char*
|
||||
bgpq_get_source(char *object){
|
||||
char *d = strstr(object, "::");
|
||||
if (d){
|
||||
char *source = (char*)calloc(1, 256);
|
||||
unsigned int slen = d - object;
|
||||
char *
|
||||
bgpq_get_source(char *object) {
|
||||
char *d;
|
||||
char *source;
|
||||
unsigned int slen;
|
||||
|
||||
d = strstr(object, "::");
|
||||
|
||||
if (d) {
|
||||
if ((source = calloc(1, 256)) == NULL)
|
||||
err(1, NULL);
|
||||
|
||||
slen = d - object;
|
||||
memcpy(source, object, slen);
|
||||
return source;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -295,11 +310,13 @@ bgpq_expanded_macro(char *as, struct bgpq_expander *ex,
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct request *bgpq_pipeline(struct bgpq_expander *b,
|
||||
struct request *
|
||||
bgpq_pipeline(struct bgpq_expander *b,
|
||||
int (*callback)(char *, struct bgpq_expander *b, struct request *req),
|
||||
void *udata, char *fmt, ...);
|
||||
|
||||
int bgpq_expand_irrd(struct bgpq_expander *b,
|
||||
int
|
||||
bgpq_expand_irrd(struct bgpq_expander *b,
|
||||
int (*callback)(char*, struct bgpq_expander *b, struct request *req),
|
||||
void *udata, char *fmt, ...);
|
||||
|
||||
@@ -307,9 +324,11 @@ static int
|
||||
bgpq_expanded_macro_limit(char *as, struct bgpq_expander *b,
|
||||
struct request *req)
|
||||
{
|
||||
char *source;
|
||||
struct request *req1;
|
||||
|
||||
if (!strncasecmp(as, "AS-", 3) || strchr(as, '-') || strchr(as, ':')) {
|
||||
struct sx_tentry tkey = { .text = as };
|
||||
char *source;
|
||||
|
||||
if (RB_FIND(tentree, &b->already, &tkey)) {
|
||||
SX_DEBUG(debug_expander > 2, "%s is already expanding, "
|
||||
@@ -330,29 +349,29 @@ bgpq_expanded_macro_limit(char *as, struct bgpq_expander *b,
|
||||
if (pipelining) {
|
||||
if (b->usesource) {
|
||||
source = bgpq_get_source(as);
|
||||
if (source){
|
||||
bgpq_pipeline(b, NULL, NULL, "!s%s\n", source);
|
||||
if (source) {
|
||||
bgpq_pipeline(b, NULL, NULL,
|
||||
"!s%s\n", source);
|
||||
free(source);
|
||||
} else {
|
||||
bgpq_pipeline(
|
||||
b, NULL, NULL, "!s%s\n", b->defaultsources
|
||||
);
|
||||
bgpq_pipeline(b, NULL, NULL,
|
||||
"!s%s\n", b->defaultsources);
|
||||
}
|
||||
}
|
||||
struct request *req1 = bgpq_pipeline(b,
|
||||
bgpq_expanded_macro_limit, NULL, "!i%s\n",
|
||||
bgpq_get_asset(as));
|
||||
|
||||
req1 = bgpq_pipeline(b, bgpq_expanded_macro_limit,
|
||||
NULL, "!i%s\n", bgpq_get_asset(as));
|
||||
req1->depth = req->depth + 1;
|
||||
} else {
|
||||
if (b->usesource) {
|
||||
source = bgpq_get_source(as);
|
||||
if (source) {
|
||||
bgpq_expand_irrd(b, NULL, NULL, "!s%s\n", source);
|
||||
bgpq_expand_irrd(b, NULL, NULL,
|
||||
"!s%s\n", source);
|
||||
free(source);
|
||||
} else {
|
||||
bgpq_expand_irrd(
|
||||
b, NULL, NULL, "!s%s\n", b->defaultsources
|
||||
);
|
||||
bgpq_expand_irrd(b, NULL, NULL,
|
||||
"!s%s\n", b->defaultsources);
|
||||
}
|
||||
}
|
||||
b->cdepth++;
|
||||
@@ -362,8 +381,7 @@ bgpq_expanded_macro_limit(char *as, struct bgpq_expander *b,
|
||||
}
|
||||
} else {
|
||||
SX_DEBUG(debug_expander > 2, "ignoring %s at depth %i\n",
|
||||
as,
|
||||
b->cdepth ? (b->cdepth + 1) : (req->depth + 1));
|
||||
as, b->cdepth ? (b->cdepth + 1) : (req->depth + 1));
|
||||
}
|
||||
} else if (!strncasecmp(as, "AS", 2)) {
|
||||
struct sx_tentry tkey = { .text = as };
|
||||
@@ -419,14 +437,21 @@ bgpq_expanded_v6prefix(char *prefix, struct bgpq_expander *ex,
|
||||
return 1;
|
||||
}
|
||||
|
||||
static char*
|
||||
bgpq_get_irrd_sources(int fd) {
|
||||
int ret;
|
||||
char *query = "!s-lc\n";
|
||||
int qlen = strlen(query);
|
||||
const unsigned int rsize = 256;
|
||||
char *response = (char*)calloc(1, rsize);
|
||||
char *sources = (char*)calloc(1, rsize);
|
||||
static char *
|
||||
bgpq_get_irrd_sources(int fd)
|
||||
{
|
||||
char *query, *response, *sources, *start, *end;
|
||||
const unsigned int rsize = 256;
|
||||
unsigned int slen;
|
||||
int ret, qlen;
|
||||
|
||||
query = "!s-lc\n";
|
||||
qlen = strlen(query);
|
||||
|
||||
if ((response = calloc(1, rsize)) == NULL)
|
||||
err(1, NULL);
|
||||
if ((sources = calloc(1, rsize)) == NULL)
|
||||
err(1, NULL);
|
||||
|
||||
SX_DEBUG(debug_expander, "Requesting source list %s", query);
|
||||
if ((ret = write(fd, query, strlen(query))) != qlen) {
|
||||
@@ -456,10 +481,10 @@ bgpq_get_irrd_sources(int fd) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
char *start = strchr(response, '\n');
|
||||
if (start){
|
||||
start = strchr(response, '\n');
|
||||
if (start) {
|
||||
start += 1;
|
||||
char *end = strchr(start, '\n');
|
||||
end = strchr(start, '\n');
|
||||
if (!end) {
|
||||
sx_report(SX_ERROR, "No 2nd newline in response '%s': %s\n",
|
||||
response, query);
|
||||
@@ -468,12 +493,11 @@ bgpq_get_irrd_sources(int fd) {
|
||||
free(response);
|
||||
exit(1);
|
||||
}
|
||||
unsigned int slen = end - start;
|
||||
if (slen > rsize) {
|
||||
memcpy(sources, start, rsize-1);
|
||||
} else {
|
||||
slen = end - start;
|
||||
if (slen > rsize)
|
||||
memcpy(sources, start, rsize - 1);
|
||||
else
|
||||
memcpy(sources, start, slen);
|
||||
}
|
||||
} else {
|
||||
sx_report(SX_ERROR, "No 1st newline in response '%s': %s\n",
|
||||
response, query);
|
||||
@@ -482,17 +506,19 @@ bgpq_get_irrd_sources(int fd) {
|
||||
free(response);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
free(response);
|
||||
return sources;
|
||||
}
|
||||
|
||||
int bgpq_pipeline_dequeue(int fd, struct bgpq_expander *b);
|
||||
|
||||
static struct request *
|
||||
request_alloc(char *request, int (*callback)(char *, struct bgpq_expander *,
|
||||
struct request *), void *udata)
|
||||
{
|
||||
struct request *bp = malloc(sizeof(struct request));
|
||||
struct request *bp;
|
||||
|
||||
if ((bp = malloc(sizeof(struct request))) == NULL)
|
||||
err(1, NULL);
|
||||
|
||||
if (!bp)
|
||||
return NULL;
|
||||
@@ -521,9 +547,9 @@ bgpq_pipeline(struct bgpq_expander *b,
|
||||
int (*callback)(char *, struct bgpq_expander *, struct request *),
|
||||
void *udata, char *fmt, ...)
|
||||
{
|
||||
struct request *bp = NULL;
|
||||
char request[256];
|
||||
int ret;
|
||||
struct request *bp = NULL;
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
@@ -550,12 +576,14 @@ bgpq_pipeline(struct bgpq_expander *b,
|
||||
sx_report(SX_FATAL, "Error writing request: %s\n",
|
||||
strerror(errno));
|
||||
}
|
||||
|
||||
bp->offset=ret;
|
||||
if (ret == bp->size) {
|
||||
|
||||
if (ret == bp->size)
|
||||
STAILQ_INSERT_TAIL(&b->rq, bp, next);
|
||||
} else {
|
||||
else
|
||||
STAILQ_INSERT_TAIL(&b->wq, bp, next);
|
||||
}
|
||||
|
||||
} else
|
||||
STAILQ_INSERT_TAIL(&b->wq, bp, next);
|
||||
|
||||
@@ -704,10 +732,8 @@ have:
|
||||
unsigned long togot = strtoul(response + 1, &eon, 10);
|
||||
char *recvbuffer = malloc(togot + 2);
|
||||
|
||||
if (!recvbuffer) {
|
||||
sx_report(SX_FATAL, "error allocating %lu "
|
||||
"bytes: %s\n", togot + 2, strerror(errno));
|
||||
}
|
||||
if (recvbuffer == NULL)
|
||||
err(1, NULL);
|
||||
|
||||
memset(recvbuffer, 0, togot + 2);
|
||||
|
||||
@@ -815,7 +841,7 @@ have3:
|
||||
if (b->validate_asns)
|
||||
bgpq_expander_invalidate_asn(b, req->request);
|
||||
} else if (response[0] == 'D') {
|
||||
sx_report(SX_ERROR, "Key not found expanding %s",
|
||||
SX_DEBUG(debug_expander, "Key not found expanding %s",
|
||||
req->request);
|
||||
if (b->validate_asns)
|
||||
bgpq_expander_invalidate_asn(b, req->request);
|
||||
@@ -981,7 +1007,7 @@ have3:
|
||||
if (b->validate_asns)
|
||||
bgpq_expander_invalidate_asn(b, request);
|
||||
} else if (response[0] == 'D') {
|
||||
sx_report(SX_ERROR, "Key not found expanding %s",
|
||||
SX_DEBUG(debug_expander, "Key not found expanding %s",
|
||||
req->request);
|
||||
if (b->validate_asns)
|
||||
bgpq_expander_invalidate_asn(b, request);
|
||||
@@ -1004,11 +1030,13 @@ have3:
|
||||
int
|
||||
bgpq_expand(struct bgpq_expander *b)
|
||||
{
|
||||
int fd = -1, err, ret, aquery = 0;
|
||||
char *source;
|
||||
struct slentry *mc;
|
||||
struct addrinfo hints, *res = NULL, *rp;
|
||||
struct linger sl;
|
||||
struct asn_entry *asne;
|
||||
int fd = -1, err, ret, aquery = 0, nodelay = 1;
|
||||
int slen;
|
||||
|
||||
sl.l_onoff = 1;
|
||||
sl.l_linger = 5;
|
||||
@@ -1047,15 +1075,12 @@ bgpq_expand(struct bgpq_expander *b)
|
||||
fd = -1;
|
||||
continue;
|
||||
}
|
||||
err = sx_maxsockbuf(fd, SO_SNDBUF);
|
||||
if (err > 0) {
|
||||
SX_DEBUG(debug_expander, "Acquired sendbuf of %i "
|
||||
"bytes\n", err);
|
||||
} else {
|
||||
close(fd);
|
||||
fd = -1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &nodelay,
|
||||
sizeof(nodelay)) == -1)
|
||||
SX_DEBUG(debug_expander, "Unable to set TCP_NODELAY on"
|
||||
" socket: %s\n", strerror(errno));
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1133,10 +1158,11 @@ bgpq_expand(struct bgpq_expander *b)
|
||||
}
|
||||
}
|
||||
|
||||
if (b->usesource) {
|
||||
if (b->sources && b->sources[0] != 0) {
|
||||
b->defaultsources = strdup(b->sources);
|
||||
} else if (b->usesource) {
|
||||
if (b->sources && b->sources[0] != 0) {
|
||||
b->defaultsources = (char*)calloc(1, strlen(b->sources));
|
||||
strcpy(b->defaultsources, b->sources);
|
||||
b->defaultsources = strdup(b->sources);
|
||||
} else {
|
||||
b->defaultsources = bgpq_get_irrd_sources(b->fd);
|
||||
}
|
||||
@@ -1145,7 +1171,7 @@ bgpq_expand(struct bgpq_expander *b)
|
||||
}
|
||||
|
||||
if (b->sources && b->sources[0] != 0) {
|
||||
int slen = strlen(b->sources) + 4;
|
||||
slen = strlen(b->sources) + 4;
|
||||
if (slen < 256)
|
||||
slen = 256;
|
||||
char sources[slen];
|
||||
@@ -1185,7 +1211,7 @@ bgpq_expand(struct bgpq_expander *b)
|
||||
STAILQ_FOREACH(mc, &b->macroses, entry) {
|
||||
if (!b->maxdepth && RB_EMPTY(&b->stoplist)) {
|
||||
if (b->usesource) {
|
||||
char *source = bgpq_get_source(mc->text);
|
||||
source = bgpq_get_source(mc->text);
|
||||
if (source){
|
||||
if (pipelining){
|
||||
bgpq_pipeline(b, NULL, NULL, "!s%s\n", source);
|
||||
@@ -1245,7 +1271,7 @@ bgpq_expand(struct bgpq_expander *b)
|
||||
if (b->generation >= T_PREFIXLIST || b->validate_asns) {
|
||||
STAILQ_FOREACH(mc, &b->rsets, entry) {
|
||||
if (b->usesource) {
|
||||
char *source = bgpq_get_source(mc->text);
|
||||
source = bgpq_get_source(mc->text);
|
||||
if (source){
|
||||
if (pipelining){
|
||||
printf("Checking %s\n", bgpq_get_rset(mc->text));
|
||||
@@ -1348,6 +1374,7 @@ bgpq_expand(struct bgpq_expander *b)
|
||||
fl &= ~O_NONBLOCK;
|
||||
fcntl(fd, F_SETFL, fl);
|
||||
}
|
||||
|
||||
close(fd);
|
||||
free(b->defaultsources);
|
||||
|
||||
@@ -1355,8 +1382,8 @@ bgpq_expand(struct bgpq_expander *b)
|
||||
}
|
||||
|
||||
void
|
||||
sx_radix_node_freeall(struct sx_radix_node *n) {
|
||||
|
||||
sx_radix_node_freeall(struct sx_radix_node *n)
|
||||
{
|
||||
if (n->l != NULL)
|
||||
sx_radix_node_freeall(n->l);
|
||||
|
||||
@@ -1375,20 +1402,23 @@ sx_radix_node_freeall(struct sx_radix_node *n) {
|
||||
}
|
||||
|
||||
void
|
||||
sx_radix_tree_freeall(struct sx_radix_tree *t) {
|
||||
|
||||
sx_radix_tree_freeall(struct sx_radix_tree *t)
|
||||
{
|
||||
if (t->head != NULL)
|
||||
sx_radix_node_freeall(t->head);
|
||||
|
||||
free(t);
|
||||
}
|
||||
|
||||
/* XXX: needs cleaning up / figuring out */
|
||||
void
|
||||
bgpq_prequest_freeall(struct bgpq_prequest *bpr) {
|
||||
bgpq_prequest_freeall(struct bgpq_prequest *bpr)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
expander_freeall(struct bgpq_expander *expander) {
|
||||
expander_freeall(struct bgpq_expander *expander)
|
||||
{
|
||||
struct sx_tentry *var, *nxt;
|
||||
struct asn_entry *asne, *asne_next;
|
||||
|
||||
|
||||
9
extern.h
9
extern.h
@@ -59,9 +59,11 @@ typedef enum {
|
||||
V_NOKIA,
|
||||
V_HUAWEI,
|
||||
V_HUAWEI_XPL,
|
||||
V_MIKROTIK,
|
||||
V_MIKROTIK6,
|
||||
V_MIKROTIK7,
|
||||
V_NOKIA_MD,
|
||||
V_ARISTA
|
||||
V_ARISTA,
|
||||
V_NOKIA_SRL,
|
||||
} bgpq_vendor_t;
|
||||
|
||||
typedef enum {
|
||||
@@ -147,9 +149,6 @@ void sx_radix_tree_freeall(struct sx_radix_tree *t);
|
||||
void bgpq_prequest_freeall(struct bgpq_prequest *bpr);
|
||||
void expander_freeall(struct bgpq_expander *expander);
|
||||
|
||||
/* s - number of opened socket, dir is either SO_SNDBUF or SO_RCVBUF */
|
||||
int sx_maxsockbuf(int s, int dir);
|
||||
|
||||
#ifndef HAVE_STRLCPY
|
||||
size_t strlcpy(char *dst, const char *src, size_t size);
|
||||
#endif
|
||||
|
||||
52
main.c
52
main.c
@@ -51,7 +51,7 @@ static int
|
||||
usage(int ecode)
|
||||
{
|
||||
printf("\nUsage: bgpq4 [-h host[:port]] [-S sources] [-E|G|H <num>"
|
||||
"|f <num>|t] [-46ABbdJjKNnwXz] [-R len] <OBJECTS> ... "
|
||||
"|f <num>|t] [-46ABbdJjKNnpwXz] [-R len] <OBJECTS> ... "
|
||||
"[EXCEPT <OBJECTS> ...]\n");
|
||||
printf("\nVendor targets:\n");
|
||||
printf(" no option : Cisco IOS Classic (default)\n");
|
||||
@@ -60,10 +60,12 @@ usage(int ecode)
|
||||
printf(" -u : Huawei XPL\n");
|
||||
printf(" -j : JSON\n");
|
||||
printf(" -J : Juniper Junos\n");
|
||||
printf(" -K : MikroTik RouterOS\n");
|
||||
printf(" -K : MikroTik RouterOSv6\n");
|
||||
printf(" -K7 : MikroTik RouterOSv7\n");
|
||||
printf(" -b : NIC.CZ BIRD\n");
|
||||
printf(" -N : Nokia SR OS (Classic CLI)\n");
|
||||
printf(" -n : Nokia SR OS (MD-CLI)\n");
|
||||
printf(" -n2 : Nokia SR Linux\n");
|
||||
printf(" -B : OpenBSD OpenBGPD\n");
|
||||
printf(" -e : Arista EOS\n");
|
||||
printf(" -F fmt : User defined format (example: '-F %%n/%%l')\n");
|
||||
@@ -80,6 +82,7 @@ usage(int ecode)
|
||||
"registered routes\n");
|
||||
|
||||
printf("\nOutput modifiers:\n");
|
||||
printf(" -3 : assume that your device is asn32-safe (default)\n");
|
||||
printf(" -A : try to aggregate prefix-lists/route-filters\n");
|
||||
printf(" -E : generate extended access-list (Cisco), "
|
||||
"route-filter (Juniper)\n"
|
||||
@@ -91,6 +94,7 @@ usage(int ecode)
|
||||
printf(" -M match : extra match conditions for JunOS route-filters\n");
|
||||
printf(" -l name : use specified name for generated access/prefix/.."
|
||||
" list\n");
|
||||
printf(" -p : allow special ASNs like 23456 or in the private range\n");
|
||||
printf(" -R len : allow more specific routes up to specified masklen\n");
|
||||
printf(" -r len : allow more specific routes from masklen specified\n");
|
||||
printf(" -s : generate sequence numbers in prefix-lists (IOS only)\n");
|
||||
@@ -133,9 +137,9 @@ static void
|
||||
vendor_exclusive(void)
|
||||
{
|
||||
fprintf(stderr, "-b (BIRD), -B (OpenBGPD), -F (formatted), -J (Junos),"
|
||||
" -j (JSON), -N (Nokia SR OS Classic), -n (Nokia SR OS MD-CLI),"
|
||||
" -U (Huawei), -u (Huawei XPL), -e (Arista) and -X (IOS XR) options "
|
||||
" are mutually exclusive\n");
|
||||
" -j (JSON), -K[7] (Microtik ROS), -N (Nokia SR OS Classic),"
|
||||
" -n (Nokia SR OS MD-CLI), -U (Huawei), -u (Huawei XPL),"
|
||||
"-e (Arista) and -X (IOS XR) options are mutually exclusive\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -197,8 +201,18 @@ main(int argc, char* argv[])
|
||||
expander.sources=getenv("IRRD_SOURCES");
|
||||
|
||||
while ((c = getopt(argc, argv,
|
||||
"46a:AbBdDEeF:S:jJKf:l:L:m:M:NnW:pr:R:G:H:tTh:UuwXsvz")) != EOF) {
|
||||
"23467a:AbBdDEeF:S:jJKf:l:L:m:M:NnpW:r:R:G:H:tTh:UuwXsvz")) != EOF) {
|
||||
switch (c) {
|
||||
case '2':
|
||||
if (expander.vendor != V_NOKIA_MD) {
|
||||
sx_report(SX_FATAL, "'2' can only be used after -n\n");
|
||||
exit(1);
|
||||
}
|
||||
expander.vendor = V_NOKIA_SRL;
|
||||
break;
|
||||
case '3':
|
||||
/* do nothing, 32-bit ASN support is assumed */
|
||||
break;
|
||||
case '4':
|
||||
/* do nothing, expander already configured for IPv4 */
|
||||
if (expander.family == AF_INET6) {
|
||||
@@ -218,6 +232,13 @@ main(int argc, char* argv[])
|
||||
expander.family = AF_INET6;
|
||||
expander.tree->family = AF_INET6;
|
||||
break;
|
||||
case '7':
|
||||
if (expander.vendor != V_MIKROTIK6) {
|
||||
sx_report(SX_FATAL, "'7' can only be used after -K\n");
|
||||
exit(1);
|
||||
}
|
||||
expander.vendor = V_MIKROTIK7;
|
||||
break;
|
||||
case 'a':
|
||||
parseasnumber(&expander, optarg);
|
||||
break;
|
||||
@@ -297,10 +318,7 @@ main(int argc, char* argv[])
|
||||
case 'K':
|
||||
if (expander.vendor)
|
||||
vendor_exclusive();
|
||||
expander.vendor = V_MIKROTIK;
|
||||
break;
|
||||
case 'p':
|
||||
expand_special_asn = 1;
|
||||
expander.vendor = V_MIKROTIK6;
|
||||
break;
|
||||
case 'r':
|
||||
refineLow = strtoul(optarg, NULL, 10);
|
||||
@@ -389,6 +407,9 @@ main(int argc, char* argv[])
|
||||
vendor_exclusive();
|
||||
expander.vendor = V_NOKIA_MD;
|
||||
break;
|
||||
case 'p':
|
||||
expand_special_asn = 1;
|
||||
break;
|
||||
case 't':
|
||||
if (expander.generation)
|
||||
exclusive();
|
||||
@@ -451,7 +472,8 @@ main(int argc, char* argv[])
|
||||
switch (vendor) {
|
||||
case V_ARISTA:
|
||||
case V_CISCO:
|
||||
case V_MIKROTIK:
|
||||
case V_MIKROTIK6:
|
||||
case V_MIKROTIK7:
|
||||
expander.aswidth = 4;
|
||||
break;
|
||||
case V_CISCO_XR:
|
||||
@@ -460,6 +482,7 @@ main(int argc, char* argv[])
|
||||
case V_JUNIPER:
|
||||
case V_NOKIA:
|
||||
case V_NOKIA_MD:
|
||||
case V_NOKIA_SRL:
|
||||
expander.aswidth = 8;
|
||||
break;
|
||||
case V_BIRD:
|
||||
@@ -479,6 +502,7 @@ main(int argc, char* argv[])
|
||||
case V_JUNIPER:
|
||||
case V_NOKIA:
|
||||
case V_NOKIA_MD:
|
||||
case V_NOKIA_SRL:
|
||||
expander.aswidth = 8;
|
||||
break;
|
||||
}
|
||||
@@ -551,7 +575,7 @@ main(int argc, char* argv[])
|
||||
}
|
||||
|
||||
if (aggregate
|
||||
&& (expander.vendor == V_NOKIA_MD || expander.vendor == V_NOKIA)
|
||||
&& (expander.vendor == V_NOKIA_MD || expander.vendor == V_NOKIA || expander.vendor == V_NOKIA_SRL)
|
||||
&& expander.generation != T_PREFIXLIST) {
|
||||
sx_report(SX_FATAL, "Sorry, aggregation (-A) is not supported with "
|
||||
"ip-prefix-lists (-E) on Nokia.\n");
|
||||
@@ -559,7 +583,7 @@ main(int argc, char* argv[])
|
||||
}
|
||||
|
||||
if (refine
|
||||
&& (expander.vendor == V_NOKIA_MD || expander.vendor == V_NOKIA)
|
||||
&& (expander.vendor == V_NOKIA_MD || expander.vendor == V_NOKIA || expander.vendor == V_NOKIA_SRL)
|
||||
&& expander.generation != T_PREFIXLIST) {
|
||||
sx_report(SX_FATAL, "Sorry, more-specifics (-R) is not supported with "
|
||||
"ip-prefix-lists (-E) on Nokia.\n");
|
||||
@@ -567,7 +591,7 @@ main(int argc, char* argv[])
|
||||
}
|
||||
|
||||
if (refineLow
|
||||
&& (expander.vendor == V_NOKIA_MD || expander.vendor == V_NOKIA)
|
||||
&& (expander.vendor == V_NOKIA_MD || expander.vendor == V_NOKIA || expander.vendor == V_NOKIA_SRL)
|
||||
&& expander.generation != T_PREFIXLIST) {
|
||||
sx_report(SX_FATAL, "Sorry, more-specifics (-r) is not supported with "
|
||||
"ip-prefix-lists (-E) on Nokia.\n");
|
||||
|
||||
154
printer.c
154
printer.c
@@ -40,6 +40,13 @@
|
||||
|
||||
extern int debug_expander;
|
||||
|
||||
#define max(a,b) \
|
||||
({ \
|
||||
__typeof__ (a) _a = (a); \
|
||||
__typeof__ (b) _b = (b); \
|
||||
_a > _b ? _a : _b; \
|
||||
})
|
||||
|
||||
static void
|
||||
bgpq4_print_cisco_aspath(FILE *f, struct bgpq_expander *b)
|
||||
{
|
||||
@@ -82,7 +89,7 @@ bgpq4_print_cisco_aspath(FILE *f, struct bgpq_expander *b)
|
||||
static void
|
||||
bgpq4_print_cisco_xr_aspath(FILE *f, struct bgpq_expander *b)
|
||||
{
|
||||
int nc = 0, comma = 1;
|
||||
int nc = 0, comma = 0;
|
||||
struct asn_entry *asne, find, *res;
|
||||
|
||||
fprintf(f, "as-path-set %s", b->name);
|
||||
@@ -91,6 +98,7 @@ bgpq4_print_cisco_xr_aspath(FILE *f, struct bgpq_expander *b)
|
||||
if ((res = RB_FIND(asn_tree, &b->asnlist, &find)) != NULL) {
|
||||
fprintf(f, "\n ios-regex '^%u(_%u)*$'", res->asn, res->asn);
|
||||
RB_REMOVE(asn_tree, &b->asnlist, res);
|
||||
comma = 1;
|
||||
}
|
||||
|
||||
RB_FOREACH(asne, asn_tree, &b->asnlist) {
|
||||
@@ -1370,6 +1378,60 @@ checkSon:
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
bgpq4_print_nokia_srl_prefix(struct sx_radix_node *n, void *ff)
|
||||
{
|
||||
char prefix[128];
|
||||
FILE *f = (FILE*)ff;
|
||||
|
||||
if (n->isGlue)
|
||||
goto checkSon;
|
||||
|
||||
if (!f)
|
||||
f = stdout;
|
||||
|
||||
sx_prefix_snprintf(n->prefix, prefix, sizeof(prefix));
|
||||
|
||||
if (!n->isAggregate) {
|
||||
fprintf(f, " prefix %s mask-length-range exact { }\n", prefix);
|
||||
} else {
|
||||
fprintf(f, " prefix %s mask-length-range %u..%u { }\n", prefix,
|
||||
max(n->aggregateLow,n->prefix->masklen), n->aggregateHi);
|
||||
}
|
||||
|
||||
checkSon:
|
||||
if (n->son)
|
||||
bgpq4_print_nokia_srl_prefix(n->son, ff);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
FILE *f;
|
||||
int seq;
|
||||
} NOKIA_SRL_IPFILTER_PARAMS;
|
||||
|
||||
static void
|
||||
bgpq4_print_nokia_srl_ipfilter(struct sx_radix_node *n, void *ff)
|
||||
{
|
||||
char prefix[128];
|
||||
NOKIA_SRL_IPFILTER_PARAMS *params = (NOKIA_SRL_IPFILTER_PARAMS*) ff;
|
||||
|
||||
if (n->isGlue)
|
||||
goto checkSon;
|
||||
|
||||
if (!params->f)
|
||||
params->f = stdout;
|
||||
|
||||
sx_prefix_snprintf(n->prefix, prefix, sizeof(prefix));
|
||||
|
||||
fprintf(params->f, " entry %d {\n action { accept { } }\n match { source-ip { prefix %s } } }\n", params->seq, prefix);
|
||||
params->seq += 10;
|
||||
|
||||
checkSon:
|
||||
if (n->son) {
|
||||
bgpq4_print_nokia_srl_ipfilter(n->son, ff);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
bgpq4_print_juniper_prefixlist(FILE *f, struct bgpq_expander *b)
|
||||
{
|
||||
@@ -1717,7 +1779,46 @@ bgpq4_print_nokia_md_ipprefixlist(FILE *f, struct bgpq_expander *b)
|
||||
}
|
||||
|
||||
static void
|
||||
bgpq4_print_kprefix(struct sx_radix_node *n, void *ff)
|
||||
bgpq4_print_nokia_srl_prefixset(FILE *f, struct bgpq_expander *b)
|
||||
{
|
||||
bname = b->name ? b->name : "NN";
|
||||
|
||||
fprintf(f, "/routing-policy\ndelete prefix-set \"%s\"\n",
|
||||
bname);
|
||||
|
||||
fprintf(f, "prefix-set \"%s\" {\n", bname);
|
||||
|
||||
if (!sx_radix_tree_empty(b->tree)) {
|
||||
sx_radix_tree_foreach(b->tree, bgpq4_print_nokia_srl_prefix, f);
|
||||
}
|
||||
|
||||
fprintf(f,"}\n");
|
||||
}
|
||||
|
||||
static void
|
||||
bgpq4_print_nokia_srl_aclipfilter(FILE *f, struct bgpq_expander *b)
|
||||
{
|
||||
bname = b->name ? b->name : "NN";
|
||||
|
||||
fprintf(f,"/acl \ndelete ipv%c-filter \"%s\"\n",
|
||||
b->tree->family == AF_INET ? '4' : '6', bname);
|
||||
|
||||
fprintf(f,"ipv%c-filter \"%s\" {\n",
|
||||
b->tree->family == AF_INET ? '4' : '6', bname);
|
||||
|
||||
if (!sx_radix_tree_empty(b->tree)) {
|
||||
NOKIA_SRL_IPFILTER_PARAMS params = { f, 10 };
|
||||
sx_radix_tree_foreach(b->tree, bgpq4_print_nokia_srl_ipfilter, ¶ms);
|
||||
} else {
|
||||
fprintf(f,"# generated ipv%c-filter '%s' is empty\n",
|
||||
b->tree->family == AF_INET ? '4' : '6', bname);
|
||||
}
|
||||
|
||||
fprintf(f,"}\n");
|
||||
}
|
||||
|
||||
static void
|
||||
bgpq4_print_k6prefix(struct sx_radix_node *n, void *ff)
|
||||
{
|
||||
char prefix[128];
|
||||
FILE *f = (FILE*)ff;
|
||||
@@ -1745,16 +1846,52 @@ bgpq4_print_kprefix(struct sx_radix_node *n, void *ff)
|
||||
|
||||
checkSon:
|
||||
if (n->son)
|
||||
bgpq4_print_kprefix(n->son, ff);
|
||||
bgpq4_print_k6prefix(n->son, ff);
|
||||
}
|
||||
|
||||
static void
|
||||
bgpq4_print_k7prefix(struct sx_radix_node *n, void *ff)
|
||||
{
|
||||
char prefix[128];
|
||||
FILE *f = (FILE*)ff;
|
||||
|
||||
if (!f)
|
||||
f = stdout;
|
||||
|
||||
if (n->isGlue)
|
||||
goto checkSon;
|
||||
|
||||
sx_prefix_snprintf_sep(n->prefix, prefix, sizeof(prefix), "/");
|
||||
|
||||
if (n->isAggregate)
|
||||
fprintf(f,"/routing filter rule add chain=\""
|
||||
"%s-%s\" rule=\"if (dst in %s && dst-len in %d-%d) {accept}\"\n",
|
||||
bname ? bname : "NN",
|
||||
n->prefix->family == AF_INET ? "V4" : "V6",
|
||||
prefix, n->aggregateLow, n->aggregateHi);
|
||||
else
|
||||
fprintf(f,"/routing filter rule add chain=\""
|
||||
"%s-%s\" rule=\"if (dst==%s) {accept}\"\n",
|
||||
bname ? bname : "NN",
|
||||
n->prefix->family == AF_INET ? "V4" : "V6",
|
||||
prefix);
|
||||
|
||||
checkSon:
|
||||
if (n->son)
|
||||
bgpq4_print_k7prefix(n->son, ff);
|
||||
}
|
||||
|
||||
static void
|
||||
bgpq4_print_mikrotik_prefixlist(FILE *f, struct bgpq_expander *b)
|
||||
{
|
||||
bname = b->name ? b->name : "NN";
|
||||
void *cbfunc = bgpq4_print_k6prefix;
|
||||
|
||||
if (b->vendor == V_MIKROTIK7)
|
||||
cbfunc = bgpq4_print_k7prefix;
|
||||
|
||||
if (!sx_radix_tree_empty(b->tree)) {
|
||||
sx_radix_tree_foreach(b->tree, bgpq4_print_kprefix, f);
|
||||
sx_radix_tree_foreach(b->tree, cbfunc, f);
|
||||
} else {
|
||||
fprintf(f, "# generated prefix-list %s is empty\n", bname);
|
||||
}
|
||||
@@ -1791,13 +1928,17 @@ bgpq4_print_prefixlist(FILE *f, struct bgpq_expander *b)
|
||||
case V_NOKIA_MD:
|
||||
bgpq4_print_nokia_md_ipprefixlist(f, b);
|
||||
break;
|
||||
case V_NOKIA_SRL:
|
||||
bgpq4_print_nokia_srl_prefixset(f, b);
|
||||
break;
|
||||
case V_HUAWEI:
|
||||
bgpq4_print_huawei_prefixlist(f, b);
|
||||
break;
|
||||
case V_HUAWEI_XPL:
|
||||
bgpq4_print_huawei_xpl_prefixlist(f, b);
|
||||
break;
|
||||
case V_MIKROTIK:
|
||||
case V_MIKROTIK6:
|
||||
case V_MIKROTIK7:
|
||||
bgpq4_print_mikrotik_prefixlist(f, b);
|
||||
break;
|
||||
case V_ARISTA:
|
||||
@@ -1826,6 +1967,9 @@ bgpq4_print_eacl(FILE *f, struct bgpq_expander *b)
|
||||
case V_NOKIA_MD:
|
||||
bgpq4_print_nokia_md_prefixlist(f, b);
|
||||
break;
|
||||
case V_NOKIA_SRL:
|
||||
bgpq4_print_nokia_srl_aclipfilter(f, b);
|
||||
break;
|
||||
default:
|
||||
sx_report(SX_FATAL, "unreachable point\n");
|
||||
}
|
||||
|
||||
117
sx_maxsockbuf.c
117
sx_maxsockbuf.c
@@ -1,117 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2019-2020 Job Snijders <job@sobornost.net>
|
||||
* Copyright (c) 2007-2019 Alexandre Snarskii <snar@snar.spb.ru>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "extern.h"
|
||||
#include "sx_report.h"
|
||||
|
||||
int
|
||||
sx_maxsockbuf(int s, int dir)
|
||||
{
|
||||
int optval = 0, voptval;
|
||||
int hiconf = -1, loconf = -1;
|
||||
unsigned int voptlen;
|
||||
int phase = 0, iterations = 0;
|
||||
|
||||
if (s < 0) {
|
||||
sx_report(SX_FATAL,"Unable to maximize sockbuf on invalid "
|
||||
"socket %i\n", s);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
voptlen = sizeof(optval);
|
||||
|
||||
if (getsockopt(s, SOL_SOCKET, dir, (void*)&optval, &voptlen) == -1) {
|
||||
sx_report(SX_ERROR,"initial getsockopt failed: %s\n",
|
||||
strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
iterations++;
|
||||
|
||||
if (phase == 0)
|
||||
optval <<= 1;
|
||||
else {
|
||||
if (optval == (hiconf + loconf) / 2)
|
||||
break;
|
||||
optval = (hiconf + loconf) / 2;
|
||||
}
|
||||
|
||||
if (setsockopt(s, SOL_SOCKET, dir, (void*)&optval,
|
||||
sizeof(optval)) == -1) {
|
||||
|
||||
if (phase == 0)
|
||||
phase = 1;
|
||||
|
||||
hiconf = optval;
|
||||
|
||||
continue;
|
||||
} else {
|
||||
loconf = optval;
|
||||
}
|
||||
|
||||
voptlen = sizeof(voptval);
|
||||
|
||||
if (getsockopt(s, SOL_SOCKET, dir, (void*)&voptval,
|
||||
&voptlen) == -1) {
|
||||
sx_report(SX_ERROR,"getsockopt failed: %s\n",
|
||||
strerror(errno));
|
||||
return -1;
|
||||
} else if (voptval < optval) {
|
||||
if (phase == 0) {
|
||||
phase = 1;
|
||||
optval >>= 1;
|
||||
continue;
|
||||
} else if (phase == 1) {
|
||||
phase = 2;
|
||||
optval -= 2048;
|
||||
continue;
|
||||
} else
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
voptlen = sizeof(voptval);
|
||||
if (getsockopt(s, SOL_SOCKET, dir, (void*)&voptval,
|
||||
&voptlen) == -1) {
|
||||
sx_report(SX_ERROR,"getsockopt(final stage) failed: %s\n",
|
||||
strerror(errno));
|
||||
return -1;
|
||||
} else
|
||||
return voptval;
|
||||
}
|
||||
90
tests/generate_outputs.sh
Executable file
90
tests/generate_outputs.sh
Executable file
@@ -0,0 +1,90 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
if [ $# -ne 2 ]
|
||||
then
|
||||
echo "Usage: pass the following arguments in order:"
|
||||
echo ""
|
||||
echo "path to bgpq4 binary"
|
||||
echo "output directory path"
|
||||
echo ""
|
||||
echo "${0} ./bgpq4 /tmp"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
BGPQ4_PATH="${1}"
|
||||
TEST_ASN="112"
|
||||
TEST_AS_SET="AS-AS112"
|
||||
OUT_DIR="${2}"
|
||||
|
||||
if [ ! -f "${BGPQ4_PATH}" ]
|
||||
then
|
||||
echo "File ${BGPQ4_PATH} does't exist"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -e "${OUT_DIR}" ]
|
||||
then
|
||||
echo "Output directory ${OUT_DIR} does't exist"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Test the IPv4 output formatting for each supported NOS:
|
||||
"${BGPQ4_PATH}" -4 -b "AS${TEST_ASN}" > "${OUT_DIR}/bird--4.txt"
|
||||
"${BGPQ4_PATH}" -4 -e "AS${TEST_ASN}" > "${OUT_DIR}/eos--4.txt"
|
||||
"${BGPQ4_PATH}" -4 -F '%n/%l ' "AS${TEST_ASN}" > "${OUT_DIR}/formated--4.txt"
|
||||
"${BGPQ4_PATH}" -4 -U "AS${TEST_ASN}" > "${OUT_DIR}/huawei--4.txt"
|
||||
"${BGPQ4_PATH}" -4 -u "AS${TEST_ASN}" > "${OUT_DIR}/huawei-xpl--4.txt"
|
||||
"${BGPQ4_PATH}" -4 "AS${TEST_ASN}" > "${OUT_DIR}/ios--4.txt"
|
||||
"${BGPQ4_PATH}" -4 -X "AS${TEST_ASN}" > "${OUT_DIR}/ios-xr--4.txt"
|
||||
"${BGPQ4_PATH}" -4 -j "AS${TEST_ASN}" > "${OUT_DIR}/json--4.txt"
|
||||
"${BGPQ4_PATH}" -4 -J "AS${TEST_ASN}" > "${OUT_DIR}/junos--4.txt"
|
||||
"${BGPQ4_PATH}" -4 -B "AS${TEST_ASN}" > "${OUT_DIR}/openbgpd--4.txt"
|
||||
"${BGPQ4_PATH}" -4 -K "AS${TEST_ASN}" > "${OUT_DIR}/routeros6--4.txt"
|
||||
"${BGPQ4_PATH}" -4 -K7 "AS${TEST_ASN}" > "${OUT_DIR}/routeros7--4.txt"
|
||||
"${BGPQ4_PATH}" -4 -N "AS${TEST_ASN}" > "${OUT_DIR}/sros--4.txt"
|
||||
"${BGPQ4_PATH}" -4 -n "AS${TEST_ASN}" > "${OUT_DIR}/sros-mdcli--4.txt"
|
||||
"${BGPQ4_PATH}" -4 -n2 "AS${TEST_ASN}" > "${OUT_DIR}/srlinux--4.txt"
|
||||
|
||||
# Test the IPv6 prefix-list output formatting for each supported NOS:
|
||||
"${BGPQ4_PATH}" -6 -b "AS${TEST_ASN}" > "${OUT_DIR}/bird--6.txt"
|
||||
"${BGPQ4_PATH}" -6 -e "AS${TEST_ASN}" > "${OUT_DIR}/eos--6.txt"
|
||||
"${BGPQ4_PATH}" -6 -F '%n/%l ' "AS${TEST_ASN}" > "${OUT_DIR}/formated--6.txt"
|
||||
"${BGPQ4_PATH}" -6 -U "AS${TEST_ASN}" > "${OUT_DIR}/huawei--6.txt"
|
||||
"${BGPQ4_PATH}" -6 -u "AS${TEST_ASN}" > "${OUT_DIR}/huawei-xpl--6.txt"
|
||||
"${BGPQ4_PATH}" -6 "AS${TEST_ASN}" > "${OUT_DIR}/ios--6.txt"
|
||||
"${BGPQ4_PATH}" -6 -X "AS${TEST_ASN}" > "${OUT_DIR}/ios-xr--6.txt"
|
||||
"${BGPQ4_PATH}" -6 -j "AS${TEST_ASN}" > "${OUT_DIR}/json--6.txt"
|
||||
"${BGPQ4_PATH}" -6 -J "AS${TEST_ASN}" > "${OUT_DIR}/junos--6.txt"
|
||||
"${BGPQ4_PATH}" -6 -B "AS${TEST_ASN}" > "${OUT_DIR}/openbgpd--6.txt"
|
||||
"${BGPQ4_PATH}" -6 -K "AS${TEST_ASN}" > "${OUT_DIR}/routeros6--6.txt"
|
||||
"${BGPQ4_PATH}" -6 -K7 "AS${TEST_ASN}" > "${OUT_DIR}/routeros7--6.txt"
|
||||
"${BGPQ4_PATH}" -6 -N "AS${TEST_ASN}" > "${OUT_DIR}/sros--6.txt"
|
||||
"${BGPQ4_PATH}" -6 -n "AS${TEST_ASN}" > "${OUT_DIR}/sros-mdcli--6.txt"
|
||||
"${BGPQ4_PATH}" -6 -n2 "AS${TEST_ASN}" > "${OUT_DIR}/srlinux--6.txt"
|
||||
|
||||
# Test the AS path list output formatting for each supported NOS:
|
||||
"${BGPQ4_PATH}" "${TEST_AS_SET}" -f "${TEST_ASN}" -b > "${OUT_DIR}/bird--asp.txt"
|
||||
# "${BGPQ4_PATH}" "${TEST_AS_SET}" -f "${TEST_ASN}" -e > "${OUT_DIR}/eos--asp.txt" # Not supported
|
||||
"${BGPQ4_PATH}" "${TEST_AS_SET}" -f "${TEST_ASN}" -U > "${OUT_DIR}/huawei--asp.txt"
|
||||
"${BGPQ4_PATH}" "${TEST_AS_SET}" -f "${TEST_ASN}" -u > "${OUT_DIR}/huawei-xpl--asp.txt"
|
||||
"${BGPQ4_PATH}" "${TEST_AS_SET}" -f "${TEST_ASN}" > "${OUT_DIR}/ios--asp.txt"
|
||||
"${BGPQ4_PATH}" "${TEST_AS_SET}" -f "${TEST_ASN}" -X > "${OUT_DIR}/ios-xr--asp.txt"
|
||||
"${BGPQ4_PATH}" "${TEST_AS_SET}" -f "${TEST_ASN}" -j > "${OUT_DIR}/json--asp.txt"
|
||||
"${BGPQ4_PATH}" "${TEST_AS_SET}" -f "${TEST_ASN}" -J > "${OUT_DIR}/junos--asp.txt"
|
||||
"${BGPQ4_PATH}" "${TEST_AS_SET}" -f "${TEST_ASN}" -B > "${OUT_DIR}/openbgpd--asp.txt"
|
||||
# "${BGPQ4_PATH}" "${TEST_AS_SET}" -f "${TEST_ASN}" -K > "${OUT_DIR}/routeros6--asp.txt" # Not supported
|
||||
# "${BGPQ4_PATH}" "${TEST_AS_SET}" -f "${TEST_ASN}" -K7 > "${OUT_DIR}/routeros7--asp.txt" # Not supported
|
||||
"${BGPQ4_PATH}" "${TEST_AS_SET}" -f "${TEST_ASN}" -N > "${OUT_DIR}/sros--asp.txt"
|
||||
"${BGPQ4_PATH}" "${TEST_AS_SET}" -f "${TEST_ASN}" -n > "${OUT_DIR}/sros-mdcli--asp.txt"
|
||||
|
||||
# Test IRR source scopes
|
||||
# Limit ASN to valid source:
|
||||
"${BGPQ4_PATH}" "AS${TEST_ASN}" -S RIPE-NONAUTH > "${OUT_DIR}/as112-ripe-nonauth.txt"
|
||||
# Limit ASN to invalid sources:
|
||||
"${BGPQ4_PATH}" "AS${TEST_ASN}" -S APNIC,AFRINIC > "${OUT_DIR}/as112-apnic.txt"
|
||||
# Limit AS-SET using IRR prefix notation to valid source:
|
||||
"${BGPQ4_PATH}" "RIPE::${TEST_AS_SET}" > "${OUT_DIR}/as-as112-ripe-notation.txt"
|
||||
# Limit AS-SET using IRR prefix notation to invalid source:
|
||||
"${BGPQ4_PATH}" "APNIC::${TEST_AS_SET}" > "${OUT_DIR}/as-as112-apnic-notation.txt"
|
||||
3
tests/reference/as-as112-apnic-notation.txt
Normal file
3
tests/reference/as-as112-apnic-notation.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
no ip prefix-list NN
|
||||
! generated prefix-list NN is empty
|
||||
ip prefix-list NN deny 0.0.0.0/0
|
||||
3
tests/reference/as-as112-ripe-notation.txt
Normal file
3
tests/reference/as-as112-ripe-notation.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
no ip prefix-list NN
|
||||
ip prefix-list NN permit 192.31.196.0/24
|
||||
ip prefix-list NN permit 192.175.48.0/24
|
||||
3
tests/reference/as112-apnic.txt
Normal file
3
tests/reference/as112-apnic.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
no ip prefix-list NN
|
||||
! generated prefix-list NN is empty
|
||||
ip prefix-list NN deny 0.0.0.0/0
|
||||
3
tests/reference/as112-ripe-nonauth.txt
Normal file
3
tests/reference/as112-ripe-nonauth.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
no ip prefix-list NN
|
||||
ip prefix-list NN permit 192.31.196.0/24
|
||||
ip prefix-list NN permit 192.175.48.0/24
|
||||
4
tests/reference/bird--4.txt
Normal file
4
tests/reference/bird--4.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
NN = [
|
||||
192.31.196.0/24,
|
||||
192.175.48.0/24
|
||||
];
|
||||
4
tests/reference/bird--6.txt
Normal file
4
tests/reference/bird--6.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
NN = [
|
||||
2001:4:112::/48,
|
||||
2620:4f:8000::/48
|
||||
];
|
||||
3
tests/reference/bird--asp.txt
Normal file
3
tests/reference/bird--asp.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
NN = [
|
||||
112
|
||||
];
|
||||
4
tests/reference/eos--4.txt
Normal file
4
tests/reference/eos--4.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
no ip prefix-list NN
|
||||
ip prefix-list NN
|
||||
seq 1 permit 192.31.196.0/24
|
||||
seq 2 permit 192.175.48.0/24
|
||||
4
tests/reference/eos--6.txt
Normal file
4
tests/reference/eos--6.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
no ipv6 prefix-list NN
|
||||
ipv6 prefix-list NN
|
||||
seq 1 permit 2001:4:112::/48
|
||||
seq 2 permit 2620:4f:8000::/48
|
||||
1
tests/reference/formated--4.txt
Normal file
1
tests/reference/formated--4.txt
Normal file
@@ -0,0 +1 @@
|
||||
192.31.196.0/24 192.175.48.0/24
|
||||
1
tests/reference/formated--6.txt
Normal file
1
tests/reference/formated--6.txt
Normal file
@@ -0,0 +1 @@
|
||||
2001:4:112::/48 2620:4f:8000::/48
|
||||
3
tests/reference/huawei--4.txt
Normal file
3
tests/reference/huawei--4.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
undo ip ip-prefix NN
|
||||
ip ip-prefix NN permit 192.31.196.0 24
|
||||
ip ip-prefix NN permit 192.175.48.0 24
|
||||
3
tests/reference/huawei--6.txt
Normal file
3
tests/reference/huawei--6.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
undo ip ipv6-prefix NN
|
||||
ip ipv6-prefix NN permit 2001:4:112:: 48
|
||||
ip ipv6-prefix NN permit 2620:4f:8000:: 48
|
||||
2
tests/reference/huawei--asp.txt
Normal file
2
tests/reference/huawei--asp.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
undo ip as-path-filter NN
|
||||
ip as-path-filter NN permit ^112(_112)*$
|
||||
5
tests/reference/huawei-xpl--4.txt
Normal file
5
tests/reference/huawei-xpl--4.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
no xpl ip-prefix-list NN
|
||||
xpl ip-prefix-list NN
|
||||
192.31.196.0 24,
|
||||
192.175.48.0 24
|
||||
end-list
|
||||
5
tests/reference/huawei-xpl--6.txt
Normal file
5
tests/reference/huawei-xpl--6.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
no xpl ipv6-prefix-list NN
|
||||
xpl ipv6-prefix-list NN
|
||||
2001:4:112:: 48,
|
||||
2620:4f:8000:: 48
|
||||
end-list
|
||||
3
tests/reference/huawei-xpl--asp.txt
Normal file
3
tests/reference/huawei-xpl--asp.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
xpl as-path-list NN
|
||||
regular ^112(_112)*$
|
||||
end-list
|
||||
3
tests/reference/ios--4.txt
Normal file
3
tests/reference/ios--4.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
no ip prefix-list NN
|
||||
ip prefix-list NN permit 192.31.196.0/24
|
||||
ip prefix-list NN permit 192.175.48.0/24
|
||||
3
tests/reference/ios--6.txt
Normal file
3
tests/reference/ios--6.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
no ipv6 prefix-list NN
|
||||
ipv6 prefix-list NN permit 2001:4:112::/48
|
||||
ipv6 prefix-list NN permit 2620:4f:8000::/48
|
||||
2
tests/reference/ios--asp.txt
Normal file
2
tests/reference/ios--asp.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
no ip as-path access-list NN
|
||||
ip as-path access-list NN permit ^112(_112)*$
|
||||
5
tests/reference/ios-xr--4.txt
Normal file
5
tests/reference/ios-xr--4.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
no prefix-set NN
|
||||
prefix-set NN
|
||||
192.31.196.0/24,
|
||||
192.175.48.0/24
|
||||
end-set
|
||||
5
tests/reference/ios-xr--6.txt
Normal file
5
tests/reference/ios-xr--6.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
no prefix-set NN
|
||||
prefix-set NN
|
||||
2001:4:112::/48,
|
||||
2620:4f:8000::/48
|
||||
end-set
|
||||
3
tests/reference/ios-xr--asp.txt
Normal file
3
tests/reference/ios-xr--asp.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
as-path-set NN
|
||||
ios-regex '^112(_112)*$'
|
||||
end-set
|
||||
4
tests/reference/json--4.txt
Normal file
4
tests/reference/json--4.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
{ "NN": [
|
||||
{ "prefix": "192.31.196.0\/24", "exact": true },
|
||||
{ "prefix": "192.175.48.0\/24", "exact": true }
|
||||
] }
|
||||
4
tests/reference/json--6.txt
Normal file
4
tests/reference/json--6.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
{ "NN": [
|
||||
{ "prefix": "2001:4:112::\/48", "exact": true },
|
||||
{ "prefix": "2620:4f:8000::\/48", "exact": true }
|
||||
] }
|
||||
3
tests/reference/json--asp.txt
Normal file
3
tests/reference/json--asp.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
{"NN": [
|
||||
112
|
||||
]}
|
||||
7
tests/reference/junos--4.txt
Normal file
7
tests/reference/junos--4.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
policy-options {
|
||||
replace:
|
||||
prefix-list NN {
|
||||
192.31.196.0/24;
|
||||
192.175.48.0/24;
|
||||
}
|
||||
}
|
||||
7
tests/reference/junos--6.txt
Normal file
7
tests/reference/junos--6.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
policy-options {
|
||||
replace:
|
||||
prefix-list NN {
|
||||
2001:4:112::/48;
|
||||
2620:4f:8000::/48;
|
||||
}
|
||||
}
|
||||
6
tests/reference/junos--asp.txt
Normal file
6
tests/reference/junos--asp.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
policy-options {
|
||||
replace:
|
||||
as-path-group NN {
|
||||
as-path a0 "^112(112)*$";
|
||||
}
|
||||
}
|
||||
4
tests/reference/openbgpd--4.txt
Normal file
4
tests/reference/openbgpd--4.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
prefix {
|
||||
192.31.196.0/24
|
||||
192.175.48.0/24
|
||||
}
|
||||
4
tests/reference/openbgpd--6.txt
Normal file
4
tests/reference/openbgpd--6.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
prefix {
|
||||
2001:4:112::/48
|
||||
2620:4f:8000::/48
|
||||
}
|
||||
1
tests/reference/openbgpd--asp.txt
Normal file
1
tests/reference/openbgpd--asp.txt
Normal file
@@ -0,0 +1 @@
|
||||
allow from AS 112 AS 112
|
||||
2
tests/reference/routeros6--4.txt
Normal file
2
tests/reference/routeros6--4.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
/routing filter add action=accept chain="NN-V4" prefix=192.31.196.0/24
|
||||
/routing filter add action=accept chain="NN-V4" prefix=192.175.48.0/24
|
||||
2
tests/reference/routeros6--6.txt
Normal file
2
tests/reference/routeros6--6.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
/routing filter add action=accept chain="NN-V6" prefix=2001:4:112::/48
|
||||
/routing filter add action=accept chain="NN-V6" prefix=2620:4f:8000::/48
|
||||
2
tests/reference/routeros7--4.txt
Normal file
2
tests/reference/routeros7--4.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
/routing filter rule add chain="NN-V4" rule="if (dst==192.31.196.0/24) {accept}"
|
||||
/routing filter rule add chain="NN-V4" rule="if (dst==192.175.48.0/24) {accept}"
|
||||
2
tests/reference/routeros7--6.txt
Normal file
2
tests/reference/routeros7--6.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
/routing filter rule add chain="NN-V6" rule="if (dst==2001:4:112::/48) {accept}"
|
||||
/routing filter rule add chain="NN-V6" rule="if (dst==2620:4f:8000::/48) {accept}"
|
||||
6
tests/reference/srlinux--4.txt
Normal file
6
tests/reference/srlinux--4.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
/routing-policy
|
||||
delete prefix-set "NN"
|
||||
prefix-set "NN" {
|
||||
prefix 192.31.196.0/24 mask-length-range exact { }
|
||||
prefix 192.175.48.0/24 mask-length-range exact { }
|
||||
}
|
||||
6
tests/reference/srlinux--6.txt
Normal file
6
tests/reference/srlinux--6.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
/routing-policy
|
||||
delete prefix-set "NN"
|
||||
prefix-set "NN" {
|
||||
prefix 2001:4:112::/48 mask-length-range exact { }
|
||||
prefix 2620:4f:8000::/48 mask-length-range exact { }
|
||||
}
|
||||
8
tests/reference/sros--4.txt
Normal file
8
tests/reference/sros--4.txt
Normal file
@@ -0,0 +1,8 @@
|
||||
configure router policy-options
|
||||
begin
|
||||
no prefix-list "NN"
|
||||
prefix-list "NN"
|
||||
prefix 192.31.196.0/24 exact
|
||||
prefix 192.175.48.0/24 exact
|
||||
exit
|
||||
commit
|
||||
8
tests/reference/sros--6.txt
Normal file
8
tests/reference/sros--6.txt
Normal file
@@ -0,0 +1,8 @@
|
||||
configure router policy-options
|
||||
begin
|
||||
no prefix-list "NN"
|
||||
prefix-list "NN"
|
||||
prefix 2001:4:112::/48 exact
|
||||
prefix 2620:4f:8000::/48 exact
|
||||
exit
|
||||
commit
|
||||
7
tests/reference/sros--asp.txt
Normal file
7
tests/reference/sros--asp.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
configure router policy-options
|
||||
begin
|
||||
no as-path-group "NN"
|
||||
as-path-group "NN"
|
||||
entry 1 expression "112+"
|
||||
exit
|
||||
commit
|
||||
8
tests/reference/sros-mdcli--4.txt
Normal file
8
tests/reference/sros-mdcli--4.txt
Normal file
@@ -0,0 +1,8 @@
|
||||
/configure policy-options
|
||||
delete prefix-list "NN"
|
||||
prefix-list "NN" {
|
||||
prefix 192.31.196.0/24 type exact {
|
||||
}
|
||||
prefix 192.175.48.0/24 type exact {
|
||||
}
|
||||
}
|
||||
8
tests/reference/sros-mdcli--6.txt
Normal file
8
tests/reference/sros-mdcli--6.txt
Normal file
@@ -0,0 +1,8 @@
|
||||
/configure policy-options
|
||||
delete prefix-list "NN"
|
||||
prefix-list "NN" {
|
||||
prefix 2001:4:112::/48 type exact {
|
||||
}
|
||||
prefix 2620:4f:8000::/48 type exact {
|
||||
}
|
||||
}
|
||||
7
tests/reference/sros-mdcli--asp.txt
Normal file
7
tests/reference/sros-mdcli--asp.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
/configure policy-options
|
||||
delete as-path-group "NN"
|
||||
as-path-group "NN" {
|
||||
entry 1 {
|
||||
expression "112+"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user