BGPQ4(8) | System Manager's Manual | BGPQ4(8) |
bgpq4
— bgp
filtering automation tool
bgpq4 |
[-h host[:port]]
[-S sources]
[-EPz ] [-f
asn | -F
fmt | -G
asn -t ]
[-46ABbDdJjNnsXU ] [-a
asn] [-r
len] [-R
len] [-m
max] [-W
len] OBJECTS [...] [EXCEPT
OBJECTS] |
The bgpq4
utility used to generate
configurations (prefix-lists, extended access-lists, policy-statement terms
and as-path lists) based on RADB data.
The options are as follows:
-4
-6
-A
-a
asn-B
-b
-d
-E
-f
number-F
fmt-G
number-h
host[:port]-J
-j
-K
-l
name-L
limit-m
len-M
match-n
-N
-p
-P
-r
len-R
len-s
-S
sources-t
-T
-W
len-U
-X
-z
Generating named juniper prefix-filter for AS20597:
$ bgpq4 -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.192.0/18; 85.249.8.0/21; 85.249.224.0/19; 89.112.0.0/19; 89.112.4.0/22; 89.112.32.0/19; 89.112.64.0/19; 217.170.64.0/20; 217.170.80.0/20; } }
For Cisco we can use aggregation (-A) flag to make this prefix-filter more compact:
$ bgpq4 -Al eltel AS20597 no ip prefix-list eltel ip prefix-list eltel permit 81.9.0.0/20 ip prefix-list eltel permit 81.9.32.0/20 ip prefix-list eltel permit 81.9.96.0/20 ip prefix-list eltel permit 81.222.128.0/20 ip prefix-list eltel permit 81.222.192.0/18 ip prefix-list eltel permit 85.249.8.0/21 ip prefix-list eltel permit 85.249.224.0/19 ip prefix-list eltel permit 89.112.0.0/18 ge 19 le 19 ip prefix-list eltel permit 89.112.4.0/22 ip prefix-list eltel permit 89.112.64.0/19 ip prefix-list eltel permit 217.170.64.0/19 ge 20 le 20
- you see, prefixes 89.112.0.0/19 and 89.112.32.0/19 now aggregated into single entry 89.112.0.0/18 ge 19 le 19.
Well, for Juniper we can generate even more interesting policy-options, using -M <extra match conditions>, -R <len> and hierarchical names:
$ bgpq4 -AJEl eltel/specifics -r 29 -R 32 -M "community blackhole" AS20597 policy-options { policy-statement eltel { term specifics { replace: from { community blackhole; route-filter 81.9.0.0/20 prefix-length-range /29-/32; route-filter 81.9.32.0/20 prefix-length-range /29-/32; route-filter 81.9.96.0/20 prefix-length-range /29-/32; route-filter 81.222.128.0/20 prefix-length-range /29-/32; route-filter 81.222.192.0/18 prefix-length-range /29-/32; route-filter 85.249.8.0/21 prefix-length-range /29-/32; route-filter 85.249.224.0/19 prefix-length-range /29-/32; route-filter 89.112.0.0/17 prefix-length-range /29-/32; route-filter 217.170.64.0/19 prefix-length-range /29-/32; } } } }generated policy-option term now allows all specifics with prefix-length between /29 and /32 for eltel networks if they match with special community blackhole (defined elsewhere in configuration).
Of course, this version supports IPv6 (-6):
$ bgpq4 -6l as-retn-6 AS-RETN6 no ipv6 prefix-list as-retn-6 ipv6 prefix-list as-retn-6 permit 2001:7fb:fe00::/48 ipv6 prefix-list as-retn-6 permit 2001:7fb:fe01::/48 [....]and assumes your device supports 32-bit ASNs
$ bgpq4 -Jf 112 AS-SPACENET policy-options { replace: as-path-group NN { as-path a0 "^112(112)*$"; as-path a1 "^112(.)*(1898|5539|8495|8763|8878|12136|12931|15909)$"; as-path a2 "^112(.)*(21358|23456|23600|24151|25152|31529|34127|34906)$"; as-path a3 "^112(.)*(35052|41720|43628|44450|196611)$"; } }
see `AS196611` in the end of the list ? That's a 32-bit ASN.
If you want to generate configuration not for routers, but for some other programs/systems, you may use user-defined formatting, like in example below:
$ bgpq4 -F "ipfw add pass all from %n/%l to any\n" as3254 ipfw add pass all from 62.244.0.0/18 to any ipfw add pass all from 91.219.29.0/24 to any ipfw add pass all from 91.219.30.0/24 to any ipfw add pass all from 193.193.192.0/19 to any
Recognized format characters: %n - network, %l - mask length, %a - aggregate low mask length, %A - aggregate high mask length, %N - object name, %m - object mask and %i - inversed mask. Recognized escape characters: \n - new line, \t - tabulation. Please note that no new lines inserted automatically after each sentence, you have to add them into format string manually, elsewhere output will be in one line (sometimes it makes sense):
$ bgpq4 -6F "%n/%l; " as-eltel 2001:1b00::/32; 2620:4f:8000::/48; 2a04:bac0::/29; 2a05:3a80::/48;
When everything is OK, bgpq4
generates
access-list to standard output and exits with status == 0. In case of errors
they are printed to stderr and program exits with non-zero status.
https://github.com/bgp/bgpq4 BGPQ4 on Github.
Job Snijders ⟨job@ntt.net⟩
December 1, 2019 | Debian |