Debian Codegraph @

bgpq3.html

raw
1 <p><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.or
2 g/TR/html4/loose.dtd"> <br />
3 <html><head><style type='text/css'>
4 h1 { color: #3c78b5; border-bottom: 3px solid #3c78b5; font-size: 180%; }
5 h2 { color: #3c78b5; border-bottom: 2px solid #3c78b5; font-size: 140%; }
6 h3 { color: #3c78b5; border-bottom: 1px dotted #3c78b5; font-size: 129%; }
7 em { color: #0000FF; }
8 code { font-size:12px; background-color:#f8f8ff; border:1px; }
9 pre { border: 1px dotted #3c78b5; background-color: #f8f8ff; margin: 1em 1em;}
10 body { width: 80%; margin: 0 3em; }
11 ul { list-style: none; }
12 </style></head><body> </p>
13
14 <h2>NAME</h2>
15
16 <p><code>bgpq3</code> - bgp filtering automation tool</p>
17
18 <h2>SYNOPSIS</h2>
19
20 <p><code>
21 bgpq3 [-h host[:port]] [-S sources] [-EPz] [-f asn | -F fmt | -G asn | -t] [-2346ABbDdJjNnpsUX] [-a asn] [-r len] [-R len] [-m max] [-W len] OBJECTS [...] EXCEPT OBJECTS
22 </code></p>
23
24 <h2>DESCRIPTION</h2>
25
26 <p>The bgpq3 utility used to generate configuration (prefix-lists,
27 extended access-lists, policy-statement terms and as-path lists)
28 based on RADB data.</p>
29
30 <p>The options are as follows:</p>
31
32 <h4>-2</h4>
33
34 <p>Allow routes registered for as23456 (transition-as) (default: false)</p>
35
36 <h4>-3</h4>
37
38 <p>Assume that your device is asn32-capable.</p>
39
40 <h4>-4</h4>
41
42 <p>Generate IPv4 prefix/access-lists (default).</p>
43
44 <h4>-6</h4>
45
46 <p>Generate IPv6 prefix/access-lists (IPv4 by default).</p>
47
48 <h4>-A</h4>
49
50 <p>Try to aggregate generated filters as much as possible (not all output formats
51 supported).</p>
52
53 <h4>-a asn</h4>
54
55 <p>Specify ASN that shall be denied in case of empty prefix-list (OpenBGPD).</p>
56
57 <h4>-B</h4>
58
59 <p>Generate output in OpenBGPD format (default: Cisco).</p>
60
61 <h4>-b</h4>
62
63 <p>Generate output in BIRD format (default: Cisco).</p>
64
65 <h4>-d</h4>
66
67 <p>Enable some debugging output.</p>
68
69 <h4>-D</h4>
70
71 <p>Use asdot notation for Cisco as-path access-lists.</p>
72
73 <h4>-E</h4>
74
75 <p>Generate extended access-list (Cisco) or policy-statement term using
76 route-filters (Juniper), [ip|ipv6]-prefix-list (Nokia) or prefix-filter
77 (OpenBGPD)</p>
78
79 <h4>-f <code>AS number</code></h4>
80
81 <p>Generate input as-path access-list for adjacent as <code>AS number</code>.</p>
82
83 <h4>-F <code>fmt</code></h4>
84
85 <p>Generate output in user-defined format.</p>
86
87 <h4>-G <code>number</code></h4>
88
89 <p>Generate output as-path access-list.</p>
90
91 <h4>-h <code>host[:port]</code></h4>
92
93 <p>Host running IRRD database (default: <code>whois.radb.net</code>).</p>
94
95 <h4>-J</h4>
96
97 <p>Generate config for Juniper (default: Cisco).</p>
98
99 <h4>-j</h4>
100
101 <p>Generate output in JSON format (default: Cisco).</p>
102
103 <h4>-m <code>length</code></h4>
104
105 <p>Maximum length of accepted prefixes (default: <code>32</code> for IPv4, <code>128</code> for IPv6).</p>
106
107 <h4>-M <code>match</code></h4>
108
109 <p>Extra match conditions for Juniper route-filters. See the examples section.</p>
110
111 <h4>-n</h4>
112
113 <p>Generate config for Nokia SR OS (former Alcatel-Lucent) MD-CLI (default: Cisco)</p>
114
115 <h4>-N</h4>
116
117 <p>Generate config for Nokia SR OS (former Alcatel-Lucent) classic CLI (default: Cisco)</p>
118
119 <h4>-l <code>name</code></h4>
120
121 <p><code>Name</code> of generated configuration stanza.</p>
122
123 <h4>-L <code>limit</code></h4>
124
125 <p>Limit recursion depth when expanding. This slows <code>bgpq3</code> a bit, but sometimes
126 is a useful feature to prevent generated filters from growing too big.</p>
127
128 <h4>-p</h4>
129
130 <p>Enable use of private ASNs and ASNs used for documentation purpose only
131 (default: disabled).</p>
132
133 <h4>-P</h4>
134
135 <p>Generate prefix-list (default behaviour, flag added for backward compatibility
136 only).</p>
137
138 <h4>-r <code>length</code></h4>
139
140 <p>Allow more-specific routes with masklen starting with specified length.</p>
141
142 <h4>-R <code>length</code></h4>
143
144 <p>Allow more-specific routes up to specified masklen too. (Please, note: objects
145 with prefix-length greater than specified length will be always allowed.)</p>
146
147 <h4>-s</h4>
148
149 <p>Generate sequence numbers in IOS-style prefix-lists.</p>
150
151 <h4>-S <code>sources</code></h4>
152
153 <p>Use specified database sources only (example: RIPE,APNIC,RADB).</p>
154
155 <h4>-t</h4>
156
157 <p>Generate as-sets for OpenBGPD (OpenBSD 6.4+), BIRD and JSON formats.</p>
158
159 <h4>-T</h4>
160
161 <p>Disable pipelining. (not recommended)</p>
162
163 <h4>-U</h4>
164
165 <p>Generate output in Huawei format (default: Cisco).</p>
166
167 <h4>-W <code>length</code></h4>
168
169 <p>Generate as-path strings of a given length maximum (0 for infinity).</p>
170
171 <h4>-X</h4>
172
173 <p>Generate config for Cisco IOS XR devices (plain IOS by default).</p>
174
175 <h4>-z</h4>
176
177 <p>Generate Juniper route-filter-list (JunOS 16.2+).</p>
178
179 <h4><code>OBJECTS</code></h4>
180
181 <p><code>OBJECTS</code> means networks (in prefix format), autonomous systems, as-sets and
182 route-sets. If multiple objects are specified they will be merged.</p>
183
184 <h4><code>EXCEPT OBJECTS</code></h4>
185
186 <p>You can exclude autonomous sets, as-sets and route-sets found during
187 expansion from future expansion.</p>
188
189 <h2>EXAMPLES</h2>
190
191 <p>Generating named Juniper prefix-filter for <code>AS20597</code>:</p>
192
193 <pre><code> user@host:~&gt;bgpq3 -Jl eltel AS20597
194 policy-options {
195 replace:
196 prefix-list eltel {
197 81.9.0.0/20;
198 81.9.32.0/20;
199 81.9.96.0/20;
200 81.222.128.0/20;
201 81.222.192.0/18;
202 85.249.8.0/21;
203 85.249.224.0/19;
204 89.112.0.0/19;
205 89.112.4.0/22;
206 89.112.32.0/19;
207 89.112.64.0/19;
208 217.170.64.0/20;
209 217.170.80.0/20;
210 }
211 }
212 </code></pre>
213
214 <p>For Cisco we can use aggregation (-A) flag to make this prefix-filter
215 more compact:</p>
216
217 <pre><code> user@host:~&gt;bgpq3 -Al eltel AS20597
218 no ip prefix-list eltel
219 ip prefix-list eltel permit 81.9.0.0/20
220 ip prefix-list eltel permit 81.9.32.0/20
221 ip prefix-list eltel permit 81.9.96.0/20
222 ip prefix-list eltel permit 81.222.128.0/20
223 ip prefix-list eltel permit 81.222.192.0/18
224 ip prefix-list eltel permit 85.249.8.0/21
225 ip prefix-list eltel permit 85.249.224.0/19
226 ip prefix-list eltel permit 89.112.0.0/18 ge 19 le 19
227 ip prefix-list eltel permit 89.112.4.0/22
228 ip prefix-list eltel permit 89.112.64.0/19
229 ip prefix-list eltel permit 217.170.64.0/19 ge 20 le 20
230 </code></pre>
231
232 <p>and, as you see, prefixes <code>89.112.0.0/19</code> and <code>89.112.32.0/19</code> now aggregated
233 into single entry </p>
234
235 <pre><code>ip prefix-list eltel permit 89.112.0.0/18 ge 19 le 19.
236 </code></pre>
237
238 <p>Well, for Juniper we can generate even more interesting policy-statement,
239 using <code>-M &lt;extra match conditions&gt;</code>, <code>-r &lt;len&gt;</code>, <code>-R &lt;len&gt;</code> and hierarchical
240 names:</p>
241
242 <pre><code> user@host:~&gt;bgpq3 -AJEl eltel/specifics -r 29 -R 32 -M "community blackhole" AS20597
243 policy-options {
244 policy-statement eltel {
245 term specifics {
246 replace:
247 from {
248 community blackhole;
249 route-filter 81.9.0.0/20 prefix-length-range /29-/32;
250 route-filter 81.9.32.0/20 prefix-length-range /29-/32;
251 route-filter 81.9.96.0/20 prefix-length-range /29-/32;
252 route-filter 81.222.128.0/20 prefix-length-range /29-/32;
253 route-filter 81.222.192.0/18 prefix-length-range /29-/32;
254 route-filter 85.249.8.0/21 prefix-length-range /29-/32;
255 route-filter 85.249.224.0/19 prefix-length-range /29-/32;
256 route-filter 89.112.0.0/17 prefix-length-range /29-/32;
257 route-filter 217.170.64.0/19 prefix-length-range /29-/32;
258 }
259 }
260 }
261 }
262 </code></pre>
263
264 <p>generated policy-option term now allows more-specific routes in range
265 /29 - /32 for eltel networks if they marked with community 'blackhole'
266 (defined elsewhere in configuration).</p>
267
268 <p>Of course, <code>bgpq3</code> supports IPv6 (-6):</p>
269
270 <pre><code> user@host:~&gt;bgpq3 -6l as-retn-6 AS-RETN6
271 no ipv6 prefix-list as-retn-6
272 ipv6 prefix-list as-retn-6 permit 2001:7fb:fe00::/48
273 ipv6 prefix-list as-retn-6 permit 2001:7fb:fe01::/48
274 [....]
275 </code></pre>
276
277 <p>and ASN32</p>
278
279 <pre><code> user@host:~&gt;bgpq3 -J3f 112 AS-SPACENET
280 policy-options {
281 replace:
282 as-path-group NN {
283 as-path a0 "^112(112)*$";
284 as-path a1 "^112(.)*(1898|5539|8495|8763|8878|12136|12931|15909)$";
285 as-path a2 "^112(.)*(21358|23456|23600|24151|25152|31529|34127|34906)$";
286 as-path a3 "^112(.)*(35052|41720|43628|44450|196611)$";
287 }
288 }
289 </code></pre>
290
291 <p>see <code>AS196611</code> in the end of the list ? That's <code>AS3.3</code> in 'asplain' notation.</p>
292
293 <p>If your router does not support ASN32 (yet) you should not use switch -3,
294 and the result will be next:</p>
295
296 <pre><code> user@host:~&gt;bgpq3 -f 112 AS-SPACENET
297 no ip as-path access-list NN
298 ip as-path access-list NN permit ^112( 112)*$
299 ip as-path access-list NN permit ^112( [0-9]+)* (1898|5539|8495|8763)$
300 ip as-path access-list NN permit ^112( [0-9]+)* (8878|12136|12931|15909)$
301 ip as-path access-list NN permit ^112( [0-9]+)* (21358|23456|23600|24151)$
302 ip as-path access-list NN permit ^112( [0-9]+)* (25152|31529|34127|34906)$
303 ip as-path access-list NN permit ^112( [0-9]+)* (35052|41720|43628|44450)$
304 </code></pre>
305
306 <p><code>AS196611</code> is no more in the list, however, <code>AS23456</code> (transition AS) would
307 have been added to list if it were not present.</p>
308
309 <h2>USER-DEFINED FORMAT</h2>
310
311 <p>If you want to generate configuration not for routers, but for some
312 other programs/systems, you may use user-defined formatting, like in
313 example below:</p>
314
315 <pre><code>user@host:~&gt;bgpq3 -F "ipfw add pass all from %n/%l to any\\n" as3254
316 ipfw add pass all from 62.244.0.0/18 to any
317 ipfw add pass all from 91.219.29.0/24 to any
318 ipfw add pass all from 91.219.30.0/24 to any
319 ipfw add pass all from 193.193.192.0/19 to any
320 </code></pre>
321
322 <p>Recognized format characters: '%n' - network, '%l' - mask length,
323 '%N' - object name, '%m' - object mask and '%i' - inversed mask.
324 Recognized escape characters: '\n' - new line, '\t' - tabulation.
325 Please note that no new lines inserted automatically after each sentence,
326 you have to add them into format string manually, elsewhere output will
327 be in one line (sometimes it makes sense):</p>
328
329 <pre><code>user@host:~&gt;bgpq3 -6F "%n/%l; " as-eltel
330 2001:1b00::/32; 2620:4f:8000::/48; 2a04:bac0::/29; 2a05:3a80::/48;
331 </code></pre>
332
333 <h2>NOTES ON 'Database Sources' (-S) flag</h2>
334
335 <p>By default <code>bgpq3</code> trusts to data from all databases mirrored into RADB.
336 Unfortunately, not all these databases are equal in how much can we
337 trust their data. RIR maintained databases (AFRINIC,ARIN,APNIC and RIPE)
338 shall be trusted more than the others because they are indeed have the
339 knowledge about which address space allocated to this or that ASn,
340 other databases lack this knowledge and can (and, actually, do) contain
341 some stale data: noone but RIRs care to remove outdated route-objects
342 when address space revoked from one ASn and allocated to another.
343 In order to keep their filters both compact and actual, <code>bgpq3</code> users
344 are encouraged to use '-S' flag to limit database sources to only
345 ones they trust.</p>
346
347 <p>General recommendations:
348 * use minimal set of RIR databases (only those in which you and your
349 customers have registered route-objects). Keep RIR of your home region
350 first in the list.
351 * use non-RIR databases only when operating in LACNIC region (for some
352 reason LACNIC does not export their data to RADB) or when you are unable
353 to make your customers maintain their data in RIR databases.
354 * avoid using RIPE-NONAUTH as trusted source: these records were created
355 in RIPE database but for address space allocated to different RIR,
356 so RIPE had no chance to check validity of this route.</p>
357
358 <p>Note on source ordering: order matters. When expanding as-sets,
359 <code>IRRd</code> sequentally checks all sources for matching object and stops
360 on first found entry. So, in case when as-set registered in multiple
361 databases (with different content), generated filters may differ
362 depending on source order:</p>
363
364 <pre><code>snar@host:~&gt;bgpq3 -S RIPE,RADB as-space
365 no ip prefix-list NN
366 ip prefix-list NN permit 195.190.32.0/19
367
368 snar@host:~&gt;bgpq3 -S RADB,RIPE as-space
369 no ip prefix-list NN
370 ip prefix-list NN permit 45.4.4.0/22
371 ip prefix-list NN permit 45.4.132.0/22
372 ip prefix-list NN permit 45.6.128.0/22
373 ip prefix-list NN permit 45.65.184.0/22
374 [...]
375 </code></pre>
376
377 <p>Example: as we are operating mostly in Europe and APAC, we generate most
378 of our filters with '-S RIPE,APNIC,RADB'.</p>
379
380 <h2>DIAGNOSTICS</h2>
381
382 <p>When everything is OK, <code>bgpq3</code> generates result to standard output and
383 exits with status == 0. In case of errors they are printed to stderr and
384 program exits with non-zero status.</p>
385
386 <h2>NOTES ON ULTRA-LARGE PREFIX-LISTS</h2>
387
388 <p>To improve <code>bgpq3</code> performance when expanding extra-large AS-SETs you
389 shall tune OS settings to enlarge TCP send buffer.</p>
390
391 <p>FreeBSD can be tuned in the following way:</p>
392
393 <pre><code>sysctl -w net.inet.tcp.sendbuf_max=2097152
394 </code></pre>
395
396 <p>Linux can be tuned in the following way:</p>
397
398 <pre><code>sysctl -w net.ipv4.tcp_window_scaling=1
399 sysctl -w net.core.rmem_max=2097152
400 sysctl -w net.core.wmem_max=2097152
401 sysctl -w net.ipv4.tcp_rmem="4096 87380 2097152"
402 sysctl -w net.ipv4.tcp_wmem="4096 65536 2097152"
403 </code></pre>
404
405 <p>Please note that generated prefix-lists may not fit your router's
406 limitations. For example, JunOS supports only 85,325 prefixes in
407 each prefix-list <a href="http://www.juniper.net/techpubs/en_US/junos11.4/topics/reference/configuration-statement/prefix-list-edit-policy-options.html">4</a>. </p>
408
409 <h2>SEE ALSO</h2>
410
411 <ol>
412 <li><a href="http://www.radb.net/">Routing Arbiter</a></li>
413 <li><a href="https://tools.ietf.org/html/draft-michaelson-4byte-as-representation-05">draft-michaelson-4byte-as-representation-05</a>
414 for information on 'asdot' and 'asplain' notations.</li>
415 <li><a href="http://www.cisco.com/en/US/prod/collateral/iosswrel/ps6537/ps6554/ps6599/data_sheet_C78-521821.html">Cisco documentation</a>
416 for information on Cisco implementation of ASN32.</li>
417 <li><a href="http://www.juniper.net/techpubs/en_US/junos11.4/topics/reference/configuration-statement/prefix-list-edit-policy-options.html">JunOS prefix-lists limitation</a></li>
418 </ol>
419
420 <h2>AUTHOR</h2>
421
422 <p>Alexandre Snarskii <a href="mailto:[email protected]">[email protected]</a></p>
423
424 <h2>Program Homepage</h2>
425
426 <p><a href="http://snar.spb.ru/prog/bgpq3/">http://snar.spb.ru/prog/bgpq3/</a></p>