]>
Commit | Line | Data |
---|---|---|
eb5d44eb | 1 | /* |
2 | * IS-IS Rout(e)ing protocol - isis_zebra.c | |
3 | * | |
4 | * Copyright (C) 2001,2002 Sampo Saaristo | |
5 | * Tampere University of Technology | |
6 | * Institute of Communications Engineering | |
7 | * | |
8 | * This program is free software; you can redistribute it and/or modify it | |
9 | * under the terms of the GNU General Public Licenseas published by the Free | |
10 | * Software Foundation; either version 2 of the License, or (at your option) | |
11 | * any later version. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful,but WITHOUT | |
14 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
16 | * more details. | |
17 | ||
18 | * You should have received a copy of the GNU General Public License along | |
19 | * with this program; if not, write to the Free Software Foundation, Inc., | |
20 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
21 | */ | |
22 | ||
23 | #include <zebra.h> | |
eb5d44eb | 24 | |
25 | #include "thread.h" | |
26 | #include "command.h" | |
27 | #include "memory.h" | |
28 | #include "log.h" | |
29 | #include "if.h" | |
30 | #include "network.h" | |
31 | #include "prefix.h" | |
32 | #include "zclient.h" | |
33 | #include "stream.h" | |
34 | #include "linklist.h" | |
35 | ||
36 | #include "isisd/isis_constants.h" | |
37 | #include "isisd/isis_common.h" | |
38 | #include "isisd/isis_circuit.h" | |
39 | #include "isisd/isis_csm.h" | |
40 | #include "isisd/isis_route.h" | |
41 | #include "isisd/isis_zebra.h" | |
42 | ||
43 | struct zclient *zclient = NULL; | |
44 | ||
45 | extern struct thread_master *master; | |
18a6dce6 | 46 | struct in_addr router_id_zebra; |
47 | ||
48 | /* Router-id update message from zebra. */ | |
92365889 | 49 | static int |
18a6dce6 | 50 | isis_router_id_update_zebra (int command, struct zclient *zclient, |
51 | zebra_size_t length) | |
52 | { | |
53 | struct prefix router_id; | |
18a6dce6 | 54 | |
55 | zebra_router_id_update_read (zclient->ibuf,&router_id); | |
56 | router_id_zebra = router_id.u.prefix4; | |
57 | ||
58 | /* FIXME: Do we react somehow? */ | |
59 | return 0; | |
60 | } | |
eb5d44eb | 61 | |
92365889 | 62 | static int |
eb5d44eb | 63 | isis_zebra_if_add (int command, struct zclient *zclient, zebra_size_t length) |
64 | { | |
65 | struct interface *ifp; | |
66 | ||
67 | ifp = zebra_interface_add_read (zclient->ibuf); | |
f390d2c7 | 68 | |
eb5d44eb | 69 | |
529d65b3 | 70 | zlog_debug ("Zebra I/F add: %s index %d flags %ld metric %d mtu %d", |
71 | ifp->name, ifp->ifindex, ifp->flags, ifp->metric, ifp->mtu); | |
f390d2c7 | 72 | |
b30c5e67 | 73 | if (if_is_operative (ifp)) |
eb5d44eb | 74 | isis_csm_state_change (IF_UP_FROM_Z, circuit_scan_by_ifp (ifp), ifp); |
f390d2c7 | 75 | |
eb5d44eb | 76 | return 0; |
77 | } | |
78 | ||
92365889 | 79 | static int |
eb5d44eb | 80 | isis_zebra_if_del (int command, struct zclient *zclient, zebra_size_t length) |
81 | { | |
82 | struct interface *ifp; | |
83 | struct stream *s; | |
84 | ||
85 | s = zclient->ibuf; | |
86 | ifp = zebra_interface_state_read (s); | |
f390d2c7 | 87 | |
eb5d44eb | 88 | if (!ifp) |
89 | return 0; | |
90 | ||
b30c5e67 | 91 | if (if_is_operative (ifp)) |
eb5d44eb | 92 | zlog_warn ("Zebra: got delete of %s, but interface is still up", |
f390d2c7 | 93 | ifp->name); |
eb5d44eb | 94 | |
529d65b3 | 95 | zlog_debug ("Zebra I/F delete: %s index %d flags %ld metric %d mtu %d", |
96 | ifp->name, ifp->ifindex, ifp->flags, ifp->metric, ifp->mtu); | |
eb5d44eb | 97 | |
d2fc8896 | 98 | |
99 | /* Cannot call if_delete because we should retain the pseudo interface | |
100 | in case there is configuration info attached to it. */ | |
101 | if_delete_retain(ifp); | |
f390d2c7 | 102 | |
eb5d44eb | 103 | isis_csm_state_change (IF_DOWN_FROM_Z, circuit_scan_by_ifp (ifp), ifp); |
104 | ||
d2fc8896 | 105 | ifp->ifindex = IFINDEX_INTERNAL; |
106 | ||
eb5d44eb | 107 | return 0; |
108 | } | |
109 | ||
92365889 | 110 | static struct interface * |
eb5d44eb | 111 | zebra_interface_if_lookup (struct stream *s) |
112 | { | |
bd88bf49 | 113 | char ifname_tmp[INTERFACE_NAMSIZ]; |
eb5d44eb | 114 | |
115 | /* Read interface name. */ | |
116 | stream_get (ifname_tmp, s, INTERFACE_NAMSIZ); | |
117 | ||
d2fc8896 | 118 | /* And look it up. */ |
bd88bf49 | 119 | return if_lookup_by_name_len(ifname_tmp, |
120 | strnlen(ifname_tmp, INTERFACE_NAMSIZ)); | |
eb5d44eb | 121 | } |
122 | ||
92365889 | 123 | static int |
f390d2c7 | 124 | isis_zebra_if_state_up (int command, struct zclient *zclient, |
eb5d44eb | 125 | zebra_size_t length) |
126 | { | |
127 | struct interface *ifp; | |
f390d2c7 | 128 | |
eb5d44eb | 129 | ifp = zebra_interface_if_lookup (zclient->ibuf); |
f390d2c7 | 130 | |
eb5d44eb | 131 | if (!ifp) |
132 | return 0; | |
f390d2c7 | 133 | |
b30c5e67 | 134 | if (if_is_operative (ifp)) |
f390d2c7 | 135 | { |
136 | zebra_interface_if_set_value (zclient->ibuf, ifp); | |
4660687a | 137 | /* HT: This is wrong actually. We can't assume that circuit exist |
138 | * if we delete circuit during if_state_down event. Needs rethink. | |
139 | * TODO */ | |
f390d2c7 | 140 | isis_circuit_update_params (circuit_scan_by_ifp (ifp), ifp); |
141 | return 0; | |
142 | } | |
143 | ||
eb5d44eb | 144 | zebra_interface_if_set_value (zclient->ibuf, ifp); |
145 | isis_csm_state_change (IF_UP_FROM_Z, circuit_scan_by_ifp (ifp), ifp); | |
f390d2c7 | 146 | |
eb5d44eb | 147 | return 0; |
148 | } | |
149 | ||
92365889 | 150 | static int |
f390d2c7 | 151 | isis_zebra_if_state_down (int command, struct zclient *zclient, |
eb5d44eb | 152 | zebra_size_t length) |
153 | { | |
154 | struct interface *ifp; | |
f390d2c7 | 155 | |
eb5d44eb | 156 | ifp = zebra_interface_if_lookup (zclient->ibuf); |
f390d2c7 | 157 | |
eb5d44eb | 158 | if (ifp == NULL) |
159 | return 0; | |
f390d2c7 | 160 | |
b30c5e67 | 161 | if (if_is_operative (ifp)) |
f390d2c7 | 162 | { |
163 | zebra_interface_if_set_value (zclient->ibuf, ifp); | |
164 | isis_csm_state_change (IF_DOWN_FROM_Z, circuit_scan_by_ifp (ifp), ifp); | |
165 | } | |
166 | ||
eb5d44eb | 167 | return 0; |
168 | } | |
169 | ||
92365889 | 170 | static int |
f390d2c7 | 171 | isis_zebra_if_address_add (int command, struct zclient *zclient, |
172 | zebra_size_t length) | |
eb5d44eb | 173 | { |
174 | struct connected *c; | |
175 | struct prefix *p; | |
f7c43dcb | 176 | char buf[BUFSIZ]; |
eb5d44eb | 177 | |
f390d2c7 | 178 | c = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_ADD, |
179 | zclient->ibuf); | |
180 | ||
eb5d44eb | 181 | if (c == NULL) |
182 | return 0; | |
f390d2c7 | 183 | |
eb5d44eb | 184 | p = c->address; |
f390d2c7 | 185 | |
eb5d44eb | 186 | prefix2str (p, buf, BUFSIZ); |
187 | #ifdef EXTREME_DEBUG | |
f390d2c7 | 188 | if (p->family == AF_INET) |
529d65b3 | 189 | zlog_debug ("connected IP address %s", buf); |
eb5d44eb | 190 | #ifdef HAVE_IPV6 |
191 | if (p->family == AF_INET6) | |
529d65b3 | 192 | zlog_debug ("connected IPv6 address %s", buf); |
eb5d44eb | 193 | #endif /* HAVE_IPV6 */ |
194 | #endif /* EXTREME_DEBUG */ | |
b30c5e67 | 195 | if (if_is_operative (c->ifp)) |
196 | isis_circuit_add_addr (circuit_scan_by_ifp (c->ifp), c); | |
eb5d44eb | 197 | |
198 | return 0; | |
199 | } | |
200 | ||
92365889 | 201 | static int |
f390d2c7 | 202 | isis_zebra_if_address_del (int command, struct zclient *client, |
203 | zebra_size_t length) | |
eb5d44eb | 204 | { |
205 | struct connected *c; | |
206 | struct interface *ifp; | |
1cd80845 | 207 | #ifdef EXTREME_DEBUG |
f891f443 | 208 | struct prefix *p; |
209 | u_char buf[BUFSIZ]; | |
1cd80845 | 210 | #endif /* EXTREME_DEBUG */ |
eb5d44eb | 211 | |
f390d2c7 | 212 | c = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_DELETE, |
213 | zclient->ibuf); | |
214 | ||
eb5d44eb | 215 | if (c == NULL) |
216 | return 0; | |
f390d2c7 | 217 | |
eb5d44eb | 218 | ifp = c->ifp; |
f390d2c7 | 219 | |
f891f443 | 220 | #ifdef EXTREME_DEBUG |
221 | p = c->address; | |
222 | prefix2str (p, buf, BUFSIZ); | |
223 | ||
224 | if (p->family == AF_INET) | |
529d65b3 | 225 | zlog_debug ("disconnected IP address %s", buf); |
f891f443 | 226 | #ifdef HAVE_IPV6 |
227 | if (p->family == AF_INET6) | |
529d65b3 | 228 | zlog_debug ("disconnected IPv6 address %s", buf); |
f891f443 | 229 | #endif /* HAVE_IPV6 */ |
230 | #endif /* EXTREME_DEBUG */ | |
f390d2c7 | 231 | |
b30c5e67 | 232 | if (if_is_operative (ifp)) |
233 | isis_circuit_del_addr (circuit_scan_by_ifp (ifp), c); | |
f891f443 | 234 | connected_free (c); |
f390d2c7 | 235 | |
eb5d44eb | 236 | return 0; |
237 | } | |
238 | ||
92365889 | 239 | static void |
f390d2c7 | 240 | isis_zebra_route_add_ipv4 (struct prefix *prefix, |
241 | struct isis_route_info *route_info) | |
eb5d44eb | 242 | { |
243 | u_char message, flags; | |
244 | int psize; | |
245 | struct stream *stream; | |
246 | struct isis_nexthop *nexthop; | |
247 | struct listnode *node; | |
248 | ||
249 | if (CHECK_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNC)) | |
250 | return; | |
251 | ||
f390d2c7 | 252 | if (zclient->redist[ZEBRA_ROUTE_ISIS]) |
253 | { | |
254 | message = 0; | |
255 | flags = 0; | |
256 | ||
257 | SET_FLAG (message, ZAPI_MESSAGE_NEXTHOP); | |
258 | SET_FLAG (message, ZAPI_MESSAGE_METRIC); | |
2097cd8a | 259 | #if 0 |
f390d2c7 | 260 | SET_FLAG (message, ZAPI_MESSAGE_DISTANCE); |
2097cd8a | 261 | #endif |
f390d2c7 | 262 | |
263 | stream = zclient->obuf; | |
264 | stream_reset (stream); | |
265 | /* Length place holder. */ | |
266 | stream_putw (stream, 0); | |
267 | /* command */ | |
268 | stream_putc (stream, ZEBRA_IPV4_ROUTE_ADD); | |
269 | /* type */ | |
270 | stream_putc (stream, ZEBRA_ROUTE_ISIS); | |
271 | /* flags */ | |
272 | stream_putc (stream, flags); | |
273 | /* message */ | |
274 | stream_putc (stream, message); | |
275 | /* prefix information */ | |
276 | psize = PSIZE (prefix->prefixlen); | |
277 | stream_putc (stream, prefix->prefixlen); | |
278 | stream_write (stream, (u_char *) & prefix->u.prefix4, psize); | |
279 | ||
280 | stream_putc (stream, listcount (route_info->nexthops)); | |
281 | ||
282 | /* Nexthop, ifindex, distance and metric information */ | |
1eb8ef25 | 283 | for (ALL_LIST_ELEMENTS_RO (route_info->nexthops, node, nexthop)) |
f390d2c7 | 284 | { |
f390d2c7 | 285 | /* FIXME: can it be ? */ |
286 | if (nexthop->ip.s_addr != INADDR_ANY) | |
287 | { | |
288 | stream_putc (stream, ZEBRA_NEXTHOP_IPV4); | |
289 | stream_put_in_addr (stream, &nexthop->ip); | |
290 | } | |
291 | else | |
292 | { | |
293 | stream_putc (stream, ZEBRA_NEXTHOP_IFINDEX); | |
294 | stream_putl (stream, nexthop->ifindex); | |
295 | } | |
296 | } | |
2097cd8a | 297 | #if 0 |
f390d2c7 | 298 | if (CHECK_FLAG (message, ZAPI_MESSAGE_DISTANCE)) |
299 | stream_putc (stream, route_info->depth); | |
2097cd8a | 300 | #endif |
f390d2c7 | 301 | if (CHECK_FLAG (message, ZAPI_MESSAGE_METRIC)) |
302 | stream_putl (stream, route_info->cost); | |
303 | ||
304 | stream_putw_at (stream, 0, stream_get_endp (stream)); | |
634f9ea2 | 305 | zclient_send_message(zclient); |
f390d2c7 | 306 | } |
eb5d44eb | 307 | } |
308 | ||
92365889 | 309 | static void |
f390d2c7 | 310 | isis_zebra_route_del_ipv4 (struct prefix *prefix, |
311 | struct isis_route_info *route_info) | |
eb5d44eb | 312 | { |
313 | struct zapi_ipv4 api; | |
314 | struct prefix_ipv4 prefix4; | |
f390d2c7 | 315 | |
316 | if (zclient->redist[ZEBRA_ROUTE_ISIS]) | |
317 | { | |
318 | api.type = ZEBRA_ROUTE_ISIS; | |
319 | api.flags = 0; | |
320 | api.message = 0; | |
321 | prefix4.family = AF_INET; | |
322 | prefix4.prefixlen = prefix->prefixlen; | |
323 | prefix4.prefix = prefix->u.prefix4; | |
324 | zapi_ipv4_route (ZEBRA_IPV4_ROUTE_DELETE, zclient, &prefix4, &api); | |
325 | } | |
326 | ||
eb5d44eb | 327 | return; |
328 | } | |
329 | ||
330 | #ifdef HAVE_IPV6 | |
331 | void | |
332 | isis_zebra_route_add_ipv6 (struct prefix *prefix, | |
f390d2c7 | 333 | struct isis_route_info *route_info) |
eb5d44eb | 334 | { |
335 | struct zapi_ipv6 api; | |
336 | struct in6_addr **nexthop_list; | |
337 | unsigned int *ifindex_list; | |
338 | struct isis_nexthop6 *nexthop6; | |
339 | int i, size; | |
340 | struct listnode *node; | |
341 | struct prefix_ipv6 prefix6; | |
342 | ||
343 | if (CHECK_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNC)) | |
344 | return; | |
f390d2c7 | 345 | |
eb5d44eb | 346 | api.type = ZEBRA_ROUTE_ISIS; |
347 | api.flags = 0; | |
348 | api.message = 0; | |
349 | SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP); | |
350 | SET_FLAG (api.message, ZAPI_MESSAGE_IFINDEX); | |
351 | SET_FLAG (api.message, ZAPI_MESSAGE_METRIC); | |
352 | api.metric = route_info->cost; | |
353 | #if 0 | |
354 | SET_FLAG (api.message, ZAPI_MESSAGE_DISTANCE); | |
355 | api.distance = route_info->depth; | |
356 | #endif | |
357 | api.nexthop_num = listcount (route_info->nexthops6); | |
358 | api.ifindex_num = listcount (route_info->nexthops6); | |
f390d2c7 | 359 | |
eb5d44eb | 360 | /* allocate memory for nexthop_list */ |
361 | size = sizeof (struct isis_nexthop6 *) * listcount (route_info->nexthops6); | |
362 | nexthop_list = (struct in6_addr **) XMALLOC (MTYPE_ISIS_TMP, size); | |
f390d2c7 | 363 | if (!nexthop_list) |
364 | { | |
365 | zlog_err ("isis_zebra_add_route_ipv6: out of memory!"); | |
366 | return; | |
367 | } | |
368 | ||
eb5d44eb | 369 | /* allocate memory for ifindex_list */ |
370 | size = sizeof (unsigned int) * listcount (route_info->nexthops6); | |
371 | ifindex_list = (unsigned int *) XMALLOC (MTYPE_ISIS_TMP, size); | |
f390d2c7 | 372 | if (!ifindex_list) |
373 | { | |
374 | zlog_err ("isis_zebra_add_route_ipv6: out of memory!"); | |
375 | XFREE (MTYPE_ISIS_TMP, nexthop_list); | |
376 | return; | |
377 | } | |
378 | ||
eb5d44eb | 379 | /* for each nexthop */ |
380 | i = 0; | |
1eb8ef25 | 381 | for (ALL_LIST_ELEMENTS_RO (route_info->nexthops6, node, nexthop6)) |
f390d2c7 | 382 | { |
f390d2c7 | 383 | if (!IN6_IS_ADDR_LINKLOCAL (&nexthop6->ip6) && |
384 | !IN6_IS_ADDR_UNSPECIFIED (&nexthop6->ip6)) | |
385 | { | |
386 | api.nexthop_num--; | |
387 | api.ifindex_num--; | |
388 | continue; | |
389 | } | |
390 | ||
391 | nexthop_list[i] = &nexthop6->ip6; | |
392 | ifindex_list[i] = nexthop6->ifindex; | |
393 | i++; | |
eb5d44eb | 394 | } |
f390d2c7 | 395 | |
eb5d44eb | 396 | api.nexthop = nexthop_list; |
397 | api.ifindex = ifindex_list; | |
f390d2c7 | 398 | |
399 | if (api.nexthop_num && api.ifindex_num) | |
400 | { | |
401 | prefix6.family = AF_INET6; | |
402 | prefix6.prefixlen = prefix->prefixlen; | |
403 | memcpy (&prefix6.prefix, &prefix->u.prefix6, sizeof (struct in6_addr)); | |
404 | zapi_ipv6_route (ZEBRA_IPV6_ROUTE_ADD, zclient, &prefix6, &api); | |
405 | SET_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNC); | |
406 | } | |
407 | ||
eb5d44eb | 408 | XFREE (MTYPE_ISIS_TMP, nexthop_list); |
409 | XFREE (MTYPE_ISIS_TMP, ifindex_list); | |
f390d2c7 | 410 | |
eb5d44eb | 411 | return; |
412 | } | |
413 | ||
92365889 | 414 | static void |
f390d2c7 | 415 | isis_zebra_route_del_ipv6 (struct prefix *prefix, |
416 | struct isis_route_info *route_info) | |
eb5d44eb | 417 | { |
418 | struct zapi_ipv6 api; | |
419 | struct in6_addr **nexthop_list; | |
420 | unsigned int *ifindex_list; | |
421 | struct isis_nexthop6 *nexthop6; | |
422 | int i, size; | |
423 | struct listnode *node; | |
424 | struct prefix_ipv6 prefix6; | |
425 | ||
426 | if (CHECK_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNC)) | |
427 | return; | |
f390d2c7 | 428 | |
eb5d44eb | 429 | api.type = ZEBRA_ROUTE_ISIS; |
430 | api.flags = 0; | |
431 | api.message = 0; | |
432 | SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP); | |
433 | SET_FLAG (api.message, ZAPI_MESSAGE_IFINDEX); | |
434 | api.nexthop_num = listcount (route_info->nexthops6); | |
435 | api.ifindex_num = listcount (route_info->nexthops6); | |
f390d2c7 | 436 | |
eb5d44eb | 437 | /* allocate memory for nexthop_list */ |
438 | size = sizeof (struct isis_nexthop6 *) * listcount (route_info->nexthops6); | |
439 | nexthop_list = (struct in6_addr **) XMALLOC (MTYPE_ISIS_TMP, size); | |
f390d2c7 | 440 | if (!nexthop_list) |
441 | { | |
442 | zlog_err ("isis_zebra_route_del_ipv6: out of memory!"); | |
443 | return; | |
444 | } | |
445 | ||
eb5d44eb | 446 | /* allocate memory for ifindex_list */ |
447 | size = sizeof (unsigned int) * listcount (route_info->nexthops6); | |
448 | ifindex_list = (unsigned int *) XMALLOC (MTYPE_ISIS_TMP, size); | |
f390d2c7 | 449 | if (!ifindex_list) |
450 | { | |
451 | zlog_err ("isis_zebra_route_del_ipv6: out of memory!"); | |
452 | XFREE (MTYPE_ISIS_TMP, nexthop_list); | |
453 | return; | |
454 | } | |
455 | ||
eb5d44eb | 456 | /* for each nexthop */ |
457 | i = 0; | |
1eb8ef25 | 458 | for (ALL_LIST_ELEMENTS_RO (route_info->nexthops6, node, nexthop6)) |
f390d2c7 | 459 | { |
f390d2c7 | 460 | if (!IN6_IS_ADDR_LINKLOCAL (&nexthop6->ip6) && |
461 | !IN6_IS_ADDR_UNSPECIFIED (&nexthop6->ip6)) | |
462 | { | |
463 | api.nexthop_num--; | |
464 | api.ifindex_num--; | |
465 | continue; | |
466 | } | |
467 | ||
468 | nexthop_list[i] = &nexthop6->ip6; | |
469 | ifindex_list[i] = nexthop6->ifindex; | |
470 | i++; | |
eb5d44eb | 471 | } |
f390d2c7 | 472 | |
eb5d44eb | 473 | api.nexthop = nexthop_list; |
474 | api.ifindex = ifindex_list; | |
f390d2c7 | 475 | |
476 | if (api.nexthop_num && api.ifindex_num) | |
477 | { | |
478 | prefix6.family = AF_INET6; | |
479 | prefix6.prefixlen = prefix->prefixlen; | |
480 | memcpy (&prefix6.prefix, &prefix->u.prefix6, sizeof (struct in6_addr)); | |
481 | zapi_ipv6_route (ZEBRA_IPV6_ROUTE_DELETE, zclient, &prefix6, &api); | |
482 | UNSET_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNC); | |
483 | } | |
484 | ||
eb5d44eb | 485 | XFREE (MTYPE_ISIS_TMP, nexthop_list); |
f390d2c7 | 486 | XFREE (MTYPE_ISIS_TMP, ifindex_list); |
eb5d44eb | 487 | } |
488 | ||
eb5d44eb | 489 | #endif /* HAVE_IPV6 */ |
490 | ||
eb5d44eb | 491 | void |
492 | isis_zebra_route_update (struct prefix *prefix, | |
f390d2c7 | 493 | struct isis_route_info *route_info) |
eb5d44eb | 494 | { |
495 | if (zclient->sock < 0) | |
496 | return; | |
497 | ||
498 | if (!zclient->redist[ZEBRA_ROUTE_ISIS]) | |
499 | return; | |
500 | ||
f390d2c7 | 501 | if (CHECK_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ACTIVE)) |
502 | { | |
503 | if (prefix->family == AF_INET) | |
504 | isis_zebra_route_add_ipv4 (prefix, route_info); | |
eb5d44eb | 505 | #ifdef HAVE_IPV6 |
f390d2c7 | 506 | else if (prefix->family == AF_INET6) |
507 | isis_zebra_route_add_ipv6 (prefix, route_info); | |
eb5d44eb | 508 | #endif /* HAVE_IPV6 */ |
f390d2c7 | 509 | } |
510 | else | |
511 | { | |
512 | if (prefix->family == AF_INET) | |
513 | isis_zebra_route_del_ipv4 (prefix, route_info); | |
eb5d44eb | 514 | #ifdef HAVE_IPV6 |
f390d2c7 | 515 | else if (prefix->family == AF_INET6) |
516 | isis_zebra_route_del_ipv6 (prefix, route_info); | |
eb5d44eb | 517 | #endif /* HAVE_IPV6 */ |
f390d2c7 | 518 | } |
eb5d44eb | 519 | return; |
520 | } | |
521 | ||
92365889 | 522 | static int |
f390d2c7 | 523 | isis_zebra_read_ipv4 (int command, struct zclient *zclient, |
eb5d44eb | 524 | zebra_size_t length) |
525 | { | |
526 | struct stream *stream; | |
527 | struct zapi_ipv4 api; | |
528 | struct prefix_ipv4 p; | |
529 | unsigned long ifindex; | |
530 | struct in_addr nexthop; | |
531 | ||
532 | stream = zclient->ibuf; | |
533 | memset (&p, 0, sizeof (struct prefix_ipv4)); | |
534 | ifindex = 0; | |
535 | ||
f390d2c7 | 536 | api.type = stream_getc (stream); |
537 | api.flags = stream_getc (stream); | |
eb5d44eb | 538 | api.message = stream_getc (stream); |
539 | ||
540 | p.family = AF_INET; | |
541 | p.prefixlen = stream_getc (stream); | |
542 | stream_get (&p.prefix, stream, PSIZE (p.prefixlen)); | |
f390d2c7 | 543 | |
544 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP)) | |
545 | { | |
eb5d44eb | 546 | api.nexthop_num = stream_getc (stream); |
547 | nexthop.s_addr = stream_get_ipv4 (stream); | |
f390d2c7 | 548 | } |
549 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_IFINDEX)) | |
550 | { | |
551 | api.ifindex_num = stream_getc (stream); | |
552 | ifindex = stream_getl (stream); | |
553 | } | |
eb5d44eb | 554 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE)) |
555 | api.distance = stream_getc (stream); | |
556 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC)) | |
557 | api.metric = stream_getl (stream); | |
558 | else | |
559 | api.metric = 0; | |
f390d2c7 | 560 | |
561 | if (command == ZEBRA_IPV4_ROUTE_ADD) | |
562 | { | |
529d65b3 | 563 | zlog_debug ("IPv4 Route add from Z"); |
f390d2c7 | 564 | } |
eb5d44eb | 565 | |
566 | return 0; | |
567 | } | |
568 | ||
92365889 | 569 | static int |
f390d2c7 | 570 | isis_zebra_read_ipv6 (int command, struct zclient *zclient, |
eb5d44eb | 571 | zebra_size_t length) |
572 | { | |
eb5d44eb | 573 | return 0; |
574 | } | |
575 | ||
576 | #define ISIS_TYPE_IS_REDISTRIBUTED(T) \ | |
577 | T == ZEBRA_ROUTE_MAX ? zclient->default_information : zclient->redist[type] | |
578 | ||
579 | int | |
580 | isis_distribute_list_update (int routetype) | |
581 | { | |
582 | return 0; | |
583 | } | |
584 | ||
92365889 | 585 | #if 0 /* Not yet. */ |
586 | static int | |
f390d2c7 | 587 | isis_redistribute_default_set (int routetype, int metric_type, |
588 | int metric_value) | |
eb5d44eb | 589 | { |
590 | return 0; | |
591 | } | |
92365889 | 592 | #endif /* 0 */ |
eb5d44eb | 593 | |
eb5d44eb | 594 | void |
595 | isis_zebra_init () | |
596 | { | |
eb5d44eb | 597 | zclient = zclient_new (); |
598 | zclient_init (zclient, ZEBRA_ROUTE_ISIS); | |
18a6dce6 | 599 | zclient->router_id_update = isis_router_id_update_zebra; |
eb5d44eb | 600 | zclient->interface_add = isis_zebra_if_add; |
601 | zclient->interface_delete = isis_zebra_if_del; | |
602 | zclient->interface_up = isis_zebra_if_state_up; | |
603 | zclient->interface_down = isis_zebra_if_state_down; | |
604 | zclient->interface_address_add = isis_zebra_if_address_add; | |
605 | zclient->interface_address_delete = isis_zebra_if_address_del; | |
606 | zclient->ipv4_route_add = isis_zebra_read_ipv4; | |
607 | zclient->ipv4_route_delete = isis_zebra_read_ipv4; | |
608 | #ifdef HAVE_IPV6 | |
609 | zclient->ipv6_route_add = isis_zebra_read_ipv6; | |
610 | zclient->ipv6_route_delete = isis_zebra_read_ipv6; | |
611 | #endif /* HAVE_IPV6 */ | |
612 | ||
613 | return; | |
614 | } |