/
bgpd.h
2370 lines (1985 loc) · 81.4 KB
/
bgpd.h
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
/* BGP message definition header.
* Copyright (C) 1996, 97, 98, 99, 2000 Kunihiro Ishiguro
*
* This file is part of GNU Zebra.
*
* GNU Zebra is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* GNU Zebra is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; see the file COPYING; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _QUAGGA_BGPD_H
#define _QUAGGA_BGPD_H
#include "qobj.h"
#include <pthread.h>
#include "hook.h"
#include "frr_pthread.h"
#include "lib/json.h"
#include "vrf.h"
#include "vty.h"
#include "iana_afi.h"
/* For union sockunion. */
#include "queue.h"
#include "sockunion.h"
#include "routemap.h"
#include "linklist.h"
#include "defaults.h"
#include "bgp_memory.h"
#include "bitfield.h"
#include "vxlan.h"
#include "bgp_labelpool.h"
#include "bgp_addpath_types.h"
#include "bgp_nexthop.h"
#include "bgp_damp.h"
#define BGP_MAX_HOSTNAME 64 /* Linux max, is larger than most other sys */
#define BGP_PEER_MAX_HASH_SIZE 16384
/* Default interval for IPv6 RAs when triggered by BGP unnumbered neighbor. */
#define BGP_UNNUM_DEFAULT_RA_INTERVAL 10
struct update_subgroup;
struct bpacket;
struct bgp_pbr_config;
/*
* Allow the neighbor XXXX remote-as to take internal or external
* AS_SPECIFIED is zero to auto-inherit original non-feature/enhancement
* behavior
* in the system.
*/
enum { AS_UNSPECIFIED = 0,
AS_SPECIFIED,
AS_INTERNAL,
AS_EXTERNAL,
};
/* Zebra Gracaful Restart states */
enum zebra_gr_mode {
ZEBRA_GR_DISABLE = 0,
ZEBRA_GR_ENABLE
};
/* Typedef BGP specific types. */
typedef uint32_t as_t;
typedef uint16_t as16_t; /* we may still encounter 16 Bit asnums */
typedef uint16_t bgp_size_t;
#define max(a, b) \
({ \
__typeof__(a) _a = (a); \
__typeof__(b) _b = (b); \
_a > _b ? _a : _b; \
})
enum bgp_af_index {
BGP_AF_START,
BGP_AF_IPV4_UNICAST = BGP_AF_START,
BGP_AF_IPV4_MULTICAST,
BGP_AF_IPV4_VPN,
BGP_AF_IPV6_UNICAST,
BGP_AF_IPV6_MULTICAST,
BGP_AF_IPV6_VPN,
BGP_AF_IPV4_ENCAP,
BGP_AF_IPV6_ENCAP,
BGP_AF_L2VPN_EVPN,
BGP_AF_IPV4_LBL_UNICAST,
BGP_AF_IPV6_LBL_UNICAST,
BGP_AF_IPV4_FLOWSPEC,
BGP_AF_IPV6_FLOWSPEC,
BGP_AF_MAX
};
#define AF_FOREACH(af) for ((af) = BGP_AF_START; (af) < BGP_AF_MAX; (af)++)
#define FOREACH_SAFI(safi) \
for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
extern struct frr_pthread *bgp_pth_io;
extern struct frr_pthread *bgp_pth_ka;
/* BGP master for system wide configurations and variables. */
struct bgp_master {
/* BGP instance list. */
struct list *bgp;
/* BGP thread master. */
struct thread_master *master;
/* Listening sockets */
struct list *listen_sockets;
/* BGP port number. */
uint16_t port;
/* Listener addresses */
struct list *addresses;
/* The Mac table */
struct hash *self_mac_hash;
/* BGP start time. */
time_t start_time;
/* Various BGP global configuration. */
uint8_t options;
#define BGP_OPT_NO_FIB (1 << 0)
#define BGP_OPT_NO_LISTEN (1 << 1)
#define BGP_OPT_NO_ZEBRA (1 << 2)
uint64_t updgrp_idspace;
uint64_t subgrp_idspace;
/* timer to dampen route map changes */
struct thread *t_rmap_update; /* Handle route map updates */
uint32_t rmap_update_timer; /* Route map update timer */
#define RMAP_DEFAULT_UPDATE_TIMER 5 /* disabled by default */
/* Id space for automatic RD derivation for an EVI/VRF */
bitfield_t rd_idspace;
/* dynamic mpls label allocation pool */
struct labelpool labelpool;
/* BGP-EVPN VRF ID. Defaults to default VRF (if any) */
struct bgp* bgp_evpn;
/* How big should we set the socket buffer size */
uint32_t socket_buffer;
/* Should we do wait for fib install globally? */
bool wait_for_fib;
/* EVPN multihoming */
struct bgp_evpn_mh_info *mh_info;
/* global update-delay timer values */
uint16_t v_update_delay;
uint16_t v_establish_wait;
uint32_t flags;
#define BM_FLAG_GRACEFUL_SHUTDOWN (1 << 0)
#define BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA (1 << 1)
bool terminating; /* global flag that sigint terminate seen */
QOBJ_FIELDS
};
DECLARE_QOBJ_TYPE(bgp_master)
/* BGP route-map structure. */
struct bgp_rmap {
char *name;
struct route_map *map;
};
struct bgp_redist {
unsigned short instance;
/* BGP redistribute metric configuration. */
uint8_t redist_metric_flag;
uint32_t redist_metric;
/* BGP redistribute route-map. */
struct bgp_rmap rmap;
};
typedef enum {
BGP_VPN_POLICY_DIR_FROMVPN = 0,
BGP_VPN_POLICY_DIR_TOVPN = 1,
BGP_VPN_POLICY_DIR_MAX = 2
} vpn_policy_direction_t;
struct vpn_policy {
struct bgp *bgp; /* parent */
afi_t afi;
struct ecommunity *rtlist[BGP_VPN_POLICY_DIR_MAX];
struct ecommunity *import_redirect_rtlist;
char *rmap_name[BGP_VPN_POLICY_DIR_MAX];
struct route_map *rmap[BGP_VPN_POLICY_DIR_MAX];
/* should be mpls_label_t? */
uint32_t tovpn_label; /* may be MPLS_LABEL_NONE */
uint32_t tovpn_zebra_vrf_label_last_sent;
struct prefix_rd tovpn_rd;
struct prefix tovpn_nexthop; /* unset => set to 0 */
uint32_t flags;
#define BGP_VPN_POLICY_TOVPN_LABEL_AUTO (1 << 0)
#define BGP_VPN_POLICY_TOVPN_RD_SET (1 << 1)
#define BGP_VPN_POLICY_TOVPN_NEXTHOP_SET (1 << 2)
/*
* If we are importing another vrf into us keep a list of
* vrf names that are being imported into us.
*/
struct list *import_vrf;
/*
* if we are being exported to another vrf keep a list of
* vrf names that we are being exported to.
*/
struct list *export_vrf;
};
/*
* Type of 'struct bgp'.
* - Default: The default instance
* - VRF: A specific (non-default) VRF
* - View: An instance used for route exchange
* The "default" instance is treated separately to simplify the code. Note
* that if deployed in a Multi-VRF environment, it may not exist.
*/
enum bgp_instance_type {
BGP_INSTANCE_TYPE_DEFAULT,
BGP_INSTANCE_TYPE_VRF,
BGP_INSTANCE_TYPE_VIEW
};
#define BGP_SEND_EOR(bgp, afi, safi) \
(!CHECK_FLAG(bgp->flags, BGP_FLAG_GR_DISABLE_EOR) \
&& ((bgp->gr_info[afi][safi].t_select_deferral == NULL) \
|| (bgp->gr_info[afi][safi].eor_required \
== bgp->gr_info[afi][safi].eor_received)))
/* BGP GR Global ds */
#define BGP_GLOBAL_GR_MODE 4
#define BGP_GLOBAL_GR_EVENT_CMD 4
/* Graceful restart selection deferral timer info */
struct graceful_restart_info {
/* Count of EOR message expected */
uint32_t eor_required;
/* Count of EOR received */
uint32_t eor_received;
/* Deferral Timer */
struct thread *t_select_deferral;
/* Routes Deferred */
uint32_t gr_deferred;
/* Best route select */
struct thread *t_route_select;
/* AFI, SAFI enabled */
bool af_enabled[AFI_MAX][SAFI_MAX];
/* Route update completed */
bool route_sync[AFI_MAX][SAFI_MAX];
};
enum global_mode {
GLOBAL_HELPER = 0, /* This is the default mode */
GLOBAL_GR,
GLOBAL_DISABLE,
GLOBAL_INVALID
};
enum global_gr_command {
GLOBAL_GR_CMD = 0,
NO_GLOBAL_GR_CMD,
GLOBAL_DISABLE_CMD,
NO_GLOBAL_DISABLE_CMD
};
#define BGP_GR_SUCCESS 0
#define BGP_GR_FAILURE 1
/* Handling of BGP link bandwidth (LB) on receiver - whether and how to
* do weighted ECMP. Note: This applies after multipath computation.
*/
enum bgp_link_bw_handling {
/* Do ECMP if some paths don't have LB - default */
BGP_LINK_BW_ECMP,
/* Completely ignore LB, just do regular ECMP */
BGP_LINK_BW_IGNORE_BW,
/* Skip paths without LB, do wECMP on others */
BGP_LINK_BW_SKIP_MISSING,
/* Do wECMP with default weight for paths not having LB */
BGP_LINK_BW_DEFWT_4_MISSING
};
RB_HEAD(bgp_es_vrf_rb_head, bgp_evpn_es_vrf);
RB_PROTOTYPE(bgp_es_vrf_rb_head, bgp_evpn_es_vrf, rb_node, bgp_es_vrf_rb_cmp);
struct bgp_snmp_stats {
/* SNMP variables for mplsL3Vpn*/
time_t creation_time;
time_t modify_time;
bool active;
uint32_t routes_added;
uint32_t routes_deleted;
};
/* BGP instance structure. */
struct bgp {
/* AS number of this BGP instance. */
as_t as;
/* Name of this BGP instance. */
char *name;
char *name_pretty; /* printable "VRF|VIEW name|default" */
/* Type of instance and VRF id. */
enum bgp_instance_type inst_type;
vrf_id_t vrf_id;
/* Reference count to allow peer_delete to finish after bgp_delete */
int lock;
/* Self peer. */
struct peer *peer_self;
/* BGP peer. */
struct list *peer;
struct hash *peerhash;
/* BGP peer group. */
struct list *group;
/* The maximum number of BGP dynamic neighbors that can be created */
int dynamic_neighbors_limit;
/* The current number of BGP dynamic neighbors */
int dynamic_neighbors_count;
struct hash *update_groups[BGP_AF_MAX];
/*
* Global statistics for update groups.
*/
struct {
uint32_t join_events;
uint32_t prune_events;
uint32_t merge_events;
uint32_t split_events;
uint32_t updgrp_switch_events;
uint32_t peer_refreshes_combined;
uint32_t adj_count;
uint32_t merge_checks_triggered;
uint32_t updgrps_created;
uint32_t updgrps_deleted;
uint32_t subgrps_created;
uint32_t subgrps_deleted;
} update_group_stats;
struct bgp_snmp_stats *snmp_stats;
/* BGP configuration. */
uint16_t config;
#define BGP_CONFIG_CLUSTER_ID (1 << 0)
#define BGP_CONFIG_CONFEDERATION (1 << 1)
/* BGP router identifier. */
struct in_addr router_id;
struct in_addr router_id_static;
struct in_addr router_id_zebra;
/* BGP route reflector cluster ID. */
struct in_addr cluster_id;
/* BGP confederation information. */
as_t confed_id;
as_t *confed_peers;
int confed_peers_cnt;
struct thread
*t_startup; /* start-up timer on only once at the beginning */
uint32_t v_maxmed_onstartup; /* Duration of max-med on start-up */
#define BGP_MAXMED_ONSTARTUP_UNCONFIGURED 0 /* 0 means off, its the default */
uint32_t maxmed_onstartup_value; /* Max-med value when active on
start-up */
struct thread
*t_maxmed_onstartup; /* non-null when max-med onstartup is on */
uint8_t maxmed_onstartup_over; /* Flag to make it effective only once */
bool v_maxmed_admin; /* true/false if max-med administrative is on/off
*/
#define BGP_MAXMED_ADMIN_UNCONFIGURED false /* Off by default */
uint32_t maxmed_admin_value; /* Max-med value when administrative in on
*/
#define BGP_MAXMED_VALUE_DEFAULT 4294967294 /* Maximum by default */
uint8_t maxmed_active; /* 1/0 if max-med is active or not */
uint32_t maxmed_value; /* Max-med value when its active */
/* BGP update delay on startup */
struct thread *t_update_delay;
struct thread *t_establish_wait;
uint8_t update_delay_over;
uint8_t main_zebra_update_hold;
uint8_t main_peers_update_hold;
uint16_t v_update_delay;
uint16_t v_establish_wait;
char update_delay_begin_time[64];
char update_delay_end_time[64];
char update_delay_zebra_resume_time[64];
char update_delay_peers_resume_time[64];
uint32_t established;
uint32_t restarted_peers;
uint32_t implicit_eors;
uint32_t explicit_eors;
#define BGP_UPDATE_DELAY_DEF 0
#define BGP_UPDATE_DELAY_MIN 0
#define BGP_UPDATE_DELAY_MAX 3600
/* Reference bandwidth for BGP link-bandwidth. Used when
* the LB value has to be computed based on some other
* factor (e.g., number of multipaths for the prefix)
* Value is in Mbps
*/
uint32_t lb_ref_bw;
#define BGP_LINK_BW_REF_BW 1
/* BGP flags. */
uint32_t flags;
#define BGP_FLAG_ALWAYS_COMPARE_MED (1 << 0)
#define BGP_FLAG_DETERMINISTIC_MED (1 << 1)
#define BGP_FLAG_MED_MISSING_AS_WORST (1 << 2)
#define BGP_FLAG_MED_CONFED (1 << 3)
#define BGP_FLAG_NO_DEFAULT_IPV4 (1 << 4)
#define BGP_FLAG_NO_CLIENT_TO_CLIENT (1 << 5)
#define BGP_FLAG_COMPARE_ROUTER_ID (1 << 7)
#define BGP_FLAG_ASPATH_IGNORE (1 << 8)
#define BGP_FLAG_IMPORT_CHECK (1 << 9)
#define BGP_FLAG_NO_FAST_EXT_FAILOVER (1 << 10)
#define BGP_FLAG_LOG_NEIGHBOR_CHANGES (1 << 11)
/* This flag is set when we have full BGP Graceful-Restart mode enable */
#define BGP_FLAG_GRACEFUL_RESTART (1 << 12)
#define BGP_FLAG_ASPATH_CONFED (1 << 13)
#define BGP_FLAG_ASPATH_MULTIPATH_RELAX (1 << 14)
#define BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY (1 << 15)
#define BGP_FLAG_DISABLE_NH_CONNECTED_CHK (1 << 16)
#define BGP_FLAG_MULTIPATH_RELAX_AS_SET (1 << 17)
#define BGP_FLAG_FORCE_STATIC_PROCESS (1 << 18)
#define BGP_FLAG_SHOW_HOSTNAME (1 << 19)
#define BGP_FLAG_GR_PRESERVE_FWD (1 << 20)
#define BGP_FLAG_GRACEFUL_SHUTDOWN (1 << 21)
#define BGP_FLAG_DELETE_IN_PROGRESS (1 << 22)
#define BGP_FLAG_SELECT_DEFER_DISABLE (1 << 23)
#define BGP_FLAG_GR_DISABLE_EOR (1 << 24)
#define BGP_FLAG_EBGP_REQUIRES_POLICY (1 << 25)
#define BGP_FLAG_SHOW_NEXTHOP_HOSTNAME (1 << 26)
/* This flag is set if the instance is in administrative shutdown */
#define BGP_FLAG_SHUTDOWN (1 << 27)
#define BGP_FLAG_SUPPRESS_FIB_PENDING (1 << 28)
#define BGP_FLAG_SUPPRESS_DUPLICATES (1 << 29)
enum global_mode GLOBAL_GR_FSM[BGP_GLOBAL_GR_MODE]
[BGP_GLOBAL_GR_EVENT_CMD];
enum global_mode global_gr_present_state;
/* This variable stores the current Graceful Restart state of Zebra
* - ZEBRA_GR_ENABLE / ZEBRA_GR_DISABLE
*/
enum zebra_gr_mode present_zebra_gr_state;
/* BGP Per AF flags */
uint16_t af_flags[AFI_MAX][SAFI_MAX];
#define BGP_CONFIG_DAMPENING (1 << 0)
/* l2vpn evpn flags - 1 << 0 is used for DAMPENNG */
#define BGP_L2VPN_EVPN_ADVERTISE_IPV4_UNICAST (1 << 1)
#define BGP_L2VPN_EVPN_ADVERTISE_IPV6_UNICAST (1 << 2)
#define BGP_L2VPN_EVPN_DEFAULT_ORIGINATE_IPV4 (1 << 3)
#define BGP_L2VPN_EVPN_DEFAULT_ORIGINATE_IPV6 (1 << 4)
/* import/export between address families */
#define BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT (1 << 5)
#define BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT (1 << 6)
/* vrf-route leaking flags */
#define BGP_CONFIG_VRF_TO_VRF_IMPORT (1 << 7)
#define BGP_CONFIG_VRF_TO_VRF_EXPORT (1 << 8)
/* BGP per AF peer count */
uint32_t af_peer_count[AFI_MAX][SAFI_MAX];
/* Tree for next-hop lookup cache. */
struct bgp_nexthop_cache_head nexthop_cache_table[AFI_MAX];
/* Tree for import-check */
struct bgp_nexthop_cache_head import_check_table[AFI_MAX];
struct bgp_table *connected_table[AFI_MAX];
struct hash *address_hash;
/* DB for all local tunnel-ips - used mainly for martian checks
Currently it only has all VxLan tunnel IPs*/
struct hash *tip_hash;
/* Static route configuration. */
struct bgp_table *route[AFI_MAX][SAFI_MAX];
/* Aggregate address configuration. */
struct bgp_table *aggregate[AFI_MAX][SAFI_MAX];
/* BGP routing information base. */
struct bgp_table *rib[AFI_MAX][SAFI_MAX];
/* BGP table route-map. */
struct bgp_rmap table_map[AFI_MAX][SAFI_MAX];
/* BGP redistribute configuration. */
struct list *redist[AFI_MAX][ZEBRA_ROUTE_MAX];
/* Allocate MPLS labels */
uint8_t allocate_mpls_labels[AFI_MAX][SAFI_MAX];
/* Allocate hash entries to store policy routing information
* The hash are used to host pbr rules somewhere.
* Actually, pbr will only be used by flowspec
* those hash elements will have relationship together as
* illustrated in below diagram:
*
* pbr_action a <----- pbr_match i <--- pbr_match_entry 1..n
* <----- pbr_match j <--- pbr_match_entry 1..m
* <----- pbr_rule k
*
* - here in BGP structure, the list of match and actions will
* stand for the list of ipset sets, and table_ids in the kernel
* - the arrow above between pbr_match and pbr_action indicate
* that a backpointer permits match to find the action
* - the arrow betwen match_entry and match is a hash list
* contained in match, that lists the whole set of entries
*/
struct hash *pbr_match_hash;
struct hash *pbr_rule_hash;
struct hash *pbr_action_hash;
/* timer to re-evaluate neighbor default-originate route-maps */
struct thread *t_rmap_def_originate_eval;
#define RMAP_DEFAULT_ORIGINATE_EVAL_TIMER 5
/* BGP distance configuration. */
uint8_t distance_ebgp[AFI_MAX][SAFI_MAX];
uint8_t distance_ibgp[AFI_MAX][SAFI_MAX];
uint8_t distance_local[AFI_MAX][SAFI_MAX];
/* BGP default local-preference. */
uint32_t default_local_pref;
/* BGP default subgroup pkt queue max */
uint32_t default_subgroup_pkt_queue_max;
/* BGP default timer. */
uint32_t default_holdtime;
uint32_t default_keepalive;
uint32_t default_connect_retry;
uint32_t default_delayopen;
/* BGP graceful restart */
uint32_t restart_time;
uint32_t stalepath_time;
uint32_t select_defer_time;
struct graceful_restart_info gr_info[AFI_MAX][SAFI_MAX];
uint32_t rib_stale_time;
#define BGP_ROUTE_SELECT_DELAY 1
#define BGP_MAX_BEST_ROUTE_SELECT 10000
/* Maximum-paths configuration */
struct bgp_maxpaths_cfg {
uint16_t maxpaths_ebgp;
uint16_t maxpaths_ibgp;
uint16_t ibgp_flags;
#define BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN (1 << 0)
} maxpaths[AFI_MAX][SAFI_MAX];
_Atomic uint32_t wpkt_quanta; // max # packets to write per i/o cycle
_Atomic uint32_t rpkt_quanta; // max # packets to read per i/o cycle
/* Automatic coalesce adjust on/off */
bool heuristic_coalesce;
/* Actual coalesce time */
uint32_t coalesce_time;
/* Auto-shutdown new peers */
bool autoshutdown;
struct bgp_addpath_bgp_data tx_addpath;
#ifdef ENABLE_BGP_VNC
struct rfapi_cfg *rfapi_cfg;
struct rfapi *rfapi;
#endif
/* EVPN related information */
/* EVI hash table */
struct hash *vnihash;
/* EVPN enable - advertise gateway macip routes */
int advertise_gw_macip;
/* EVPN enable - advertise local VNIs and their MACs etc. */
int advertise_all_vni;
/* draft-ietf-idr-deprecate-as-set-confed-set
* Reject aspaths with AS_SET and/or AS_CONFED_SET.
*/
bool reject_as_sets;
struct bgp_evpn_info *evpn_info;
/* EVPN - use RFC 8365 to auto-derive RT */
int advertise_autort_rfc8365;
/*
* Flooding mechanism for BUM packets for VxLAN-EVPN.
*/
enum vxlan_flood_control vxlan_flood_ctrl;
/* Hash table of Import RTs to EVIs */
struct hash *import_rt_hash;
/* Hash table of VRF import RTs to VRFs */
struct hash *vrf_import_rt_hash;
/* L3-VNI corresponding to this vrf */
vni_t l3vni;
/* router-mac to be used in mac-ip routes for this vrf */
struct ethaddr rmac;
/* originator ip - to be used as NH for type-5 routes */
struct in_addr originator_ip;
/* SVI associated with the L3-VNI corresponding to this vrf */
ifindex_t l3vni_svi_ifindex;
/* RB tree of ES-VRFs */
struct bgp_es_vrf_rb_head es_vrf_rb_tree;
/* vrf flags */
uint32_t vrf_flags;
#define BGP_VRF_AUTO (1 << 0)
#define BGP_VRF_IMPORT_RT_CFGD (1 << 1)
#define BGP_VRF_EXPORT_RT_CFGD (1 << 2)
#define BGP_VRF_RD_CFGD (1 << 3)
#define BGP_VRF_L3VNI_PREFIX_ROUTES_ONLY (1 << 4)
/* unique ID for auto derivation of RD for this vrf */
uint16_t vrf_rd_id;
/* Automatically derived RD for this VRF */
struct prefix_rd vrf_prd_auto;
/* RD for this VRF */
struct prefix_rd vrf_prd;
/* import rt list for the vrf instance */
struct list *vrf_import_rtl;
/* export rt list for the vrf instance */
struct list *vrf_export_rtl;
/* list of corresponding l2vnis (struct bgpevpn) */
struct list *l2vnis;
/* route map for advertise ipv4/ipv6 unicast (type-5 routes) */
struct bgp_rmap adv_cmd_rmap[AFI_MAX][SAFI_MAX];
struct vpn_policy vpn_policy[AFI_MAX];
struct bgp_pbr_config *bgp_pbr_cfg;
/* Count of peers in established state */
uint32_t established_peers;
/* Weighted ECMP related config. */
enum bgp_link_bw_handling lb_handling;
/* Process Queue for handling routes */
struct work_queue *process_queue;
/* BGP Conditional advertisement */
uint32_t condition_filter_count;
struct thread *t_condition_check;
/* BGP route flap dampening configuration */
struct bgp_damp_config damp[AFI_MAX][SAFI_MAX];
QOBJ_FIELDS
};
DECLARE_QOBJ_TYPE(bgp)
DECLARE_HOOK(bgp_inst_delete, (struct bgp *bgp), (bgp))
DECLARE_HOOK(bgp_inst_config_write,
(struct bgp *bgp, struct vty *vty),
(bgp, vty))
/* Thread callback information */
struct afi_safi_info {
afi_t afi;
safi_t safi;
struct bgp *bgp;
};
#define BGP_ROUTE_ADV_HOLD(bgp) (bgp->main_peers_update_hold)
#define IS_BGP_INST_KNOWN_TO_ZEBRA(bgp) \
(bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT \
|| (bgp->inst_type == BGP_INSTANCE_TYPE_VRF \
&& bgp->vrf_id != VRF_UNKNOWN))
#define BGP_SELECT_DEFER_DISABLE(bgp) \
(CHECK_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE))
#define BGP_SUPPRESS_FIB_ENABLED(bgp) \
(CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING) \
|| bm->wait_for_fib)
/* BGP peer-group support. */
struct peer_group {
/* Name of the peer-group. */
char *name;
/* Pointer to BGP. */
struct bgp *bgp;
/* Peer-group client list. */
struct list *peer;
/** Dynamic neighbor listening ranges */
struct list *listen_range[AFI_MAX];
/* Peer-group config */
struct peer *conf;
};
/* BGP Notify message format. */
struct bgp_notify {
uint8_t code;
uint8_t subcode;
char *data;
bgp_size_t length;
uint8_t *raw_data;
};
/* Next hop self address. */
struct bgp_nexthop {
struct interface *ifp;
struct in_addr v4;
struct in6_addr v6_global;
struct in6_addr v6_local;
};
/* BGP addpath values */
#define BGP_ADDPATH_RX 1
#define BGP_ADDPATH_TX 2
#define BGP_ADDPATH_ID_LEN 4
#define BGP_ADDPATH_TX_ID_FOR_DEFAULT_ORIGINATE 1
/* Route map direction */
#define RMAP_IN 0
#define RMAP_OUT 1
#define RMAP_MAX 2
#define BGP_DEFAULT_TTL 1
#define BGP_GTSM_HOPS_DISABLED 0
#define BGP_GTSM_HOPS_CONNECTED 1
/* Advertise map */
#define CONDITION_NON_EXIST false
#define CONDITION_EXIST true
enum update_type { WITHDRAW, ADVERTISE };
#include "filter.h"
/* BGP filter structure. */
struct bgp_filter {
/* Distribute-list. */
struct {
char *name;
struct access_list *alist;
} dlist[FILTER_MAX];
/* Prefix-list. */
struct {
char *name;
struct prefix_list *plist;
} plist[FILTER_MAX];
/* Filter-list. */
struct {
char *name;
struct as_list *aslist;
} aslist[FILTER_MAX];
/* Route-map. */
struct {
char *name;
struct route_map *map;
} map[RMAP_MAX];
/* Unsuppress-map. */
struct {
char *name;
struct route_map *map;
} usmap;
/* Advertise-map */
struct {
char *aname;
struct route_map *amap;
bool condition;
char *cname;
struct route_map *cmap;
enum update_type update_type;
} advmap;
};
/* IBGP/EBGP identifier. We also have a CONFED peer, which is to say,
a peer who's AS is part of our Confederation. */
typedef enum {
BGP_PEER_UNSPECIFIED,
BGP_PEER_IBGP,
BGP_PEER_EBGP,
BGP_PEER_INTERNAL,
BGP_PEER_CONFED,
} bgp_peer_sort_t;
/* BGP message header and packet size. */
#define BGP_MARKER_SIZE 16
#define BGP_HEADER_SIZE 19
#define BGP_MAX_PACKET_SIZE 4096
#define BGP_MAX_PACKET_SIZE_OVERFLOW 1024
/*
* Trigger delay for bgp_announce_route().
*/
#define BGP_ANNOUNCE_ROUTE_SHORT_DELAY_MS 100
#define BGP_ANNOUNCE_ROUTE_DELAY_MS 500
struct peer_af {
/* back pointer to the peer */
struct peer *peer;
/* which subgroup the peer_af belongs to */
struct update_subgroup *subgroup;
/* for being part of an update subgroup's peer list */
LIST_ENTRY(peer_af) subgrp_train;
/* for being part of a packet's peer list */
LIST_ENTRY(peer_af) pkt_train;
struct bpacket *next_pkt_to_send;
/*
* Trigger timer for bgp_announce_route().
*/
struct thread *t_announce_route;
afi_t afi;
safi_t safi;
int afid;
};
/* BGP GR per peer ds */
#define BGP_PEER_GR_MODE 5
#define BGP_PEER_GR_EVENT_CMD 6
enum peer_mode {
PEER_HELPER = 0,
PEER_GR,
PEER_DISABLE,
PEER_INVALID,
PEER_GLOBAL_INHERIT /* This is the default mode */
};
enum peer_gr_command {
PEER_GR_CMD = 0,
NO_PEER_GR_CMD,
PEER_DISABLE_CMD,
NO_PEER_DISABLE_CMD,
PEER_HELPER_CMD,
NO_PEER_HELPER_CMD
};
typedef unsigned int (*bgp_peer_gr_action_ptr)(struct peer *, int, int);
struct bgp_peer_gr {
enum peer_mode next_state;
bgp_peer_gr_action_ptr action_fun;
};
/*
* BGP FSM event codes, per RFC 4271 ss. 8.1
*/
enum bgp_fsm_rfc_codes {
BGP_FSM_ManualStart = 1,
BGP_FSM_ManualStop = 2,
BGP_FSM_AutomaticStart = 3,
BGP_FSM_ManualStart_with_PassiveTcpEstablishment = 4,
BGP_FSM_AutomaticStart_with_PassiveTcpEstablishment = 5,
BGP_FSM_AutomaticStart_with_DampPeerOscillations = 6,
BGP_FSM_AutomaticStart_with_DampPeerOscillations_and_PassiveTcpEstablishment =
7,
BGP_FSM_AutomaticStop = 8,
BGP_FSM_ConnectRetryTimer_Expires = 9,
BGP_FSM_HoldTimer_Expires = 10,
BGP_FSM_KeepaliveTimer_Expires = 11,
BGP_FSM_DelayOpenTimer_Expires = 12,
BGP_FSM_IdleHoldTimer_Expires = 13,
BGP_FSM_TcpConnection_Valid = 14,
BGP_FSM_Tcp_CR_Invalid = 15,
BGP_FSM_Tcp_CR_Acked = 16,
BGP_FSM_TcpConnectionConfirmed = 17,
BGP_FSM_TcpConnectionFails = 18,
BGP_FSM_BGPOpen = 19,
BGP_FSM_BGPOpen_with_DelayOpenTimer_running = 20,
BGP_FSM_BGPHeaderErr = 21,
BGP_FSM_BGPOpenMsgErr = 22,
BGP_FSM_OpenCollisionDump = 23,
BGP_FSM_NotifMsgVerErr = 24,
BGP_FSM_NotifMsg = 25,
BGP_FSM_KeepAliveMsg = 26,
BGP_FSM_UpdateMsg = 27,
BGP_FSM_UpdateMsgErr = 28
};
/*
* BGP finite state machine events
*
* Note: these do not correspond to RFC-defined event codes. Those are
* defined elsewhere.
*/
enum bgp_fsm_events {
BGP_Start = 1,
BGP_Stop,
TCP_connection_open,
TCP_connection_open_w_delay,
TCP_connection_closed,
TCP_connection_open_failed,
TCP_fatal_error,
ConnectRetry_timer_expired,
Hold_Timer_expired,
KeepAlive_timer_expired,
DelayOpen_timer_expired,
Receive_OPEN_message,
Receive_KEEPALIVE_message,
Receive_UPDATE_message,
Receive_NOTIFICATION_message,
Clearing_Completed,
BGP_EVENTS_MAX,
};
/* BGP finite state machine status. */
enum bgp_fsm_status {
Idle = 1,
Connect,
Active,
OpenSent,
OpenConfirm,
Established,
Clearing,
Deleted,
BGP_STATUS_MAX,
};
#define PEER_HOSTNAME(peer) ((peer)->host ? (peer)->host : "(unknown peer)")
/* BGP neighbor structure. */