@@ -434,7 +434,8 @@ void bgp_path_info_path_with_addpath_rx_str(struct bgp_path_info *pi, char *buf)
434
434
static int bgp_path_info_cmp (struct bgp * bgp , struct bgp_path_info * new ,
435
435
struct bgp_path_info * exist , int * paths_eq ,
436
436
struct bgp_maxpaths_cfg * mpath_cfg , int debug ,
437
- char * pfx_buf , afi_t afi , safi_t safi )
437
+ char * pfx_buf , afi_t afi , safi_t safi ,
438
+ enum bgp_path_selection_reason * reason )
438
439
{
439
440
struct attr * newattr , * existattr ;
440
441
bgp_peer_sort_t new_sort ;
@@ -463,6 +464,7 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,
463
464
464
465
/* 0. Null check. */
465
466
if (new == NULL ) {
467
+ * reason = bgp_path_selection_none ;
466
468
if (debug )
467
469
zlog_debug ("%s: new is NULL" , pfx_buf );
468
470
return 0 ;
@@ -472,6 +474,7 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,
472
474
bgp_path_info_path_with_addpath_rx_str (new , new_buf );
473
475
474
476
if (exist == NULL ) {
477
+ * reason = bgp_path_selection_first ;
475
478
if (debug )
476
479
zlog_debug ("%s: %s is the initial bestpath" , pfx_buf ,
477
480
new_buf );
@@ -514,6 +517,7 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,
514
517
}
515
518
516
519
if (newattr -> sticky && !existattr -> sticky ) {
520
+ * reason = bgp_path_selection_evpn_sticky_mac ;
517
521
if (debug )
518
522
zlog_debug (
519
523
"%s: %s wins over %s due to sticky MAC flag" ,
@@ -522,6 +526,7 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,
522
526
}
523
527
524
528
if (!newattr -> sticky && existattr -> sticky ) {
529
+ * reason = bgp_path_selection_evpn_sticky_mac ;
525
530
if (debug )
526
531
zlog_debug (
527
532
"%s: %s loses to %s due to sticky MAC flag" ,
@@ -534,6 +539,7 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,
534
539
exist_mm_seq = mac_mobility_seqnum (existattr );
535
540
536
541
if (new_mm_seq > exist_mm_seq ) {
542
+ * reason = bgp_path_selection_evpn_seq ;
537
543
if (debug )
538
544
zlog_debug (
539
545
"%s: %s wins over %s due to MM seq %u > %u" ,
@@ -543,6 +549,7 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,
543
549
}
544
550
545
551
if (new_mm_seq < exist_mm_seq ) {
552
+ * reason = bgp_path_selection_evpn_seq ;
546
553
if (debug )
547
554
zlog_debug (
548
555
"%s: %s loses to %s due to MM seq %u < %u" ,
@@ -557,6 +564,7 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,
557
564
*/
558
565
nh_cmp = bgp_path_info_nexthop_cmp (new , exist );
559
566
if (nh_cmp < 0 ) {
567
+ * reason = bgp_path_selection_evpn_lower_ip ;
560
568
if (debug )
561
569
zlog_debug (
562
570
"%s: %s wins over %s due to same MM seq %u and lower IP %s" ,
@@ -565,6 +573,7 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,
565
573
return 1 ;
566
574
}
567
575
if (nh_cmp > 0 ) {
576
+ * reason = bgp_path_selection_evpn_lower_ip ;
568
577
if (debug )
569
578
zlog_debug (
570
579
"%s: %s loses to %s due to same MM seq %u and higher IP %s" ,
@@ -579,6 +588,7 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,
579
588
exist_weight = existattr -> weight ;
580
589
581
590
if (new_weight > exist_weight ) {
591
+ * reason = bgp_path_selection_weight ;
582
592
if (debug )
583
593
zlog_debug ("%s: %s wins over %s due to weight %d > %d" ,
584
594
pfx_buf , new_buf , exist_buf , new_weight ,
@@ -587,6 +597,7 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,
587
597
}
588
598
589
599
if (new_weight < exist_weight ) {
600
+ * reason = bgp_path_selection_weight ;
590
601
if (debug )
591
602
zlog_debug ("%s: %s loses to %s due to weight %d < %d" ,
592
603
pfx_buf , new_buf , exist_buf , new_weight ,
@@ -603,6 +614,7 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,
603
614
exist_pref = existattr -> local_pref ;
604
615
605
616
if (new_pref > exist_pref ) {
617
+ * reason = bgp_path_selection_local_pref ;
606
618
if (debug )
607
619
zlog_debug (
608
620
"%s: %s wins over %s due to localpref %d > %d" ,
@@ -612,6 +624,7 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,
612
624
}
613
625
614
626
if (new_pref < exist_pref ) {
627
+ * reason = bgp_path_selection_local_pref ;
615
628
if (debug )
616
629
zlog_debug (
617
630
"%s: %s loses to %s due to localpref %d < %d" ,
@@ -627,6 +640,7 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,
627
640
*/
628
641
if (!(new -> sub_type == BGP_ROUTE_NORMAL ||
629
642
new -> sub_type == BGP_ROUTE_IMPORTED )) {
643
+ * reason = bgp_path_selection_local_route ;
630
644
if (debug )
631
645
zlog_debug (
632
646
"%s: %s wins over %s due to preferred BGP_ROUTE type" ,
@@ -636,6 +650,7 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,
636
650
637
651
if (!(exist -> sub_type == BGP_ROUTE_NORMAL ||
638
652
exist -> sub_type == BGP_ROUTE_IMPORTED )) {
653
+ * reason = bgp_path_selection_local_route ;
639
654
if (debug )
640
655
zlog_debug (
641
656
"%s: %s loses to %s due to preferred BGP_ROUTE type" ,
@@ -655,6 +670,7 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,
655
670
aspath_hops += aspath_count_confeds (newattr -> aspath );
656
671
657
672
if (aspath_hops < (exist_hops + exist_confeds )) {
673
+ * reason = bgp_path_selection_confed_as_path ;
658
674
if (debug )
659
675
zlog_debug (
660
676
"%s: %s wins over %s due to aspath (with confeds) hopcount %d < %d" ,
@@ -665,6 +681,7 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,
665
681
}
666
682
667
683
if (aspath_hops > (exist_hops + exist_confeds )) {
684
+ * reason = bgp_path_selection_confed_as_path ;
668
685
if (debug )
669
686
zlog_debug (
670
687
"%s: %s loses to %s due to aspath (with confeds) hopcount %d > %d" ,
@@ -677,6 +694,7 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,
677
694
int newhops = aspath_count_hops (newattr -> aspath );
678
695
679
696
if (newhops < exist_hops ) {
697
+ * reason = bgp_path_selection_as_path ;
680
698
if (debug )
681
699
zlog_debug (
682
700
"%s: %s wins over %s due to aspath hopcount %d < %d" ,
@@ -686,6 +704,7 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,
686
704
}
687
705
688
706
if (newhops > exist_hops ) {
707
+ * reason = bgp_path_selection_as_path ;
689
708
if (debug )
690
709
zlog_debug (
691
710
"%s: %s loses to %s due to aspath hopcount %d > %d" ,
@@ -698,6 +717,7 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,
698
717
699
718
/* 5. Origin check. */
700
719
if (newattr -> origin < existattr -> origin ) {
720
+ * reason = bgp_path_selection_origin ;
701
721
if (debug )
702
722
zlog_debug ("%s: %s wins over %s due to ORIGIN %s < %s" ,
703
723
pfx_buf , new_buf , exist_buf ,
@@ -707,6 +727,7 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,
707
727
}
708
728
709
729
if (newattr -> origin > existattr -> origin ) {
730
+ * reason = bgp_path_selection_origin ;
710
731
if (debug )
711
732
zlog_debug ("%s: %s loses to %s due to ORIGIN %s > %s" ,
712
733
pfx_buf , new_buf , exist_buf ,
@@ -732,6 +753,7 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,
732
753
exist_med = bgp_med_value (exist -> attr , bgp );
733
754
734
755
if (new_med < exist_med ) {
756
+ * reason = bgp_path_selection_med ;
735
757
if (debug )
736
758
zlog_debug (
737
759
"%s: %s wins over %s due to MED %d < %d" ,
@@ -741,6 +763,7 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,
741
763
}
742
764
743
765
if (new_med > exist_med ) {
766
+ * reason = bgp_path_selection_med ;
744
767
if (debug )
745
768
zlog_debug (
746
769
"%s: %s loses to %s due to MED %d > %d" ,
@@ -756,6 +779,7 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,
756
779
757
780
if (new_sort == BGP_PEER_EBGP
758
781
&& (exist_sort == BGP_PEER_IBGP || exist_sort == BGP_PEER_CONFED )) {
782
+ * reason = bgp_path_selection_peer ;
759
783
if (debug )
760
784
zlog_debug (
761
785
"%s: %s wins over %s due to eBGP peer > iBGP peer" ,
@@ -765,6 +789,7 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,
765
789
766
790
if (exist_sort == BGP_PEER_EBGP
767
791
&& (new_sort == BGP_PEER_IBGP || new_sort == BGP_PEER_CONFED )) {
792
+ * reason = bgp_path_selection_peer ;
768
793
if (debug )
769
794
zlog_debug (
770
795
"%s: %s loses to %s due to iBGP peer < eBGP peer" ,
@@ -834,6 +859,7 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,
834
859
if (CHECK_FLAG (bgp -> config , BGP_CONFIG_CONFEDERATION )) {
835
860
if (new_sort == BGP_PEER_CONFED
836
861
&& exist_sort == BGP_PEER_IBGP ) {
862
+ * reason = bgp_path_selection_confed ;
837
863
if (debug )
838
864
zlog_debug (
839
865
"%s: %s wins over %s due to confed-external peer > confed-internal peer" ,
@@ -843,6 +869,7 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,
843
869
844
870
if (exist_sort == BGP_PEER_CONFED
845
871
&& new_sort == BGP_PEER_IBGP ) {
872
+ * reason = bgp_path_selection_confed ;
846
873
if (debug )
847
874
zlog_debug (
848
875
"%s: %s loses to %s due to confed-internal peer < confed-external peer" ,
@@ -918,6 +945,7 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,
918
945
"%s: %s loses to %s after IGP metric comparison" ,
919
946
pfx_buf , new_buf , exist_buf );
920
947
}
948
+ * reason = bgp_path_selection_igp_metric ;
921
949
return ret ;
922
950
}
923
951
@@ -928,6 +956,7 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,
928
956
if (!bgp_flag_check (bgp , BGP_FLAG_COMPARE_ROUTER_ID )
929
957
&& new_sort == BGP_PEER_EBGP && exist_sort == BGP_PEER_EBGP ) {
930
958
if (CHECK_FLAG (new -> flags , BGP_PATH_SELECTED )) {
959
+ * reason = bgp_path_selection_older ;
931
960
if (debug )
932
961
zlog_debug (
933
962
"%s: %s wins over %s due to oldest external" ,
@@ -936,6 +965,7 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,
936
965
}
937
966
938
967
if (CHECK_FLAG (exist -> flags , BGP_PATH_SELECTED )) {
968
+ * reason = bgp_path_selection_older ;
939
969
if (debug )
940
970
zlog_debug (
941
971
"%s: %s loses to %s due to oldest external" ,
@@ -959,6 +989,7 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,
959
989
exist_id .s_addr = exist -> peer -> remote_id .s_addr ;
960
990
961
991
if (ntohl (new_id .s_addr ) < ntohl (exist_id .s_addr )) {
992
+ * reason = bgp_path_selection_router_id ;
962
993
if (debug )
963
994
zlog_debug (
964
995
"%s: %s wins over %s due to Router-ID comparison" ,
@@ -967,6 +998,7 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,
967
998
}
968
999
969
1000
if (ntohl (new_id .s_addr ) > ntohl (exist_id .s_addr )) {
1001
+ * reason = bgp_path_selection_router_id ;
970
1002
if (debug )
971
1003
zlog_debug (
972
1004
"%s: %s loses to %s due to Router-ID comparison" ,
@@ -979,6 +1011,7 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,
979
1011
exist_cluster = BGP_CLUSTER_LIST_LENGTH (exist -> attr );
980
1012
981
1013
if (new_cluster < exist_cluster ) {
1014
+ * reason = bgp_path_selection_cluster_length ;
982
1015
if (debug )
983
1016
zlog_debug (
984
1017
"%s: %s wins over %s due to CLUSTER_LIST length %d < %d" ,
@@ -988,6 +1021,7 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,
988
1021
}
989
1022
990
1023
if (new_cluster > exist_cluster ) {
1024
+ * reason = bgp_path_selection_cluster_length ;
991
1025
if (debug )
992
1026
zlog_debug (
993
1027
"%s: %s loses to %s due to CLUSTER_LIST length %d > %d" ,
@@ -1001,6 +1035,7 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,
1001
1035
* valid peer information (as the connection may or may not be up).
1002
1036
*/
1003
1037
if (CHECK_FLAG (exist -> flags , BGP_PATH_STALE )) {
1038
+ * reason = bgp_path_selection_stale ;
1004
1039
if (debug )
1005
1040
zlog_debug (
1006
1041
"%s: %s wins over %s due to latter path being STALE" ,
@@ -1009,6 +1044,7 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,
1009
1044
}
1010
1045
1011
1046
if (CHECK_FLAG (new -> flags , BGP_PATH_STALE )) {
1047
+ * reason = bgp_path_selection_stale ;
1012
1048
if (debug )
1013
1049
zlog_debug (
1014
1050
"%s: %s loses to %s due to former path being STALE" ,
@@ -1017,14 +1053,19 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,
1017
1053
}
1018
1054
1019
1055
/* locally configured routes to advertise do not have su_remote */
1020
- if (new -> peer -> su_remote == NULL )
1056
+ if (new -> peer -> su_remote == NULL ) {
1057
+ * reason = bgp_path_selection_local_configured ;
1021
1058
return 0 ;
1022
- if (exist -> peer -> su_remote == NULL )
1059
+ }
1060
+ if (exist -> peer -> su_remote == NULL ) {
1061
+ * reason = bgp_path_selection_local_configured ;
1023
1062
return 1 ;
1063
+ }
1024
1064
1025
1065
ret = sockunion_cmp (new -> peer -> su_remote , exist -> peer -> su_remote );
1026
1066
1027
1067
if (ret == 1 ) {
1068
+ * reason = bgp_path_selection_neighbor_ip ;
1028
1069
if (debug )
1029
1070
zlog_debug (
1030
1071
"%s: %s loses to %s due to Neighor IP comparison" ,
@@ -1033,13 +1074,15 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,
1033
1074
}
1034
1075
1035
1076
if (ret == -1 ) {
1077
+ * reason = bgp_path_selection_neighbor_ip ;
1036
1078
if (debug )
1037
1079
zlog_debug (
1038
1080
"%s: %s wins over %s due to Neighor IP comparison" ,
1039
1081
pfx_buf , new_buf , exist_buf );
1040
1082
return 1 ;
1041
1083
}
1042
1084
1085
+ * reason = bgp_path_selection_default ;
1043
1086
if (debug )
1044
1087
zlog_debug ("%s: %s wins over %s due to nothing left to compare" ,
1045
1088
pfx_buf , new_buf , exist_buf );
@@ -1053,12 +1096,13 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,
1053
1096
* This version is compatible with */
1054
1097
int bgp_path_info_cmp_compatible (struct bgp * bgp , struct bgp_path_info * new ,
1055
1098
struct bgp_path_info * exist , char * pfx_buf ,
1056
- afi_t afi , safi_t safi )
1099
+ afi_t afi , safi_t safi ,
1100
+ enum bgp_path_selection_reason * reason )
1057
1101
{
1058
1102
int paths_eq ;
1059
1103
int ret ;
1060
1104
ret = bgp_path_info_cmp (bgp , new , exist , & paths_eq , NULL , 0 , pfx_buf ,
1061
- afi , safi );
1105
+ afi , safi , reason );
1062
1106
1063
1107
if (paths_eq )
1064
1108
ret = 0 ;
@@ -1955,7 +1999,8 @@ void bgp_best_selection(struct bgp *bgp, struct bgp_node *rn,
1955
1999
if (bgp_path_info_cmp (
1956
2000
bgp , pi2 , new_select ,
1957
2001
& paths_eq , mpath_cfg , debug ,
1958
- pfx_buf , afi , safi )) {
2002
+ pfx_buf , afi , safi ,
2003
+ & rn -> reason )) {
1959
2004
bgp_path_info_unset_flag (
1960
2005
rn , new_select ,
1961
2006
BGP_PATH_DMED_SELECTED );
@@ -2028,7 +2073,7 @@ void bgp_best_selection(struct bgp *bgp, struct bgp_node *rn,
2028
2073
bgp_path_info_unset_flag (rn , pi , BGP_PATH_DMED_CHECK );
2029
2074
2030
2075
if (bgp_path_info_cmp (bgp , pi , new_select , & paths_eq , mpath_cfg ,
2031
- debug , pfx_buf , afi , safi )) {
2076
+ debug , pfx_buf , afi , safi , & rn -> reason )) {
2032
2077
new_select = pi ;
2033
2078
}
2034
2079
}
@@ -2084,7 +2129,8 @@ void bgp_best_selection(struct bgp *bgp, struct bgp_node *rn,
2084
2129
}
2085
2130
2086
2131
bgp_path_info_cmp (bgp , pi , new_select , & paths_eq ,
2087
- mpath_cfg , debug , pfx_buf , afi , safi );
2132
+ mpath_cfg , debug , pfx_buf , afi , safi ,
2133
+ & rn -> reason );
2088
2134
2089
2135
if (paths_eq ) {
2090
2136
if (debug )
0 commit comments