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 |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms of the GNU General Public Licenseas published by the Free |
| 10 | * Software Foundation; either version 2 of the License, or (at your option) |
| 11 | * any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful,but WITHOUT |
| 14 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 16 | * more details. |
| 17 | |
| 18 | * You should have received a copy of the GNU General Public License along |
| 19 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 20 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 21 | */ |
| 22 | |
| 23 | #include <zebra.h> |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 24 | |
| 25 | #include "thread.h" |
| 26 | #include "command.h" |
| 27 | #include "memory.h" |
| 28 | #include "log.h" |
| 29 | #include "if.h" |
| 30 | #include "network.h" |
| 31 | #include "prefix.h" |
| 32 | #include "zclient.h" |
| 33 | #include "stream.h" |
| 34 | #include "linklist.h" |
| 35 | |
| 36 | #include "isisd/isis_constants.h" |
| 37 | #include "isisd/isis_common.h" |
| 38 | #include "isisd/isis_circuit.h" |
| 39 | #include "isisd/isis_csm.h" |
| 40 | #include "isisd/isis_route.h" |
| 41 | #include "isisd/isis_zebra.h" |
| 42 | |
| 43 | struct zclient *zclient = NULL; |
| 44 | |
| 45 | extern struct thread_master *master; |
| 46 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 47 | int |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 48 | isis_zebra_if_add (int command, struct zclient *zclient, zebra_size_t length) |
| 49 | { |
| 50 | struct interface *ifp; |
| 51 | |
| 52 | ifp = zebra_interface_add_read (zclient->ibuf); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 53 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 54 | |
| 55 | zlog_info ("Zebra I/F add: %s index %d flags %ld metric %d mtu %d", |
| 56 | ifp->name, ifp->ifindex, ifp->flags, ifp->metric, ifp->mtu); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 57 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 58 | if (if_is_up (ifp)) |
| 59 | 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] | 60 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 61 | return 0; |
| 62 | } |
| 63 | |
| 64 | int |
| 65 | isis_zebra_if_del (int command, struct zclient *zclient, zebra_size_t length) |
| 66 | { |
| 67 | struct interface *ifp; |
| 68 | struct stream *s; |
| 69 | |
| 70 | s = zclient->ibuf; |
| 71 | ifp = zebra_interface_state_read (s); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 72 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 73 | if (!ifp) |
| 74 | return 0; |
| 75 | |
| 76 | if (if_is_up (ifp)) |
| 77 | zlog_warn ("Zebra: got delete of %s, but interface is still up", |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 78 | ifp->name); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 79 | |
| 80 | zlog_info ("Zebra I/F delete: %s index %d flags %ld metric %d mtu %d", |
| 81 | ifp->name, ifp->ifindex, ifp->flags, ifp->metric, ifp->mtu); |
| 82 | |
| 83 | if_delete (ifp); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 84 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 85 | isis_csm_state_change (IF_DOWN_FROM_Z, circuit_scan_by_ifp (ifp), ifp); |
| 86 | |
| 87 | return 0; |
| 88 | } |
| 89 | |
| 90 | struct interface * |
| 91 | zebra_interface_if_lookup (struct stream *s) |
| 92 | { |
| 93 | struct interface *ifp; |
| 94 | u_char ifname_tmp[INTERFACE_NAMSIZ]; |
| 95 | |
| 96 | /* Read interface name. */ |
| 97 | stream_get (ifname_tmp, s, INTERFACE_NAMSIZ); |
| 98 | |
| 99 | /* Lookup this by interface index. */ |
| 100 | ifp = if_lookup_by_name (ifname_tmp); |
| 101 | |
| 102 | /* If such interface does not exist, indicate an error */ |
| 103 | if (!ifp) |
| 104 | return NULL; |
| 105 | |
| 106 | return ifp; |
| 107 | } |
| 108 | |
| 109 | void |
| 110 | zebra_interface_if_set_value (struct stream *s, struct interface *ifp) |
| 111 | { |
| 112 | /* Read interface's index. */ |
| 113 | ifp->ifindex = stream_getl (s); |
| 114 | |
| 115 | /* Read interface's value. */ |
| 116 | ifp->flags = stream_getl (s); |
| 117 | ifp->metric = stream_getl (s); |
| 118 | ifp->mtu = stream_getl (s); |
| 119 | ifp->bandwidth = stream_getl (s); |
| 120 | } |
| 121 | |
| 122 | int |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 123 | isis_zebra_if_state_up (int command, struct zclient *zclient, |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 124 | zebra_size_t length) |
| 125 | { |
| 126 | struct interface *ifp; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 127 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 128 | ifp = zebra_interface_if_lookup (zclient->ibuf); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 129 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 130 | if (!ifp) |
| 131 | return 0; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 132 | |
| 133 | if (if_is_up (ifp)) |
| 134 | { |
| 135 | zebra_interface_if_set_value (zclient->ibuf, ifp); |
| 136 | isis_circuit_update_params (circuit_scan_by_ifp (ifp), ifp); |
| 137 | return 0; |
| 138 | } |
| 139 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 140 | zebra_interface_if_set_value (zclient->ibuf, ifp); |
| 141 | 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] | 142 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 143 | return 0; |
| 144 | } |
| 145 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 146 | int |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 147 | isis_zebra_if_state_down (int command, struct zclient *zclient, |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 148 | zebra_size_t length) |
| 149 | { |
| 150 | struct interface *ifp; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 151 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 152 | ifp = zebra_interface_if_lookup (zclient->ibuf); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 153 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 154 | if (ifp == NULL) |
| 155 | return 0; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 156 | |
| 157 | if (if_is_up (ifp)) |
| 158 | { |
| 159 | zebra_interface_if_set_value (zclient->ibuf, ifp); |
| 160 | isis_csm_state_change (IF_DOWN_FROM_Z, circuit_scan_by_ifp (ifp), ifp); |
| 161 | } |
| 162 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 163 | return 0; |
| 164 | } |
| 165 | |
| 166 | int |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 167 | isis_zebra_if_address_add (int command, struct zclient *zclient, |
| 168 | zebra_size_t length) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 169 | { |
| 170 | struct connected *c; |
| 171 | struct prefix *p; |
| 172 | u_char buf[BUFSIZ]; |
| 173 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 174 | c = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_ADD, |
| 175 | zclient->ibuf); |
| 176 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 177 | if (c == NULL) |
| 178 | return 0; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 179 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 180 | p = c->address; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 181 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 182 | prefix2str (p, buf, BUFSIZ); |
| 183 | #ifdef EXTREME_DEBUG |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 184 | if (p->family == AF_INET) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 185 | zlog_info ("connected IP address %s", buf); |
| 186 | #ifdef HAVE_IPV6 |
| 187 | if (p->family == AF_INET6) |
| 188 | zlog_info ("connected IPv6 address %s", buf); |
| 189 | #endif /* HAVE_IPV6 */ |
| 190 | #endif /* EXTREME_DEBUG */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 191 | isis_circuit_add_addr (circuit_scan_by_ifp (c->ifp), c); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 192 | |
| 193 | return 0; |
| 194 | } |
| 195 | |
| 196 | int |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 197 | isis_zebra_if_address_del (int command, struct zclient *client, |
| 198 | zebra_size_t length) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 199 | { |
| 200 | struct connected *c; |
| 201 | struct interface *ifp; |
hasso | f891f44 | 2004-09-14 13:54:30 +0000 | [diff] [blame^] | 202 | struct prefix *p; |
| 203 | u_char buf[BUFSIZ]; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 204 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 205 | c = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_DELETE, |
| 206 | zclient->ibuf); |
| 207 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 208 | if (c == NULL) |
| 209 | return 0; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 210 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 211 | ifp = c->ifp; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 212 | |
hasso | f891f44 | 2004-09-14 13:54:30 +0000 | [diff] [blame^] | 213 | #ifdef EXTREME_DEBUG |
| 214 | p = c->address; |
| 215 | prefix2str (p, buf, BUFSIZ); |
| 216 | |
| 217 | if (p->family == AF_INET) |
| 218 | zlog_info ("disconnected IP address %s", buf); |
| 219 | #ifdef HAVE_IPV6 |
| 220 | if (p->family == AF_INET6) |
| 221 | zlog_info ("disconnected IPv6 address %s", buf); |
| 222 | #endif /* HAVE_IPV6 */ |
| 223 | #endif /* EXTREME_DEBUG */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 224 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 225 | isis_circuit_del_addr (circuit_scan_by_ifp (ifp), c); |
hasso | f891f44 | 2004-09-14 13:54:30 +0000 | [diff] [blame^] | 226 | connected_free (c); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 227 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 228 | return 0; |
| 229 | } |
| 230 | |
| 231 | void |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 232 | isis_zebra_route_add_ipv4 (struct prefix *prefix, |
| 233 | struct isis_route_info *route_info) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 234 | { |
| 235 | u_char message, flags; |
| 236 | int psize; |
| 237 | struct stream *stream; |
| 238 | struct isis_nexthop *nexthop; |
| 239 | struct listnode *node; |
| 240 | |
| 241 | if (CHECK_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNC)) |
| 242 | return; |
| 243 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 244 | if (zclient->redist[ZEBRA_ROUTE_ISIS]) |
| 245 | { |
| 246 | message = 0; |
| 247 | flags = 0; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 248 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 249 | SET_FLAG (message, ZAPI_MESSAGE_NEXTHOP); |
| 250 | SET_FLAG (message, ZAPI_MESSAGE_METRIC); |
hasso | 2097cd8 | 2003-12-23 11:51:08 +0000 | [diff] [blame] | 251 | #if 0 |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 252 | SET_FLAG (message, ZAPI_MESSAGE_DISTANCE); |
hasso | 2097cd8 | 2003-12-23 11:51:08 +0000 | [diff] [blame] | 253 | #endif |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 254 | |
| 255 | stream = zclient->obuf; |
| 256 | stream_reset (stream); |
| 257 | /* Length place holder. */ |
| 258 | stream_putw (stream, 0); |
| 259 | /* command */ |
| 260 | stream_putc (stream, ZEBRA_IPV4_ROUTE_ADD); |
| 261 | /* type */ |
| 262 | stream_putc (stream, ZEBRA_ROUTE_ISIS); |
| 263 | /* flags */ |
| 264 | stream_putc (stream, flags); |
| 265 | /* message */ |
| 266 | stream_putc (stream, message); |
| 267 | /* prefix information */ |
| 268 | psize = PSIZE (prefix->prefixlen); |
| 269 | stream_putc (stream, prefix->prefixlen); |
| 270 | stream_write (stream, (u_char *) & prefix->u.prefix4, psize); |
| 271 | |
| 272 | stream_putc (stream, listcount (route_info->nexthops)); |
| 273 | |
| 274 | /* Nexthop, ifindex, distance and metric information */ |
| 275 | for (node = listhead (route_info->nexthops); node; nextnode (node)) |
| 276 | { |
| 277 | nexthop = getdata (node); |
| 278 | /* FIXME: can it be ? */ |
| 279 | if (nexthop->ip.s_addr != INADDR_ANY) |
| 280 | { |
| 281 | stream_putc (stream, ZEBRA_NEXTHOP_IPV4); |
| 282 | stream_put_in_addr (stream, &nexthop->ip); |
| 283 | } |
| 284 | else |
| 285 | { |
| 286 | stream_putc (stream, ZEBRA_NEXTHOP_IFINDEX); |
| 287 | stream_putl (stream, nexthop->ifindex); |
| 288 | } |
| 289 | } |
| 290 | #if 0 |
| 291 | if (CHECK_FLAG (message, ZAPI_MESSAGE_DISTANCE)) |
| 292 | stream_putc (stream, route_info->depth); |
| 293 | #endif |
| 294 | if (CHECK_FLAG (message, ZAPI_MESSAGE_METRIC)) |
| 295 | stream_putl (stream, route_info->cost); |
| 296 | |
| 297 | stream_putw_at (stream, 0, stream_get_endp (stream)); |
| 298 | writen (zclient->sock, stream->data, stream_get_endp (stream)); |
| 299 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | void |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 303 | isis_zebra_route_del_ipv4 (struct prefix *prefix, |
| 304 | struct isis_route_info *route_info) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 305 | { |
| 306 | struct zapi_ipv4 api; |
| 307 | struct prefix_ipv4 prefix4; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 308 | |
| 309 | if (zclient->redist[ZEBRA_ROUTE_ISIS]) |
| 310 | { |
| 311 | api.type = ZEBRA_ROUTE_ISIS; |
| 312 | api.flags = 0; |
| 313 | api.message = 0; |
| 314 | prefix4.family = AF_INET; |
| 315 | prefix4.prefixlen = prefix->prefixlen; |
| 316 | prefix4.prefix = prefix->u.prefix4; |
| 317 | zapi_ipv4_route (ZEBRA_IPV4_ROUTE_DELETE, zclient, &prefix4, &api); |
| 318 | } |
| 319 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 320 | return; |
| 321 | } |
| 322 | |
| 323 | #ifdef HAVE_IPV6 |
| 324 | void |
| 325 | isis_zebra_route_add_ipv6 (struct prefix *prefix, |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 326 | struct isis_route_info *route_info) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 327 | { |
| 328 | struct zapi_ipv6 api; |
| 329 | struct in6_addr **nexthop_list; |
| 330 | unsigned int *ifindex_list; |
| 331 | struct isis_nexthop6 *nexthop6; |
| 332 | int i, size; |
| 333 | struct listnode *node; |
| 334 | struct prefix_ipv6 prefix6; |
| 335 | |
| 336 | if (CHECK_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNC)) |
| 337 | return; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 338 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 339 | api.type = ZEBRA_ROUTE_ISIS; |
| 340 | api.flags = 0; |
| 341 | api.message = 0; |
| 342 | SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP); |
| 343 | SET_FLAG (api.message, ZAPI_MESSAGE_IFINDEX); |
| 344 | SET_FLAG (api.message, ZAPI_MESSAGE_METRIC); |
| 345 | api.metric = route_info->cost; |
| 346 | #if 0 |
| 347 | SET_FLAG (api.message, ZAPI_MESSAGE_DISTANCE); |
| 348 | api.distance = route_info->depth; |
| 349 | #endif |
| 350 | api.nexthop_num = listcount (route_info->nexthops6); |
| 351 | api.ifindex_num = listcount (route_info->nexthops6); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 352 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 353 | /* allocate memory for nexthop_list */ |
| 354 | size = sizeof (struct isis_nexthop6 *) * listcount (route_info->nexthops6); |
| 355 | nexthop_list = (struct in6_addr **) XMALLOC (MTYPE_ISIS_TMP, size); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 356 | if (!nexthop_list) |
| 357 | { |
| 358 | zlog_err ("isis_zebra_add_route_ipv6: out of memory!"); |
| 359 | return; |
| 360 | } |
| 361 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 362 | /* allocate memory for ifindex_list */ |
| 363 | size = sizeof (unsigned int) * listcount (route_info->nexthops6); |
| 364 | ifindex_list = (unsigned int *) XMALLOC (MTYPE_ISIS_TMP, size); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 365 | if (!ifindex_list) |
| 366 | { |
| 367 | zlog_err ("isis_zebra_add_route_ipv6: out of memory!"); |
| 368 | XFREE (MTYPE_ISIS_TMP, nexthop_list); |
| 369 | return; |
| 370 | } |
| 371 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 372 | /* for each nexthop */ |
| 373 | i = 0; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 374 | for (node = listhead (route_info->nexthops6); node; nextnode (node)) |
| 375 | { |
| 376 | nexthop6 = getdata (node); |
| 377 | |
| 378 | if (!IN6_IS_ADDR_LINKLOCAL (&nexthop6->ip6) && |
| 379 | !IN6_IS_ADDR_UNSPECIFIED (&nexthop6->ip6)) |
| 380 | { |
| 381 | api.nexthop_num--; |
| 382 | api.ifindex_num--; |
| 383 | continue; |
| 384 | } |
| 385 | |
| 386 | nexthop_list[i] = &nexthop6->ip6; |
| 387 | ifindex_list[i] = nexthop6->ifindex; |
| 388 | i++; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 389 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 390 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 391 | api.nexthop = nexthop_list; |
| 392 | api.ifindex = ifindex_list; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 393 | |
| 394 | if (api.nexthop_num && api.ifindex_num) |
| 395 | { |
| 396 | prefix6.family = AF_INET6; |
| 397 | prefix6.prefixlen = prefix->prefixlen; |
| 398 | memcpy (&prefix6.prefix, &prefix->u.prefix6, sizeof (struct in6_addr)); |
| 399 | zapi_ipv6_route (ZEBRA_IPV6_ROUTE_ADD, zclient, &prefix6, &api); |
| 400 | SET_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNC); |
| 401 | } |
| 402 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 403 | XFREE (MTYPE_ISIS_TMP, nexthop_list); |
| 404 | XFREE (MTYPE_ISIS_TMP, ifindex_list); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 405 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 406 | return; |
| 407 | } |
| 408 | |
| 409 | void |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 410 | isis_zebra_route_del_ipv6 (struct prefix *prefix, |
| 411 | struct isis_route_info *route_info) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 412 | { |
| 413 | struct zapi_ipv6 api; |
| 414 | struct in6_addr **nexthop_list; |
| 415 | unsigned int *ifindex_list; |
| 416 | struct isis_nexthop6 *nexthop6; |
| 417 | int i, size; |
| 418 | struct listnode *node; |
| 419 | struct prefix_ipv6 prefix6; |
| 420 | |
| 421 | if (CHECK_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNC)) |
| 422 | return; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 423 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 424 | api.type = ZEBRA_ROUTE_ISIS; |
| 425 | api.flags = 0; |
| 426 | api.message = 0; |
| 427 | SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP); |
| 428 | SET_FLAG (api.message, ZAPI_MESSAGE_IFINDEX); |
| 429 | api.nexthop_num = listcount (route_info->nexthops6); |
| 430 | api.ifindex_num = listcount (route_info->nexthops6); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 431 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 432 | /* allocate memory for nexthop_list */ |
| 433 | size = sizeof (struct isis_nexthop6 *) * listcount (route_info->nexthops6); |
| 434 | nexthop_list = (struct in6_addr **) XMALLOC (MTYPE_ISIS_TMP, size); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 435 | if (!nexthop_list) |
| 436 | { |
| 437 | zlog_err ("isis_zebra_route_del_ipv6: out of memory!"); |
| 438 | return; |
| 439 | } |
| 440 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 441 | /* allocate memory for ifindex_list */ |
| 442 | size = sizeof (unsigned int) * listcount (route_info->nexthops6); |
| 443 | ifindex_list = (unsigned int *) XMALLOC (MTYPE_ISIS_TMP, size); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 444 | if (!ifindex_list) |
| 445 | { |
| 446 | zlog_err ("isis_zebra_route_del_ipv6: out of memory!"); |
| 447 | XFREE (MTYPE_ISIS_TMP, nexthop_list); |
| 448 | return; |
| 449 | } |
| 450 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 451 | /* for each nexthop */ |
| 452 | i = 0; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 453 | for (node = listhead (route_info->nexthops6); node; nextnode (node)) |
| 454 | { |
| 455 | nexthop6 = getdata (node); |
| 456 | |
| 457 | if (!IN6_IS_ADDR_LINKLOCAL (&nexthop6->ip6) && |
| 458 | !IN6_IS_ADDR_UNSPECIFIED (&nexthop6->ip6)) |
| 459 | { |
| 460 | api.nexthop_num--; |
| 461 | api.ifindex_num--; |
| 462 | continue; |
| 463 | } |
| 464 | |
| 465 | nexthop_list[i] = &nexthop6->ip6; |
| 466 | ifindex_list[i] = nexthop6->ifindex; |
| 467 | i++; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 468 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 469 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 470 | api.nexthop = nexthop_list; |
| 471 | api.ifindex = ifindex_list; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 472 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 473 | if (api.nexthop_num && api.ifindex_num) |
| 474 | { |
| 475 | prefix6.family = AF_INET6; |
| 476 | prefix6.prefixlen = prefix->prefixlen; |
| 477 | memcpy (&prefix6.prefix, &prefix->u.prefix6, sizeof (struct in6_addr)); |
| 478 | zapi_ipv6_route (ZEBRA_IPV6_ROUTE_DELETE, zclient, &prefix6, &api); |
| 479 | UNSET_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNC); |
| 480 | } |
| 481 | |
| 482 | XFREE (MTYPE_ISIS_TMP, nexthop_list); |
| 483 | XFREE (MTYPE_ISIS_TMP, ifindex_list); |
| 484 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 485 | |
| 486 | #endif /* HAVE_IPV6 */ |
| 487 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 488 | void |
| 489 | isis_zebra_route_update (struct prefix *prefix, |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 490 | struct isis_route_info *route_info) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 491 | { |
| 492 | if (zclient->sock < 0) |
| 493 | return; |
| 494 | |
| 495 | if (!zclient->redist[ZEBRA_ROUTE_ISIS]) |
| 496 | return; |
| 497 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 498 | if (CHECK_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ACTIVE)) |
| 499 | { |
| 500 | if (prefix->family == AF_INET) |
| 501 | isis_zebra_route_add_ipv4 (prefix, route_info); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 502 | #ifdef HAVE_IPV6 |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 503 | else if (prefix->family == AF_INET6) |
| 504 | isis_zebra_route_add_ipv6 (prefix, route_info); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 505 | #endif /* HAVE_IPV6 */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 506 | } |
| 507 | else |
| 508 | { |
| 509 | if (prefix->family == AF_INET) |
| 510 | isis_zebra_route_del_ipv4 (prefix, route_info); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 511 | #ifdef HAVE_IPV6 |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 512 | else if (prefix->family == AF_INET6) |
| 513 | isis_zebra_route_del_ipv6 (prefix, route_info); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 514 | #endif /* HAVE_IPV6 */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 515 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 516 | return; |
| 517 | } |
| 518 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 519 | int |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 520 | isis_zebra_read_ipv4 (int command, struct zclient *zclient, |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 521 | zebra_size_t length) |
| 522 | { |
| 523 | struct stream *stream; |
| 524 | struct zapi_ipv4 api; |
| 525 | struct prefix_ipv4 p; |
| 526 | unsigned long ifindex; |
| 527 | struct in_addr nexthop; |
| 528 | |
| 529 | stream = zclient->ibuf; |
| 530 | memset (&p, 0, sizeof (struct prefix_ipv4)); |
| 531 | ifindex = 0; |
| 532 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 533 | api.type = stream_getc (stream); |
| 534 | api.flags = stream_getc (stream); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 535 | api.message = stream_getc (stream); |
| 536 | |
| 537 | p.family = AF_INET; |
| 538 | p.prefixlen = stream_getc (stream); |
| 539 | stream_get (&p.prefix, stream, PSIZE (p.prefixlen)); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 540 | |
| 541 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP)) |
| 542 | { |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 543 | api.nexthop_num = stream_getc (stream); |
| 544 | nexthop.s_addr = stream_get_ipv4 (stream); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 545 | } |
| 546 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_IFINDEX)) |
| 547 | { |
| 548 | api.ifindex_num = stream_getc (stream); |
| 549 | ifindex = stream_getl (stream); |
| 550 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 551 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE)) |
| 552 | api.distance = stream_getc (stream); |
| 553 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC)) |
| 554 | api.metric = stream_getl (stream); |
| 555 | else |
| 556 | api.metric = 0; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 557 | |
| 558 | if (command == ZEBRA_IPV4_ROUTE_ADD) |
| 559 | { |
| 560 | zlog_info ("IPv4 Route add from Z"); |
| 561 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 562 | |
| 563 | return 0; |
| 564 | } |
| 565 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 566 | int |
| 567 | isis_zebra_read_ipv6 (int command, struct zclient *zclient, |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 568 | zebra_size_t length) |
| 569 | { |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 570 | return 0; |
| 571 | } |
| 572 | |
| 573 | #define ISIS_TYPE_IS_REDISTRIBUTED(T) \ |
| 574 | T == ZEBRA_ROUTE_MAX ? zclient->default_information : zclient->redist[type] |
| 575 | |
| 576 | int |
| 577 | isis_distribute_list_update (int routetype) |
| 578 | { |
| 579 | return 0; |
| 580 | } |
| 581 | |
| 582 | int |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 583 | isis_redistribute_default_set (int routetype, int metric_type, |
| 584 | int metric_value) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 585 | { |
| 586 | return 0; |
| 587 | } |
| 588 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 589 | void |
| 590 | isis_zebra_init () |
| 591 | { |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 592 | zclient = zclient_new (); |
| 593 | zclient_init (zclient, ZEBRA_ROUTE_ISIS); |
| 594 | zclient->interface_add = isis_zebra_if_add; |
| 595 | zclient->interface_delete = isis_zebra_if_del; |
| 596 | zclient->interface_up = isis_zebra_if_state_up; |
| 597 | zclient->interface_down = isis_zebra_if_state_down; |
| 598 | zclient->interface_address_add = isis_zebra_if_address_add; |
| 599 | zclient->interface_address_delete = isis_zebra_if_address_del; |
| 600 | zclient->ipv4_route_add = isis_zebra_read_ipv4; |
| 601 | zclient->ipv4_route_delete = isis_zebra_read_ipv4; |
| 602 | #ifdef HAVE_IPV6 |
| 603 | zclient->ipv6_route_add = isis_zebra_read_ipv6; |
| 604 | zclient->ipv6_route_delete = isis_zebra_read_ipv6; |
| 605 | #endif /* HAVE_IPV6 */ |
| 606 | |
| 607 | return; |
| 608 | } |
| 609 | |
| 610 | void |
| 611 | isis_zebra_finish () |
| 612 | { |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 613 | zclient_stop (zclient); |
| 614 | zclient_free (zclient); |
| 615 | zclient = (struct zclient *) NULL; |
| 616 | |
| 617 | return; |
| 618 | } |