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
*ri
, struct prefix
*p
);
54 static void path_nh_map(struct bgp_path_info
*path
,
55 struct bgp_nexthop_cache
*bnc
, int keep
);
57 static int bgp_isvalid_nexthop(struct bgp_nexthop_cache
*bnc
)
59 return (bgp_zebra_num_connects() == 0
60 || (bnc
&& CHECK_FLAG(bnc
->flags
, BGP_NEXTHOP_VALID
)));
63 static int bgp_isvalid_labeled_nexthop(struct bgp_nexthop_cache
*bnc
)
65 return (bgp_zebra_num_connects() == 0
66 || (bnc
&& CHECK_FLAG(bnc
->flags
, BGP_NEXTHOP_LABELED_VALID
)));
69 int bgp_find_nexthop(struct bgp_path_info
*path
, int connected
)
71 struct bgp_nexthop_cache
*bnc
= path
->nexthop
;
77 * We are cheating here. Views have no associated underlying
78 * ability to detect nexthops. So when we have a view
79 * just tell everyone the nexthop is valid
81 if (path
->peer
&& path
->peer
->bgp
->inst_type
== BGP_INSTANCE_TYPE_VIEW
)
84 if (connected
&& !(CHECK_FLAG(bnc
->flags
, BGP_NEXTHOP_CONNECTED
)))
87 return (bgp_isvalid_nexthop(bnc
));
90 static void bgp_unlink_nexthop_check(struct bgp_nexthop_cache
*bnc
)
92 if (LIST_EMPTY(&(bnc
->paths
)) && !bnc
->nht_info
) {
93 if (BGP_DEBUG(nht
, NHT
)) {
94 char buf
[PREFIX2STR_BUFFER
];
95 zlog_debug("bgp_unlink_nexthop: freeing bnc %s",
96 bnc_str(bnc
, buf
, PREFIX2STR_BUFFER
));
98 unregister_zebra_rnh(bnc
,
99 CHECK_FLAG(bnc
->flags
, BGP_STATIC_ROUTE
));
100 bgp_nexthop_set_node_info(bnc
->node
, NULL
);
101 bgp_unlock_node(bnc
->node
);
107 void bgp_unlink_nexthop(struct bgp_path_info
*path
)
109 struct bgp_nexthop_cache
*bnc
= path
->nexthop
;
114 path_nh_map(path
, NULL
, 0);
116 bgp_unlink_nexthop_check(bnc
);
119 void bgp_unlink_nexthop_by_peer(struct peer
*peer
)
123 struct bgp_nexthop_cache
*bnc
;
124 afi_t afi
= family2afi(peer
->su
.sa
.sa_family
);
126 if (!sockunion2hostprefix(&peer
->su
, &p
))
129 rn
= bgp_node_get(peer
->bgp
->nexthop_cache_table
[afi
], &p
);
131 bnc
= bgp_nexthop_get_node_info(rn
);
135 /* cleanup the peer reference */
136 bnc
->nht_info
= NULL
;
138 bgp_unlink_nexthop_check(bnc
);
142 * A route and its nexthop might belong to different VRFs. Therefore,
143 * we need both the bgp_route and bgp_nexthop pointers.
145 int bgp_find_or_add_nexthop(struct bgp
*bgp_route
, struct bgp
*bgp_nexthop
,
146 afi_t afi
, struct bgp_path_info
*ri
,
147 struct peer
*peer
, int connected
)
150 struct bgp_nexthop_cache
*bnc
;
152 int is_bgp_static_route
= 0;
155 is_bgp_static_route
= ((ri
->type
== ZEBRA_ROUTE_BGP
)
156 && (ri
->sub_type
== BGP_ROUTE_STATIC
))
160 /* Since Extended Next-hop Encoding (RFC5549) support, we want
162 address-family from the next-hop. */
163 if (!is_bgp_static_route
)
164 afi
= BGP_ATTR_NEXTHOP_AFI_IP6(ri
->attr
) ? AFI_IP6
167 /* This will return TRUE if the global IPv6 NH is a link local
169 if (make_prefix(afi
, ri
, &p
) < 0)
172 if (!sockunion2hostprefix(&peer
->su
, &p
)) {
173 if (BGP_DEBUG(nht
, NHT
)) {
175 "%s: Attempting to register with unknown AFI %d (not %d or %d)",
176 __FUNCTION__
, afi
, AFI_IP
, AFI_IP6
);
183 if (is_bgp_static_route
)
184 rn
= bgp_node_get(bgp_nexthop
->import_check_table
[afi
], &p
);
186 rn
= bgp_node_get(bgp_nexthop
->nexthop_cache_table
[afi
], &p
);
188 bnc
= bgp_nexthop_get_node_info(rn
);
191 bgp_nexthop_set_node_info(rn
, bnc
);
193 bnc
->bgp
= bgp_nexthop
;
195 if (BGP_DEBUG(nht
, NHT
)) {
196 char buf
[PREFIX2STR_BUFFER
];
198 zlog_debug("Allocated bnc %s peer %p",
199 bnc_str(bnc
, buf
, PREFIX2STR_BUFFER
), peer
);
204 if (is_bgp_static_route
) {
205 SET_FLAG(bnc
->flags
, BGP_STATIC_ROUTE
);
207 /* If we're toggling the type, re-register */
208 if ((bgp_flag_check(bgp_route
, BGP_FLAG_IMPORT_CHECK
))
209 && !CHECK_FLAG(bnc
->flags
, BGP_STATIC_ROUTE_EXACT_MATCH
)) {
210 SET_FLAG(bnc
->flags
, BGP_STATIC_ROUTE_EXACT_MATCH
);
211 UNSET_FLAG(bnc
->flags
, BGP_NEXTHOP_REGISTERED
);
212 UNSET_FLAG(bnc
->flags
, BGP_NEXTHOP_VALID
);
213 } else if ((!bgp_flag_check(bgp_route
, BGP_FLAG_IMPORT_CHECK
))
214 && CHECK_FLAG(bnc
->flags
,
215 BGP_STATIC_ROUTE_EXACT_MATCH
)) {
216 UNSET_FLAG(bnc
->flags
, BGP_STATIC_ROUTE_EXACT_MATCH
);
217 UNSET_FLAG(bnc
->flags
, BGP_NEXTHOP_REGISTERED
);
218 UNSET_FLAG(bnc
->flags
, BGP_NEXTHOP_VALID
);
221 /* When nexthop is already known, but now requires 'connected'
223 * re-register it. The reverse scenario where the nexthop currently
225 * 'connected' resolution does not need a re-register (i.e., we treat
226 * 'connected-required' as an override) except in the scenario where
228 * is actually a case of tracking a peer for connectivity (e.g., after
229 * disable connected-check).
230 * NOTE: We don't track the number of paths separately for 'connected-
231 * required' vs 'connected-not-required' as this change is not a common
234 else if (connected
&& !CHECK_FLAG(bnc
->flags
, BGP_NEXTHOP_CONNECTED
)) {
235 SET_FLAG(bnc
->flags
, BGP_NEXTHOP_CONNECTED
);
236 UNSET_FLAG(bnc
->flags
, BGP_NEXTHOP_REGISTERED
);
237 UNSET_FLAG(bnc
->flags
, BGP_NEXTHOP_VALID
);
238 } else if (peer
&& !connected
239 && CHECK_FLAG(bnc
->flags
, BGP_NEXTHOP_CONNECTED
)) {
240 UNSET_FLAG(bnc
->flags
, BGP_NEXTHOP_CONNECTED
);
241 UNSET_FLAG(bnc
->flags
, BGP_NEXTHOP_REGISTERED
);
242 UNSET_FLAG(bnc
->flags
, BGP_NEXTHOP_VALID
);
244 if (bgp_route
->inst_type
== BGP_INSTANCE_TYPE_VIEW
) {
245 bnc
->flags
|= BGP_NEXTHOP_REGISTERED
;
246 bnc
->flags
|= BGP_NEXTHOP_VALID
;
247 } else if (!CHECK_FLAG(bnc
->flags
, BGP_NEXTHOP_REGISTERED
))
248 register_zebra_rnh(bnc
, is_bgp_static_route
);
249 if (ri
&& ri
->nexthop
!= bnc
) {
250 /* Unlink from existing nexthop cache, if any. This will also
252 * the nexthop cache entry, if appropriate.
254 bgp_unlink_nexthop(ri
);
256 path_nh_map(ri
, bnc
, 1); /* updates NHT ri list reference */
258 if (CHECK_FLAG(bnc
->flags
, BGP_NEXTHOP_VALID
) && bnc
->metric
)
259 (bgp_info_extra_get(ri
))->igpmetric
= bnc
->metric
;
261 ri
->extra
->igpmetric
= 0;
263 bnc
->nht_info
= (void *)peer
; /* NHT peer reference */
266 * We are cheating here. Views have no associated underlying
267 * ability to detect nexthops. So when we have a view
268 * just tell everyone the nexthop is valid
270 if (bgp_route
->inst_type
== BGP_INSTANCE_TYPE_VIEW
)
273 return (bgp_isvalid_nexthop(bnc
));
276 void bgp_delete_connected_nexthop(afi_t afi
, struct peer
*peer
)
279 struct bgp_nexthop_cache
*bnc
;
285 if (!sockunion2hostprefix(&peer
->su
, &p
))
288 rn
= bgp_node_lookup(
289 peer
->bgp
->nexthop_cache_table
[family2afi(p
.family
)], &p
);
291 if (BGP_DEBUG(nht
, NHT
))
292 zlog_debug("Cannot find connected NHT node for peer %s",
297 bnc
= bgp_nexthop_get_node_info(rn
);
299 if (BGP_DEBUG(nht
, NHT
))
300 zlog_debug("Cannot find connected NHT node for peer %s on route_node as expected",
307 if (bnc
->nht_info
!= peer
) {
308 if (BGP_DEBUG(nht
, NHT
))
310 "Connected NHT %p node for peer %s points to %p",
311 bnc
, peer
->host
, bnc
->nht_info
);
315 bnc
->nht_info
= NULL
;
317 if (LIST_EMPTY(&(bnc
->paths
))) {
318 if (BGP_DEBUG(nht
, NHT
))
319 zlog_debug("Freeing connected NHT node %p for peer %s",
321 unregister_zebra_rnh(bnc
, 0);
322 bgp_nexthop_set_node_info(bnc
->node
, NULL
);
323 bgp_unlock_node(bnc
->node
);
328 void bgp_parse_nexthop_update(int command
, vrf_id_t vrf_id
)
330 struct bgp_node
*rn
= NULL
;
331 struct bgp_nexthop_cache
*bnc
;
332 struct nexthop
*nexthop
;
333 struct nexthop
*oldnh
;
334 struct nexthop
*nhlist_head
= NULL
;
335 struct nexthop
*nhlist_tail
= NULL
;
338 struct zapi_route nhr
;
340 bgp
= bgp_lookup_by_vrf_id(vrf_id
);
344 "parse nexthop update: instance not found for vrf_id %u",
349 if (!zapi_nexthop_update_decode(zclient
->ibuf
, &nhr
)) {
350 if (BGP_DEBUG(nht
, NHT
))
351 zlog_debug("%s: Failure to decode nexthop update",
352 __PRETTY_FUNCTION__
);
356 if (command
== ZEBRA_NEXTHOP_UPDATE
)
357 rn
= bgp_node_lookup(
358 bgp
->nexthop_cache_table
[family2afi(nhr
.prefix
.family
)],
360 else if (command
== ZEBRA_IMPORT_CHECK_UPDATE
)
361 rn
= bgp_node_lookup(
362 bgp
->import_check_table
[family2afi(nhr
.prefix
.family
)],
366 if (BGP_DEBUG(nht
, NHT
)) {
367 char buf
[PREFIX2STR_BUFFER
];
368 prefix2str(&nhr
.prefix
, buf
, sizeof(buf
));
369 zlog_debug("parse nexthop update(%s): rn not found",
375 bnc
= bgp_nexthop_get_node_info(rn
);
377 if (BGP_DEBUG(nht
, NHT
)) {
378 char buf
[PREFIX2STR_BUFFER
];
380 prefix2str(&nhr
.prefix
, buf
, sizeof(buf
));
381 zlog_debug("parse nexthop update(%s): bnc node info not found",
389 bnc
->last_update
= bgp_clock();
390 bnc
->change_flags
= 0;
392 /* debug print the input */
393 if (BGP_DEBUG(nht
, NHT
)) {
394 char buf
[PREFIX2STR_BUFFER
];
395 prefix2str(&nhr
.prefix
, buf
, sizeof(buf
));
397 "%u: Rcvd NH update %s - metric %d/%d #nhops %d/%d flags 0x%x",
398 vrf_id
, buf
, nhr
.metric
, bnc
->metric
, nhr
.nexthop_num
,
399 bnc
->nexthop_num
, bnc
->flags
);
402 if (nhr
.metric
!= bnc
->metric
)
403 bnc
->change_flags
|= BGP_NEXTHOP_METRIC_CHANGED
;
405 if (nhr
.nexthop_num
!= bnc
->nexthop_num
)
406 bnc
->change_flags
|= BGP_NEXTHOP_CHANGED
;
408 if (nhr
.nexthop_num
) {
409 struct peer
*peer
= bnc
->nht_info
;
411 /* notify bgp fsm if nbr ip goes from invalid->valid */
412 if (!bnc
->nexthop_num
)
413 UNSET_FLAG(bnc
->flags
, BGP_NEXTHOP_PEER_NOTIFIED
);
415 bnc
->flags
|= BGP_NEXTHOP_VALID
;
416 bnc
->metric
= nhr
.metric
;
417 bnc
->nexthop_num
= nhr
.nexthop_num
;
419 bnc
->flags
&= ~BGP_NEXTHOP_LABELED_VALID
; /* check below */
421 for (i
= 0; i
< nhr
.nexthop_num
; i
++) {
424 nexthop
= nexthop_from_zapi_nexthop(&nhr
.nexthops
[i
]);
427 * Turn on RA for the v6 nexthops
428 * we receive from bgp. This is to allow us
429 * to work with v4 routing over v6 nexthops
431 if (peer
&& !peer
->ifp
432 && CHECK_FLAG(peer
->flags
,
433 PEER_FLAG_CAPABILITY_ENHE
)
434 && nhr
.prefix
.family
== AF_INET6
) {
435 struct interface
*ifp
;
437 ifp
= if_lookup_by_index(nexthop
->ifindex
,
439 zclient_send_interface_radv_req(
440 zclient
, nexthop
->vrf_id
, ifp
, true,
441 BGP_UNNUM_DEFAULT_RA_INTERVAL
);
443 /* There is at least one label-switched path */
444 if (nexthop
->nh_label
&&
445 nexthop
->nh_label
->num_labels
) {
447 bnc
->flags
|= BGP_NEXTHOP_LABELED_VALID
;
448 num_labels
= nexthop
->nh_label
->num_labels
;
451 if (BGP_DEBUG(nht
, NHT
)) {
452 char buf
[NEXTHOP_STRLEN
];
454 " nhop via %s (%d labels)",
455 nexthop2str(nexthop
, buf
, sizeof(buf
)),
460 nhlist_tail
->next
= nexthop
;
461 nhlist_tail
= nexthop
;
463 nhlist_tail
= nexthop
;
464 nhlist_head
= nexthop
;
467 /* No need to evaluate the nexthop if we have already
469 * that there has been a change.
471 if (bnc
->change_flags
& BGP_NEXTHOP_CHANGED
)
474 for (oldnh
= bnc
->nexthop
; oldnh
; oldnh
= oldnh
->next
)
475 if (nexthop_same_no_recurse(oldnh
, nexthop
) &&
476 nexthop_labels_match(oldnh
, nexthop
))
480 bnc
->change_flags
|= BGP_NEXTHOP_CHANGED
;
482 bnc_nexthop_free(bnc
);
483 bnc
->nexthop
= nhlist_head
;
485 bnc
->flags
&= ~BGP_NEXTHOP_VALID
;
486 bnc
->nexthop_num
= nhr
.nexthop_num
;
488 /* notify bgp fsm if nbr ip goes from valid->invalid */
489 UNSET_FLAG(bnc
->flags
, BGP_NEXTHOP_PEER_NOTIFIED
);
491 bnc_nexthop_free(bnc
);
499 * Cleanup nexthop registration and status information for BGP nexthops
500 * pertaining to this VRF. This is invoked upon VRF deletion.
502 void bgp_cleanup_nexthops(struct bgp
*bgp
)
506 struct bgp_nexthop_cache
*bnc
;
508 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++) {
509 if (!bgp
->nexthop_cache_table
[afi
])
512 for (rn
= bgp_table_top(bgp
->nexthop_cache_table
[afi
]); rn
;
513 rn
= bgp_route_next(rn
)) {
514 bnc
= bgp_nexthop_get_node_info(rn
);
518 /* Clear relevant flags. */
519 UNSET_FLAG(bnc
->flags
, BGP_NEXTHOP_VALID
);
520 UNSET_FLAG(bnc
->flags
, BGP_NEXTHOP_REGISTERED
);
521 UNSET_FLAG(bnc
->flags
, BGP_NEXTHOP_PEER_NOTIFIED
);
527 * make_prefix - make a prefix structure from the path (essentially
530 static int make_prefix(int afi
, struct bgp_path_info
*ri
, struct prefix
*p
)
533 int is_bgp_static
= ((ri
->type
== ZEBRA_ROUTE_BGP
)
534 && (ri
->sub_type
== BGP_ROUTE_STATIC
))
538 memset(p
, 0, sizeof(struct prefix
));
543 p
->u
.prefix4
= ri
->net
->p
.u
.prefix4
;
544 p
->prefixlen
= ri
->net
->p
.prefixlen
;
546 p
->u
.prefix4
= ri
->attr
->nexthop
;
547 p
->prefixlen
= IPV4_MAX_BITLEN
;
551 p
->family
= AF_INET6
;
554 p
->u
.prefix6
= ri
->net
->p
.u
.prefix6
;
555 p
->prefixlen
= ri
->net
->p
.prefixlen
;
557 p
->u
.prefix6
= ri
->attr
->mp_nexthop_global
;
558 p
->prefixlen
= IPV6_MAX_BITLEN
;
562 if (BGP_DEBUG(nht
, NHT
)) {
564 "%s: Attempting to make prefix with unknown AFI %d (not %d or %d)",
565 __FUNCTION__
, afi
, AFI_IP
, AFI_IP6
);
573 * sendmsg_zebra_rnh -- Format and send a nexthop register/Unregister
576 * struct bgp_nexthop_cache *bnc -- the nexthop structure.
577 * int command -- command to send to zebra
581 static void sendmsg_zebra_rnh(struct bgp_nexthop_cache
*bnc
, int command
)
584 bool exact_match
= false;
590 /* Don't try to register if Zebra doesn't know of this instance. */
591 if (!IS_BGP_INST_KNOWN_TO_ZEBRA(bnc
->bgp
))
595 if ((command
== ZEBRA_NEXTHOP_REGISTER
596 || command
== ZEBRA_IMPORT_ROUTE_REGISTER
)
597 && (CHECK_FLAG(bnc
->flags
, BGP_NEXTHOP_CONNECTED
)
598 || CHECK_FLAG(bnc
->flags
, BGP_STATIC_ROUTE_EXACT_MATCH
)))
601 if (BGP_DEBUG(zebra
, ZEBRA
)) {
602 char buf
[PREFIX2STR_BUFFER
];
604 prefix2str(p
, buf
, PREFIX2STR_BUFFER
);
605 zlog_debug("%s: sending cmd %s for %s (vrf %s)",
606 __func__
, zserv_command_string(command
), buf
,
610 ret
= zclient_send_rnh(zclient
, command
, p
, exact_match
,
612 /* TBD: handle the failure */
614 flog_warn(EC_BGP_ZEBRA_SEND
,
615 "sendmsg_nexthop: zclient_send_message() failed");
617 if ((command
== ZEBRA_NEXTHOP_REGISTER
)
618 || (command
== ZEBRA_IMPORT_ROUTE_REGISTER
))
619 SET_FLAG(bnc
->flags
, BGP_NEXTHOP_REGISTERED
);
620 else if ((command
== ZEBRA_NEXTHOP_UNREGISTER
)
621 || (command
== ZEBRA_IMPORT_ROUTE_UNREGISTER
))
622 UNSET_FLAG(bnc
->flags
, BGP_NEXTHOP_REGISTERED
);
627 * register_zebra_rnh - register a NH/route with Zebra for notification
628 * when the route or the route to the nexthop changes.
630 * struct bgp_nexthop_cache *bnc
634 static void register_zebra_rnh(struct bgp_nexthop_cache
*bnc
,
635 int is_bgp_import_route
)
637 /* Check if we have already registered */
638 if (bnc
->flags
& BGP_NEXTHOP_REGISTERED
)
640 if (is_bgp_import_route
)
641 sendmsg_zebra_rnh(bnc
, ZEBRA_IMPORT_ROUTE_REGISTER
);
643 sendmsg_zebra_rnh(bnc
, ZEBRA_NEXTHOP_REGISTER
);
647 * unregister_zebra_rnh -- Unregister the route/nexthop from Zebra.
649 * struct bgp_nexthop_cache *bnc
653 static void unregister_zebra_rnh(struct bgp_nexthop_cache
*bnc
,
654 int is_bgp_import_route
)
656 /* Check if we have already registered */
657 if (!CHECK_FLAG(bnc
->flags
, BGP_NEXTHOP_REGISTERED
))
660 if (is_bgp_import_route
)
661 sendmsg_zebra_rnh(bnc
, ZEBRA_IMPORT_ROUTE_UNREGISTER
);
663 sendmsg_zebra_rnh(bnc
, ZEBRA_NEXTHOP_UNREGISTER
);
667 * evaluate_paths - Evaluate the paths/nets associated with a nexthop.
669 * struct bgp_nexthop_cache *bnc -- the nexthop structure.
673 static void evaluate_paths(struct bgp_nexthop_cache
*bnc
)
676 struct bgp_path_info
*path
;
678 struct peer
*peer
= (struct peer
*)bnc
->nht_info
;
679 struct bgp_table
*table
;
681 struct bgp
*bgp_path
;
683 if (BGP_DEBUG(nht
, NHT
)) {
684 char buf
[PREFIX2STR_BUFFER
];
685 bnc_str(bnc
, buf
, PREFIX2STR_BUFFER
);
687 "NH update for %s - flags 0x%x chgflags 0x%x - evaluate paths",
688 buf
, bnc
->flags
, bnc
->change_flags
);
691 LIST_FOREACH (path
, &(bnc
->paths
), nh_thread
) {
692 if (!(path
->type
== ZEBRA_ROUTE_BGP
693 && ((path
->sub_type
== BGP_ROUTE_NORMAL
)
694 || (path
->sub_type
== BGP_ROUTE_STATIC
)
695 || (path
->sub_type
== BGP_ROUTE_IMPORTED
))))
699 assert(rn
&& bgp_node_table(rn
));
700 afi
= family2afi(rn
->p
.family
);
701 table
= bgp_node_table(rn
);
705 * handle routes from other VRFs (they can have a
706 * nexthop in THIS VRF). bgp_path is the bgp instance
707 * that owns the route referencing this nexthop.
709 bgp_path
= table
->bgp
;
712 * Path becomes valid/invalid depending on whether the nexthop
713 * reachable/unreachable.
715 * In case of unicast routes that were imported from vpn
716 * and that have labels, they are valid only if there are
717 * nexthops with labels
720 int bnc_is_valid_nexthop
= 0;
722 if (safi
== SAFI_UNICAST
&&
723 path
->sub_type
== BGP_ROUTE_IMPORTED
&&
725 path
->extra
->num_labels
) {
727 bnc_is_valid_nexthop
=
728 bgp_isvalid_labeled_nexthop(bnc
) ? 1 : 0;
730 bnc_is_valid_nexthop
=
731 bgp_isvalid_nexthop(bnc
) ? 1 : 0;
734 if (BGP_DEBUG(nht
, NHT
)) {
735 char buf
[PREFIX_STRLEN
];
737 prefix2str(&rn
->p
, buf
, PREFIX_STRLEN
);
738 zlog_debug("%s: prefix %s (vrf %s) %svalid",
739 __func__
, buf
, bgp_path
->name
,
740 (bnc_is_valid_nexthop
? "" : "not "));
743 if ((CHECK_FLAG(path
->flags
, BGP_PATH_VALID
) ? 1 : 0)
744 != bnc_is_valid_nexthop
) {
745 if (CHECK_FLAG(path
->flags
, BGP_PATH_VALID
)) {
746 bgp_aggregate_decrement(bgp_path
, &rn
->p
,
748 bgp_info_unset_flag(rn
, path
, BGP_PATH_VALID
);
750 bgp_info_set_flag(rn
, path
, BGP_PATH_VALID
);
751 bgp_aggregate_increment(bgp_path
, &rn
->p
,
756 /* Copy the metric to the path. Will be used for bestpath
758 if (bgp_isvalid_nexthop(bnc
) && bnc
->metric
)
759 (bgp_info_extra_get(path
))->igpmetric
= bnc
->metric
;
760 else if (path
->extra
)
761 path
->extra
->igpmetric
= 0;
763 if (CHECK_FLAG(bnc
->change_flags
, BGP_NEXTHOP_METRIC_CHANGED
)
764 || CHECK_FLAG(bnc
->change_flags
, BGP_NEXTHOP_CHANGED
))
765 SET_FLAG(path
->flags
, BGP_PATH_IGP_CHANGED
);
767 bgp_process(bgp_path
, rn
, afi
, safi
);
770 if (peer
&& !CHECK_FLAG(bnc
->flags
, BGP_NEXTHOP_PEER_NOTIFIED
)) {
771 if (BGP_DEBUG(nht
, NHT
))
772 zlog_debug("%s: Updating peer (%s) status with NHT",
773 __FUNCTION__
, peer
->host
);
774 bgp_fsm_nht_update(peer
, bgp_isvalid_nexthop(bnc
));
775 SET_FLAG(bnc
->flags
, BGP_NEXTHOP_PEER_NOTIFIED
);
778 RESET_FLAG(bnc
->change_flags
);
782 * path_nh_map - make or break path-to-nexthop association.
784 * path - pointer to the path structure
785 * bnc - pointer to the nexthop structure
786 * make - if set, make the association. if unset, just break the existing
789 static void path_nh_map(struct bgp_path_info
*path
,
790 struct bgp_nexthop_cache
*bnc
, int make
)
793 LIST_REMOVE(path
, nh_thread
);
794 path
->nexthop
->path_count
--;
795 path
->nexthop
= NULL
;
798 LIST_INSERT_HEAD(&(bnc
->paths
), path
, nh_thread
);
800 path
->nexthop
->path_count
++;