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)); |
Donald Sharp | 5e57b5f | 2016-03-11 16:28:34 -0500 | [diff] [blame] | 532 | unsigned char plength = 0; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 533 | |
| 534 | stream = zclient->ibuf; |
Christian Franke | acf9865 | 2015-11-12 14:24:22 +0100 | [diff] [blame] | 535 | memset(&api, 0, sizeof(api)); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 536 | memset (&p, 0, sizeof (struct prefix_ipv4)); |
Christian Franke | acf9865 | 2015-11-12 14:24:22 +0100 | [diff] [blame] | 537 | memset(&nexthop, 0, sizeof(nexthop)); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 538 | ifindex = 0; |
| 539 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 540 | api.type = stream_getc (stream); |
| 541 | api.flags = stream_getc (stream); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 542 | api.message = stream_getc (stream); |
| 543 | |
| 544 | p.family = AF_INET; |
Donald Sharp | 5e57b5f | 2016-03-11 16:28:34 -0500 | [diff] [blame] | 545 | plength = stream_getc (stream); |
| 546 | p.prefixlen = MIN(IPV4_MAX_PREFIXLEN, plength); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 547 | stream_get (&p.prefix, stream, PSIZE (p.prefixlen)); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 548 | |
| 549 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP)) |
| 550 | { |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 551 | api.nexthop_num = stream_getc (stream); |
| 552 | nexthop.s_addr = stream_get_ipv4 (stream); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 553 | } |
| 554 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_IFINDEX)) |
| 555 | { |
| 556 | api.ifindex_num = stream_getc (stream); |
| 557 | ifindex = stream_getl (stream); |
| 558 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 559 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE)) |
| 560 | api.distance = stream_getc (stream); |
| 561 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC)) |
| 562 | api.metric = stream_getl (stream); |
Christian Franke | acf9865 | 2015-11-12 14:24:22 +0100 | [diff] [blame] | 563 | |
| 564 | /* |
| 565 | * Avoid advertising a false default reachability. (A default |
| 566 | * route installed by IS-IS gets redistributed from zebra back |
| 567 | * into IS-IS causing us to start advertising default reachabity |
| 568 | * without this check) |
| 569 | */ |
| 570 | if (p.prefixlen == 0 && api.type == ZEBRA_ROUTE_ISIS) |
| 571 | command = ZEBRA_IPV4_ROUTE_DELETE; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 572 | |
| 573 | if (command == ZEBRA_IPV4_ROUTE_ADD) |
Christian Franke | acf9865 | 2015-11-12 14:24:22 +0100 | [diff] [blame] | 574 | isis_redist_add(api.type, p_generic, api.distance, api.metric); |
| 575 | else |
| 576 | isis_redist_delete(api.type, p_generic); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 577 | |
| 578 | return 0; |
| 579 | } |
| 580 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 581 | static int |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 582 | isis_zebra_read_ipv6 (int command, struct zclient *zclient, |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 583 | zebra_size_t length, vrf_id_t vrf_id) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 584 | { |
Christian Franke | acf9865 | 2015-11-12 14:24:22 +0100 | [diff] [blame] | 585 | struct stream *stream; |
| 586 | struct zapi_ipv6 api; |
| 587 | struct prefix_ipv6 p; |
| 588 | struct prefix *p_generic = (struct prefix*)&p; |
| 589 | struct in6_addr nexthop; |
| 590 | unsigned long ifindex __attribute__((unused)); |
| 591 | |
| 592 | stream = zclient->ibuf; |
| 593 | memset(&api, 0, sizeof(api)); |
| 594 | memset(&p, 0, sizeof(struct prefix_ipv6)); |
| 595 | memset(&nexthop, 0, sizeof(nexthop)); |
| 596 | ifindex = 0; |
| 597 | |
| 598 | api.type = stream_getc(stream); |
| 599 | api.flags = stream_getc(stream); |
| 600 | api.message = stream_getc(stream); |
| 601 | |
| 602 | p.family = AF_INET6; |
| 603 | p.prefixlen = stream_getc(stream); |
| 604 | stream_get(&p.prefix, stream, PSIZE(p.prefixlen)); |
| 605 | |
| 606 | if (CHECK_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP)) |
| 607 | { |
| 608 | api.nexthop_num = stream_getc(stream); /* this is always 1 */ |
| 609 | stream_get(&nexthop, stream, sizeof(nexthop)); |
| 610 | } |
| 611 | if (CHECK_FLAG(api.message, ZAPI_MESSAGE_IFINDEX)) |
| 612 | { |
| 613 | api.ifindex_num = stream_getc(stream); |
| 614 | ifindex = stream_getl(stream); |
| 615 | } |
| 616 | if (CHECK_FLAG(api.message, ZAPI_MESSAGE_DISTANCE)) |
| 617 | api.distance = stream_getc(stream); |
| 618 | if (CHECK_FLAG(api.message, ZAPI_MESSAGE_METRIC)) |
| 619 | api.metric = stream_getl(stream); |
| 620 | |
| 621 | /* |
| 622 | * Avoid advertising a false default reachability. (A default |
| 623 | * route installed by IS-IS gets redistributed from zebra back |
| 624 | * into IS-IS causing us to start advertising default reachabity |
| 625 | * without this check) |
| 626 | */ |
| 627 | if (p.prefixlen == 0 && api.type == ZEBRA_ROUTE_ISIS) |
| 628 | command = ZEBRA_IPV6_ROUTE_DELETE; |
| 629 | |
| 630 | if (command == ZEBRA_IPV6_ROUTE_ADD) |
| 631 | isis_redist_add(api.type, p_generic, api.distance, api.metric); |
| 632 | else |
| 633 | isis_redist_delete(api.type, p_generic); |
| 634 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 635 | return 0; |
| 636 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 637 | |
| 638 | int |
| 639 | isis_distribute_list_update (int routetype) |
| 640 | { |
| 641 | return 0; |
| 642 | } |
| 643 | |
Christian Franke | acf9865 | 2015-11-12 14:24:22 +0100 | [diff] [blame] | 644 | void |
| 645 | isis_zebra_redistribute_set(int type) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 646 | { |
Christian Franke | acf9865 | 2015-11-12 14:24:22 +0100 | [diff] [blame] | 647 | if (type == DEFAULT_ROUTE) |
| 648 | zclient_redistribute_default(ZEBRA_REDISTRIBUTE_DEFAULT_ADD, zclient, VRF_DEFAULT); |
| 649 | else |
| 650 | zclient_redistribute(ZEBRA_REDISTRIBUTE_ADD, zclient, type, VRF_DEFAULT); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 651 | } |
Christian Franke | acf9865 | 2015-11-12 14:24:22 +0100 | [diff] [blame] | 652 | |
| 653 | void |
| 654 | isis_zebra_redistribute_unset(int type) |
| 655 | { |
| 656 | if (type == DEFAULT_ROUTE) |
| 657 | zclient_redistribute_default(ZEBRA_REDISTRIBUTE_DEFAULT_DELETE, zclient, VRF_DEFAULT); |
| 658 | else |
| 659 | zclient_redistribute(ZEBRA_REDISTRIBUTE_DELETE, zclient, type, VRF_DEFAULT); |
| 660 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 661 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 662 | static void |
| 663 | isis_zebra_connected (struct zclient *zclient) |
| 664 | { |
| 665 | zclient_send_requests (zclient, VRF_DEFAULT); |
| 666 | } |
| 667 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 668 | void |
Donald Sharp | 7125293 | 2015-09-24 09:25:19 -0400 | [diff] [blame] | 669 | isis_zebra_init (struct thread_master *master) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 670 | { |
Donald Sharp | 7125293 | 2015-09-24 09:25:19 -0400 | [diff] [blame] | 671 | zclient = zclient_new (master); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 672 | zclient_init (zclient, ZEBRA_ROUTE_ISIS); |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 673 | zclient->zebra_connected = isis_zebra_connected; |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 674 | zclient->router_id_update = isis_router_id_update_zebra; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 675 | zclient->interface_add = isis_zebra_if_add; |
| 676 | zclient->interface_delete = isis_zebra_if_del; |
| 677 | zclient->interface_up = isis_zebra_if_state_up; |
| 678 | zclient->interface_down = isis_zebra_if_state_down; |
| 679 | zclient->interface_address_add = isis_zebra_if_address_add; |
| 680 | zclient->interface_address_delete = isis_zebra_if_address_del; |
| 681 | zclient->ipv4_route_add = isis_zebra_read_ipv4; |
| 682 | zclient->ipv4_route_delete = isis_zebra_read_ipv4; |
| 683 | #ifdef HAVE_IPV6 |
| 684 | zclient->ipv6_route_add = isis_zebra_read_ipv6; |
| 685 | zclient->ipv6_route_delete = isis_zebra_read_ipv6; |
| 686 | #endif /* HAVE_IPV6 */ |
| 687 | |
| 688 | return; |
| 689 | } |