-
Notifications
You must be signed in to change notification settings - Fork 6
/
bird.conf
749 lines (597 loc) · 18.9 KB
/
bird.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
# --- Configuration ---
define ROUTER_ID = 198.51.100.1;
define OUR_AS = 65536;
define REGION_ID = 840;
define SITE_ID = 1;
define ORIGINATED_PREFIXES_4 = [
198.51.100.0/24
];
define ORIGINATED_PREFIXES_6 = [
2001:db8::/32
];
define OUR_INTERNAL_PREFIXES_4 = [
198.51.100.0/24+
];
define OUR_INTERNAL_PREFIXES_6 = [
2001:db8::/32+
];
define GLOBAL_BLACKLIST_4 = [
203.0.113.0/23+
];
define GLOBAL_BLACKLIST_6 = [
fd00:504:36::/64+
];
define GLOBAL_WHITELIST_6 = [
2001:db8:fff::/48
];
# --- Constants ---
define BOGONS_4 = [
0.0.0.0/0, # Default route
0.0.0.0/8{8,32}, # IANA - Local Identification
10.0.0.0/8{8,32}, # RFC 1918 - Private Use
100.64.0.0/10{10,32}, # RFC 6598 - Shared Address Space
127.0.0.0/8{8,32}, # IANA - Loopback
169.254.0.0/16{16,32}, # RFC 3927 - Link Local
172.16.0.0/12{12,32}, # RFC 1918 - Private Use
192.0.2.0/24{24,32}, # RFC 5737 - TEST-NET-1
192.88.99.0/24{24,32}, # RFC 3068 - 6to4 prefix
192.168.0.0/16{16,32}, # RFC 1918 - Private Use
198.18.0.0/15{15,32}, # RFC 2544 - Network Interconnect Device Benchmark Testing
198.51.100.0/24{24,32}, # RFC 5737 - TEST-NET-2
203.0.113.0/24{24,32}, # RFC 5737 - TEST-NET-3
224.0.0.0/3{3,32} # RFC 5771 - Multcast (formerly Class D)
];
define BOGONS_6 = [
::/0, # Default route
::/8{8,128}, # loopback, unspecified, v4-mapped
64:ff9b::/96{96,128}, # RFC 6052 - IPv4-IPv6 Translation
100::/8{8,128}, # RFC 6666 - reserved for Discard-Only Address Block
200::/7{7,128}, # RFC 4048 - Reserved by IETF
400::/6{6,128}, # RFC 4291 - Reserved by IETF
800::/5{5,128}, # RFC 4291 - Reserved by IETF
1000::/4{4,128}, # RFC 4291 - Reserved by IETF
2001::/33{33,128}, # RFC 4380 - Teredo prefix
2001:0:8000::/33{33,128}, # RFC 4380 - Teredo prefix
2001:2::/48{48,128}, # RFC 5180 - Benchmarking
2001:3::/32{32,128}, # RFC 7450 - Automatic Multicast Tunneling
2001:10::/28{28,128}, # RFC 4843 - Deprecated ORCHID
2001:20::/28{28,128}, # RFC 7343 - ORCHIDv2
2001:db8::/32{32,128}, # RFC 3849 - NON-ROUTABLE range to be used for documentation purpose
2002::/16{16,128}, # RFC 3068 - 6to4 prefix
3ffe::/16{16,128}, # RFC 5156 - used for the 6bone but was returned
4000::/3{3,128}, # RFC 4291 - Reserved by IETF
5f00::/8{8,128}, # RFC 5156 - used for the 6bone but was returned
6000::/3{3,128}, # RFC 4291 - Reserved by IETF
8000::/3{3,128}, # RFC 4291 - Reserved by IETF
a000::/3{3,128}, # RFC 4291 - Reserved by IETF
c000::/3{3,128}, # RFC 4291 - Reserved by IETF
e000::/4{4,128}, # RFC 4291 - Reserved by IETF
f000::/5{5,128}, # RFC 4291 - Reserved by IETF
f800::/6{6,128}, # RFC 4291 - Reserved by IETF
fc00::/7{7,128}, # RFC 4193 - Unique Local Unicast
fe80::/10{10,128}, # RFC 4291 - Link Local Unicast
fec0::/10{10,128}, # RFC 4291 - Reserved by IETF
ff00::/8{8,128} # RFC 4291 - Multicast
];
define INVALID_ASNS = [
0, # Reserved. RFC7607
23456, # AS_TRANS. RFC6793
64496..64511, # Reserved for use in documentation and sample code. RFC5398
64512..65534, # Reserved for Private Use. RFC6996
65535, # Reserved. RFC7300
65536..65551, # Reserved for use in documentation and sample code. RFC5398
65552..131071, # Reserved.
4200000000..4294967294, # Reserved for Private Use. [RFC6996]
4294967295 # Reserved. RFC7300
];
router id ROUTER_ID;
timeformat base iso long;
timeformat log iso long;
timeformat protocol iso long;
timeformat route iso long;
protocol device {};
protocol direct {
ipv4;
ipv6;
}
protocol kernel {
scan time 10;
ipv4 {
export filter {
if source = RTS_STATIC then {
accept;
} else {
krt_prefsrc = 198.51.100.1;
accept;
}
};
};
}
protocol kernel {
scan time 10;
ipv6 {
export filter {
if source = RTS_STATIC then {
accept;
} else {
krt_prefsrc = 2001:db8::200:5eff:fe15:429e;
accept;
}
};
};
}
# --- RPKI ---
roa4 table RPKI4;
roa6 table RPKI6;
protocol rpki {
roa4 { table RPKI4; };
roa6 { table RPKI6; };
remote "rpki.fqdn.example" port 8282;
retry keep 90;
refresh keep 900;
expire keep 172800;
}
# --- Functions ---
function prefix_is_bogon() {
if net.type = NET_IP4 then
if net ~ BOGONS_4 then return true;
if net.type = NET_IP6 then
if net ~ BOGONS_6 then return true;
return false;
}
function as_path_contains_invalid_asn() {
return bgp_path ~ INVALID_ASNS;
}
function prefix_is_in_global_blacklist() {
if net.type = NET_IP4 then
if net ~ GLOBAL_BLACKLIST_4 then return true;
if net.type = NET_IP6 then
if net ~ GLOBAL_BLACKLIST_6 then return true;
return false;
}
function prefix_is_in_global_whitelist() {
if net.type = NET_IP6 then
if net ~ GLOBAL_WHITELIST_6 then return true;
return false;
}
function is_own_prefix() {
if net.type = NET_IP4 then {
if net ~ ORIGINATED_PREFIXES_4 then {
bgp_large_community.add((OUR_AS, 101, 1));
return true;
}
}
if net.type = NET_IP6 then {
if net ~ ORIGINATED_PREFIXES_6 then {
bgp_large_community.add((OUR_AS, 101, 1));
return true;
}
}
return false;
}
function is_own_internal_prefix() {
if net.type = NET_IP4 then
if net ~ OUR_INTERNAL_PREFIXES_4 then return true;
if net.type = NET_IP6 then
if net ~ OUR_INTERNAL_PREFIXES_6 then return true;
return false;
}
function was_learned_from_peer() {
if (OUR_AS, 101, 2) ~ bgp_large_community then return true;
return false;
}
function was_learned_from_private_peer() {
if (OUR_AS, 101, 3) ~ bgp_large_community then return true;
return false;
}
function was_learned_from_upstream() {
if (OUR_AS, 101, 4) ~ bgp_large_community then return true;
return false;
}
function was_learned_from_customer() {
if (OUR_AS, 101, 5) ~ bgp_large_community then return true;
return false;
}
function is_prefix_length_valid(int pref_len_min; int pref_len_max) {
if net.len < pref_len_min then return false;
if net.len > pref_len_max then return false;
return true;
}
function should_not_export_to_site() {
if (OUR_AS, 603, SITE_ID) ~ bgp_large_community then return true;
return false;
}
function should_not_export_to_region() {
if (OUR_AS, 603, REGION_ID) ~ bgp_large_community then return true;
return false;
}
function should_not_export_to_peers() {
if (OUR_AS, 601, 2) ~ bgp_large_community then return true;
return false;
}
function should_not_export_to_private_peers() {
if (OUR_AS, 601, 3) ~ bgp_large_community then return true;
return false;
}
function should_not_export_to_upstreams() {
if (OUR_AS, 601, 4) ~ bgp_large_community then return true;
return false;
}
function should_not_export_to_customers() {
if (OUR_AS, 601, 5) ~ bgp_large_community then return true;
return false;
}
function add_peer_community() {
bgp_large_community.add((OUR_AS, 101, 2));
}
function add_private_peer_community() {
bgp_large_community.add((OUR_AS, 101, 3));
}
function add_upstream_community() {
bgp_large_community.add((OUR_AS, 101, 4));
}
function add_customer_community() {
bgp_large_community.add((OUR_AS, 101, 5));
}
function add_region_community() {
bgp_large_community.add((OUR_AS, 102, REGION_ID));
}
function add_site_community() {
bgp_large_community.add((OUR_AS, 103, SITE_ID));
}
function add_global_prepends() {
if (OUR_AS, 900, 1) ~ bgp_large_community then
{ bgp_path.prepend(OUR_AS); }
if (OUR_AS, 900, 2) ~ bgp_large_community then
{ bgp_path.prepend(OUR_AS); bgp_path.prepend(OUR_AS); }
if (OUR_AS, 900, 3) ~ bgp_large_community then
{ bgp_path.prepend(OUR_AS); bgp_path.prepend(OUR_AS); bgp_path.prepend(OUR_AS); }
}
function add_as_specific_prepends(int exporting_asn) {
if (OUR_AS, 991, exporting_asn) ~ bgp_large_community then
{ bgp_path.prepend(OUR_AS); }
if (OUR_AS, 992, exporting_asn) ~ bgp_large_community then
{ bgp_path.prepend(OUR_AS); bgp_path.prepend(OUR_AS); }
if (OUR_AS, 993, exporting_asn) ~ bgp_large_community then
{ bgp_path.prepend(OUR_AS); bgp_path.prepend(OUR_AS); bgp_path.prepend(OUR_AS); }
}
function handle_as_specific_no_export(int exporting_asn) {
if (OUR_AS, 600, exporting_asn) ~ bgp_large_community then
reject "NO_EXPORT community in place for specific AS - NOT ANNOUNCING ", net;
}
function add_rpki_community(string rpki_status) {
if rpki_status = "valid" then {
bgp_ext_community.add((unknown 0x4300, 0, 0));
}
if rpki_status = "unknown" then {
bgp_ext_community.add((unknown 0x4300, 0, 1));
}
if rpki_status = "invalid" then {
bgp_ext_community.add((unknown 0x4300, 0, 2));
}
}
function perform_rpki_validation() {
if net.type = NET_IP4 then {
case roa_check(RPKI4) {
ROA_VALID: add_rpki_community("valid");
ROA_UNKNOWN: add_rpki_community("unknown");
ROA_INVALID: add_rpki_community("invalid");
}
} else {
case roa_check(RPKI6) {
ROA_VALID: add_rpki_community("valid");
ROA_UNKNOWN: add_rpki_community("unknown");
ROA_INVALID: add_rpki_community("invalid");
}
}
}
function route_is_rpki_invalid() {
return (unknown 0x4300, 0, 2) ~ bgp_ext_community;
}
function honor_graceful_shutdown() {
if (65535, 0) ~ bgp_community then {
bgp_local_pref = 0;
}
}
# https://tools.ietf.org/html/rfc7454#section-11
function scrub_communities_in() {
bgp_large_community.delete((OUR_AS, 101, 1)); # Learned from peer
bgp_large_community.delete((OUR_AS, 101, 2)); # Learned from private peer
bgp_large_community.delete((OUR_AS, 101, 3)); # Learned from IXP
bgp_large_community.delete((OUR_AS, 101, 4)); # Learned from transit provider
bgp_large_community.delete((OUR_AS, 101, 5)); # Learned from customer
bgp_large_community.delete((OUR_AS, 102, REGION_ID)); # Learned in region
bgp_large_community.delete((OUR_AS, 103, SITE_ID)); # Learned in site
}
function strip_private_asns() {
bgp_path.delete([64512..65534]);
bgp_path.delete([4200000000..4294967294]);
}
# --- Filters (technically functions) ---
function default_import() {
if bgp_path.len > 32 then
reject "AS_PATH len [", bgp_path.len ,"] longer than 32 - REJECTING ", net;
if prefix_is_in_global_blacklist() then
reject "prefix is in global blacklist - REJECTING ", net;
if is_own_prefix() then
reject "prefix is our own - REJECTING ", net;
if is_own_internal_prefix() then {
if !prefix_is_in_global_whitelist() then
reject "prefix is our own and internal - REJECTING ", net;
}
if prefix_is_bogon() then
reject "prefix is bogon - REJECTING ", net;
if net.type = NET_IP4 then
if !is_prefix_length_valid(8, 24) then
reject "prefix len [", net.len, "] not in 8-24 - REJECTING ", net;
if net.type = NET_IP6 then
if !is_prefix_length_valid(12, 48) then
reject "prefix len [", net.len, "] not in 12-48 - REJECTING ", net;
perform_rpki_validation();
if route_is_rpki_invalid() then
reject "RPKI, route is INVALID - REJECTING ", net;
add_region_community();
add_site_community();
honor_graceful_shutdown();
accept;
}
function peer_import() {
scrub_communities_in();
add_peer_community();
default_import();
}
function peer_export() {
strip_private_asns();
add_global_prepends();
if is_own_prefix() then accept;
if route_is_rpki_invalid() then
reject "RPKI, route is INVALID - NOT ANNOUNCING ", net;
if is_own_internal_prefix() then {
if !prefix_is_in_global_whitelist() then
reject "prefix is our own and internal - NOT ANNOUNCING ", net;
}
if net.type = NET_IP4 then
if !is_prefix_length_valid(8, 24) then
reject "prefix len [", net.len, "] not in 8-24 - REJECTING ", net;
if net.type = NET_IP6 then
if !is_prefix_length_valid(12, 48) then
reject "prefix len [", net.len, "] not in 12-48 - REJECTING ", net;
if prefix_is_bogon() then
reject "prefix is bogon - NOT ANNOUNCING ", net;
if as_path_contains_invalid_asn() then
reject "AS_PATH [", bgp_path ,"] contains invalid ASN - REJECTING ", net;
if should_not_export_to_site() then
reject "NO_EXPORT community in place for site - NOT ANNOUNCING ", net;
if should_not_export_to_region() then
reject "NO_EXPORT community in place for region - NOT ANNOUNCING ", net;
if should_not_export_to_peers() then
reject "NO_EXPORT community in place for peers - NOT ANNOUNCING ", net;
if prefix_is_in_global_blacklist() then
reject "prefix is in global blacklist - REJECTING ", net;
if was_learned_from_customer() then accept;
reject;
}
function upstream_import() {
scrub_communities_in();
add_upstream_community();
default_import();
}
function upstream_export() {
strip_private_asns();
add_global_prepends();
if is_own_prefix() then accept;
if route_is_rpki_invalid() then
reject "RPKI, route is INVALID - NOT ANNOUNCING ", net;
if is_own_internal_prefix() then {
if !prefix_is_in_global_whitelist() then
reject "prefix is our own and internal - NOT ANNOUNCING ", net;
}
if net.type = NET_IP4 then
if !is_prefix_length_valid(8, 24) then
reject "prefix len [", net.len, "] not in 8-24 - REJECTING ", net;
if net.type = NET_IP6 then
if !is_prefix_length_valid(12, 48) then
reject "prefix len [", net.len, "] not in 12-48 - REJECTING ", net;
if prefix_is_bogon() then
reject "prefix is bogon - NOT ANNOUNCING ", net;
if as_path_contains_invalid_asn() then
reject "AS_PATH [", bgp_path ,"] contains invalid ASN - REJECTING ", net;
if should_not_export_to_site() then
reject "NO_EXPORT community in place for site - NOT ANNOUNCING ", net;
if should_not_export_to_region() then
reject "NO_EXPORT community in place for region - NOT ANNOUNCING ", net;
if should_not_export_to_upstreams() then
reject "NO_EXPORT community in place for upstreams - NOT ANNOUNCING ", net;
if prefix_is_in_global_blacklist() then
reject "prefix is in global blacklist - REJECTING ", net;
if was_learned_from_customer() then accept;
reject;
}
function customer_import() {
scrub_communities_in();
add_customer_community();
default_import();
}
function customer_export() {
strip_private_asns();
add_global_prepends();
if is_own_prefix() then accept;
if route_is_rpki_invalid() then
reject "RPKI, route is INVALID - NOT ANNOUNCING ", net;
if is_own_internal_prefix() then {
if !prefix_is_in_global_whitelist() then
reject "prefix is our own and internal - NOT ANNOUNCING ", net;
}
if net.type = NET_IP4 then
if !is_prefix_length_valid(8, 24) then
reject "prefix len [", net.len, "] not in 8-24 - REJECTING ", net;
if net.type = NET_IP6 then
if !is_prefix_length_valid(12, 48) then
reject "prefix len [", net.len, "] not in 12-48 - REJECTING ", net;
if prefix_is_bogon() then
reject "prefix is bogon - NOT ANNOUNCING ", net;
if as_path_contains_invalid_asn() then
reject "AS_PATH [", bgp_path ,"] contains invalid ASN - REJECTING ", net;
if should_not_export_to_site() then
reject "NO_EXPORT community in place for site - NOT ANNOUNCING ", net;
if should_not_export_to_region() then
reject "NO_EXPORT community in place for region - NOT ANNOUNCING ", net;
if should_not_export_to_customers() then
reject "NO_EXPORT community in place for customers - NOT ANNOUNCING ", net;
if prefix_is_in_global_blacklist() then
reject "prefix is in global blacklist - REJECTING ", net;
if was_learned_from_peer() then accept;
if was_learned_from_private_peer() then accept;
if was_learned_from_upstream() then accept;
if was_learned_from_customer() then accept;
reject;
}
function core_import() {
if prefix_is_bogon() then reject;
if prefix_is_in_global_blacklist() then
reject "prefix is in global blacklist - REJECTING ", net;
honor_graceful_shutdown();
accept;
}
function core_export() {
if prefix_is_bogon() then reject;
if prefix_is_in_global_blacklist() then
reject "prefix is in global blacklist - REJECTING ", net;
if is_own_prefix() then accept;
if is_own_internal_prefix() then accept;
if was_learned_from_peer() then accept;
if was_learned_from_private_peer() then accept;
if was_learned_from_upstream() then accept;
if was_learned_from_customer() then accept;
reject;
}
# --- Templates ---
template bgp peer4 {
hold time 90;
keepalive time 30;
graceful restart;
ipv4 {
next hop self;
import keep filtered;
import where peer_import();
export where peer_export();
};
}
template bgp peer6 {
hold time 90;
keepalive time 30;
graceful restart;
ipv6 {
next hop self;
import keep filtered;
import where peer_import();
export where peer_export();
};
}
template bgp customer4 {
hold time 90;
keepalive time 30;
graceful restart;
ipv4 {
next hop self;
import keep filtered;
import where customer_import();
export where customer_export();
};
}
template bgp customer6 {
hold time 90;
keepalive time 30;
graceful restart;
ipv6 {
next hop self;
import keep filtered;
import where customer_import();
export where customer_export();
};
}
template bgp core4 {
hold time 90;
keepalive time 30;
graceful restart;
ipv4 {
next hop self;
import keep filtered;
import where core_import();
export where core_export();
};
}
template bgp core6 {
hold time 90;
keepalive time 30;
graceful restart;
ipv6 {
next hop self;
import keep filtered;
import where core_import();
export where core_export();
};
}
template bgp upstream4 {
hold time 90;
keepalive time 30;
graceful restart;
ipv4 {
next hop self;
import keep filtered;
import where upstream_import();
export where upstream_export();
};
}
template bgp upstream6 {
hold time 90;
keepalive time 30;
graceful restart;
ipv6 {
next hop self;
import keep filtered;
import where upstream_import();
export where upstream_export();
};
}
template bgp lookingglass4 {
hold time 90;
keepalive time 30;
graceful restart;
ipv4 {
next hop self;
import keep filtered;
import filter { reject; };
export where customer_export();
};
}
template bgp lookingglass6 {
hold time 90;
keepalive time 30;
graceful restart;
ipv6 {
next hop self;
import keep filtered;
import filter { reject; };
export where customer_export();
};
}
template bgp telemetry4 {
hold time 90;
keepalive time 30;
graceful restart;
rr client;
ipv4 {
next hop self;
import filter { reject; };
export filter { accept; };
};
ipv6 {
next hop address 127.0.0.1;
import filter { reject; };
export filter { accept; };
};
}
include "/etc/bird/static.conf";
include "/etc/bird/peers.conf";
# vim: set ft=bird nofoldenable: