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