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