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