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