1 /* BGP Nexthop tracking
2 * Copyright (C) 2013 Cumulus Networks, Inc.
4 * This file is part of GNU Zebra.
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
35 #include "bgpd/bgpd.h"
36 #include "bgpd/bgp_table.h"
37 #include "bgpd/bgp_route.h"
38 #include "bgpd/bgp_attr.h"
39 #include "bgpd/bgp_nexthop.h"
40 #include "bgpd/bgp_debug.h"
41 #include "bgpd/bgp_errors.h"
42 #include "bgpd/bgp_nht.h"
43 #include "bgpd/bgp_fsm.h"
44 #include "bgpd/bgp_zebra.h"
46 extern struct zclient
*zclient
;
48 static void register_zebra_rnh(struct bgp_nexthop_cache
*bnc
,
49 int is_bgp_static_route
);
50 static void unregister_zebra_rnh(struct bgp_nexthop_cache
*bnc
,
51 int is_bgp_static_route
);
52 static void evaluate_paths(struct bgp_nexthop_cache
*bnc
);
53 static int make_prefix(int afi
, struct bgp_path_info
*pi
, struct prefix
*p
);
55 static int bgp_isvalid_nexthop(struct bgp_nexthop_cache
*bnc
)
57 return (bgp_zebra_num_connects() == 0
58 || (bnc
&& CHECK_FLAG(bnc
->flags
, BGP_NEXTHOP_VALID
)));
61 static int bgp_isvalid_labeled_nexthop(struct bgp_nexthop_cache
*bnc
)
63 return (bgp_zebra_num_connects() == 0
64 || (bnc
&& CHECK_FLAG(bnc
->flags
, BGP_NEXTHOP_LABELED_VALID
)));
67 int bgp_find_nexthop(struct bgp_path_info
*path
, int connected
)
69 struct bgp_nexthop_cache
*bnc
= path
->nexthop
;
75 * We are cheating here. Views have no associated underlying
76 * ability to detect nexthops. So when we have a view
77 * just tell everyone the nexthop is valid
79 if (path
->peer
&& path
->peer
->bgp
->inst_type
== BGP_INSTANCE_TYPE_VIEW
)
82 if (connected
&& !(CHECK_FLAG(bnc
->flags
, BGP_NEXTHOP_CONNECTED
)))
85 return (bgp_isvalid_nexthop(bnc
));
88 static void bgp_unlink_nexthop_check(struct bgp_nexthop_cache
*bnc
)
90 if (LIST_EMPTY(&(bnc
->paths
)) && !bnc
->nht_info
) {
91 if (BGP_DEBUG(nht
, NHT
)) {
92 char buf
[PREFIX2STR_BUFFER
];
93 zlog_debug("bgp_unlink_nexthop: freeing bnc %s",
94 bnc_str(bnc
, buf
, PREFIX2STR_BUFFER
));
96 unregister_zebra_rnh(bnc
,
97 CHECK_FLAG(bnc
->flags
, BGP_STATIC_ROUTE
));
98 bgp_nexthop_set_node_info(bnc
->node
, NULL
);
99 bgp_unlock_node(bnc
->node
);
105 void bgp_unlink_nexthop(struct bgp_path_info
*path
)
107 struct bgp_nexthop_cache
*bnc
= path
->nexthop
;
112 path_nh_map(path
, NULL
, false);
114 bgp_unlink_nexthop_check(bnc
);
117 void bgp_unlink_nexthop_by_peer(struct peer
*peer
)
121 struct bgp_nexthop_cache
*bnc
;
122 afi_t afi
= family2afi(peer
->su
.sa
.sa_family
);
124 if (!sockunion2hostprefix(&peer
->su
, &p
))
127 rn
= bgp_node_get(peer
->bgp
->nexthop_cache_table
[afi
], &p
);
129 bnc
= bgp_nexthop_get_node_info(rn
);
133 /* cleanup the peer reference */
134 bnc
->nht_info
= NULL
;
136 bgp_unlink_nexthop_check(bnc
);
140 * A route and its nexthop might belong to different VRFs. Therefore,
141 * we need both the bgp_route and bgp_nexthop pointers.
143 int bgp_find_or_add_nexthop(struct bgp
*bgp_route
, struct bgp
*bgp_nexthop
,
144 afi_t afi
, struct bgp_path_info
*pi
,
145 struct peer
*peer
, int connected
)
148 struct bgp_nexthop_cache
*bnc
;
150 int is_bgp_static_route
= 0;
153 is_bgp_static_route
= ((pi
->type
== ZEBRA_ROUTE_BGP
)
154 && (pi
->sub_type
== BGP_ROUTE_STATIC
))
158 /* Since Extended Next-hop Encoding (RFC5549) support, we want
160 address-family from the next-hop. */
161 if (!is_bgp_static_route
)
162 afi
= BGP_ATTR_NEXTHOP_AFI_IP6(pi
->attr
) ? AFI_IP6
165 /* This will return TRUE if the global IPv6 NH is a link local
167 if (make_prefix(afi
, pi
, &p
) < 0)
170 if (!sockunion2hostprefix(&peer
->su
, &p
)) {
171 if (BGP_DEBUG(nht
, NHT
)) {
173 "%s: Attempting to register with unknown AFI %d (not %d or %d)",
174 __FUNCTION__
, afi
, AFI_IP
, AFI_IP6
);
181 if (is_bgp_static_route
)
182 rn
= bgp_node_get(bgp_nexthop
->import_check_table
[afi
], &p
);
184 rn
= bgp_node_get(bgp_nexthop
->nexthop_cache_table
[afi
], &p
);
186 bnc
= bgp_nexthop_get_node_info(rn
);
189 bgp_nexthop_set_node_info(rn
, bnc
);
191 bnc
->bgp
= bgp_nexthop
;
193 if (BGP_DEBUG(nht
, NHT
)) {
194 char buf
[PREFIX2STR_BUFFER
];
196 zlog_debug("Allocated bnc %s peer %p",
197 bnc_str(bnc
, buf
, PREFIX2STR_BUFFER
), peer
);
202 if (is_bgp_static_route
) {
203 SET_FLAG(bnc
->flags
, BGP_STATIC_ROUTE
);
205 /* If we're toggling the type, re-register */
206 if ((bgp_flag_check(bgp_route
, BGP_FLAG_IMPORT_CHECK
))
207 && !CHECK_FLAG(bnc
->flags
, BGP_STATIC_ROUTE_EXACT_MATCH
)) {
208 SET_FLAG(bnc
->flags
, BGP_STATIC_ROUTE_EXACT_MATCH
);
209 UNSET_FLAG(bnc
->flags
, BGP_NEXTHOP_REGISTERED
);
210 UNSET_FLAG(bnc
->flags
, BGP_NEXTHOP_VALID
);
211 } else if ((!bgp_flag_check(bgp_route
, BGP_FLAG_IMPORT_CHECK
))
212 && CHECK_FLAG(bnc
->flags
,
213 BGP_STATIC_ROUTE_EXACT_MATCH
)) {
214 UNSET_FLAG(bnc
->flags
, BGP_STATIC_ROUTE_EXACT_MATCH
);
215 UNSET_FLAG(bnc
->flags
, BGP_NEXTHOP_REGISTERED
);
216 UNSET_FLAG(bnc
->flags
, BGP_NEXTHOP_VALID
);
219 /* When nexthop is already known, but now requires 'connected'
221 * re-register it. The reverse scenario where the nexthop currently
223 * 'connected' resolution does not need a re-register (i.e., we treat
224 * 'connected-required' as an override) except in the scenario where
226 * is actually a case of tracking a peer for connectivity (e.g., after
227 * disable connected-check).
228 * NOTE: We don't track the number of paths separately for 'connected-
229 * required' vs 'connected-not-required' as this change is not a common
232 else if (connected
&& !CHECK_FLAG(bnc
->flags
, BGP_NEXTHOP_CONNECTED
)) {
233 SET_FLAG(bnc
->flags
, BGP_NEXTHOP_CONNECTED
);
234 UNSET_FLAG(bnc
->flags
, BGP_NEXTHOP_REGISTERED
);
235 UNSET_FLAG(bnc
->flags
, BGP_NEXTHOP_VALID
);
236 } else if (peer
&& !connected
237 && CHECK_FLAG(bnc
->flags
, BGP_NEXTHOP_CONNECTED
)) {
238 UNSET_FLAG(bnc
->flags
, BGP_NEXTHOP_CONNECTED
);
239 UNSET_FLAG(bnc
->flags
, BGP_NEXTHOP_REGISTERED
);
240 UNSET_FLAG(bnc
->flags
, BGP_NEXTHOP_VALID
);
242 if (bgp_route
->inst_type
== BGP_INSTANCE_TYPE_VIEW
) {
243 bnc
->flags
|= BGP_NEXTHOP_REGISTERED
;
244 bnc
->flags
|= BGP_NEXTHOP_VALID
;
245 } else if (!CHECK_FLAG(bnc
->flags
, BGP_NEXTHOP_REGISTERED
))
246 register_zebra_rnh(bnc
, is_bgp_static_route
);
247 if (pi
&& pi
->nexthop
!= bnc
) {
248 /* Unlink from existing nexthop cache, if any. This will also
250 * the nexthop cache entry, if appropriate.
252 bgp_unlink_nexthop(pi
);
254 /* updates NHT pi list reference */
255 path_nh_map(pi
, bnc
, true);
257 if (CHECK_FLAG(bnc
->flags
, BGP_NEXTHOP_VALID
) && bnc
->metric
)
258 (bgp_path_info_extra_get(pi
))->igpmetric
= bnc
->metric
;
260 pi
->extra
->igpmetric
= 0;
262 bnc
->nht_info
= (void *)peer
; /* NHT peer reference */
265 * We are cheating here. Views have no associated underlying
266 * ability to detect nexthops. So when we have a view
267 * just tell everyone the nexthop is valid
269 if (bgp_route
->inst_type
== BGP_INSTANCE_TYPE_VIEW
)
272 return (bgp_isvalid_nexthop(bnc
));
275 void bgp_delete_connected_nexthop(afi_t afi
, struct peer
*peer
)
278 struct bgp_nexthop_cache
*bnc
;
284 if (!sockunion2hostprefix(&peer
->su
, &p
))
287 rn
= bgp_node_lookup(
288 peer
->bgp
->nexthop_cache_table
[family2afi(p
.family
)], &p
);
290 if (BGP_DEBUG(nht
, NHT
))
291 zlog_debug("Cannot find connected NHT node for peer %s",
296 bnc
= bgp_nexthop_get_node_info(rn
);
298 if (BGP_DEBUG(nht
, NHT
))
299 zlog_debug("Cannot find connected NHT node for peer %s on route_node as expected",
306 if (bnc
->nht_info
!= peer
) {
307 if (BGP_DEBUG(nht
, NHT
))
309 "Connected NHT %p node for peer %s points to %p",
310 bnc
, peer
->host
, bnc
->nht_info
);
314 bnc
->nht_info
= NULL
;
316 if (LIST_EMPTY(&(bnc
->paths
))) {
317 if (BGP_DEBUG(nht
, NHT
))
318 zlog_debug("Freeing connected NHT node %p for peer %s",
320 unregister_zebra_rnh(bnc
, 0);
321 bgp_nexthop_set_node_info(bnc
->node
, NULL
);
322 bgp_unlock_node(bnc
->node
);
327 void bgp_parse_nexthop_update(int command
, vrf_id_t vrf_id
)
329 struct bgp_node
*rn
= NULL
;
330 struct bgp_nexthop_cache
*bnc
;
331 struct nexthop
*nexthop
;
332 struct nexthop
*oldnh
;
333 struct nexthop
*nhlist_head
= NULL
;
334 struct nexthop
*nhlist_tail
= NULL
;
337 struct zapi_route nhr
;
339 bgp
= bgp_lookup_by_vrf_id(vrf_id
);
343 "parse nexthop update: instance not found for vrf_id %u",
348 if (!zapi_nexthop_update_decode(zclient
->ibuf
, &nhr
)) {
349 if (BGP_DEBUG(nht
, NHT
))
350 zlog_debug("%s: Failure to decode nexthop update",
351 __PRETTY_FUNCTION__
);
355 if (command
== ZEBRA_NEXTHOP_UPDATE
)
356 rn
= bgp_node_lookup(
357 bgp
->nexthop_cache_table
[family2afi(nhr
.prefix
.family
)],
359 else if (command
== ZEBRA_IMPORT_CHECK_UPDATE
)
360 rn
= bgp_node_lookup(
361 bgp
->import_check_table
[family2afi(nhr
.prefix
.family
)],
365 if (BGP_DEBUG(nht
, NHT
)) {
366 char buf
[PREFIX2STR_BUFFER
];
367 prefix2str(&nhr
.prefix
, buf
, sizeof(buf
));
368 zlog_debug("parse nexthop update(%s): rn not found",
374 bnc
= bgp_nexthop_get_node_info(rn
);
376 if (BGP_DEBUG(nht
, NHT
)) {
377 char buf
[PREFIX2STR_BUFFER
];
379 prefix2str(&nhr
.prefix
, buf
, sizeof(buf
));
380 zlog_debug("parse nexthop update(%s): bnc node info not found",
388 bnc
->last_update
= bgp_clock();
389 bnc
->change_flags
= 0;
391 /* debug print the input */
392 if (BGP_DEBUG(nht
, NHT
)) {
393 char buf
[PREFIX2STR_BUFFER
];
394 prefix2str(&nhr
.prefix
, buf
, sizeof(buf
));
396 "%u: Rcvd NH update %s - metric %d/%d #nhops %d/%d flags 0x%x",
397 vrf_id
, buf
, nhr
.metric
, bnc
->metric
, nhr
.nexthop_num
,
398 bnc
->nexthop_num
, bnc
->flags
);
401 if (nhr
.metric
!= bnc
->metric
)
402 bnc
->change_flags
|= BGP_NEXTHOP_METRIC_CHANGED
;
404 if (nhr
.nexthop_num
!= bnc
->nexthop_num
)
405 bnc
->change_flags
|= BGP_NEXTHOP_CHANGED
;
407 if (nhr
.nexthop_num
) {
408 struct peer
*peer
= bnc
->nht_info
;
410 /* notify bgp fsm if nbr ip goes from invalid->valid */
411 if (!bnc
->nexthop_num
)
412 UNSET_FLAG(bnc
->flags
, BGP_NEXTHOP_PEER_NOTIFIED
);
414 bnc
->flags
|= BGP_NEXTHOP_VALID
;
415 bnc
->metric
= nhr
.metric
;
416 bnc
->nexthop_num
= nhr
.nexthop_num
;
418 bnc
->flags
&= ~BGP_NEXTHOP_LABELED_VALID
; /* check below */
420 for (i
= 0; i
< nhr
.nexthop_num
; i
++) {
423 nexthop
= nexthop_from_zapi_nexthop(&nhr
.nexthops
[i
]);
426 * Turn on RA for the v6 nexthops
427 * we receive from bgp. This is to allow us
428 * to work with v4 routing over v6 nexthops
430 if (peer
&& !peer
->ifp
431 && CHECK_FLAG(peer
->flags
,
432 PEER_FLAG_CAPABILITY_ENHE
)
433 && nhr
.prefix
.family
== AF_INET6
) {
434 struct interface
*ifp
;
436 ifp
= if_lookup_by_index(nexthop
->ifindex
,
438 zclient_send_interface_radv_req(
439 zclient
, nexthop
->vrf_id
, ifp
, true,
440 BGP_UNNUM_DEFAULT_RA_INTERVAL
);
442 /* There is at least one label-switched path */
443 if (nexthop
->nh_label
&&
444 nexthop
->nh_label
->num_labels
) {
446 bnc
->flags
|= BGP_NEXTHOP_LABELED_VALID
;
447 num_labels
= nexthop
->nh_label
->num_labels
;
450 if (BGP_DEBUG(nht
, NHT
)) {
451 char buf
[NEXTHOP_STRLEN
];
453 " nhop via %s (%d labels)",
454 nexthop2str(nexthop
, buf
, sizeof(buf
)),
459 nhlist_tail
->next
= nexthop
;
460 nhlist_tail
= nexthop
;
462 nhlist_tail
= nexthop
;
463 nhlist_head
= nexthop
;
466 /* No need to evaluate the nexthop if we have already
468 * that there has been a change.
470 if (bnc
->change_flags
& BGP_NEXTHOP_CHANGED
)
473 for (oldnh
= bnc
->nexthop
; oldnh
; oldnh
= oldnh
->next
)
474 if (nexthop_same_no_recurse(oldnh
, nexthop
) &&
475 nexthop_labels_match(oldnh
, nexthop
))
479 bnc
->change_flags
|= BGP_NEXTHOP_CHANGED
;
481 bnc_nexthop_free(bnc
);
482 bnc
->nexthop
= nhlist_head
;
484 bnc
->flags
&= ~BGP_NEXTHOP_VALID
;
485 bnc
->nexthop_num
= nhr
.nexthop_num
;
487 /* notify bgp fsm if nbr ip goes from valid->invalid */
488 UNSET_FLAG(bnc
->flags
, BGP_NEXTHOP_PEER_NOTIFIED
);
490 bnc_nexthop_free(bnc
);
498 * Cleanup nexthop registration and status information for BGP nexthops
499 * pertaining to this VRF. This is invoked upon VRF deletion.
501 void bgp_cleanup_nexthops(struct bgp
*bgp
)
505 struct bgp_nexthop_cache
*bnc
;
507 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++) {
508 if (!bgp
->nexthop_cache_table
[afi
])
511 for (rn
= bgp_table_top(bgp
->nexthop_cache_table
[afi
]); rn
;
512 rn
= bgp_route_next(rn
)) {
513 bnc
= bgp_nexthop_get_node_info(rn
);
517 /* Clear relevant flags. */
518 UNSET_FLAG(bnc
->flags
, BGP_NEXTHOP_VALID
);
519 UNSET_FLAG(bnc
->flags
, BGP_NEXTHOP_REGISTERED
);
520 UNSET_FLAG(bnc
->flags
, BGP_NEXTHOP_PEER_NOTIFIED
);
526 * make_prefix - make a prefix structure from the path (essentially
529 static int make_prefix(int afi
, struct bgp_path_info
*pi
, struct prefix
*p
)
532 int is_bgp_static
= ((pi
->type
== ZEBRA_ROUTE_BGP
)
533 && (pi
->sub_type
== BGP_ROUTE_STATIC
))
537 memset(p
, 0, sizeof(struct prefix
));
542 p
->u
.prefix4
= pi
->net
->p
.u
.prefix4
;
543 p
->prefixlen
= pi
->net
->p
.prefixlen
;
545 p
->u
.prefix4
= pi
->attr
->nexthop
;
546 p
->prefixlen
= IPV4_MAX_BITLEN
;
550 p
->family
= AF_INET6
;
553 p
->u
.prefix6
= pi
->net
->p
.u
.prefix6
;
554 p
->prefixlen
= pi
->net
->p
.prefixlen
;
556 p
->u
.prefix6
= pi
->attr
->mp_nexthop_global
;
557 p
->prefixlen
= IPV6_MAX_BITLEN
;
561 if (BGP_DEBUG(nht
, NHT
)) {
563 "%s: Attempting to make prefix with unknown AFI %d (not %d or %d)",
564 __FUNCTION__
, afi
, AFI_IP
, AFI_IP6
);
572 * sendmsg_zebra_rnh -- Format and send a nexthop register/Unregister
575 * struct bgp_nexthop_cache *bnc -- the nexthop structure.
576 * int command -- command to send to zebra
580 static void sendmsg_zebra_rnh(struct bgp_nexthop_cache
*bnc
, int command
)
583 bool exact_match
= false;
589 /* Don't try to register if Zebra doesn't know of this instance. */
590 if (!IS_BGP_INST_KNOWN_TO_ZEBRA(bnc
->bgp
))
594 if ((command
== ZEBRA_NEXTHOP_REGISTER
595 || command
== ZEBRA_IMPORT_ROUTE_REGISTER
)
596 && (CHECK_FLAG(bnc
->flags
, BGP_NEXTHOP_CONNECTED
)
597 || CHECK_FLAG(bnc
->flags
, BGP_STATIC_ROUTE_EXACT_MATCH
)))
600 if (BGP_DEBUG(zebra
, ZEBRA
)) {
601 char buf
[PREFIX2STR_BUFFER
];
603 prefix2str(p
, buf
, PREFIX2STR_BUFFER
);
604 zlog_debug("%s: sending cmd %s for %s (vrf %s)",
605 __func__
, zserv_command_string(command
), buf
,
609 ret
= zclient_send_rnh(zclient
, command
, p
, exact_match
,
611 /* TBD: handle the failure */
613 flog_warn(EC_BGP_ZEBRA_SEND
,
614 "sendmsg_nexthop: zclient_send_message() failed");
616 if ((command
== ZEBRA_NEXTHOP_REGISTER
)
617 || (command
== ZEBRA_IMPORT_ROUTE_REGISTER
))
618 SET_FLAG(bnc
->flags
, BGP_NEXTHOP_REGISTERED
);
619 else if ((command
== ZEBRA_NEXTHOP_UNREGISTER
)
620 || (command
== ZEBRA_IMPORT_ROUTE_UNREGISTER
))
621 UNSET_FLAG(bnc
->flags
, BGP_NEXTHOP_REGISTERED
);
626 * register_zebra_rnh - register a NH/route with Zebra for notification
627 * when the route or the route to the nexthop changes.
629 * struct bgp_nexthop_cache *bnc
633 static void register_zebra_rnh(struct bgp_nexthop_cache
*bnc
,
634 int is_bgp_import_route
)
636 /* Check if we have already registered */
637 if (bnc
->flags
& BGP_NEXTHOP_REGISTERED
)
639 if (is_bgp_import_route
)
640 sendmsg_zebra_rnh(bnc
, ZEBRA_IMPORT_ROUTE_REGISTER
);
642 sendmsg_zebra_rnh(bnc
, ZEBRA_NEXTHOP_REGISTER
);
646 * unregister_zebra_rnh -- Unregister the route/nexthop from Zebra.
648 * struct bgp_nexthop_cache *bnc
652 static void unregister_zebra_rnh(struct bgp_nexthop_cache
*bnc
,
653 int is_bgp_import_route
)
655 /* Check if we have already registered */
656 if (!CHECK_FLAG(bnc
->flags
, BGP_NEXTHOP_REGISTERED
))
659 if (is_bgp_import_route
)
660 sendmsg_zebra_rnh(bnc
, ZEBRA_IMPORT_ROUTE_UNREGISTER
);
662 sendmsg_zebra_rnh(bnc
, ZEBRA_NEXTHOP_UNREGISTER
);
666 * evaluate_paths - Evaluate the paths/nets associated with a nexthop.
668 * struct bgp_nexthop_cache *bnc -- the nexthop structure.
672 static void evaluate_paths(struct bgp_nexthop_cache
*bnc
)
675 struct bgp_path_info
*path
;
677 struct peer
*peer
= (struct peer
*)bnc
->nht_info
;
678 struct bgp_table
*table
;
680 struct bgp
*bgp_path
;
682 if (BGP_DEBUG(nht
, NHT
)) {
683 char buf
[PREFIX2STR_BUFFER
];
684 bnc_str(bnc
, buf
, PREFIX2STR_BUFFER
);
686 "NH update for %s - flags 0x%x chgflags 0x%x - evaluate paths",
687 buf
, bnc
->flags
, bnc
->change_flags
);
690 LIST_FOREACH (path
, &(bnc
->paths
), nh_thread
) {
691 if (!(path
->type
== ZEBRA_ROUTE_BGP
692 && ((path
->sub_type
== BGP_ROUTE_NORMAL
)
693 || (path
->sub_type
== BGP_ROUTE_STATIC
)
694 || (path
->sub_type
== BGP_ROUTE_IMPORTED
))))
698 assert(rn
&& bgp_node_table(rn
));
699 afi
= family2afi(rn
->p
.family
);
700 table
= bgp_node_table(rn
);
704 * handle routes from other VRFs (they can have a
705 * nexthop in THIS VRF). bgp_path is the bgp instance
706 * that owns the route referencing this nexthop.
708 bgp_path
= table
->bgp
;
711 * Path becomes valid/invalid depending on whether the nexthop
712 * reachable/unreachable.
714 * In case of unicast routes that were imported from vpn
715 * and that have labels, they are valid only if there are
716 * nexthops with labels
719 int bnc_is_valid_nexthop
= 0;
721 if (safi
== SAFI_UNICAST
&&
722 path
->sub_type
== BGP_ROUTE_IMPORTED
&&
724 path
->extra
->num_labels
) {
726 bnc_is_valid_nexthop
=
727 bgp_isvalid_labeled_nexthop(bnc
) ? 1 : 0;
729 bnc_is_valid_nexthop
=
730 bgp_isvalid_nexthop(bnc
) ? 1 : 0;
733 if (BGP_DEBUG(nht
, NHT
)) {
734 char buf
[PREFIX_STRLEN
];
736 prefix2str(&rn
->p
, buf
, PREFIX_STRLEN
);
737 zlog_debug("%s: prefix %s (vrf %s) %svalid",
738 __func__
, buf
, bgp_path
->name
,
739 (bnc_is_valid_nexthop
? "" : "not "));
742 if ((CHECK_FLAG(path
->flags
, BGP_PATH_VALID
) ? 1 : 0)
743 != bnc_is_valid_nexthop
) {
744 if (CHECK_FLAG(path
->flags
, BGP_PATH_VALID
)) {
745 bgp_aggregate_decrement(bgp_path
, &rn
->p
,
747 bgp_path_info_unset_flag(rn
, path
,
750 bgp_path_info_set_flag(rn
, path
,
752 bgp_aggregate_increment(bgp_path
, &rn
->p
,
757 /* Copy the metric to the path. Will be used for bestpath
759 if (bgp_isvalid_nexthop(bnc
) && bnc
->metric
)
760 (bgp_path_info_extra_get(path
))->igpmetric
=
762 else if (path
->extra
)
763 path
->extra
->igpmetric
= 0;
765 if (CHECK_FLAG(bnc
->change_flags
, BGP_NEXTHOP_METRIC_CHANGED
)
766 || CHECK_FLAG(bnc
->change_flags
, BGP_NEXTHOP_CHANGED
))
767 SET_FLAG(path
->flags
, BGP_PATH_IGP_CHANGED
);
769 bgp_process(bgp_path
, rn
, afi
, safi
);
772 if (peer
&& !CHECK_FLAG(bnc
->flags
, BGP_NEXTHOP_PEER_NOTIFIED
)) {
773 if (BGP_DEBUG(nht
, NHT
))
774 zlog_debug("%s: Updating peer (%s) status with NHT",
775 __FUNCTION__
, peer
->host
);
776 bgp_fsm_nht_update(peer
, bgp_isvalid_nexthop(bnc
));
777 SET_FLAG(bnc
->flags
, BGP_NEXTHOP_PEER_NOTIFIED
);
780 RESET_FLAG(bnc
->change_flags
);
784 * path_nh_map - make or break path-to-nexthop association.
786 * path - pointer to the path structure
787 * bnc - pointer to the nexthop structure
788 * make - if set, make the association. if unset, just break the existing
791 void path_nh_map(struct bgp_path_info
*path
, struct bgp_nexthop_cache
*bnc
,
795 LIST_REMOVE(path
, nh_thread
);
796 path
->nexthop
->path_count
--;
797 path
->nexthop
= NULL
;
800 LIST_INSERT_HEAD(&(bnc
->paths
), path
, nh_thread
);
802 path
->nexthop
->path_count
++;