2 * Zebra connect library for OSPFd
3 * Copyright (C) 1997, 98, 99, 2000 Kunihiro Ishiguro, Toshiaki Takada
5 * This file is part of GNU Zebra.
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; see the file COPYING; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
39 #include "ospfd/ospfd.h"
40 #include "ospfd/ospf_interface.h"
41 #include "ospfd/ospf_ism.h"
42 #include "ospfd/ospf_asbr.h"
43 #include "ospfd/ospf_asbr.h"
44 #include "ospfd/ospf_abr.h"
45 #include "ospfd/ospf_lsa.h"
46 #include "ospfd/ospf_dump.h"
47 #include "ospfd/ospf_route.h"
48 #include "ospfd/ospf_lsdb.h"
49 #include "ospfd/ospf_neighbor.h"
50 #include "ospfd/ospf_nsm.h"
51 #include "ospfd/ospf_zebra.h"
52 #include "ospfd/ospf_te.h"
54 DEFINE_MTYPE_STATIC(OSPFD
, OSPF_EXTERNAL
, "OSPF External route table")
55 DEFINE_MTYPE_STATIC(OSPFD
, OSPF_REDISTRIBUTE
, "OSPF Redistriute")
56 DEFINE_MTYPE_STATIC(OSPFD
, OSPF_DIST_ARGS
, "OSPF Distribute arguments")
58 DEFINE_HOOK(ospf_if_update
, (struct interface
* ifp
), (ifp
))
59 DEFINE_HOOK(ospf_if_delete
, (struct interface
* ifp
), (ifp
))
61 /* Zebra structure to hold current status. */
62 struct zclient
*zclient
= NULL
;
64 /* For registering threads. */
65 extern struct thread_master
*master
;
67 /* Router-id update message from zebra. */
68 static int ospf_router_id_update_zebra(int command
, struct zclient
*zclient
,
69 zebra_size_t length
, vrf_id_t vrf_id
)
71 struct ospf
*ospf
= NULL
;
72 struct prefix router_id
;
73 zebra_router_id_update_read(zclient
->ibuf
, &router_id
);
75 if (IS_DEBUG_OSPF(zebra
, ZEBRA_INTERFACE
)) {
76 char buf
[PREFIX2STR_BUFFER
];
77 prefix2str(&router_id
, buf
, sizeof(buf
));
78 zlog_debug("Zebra rcvd: router id update %s vrf %s id %u", buf
,
79 ospf_vrf_id_to_name(vrf_id
), vrf_id
);
82 ospf
= ospf_lookup_by_vrf_id(vrf_id
);
85 ospf
->router_id_zebra
= router_id
.u
.prefix4
;
86 ospf_router_id_update(ospf
);
88 if (IS_DEBUG_OSPF_EVENT
) {
89 char buf
[PREFIX2STR_BUFFER
];
91 prefix2str(&router_id
, buf
, sizeof(buf
));
93 "%s: ospf instance not found for vrf %s id %u router_id %s",
95 ospf_vrf_id_to_name(vrf_id
), vrf_id
, buf
);
101 /* Inteface addition message from zebra. */
102 static int ospf_interface_add(int command
, struct zclient
*zclient
,
103 zebra_size_t length
, vrf_id_t vrf_id
)
105 struct interface
*ifp
= NULL
;
106 struct ospf
*ospf
= NULL
;
108 ifp
= zebra_interface_add_read(zclient
->ibuf
, vrf_id
);
112 if (IS_DEBUG_OSPF(zebra
, ZEBRA_INTERFACE
))
114 "Zebra: interface add %s vrf %s[%u] index %d flags %llx metric %d mtu %d speed %u",
115 ifp
->name
, ospf_vrf_id_to_name(ifp
->vrf_id
),
116 ifp
->vrf_id
, ifp
->ifindex
,
117 (unsigned long long)ifp
->flags
, ifp
->metric
, ifp
->mtu
,
122 if (IF_DEF_PARAMS(ifp
)
123 && !OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp
), type
)) {
124 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), type
);
125 IF_DEF_PARAMS(ifp
)->type
= ospf_default_iftype(ifp
);
128 ospf
= ospf_lookup_by_vrf_id(vrf_id
);
132 ospf_if_recalculate_output_cost(ifp
);
134 ospf_if_update(ospf
, ifp
);
136 hook_call(ospf_if_update
, ifp
);
141 static int ospf_interface_delete(int command
, struct zclient
*zclient
,
142 zebra_size_t length
, vrf_id_t vrf_id
)
144 struct interface
*ifp
;
146 struct route_node
*rn
;
149 /* zebra_interface_state_read() updates interface structure in iflist */
150 ifp
= zebra_interface_state_read(s
, vrf_id
);
155 if (IS_DEBUG_OSPF(zebra
, ZEBRA_INTERFACE
))
157 "Zebra: interface delete %s vrf %s[%u] index %d flags %llx metric %d mtu %d",
158 ifp
->name
, ospf_vrf_id_to_name(ifp
->vrf_id
),
159 ifp
->vrf_id
, ifp
->ifindex
,
160 (unsigned long long)ifp
->flags
, ifp
->metric
, ifp
->mtu
);
162 hook_call(ospf_if_delete
, ifp
);
164 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
166 ospf_if_free((struct ospf_interface
*)rn
->info
);
168 if_set_index(ifp
, IFINDEX_INTERNAL
);
172 static struct interface
*zebra_interface_if_lookup(struct stream
*s
,
175 char ifname_tmp
[INTERFACE_NAMSIZ
];
177 /* Read interface name. */
178 stream_get(ifname_tmp
, s
, INTERFACE_NAMSIZ
);
180 /* And look it up. */
181 return if_lookup_by_name(ifname_tmp
, vrf_id
);
184 static int ospf_interface_state_up(int command
, struct zclient
*zclient
,
185 zebra_size_t length
, vrf_id_t vrf_id
)
187 struct interface
*ifp
;
188 struct ospf_interface
*oi
;
189 struct route_node
*rn
;
191 ifp
= zebra_interface_if_lookup(zclient
->ibuf
, vrf_id
);
196 /* Interface is already up. */
197 if (if_is_operative(ifp
)) {
198 /* Temporarily keep ifp values. */
199 struct interface if_tmp
;
200 memcpy(&if_tmp
, ifp
, sizeof(struct interface
));
202 zebra_interface_if_set_value(zclient
->ibuf
, ifp
);
204 if (IS_DEBUG_OSPF(zebra
, ZEBRA_INTERFACE
))
206 "Zebra: Interface[%s] state update speed %u -> %u, bw %d -> %d",
207 ifp
->name
, if_tmp
.speed
, ifp
->speed
,
208 if_tmp
.bandwidth
, ifp
->bandwidth
);
210 ospf_if_recalculate_output_cost(ifp
);
212 if (if_tmp
.mtu
!= ifp
->mtu
) {
213 if (IS_DEBUG_OSPF(zebra
, ZEBRA_INTERFACE
))
215 "Zebra: Interface[%s] MTU change %u -> %u.",
216 ifp
->name
, if_tmp
.mtu
, ifp
->mtu
);
218 /* Must reset the interface (simulate down/up) when MTU
225 zebra_interface_if_set_value(zclient
->ibuf
, ifp
);
227 if (IS_DEBUG_OSPF(zebra
, ZEBRA_INTERFACE
))
228 zlog_debug("Zebra: Interface[%s] state change to up.",
231 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
232 if ((oi
= rn
->info
) == NULL
)
241 static int ospf_interface_state_down(int command
, struct zclient
*zclient
,
242 zebra_size_t length
, vrf_id_t vrf_id
)
244 struct interface
*ifp
;
245 struct ospf_interface
*oi
;
246 struct route_node
*node
;
248 ifp
= zebra_interface_state_read(zclient
->ibuf
, vrf_id
);
253 if (IS_DEBUG_OSPF(zebra
, ZEBRA_INTERFACE
))
254 zlog_debug("Zebra: Interface[%s] state change to down.",
257 for (node
= route_top(IF_OIFS(ifp
)); node
; node
= route_next(node
)) {
258 if ((oi
= node
->info
) == NULL
)
266 static int ospf_interface_address_add(int command
, struct zclient
*zclient
,
267 zebra_size_t length
, vrf_id_t vrf_id
)
270 struct ospf
*ospf
= NULL
;
273 c
= zebra_interface_address_read(command
, zclient
->ibuf
, vrf_id
);
278 if (IS_DEBUG_OSPF(zebra
, ZEBRA_INTERFACE
)) {
279 char buf
[PREFIX2STR_BUFFER
];
280 prefix2str(c
->address
, buf
, sizeof(buf
));
281 zlog_debug("Zebra: interface %s address add %s vrf %s id %u",
282 c
->ifp
->name
, buf
, ospf_vrf_id_to_name(vrf_id
),
286 ospf
= ospf_lookup_by_vrf_id(vrf_id
);
290 ospf_if_update(ospf
, c
->ifp
);
292 hook_call(ospf_if_update
, c
->ifp
);
297 static int ospf_interface_address_delete(int command
, struct zclient
*zclient
,
298 zebra_size_t length
, vrf_id_t vrf_id
)
301 struct interface
*ifp
;
302 struct ospf_interface
*oi
;
303 struct route_node
*rn
;
306 c
= zebra_interface_address_read(command
, zclient
->ibuf
, vrf_id
);
311 if (IS_DEBUG_OSPF(zebra
, ZEBRA_INTERFACE
)) {
312 char buf
[PREFIX2STR_BUFFER
];
313 prefix2str(c
->address
, buf
, sizeof(buf
));
314 zlog_debug("Zebra: interface %s address delete %s",
320 p
.prefixlen
= IPV4_MAX_PREFIXLEN
;
322 rn
= route_node_lookup(IF_OIFS(ifp
), &p
);
330 route_unlock_node(rn
);
332 /* Call interface hook functions to clean up */
335 hook_call(ospf_if_update
, c
->ifp
);
342 static int ospf_interface_link_params(int command
, struct zclient
*zclient
,
345 struct interface
*ifp
;
347 ifp
= zebra_interface_link_params_read(zclient
->ibuf
);
353 ospf_mpls_te_update_if(ifp
);
358 /* VRF update for an interface. */
359 static int ospf_interface_vrf_update(int command
, struct zclient
*zclient
,
360 zebra_size_t length
, vrf_id_t vrf_id
)
362 struct interface
*ifp
= NULL
;
365 ifp
= zebra_interface_vrf_update_read(zclient
->ibuf
, vrf_id
,
370 if (IS_DEBUG_OSPF_EVENT
)
372 "%s: Rx Interface %s VRF change vrf_id %u New vrf %s id %u",
373 __PRETTY_FUNCTION__
, ifp
->name
, vrf_id
,
374 ospf_vrf_id_to_name(new_vrf_id
), new_vrf_id
);
376 /*if_update(ifp, ifp->name, strlen(ifp->name), new_vrf_id);*/
377 if_update_to_new_vrf(ifp
, new_vrf_id
);
382 void ospf_zebra_add(struct ospf
*ospf
, struct prefix_ipv4
*p
,
383 struct ospf_route
* or)
385 struct zapi_route api
;
386 struct zapi_nexthop
*api_nh
;
388 struct ospf_path
*path
;
389 struct listnode
*node
;
392 memset(&api
, 0, sizeof(api
));
393 api
.vrf_id
= ospf
->vrf_id
;
394 api
.type
= ZEBRA_ROUTE_OSPF
;
395 api
.instance
= ospf
->instance
;
396 api
.safi
= SAFI_UNICAST
;
398 memcpy(&api
.prefix
, p
, sizeof(*p
));
399 SET_FLAG(api
.message
, ZAPI_MESSAGE_NEXTHOP
);
402 SET_FLAG(api
.message
, ZAPI_MESSAGE_METRIC
);
403 if (or->path_type
== OSPF_PATH_TYPE1_EXTERNAL
)
404 api
.metric
= or->cost
+ or->u
.ext
.type2_cost
;
405 else if (or->path_type
== OSPF_PATH_TYPE2_EXTERNAL
)
406 api
.metric
= or->u
.ext
.type2_cost
;
408 api
.metric
= or->cost
;
410 /* Check if path type is ASE */
411 if (((or->path_type
== OSPF_PATH_TYPE1_EXTERNAL
)
412 || (or->path_type
== OSPF_PATH_TYPE2_EXTERNAL
))
413 && (or->u
.ext
.tag
> 0) && (or->u
.ext
.tag
<= ROUTE_TAG_MAX
)) {
414 SET_FLAG(api
.message
, ZAPI_MESSAGE_TAG
);
415 api
.tag
= or->u
.ext
.tag
;
418 /* Distance value. */
419 distance
= ospf_distance_apply(ospf
, p
, or);
421 SET_FLAG(api
.message
, ZAPI_MESSAGE_DISTANCE
);
422 api
.distance
= distance
;
425 /* Nexthop, ifindex, distance and metric information. */
426 for (ALL_LIST_ELEMENTS_RO(or->paths
, node
, path
)) {
427 if (count
>= MULTIPATH_NUM
)
429 api_nh
= &api
.nexthops
[count
];
431 if (path
->unnumbered
|| (path
->nexthop
.s_addr
!= INADDR_ANY
432 && path
->ifindex
!= 0)) {
433 #else /* HAVE_NETLINK */
434 if (path
->nexthop
.s_addr
!= INADDR_ANY
&& path
->ifindex
!= 0) {
435 #endif /* HAVE_NETLINK */
436 api_nh
->gate
.ipv4
= path
->nexthop
;
437 api_nh
->ifindex
= path
->ifindex
;
438 api_nh
->type
= NEXTHOP_TYPE_IPV4_IFINDEX
;
439 } else if (path
->nexthop
.s_addr
!= INADDR_ANY
) {
440 api_nh
->gate
.ipv4
= path
->nexthop
;
441 api_nh
->type
= NEXTHOP_TYPE_IPV4
;
443 api_nh
->ifindex
= path
->ifindex
;
444 api_nh
->type
= NEXTHOP_TYPE_IFINDEX
;
446 api_nh
->vrf_id
= ospf
->vrf_id
;
449 if (IS_DEBUG_OSPF(zebra
, ZEBRA_REDISTRIBUTE
)) {
450 char buf
[2][INET_ADDRSTRLEN
];
451 struct interface
*ifp
;
453 ifp
= if_lookup_by_index(path
->ifindex
, ospf
->vrf_id
);
456 "Zebra: Route add %s nexthop %s, ifindex=%d %s",
457 prefix2str(p
, buf
[0], sizeof(buf
[0])),
458 inet_ntop(AF_INET
, &path
->nexthop
,
459 buf
[1], sizeof(buf
[1])),
460 path
->ifindex
, ifp
? ifp
->name
: " ");
463 api
.nexthop_num
= count
;
465 zclient_route_send(ZEBRA_ROUTE_ADD
, zclient
, &api
);
468 void ospf_zebra_delete(struct ospf
*ospf
, struct prefix_ipv4
*p
,
469 struct ospf_route
* or)
471 struct zapi_route api
;
473 memset(&api
, 0, sizeof(api
));
474 api
.vrf_id
= ospf
->vrf_id
;
475 api
.type
= ZEBRA_ROUTE_OSPF
;
476 api
.instance
= ospf
->instance
;
477 api
.safi
= SAFI_UNICAST
;
478 memcpy(&api
.prefix
, p
, sizeof(*p
));
480 if (IS_DEBUG_OSPF(zebra
, ZEBRA_REDISTRIBUTE
)) {
481 char buf
[PREFIX2STR_BUFFER
];
482 zlog_debug("Zebra: Route delete %s",
483 prefix2str(p
, buf
, sizeof(buf
)));
486 zclient_route_send(ZEBRA_ROUTE_DELETE
, zclient
, &api
);
489 void ospf_zebra_add_discard(struct ospf
*ospf
, struct prefix_ipv4
*p
)
491 struct zapi_route api
;
493 memset(&api
, 0, sizeof(api
));
494 api
.vrf_id
= ospf
->vrf_id
;
495 api
.type
= ZEBRA_ROUTE_OSPF
;
496 api
.instance
= ospf
->instance
;
497 api
.safi
= SAFI_UNICAST
;
498 memcpy(&api
.prefix
, p
, sizeof(*p
));
499 zapi_route_set_blackhole(&api
, BLACKHOLE_NULL
);
501 zclient_route_send(ZEBRA_ROUTE_ADD
, zclient
, &api
);
503 if (IS_DEBUG_OSPF(zebra
, ZEBRA_REDISTRIBUTE
)) {
504 char buf
[PREFIX2STR_BUFFER
];
505 zlog_debug("Zebra: Route add discard %s",
506 prefix2str(p
, buf
, sizeof(buf
)));
510 void ospf_zebra_delete_discard(struct ospf
*ospf
, struct prefix_ipv4
*p
)
512 struct zapi_route api
;
514 memset(&api
, 0, sizeof(api
));
515 api
.vrf_id
= ospf
->vrf_id
;
516 api
.type
= ZEBRA_ROUTE_OSPF
;
517 api
.instance
= ospf
->instance
;
518 api
.safi
= SAFI_UNICAST
;
519 memcpy(&api
.prefix
, p
, sizeof(*p
));
520 zapi_route_set_blackhole(&api
, BLACKHOLE_NULL
);
522 zclient_route_send(ZEBRA_ROUTE_DELETE
, zclient
, &api
);
524 if (IS_DEBUG_OSPF(zebra
, ZEBRA_REDISTRIBUTE
)) {
525 char buf
[PREFIX2STR_BUFFER
];
526 zlog_debug("Zebra: Route delete discard %s",
527 prefix2str(p
, buf
, sizeof(buf
)));
531 struct ospf_external
*ospf_external_lookup(struct ospf
*ospf
, uint8_t type
,
532 unsigned short instance
)
534 struct list
*ext_list
;
535 struct listnode
*node
;
536 struct ospf_external
*ext
;
538 ext_list
= ospf
->external
[type
];
542 for (ALL_LIST_ELEMENTS_RO(ext_list
, node
, ext
))
543 if (ext
->instance
== instance
)
549 struct ospf_external
*ospf_external_add(struct ospf
*ospf
, uint8_t type
,
550 unsigned short instance
)
552 struct list
*ext_list
;
553 struct ospf_external
*ext
;
555 ext
= ospf_external_lookup(ospf
, type
, instance
);
559 if (!ospf
->external
[type
])
560 ospf
->external
[type
] = list_new();
562 ext_list
= ospf
->external
[type
];
563 ext
= (struct ospf_external
*)XCALLOC(MTYPE_OSPF_EXTERNAL
,
564 sizeof(struct ospf_external
));
565 ext
->instance
= instance
;
566 EXTERNAL_INFO(ext
) = route_table_init();
568 listnode_add(ext_list
, ext
);
573 void ospf_external_del(struct ospf
*ospf
, uint8_t type
, unsigned short instance
)
575 struct ospf_external
*ext
;
577 ext
= ospf_external_lookup(ospf
, type
, instance
);
580 if (EXTERNAL_INFO(ext
))
581 route_table_finish(EXTERNAL_INFO(ext
));
583 listnode_delete(ospf
->external
[type
], ext
);
585 if (!ospf
->external
[type
]->count
)
586 list_delete(&ospf
->external
[type
]);
588 XFREE(MTYPE_OSPF_EXTERNAL
, ext
);
592 struct ospf_redist
*ospf_redist_lookup(struct ospf
*ospf
, uint8_t type
,
593 unsigned short instance
)
595 struct list
*red_list
;
596 struct listnode
*node
;
597 struct ospf_redist
*red
;
599 red_list
= ospf
->redist
[type
];
603 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
))
604 if (red
->instance
== instance
)
610 struct ospf_redist
*ospf_redist_add(struct ospf
*ospf
, uint8_t type
,
611 unsigned short instance
)
613 struct list
*red_list
;
614 struct ospf_redist
*red
;
616 red
= ospf_redist_lookup(ospf
, type
, instance
);
620 if (!ospf
->redist
[type
])
621 ospf
->redist
[type
] = list_new();
623 red_list
= ospf
->redist
[type
];
624 red
= (struct ospf_redist
*)XCALLOC(MTYPE_OSPF_REDISTRIBUTE
,
625 sizeof(struct ospf_redist
));
626 red
->instance
= instance
;
627 red
->dmetric
.type
= -1;
628 red
->dmetric
.value
= -1;
629 ROUTEMAP_NAME(red
) = NULL
;
630 ROUTEMAP(red
) = NULL
;
632 listnode_add(red_list
, red
);
637 void ospf_redist_del(struct ospf
*ospf
, uint8_t type
, unsigned short instance
)
639 struct ospf_redist
*red
;
641 red
= ospf_redist_lookup(ospf
, type
, instance
);
644 listnode_delete(ospf
->redist
[type
], red
);
645 if (!ospf
->redist
[type
]->count
) {
646 list_delete(&ospf
->redist
[type
]);
648 ospf_routemap_unset(red
);
649 XFREE(MTYPE_OSPF_REDISTRIBUTE
, red
);
654 int ospf_is_type_redistributed(struct ospf
*ospf
, int type
,
655 unsigned short instance
)
657 return (DEFAULT_ROUTE_TYPE(type
)
658 ? vrf_bitmap_check(zclient
->default_information
,
661 && redist_check_instance(
662 &zclient
->mi_redist
[AFI_IP
][type
],
666 zclient
->redist
[AFI_IP
][type
],
670 int ospf_redistribute_set(struct ospf
*ospf
, int type
, unsigned short instance
,
671 int mtype
, int mvalue
)
674 struct ospf_redist
*red
;
676 red
= ospf_redist_lookup(ospf
, type
, instance
);
680 "Redistribute[%s][%d]: Lookup failed Type[%d] , Metric[%d]",
681 ospf_redist_string(type
), instance
,
682 metric_type(ospf
, type
, instance
),
683 metric_value(ospf
, type
, instance
));
684 return CMD_WARNING_CONFIG_FAILED
;
687 if (ospf_is_type_redistributed(ospf
, type
, instance
)) {
688 if (mtype
!= red
->dmetric
.type
) {
689 red
->dmetric
.type
= mtype
;
690 force
= LSA_REFRESH_FORCE
;
692 if (mvalue
!= red
->dmetric
.value
) {
693 red
->dmetric
.value
= mvalue
;
694 force
= LSA_REFRESH_FORCE
;
697 ospf_external_lsa_refresh_type(ospf
, type
, instance
, force
);
699 if (IS_DEBUG_OSPF(zebra
, ZEBRA_REDISTRIBUTE
))
701 "Redistribute[%s][%d]: Refresh Type[%d], Metric[%d]",
702 ospf_redist_string(type
), instance
,
703 metric_type(ospf
, type
, instance
),
704 metric_value(ospf
, type
, instance
));
709 red
->dmetric
.type
= mtype
;
710 red
->dmetric
.value
= mvalue
;
712 ospf_external_add(ospf
, type
, instance
);
714 zclient_redistribute(ZEBRA_REDISTRIBUTE_ADD
, zclient
, AFI_IP
, type
,
715 instance
, ospf
->vrf_id
);
717 if (IS_DEBUG_OSPF(zebra
, ZEBRA_REDISTRIBUTE
))
719 "Redistribute[%s][%d] vrf id %u: Start Type[%d], Metric[%d]",
720 ospf_redist_string(type
), instance
, ospf
->vrf_id
,
721 metric_type(ospf
, type
, instance
),
722 metric_value(ospf
, type
, instance
));
724 ospf_asbr_status_update(ospf
, ++ospf
->redistribute
);
729 int ospf_redistribute_unset(struct ospf
*ospf
, int type
,
730 unsigned short instance
)
732 if (type
== zclient
->redist_default
&& instance
== zclient
->instance
)
735 if (!ospf_is_type_redistributed(ospf
, type
, instance
))
738 zclient_redistribute(ZEBRA_REDISTRIBUTE_DELETE
, zclient
, AFI_IP
, type
,
739 instance
, ospf
->vrf_id
);
741 if (IS_DEBUG_OSPF(zebra
, ZEBRA_REDISTRIBUTE
))
742 zlog_debug("Redistribute[%s][%d] vrf id %u: Stop",
743 ospf_redist_string(type
), instance
, ospf
->vrf_id
);
745 /* Remove the routes from OSPF table. */
746 ospf_redistribute_withdraw(ospf
, type
, instance
);
748 ospf_external_del(ospf
, type
, instance
);
750 ospf_asbr_status_update(ospf
, --ospf
->redistribute
);
755 int ospf_redistribute_default_set(struct ospf
*ospf
, int originate
, int mtype
,
758 struct ospf_external
*ext
;
759 struct prefix_ipv4 p
;
760 struct in_addr nexthop
;
761 int cur_originate
= ospf
->default_originate
;
768 ospf
->default_originate
= originate
;
770 ospf_external_add(ospf
, DEFAULT_ROUTE
, 0);
772 if (cur_originate
== DEFAULT_ORIGINATE_NONE
) {
773 /* First time configuration */
774 if (IS_DEBUG_OSPF(zebra
, ZEBRA_REDISTRIBUTE
))
775 zlog_debug("Redistribute[DEFAULT]: Start Type[%d], Metric[%d]",
776 metric_type(ospf
, DEFAULT_ROUTE
, 0),
777 metric_value(ospf
, DEFAULT_ROUTE
, 0));
779 if (ospf
->router_id
.s_addr
== 0)
780 ospf
->external_origin
|= (1 << DEFAULT_ROUTE
);
781 if ((originate
== DEFAULT_ORIGINATE_ALWAYS
)
782 && (ospf
->router_id
.s_addr
)) {
784 /* always , so originate lsa even it doesn't
787 ospf_external_info_add(ospf
, DEFAULT_ROUTE
, 0,
789 ospf_external_lsa_refresh_default(ospf
);
791 } else if (originate
== DEFAULT_ORIGINATE_ZEBRA
) {
792 /* Send msg to Zebra to validate default route
795 zclient_redistribute_default(
796 ZEBRA_REDISTRIBUTE_DEFAULT_ADD
,
797 zclient
, ospf
->vrf_id
);
800 ospf_asbr_status_update(ospf
, ++ospf
->redistribute
);
804 } else if (originate
== cur_originate
) {
805 /* Refresh the lsa since metric might different */
806 if (IS_DEBUG_OSPF(zebra
, ZEBRA_REDISTRIBUTE
))
808 "Redistribute[%s]: Refresh Type[%d], Metric[%d]",
809 ospf_redist_string(DEFAULT_ROUTE
),
810 metric_type(ospf
, DEFAULT_ROUTE
, 0),
811 metric_value(ospf
, DEFAULT_ROUTE
, 0));
813 ospf_external_lsa_refresh_default(ospf
);
816 /* "default-info originate always" configured now,
817 * where "default-info originate" configured previoulsly.
819 if (originate
== DEFAULT_ORIGINATE_ALWAYS
) {
821 zclient_redistribute_default(
822 ZEBRA_REDISTRIBUTE_DEFAULT_DELETE
,
823 zclient
, ospf
->vrf_id
);
824 /* here , ex-info should be added since ex-info might
825 * have not updated earlier if def route is not exist.
826 * If ex-iinfo ex-info already exist , it will return
829 ospf_external_info_add(ospf
, DEFAULT_ROUTE
, 0,
831 ospf_external_lsa_refresh_default(ospf
);
834 /* "default-info originate" configured now,where
835 * "default-info originate always" configured
839 ospf_external_lsa_flush(ospf
, DEFAULT_ROUTE
, &p
, 0);
841 ext
= ospf_external_lookup(ospf
, DEFAULT_ROUTE
, 0);
842 if (ext
&& EXTERNAL_INFO(ext
))
843 ospf_external_info_delete(ospf
,
844 DEFAULT_ROUTE
, 0, p
);
846 zclient_redistribute_default(
847 ZEBRA_REDISTRIBUTE_DEFAULT_ADD
,
848 zclient
, ospf
->vrf_id
);
854 int ospf_redistribute_default_unset(struct ospf
*ospf
)
856 if (ospf
->default_originate
== DEFAULT_ORIGINATE_ZEBRA
) {
857 if (!ospf_is_type_redistributed(ospf
, DEFAULT_ROUTE
, 0))
859 zclient_redistribute_default(ZEBRA_REDISTRIBUTE_DEFAULT_DELETE
,
860 zclient
, ospf
->vrf_id
);
863 ospf
->default_originate
= DEFAULT_ORIGINATE_NONE
;
865 if (IS_DEBUG_OSPF(zebra
, ZEBRA_REDISTRIBUTE
))
866 zlog_debug("Redistribute[DEFAULT]: Stop");
868 // Pending: how does the external_info cleanup work in this case?
870 ospf_asbr_status_update(ospf
, --ospf
->redistribute
);
875 static int ospf_external_lsa_originate_check(struct ospf
*ospf
,
876 struct external_info
*ei
)
878 /* If prefix is multicast, then do not originate LSA. */
879 if (IN_MULTICAST(htonl(ei
->p
.prefix
.s_addr
))) {
881 "LSA[Type5:%s]: Not originate AS-external-LSA, "
882 "Prefix belongs multicast",
883 inet_ntoa(ei
->p
.prefix
));
887 /* Take care of default-originate. */
888 if (is_prefix_default(&ei
->p
))
889 if (ospf
->default_originate
== DEFAULT_ORIGINATE_NONE
) {
891 "LSA[Type5:0.0.0.0]: Not originate AS-external-LSA "
899 /* If connected prefix is OSPF enable interface, then do not announce. */
900 int ospf_distribute_check_connected(struct ospf
*ospf
, struct external_info
*ei
)
902 struct listnode
*node
;
903 struct ospf_interface
*oi
;
906 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
))
907 if (prefix_match(oi
->address
, (struct prefix
*)&ei
->p
))
912 /* return 1 if external LSA must be originated, 0 otherwise */
913 int ospf_redistribute_check(struct ospf
*ospf
, struct external_info
*ei
,
916 struct route_map_set_values save_values
;
917 struct prefix_ipv4
*p
= &ei
->p
;
918 struct ospf_redist
*red
;
919 uint8_t type
= is_prefix_default(&ei
->p
) ? DEFAULT_ROUTE
: ei
->type
;
920 unsigned short instance
= is_prefix_default(&ei
->p
) ? 0 : ei
->instance
;
925 if (!ospf_external_lsa_originate_check(ospf
, ei
))
928 /* Take care connected route. */
929 if (type
== ZEBRA_ROUTE_CONNECT
930 && !ospf_distribute_check_connected(ospf
, ei
))
933 if (!DEFAULT_ROUTE_TYPE(type
) && DISTRIBUTE_NAME(ospf
, type
))
934 /* distirbute-list exists, but access-list may not? */
935 if (DISTRIBUTE_LIST(ospf
, type
))
936 if (access_list_apply(DISTRIBUTE_LIST(ospf
, type
), p
)
938 if (IS_DEBUG_OSPF(zebra
, ZEBRA_REDISTRIBUTE
)) {
939 char buf
[PREFIX2STR_BUFFER
];
941 "Redistribute[%s]: %s filtered by distribute-list.",
942 ospf_redist_string(type
),
943 prefix2str(p
, buf
, sizeof(buf
)));
948 save_values
= ei
->route_map_set
;
949 ospf_reset_route_map_set_values(&ei
->route_map_set
);
951 /* apply route-map if needed */
952 red
= ospf_redist_lookup(ospf
, type
, instance
);
953 if (red
&& ROUTEMAP_NAME(red
)) {
956 ret
= route_map_apply(ROUTEMAP(red
), (struct prefix
*)p
,
959 if (ret
== RMAP_DENYMATCH
) {
960 ei
->route_map_set
= save_values
;
961 if (IS_DEBUG_OSPF(zebra
, ZEBRA_REDISTRIBUTE
)) {
962 char buf
[PREFIX2STR_BUFFER
];
964 "Redistribute[%s]: %s filtered by route-map.",
965 ospf_redist_string(type
),
966 prefix2str(p
, buf
, sizeof(buf
)));
971 /* check if 'route-map set' changed something */
973 *changed
= !ospf_route_map_set_compare(
974 &ei
->route_map_set
, &save_values
);
980 /* OSPF route-map set for redistribution */
981 void ospf_routemap_set(struct ospf_redist
*red
, const char *name
)
983 if (ROUTEMAP_NAME(red
))
984 free(ROUTEMAP_NAME(red
));
986 ROUTEMAP_NAME(red
) = strdup(name
);
987 ROUTEMAP(red
) = route_map_lookup_by_name(name
);
990 void ospf_routemap_unset(struct ospf_redist
*red
)
992 if (ROUTEMAP_NAME(red
))
993 free(ROUTEMAP_NAME(red
));
995 ROUTEMAP_NAME(red
) = NULL
;
996 ROUTEMAP(red
) = NULL
;
999 /* Zebra route add and delete treatment. */
1000 static int ospf_zebra_read_route(int command
, struct zclient
*zclient
,
1001 zebra_size_t length
, vrf_id_t vrf_id
)
1003 struct zapi_route api
;
1004 struct prefix_ipv4 p
;
1005 unsigned long ifindex
;
1006 struct in_addr nexthop
;
1007 struct external_info
*ei
;
1012 ospf
= ospf_lookup_by_vrf_id(vrf_id
);
1016 if (zapi_route_decode(zclient
->ibuf
, &api
) < 0)
1019 ifindex
= api
.nexthops
[0].ifindex
;
1020 nexthop
= api
.nexthops
[0].gate
.ipv4
;
1023 memcpy(&p
, &api
.prefix
, sizeof(p
));
1024 if (IPV4_NET127(ntohl(p
.prefix
.s_addr
)))
1027 /* Re-destributed route is default route.
1028 * Here, route type is used as 'ZEBRA_ROUTE_KERNEL' for
1029 * updating ex-info. But in resetting (no default-info
1030 * originate)ZEBRA_ROUTE_MAX is used to delete the ex-info.
1031 * Resolved this inconsistency by maintaining same route type.
1033 if (is_prefix_default(&p
))
1034 rt_type
= DEFAULT_ROUTE
;
1036 if (IS_DEBUG_OSPF(zebra
, ZEBRA_REDISTRIBUTE
)) {
1037 char buf_prefix
[PREFIX_STRLEN
];
1038 prefix2str(&api
.prefix
, buf_prefix
, sizeof(buf_prefix
));
1040 zlog_debug("%s: from client %s: vrf_id %d, p %s", __func__
,
1041 zebra_route_string(api
.type
), vrf_id
, buf_prefix
);
1044 if (command
== ZEBRA_REDISTRIBUTE_ROUTE_ADD
) {
1045 /* XXX|HACK|TODO|FIXME:
1046 * Maybe we should ignore reject/blackhole routes? Testing
1047 * shows that there is no problems though and this is only way
1048 * to "summarize" routes in ASBR at the moment. Maybe we need
1049 * just a better generalised solution for these types?
1052 /* Protocol tag overwrites all other tag value sent by zebra */
1053 if (ospf
->dtag
[rt_type
] > 0)
1054 api
.tag
= ospf
->dtag
[rt_type
];
1057 * Given zebra sends update for a prefix via ADD message, it
1059 * be considered as an implicit DEL for that prefix with other
1063 for (i
= 0; i
<= ZEBRA_ROUTE_MAX
; i
++)
1065 ospf_external_info_delete(ospf
, i
, api
.instance
,
1068 ei
= ospf_external_info_add(ospf
, rt_type
, api
.instance
, p
,
1069 ifindex
, nexthop
, api
.tag
);
1071 /* Nothing has changed, so nothing to do; return */
1074 if (ospf
->router_id
.s_addr
== 0)
1075 /* Set flags to generate AS-external-LSA originate event
1076 for each redistributed protocols later. */
1077 ospf
->external_origin
|= (1 << rt_type
);
1080 if (is_prefix_default(&p
))
1081 ospf_external_lsa_refresh_default(ospf
);
1083 struct ospf_lsa
*current
;
1085 current
= ospf_external_info_find_lsa(
1088 ospf_external_lsa_originate(
1093 ZEBRA_REDISTRIBUTE
))
1095 "ospf_zebra_read_route() : %s refreshing LSA",
1098 ospf_external_lsa_refresh(
1105 } else /* if (command == ZEBRA_REDISTRIBUTE_ROUTE_DEL) */
1107 ospf_external_info_delete(ospf
, rt_type
, api
.instance
, p
);
1108 if (is_prefix_default(&p
))
1109 ospf_external_lsa_refresh_default(ospf
);
1111 ospf_external_lsa_flush(ospf
, rt_type
, &p
,
1112 ifindex
/*, nexthop */);
1119 int ospf_distribute_list_out_set(struct ospf
*ospf
, int type
, const char *name
)
1121 /* Lookup access-list for distribute-list. */
1122 DISTRIBUTE_LIST(ospf
, type
) = access_list_lookup(AFI_IP
, name
);
1124 /* Clear previous distribute-name. */
1125 if (DISTRIBUTE_NAME(ospf
, type
))
1126 free(DISTRIBUTE_NAME(ospf
, type
));
1128 /* Set distribute-name. */
1129 DISTRIBUTE_NAME(ospf
, type
) = strdup(name
);
1131 /* If access-list have been set, schedule update timer. */
1132 if (DISTRIBUTE_LIST(ospf
, type
))
1133 ospf_distribute_list_update(ospf
, type
, 0);
1138 int ospf_distribute_list_out_unset(struct ospf
*ospf
, int type
,
1141 /* Schedule update timer. */
1142 if (DISTRIBUTE_LIST(ospf
, type
))
1143 ospf_distribute_list_update(ospf
, type
, 0);
1145 /* Unset distribute-list. */
1146 DISTRIBUTE_LIST(ospf
, type
) = NULL
;
1148 /* Clear distribute-name. */
1149 if (DISTRIBUTE_NAME(ospf
, type
))
1150 free(DISTRIBUTE_NAME(ospf
, type
));
1152 DISTRIBUTE_NAME(ospf
, type
) = NULL
;
1157 /* distribute-list update timer. */
1158 static int ospf_distribute_list_update_timer(struct thread
*thread
)
1160 struct route_node
*rn
;
1161 struct external_info
*ei
;
1162 struct route_table
*rt
;
1163 struct ospf_lsa
*lsa
;
1164 int type
, default_refresh
= 0, arg_type
;
1165 struct ospf
*ospf
= NULL
;
1166 void **arg
= THREAD_ARG(thread
);
1168 ospf
= (struct ospf
*)arg
[0];
1169 arg_type
= (int)(intptr_t)arg
[1];
1174 ospf
->t_distribute_update
= NULL
;
1176 zlog_info("Zebra[Redistribute]: distribute-list update timer fired!");
1178 if (IS_DEBUG_OSPF_EVENT
) {
1180 "%s: ospf distribute-list update arg_type %d vrf %s id %d",
1181 __PRETTY_FUNCTION__
, arg_type
,
1182 ospf_vrf_id_to_name(ospf
->vrf_id
), ospf
->vrf_id
);
1185 /* foreach all external info. */
1186 for (type
= 0; type
<= ZEBRA_ROUTE_MAX
; type
++) {
1187 struct list
*ext_list
;
1188 struct listnode
*node
;
1189 struct ospf_external
*ext
;
1191 ext_list
= ospf
->external
[type
];
1195 for (ALL_LIST_ELEMENTS_RO(ext_list
, node
, ext
)) {
1196 rt
= ext
->external_info
;
1199 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
))
1200 if ((ei
= rn
->info
) != NULL
) {
1201 if (is_prefix_default(&ei
->p
))
1202 default_refresh
= 1;
1204 (lsa
= ospf_external_info_find_lsa(
1206 ospf_external_lsa_refresh(
1208 LSA_REFRESH_IF_CHANGED
);
1210 ospf_external_lsa_originate(
1215 if (default_refresh
)
1216 ospf_external_lsa_refresh_default(ospf
);
1218 XFREE(MTYPE_OSPF_DIST_ARGS
, arg
);
1222 /* Update distribute-list and set timer to apply access-list. */
1223 void ospf_distribute_list_update(struct ospf
*ospf
, int type
,
1224 unsigned short instance
)
1226 struct route_table
*rt
;
1227 struct ospf_external
*ext
;
1228 void **args
= XCALLOC(MTYPE_OSPF_DIST_ARGS
, sizeof(void *) * 2);
1231 args
[1] = (void *)((ptrdiff_t)type
);
1233 /* External info does not exist. */
1234 ext
= ospf_external_lookup(ospf
, type
, instance
);
1235 if (!ext
|| !(rt
= EXTERNAL_INFO(ext
))) {
1236 XFREE(MTYPE_OSPF_DIST_ARGS
, args
);
1240 /* If exists previously invoked thread, then let it continue. */
1241 if (ospf
->t_distribute_update
) {
1242 XFREE(MTYPE_OSPF_DIST_ARGS
, args
);
1247 ospf
->t_distribute_update
= NULL
;
1248 thread_add_timer_msec(master
, ospf_distribute_list_update_timer
,
1249 (void **)args
, ospf
->min_ls_interval
,
1250 &ospf
->t_distribute_update
);
1253 /* If access-list is updated, apply some check. */
1254 static void ospf_filter_update(struct access_list
*access
)
1259 struct ospf_area
*area
;
1260 struct listnode
*node
, *n1
;
1262 /* If OSPF instance does not exist, return right now. */
1263 if (listcount(om
->ospf
) == 0)
1266 /* Iterate all ospf [VRF] instances */
1267 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, n1
, ospf
)) {
1268 /* Update distribute-list, and apply filter. */
1269 for (type
= 0; type
<= ZEBRA_ROUTE_MAX
; type
++) {
1270 struct list
*red_list
;
1271 struct ospf_redist
*red
;
1273 red_list
= ospf
->redist
[type
];
1275 for (ALL_LIST_ELEMENTS_RO(red_list
, node
,
1277 if (ROUTEMAP(red
)) {
1278 /* if route-map is not NULL it
1280 * using this access list */
1281 ospf_distribute_list_update(
1287 /* There is place for route-map for default-information
1288 * (ZEBRA_ROUTE_MAX),
1289 * but no distribute list. */
1290 if (type
== ZEBRA_ROUTE_MAX
)
1293 if (DISTRIBUTE_NAME(ospf
, type
)) {
1294 /* Keep old access-list for distribute-list. */
1295 struct access_list
*old
=
1296 DISTRIBUTE_LIST(ospf
, type
);
1298 /* Update access-list for distribute-list. */
1299 DISTRIBUTE_LIST(ospf
, type
) =
1302 DISTRIBUTE_NAME(ospf
, type
));
1304 /* No update for this distribute type. */
1306 && DISTRIBUTE_LIST(ospf
, type
) == NULL
)
1309 /* Schedule distribute-list update timer. */
1310 if (DISTRIBUTE_LIST(ospf
, type
) == NULL
1311 || strcmp(DISTRIBUTE_NAME(ospf
, type
),
1314 ospf_distribute_list_update(ospf
, type
,
1319 /* Update Area access-list. */
1320 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1321 if (EXPORT_NAME(area
)) {
1322 EXPORT_LIST(area
) = NULL
;
1326 if (IMPORT_NAME(area
)) {
1327 IMPORT_LIST(area
) = NULL
;
1332 /* Schedule ABR tasks -- this will be changed -- takada. */
1333 if (IS_OSPF_ABR(ospf
) && abr_inv
)
1334 ospf_schedule_abr_task(ospf
);
1338 /* If prefix-list is updated, do some updates. */
1339 void ospf_prefix_list_update(struct prefix_list
*plist
)
1341 struct ospf
*ospf
= NULL
;
1344 struct ospf_area
*area
;
1345 struct listnode
*node
, *n1
;
1347 /* If OSPF instatnce does not exist, return right now. */
1348 if (listcount(om
->ospf
) == 0)
1351 /* Iterate all ospf [VRF] instances */
1352 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, n1
, ospf
)) {
1354 /* Update all route-maps which are used
1355 * as redistribution filters.
1356 * They might use prefix-list.
1358 for (type
= 0; type
<= ZEBRA_ROUTE_MAX
; type
++) {
1359 struct list
*red_list
;
1360 struct ospf_redist
*red
;
1362 red_list
= ospf
->redist
[type
];
1364 for (ALL_LIST_ELEMENTS_RO(red_list
, node
,
1366 if (ROUTEMAP(red
)) {
1367 /* if route-map is not NULL
1369 * this prefix list */
1370 ospf_distribute_list_update(
1378 /* Update area filter-lists. */
1379 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
1380 /* Update filter-list in. */
1381 if (PREFIX_NAME_IN(area
))
1382 if (strcmp(PREFIX_NAME_IN(area
),
1383 prefix_list_name(plist
))
1385 PREFIX_LIST_IN(area
) =
1388 PREFIX_NAME_IN(area
));
1392 /* Update filter-list out. */
1393 if (PREFIX_NAME_OUT(area
))
1394 if (strcmp(PREFIX_NAME_OUT(area
),
1395 prefix_list_name(plist
))
1397 PREFIX_LIST_IN(area
) =
1400 PREFIX_NAME_OUT(area
));
1405 /* Schedule ABR task. */
1406 if (IS_OSPF_ABR(ospf
) && abr_inv
)
1407 ospf_schedule_abr_task(ospf
);
1411 static struct ospf_distance
*ospf_distance_new(void)
1413 return XCALLOC(MTYPE_OSPF_DISTANCE
, sizeof(struct ospf_distance
));
1416 static void ospf_distance_free(struct ospf_distance
*odistance
)
1418 XFREE(MTYPE_OSPF_DISTANCE
, odistance
);
1421 int ospf_distance_set(struct vty
*vty
, struct ospf
*ospf
,
1422 const char *distance_str
, const char *ip_str
,
1423 const char *access_list_str
)
1426 struct prefix_ipv4 p
;
1428 struct route_node
*rn
;
1429 struct ospf_distance
*odistance
;
1431 ret
= str2prefix_ipv4(ip_str
, &p
);
1433 vty_out(vty
, "Malformed prefix\n");
1434 return CMD_WARNING_CONFIG_FAILED
;
1437 distance
= atoi(distance_str
);
1439 /* Get OSPF distance node. */
1440 rn
= route_node_get(ospf
->distance_table
, (struct prefix
*)&p
);
1442 odistance
= rn
->info
;
1443 route_unlock_node(rn
);
1445 odistance
= ospf_distance_new();
1446 rn
->info
= odistance
;
1449 /* Set distance value. */
1450 odistance
->distance
= distance
;
1452 /* Reset access-list configuration. */
1453 if (odistance
->access_list
) {
1454 free(odistance
->access_list
);
1455 odistance
->access_list
= NULL
;
1457 if (access_list_str
)
1458 odistance
->access_list
= strdup(access_list_str
);
1463 int ospf_distance_unset(struct vty
*vty
, struct ospf
*ospf
,
1464 const char *distance_str
, const char *ip_str
,
1465 char const *access_list_str
)
1468 struct prefix_ipv4 p
;
1469 struct route_node
*rn
;
1470 struct ospf_distance
*odistance
;
1472 ret
= str2prefix_ipv4(ip_str
, &p
);
1474 vty_out(vty
, "Malformed prefix\n");
1475 return CMD_WARNING_CONFIG_FAILED
;
1478 rn
= route_node_lookup(ospf
->distance_table
, (struct prefix
*)&p
);
1480 vty_out(vty
, "Can't find specified prefix\n");
1481 return CMD_WARNING_CONFIG_FAILED
;
1484 odistance
= rn
->info
;
1486 if (odistance
->access_list
)
1487 free(odistance
->access_list
);
1488 ospf_distance_free(odistance
);
1491 route_unlock_node(rn
);
1492 route_unlock_node(rn
);
1497 void ospf_distance_reset(struct ospf
*ospf
)
1499 struct route_node
*rn
;
1500 struct ospf_distance
*odistance
;
1502 for (rn
= route_top(ospf
->distance_table
); rn
; rn
= route_next(rn
))
1503 if ((odistance
= rn
->info
) != NULL
) {
1504 if (odistance
->access_list
)
1505 free(odistance
->access_list
);
1506 ospf_distance_free(odistance
);
1508 route_unlock_node(rn
);
1512 uint8_t ospf_distance_apply(struct ospf
*ospf
, struct prefix_ipv4
*p
,
1513 struct ospf_route
* or)
1519 if (ospf
->distance_intra
)
1520 if (or->path_type
== OSPF_PATH_INTRA_AREA
)
1521 return ospf
->distance_intra
;
1523 if (ospf
->distance_inter
)
1524 if (or->path_type
== OSPF_PATH_INTER_AREA
)
1525 return ospf
->distance_inter
;
1527 if (ospf
->distance_external
)
1528 if (or->path_type
== OSPF_PATH_TYPE1_EXTERNAL
||
1529 or->path_type
== OSPF_PATH_TYPE2_EXTERNAL
)
1530 return ospf
->distance_external
;
1532 if (ospf
->distance_all
)
1533 return ospf
->distance_all
;
1538 void ospf_zebra_vrf_register(struct ospf
*ospf
)
1540 if (!zclient
|| zclient
->sock
< 0 || !ospf
)
1543 if (ospf
->vrf_id
!= VRF_UNKNOWN
) {
1544 if (IS_DEBUG_OSPF_EVENT
)
1545 zlog_debug("%s: Register VRF %s id %u",
1546 __PRETTY_FUNCTION__
,
1547 ospf_vrf_id_to_name(ospf
->vrf_id
),
1549 zclient_send_reg_requests(zclient
, ospf
->vrf_id
);
1553 void ospf_zebra_vrf_deregister(struct ospf
*ospf
)
1555 if (!zclient
|| zclient
->sock
< 0 || !ospf
)
1558 if (ospf
->vrf_id
!= VRF_DEFAULT
&& ospf
->vrf_id
!= VRF_UNKNOWN
) {
1559 if (IS_DEBUG_OSPF_EVENT
)
1560 zlog_debug("%s: De-Register VRF %s id %u to Zebra.",
1561 __PRETTY_FUNCTION__
,
1562 ospf_vrf_id_to_name(ospf
->vrf_id
),
1564 /* Deregister for router-id, interfaces,
1565 * redistributed routes. */
1566 zclient_send_dereg_requests(zclient
, ospf
->vrf_id
);
1569 static void ospf_zebra_connected(struct zclient
*zclient
)
1571 /* Send the client registration */
1572 bfd_client_sendmsg(zclient
, ZEBRA_BFD_CLIENT_REGISTER
);
1574 zclient_send_reg_requests(zclient
, VRF_DEFAULT
);
1577 void ospf_zebra_init(struct thread_master
*master
, unsigned short instance
)
1579 /* Allocate zebra structure. */
1580 zclient
= zclient_new(master
, &zclient_options_default
);
1581 zclient_init(zclient
, ZEBRA_ROUTE_OSPF
, instance
, &ospfd_privs
);
1582 zclient
->zebra_connected
= ospf_zebra_connected
;
1583 zclient
->router_id_update
= ospf_router_id_update_zebra
;
1584 zclient
->interface_add
= ospf_interface_add
;
1585 zclient
->interface_delete
= ospf_interface_delete
;
1586 zclient
->interface_up
= ospf_interface_state_up
;
1587 zclient
->interface_down
= ospf_interface_state_down
;
1588 zclient
->interface_address_add
= ospf_interface_address_add
;
1589 zclient
->interface_address_delete
= ospf_interface_address_delete
;
1590 zclient
->interface_link_params
= ospf_interface_link_params
;
1591 zclient
->interface_vrf_update
= ospf_interface_vrf_update
;
1593 zclient
->redistribute_route_add
= ospf_zebra_read_route
;
1594 zclient
->redistribute_route_del
= ospf_zebra_read_route
;
1596 access_list_add_hook(ospf_filter_update
);
1597 access_list_delete_hook(ospf_filter_update
);
1598 prefix_list_add_hook(ospf_prefix_list_update
);
1599 prefix_list_delete_hook(ospf_prefix_list_update
);