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/redistribute.h"
45 #include "zebra/debug.h"
46 #include "zebra/zebra_rnh.h"
47 #include "zebra/interface.h"
49 /* Default rtm_table for all clients */
50 extern struct zebra_t zebrad
;
52 static void free_state(vrf_id_t vrf_id
, struct rib
*rib
, struct route_node
*rn
);
53 static void copy_state(struct rnh
*rnh
, struct rib
*rib
,
54 struct route_node
*rn
);
55 #define lookup_rnh_table(v, f) \
57 struct zebra_vrf *zvrf; \
58 struct route_table *t = NULL; \
59 zvrf = zebra_vrf_lookup(v); \
61 t = zvrf->rnh_table[family2afi(f)]; \
65 static int compare_state(struct rib
*r1
, struct rib
*r2
);
66 static int send_client(struct rnh
*rnh
, struct zserv
*client
, rnh_type_t type
,
68 static void print_rnh(struct route_node
*rn
, struct vty
*vty
);
70 int zebra_rnh_ip_default_route
= 0;
71 int zebra_rnh_ipv6_default_route
= 0;
73 static inline struct route_table
*get_rnh_table(vrf_id_t vrfid
, int family
,
76 struct zebra_vrf
*zvrf
;
77 struct route_table
*t
= NULL
;
79 zvrf
= zebra_vrf_lookup(vrfid
);
83 case RNH_NEXTHOP_TYPE
:
84 t
= zvrf
->rnh_table
[family2afi(family
)];
86 case RNH_IMPORT_CHECK_TYPE
:
87 t
= zvrf
->import_check_table
[family2afi(family
)];
94 char *rnh_str (struct rnh
*rnh
, char *buf
, int size
)
96 prefix2str(&(rnh
->node
->p
), buf
, size
);
101 zebra_add_rnh (struct prefix
*p
, vrf_id_t vrfid
, rnh_type_t type
)
103 struct route_table
*table
;
104 struct route_node
*rn
;
105 struct rnh
*rnh
= NULL
;
106 char buf
[PREFIX2STR_BUFFER
];
108 if (IS_ZEBRA_DEBUG_NHT
)
110 prefix2str(p
, buf
, sizeof (buf
));
111 zlog_debug("%u: Add RNH %s type %d", vrfid
, buf
, type
);
113 table
= get_rnh_table(vrfid
, PREFIX_FAMILY(p
), type
);
116 prefix2str(p
, buf
, sizeof (buf
));
117 zlog_warn("%u: Add RNH %s type %d - table not found",
122 /* Make it sure prefixlen is applied to the prefix. */
125 /* Lookup (or add) route node.*/
126 rn
= route_node_get (table
, p
);
130 rnh
= XCALLOC(MTYPE_RNH
, sizeof(struct rnh
));
131 rnh
->client_list
= list_new();
133 rnh
->zebra_static_route_list
= list_new();
134 route_lock_node (rn
);
139 route_unlock_node (rn
);
144 zebra_lookup_rnh (struct prefix
*p
, vrf_id_t vrfid
, rnh_type_t type
)
146 struct route_table
*table
;
147 struct route_node
*rn
;
149 table
= get_rnh_table(vrfid
, PREFIX_FAMILY(p
), type
);
153 /* Make it sure prefixlen is applied to the prefix. */
156 /* Lookup route node.*/
157 rn
= route_node_lookup (table
, p
);
161 route_unlock_node (rn
);
166 zebra_delete_rnh (struct rnh
*rnh
, rnh_type_t type
)
168 struct route_node
*rn
;
170 if (!rnh
|| (rnh
->flags
& ZEBRA_NHT_DELETED
) || !(rn
= rnh
->node
))
173 if (IS_ZEBRA_DEBUG_NHT
)
175 char buf
[PREFIX2STR_BUFFER
];
176 zlog_debug("%u: Del RNH %s type %d",
177 rnh
->vrf_id
, rnh_str(rnh
, buf
, sizeof (buf
)), type
);
180 rnh
->flags
|= ZEBRA_NHT_DELETED
;
181 list_free(rnh
->client_list
);
182 list_free(rnh
->zebra_static_route_list
);
183 free_state(rnh
->vrf_id
, rnh
->state
, rn
);
184 XFREE(MTYPE_RNH
, rn
->info
);
186 route_unlock_node (rn
);
191 zebra_add_rnh_client (struct rnh
*rnh
, struct zserv
*client
, rnh_type_t type
,
194 if (IS_ZEBRA_DEBUG_NHT
)
196 char buf
[PREFIX2STR_BUFFER
];
197 zlog_debug("%u: Client %s registers for RNH %s type %d",
198 vrf_id
, zebra_route_string(client
->proto
),
199 rnh_str(rnh
, buf
, sizeof (buf
)), type
);
201 if (!listnode_lookup(rnh
->client_list
, client
))
203 listnode_add(rnh
->client_list
, client
);
204 send_client(rnh
, client
, type
, vrf_id
); // Pending: check if its needed
209 zebra_remove_rnh_client (struct rnh
*rnh
, struct zserv
*client
, rnh_type_t type
)
211 if (IS_ZEBRA_DEBUG_NHT
)
213 char buf
[PREFIX2STR_BUFFER
];
214 zlog_debug("Client %s unregisters for RNH %s type %d",
215 zebra_route_string(client
->proto
),
216 rnh_str(rnh
, buf
, sizeof (buf
)), type
);
218 listnode_delete(rnh
->client_list
, client
);
219 if (list_isempty(rnh
->client_list
) &&
220 list_isempty(rnh
->zebra_static_route_list
))
221 zebra_delete_rnh(rnh
, type
);
225 zebra_register_rnh_static_nh(vrf_id_t vrf_id
, struct prefix
*nh
,
226 struct route_node
*static_rn
)
230 rnh
= zebra_add_rnh(nh
, vrf_id
, RNH_NEXTHOP_TYPE
);
231 if (rnh
&& !listnode_lookup(rnh
->zebra_static_route_list
, static_rn
))
233 listnode_add(rnh
->zebra_static_route_list
, static_rn
);
238 zebra_deregister_rnh_static_nh(vrf_id_t vrf_id
, struct prefix
*nh
,
239 struct route_node
*static_rn
)
243 rnh
= zebra_lookup_rnh(nh
, vrf_id
, RNH_NEXTHOP_TYPE
);
244 if (!rnh
|| (rnh
->flags
& ZEBRA_NHT_DELETED
))
247 listnode_delete(rnh
->zebra_static_route_list
, static_rn
);
249 if (list_isempty(rnh
->client_list
) &&
250 list_isempty(rnh
->zebra_static_route_list
))
251 zebra_delete_rnh(rnh
, RNH_NEXTHOP_TYPE
);
255 zebra_deregister_rnh_static_nexthops (vrf_id_t vrf_id
, struct nexthop
*nexthop
,
256 struct route_node
*rn
)
261 for (nh
= nexthop
; nh
; nh
= nh
->next
)
263 if (nh
->type
== NEXTHOP_TYPE_IPV4
)
265 nh_p
.family
= AF_INET
;
266 nh_p
.prefixlen
= IPV4_MAX_BITLEN
;
267 nh_p
.u
.prefix4
= nh
->gate
.ipv4
;
269 else if (nh
->type
== NEXTHOP_TYPE_IPV6
)
271 nh_p
.family
= AF_INET6
;
272 nh_p
.prefixlen
= IPV6_MAX_BITLEN
;
273 nh_p
.u
.prefix6
= nh
->gate
.ipv6
;
275 zebra_deregister_rnh_static_nh(vrf_id
, &nh_p
, rn
);
279 /* Apply the NHT route-map for a client to the route (and nexthops)
283 zebra_rnh_apply_nht_rmap(int family
, struct route_node
*prn
,
284 struct rib
*rib
, int proto
)
286 int at_least_one
= 0;
287 int rmap_family
; /* Route map has diff AF family enum */
288 struct nexthop
*nexthop
;
291 rmap_family
= (family
== AF_INET
) ? AFI_IP
: AFI_IP6
;
295 for (nexthop
= rib
->nexthop
; nexthop
; nexthop
= nexthop
->next
)
297 ret
= zebra_nht_route_map_check(rmap_family
, proto
, &prn
->p
, rib
,
299 if (ret
!= RMAP_DENYMATCH
)
301 SET_FLAG (nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
302 at_least_one
++; /* at least one valid NH */
306 UNSET_FLAG (nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
);
310 return (at_least_one
);
314 * Determine appropriate route (RIB entry) resolving a tracked entry
315 * (nexthop or BGP route for import).
318 zebra_rnh_resolve_entry (vrf_id_t vrfid
, int family
, rnh_type_t type
,
319 struct route_node
*nrn
, struct rnh
*rnh
,
320 struct route_node
**prn
)
322 struct route_table
*route_table
;
323 struct route_node
*rn
;
328 route_table
= zebra_vrf_table(family2afi(family
), SAFI_UNICAST
, vrfid
);
329 if (!route_table
) // unexpected
332 rn
= route_node_match(route_table
, &nrn
->p
);
336 /* Do not resolve over default route unless allowed &&
337 * match route to be exact if so specified
339 if ((type
== RNH_NEXTHOP_TYPE
) &&
340 (is_default_prefix (&rn
->p
) &&
341 !nh_resolve_via_default(rn
->p
.family
)))
343 else if ((type
== RNH_IMPORT_CHECK_TYPE
) &&
344 ((is_default_prefix(&rn
->p
)) ||
345 ((CHECK_FLAG(rnh
->flags
, ZEBRA_NHT_EXACT_MATCH
)) &&
346 !prefix_same(&nrn
->p
, &rn
->p
))))
350 /* Identify appropriate route entry. */
351 RNODE_FOREACH_RIB(rn
, rib
)
353 if (CHECK_FLAG (rib
->status
, RIB_ENTRY_REMOVED
))
355 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_SELECTED
))
357 if (CHECK_FLAG(rnh
->flags
, ZEBRA_NHT_CONNECTED
))
359 if (rib
->type
== ZEBRA_ROUTE_CONNECT
)
362 else if ((type
== RNH_IMPORT_CHECK_TYPE
) &&
363 (rib
->type
== ZEBRA_ROUTE_BGP
))
371 /* Need to unlock route node */
372 route_unlock_node(rn
);
379 * See if a tracked route entry for import (by BGP) has undergone any
380 * change, and if so, notify the client.
383 zebra_rnh_eval_import_check_entry (vrf_id_t vrfid
, int family
, int force
,
384 struct route_node
*nrn
, struct rnh
*rnh
,
387 int state_changed
= 0;
388 struct zserv
*client
;
389 char bufn
[INET6_ADDRSTRLEN
];
390 struct listnode
*node
;
391 struct nexthop
*nexthop
, *tnexthop
;
394 if (rib
&& (rnh
->state
== NULL
))
396 for (ALL_NEXTHOPS_RO(rib
->nexthop
, nexthop
, tnexthop
, recursing
))
397 if (CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_FIB
))
403 else if (!rib
&& (rnh
->state
!= NULL
))
406 if (compare_state(rib
, rnh
->state
))
407 copy_state(rnh
, rib
, nrn
);
409 if (state_changed
|| force
)
411 if (IS_ZEBRA_DEBUG_NHT
)
413 prefix2str(&nrn
->p
, bufn
, INET6_ADDRSTRLEN
);
414 zlog_debug("%u:%s: Route import check %s %s\n",
415 vrfid
, bufn
, rnh
->state
? "passed" : "failed",
416 state_changed
? "(state changed)" : "");
418 /* state changed, notify clients */
419 for (ALL_LIST_ELEMENTS_RO(rnh
->client_list
, node
, client
))
421 send_client(rnh
, client
, RNH_IMPORT_CHECK_TYPE
, vrfid
);
427 * Notify clients registered for this nexthop about a change.
430 zebra_rnh_notify_protocol_clients (vrf_id_t vrfid
, int family
,
431 struct route_node
*nrn
, struct rnh
*rnh
,
432 struct route_node
*prn
, struct rib
*rib
)
434 struct listnode
*node
;
435 struct zserv
*client
;
436 char bufn
[INET6_ADDRSTRLEN
];
437 char bufp
[INET6_ADDRSTRLEN
];
438 int num_resolving_nh
;
440 if (IS_ZEBRA_DEBUG_NHT
)
442 prefix2str(&nrn
->p
, bufn
, INET6_ADDRSTRLEN
);
445 prefix2str(&prn
->p
, bufp
, INET6_ADDRSTRLEN
);
446 zlog_debug("%u:%s: NH resolved over route %s", vrfid
, bufn
, bufp
);
449 zlog_debug("%u:%s: NH has become unresolved", vrfid
, bufn
);
452 for (ALL_LIST_ELEMENTS_RO(rnh
->client_list
, node
, client
))
456 /* Apply route-map for this client to route resolving this
457 * nexthop to see if it is filtered or not.
459 num_resolving_nh
= zebra_rnh_apply_nht_rmap(family
, prn
, rib
,
461 if (num_resolving_nh
)
462 rnh
->filtered
[client
->proto
] = 0;
464 rnh
->filtered
[client
->proto
] = 1;
466 if (IS_ZEBRA_DEBUG_NHT
)
467 zlog_debug("%u:%s: Notifying client %s about NH %s",
468 vrfid
, bufn
, zebra_route_string(client
->proto
),
469 num_resolving_nh
? "" : "(filtered by route-map)");
473 rnh
->filtered
[client
->proto
] = 0;
474 if (IS_ZEBRA_DEBUG_NHT
)
475 zlog_debug("%u:%s: Notifying client %s about NH (unreachable)",
476 vrfid
, bufn
, zebra_route_string(client
->proto
));
479 send_client(rnh
, client
, RNH_NEXTHOP_TYPE
, vrfid
);
484 zebra_rnh_process_static_routes (vrf_id_t vrfid
, int family
,
485 struct route_node
*nrn
, struct rnh
*rnh
,
486 struct route_node
*prn
, struct rib
*rib
)
488 struct listnode
*node
;
489 int num_resolving_nh
= 0;
490 struct route_node
*static_rn
;
492 struct nexthop
*nexthop
;
493 char bufn
[INET6_ADDRSTRLEN
];
494 char bufp
[INET6_ADDRSTRLEN
];
495 char bufs
[INET6_ADDRSTRLEN
];
497 if (IS_ZEBRA_DEBUG_NHT
)
499 prefix2str(&nrn
->p
, bufn
, INET6_ADDRSTRLEN
);
501 prefix2str(&prn
->p
, bufp
, INET6_ADDRSTRLEN
);
506 /* Apply route-map for "static" to route resolving this
507 * nexthop to see if it is filtered or not.
509 num_resolving_nh
= zebra_rnh_apply_nht_rmap(family
, prn
, rib
,
511 if (num_resolving_nh
)
512 rnh
->filtered
[ZEBRA_ROUTE_STATIC
] = 0;
514 rnh
->filtered
[ZEBRA_ROUTE_STATIC
] = 1;
517 rnh
->filtered
[ZEBRA_ROUTE_STATIC
] = 0;
519 /* Evaluate each static route associated with this nexthop. */
520 for (ALL_LIST_ELEMENTS_RO(rnh
->zebra_static_route_list
, node
,
523 RNODE_FOREACH_RIB(static_rn
, srib
)
525 if (srib
->type
== ZEBRA_ROUTE_STATIC
)
526 break; /* currently works for only 1 static route. */
529 if (!srib
) // unexpected
532 /* Set the filter flag for the correct nexthop - static route may
533 * be having multiple. We care here only about registered nexthops.
535 for (nexthop
= srib
->nexthop
; nexthop
; nexthop
= nexthop
->next
)
537 switch (nexthop
->type
)
539 case NEXTHOP_TYPE_IPV4
:
540 case NEXTHOP_TYPE_IPV4_IFINDEX
:
541 if (nexthop
->gate
.ipv4
.s_addr
== nrn
->p
.u
.prefix4
.s_addr
)
543 if (num_resolving_nh
)
544 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FILTERED
);
546 SET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FILTERED
);
549 case NEXTHOP_TYPE_IPV6
:
550 case NEXTHOP_TYPE_IPV6_IFINDEX
:
551 if (memcmp(&nexthop
->gate
.ipv6
,&nrn
->p
.u
.prefix6
, 16) == 0)
553 if (num_resolving_nh
)
554 UNSET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FILTERED
);
556 SET_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FILTERED
);
564 if (IS_ZEBRA_DEBUG_NHT
)
566 prefix2str(&static_rn
->p
, bufs
, INET6_ADDRSTRLEN
);
568 zlog_debug("%u:%s: NH change %s, scheduling static route %s",
569 vrfid
, bufn
, num_resolving_nh
?
570 "" : "(filtered by route-map)", bufs
);
572 zlog_debug("%u:%s: NH unreachable, scheduling static route %s",
576 SET_FLAG(srib
->flags
, ZEBRA_FLAG_CHANGED
);
577 SET_FLAG(srib
->status
, RIB_ENTRY_NEXTHOPS_CHANGED
);
578 rib_queue_add(&zebrad
, static_rn
);
583 * See if a tracked nexthop entry has undergone any change, and if so,
584 * take appropriate action; this involves notifying any clients and/or
585 * scheduling dependent static routes for processing.
588 zebra_rnh_eval_nexthop_entry (vrf_id_t vrfid
, int family
, int force
,
589 struct route_node
*nrn
, struct rnh
*rnh
,
590 struct route_node
*prn
, struct rib
*rib
)
592 int state_changed
= 0;
594 /* If we're resolving over a different route, resolution has changed or
595 * the resolving route has some change (e.g., metric), there is a state
598 if (!prefix_same(&rnh
->resolved_route
, &prn
->p
))
601 UNSET_FLAG(rib
->status
, RIB_ENTRY_NEXTHOPS_CHANGED
);
604 prefix_copy(&rnh
->resolved_route
, &prn
->p
);
606 memset(&rnh
->resolved_route
, 0, sizeof(struct prefix
));
608 copy_state(rnh
, rib
, nrn
);
611 else if (compare_state(rib
, rnh
->state
))
614 UNSET_FLAG(rib
->status
, RIB_ENTRY_NEXTHOPS_CHANGED
);
616 copy_state(rnh
, rib
, nrn
);
620 if (state_changed
|| force
)
622 /* NOTE: Use the "copy" of resolving route stored in 'rnh' i.e.,
625 /* Notify registered protocol clients. */
626 zebra_rnh_notify_protocol_clients (vrfid
, family
, nrn
, rnh
,
629 /* Process static routes attached to this nexthop */
630 zebra_rnh_process_static_routes (vrfid
, family
, nrn
, rnh
,
635 /* Evaluate one tracked entry */
637 zebra_rnh_evaluate_entry (vrf_id_t vrfid
, int family
, int force
, rnh_type_t type
,
638 struct route_node
*nrn
)
642 struct route_node
*prn
;
643 char bufn
[INET6_ADDRSTRLEN
];
645 if (IS_ZEBRA_DEBUG_NHT
)
647 prefix2str(&nrn
->p
, bufn
, INET6_ADDRSTRLEN
);
648 zlog_debug("%u:%s: Evaluate RNH, type %d %s",
649 vrfid
, bufn
, type
, force
? "(force)" : "");
654 /* Identify route entry (RIB) resolving this tracked entry. */
655 rib
= zebra_rnh_resolve_entry (vrfid
, family
, type
, nrn
, rnh
, &prn
);
657 /* If the entry cannot be resolved and that is also the existing state,
658 * there is nothing further to do.
660 if (!rib
&& rnh
->state
== NULL
&& !force
)
663 /* Process based on type of entry. */
664 if (type
== RNH_IMPORT_CHECK_TYPE
)
665 zebra_rnh_eval_import_check_entry (vrfid
, family
, force
,
668 zebra_rnh_eval_nexthop_entry (vrfid
, family
, force
,
673 /* Evaluate all tracked entries (nexthops or routes for import into BGP)
674 * of a particular VRF and address-family or a specific prefix.
677 zebra_evaluate_rnh (vrf_id_t vrfid
, int family
, int force
, rnh_type_t type
,
680 struct route_table
*rnh_table
;
681 struct route_node
*nrn
;
683 rnh_table
= get_rnh_table(vrfid
, family
, type
);
684 if (!rnh_table
) // unexpected
689 /* Evaluating a specific entry, make sure it exists. */
690 nrn
= route_node_lookup (rnh_table
, p
);
691 if (nrn
&& nrn
->info
)
692 zebra_rnh_evaluate_entry (vrfid
, family
, force
, type
, nrn
);
694 route_unlock_node (nrn
);
698 /* Evaluate entire table. */
699 nrn
= route_top (rnh_table
);
703 zebra_rnh_evaluate_entry (vrfid
, family
, force
, type
, nrn
);
704 nrn
= route_next(nrn
); /* this will also unlock nrn */
710 zebra_print_rnh_table (vrf_id_t vrfid
, int af
, struct vty
*vty
, rnh_type_t type
)
712 struct route_table
*table
;
713 struct route_node
*rn
;
715 table
= get_rnh_table(vrfid
, af
, type
);
718 zlog_debug("print_rnhs: rnh table not found\n");
722 for (rn
= route_top(table
); rn
; rn
= route_next(rn
))
728 zebra_cleanup_rnh_client (vrf_id_t vrf_id
, int family
, struct zserv
*client
,
731 struct route_table
*ntable
;
732 struct route_node
*nrn
;
735 if (IS_ZEBRA_DEBUG_NHT
)
736 zlog_debug("%u: Client %s RNH cleanup for family %d type %d",
737 vrf_id
, zebra_route_string(client
->proto
), family
, type
);
739 ntable
= get_rnh_table(vrf_id
, family
, type
);
742 zlog_debug("cleanup_rnh_client: rnh table not found\n");
746 for (nrn
= route_top (ntable
); nrn
; nrn
= route_next (nrn
))
752 zebra_remove_rnh_client(rnh
, client
, type
);
758 * free_state - free up the rib structure associated with the rnh.
761 free_state (vrf_id_t vrf_id
, struct rib
*rib
, struct route_node
*rn
)
767 /* free RIB and nexthops */
768 zebra_deregister_rnh_static_nexthops (vrf_id
, rib
->nexthop
, rn
);
769 nexthops_free(rib
->nexthop
);
770 XFREE (MTYPE_RIB
, rib
);
774 copy_state (struct rnh
*rnh
, struct rib
*rib
, struct route_node
*rn
)
781 free_state(rnh
->vrf_id
, rnh
->state
, rn
);
788 state
= XCALLOC (MTYPE_RIB
, sizeof (struct rib
));
789 state
->type
= rib
->type
;
790 state
->metric
= rib
->metric
;
792 for (nh
= rib
->nexthop
; nh
; nh
= nh
->next
)
793 rib_copy_nexthops(state
, nh
);
798 compare_state (struct rib
*r1
, struct rib
*r2
)
804 if ((!r1
&& r2
) || (r1
&& !r2
))
807 if (r1
->metric
!= r2
->metric
)
810 if (r1
->nexthop_num
!= r2
->nexthop_num
)
813 if (CHECK_FLAG(r1
->status
, RIB_ENTRY_NEXTHOPS_CHANGED
))
820 send_client (struct rnh
*rnh
, struct zserv
*client
, rnh_type_t type
, vrf_id_t vrf_id
)
826 struct nexthop
*nexthop
;
827 struct route_node
*rn
;
828 int cmd
= (type
== RNH_IMPORT_CHECK_TYPE
)
829 ? ZEBRA_IMPORT_CHECK_UPDATE
: ZEBRA_NEXTHOP_UPDATE
;
834 /* Get output stream. */
838 zserv_create_header (s
, cmd
, vrf_id
);
840 stream_putw(s
, rn
->p
.family
);
841 switch (rn
->p
.family
)
844 stream_putc(s
, rn
->p
.prefixlen
);
845 stream_put_in_addr(s
, &rn
->p
.u
.prefix4
);
848 stream_putc(s
, rn
->p
.prefixlen
);
849 stream_put(s
, &rn
->p
.u
.prefix6
, IPV6_MAX_BYTELEN
);
852 zlog_err("%s: Unknown family (%d) notification attempted\n",
853 __FUNCTION__
, rn
->p
.family
);
858 stream_putl (s
, rib
->metric
);
860 nump
= stream_get_endp(s
);
862 for (nexthop
= rib
->nexthop
; nexthop
; nexthop
= nexthop
->next
)
863 if ((CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_FIB
) ||
864 CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_RECURSIVE
)) &&
865 CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
))
867 stream_putc (s
, nexthop
->type
);
868 switch (nexthop
->type
)
870 case ZEBRA_NEXTHOP_IPV4
:
871 stream_put_in_addr (s
, &nexthop
->gate
.ipv4
);
873 case ZEBRA_NEXTHOP_IFINDEX
:
874 stream_putl (s
, nexthop
->ifindex
);
876 case ZEBRA_NEXTHOP_IPV4_IFINDEX
:
877 stream_put_in_addr (s
, &nexthop
->gate
.ipv4
);
878 stream_putl (s
, nexthop
->ifindex
);
881 case ZEBRA_NEXTHOP_IPV6
:
882 stream_put (s
, &nexthop
->gate
.ipv6
, 16);
884 case ZEBRA_NEXTHOP_IPV6_IFINDEX
:
885 stream_put (s
, &nexthop
->gate
.ipv6
, 16);
886 stream_putl (s
, nexthop
->ifindex
);
888 #endif /* HAVE_IPV6 */
895 stream_putc_at (s
, nump
, num
);
902 stream_putw_at (s
, 0, stream_get_endp (s
));
904 client
->nh_last_upd_time
= quagga_time(NULL
);
905 client
->last_write_cmd
= cmd
;
906 return zebra_server_send_message(client
);
910 print_nh (struct nexthop
*nexthop
, struct vty
*vty
)
914 switch (nexthop
->type
)
916 case NEXTHOP_TYPE_IPV4
:
917 case NEXTHOP_TYPE_IPV4_IFINDEX
:
918 vty_out (vty
, " via %s", inet_ntoa (nexthop
->gate
.ipv4
));
919 if (nexthop
->ifindex
)
920 vty_out (vty
, ", %s", ifindex2ifname_per_ns (dzns
, nexthop
->ifindex
));
922 case NEXTHOP_TYPE_IPV6
:
923 case NEXTHOP_TYPE_IPV6_IFINDEX
:
925 inet_ntop (AF_INET6
, &nexthop
->gate
.ipv6
, buf
, BUFSIZ
));
926 if (nexthop
->ifindex
)
927 vty_out (vty
, ", via %s", ifindex2ifname_per_ns (dzns
, nexthop
->ifindex
));
929 case NEXTHOP_TYPE_IFINDEX
:
930 vty_out (vty
, " is directly connected, %s",
931 ifindex2ifname_per_ns (dzns
, nexthop
->ifindex
));
933 case NEXTHOP_TYPE_BLACKHOLE
:
934 vty_out (vty
, " is directly connected, Null0");
939 vty_out(vty
, "%s", VTY_NEWLINE
);
943 print_rnh (struct route_node
*rn
, struct vty
*vty
)
946 struct nexthop
*nexthop
;
947 struct listnode
*node
;
948 struct zserv
*client
;
952 vty_out(vty
, "%s%s%s", inet_ntop(rn
->p
.family
, &rn
->p
.u
.prefix
, buf
, BUFSIZ
),
953 CHECK_FLAG(rnh
->flags
, ZEBRA_NHT_CONNECTED
) ? "(Connected)" : "",
957 vty_out(vty
, " resolved via %s%s",
958 zebra_route_string(rnh
->state
->type
), VTY_NEWLINE
);
959 for (nexthop
= rnh
->state
->nexthop
; nexthop
; nexthop
= nexthop
->next
)
960 print_nh(nexthop
, vty
);
963 vty_out(vty
, " unresolved%s%s",
964 CHECK_FLAG(rnh
->flags
, ZEBRA_NHT_CONNECTED
) ? "(Connected)" : "",
967 vty_out(vty
, " Client list:");
968 for (ALL_LIST_ELEMENTS_RO(rnh
->client_list
, node
, client
))
969 vty_out(vty
, " %s(fd %d)%s", zebra_route_string(client
->proto
),
970 client
->sock
, rnh
->filtered
[client
->proto
] ? "(filtered)" : "");
971 if (!list_isempty(rnh
->zebra_static_route_list
))
972 vty_out(vty
, " zebra%s", rnh
->filtered
[ZEBRA_ROUTE_STATIC
] ? "(filtered)" : "");
973 vty_out(vty
, "%s", VTY_NEWLINE
);