xref: /openbsd-src/etc/examples/bgpd.conf (revision 4cf1cdd0672771489a31292fd4ba780240e789e9)
1# $OpenBSD: bgpd.conf,v 1.26 2024/12/18 16:00:26 claudio Exp $
2# example bgpd configuration file, see bgpd.conf(5)
3
4# define our own ASN as a macro
5ASN="4200000001"
6
7# global configuration
8AS $ASN
9router-id 192.0.2.1
10
11# list of networks that may be originated by our ASN
12prefix-set mynetworks {
13	192.0.2.0/24
14	2001:db8:abcd::/48
15}
16
17include "/var/db/rpki-client/openbgpd"
18
19# define bogon prefixes which should not be part of the DFZ
20prefix-set bogons {
21	0.0.0.0/8 or-longer		# 'this' network [RFC1122]
22	10.0.0.0/8 or-longer		# private space [RFC1918]
23	100.64.0.0/10 or-longer		# CGN Shared [RFC6598]
24	127.0.0.0/8 or-longer		# localhost [RFC1122]
25	169.254.0.0/16 or-longer	# link local [RFC3927]
26	172.16.0.0/12 or-longer		# private space [RFC1918]
27	192.0.2.0/24 or-longer		# TEST-NET-1 [RFC5737]
28	192.88.99.0/24 or-longer	# 6to4 anycast relay [RFC7526]
29	192.168.0.0/16 or-longer	# private space [RFC1918]
30	198.18.0.0/15 or-longer		# benchmarking [RFC2544]
31	198.51.100.0/24 or-longer	# TEST-NET-2 [RFC5737]
32	203.0.113.0/24 or-longer	# TEST-NET-3 [RFC5737]
33	224.0.0.0/4 or-longer		# multicast
34	240.0.0.0/4 or-longer		# reserved for future use
35	::/8 or-longer			# RFC 4291 IPv4-compatible, loopback, et al
36	0100::/64 or-longer		# Discard-Only [RFC6666]
37	2001:2::/48 or-longer		# BMWG [RFC5180]
38	2001:10::/28 or-longer		# ORCHID [RFC4843]
39	2001:db8::/32 or-longer		# docu range [RFC3849]
40	2002::/16 or-longer		# 6to4 anycast relay [RFC7526]
41	3ffe::/16 or-longer		# old 6bone
42	3fff::/20 or-longer		# docu range [RFC9637]
43	5f00::/16 or-longer		# segment routing SRv6 SIDs [RFC9602]
44	fc00::/7 or-longer		# unique local unicast
45	fe80::/10 or-longer		# link local unicast
46	fec0::/10 or-longer		# old site local unicast
47	ff00::/8 or-longer		# multicast
48}
49
50# Generate routes for the networks our ASN will originate.
51# The communities (read 'tags') are later used to match on what
52# is announced to EBGP neighbors
53network prefix-set mynetworks set large-community local-as:1:1
54
55# assume simple network with 3 routers in IBGP full mesh
56group "ibgp mesh" {
57	remote-as $ASN
58	# use loopback for IBGP sessions, assume it's distributed in OSPF
59	local-address 192.0.2.1
60	local-address 2001:db8:abcd::1
61
62	neighbor 192.0.2.2		# router 2 ipv4
63	neighbor 2001:db8:abcd::2	# router 2 ipv6
64	neighbor 192.0.2.3		# router 3 ipv4
65	neighbor 2001:db8:abcd::3	# router 3 ipv6
66}
67
68# upstream providers
69group "upstreams" {
70	neighbor 203.0.113.1 {
71		remote-as 65002
72		descr "upstream1"
73	}
74	neighbor 198.51.100.0 {
75		remote-as 65123
76		descr "upstream2-4"
77	}
78	neighbor 2001:db8:666::2 {
79		remote-as 65123
80		descr "upstream2-6"
81	}
82}
83
84## rules section
85
86# uncomment the following two lines to accept a default route from upstreams
87#allow from group upstreams prefix 0.0.0.0/0
88#allow from group upstreams prefix ::/0
89
90### for simple BGP setups, no editing below this line is required ###
91
92# Outbound EBGP: only allow self originated networks to ebgp peers
93# Don't leak any routes from upstream or peering sessions. This is done
94# by checking for routes that are tagged with the large-community local-as:1:1
95allow to ebgp prefix-set mynetworks large-community local-as:1:1
96
97# deny more-specifics of our own originated prefixes
98deny quick from ebgp prefix-set mynetworks or-longer
99
100# IBGP: allow all updates to and from our IBGP neighbors
101allow from ibgp
102allow to ibgp
103
104# Scrub normal and large communities relevant to our ASN from EBGP neighbors
105# https://tools.ietf.org/html/rfc7454#section-11
106match from ebgp set { community delete local-as:* }
107match from ebgp set { large-community delete local-as:*:* }
108
109# filter out prefixes longer than 24 or shorter than 8 bits for IPv4
110# and longer than 48 or shorter than 16 bits for IPv6.
111allow from any inet prefixlen 8 - 24
112allow from any inet6 prefixlen 16 - 48
113
114# Honor requests to gracefully shutdown BGP sessions
115# https://tools.ietf.org/html/rfc8326
116match from ebgp community GRACEFUL_SHUTDOWN set { localpref 0 }
117
118deny quick from any prefix-set bogons
119
120# deny RPKI invalid, built by rpki-client(8), see root crontab
121deny quick from ebgp ovs invalid
122
123# filter bogon AS numbers
124# AS_TRANS (23456) is not supposed to show up in any path and indicates a
125# misconfiguration. Additionally Private or Reserved ASNs have no place in
126# the public DFZ. https://www.iana.org/assignments/as-numbers/as-numbers.xhtml
127deny quick from any AS 23456
128deny quick from any AS 64496 - 131071
129deny quick from any AS 4200000000 - 4294967295
130
131# filter out too long paths
132deny from any max-as-len 100
133