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