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