1 /* Zebra next hop tracking code
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
17 * along with GNU Zebra; see the file COPYING. If not, write to the Free
18 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
31 #include "sockunion.h"
34 #include "workqueue.h"
41 #include "zebra/rib.h"
43 #include "zebra/zserv.h"
44 #include "zebra/zebra_ns.h"
45 #include "zebra/zebra_vrf.h"
46 #include "zebra/redistribute.h"
47 #include "zebra/debug.h"
48 #include "zebra/zebra_rnh.h"
49 #include "zebra/zebra_routemap.h"
50 #include "zebra/interface.h"
51 #include "zebra/zebra_memory.h"
53 static void free_state(vrf_id_t vrf_id
, struct rib
*rib
, struct route_node
*rn
);
54 static void copy_state(struct rnh
*rnh
, struct rib
*rib
,
55 struct route_node
*rn
);
56 #define lookup_rnh_table(v, f) \
58 struct zebra_vrf *zvrf; \
59 struct route_table *t = NULL; \
60 zvrf = zebra_vrf_lookup(v); \
62 t = zvrf->rnh_table[family2afi(f)]; \
66 static int compare_state(struct rib
*r1
, struct rib
*r2
);
67 static int send_client(struct rnh
*rnh
, struct zserv
*client
, rnh_type_t type
,
69 static void print_rnh(struct route_node
*rn
, struct vty
*vty
);
71 int zebra_rnh_ip_default_route
= 0;
72 int zebra_rnh_ipv6_default_route
= 0;
74 static inline struct route_table
*get_rnh_table(vrf_id_t vrfid
, int family
,
77 struct zebra_vrf
*zvrf
;
78 struct route_table
*t
= NULL
;
80 zvrf
= zebra_vrf_lookup(vrfid
);
84 case RNH_NEXTHOP_TYPE
:
85 t
= zvrf
->rnh_table
[family2afi(family
)];
87 case RNH_IMPORT_CHECK_TYPE
:
88 t
= zvrf
->import_check_table
[family2afi(family
)];
95 char *rnh_str (struct rnh
*rnh
, char *buf
, int size
)
97 prefix2str(&(rnh
->node
->p
), buf
, size
);
102 zebra_add_rnh (struct prefix
*p
, vrf_id_t vrfid
, rnh_type_t type
)
104 struct route_table
*table
;
105 struct route_node
*rn
;
106 struct rnh
*rnh
= NULL
;
107 char buf
[PREFIX2STR_BUFFER
];
109 if (IS_ZEBRA_DEBUG_NHT
)
111 prefix2str(p
, buf
, sizeof (buf
));
112 zlog_debug("%u: Add RNH %s type %d", vrfid
, buf
, type
);
114 table
= get_rnh_table(vrfid
, PREFIX_FAMILY(p
), type
);
117 prefix2str(p
, buf
, sizeof (buf
));
118 zlog_warn("%u: Add RNH %s type %d - table not found",
123 /* Make it sure prefixlen is applied to the prefix. */
126 /* Lookup (or add) route node.*/
127 rn
= route_node_get (table
, p
);
131 rnh
= XCALLOC(MTYPE_RNH
, sizeof(struct rnh
));
132 rnh
->client_list
= list_new();
134 rnh
->zebra_static_route_list
= list_new();
135 route_lock_node (rn
);
140 route_unlock_node (rn
);
145 zebra_lookup_rnh (struct prefix
*p
, vrf_id_t vrfid
, rnh_type_t type
)
147 struct route_table
*table
;
148 struct route_node
*rn
;
150 table
= get_rnh_table(vrfid
, PREFIX_FAMILY(p
), type
);
154 /* Make it sure prefixlen is applied to the prefix. */
157 /* Lookup route node.*/
158 rn
= route_node_lookup (table
, p
);
162 route_unlock_node (rn
);
167 zebra_delete_rnh (struct rnh
*rnh
, rnh_type_t type
)
169 struct route_node
*rn
;
171 if (!rnh
|| (rnh
->flags
& ZEBRA_NHT_DELETED
) || !(rn
= rnh
->node
))
174 if (IS_ZEBRA_DEBUG_NHT
)
176 char buf
[PREFIX2STR_BUFFER
];
177 zlog_debug("%u: Del RNH %s type %d",
178 rnh
->vrf_id
, rnh_str(rnh
, buf
, sizeof (buf
)), type
);
181 rnh
->flags
|= ZEBRA_NHT_DELETED
;
182 list_free(rnh
->client_list
);
183 list_free(rnh
->zebra_static_route_list
);
184 free_state(rnh
->vrf_id
, rnh
->state
, rn
);
185 XFREE(MTYPE_RNH
, rn
->info
);
187 route_unlock_node (rn
);
192 zebra_add_rnh_client (struct rnh
*rnh
, struct zserv
*client
, rnh_type_t type
,
195 if (IS_ZEBRA_DEBUG_NHT
)
197 char buf
[PREFIX2STR_BUFFER
];
198 zlog_debug("%u: Client %s registers for RNH %s type %d",
199 vrf_id
, zebra_route_string(client
->proto
),
200 rnh_str(rnh
, buf
, sizeof (buf
)), type
);
202 if (!listnode_lookup(rnh
->client_list
, client
))
204 listnode_add(rnh
->client_list
, client
);
205 send_client(rnh
, client
, type
, vrf_id
); // Pending: check if its needed
210 zebra_remove_rnh_client (struct rnh
*rnh
, struct zserv
*client
, rnh_type_t type
)
212 if (IS_ZEBRA_DEBUG_NHT
)
214 char buf
[PREFIX2STR_BUFFER
];
215 zlog_debug("Client %s unregisters for RNH %s type %d",
216 zebra_route_string(client
->proto
),
217 rnh_str(rnh
, buf
, sizeof (buf
)), type
);
219 listnode_delete(rnh
->client_list
, client
);
220 if (list_isempty(rnh
->client_list
) &&
221 list_isempty(rnh
->zebra_static_route_list
))
222 zebra_delete_rnh(rnh
, type
);
226 zebra_register_rnh_static_nh(vrf_id_t vrf_id
, struct prefix
*nh
,
227 struct route_node
*static_rn
)
231 rnh
= zebra_add_rnh(nh
, vrf_id
, RNH_NEXTHOP_TYPE
);
232 if (rnh
&& !listnode_lookup(rnh
->zebra_static_route_list
, static_rn
))
234 listnode_add(rnh
->zebra_static_route_list
, static_rn
);
239 zebra_deregister_rnh_static_nh(vrf_id_t vrf_id
, struct prefix
*nh
,
240 struct route_node
*static_rn
)
244 rnh
= zebra_lookup_rnh(nh
, vrf_id
, RNH_NEXTHOP_TYPE
);
245 if (!rnh
|| (rnh
->flags
& ZEBRA_NHT_DELETED
))
248 listnode_delete(rnh
->zebra_static_route_list
, static_rn
);
250 if (list_isempty(rnh
->client_list
) &&
251 list_isempty(rnh
->zebra_static_route_list
))
252 zebra_delete_rnh(rnh
, RNH_NEXTHOP_TYPE
);
256 zebra_deregister_rnh_static_nexthops (vrf_id_t vrf_id
, struct nexthop
*nexthop
,
257 struct route_node
*rn
)
262 for (nh
= nexthop
; nh
; nh
= nh
->next
)
266 case NEXTHOP_TYPE_IPV4
:
267 case NEXTHOP_TYPE_IPV4_IFINDEX
:
268 nh_p
.family
= AF_INET
;
269 nh_p
.prefixlen
= IPV4_MAX_BITLEN
;
270 nh_p
.u
.prefix4
= nh
->gate
.ipv4
;
272 case NEXTHOP_TYPE_IPV6
:
273 case NEXTHOP_TYPE_IPV6_IFINDEX
:
274 nh_p
.family
= AF_INET6
;
275 nh_p
.prefixlen
= IPV6_MAX_BITLEN
;
276 nh_p
.u
.prefix6
= nh
->gate
.ipv6
;
279 * Not sure what really to do here, we are not
280 * supposed to have either of these for NHT
281 * and the code has no way to know what prefix
282 * to use. So I'm going to just continue
283 * for the moment, which is preferable to
284 * what is currently happening which is a
286 * Some simple testing shows that we
287 * are not leaving slag around for these
288 * skipped static routes. Since
289 * they don't appear to be installed
291 case NEXTHOP_TYPE_IFINDEX
:
292 case NEXTHOP_TYPE_BLACKHOLE
:
296 zebra_deregister_rnh_static_nh(vrf_id
, &nh_p
, rn
);
300 /* Apply the NHT route-map for a client to the route (and nexthops)
304 zebra_rnh_apply_nht_rmap(int family
, struct route_node
*prn
,
305 struct rib
*rib
, int proto
)
307 int at_least_one
= 0;
308 int rmap_family
; /* Route map has diff AF family enum */
309 struct nexthop
*nexthop
;
312 rmap_family
= (family
== AF_INET
) ? AFI_IP
: AFI_IP6
;
316 for (nexthop
= rib
->nexthop
; nexthop
; nexthop
= nexthop
->next
)
318 ret
= zebra_nht_route_map_check(rmap_family
, proto
, &prn
->p
, rib
,
320 if (ret
!= RMAP_DENYMATCH
)
322 SET_FLAG (nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
323 at_least_one
++; /* at least one valid NH */
327 UNSET_FLAG (nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
331 return (at_least_one
);
335 * Determine appropriate route (RIB entry) resolving a tracked entry
336 * (nexthop or BGP route for import).
339 zebra_rnh_resolve_entry (vrf_id_t vrfid
, int family
, rnh_type_t type
,
340 struct route_node
*nrn
, struct rnh
*rnh
,
341 struct route_node
**prn
)
343 struct route_table
*route_table
;
344 struct route_node
*rn
;
349 route_table
= zebra_vrf_table(family2afi(family
), SAFI_UNICAST
, vrfid
);
350 if (!route_table
) // unexpected
353 rn
= route_node_match(route_table
, &nrn
->p
);
357 /* When resolving nexthops, do not resolve via the default route unless
358 * 'ip nht resolve-via-default' is configured.
360 if ((type
== RNH_NEXTHOP_TYPE
) &&
361 (is_default_prefix (&rn
->p
) &&
362 !nh_resolve_via_default(rn
->p
.family
)))
364 else if ((type
== RNH_IMPORT_CHECK_TYPE
) &&
365 CHECK_FLAG(rnh
->flags
, ZEBRA_NHT_EXACT_MATCH
) &&
366 !prefix_same(&nrn
->p
, &rn
->p
))
370 /* Identify appropriate route entry. */
371 RNODE_FOREACH_RIB(rn
, rib
)
373 if (CHECK_FLAG (rib
->status
, RIB_ENTRY_REMOVED
))
375 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_SELECTED
))
377 if (CHECK_FLAG(rnh
->flags
, ZEBRA_NHT_CONNECTED
))
379 if (rib
->type
== ZEBRA_ROUTE_CONNECT
)
382 else if ((type
== RNH_IMPORT_CHECK_TYPE
) &&
383 (rib
->type
== ZEBRA_ROUTE_BGP
))
391 /* Need to unlock route node */
392 route_unlock_node(rn
);
399 * See if a tracked route entry for import (by BGP) has undergone any
400 * change, and if so, notify the client.
403 zebra_rnh_eval_import_check_entry (vrf_id_t vrfid
, int family
, int force
,
404 struct route_node
*nrn
, struct rnh
*rnh
,
407 int state_changed
= 0;
408 struct zserv
*client
;
409 char bufn
[INET6_ADDRSTRLEN
];
410 struct listnode
*node
;
411 struct nexthop
*nexthop
, *tnexthop
;
414 if (rib
&& (rnh
->state
== NULL
))
416 for (ALL_NEXTHOPS_RO(rib
->nexthop
, nexthop
, tnexthop
, recursing
))
417 if (CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_FIB
))
423 else if (!rib
&& (rnh
->state
!= NULL
))
426 if (compare_state(rib
, rnh
->state
))
427 copy_state(rnh
, rib
, nrn
);
429 if (state_changed
|| force
)
431 if (IS_ZEBRA_DEBUG_NHT
)
433 prefix2str(&nrn
->p
, bufn
, INET6_ADDRSTRLEN
);
434 zlog_debug("%u:%s: Route import check %s %s\n",
435 vrfid
, bufn
, rnh
->state
? "passed" : "failed",
436 state_changed
? "(state changed)" : "");
438 /* state changed, notify clients */
439 for (ALL_LIST_ELEMENTS_RO(rnh
->client_list
, node
, client
))
441 send_client(rnh
, client
, RNH_IMPORT_CHECK_TYPE
, vrfid
);
447 * Notify clients registered for this nexthop about a change.
450 zebra_rnh_notify_protocol_clients (vrf_id_t vrfid
, int family
,
451 struct route_node
*nrn
, struct rnh
*rnh
,
452 struct route_node
*prn
, struct rib
*rib
)
454 struct listnode
*node
;
455 struct zserv
*client
;
456 char bufn
[INET6_ADDRSTRLEN
];
457 char bufp
[INET6_ADDRSTRLEN
];
458 int num_resolving_nh
;
460 if (IS_ZEBRA_DEBUG_NHT
)
462 prefix2str(&nrn
->p
, bufn
, INET6_ADDRSTRLEN
);
465 prefix2str(&prn
->p
, bufp
, INET6_ADDRSTRLEN
);
466 zlog_debug("%u:%s: NH resolved over route %s", vrfid
, bufn
, bufp
);
469 zlog_debug("%u:%s: NH has become unresolved", vrfid
, bufn
);
472 for (ALL_LIST_ELEMENTS_RO(rnh
->client_list
, node
, client
))
476 /* Apply route-map for this client to route resolving this
477 * nexthop to see if it is filtered or not.
479 num_resolving_nh
= zebra_rnh_apply_nht_rmap(family
, prn
, rib
,
481 if (num_resolving_nh
)
482 rnh
->filtered
[client
->proto
] = 0;
484 rnh
->filtered
[client
->proto
] = 1;
486 if (IS_ZEBRA_DEBUG_NHT
)
487 zlog_debug("%u:%s: Notifying client %s about NH %s",
488 vrfid
, bufn
, zebra_route_string(client
->proto
),
489 num_resolving_nh
? "" : "(filtered by route-map)");
493 rnh
->filtered
[client
->proto
] = 0;
494 if (IS_ZEBRA_DEBUG_NHT
)
495 zlog_debug("%u:%s: Notifying client %s about NH (unreachable)",
496 vrfid
, bufn
, zebra_route_string(client
->proto
));
499 send_client(rnh
, client
, RNH_NEXTHOP_TYPE
, vrfid
);
504 zebra_rnh_process_static_routes (vrf_id_t vrfid
, int family
,
505 struct route_node
*nrn
, struct rnh
*rnh
,
506 struct route_node
*prn
, struct rib
*rib
)
508 struct listnode
*node
;
509 int num_resolving_nh
= 0;
510 struct route_node
*static_rn
;
512 struct nexthop
*nexthop
;
513 char bufn
[INET6_ADDRSTRLEN
];
514 char bufp
[INET6_ADDRSTRLEN
];
515 char bufs
[INET6_ADDRSTRLEN
];
517 if (IS_ZEBRA_DEBUG_NHT
)
519 prefix2str(&nrn
->p
, bufn
, INET6_ADDRSTRLEN
);
521 prefix2str(&prn
->p
, bufp
, INET6_ADDRSTRLEN
);
526 /* Apply route-map for "static" to route resolving this
527 * nexthop to see if it is filtered or not.
529 num_resolving_nh
= zebra_rnh_apply_nht_rmap(family
, prn
, rib
,
531 if (num_resolving_nh
)
532 rnh
->filtered
[ZEBRA_ROUTE_STATIC
] = 0;
534 rnh
->filtered
[ZEBRA_ROUTE_STATIC
] = 1;
537 rnh
->filtered
[ZEBRA_ROUTE_STATIC
] = 0;
539 /* Evaluate each static route associated with this nexthop. */
540 for (ALL_LIST_ELEMENTS_RO(rnh
->zebra_static_route_list
, node
,
543 RNODE_FOREACH_RIB(static_rn
, srib
)
545 if (srib
->type
== ZEBRA_ROUTE_STATIC
)
548 /* Set the filter flag for the correct nexthop - static route may
549 * be having multiple. We care here only about registered nexthops.
551 for (nexthop
= srib
->nexthop
; nexthop
; nexthop
= nexthop
->next
)
553 switch (nexthop
->type
)
555 case NEXTHOP_TYPE_IPV4
:
556 case NEXTHOP_TYPE_IPV4_IFINDEX
:
557 if (nexthop
->gate
.ipv4
.s_addr
== nrn
->p
.u
.prefix4
.s_addr
)
559 if (num_resolving_nh
)
560 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FILTERED
);
562 SET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FILTERED
);
565 case NEXTHOP_TYPE_IPV6
:
566 case NEXTHOP_TYPE_IPV6_IFINDEX
:
568 if (memcmp(&nexthop
->gate
.ipv6
,&nrn
->p
.u
.prefix6
, 16) == 0)
570 if (num_resolving_nh
)
571 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FILTERED
);
573 SET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FILTERED
);
581 if (IS_ZEBRA_DEBUG_NHT
)
583 prefix2str(&static_rn
->p
, bufs
, INET6_ADDRSTRLEN
);
585 zlog_debug("%u:%s: NH change %s, scheduling static route %s",
586 vrfid
, bufn
, num_resolving_nh
?
587 "" : "(filtered by route-map)", bufs
);
589 zlog_debug("%u:%s: NH unreachable, scheduling static route %s",
593 SET_FLAG(srib
->status
, RIB_ENTRY_CHANGED
);
594 SET_FLAG(srib
->status
, RIB_ENTRY_NEXTHOPS_CHANGED
);
597 rib_queue_add(static_rn
);
602 * See if a tracked nexthop entry has undergone any change, and if so,
603 * take appropriate action; this involves notifying any clients and/or
604 * scheduling dependent static routes for processing.
607 zebra_rnh_eval_nexthop_entry (vrf_id_t vrfid
, int family
, int force
,
608 struct route_node
*nrn
, struct rnh
*rnh
,
609 struct route_node
*prn
, struct rib
*rib
)
611 int state_changed
= 0;
613 /* If we're resolving over a different route, resolution has changed or
614 * the resolving route has some change (e.g., metric), there is a state
617 if (!prefix_same(&rnh
->resolved_route
, &prn
->p
))
620 UNSET_FLAG(rib
->status
, RIB_ENTRY_NEXTHOPS_CHANGED
);
623 prefix_copy(&rnh
->resolved_route
, &prn
->p
);
625 memset(&rnh
->resolved_route
, 0, sizeof(struct prefix
));
627 copy_state(rnh
, rib
, nrn
);
630 else if (compare_state(rib
, rnh
->state
))
633 UNSET_FLAG(rib
->status
, RIB_ENTRY_NEXTHOPS_CHANGED
);
635 copy_state(rnh
, rib
, nrn
);
639 if (state_changed
|| force
)
641 /* NOTE: Use the "copy" of resolving route stored in 'rnh' i.e.,
644 /* Notify registered protocol clients. */
645 zebra_rnh_notify_protocol_clients (vrfid
, family
, nrn
, rnh
,
648 /* Process static routes attached to this nexthop */
649 zebra_rnh_process_static_routes (vrfid
, family
, nrn
, rnh
,
654 /* Evaluate one tracked entry */
656 zebra_rnh_evaluate_entry (vrf_id_t vrfid
, int family
, int force
, rnh_type_t type
,
657 struct route_node
*nrn
)
661 struct route_node
*prn
;
662 char bufn
[INET6_ADDRSTRLEN
];
664 if (IS_ZEBRA_DEBUG_NHT
)
666 prefix2str(&nrn
->p
, bufn
, INET6_ADDRSTRLEN
);
667 zlog_debug("%u:%s: Evaluate RNH, type %d %s",
668 vrfid
, bufn
, type
, force
? "(force)" : "");
673 /* Identify route entry (RIB) resolving this tracked entry. */
674 rib
= zebra_rnh_resolve_entry (vrfid
, family
, type
, nrn
, rnh
, &prn
);
676 /* If the entry cannot be resolved and that is also the existing state,
677 * there is nothing further to do.
679 if (!rib
&& rnh
->state
== NULL
&& !force
)
682 /* Process based on type of entry. */
683 if (type
== RNH_IMPORT_CHECK_TYPE
)
684 zebra_rnh_eval_import_check_entry (vrfid
, family
, force
,
687 zebra_rnh_eval_nexthop_entry (vrfid
, family
, force
,
692 /* Evaluate all tracked entries (nexthops or routes for import into BGP)
693 * of a particular VRF and address-family or a specific prefix.
696 zebra_evaluate_rnh (vrf_id_t vrfid
, int family
, int force
, rnh_type_t type
,
699 struct route_table
*rnh_table
;
700 struct route_node
*nrn
;
702 rnh_table
= get_rnh_table(vrfid
, family
, type
);
703 if (!rnh_table
) // unexpected
708 /* Evaluating a specific entry, make sure it exists. */
709 nrn
= route_node_lookup (rnh_table
, p
);
710 if (nrn
&& nrn
->info
)
711 zebra_rnh_evaluate_entry (vrfid
, family
, force
, type
, nrn
);
713 route_unlock_node (nrn
);
717 /* Evaluate entire table. */
718 nrn
= route_top (rnh_table
);
722 zebra_rnh_evaluate_entry (vrfid
, family
, force
, type
, nrn
);
723 nrn
= route_next(nrn
); /* this will also unlock nrn */
729 zebra_print_rnh_table (vrf_id_t vrfid
, int af
, struct vty
*vty
, rnh_type_t type
)
731 struct route_table
*table
;
732 struct route_node
*rn
;
734 table
= get_rnh_table(vrfid
, af
, type
);
737 zlog_debug("print_rnhs: rnh table not found\n");
741 for (rn
= route_top(table
); rn
; rn
= route_next(rn
))
747 zebra_cleanup_rnh_client (vrf_id_t vrf_id
, int family
, struct zserv
*client
,
750 struct route_table
*ntable
;
751 struct route_node
*nrn
;
754 if (IS_ZEBRA_DEBUG_NHT
)
755 zlog_debug("%u: Client %s RNH cleanup for family %d type %d",
756 vrf_id
, zebra_route_string(client
->proto
), family
, type
);
758 ntable
= get_rnh_table(vrf_id
, family
, type
);
761 zlog_debug("cleanup_rnh_client: rnh table not found\n");
765 for (nrn
= route_top (ntable
); nrn
; nrn
= route_next (nrn
))
771 zebra_remove_rnh_client(rnh
, client
, type
);
777 * free_state - free up the rib structure associated with the rnh.
780 free_state (vrf_id_t vrf_id
, struct rib
*rib
, struct route_node
*rn
)
786 /* free RIB and nexthops */
787 zebra_deregister_rnh_static_nexthops (vrf_id
, rib
->nexthop
, rn
);
788 nexthops_free(rib
->nexthop
);
789 XFREE (MTYPE_RIB
, rib
);
793 copy_state (struct rnh
*rnh
, struct rib
*rib
, struct route_node
*rn
)
800 free_state(rnh
->vrf_id
, rnh
->state
, rn
);
807 state
= XCALLOC (MTYPE_RIB
, sizeof (struct rib
));
808 state
->type
= rib
->type
;
809 state
->metric
= rib
->metric
;
811 for (nh
= rib
->nexthop
; nh
; nh
= nh
->next
)
812 rib_copy_nexthops(state
, nh
);
817 compare_state (struct rib
*r1
, struct rib
*r2
)
823 if ((!r1
&& r2
) || (r1
&& !r2
))
826 if (r1
->metric
!= r2
->metric
)
829 if (r1
->nexthop_num
!= r2
->nexthop_num
)
832 if (CHECK_FLAG(r1
->status
, RIB_ENTRY_NEXTHOPS_CHANGED
))
839 send_client (struct rnh
*rnh
, struct zserv
*client
, rnh_type_t type
, vrf_id_t vrf_id
)
845 struct nexthop
*nexthop
;
846 struct route_node
*rn
;
847 int cmd
= (type
== RNH_IMPORT_CHECK_TYPE
)
848 ? ZEBRA_IMPORT_CHECK_UPDATE
: ZEBRA_NEXTHOP_UPDATE
;
853 /* Get output stream. */
857 zserv_create_header (s
, cmd
, vrf_id
);
859 stream_putw(s
, rn
->p
.family
);
860 switch (rn
->p
.family
)
863 stream_putc(s
, rn
->p
.prefixlen
);
864 stream_put_in_addr(s
, &rn
->p
.u
.prefix4
);
867 stream_putc(s
, rn
->p
.prefixlen
);
868 stream_put(s
, &rn
->p
.u
.prefix6
, IPV6_MAX_BYTELEN
);
871 zlog_err("%s: Unknown family (%d) notification attempted\n",
872 __FUNCTION__
, rn
->p
.family
);
877 stream_putl (s
, rib
->metric
);
879 nump
= stream_get_endp(s
);
881 for (nexthop
= rib
->nexthop
; nexthop
; nexthop
= nexthop
->next
)
882 if ((CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_FIB
) ||
883 CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_RECURSIVE
)) &&
884 CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
))
886 stream_putc (s
, nexthop
->type
);
887 switch (nexthop
->type
)
889 case NEXTHOP_TYPE_IPV4
:
890 stream_put_in_addr (s
, &nexthop
->gate
.ipv4
);
892 case NEXTHOP_TYPE_IFINDEX
:
893 stream_putl (s
, nexthop
->ifindex
);
895 case NEXTHOP_TYPE_IPV4_IFINDEX
:
896 stream_put_in_addr (s
, &nexthop
->gate
.ipv4
);
897 stream_putl (s
, nexthop
->ifindex
);
900 case NEXTHOP_TYPE_IPV6
:
901 stream_put (s
, &nexthop
->gate
.ipv6
, 16);
903 case NEXTHOP_TYPE_IPV6_IFINDEX
:
904 stream_put (s
, &nexthop
->gate
.ipv6
, 16);
905 stream_putl (s
, nexthop
->ifindex
);
907 #endif /* HAVE_IPV6 */
914 stream_putc_at (s
, nump
, num
);
921 stream_putw_at (s
, 0, stream_get_endp (s
));
923 client
->nh_last_upd_time
= quagga_monotime();
924 client
->last_write_cmd
= cmd
;
925 return zebra_server_send_message(client
);
929 print_nh (struct nexthop
*nexthop
, struct vty
*vty
)
932 struct zebra_ns
*zns
= zebra_ns_lookup (NS_DEFAULT
);
934 switch (nexthop
->type
)
936 case NEXTHOP_TYPE_IPV4
:
937 case NEXTHOP_TYPE_IPV4_IFINDEX
:
938 vty_out (vty
, " via %s", inet_ntoa (nexthop
->gate
.ipv4
));
939 if (nexthop
->ifindex
)
940 vty_out (vty
, ", %s", ifindex2ifname_per_ns (zns
, nexthop
->ifindex
));
942 case NEXTHOP_TYPE_IPV6
:
943 case NEXTHOP_TYPE_IPV6_IFINDEX
:
945 inet_ntop (AF_INET6
, &nexthop
->gate
.ipv6
, buf
, BUFSIZ
));
946 if (nexthop
->ifindex
)
947 vty_out (vty
, ", via %s", ifindex2ifname_per_ns (zns
, nexthop
->ifindex
));
949 case NEXTHOP_TYPE_IFINDEX
:
950 vty_out (vty
, " is directly connected, %s",
951 ifindex2ifname_per_ns (zns
, nexthop
->ifindex
));
953 case NEXTHOP_TYPE_BLACKHOLE
:
954 vty_out (vty
, " is directly connected, Null0");
959 vty_out(vty
, "%s", VTY_NEWLINE
);
963 print_rnh (struct route_node
*rn
, struct vty
*vty
)
966 struct nexthop
*nexthop
;
967 struct listnode
*node
;
968 struct zserv
*client
;
972 vty_out(vty
, "%s%s%s", inet_ntop(rn
->p
.family
, &rn
->p
.u
.prefix
, buf
, BUFSIZ
),
973 CHECK_FLAG(rnh
->flags
, ZEBRA_NHT_CONNECTED
) ? "(Connected)" : "",
977 vty_out(vty
, " resolved via %s%s",
978 zebra_route_string(rnh
->state
->type
), VTY_NEWLINE
);
979 for (nexthop
= rnh
->state
->nexthop
; nexthop
; nexthop
= nexthop
->next
)
980 print_nh(nexthop
, vty
);
983 vty_out(vty
, " unresolved%s%s",
984 CHECK_FLAG(rnh
->flags
, ZEBRA_NHT_CONNECTED
) ? "(Connected)" : "",
987 vty_out(vty
, " Client list:");
988 for (ALL_LIST_ELEMENTS_RO(rnh
->client_list
, node
, client
))
989 vty_out(vty
, " %s(fd %d)%s", zebra_route_string(client
->proto
),
990 client
->sock
, rnh
->filtered
[client
->proto
] ? "(filtered)" : "");
991 if (!list_isempty(rnh
->zebra_static_route_list
))
992 vty_out(vty
, " zebra%s", rnh
->filtered
[ZEBRA_ROUTE_STATIC
] ? "(filtered)" : "");
993 vty_out(vty
, "%s", VTY_NEWLINE
);