-
Notifications
You must be signed in to change notification settings - Fork 46
/
bird4.conf
2021 lines (1657 loc) · 57.2 KB
/
bird4.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
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
router id 192.0.2.2;
define rs_as = 999;
log "/var/log/bird.log" all;
log syslog all;
debug protocols { states, routes, filters, interfaces, events };
protocol device {};
table master sorted;
# ---------------------------------------------------------
# RPKI
roa table RPKI {
};
# RPKI ROAs used as route objects
define RPKI_ROAs_as_route_objects_AS10745 = [
192.136.136.0/24, 192.149.252.0/24, 199.43.0.0/24
];
define RPKI_ROAs_as_route_objects_AS3333 = [
193.0.24.0/24, 193.0.12.0/23, 193.0.18.0/23, 193.0.0.0/21,
193.0.22.0/23, 193.0.10.0/23, 193.0.20.0/23, 193.0.24.0/22{22,26}
];
# ---------------------------------------------------------
# COMMON
# This function returns True if 'net' is a bogon prefix
# or falls within a bogon prefix.
function prefix_is_bogon()
prefix set bogons;
{
bogons = [
# Default route
0.0.0.0/0,
# IANA - Local Identification
0.0.0.0/8{8,32},
# RFC 1918 - Private Use
10.0.0.0/8{8,32},
# IANA - Loopback
127.0.0.0/8{8,32},
# RFC 3927 - Link Local
169.254.0.0/16{16,32},
# RFC 1918 - Private Use
172.16.0.0/12{12,32},
# RFC 5737 - TEST-NET-1
192.0.2.0/24{24,32},
# RFC 1918 - Private Use
192.168.0.0/16{16,32},
# RFC 2544 - Network Interconnect Device Benchmark Testing
198.18.0.0/15{15,32},
# RFC 5737 - TEST-NET-2
198.51.100.0/24{24,32},
# RFC 5737 - TEST-NET-3
203.0.113.0/24{24,32},
# RFC 5771 - Multcast (formerly Class D)
224.0.0.0/3{3,32},
# RFC 6598 - Shared Address Space
100.64.0.0/10{10,32}
];
if net ~ bogons then return true;
return false;
}
# This function returns True if 'net' falls within a
# prefix contained in the global blacklist (for example,
# local networks)
function prefix_is_in_global_blacklist()
prefix set global_blacklist;
{
global_blacklist = [
# Local network
192.0.2.0/24{24,32}
];
if net ~ global_blacklist then return true;
return false;
}
# This function returns True if the length of 'net' prefix
# falls within the range 'min'-'max' (included).
function prefix_len_is_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;
}
# This function returns True if the AS_PATH contains one or
# more private/reserved ASN.
function as_path_contains_invalid_asn()
int set invalid_asns;
{
# http://www.iana.org/assignments/as-numbers/as-numbers.xhtml
invalid_asns = [
# 16-bit
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
# 32-bit
65536..65551, # Reserved for use in documentation and sample code. RFC5398
65552..131071, # Reserved.
4200000000..4294967294, # Reserved for Private Use. [RFC6996]
4294967295 # Reserved. RFC7300
];
return bgp_path ~ invalid_asns;
}
# This function returns True if the AS_PATH contains one or
# more transit-free ASNs in a position different from the first.
function as_path_contains_transit_free_asn()
int set transit_free_asns;
{
transit_free_asns = [
174, 209, 286, 701, 1239,
1299, 2828, 2914, 3257, 3320,
3356, 3549, 5511, 6453, 6461,
6762, 6830, 7018, 12956
];
if bgp_path.first ~ transit_free_asns then
return false;
return bgp_path ~ transit_free_asns;
}
# This function returns the RTT measured for the peer given in client_ip.
# If the RTT is not available it returns 0.
function get_peer_rtt(ip client_ip) {
case client_ip {
192.0.2.11 : return 604; # 604.0
192.0.2.22 : return 123; # 123.0
}
return 0;
}
# This function scrubs BGP communities used by the route server
# for signaling purpose toward its clients. (RFC7454, Section 11)
# It must be applied on routes entering the route server.
function scrub_communities_in() {
# origin_not_present_in_as_set
bgp_community.delete([(65530, 0)]);
bgp_large_community.delete([(999, 65530, 0)]);
# origin_present_in_as_set
bgp_community.delete([(65530, 1)]);
bgp_large_community.delete([(999, 65530, 1)]);
# prefix_validated_via_rpki_roas
bgp_community.delete([(65530, 2)]);
bgp_large_community.delete([(999, 65530, 2)]);
# route_validated_via_white_list
bgp_community.delete([(65530, 3)]);
bgp_large_community.delete([(999, 65530, 3)]);
# from_europe
bgp_community.delete([(65534, 1)]);
bgp_large_community.delete([(999, 65534, 1)]);
bgp_ext_community.delete([(rt, 65534, 1)]);
# from_usa
bgp_community.delete([(65534, 2)]);
bgp_large_community.delete([(999, 65534, 2)]);
bgp_ext_community.delete([(rt, 65534, 2)]);
}
# This function scrubs BGP communities used by clients to instruct
# the route server to perform some actions.
# It must be applied on routes leaving the route server.
function scrub_communities_out() {
# add_noadvertise_to_any
bgp_community.delete([(65508, 999)]);
bgp_large_community.delete([(999, 65508, 999)]);
bgp_ext_community.delete([(rt, 65508, 999)]);
# add_noadvertise_to_peer
bgp_community.delete([(65510, 1..64511)]);
bgp_large_community.delete([(999, 65510, 1..64511)]);
bgp_large_community.delete([(999, 65510, 131072..4199999999)]);
bgp_ext_community.delete([(rt, 65510, 1..64511)]);
bgp_ext_community.delete([(rt, 65510, 131072..4199999999)]);
# add_noexport_to_any
bgp_community.delete([(65507, 999)]);
bgp_large_community.delete([(999, 65507, 999)]);
bgp_ext_community.delete([(rt, 65507, 999)]);
# add_noexport_to_peer
bgp_community.delete([(65509, 1..64511)]);
bgp_large_community.delete([(999, 65509, 1..64511)]);
bgp_large_community.delete([(999, 65509, 131072..4199999999)]);
bgp_ext_community.delete([(rt, 65509, 1..64511)]);
bgp_ext_community.delete([(rt, 65509, 131072..4199999999)]);
# announce_to_peer
bgp_community.delete([(999, 1..64511)]);
bgp_large_community.delete([(999, 999, 1..64511)]);
bgp_large_community.delete([(999, 999, 131072..4199999999)]);
bgp_ext_community.delete([(rt, 999, 1..64511)]);
bgp_ext_community.delete([(rt, 999, 131072..4199999999)]);
# announce_to_peers_with_rtt_higher_than
bgp_community.delete([(64514, *)]);
bgp_large_community.delete([(999, 64514, *)]);
bgp_ext_community.delete([(rt, 64514, *)]);
# announce_to_peers_with_rtt_lower_than
bgp_community.delete([(64513, *)]);
bgp_large_community.delete([(999, 64513, *)]);
bgp_ext_community.delete([(rt, 64513, *)]);
# blackholing
bgp_community.delete([(65534, 0)]);
bgp_large_community.delete([(999, 666, 0)]);
# do_not_announce_to_any
bgp_community.delete([(0, 999)]);
bgp_large_community.delete([(999, 0, 999)]);
bgp_ext_community.delete([(rt, 0, 999)]);
# do_not_announce_to_peer
bgp_community.delete([(0, 1..64511)]);
bgp_large_community.delete([(999, 0, 1..64511)]);
bgp_large_community.delete([(999, 0, 131072..4199999999)]);
bgp_ext_community.delete([(rt, 0, 1..64511)]);
bgp_ext_community.delete([(rt, 0, 131072..4199999999)]);
# do_not_announce_to_peers_with_rtt_higher_than
bgp_community.delete([(64512, *)]);
bgp_large_community.delete([(999, 64512, *)]);
bgp_ext_community.delete([(rt, 64512, *)]);
# do_not_announce_to_peers_with_rtt_lower_than
bgp_community.delete([(64511, *)]);
bgp_large_community.delete([(999, 64511, *)]);
bgp_ext_community.delete([(rt, 64511, *)]);
# prepend_once_to_any
bgp_community.delete([(65501, 999)]);
bgp_large_community.delete([(999, 65501, 999)]);
bgp_ext_community.delete([(rt, 65501, 999)]);
# prepend_once_to_peer
bgp_community.delete([(65504, 1..64511)]);
bgp_large_community.delete([(999, 65504, 1..64511)]);
bgp_large_community.delete([(999, 65504, 131072..4199999999)]);
bgp_ext_community.delete([(rt, 65504, 1..64511)]);
bgp_ext_community.delete([(rt, 65504, 131072..4199999999)]);
# prepend_once_to_peers_with_rtt_higher_than
bgp_community.delete([(64518, *)]);
bgp_large_community.delete([(999, 64518, *)]);
bgp_ext_community.delete([(rt, 64518, *)]);
# prepend_once_to_peers_with_rtt_lower_than
bgp_community.delete([(64515, *)]);
bgp_large_community.delete([(999, 64515, *)]);
bgp_ext_community.delete([(rt, 64515, *)]);
# prepend_thrice_to_any
bgp_community.delete([(65503, 999)]);
bgp_large_community.delete([(999, 65503, 999)]);
bgp_ext_community.delete([(rt, 65503, 999)]);
# prepend_thrice_to_peer
bgp_community.delete([(65506, 1..64511)]);
bgp_large_community.delete([(999, 65506, 1..64511)]);
bgp_large_community.delete([(999, 65506, 131072..4199999999)]);
bgp_ext_community.delete([(rt, 65506, 1..64511)]);
bgp_ext_community.delete([(rt, 65506, 131072..4199999999)]);
# prepend_thrice_to_peers_with_rtt_higher_than
bgp_community.delete([(64520, *)]);
bgp_large_community.delete([(999, 64520, *)]);
bgp_ext_community.delete([(rt, 64520, *)]);
# prepend_thrice_to_peers_with_rtt_lower_than
bgp_community.delete([(64517, *)]);
bgp_large_community.delete([(999, 64517, *)]);
bgp_ext_community.delete([(rt, 64517, *)]);
# prepend_twice_to_any
bgp_community.delete([(65502, 999)]);
bgp_large_community.delete([(999, 65502, 999)]);
bgp_ext_community.delete([(rt, 65502, 999)]);
# prepend_twice_to_peer
bgp_community.delete([(65505, 1..64511)]);
bgp_large_community.delete([(999, 65505, 1..64511)]);
bgp_large_community.delete([(999, 65505, 131072..4199999999)]);
bgp_ext_community.delete([(rt, 65505, 1..64511)]);
bgp_ext_community.delete([(rt, 65505, 131072..4199999999)]);
# prepend_twice_to_peers_with_rtt_higher_than
bgp_community.delete([(64519, *)]);
bgp_large_community.delete([(999, 64519, *)]);
bgp_ext_community.delete([(rt, 64519, *)]);
# prepend_twice_to_peers_with_rtt_lower_than
bgp_community.delete([(64516, *)]);
bgp_large_community.delete([(999, 64516, *)]);
bgp_ext_community.delete([(rt, 64516, *)]);
}
# This function verifies if the route is tagged with one of
# the blackhole filtering communities.
function is_blackhole_filtering_request() {
if (65535, 666) ~ bgp_community then
return true;
if (65534, 0) ~ bgp_community then
return true;
if (999, 666, 0) ~ bgp_large_community then
return true;
return false;
}
# This function must be applied to outgoing routes.
# It applies the blackhole filtering policy to the current route.
function apply_blackhole_filtering_policy() {
# Configured policy: rewrite-next-hop
bgp_community.add((65535, 666));
bgp_next_hop = 192.0.2.66;
# NO_EXPORT
bgp_community.add((65535, 65281));
}
# This function verifies if the current route can be announced to
# the given client on the basis of the attached control BGP
# communities.
function route_can_be_announced_to(int peer_as; ip client_ip; string client_id)
int client_rtt;
{
# do_not_announce_to_peer
if peer_as <= 65535 then {
if (0, peer_as) ~ bgp_community then
return false;
}
if (999, 0, peer_as) ~ bgp_large_community then
return false;
if (rt, 0, peer_as) ~ bgp_ext_community then
return false;
# announce_to_peer
if peer_as <= 65535 then {
if (999, peer_as) ~ bgp_community then
return true;
}
if (999, 999, peer_as) ~ bgp_large_community then
return true;
if (rt, 999, peer_as) ~ bgp_ext_community then
return true;
client_rtt = get_peer_rtt(client_ip);
if client_rtt > 0 then {
# do_not_announce_to_peers_with_rtt_higher_than
# 5 ms
if (64512, 5) ~ bgp_community then
{ if client_rtt > 5 then
return false; }
if (999, 64512, 5) ~ bgp_large_community then
{ if client_rtt > 5 then
return false; }
if (rt, 64512, 5) ~ bgp_ext_community then
{ if client_rtt > 5 then
return false; }
# 10 ms
if (64512, 10) ~ bgp_community then
{ if client_rtt > 10 then
return false; }
if (999, 64512, 10) ~ bgp_large_community then
{ if client_rtt > 10 then
return false; }
if (rt, 64512, 10) ~ bgp_ext_community then
{ if client_rtt > 10 then
return false; }
# 15 ms
if (64512, 15) ~ bgp_community then
{ if client_rtt > 15 then
return false; }
if (999, 64512, 15) ~ bgp_large_community then
{ if client_rtt > 15 then
return false; }
if (rt, 64512, 15) ~ bgp_ext_community then
{ if client_rtt > 15 then
return false; }
# 20 ms
if (64512, 20) ~ bgp_community then
{ if client_rtt > 20 then
return false; }
if (999, 64512, 20) ~ bgp_large_community then
{ if client_rtt > 20 then
return false; }
if (rt, 64512, 20) ~ bgp_ext_community then
{ if client_rtt > 20 then
return false; }
# 30 ms
if (64512, 30) ~ bgp_community then
{ if client_rtt > 30 then
return false; }
if (999, 64512, 30) ~ bgp_large_community then
{ if client_rtt > 30 then
return false; }
if (rt, 64512, 30) ~ bgp_ext_community then
{ if client_rtt > 30 then
return false; }
# 50 ms
if (64512, 50) ~ bgp_community then
{ if client_rtt > 50 then
return false; }
if (999, 64512, 50) ~ bgp_large_community then
{ if client_rtt > 50 then
return false; }
if (rt, 64512, 50) ~ bgp_ext_community then
{ if client_rtt > 50 then
return false; }
# 100 ms
if (64512, 100) ~ bgp_community then
{ if client_rtt > 100 then
return false; }
if (999, 64512, 100) ~ bgp_large_community then
{ if client_rtt > 100 then
return false; }
if (rt, 64512, 100) ~ bgp_ext_community then
{ if client_rtt > 100 then
return false; }
# 200 ms
if (64512, 200) ~ bgp_community then
{ if client_rtt > 200 then
return false; }
if (999, 64512, 200) ~ bgp_large_community then
{ if client_rtt > 200 then
return false; }
if (rt, 64512, 200) ~ bgp_ext_community then
{ if client_rtt > 200 then
return false; }
# 500 ms
if (64512, 500) ~ bgp_community then
{ if client_rtt > 500 then
return false; }
if (999, 64512, 500) ~ bgp_large_community then
{ if client_rtt > 500 then
return false; }
if (rt, 64512, 500) ~ bgp_ext_community then
{ if client_rtt > 500 then
return false; }
# do_not_announce_to_peers_with_rtt_lower_than
# 5 ms
if (64511, 5) ~ bgp_community then
{ if client_rtt <= 5 then
return false; }
if (999, 64511, 5) ~ bgp_large_community then
{ if client_rtt <= 5 then
return false; }
if (rt, 64511, 5) ~ bgp_ext_community then
{ if client_rtt <= 5 then
return false; }
# 10 ms
if (64511, 10) ~ bgp_community then
{ if client_rtt <= 10 then
return false; }
if (999, 64511, 10) ~ bgp_large_community then
{ if client_rtt <= 10 then
return false; }
if (rt, 64511, 10) ~ bgp_ext_community then
{ if client_rtt <= 10 then
return false; }
# 15 ms
if (64511, 15) ~ bgp_community then
{ if client_rtt <= 15 then
return false; }
if (999, 64511, 15) ~ bgp_large_community then
{ if client_rtt <= 15 then
return false; }
if (rt, 64511, 15) ~ bgp_ext_community then
{ if client_rtt <= 15 then
return false; }
# 20 ms
if (64511, 20) ~ bgp_community then
{ if client_rtt <= 20 then
return false; }
if (999, 64511, 20) ~ bgp_large_community then
{ if client_rtt <= 20 then
return false; }
if (rt, 64511, 20) ~ bgp_ext_community then
{ if client_rtt <= 20 then
return false; }
# 30 ms
if (64511, 30) ~ bgp_community then
{ if client_rtt <= 30 then
return false; }
if (999, 64511, 30) ~ bgp_large_community then
{ if client_rtt <= 30 then
return false; }
if (rt, 64511, 30) ~ bgp_ext_community then
{ if client_rtt <= 30 then
return false; }
# 50 ms
if (64511, 50) ~ bgp_community then
{ if client_rtt <= 50 then
return false; }
if (999, 64511, 50) ~ bgp_large_community then
{ if client_rtt <= 50 then
return false; }
if (rt, 64511, 50) ~ bgp_ext_community then
{ if client_rtt <= 50 then
return false; }
# 100 ms
if (64511, 100) ~ bgp_community then
{ if client_rtt <= 100 then
return false; }
if (999, 64511, 100) ~ bgp_large_community then
{ if client_rtt <= 100 then
return false; }
if (rt, 64511, 100) ~ bgp_ext_community then
{ if client_rtt <= 100 then
return false; }
# 200 ms
if (64511, 200) ~ bgp_community then
{ if client_rtt <= 200 then
return false; }
if (999, 64511, 200) ~ bgp_large_community then
{ if client_rtt <= 200 then
return false; }
if (rt, 64511, 200) ~ bgp_ext_community then
{ if client_rtt <= 200 then
return false; }
# 500 ms
if (64511, 500) ~ bgp_community then
{ if client_rtt <= 500 then
return false; }
if (999, 64511, 500) ~ bgp_large_community then
{ if client_rtt <= 500 then
return false; }
if (rt, 64511, 500) ~ bgp_ext_community then
{ if client_rtt <= 500 then
return false; }
# announce_to_peers_with_rtt_higher_than
# 5 ms
if (64514, 5) ~ bgp_community then
{ if client_rtt > 5 then
return true; }
if (999, 64514, 5) ~ bgp_large_community then
{ if client_rtt > 5 then
return true; }
if (rt, 64514, 5) ~ bgp_ext_community then
{ if client_rtt > 5 then
return true; }
# 10 ms
if (64514, 10) ~ bgp_community then
{ if client_rtt > 10 then
return true; }
if (999, 64514, 10) ~ bgp_large_community then
{ if client_rtt > 10 then
return true; }
if (rt, 64514, 10) ~ bgp_ext_community then
{ if client_rtt > 10 then
return true; }
# 15 ms
if (64514, 15) ~ bgp_community then
{ if client_rtt > 15 then
return true; }
if (999, 64514, 15) ~ bgp_large_community then
{ if client_rtt > 15 then
return true; }
if (rt, 64514, 15) ~ bgp_ext_community then
{ if client_rtt > 15 then
return true; }
# 20 ms
if (64514, 20) ~ bgp_community then
{ if client_rtt > 20 then
return true; }
if (999, 64514, 20) ~ bgp_large_community then
{ if client_rtt > 20 then
return true; }
if (rt, 64514, 20) ~ bgp_ext_community then
{ if client_rtt > 20 then
return true; }
# 30 ms
if (64514, 30) ~ bgp_community then
{ if client_rtt > 30 then
return true; }
if (999, 64514, 30) ~ bgp_large_community then
{ if client_rtt > 30 then
return true; }
if (rt, 64514, 30) ~ bgp_ext_community then
{ if client_rtt > 30 then
return true; }
# 50 ms
if (64514, 50) ~ bgp_community then
{ if client_rtt > 50 then
return true; }
if (999, 64514, 50) ~ bgp_large_community then
{ if client_rtt > 50 then
return true; }
if (rt, 64514, 50) ~ bgp_ext_community then
{ if client_rtt > 50 then
return true; }
# 100 ms
if (64514, 100) ~ bgp_community then
{ if client_rtt > 100 then
return true; }
if (999, 64514, 100) ~ bgp_large_community then
{ if client_rtt > 100 then
return true; }
if (rt, 64514, 100) ~ bgp_ext_community then
{ if client_rtt > 100 then
return true; }
# 200 ms
if (64514, 200) ~ bgp_community then
{ if client_rtt > 200 then
return true; }
if (999, 64514, 200) ~ bgp_large_community then
{ if client_rtt > 200 then
return true; }
if (rt, 64514, 200) ~ bgp_ext_community then
{ if client_rtt > 200 then
return true; }
# 500 ms
if (64514, 500) ~ bgp_community then
{ if client_rtt > 500 then
return true; }
if (999, 64514, 500) ~ bgp_large_community then
{ if client_rtt > 500 then
return true; }
if (rt, 64514, 500) ~ bgp_ext_community then
{ if client_rtt > 500 then
return true; }
# announce_to_peers_with_rtt_lower_than
# 5 ms
if (64513, 5) ~ bgp_community then
{ if client_rtt <= 5 then
return true; }
if (999, 64513, 5) ~ bgp_large_community then
{ if client_rtt <= 5 then
return true; }
if (rt, 64513, 5) ~ bgp_ext_community then
{ if client_rtt <= 5 then
return true; }
# 10 ms
if (64513, 10) ~ bgp_community then
{ if client_rtt <= 10 then
return true; }
if (999, 64513, 10) ~ bgp_large_community then
{ if client_rtt <= 10 then
return true; }
if (rt, 64513, 10) ~ bgp_ext_community then
{ if client_rtt <= 10 then
return true; }
# 15 ms
if (64513, 15) ~ bgp_community then
{ if client_rtt <= 15 then
return true; }
if (999, 64513, 15) ~ bgp_large_community then
{ if client_rtt <= 15 then
return true; }
if (rt, 64513, 15) ~ bgp_ext_community then
{ if client_rtt <= 15 then
return true; }
# 20 ms
if (64513, 20) ~ bgp_community then
{ if client_rtt <= 20 then
return true; }
if (999, 64513, 20) ~ bgp_large_community then
{ if client_rtt <= 20 then
return true; }
if (rt, 64513, 20) ~ bgp_ext_community then
{ if client_rtt <= 20 then
return true; }
# 30 ms
if (64513, 30) ~ bgp_community then
{ if client_rtt <= 30 then
return true; }
if (999, 64513, 30) ~ bgp_large_community then
{ if client_rtt <= 30 then
return true; }
if (rt, 64513, 30) ~ bgp_ext_community then
{ if client_rtt <= 30 then
return true; }
# 50 ms
if (64513, 50) ~ bgp_community then
{ if client_rtt <= 50 then
return true; }
if (999, 64513, 50) ~ bgp_large_community then
{ if client_rtt <= 50 then
return true; }
if (rt, 64513, 50) ~ bgp_ext_community then
{ if client_rtt <= 50 then
return true; }
# 100 ms
if (64513, 100) ~ bgp_community then
{ if client_rtt <= 100 then
return true; }
if (999, 64513, 100) ~ bgp_large_community then
{ if client_rtt <= 100 then
return true; }
if (rt, 64513, 100) ~ bgp_ext_community then
{ if client_rtt <= 100 then
return true; }
# 200 ms
if (64513, 200) ~ bgp_community then
{ if client_rtt <= 200 then
return true; }
if (999, 64513, 200) ~ bgp_large_community then
{ if client_rtt <= 200 then
return true; }
if (rt, 64513, 200) ~ bgp_ext_community then
{ if client_rtt <= 200 then
return true; }
# 500 ms
if (64513, 500) ~ bgp_community then
{ if client_rtt <= 500 then
return true; }
if (999, 64513, 500) ~ bgp_large_community then
{ if client_rtt <= 500 then
return true; }
if (rt, 64513, 500) ~ bgp_ext_community then
{ if client_rtt <= 500 then
return true; }
}
# do_not_announce_to_any
if (0, 999) ~ bgp_community then
return false;
if (999, 0, 999) ~ bgp_large_community then
return false;
if (rt, 0, 999) ~ bgp_ext_community then
return false;
return true;
}
# This function prepends the left-most ASN <times> times.
function do_prepend(int times) {
case times {
1: bgp_path.prepend(bgp_path.first);
2: bgp_path.prepend(bgp_path.first); bgp_path.prepend(bgp_path.first);
3: bgp_path.prepend(bgp_path.first); bgp_path.prepend(bgp_path.first); bgp_path.prepend(bgp_path.first);
}
}
# This function verifies if the current route matches one of the
# control communities in charge of prepending client's ASN.
function apply_prepend(int peer_as; ip client_ip)
int client_rtt;
{
# prepend_once_to_peer
if peer_as <= 65535 then {
if (65504, peer_as) ~ bgp_community then
{ do_prepend(1); return true; }
}
if (999, 65504, peer_as) ~ bgp_large_community then
{ do_prepend(1); return true; }
if (rt, 65504, peer_as) ~ bgp_ext_community then
{ do_prepend(1); return true; }
# prepend_twice_to_peer
if peer_as <= 65535 then {
if (65505, peer_as) ~ bgp_community then
{ do_prepend(2); return true; }
}
if (999, 65505, peer_as) ~ bgp_large_community then
{ do_prepend(2); return true; }
if (rt, 65505, peer_as) ~ bgp_ext_community then
{ do_prepend(2); return true; }
# prepend_thrice_to_peer
if peer_as <= 65535 then {
if (65506, peer_as) ~ bgp_community then
{ do_prepend(3); return true; }
}
if (999, 65506, peer_as) ~ bgp_large_community then
{ do_prepend(3); return true; }
if (rt, 65506, peer_as) ~ bgp_ext_community then
{ do_prepend(3); return true; }
client_rtt = get_peer_rtt(client_ip);
if client_rtt > 0 then {
# prepend_once_to_peers_with_rtt_higher_than 500 ms
if (64518, 500) ~ bgp_community then
{ if client_rtt > 500 then
{ do_prepend(1); return true; } }
if (999, 64518, 500) ~ bgp_large_community then
{ if client_rtt > 500 then
{ do_prepend(1); return true; } }
if (rt, 64518, 500) ~ bgp_ext_community then
{ if client_rtt > 500 then
{ do_prepend(1); return true; } }
# prepend_twice_to_peers_with_rtt_higher_than 500 ms
if (64519, 500) ~ bgp_community then
{ if client_rtt > 500 then
{ do_prepend(2); return true; } }
if (999, 64519, 500) ~ bgp_large_community then
{ if client_rtt > 500 then
{ do_prepend(2); return true; } }
if (rt, 64519, 500) ~ bgp_ext_community then
{ if client_rtt > 500 then
{ do_prepend(2); return true; } }
# prepend_thrice_to_peers_with_rtt_higher_than 500 ms
if (64520, 500) ~ bgp_community then
{ if client_rtt > 500 then
{ do_prepend(3); return true; } }
if (999, 64520, 500) ~ bgp_large_community then
{ if client_rtt > 500 then
{ do_prepend(3); return true; } }
if (rt, 64520, 500) ~ bgp_ext_community then
{ if client_rtt > 500 then
{ do_prepend(3); return true; } }
# prepend_once_to_peers_with_rtt_higher_than 200 ms
if (64518, 200) ~ bgp_community then
{ if client_rtt > 200 then
{ do_prepend(1); return true; } }
if (999, 64518, 200) ~ bgp_large_community then
{ if client_rtt > 200 then
{ do_prepend(1); return true; } }
if (rt, 64518, 200) ~ bgp_ext_community then
{ if client_rtt > 200 then
{ do_prepend(1); return true; } }
# prepend_twice_to_peers_with_rtt_higher_than 200 ms
if (64519, 200) ~ bgp_community then
{ if client_rtt > 200 then
{ do_prepend(2); return true; } }
if (999, 64519, 200) ~ bgp_large_community then
{ if client_rtt > 200 then
{ do_prepend(2); return true; } }
if (rt, 64519, 200) ~ bgp_ext_community then
{ if client_rtt > 200 then
{ do_prepend(2); return true; } }
# prepend_thrice_to_peers_with_rtt_higher_than 200 ms
if (64520, 200) ~ bgp_community then
{ if client_rtt > 200 then
{ do_prepend(3); return true; } }
if (999, 64520, 200) ~ bgp_large_community then
{ if client_rtt > 200 then
{ do_prepend(3); return true; } }
if (rt, 64520, 200) ~ bgp_ext_community then
{ if client_rtt > 200 then
{ do_prepend(3); return true; } }
# prepend_once_to_peers_with_rtt_higher_than 100 ms
if (64518, 100) ~ bgp_community then
{ if client_rtt > 100 then
{ do_prepend(1); return true; } }
if (999, 64518, 100) ~ bgp_large_community then
{ if client_rtt > 100 then
{ do_prepend(1); return true; } }
if (rt, 64518, 100) ~ bgp_ext_community then
{ if client_rtt > 100 then
{ do_prepend(1); return true; } }
# prepend_twice_to_peers_with_rtt_higher_than 100 ms
if (64519, 100) ~ bgp_community then
{ if client_rtt > 100 then
{ do_prepend(2); return true; } }
if (999, 64519, 100) ~ bgp_large_community then
{ if client_rtt > 100 then
{ do_prepend(2); return true; } }
if (rt, 64519, 100) ~ bgp_ext_community then
{ if client_rtt > 100 then
{ do_prepend(2); return true; } }
# prepend_thrice_to_peers_with_rtt_higher_than 100 ms
if (64520, 100) ~ bgp_community then
{ if client_rtt > 100 then
{ do_prepend(3); return true; } }
if (999, 64520, 100) ~ bgp_large_community then
{ if client_rtt > 100 then
{ do_prepend(3); return true; } }
if (rt, 64520, 100) ~ bgp_ext_community then
{ if client_rtt > 100 then
{ do_prepend(3); return true; } }
# prepend_once_to_peers_with_rtt_higher_than 50 ms
if (64518, 50) ~ bgp_community then
{ if client_rtt > 50 then
{ do_prepend(1); return true; } }
if (999, 64518, 50) ~ bgp_large_community then
{ if client_rtt > 50 then
{ do_prepend(1); return true; } }
if (rt, 64518, 50) ~ bgp_ext_community then
{ if client_rtt > 50 then
{ do_prepend(1); return true; } }
# prepend_twice_to_peers_with_rtt_higher_than 50 ms
if (64519, 50) ~ bgp_community then
{ if client_rtt > 50 then
{ do_prepend(2); return true; } }
if (999, 64519, 50) ~ bgp_large_community then
{ if client_rtt > 50 then
{ do_prepend(2); return true; } }
if (rt, 64519, 50) ~ bgp_ext_community then
{ if client_rtt > 50 then
{ do_prepend(2); return true; } }
# prepend_thrice_to_peers_with_rtt_higher_than 50 ms
if (64520, 50) ~ bgp_community then
{ if client_rtt > 50 then
{ do_prepend(3); return true; } }
if (999, 64520, 50) ~ bgp_large_community then
{ if client_rtt > 50 then
{ do_prepend(3); return true; } }
if (rt, 64520, 50) ~ bgp_ext_community then
{ if client_rtt > 50 then
{ do_prepend(3); return true; } }
# prepend_once_to_peers_with_rtt_higher_than 30 ms
if (64518, 30) ~ bgp_community then
{ if client_rtt > 30 then
{ do_prepend(1); return true; } }
if (999, 64518, 30) ~ bgp_large_community then
{ if client_rtt > 30 then
{ do_prepend(1); return true; } }
if (rt, 64518, 30) ~ bgp_ext_community then
{ if client_rtt > 30 then
{ do_prepend(1); return true; } }
# prepend_twice_to_peers_with_rtt_higher_than 30 ms
if (64519, 30) ~ bgp_community then
{ if client_rtt > 30 then
{ do_prepend(2); return true; } }
if (999, 64519, 30) ~ bgp_large_community then
{ if client_rtt > 30 then
{ do_prepend(2); return true; } }
if (rt, 64519, 30) ~ bgp_ext_community then