1BGPQ4(8)                  BSD System Manager's Manual                 BGPQ4(8)
2

NAME

4     bgpq4 — bgp filtering automation tool
5

SYNOPSIS

7     bgpq4 [-h host[:port]] [-S sources] [-EPz] [-f asn | -F fmt | -G asn -H
8           asn -t] [-46ABbDdJjNnpsXU] [-a asn] [-r len] [-R len] [-m max]
9           [-W len] OBJECTS [...] [EXCEPT OBJECTS]
10

DESCRIPTION

12     The bgpq4 utility used to generate configurations (prefix-lists, extended
13     access-lists, policy-statement terms and as-path lists) based on IRR
14     data.
15
16     The options are as follows:
17
18     -4      generate IPv4 prefix/access-lists (default).
19
20     -6      generate IPv6 prefix/access-lists (IPv4 by default).
21
22     -A      try to aggregate prefix-lists as much as possible (not all output
23             formats supported).
24
25     -a asn  specify what asn shall be denied in case of empty prefix-list
26             (OpenBGPD)
27
28     -B      generate output in OpenBGPD format (default: Cisco)
29
30     -b      generate output in BIRD format (default: Cisco).
31
32     -d      enable some debugging output.
33
34     -e      generate output in Arista EOS format (default: Cisco).
35
36     -E      generate extended access-list (Cisco), policy-statement term us‐
37             ing route-filters (Juniper), [ip|ipv6]-prefix-list (Nokia) or
38             prefix-sets (OpenBGPd).
39
40     -f number
41             generate input as-path access-list.
42
43     -F fmt  generate output in user-defined format.
44
45     -G number
46             generate output as-path access-list.
47
48     -H number
49             generate output as-list for as-path-origin filter (JunOS 21.3R1+)
50
51     -h host[:port]
52             host running IRRD database (default: rr.ntt.net).
53
54     -J      generate config for Juniper (default: Cisco).
55
56     -j      generate output in JSON format (default: Cisco).
57
58     -K      generate config for Mikrotik ROSv6 (default: Cisco).
59
60     -K7     generate config for Mikrotik ROSv7 (default: Cisco).
61
62     -l name
63             name of generated entry.
64
65     -L limit
66             limit recursion depth when expanding as-sets.
67
68     -m len  maximum prefix-length of accepted prefixes (default: 32 for IPv4
69             and 128 for IPv6).
70
71     -M match
72             extra match conditions for Juniper route-filters.
73
74     -n      generate config for Nokia SR OS MD-CLI (Cisco IOS by default)
75
76     -N      generate config for Nokia SR OS classic CLI (Cisco IOS by de‐
77             fault).
78
79     -p      emit prefixes where the origin ASN is in the private ASN range
80             (disabled by default).
81
82     -r len  allow more specific routes starting with specified masklen too.
83
84     -R len  allow more specific routes up to specified masklen too.
85
86     -s      generate sequence numbers in IOS-style prefix-lists.
87
88     -S sources
89             use specified sources only (recommended: RPKI,AFRINIC,AP‐
90             NIC,ARIN,LACNIC,RIPE).
91
92     -t      generate as-sets for OpenBGPd, BIRD and JSON formats.
93
94     -T      disable pipelining (not recommended).
95
96     -U      generate config for Huawei devices (Cisco IOS by default)
97
98     -u      generate config for Huawei devices in XPL format (Cisco IOS by
99             default)
100
101     -W len  generate as-path strings of no more than len items (use 0 for in‐
102             finity).
103
104     -X      generate config for Cisco IOS XR devices (plain IOS by default).
105
106     -z      generate route-filter-lists (JunOS 16.2+).
107
108     OBJECTS
109             means networks (in prefix format), autonomous systems, as-sets
110             and route-sets.
111
112     EXCEPT OBJECTS
113             those objects will be excluded from expansion.
114

EXAMPLES

116     Generating named juniper prefix-filter for AS20597:
117
118     $ bgpq4 -Jl eltel AS20597
119     policy-options {
120     replace:
121      prefix-list eltel {
122         81.9.0.0/20;
123         81.9.32.0/20;
124         81.9.96.0/20;
125         81.222.128.0/20;
126         81.222.192.0/18;
127         85.249.8.0/21;
128         85.249.224.0/19;
129         89.112.0.0/19;
130         89.112.4.0/22;
131         89.112.32.0/19;
132         89.112.64.0/19;
133         217.170.64.0/20;
134         217.170.80.0/20;
135      }
136     }
137
138     For Cisco we can use aggregation (-A) flag to make this prefix-filter
139     more compact:
140
141     $ bgpq4 -Al eltel AS20597
142     no ip prefix-list eltel
143     ip prefix-list eltel permit 81.9.0.0/20
144     ip prefix-list eltel permit 81.9.32.0/20
145     ip prefix-list eltel permit 81.9.96.0/20
146     ip prefix-list eltel permit 81.222.128.0/20
147     ip prefix-list eltel permit 81.222.192.0/18
148     ip prefix-list eltel permit 85.249.8.0/21
149     ip prefix-list eltel permit 85.249.224.0/19
150     ip prefix-list eltel permit 89.112.0.0/18 ge 19 le 19
151     ip prefix-list eltel permit 89.112.4.0/22
152     ip prefix-list eltel permit 89.112.64.0/19
153     ip prefix-list eltel permit 217.170.64.0/19 ge 20 le 20
154
155     Prefixes 89.112.0.0/19 and 89.112.32.0/19 now aggregated into single en‐
156     try 89.112.0.0/18 ge 19 le 19.
157
158     Well, for Juniper we can generate even more interesting policy-options,
159     using -M <extra match conditions>, -R <len> and hierarchical names:
160
161     $ bgpq4 -AJEl eltel/specifics -r 29 -R 32 -M "community blackhole" AS20597
162     policy-options {
163      policy-statement eltel {
164       term specifics {
165     replace:
166        from {
167         community blackhole;
168         route-filter 81.9.0.0/20 prefix-length-range /29-/32;
169         route-filter 81.9.32.0/20 prefix-length-range /29-/32;
170         route-filter 81.9.96.0/20 prefix-length-range /29-/32;
171         route-filter 81.222.128.0/20 prefix-length-range /29-/32;
172         route-filter 81.222.192.0/18 prefix-length-range /29-/32;
173         route-filter 85.249.8.0/21 prefix-length-range /29-/32;
174         route-filter 85.249.224.0/19 prefix-length-range /29-/32;
175         route-filter 89.112.0.0/17 prefix-length-range /29-/32;
176         route-filter 217.170.64.0/19 prefix-length-range /29-/32;
177        }
178       }
179      }
180     }
181     generated policy-option term now allows all specifics with prefix-length
182     between /29 and /32 for eltel networks if they match with special commu‐
183     nity blackhole (defined elsewhere in configuration).
184
185     Of course, this version supports IPv6 (-6):
186
187     $ bgpq4 -6l as-retn-6 AS-RETN6
188     no ipv6 prefix-list as-retn-6
189     ipv6 prefix-list as-retn-6 permit 2001:7fb:fe00::/48
190     ipv6 prefix-list as-retn-6 permit 2001:7fb:fe01::/48
191     [....]
192     and assumes your device supports 32-bit ASNs
193
194     $ bgpq4 -Jf 112 AS-SPACENET
195     policy-options {
196     replace:
197      as-path-group NN {
198       as-path a0 "^112(112)*$";
199       as-path a1 "^112(.)*(1898|5539|8495|8763|8878|12136|12931|15909)$";
200       as-path a2 "^112(.)*(21358|23456|23600|24151|25152|31529|34127|34906)$";
201       as-path a3 "^112(.)*(35052|41720|43628|44450|196611)$";
202      }
203     }
204     see `AS196611` in the end of the list ? That's a 32-bit ASN.
205

USER-DEFINED FORMAT

207     If you want to generate configuration not for routers, but for some other
208     programs/systems, you may use user-defined formatting, like in example
209     below:
210
211     $ bgpq4 -F "ipfw add pass all from %n/%l to any\n" as3254
212     ipfw add pass all from 62.244.0.0/18 to any
213     ipfw add pass all from 91.219.29.0/24 to any
214     ipfw add pass all from 91.219.30.0/24 to any
215     ipfw add pass all from 193.193.192.0/19 to any
216
217     Recognized format sequences are:
218
219           %n      network
220           %l      mask length
221           %a      aggregate low mask length
222           %A      aggregate high mask length
223           %N      object name
224           %m      object mask
225           %i      inversed mask
226           \n      new line
227           \t      tabulation
228
229     Please note that no new lines are inserted automatically after each sen‐
230     tence.  You have to add them into format string manually, otherwise the
231     output will be in one single line (sometimes it makes sense):
232
233     $ bgpq4 -6F "%n/%l; " as-eltel
234     2001:1b00::/32; 2620:4f:8000::/48; 2a04:bac0::/29; 2a05:3a80::/48;
235

NOTES ON SOURCES

237     By default bgpq4 trusts data from all the databases mirrored into NTT's
238     IRR service.  Unfortunately, not all these databases are equal in how
239     much we can trust their data.  RIR maintained databases (AFRINIC, ARIN,
240     APNIC, LACNIC and RIPE) shall be trusted more than the others because
241     they have the knowledge about who the rightful holders of resources are,
242     while other databases lack this knowledge and can (and, actually do) con‐
243     tain stale data: no one but the RIRs care to remove outdated route-ob‐
244     jects when address space is de-allocated or transferred.  In order to
245     keep their filters both compact and actual, bgpq4 users are encouraged to
246     use '-S' flag to limit database sources to only the ones they trust.
247
248     General recommendations:
249
250     Use a minimal set of RIR databases (only those in which you and your cus‐
251     tomers have registered route-objects).
252
253     Avoid using ARIN-NONAUTH and RIPE-NONAUTH as trusted sources: these
254     records were created in the database, but for address space allocated to
255     different RIRs, so the NONAUTH databases have no chance to confirm valid‐
256     ity of the route objects they contain.
257
258     $ bgpq4 -S RIPE,RADB as-space
259     no ip prefix-list NN
260     ip prefix-list NN permit 195.190.32.0/19
261
262     $ bgpq4 -S RADB,RIPE as-space
263     no ip prefix-list NN
264     ip prefix-list NN permit 45.4.4.0/22
265     ip prefix-list NN permit 45.4.132.0/22
266     ip prefix-list NN permit 45.6.128.0/22
267     ip prefix-list NN permit 45.65.184.0/22
268     [...]
269

PERFORMANCE

271     To improve `bgpq4` performance when expanding extra-large AS-SETs you
272     shall tune OS settings to enlarge TCP send buffer.
273
274     FreeBSD can be tuned in the following way:
275
276           sysctl -w net.inet.tcp.sendbuf_max=2097152
277
278     Linux can be tuned in the following way:
279
280           sysctl -w net.ipv4.tcp_window_scaling=1
281           sysctl -w net.core.rmem_max=2097152
282           sysctl -w net.core.wmem_max=2097152
283           sysctl -w net.ipv4.tcp_rmem="4096 87380 2097152"
284           sysctl -w net.ipv4.tcp_wmem="4096 65536 2097152"
285

BUILDING

287     This project uses autotools. If you are building from the repository, run
288     the following command to prepare the build system:
289
290           ./bootstrap
291
292     In order to compile the software, run:
293
294           ./configure
295           make
296           make install
297
298     If you wish to remove the generated build system files from your working
299     tree, run:
300
301           make maintainer-clean
302
303     In order to create a distribution archive, run:
304
305           make dist
306

DIAGNOSTICS

308     When everything is OK, bgpq4 generates access-list to standard output and
309     exits with status == 0.  In case of errors they are printed to stderr and
310     program exits with non-zero status.
311

AUTHORS

313     Alexandre Snarskii, Christian David, Claudio Jeker, Job Snijders, Massim‐
314     iliano Stucchi, Michail Litvak, Peter Schoenmaker, Roelf Wichertjes, and
315     contributions from many others.
316

SEE ALSO

318     https://github.com/bgp/bgpq4 BGPQ4 on Github.
319
320     http://bgpfilterguide.nlnog.net/ NLNOG's BGP Filter Guide.
321
322     https://tcp0.com/cgi-bin/mailman/listinfo/bgpq4 Users and interested par‐
323     ties can subscribe to the BGPQ4 mailing list bgpq4@tcp0.com
324

PROJECT MAINTAINER

326     Job Snijders <job@sobornost.net>
327
328BSD                            December 23, 2020                           BSD
Impressum