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