1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * Copyright (C) 2010 Google Inc.
6 * This file is part of Quagga
14 #include "sockunion.h"
19 #include "bgpd/bgpd.h"
20 #include "bgpd/bgp_table.h"
21 #include "bgpd/bgp_route.h"
22 #include "bgpd/bgp_attr.h"
23 #include "bgpd/bgp_debug.h"
24 #include "bgpd/bgp_aspath.h"
25 #include "bgpd/bgp_community.h"
26 #include "bgpd/bgp_ecommunity.h"
27 #include "bgpd/bgp_lcommunity.h"
28 #include "bgpd/bgp_mpath.h"
31 * bgp_maximum_paths_set
33 * Record maximum-paths configuration for BGP instance
35 int bgp_maximum_paths_set(struct bgp
*bgp
, afi_t afi
, safi_t safi
, int peertype
,
36 uint16_t maxpaths
, bool same_clusterlen
)
38 if (!bgp
|| (afi
>= AFI_MAX
) || (safi
>= SAFI_MAX
))
43 bgp
->maxpaths
[afi
][safi
].maxpaths_ibgp
= maxpaths
;
44 bgp
->maxpaths
[afi
][safi
].same_clusterlen
= same_clusterlen
;
47 bgp
->maxpaths
[afi
][safi
].maxpaths_ebgp
= maxpaths
;
57 * bgp_maximum_paths_unset
59 * Remove maximum-paths configuration from BGP instance
61 int bgp_maximum_paths_unset(struct bgp
*bgp
, afi_t afi
, safi_t safi
,
64 if (!bgp
|| (afi
>= AFI_MAX
) || (safi
>= SAFI_MAX
))
69 bgp
->maxpaths
[afi
][safi
].maxpaths_ibgp
= multipath_num
;
70 bgp
->maxpaths
[afi
][safi
].same_clusterlen
= false;
73 bgp
->maxpaths
[afi
][safi
].maxpaths_ebgp
= multipath_num
;
85 * Return true if ifindex for ifp1 and ifp2 are the same, else return false.
87 static int bgp_interface_same(struct interface
*ifp1
, struct interface
*ifp2
)
98 return (ifp1
->ifindex
== ifp2
->ifindex
);
103 * bgp_path_info_nexthop_cmp
105 * Compare the nexthops of two paths. Return value is less than, equal to,
106 * or greater than zero if bpi1 is respectively less than, equal to,
107 * or greater than bpi2.
109 int bgp_path_info_nexthop_cmp(struct bgp_path_info
*bpi1
,
110 struct bgp_path_info
*bpi2
)
113 struct in6_addr addr1
, addr2
;
115 compare
= IPV4_ADDR_CMP(&bpi1
->attr
->nexthop
, &bpi2
->attr
->nexthop
);
117 if (bpi1
->attr
->mp_nexthop_len
== bpi2
->attr
->mp_nexthop_len
) {
118 switch (bpi1
->attr
->mp_nexthop_len
) {
119 case BGP_ATTR_NHLEN_IPV4
:
120 case BGP_ATTR_NHLEN_VPNV4
:
121 compare
= IPV4_ADDR_CMP(
122 &bpi1
->attr
->mp_nexthop_global_in
,
123 &bpi2
->attr
->mp_nexthop_global_in
);
125 case BGP_ATTR_NHLEN_IPV6_GLOBAL
:
126 case BGP_ATTR_NHLEN_VPNV6_GLOBAL
:
127 compare
= IPV6_ADDR_CMP(
128 &bpi1
->attr
->mp_nexthop_global
,
129 &bpi2
->attr
->mp_nexthop_global
);
131 case BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
:
132 addr1
= (bpi1
->attr
->mp_nexthop_prefer_global
)
133 ? bpi1
->attr
->mp_nexthop_global
134 : bpi1
->attr
->mp_nexthop_local
;
135 addr2
= (bpi2
->attr
->mp_nexthop_prefer_global
)
136 ? bpi2
->attr
->mp_nexthop_global
137 : bpi2
->attr
->mp_nexthop_local
;
139 if (!bpi1
->attr
->mp_nexthop_prefer_global
140 && !bpi2
->attr
->mp_nexthop_prefer_global
)
141 compare
= !bgp_interface_same(
146 compare
= IPV6_ADDR_CMP(&addr1
, &addr2
);
151 /* This can happen if one IPv6 peer sends you global and
153 * nexthops but another IPv6 peer only sends you global
155 else if (bpi1
->attr
->mp_nexthop_len
156 == BGP_ATTR_NHLEN_IPV6_GLOBAL
157 || bpi1
->attr
->mp_nexthop_len
158 == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
) {
159 compare
= IPV6_ADDR_CMP(&bpi1
->attr
->mp_nexthop_global
,
160 &bpi2
->attr
->mp_nexthop_global
);
162 if (bpi1
->attr
->mp_nexthop_len
163 < bpi2
->attr
->mp_nexthop_len
)
172 * If both nexthops are same then check
173 * if they belong to same VRF
175 if (!compare
&& bpi1
->attr
->nh_type
!= NEXTHOP_TYPE_BLACKHOLE
) {
176 if (bpi1
->extra
&& bpi1
->extra
->bgp_orig
&& bpi2
->extra
177 && bpi2
->extra
->bgp_orig
) {
178 if (bpi1
->extra
->bgp_orig
->vrf_id
179 != bpi2
->extra
->bgp_orig
->vrf_id
) {
189 * bgp_path_info_mpath_cmp
191 * This function determines our multipath list ordering. By ordering
192 * the list we can deterministically select which paths are included
193 * in the multipath set. The ordering also helps in detecting changes
194 * in the multipath selection so we can detect whether to send an
197 * The order of paths is determined first by received nexthop, and then
198 * by peer address if the nexthops are the same.
200 static int bgp_path_info_mpath_cmp(void *val1
, void *val2
)
202 struct bgp_path_info
*bpi1
, *bpi2
;
208 compare
= bgp_path_info_nexthop_cmp(bpi1
, bpi2
);
211 if (!bpi1
->peer
->su_remote
&& !bpi2
->peer
->su_remote
)
213 else if (!bpi1
->peer
->su_remote
)
215 else if (!bpi2
->peer
->su_remote
)
218 compare
= sockunion_cmp(bpi1
->peer
->su_remote
,
219 bpi2
->peer
->su_remote
);
228 * Initialize the mp_list, which holds the list of multipaths
229 * selected by bgp_best_selection
231 void bgp_mp_list_init(struct list
*mp_list
)
234 memset(mp_list
, 0, sizeof(struct list
));
235 mp_list
->cmp
= bgp_path_info_mpath_cmp
;
241 * Clears all entries out of the mp_list
243 void bgp_mp_list_clear(struct list
*mp_list
)
246 list_delete_all_node(mp_list
);
252 * Adds a multipath entry to the mp_list
254 void bgp_mp_list_add(struct list
*mp_list
, struct bgp_path_info
*mpinfo
)
256 assert(mp_list
&& mpinfo
);
257 listnode_add_sort(mp_list
, mpinfo
);
261 * bgp_path_info_mpath_new
263 * Allocate and zero memory for a new bgp_path_info_mpath element
265 static struct bgp_path_info_mpath
*bgp_path_info_mpath_new(void)
267 struct bgp_path_info_mpath
*new_mpath
;
269 new_mpath
= XCALLOC(MTYPE_BGP_MPATH_INFO
,
270 sizeof(struct bgp_path_info_mpath
));
276 * bgp_path_info_mpath_free
278 * Release resources for a bgp_path_info_mpath element and zero out pointer
280 void bgp_path_info_mpath_free(struct bgp_path_info_mpath
**mpath
)
282 if (mpath
&& *mpath
) {
283 if ((*mpath
)->mp_attr
)
284 bgp_attr_unintern(&(*mpath
)->mp_attr
);
285 XFREE(MTYPE_BGP_MPATH_INFO
, *mpath
);
290 * bgp_path_info_mpath_get
292 * Fetch the mpath element for the given bgp_path_info. Used for
293 * doing lazy allocation.
295 static struct bgp_path_info_mpath
*
296 bgp_path_info_mpath_get(struct bgp_path_info
*path
)
298 struct bgp_path_info_mpath
*mpath
;
304 mpath
= bgp_path_info_mpath_new();
306 mpath
->mp_info
= path
;
312 * bgp_path_info_mpath_enqueue
314 * Enqueue a path onto the multipath list given the previous multipath
317 static void bgp_path_info_mpath_enqueue(struct bgp_path_info
*prev_info
,
318 struct bgp_path_info
*path
)
320 struct bgp_path_info_mpath
*prev
, *mpath
;
322 prev
= bgp_path_info_mpath_get(prev_info
);
323 mpath
= bgp_path_info_mpath_get(path
);
327 mpath
->mp_next
= prev
->mp_next
;
328 mpath
->mp_prev
= prev
;
330 prev
->mp_next
->mp_prev
= mpath
;
331 prev
->mp_next
= mpath
;
333 SET_FLAG(path
->flags
, BGP_PATH_MULTIPATH
);
337 * bgp_path_info_mpath_dequeue
339 * Remove a path from the multipath list
341 void bgp_path_info_mpath_dequeue(struct bgp_path_info
*path
)
343 struct bgp_path_info_mpath
*mpath
= path
->mpath
;
347 mpath
->mp_prev
->mp_next
= mpath
->mp_next
;
349 mpath
->mp_next
->mp_prev
= mpath
->mp_prev
;
350 mpath
->mp_next
= mpath
->mp_prev
= NULL
;
351 UNSET_FLAG(path
->flags
, BGP_PATH_MULTIPATH
);
355 * bgp_path_info_mpath_next
357 * Given a bgp_path_info, return the next multipath entry
359 struct bgp_path_info
*bgp_path_info_mpath_next(struct bgp_path_info
*path
)
361 if (!path
->mpath
|| !path
->mpath
->mp_next
)
363 return path
->mpath
->mp_next
->mp_info
;
367 * bgp_path_info_mpath_first
369 * Given bestpath bgp_path_info, return the first multipath entry.
371 struct bgp_path_info
*bgp_path_info_mpath_first(struct bgp_path_info
*path
)
373 return bgp_path_info_mpath_next(path
);
377 * bgp_path_info_mpath_count
379 * Given the bestpath bgp_path_info, return the number of multipath entries
381 uint32_t bgp_path_info_mpath_count(struct bgp_path_info
*path
)
385 return path
->mpath
->mp_count
;
389 * bgp_path_info_mpath_count_set
391 * Sets the count of multipaths into bestpath's mpath element
393 static void bgp_path_info_mpath_count_set(struct bgp_path_info
*path
,
396 struct bgp_path_info_mpath
*mpath
;
397 if (!count
&& !path
->mpath
)
399 mpath
= bgp_path_info_mpath_get(path
);
402 mpath
->mp_count
= count
;
406 * bgp_path_info_mpath_lb_update
408 * Update cumulative info related to link-bandwidth
410 static void bgp_path_info_mpath_lb_update(struct bgp_path_info
*path
, bool set
,
411 bool all_paths_lb
, uint64_t cum_bw
)
413 struct bgp_path_info_mpath
*mpath
;
417 if (!set
|| (cum_bw
== 0 && !all_paths_lb
))
420 mpath
= bgp_path_info_mpath_get(path
);
426 SET_FLAG(mpath
->mp_flags
, BGP_MP_LB_PRESENT
);
428 UNSET_FLAG(mpath
->mp_flags
, BGP_MP_LB_PRESENT
);
430 SET_FLAG(mpath
->mp_flags
, BGP_MP_LB_ALL
);
432 UNSET_FLAG(mpath
->mp_flags
, BGP_MP_LB_ALL
);
433 mpath
->cum_bw
= cum_bw
;
441 * bgp_path_info_mpath_attr
443 * Given bestpath bgp_path_info, return aggregated attribute set used
444 * for advertising the multipath route
446 struct attr
*bgp_path_info_mpath_attr(struct bgp_path_info
*path
)
450 return path
->mpath
->mp_attr
;
454 * bgp_path_info_chkwtd
456 * Return if we should attempt to do weighted ECMP or not
457 * The path passed in is the bestpath.
459 bool bgp_path_info_mpath_chkwtd(struct bgp
*bgp
, struct bgp_path_info
*path
)
461 /* Check if told to ignore weights or not multipath */
462 if (bgp
->lb_handling
== BGP_LINK_BW_IGNORE_BW
|| !path
->mpath
)
465 /* All paths in multipath should have associated weight (bandwidth)
466 * unless told explicitly otherwise.
468 if (bgp
->lb_handling
!= BGP_LINK_BW_SKIP_MISSING
&&
469 bgp
->lb_handling
!= BGP_LINK_BW_DEFWT_4_MISSING
)
470 return (path
->mpath
->mp_flags
& BGP_MP_LB_ALL
);
472 /* At least one path should have bandwidth. */
473 return (path
->mpath
->mp_flags
& BGP_MP_LB_PRESENT
);
477 * bgp_path_info_mpath_attr
479 * Given bestpath bgp_path_info, return cumulative bandwidth
480 * computed for all multipaths with bandwidth info
482 uint64_t bgp_path_info_mpath_cumbw(struct bgp_path_info
*path
)
486 return path
->mpath
->cum_bw
;
490 * bgp_path_info_mpath_attr_set
492 * Sets the aggregated attribute into bestpath's mpath element
494 static void bgp_path_info_mpath_attr_set(struct bgp_path_info
*path
,
497 struct bgp_path_info_mpath
*mpath
;
498 if (!attr
&& !path
->mpath
)
500 mpath
= bgp_path_info_mpath_get(path
);
503 mpath
->mp_attr
= attr
;
507 * bgp_path_info_mpath_update
509 * Compare and sync up the multipath list with the mp_list generated by
512 void bgp_path_info_mpath_update(struct bgp
*bgp
, struct bgp_dest
*dest
,
513 struct bgp_path_info
*new_best
,
514 struct bgp_path_info
*old_best
,
515 struct list
*mp_list
,
516 struct bgp_maxpaths_cfg
*mpath_cfg
)
518 uint16_t maxpaths
, mpath_count
, old_mpath_count
;
520 uint64_t cum_bw
, old_cum_bw
;
521 struct listnode
*mp_node
, *mp_next_node
;
522 struct bgp_path_info
*cur_mpath
, *new_mpath
, *next_mpath
, *prev_mpath
;
523 int mpath_changed
, debug
;
525 char path_buf
[PATH_ADDPATH_STR_BUFFER
];
528 maxpaths
= multipath_num
;
532 old_cum_bw
= cum_bw
= 0;
533 prev_mpath
= new_best
;
534 mp_node
= listhead(mp_list
);
535 debug
= bgp_debug_bestpath(dest
);
539 if (new_best
!= old_best
)
540 bgp_path_info_mpath_dequeue(new_best
);
541 maxpaths
= (new_best
->peer
->sort
== BGP_PEER_IBGP
)
542 ? mpath_cfg
->maxpaths_ibgp
543 : mpath_cfg
->maxpaths_ebgp
;
547 cur_mpath
= bgp_path_info_mpath_first(old_best
);
548 old_mpath_count
= bgp_path_info_mpath_count(old_best
);
549 old_cum_bw
= bgp_path_info_mpath_cumbw(old_best
);
550 bgp_path_info_mpath_count_set(old_best
, 0);
551 bgp_path_info_mpath_lb_update(old_best
, false, false, 0);
552 bgp_path_info_mpath_dequeue(old_best
);
557 "%pRN(%s): starting mpath update, newbest %s num candidates %d old-mpath-count %d old-cum-bw %" PRIu64
,
558 bgp_dest_to_rnode(dest
), bgp
->name_pretty
,
559 new_best
? new_best
->peer
->host
: "NONE",
560 mp_list
? listcount(mp_list
) : 0, old_mpath_count
,
564 * We perform an ordered walk through both lists in parallel.
565 * The reason for the ordered walk is that if there are paths
566 * that were previously multipaths and are still multipaths, the walk
567 * should encounter them in both lists at the same time. Otherwise
568 * there will be paths that are in one list or another, and we
569 * will deal with these separately.
571 * Note that new_best might be somewhere in the mp_list, so we need
574 all_paths_lb
= true; /* We'll reset if any path doesn't have LB. */
575 while (mp_node
|| cur_mpath
) {
576 struct bgp_path_info
*tmp_info
;
579 * We can bail out of this loop if all existing paths on the
580 * multipath list have been visited (for cleanup purposes) and
581 * the maxpath requirement is fulfulled
583 if (!cur_mpath
&& (mpath_count
>= maxpaths
))
586 mp_next_node
= mp_node
? listnextnode(mp_node
) : NULL
;
588 cur_mpath
? bgp_path_info_mpath_next(cur_mpath
) : NULL
;
589 tmp_info
= mp_node
? listgetdata(mp_node
) : NULL
;
593 "%pRN(%s): comparing candidate %s with existing mpath %s",
594 bgp_dest_to_rnode(dest
), bgp
->name_pretty
,
595 tmp_info
? tmp_info
->peer
->host
: "NONE",
596 cur_mpath
? cur_mpath
->peer
->host
: "NONE");
599 * If equal, the path was a multipath and is still a multipath.
600 * Insert onto new multipath list if maxpaths allows.
602 if (mp_node
&& (listgetdata(mp_node
) == cur_mpath
)) {
603 list_delete_node(mp_list
, mp_node
);
604 bgp_path_info_mpath_dequeue(cur_mpath
);
605 if ((mpath_count
< maxpaths
)
607 && bgp_path_info_nexthop_cmp(prev_mpath
,
609 bgp_path_info_mpath_enqueue(prev_mpath
,
611 prev_mpath
= cur_mpath
;
613 if (ecommunity_linkbw_present(
614 bgp_attr_get_ecommunity(
619 all_paths_lb
= false;
621 bgp_path_info_path_with_addpath_rx_str(
625 "%pRN: %s is still multipath, cur count %d",
626 bgp_dest_to_rnode(dest
),
627 path_buf
, mpath_count
);
632 bgp_path_info_path_with_addpath_rx_str(
636 "%pRN: remove mpath %s nexthop %pI4, cur count %d",
637 bgp_dest_to_rnode(dest
),
639 &cur_mpath
->attr
->nexthop
,
643 mp_node
= mp_next_node
;
644 cur_mpath
= next_mpath
;
650 || (bgp_path_info_mpath_cmp(cur_mpath
,
651 listgetdata(mp_node
))
654 * If here, we have an old multipath and either the
656 * is finished or the next mp_node points to a later
657 * multipath, so we need to purge this path from the
660 bgp_path_info_mpath_dequeue(cur_mpath
);
663 bgp_path_info_path_with_addpath_rx_str(
664 cur_mpath
, path_buf
, sizeof(path_buf
));
666 "%pRN: remove mpath %s nexthop %pI4, cur count %d",
667 bgp_dest_to_rnode(dest
), path_buf
,
668 &cur_mpath
->attr
->nexthop
, mpath_count
);
670 cur_mpath
= next_mpath
;
673 * If here, we have a path on the mp_list that was not
675 * a multipath (due to non-equivalance or maxpaths
677 * or the matching multipath is sorted later in the
679 * list. Before we enqueue the path on the new multipath
681 * make sure its not on the old_best multipath list or
684 * - If next_mpath points to this new path, update
686 * point to the multipath after this one
687 * - Dequeue the path from the multipath list just to
690 new_mpath
= listgetdata(mp_node
);
691 list_delete_node(mp_list
, mp_node
);
694 if ((mpath_count
< maxpaths
) && (new_mpath
!= new_best
)
695 && bgp_path_info_nexthop_cmp(prev_mpath
,
697 bgp_path_info_mpath_dequeue(new_mpath
);
699 bgp_path_info_mpath_enqueue(prev_mpath
,
701 prev_mpath
= new_mpath
;
704 if (ecommunity_linkbw_present(
705 bgp_attr_get_ecommunity(
710 all_paths_lb
= false;
712 bgp_path_info_path_with_addpath_rx_str(
716 "%pRN: add mpath %s nexthop %pI4, cur count %d",
717 bgp_dest_to_rnode(dest
),
719 &new_mpath
->attr
->nexthop
,
723 mp_node
= mp_next_node
;
728 bgp_path_info_mpath_count_set(new_best
, mpath_count
- 1);
729 if (mpath_count
<= 1 ||
730 !ecommunity_linkbw_present(
731 bgp_attr_get_ecommunity(new_best
->attr
), &bwval
))
732 all_paths_lb
= false;
735 bgp_path_info_mpath_lb_update(new_best
, true,
736 all_paths_lb
, cum_bw
);
740 "%pRN(%s): New mpath count (incl newbest) %d mpath-change %s all_paths_lb %d cum_bw %" PRIu64
,
741 bgp_dest_to_rnode(dest
), bgp
->name_pretty
,
742 mpath_count
, mpath_changed
? "YES" : "NO",
743 all_paths_lb
, cum_bw
);
746 || (bgp_path_info_mpath_count(new_best
) != old_mpath_count
))
747 SET_FLAG(new_best
->flags
, BGP_PATH_MULTIPATH_CHG
);
748 if ((mpath_count
- 1) != old_mpath_count
||
749 old_cum_bw
!= cum_bw
)
750 SET_FLAG(new_best
->flags
, BGP_PATH_LINK_BW_CHG
);
755 * bgp_mp_dmed_deselect
757 * Clean up multipath information for BGP_PATH_DMED_SELECTED path that
758 * is not selected as best path
760 void bgp_mp_dmed_deselect(struct bgp_path_info
*dmed_best
)
762 struct bgp_path_info
*mpinfo
, *mpnext
;
767 for (mpinfo
= bgp_path_info_mpath_first(dmed_best
); mpinfo
;
769 mpnext
= bgp_path_info_mpath_next(mpinfo
);
770 bgp_path_info_mpath_dequeue(mpinfo
);
773 bgp_path_info_mpath_count_set(dmed_best
, 0);
774 UNSET_FLAG(dmed_best
->flags
, BGP_PATH_MULTIPATH_CHG
);
775 UNSET_FLAG(dmed_best
->flags
, BGP_PATH_LINK_BW_CHG
);
776 assert(bgp_path_info_mpath_first(dmed_best
) == NULL
);
780 * bgp_path_info_mpath_aggregate_update
782 * Set the multipath aggregate attribute. We need to see if the
783 * aggregate has changed and then set the ATTR_CHANGED flag on the
784 * bestpath info so that a peer update will be generated. The
785 * change is detected by generating the current attribute,
786 * interning it, and then comparing the interned pointer with the
787 * current value. We can skip this generate/compare step if there
788 * is no change in multipath selection and no attribute change in
791 void bgp_path_info_mpath_aggregate_update(struct bgp_path_info
*new_best
,
792 struct bgp_path_info
*old_best
)
794 struct bgp_path_info
*mpinfo
;
795 struct aspath
*aspath
;
796 struct aspath
*asmerge
;
797 struct attr
*new_attr
, *old_attr
;
799 struct community
*community
, *commerge
;
800 struct ecommunity
*ecomm
, *ecommerge
;
801 struct lcommunity
*lcomm
, *lcommerge
;
802 struct attr attr
= {0};
804 if (old_best
&& (old_best
!= new_best
)
805 && (old_attr
= bgp_path_info_mpath_attr(old_best
))) {
806 bgp_attr_unintern(&old_attr
);
807 bgp_path_info_mpath_attr_set(old_best
, NULL
);
813 if (!bgp_path_info_mpath_count(new_best
)) {
814 if ((new_attr
= bgp_path_info_mpath_attr(new_best
))) {
815 bgp_attr_unintern(&new_attr
);
816 bgp_path_info_mpath_attr_set(new_best
, NULL
);
817 SET_FLAG(new_best
->flags
, BGP_PATH_ATTR_CHANGED
);
822 attr
= *new_best
->attr
;
825 && CHECK_FLAG(new_best
->peer
->bgp
->flags
,
826 BGP_FLAG_MULTIPATH_RELAX_AS_SET
)) {
828 /* aggregate attribute from multipath constituents */
829 aspath
= aspath_dup(attr
.aspath
);
830 origin
= attr
.origin
;
832 bgp_attr_get_community(&attr
)
833 ? community_dup(bgp_attr_get_community(&attr
))
835 ecomm
= (bgp_attr_get_ecommunity(&attr
))
836 ? ecommunity_dup(bgp_attr_get_ecommunity(&attr
))
838 lcomm
= (bgp_attr_get_lcommunity(&attr
))
839 ? lcommunity_dup(bgp_attr_get_lcommunity(&attr
))
842 for (mpinfo
= bgp_path_info_mpath_first(new_best
); mpinfo
;
843 mpinfo
= bgp_path_info_mpath_next(mpinfo
)) {
845 aspath_aggregate(aspath
, mpinfo
->attr
->aspath
);
849 if (origin
< mpinfo
->attr
->origin
)
850 origin
= mpinfo
->attr
->origin
;
852 if (bgp_attr_get_community(mpinfo
->attr
)) {
854 commerge
= community_merge(
856 bgp_attr_get_community(
859 community_uniq_sort(commerge
);
860 community_free(&commerge
);
862 community
= community_dup(
863 bgp_attr_get_community(
867 if (bgp_attr_get_ecommunity(mpinfo
->attr
)) {
869 ecommerge
= ecommunity_merge(
870 ecomm
, bgp_attr_get_ecommunity(
872 ecomm
= ecommunity_uniq_sort(ecommerge
);
873 ecommunity_free(&ecommerge
);
875 ecomm
= ecommunity_dup(
876 bgp_attr_get_ecommunity(
879 if (bgp_attr_get_lcommunity(mpinfo
->attr
)) {
881 lcommerge
= lcommunity_merge(
882 lcomm
, bgp_attr_get_lcommunity(
884 lcomm
= lcommunity_uniq_sort(lcommerge
);
885 lcommunity_free(&lcommerge
);
887 lcomm
= lcommunity_dup(
888 bgp_attr_get_lcommunity(
893 attr
.aspath
= aspath
;
894 attr
.origin
= origin
;
896 bgp_attr_set_community(&attr
, community
);
898 bgp_attr_set_ecommunity(&attr
, ecomm
);
900 bgp_attr_set_lcommunity(&attr
, lcomm
);
902 /* Zap multipath attr nexthop so we set nexthop to self */
903 attr
.nexthop
.s_addr
= INADDR_ANY
;
904 memset(&attr
.mp_nexthop_global
, 0, sizeof(struct in6_addr
));
906 /* TODO: should we set ATOMIC_AGGREGATE and AGGREGATOR? */
909 new_attr
= bgp_attr_intern(&attr
);
911 if (new_attr
!= bgp_path_info_mpath_attr(new_best
)) {
912 if ((old_attr
= bgp_path_info_mpath_attr(new_best
)))
913 bgp_attr_unintern(&old_attr
);
914 bgp_path_info_mpath_attr_set(new_best
, new_attr
);
915 SET_FLAG(new_best
->flags
, BGP_PATH_ATTR_CHANGED
);
917 bgp_attr_unintern(&new_attr
);