]>
Commit | Line | Data |
---|---|---|
eb5d44eb | 1 | /* |
d62a17ae | 2 | * IS-IS Rout(e)ing protocol - isis_zebra.c |
eb5d44eb | 3 | * |
4 | * Copyright (C) 2001,2002 Sampo Saaristo | |
d62a17ae | 5 | * Tampere University of Technology |
eb5d44eb | 6 | * Institute of Communications Engineering |
f3ccedaa | 7 | * Copyright (C) 2013-2015 Christian Franke <chris@opensourcerouting.org> |
eb5d44eb | 8 | * |
d62a17ae | 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) | |
eb5d44eb | 12 | * any later version. |
13 | * | |
d62a17ae | 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 | |
eb5d44eb | 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" | |
c89c05dd | 45 | #include "isisd/isisd.h" |
eb5d44eb | 46 | #include "isisd/isis_circuit.h" |
47 | #include "isisd/isis_csm.h" | |
3f045a08 | 48 | #include "isisd/isis_lsp.h" |
eb5d44eb | 49 | #include "isisd/isis_route.h" |
50 | #include "isisd/isis_zebra.h" | |
f8c06e2c | 51 | #include "isisd/isis_te.h" |
eb5d44eb | 52 | |
53 | struct zclient *zclient = NULL; | |
54 | ||
18a6dce6 | 55 | /* Router-id update message from zebra. */ |
d62a17ae | 56 | static int isis_router_id_update_zebra(int command, struct zclient *zclient, |
57 | zebra_size_t length, vrf_id_t vrf_id) | |
18a6dce6 | 58 | { |
d62a17ae | 59 | struct isis_area *area; |
60 | struct listnode *node; | |
61 | struct prefix router_id; | |
62 | ||
63 | /* | |
64 | * If ISIS TE is enable, TE Router ID is set through specific command. | |
65 | * See mpls_te_router_addr() command in isis_te.c | |
66 | */ | |
67 | if (IS_MPLS_TE(isisMplsTE)) | |
68 | return 0; | |
69 | ||
70 | zebra_router_id_update_read(zclient->ibuf, &router_id); | |
71 | if (isis->router_id == router_id.u.prefix4.s_addr) | |
72 | return 0; | |
73 | ||
74 | isis->router_id = router_id.u.prefix4.s_addr; | |
75 | for (ALL_LIST_ELEMENTS_RO(isis->area_list, node, area)) | |
76 | if (listcount(area->area_addrs) > 0) | |
77 | lsp_regenerate_schedule(area, area->is_type, 0); | |
78 | ||
79 | return 0; | |
18a6dce6 | 80 | } |
eb5d44eb | 81 | |
d62a17ae | 82 | static int isis_zebra_if_add(int command, struct zclient *zclient, |
83 | zebra_size_t length, vrf_id_t vrf_id) | |
eb5d44eb | 84 | { |
d62a17ae | 85 | struct interface *ifp; |
eb5d44eb | 86 | |
d62a17ae | 87 | ifp = zebra_interface_add_read(zclient->ibuf, vrf_id); |
f390d2c7 | 88 | |
d62a17ae | 89 | if (isis->debugs & DEBUG_ZEBRA) |
90 | zlog_debug( | |
91 | "Zebra I/F add: %s index %d flags %ld metric %d mtu %d", | |
92 | ifp->name, ifp->ifindex, (long)ifp->flags, ifp->metric, | |
93 | ifp->mtu); | |
f390d2c7 | 94 | |
d62a17ae | 95 | if (if_is_operative(ifp)) |
96 | isis_csm_state_change(IF_UP_FROM_Z, circuit_scan_by_ifp(ifp), | |
97 | ifp); | |
f390d2c7 | 98 | |
d62a17ae | 99 | return 0; |
eb5d44eb | 100 | } |
101 | ||
d62a17ae | 102 | static int isis_zebra_if_del(int command, struct zclient *zclient, |
103 | zebra_size_t length, vrf_id_t vrf_id) | |
eb5d44eb | 104 | { |
d62a17ae | 105 | struct interface *ifp; |
106 | struct stream *s; | |
eb5d44eb | 107 | |
d62a17ae | 108 | s = zclient->ibuf; |
109 | ifp = zebra_interface_state_read(s, vrf_id); | |
f390d2c7 | 110 | |
d62a17ae | 111 | if (!ifp) |
112 | return 0; | |
eb5d44eb | 113 | |
d62a17ae | 114 | if (if_is_operative(ifp)) |
115 | zlog_warn("Zebra: got delete of %s, but interface is still up", | |
116 | ifp->name); | |
eb5d44eb | 117 | |
d62a17ae | 118 | if (isis->debugs & DEBUG_ZEBRA) |
119 | zlog_debug( | |
120 | "Zebra I/F delete: %s index %d flags %ld metric %d mtu %d", | |
121 | ifp->name, ifp->ifindex, (long)ifp->flags, ifp->metric, | |
122 | ifp->mtu); | |
eb5d44eb | 123 | |
d62a17ae | 124 | isis_csm_state_change(IF_DOWN_FROM_Z, circuit_scan_by_ifp(ifp), ifp); |
d2fc8896 | 125 | |
d62a17ae | 126 | /* Cannot call if_delete because we should retain the pseudo interface |
127 | in case there is configuration info attached to it. */ | |
128 | if_delete_retain(ifp); | |
f390d2c7 | 129 | |
d62a17ae | 130 | ifp->ifindex = IFINDEX_DELETED; |
d2fc8896 | 131 | |
d62a17ae | 132 | return 0; |
eb5d44eb | 133 | } |
134 | ||
d62a17ae | 135 | static int isis_zebra_if_state_up(int command, struct zclient *zclient, |
136 | zebra_size_t length, vrf_id_t vrf_id) | |
eb5d44eb | 137 | { |
d62a17ae | 138 | struct interface *ifp; |
f390d2c7 | 139 | |
d62a17ae | 140 | ifp = zebra_interface_state_read(zclient->ibuf, vrf_id); |
f390d2c7 | 141 | |
d62a17ae | 142 | if (ifp == NULL) |
143 | return 0; | |
f390d2c7 | 144 | |
d62a17ae | 145 | isis_csm_state_change(IF_UP_FROM_Z, circuit_scan_by_ifp(ifp), ifp); |
f390d2c7 | 146 | |
d62a17ae | 147 | return 0; |
eb5d44eb | 148 | } |
149 | ||
d62a17ae | 150 | static int isis_zebra_if_state_down(int command, struct zclient *zclient, |
151 | zebra_size_t length, vrf_id_t vrf_id) | |
eb5d44eb | 152 | { |
d62a17ae | 153 | struct interface *ifp; |
154 | struct isis_circuit *circuit; | |
f390d2c7 | 155 | |
d62a17ae | 156 | ifp = zebra_interface_state_read(zclient->ibuf, vrf_id); |
f390d2c7 | 157 | |
d62a17ae | 158 | if (ifp == NULL) |
159 | return 0; | |
f390d2c7 | 160 | |
d62a17ae | 161 | circuit = isis_csm_state_change(IF_DOWN_FROM_Z, |
162 | circuit_scan_by_ifp(ifp), ifp); | |
163 | if (circuit) | |
164 | SET_FLAG(circuit->flags, ISIS_CIRCUIT_FLAPPED_AFTER_SPF); | |
f390d2c7 | 165 | |
d62a17ae | 166 | return 0; |
eb5d44eb | 167 | } |
168 | ||
d62a17ae | 169 | static int isis_zebra_if_address_add(int command, struct zclient *zclient, |
170 | zebra_size_t length, vrf_id_t vrf_id) | |
eb5d44eb | 171 | { |
d62a17ae | 172 | struct connected *c; |
173 | struct prefix *p; | |
174 | char buf[PREFIX2STR_BUFFER]; | |
eb5d44eb | 175 | |
d62a17ae | 176 | c = zebra_interface_address_read(ZEBRA_INTERFACE_ADDRESS_ADD, |
177 | zclient->ibuf, vrf_id); | |
f390d2c7 | 178 | |
d62a17ae | 179 | if (c == NULL) |
180 | return 0; | |
f390d2c7 | 181 | |
d62a17ae | 182 | p = c->address; |
f390d2c7 | 183 | |
d62a17ae | 184 | prefix2str(p, buf, sizeof(buf)); |
eb5d44eb | 185 | #ifdef EXTREME_DEBUG |
d62a17ae | 186 | if (p->family == AF_INET) |
187 | zlog_debug("connected IP address %s", buf); | |
188 | if (p->family == AF_INET6) | |
189 | zlog_debug("connected IPv6 address %s", buf); | |
eb5d44eb | 190 | #endif /* EXTREME_DEBUG */ |
d62a17ae | 191 | if (if_is_operative(c->ifp)) |
192 | isis_circuit_add_addr(circuit_scan_by_ifp(c->ifp), c); | |
eb5d44eb | 193 | |
d62a17ae | 194 | return 0; |
eb5d44eb | 195 | } |
196 | ||
d62a17ae | 197 | static int isis_zebra_if_address_del(int command, struct zclient *client, |
198 | zebra_size_t length, vrf_id_t vrf_id) | |
eb5d44eb | 199 | { |
d62a17ae | 200 | struct connected *c; |
201 | struct interface *ifp; | |
1cd80845 | 202 | #ifdef EXTREME_DEBUG |
d62a17ae | 203 | struct prefix *p; |
204 | char buf[PREFIX2STR_BUFFER]; | |
1cd80845 | 205 | #endif /* EXTREME_DEBUG */ |
eb5d44eb | 206 | |
d62a17ae | 207 | c = zebra_interface_address_read(ZEBRA_INTERFACE_ADDRESS_DELETE, |
208 | zclient->ibuf, vrf_id); | |
f390d2c7 | 209 | |
d62a17ae | 210 | if (c == NULL) |
211 | return 0; | |
f390d2c7 | 212 | |
d62a17ae | 213 | ifp = c->ifp; |
f390d2c7 | 214 | |
f891f443 | 215 | #ifdef EXTREME_DEBUG |
d62a17ae | 216 | p = c->address; |
217 | prefix2str(p, buf, sizeof(buf)); | |
f891f443 | 218 | |
d62a17ae | 219 | if (p->family == AF_INET) |
220 | zlog_debug("disconnected IP address %s", buf); | |
221 | if (p->family == AF_INET6) | |
222 | zlog_debug("disconnected IPv6 address %s", buf); | |
f891f443 | 223 | #endif /* EXTREME_DEBUG */ |
f390d2c7 | 224 | |
d62a17ae | 225 | if (if_is_operative(ifp)) |
226 | isis_circuit_del_addr(circuit_scan_by_ifp(ifp), c); | |
227 | connected_free(c); | |
f390d2c7 | 228 | |
d62a17ae | 229 | return 0; |
eb5d44eb | 230 | } |
231 | ||
d62a17ae | 232 | static int isis_zebra_link_params(int command, struct zclient *zclient, |
233 | zebra_size_t length) | |
f8c06e2c | 234 | { |
d62a17ae | 235 | struct interface *ifp; |
f8c06e2c | 236 | |
d62a17ae | 237 | ifp = zebra_interface_link_params_read(zclient->ibuf); |
f8c06e2c | 238 | |
d62a17ae | 239 | if (ifp == NULL) |
240 | return 0; | |
f8c06e2c | 241 | |
d62a17ae | 242 | /* Update TE TLV */ |
243 | isis_mpls_te_update(ifp); | |
f8c06e2c | 244 | |
d62a17ae | 245 | return 0; |
f8c06e2c OD |
246 | } |
247 | ||
f80dd32b RW |
248 | static void isis_zebra_route_add_route(struct prefix *prefix, |
249 | struct isis_route_info *route_info) | |
eb5d44eb | 250 | { |
c0721de4 RW |
251 | struct zapi_route api; |
252 | struct zapi_nexthop *api_nh; | |
d62a17ae | 253 | struct isis_nexthop *nexthop; |
f80dd32b | 254 | struct isis_nexthop6 *nexthop6; |
d62a17ae | 255 | struct listnode *node; |
c0721de4 | 256 | int count = 0; |
d62a17ae | 257 | |
258 | if (CHECK_FLAG(route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED)) | |
259 | return; | |
260 | ||
c0721de4 RW |
261 | memset(&api, 0, sizeof(api)); |
262 | api.vrf_id = VRF_DEFAULT; | |
263 | api.type = ZEBRA_ROUTE_ISIS; | |
264 | api.safi = SAFI_UNICAST; | |
265 | api.prefix = *prefix; | |
266 | SET_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP); | |
267 | SET_FLAG(api.message, ZAPI_MESSAGE_METRIC); | |
268 | api.metric = route_info->cost; | |
2097cd8a | 269 | #if 0 |
c0721de4 RW |
270 | SET_FLAG(api.message, ZAPI_MESSAGE_DISTANCE); |
271 | api.distance = route_info->depth; | |
2097cd8a | 272 | #endif |
f390d2c7 | 273 | |
f80dd32b RW |
274 | /* Nexthops */ |
275 | switch (prefix->family) { | |
276 | case AF_INET: | |
277 | for (ALL_LIST_ELEMENTS_RO(route_info->nexthops, node, | |
278 | nexthop)) { | |
279 | api_nh = &api.nexthops[count]; | |
280 | /* FIXME: can it be ? */ | |
281 | if (nexthop->ip.s_addr != INADDR_ANY) { | |
282 | api_nh->type = NEXTHOP_TYPE_IPV4_IFINDEX; | |
283 | api_nh->gate.ipv4 = nexthop->ip; | |
284 | } else { | |
285 | api_nh->type = NEXTHOP_TYPE_IFINDEX; | |
286 | } | |
287 | api_nh->ifindex = nexthop->ifindex; | |
288 | count++; | |
d62a17ae | 289 | } |
f80dd32b RW |
290 | break; |
291 | case AF_INET6: | |
292 | for (ALL_LIST_ELEMENTS_RO(route_info->nexthops6, node, | |
293 | nexthop6)) { | |
294 | if (!IN6_IS_ADDR_LINKLOCAL(&nexthop6->ip6) | |
295 | && !IN6_IS_ADDR_UNSPECIFIED(&nexthop6->ip6)) { | |
296 | continue; | |
297 | } | |
298 | ||
299 | api_nh = &api.nexthops[count]; | |
300 | api_nh->gate.ipv6 = nexthop6->ip6; | |
301 | api_nh->ifindex = nexthop6->ifindex; | |
302 | api_nh->type = NEXTHOP_TYPE_IPV6_IFINDEX; | |
303 | count++; | |
d62a17ae | 304 | } |
f80dd32b | 305 | break; |
d62a17ae | 306 | } |
c0721de4 RW |
307 | if (!count) |
308 | return; | |
f390d2c7 | 309 | |
c0721de4 | 310 | api.nexthop_num = count; |
f390d2c7 | 311 | |
c0721de4 RW |
312 | zclient_route_send(ZEBRA_ROUTE_ADD, zclient, &api); |
313 | SET_FLAG(route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED); | |
314 | UNSET_FLAG(route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_RESYNC); | |
eb5d44eb | 315 | } |
316 | ||
f80dd32b RW |
317 | static void isis_zebra_route_del_route(struct prefix *prefix, |
318 | struct isis_route_info *route_info) | |
eb5d44eb | 319 | { |
c0721de4 | 320 | struct zapi_route api; |
d62a17ae | 321 | |
322 | if (!CHECK_FLAG(route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED)) | |
323 | return; | |
324 | ||
c0721de4 | 325 | memset(&api, 0, sizeof(api)); |
d62a17ae | 326 | api.vrf_id = VRF_DEFAULT; |
327 | api.type = ZEBRA_ROUTE_ISIS; | |
d62a17ae | 328 | api.safi = SAFI_UNICAST; |
c0721de4 | 329 | api.prefix = *prefix; |
f390d2c7 | 330 | |
c0721de4 RW |
331 | zclient_route_send(ZEBRA_ROUTE_DELETE, zclient, &api); |
332 | UNSET_FLAG(route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED); | |
eb5d44eb | 333 | } |
334 | ||
d62a17ae | 335 | void isis_zebra_route_update(struct prefix *prefix, |
336 | struct isis_route_info *route_info) | |
eb5d44eb | 337 | { |
d62a17ae | 338 | if (zclient->sock < 0) |
339 | return; | |
340 | ||
f80dd32b RW |
341 | if (CHECK_FLAG(route_info->flag, ISIS_ROUTE_FLAG_ACTIVE)) |
342 | isis_zebra_route_add_route(prefix, route_info); | |
343 | else | |
344 | isis_zebra_route_del_route(prefix, route_info); | |
eb5d44eb | 345 | } |
346 | ||
74489921 RW |
347 | static int isis_zebra_read(int command, struct zclient *zclient, |
348 | zebra_size_t length, vrf_id_t vrf_id) | |
eb5d44eb | 349 | { |
74489921 | 350 | struct zapi_route api; |
d62a17ae | 351 | |
74489921 RW |
352 | if (zapi_route_decode(zclient->ibuf, &api) < 0) |
353 | return -1; | |
d62a17ae | 354 | |
74489921 RW |
355 | /* we completely ignore srcdest routes for now. */ |
356 | if (CHECK_FLAG(api.message, ZAPI_MESSAGE_SRCPFX)) | |
d62a17ae | 357 | return 0; |
358 | ||
d62a17ae | 359 | /* |
360 | * Avoid advertising a false default reachability. (A default | |
361 | * route installed by IS-IS gets redistributed from zebra back | |
362 | * into IS-IS causing us to start advertising default reachabity | |
363 | * without this check) | |
364 | */ | |
74489921 RW |
365 | if (api.prefix.prefixlen == 0 && api.type == ZEBRA_ROUTE_ISIS) |
366 | command = ZEBRA_REDISTRIBUTE_ROUTE_DEL; | |
d62a17ae | 367 | |
74489921 RW |
368 | if (command == ZEBRA_REDISTRIBUTE_ROUTE_ADD) |
369 | isis_redist_add(api.type, &api.prefix, api.distance, | |
370 | api.metric); | |
d62a17ae | 371 | else |
74489921 | 372 | isis_redist_delete(api.type, &api.prefix); |
d62a17ae | 373 | |
374 | return 0; | |
eb5d44eb | 375 | } |
eb5d44eb | 376 | |
d62a17ae | 377 | int isis_distribute_list_update(int routetype) |
eb5d44eb | 378 | { |
d62a17ae | 379 | return 0; |
eb5d44eb | 380 | } |
381 | ||
d62a17ae | 382 | void isis_zebra_redistribute_set(afi_t afi, int type) |
eb5d44eb | 383 | { |
d62a17ae | 384 | if (type == DEFAULT_ROUTE) |
385 | zclient_redistribute_default(ZEBRA_REDISTRIBUTE_DEFAULT_ADD, | |
386 | zclient, VRF_DEFAULT); | |
387 | else | |
388 | zclient_redistribute(ZEBRA_REDISTRIBUTE_ADD, zclient, afi, type, | |
389 | 0, VRF_DEFAULT); | |
f3ccedaa CF |
390 | } |
391 | ||
d62a17ae | 392 | void isis_zebra_redistribute_unset(afi_t afi, int type) |
f3ccedaa | 393 | { |
d62a17ae | 394 | if (type == DEFAULT_ROUTE) |
395 | zclient_redistribute_default(ZEBRA_REDISTRIBUTE_DEFAULT_DELETE, | |
396 | zclient, VRF_DEFAULT); | |
397 | else | |
398 | zclient_redistribute(ZEBRA_REDISTRIBUTE_DELETE, zclient, afi, | |
399 | type, 0, VRF_DEFAULT); | |
eb5d44eb | 400 | } |
401 | ||
d62a17ae | 402 | static void isis_zebra_connected(struct zclient *zclient) |
7076bb2f | 403 | { |
d62a17ae | 404 | zclient_send_reg_requests(zclient, VRF_DEFAULT); |
7076bb2f FL |
405 | } |
406 | ||
d62a17ae | 407 | void isis_zebra_init(struct thread_master *master) |
eb5d44eb | 408 | { |
d62a17ae | 409 | zclient = zclient_new(master); |
410 | zclient_init(zclient, ZEBRA_ROUTE_ISIS, 0); | |
411 | zclient->zebra_connected = isis_zebra_connected; | |
412 | zclient->router_id_update = isis_router_id_update_zebra; | |
413 | zclient->interface_add = isis_zebra_if_add; | |
414 | zclient->interface_delete = isis_zebra_if_del; | |
415 | zclient->interface_up = isis_zebra_if_state_up; | |
416 | zclient->interface_down = isis_zebra_if_state_down; | |
417 | zclient->interface_address_add = isis_zebra_if_address_add; | |
418 | zclient->interface_address_delete = isis_zebra_if_address_del; | |
419 | zclient->interface_link_params = isis_zebra_link_params; | |
74489921 RW |
420 | zclient->redistribute_route_add = isis_zebra_read; |
421 | zclient->redistribute_route_del = isis_zebra_read; | |
d62a17ae | 422 | |
423 | return; | |
eb5d44eb | 424 | } |
8d429559 | 425 | |
d62a17ae | 426 | void isis_zebra_stop(void) |
8d429559 | 427 | { |
d62a17ae | 428 | zclient_stop(zclient); |
429 | zclient_free(zclient); | |
8d429559 | 430 | } |