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