Filter BGP Imports with IRR
Ze can build a BGP import prefix-list from an ASN or IRR AS-SET. The bgp-filter-irr plugin resolves the AS-SET through an IRR whois server, keeps the resulting IPv4 and IPv6 prefixes in memory, and rejects received routes that are not in that list.
Use this for a customer or peer that should only announce prefixes registered to its network. It replaces a separate bgpq4 job and static prefix-list deployment.
Complete example
This example accepts registered routes from customer AS 65001. Replace the addresses, ASN, and AS-CUSTOMER with values for your network.
plugin {
internal bgp-adj-rib-in {
use bgp-adj-rib-in
}
internal bgp-filter-irr {
use bgp-filter-irr
}
}
policy {
irr {
server whois.radb.net
peeringdb-url https://www.peeringdb.com
refresh-interval 3600
}
}
bgp {
router-id 192.0.2.1
session {
asn {
local 65000
}
}
peer customer-a {
connection {
remote {
ip 198.51.100.2
}
local {
ip 198.51.100.1
}
}
session {
asn {
local 65000
remote 65001
}
family {
ipv4/unicast {
prefix {
maximum 1000
}
}
ipv6/unicast {
prefix {
maximum 1000
}
}
}
irr {
as-set AS-CUSTOMER
}
}
filter {
import {
filters [ bgp-filter-irr:65001 ];
final accept;
}
}
attach process bgp-adj-rib-in {
receive [ update-received state ]
}
}
}
The two plugin blocks load the filter and Adj-RIB-In. The Adj-RIB-In plugin is not required to make the filter decision, but it provides show bgp adj-rib-in so you can verify which routes passed.
The suffix in bgp-filter-irr:65001 is the peer's remote ASN. It selects the dynamic list associated with AS 65001. Use the corresponding ASN in each peer's filter reference. Prefixes that do not match that list are rejected by the implicit deny.
No attach process bgp-filter-irr block is needed. A filter reference invokes the plugin directly through the BGP import filter chain.
Add it to an existing stored configuration
If the stored ze.conf already contains the BGP peer but no IRR filter, stop Ze and add these settings to the stored configuration. An offline ze config set writes the file path it is given and never resolves a stored name, so the stored configuration travels through stdin: ze config cat reads it, one ze config set - stage applies each setting, and ze config import stores the result as a new version.
$ sudo systemctl stop ze.service
$ ze config cat ze.conf |
> ze config set - plugin internal bgp-filter-irr use bgp-filter-irr |
> ze config set - policy irr server whois.radb.net |
> ze config set - policy irr refresh-interval 3600 |
> ze config set - bgp peer customer-a session irr as-set AS-CUSTOMER |
> ze config set - bgp peer customer-a filter import filters bgp-filter-irr:65001 |
> ze config set - bgp peer customer-a filter import final accept |
> ze config import --yes --name ze.conf -
$ sudo systemctl start ze.service
The import replaces the stored ze.conf only because --yes confirms it; the previous version stays available to ze config rollback. Nothing here contacts the daemon, which is stopped anyway. Starting Ze loads the plugin and resolves the AS-SET in the background. An UPDATE that arrives before the list is rejected at once and kept for another evaluation, as After a restart describes. Replace ze.conf, customer-a, AS-CUSTOMER, and 65001 with the stored configuration key, peer name, AS-SET, and remote ASN for your deployment.
Run ze config cat ze.conf before and after these commands to review the stored changes. This offline workflow is separate from the live SSH workflow in the demonstration below.
Choose the AS-SET
Set session { irr { as-set AS-CUSTOMER; } } when you know the correct AS-SET. This is the most predictable production configuration.
If you omit as-set, Ze queries PeeringDB with the remote ASN. It uses the registered irr_as_set value when one exists, then falls back to the origin object AS<number> if PeeringDB does not return an AS-SET.
For a peer that must bypass this policy, set:
session {
irr {
enable disable
}
}
Changing IRR settings on a running router
A commit that changes a peer's as-set, the IRR server, or a peer's
filter import filters reference takes effect on the running filter. A changed
as-set does not inherit the list of the old one: an UPDATE from that peer before
the new set resolves has its announced routes rejected and kept, and the filter
asks the peer for them again once the new list arrives.
Deleting the as-set counts as a change: Ze asks PeeringDB again, as it would
for a peer that never named one, and filters against the set PeeringDB returns.
If PeeringDB does not answer, Ze queries AS<asn> itself until the next
refresh after PeeringDB answers. With no as-set, every refresh asks PeeringDB,
and Ze caches each PeeringDB answer for an hour, so a change to the registered
AS-SET is followed at the first refresh after the cached answer expires: up to
about two hours at the default refresh-interval of 3600 seconds, and up to a
day at 86400. A configuration reload starts a new PeeringDB cache, so the next
refresh after a reload sees the change. clear peeringdb cache asn <asn>
empties the cached answer without a reload, so the next refresh asks PeeringDB
again.
Verify before carrying traffic
After committing the configuration and establishing the BGP session, check the generated list:
$ ze cli -c 'show bgp irr | no-more'
$ ze cli -c 'show bgp irr prefix customer-a | no-more'
These commands use the CLI's default text format. Its indented key/value layout can resemble YAML, but it is not YAML. text is the default unless environment { cli { format { default ... } } } changes it. Select another format explicitly with | yaml, | json, or | table.
The prefix command takes the configured peer name. Confirm that the status is ok, the resolved AS-SET is correct, and the prefix counts are plausible.
Test both a registered and an unregistered route without changing policy:
$ ze cli -c 'show bgp irr check customer-a 203.0.113.0/24 | no-more'
$ ze cli -c 'show bgp irr check customer-a 192.0.2.0/24 | no-more'
Each result reports accepted: true or accepted: false. Use show bgp adj-rib-in to confirm that only accepted routes entered the inbound RIB.
Refresh and failure behavior
Ze refreshes each list at refresh-interval. You can also refresh all enrolled peers, one ASN, or every peer using one AS-SET:
$ ze cli -c 'update bgp irr all'
$ ze cli -c 'update bgp irr asn 65001'
$ ze cli -c 'update bgp irr as-set AS-CUSTOMER'
A refresh that returns prefixes atomically replaces the in-memory list. The firewall IRR plugin also writes its lists to ZeFS; the BGP filter does not (see "After a restart" below). Three other outcomes keep the last known good list instead, and each records the reason in show bgp irr:
- The refresh failed: the server was unreachable, refused the query, or sent a truncated reply.
- The refresh returned more than 500000 prefixes across both families. The BGP filter refuses the list whole rather than cutting it, because a cut kept the IPv4 half and lost IPv6; the error gives the IPv4 and IPv6 counts. Narrow the AS-SET.
- The refresh succeeded and returned no prefixes at all. Ze treats "I have nothing" the same as a failure, because an empty allow-list rejects every route the peer sends. A server that answers
D(key not found), answers with no records, or reports an error can therefore not empty a live list.
The prefixes an empty answer left in place are still enforced. show bgp irr and show firewall irr mark the entry stale and give the age of the data, so enforcing data nobody has confirmed is visible rather than silent.
The two address families are kept separately. Ze queries IPv4 and IPv6 with two commands, and a server that returns prefixes for one and nothing for the other keeps the last known good list of the family that returned nothing. The entry is marked stale and reports the age of the older list. This matters most for an interface binding, where the rules accept the registered prefixes of each family and drop the rest: a family whose list was emptied would have every packet dropped.
Removing prefixes is always deliberate. When an AS-SET is deregistered upstream for good, clear its cached data:
$ ze cli -c 'clear firewall irr as-set AS-CUSTOMER'
$ ze cli -c 'clear firewall irr asn 65001'
The entry disappears from memory and from ZeFS, and the firewall tables are re-applied. Firewall configuration that still references the name fails to verify until it is fetched again with update firewall irr.
After a restart
The BGP filter keeps its prefix-lists in memory only and writes nothing to disk, so a restarted Ze starts with no list for any ASN and resolves every enrolled ASN again from the IRR server. A configuration reload keeps the lists already resolved, except for an ASN whose AS-SET changed, which starts from no list.
Until an ASN's first resolution completes, an UPDATE from its peer has its announced routes rejected at once, with no wait, and they are kept for another evaluation; its withdrawals still apply. show bgp irr reports the ASN pending meanwhile. When the list arrives, the filter asks the peer for them again by ROUTE-REFRESH, as described in the next section, so the peer needs Route Refresh negotiated and the refresh permission. A peer without them keeps those routes rejected until it sends them again.
When the IRR server cannot be reached at startup, no last known good list exists to fall back to: the peer's announcements are rejected, and the filter retries the lookup every minute while it holds a rejected route, until the server answers.
At first enrollment, do not place the session into service until show bgp irr reports status: ok. A peer without loaded prefix data has no list from which to make a useful allow decision.
A rejected route is evaluated again when the list changes
A route rejected because its ASN had no list yet, or because the list did not hold it, is kept for another evaluation. When a list arrives or a refresh changes it, the filter checks what it kept, and for each peer with a route the new list authorizes it sends a ROUTE-REFRESH for that family. The peer sends its routes again and the filter decides them against the new list. While an ASN that holds a rejected route has no list, or its last lookup failed, the filter retries the lookup every minute.
The ROUTE-REFRESH needs two things. Route Refresh must be negotiated with the peer: Ze advertises it only when the peer's capability block, or its group's, says route-refresh enable, and the peer must advertise it too. The peer must also give the filter the permission to send it, with refresh or * in the send list:
capability {
route-refresh enable
}
attach process bgp-filter-irr {
send [ refresh ]
}
A send list on the peer replaces the group's, so a peer that states its own send list for the filter needs refresh in that list. Without either piece, the route stays rejected until the peer sends it again, and the filter logs one warning for the peer that names the missing piece. When a configuration is applied, the filter also logs one warning for each IRR-filtered peer that lacks the permission, and one for each to which Ze does not advertise Route Refresh. If the ROUTE-REFRESH fails for another reason, for example a timeout, the filter asks again on its next pass. At most 100 000 rejected prefixes are kept; past that a rejected prefix is evaluated again only when its peer sends it again, and the filter logs one warning. A withdrawal, an accepted announcement and a session that goes down each drop what was kept for that route or peer.
An UPDATE that announces some routes the list authorizes and some it does not keeps the authorized ones and drops the rest, in the IPv4 NLRI field and in a multiprotocol block of IPv4 or IPv6 unicast, multicast or labeled unicast alike. An UPDATE that withdraws routes keeps its withdrawals even when the filter rejects every route it announces, and even before the ASN has a list. The exception is a rejected route in a multiprotocol block of another family, a FlowSpec rule for example, which Ze cannot remove from the UPDATE: that UPDATE is rejected whole, its authorized routes and its withdrawals included. The filter then asks the peer for the authorized routes again every minute, and the peer answers with the same UPDATE, so those routes stay rejected until the peer stops announcing the refused one.
Local demonstration
The demonstration starts Ze with a customer peer but no IRR policy. It loads the server, AS-SET and import filter sections into one SSH candidate, compares them, then commits. The IRR service is a deterministic local test server, not a public registry. Its AS-TEST object contains 10.0.0.0/24 but not 192.168.0.0/24.
The customer announces both routes and two control prefixes. The check commands explain decisions; they do not prove an UPDATE arrived. Before each reannouncement, the lab waits for the previous customer session to depart and its Adj-RIB-In to clear. It puts the current policy's accepted control last in the fixture's actual send order: 10.0.1.0/24 for AS-TEST, or 192.0.2.0/24 for AS-V4ONLY. Seeing that control in Adj-RIB-In proves the earlier announcements were processed. The outside prefix and the other policy's control must be absent.
The failure changes the peer to AS-V4ONLY, which lacks the customer prefix. After the new session's final control arrives, 10.0.0.0/24 must be absent. The repair restores AS-TEST through SSH, refreshes it with update bgp irr as-set AS-TEST, then announces again and checks the customer route and its final control. Customer establishment has a separate deadline covering Ze's existing maximum 60-second reconnect backoff plus handshake time; policy convergence still uses its shorter bound. Ze stays running throughout.
Add IRR filtering to an existing BGP peer
Load the local test IRR server, AS-SET and import policy over SSH, prove route acceptance and refusal, then diagnose and repair a wrong AS-SET without restarting Ze.
Read the demonstration transcript
IRR: live import filtering and repair
The running base router has a customer in AS 65001 and no IRR policy.
The IRR service at 127.0.0.1:4343 is a local test server, not a public registry.
AS-TEST contains 10.0.0.0/24 but not 192.168.0.0/24.
$ ze-demo card topic-irr lab
$ ze cli -c 'show bgp irr | yaml | no-more'
Load three sections in one SSH candidate:
$ ze-demo card topic-irr overview
$ sshpass -e ssh ze-demo
ze# load file absolute merge /src/demos/terminal/topics/irr/1-server.conf
ze# load file absolute merge /src/demos/terminal/topics/irr/2-as-set.conf
ze# load file absolute merge /src/demos/terminal/topics/irr/3-import.conf
ze# show | compare
ze# commit now
ze# exit
ze> exit
The customer announces both disputed routes and two controls. Inspect show bgp
irr, show bgp irr prefix customer and show bgp irr check customer for each prefix.
Adj-RIB-In must contain 10.0.0.0/24 and the final accepted 10.0.1.0/24 control,
but omit both 192.168.0.0/24 and the wrong-set 192.0.2.0/24 control.
$ ze-demo card topic-irr proof
$ ze cli -c 'show bgp irr | yaml | no-more'
$ ze cli -c 'show bgp irr prefix customer | yaml | no-more'
$ ze cli -c 'show bgp irr check customer 10.0.0.0/24 | yaml | no-more'
$ ze cli -c 'show bgp irr check customer 192.168.0.0/24 | yaml | no-more'
$ ze cli -c 'show bgp adj-rib-in | no-more'
Load 4-wrong-as-set.conf in the SSH editor and commit. The local AS-V4ONLY
object is valid, but its 192.0.2.0/24 prefix does not authorize this customer.
Before reannouncing, wait for the old session and its routes to clear. The new
fixture sends AS-V4ONLY's accepted 192.0.2.0/24 control last. Only after that
control arrives can the absence of both 10.0 routes prove refusal, not delay.
$ ze-demo card topic-irr failure
$ sshpass -e ssh ze-demo
ze# load file absolute merge /src/demos/terminal/topics/irr/4-wrong-as-set.conf
ze# show | compare
ze# commit now
ze# exit
ze> exit
$ ze cli -c 'show bgp irr check customer 10.0.0.0/24 | yaml | no-more'
$ ze cli -c 'show bgp irr prefix customer | yaml | no-more'
$ ze cli -c 'show bgp adj-rib-in | no-more'
Load 2-as-set.conf again and commit the repair. Run update bgp irr as-set
AS-TEST, then ze-demo run showcase-lab control customer reannounce. Inspect
the accepted decision, 10.0.0.0/24 and its final 10.0.1.0/24 control again.
The wrong-set control and outside route must be absent. Ze stays running.
$ ze-demo card topic-irr recovery
$ sshpass -e ssh ze-demo
ze# load file absolute merge /src/demos/terminal/topics/irr/2-as-set.conf
ze# show | compare
ze# commit now
ze# exit
ze> exit
$ ze cli -c 'update bgp irr as-set AS-TEST | yaml | no-more'
$ ze-demo run showcase-lab control customer reannounce
$ ze cli -c 'show bgp irr check customer 10.0.0.0/24 | yaml | no-more'
$ ze cli -c 'show bgp adj-rib-in | no-more'
These are the authored walkthrough steps. Runtime validation and recording
must succeed before this source is published as a recording.
Troubleshooting
| Symptom | Check | Resolution |
|---|---|---|
show bgp irr has no entry for the ASN |
Plugin and filter reference | Load bgp-filter-irr and configure filter { import { filters [ bgp-filter-irr:<remote-asn> ]; final accept; } } on the peer. |
Status stays pending |
IRR connectivity | Permit outbound TCP to the configured whois server and run update bgp irr asn <asn>. |
Status is error |
error field in show bgp irr |
Correct the AS-SET or server, then refresh. The last known good list remains active. |
Status is stale |
stale-since and data-age-seconds in show firewall irr |
The last refresh returned no prefixes. Confirm the AS-SET still exists and the server is reachable, then refresh. The previous prefixes stay enforced meanwhile. |
Status is oversized, and the rules naming the entry filter nothing |
ipv4-count and ipv6-count in show firewall irr |
One family holds more than the 500000 prefixes a firewall set takes. Ze programs none of the list, because a set holding part of it drops traffic an accept rule was written to pass. Narrow the AS-SET to the members you filter on, or run clear firewall irr as-set <name>. |
| An AS-SET no longer exists and its prefixes are still enforced | show firewall irr |
Run clear firewall irr as-set <name>. An empty answer never removes prefixes, so removal is an operator action. |
| The wrong AS-SET is selected | as-set in show bgp irr |
Configure the expected AS-SET explicitly under the peer session. |
| A valid customer route is rejected | show bgp irr check <peer-name> <prefix> |
Confirm the exact prefix is registered in the selected IRR sources and refresh the list. |
| An unregistered route appears in Adj-RIB-In | Active import chain | Confirm the peer uses the IRR filter and has not set irr { enable disable; }. |