paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1 | /* |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2 | * Copyright (C) 2003 Yasuhiro Ohara |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3 | * |
| 4 | * This file is part of GNU Zebra. |
| 5 | * |
| 6 | * GNU Zebra is free software; you can redistribute it and/or modify it |
| 7 | * under the terms of the GNU General Public License as published by the |
| 8 | * Free Software Foundation; either version 2, or (at your option) any |
| 9 | * later version. |
| 10 | * |
| 11 | * GNU Zebra is distributed in the hope that it will be useful, but |
| 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with GNU Zebra; see the file COPYING. If not, write to the |
| 18 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 19 | * Boston, MA 02111-1307, USA. |
| 20 | */ |
| 21 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 22 | #include <zebra.h> |
| 23 | |
| 24 | #include "log.h" |
| 25 | #include "vty.h" |
| 26 | #include "command.h" |
| 27 | #include "prefix.h" |
| 28 | #include "stream.h" |
| 29 | #include "zclient.h" |
| 30 | #include "memory.h" |
| 31 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 32 | #include "ospf6_proto.h" |
| 33 | #include "ospf6_top.h" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 34 | #include "ospf6_interface.h" |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 35 | #include "ospf6_route.h" |
| 36 | #include "ospf6_lsa.h" |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 37 | #include "ospf6_lsdb.h" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 38 | #include "ospf6_asbr.h" |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 39 | #include "ospf6_zebra.h" |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 40 | #include "ospf6d.h" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 41 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 42 | unsigned char conf_debug_ospf6_zebra = 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 43 | |
| 44 | /* information about zebra. */ |
| 45 | struct zclient *zclient = NULL; |
| 46 | |
| 47 | /* redistribute function */ |
| 48 | void |
| 49 | ospf6_zebra_redistribute (int type) |
| 50 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 51 | if (zclient->redist[type]) |
| 52 | return; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 53 | zclient->redist[type] = 1; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 54 | if (zclient->sock > 0) |
| 55 | zebra_redistribute_send (ZEBRA_REDISTRIBUTE_ADD, zclient->sock, type); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | void |
| 59 | ospf6_zebra_no_redistribute (int type) |
| 60 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 61 | if (! zclient->redist[type]) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 62 | return; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 63 | zclient->redist[type] = 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 64 | if (zclient->sock > 0) |
| 65 | zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, zclient->sock, type); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 66 | } |
| 67 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 68 | /* Inteface addition message from zebra. */ |
| 69 | int |
| 70 | ospf6_zebra_if_add (int command, struct zclient *zclient, zebra_size_t length) |
| 71 | { |
| 72 | struct interface *ifp; |
| 73 | |
| 74 | ifp = zebra_interface_add_read (zclient->ibuf); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 75 | if (IS_OSPF6_DEBUG_ZEBRA (RECV)) |
| 76 | zlog_info ("Zebra Interface add: %s index %d mtu %d", |
hasso | 1203e1c | 2004-07-23 21:34:27 +0000 | [diff] [blame] | 77 | ifp->name, ifp->ifindex, ifp->mtu6); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 78 | ospf6_interface_if_add (ifp); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | int |
| 83 | ospf6_zebra_if_del (int command, struct zclient *zclient, zebra_size_t length) |
| 84 | { |
| 85 | #if 0 |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 86 | struct interface *ifp; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 87 | |
| 88 | ifp = zebra_interface_delete_read (zclient->ibuf); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 89 | if (IS_OSPF6_DEBUG_ZEBRA (RECV)) |
| 90 | zlog_info ("Zebra Interface delete: %s index %d mtu %d", |
hasso | 1203e1c | 2004-07-23 21:34:27 +0000 | [diff] [blame] | 91 | ifp->name, ifp->ifindex, ifp->mtu6); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 92 | |
| 93 | ospf6_interface_if_del (ifp); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 94 | #endif /*0*/ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 95 | return 0; |
| 96 | } |
| 97 | |
| 98 | int |
| 99 | ospf6_zebra_if_state_update (int command, struct zclient *zclient, |
| 100 | zebra_size_t length) |
| 101 | { |
| 102 | struct interface *ifp; |
| 103 | |
| 104 | ifp = zebra_interface_state_read (zclient->ibuf); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 105 | if (IS_OSPF6_DEBUG_ZEBRA (RECV)) |
| 106 | zlog_info ("Zebra Interface state change: " |
| 107 | "%s index %d flags %ld metric %d mtu %d", |
hasso | 1203e1c | 2004-07-23 21:34:27 +0000 | [diff] [blame] | 108 | ifp->name, ifp->ifindex, ifp->flags, ifp->metric, ifp->mtu6); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 109 | |
| 110 | ospf6_interface_state_update (ifp); |
| 111 | return 0; |
| 112 | } |
| 113 | |
| 114 | int |
| 115 | ospf6_zebra_if_address_update_add (int command, struct zclient *zclient, |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 116 | zebra_size_t length) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 117 | { |
| 118 | struct connected *c; |
| 119 | char buf[128]; |
| 120 | |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 121 | c = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_ADD, zclient->ibuf); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 122 | if (c == NULL) |
| 123 | return 0; |
| 124 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 125 | if (IS_OSPF6_DEBUG_ZEBRA (RECV)) |
| 126 | zlog_info ("Zebra Interface address add: %s %5s %s/%d", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 127 | c->ifp->name, prefix_family_str (c->address), |
| 128 | inet_ntop (c->address->family, &c->address->u.prefix, |
| 129 | buf, sizeof (buf)), c->address->prefixlen); |
| 130 | |
| 131 | if (c->address->family == AF_INET6) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 132 | ospf6_interface_connected_route_update (c->ifp); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 133 | |
| 134 | return 0; |
| 135 | } |
| 136 | |
| 137 | int |
| 138 | ospf6_zebra_if_address_update_delete (int command, struct zclient *zclient, |
| 139 | zebra_size_t length) |
| 140 | { |
| 141 | struct connected *c; |
| 142 | char buf[128]; |
| 143 | |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 144 | c = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_DELETE, zclient->ibuf); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 145 | if (c == NULL) |
| 146 | return 0; |
| 147 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 148 | if (IS_OSPF6_DEBUG_ZEBRA (RECV)) |
| 149 | zlog_info ("Zebra Interface address delete: %s %5s %s/%d", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 150 | c->ifp->name, prefix_family_str (c->address), |
| 151 | inet_ntop (c->address->family, &c->address->u.prefix, |
| 152 | buf, sizeof (buf)), c->address->prefixlen); |
| 153 | |
| 154 | if (c->address->family == AF_INET6) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 155 | ospf6_interface_connected_route_update (c->ifp); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 156 | |
| 157 | return 0; |
| 158 | } |
| 159 | |
| 160 | |
| 161 | |
| 162 | const char *zebra_route_name[ZEBRA_ROUTE_MAX] = |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 163 | { "System", "Kernel", "Connect", "Static", "RIP", "RIPng", "OSPF", |
hasso | f3f27f6 | 2004-09-10 18:07:57 +0000 | [diff] [blame^] | 164 | "OSPF6", "ISIS", "BGP" }; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 165 | |
| 166 | const char *zebra_route_abname[ZEBRA_ROUTE_MAX] = |
hasso | f3f27f6 | 2004-09-10 18:07:57 +0000 | [diff] [blame^] | 167 | { "X", "K", "C", "S", "r", "R", "o", "O", "I", "B" }; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 168 | |
| 169 | int |
| 170 | ospf6_zebra_read_ipv6 (int command, struct zclient *zclient, |
| 171 | zebra_size_t length) |
| 172 | { |
| 173 | struct stream *s; |
| 174 | struct zapi_ipv6 api; |
| 175 | unsigned long ifindex; |
| 176 | struct prefix_ipv6 p; |
| 177 | struct in6_addr *nexthop; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 178 | |
| 179 | s = zclient->ibuf; |
| 180 | ifindex = 0; |
| 181 | nexthop = NULL; |
| 182 | memset (&api, 0, sizeof (api)); |
| 183 | |
| 184 | /* Type, flags, message. */ |
| 185 | api.type = stream_getc (s); |
| 186 | api.flags = stream_getc (s); |
| 187 | api.message = stream_getc (s); |
| 188 | |
| 189 | /* IPv6 prefix. */ |
| 190 | memset (&p, 0, sizeof (struct prefix_ipv6)); |
| 191 | p.family = AF_INET6; |
| 192 | p.prefixlen = stream_getc (s); |
| 193 | stream_get (&p.prefix, s, PSIZE (p.prefixlen)); |
| 194 | |
| 195 | /* Nexthop, ifindex, distance, metric. */ |
| 196 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP)) |
| 197 | { |
| 198 | api.nexthop_num = stream_getc (s); |
| 199 | nexthop = (struct in6_addr *) |
| 200 | malloc (api.nexthop_num * sizeof (struct in6_addr)); |
| 201 | stream_get (nexthop, s, api.nexthop_num * sizeof (struct in6_addr)); |
| 202 | } |
| 203 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_IFINDEX)) |
| 204 | { |
| 205 | api.ifindex_num = stream_getc (s); |
| 206 | ifindex = stream_getl (s); |
| 207 | } |
| 208 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE)) |
| 209 | api.distance = stream_getc (s); |
| 210 | else |
| 211 | api.distance = 0; |
| 212 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC)) |
| 213 | api.metric = stream_getl (s); |
| 214 | else |
| 215 | api.metric = 0; |
| 216 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 217 | if (IS_OSPF6_DEBUG_ZEBRA (RECV)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 218 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 219 | char prefixstr[128], nexthopstr[128]; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 220 | prefix2str ((struct prefix *)&p, prefixstr, sizeof (prefixstr)); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 221 | if (nexthop) |
| 222 | inet_ntop (AF_INET6, nexthop, nexthopstr, sizeof (nexthopstr)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 223 | else |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 224 | snprintf (nexthopstr, sizeof (nexthopstr), "::"); |
| 225 | |
| 226 | zlog_info ("Zebra Receive route %s: %s %s nexthop %s ifindex %ld", |
| 227 | (command == ZEBRA_IPV6_ROUTE_ADD ? "add" : "delete"), |
| 228 | zebra_route_name[api.type], prefixstr, nexthopstr, ifindex); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | if (command == ZEBRA_IPV6_ROUTE_ADD) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 232 | ospf6_asbr_redistribute_add (api.type, ifindex, (struct prefix *) &p, |
| 233 | api.nexthop_num, nexthop); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 234 | else |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 235 | ospf6_asbr_redistribute_remove (api.type, ifindex, (struct prefix *) &p); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 236 | |
| 237 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP)) |
| 238 | free (nexthop); |
| 239 | |
| 240 | return 0; |
| 241 | } |
| 242 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 243 | |
| 244 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 245 | |
| 246 | DEFUN (show_zebra, |
| 247 | show_zebra_cmd, |
| 248 | "show zebra", |
| 249 | SHOW_STR |
| 250 | "Zebra information\n") |
| 251 | { |
| 252 | int i; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 253 | if (zclient == NULL) |
| 254 | { |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 255 | vty_out (vty, "Not connected to zebra%s", VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 256 | return CMD_SUCCESS; |
| 257 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 258 | |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 259 | vty_out (vty, "Zebra Infomation%s", VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 260 | vty_out (vty, " enable: %d fail: %d%s", |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 261 | zclient->enable, zclient->fail, VNL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 262 | vty_out (vty, " redistribute default: %d%s", zclient->redist_default, |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 263 | VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 264 | vty_out (vty, " redistribute:"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 265 | for (i = 0; i < ZEBRA_ROUTE_MAX; i++) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 266 | { |
| 267 | if (zclient->redist[i]) |
| 268 | vty_out (vty, " %s", zebra_route_name[i]); |
| 269 | } |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 270 | vty_out (vty, "%s", VNL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 271 | return CMD_SUCCESS; |
| 272 | } |
| 273 | |
| 274 | DEFUN (router_zebra, |
| 275 | router_zebra_cmd, |
| 276 | "router zebra", |
| 277 | "Enable a routing process\n" |
| 278 | "Make connection to zebra daemon\n") |
| 279 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 280 | vty->node = ZEBRA_NODE; |
| 281 | zclient->enable = 1; |
| 282 | zclient_start (zclient); |
| 283 | return CMD_SUCCESS; |
| 284 | } |
| 285 | |
| 286 | DEFUN (no_router_zebra, |
| 287 | no_router_zebra_cmd, |
| 288 | "no router zebra", |
| 289 | NO_STR |
| 290 | "Configure routing process\n" |
| 291 | "Disable connection to zebra daemon\n") |
| 292 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 293 | zclient->enable = 0; |
| 294 | zclient_stop (zclient); |
| 295 | return CMD_SUCCESS; |
| 296 | } |
| 297 | |
| 298 | /* Zebra configuration write function. */ |
| 299 | int |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 300 | config_write_ospf6_zebra (struct vty *vty) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 301 | { |
| 302 | if (! zclient->enable) |
| 303 | { |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 304 | vty_out (vty, "no router zebra%s", VNL); |
| 305 | vty_out (vty, "!%s", VNL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 306 | } |
| 307 | else if (! zclient->redist[ZEBRA_ROUTE_OSPF6]) |
| 308 | { |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 309 | vty_out (vty, "router zebra%s", VNL); |
| 310 | vty_out (vty, " no redistribute ospf6%s", VNL); |
| 311 | vty_out (vty, "!%s", VNL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 312 | } |
| 313 | return 0; |
| 314 | } |
| 315 | |
| 316 | /* Zebra node structure. */ |
| 317 | struct cmd_node zebra_node = |
| 318 | { |
| 319 | ZEBRA_NODE, |
| 320 | "%s(config-zebra)# ", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 321 | }; |
| 322 | |
| 323 | #define ADD 0 |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 324 | #define REM 1 |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 325 | static void |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 326 | ospf6_zebra_route_update (int type, struct ospf6_route *request) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 327 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 328 | struct zapi_ipv6 api; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 329 | char buf[64], ifname[IFNAMSIZ]; |
| 330 | int nhcount; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 331 | struct in6_addr **nexthops; |
| 332 | unsigned int *ifindexes; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 333 | int i, ret = 0; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 334 | struct prefix_ipv6 *dest; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 335 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 336 | if (IS_OSPF6_DEBUG_ZEBRA (SEND)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 337 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 338 | prefix2str (&request->prefix, buf, sizeof (buf)); |
| 339 | zlog_info ("Send %s route: %s", |
| 340 | (type == REM ? "remove" : "add"), buf); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | if (zclient->sock < 0) |
| 344 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 345 | if (IS_OSPF6_DEBUG_ZEBRA (SEND)) |
| 346 | zlog_info (" Not connected to Zebra"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 347 | return; |
| 348 | } |
| 349 | |
| 350 | if (request->path.origin.adv_router == ospf6->router_id && |
| 351 | (request->path.type == OSPF6_PATH_TYPE_EXTERNAL1 || |
| 352 | request->path.type == OSPF6_PATH_TYPE_EXTERNAL2)) |
| 353 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 354 | if (IS_OSPF6_DEBUG_ZEBRA (SEND)) |
| 355 | zlog_info (" Ignore self-originated external route"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 356 | return; |
| 357 | } |
| 358 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 359 | /* If removing is the best path and if there's another path, |
| 360 | treat this request as add the secondary path */ |
| 361 | if (type == REM && ospf6_route_is_best (request) && |
| 362 | request->next && ospf6_route_is_same (request, request->next)) |
| 363 | { |
| 364 | if (IS_OSPF6_DEBUG_ZEBRA (SEND)) |
| 365 | zlog_info (" Best-path removal resulted Sencondary addition"); |
| 366 | type = ADD; |
| 367 | request = request->next; |
| 368 | } |
| 369 | |
| 370 | /* Only the best path will be sent to zebra. */ |
| 371 | if (! ospf6_route_is_best (request)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 372 | { |
| 373 | /* this is not preferred best route, ignore */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 374 | if (IS_OSPF6_DEBUG_ZEBRA (SEND)) |
| 375 | zlog_info (" Ignore non-best route"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 376 | return; |
| 377 | } |
| 378 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 379 | nhcount = 0; |
| 380 | for (i = 0; i < OSPF6_MULTI_PATH_LIMIT; i++) |
| 381 | if (ospf6_nexthop_is_set (&request->nexthop[i])) |
| 382 | nhcount++; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 383 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 384 | if (nhcount == 0) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 385 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 386 | if (IS_OSPF6_DEBUG_ZEBRA (SEND)) |
| 387 | zlog_info (" No nexthop, ignore"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 388 | return; |
| 389 | } |
| 390 | |
| 391 | /* allocate memory for nexthop_list */ |
| 392 | nexthops = XCALLOC (MTYPE_OSPF6_OTHER, |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 393 | nhcount * sizeof (struct in6_addr *)); |
| 394 | if (nexthops == NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 395 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 396 | zlog_warn ("Can't send route to zebra: malloc failed"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 397 | return; |
| 398 | } |
| 399 | |
| 400 | /* allocate memory for ifindex_list */ |
| 401 | ifindexes = XCALLOC (MTYPE_OSPF6_OTHER, |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 402 | nhcount * sizeof (unsigned int)); |
| 403 | if (ifindexes == NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 404 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 405 | zlog_warn ("Can't send route to zebra: malloc failed"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 406 | XFREE (MTYPE_OSPF6_OTHER, nexthops); |
| 407 | return; |
| 408 | } |
| 409 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 410 | for (i = 0; i < nhcount; i++) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 411 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 412 | if (IS_OSPF6_DEBUG_ZEBRA (SEND)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 413 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 414 | inet_ntop (AF_INET6, &request->nexthop[i].address, |
| 415 | buf, sizeof (buf)); |
| 416 | if_indextoname (request->nexthop[i].ifindex, ifname); |
| 417 | zlog_info (" nexthop: %s%%%s(%d)", buf, ifname, |
| 418 | request->nexthop[i].ifindex); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 419 | } |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 420 | nexthops[i] = &request->nexthop[i].address; |
| 421 | ifindexes[i] = request->nexthop[i].ifindex; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | api.type = ZEBRA_ROUTE_OSPF6; |
| 425 | api.flags = 0; |
| 426 | api.message = 0; |
| 427 | SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 428 | api.nexthop_num = nhcount; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 429 | api.nexthop = nexthops; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 430 | SET_FLAG (api.message, ZAPI_MESSAGE_IFINDEX); |
| 431 | api.ifindex_num = nhcount; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 432 | api.ifindex = ifindexes; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 433 | SET_FLAG (api.message, ZAPI_MESSAGE_METRIC); |
| 434 | api.metric = (request->path.metric_type == 2 ? |
| 435 | request->path.cost_e2 : request->path.cost); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 436 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 437 | dest = (struct prefix_ipv6 *) &request->prefix; |
| 438 | if (type == REM) |
| 439 | ret = zapi_ipv6_route (ZEBRA_IPV6_ROUTE_DELETE, zclient, dest, &api); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 440 | else |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 441 | ret = zapi_ipv6_route (ZEBRA_IPV6_ROUTE_ADD, zclient, dest, &api); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 442 | |
| 443 | if (ret < 0) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 444 | zlog_err ("zapi_ipv6_route() %s failed: %s", |
| 445 | (type == REM ? "delete" : "add"), strerror (errno)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 446 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 447 | XFREE (MTYPE_OSPF6_OTHER, nexthops); |
| 448 | XFREE (MTYPE_OSPF6_OTHER, ifindexes); |
| 449 | |
| 450 | return; |
| 451 | } |
| 452 | |
| 453 | void |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 454 | ospf6_zebra_route_update_add (struct ospf6_route *request) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 455 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 456 | if (! zclient->redist[ZEBRA_ROUTE_OSPF6]) |
| 457 | { |
| 458 | ospf6->route_table->hook_add = NULL; |
| 459 | ospf6->route_table->hook_remove = NULL; |
| 460 | return; |
| 461 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 462 | ospf6_zebra_route_update (ADD, request); |
| 463 | } |
| 464 | |
| 465 | void |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 466 | ospf6_zebra_route_update_remove (struct ospf6_route *request) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 467 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 468 | if (! zclient->redist[ZEBRA_ROUTE_OSPF6]) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 469 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 470 | ospf6->route_table->hook_add = NULL; |
| 471 | ospf6->route_table->hook_remove = NULL; |
| 472 | return; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 473 | } |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 474 | ospf6_zebra_route_update (REM, request); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 475 | } |
| 476 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 477 | DEFUN (redistribute_ospf6, |
| 478 | redistribute_ospf6_cmd, |
| 479 | "redistribute ospf6", |
| 480 | "Redistribute control\n" |
| 481 | "OSPF6 route\n") |
| 482 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 483 | struct ospf6_route *route; |
| 484 | |
| 485 | if (zclient->redist[ZEBRA_ROUTE_OSPF6]) |
| 486 | return CMD_SUCCESS; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 487 | |
| 488 | zclient->redist[ZEBRA_ROUTE_OSPF6] = 1; |
| 489 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 490 | if (ospf6 == NULL) |
| 491 | return CMD_SUCCESS; |
| 492 | |
| 493 | /* send ospf6 route to zebra route table */ |
| 494 | for (route = ospf6_route_head (ospf6->route_table); route; |
| 495 | route = ospf6_route_next (route)) |
| 496 | ospf6_zebra_route_update_add (route); |
| 497 | |
| 498 | ospf6->route_table->hook_add = ospf6_zebra_route_update_add; |
| 499 | ospf6->route_table->hook_remove = ospf6_zebra_route_update_remove; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 500 | |
| 501 | return CMD_SUCCESS; |
| 502 | } |
| 503 | |
| 504 | DEFUN (no_redistribute_ospf6, |
| 505 | no_redistribute_ospf6_cmd, |
| 506 | "no redistribute ospf6", |
| 507 | NO_STR |
| 508 | "Redistribute control\n" |
| 509 | "OSPF6 route\n") |
| 510 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 511 | struct ospf6_route *route; |
| 512 | |
| 513 | if (! zclient->redist[ZEBRA_ROUTE_OSPF6]) |
| 514 | return CMD_SUCCESS; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 515 | |
| 516 | zclient->redist[ZEBRA_ROUTE_OSPF6] = 0; |
| 517 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 518 | if (ospf6 == NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 519 | return CMD_SUCCESS; |
| 520 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 521 | ospf6->route_table->hook_add = NULL; |
| 522 | ospf6->route_table->hook_remove = NULL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 523 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 524 | /* withdraw ospf6 route from zebra route table */ |
| 525 | for (route = ospf6_route_head (ospf6->route_table); route; |
| 526 | route = ospf6_route_next (route)) |
| 527 | ospf6_zebra_route_update_remove (route); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 528 | |
| 529 | return CMD_SUCCESS; |
| 530 | } |
| 531 | |
| 532 | void |
| 533 | ospf6_zebra_init () |
| 534 | { |
| 535 | /* Allocate zebra structure. */ |
| 536 | zclient = zclient_new (); |
| 537 | zclient_init (zclient, ZEBRA_ROUTE_OSPF6); |
| 538 | zclient->interface_add = ospf6_zebra_if_add; |
| 539 | zclient->interface_delete = ospf6_zebra_if_del; |
| 540 | zclient->interface_up = ospf6_zebra_if_state_update; |
| 541 | zclient->interface_down = ospf6_zebra_if_state_update; |
| 542 | zclient->interface_address_add = ospf6_zebra_if_address_update_add; |
| 543 | zclient->interface_address_delete = ospf6_zebra_if_address_update_delete; |
| 544 | zclient->ipv4_route_add = NULL; |
| 545 | zclient->ipv4_route_delete = NULL; |
| 546 | zclient->ipv6_route_add = ospf6_zebra_read_ipv6; |
| 547 | zclient->ipv6_route_delete = ospf6_zebra_read_ipv6; |
| 548 | |
| 549 | /* redistribute connected route by default */ |
| 550 | /* ospf6_zebra_redistribute (ZEBRA_ROUTE_CONNECT); */ |
| 551 | |
| 552 | /* Install zebra node. */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 553 | install_node (&zebra_node, config_write_ospf6_zebra); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 554 | |
| 555 | /* Install command element for zebra node. */ |
| 556 | install_element (VIEW_NODE, &show_zebra_cmd); |
| 557 | install_element (ENABLE_NODE, &show_zebra_cmd); |
| 558 | install_element (CONFIG_NODE, &router_zebra_cmd); |
| 559 | install_element (CONFIG_NODE, &no_router_zebra_cmd); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 560 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 561 | install_default (ZEBRA_NODE); |
| 562 | install_element (ZEBRA_NODE, &redistribute_ospf6_cmd); |
| 563 | install_element (ZEBRA_NODE, &no_redistribute_ospf6_cmd); |
| 564 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 565 | return; |
| 566 | } |
| 567 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 568 | /* Debug */ |
| 569 | |
| 570 | DEFUN (debug_ospf6_zebra_sendrecv, |
| 571 | debug_ospf6_zebra_sendrecv_cmd, |
| 572 | "debug ospf6 zebra (send|recv)", |
| 573 | DEBUG_STR |
| 574 | OSPF6_STR |
| 575 | "Debug connection between zebra\n" |
| 576 | "Debug Sending zebra\n" |
| 577 | "Debug Receiving zebra\n" |
| 578 | ) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 579 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 580 | unsigned char level = 0; |
| 581 | |
| 582 | if (argc) |
| 583 | { |
| 584 | if (! strncmp (argv[0], "s", 1)) |
| 585 | level = OSPF6_DEBUG_ZEBRA_SEND; |
| 586 | else if (! strncmp (argv[0], "r", 1)) |
| 587 | level = OSPF6_DEBUG_ZEBRA_RECV; |
| 588 | } |
| 589 | else |
| 590 | level = OSPF6_DEBUG_ZEBRA_SEND | OSPF6_DEBUG_ZEBRA_RECV; |
| 591 | |
| 592 | OSPF6_DEBUG_ZEBRA_ON (level); |
| 593 | return CMD_SUCCESS; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 594 | } |
| 595 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 596 | ALIAS (debug_ospf6_zebra_sendrecv, |
| 597 | debug_ospf6_zebra_cmd, |
| 598 | "debug ospf6 zebra", |
| 599 | DEBUG_STR |
| 600 | OSPF6_STR |
| 601 | "Debug connection between zebra\n" |
| 602 | ); |
| 603 | |
| 604 | |
| 605 | DEFUN (no_debug_ospf6_zebra_sendrecv, |
| 606 | no_debug_ospf6_zebra_sendrecv_cmd, |
| 607 | "no debug ospf6 zebra (send|recv)", |
| 608 | NO_STR |
| 609 | DEBUG_STR |
| 610 | OSPF6_STR |
| 611 | "Debug connection between zebra\n" |
| 612 | "Debug Sending zebra\n" |
| 613 | "Debug Receiving zebra\n" |
| 614 | ) |
| 615 | { |
| 616 | unsigned char level = 0; |
| 617 | |
| 618 | if (argc) |
| 619 | { |
| 620 | if (! strncmp (argv[0], "s", 1)) |
| 621 | level = OSPF6_DEBUG_ZEBRA_SEND; |
| 622 | else if (! strncmp (argv[0], "r", 1)) |
| 623 | level = OSPF6_DEBUG_ZEBRA_RECV; |
| 624 | } |
| 625 | else |
| 626 | level = OSPF6_DEBUG_ZEBRA_SEND | OSPF6_DEBUG_ZEBRA_RECV; |
| 627 | |
| 628 | OSPF6_DEBUG_ZEBRA_OFF (level); |
| 629 | return CMD_SUCCESS; |
| 630 | } |
| 631 | |
| 632 | ALIAS (no_debug_ospf6_zebra_sendrecv, |
| 633 | no_debug_ospf6_zebra_cmd, |
| 634 | "no debug ospf6 zebra", |
| 635 | NO_STR |
| 636 | DEBUG_STR |
| 637 | OSPF6_STR |
| 638 | "Debug connection between zebra\n" |
| 639 | ); |
| 640 | |
| 641 | int |
| 642 | config_write_ospf6_debug_zebra (struct vty *vty) |
| 643 | { |
| 644 | if (IS_OSPF6_DEBUG_ZEBRA (SEND) && IS_OSPF6_DEBUG_ZEBRA (RECV)) |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 645 | vty_out (vty, "debug ospf6 zebra%s", VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 646 | else |
| 647 | { |
| 648 | if (IS_OSPF6_DEBUG_ZEBRA (SEND)) |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 649 | vty_out (vty, "debug ospf6 zebra send%s", VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 650 | if (IS_OSPF6_DEBUG_ZEBRA (RECV)) |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 651 | vty_out (vty, "debug ospf6 zebra recv%s", VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 652 | } |
| 653 | return 0; |
| 654 | } |
| 655 | |
| 656 | void |
| 657 | install_element_ospf6_debug_zebra () |
| 658 | { |
| 659 | install_element (ENABLE_NODE, &debug_ospf6_zebra_cmd); |
| 660 | install_element (ENABLE_NODE, &no_debug_ospf6_zebra_cmd); |
| 661 | install_element (ENABLE_NODE, &debug_ospf6_zebra_sendrecv_cmd); |
| 662 | install_element (ENABLE_NODE, &no_debug_ospf6_zebra_sendrecv_cmd); |
| 663 | install_element (CONFIG_NODE, &debug_ospf6_zebra_cmd); |
| 664 | install_element (CONFIG_NODE, &no_debug_ospf6_zebra_cmd); |
| 665 | install_element (CONFIG_NODE, &debug_ospf6_zebra_sendrecv_cmd); |
| 666 | install_element (CONFIG_NODE, &no_debug_ospf6_zebra_sendrecv_cmd); |
| 667 | } |
| 668 | |
| 669 | |