blob: d9b0837b1cd4ddc35354de8fee635c7e43d60867 [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/*
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
18 * along with GNU Zebra; see the file COPYING. If not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
21 */
22
23#include <zebra.h>
24
25#include "thread.h"
26#include "command.h"
27#include "network.h"
28#include "prefix.h"
29#include "routemap.h"
30#include "table.h"
31#include "stream.h"
32#include "memory.h"
33#include "zclient.h"
34#include "filter.h"
hassodd669bb2004-05-10 07:43:59 +000035#include "plist.h"
paul718e3742002-12-13 20:15:29 +000036#include "log.h"
37
38#include "ospfd/ospfd.h"
39#include "ospfd/ospf_interface.h"
40#include "ospfd/ospf_ism.h"
41#include "ospfd/ospf_asbr.h"
42#include "ospfd/ospf_asbr.h"
43#include "ospfd/ospf_abr.h"
44#include "ospfd/ospf_lsa.h"
45#include "ospfd/ospf_dump.h"
46#include "ospfd/ospf_route.h"
47#include "ospfd/ospf_zebra.h"
48#ifdef HAVE_SNMP
49#include "ospfd/ospf_snmp.h"
50#endif /* HAVE_SNMP */
Olivier Dugeon29a14012016-04-19 18:42:40 +020051#include "ospfd/ospf_te.h"
paul718e3742002-12-13 20:15:29 +000052
53/* Zebra structure to hold current status. */
54struct zclient *zclient = NULL;
55
56/* For registering threads. */
57extern struct thread_master *master;
hasso18a6dce2004-10-03 18:18:34 +000058struct in_addr router_id_zebra;
59
60/* Router-id update message from zebra. */
paul4dadc292005-05-06 21:37:42 +000061static int
hasso18a6dce2004-10-03 18:18:34 +000062ospf_router_id_update_zebra (int command, struct zclient *zclient,
Feng Luc99f3482014-10-16 09:52:36 +080063 zebra_size_t length, vrf_id_t vrf_id)
hasso18a6dce2004-10-03 18:18:34 +000064{
65 struct ospf *ospf;
66 struct prefix router_id;
67 zebra_router_id_update_read(zclient->ibuf,&router_id);
68
Andrew J. Schorr7f643eb2006-11-30 16:17:02 +000069 if (IS_DEBUG_OSPF (zebra, ZEBRA_INTERFACE))
70 {
71 char buf[128];
72 prefix2str(&router_id, buf, sizeof(buf));
73 zlog_debug("Zebra rcvd: router id update %s", buf);
74 }
75
hasso18a6dce2004-10-03 18:18:34 +000076 router_id_zebra = router_id.u.prefix4;
77
78 ospf = ospf_lookup ();
paulb29800a2005-11-20 14:50:45 +000079
hasso18a6dce2004-10-03 18:18:34 +000080 if (ospf != NULL)
paulb29800a2005-11-20 14:50:45 +000081 ospf_router_id_update (ospf);
82
hasso18a6dce2004-10-03 18:18:34 +000083 return 0;
84}
paul718e3742002-12-13 20:15:29 +000085
86/* Inteface addition message from zebra. */
paul4dadc292005-05-06 21:37:42 +000087static int
Feng Luc99f3482014-10-16 09:52:36 +080088ospf_interface_add (int command, struct zclient *zclient, zebra_size_t length,
89 vrf_id_t vrf_id)
paul718e3742002-12-13 20:15:29 +000090{
91 struct interface *ifp;
92
Feng Luc99f3482014-10-16 09:52:36 +080093 ifp = zebra_interface_add_read (zclient->ibuf, vrf_id);
paul718e3742002-12-13 20:15:29 +000094
95 if (IS_DEBUG_OSPF (zebra, ZEBRA_INTERFACE))
Stephen Hemminger30d20592009-07-28 11:58:51 +010096 zlog_debug ("Zebra: interface add %s index %d flags %llx metric %d mtu %d",
97 ifp->name, ifp->ifindex, (unsigned long long)ifp->flags,
98 ifp->metric, ifp->mtu);
paul718e3742002-12-13 20:15:29 +000099
paulcf795c52003-06-19 02:13:25 +0000100 assert (ifp->info);
paulf2c80652002-12-13 21:44:27 +0000101
paul718e3742002-12-13 20:15:29 +0000102 if (!OSPF_IF_PARAM_CONFIGURED (IF_DEF_PARAMS (ifp), type))
103 {
104 SET_IF_PARAM (IF_DEF_PARAMS (ifp), type);
ajsbc18d612004-12-15 15:07:19 +0000105 IF_DEF_PARAMS (ifp)->type = ospf_default_iftype(ifp);
paul718e3742002-12-13 20:15:29 +0000106 }
107
Joakim Tjernlunda49eb302008-09-02 19:06:31 +0100108 ospf_if_update (NULL, ifp);
paul718e3742002-12-13 20:15:29 +0000109
110#ifdef HAVE_SNMP
111 ospf_snmp_if_update (ifp);
112#endif /* HAVE_SNMP */
113
114 return 0;
115}
116
paul4dadc292005-05-06 21:37:42 +0000117static int
paul718e3742002-12-13 20:15:29 +0000118ospf_interface_delete (int command, struct zclient *zclient,
Feng Luc99f3482014-10-16 09:52:36 +0800119 zebra_size_t length, vrf_id_t vrf_id)
paul718e3742002-12-13 20:15:29 +0000120{
121 struct interface *ifp;
122 struct stream *s;
123 struct route_node *rn;
124
paulcf795c52003-06-19 02:13:25 +0000125 s = zclient->ibuf;
paul718e3742002-12-13 20:15:29 +0000126 /* zebra_interface_state_read() updates interface structure in iflist */
Feng Luc99f3482014-10-16 09:52:36 +0800127 ifp = zebra_interface_state_read (s, vrf_id);
paul718e3742002-12-13 20:15:29 +0000128
129 if (ifp == NULL)
130 return 0;
131
132 if (if_is_up (ifp))
133 zlog_warn ("Zebra: got delete of %s, but interface is still up",
paulcf795c52003-06-19 02:13:25 +0000134 ifp->name);
135
paul718e3742002-12-13 20:15:29 +0000136 if (IS_DEBUG_OSPF (zebra, ZEBRA_INTERFACE))
ajs9b0e25c2004-12-08 19:06:51 +0000137 zlog_debug
Andrew Certain0798cee2012-12-04 13:43:42 -0800138 ("Zebra: interface delete %s index %d flags %llx metric %d mtu %d",
139 ifp->name, ifp->ifindex, (unsigned long long)ifp->flags, ifp->metric, ifp->mtu);
paul718e3742002-12-13 20:15:29 +0000140
141#ifdef HAVE_SNMP
142 ospf_snmp_if_delete (ifp);
143#endif /* HAVE_SNMP */
144
145 for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
146 if (rn->info)
147 ospf_if_free ((struct ospf_interface *) rn->info);
148
ajsd2fc8892005-04-02 18:38:43 +0000149 ifp->ifindex = IFINDEX_INTERNAL;
paul718e3742002-12-13 20:15:29 +0000150 return 0;
151}
152
ajsd2fc8892005-04-02 18:38:43 +0000153static struct interface *
Feng Luc99f3482014-10-16 09:52:36 +0800154zebra_interface_if_lookup (struct stream *s, vrf_id_t vrf_id)
paul718e3742002-12-13 20:15:29 +0000155{
ajs21fefa92005-04-02 23:16:41 +0000156 char ifname_tmp[INTERFACE_NAMSIZ];
paul718e3742002-12-13 20:15:29 +0000157
158 /* Read interface name. */
159 stream_get (ifname_tmp, s, INTERFACE_NAMSIZ);
160
ajsd2fc8892005-04-02 18:38:43 +0000161 /* And look it up. */
ajs21fefa92005-04-02 23:16:41 +0000162 return if_lookup_by_name_len(ifname_tmp,
163 strnlen(ifname_tmp, INTERFACE_NAMSIZ));
paul718e3742002-12-13 20:15:29 +0000164}
165
paul4dadc292005-05-06 21:37:42 +0000166static int
paul718e3742002-12-13 20:15:29 +0000167ospf_interface_state_up (int command, struct zclient *zclient,
Feng Luc99f3482014-10-16 09:52:36 +0800168 zebra_size_t length, vrf_id_t vrf_id)
paul718e3742002-12-13 20:15:29 +0000169{
170 struct interface *ifp;
paul718e3742002-12-13 20:15:29 +0000171 struct ospf_interface *oi;
172 struct route_node *rn;
paulcf795c52003-06-19 02:13:25 +0000173
Feng Luc99f3482014-10-16 09:52:36 +0800174 ifp = zebra_interface_if_lookup (zclient->ibuf, vrf_id);
paul718e3742002-12-13 20:15:29 +0000175
176 if (ifp == NULL)
177 return 0;
178
179 /* Interface is already up. */
paul2e3b2e42002-12-13 21:03:13 +0000180 if (if_is_operative (ifp))
paul718e3742002-12-13 20:15:29 +0000181 {
182 /* Temporarily keep ifp values. */
ajsa608bbf2005-03-29 17:03:49 +0000183 struct interface if_tmp;
paul718e3742002-12-13 20:15:29 +0000184 memcpy (&if_tmp, ifp, sizeof (struct interface));
185
186 zebra_interface_if_set_value (zclient->ibuf, ifp);
187
188 if (IS_DEBUG_OSPF (zebra, ZEBRA_INTERFACE))
ajs9b0e25c2004-12-08 19:06:51 +0000189 zlog_debug ("Zebra: Interface[%s] state update.", ifp->name);
paul718e3742002-12-13 20:15:29 +0000190
191 if (if_tmp.bandwidth != ifp->bandwidth)
paulcf795c52003-06-19 02:13:25 +0000192 {
193 if (IS_DEBUG_OSPF (zebra, ZEBRA_INTERFACE))
ajs9b0e25c2004-12-08 19:06:51 +0000194 zlog_debug ("Zebra: Interface[%s] bandwidth change %d -> %d.",
paulcf795c52003-06-19 02:13:25 +0000195 ifp->name, if_tmp.bandwidth, ifp->bandwidth);
paul718e3742002-12-13 20:15:29 +0000196
paulcf795c52003-06-19 02:13:25 +0000197 ospf_if_recalculate_output_cost (ifp);
198 }
ajsa608bbf2005-03-29 17:03:49 +0000199
200 if (if_tmp.mtu != ifp->mtu)
201 {
202 if (IS_DEBUG_OSPF (zebra, ZEBRA_INTERFACE))
203 zlog_debug ("Zebra: Interface[%s] MTU change %u -> %u.",
204 ifp->name, if_tmp.mtu, ifp->mtu);
205
206 /* Must reset the interface (simulate down/up) when MTU changes. */
207 ospf_if_reset(ifp);
208 }
paul718e3742002-12-13 20:15:29 +0000209 return 0;
210 }
paulcf795c52003-06-19 02:13:25 +0000211
paul718e3742002-12-13 20:15:29 +0000212 zebra_interface_if_set_value (zclient->ibuf, ifp);
paulcf795c52003-06-19 02:13:25 +0000213
paul718e3742002-12-13 20:15:29 +0000214 if (IS_DEBUG_OSPF (zebra, ZEBRA_INTERFACE))
ajs9b0e25c2004-12-08 19:06:51 +0000215 zlog_debug ("Zebra: Interface[%s] state change to up.", ifp->name);
paulcf795c52003-06-19 02:13:25 +0000216
217 for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
paul718e3742002-12-13 20:15:29 +0000218 {
paulcf795c52003-06-19 02:13:25 +0000219 if ((oi = rn->info) == NULL)
220 continue;
221
paul718e3742002-12-13 20:15:29 +0000222 ospf_if_up (oi);
223 }
paulcf795c52003-06-19 02:13:25 +0000224
paul718e3742002-12-13 20:15:29 +0000225 return 0;
226}
227
paul4dadc292005-05-06 21:37:42 +0000228static int
paul718e3742002-12-13 20:15:29 +0000229ospf_interface_state_down (int command, struct zclient *zclient,
Feng Luc99f3482014-10-16 09:52:36 +0800230 zebra_size_t length, vrf_id_t vrf_id)
paul718e3742002-12-13 20:15:29 +0000231{
232 struct interface *ifp;
233 struct ospf_interface *oi;
234 struct route_node *node;
235
Feng Luc99f3482014-10-16 09:52:36 +0800236 ifp = zebra_interface_state_read (zclient->ibuf, vrf_id);
paul718e3742002-12-13 20:15:29 +0000237
238 if (ifp == NULL)
239 return 0;
240
241 if (IS_DEBUG_OSPF (zebra, ZEBRA_INTERFACE))
ajs9b0e25c2004-12-08 19:06:51 +0000242 zlog_debug ("Zebra: Interface[%s] state change to down.", ifp->name);
paul718e3742002-12-13 20:15:29 +0000243
paulcf795c52003-06-19 02:13:25 +0000244 for (node = route_top (IF_OIFS (ifp)); node; node = route_next (node))
paul718e3742002-12-13 20:15:29 +0000245 {
paulcf795c52003-06-19 02:13:25 +0000246 if ((oi = node->info) == NULL)
247 continue;
paul718e3742002-12-13 20:15:29 +0000248 ospf_if_down (oi);
249 }
250
251 return 0;
252}
253
paul4dadc292005-05-06 21:37:42 +0000254static int
paul718e3742002-12-13 20:15:29 +0000255ospf_interface_address_add (int command, struct zclient *zclient,
Feng Luc99f3482014-10-16 09:52:36 +0800256 zebra_size_t length, vrf_id_t vrf_id)
paul718e3742002-12-13 20:15:29 +0000257{
258 struct connected *c;
259
Feng Luc99f3482014-10-16 09:52:36 +0800260 c = zebra_interface_address_read (command, zclient->ibuf, vrf_id);
paul718e3742002-12-13 20:15:29 +0000261
262 if (c == NULL)
263 return 0;
264
Andrew J. Schorr7f643eb2006-11-30 16:17:02 +0000265 if (IS_DEBUG_OSPF (zebra, ZEBRA_INTERFACE))
266 {
267 char buf[128];
268 prefix2str(c->address, buf, sizeof(buf));
269 zlog_debug("Zebra: interface %s address add %s", c->ifp->name, buf);
270 }
271
Joakim Tjernlunda49eb302008-09-02 19:06:31 +0100272 ospf_if_update (NULL, c->ifp);
paul718e3742002-12-13 20:15:29 +0000273
274#ifdef HAVE_SNMP
275 ospf_snmp_if_update (c->ifp);
276#endif /* HAVE_SNMP */
277
278 return 0;
279}
280
paul4dadc292005-05-06 21:37:42 +0000281static int
paul718e3742002-12-13 20:15:29 +0000282ospf_interface_address_delete (int command, struct zclient *zclient,
Feng Luc99f3482014-10-16 09:52:36 +0800283 zebra_size_t length, vrf_id_t vrf_id)
paul718e3742002-12-13 20:15:29 +0000284{
285 struct connected *c;
286 struct interface *ifp;
287 struct ospf_interface *oi;
288 struct route_node *rn;
289 struct prefix p;
290
Feng Luc99f3482014-10-16 09:52:36 +0800291 c = zebra_interface_address_read (command, zclient->ibuf, vrf_id);
paul718e3742002-12-13 20:15:29 +0000292
293 if (c == NULL)
294 return 0;
295
Andrew J. Schorr7f643eb2006-11-30 16:17:02 +0000296 if (IS_DEBUG_OSPF (zebra, ZEBRA_INTERFACE))
297 {
298 char buf[128];
299 prefix2str(c->address, buf, sizeof(buf));
300 zlog_debug("Zebra: interface %s address delete %s", c->ifp->name, buf);
301 }
302
paul718e3742002-12-13 20:15:29 +0000303 ifp = c->ifp;
304 p = *c->address;
305 p.prefixlen = IPV4_MAX_PREFIXLEN;
306
307 rn = route_node_lookup (IF_OIFS (ifp), &p);
paulcf795c52003-06-19 02:13:25 +0000308 if (!rn)
paul98429f62006-01-10 22:11:54 +0000309 {
310 connected_free (c);
311 return 0;
312 }
paul718e3742002-12-13 20:15:29 +0000313
314 assert (rn->info);
315 oi = rn->info;
Joakim Tjernlundfbb6c862010-03-08 13:58:09 +0100316 route_unlock_node (rn);
paulcf795c52003-06-19 02:13:25 +0000317
paul718e3742002-12-13 20:15:29 +0000318 /* Call interface hook functions to clean up */
319 ospf_if_free (oi);
paulcf795c52003-06-19 02:13:25 +0000320
paul718e3742002-12-13 20:15:29 +0000321#ifdef HAVE_SNMP
322 ospf_snmp_if_update (c->ifp);
323#endif /* HAVE_SNMP */
324
325 connected_free (c);
326
paul718e3742002-12-13 20:15:29 +0000327 return 0;
328}
paul72357f22003-06-19 02:11:23 +0000329
Olivier Dugeon29a14012016-04-19 18:42:40 +0200330static int
331ospf_interface_link_params (int command, struct zclient *zclient,
332 zebra_size_t length)
333{
334 struct interface *ifp;
335
336 ifp = zebra_interface_link_params_read (zclient->ibuf);
337
338 if (ifp == NULL)
339 return 0;
340
341 /* Update TE TLV */
342 ospf_mpls_te_update_if (ifp);
343
344 return 0;
345}
346
347
paul718e3742002-12-13 20:15:29 +0000348void
349ospf_zebra_add (struct prefix_ipv4 *p, struct ospf_route *or)
350{
351 u_char message;
352 u_char distance;
353 u_char flags;
354 int psize;
355 struct stream *s;
356 struct ospf_path *path;
hasso52dc7ee2004-09-23 19:18:23 +0000357 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000358
Feng Luc99f3482014-10-16 09:52:36 +0800359 if (vrf_bitmap_check (zclient->redist[ZEBRA_ROUTE_OSPF], VRF_DEFAULT))
paul718e3742002-12-13 20:15:29 +0000360 {
361 message = 0;
362 flags = 0;
363
364 /* OSPF pass nexthop and metric */
365 SET_FLAG (message, ZAPI_MESSAGE_NEXTHOP);
366 SET_FLAG (message, ZAPI_MESSAGE_METRIC);
367
368 /* Distance value. */
369 distance = ospf_distance_apply (p, or);
370 if (distance)
paul72357f22003-06-19 02:11:23 +0000371 SET_FLAG (message, ZAPI_MESSAGE_DISTANCE);
paul718e3742002-12-13 20:15:29 +0000372
373 /* Make packet. */
374 s = zclient->obuf;
375 stream_reset (s);
376
paul718e3742002-12-13 20:15:29 +0000377 /* Put command, type, flags, message. */
Feng Luc99f3482014-10-16 09:52:36 +0800378 zclient_create_header (s, ZEBRA_IPV4_ROUTE_ADD, VRF_DEFAULT);
paul718e3742002-12-13 20:15:29 +0000379 stream_putc (s, ZEBRA_ROUTE_OSPF);
380 stream_putc (s, flags);
381 stream_putc (s, message);
Denis Ovsienkob4e45f62011-12-05 16:35:14 +0400382 stream_putw (s, SAFI_UNICAST);
paulcf795c52003-06-19 02:13:25 +0000383
paul718e3742002-12-13 20:15:29 +0000384 /* Put prefix information. */
385 psize = PSIZE (p->prefixlen);
386 stream_putc (s, p->prefixlen);
paulcf795c52003-06-19 02:13:25 +0000387 stream_write (s, (u_char *) & p->prefix, psize);
paul718e3742002-12-13 20:15:29 +0000388
389 /* Nexthop count. */
paul96735ee2003-08-10 02:51:22 +0000390 stream_putc (s, or->paths->count);
paul718e3742002-12-13 20:15:29 +0000391
392 /* Nexthop, ifindex, distance and metric information. */
paul1eb8ef22005-04-07 07:30:20 +0000393 for (ALL_LIST_ELEMENTS_RO (or->paths, node, path))
paul72357f22003-06-19 02:11:23 +0000394 {
Joakim Tjernlundba281d32012-07-07 17:06:13 +0200395 if (path->nexthop.s_addr != INADDR_ANY &&
396 path->ifindex != 0)
397 {
398 stream_putc (s, ZEBRA_NEXTHOP_IPV4_IFINDEX);
399 stream_put_in_addr (s, &path->nexthop);
400 stream_putl (s, path->ifindex);
401 }
402 else if (path->nexthop.s_addr != INADDR_ANY)
paulcf795c52003-06-19 02:13:25 +0000403 {
404 stream_putc (s, ZEBRA_NEXTHOP_IPV4);
405 stream_put_in_addr (s, &path->nexthop);
406 }
407 else
408 {
409 stream_putc (s, ZEBRA_NEXTHOP_IFINDEX);
Joakim Tjernlunda8ba8472009-07-27 12:42:34 +0200410 if (path->ifindex)
411 stream_putl (s, path->ifindex);
paulcf795c52003-06-19 02:13:25 +0000412 else
413 stream_putl (s, 0);
414 }
paul72357f22003-06-19 02:11:23 +0000415
416 if (IS_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE))
417 {
Andrew J. Schorr56b3ea02007-03-14 20:21:43 +0000418 char buf[2][INET_ADDRSTRLEN];
419 zlog_debug("Zebra: Route add %s/%d nexthop %s",
420 inet_ntop(AF_INET, &p->prefix,
421 buf[0], sizeof(buf[0])),
422 p->prefixlen,
423 inet_ntop(AF_INET, &path->nexthop,
424 buf[1], sizeof(buf[1])));
paulcf795c52003-06-19 02:13:25 +0000425 }
426 }
paul718e3742002-12-13 20:15:29 +0000427
428 if (CHECK_FLAG (message, ZAPI_MESSAGE_DISTANCE))
paulcf795c52003-06-19 02:13:25 +0000429 stream_putc (s, distance);
paul718e3742002-12-13 20:15:29 +0000430 if (CHECK_FLAG (message, ZAPI_MESSAGE_METRIC))
paulcf795c52003-06-19 02:13:25 +0000431 {
432 if (or->path_type == OSPF_PATH_TYPE1_EXTERNAL)
433 stream_putl (s, or->cost + or->u.ext.type2_cost);
434 else if (or->path_type == OSPF_PATH_TYPE2_EXTERNAL)
435 stream_putl (s, or->u.ext.type2_cost);
436 else
437 stream_putl (s, or->cost);
438 }
paul718e3742002-12-13 20:15:29 +0000439
440 stream_putw_at (s, 0, stream_get_endp (s));
441
ajs634f9ea2005-04-11 15:51:40 +0000442 zclient_send_message(zclient);
paul718e3742002-12-13 20:15:29 +0000443 }
444}
445
446void
447ospf_zebra_delete (struct prefix_ipv4 *p, struct ospf_route *or)
448{
Joakim Tjernlundba281d32012-07-07 17:06:13 +0200449 u_char message;
450 u_char distance;
451 u_char flags;
452 int psize;
453 struct stream *s;
paul72357f22003-06-19 02:11:23 +0000454 struct ospf_path *path;
Joakim Tjernlundba281d32012-07-07 17:06:13 +0200455 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000456
Feng Luc99f3482014-10-16 09:52:36 +0800457 if (vrf_bitmap_check (zclient->redist[ZEBRA_ROUTE_OSPF], VRF_DEFAULT))
paul718e3742002-12-13 20:15:29 +0000458 {
Joakim Tjernlundba281d32012-07-07 17:06:13 +0200459 message = 0;
460 flags = 0;
461 /* Distance value. */
462 distance = ospf_distance_apply (p, or);
463 /* Make packet. */
464 s = zclient->obuf;
465 stream_reset (s);
paul718e3742002-12-13 20:15:29 +0000466
Joakim Tjernlundba281d32012-07-07 17:06:13 +0200467 /* Put command, type, flags, message. */
Feng Luc99f3482014-10-16 09:52:36 +0800468 zclient_create_header (s, ZEBRA_IPV4_ROUTE_DELETE, VRF_DEFAULT);
Joakim Tjernlundba281d32012-07-07 17:06:13 +0200469 stream_putc (s, ZEBRA_ROUTE_OSPF);
470 stream_putc (s, flags);
471 stream_putc (s, message);
472 stream_putw (s, SAFI_UNICAST);
paul72357f22003-06-19 02:11:23 +0000473
Joakim Tjernlundba281d32012-07-07 17:06:13 +0200474 /* Put prefix information. */
475 psize = PSIZE (p->prefixlen);
476 stream_putc (s, p->prefixlen);
477 stream_write (s, (u_char *) & p->prefix, psize);
paul72357f22003-06-19 02:11:23 +0000478
Joakim Tjernlundba281d32012-07-07 17:06:13 +0200479 /* Nexthop count. */
480 stream_putc (s, or->paths->count);
481
482 /* Nexthop, ifindex, distance and metric information. */
483 for (ALL_LIST_ELEMENTS_RO (or->paths, node, path))
484 {
485 if (path->nexthop.s_addr != INADDR_ANY &&
486 path->ifindex != 0)
487 {
488 stream_putc (s, ZEBRA_NEXTHOP_IPV4_IFINDEX);
489 stream_put_in_addr (s, &path->nexthop);
490 stream_putl (s, path->ifindex);
491 }
492 else if (path->nexthop.s_addr != INADDR_ANY)
493 {
494 stream_putc (s, ZEBRA_NEXTHOP_IPV4);
495 stream_put_in_addr (s, &path->nexthop);
496 }
497 else
498 {
499 stream_putc (s, ZEBRA_NEXTHOP_IFINDEX);
500 stream_putl (s, path->ifindex);
501 }
502
503 if (IS_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE))
504 {
Andrew J. Schorr56b3ea02007-03-14 20:21:43 +0000505 char buf[2][INET_ADDRSTRLEN];
Christian Frankea25a1262013-11-27 14:36:05 +0000506 zlog_debug("Zebra: Route delete %s/%d nexthop %s",
Joakim Tjernlundba281d32012-07-07 17:06:13 +0200507 inet_ntop(AF_INET, &p->prefix,
508 buf[0], sizeof(buf[0])),
Andrew J. Schorr56b3ea02007-03-14 20:21:43 +0000509 p->prefixlen,
Joakim Tjernlundba281d32012-07-07 17:06:13 +0200510 inet_ntop(AF_INET, &path->nexthop,
Andrew J. Schorr56b3ea02007-03-14 20:21:43 +0000511 buf[1], sizeof(buf[1])));
Joakim Tjernlundba281d32012-07-07 17:06:13 +0200512 }
513 }
514
515 if (CHECK_FLAG (message, ZAPI_MESSAGE_DISTANCE))
516 stream_putc (s, distance);
517 if (CHECK_FLAG (message, ZAPI_MESSAGE_METRIC))
518 {
519 if (or->path_type == OSPF_PATH_TYPE1_EXTERNAL)
520 stream_putl (s, or->cost + or->u.ext.type2_cost);
521 else if (or->path_type == OSPF_PATH_TYPE2_EXTERNAL)
522 stream_putl (s, or->u.ext.type2_cost);
523 else
524 stream_putl (s, or->cost);
525 }
526
527 stream_putw_at (s, 0, stream_get_endp (s));
528
529 zclient_send_message(zclient);
paul718e3742002-12-13 20:15:29 +0000530 }
531}
532
533void
534ospf_zebra_add_discard (struct prefix_ipv4 *p)
535{
536 struct zapi_ipv4 api;
537
Feng Luc99f3482014-10-16 09:52:36 +0800538 if (vrf_bitmap_check (zclient->redist[ZEBRA_ROUTE_OSPF], VRF_DEFAULT))
paul718e3742002-12-13 20:15:29 +0000539 {
Feng Luc99f3482014-10-16 09:52:36 +0800540 api.vrf_id = VRF_DEFAULT;
paul718e3742002-12-13 20:15:29 +0000541 api.type = ZEBRA_ROUTE_OSPF;
542 api.flags = ZEBRA_FLAG_BLACKHOLE;
543 api.message = 0;
Denis Ovsienkob4e45f62011-12-05 16:35:14 +0400544 api.safi = SAFI_UNICAST;
paul718e3742002-12-13 20:15:29 +0000545 SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP);
546 api.nexthop_num = 0;
547 api.ifindex_num = 0;
Piotr Chytłaeefddcc2015-12-01 09:48:02 -0500548 api.tag = 0;
paul718e3742002-12-13 20:15:29 +0000549
paul0a589352004-05-08 11:48:26 +0000550 zapi_ipv4_route (ZEBRA_IPV4_ROUTE_ADD, zclient, p, &api);
Andrew J. Schorr7f643eb2006-11-30 16:17:02 +0000551
552 if (IS_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE))
553 zlog_debug ("Zebra: Route add discard %s/%d",
554 inet_ntoa (p->prefix), p->prefixlen);
paul718e3742002-12-13 20:15:29 +0000555 }
556}
557
558void
559ospf_zebra_delete_discard (struct prefix_ipv4 *p)
560{
561 struct zapi_ipv4 api;
562
Feng Luc99f3482014-10-16 09:52:36 +0800563 if (vrf_bitmap_check (zclient->redist[ZEBRA_ROUTE_OSPF], VRF_DEFAULT))
paul718e3742002-12-13 20:15:29 +0000564 {
Feng Luc99f3482014-10-16 09:52:36 +0800565 api.vrf_id = VRF_DEFAULT;
paul718e3742002-12-13 20:15:29 +0000566 api.type = ZEBRA_ROUTE_OSPF;
567 api.flags = ZEBRA_FLAG_BLACKHOLE;
568 api.message = 0;
Denis Ovsienkob4e45f62011-12-05 16:35:14 +0400569 api.safi = SAFI_UNICAST;
paul718e3742002-12-13 20:15:29 +0000570 SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP);
571 api.nexthop_num = 0;
572 api.ifindex_num = 0;
Piotr Chytłaeefddcc2015-12-01 09:48:02 -0500573 api.tag = 0;
paul718e3742002-12-13 20:15:29 +0000574
paul0a589352004-05-08 11:48:26 +0000575 zapi_ipv4_route (ZEBRA_IPV4_ROUTE_DELETE, zclient, p, &api);
paul72357f22003-06-19 02:11:23 +0000576
577 if (IS_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE))
ajs9b0e25c2004-12-08 19:06:51 +0000578 zlog_debug ("Zebra: Route delete discard %s/%d",
paulcf795c52003-06-19 02:13:25 +0000579 inet_ntoa (p->prefix), p->prefixlen);
paul72357f22003-06-19 02:11:23 +0000580
paul718e3742002-12-13 20:15:29 +0000581 }
582}
583
584int
585ospf_is_type_redistributed (int type)
586{
587 return (DEFAULT_ROUTE_TYPE (type)) ?
Feng Luc99f3482014-10-16 09:52:36 +0800588 vrf_bitmap_check (zclient->default_information, VRF_DEFAULT) : \
589 vrf_bitmap_check (zclient->redist[type], VRF_DEFAULT);
paul718e3742002-12-13 20:15:29 +0000590}
591
592int
paul020709f2003-04-04 02:44:16 +0000593ospf_redistribute_set (struct ospf *ospf, int type, int mtype, int mvalue)
paul718e3742002-12-13 20:15:29 +0000594{
595 int force = 0;
paulcf795c52003-06-19 02:13:25 +0000596
paul718e3742002-12-13 20:15:29 +0000597 if (ospf_is_type_redistributed (type))
598 {
paul68980082003-03-25 05:07:42 +0000599 if (mtype != ospf->dmetric[type].type)
paulcf795c52003-06-19 02:13:25 +0000600 {
601 ospf->dmetric[type].type = mtype;
602 force = LSA_REFRESH_FORCE;
603 }
paul68980082003-03-25 05:07:42 +0000604 if (mvalue != ospf->dmetric[type].value)
paulcf795c52003-06-19 02:13:25 +0000605 {
606 ospf->dmetric[type].value = mvalue;
607 force = LSA_REFRESH_FORCE;
608 }
609
paul68980082003-03-25 05:07:42 +0000610 ospf_external_lsa_refresh_type (ospf, type, force);
paulcf795c52003-06-19 02:13:25 +0000611
paul718e3742002-12-13 20:15:29 +0000612 if (IS_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE))
ajs9b0e25c2004-12-08 19:06:51 +0000613 zlog_debug ("Redistribute[%s]: Refresh Type[%d], Metric[%d]",
ajsf52d13c2005-10-01 17:38:06 +0000614 ospf_redist_string(type),
paulcf795c52003-06-19 02:13:25 +0000615 metric_type (ospf, type), metric_value (ospf, type));
616
paul718e3742002-12-13 20:15:29 +0000617 return CMD_SUCCESS;
618 }
619
paul68980082003-03-25 05:07:42 +0000620 ospf->dmetric[type].type = mtype;
621 ospf->dmetric[type].value = mvalue;
paul718e3742002-12-13 20:15:29 +0000622
Feng Luc99f3482014-10-16 09:52:36 +0800623 zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, type, VRF_DEFAULT);
paul718e3742002-12-13 20:15:29 +0000624
625 if (IS_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE))
ajs9b0e25c2004-12-08 19:06:51 +0000626 zlog_debug ("Redistribute[%s]: Start Type[%d], Metric[%d]",
ajsf52d13c2005-10-01 17:38:06 +0000627 ospf_redist_string(type),
paulcf795c52003-06-19 02:13:25 +0000628 metric_type (ospf, type), metric_value (ospf, type));
629
paul68980082003-03-25 05:07:42 +0000630 ospf_asbr_status_update (ospf, ++ospf->redistribute);
paul718e3742002-12-13 20:15:29 +0000631
632 return CMD_SUCCESS;
633}
634
635int
paul020709f2003-04-04 02:44:16 +0000636ospf_redistribute_unset (struct ospf *ospf, int type)
paul718e3742002-12-13 20:15:29 +0000637{
638 if (type == zclient->redist_default)
639 return CMD_SUCCESS;
640
paulcf795c52003-06-19 02:13:25 +0000641 if (!ospf_is_type_redistributed (type))
paul718e3742002-12-13 20:15:29 +0000642 return CMD_SUCCESS;
643
Feng Luc99f3482014-10-16 09:52:36 +0800644 zclient_redistribute (ZEBRA_REDISTRIBUTE_DELETE, zclient, type, VRF_DEFAULT);
paulcf795c52003-06-19 02:13:25 +0000645
paul718e3742002-12-13 20:15:29 +0000646 if (IS_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE))
ajs9b0e25c2004-12-08 19:06:51 +0000647 zlog_debug ("Redistribute[%s]: Stop",
ajsf52d13c2005-10-01 17:38:06 +0000648 ospf_redist_string(type));
paul718e3742002-12-13 20:15:29 +0000649
paul68980082003-03-25 05:07:42 +0000650 ospf->dmetric[type].type = -1;
651 ospf->dmetric[type].value = -1;
paul718e3742002-12-13 20:15:29 +0000652
653 /* Remove the routes from OSPF table. */
Paul Jakma6db3a6f2006-05-12 23:02:46 +0000654 ospf_redistribute_withdraw (ospf, type);
paul718e3742002-12-13 20:15:29 +0000655
paul68980082003-03-25 05:07:42 +0000656 ospf_asbr_status_update (ospf, --ospf->redistribute);
paul718e3742002-12-13 20:15:29 +0000657
658 return CMD_SUCCESS;
659}
660
661int
paul020709f2003-04-04 02:44:16 +0000662ospf_redistribute_default_set (struct ospf *ospf, int originate,
paulcf795c52003-06-19 02:13:25 +0000663 int mtype, int mvalue)
paul718e3742002-12-13 20:15:29 +0000664{
Andrew J. Schorr8fb8a502006-10-24 19:04:26 +0000665 ospf->default_originate = originate;
666 ospf->dmetric[DEFAULT_ROUTE].type = mtype;
667 ospf->dmetric[DEFAULT_ROUTE].value = mvalue;
paul020709f2003-04-04 02:44:16 +0000668
paul718e3742002-12-13 20:15:29 +0000669 if (ospf_is_type_redistributed (DEFAULT_ROUTE))
670 {
Andrew J. Schorr8fb8a502006-10-24 19:04:26 +0000671 /* if ospf->default_originate changes value, is calling
672 ospf_external_lsa_refresh_default sufficient to implement
673 the change? */
paul68980082003-03-25 05:07:42 +0000674 ospf_external_lsa_refresh_default (ospf);
paulcf795c52003-06-19 02:13:25 +0000675
paul718e3742002-12-13 20:15:29 +0000676 if (IS_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE))
ajs9b0e25c2004-12-08 19:06:51 +0000677 zlog_debug ("Redistribute[%s]: Refresh Type[%d], Metric[%d]",
ajsf52d13c2005-10-01 17:38:06 +0000678 ospf_redist_string(DEFAULT_ROUTE),
paulcf795c52003-06-19 02:13:25 +0000679 metric_type (ospf, DEFAULT_ROUTE),
680 metric_value (ospf, DEFAULT_ROUTE));
paul718e3742002-12-13 20:15:29 +0000681 return CMD_SUCCESS;
682 }
683
Feng Luc99f3482014-10-16 09:52:36 +0800684 zclient_redistribute_default (ZEBRA_REDISTRIBUTE_DEFAULT_ADD, zclient,
685 VRF_DEFAULT);
paulcf795c52003-06-19 02:13:25 +0000686
paul718e3742002-12-13 20:15:29 +0000687 if (IS_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE))
ajs9b0e25c2004-12-08 19:06:51 +0000688 zlog_debug ("Redistribute[DEFAULT]: Start Type[%d], Metric[%d]",
paulcf795c52003-06-19 02:13:25 +0000689 metric_type (ospf, DEFAULT_ROUTE),
690 metric_value (ospf, DEFAULT_ROUTE));
paul718e3742002-12-13 20:15:29 +0000691
paul68980082003-03-25 05:07:42 +0000692 if (ospf->router_id.s_addr == 0)
693 ospf->external_origin |= (1 << DEFAULT_ROUTE);
paul718e3742002-12-13 20:15:29 +0000694 else
Paul Jakma4021b602006-05-12 22:55:41 +0000695 thread_add_timer (master, ospf_default_originate_timer, ospf, 1);
paul718e3742002-12-13 20:15:29 +0000696
paul68980082003-03-25 05:07:42 +0000697 ospf_asbr_status_update (ospf, ++ospf->redistribute);
paul718e3742002-12-13 20:15:29 +0000698
699 return CMD_SUCCESS;
700}
701
702int
paul020709f2003-04-04 02:44:16 +0000703ospf_redistribute_default_unset (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +0000704{
705 if (!ospf_is_type_redistributed (DEFAULT_ROUTE))
706 return CMD_SUCCESS;
707
paul68980082003-03-25 05:07:42 +0000708 ospf->default_originate = DEFAULT_ORIGINATE_NONE;
709 ospf->dmetric[DEFAULT_ROUTE].type = -1;
710 ospf->dmetric[DEFAULT_ROUTE].value = -1;
paul718e3742002-12-13 20:15:29 +0000711
Feng Luc99f3482014-10-16 09:52:36 +0800712 zclient_redistribute_default (ZEBRA_REDISTRIBUTE_DEFAULT_DELETE, zclient,
713 VRF_DEFAULT);
paul718e3742002-12-13 20:15:29 +0000714
715 if (IS_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE))
ajs9b0e25c2004-12-08 19:06:51 +0000716 zlog_debug ("Redistribute[DEFAULT]: Stop");
paulcf795c52003-06-19 02:13:25 +0000717
paul68980082003-03-25 05:07:42 +0000718 ospf_asbr_status_update (ospf, --ospf->redistribute);
paul718e3742002-12-13 20:15:29 +0000719
720 return CMD_SUCCESS;
721}
722
paul4dadc292005-05-06 21:37:42 +0000723static int
paul020709f2003-04-04 02:44:16 +0000724ospf_external_lsa_originate_check (struct ospf *ospf,
paulcf795c52003-06-19 02:13:25 +0000725 struct external_info *ei)
paul718e3742002-12-13 20:15:29 +0000726{
727 /* If prefix is multicast, then do not originate LSA. */
728 if (IN_MULTICAST (htonl (ei->p.prefix.s_addr)))
729 {
730 zlog_info ("LSA[Type5:%s]: Not originate AS-external-LSA, "
paulcf795c52003-06-19 02:13:25 +0000731 "Prefix belongs multicast", inet_ntoa (ei->p.prefix));
paul718e3742002-12-13 20:15:29 +0000732 return 0;
733 }
734
735 /* Take care of default-originate. */
736 if (is_prefix_default (&ei->p))
paul68980082003-03-25 05:07:42 +0000737 if (ospf->default_originate == DEFAULT_ORIGINATE_NONE)
paul718e3742002-12-13 20:15:29 +0000738 {
Denis Ovsienkobcc6c592011-09-10 23:29:19 +0400739 zlog_info ("LSA[Type5:0.0.0.0]: Not originate AS-external-LSA "
paulcf795c52003-06-19 02:13:25 +0000740 "for default");
741 return 0;
paul718e3742002-12-13 20:15:29 +0000742 }
743
744 return 1;
745}
746
747/* If connected prefix is OSPF enable interface, then do not announce. */
748int
paulcf795c52003-06-19 02:13:25 +0000749ospf_distribute_check_connected (struct ospf *ospf, struct external_info *ei)
paul718e3742002-12-13 20:15:29 +0000750{
Joakim Tjernlund5d8de932009-08-07 13:48:15 +0200751 struct listnode *node;
752 struct ospf_interface *oi;
paul718e3742002-12-13 20:15:29 +0000753
Joakim Tjernlund5d8de932009-08-07 13:48:15 +0200754
755 for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
756 if (prefix_match (oi->address, (struct prefix *) &ei->p))
paulcf795c52003-06-19 02:13:25 +0000757 return 0;
paul718e3742002-12-13 20:15:29 +0000758 return 1;
759}
760
761/* return 1 if external LSA must be originated, 0 otherwise */
762int
paul68980082003-03-25 05:07:42 +0000763ospf_redistribute_check (struct ospf *ospf,
paulcf795c52003-06-19 02:13:25 +0000764 struct external_info *ei, int *changed)
paul718e3742002-12-13 20:15:29 +0000765{
766 struct route_map_set_values save_values;
767 struct prefix_ipv4 *p = &ei->p;
768 u_char type = is_prefix_default (&ei->p) ? DEFAULT_ROUTE : ei->type;
paulcf795c52003-06-19 02:13:25 +0000769
paul718e3742002-12-13 20:15:29 +0000770 if (changed)
771 *changed = 0;
772
paul020709f2003-04-04 02:44:16 +0000773 if (!ospf_external_lsa_originate_check (ospf, ei))
paul718e3742002-12-13 20:15:29 +0000774 return 0;
775
776 /* Take care connected route. */
paul68980082003-03-25 05:07:42 +0000777 if (type == ZEBRA_ROUTE_CONNECT &&
778 !ospf_distribute_check_connected (ospf, ei))
paul718e3742002-12-13 20:15:29 +0000779 return 0;
780
paul020709f2003-04-04 02:44:16 +0000781 if (!DEFAULT_ROUTE_TYPE (type) && DISTRIBUTE_NAME (ospf, type))
paul718e3742002-12-13 20:15:29 +0000782 /* distirbute-list exists, but access-list may not? */
paul020709f2003-04-04 02:44:16 +0000783 if (DISTRIBUTE_LIST (ospf, type))
784 if (access_list_apply (DISTRIBUTE_LIST (ospf, type), p) == FILTER_DENY)
paulcf795c52003-06-19 02:13:25 +0000785 {
786 if (IS_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE))
ajs9b0e25c2004-12-08 19:06:51 +0000787 zlog_debug ("Redistribute[%s]: %s/%d filtered by ditribute-list.",
ajsf52d13c2005-10-01 17:38:06 +0000788 ospf_redist_string(type),
paulcf795c52003-06-19 02:13:25 +0000789 inet_ntoa (p->prefix), p->prefixlen);
790 return 0;
791 }
paul718e3742002-12-13 20:15:29 +0000792
793 save_values = ei->route_map_set;
794 ospf_reset_route_map_set_values (&ei->route_map_set);
paulcf795c52003-06-19 02:13:25 +0000795
paul718e3742002-12-13 20:15:29 +0000796 /* apply route-map if needed */
paul020709f2003-04-04 02:44:16 +0000797 if (ROUTEMAP_NAME (ospf, type))
paul718e3742002-12-13 20:15:29 +0000798 {
799 int ret;
800
paulcf795c52003-06-19 02:13:25 +0000801 ret = route_map_apply (ROUTEMAP (ospf, type), (struct prefix *) p,
802 RMAP_OSPF, ei);
paul718e3742002-12-13 20:15:29 +0000803
804 if (ret == RMAP_DENYMATCH)
paulcf795c52003-06-19 02:13:25 +0000805 {
806 ei->route_map_set = save_values;
807 if (IS_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE))
ajs9b0e25c2004-12-08 19:06:51 +0000808 zlog_debug ("Redistribute[%s]: %s/%d filtered by route-map.",
ajsf52d13c2005-10-01 17:38:06 +0000809 ospf_redist_string(type),
paulcf795c52003-06-19 02:13:25 +0000810 inet_ntoa (p->prefix), p->prefixlen);
811 return 0;
812 }
813
paul718e3742002-12-13 20:15:29 +0000814 /* check if 'route-map set' changed something */
815 if (changed)
paulcf795c52003-06-19 02:13:25 +0000816 *changed = !ospf_route_map_set_compare (&ei->route_map_set,
817 &save_values);
paul718e3742002-12-13 20:15:29 +0000818 }
819
820 return 1;
821}
822
823/* OSPF route-map set for redistribution */
824void
paul6c835672004-10-11 11:00:30 +0000825ospf_routemap_set (struct ospf *ospf, int type, const char *name)
paul718e3742002-12-13 20:15:29 +0000826{
paul020709f2003-04-04 02:44:16 +0000827 if (ROUTEMAP_NAME (ospf, type))
828 free (ROUTEMAP_NAME (ospf, type));
paul718e3742002-12-13 20:15:29 +0000829
paul020709f2003-04-04 02:44:16 +0000830 ROUTEMAP_NAME (ospf, type) = strdup (name);
831 ROUTEMAP (ospf, type) = route_map_lookup_by_name (name);
paul718e3742002-12-13 20:15:29 +0000832}
833
834void
paul020709f2003-04-04 02:44:16 +0000835ospf_routemap_unset (struct ospf *ospf, int type)
paul718e3742002-12-13 20:15:29 +0000836{
paul020709f2003-04-04 02:44:16 +0000837 if (ROUTEMAP_NAME (ospf, type))
838 free (ROUTEMAP_NAME (ospf, type));
paul718e3742002-12-13 20:15:29 +0000839
paul020709f2003-04-04 02:44:16 +0000840 ROUTEMAP_NAME (ospf, type) = NULL;
841 ROUTEMAP (ospf, type) = NULL;
paul718e3742002-12-13 20:15:29 +0000842}
843
844/* Zebra route add and delete treatment. */
paul4dadc292005-05-06 21:37:42 +0000845static int
paul718e3742002-12-13 20:15:29 +0000846ospf_zebra_read_ipv4 (int command, struct zclient *zclient,
Feng Luc99f3482014-10-16 09:52:36 +0800847 zebra_size_t length, vrf_id_t vrf_id)
paul718e3742002-12-13 20:15:29 +0000848{
849 struct stream *s;
850 struct zapi_ipv4 api;
851 unsigned long ifindex;
852 struct in_addr nexthop;
853 struct prefix_ipv4 p;
854 struct external_info *ei;
paul020709f2003-04-04 02:44:16 +0000855 struct ospf *ospf;
Donald Sharp5e57b5f2016-03-11 16:28:34 -0500856 unsigned char plength = 0;
paul718e3742002-12-13 20:15:29 +0000857
858 s = zclient->ibuf;
859 ifindex = 0;
860 nexthop.s_addr = 0;
861
862 /* Type, flags, message. */
863 api.type = stream_getc (s);
864 api.flags = stream_getc (s);
865 api.message = stream_getc (s);
866
867 /* IPv4 prefix. */
868 memset (&p, 0, sizeof (struct prefix_ipv4));
869 p.family = AF_INET;
Donald Sharp5e57b5f2016-03-11 16:28:34 -0500870 plength = stream_getc (s);
871 p.prefixlen = MIN(IPV4_MAX_PREFIXLEN, plength);
paul718e3742002-12-13 20:15:29 +0000872 stream_get (&p.prefix, s, PSIZE (p.prefixlen));
873
hasso8585d4e2004-04-20 17:25:12 +0000874 if (IPV4_NET127(ntohl(p.prefix.s_addr)))
875 return 0;
876
paul718e3742002-12-13 20:15:29 +0000877 /* Nexthop, ifindex, distance, metric. */
878 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP))
879 {
880 api.nexthop_num = stream_getc (s);
881 nexthop.s_addr = stream_get_ipv4 (s);
882 }
883 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_IFINDEX))
884 {
885 api.ifindex_num = stream_getc (s);
gdt6a8da852004-02-13 17:40:51 +0000886 /* XXX assert(api.ifindex_num == 1); */
paul718e3742002-12-13 20:15:29 +0000887 ifindex = stream_getl (s);
888 }
889 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE))
890 api.distance = stream_getc (s);
891 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC))
892 api.metric = stream_getl (s);
Piotr Chytłaeefddcc2015-12-01 09:48:02 -0500893 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_TAG))
894 api.tag = stream_getw (s);
895 else
896 api.tag = 0;
paul718e3742002-12-13 20:15:29 +0000897
paul020709f2003-04-04 02:44:16 +0000898 ospf = ospf_lookup ();
899 if (ospf == NULL)
900 return 0;
901
paul718e3742002-12-13 20:15:29 +0000902 if (command == ZEBRA_IPV4_ROUTE_ADD)
903 {
paul7021c422003-07-15 12:52:22 +0000904 /* XXX|HACK|TODO|FIXME:
hassoa0a39762004-04-23 08:51:10 +0000905 * Maybe we should ignore reject/blackhole routes? Testing shows that
906 * there is no problems though and this is only way to "summarize"
907 * routes in ASBR at the moment. Maybe we need just a better generalised
908 * solution for these types?
909 *
910 * if ( CHECK_FLAG (api.flags, ZEBRA_FLAG_BLACKHOLE)
911 * || CHECK_FLAG (api.flags, ZEBRA_FLAG_REJECT))
912 * return 0;
paul7021c422003-07-15 12:52:22 +0000913 */
paul7021c422003-07-15 12:52:22 +0000914
paul718e3742002-12-13 20:15:29 +0000915 ei = ospf_external_info_add (api.type, p, ifindex, nexthop);
916
paul68980082003-03-25 05:07:42 +0000917 if (ospf->router_id.s_addr == 0)
paulcf795c52003-06-19 02:13:25 +0000918 /* Set flags to generate AS-external-LSA originate event
919 for each redistributed protocols later. */
920 ospf->external_origin |= (1 << api.type);
paul718e3742002-12-13 20:15:29 +0000921 else
paulcf795c52003-06-19 02:13:25 +0000922 {
923 if (ei)
924 {
925 if (is_prefix_default (&p))
926 ospf_external_lsa_refresh_default (ospf);
927 else
928 {
929 struct ospf_lsa *current;
paul718e3742002-12-13 20:15:29 +0000930
paulcf795c52003-06-19 02:13:25 +0000931 current = ospf_external_info_find_lsa (ospf, &ei->p);
932 if (!current)
933 ospf_external_lsa_originate (ospf, ei);
934 else if (IS_LSA_MAXAGE (current))
935 ospf_external_lsa_refresh (ospf, current,
936 ei, LSA_REFRESH_FORCE);
937 else
938 zlog_warn ("ospf_zebra_read_ipv4() : %s already exists",
939 inet_ntoa (p.prefix));
940 }
941 }
942 }
paul718e3742002-12-13 20:15:29 +0000943 }
paulcf795c52003-06-19 02:13:25 +0000944 else /* if (command == ZEBRA_IPV4_ROUTE_DELETE) */
paul718e3742002-12-13 20:15:29 +0000945 {
946 ospf_external_info_delete (api.type, p);
paul7021c422003-07-15 12:52:22 +0000947 if (is_prefix_default (&p))
paulcf795c52003-06-19 02:13:25 +0000948 ospf_external_lsa_refresh_default (ospf);
paul7021c422003-07-15 12:52:22 +0000949 else
ajs5339cfd2005-09-19 13:28:05 +0000950 ospf_external_lsa_flush (ospf, api.type, &p, ifindex /*, nexthop */);
paul718e3742002-12-13 20:15:29 +0000951 }
952
953 return 0;
954}
David Lamparter6b0655a2014-06-04 06:53:35 +0200955
paulcf795c52003-06-19 02:13:25 +0000956
paul718e3742002-12-13 20:15:29 +0000957int
paul6c835672004-10-11 11:00:30 +0000958ospf_distribute_list_out_set (struct ospf *ospf, int type, const char *name)
paul718e3742002-12-13 20:15:29 +0000959{
960 /* Lookup access-list for distribute-list. */
paul020709f2003-04-04 02:44:16 +0000961 DISTRIBUTE_LIST (ospf, type) = access_list_lookup (AFI_IP, name);
paul718e3742002-12-13 20:15:29 +0000962
963 /* Clear previous distribute-name. */
paul020709f2003-04-04 02:44:16 +0000964 if (DISTRIBUTE_NAME (ospf, type))
965 free (DISTRIBUTE_NAME (ospf, type));
paul718e3742002-12-13 20:15:29 +0000966
967 /* Set distribute-name. */
paul020709f2003-04-04 02:44:16 +0000968 DISTRIBUTE_NAME (ospf, type) = strdup (name);
paul718e3742002-12-13 20:15:29 +0000969
970 /* If access-list have been set, schedule update timer. */
paul020709f2003-04-04 02:44:16 +0000971 if (DISTRIBUTE_LIST (ospf, type))
paul68980082003-03-25 05:07:42 +0000972 ospf_distribute_list_update (ospf, type);
paul718e3742002-12-13 20:15:29 +0000973
974 return CMD_SUCCESS;
975}
976
977int
paul6c835672004-10-11 11:00:30 +0000978ospf_distribute_list_out_unset (struct ospf *ospf, int type, const char *name)
paul718e3742002-12-13 20:15:29 +0000979{
980 /* Schedule update timer. */
paul020709f2003-04-04 02:44:16 +0000981 if (DISTRIBUTE_LIST (ospf, type))
paul68980082003-03-25 05:07:42 +0000982 ospf_distribute_list_update (ospf, type);
paul718e3742002-12-13 20:15:29 +0000983
984 /* Unset distribute-list. */
paul020709f2003-04-04 02:44:16 +0000985 DISTRIBUTE_LIST (ospf, type) = NULL;
paul718e3742002-12-13 20:15:29 +0000986
987 /* Clear distribute-name. */
paul020709f2003-04-04 02:44:16 +0000988 if (DISTRIBUTE_NAME (ospf, type))
989 free (DISTRIBUTE_NAME (ospf, type));
paulcf795c52003-06-19 02:13:25 +0000990
paul020709f2003-04-04 02:44:16 +0000991 DISTRIBUTE_NAME (ospf, type) = NULL;
paul718e3742002-12-13 20:15:29 +0000992
993 return CMD_SUCCESS;
994}
995
996/* distribute-list update timer. */
paul4dadc292005-05-06 21:37:42 +0000997static int
paul718e3742002-12-13 20:15:29 +0000998ospf_distribute_list_update_timer (struct thread *thread)
999{
1000 struct route_node *rn;
1001 struct external_info *ei;
1002 struct route_table *rt;
1003 struct ospf_lsa *lsa;
Joakim Tjernlund46154fe2010-04-14 16:01:25 +02001004 int type, default_refresh = 0;
paul020709f2003-04-04 02:44:16 +00001005 struct ospf *ospf;
paul718e3742002-12-13 20:15:29 +00001006
paul020709f2003-04-04 02:44:16 +00001007 ospf = ospf_lookup ();
1008 if (ospf == NULL)
1009 return 0;
1010
paul68980082003-03-25 05:07:42 +00001011 ospf->t_distribute_update = NULL;
paul718e3742002-12-13 20:15:29 +00001012
1013 zlog_info ("Zebra[Redistribute]: distribute-list update timer fired!");
1014
1015 /* foreach all external info. */
Joakim Tjernlund274d3f02010-04-14 11:05:27 +02001016 for (type = 0; type <= ZEBRA_ROUTE_MAX; type++)
1017 {
1018 rt = EXTERNAL_INFO (type);
1019 if (!rt)
1020 continue;
1021 for (rn = route_top (rt); rn; rn = route_next (rn))
1022 if ((ei = rn->info) != NULL)
1023 {
1024 if (is_prefix_default (&ei->p))
Joakim Tjernlund46154fe2010-04-14 16:01:25 +02001025 default_refresh = 1;
Joakim Tjernlund274d3f02010-04-14 11:05:27 +02001026 else if ((lsa = ospf_external_info_find_lsa (ospf, &ei->p)))
1027 ospf_external_lsa_refresh (ospf, lsa, ei, LSA_REFRESH_IF_CHANGED);
1028 else
1029 ospf_external_lsa_originate (ospf, ei);
1030 }
1031 }
Joakim Tjernlund46154fe2010-04-14 16:01:25 +02001032 if (default_refresh)
1033 ospf_external_lsa_refresh_default (ospf);
paul718e3742002-12-13 20:15:29 +00001034 return 0;
1035}
1036
paul718e3742002-12-13 20:15:29 +00001037/* Update distribute-list and set timer to apply access-list. */
1038void
Andrew Certain0798cee2012-12-04 13:43:42 -08001039ospf_distribute_list_update (struct ospf *ospf, uintptr_t type)
paul718e3742002-12-13 20:15:29 +00001040{
1041 struct route_table *rt;
paulcf795c52003-06-19 02:13:25 +00001042
paul718e3742002-12-13 20:15:29 +00001043 /* External info does not exist. */
1044 if (!(rt = EXTERNAL_INFO (type)))
1045 return;
1046
Joakim Tjernlund45acaa02010-04-14 11:05:28 +02001047 /* If exists previously invoked thread, then let it continue. */
paul68980082003-03-25 05:07:42 +00001048 if (ospf->t_distribute_update)
Joakim Tjernlund45acaa02010-04-14 11:05:28 +02001049 return;
paul718e3742002-12-13 20:15:29 +00001050
1051 /* Set timer. */
paul68980082003-03-25 05:07:42 +00001052 ospf->t_distribute_update =
Michael Rossberg2ef762e2015-07-27 07:56:25 +02001053 thread_add_timer_msec (master, ospf_distribute_list_update_timer,
1054 (void *) type, ospf->min_ls_interval);
paul718e3742002-12-13 20:15:29 +00001055}
1056
1057/* If access-list is updated, apply some check. */
paul4dadc292005-05-06 21:37:42 +00001058static void
paul718e3742002-12-13 20:15:29 +00001059ospf_filter_update (struct access_list *access)
1060{
paul020709f2003-04-04 02:44:16 +00001061 struct ospf *ospf;
paul718e3742002-12-13 20:15:29 +00001062 int type;
1063 int abr_inv = 0;
1064 struct ospf_area *area;
hasso52dc7ee2004-09-23 19:18:23 +00001065 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001066
1067 /* If OSPF instatnce does not exist, return right now. */
paul020709f2003-04-04 02:44:16 +00001068 ospf = ospf_lookup ();
paul68980082003-03-25 05:07:42 +00001069 if (ospf == NULL)
paul718e3742002-12-13 20:15:29 +00001070 return;
1071
paul718e3742002-12-13 20:15:29 +00001072 /* Update distribute-list, and apply filter. */
hasso01018ce2005-08-05 07:40:15 +00001073 for (type = 0; type <= ZEBRA_ROUTE_MAX; type++)
paul718e3742002-12-13 20:15:29 +00001074 {
paul020709f2003-04-04 02:44:16 +00001075 if (ROUTEMAP (ospf, type) != NULL)
paulcf795c52003-06-19 02:13:25 +00001076 {
1077 /* if route-map is not NULL it may be using this access list */
1078 ospf_distribute_list_update (ospf, type);
1079 continue;
1080 }
1081
hasso01018ce2005-08-05 07:40:15 +00001082 /* There is place for route-map for default-information (ZEBRA_ROUTE_MAX),
1083 * but no distribute list. */
1084 if (type == ZEBRA_ROUTE_MAX)
1085 break;
paul718e3742002-12-13 20:15:29 +00001086
paul020709f2003-04-04 02:44:16 +00001087 if (DISTRIBUTE_NAME (ospf, type))
paulcf795c52003-06-19 02:13:25 +00001088 {
1089 /* Keep old access-list for distribute-list. */
1090 struct access_list *old = DISTRIBUTE_LIST (ospf, type);
1091
1092 /* Update access-list for distribute-list. */
1093 DISTRIBUTE_LIST (ospf, type) =
1094 access_list_lookup (AFI_IP, DISTRIBUTE_NAME (ospf, type));
1095
1096 /* No update for this distribute type. */
1097 if (old == NULL && DISTRIBUTE_LIST (ospf, type) == NULL)
1098 continue;
1099
1100 /* Schedule distribute-list update timer. */
1101 if (DISTRIBUTE_LIST (ospf, type) == NULL ||
1102 strcmp (DISTRIBUTE_NAME (ospf, type), access->name) == 0)
1103 ospf_distribute_list_update (ospf, type);
1104 }
paul718e3742002-12-13 20:15:29 +00001105 }
1106
1107 /* Update Area access-list. */
paul1eb8ef22005-04-07 07:30:20 +00001108 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
1109 {
1110 if (EXPORT_NAME (area))
1111 {
1112 EXPORT_LIST (area) = NULL;
1113 abr_inv++;
1114 }
paul718e3742002-12-13 20:15:29 +00001115
paul1eb8ef22005-04-07 07:30:20 +00001116 if (IMPORT_NAME (area))
1117 {
1118 IMPORT_LIST (area) = NULL;
1119 abr_inv++;
1120 }
1121 }
paul718e3742002-12-13 20:15:29 +00001122
1123 /* Schedule ABR tasks -- this will be changed -- takada. */
paul020709f2003-04-04 02:44:16 +00001124 if (IS_OSPF_ABR (ospf) && abr_inv)
paul68980082003-03-25 05:07:42 +00001125 ospf_schedule_abr_task (ospf);
paul718e3742002-12-13 20:15:29 +00001126}
hassodd669bb2004-05-10 07:43:59 +00001127
1128/* If prefix-list is updated, do some updates. */
1129void
1130ospf_prefix_list_update (struct prefix_list *plist)
1131{
1132 struct ospf *ospf;
1133 int type;
1134 int abr_inv = 0;
1135 struct ospf_area *area;
hasso52dc7ee2004-09-23 19:18:23 +00001136 struct listnode *node;
hassodd669bb2004-05-10 07:43:59 +00001137
1138 /* If OSPF instatnce does not exist, return right now. */
1139 ospf = ospf_lookup ();
1140 if (ospf == NULL)
1141 return;
1142
1143 /* Update all route-maps which are used as redistribution filters.
1144 * They might use prefix-list.
1145 */
hasso01018ce2005-08-05 07:40:15 +00001146 for (type = 0; type <= ZEBRA_ROUTE_MAX; type++)
hassodd669bb2004-05-10 07:43:59 +00001147 {
1148 if (ROUTEMAP (ospf, type) != NULL)
1149 {
1150 /* If route-map is not NULL it may be using this prefix list */
1151 ospf_distribute_list_update (ospf, type);
1152 continue;
1153 }
1154 }
1155
1156 /* Update area filter-lists. */
paul1eb8ef22005-04-07 07:30:20 +00001157 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
1158 {
1159 /* Update filter-list in. */
1160 if (PREFIX_NAME_IN (area))
David Lampartere66cbd12015-04-13 10:21:34 +02001161 if (strcmp (PREFIX_NAME_IN (area), prefix_list_name (plist)) == 0)
paul1eb8ef22005-04-07 07:30:20 +00001162 {
1163 PREFIX_LIST_IN (area) =
1164 prefix_list_lookup (AFI_IP, PREFIX_NAME_IN (area));
1165 abr_inv++;
1166 }
hassodd669bb2004-05-10 07:43:59 +00001167
paul1eb8ef22005-04-07 07:30:20 +00001168 /* Update filter-list out. */
1169 if (PREFIX_NAME_OUT (area))
David Lampartere66cbd12015-04-13 10:21:34 +02001170 if (strcmp (PREFIX_NAME_OUT (area), prefix_list_name (plist)) == 0)
paul1eb8ef22005-04-07 07:30:20 +00001171 {
1172 PREFIX_LIST_IN (area) =
1173 prefix_list_lookup (AFI_IP, PREFIX_NAME_OUT (area));
1174 abr_inv++;
1175 }
1176 }
hassodd669bb2004-05-10 07:43:59 +00001177
1178 /* Schedule ABR task. */
1179 if (IS_OSPF_ABR (ospf) && abr_inv)
1180 ospf_schedule_abr_task (ospf);
1181}
paulcf795c52003-06-19 02:13:25 +00001182
paul4dadc292005-05-06 21:37:42 +00001183static struct ospf_distance *
1184ospf_distance_new (void)
paul718e3742002-12-13 20:15:29 +00001185{
Stephen Hemminger393deb92008-08-18 14:13:29 -07001186 return XCALLOC (MTYPE_OSPF_DISTANCE, sizeof (struct ospf_distance));
paul718e3742002-12-13 20:15:29 +00001187}
1188
paul4dadc292005-05-06 21:37:42 +00001189static void
paul718e3742002-12-13 20:15:29 +00001190ospf_distance_free (struct ospf_distance *odistance)
1191{
1192 XFREE (MTYPE_OSPF_DISTANCE, odistance);
1193}
1194
1195int
paul6c835672004-10-11 11:00:30 +00001196ospf_distance_set (struct vty *vty, struct ospf *ospf,
1197 const char *distance_str,
1198 const char *ip_str,
1199 const char *access_list_str)
paul718e3742002-12-13 20:15:29 +00001200{
1201 int ret;
1202 struct prefix_ipv4 p;
1203 u_char distance;
1204 struct route_node *rn;
1205 struct ospf_distance *odistance;
1206
1207 ret = str2prefix_ipv4 (ip_str, &p);
1208 if (ret == 0)
1209 {
1210 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
1211 return CMD_WARNING;
1212 }
1213
1214 distance = atoi (distance_str);
1215
1216 /* Get OSPF distance node. */
paul68980082003-03-25 05:07:42 +00001217 rn = route_node_get (ospf->distance_table, (struct prefix *) &p);
paul718e3742002-12-13 20:15:29 +00001218 if (rn->info)
1219 {
1220 odistance = rn->info;
1221 route_unlock_node (rn);
1222 }
1223 else
1224 {
1225 odistance = ospf_distance_new ();
1226 rn->info = odistance;
1227 }
1228
1229 /* Set distance value. */
1230 odistance->distance = distance;
1231
1232 /* Reset access-list configuration. */
1233 if (odistance->access_list)
1234 {
1235 free (odistance->access_list);
1236 odistance->access_list = NULL;
1237 }
1238 if (access_list_str)
1239 odistance->access_list = strdup (access_list_str);
1240
1241 return CMD_SUCCESS;
1242}
1243
1244int
paul6c835672004-10-11 11:00:30 +00001245ospf_distance_unset (struct vty *vty, struct ospf *ospf,
1246 const char *distance_str,
1247 const char *ip_str, char
1248 const *access_list_str)
paul718e3742002-12-13 20:15:29 +00001249{
1250 int ret;
1251 struct prefix_ipv4 p;
paul718e3742002-12-13 20:15:29 +00001252 struct route_node *rn;
1253 struct ospf_distance *odistance;
1254
1255 ret = str2prefix_ipv4 (ip_str, &p);
1256 if (ret == 0)
1257 {
1258 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
1259 return CMD_WARNING;
1260 }
1261
paulcf795c52003-06-19 02:13:25 +00001262 rn = route_node_lookup (ospf->distance_table, (struct prefix *) &p);
1263 if (!rn)
paul718e3742002-12-13 20:15:29 +00001264 {
1265 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
1266 return CMD_WARNING;
1267 }
1268
1269 odistance = rn->info;
1270
1271 if (odistance->access_list)
1272 free (odistance->access_list);
1273 ospf_distance_free (odistance);
1274
1275 rn->info = NULL;
1276 route_unlock_node (rn);
1277 route_unlock_node (rn);
1278
1279 return CMD_SUCCESS;
1280}
1281
1282void
paul68980082003-03-25 05:07:42 +00001283ospf_distance_reset (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +00001284{
1285 struct route_node *rn;
1286 struct ospf_distance *odistance;
1287
paul68980082003-03-25 05:07:42 +00001288 for (rn = route_top (ospf->distance_table); rn; rn = route_next (rn))
paul718e3742002-12-13 20:15:29 +00001289 if ((odistance = rn->info) != NULL)
1290 {
paulcf795c52003-06-19 02:13:25 +00001291 if (odistance->access_list)
1292 free (odistance->access_list);
1293 ospf_distance_free (odistance);
1294 rn->info = NULL;
1295 route_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00001296 }
1297}
1298
1299u_char
1300ospf_distance_apply (struct prefix_ipv4 *p, struct ospf_route *or)
1301{
paul020709f2003-04-04 02:44:16 +00001302 struct ospf *ospf;
paul718e3742002-12-13 20:15:29 +00001303
paul020709f2003-04-04 02:44:16 +00001304 ospf = ospf_lookup ();
paul68980082003-03-25 05:07:42 +00001305 if (ospf == NULL)
paul718e3742002-12-13 20:15:29 +00001306 return 0;
1307
paul68980082003-03-25 05:07:42 +00001308 if (ospf->distance_intra)
paul718e3742002-12-13 20:15:29 +00001309 if (or->path_type == OSPF_PATH_INTRA_AREA)
paul68980082003-03-25 05:07:42 +00001310 return ospf->distance_intra;
paul718e3742002-12-13 20:15:29 +00001311
paul68980082003-03-25 05:07:42 +00001312 if (ospf->distance_inter)
paul718e3742002-12-13 20:15:29 +00001313 if (or->path_type == OSPF_PATH_INTER_AREA)
paul68980082003-03-25 05:07:42 +00001314 return ospf->distance_inter;
paul718e3742002-12-13 20:15:29 +00001315
paul68980082003-03-25 05:07:42 +00001316 if (ospf->distance_external)
paul718e3742002-12-13 20:15:29 +00001317 if (or->path_type == OSPF_PATH_TYPE1_EXTERNAL
paulcf795c52003-06-19 02:13:25 +00001318 || or->path_type == OSPF_PATH_TYPE2_EXTERNAL)
paul68980082003-03-25 05:07:42 +00001319 return ospf->distance_external;
paulcf795c52003-06-19 02:13:25 +00001320
paul68980082003-03-25 05:07:42 +00001321 if (ospf->distance_all)
1322 return ospf->distance_all;
paul718e3742002-12-13 20:15:29 +00001323
1324 return 0;
1325}
1326
Feng Luc99f3482014-10-16 09:52:36 +08001327static void
1328ospf_zebra_connected (struct zclient *zclient)
1329{
1330 zclient_send_requests (zclient, VRF_DEFAULT);
1331}
1332
paul718e3742002-12-13 20:15:29 +00001333void
Donald Sharp71252932015-09-24 09:25:19 -04001334ospf_zebra_init (struct thread_master *master)
paul718e3742002-12-13 20:15:29 +00001335{
1336 /* Allocate zebra structure. */
Donald Sharp71252932015-09-24 09:25:19 -04001337 zclient = zclient_new (master);
paul718e3742002-12-13 20:15:29 +00001338 zclient_init (zclient, ZEBRA_ROUTE_OSPF);
Feng Luc99f3482014-10-16 09:52:36 +08001339 zclient->zebra_connected = ospf_zebra_connected;
hasso18a6dce2004-10-03 18:18:34 +00001340 zclient->router_id_update = ospf_router_id_update_zebra;
paul718e3742002-12-13 20:15:29 +00001341 zclient->interface_add = ospf_interface_add;
1342 zclient->interface_delete = ospf_interface_delete;
1343 zclient->interface_up = ospf_interface_state_up;
1344 zclient->interface_down = ospf_interface_state_down;
1345 zclient->interface_address_add = ospf_interface_address_add;
1346 zclient->interface_address_delete = ospf_interface_address_delete;
Olivier Dugeon29a14012016-04-19 18:42:40 +02001347 zclient->interface_link_params = ospf_interface_link_params;
1348
paul718e3742002-12-13 20:15:29 +00001349 zclient->ipv4_route_add = ospf_zebra_read_ipv4;
1350 zclient->ipv4_route_delete = ospf_zebra_read_ipv4;
1351
1352 access_list_add_hook (ospf_filter_update);
1353 access_list_delete_hook (ospf_filter_update);
hassodd669bb2004-05-10 07:43:59 +00001354 prefix_list_add_hook (ospf_prefix_list_update);
1355 prefix_list_delete_hook (ospf_prefix_list_update);
paul718e3742002-12-13 20:15:29 +00001356}