jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 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 |
Christian Franke | acf9865 | 2015-11-12 14:24:22 +0100 | [diff] [blame] | 7 | * Copyright (C) 2013-2015 Christian Franke <chris@opensourcerouting.org> |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 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. |
| 18 | |
| 19 | * You should have received a copy of the GNU General Public License along |
| 20 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 21 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 22 | */ |
| 23 | |
| 24 | #include <zebra.h> |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 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" |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 36 | #include "vrf.h" |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 37 | |
hasso | c89c05d | 2005-09-04 21:36:36 +0000 | [diff] [blame] | 38 | #include "isisd/dict.h" |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 39 | #include "isisd/isis_constants.h" |
| 40 | #include "isisd/isis_common.h" |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 41 | #include "isisd/isis_flags.h" |
| 42 | #include "isisd/isis_misc.h" |
| 43 | #include "isisd/isis_circuit.h" |
| 44 | #include "isisd/isis_tlv.h" |
hasso | c89c05d | 2005-09-04 21:36:36 +0000 | [diff] [blame] | 45 | #include "isisd/isisd.h" |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 46 | #include "isisd/isis_circuit.h" |
| 47 | #include "isisd/isis_csm.h" |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 48 | #include "isisd/isis_lsp.h" |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 49 | #include "isisd/isis_route.h" |
| 50 | #include "isisd/isis_zebra.h" |
Olivier Dugeon | 4f59357 | 2016-04-19 19:03:05 +0200 | [diff] [blame] | 51 | #include "isisd/isis_te.h" |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 52 | |
| 53 | struct zclient *zclient = NULL; |
| 54 | |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 55 | /* Router-id update message from zebra. */ |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 56 | static int |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 57 | isis_router_id_update_zebra (int command, struct zclient *zclient, |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 58 | zebra_size_t length, vrf_id_t vrf_id) |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 59 | { |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 60 | struct isis_area *area; |
| 61 | struct listnode *node; |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 62 | struct prefix router_id; |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 63 | |
Olivier Dugeon | 4f59357 | 2016-04-19 19:03:05 +0200 | [diff] [blame] | 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 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 71 | zebra_router_id_update_read (zclient->ibuf, &router_id); |
| 72 | if (isis->router_id == router_id.u.prefix4.s_addr) |
| 73 | return 0; |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 74 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 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 | |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 80 | return 0; |
| 81 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 82 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 83 | static int |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 84 | isis_zebra_if_add (int command, struct zclient *zclient, zebra_size_t length, |
| 85 | vrf_id_t vrf_id) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 86 | { |
| 87 | struct interface *ifp; |
| 88 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 89 | ifp = zebra_interface_add_read (zclient->ibuf, vrf_id); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 90 | |
hasso | c89c05d | 2005-09-04 21:36:36 +0000 | [diff] [blame] | 91 | if (isis->debugs & DEBUG_ZEBRA) |
| 92 | zlog_debug ("Zebra I/F add: %s index %d flags %ld metric %d mtu %d", |
Paul Jakma | 41b36e9 | 2006-12-08 01:09:50 +0000 | [diff] [blame] | 93 | ifp->name, ifp->ifindex, (long)ifp->flags, ifp->metric, ifp->mtu); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 94 | |
hasso | b30c5e6 | 2004-12-29 20:06:41 +0000 | [diff] [blame] | 95 | if (if_is_operative (ifp)) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 96 | isis_csm_state_change (IF_UP_FROM_Z, circuit_scan_by_ifp (ifp), ifp); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 97 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 98 | return 0; |
| 99 | } |
| 100 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 101 | static int |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 102 | isis_zebra_if_del (int command, struct zclient *zclient, zebra_size_t length, |
| 103 | vrf_id_t vrf_id) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 104 | { |
| 105 | struct interface *ifp; |
| 106 | struct stream *s; |
| 107 | |
| 108 | s = zclient->ibuf; |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 109 | ifp = zebra_interface_state_read (s, vrf_id); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 110 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 111 | if (!ifp) |
| 112 | return 0; |
| 113 | |
hasso | b30c5e6 | 2004-12-29 20:06:41 +0000 | [diff] [blame] | 114 | if (if_is_operative (ifp)) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 115 | zlog_warn ("Zebra: got delete of %s, but interface is still up", |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 116 | ifp->name); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 117 | |
hasso | c89c05d | 2005-09-04 21:36:36 +0000 | [diff] [blame] | 118 | if (isis->debugs & DEBUG_ZEBRA) |
| 119 | zlog_debug ("Zebra I/F delete: %s index %d flags %ld metric %d mtu %d", |
Paul Jakma | 41b36e9 | 2006-12-08 01:09:50 +0000 | [diff] [blame] | 120 | ifp->name, ifp->ifindex, (long)ifp->flags, ifp->metric, ifp->mtu); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 121 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 122 | isis_csm_state_change (IF_DOWN_FROM_Z, circuit_scan_by_ifp (ifp), ifp); |
ajs | d2fc889 | 2005-04-02 18:38:43 +0000 | [diff] [blame] | 123 | |
| 124 | /* Cannot call if_delete because we should retain the pseudo interface |
| 125 | in case there is configuration info attached to it. */ |
| 126 | if_delete_retain(ifp); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 127 | |
ajs | d2fc889 | 2005-04-02 18:38:43 +0000 | [diff] [blame] | 128 | ifp->ifindex = IFINDEX_INTERNAL; |
| 129 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 130 | return 0; |
| 131 | } |
| 132 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 133 | static int |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 134 | isis_zebra_if_state_up (int command, struct zclient *zclient, |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 135 | zebra_size_t length, vrf_id_t vrf_id) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 136 | { |
| 137 | struct interface *ifp; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 138 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 139 | ifp = zebra_interface_state_read (zclient->ibuf, vrf_id); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 140 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 141 | if (ifp == NULL) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 142 | return 0; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 143 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 144 | isis_csm_state_change (IF_UP_FROM_Z, circuit_scan_by_ifp (ifp), ifp); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 145 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 146 | return 0; |
| 147 | } |
| 148 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 149 | static int |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 150 | isis_zebra_if_state_down (int command, struct zclient *zclient, |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 151 | zebra_size_t length, vrf_id_t vrf_id) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 152 | { |
| 153 | struct interface *ifp; |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 154 | struct isis_circuit *circuit; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 155 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 156 | ifp = zebra_interface_state_read (zclient->ibuf, vrf_id); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 157 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 158 | if (ifp == NULL) |
| 159 | return 0; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 160 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 161 | circuit = isis_csm_state_change (IF_DOWN_FROM_Z, circuit_scan_by_ifp (ifp), |
| 162 | ifp); |
| 163 | if (circuit) |
| 164 | SET_FLAG(circuit->flags, ISIS_CIRCUIT_FLAPPED_AFTER_SPF); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 165 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 166 | return 0; |
| 167 | } |
| 168 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 169 | static int |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 170 | isis_zebra_if_address_add (int command, struct zclient *zclient, |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 171 | zebra_size_t length, vrf_id_t vrf_id) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 172 | { |
| 173 | struct connected *c; |
| 174 | struct prefix *p; |
hasso | f7c43dc | 2004-09-26 16:24:14 +0000 | [diff] [blame] | 175 | char buf[BUFSIZ]; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 176 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 177 | c = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_ADD, |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 178 | zclient->ibuf, vrf_id); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 179 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 180 | if (c == NULL) |
| 181 | return 0; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 182 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 183 | p = c->address; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 184 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 185 | prefix2str (p, buf, BUFSIZ); |
| 186 | #ifdef EXTREME_DEBUG |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 187 | if (p->family == AF_INET) |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 188 | zlog_debug ("connected IP address %s", buf); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 189 | #ifdef HAVE_IPV6 |
| 190 | if (p->family == AF_INET6) |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 191 | zlog_debug ("connected IPv6 address %s", buf); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 192 | #endif /* HAVE_IPV6 */ |
| 193 | #endif /* EXTREME_DEBUG */ |
hasso | b30c5e6 | 2004-12-29 20:06:41 +0000 | [diff] [blame] | 194 | if (if_is_operative (c->ifp)) |
| 195 | isis_circuit_add_addr (circuit_scan_by_ifp (c->ifp), c); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 196 | |
| 197 | return 0; |
| 198 | } |
| 199 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 200 | static int |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 201 | isis_zebra_if_address_del (int command, struct zclient *client, |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 202 | zebra_size_t length, vrf_id_t vrf_id) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 203 | { |
| 204 | struct connected *c; |
| 205 | struct interface *ifp; |
hasso | 1cd8084 | 2004-10-07 20:07:40 +0000 | [diff] [blame] | 206 | #ifdef EXTREME_DEBUG |
hasso | f891f44 | 2004-09-14 13:54:30 +0000 | [diff] [blame] | 207 | struct prefix *p; |
| 208 | u_char buf[BUFSIZ]; |
hasso | 1cd8084 | 2004-10-07 20:07:40 +0000 | [diff] [blame] | 209 | #endif /* EXTREME_DEBUG */ |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 210 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 211 | c = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_DELETE, |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 212 | zclient->ibuf, vrf_id); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 213 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 214 | if (c == NULL) |
| 215 | return 0; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 216 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 217 | ifp = c->ifp; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 218 | |
hasso | f891f44 | 2004-09-14 13:54:30 +0000 | [diff] [blame] | 219 | #ifdef EXTREME_DEBUG |
| 220 | p = c->address; |
| 221 | prefix2str (p, buf, BUFSIZ); |
| 222 | |
| 223 | if (p->family == AF_INET) |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 224 | zlog_debug ("disconnected IP address %s", buf); |
hasso | f891f44 | 2004-09-14 13:54:30 +0000 | [diff] [blame] | 225 | #ifdef HAVE_IPV6 |
| 226 | if (p->family == AF_INET6) |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 227 | zlog_debug ("disconnected IPv6 address %s", buf); |
hasso | f891f44 | 2004-09-14 13:54:30 +0000 | [diff] [blame] | 228 | #endif /* HAVE_IPV6 */ |
| 229 | #endif /* EXTREME_DEBUG */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 230 | |
hasso | b30c5e6 | 2004-12-29 20:06:41 +0000 | [diff] [blame] | 231 | if (if_is_operative (ifp)) |
| 232 | isis_circuit_del_addr (circuit_scan_by_ifp (ifp), c); |
hasso | f891f44 | 2004-09-14 13:54:30 +0000 | [diff] [blame] | 233 | connected_free (c); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 234 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 235 | return 0; |
| 236 | } |
| 237 | |
Olivier Dugeon | 4f59357 | 2016-04-19 19:03:05 +0200 | [diff] [blame] | 238 | static int |
| 239 | isis_zebra_link_params (int command, struct zclient *zclient, |
| 240 | zebra_size_t length) |
| 241 | { |
| 242 | struct interface *ifp; |
| 243 | |
| 244 | ifp = zebra_interface_link_params_read (zclient->ibuf); |
| 245 | |
| 246 | if (ifp == NULL) |
| 247 | return 0; |
| 248 | |
| 249 | /* Update TE TLV */ |
| 250 | isis_mpls_te_update(ifp); |
| 251 | |
| 252 | return 0; |
| 253 | } |
| 254 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 255 | static void |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 256 | isis_zebra_route_add_ipv4 (struct prefix *prefix, |
| 257 | struct isis_route_info *route_info) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 258 | { |
| 259 | u_char message, flags; |
| 260 | int psize; |
| 261 | struct stream *stream; |
| 262 | struct isis_nexthop *nexthop; |
| 263 | struct listnode *node; |
| 264 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 265 | if (CHECK_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED)) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 266 | return; |
| 267 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 268 | if (vrf_bitmap_check (zclient->redist[ZEBRA_ROUTE_ISIS], VRF_DEFAULT)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 269 | { |
| 270 | message = 0; |
| 271 | flags = 0; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 272 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 273 | SET_FLAG (message, ZAPI_MESSAGE_NEXTHOP); |
| 274 | SET_FLAG (message, ZAPI_MESSAGE_METRIC); |
hasso | 2097cd8 | 2003-12-23 11:51:08 +0000 | [diff] [blame] | 275 | #if 0 |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 276 | SET_FLAG (message, ZAPI_MESSAGE_DISTANCE); |
hasso | 2097cd8 | 2003-12-23 11:51:08 +0000 | [diff] [blame] | 277 | #endif |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 278 | |
| 279 | stream = zclient->obuf; |
| 280 | stream_reset (stream); |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 281 | zclient_create_header (stream, ZEBRA_IPV4_ROUTE_ADD, VRF_DEFAULT); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 282 | /* type */ |
| 283 | stream_putc (stream, ZEBRA_ROUTE_ISIS); |
| 284 | /* flags */ |
| 285 | stream_putc (stream, flags); |
| 286 | /* message */ |
| 287 | stream_putc (stream, message); |
Avneesh Sachdev | aa3b264 | 2012-04-11 23:56:03 -0700 | [diff] [blame] | 288 | /* SAFI */ |
| 289 | stream_putw (stream, SAFI_UNICAST); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 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 */ |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 298 | for (ALL_LIST_ELEMENTS_RO (route_info->nexthops, node, nexthop)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 299 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 300 | /* FIXME: can it be ? */ |
| 301 | if (nexthop->ip.s_addr != INADDR_ANY) |
| 302 | { |
| 303 | stream_putc (stream, ZEBRA_NEXTHOP_IPV4); |
| 304 | stream_put_in_addr (stream, &nexthop->ip); |
| 305 | } |
| 306 | else |
| 307 | { |
| 308 | stream_putc (stream, ZEBRA_NEXTHOP_IFINDEX); |
| 309 | stream_putl (stream, nexthop->ifindex); |
| 310 | } |
| 311 | } |
| 312 | #if 0 |
| 313 | if (CHECK_FLAG (message, ZAPI_MESSAGE_DISTANCE)) |
| 314 | stream_putc (stream, route_info->depth); |
| 315 | #endif |
| 316 | if (CHECK_FLAG (message, ZAPI_MESSAGE_METRIC)) |
| 317 | stream_putl (stream, route_info->cost); |
| 318 | |
| 319 | stream_putw_at (stream, 0, stream_get_endp (stream)); |
ajs | 634f9ea | 2005-04-11 15:51:40 +0000 | [diff] [blame] | 320 | zclient_send_message(zclient); |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 321 | SET_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED); |
| 322 | UNSET_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_RESYNC); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 323 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 324 | } |
| 325 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 326 | static void |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 327 | isis_zebra_route_del_ipv4 (struct prefix *prefix, |
| 328 | struct isis_route_info *route_info) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 329 | { |
| 330 | struct zapi_ipv4 api; |
| 331 | struct prefix_ipv4 prefix4; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 332 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 333 | if (vrf_bitmap_check (zclient->redist[ZEBRA_ROUTE_ISIS], VRF_DEFAULT)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 334 | { |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 335 | api.vrf_id = VRF_DEFAULT; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 336 | api.type = ZEBRA_ROUTE_ISIS; |
| 337 | api.flags = 0; |
| 338 | api.message = 0; |
Avneesh Sachdev | aa3b264 | 2012-04-11 23:56:03 -0700 | [diff] [blame] | 339 | api.safi = SAFI_UNICAST; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 340 | prefix4.family = AF_INET; |
| 341 | prefix4.prefixlen = prefix->prefixlen; |
| 342 | prefix4.prefix = prefix->u.prefix4; |
| 343 | zapi_ipv4_route (ZEBRA_IPV4_ROUTE_DELETE, zclient, &prefix4, &api); |
| 344 | } |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 345 | UNSET_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 346 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 347 | return; |
| 348 | } |
| 349 | |
| 350 | #ifdef HAVE_IPV6 |
David Lamparter | f50ee93 | 2015-03-04 07:13:38 +0100 | [diff] [blame] | 351 | static void |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 352 | isis_zebra_route_add_ipv6 (struct prefix *prefix, |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 353 | struct isis_route_info *route_info) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 354 | { |
| 355 | struct zapi_ipv6 api; |
| 356 | struct in6_addr **nexthop_list; |
Paul Jakma | 9099f9b | 2016-01-18 10:12:10 +0000 | [diff] [blame] | 357 | ifindex_t *ifindex_list; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 358 | struct isis_nexthop6 *nexthop6; |
| 359 | int i, size; |
| 360 | struct listnode *node; |
| 361 | struct prefix_ipv6 prefix6; |
| 362 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 363 | if (CHECK_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED)) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 364 | return; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 365 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 366 | api.vrf_id = VRF_DEFAULT; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 367 | api.type = ZEBRA_ROUTE_ISIS; |
| 368 | api.flags = 0; |
| 369 | api.message = 0; |
Avneesh Sachdev | aa3b264 | 2012-04-11 23:56:03 -0700 | [diff] [blame] | 370 | api.safi = SAFI_UNICAST; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 371 | SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP); |
| 372 | SET_FLAG (api.message, ZAPI_MESSAGE_IFINDEX); |
| 373 | SET_FLAG (api.message, ZAPI_MESSAGE_METRIC); |
| 374 | api.metric = route_info->cost; |
| 375 | #if 0 |
| 376 | SET_FLAG (api.message, ZAPI_MESSAGE_DISTANCE); |
| 377 | api.distance = route_info->depth; |
| 378 | #endif |
| 379 | api.nexthop_num = listcount (route_info->nexthops6); |
| 380 | api.ifindex_num = listcount (route_info->nexthops6); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 381 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 382 | /* allocate memory for nexthop_list */ |
| 383 | size = sizeof (struct isis_nexthop6 *) * listcount (route_info->nexthops6); |
| 384 | nexthop_list = (struct in6_addr **) XMALLOC (MTYPE_ISIS_TMP, size); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 385 | if (!nexthop_list) |
| 386 | { |
| 387 | zlog_err ("isis_zebra_add_route_ipv6: out of memory!"); |
| 388 | return; |
| 389 | } |
| 390 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 391 | /* allocate memory for ifindex_list */ |
| 392 | size = sizeof (unsigned int) * listcount (route_info->nexthops6); |
Paul Jakma | 9099f9b | 2016-01-18 10:12:10 +0000 | [diff] [blame] | 393 | ifindex_list = (ifindex_t *) XMALLOC (MTYPE_ISIS_TMP, size); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 394 | if (!ifindex_list) |
| 395 | { |
| 396 | zlog_err ("isis_zebra_add_route_ipv6: out of memory!"); |
| 397 | XFREE (MTYPE_ISIS_TMP, nexthop_list); |
| 398 | return; |
| 399 | } |
| 400 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 401 | /* for each nexthop */ |
| 402 | i = 0; |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 403 | for (ALL_LIST_ELEMENTS_RO (route_info->nexthops6, node, nexthop6)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 404 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 405 | if (!IN6_IS_ADDR_LINKLOCAL (&nexthop6->ip6) && |
| 406 | !IN6_IS_ADDR_UNSPECIFIED (&nexthop6->ip6)) |
| 407 | { |
| 408 | api.nexthop_num--; |
| 409 | api.ifindex_num--; |
| 410 | continue; |
| 411 | } |
| 412 | |
| 413 | nexthop_list[i] = &nexthop6->ip6; |
| 414 | ifindex_list[i] = nexthop6->ifindex; |
| 415 | i++; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 416 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 417 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 418 | api.nexthop = nexthop_list; |
| 419 | api.ifindex = ifindex_list; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 420 | |
| 421 | if (api.nexthop_num && api.ifindex_num) |
| 422 | { |
| 423 | prefix6.family = AF_INET6; |
| 424 | prefix6.prefixlen = prefix->prefixlen; |
| 425 | memcpy (&prefix6.prefix, &prefix->u.prefix6, sizeof (struct in6_addr)); |
| 426 | zapi_ipv6_route (ZEBRA_IPV6_ROUTE_ADD, zclient, &prefix6, &api); |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 427 | SET_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED); |
| 428 | UNSET_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_RESYNC); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 429 | } |
| 430 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 431 | XFREE (MTYPE_ISIS_TMP, nexthop_list); |
| 432 | XFREE (MTYPE_ISIS_TMP, ifindex_list); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 433 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 434 | return; |
| 435 | } |
| 436 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 437 | static void |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 438 | isis_zebra_route_del_ipv6 (struct prefix *prefix, |
| 439 | struct isis_route_info *route_info) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 440 | { |
| 441 | struct zapi_ipv6 api; |
| 442 | struct in6_addr **nexthop_list; |
Paul Jakma | 9099f9b | 2016-01-18 10:12:10 +0000 | [diff] [blame] | 443 | ifindex_t *ifindex_list; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 444 | struct isis_nexthop6 *nexthop6; |
| 445 | int i, size; |
| 446 | struct listnode *node; |
| 447 | struct prefix_ipv6 prefix6; |
| 448 | |
Christian Franke | 912aac4 | 2015-11-10 18:04:47 +0100 | [diff] [blame] | 449 | if (!CHECK_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED)) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 450 | return; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 451 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 452 | api.vrf_id = VRF_DEFAULT; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 453 | api.type = ZEBRA_ROUTE_ISIS; |
| 454 | api.flags = 0; |
| 455 | api.message = 0; |
Avneesh Sachdev | aa3b264 | 2012-04-11 23:56:03 -0700 | [diff] [blame] | 456 | api.safi = SAFI_UNICAST; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 457 | SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP); |
| 458 | SET_FLAG (api.message, ZAPI_MESSAGE_IFINDEX); |
| 459 | api.nexthop_num = listcount (route_info->nexthops6); |
| 460 | api.ifindex_num = listcount (route_info->nexthops6); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 461 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 462 | /* allocate memory for nexthop_list */ |
| 463 | size = sizeof (struct isis_nexthop6 *) * listcount (route_info->nexthops6); |
| 464 | nexthop_list = (struct in6_addr **) XMALLOC (MTYPE_ISIS_TMP, size); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 465 | if (!nexthop_list) |
| 466 | { |
| 467 | zlog_err ("isis_zebra_route_del_ipv6: out of memory!"); |
| 468 | return; |
| 469 | } |
| 470 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 471 | /* allocate memory for ifindex_list */ |
| 472 | size = sizeof (unsigned int) * listcount (route_info->nexthops6); |
Paul Jakma | 9099f9b | 2016-01-18 10:12:10 +0000 | [diff] [blame] | 473 | ifindex_list = (ifindex_t *) XMALLOC (MTYPE_ISIS_TMP, size); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 474 | if (!ifindex_list) |
| 475 | { |
| 476 | zlog_err ("isis_zebra_route_del_ipv6: out of memory!"); |
| 477 | XFREE (MTYPE_ISIS_TMP, nexthop_list); |
| 478 | return; |
| 479 | } |
| 480 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 481 | /* for each nexthop */ |
| 482 | i = 0; |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 483 | for (ALL_LIST_ELEMENTS_RO (route_info->nexthops6, node, nexthop6)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 484 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 485 | if (!IN6_IS_ADDR_LINKLOCAL (&nexthop6->ip6) && |
| 486 | !IN6_IS_ADDR_UNSPECIFIED (&nexthop6->ip6)) |
| 487 | { |
| 488 | api.nexthop_num--; |
| 489 | api.ifindex_num--; |
| 490 | continue; |
| 491 | } |
| 492 | |
| 493 | nexthop_list[i] = &nexthop6->ip6; |
| 494 | ifindex_list[i] = nexthop6->ifindex; |
| 495 | i++; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 496 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 497 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 498 | api.nexthop = nexthop_list; |
| 499 | api.ifindex = ifindex_list; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 500 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 501 | if (api.nexthop_num && api.ifindex_num) |
| 502 | { |
| 503 | prefix6.family = AF_INET6; |
| 504 | prefix6.prefixlen = prefix->prefixlen; |
| 505 | memcpy (&prefix6.prefix, &prefix->u.prefix6, sizeof (struct in6_addr)); |
| 506 | zapi_ipv6_route (ZEBRA_IPV6_ROUTE_DELETE, zclient, &prefix6, &api); |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 507 | UNSET_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | XFREE (MTYPE_ISIS_TMP, nexthop_list); |
| 511 | XFREE (MTYPE_ISIS_TMP, ifindex_list); |
| 512 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 513 | |
| 514 | #endif /* HAVE_IPV6 */ |
| 515 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 516 | void |
| 517 | isis_zebra_route_update (struct prefix *prefix, |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 518 | struct isis_route_info *route_info) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 519 | { |
| 520 | if (zclient->sock < 0) |
| 521 | return; |
| 522 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 523 | if (!vrf_bitmap_check (zclient->redist[ZEBRA_ROUTE_ISIS], VRF_DEFAULT)) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 524 | return; |
| 525 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 526 | if (CHECK_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ACTIVE)) |
| 527 | { |
| 528 | if (prefix->family == AF_INET) |
| 529 | isis_zebra_route_add_ipv4 (prefix, route_info); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 530 | #ifdef HAVE_IPV6 |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 531 | else if (prefix->family == AF_INET6) |
| 532 | isis_zebra_route_add_ipv6 (prefix, route_info); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 533 | #endif /* HAVE_IPV6 */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 534 | } |
| 535 | else |
| 536 | { |
| 537 | if (prefix->family == AF_INET) |
| 538 | isis_zebra_route_del_ipv4 (prefix, route_info); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 539 | #ifdef HAVE_IPV6 |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 540 | else if (prefix->family == AF_INET6) |
| 541 | isis_zebra_route_del_ipv6 (prefix, route_info); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 542 | #endif /* HAVE_IPV6 */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 543 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 544 | return; |
| 545 | } |
| 546 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 547 | static int |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 548 | isis_zebra_read_ipv4 (int command, struct zclient *zclient, |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 549 | zebra_size_t length, vrf_id_t vrf_id) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 550 | { |
| 551 | struct stream *stream; |
| 552 | struct zapi_ipv4 api; |
| 553 | struct prefix_ipv4 p; |
Christian Franke | acf9865 | 2015-11-12 14:24:22 +0100 | [diff] [blame] | 554 | struct prefix *p_generic = (struct prefix*)&p; |
David Lamparter | f50ee93 | 2015-03-04 07:13:38 +0100 | [diff] [blame] | 555 | unsigned long ifindex __attribute__ ((unused)); |
| 556 | struct in_addr nexthop __attribute__ ((unused)); |
Donald Sharp | 5e57b5f | 2016-03-11 16:28:34 -0500 | [diff] [blame] | 557 | unsigned char plength = 0; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 558 | |
| 559 | stream = zclient->ibuf; |
Christian Franke | acf9865 | 2015-11-12 14:24:22 +0100 | [diff] [blame] | 560 | memset(&api, 0, sizeof(api)); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 561 | memset (&p, 0, sizeof (struct prefix_ipv4)); |
Christian Franke | acf9865 | 2015-11-12 14:24:22 +0100 | [diff] [blame] | 562 | memset(&nexthop, 0, sizeof(nexthop)); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 563 | ifindex = 0; |
| 564 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 565 | api.type = stream_getc (stream); |
| 566 | api.flags = stream_getc (stream); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 567 | api.message = stream_getc (stream); |
| 568 | |
| 569 | p.family = AF_INET; |
Donald Sharp | 5e57b5f | 2016-03-11 16:28:34 -0500 | [diff] [blame] | 570 | plength = stream_getc (stream); |
| 571 | p.prefixlen = MIN(IPV4_MAX_PREFIXLEN, plength); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 572 | stream_get (&p.prefix, stream, PSIZE (p.prefixlen)); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 573 | |
| 574 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP)) |
| 575 | { |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 576 | api.nexthop_num = stream_getc (stream); |
| 577 | nexthop.s_addr = stream_get_ipv4 (stream); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 578 | } |
| 579 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_IFINDEX)) |
| 580 | { |
| 581 | api.ifindex_num = stream_getc (stream); |
| 582 | ifindex = stream_getl (stream); |
| 583 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 584 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE)) |
| 585 | api.distance = stream_getc (stream); |
| 586 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC)) |
| 587 | api.metric = stream_getl (stream); |
Christian Franke | acf9865 | 2015-11-12 14:24:22 +0100 | [diff] [blame] | 588 | |
| 589 | /* |
| 590 | * Avoid advertising a false default reachability. (A default |
| 591 | * route installed by IS-IS gets redistributed from zebra back |
| 592 | * into IS-IS causing us to start advertising default reachabity |
| 593 | * without this check) |
| 594 | */ |
| 595 | if (p.prefixlen == 0 && api.type == ZEBRA_ROUTE_ISIS) |
| 596 | command = ZEBRA_IPV4_ROUTE_DELETE; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 597 | |
| 598 | if (command == ZEBRA_IPV4_ROUTE_ADD) |
Christian Franke | acf9865 | 2015-11-12 14:24:22 +0100 | [diff] [blame] | 599 | isis_redist_add(api.type, p_generic, api.distance, api.metric); |
| 600 | else |
| 601 | isis_redist_delete(api.type, p_generic); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 602 | |
| 603 | return 0; |
| 604 | } |
| 605 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 606 | static int |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 607 | isis_zebra_read_ipv6 (int command, struct zclient *zclient, |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 608 | zebra_size_t length, vrf_id_t vrf_id) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 609 | { |
Christian Franke | acf9865 | 2015-11-12 14:24:22 +0100 | [diff] [blame] | 610 | struct stream *stream; |
| 611 | struct zapi_ipv6 api; |
| 612 | struct prefix_ipv6 p; |
| 613 | struct prefix *p_generic = (struct prefix*)&p; |
| 614 | struct in6_addr nexthop; |
| 615 | unsigned long ifindex __attribute__((unused)); |
| 616 | |
| 617 | stream = zclient->ibuf; |
| 618 | memset(&api, 0, sizeof(api)); |
| 619 | memset(&p, 0, sizeof(struct prefix_ipv6)); |
| 620 | memset(&nexthop, 0, sizeof(nexthop)); |
| 621 | ifindex = 0; |
| 622 | |
| 623 | api.type = stream_getc(stream); |
| 624 | api.flags = stream_getc(stream); |
| 625 | api.message = stream_getc(stream); |
| 626 | |
| 627 | p.family = AF_INET6; |
| 628 | p.prefixlen = stream_getc(stream); |
| 629 | stream_get(&p.prefix, stream, PSIZE(p.prefixlen)); |
| 630 | |
| 631 | if (CHECK_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP)) |
| 632 | { |
| 633 | api.nexthop_num = stream_getc(stream); /* this is always 1 */ |
| 634 | stream_get(&nexthop, stream, sizeof(nexthop)); |
| 635 | } |
| 636 | if (CHECK_FLAG(api.message, ZAPI_MESSAGE_IFINDEX)) |
| 637 | { |
| 638 | api.ifindex_num = stream_getc(stream); |
| 639 | ifindex = stream_getl(stream); |
| 640 | } |
| 641 | if (CHECK_FLAG(api.message, ZAPI_MESSAGE_DISTANCE)) |
| 642 | api.distance = stream_getc(stream); |
| 643 | if (CHECK_FLAG(api.message, ZAPI_MESSAGE_METRIC)) |
| 644 | api.metric = stream_getl(stream); |
| 645 | |
| 646 | /* |
| 647 | * Avoid advertising a false default reachability. (A default |
| 648 | * route installed by IS-IS gets redistributed from zebra back |
| 649 | * into IS-IS causing us to start advertising default reachabity |
| 650 | * without this check) |
| 651 | */ |
| 652 | if (p.prefixlen == 0 && api.type == ZEBRA_ROUTE_ISIS) |
| 653 | command = ZEBRA_IPV6_ROUTE_DELETE; |
| 654 | |
| 655 | if (command == ZEBRA_IPV6_ROUTE_ADD) |
| 656 | isis_redist_add(api.type, p_generic, api.distance, api.metric); |
| 657 | else |
| 658 | isis_redist_delete(api.type, p_generic); |
| 659 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 660 | return 0; |
| 661 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 662 | |
| 663 | int |
| 664 | isis_distribute_list_update (int routetype) |
| 665 | { |
| 666 | return 0; |
| 667 | } |
| 668 | |
Christian Franke | acf9865 | 2015-11-12 14:24:22 +0100 | [diff] [blame] | 669 | void |
| 670 | isis_zebra_redistribute_set(int type) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 671 | { |
Christian Franke | acf9865 | 2015-11-12 14:24:22 +0100 | [diff] [blame] | 672 | if (type == DEFAULT_ROUTE) |
| 673 | zclient_redistribute_default(ZEBRA_REDISTRIBUTE_DEFAULT_ADD, zclient, VRF_DEFAULT); |
| 674 | else |
| 675 | zclient_redistribute(ZEBRA_REDISTRIBUTE_ADD, zclient, type, VRF_DEFAULT); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 676 | } |
Christian Franke | acf9865 | 2015-11-12 14:24:22 +0100 | [diff] [blame] | 677 | |
| 678 | void |
| 679 | isis_zebra_redistribute_unset(int type) |
| 680 | { |
| 681 | if (type == DEFAULT_ROUTE) |
| 682 | zclient_redistribute_default(ZEBRA_REDISTRIBUTE_DEFAULT_DELETE, zclient, VRF_DEFAULT); |
| 683 | else |
| 684 | zclient_redistribute(ZEBRA_REDISTRIBUTE_DELETE, zclient, type, VRF_DEFAULT); |
| 685 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 686 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 687 | static void |
| 688 | isis_zebra_connected (struct zclient *zclient) |
| 689 | { |
| 690 | zclient_send_requests (zclient, VRF_DEFAULT); |
| 691 | } |
| 692 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 693 | void |
Donald Sharp | 7125293 | 2015-09-24 09:25:19 -0400 | [diff] [blame] | 694 | isis_zebra_init (struct thread_master *master) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 695 | { |
Donald Sharp | 7125293 | 2015-09-24 09:25:19 -0400 | [diff] [blame] | 696 | zclient = zclient_new (master); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 697 | zclient_init (zclient, ZEBRA_ROUTE_ISIS); |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 698 | zclient->zebra_connected = isis_zebra_connected; |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 699 | zclient->router_id_update = isis_router_id_update_zebra; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 700 | zclient->interface_add = isis_zebra_if_add; |
| 701 | zclient->interface_delete = isis_zebra_if_del; |
| 702 | zclient->interface_up = isis_zebra_if_state_up; |
| 703 | zclient->interface_down = isis_zebra_if_state_down; |
| 704 | zclient->interface_address_add = isis_zebra_if_address_add; |
| 705 | zclient->interface_address_delete = isis_zebra_if_address_del; |
Olivier Dugeon | 4f59357 | 2016-04-19 19:03:05 +0200 | [diff] [blame] | 706 | zclient->interface_link_params = isis_zebra_link_params; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 707 | zclient->ipv4_route_add = isis_zebra_read_ipv4; |
| 708 | zclient->ipv4_route_delete = isis_zebra_read_ipv4; |
| 709 | #ifdef HAVE_IPV6 |
| 710 | zclient->ipv6_route_add = isis_zebra_read_ipv6; |
| 711 | zclient->ipv6_route_delete = isis_zebra_read_ipv6; |
| 712 | #endif /* HAVE_IPV6 */ |
| 713 | |
| 714 | return; |
| 715 | } |