1BGPQ4(8) BSD System Manager's Manual BGPQ4(8)
2
4 bgpq4 — bgp filtering automation tool
5
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
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 -n2 generate config for Nokia SR Linux (Cisco IOS by default)
77
78 -N generate config for Nokia SR OS classic CLI (Cisco IOS by de‐
79 fault).
80
81 -p emit prefixes where the origin ASN is 23456 or in the private ASN
82 range (disabled by default).
83
84 -r len allow more specific routes starting with specified masklen too.
85
86 -R len allow more specific routes up to specified masklen too.
87
88 -s generate sequence numbers in IOS-style prefix-lists.
89
90 -S sources
91 use specified sources only (recommended: RPKI,AFRINIC,AP‐
92 NIC,ARIN,LACNIC,RIPE).
93
94 -t generate as-sets for OpenBGPd, BIRD and JSON formats.
95
96 -T disable pipelining (not recommended).
97
98 -U generate config for Huawei devices (Cisco IOS by default)
99
100 -u generate config for Huawei devices in XPL format (Cisco IOS by
101 default)
102
103 -W len generate as-path strings of no more than len items (use 0 for in‐
104 finity).
105
106 -X generate config for Cisco IOS XR devices (plain IOS by default).
107
108 -z generate route-filter-lists (JunOS 16.2+).
109
110 OBJECTS
111 means networks (in prefix format), autonomous systems, as-sets
112 and route-sets.
113
114 EXCEPT OBJECTS
115 those objects will be excluded from expansion.
116
118 Generating named juniper prefix-filter for AS20597:
119
120 $ bgpq4 -Jl eltel AS20597
121 policy-options {
122 replace:
123 prefix-list eltel {
124 81.9.0.0/20;
125 81.9.32.0/20;
126 81.9.96.0/20;
127 81.222.128.0/20;
128 81.222.192.0/18;
129 85.249.8.0/21;
130 85.249.224.0/19;
131 89.112.0.0/19;
132 89.112.4.0/22;
133 89.112.32.0/19;
134 89.112.64.0/19;
135 217.170.64.0/20;
136 217.170.80.0/20;
137 }
138 }
139
140 For Cisco we can use aggregation (-A) flag to make this prefix-filter
141 more compact:
142
143 $ bgpq4 -Al eltel AS20597
144 no ip prefix-list eltel
145 ip prefix-list eltel permit 81.9.0.0/20
146 ip prefix-list eltel permit 81.9.32.0/20
147 ip prefix-list eltel permit 81.9.96.0/20
148 ip prefix-list eltel permit 81.222.128.0/20
149 ip prefix-list eltel permit 81.222.192.0/18
150 ip prefix-list eltel permit 85.249.8.0/21
151 ip prefix-list eltel permit 85.249.224.0/19
152 ip prefix-list eltel permit 89.112.0.0/18 ge 19 le 19
153 ip prefix-list eltel permit 89.112.4.0/22
154 ip prefix-list eltel permit 89.112.64.0/19
155 ip prefix-list eltel permit 217.170.64.0/19 ge 20 le 20
156
157 Prefixes 89.112.0.0/19 and 89.112.32.0/19 now aggregated into single en‐
158 try 89.112.0.0/18 ge 19 le 19.
159
160 Well, for Juniper we can generate even more interesting policy-options,
161 using -M <extra match conditions>, -R <len> and hierarchical names:
162
163 $ bgpq4 -AJEl eltel/specifics -r 29 -R 32 -M "community blackhole" AS20597
164 policy-options {
165 policy-statement eltel {
166 term specifics {
167 replace:
168 from {
169 community blackhole;
170 route-filter 81.9.0.0/20 prefix-length-range /29-/32;
171 route-filter 81.9.32.0/20 prefix-length-range /29-/32;
172 route-filter 81.9.96.0/20 prefix-length-range /29-/32;
173 route-filter 81.222.128.0/20 prefix-length-range /29-/32;
174 route-filter 81.222.192.0/18 prefix-length-range /29-/32;
175 route-filter 85.249.8.0/21 prefix-length-range /29-/32;
176 route-filter 85.249.224.0/19 prefix-length-range /29-/32;
177 route-filter 89.112.0.0/17 prefix-length-range /29-/32;
178 route-filter 217.170.64.0/19 prefix-length-range /29-/32;
179 }
180 }
181 }
182 }
183 generated policy-option term now allows all specifics with prefix-length
184 between /29 and /32 for eltel networks if they match with special commu‐
185 nity blackhole (defined elsewhere in configuration).
186
187 Of course, this version supports IPv6 (-6):
188
189 $ bgpq4 -6l as-retn-6 AS-RETN6
190 no ipv6 prefix-list as-retn-6
191 ipv6 prefix-list as-retn-6 permit 2001:7fb:fe00::/48
192 ipv6 prefix-list as-retn-6 permit 2001:7fb:fe01::/48
193 [....]
194 and assumes your device supports 32-bit ASNs
195
196 $ bgpq4 -Jf 112 AS-SPACENET
197 policy-options {
198 replace:
199 as-path-group NN {
200 as-path a0 "^112(112)*$";
201 as-path a1 "^112(.)*(1898|5539|8495|8763|8878|12136|12931|15909)$";
202 as-path a2 "^112(.)*(21358|23456|23600|24151|25152|31529|34127|34906)$";
203 as-path a3 "^112(.)*(35052|41720|43628|44450|196611)$";
204 }
205 }
206 see `AS196611` in the end of the list ? That's a 32-bit ASN.
207
209 If you want to generate configuration not for routers, but for some other
210 programs/systems, you may use user-defined formatting, like in example
211 below:
212
213 $ bgpq4 -F "ipfw add pass all from %n/%l to any\n" as3254
214 ipfw add pass all from 62.244.0.0/18 to any
215 ipfw add pass all from 91.219.29.0/24 to any
216 ipfw add pass all from 91.219.30.0/24 to any
217 ipfw add pass all from 193.193.192.0/19 to any
218
219 Recognized format sequences are:
220
221 %n network
222 %l mask length
223 %a aggregate low mask length
224 %A aggregate high mask length
225 %N object name
226 %m object mask
227 %i inversed mask
228 \n new line
229 \t tabulation
230
231 Please note that no new lines are inserted automatically after each sen‐
232 tence. You have to add them into format string manually, otherwise the
233 output will be in one single line (sometimes it makes sense):
234
235 $ bgpq4 -6F "%n/%l; " as-eltel
236 2001:1b00::/32; 2620:4f:8000::/48; 2a04:bac0::/29; 2a05:3a80::/48;
237
239 By default bgpq4 trusts data from all the databases mirrored into NTT's
240 IRR service. Unfortunately, not all these databases are equal in how
241 much we can trust their data. RIR maintained databases (AFRINIC, ARIN,
242 APNIC, LACNIC and RIPE) shall be trusted more than the others because
243 they have the knowledge about who the rightful holders of resources are,
244 while other databases lack this knowledge and can (and, actually do) con‐
245 tain stale data: no one but the RIRs care to remove outdated route-ob‐
246 jects when address space is de-allocated or transferred. In order to
247 keep their filters both compact and actual, bgpq4 users are encouraged to
248 use '-S' flag to limit database sources to only the ones they trust.
249
250 General recommendations:
251
252 Use a minimal set of RIR databases (only those in which you and your cus‐
253 tomers have registered route-objects).
254
255 Avoid using ARIN-NONAUTH and RIPE-NONAUTH as trusted sources: these
256 records were created in the database, but for address space allocated to
257 different RIRs, so the NONAUTH databases have no chance to confirm valid‐
258 ity of the route objects they contain.
259
260 $ bgpq4 -S RIPE,RADB as-space
261 no ip prefix-list NN
262 ip prefix-list NN permit 195.190.32.0/19
263
264 $ bgpq4 -S RADB,RIPE as-space
265 no ip prefix-list NN
266 ip prefix-list NN permit 45.4.4.0/22
267 ip prefix-list NN permit 45.4.132.0/22
268 ip prefix-list NN permit 45.6.128.0/22
269 ip prefix-list NN permit 45.65.184.0/22
270 [...]
271
273 To improve `bgpq4` performance when expanding extra-large AS-SETs you
274 shall tune OS settings to enlarge TCP send buffer.
275
276 FreeBSD can be tuned in the following way:
277
278 sysctl -w net.inet.tcp.sendbuf_max=2097152
279
280 Linux can be tuned in the following way:
281
282 sysctl -w net.ipv4.tcp_window_scaling=1
283 sysctl -w net.core.rmem_max=2097152
284 sysctl -w net.core.wmem_max=2097152
285 sysctl -w net.ipv4.tcp_rmem="4096 87380 2097152"
286 sysctl -w net.ipv4.tcp_wmem="4096 65536 2097152"
287
289 This project uses autotools. If you are building from the repository, run
290 the following command to prepare the build system:
291
292 ./bootstrap
293
294 In order to compile the software, run:
295
296 ./configure
297 make
298 make install
299
300 If you wish to remove the generated build system files from your working
301 tree, run:
302
303 make maintainer-clean
304
305 In order to create a distribution archive, run:
306
307 make dist
308
310 When everything is OK, bgpq4 generates access-list to standard output and
311 exits with status == 0. In case of errors they are printed to stderr and
312 program exits with non-zero status.
313
315 Alexandre Snarskii, Christian David, Claudio Jeker, Job Snijders, Massim‐
316 iliano Stucchi, Michail Litvak, Peter Schoenmaker, Roelf Wichertjes, and
317 contributions from many others.
318
320 https://github.com/bgp/bgpq4 BGPQ4 on Github.
321
322 http://bgpfilterguide.nlnog.net/ NLNOG's BGP Filter Guide.
323
324 https://tcp0.com/cgi-bin/mailman/listinfo/bgpq4 Users and interested par‐
325 ties can subscribe to the BGPQ4 mailing list bgpq4@tcp0.com
326
328 Job Snijders <job@sobornost.net>
329
330BSD December 23, 2020 BSD