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; |
| 202 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 203 | c = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_DELETE, |
| 204 | zclient->ibuf); |
| 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 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 211 | connected_free (c); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 212 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 213 | isis_circuit_del_addr (circuit_scan_by_ifp (ifp), c); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 214 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 215 | return 0; |
| 216 | } |
| 217 | |
| 218 | void |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 219 | isis_zebra_route_add_ipv4 (struct prefix *prefix, |
| 220 | struct isis_route_info *route_info) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 221 | { |
| 222 | u_char message, flags; |
| 223 | int psize; |
| 224 | struct stream *stream; |
| 225 | struct isis_nexthop *nexthop; |
| 226 | struct listnode *node; |
| 227 | |
| 228 | if (CHECK_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNC)) |
| 229 | return; |
| 230 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 231 | if (zclient->redist[ZEBRA_ROUTE_ISIS]) |
| 232 | { |
| 233 | message = 0; |
| 234 | flags = 0; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 235 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 236 | SET_FLAG (message, ZAPI_MESSAGE_NEXTHOP); |
| 237 | SET_FLAG (message, ZAPI_MESSAGE_METRIC); |
hasso | 2097cd8 | 2003-12-23 11:51:08 +0000 | [diff] [blame] | 238 | #if 0 |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 239 | SET_FLAG (message, ZAPI_MESSAGE_DISTANCE); |
hasso | 2097cd8 | 2003-12-23 11:51:08 +0000 | [diff] [blame] | 240 | #endif |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 241 | |
| 242 | stream = zclient->obuf; |
| 243 | stream_reset (stream); |
| 244 | /* Length place holder. */ |
| 245 | stream_putw (stream, 0); |
| 246 | /* command */ |
| 247 | stream_putc (stream, ZEBRA_IPV4_ROUTE_ADD); |
| 248 | /* type */ |
| 249 | stream_putc (stream, ZEBRA_ROUTE_ISIS); |
| 250 | /* flags */ |
| 251 | stream_putc (stream, flags); |
| 252 | /* message */ |
| 253 | stream_putc (stream, message); |
| 254 | /* prefix information */ |
| 255 | psize = PSIZE (prefix->prefixlen); |
| 256 | stream_putc (stream, prefix->prefixlen); |
| 257 | stream_write (stream, (u_char *) & prefix->u.prefix4, psize); |
| 258 | |
| 259 | stream_putc (stream, listcount (route_info->nexthops)); |
| 260 | |
| 261 | /* Nexthop, ifindex, distance and metric information */ |
| 262 | for (node = listhead (route_info->nexthops); node; nextnode (node)) |
| 263 | { |
| 264 | nexthop = getdata (node); |
| 265 | /* FIXME: can it be ? */ |
| 266 | if (nexthop->ip.s_addr != INADDR_ANY) |
| 267 | { |
| 268 | stream_putc (stream, ZEBRA_NEXTHOP_IPV4); |
| 269 | stream_put_in_addr (stream, &nexthop->ip); |
| 270 | } |
| 271 | else |
| 272 | { |
| 273 | stream_putc (stream, ZEBRA_NEXTHOP_IFINDEX); |
| 274 | stream_putl (stream, nexthop->ifindex); |
| 275 | } |
| 276 | } |
| 277 | #if 0 |
| 278 | if (CHECK_FLAG (message, ZAPI_MESSAGE_DISTANCE)) |
| 279 | stream_putc (stream, route_info->depth); |
| 280 | #endif |
| 281 | if (CHECK_FLAG (message, ZAPI_MESSAGE_METRIC)) |
| 282 | stream_putl (stream, route_info->cost); |
| 283 | |
| 284 | stream_putw_at (stream, 0, stream_get_endp (stream)); |
| 285 | writen (zclient->sock, stream->data, stream_get_endp (stream)); |
| 286 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | void |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 290 | isis_zebra_route_del_ipv4 (struct prefix *prefix, |
| 291 | struct isis_route_info *route_info) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 292 | { |
| 293 | struct zapi_ipv4 api; |
| 294 | struct prefix_ipv4 prefix4; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 295 | |
| 296 | if (zclient->redist[ZEBRA_ROUTE_ISIS]) |
| 297 | { |
| 298 | api.type = ZEBRA_ROUTE_ISIS; |
| 299 | api.flags = 0; |
| 300 | api.message = 0; |
| 301 | prefix4.family = AF_INET; |
| 302 | prefix4.prefixlen = prefix->prefixlen; |
| 303 | prefix4.prefix = prefix->u.prefix4; |
| 304 | zapi_ipv4_route (ZEBRA_IPV4_ROUTE_DELETE, zclient, &prefix4, &api); |
| 305 | } |
| 306 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 307 | return; |
| 308 | } |
| 309 | |
| 310 | #ifdef HAVE_IPV6 |
| 311 | void |
| 312 | isis_zebra_route_add_ipv6 (struct prefix *prefix, |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 313 | struct isis_route_info *route_info) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 314 | { |
| 315 | struct zapi_ipv6 api; |
| 316 | struct in6_addr **nexthop_list; |
| 317 | unsigned int *ifindex_list; |
| 318 | struct isis_nexthop6 *nexthop6; |
| 319 | int i, size; |
| 320 | struct listnode *node; |
| 321 | struct prefix_ipv6 prefix6; |
| 322 | |
| 323 | if (CHECK_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNC)) |
| 324 | return; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 325 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 326 | api.type = ZEBRA_ROUTE_ISIS; |
| 327 | api.flags = 0; |
| 328 | api.message = 0; |
| 329 | SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP); |
| 330 | SET_FLAG (api.message, ZAPI_MESSAGE_IFINDEX); |
| 331 | SET_FLAG (api.message, ZAPI_MESSAGE_METRIC); |
| 332 | api.metric = route_info->cost; |
| 333 | #if 0 |
| 334 | SET_FLAG (api.message, ZAPI_MESSAGE_DISTANCE); |
| 335 | api.distance = route_info->depth; |
| 336 | #endif |
| 337 | api.nexthop_num = listcount (route_info->nexthops6); |
| 338 | api.ifindex_num = listcount (route_info->nexthops6); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 339 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 340 | /* allocate memory for nexthop_list */ |
| 341 | size = sizeof (struct isis_nexthop6 *) * listcount (route_info->nexthops6); |
| 342 | nexthop_list = (struct in6_addr **) XMALLOC (MTYPE_ISIS_TMP, size); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 343 | if (!nexthop_list) |
| 344 | { |
| 345 | zlog_err ("isis_zebra_add_route_ipv6: out of memory!"); |
| 346 | return; |
| 347 | } |
| 348 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 349 | /* allocate memory for ifindex_list */ |
| 350 | size = sizeof (unsigned int) * listcount (route_info->nexthops6); |
| 351 | ifindex_list = (unsigned int *) XMALLOC (MTYPE_ISIS_TMP, size); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 352 | if (!ifindex_list) |
| 353 | { |
| 354 | zlog_err ("isis_zebra_add_route_ipv6: out of memory!"); |
| 355 | XFREE (MTYPE_ISIS_TMP, nexthop_list); |
| 356 | return; |
| 357 | } |
| 358 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 359 | /* for each nexthop */ |
| 360 | i = 0; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 361 | for (node = listhead (route_info->nexthops6); node; nextnode (node)) |
| 362 | { |
| 363 | nexthop6 = getdata (node); |
| 364 | |
| 365 | if (!IN6_IS_ADDR_LINKLOCAL (&nexthop6->ip6) && |
| 366 | !IN6_IS_ADDR_UNSPECIFIED (&nexthop6->ip6)) |
| 367 | { |
| 368 | api.nexthop_num--; |
| 369 | api.ifindex_num--; |
| 370 | continue; |
| 371 | } |
| 372 | |
| 373 | nexthop_list[i] = &nexthop6->ip6; |
| 374 | ifindex_list[i] = nexthop6->ifindex; |
| 375 | i++; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 376 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 377 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 378 | api.nexthop = nexthop_list; |
| 379 | api.ifindex = ifindex_list; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 380 | |
| 381 | if (api.nexthop_num && api.ifindex_num) |
| 382 | { |
| 383 | prefix6.family = AF_INET6; |
| 384 | prefix6.prefixlen = prefix->prefixlen; |
| 385 | memcpy (&prefix6.prefix, &prefix->u.prefix6, sizeof (struct in6_addr)); |
| 386 | zapi_ipv6_route (ZEBRA_IPV6_ROUTE_ADD, zclient, &prefix6, &api); |
| 387 | SET_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNC); |
| 388 | } |
| 389 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 390 | XFREE (MTYPE_ISIS_TMP, nexthop_list); |
| 391 | XFREE (MTYPE_ISIS_TMP, ifindex_list); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 392 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 393 | return; |
| 394 | } |
| 395 | |
| 396 | void |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 397 | isis_zebra_route_del_ipv6 (struct prefix *prefix, |
| 398 | struct isis_route_info *route_info) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 399 | { |
| 400 | struct zapi_ipv6 api; |
| 401 | struct in6_addr **nexthop_list; |
| 402 | unsigned int *ifindex_list; |
| 403 | struct isis_nexthop6 *nexthop6; |
| 404 | int i, size; |
| 405 | struct listnode *node; |
| 406 | struct prefix_ipv6 prefix6; |
| 407 | |
| 408 | if (CHECK_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNC)) |
| 409 | return; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 410 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 411 | api.type = ZEBRA_ROUTE_ISIS; |
| 412 | api.flags = 0; |
| 413 | api.message = 0; |
| 414 | SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP); |
| 415 | SET_FLAG (api.message, ZAPI_MESSAGE_IFINDEX); |
| 416 | api.nexthop_num = listcount (route_info->nexthops6); |
| 417 | api.ifindex_num = listcount (route_info->nexthops6); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 418 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 419 | /* allocate memory for nexthop_list */ |
| 420 | size = sizeof (struct isis_nexthop6 *) * listcount (route_info->nexthops6); |
| 421 | nexthop_list = (struct in6_addr **) XMALLOC (MTYPE_ISIS_TMP, size); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 422 | if (!nexthop_list) |
| 423 | { |
| 424 | zlog_err ("isis_zebra_route_del_ipv6: out of memory!"); |
| 425 | return; |
| 426 | } |
| 427 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 428 | /* allocate memory for ifindex_list */ |
| 429 | size = sizeof (unsigned int) * listcount (route_info->nexthops6); |
| 430 | ifindex_list = (unsigned int *) XMALLOC (MTYPE_ISIS_TMP, size); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 431 | if (!ifindex_list) |
| 432 | { |
| 433 | zlog_err ("isis_zebra_route_del_ipv6: out of memory!"); |
| 434 | XFREE (MTYPE_ISIS_TMP, nexthop_list); |
| 435 | return; |
| 436 | } |
| 437 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 438 | /* for each nexthop */ |
| 439 | i = 0; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 440 | for (node = listhead (route_info->nexthops6); node; nextnode (node)) |
| 441 | { |
| 442 | nexthop6 = getdata (node); |
| 443 | |
| 444 | if (!IN6_IS_ADDR_LINKLOCAL (&nexthop6->ip6) && |
| 445 | !IN6_IS_ADDR_UNSPECIFIED (&nexthop6->ip6)) |
| 446 | { |
| 447 | api.nexthop_num--; |
| 448 | api.ifindex_num--; |
| 449 | continue; |
| 450 | } |
| 451 | |
| 452 | nexthop_list[i] = &nexthop6->ip6; |
| 453 | ifindex_list[i] = nexthop6->ifindex; |
| 454 | i++; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 455 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 456 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 457 | api.nexthop = nexthop_list; |
| 458 | api.ifindex = ifindex_list; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 459 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 460 | if (api.nexthop_num && api.ifindex_num) |
| 461 | { |
| 462 | prefix6.family = AF_INET6; |
| 463 | prefix6.prefixlen = prefix->prefixlen; |
| 464 | memcpy (&prefix6.prefix, &prefix->u.prefix6, sizeof (struct in6_addr)); |
| 465 | zapi_ipv6_route (ZEBRA_IPV6_ROUTE_DELETE, zclient, &prefix6, &api); |
| 466 | UNSET_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNC); |
| 467 | } |
| 468 | |
| 469 | XFREE (MTYPE_ISIS_TMP, nexthop_list); |
| 470 | XFREE (MTYPE_ISIS_TMP, ifindex_list); |
| 471 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 472 | |
| 473 | #endif /* HAVE_IPV6 */ |
| 474 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 475 | void |
| 476 | isis_zebra_route_update (struct prefix *prefix, |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 477 | struct isis_route_info *route_info) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 478 | { |
| 479 | if (zclient->sock < 0) |
| 480 | return; |
| 481 | |
| 482 | if (!zclient->redist[ZEBRA_ROUTE_ISIS]) |
| 483 | return; |
| 484 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 485 | if (CHECK_FLAG (route_info->flag, ISIS_ROUTE_FLAG_ACTIVE)) |
| 486 | { |
| 487 | if (prefix->family == AF_INET) |
| 488 | isis_zebra_route_add_ipv4 (prefix, route_info); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 489 | #ifdef HAVE_IPV6 |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 490 | else if (prefix->family == AF_INET6) |
| 491 | isis_zebra_route_add_ipv6 (prefix, route_info); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 492 | #endif /* HAVE_IPV6 */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 493 | } |
| 494 | else |
| 495 | { |
| 496 | if (prefix->family == AF_INET) |
| 497 | isis_zebra_route_del_ipv4 (prefix, route_info); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 498 | #ifdef HAVE_IPV6 |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 499 | else if (prefix->family == AF_INET6) |
| 500 | isis_zebra_route_del_ipv6 (prefix, route_info); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 501 | #endif /* HAVE_IPV6 */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 502 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 503 | return; |
| 504 | } |
| 505 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 506 | int |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 507 | isis_zebra_read_ipv4 (int command, struct zclient *zclient, |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 508 | zebra_size_t length) |
| 509 | { |
| 510 | struct stream *stream; |
| 511 | struct zapi_ipv4 api; |
| 512 | struct prefix_ipv4 p; |
| 513 | unsigned long ifindex; |
| 514 | struct in_addr nexthop; |
| 515 | |
| 516 | stream = zclient->ibuf; |
| 517 | memset (&p, 0, sizeof (struct prefix_ipv4)); |
| 518 | ifindex = 0; |
| 519 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 520 | api.type = stream_getc (stream); |
| 521 | api.flags = stream_getc (stream); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 522 | api.message = stream_getc (stream); |
| 523 | |
| 524 | p.family = AF_INET; |
| 525 | p.prefixlen = stream_getc (stream); |
| 526 | stream_get (&p.prefix, stream, PSIZE (p.prefixlen)); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 527 | |
| 528 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP)) |
| 529 | { |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 530 | api.nexthop_num = stream_getc (stream); |
| 531 | nexthop.s_addr = stream_get_ipv4 (stream); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 532 | } |
| 533 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_IFINDEX)) |
| 534 | { |
| 535 | api.ifindex_num = stream_getc (stream); |
| 536 | ifindex = stream_getl (stream); |
| 537 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 538 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE)) |
| 539 | api.distance = stream_getc (stream); |
| 540 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC)) |
| 541 | api.metric = stream_getl (stream); |
| 542 | else |
| 543 | api.metric = 0; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 544 | |
| 545 | if (command == ZEBRA_IPV4_ROUTE_ADD) |
| 546 | { |
| 547 | zlog_info ("IPv4 Route add from Z"); |
| 548 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 549 | |
| 550 | return 0; |
| 551 | } |
| 552 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 553 | int |
| 554 | isis_zebra_read_ipv6 (int command, struct zclient *zclient, |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 555 | zebra_size_t length) |
| 556 | { |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 557 | return 0; |
| 558 | } |
| 559 | |
| 560 | #define ISIS_TYPE_IS_REDISTRIBUTED(T) \ |
| 561 | T == ZEBRA_ROUTE_MAX ? zclient->default_information : zclient->redist[type] |
| 562 | |
| 563 | int |
| 564 | isis_distribute_list_update (int routetype) |
| 565 | { |
| 566 | return 0; |
| 567 | } |
| 568 | |
| 569 | int |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 570 | isis_redistribute_default_set (int routetype, int metric_type, |
| 571 | int metric_value) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 572 | { |
| 573 | return 0; |
| 574 | } |
| 575 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 576 | void |
| 577 | isis_zebra_init () |
| 578 | { |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 579 | zclient = zclient_new (); |
| 580 | zclient_init (zclient, ZEBRA_ROUTE_ISIS); |
| 581 | zclient->interface_add = isis_zebra_if_add; |
| 582 | zclient->interface_delete = isis_zebra_if_del; |
| 583 | zclient->interface_up = isis_zebra_if_state_up; |
| 584 | zclient->interface_down = isis_zebra_if_state_down; |
| 585 | zclient->interface_address_add = isis_zebra_if_address_add; |
| 586 | zclient->interface_address_delete = isis_zebra_if_address_del; |
| 587 | zclient->ipv4_route_add = isis_zebra_read_ipv4; |
| 588 | zclient->ipv4_route_delete = isis_zebra_read_ipv4; |
| 589 | #ifdef HAVE_IPV6 |
| 590 | zclient->ipv6_route_add = isis_zebra_read_ipv6; |
| 591 | zclient->ipv6_route_delete = isis_zebra_read_ipv6; |
| 592 | #endif /* HAVE_IPV6 */ |
| 593 | |
| 594 | return; |
| 595 | } |
| 596 | |
| 597 | void |
| 598 | isis_zebra_finish () |
| 599 | { |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 600 | zclient_stop (zclient); |
| 601 | zclient_free (zclient); |
| 602 | zclient = (struct zclient *) NULL; |
| 603 | |
| 604 | return; |
| 605 | } |