]>
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 | |
f3ccedaa | 7 | * Copyright (C) 2013-2015 Christian Franke <chris@opensourcerouting.org> |
eb5d44eb | 8 | * |
9 | * This program is free software; you can redistribute it and/or modify it | |
10 | * under the terms of the GNU General Public Licenseas published by the Free | |
11 | * Software Foundation; either version 2 of the License, or (at your option) | |
12 | * any later version. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful,but WITHOUT | |
15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
17 | * more details. | |
896014f4 DL |
18 | * |
19 | * You should have received a copy of the GNU General Public License along | |
20 | * with this program; see the file COPYING; if not, write to the Free Software | |
21 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
eb5d44eb | 22 | */ |
23 | ||
24 | #include <zebra.h> | |
eb5d44eb | 25 | |
26 | #include "thread.h" | |
27 | #include "command.h" | |
28 | #include "memory.h" | |
29 | #include "log.h" | |
30 | #include "if.h" | |
31 | #include "network.h" | |
32 | #include "prefix.h" | |
33 | #include "zclient.h" | |
34 | #include "stream.h" | |
35 | #include "linklist.h" | |
f3ccedaa | 36 | #include "nexthop.h" |
7076bb2f | 37 | #include "vrf.h" |
eb5d44eb | 38 | |
c89c05dd | 39 | #include "isisd/dict.h" |
eb5d44eb | 40 | #include "isisd/isis_constants.h" |
41 | #include "isisd/isis_common.h" | |
3f045a08 JB |
42 | #include "isisd/isis_flags.h" |
43 | #include "isisd/isis_misc.h" | |
44 | #include "isisd/isis_circuit.h" | |
45 | #include "isisd/isis_tlv.h" | |
c89c05dd | 46 | #include "isisd/isisd.h" |
eb5d44eb | 47 | #include "isisd/isis_circuit.h" |
48 | #include "isisd/isis_csm.h" | |
3f045a08 | 49 | #include "isisd/isis_lsp.h" |
eb5d44eb | 50 | #include "isisd/isis_route.h" |
51 | #include "isisd/isis_zebra.h" | |
f8c06e2c | 52 | #include "isisd/isis_te.h" |
eb5d44eb | 53 | |
54 | struct zclient *zclient = NULL; | |
55 | ||
18a6dce6 | 56 | /* Router-id update message from zebra. */ |
92365889 | 57 | static int |
18a6dce6 | 58 | isis_router_id_update_zebra (int command, struct zclient *zclient, |
7076bb2f | 59 | zebra_size_t length, vrf_id_t vrf_id) |
18a6dce6 | 60 | { |
3f045a08 JB |
61 | struct isis_area *area; |
62 | struct listnode *node; | |
18a6dce6 | 63 | struct prefix router_id; |
18a6dce6 | 64 | |
f8c06e2c OD |
65 | /* |
66 | * If ISIS TE is enable, TE Router ID is set through specific command. | |
67 | * See mpls_te_router_addr() command in isis_te.c | |
68 | */ | |
69 | if (IS_MPLS_TE(isisMplsTE)) | |
70 | return 0; | |
71 | ||
3f045a08 JB |
72 | zebra_router_id_update_read (zclient->ibuf, &router_id); |
73 | if (isis->router_id == router_id.u.prefix4.s_addr) | |
74 | return 0; | |
75 | ||
76 | isis->router_id = router_id.u.prefix4.s_addr; | |
77 | for (ALL_LIST_ELEMENTS_RO (isis->area_list, node, area)) | |
78 | if (listcount (area->area_addrs) > 0) | |
79 | lsp_regenerate_schedule (area, area->is_type, 0); | |
18a6dce6 | 80 | |
18a6dce6 | 81 | return 0; |
82 | } | |
eb5d44eb | 83 | |
92365889 | 84 | static int |
7076bb2f FL |
85 | isis_zebra_if_add (int command, struct zclient *zclient, zebra_size_t length, |
86 | vrf_id_t vrf_id) | |
eb5d44eb | 87 | { |
88 | struct interface *ifp; | |
89 | ||
7076bb2f | 90 | ifp = zebra_interface_add_read (zclient->ibuf, vrf_id); |
f390d2c7 | 91 | |
c89c05dd | 92 | if (isis->debugs & DEBUG_ZEBRA) |
93 | zlog_debug ("Zebra I/F add: %s index %d flags %ld metric %d mtu %d", | |
41b36e90 | 94 | ifp->name, ifp->ifindex, (long)ifp->flags, ifp->metric, ifp->mtu); |
f390d2c7 | 95 | |
b30c5e67 | 96 | if (if_is_operative (ifp)) |
eb5d44eb | 97 | isis_csm_state_change (IF_UP_FROM_Z, circuit_scan_by_ifp (ifp), ifp); |
f390d2c7 | 98 | |
eb5d44eb | 99 | return 0; |
100 | } | |
101 | ||
92365889 | 102 | static int |
7076bb2f FL |
103 | isis_zebra_if_del (int command, struct zclient *zclient, zebra_size_t length, |
104 | vrf_id_t vrf_id) | |
eb5d44eb | 105 | { |
106 | struct interface *ifp; | |
107 | struct stream *s; | |
108 | ||
109 | s = zclient->ibuf; | |
7076bb2f | 110 | ifp = zebra_interface_state_read (s, vrf_id); |
f390d2c7 | 111 | |
eb5d44eb | 112 | if (!ifp) |
113 | return 0; | |
114 | ||
b30c5e67 | 115 | if (if_is_operative (ifp)) |
eb5d44eb | 116 | zlog_warn ("Zebra: got delete of %s, but interface is still up", |
f390d2c7 | 117 | ifp->name); |
eb5d44eb | 118 | |
c89c05dd | 119 | if (isis->debugs & DEBUG_ZEBRA) |
120 | zlog_debug ("Zebra I/F delete: %s index %d flags %ld metric %d mtu %d", | |
41b36e90 | 121 | ifp->name, ifp->ifindex, (long)ifp->flags, ifp->metric, ifp->mtu); |
eb5d44eb | 122 | |
3f045a08 | 123 | isis_csm_state_change (IF_DOWN_FROM_Z, circuit_scan_by_ifp (ifp), ifp); |
d2fc8896 | 124 | |
125 | /* Cannot call if_delete because we should retain the pseudo interface | |
126 | in case there is configuration info attached to it. */ | |
127 | if_delete_retain(ifp); | |
f390d2c7 | 128 | |
84361d61 | 129 | ifp->ifindex = IFINDEX_DELETED; |
d2fc8896 | 130 | |
eb5d44eb | 131 | return 0; |
132 | } | |
133 | ||
92365889 | 134 | static int |
f390d2c7 | 135 | isis_zebra_if_state_up (int command, struct zclient *zclient, |
7076bb2f | 136 | zebra_size_t length, vrf_id_t vrf_id) |
eb5d44eb | 137 | { |
138 | struct interface *ifp; | |
f390d2c7 | 139 | |
7076bb2f | 140 | ifp = zebra_interface_state_read (zclient->ibuf, vrf_id); |
f390d2c7 | 141 | |
3f045a08 | 142 | if (ifp == NULL) |
eb5d44eb | 143 | return 0; |
f390d2c7 | 144 | |
eb5d44eb | 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, |
7076bb2f | 152 | zebra_size_t length, vrf_id_t vrf_id) |
eb5d44eb | 153 | { |
154 | struct interface *ifp; | |
3f045a08 | 155 | struct isis_circuit *circuit; |
f390d2c7 | 156 | |
7076bb2f | 157 | ifp = zebra_interface_state_read (zclient->ibuf, vrf_id); |
f390d2c7 | 158 | |
eb5d44eb | 159 | if (ifp == NULL) |
160 | return 0; | |
f390d2c7 | 161 | |
3f045a08 JB |
162 | circuit = isis_csm_state_change (IF_DOWN_FROM_Z, circuit_scan_by_ifp (ifp), |
163 | ifp); | |
164 | if (circuit) | |
165 | SET_FLAG(circuit->flags, ISIS_CIRCUIT_FLAPPED_AFTER_SPF); | |
f390d2c7 | 166 | |
eb5d44eb | 167 | return 0; |
168 | } | |
169 | ||
92365889 | 170 | static int |
f390d2c7 | 171 | isis_zebra_if_address_add (int command, struct zclient *zclient, |
7076bb2f | 172 | zebra_size_t length, vrf_id_t vrf_id) |
eb5d44eb | 173 | { |
174 | struct connected *c; | |
175 | struct prefix *p; | |
4690c7d7 | 176 | char buf[PREFIX2STR_BUFFER]; |
eb5d44eb | 177 | |
f390d2c7 | 178 | c = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_ADD, |
7076bb2f | 179 | zclient->ibuf, vrf_id); |
f390d2c7 | 180 | |
eb5d44eb | 181 | if (c == NULL) |
182 | return 0; | |
f390d2c7 | 183 | |
eb5d44eb | 184 | p = c->address; |
f390d2c7 | 185 | |
4690c7d7 | 186 | prefix2str (p, buf, sizeof (buf)); |
eb5d44eb | 187 | #ifdef EXTREME_DEBUG |
f390d2c7 | 188 | if (p->family == AF_INET) |
529d65b3 | 189 | zlog_debug ("connected IP address %s", buf); |
eb5d44eb | 190 | if (p->family == AF_INET6) |
529d65b3 | 191 | zlog_debug ("connected IPv6 address %s", buf); |
eb5d44eb | 192 | #endif /* EXTREME_DEBUG */ |
b30c5e67 | 193 | if (if_is_operative (c->ifp)) |
194 | isis_circuit_add_addr (circuit_scan_by_ifp (c->ifp), c); | |
eb5d44eb | 195 | |
196 | return 0; | |
197 | } | |
198 | ||
92365889 | 199 | static int |
f390d2c7 | 200 | isis_zebra_if_address_del (int command, struct zclient *client, |
7076bb2f | 201 | zebra_size_t length, vrf_id_t vrf_id) |
eb5d44eb | 202 | { |
203 | struct connected *c; | |
204 | struct interface *ifp; | |
1cd80845 | 205 | #ifdef EXTREME_DEBUG |
f891f443 | 206 | struct prefix *p; |
4690c7d7 | 207 | char buf[PREFIX2STR_BUFFER]; |
1cd80845 | 208 | #endif /* EXTREME_DEBUG */ |
eb5d44eb | 209 | |
f390d2c7 | 210 | c = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_DELETE, |
7076bb2f | 211 | zclient->ibuf, vrf_id); |
f390d2c7 | 212 | |
eb5d44eb | 213 | if (c == NULL) |
214 | return 0; | |
f390d2c7 | 215 | |
eb5d44eb | 216 | ifp = c->ifp; |
f390d2c7 | 217 | |
f891f443 | 218 | #ifdef EXTREME_DEBUG |
219 | p = c->address; | |
4690c7d7 | 220 | prefix2str (p, buf, sizeof (buf)); |
f891f443 | 221 | |
222 | if (p->family == AF_INET) | |
529d65b3 | 223 | zlog_debug ("disconnected IP address %s", buf); |
f891f443 | 224 | if (p->family == AF_INET6) |
529d65b3 | 225 | zlog_debug ("disconnected IPv6 address %s", buf); |
f891f443 | 226 | #endif /* EXTREME_DEBUG */ |
f390d2c7 | 227 | |
b30c5e67 | 228 | if (if_is_operative (ifp)) |
229 | isis_circuit_del_addr (circuit_scan_by_ifp (ifp), c); | |
f891f443 | 230 | connected_free (c); |
f390d2c7 | 231 | |
eb5d44eb | 232 | return 0; |
233 | } | |
234 | ||
f8c06e2c OD |
235 | static int |
236 | isis_zebra_link_params (int command, struct zclient *zclient, | |
237 | zebra_size_t length) | |
238 | { | |
239 | struct interface *ifp; | |
240 | ||
241 | ifp = zebra_interface_link_params_read (zclient->ibuf); | |
242 | ||
243 | if (ifp == NULL) | |
244 | return 0; | |
245 | ||
246 | /* Update TE TLV */ | |
247 | isis_mpls_te_update(ifp); | |
248 | ||
249 | return 0; | |
250 | } | |
251 | ||
92365889 | 252 | static void |
f390d2c7 | 253 | isis_zebra_route_add_ipv4 (struct prefix *prefix, |
254 | struct isis_route_info *route_info) | |
eb5d44eb | 255 | { |
0fc452dc CF |
256 | u_char message; |
257 | u_int32_t flags; | |
eb5d44eb | 258 | int psize; |
259 | struct stream *stream; | |
260 | struct isis_nexthop *nexthop; | |
261 | struct listnode *node; | |
262 | ||
3f045a08 | 263 | if (CHECK_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED)) |
eb5d44eb | 264 | return; |
265 | ||
7076bb2f | 266 | if (vrf_bitmap_check (zclient->redist[AFI_IP][ZEBRA_ROUTE_ISIS], VRF_DEFAULT)) |
f390d2c7 | 267 | { |
268 | message = 0; | |
269 | flags = 0; | |
270 | ||
271 | SET_FLAG (message, ZAPI_MESSAGE_NEXTHOP); | |
272 | SET_FLAG (message, ZAPI_MESSAGE_METRIC); | |
2097cd8a | 273 | #if 0 |
f390d2c7 | 274 | SET_FLAG (message, ZAPI_MESSAGE_DISTANCE); |
2097cd8a | 275 | #endif |
f390d2c7 | 276 | |
277 | stream = zclient->obuf; | |
278 | stream_reset (stream); | |
7076bb2f | 279 | zclient_create_header (stream, ZEBRA_IPV4_ROUTE_ADD, VRF_DEFAULT); |
f390d2c7 | 280 | /* type */ |
281 | stream_putc (stream, ZEBRA_ROUTE_ISIS); | |
7c8ff89e DS |
282 | /* instance */ |
283 | stream_putw (stream, 0); | |
f390d2c7 | 284 | /* flags */ |
0fc452dc | 285 | stream_putl (stream, flags); |
f390d2c7 | 286 | /* message */ |
287 | stream_putc (stream, message); | |
aa3b2642 AS |
288 | /* SAFI */ |
289 | stream_putw (stream, SAFI_UNICAST); | |
f390d2c7 | 290 | /* prefix information */ |
291 | psize = PSIZE (prefix->prefixlen); | |
292 | stream_putc (stream, prefix->prefixlen); | |
293 | stream_write (stream, (u_char *) & prefix->u.prefix4, psize); | |
294 | ||
295 | stream_putc (stream, listcount (route_info->nexthops)); | |
296 | ||
297 | /* Nexthop, ifindex, distance and metric information */ | |
1eb8ef25 | 298 | for (ALL_LIST_ELEMENTS_RO (route_info->nexthops, node, nexthop)) |
f390d2c7 | 299 | { |
f390d2c7 | 300 | /* FIXME: can it be ? */ |
301 | if (nexthop->ip.s_addr != INADDR_ANY) | |
302 | { | |
481f1484 | 303 | stream_putc (stream, NEXTHOP_TYPE_IPV4_IFINDEX); |
f390d2c7 | 304 | stream_put_in_addr (stream, &nexthop->ip); |
481f1484 | 305 | stream_putl (stream, nexthop->ifindex); |
f390d2c7 | 306 | } |
307 | else | |
308 | { | |
5b30316e | 309 | stream_putc (stream, NEXTHOP_TYPE_IFINDEX); |
f390d2c7 | 310 | stream_putl (stream, nexthop->ifindex); |
311 | } | |
312 | } | |
2097cd8a | 313 | #if 0 |
f390d2c7 | 314 | if (CHECK_FLAG (message, ZAPI_MESSAGE_DISTANCE)) |
315 | stream_putc (stream, route_info->depth); | |
2097cd8a | 316 | #endif |
f390d2c7 | 317 | if (CHECK_FLAG (message, ZAPI_MESSAGE_METRIC)) |
318 | stream_putl (stream, route_info->cost); | |
319 | ||
320 | stream_putw_at (stream, 0, stream_get_endp (stream)); | |
634f9ea2 | 321 | zclient_send_message(zclient); |
3f045a08 JB |
322 | SET_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED); |
323 | UNSET_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_RESYNC); | |
f390d2c7 | 324 | } |
eb5d44eb | 325 | } |
326 | ||
92365889 | 327 | static void |
f390d2c7 | 328 | isis_zebra_route_del_ipv4 (struct prefix *prefix, |
329 | struct isis_route_info *route_info) | |
eb5d44eb | 330 | { |
331 | struct zapi_ipv4 api; | |
332 | struct prefix_ipv4 prefix4; | |
f390d2c7 | 333 | |
7076bb2f | 334 | if (vrf_bitmap_check (zclient->redist[AFI_IP][ZEBRA_ROUTE_ISIS], VRF_DEFAULT)) |
f390d2c7 | 335 | { |
7076bb2f | 336 | api.vrf_id = VRF_DEFAULT; |
f390d2c7 | 337 | api.type = ZEBRA_ROUTE_ISIS; |
7c8ff89e | 338 | api.instance = 0; |
f390d2c7 | 339 | api.flags = 0; |
340 | api.message = 0; | |
aa3b2642 | 341 | api.safi = SAFI_UNICAST; |
f390d2c7 | 342 | prefix4.family = AF_INET; |
343 | prefix4.prefixlen = prefix->prefixlen; | |
344 | prefix4.prefix = prefix->u.prefix4; | |
345 | zapi_ipv4_route (ZEBRA_IPV4_ROUTE_DELETE, zclient, &prefix4, &api); | |
346 | } | |
3f045a08 | 347 | UNSET_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED); |
f390d2c7 | 348 | |
eb5d44eb | 349 | return; |
350 | } | |
351 | ||
91283e76 | 352 | static void |
eb5d44eb | 353 | isis_zebra_route_add_ipv6 (struct prefix *prefix, |
f390d2c7 | 354 | struct isis_route_info *route_info) |
eb5d44eb | 355 | { |
356 | struct zapi_ipv6 api; | |
357 | struct in6_addr **nexthop_list; | |
b892f1dd | 358 | ifindex_t *ifindex_list; |
eb5d44eb | 359 | struct isis_nexthop6 *nexthop6; |
360 | int i, size; | |
361 | struct listnode *node; | |
362 | struct prefix_ipv6 prefix6; | |
363 | ||
3f045a08 | 364 | if (CHECK_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED)) |
eb5d44eb | 365 | return; |
f390d2c7 | 366 | |
7076bb2f | 367 | api.vrf_id = VRF_DEFAULT; |
eb5d44eb | 368 | api.type = ZEBRA_ROUTE_ISIS; |
7c8ff89e | 369 | api.instance = 0; |
eb5d44eb | 370 | api.flags = 0; |
371 | api.message = 0; | |
aa3b2642 | 372 | api.safi = SAFI_UNICAST; |
eb5d44eb | 373 | SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP); |
374 | SET_FLAG (api.message, ZAPI_MESSAGE_IFINDEX); | |
375 | SET_FLAG (api.message, ZAPI_MESSAGE_METRIC); | |
376 | api.metric = route_info->cost; | |
377 | #if 0 | |
378 | SET_FLAG (api.message, ZAPI_MESSAGE_DISTANCE); | |
379 | api.distance = route_info->depth; | |
380 | #endif | |
381 | api.nexthop_num = listcount (route_info->nexthops6); | |
382 | api.ifindex_num = listcount (route_info->nexthops6); | |
f390d2c7 | 383 | |
eb5d44eb | 384 | /* allocate memory for nexthop_list */ |
385 | size = sizeof (struct isis_nexthop6 *) * listcount (route_info->nexthops6); | |
386 | nexthop_list = (struct in6_addr **) XMALLOC (MTYPE_ISIS_TMP, size); | |
f390d2c7 | 387 | if (!nexthop_list) |
388 | { | |
389 | zlog_err ("isis_zebra_add_route_ipv6: out of memory!"); | |
390 | return; | |
391 | } | |
392 | ||
eb5d44eb | 393 | /* allocate memory for ifindex_list */ |
394 | size = sizeof (unsigned int) * listcount (route_info->nexthops6); | |
b892f1dd | 395 | ifindex_list = (ifindex_t *) XMALLOC (MTYPE_ISIS_TMP, size); |
f390d2c7 | 396 | if (!ifindex_list) |
397 | { | |
398 | zlog_err ("isis_zebra_add_route_ipv6: out of memory!"); | |
399 | XFREE (MTYPE_ISIS_TMP, nexthop_list); | |
400 | return; | |
401 | } | |
402 | ||
eb5d44eb | 403 | /* for each nexthop */ |
404 | i = 0; | |
1eb8ef25 | 405 | for (ALL_LIST_ELEMENTS_RO (route_info->nexthops6, node, nexthop6)) |
f390d2c7 | 406 | { |
f390d2c7 | 407 | if (!IN6_IS_ADDR_LINKLOCAL (&nexthop6->ip6) && |
408 | !IN6_IS_ADDR_UNSPECIFIED (&nexthop6->ip6)) | |
409 | { | |
410 | api.nexthop_num--; | |
411 | api.ifindex_num--; | |
412 | continue; | |
413 | } | |
414 | ||
415 | nexthop_list[i] = &nexthop6->ip6; | |
416 | ifindex_list[i] = nexthop6->ifindex; | |
417 | i++; | |
eb5d44eb | 418 | } |
f390d2c7 | 419 | |
eb5d44eb | 420 | api.nexthop = nexthop_list; |
421 | api.ifindex = ifindex_list; | |
f390d2c7 | 422 | |
423 | if (api.nexthop_num && api.ifindex_num) | |
424 | { | |
425 | prefix6.family = AF_INET6; | |
426 | prefix6.prefixlen = prefix->prefixlen; | |
427 | memcpy (&prefix6.prefix, &prefix->u.prefix6, sizeof (struct in6_addr)); | |
d75f3b00 | 428 | zapi_ipv6_route (ZEBRA_IPV6_ROUTE_ADD, zclient, &prefix6, NULL, &api); |
3f045a08 JB |
429 | SET_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED); |
430 | UNSET_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_RESYNC); | |
f390d2c7 | 431 | } |
432 | ||
eb5d44eb | 433 | XFREE (MTYPE_ISIS_TMP, nexthop_list); |
434 | XFREE (MTYPE_ISIS_TMP, ifindex_list); | |
f390d2c7 | 435 | |
eb5d44eb | 436 | return; |
437 | } | |
438 | ||
92365889 | 439 | static void |
f390d2c7 | 440 | isis_zebra_route_del_ipv6 (struct prefix *prefix, |
441 | struct isis_route_info *route_info) | |
eb5d44eb | 442 | { |
443 | struct zapi_ipv6 api; | |
444 | struct in6_addr **nexthop_list; | |
b892f1dd | 445 | ifindex_t *ifindex_list; |
eb5d44eb | 446 | struct isis_nexthop6 *nexthop6; |
447 | int i, size; | |
448 | struct listnode *node; | |
449 | struct prefix_ipv6 prefix6; | |
450 | ||
c354c014 | 451 | if (!CHECK_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED)) |
eb5d44eb | 452 | return; |
f390d2c7 | 453 | |
7076bb2f | 454 | api.vrf_id = VRF_DEFAULT; |
eb5d44eb | 455 | api.type = ZEBRA_ROUTE_ISIS; |
7c8ff89e | 456 | api.instance = 0; |
eb5d44eb | 457 | api.flags = 0; |
458 | api.message = 0; | |
aa3b2642 | 459 | api.safi = SAFI_UNICAST; |
eb5d44eb | 460 | SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP); |
461 | SET_FLAG (api.message, ZAPI_MESSAGE_IFINDEX); | |
462 | api.nexthop_num = listcount (route_info->nexthops6); | |
463 | api.ifindex_num = listcount (route_info->nexthops6); | |
f390d2c7 | 464 | |
eb5d44eb | 465 | /* allocate memory for nexthop_list */ |
466 | size = sizeof (struct isis_nexthop6 *) * listcount (route_info->nexthops6); | |
467 | nexthop_list = (struct in6_addr **) XMALLOC (MTYPE_ISIS_TMP, size); | |
f390d2c7 | 468 | if (!nexthop_list) |
469 | { | |
470 | zlog_err ("isis_zebra_route_del_ipv6: out of memory!"); | |
471 | return; | |
472 | } | |
473 | ||
eb5d44eb | 474 | /* allocate memory for ifindex_list */ |
475 | size = sizeof (unsigned int) * listcount (route_info->nexthops6); | |
b892f1dd | 476 | ifindex_list = (ifindex_t *) XMALLOC (MTYPE_ISIS_TMP, size); |
f390d2c7 | 477 | if (!ifindex_list) |
478 | { | |
479 | zlog_err ("isis_zebra_route_del_ipv6: out of memory!"); | |
480 | XFREE (MTYPE_ISIS_TMP, nexthop_list); | |
481 | return; | |
482 | } | |
483 | ||
eb5d44eb | 484 | /* for each nexthop */ |
485 | i = 0; | |
1eb8ef25 | 486 | for (ALL_LIST_ELEMENTS_RO (route_info->nexthops6, node, nexthop6)) |
f390d2c7 | 487 | { |
f390d2c7 | 488 | if (!IN6_IS_ADDR_LINKLOCAL (&nexthop6->ip6) && |
489 | !IN6_IS_ADDR_UNSPECIFIED (&nexthop6->ip6)) | |
490 | { | |
491 | api.nexthop_num--; | |
492 | api.ifindex_num--; | |
493 | continue; | |
494 | } | |
495 | ||
496 | nexthop_list[i] = &nexthop6->ip6; | |
497 | ifindex_list[i] = nexthop6->ifindex; | |
498 | i++; | |
eb5d44eb | 499 | } |
f390d2c7 | 500 | |
eb5d44eb | 501 | api.nexthop = nexthop_list; |
502 | api.ifindex = ifindex_list; | |
f390d2c7 | 503 | |
504 | if (api.nexthop_num && api.ifindex_num) | |
505 | { | |
506 | prefix6.family = AF_INET6; | |
507 | prefix6.prefixlen = prefix->prefixlen; | |
508 | memcpy (&prefix6.prefix, &prefix->u.prefix6, sizeof (struct in6_addr)); | |
d75f3b00 | 509 | zapi_ipv6_route (ZEBRA_IPV6_ROUTE_DELETE, zclient, &prefix6, NULL, &api); |
3f045a08 | 510 | UNSET_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED); |
f390d2c7 | 511 | } |
512 | ||
eb5d44eb | 513 | XFREE (MTYPE_ISIS_TMP, nexthop_list); |
f390d2c7 | 514 | XFREE (MTYPE_ISIS_TMP, ifindex_list); |
eb5d44eb | 515 | } |
516 | ||
eb5d44eb | 517 | void |
518 | isis_zebra_route_update (struct prefix *prefix, | |
f390d2c7 | 519 | struct isis_route_info *route_info) |
eb5d44eb | 520 | { |
521 | if (zclient->sock < 0) | |
522 | return; | |
523 | ||
7076bb2f FL |
524 | if ((prefix->family == AF_INET && !vrf_bitmap_check (zclient->redist[AFI_IP][ZEBRA_ROUTE_ISIS], VRF_DEFAULT)) || |
525 | (prefix->family == AF_INET6 && !vrf_bitmap_check (zclient->redist[AFI_IP6][ZEBRA_ROUTE_ISIS], VRF_DEFAULT))) | |
eb5d44eb | 526 | return; |
527 | ||
f390d2c7 | 528 | if (CHECK_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ACTIVE)) |
529 | { | |
530 | if (prefix->family == AF_INET) | |
531 | isis_zebra_route_add_ipv4 (prefix, route_info); | |
f390d2c7 | 532 | else if (prefix->family == AF_INET6) |
533 | isis_zebra_route_add_ipv6 (prefix, route_info); | |
f390d2c7 | 534 | } |
535 | else | |
536 | { | |
537 | if (prefix->family == AF_INET) | |
538 | isis_zebra_route_del_ipv4 (prefix, route_info); | |
f390d2c7 | 539 | else if (prefix->family == AF_INET6) |
540 | isis_zebra_route_del_ipv6 (prefix, route_info); | |
f390d2c7 | 541 | } |
eb5d44eb | 542 | return; |
543 | } | |
544 | ||
92365889 | 545 | static int |
f390d2c7 | 546 | isis_zebra_read_ipv4 (int command, struct zclient *zclient, |
7076bb2f | 547 | zebra_size_t length, vrf_id_t vrf_id) |
eb5d44eb | 548 | { |
549 | struct stream *stream; | |
550 | struct zapi_ipv4 api; | |
551 | struct prefix_ipv4 p; | |
f3ccedaa | 552 | struct prefix *p_generic = (struct prefix*)&p; |
eb5d44eb | 553 | |
554 | stream = zclient->ibuf; | |
f3ccedaa | 555 | memset(&api, 0, sizeof(api)); |
eb5d44eb | 556 | memset (&p, 0, sizeof (struct prefix_ipv4)); |
eb5d44eb | 557 | |
f390d2c7 | 558 | api.type = stream_getc (stream); |
7c8ff89e | 559 | api.instance = stream_getw (stream); |
0fc452dc | 560 | api.flags = stream_getl (stream); |
eb5d44eb | 561 | api.message = stream_getc (stream); |
562 | ||
563 | p.family = AF_INET; | |
d9178828 | 564 | p.prefixlen = MIN(IPV4_MAX_PREFIXLEN, stream_getc (stream)); |
eb5d44eb | 565 | stream_get (&p.prefix, stream, PSIZE (p.prefixlen)); |
f390d2c7 | 566 | |
567 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP)) | |
568 | { | |
eb5d44eb | 569 | api.nexthop_num = stream_getc (stream); |
91283e76 | 570 | (void)stream_get_ipv4 (stream); |
f390d2c7 | 571 | } |
572 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_IFINDEX)) | |
573 | { | |
574 | api.ifindex_num = stream_getc (stream); | |
91283e76 | 575 | stream_getl (stream); |
f390d2c7 | 576 | } |
eb5d44eb | 577 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE)) |
578 | api.distance = stream_getc (stream); | |
579 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC)) | |
580 | api.metric = stream_getl (stream); | |
f3ccedaa CF |
581 | |
582 | /* | |
583 | * Avoid advertising a false default reachability. (A default | |
584 | * route installed by IS-IS gets redistributed from zebra back | |
585 | * into IS-IS causing us to start advertising default reachabity | |
586 | * without this check) | |
587 | */ | |
588 | if (p.prefixlen == 0 && api.type == ZEBRA_ROUTE_ISIS) | |
589 | command = ZEBRA_IPV4_ROUTE_DELETE; | |
f390d2c7 | 590 | |
5048fe14 | 591 | if (command == ZEBRA_REDISTRIBUTE_IPV4_ADD) |
f3ccedaa CF |
592 | isis_redist_add(api.type, p_generic, api.distance, api.metric); |
593 | else | |
594 | isis_redist_delete(api.type, p_generic); | |
eb5d44eb | 595 | |
596 | return 0; | |
597 | } | |
598 | ||
92365889 | 599 | static int |
f390d2c7 | 600 | isis_zebra_read_ipv6 (int command, struct zclient *zclient, |
7076bb2f | 601 | zebra_size_t length, vrf_id_t vrf_id) |
eb5d44eb | 602 | { |
f3ccedaa CF |
603 | struct stream *stream; |
604 | struct zapi_ipv6 api; | |
605 | struct prefix_ipv6 p; | |
606 | struct prefix *p_generic = (struct prefix*)&p; | |
607 | struct in6_addr nexthop; | |
608 | unsigned long ifindex __attribute__((unused)); | |
609 | ||
610 | stream = zclient->ibuf; | |
611 | memset(&api, 0, sizeof(api)); | |
612 | memset(&p, 0, sizeof(struct prefix_ipv6)); | |
613 | memset(&nexthop, 0, sizeof(nexthop)); | |
614 | ifindex = 0; | |
615 | ||
616 | api.type = stream_getc(stream); | |
0fc452dc | 617 | api.flags = stream_getl(stream); |
f3ccedaa CF |
618 | api.message = stream_getc(stream); |
619 | ||
620 | p.family = AF_INET6; | |
621 | p.prefixlen = stream_getc(stream); | |
622 | stream_get(&p.prefix, stream, PSIZE(p.prefixlen)); | |
623 | ||
624 | if (CHECK_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP)) | |
625 | { | |
626 | api.nexthop_num = stream_getc(stream); /* this is always 1 */ | |
627 | stream_get(&nexthop, stream, sizeof(nexthop)); | |
628 | } | |
629 | if (CHECK_FLAG(api.message, ZAPI_MESSAGE_IFINDEX)) | |
630 | { | |
631 | api.ifindex_num = stream_getc(stream); | |
632 | ifindex = stream_getl(stream); | |
633 | } | |
634 | if (CHECK_FLAG(api.message, ZAPI_MESSAGE_DISTANCE)) | |
635 | api.distance = stream_getc(stream); | |
636 | if (CHECK_FLAG(api.message, ZAPI_MESSAGE_METRIC)) | |
637 | api.metric = stream_getl(stream); | |
638 | ||
639 | /* | |
640 | * Avoid advertising a false default reachability. (A default | |
641 | * route installed by IS-IS gets redistributed from zebra back | |
642 | * into IS-IS causing us to start advertising default reachabity | |
643 | * without this check) | |
644 | */ | |
645 | if (p.prefixlen == 0 && api.type == ZEBRA_ROUTE_ISIS) | |
646 | command = ZEBRA_IPV6_ROUTE_DELETE; | |
647 | ||
648 | if (command == ZEBRA_IPV6_ROUTE_ADD) | |
649 | isis_redist_add(api.type, p_generic, api.distance, api.metric); | |
650 | else | |
651 | isis_redist_delete(api.type, p_generic); | |
652 | ||
eb5d44eb | 653 | return 0; |
654 | } | |
eb5d44eb | 655 | |
656 | int | |
657 | isis_distribute_list_update (int routetype) | |
658 | { | |
659 | return 0; | |
660 | } | |
661 | ||
f3ccedaa CF |
662 | void |
663 | isis_zebra_redistribute_set(int type) | |
eb5d44eb | 664 | { |
f3ccedaa CF |
665 | if (type == DEFAULT_ROUTE) |
666 | zclient_redistribute_default(ZEBRA_REDISTRIBUTE_DEFAULT_ADD, zclient, VRF_DEFAULT); | |
667 | else | |
668 | zclient_redistribute(ZEBRA_REDISTRIBUTE_ADD, zclient, AFI_IP, type, 0, VRF_DEFAULT); | |
669 | } | |
670 | ||
671 | void | |
672 | isis_zebra_redistribute_unset(int type) | |
673 | { | |
674 | if (type == DEFAULT_ROUTE) | |
675 | zclient_redistribute_default(ZEBRA_REDISTRIBUTE_DEFAULT_DELETE, zclient, VRF_DEFAULT); | |
676 | else | |
677 | zclient_redistribute(ZEBRA_REDISTRIBUTE_DELETE, zclient, AFI_IP, type, 0, VRF_DEFAULT); | |
eb5d44eb | 678 | } |
679 | ||
7076bb2f FL |
680 | static void |
681 | isis_zebra_connected (struct zclient *zclient) | |
682 | { | |
0e5223e7 | 683 | zclient_send_reg_requests (zclient, VRF_DEFAULT); |
7076bb2f FL |
684 | } |
685 | ||
eb5d44eb | 686 | void |
4140ca4d | 687 | isis_zebra_init (struct thread_master *master) |
eb5d44eb | 688 | { |
7076bb2f | 689 | zclient = zclient_new (master); |
7c8ff89e | 690 | zclient_init (zclient, ZEBRA_ROUTE_ISIS, 0); |
7076bb2f | 691 | zclient->zebra_connected = isis_zebra_connected; |
18a6dce6 | 692 | zclient->router_id_update = isis_router_id_update_zebra; |
eb5d44eb | 693 | zclient->interface_add = isis_zebra_if_add; |
694 | zclient->interface_delete = isis_zebra_if_del; | |
695 | zclient->interface_up = isis_zebra_if_state_up; | |
696 | zclient->interface_down = isis_zebra_if_state_down; | |
697 | zclient->interface_address_add = isis_zebra_if_address_add; | |
698 | zclient->interface_address_delete = isis_zebra_if_address_del; | |
f8c06e2c | 699 | zclient->interface_link_params = isis_zebra_link_params; |
5048fe14 | 700 | zclient->redistribute_route_ipv4_add = isis_zebra_read_ipv4; |
701 | zclient->redistribute_route_ipv4_del = isis_zebra_read_ipv4; | |
5048fe14 | 702 | zclient->redistribute_route_ipv6_add = isis_zebra_read_ipv6; |
703 | zclient->redistribute_route_ipv6_del = isis_zebra_read_ipv6; | |
eb5d44eb | 704 | |
705 | return; | |
706 | } |