]> git.proxmox.com Git - mirror_frr.git/blob - ospfd/ospf_zebra.c
Merge pull request #5468 from qlyoung/bgpd-remove-bgp-attr-dup
[mirror_frr.git] / ospfd / ospf_zebra.c
1 /*
2 * Zebra connect library for OSPFd
3 * Copyright (C) 1997, 98, 99, 2000 Kunihiro Ishiguro, Toshiaki Takada
4 *
5 * This file is part of GNU Zebra.
6 *
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
10 * later version.
11 *
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.
16 *
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
20 */
21
22 #include <zebra.h>
23
24 #include "thread.h"
25 #include "command.h"
26 #include "network.h"
27 #include "prefix.h"
28 #include "routemap.h"
29 #include "table.h"
30 #include "stream.h"
31 #include "memory.h"
32 #include "zclient.h"
33 #include "filter.h"
34 #include "plist.h"
35 #include "log.h"
36 #include "lib/bfd.h"
37 #include "nexthop.h"
38
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"
53
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")
57
58 /* Zebra structure to hold current status. */
59 struct zclient *zclient = NULL;
60
61 /* For registering threads. */
62 extern struct thread_master *master;
63
64 /* Router-id update message from zebra. */
65 static int ospf_router_id_update_zebra(ZAPI_CALLBACK_ARGS)
66 {
67 struct ospf *ospf = NULL;
68 struct prefix router_id;
69 zebra_router_id_update_read(zclient->ibuf, &router_id);
70
71 if (IS_DEBUG_OSPF(zebra, ZEBRA_INTERFACE)) {
72 char buf[PREFIX2STR_BUFFER];
73 prefix2str(&router_id, buf, sizeof(buf));
74 zlog_debug("Zebra rcvd: router id update %s vrf %s id %u", buf,
75 ospf_vrf_id_to_name(vrf_id), vrf_id);
76 }
77
78 ospf = ospf_lookup_by_vrf_id(vrf_id);
79
80 if (ospf != NULL) {
81 ospf->router_id_zebra = router_id.u.prefix4;
82 ospf_router_id_update(ospf);
83 } else {
84 if (IS_DEBUG_OSPF_EVENT) {
85 char buf[PREFIX2STR_BUFFER];
86
87 prefix2str(&router_id, buf, sizeof(buf));
88 zlog_debug(
89 "%s: ospf instance not found for vrf %s id %u router_id %s",
90 __PRETTY_FUNCTION__,
91 ospf_vrf_id_to_name(vrf_id), vrf_id, buf);
92 }
93 }
94 return 0;
95 }
96
97 static int ospf_interface_address_add(ZAPI_CALLBACK_ARGS)
98 {
99 struct connected *c;
100 struct ospf *ospf = NULL;
101
102
103 c = zebra_interface_address_read(cmd, zclient->ibuf, vrf_id);
104
105 if (c == NULL)
106 return 0;
107
108 if (IS_DEBUG_OSPF(zebra, ZEBRA_INTERFACE)) {
109 char buf[PREFIX2STR_BUFFER];
110 prefix2str(c->address, buf, sizeof(buf));
111 zlog_debug("Zebra: interface %s address add %s vrf %s id %u",
112 c->ifp->name, buf, ospf_vrf_id_to_name(vrf_id),
113 vrf_id);
114 }
115
116 ospf = ospf_lookup_by_vrf_id(vrf_id);
117 if (!ospf)
118 return 0;
119
120 ospf_if_update(ospf, c->ifp);
121
122 ospf_if_interface(c->ifp);
123
124 return 0;
125 }
126
127 static int ospf_interface_address_delete(ZAPI_CALLBACK_ARGS)
128 {
129 struct connected *c;
130 struct interface *ifp;
131 struct ospf_interface *oi;
132 struct route_node *rn;
133 struct prefix p;
134
135 c = zebra_interface_address_read(cmd, zclient->ibuf, vrf_id);
136
137 if (c == NULL)
138 return 0;
139
140 if (IS_DEBUG_OSPF(zebra, ZEBRA_INTERFACE)) {
141 char buf[PREFIX2STR_BUFFER];
142 prefix2str(c->address, buf, sizeof(buf));
143 zlog_debug("Zebra: interface %s address delete %s",
144 c->ifp->name, buf);
145 }
146
147 ifp = c->ifp;
148 p = *c->address;
149 p.prefixlen = IPV4_MAX_PREFIXLEN;
150
151 rn = route_node_lookup(IF_OIFS(ifp), &p);
152 if (!rn) {
153 connected_free(&c);
154 return 0;
155 }
156
157 assert(rn->info);
158 oi = rn->info;
159 route_unlock_node(rn);
160
161 /* Call interface hook functions to clean up */
162 ospf_if_free(oi);
163
164 ospf_if_interface(c->ifp);
165
166 connected_free(&c);
167
168 return 0;
169 }
170
171 static int ospf_interface_link_params(ZAPI_CALLBACK_ARGS)
172 {
173 struct interface *ifp;
174
175 ifp = zebra_interface_link_params_read(zclient->ibuf, vrf_id);
176
177 if (ifp == NULL)
178 return 0;
179
180 /* Update TE TLV */
181 ospf_mpls_te_update_if(ifp);
182
183 return 0;
184 }
185
186 /* VRF update for an interface. */
187 static int ospf_interface_vrf_update(ZAPI_CALLBACK_ARGS)
188 {
189 struct interface *ifp = NULL;
190 vrf_id_t new_vrf_id;
191
192 ifp = zebra_interface_vrf_update_read(zclient->ibuf, vrf_id,
193 &new_vrf_id);
194 if (!ifp)
195 return 0;
196
197 if (IS_DEBUG_OSPF_EVENT)
198 zlog_debug(
199 "%s: Rx Interface %s VRF change vrf_id %u New vrf %s id %u",
200 __PRETTY_FUNCTION__, ifp->name, vrf_id,
201 ospf_vrf_id_to_name(new_vrf_id), new_vrf_id);
202
203 /*if_update(ifp, ifp->name, strlen(ifp->name), new_vrf_id);*/
204 if_update_to_new_vrf(ifp, new_vrf_id);
205
206 return 0;
207 }
208
209 void ospf_zebra_add(struct ospf *ospf, struct prefix_ipv4 *p,
210 struct ospf_route * or)
211 {
212 struct zapi_route api;
213 struct zapi_nexthop *api_nh;
214 uint8_t distance;
215 struct ospf_path *path;
216 struct listnode *node;
217 int count = 0;
218
219 memset(&api, 0, sizeof(api));
220 api.vrf_id = ospf->vrf_id;
221 api.type = ZEBRA_ROUTE_OSPF;
222 api.instance = ospf->instance;
223 api.safi = SAFI_UNICAST;
224
225 memcpy(&api.prefix, p, sizeof(*p));
226 SET_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP);
227
228 /* Metric value. */
229 SET_FLAG(api.message, ZAPI_MESSAGE_METRIC);
230 if (or->path_type == OSPF_PATH_TYPE1_EXTERNAL)
231 api.metric = or->cost + or->u.ext.type2_cost;
232 else if (or->path_type == OSPF_PATH_TYPE2_EXTERNAL)
233 api.metric = or->u.ext.type2_cost;
234 else
235 api.metric = or->cost;
236
237 /* Check if path type is ASE */
238 if (((or->path_type == OSPF_PATH_TYPE1_EXTERNAL)
239 || (or->path_type == OSPF_PATH_TYPE2_EXTERNAL))
240 && (or->u.ext.tag > 0) && (or->u.ext.tag <= ROUTE_TAG_MAX)) {
241 SET_FLAG(api.message, ZAPI_MESSAGE_TAG);
242 api.tag = or->u.ext.tag;
243 }
244
245 /* Distance value. */
246 distance = ospf_distance_apply(ospf, p, or);
247 if (distance) {
248 SET_FLAG(api.message, ZAPI_MESSAGE_DISTANCE);
249 api.distance = distance;
250 }
251
252 /* Nexthop, ifindex, distance and metric information. */
253 for (ALL_LIST_ELEMENTS_RO(or->paths, node, path)) {
254 if (count >= MULTIPATH_NUM)
255 break;
256 api_nh = &api.nexthops[count];
257 #ifdef HAVE_NETLINK
258 if (path->unnumbered || (path->nexthop.s_addr != INADDR_ANY
259 && path->ifindex != 0)) {
260 #else /* HAVE_NETLINK */
261 if (path->nexthop.s_addr != INADDR_ANY && path->ifindex != 0) {
262 #endif /* HAVE_NETLINK */
263 api_nh->gate.ipv4 = path->nexthop;
264 api_nh->ifindex = path->ifindex;
265 api_nh->type = NEXTHOP_TYPE_IPV4_IFINDEX;
266 } else if (path->nexthop.s_addr != INADDR_ANY) {
267 api_nh->gate.ipv4 = path->nexthop;
268 api_nh->type = NEXTHOP_TYPE_IPV4;
269 } else {
270 api_nh->ifindex = path->ifindex;
271 api_nh->type = NEXTHOP_TYPE_IFINDEX;
272 }
273 api_nh->vrf_id = ospf->vrf_id;
274 count++;
275
276 if (IS_DEBUG_OSPF(zebra, ZEBRA_REDISTRIBUTE)) {
277 char buf[2][INET_ADDRSTRLEN];
278 struct interface *ifp;
279
280 ifp = if_lookup_by_index(path->ifindex, ospf->vrf_id);
281
282 zlog_debug(
283 "Zebra: Route add %s nexthop %s, ifindex=%d %s",
284 prefix2str(p, buf[0], sizeof(buf[0])),
285 inet_ntop(AF_INET, &path->nexthop,
286 buf[1], sizeof(buf[1])),
287 path->ifindex, ifp ? ifp->name : " ");
288 }
289 }
290 api.nexthop_num = count;
291
292 zclient_route_send(ZEBRA_ROUTE_ADD, zclient, &api);
293 }
294
295 void ospf_zebra_delete(struct ospf *ospf, struct prefix_ipv4 *p,
296 struct ospf_route * or)
297 {
298 struct zapi_route api;
299
300 memset(&api, 0, sizeof(api));
301 api.vrf_id = ospf->vrf_id;
302 api.type = ZEBRA_ROUTE_OSPF;
303 api.instance = ospf->instance;
304 api.safi = SAFI_UNICAST;
305 memcpy(&api.prefix, p, sizeof(*p));
306
307 if (IS_DEBUG_OSPF(zebra, ZEBRA_REDISTRIBUTE)) {
308 char buf[PREFIX2STR_BUFFER];
309 zlog_debug("Zebra: Route delete %s",
310 prefix2str(p, buf, sizeof(buf)));
311 }
312
313 zclient_route_send(ZEBRA_ROUTE_DELETE, zclient, &api);
314 }
315
316 void ospf_zebra_add_discard(struct ospf *ospf, struct prefix_ipv4 *p)
317 {
318 struct zapi_route api;
319
320 memset(&api, 0, sizeof(api));
321 api.vrf_id = ospf->vrf_id;
322 api.type = ZEBRA_ROUTE_OSPF;
323 api.instance = ospf->instance;
324 api.safi = SAFI_UNICAST;
325 memcpy(&api.prefix, p, sizeof(*p));
326 zapi_route_set_blackhole(&api, BLACKHOLE_NULL);
327
328 zclient_route_send(ZEBRA_ROUTE_ADD, zclient, &api);
329
330 if (IS_DEBUG_OSPF(zebra, ZEBRA_REDISTRIBUTE)) {
331 char buf[PREFIX2STR_BUFFER];
332 zlog_debug("Zebra: Route add discard %s",
333 prefix2str(p, buf, sizeof(buf)));
334 }
335 }
336
337 void ospf_zebra_delete_discard(struct ospf *ospf, struct prefix_ipv4 *p)
338 {
339 struct zapi_route api;
340
341 memset(&api, 0, sizeof(api));
342 api.vrf_id = ospf->vrf_id;
343 api.type = ZEBRA_ROUTE_OSPF;
344 api.instance = ospf->instance;
345 api.safi = SAFI_UNICAST;
346 memcpy(&api.prefix, p, sizeof(*p));
347 zapi_route_set_blackhole(&api, BLACKHOLE_NULL);
348
349 zclient_route_send(ZEBRA_ROUTE_DELETE, zclient, &api);
350
351 if (IS_DEBUG_OSPF(zebra, ZEBRA_REDISTRIBUTE)) {
352 char buf[PREFIX2STR_BUFFER];
353 zlog_debug("Zebra: Route delete discard %s",
354 prefix2str(p, buf, sizeof(buf)));
355 }
356 }
357
358 struct ospf_external *ospf_external_lookup(struct ospf *ospf, uint8_t type,
359 unsigned short instance)
360 {
361 struct list *ext_list;
362 struct listnode *node;
363 struct ospf_external *ext;
364
365 ext_list = ospf->external[type];
366 if (!ext_list)
367 return (NULL);
368
369 for (ALL_LIST_ELEMENTS_RO(ext_list, node, ext))
370 if (ext->instance == instance)
371 return ext;
372
373 return NULL;
374 }
375
376 struct ospf_external *ospf_external_add(struct ospf *ospf, uint8_t type,
377 unsigned short instance)
378 {
379 struct list *ext_list;
380 struct ospf_external *ext;
381
382 ext = ospf_external_lookup(ospf, type, instance);
383 if (ext)
384 return ext;
385
386 if (!ospf->external[type])
387 ospf->external[type] = list_new();
388
389 ext_list = ospf->external[type];
390 ext = XCALLOC(MTYPE_OSPF_EXTERNAL, sizeof(struct ospf_external));
391 ext->instance = instance;
392 EXTERNAL_INFO(ext) = route_table_init();
393
394 listnode_add(ext_list, ext);
395
396 return ext;
397 }
398
399 void ospf_external_del(struct ospf *ospf, uint8_t type, unsigned short instance)
400 {
401 struct ospf_external *ext;
402
403 ext = ospf_external_lookup(ospf, type, instance);
404
405 if (ext) {
406 if (EXTERNAL_INFO(ext))
407 route_table_finish(EXTERNAL_INFO(ext));
408
409 listnode_delete(ospf->external[type], ext);
410
411 if (!ospf->external[type]->count)
412 list_delete(&ospf->external[type]);
413
414 XFREE(MTYPE_OSPF_EXTERNAL, ext);
415 }
416 }
417
418 struct ospf_redist *ospf_redist_lookup(struct ospf *ospf, uint8_t type,
419 unsigned short instance)
420 {
421 struct list *red_list;
422 struct listnode *node;
423 struct ospf_redist *red;
424
425 red_list = ospf->redist[type];
426 if (!red_list)
427 return (NULL);
428
429 for (ALL_LIST_ELEMENTS_RO(red_list, node, red))
430 if (red->instance == instance)
431 return red;
432
433 return NULL;
434 }
435
436 struct ospf_redist *ospf_redist_add(struct ospf *ospf, uint8_t type,
437 unsigned short instance)
438 {
439 struct list *red_list;
440 struct ospf_redist *red;
441
442 red = ospf_redist_lookup(ospf, type, instance);
443 if (red)
444 return red;
445
446 if (!ospf->redist[type])
447 ospf->redist[type] = list_new();
448
449 red_list = ospf->redist[type];
450 red = XCALLOC(MTYPE_OSPF_REDISTRIBUTE, sizeof(struct ospf_redist));
451 red->instance = instance;
452 red->dmetric.type = -1;
453 red->dmetric.value = -1;
454 ROUTEMAP_NAME(red) = NULL;
455 ROUTEMAP(red) = NULL;
456
457 listnode_add(red_list, red);
458
459 return red;
460 }
461
462 void ospf_redist_del(struct ospf *ospf, uint8_t type, unsigned short instance)
463 {
464 struct ospf_redist *red;
465
466 red = ospf_redist_lookup(ospf, type, instance);
467
468 if (red) {
469 listnode_delete(ospf->redist[type], red);
470 if (!ospf->redist[type]->count) {
471 list_delete(&ospf->redist[type]);
472 }
473 ospf_routemap_unset(red);
474 XFREE(MTYPE_OSPF_REDISTRIBUTE, red);
475 }
476 }
477
478
479 int ospf_is_type_redistributed(struct ospf *ospf, int type,
480 unsigned short instance)
481 {
482 return (DEFAULT_ROUTE_TYPE(type)
483 ? vrf_bitmap_check(zclient->default_information[AFI_IP],
484 ospf->vrf_id)
485 : ((instance
486 && redist_check_instance(
487 &zclient->mi_redist[AFI_IP][type],
488 instance))
489 || (!instance
490 && vrf_bitmap_check(
491 zclient->redist[AFI_IP][type],
492 ospf->vrf_id))));
493 }
494
495 int ospf_redistribute_set(struct ospf *ospf, int type, unsigned short instance,
496 int mtype, int mvalue)
497 {
498 int force = 0;
499 struct ospf_redist *red;
500
501 red = ospf_redist_lookup(ospf, type, instance);
502
503 if (red == NULL) {
504 zlog_err(
505 "Redistribute[%s][%d]: Lookup failed Type[%d] , Metric[%d]",
506 ospf_redist_string(type), instance,
507 metric_type(ospf, type, instance),
508 metric_value(ospf, type, instance));
509 return CMD_WARNING_CONFIG_FAILED;
510 }
511
512 if (ospf_is_type_redistributed(ospf, type, instance)) {
513 if (mtype != red->dmetric.type) {
514 red->dmetric.type = mtype;
515 force = LSA_REFRESH_FORCE;
516 }
517 if (mvalue != red->dmetric.value) {
518 red->dmetric.value = mvalue;
519 force = LSA_REFRESH_FORCE;
520 }
521
522 ospf_external_lsa_refresh_type(ospf, type, instance, force);
523
524 if (IS_DEBUG_OSPF(zebra, ZEBRA_REDISTRIBUTE))
525 zlog_debug(
526 "Redistribute[%s][%d]: Refresh Type[%d], Metric[%d]",
527 ospf_redist_string(type), instance,
528 metric_type(ospf, type, instance),
529 metric_value(ospf, type, instance));
530
531 return CMD_SUCCESS;
532 }
533
534 red->dmetric.type = mtype;
535 red->dmetric.value = mvalue;
536
537 ospf_external_add(ospf, type, instance);
538
539 zclient_redistribute(ZEBRA_REDISTRIBUTE_ADD, zclient, AFI_IP, type,
540 instance, ospf->vrf_id);
541
542 if (IS_DEBUG_OSPF(zebra, ZEBRA_REDISTRIBUTE))
543 zlog_debug(
544 "Redistribute[%s][%d] vrf id %u: Start Type[%d], Metric[%d]",
545 ospf_redist_string(type), instance, ospf->vrf_id,
546 metric_type(ospf, type, instance),
547 metric_value(ospf, type, instance));
548
549 ospf_asbr_status_update(ospf, ++ospf->redistribute);
550
551 return CMD_SUCCESS;
552 }
553
554 int ospf_redistribute_unset(struct ospf *ospf, int type,
555 unsigned short instance)
556 {
557 if (type == zclient->redist_default && instance == zclient->instance)
558 return CMD_SUCCESS;
559
560 if (!ospf_is_type_redistributed(ospf, type, instance))
561 return CMD_SUCCESS;
562
563 zclient_redistribute(ZEBRA_REDISTRIBUTE_DELETE, zclient, AFI_IP, type,
564 instance, ospf->vrf_id);
565
566 if (IS_DEBUG_OSPF(zebra, ZEBRA_REDISTRIBUTE))
567 zlog_debug("Redistribute[%s][%d] vrf id %u: Stop",
568 ospf_redist_string(type), instance, ospf->vrf_id);
569
570 /* Remove the routes from OSPF table. */
571 ospf_redistribute_withdraw(ospf, type, instance);
572
573 ospf_external_del(ospf, type, instance);
574
575 ospf_asbr_status_update(ospf, --ospf->redistribute);
576
577 return CMD_SUCCESS;
578 }
579
580 int ospf_redistribute_default_set(struct ospf *ospf, int originate, int mtype,
581 int mvalue)
582 {
583 struct prefix_ipv4 p;
584 struct in_addr nexthop;
585 int cur_originate = ospf->default_originate;
586 const char *type_str = NULL;
587
588 nexthop.s_addr = 0;
589 p.family = AF_INET;
590 p.prefix.s_addr = 0;
591 p.prefixlen = 0;
592
593 ospf->default_originate = originate;
594
595 if (cur_originate == originate) {
596 /* Refresh the lsa since metric might different */
597 if (IS_DEBUG_OSPF(zebra, ZEBRA_REDISTRIBUTE))
598 zlog_debug(
599 "Redistribute[%s]: Refresh Type[%d], Metric[%d]",
600 ospf_redist_string(DEFAULT_ROUTE),
601 metric_type(ospf, DEFAULT_ROUTE, 0),
602 metric_value(ospf, DEFAULT_ROUTE, 0));
603
604 ospf_external_lsa_refresh_default(ospf);
605 return CMD_SUCCESS;
606 }
607
608 switch (cur_originate) {
609 case DEFAULT_ORIGINATE_NONE:
610 break;
611 case DEFAULT_ORIGINATE_ZEBRA:
612 zclient_redistribute_default(ZEBRA_REDISTRIBUTE_DEFAULT_DELETE,
613 zclient, AFI_IP, ospf->vrf_id);
614 ospf->redistribute--;
615 break;
616 case DEFAULT_ORIGINATE_ALWAYS:
617 ospf_external_info_delete(ospf, DEFAULT_ROUTE, 0, p);
618 ospf_external_del(ospf, DEFAULT_ROUTE, 0);
619 ospf->redistribute--;
620 break;
621 }
622
623 switch (originate) {
624 case DEFAULT_ORIGINATE_NONE:
625 type_str = "none";
626 break;
627 case DEFAULT_ORIGINATE_ZEBRA:
628 type_str = "normal";
629 ospf->redistribute++;
630 zclient_redistribute_default(ZEBRA_REDISTRIBUTE_DEFAULT_ADD,
631 zclient, AFI_IP, ospf->vrf_id);
632 break;
633 case DEFAULT_ORIGINATE_ALWAYS:
634 type_str = "always";
635 ospf->redistribute++;
636 ospf_external_add(ospf, DEFAULT_ROUTE, 0);
637 ospf_external_info_add(ospf, DEFAULT_ROUTE, 0, p, 0, nexthop,
638 0);
639 break;
640 }
641
642 if (IS_DEBUG_OSPF(zebra, ZEBRA_REDISTRIBUTE))
643 zlog_debug("Redistribute[DEFAULT]: %s Type[%d], Metric[%d]",
644 type_str,
645 metric_type(ospf, DEFAULT_ROUTE, 0),
646 metric_value(ospf, DEFAULT_ROUTE, 0));
647
648 ospf_external_lsa_refresh_default(ospf);
649 ospf_asbr_status_update(ospf, ospf->redistribute);
650 return CMD_SUCCESS;
651 }
652
653 static int ospf_external_lsa_originate_check(struct ospf *ospf,
654 struct external_info *ei)
655 {
656 /* If prefix is multicast, then do not originate LSA. */
657 if (IN_MULTICAST(htonl(ei->p.prefix.s_addr))) {
658 zlog_info(
659 "LSA[Type5:%s]: Not originate AS-external-LSA, "
660 "Prefix belongs multicast",
661 inet_ntoa(ei->p.prefix));
662 return 0;
663 }
664
665 /* Take care of default-originate. */
666 if (is_prefix_default(&ei->p))
667 if (ospf->default_originate == DEFAULT_ORIGINATE_NONE) {
668 zlog_info(
669 "LSA[Type5:0.0.0.0]: Not originate AS-external-LSA "
670 "for default");
671 return 0;
672 }
673
674 return 1;
675 }
676
677 /* If connected prefix is OSPF enable interface, then do not announce. */
678 int ospf_distribute_check_connected(struct ospf *ospf, struct external_info *ei)
679 {
680 struct listnode *node;
681 struct ospf_interface *oi;
682
683
684 for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi))
685 if (prefix_match(oi->address, (struct prefix *)&ei->p))
686 return 0;
687 return 1;
688 }
689
690 /* return 1 if external LSA must be originated, 0 otherwise */
691 int ospf_redistribute_check(struct ospf *ospf, struct external_info *ei,
692 int *changed)
693 {
694 struct route_map_set_values save_values;
695 struct prefix_ipv4 *p = &ei->p;
696 struct ospf_redist *red;
697 uint8_t type = is_prefix_default(&ei->p) ? DEFAULT_ROUTE : ei->type;
698 unsigned short instance = is_prefix_default(&ei->p) ? 0 : ei->instance;
699
700 if (changed)
701 *changed = 0;
702
703 if (!ospf_external_lsa_originate_check(ospf, ei))
704 return 0;
705
706 /* Take care connected route. */
707 if (type == ZEBRA_ROUTE_CONNECT
708 && !ospf_distribute_check_connected(ospf, ei))
709 return 0;
710
711 if (!DEFAULT_ROUTE_TYPE(type) && DISTRIBUTE_NAME(ospf, type))
712 /* distirbute-list exists, but access-list may not? */
713 if (DISTRIBUTE_LIST(ospf, type))
714 if (access_list_apply(DISTRIBUTE_LIST(ospf, type), p)
715 == FILTER_DENY) {
716 if (IS_DEBUG_OSPF(zebra, ZEBRA_REDISTRIBUTE)) {
717 char buf[PREFIX2STR_BUFFER];
718 zlog_debug(
719 "Redistribute[%s]: %s filtered by distribute-list.",
720 ospf_redist_string(type),
721 prefix2str(p, buf, sizeof(buf)));
722 }
723 return 0;
724 }
725
726 save_values = ei->route_map_set;
727 ospf_reset_route_map_set_values(&ei->route_map_set);
728
729 /* apply route-map if needed */
730 red = ospf_redist_lookup(ospf, type, instance);
731 if (red && ROUTEMAP_NAME(red)) {
732 route_map_result_t ret;
733
734 ret = route_map_apply(ROUTEMAP(red), (struct prefix *)p,
735 RMAP_OSPF, ei);
736
737 if (ret == RMAP_DENYMATCH) {
738 ei->route_map_set = save_values;
739 if (IS_DEBUG_OSPF(zebra, ZEBRA_REDISTRIBUTE)) {
740 char buf[PREFIX2STR_BUFFER];
741 zlog_debug(
742 "Redistribute[%s]: %s filtered by route-map.",
743 ospf_redist_string(type),
744 prefix2str(p, buf, sizeof(buf)));
745 }
746 return 0;
747 }
748
749 /* check if 'route-map set' changed something */
750 if (changed)
751 *changed = !ospf_route_map_set_compare(
752 &ei->route_map_set, &save_values);
753 }
754
755 return 1;
756 }
757
758 /* OSPF route-map set for redistribution */
759 void ospf_routemap_set(struct ospf_redist *red, const char *name)
760 {
761 if (ROUTEMAP_NAME(red)) {
762 route_map_counter_decrement(ROUTEMAP(red));
763 free(ROUTEMAP_NAME(red));
764 }
765
766 ROUTEMAP_NAME(red) = strdup(name);
767 ROUTEMAP(red) = route_map_lookup_by_name(name);
768 route_map_counter_increment(ROUTEMAP(red));
769 }
770
771 void ospf_routemap_unset(struct ospf_redist *red)
772 {
773 if (ROUTEMAP_NAME(red)) {
774 route_map_counter_decrement(ROUTEMAP(red));
775 free(ROUTEMAP_NAME(red));
776 }
777
778 ROUTEMAP_NAME(red) = NULL;
779 ROUTEMAP(red) = NULL;
780 }
781
782 /* Zebra route add and delete treatment. */
783 static int ospf_zebra_read_route(ZAPI_CALLBACK_ARGS)
784 {
785 struct zapi_route api;
786 struct prefix_ipv4 p;
787 unsigned long ifindex;
788 struct in_addr nexthop;
789 struct external_info *ei;
790 struct ospf *ospf;
791 int i;
792 uint8_t rt_type;
793
794 ospf = ospf_lookup_by_vrf_id(vrf_id);
795 if (ospf == NULL)
796 return 0;
797
798 if (zapi_route_decode(zclient->ibuf, &api) < 0)
799 return -1;
800
801 ifindex = api.nexthops[0].ifindex;
802 nexthop = api.nexthops[0].gate.ipv4;
803 rt_type = api.type;
804
805 memcpy(&p, &api.prefix, sizeof(p));
806 if (IPV4_NET127(ntohl(p.prefix.s_addr)))
807 return 0;
808
809 /* Re-destributed route is default route.
810 * Here, route type is used as 'ZEBRA_ROUTE_KERNEL' for
811 * updating ex-info. But in resetting (no default-info
812 * originate)ZEBRA_ROUTE_MAX is used to delete the ex-info.
813 * Resolved this inconsistency by maintaining same route type.
814 */
815 if (is_prefix_default(&p))
816 rt_type = DEFAULT_ROUTE;
817
818 if (IS_DEBUG_OSPF(zebra, ZEBRA_REDISTRIBUTE)) {
819 char buf_prefix[PREFIX_STRLEN];
820 prefix2str(&api.prefix, buf_prefix, sizeof(buf_prefix));
821
822 zlog_debug("%s: cmd %s from client %s: vrf_id %d, p %s",
823 __func__, zserv_command_string(cmd),
824 zebra_route_string(api.type), vrf_id, buf_prefix);
825 }
826
827 if (cmd == ZEBRA_REDISTRIBUTE_ROUTE_ADD) {
828 /* XXX|HACK|TODO|FIXME:
829 * Maybe we should ignore reject/blackhole routes? Testing
830 * shows that there is no problems though and this is only way
831 * to "summarize" routes in ASBR at the moment. Maybe we need
832 * just a better generalised solution for these types?
833 */
834
835 /* Protocol tag overwrites all other tag value sent by zebra */
836 if (ospf->dtag[rt_type] > 0)
837 api.tag = ospf->dtag[rt_type];
838
839 /*
840 * Given zebra sends update for a prefix via ADD message, it
841 * should
842 * be considered as an implicit DEL for that prefix with other
843 * source
844 * types.
845 */
846 for (i = 0; i <= ZEBRA_ROUTE_MAX; i++)
847 if (i != rt_type)
848 ospf_external_info_delete(ospf, i, api.instance,
849 p);
850
851 ei = ospf_external_info_add(ospf, rt_type, api.instance, p,
852 ifindex, nexthop, api.tag);
853 if (ei == NULL) {
854 /* Nothing has changed, so nothing to do; return */
855 return 0;
856 }
857 if (ospf->router_id.s_addr != 0) {
858 if (ei) {
859 if (is_prefix_default(&p))
860 ospf_external_lsa_refresh_default(ospf);
861 else {
862 struct ospf_lsa *current;
863
864 current = ospf_external_info_find_lsa(
865 ospf, &ei->p);
866 if (!current)
867 ospf_external_lsa_originate(
868 ospf, ei);
869 else {
870 if (IS_DEBUG_OSPF(
871 zebra,
872 ZEBRA_REDISTRIBUTE))
873 zlog_debug(
874 "ospf_zebra_read_route() : %s refreshing LSA",
875 inet_ntoa(
876 p.prefix));
877 ospf_external_lsa_refresh(
878 ospf, current, ei,
879 LSA_REFRESH_FORCE);
880 }
881 }
882 }
883 }
884 } else /* if (cmd == ZEBRA_REDISTRIBUTE_ROUTE_DEL) */
885 {
886 ospf_external_info_delete(ospf, rt_type, api.instance, p);
887 if (is_prefix_default(&p))
888 ospf_external_lsa_refresh_default(ospf);
889 else
890 ospf_external_lsa_flush(ospf, rt_type, &p,
891 ifindex /*, nexthop */);
892 }
893
894 return 0;
895 }
896
897
898 int ospf_distribute_list_out_set(struct ospf *ospf, int type, const char *name)
899 {
900 /* Lookup access-list for distribute-list. */
901 DISTRIBUTE_LIST(ospf, type) = access_list_lookup(AFI_IP, name);
902
903 /* Clear previous distribute-name. */
904 if (DISTRIBUTE_NAME(ospf, type))
905 free(DISTRIBUTE_NAME(ospf, type));
906
907 /* Set distribute-name. */
908 DISTRIBUTE_NAME(ospf, type) = strdup(name);
909
910 /* If access-list have been set, schedule update timer. */
911 if (DISTRIBUTE_LIST(ospf, type))
912 ospf_distribute_list_update(ospf, type, 0);
913
914 return CMD_SUCCESS;
915 }
916
917 int ospf_distribute_list_out_unset(struct ospf *ospf, int type,
918 const char *name)
919 {
920 /* Schedule update timer. */
921 if (DISTRIBUTE_LIST(ospf, type))
922 ospf_distribute_list_update(ospf, type, 0);
923
924 /* Unset distribute-list. */
925 DISTRIBUTE_LIST(ospf, type) = NULL;
926
927 /* Clear distribute-name. */
928 if (DISTRIBUTE_NAME(ospf, type))
929 free(DISTRIBUTE_NAME(ospf, type));
930
931 DISTRIBUTE_NAME(ospf, type) = NULL;
932
933 return CMD_SUCCESS;
934 }
935
936 /* distribute-list update timer. */
937 static int ospf_distribute_list_update_timer(struct thread *thread)
938 {
939 struct route_node *rn;
940 struct external_info *ei;
941 struct route_table *rt;
942 struct ospf_lsa *lsa;
943 int type, default_refresh = 0, arg_type;
944 struct ospf *ospf = NULL;
945 void **arg = THREAD_ARG(thread);
946
947 ospf = (struct ospf *)arg[0];
948 arg_type = (int)(intptr_t)arg[1];
949
950 if (ospf == NULL)
951 return 0;
952
953 ospf->t_distribute_update = NULL;
954
955 zlog_info("Zebra[Redistribute]: distribute-list update timer fired!");
956
957 if (IS_DEBUG_OSPF_EVENT) {
958 zlog_debug(
959 "%s: ospf distribute-list update arg_type %d vrf %s id %d",
960 __PRETTY_FUNCTION__, arg_type,
961 ospf_vrf_id_to_name(ospf->vrf_id), ospf->vrf_id);
962 }
963
964 /* foreach all external info. */
965 for (type = 0; type <= ZEBRA_ROUTE_MAX; type++) {
966 struct list *ext_list;
967 struct listnode *node;
968 struct ospf_external *ext;
969
970 ext_list = ospf->external[type];
971 if (!ext_list)
972 continue;
973
974 for (ALL_LIST_ELEMENTS_RO(ext_list, node, ext)) {
975 rt = ext->external_info;
976 if (!rt)
977 continue;
978 for (rn = route_top(rt); rn; rn = route_next(rn))
979 if ((ei = rn->info) != NULL) {
980 if (is_prefix_default(&ei->p))
981 default_refresh = 1;
982 else if (
983 (lsa = ospf_external_info_find_lsa(
984 ospf, &ei->p)))
985 ospf_external_lsa_refresh(
986 ospf, lsa, ei,
987 LSA_REFRESH_IF_CHANGED);
988 else
989 ospf_external_lsa_originate(
990 ospf, ei);
991 }
992 }
993 }
994 if (default_refresh)
995 ospf_external_lsa_refresh_default(ospf);
996
997 XFREE(MTYPE_OSPF_DIST_ARGS, arg);
998 return 0;
999 }
1000
1001 /* Update distribute-list and set timer to apply access-list. */
1002 void ospf_distribute_list_update(struct ospf *ospf, int type,
1003 unsigned short instance)
1004 {
1005 struct route_table *rt;
1006 struct ospf_external *ext;
1007 void **args = XCALLOC(MTYPE_OSPF_DIST_ARGS, sizeof(void *) * 2);
1008
1009 args[0] = ospf;
1010 args[1] = (void *)((ptrdiff_t)type);
1011
1012 /* External info does not exist. */
1013 ext = ospf_external_lookup(ospf, type, instance);
1014 if (!ext || !(rt = EXTERNAL_INFO(ext))) {
1015 XFREE(MTYPE_OSPF_DIST_ARGS, args);
1016 return;
1017 }
1018
1019 /* If exists previously invoked thread, then let it continue. */
1020 if (ospf->t_distribute_update) {
1021 XFREE(MTYPE_OSPF_DIST_ARGS, args);
1022 return;
1023 }
1024
1025 /* Set timer. */
1026 ospf->t_distribute_update = NULL;
1027 thread_add_timer_msec(master, ospf_distribute_list_update_timer,
1028 (void **)args, ospf->min_ls_interval,
1029 &ospf->t_distribute_update);
1030 }
1031
1032 /* If access-list is updated, apply some check. */
1033 static void ospf_filter_update(struct access_list *access)
1034 {
1035 struct ospf *ospf;
1036 int type;
1037 int abr_inv = 0;
1038 struct ospf_area *area;
1039 struct listnode *node, *n1;
1040
1041 /* If OSPF instance does not exist, return right now. */
1042 if (listcount(om->ospf) == 0)
1043 return;
1044
1045 /* Iterate all ospf [VRF] instances */
1046 for (ALL_LIST_ELEMENTS_RO(om->ospf, n1, ospf)) {
1047 /* Update distribute-list, and apply filter. */
1048 for (type = 0; type <= ZEBRA_ROUTE_MAX; type++) {
1049 struct list *red_list;
1050 struct ospf_redist *red;
1051
1052 red_list = ospf->redist[type];
1053 if (red_list)
1054 for (ALL_LIST_ELEMENTS_RO(red_list, node,
1055 red)) {
1056 if (ROUTEMAP(red)) {
1057 /* if route-map is not NULL it
1058 * may be
1059 * using this access list */
1060 ospf_distribute_list_update(
1061 ospf, type,
1062 red->instance);
1063 }
1064 }
1065
1066 /* There is place for route-map for default-information
1067 * (ZEBRA_ROUTE_MAX),
1068 * but no distribute list. */
1069 if (type == ZEBRA_ROUTE_MAX)
1070 break;
1071
1072 if (DISTRIBUTE_NAME(ospf, type)) {
1073 /* Keep old access-list for distribute-list. */
1074 struct access_list *old =
1075 DISTRIBUTE_LIST(ospf, type);
1076
1077 /* Update access-list for distribute-list. */
1078 DISTRIBUTE_LIST(ospf, type) =
1079 access_list_lookup(
1080 AFI_IP,
1081 DISTRIBUTE_NAME(ospf, type));
1082
1083 /* No update for this distribute type. */
1084 if (old == NULL
1085 && DISTRIBUTE_LIST(ospf, type) == NULL)
1086 continue;
1087
1088 /* Schedule distribute-list update timer. */
1089 if (DISTRIBUTE_LIST(ospf, type) == NULL
1090 || strcmp(DISTRIBUTE_NAME(ospf, type),
1091 access->name)
1092 == 0)
1093 ospf_distribute_list_update(ospf, type,
1094 0);
1095 }
1096 }
1097
1098 /* Update Area access-list. */
1099 for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
1100 if (EXPORT_NAME(area)) {
1101 EXPORT_LIST(area) = NULL;
1102 abr_inv++;
1103 }
1104
1105 if (IMPORT_NAME(area)) {
1106 IMPORT_LIST(area) = NULL;
1107 abr_inv++;
1108 }
1109 }
1110
1111 /* Schedule ABR tasks -- this will be changed -- takada. */
1112 if (IS_OSPF_ABR(ospf) && abr_inv)
1113 ospf_schedule_abr_task(ospf);
1114 }
1115 }
1116
1117 /* If prefix-list is updated, do some updates. */
1118 void ospf_prefix_list_update(struct prefix_list *plist)
1119 {
1120 struct ospf *ospf = NULL;
1121 int type;
1122 int abr_inv = 0;
1123 struct ospf_area *area;
1124 struct listnode *node, *n1;
1125
1126 /* If OSPF instatnce does not exist, return right now. */
1127 if (listcount(om->ospf) == 0)
1128 return;
1129
1130 /* Iterate all ospf [VRF] instances */
1131 for (ALL_LIST_ELEMENTS_RO(om->ospf, n1, ospf)) {
1132
1133 /* Update all route-maps which are used
1134 * as redistribution filters.
1135 * They might use prefix-list.
1136 */
1137 for (type = 0; type <= ZEBRA_ROUTE_MAX; type++) {
1138 struct list *red_list;
1139 struct ospf_redist *red;
1140
1141 red_list = ospf->redist[type];
1142 if (red_list) {
1143 for (ALL_LIST_ELEMENTS_RO(red_list, node,
1144 red)) {
1145 if (ROUTEMAP(red)) {
1146 /* if route-map is not NULL
1147 * it may be using
1148 * this prefix list */
1149 ospf_distribute_list_update(
1150 ospf, type,
1151 red->instance);
1152 }
1153 }
1154 }
1155 }
1156
1157 /* Update area filter-lists. */
1158 for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
1159 /* Update filter-list in. */
1160 if (PREFIX_NAME_IN(area))
1161 if (strcmp(PREFIX_NAME_IN(area),
1162 prefix_list_name(plist))
1163 == 0) {
1164 PREFIX_LIST_IN(area) =
1165 prefix_list_lookup(
1166 AFI_IP,
1167 PREFIX_NAME_IN(area));
1168 abr_inv++;
1169 }
1170
1171 /* Update filter-list out. */
1172 if (PREFIX_NAME_OUT(area))
1173 if (strcmp(PREFIX_NAME_OUT(area),
1174 prefix_list_name(plist))
1175 == 0) {
1176 PREFIX_LIST_IN(area) =
1177 prefix_list_lookup(
1178 AFI_IP,
1179 PREFIX_NAME_OUT(area));
1180 abr_inv++;
1181 }
1182 }
1183
1184 /* Schedule ABR task. */
1185 if (IS_OSPF_ABR(ospf) && abr_inv)
1186 ospf_schedule_abr_task(ospf);
1187 }
1188 }
1189
1190 static struct ospf_distance *ospf_distance_new(void)
1191 {
1192 return XCALLOC(MTYPE_OSPF_DISTANCE, sizeof(struct ospf_distance));
1193 }
1194
1195 static void ospf_distance_free(struct ospf_distance *odistance)
1196 {
1197 XFREE(MTYPE_OSPF_DISTANCE, odistance);
1198 }
1199
1200 int ospf_distance_set(struct vty *vty, struct ospf *ospf,
1201 const char *distance_str, const char *ip_str,
1202 const char *access_list_str)
1203 {
1204 int ret;
1205 struct prefix_ipv4 p;
1206 uint8_t distance;
1207 struct route_node *rn;
1208 struct ospf_distance *odistance;
1209
1210 ret = str2prefix_ipv4(ip_str, &p);
1211 if (ret == 0) {
1212 vty_out(vty, "Malformed prefix\n");
1213 return CMD_WARNING_CONFIG_FAILED;
1214 }
1215
1216 distance = atoi(distance_str);
1217
1218 /* Get OSPF distance node. */
1219 rn = route_node_get(ospf->distance_table, (struct prefix *)&p);
1220 if (rn->info) {
1221 odistance = rn->info;
1222 route_unlock_node(rn);
1223 } else {
1224 odistance = ospf_distance_new();
1225 rn->info = odistance;
1226 }
1227
1228 /* Set distance value. */
1229 odistance->distance = distance;
1230
1231 /* Reset access-list configuration. */
1232 if (odistance->access_list) {
1233 free(odistance->access_list);
1234 odistance->access_list = NULL;
1235 }
1236 if (access_list_str)
1237 odistance->access_list = strdup(access_list_str);
1238
1239 return CMD_SUCCESS;
1240 }
1241
1242 int ospf_distance_unset(struct vty *vty, struct ospf *ospf,
1243 const char *distance_str, const char *ip_str,
1244 char const *access_list_str)
1245 {
1246 int ret;
1247 struct prefix_ipv4 p;
1248 struct route_node *rn;
1249 struct ospf_distance *odistance;
1250
1251 ret = str2prefix_ipv4(ip_str, &p);
1252 if (ret == 0) {
1253 vty_out(vty, "Malformed prefix\n");
1254 return CMD_WARNING_CONFIG_FAILED;
1255 }
1256
1257 rn = route_node_lookup(ospf->distance_table, (struct prefix *)&p);
1258 if (!rn) {
1259 vty_out(vty, "Can't find specified prefix\n");
1260 return CMD_WARNING_CONFIG_FAILED;
1261 }
1262
1263 odistance = rn->info;
1264
1265 if (odistance->access_list)
1266 free(odistance->access_list);
1267 ospf_distance_free(odistance);
1268
1269 rn->info = NULL;
1270 route_unlock_node(rn);
1271 route_unlock_node(rn);
1272
1273 return CMD_SUCCESS;
1274 }
1275
1276 void ospf_distance_reset(struct ospf *ospf)
1277 {
1278 struct route_node *rn;
1279 struct ospf_distance *odistance;
1280
1281 for (rn = route_top(ospf->distance_table); rn; rn = route_next(rn))
1282 if ((odistance = rn->info) != NULL) {
1283 if (odistance->access_list)
1284 free(odistance->access_list);
1285 ospf_distance_free(odistance);
1286 rn->info = NULL;
1287 route_unlock_node(rn);
1288 }
1289 }
1290
1291 uint8_t ospf_distance_apply(struct ospf *ospf, struct prefix_ipv4 *p,
1292 struct ospf_route * or)
1293 {
1294
1295 if (ospf == NULL)
1296 return 0;
1297
1298 if (ospf->distance_intra)
1299 if (or->path_type == OSPF_PATH_INTRA_AREA)
1300 return ospf->distance_intra;
1301
1302 if (ospf->distance_inter)
1303 if (or->path_type == OSPF_PATH_INTER_AREA)
1304 return ospf->distance_inter;
1305
1306 if (ospf->distance_external)
1307 if (or->path_type == OSPF_PATH_TYPE1_EXTERNAL ||
1308 or->path_type == OSPF_PATH_TYPE2_EXTERNAL)
1309 return ospf->distance_external;
1310
1311 if (ospf->distance_all)
1312 return ospf->distance_all;
1313
1314 return 0;
1315 }
1316
1317 void ospf_zebra_vrf_register(struct ospf *ospf)
1318 {
1319 if (!zclient || zclient->sock < 0 || !ospf)
1320 return;
1321
1322 if (ospf->vrf_id != VRF_UNKNOWN) {
1323 if (IS_DEBUG_OSPF_EVENT)
1324 zlog_debug("%s: Register VRF %s id %u",
1325 __PRETTY_FUNCTION__,
1326 ospf_vrf_id_to_name(ospf->vrf_id),
1327 ospf->vrf_id);
1328 zclient_send_reg_requests(zclient, ospf->vrf_id);
1329 }
1330 }
1331
1332 void ospf_zebra_vrf_deregister(struct ospf *ospf)
1333 {
1334 if (!zclient || zclient->sock < 0 || !ospf)
1335 return;
1336
1337 if (ospf->vrf_id != VRF_DEFAULT && ospf->vrf_id != VRF_UNKNOWN) {
1338 if (IS_DEBUG_OSPF_EVENT)
1339 zlog_debug("%s: De-Register VRF %s id %u to Zebra.",
1340 __PRETTY_FUNCTION__,
1341 ospf_vrf_id_to_name(ospf->vrf_id),
1342 ospf->vrf_id);
1343 /* Deregister for router-id, interfaces,
1344 * redistributed routes. */
1345 zclient_send_dereg_requests(zclient, ospf->vrf_id);
1346 }
1347 }
1348 static void ospf_zebra_connected(struct zclient *zclient)
1349 {
1350 /* Send the client registration */
1351 bfd_client_sendmsg(zclient, ZEBRA_BFD_CLIENT_REGISTER, VRF_DEFAULT);
1352
1353 zclient_send_reg_requests(zclient, VRF_DEFAULT);
1354 }
1355
1356 void ospf_zebra_init(struct thread_master *master, unsigned short instance)
1357 {
1358 /* Allocate zebra structure. */
1359 zclient = zclient_new(master, &zclient_options_default);
1360 zclient_init(zclient, ZEBRA_ROUTE_OSPF, instance, &ospfd_privs);
1361 zclient->zebra_connected = ospf_zebra_connected;
1362 zclient->router_id_update = ospf_router_id_update_zebra;
1363 zclient->interface_address_add = ospf_interface_address_add;
1364 zclient->interface_address_delete = ospf_interface_address_delete;
1365 zclient->interface_link_params = ospf_interface_link_params;
1366 zclient->interface_vrf_update = ospf_interface_vrf_update;
1367
1368 zclient->redistribute_route_add = ospf_zebra_read_route;
1369 zclient->redistribute_route_del = ospf_zebra_read_route;
1370
1371 access_list_add_hook(ospf_filter_update);
1372 access_list_delete_hook(ospf_filter_update);
1373 prefix_list_add_hook(ospf_prefix_list_update);
1374 prefix_list_delete_hook(ospf_prefix_list_update);
1375 }