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 | ifp->ifindex = IFINDEX_INTERNAL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 124 | return 0; |
| 125 | } |
| 126 | |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 127 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 128 | ospf6_zebra_if_state_update (int command, struct zclient *zclient, |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 129 | zebra_size_t length, vrf_id_t vrf_id) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 130 | { |
| 131 | struct interface *ifp; |
| 132 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 133 | ifp = zebra_interface_state_read (zclient->ibuf, vrf_id); |
Ingo Flaschberger | 57c4f4f | 2011-04-04 11:17:45 +0100 | [diff] [blame] | 134 | if (ifp == NULL) |
| 135 | return 0; |
| 136 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 137 | if (IS_OSPF6_DEBUG_ZEBRA (RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 138 | zlog_debug ("Zebra Interface state change: " |
Vincent Bernat | c19543b | 2012-10-24 14:45:53 +0000 | [diff] [blame] | 139 | "%s index %d flags %llx metric %d mtu %d bandwidth %d", |
Stephen Hemminger | 30d2059 | 2009-07-28 11:58:51 +0100 | [diff] [blame] | 140 | ifp->name, ifp->ifindex, (unsigned long long)ifp->flags, |
Vincent Bernat | c19543b | 2012-10-24 14:45:53 +0000 | [diff] [blame] | 141 | ifp->metric, ifp->mtu6, ifp->bandwidth); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 142 | |
| 143 | ospf6_interface_state_update (ifp); |
| 144 | return 0; |
| 145 | } |
| 146 | |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 147 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 148 | ospf6_zebra_if_address_update_add (int command, struct zclient *zclient, |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 149 | zebra_size_t length, vrf_id_t vrf_id) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 150 | { |
| 151 | struct connected *c; |
| 152 | char buf[128]; |
| 153 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 154 | c = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_ADD, zclient->ibuf, |
| 155 | vrf_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 156 | if (c == NULL) |
| 157 | return 0; |
| 158 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 159 | if (IS_OSPF6_DEBUG_ZEBRA (RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 160 | zlog_debug ("Zebra Interface address add: %s %5s %s/%d", |
| 161 | c->ifp->name, prefix_family_str (c->address), |
| 162 | inet_ntop (c->address->family, &c->address->u.prefix, |
| 163 | buf, sizeof (buf)), c->address->prefixlen); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 164 | |
| 165 | if (c->address->family == AF_INET6) |
Christian Franke | b13c1d9 | 2012-12-13 16:11:16 +0100 | [diff] [blame] | 166 | { |
| 167 | ospf6_interface_state_update (c->ifp); |
| 168 | ospf6_interface_connected_route_update (c->ifp); |
| 169 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 170 | return 0; |
| 171 | } |
| 172 | |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 173 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 174 | ospf6_zebra_if_address_update_delete (int command, struct zclient *zclient, |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 175 | zebra_size_t length, vrf_id_t vrf_id) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 176 | { |
| 177 | struct connected *c; |
| 178 | char buf[128]; |
| 179 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 180 | c = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_DELETE, zclient->ibuf, |
| 181 | vrf_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 182 | if (c == NULL) |
| 183 | return 0; |
| 184 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 185 | if (IS_OSPF6_DEBUG_ZEBRA (RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 186 | zlog_debug ("Zebra Interface address delete: %s %5s %s/%d", |
| 187 | c->ifp->name, prefix_family_str (c->address), |
| 188 | inet_ntop (c->address->family, &c->address->u.prefix, |
| 189 | buf, sizeof (buf)), c->address->prefixlen); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 190 | |
| 191 | if (c->address->family == AF_INET6) |
Christian Franke | b13c1d9 | 2012-12-13 16:11:16 +0100 | [diff] [blame] | 192 | { |
| 193 | ospf6_interface_connected_route_update (c->ifp); |
| 194 | ospf6_interface_state_update (c->ifp); |
| 195 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 196 | |
| 197 | return 0; |
| 198 | } |
| 199 | |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 200 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 201 | ospf6_zebra_read_ipv6 (int command, struct zclient *zclient, |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 202 | zebra_size_t length, vrf_id_t vrf_id) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 203 | { |
| 204 | struct stream *s; |
| 205 | struct zapi_ipv6 api; |
| 206 | unsigned long ifindex; |
| 207 | struct prefix_ipv6 p; |
| 208 | struct in6_addr *nexthop; |
Donald Sharp | 5e57b5f | 2016-03-11 16:28:34 -0500 | [diff] [blame] | 209 | unsigned char plength = 0; |
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; |
Donald Sharp | 5e57b5f | 2016-03-11 16:28:34 -0500 | [diff] [blame] | 224 | plength = stream_getc (s); |
| 225 | p.prefixlen = MIN(IPV6_MAX_PREFIXLEN, plength); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 226 | stream_get (&p.prefix, s, PSIZE (p.prefixlen)); |
| 227 | |
| 228 | /* Nexthop, ifindex, distance, metric. */ |
| 229 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP)) |
| 230 | { |
| 231 | api.nexthop_num = stream_getc (s); |
| 232 | nexthop = (struct in6_addr *) |
| 233 | malloc (api.nexthop_num * sizeof (struct in6_addr)); |
| 234 | stream_get (nexthop, s, api.nexthop_num * sizeof (struct in6_addr)); |
| 235 | } |
| 236 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_IFINDEX)) |
| 237 | { |
| 238 | api.ifindex_num = stream_getc (s); |
| 239 | ifindex = stream_getl (s); |
| 240 | } |
| 241 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE)) |
| 242 | api.distance = stream_getc (s); |
| 243 | else |
| 244 | api.distance = 0; |
| 245 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC)) |
| 246 | api.metric = stream_getl (s); |
| 247 | else |
| 248 | api.metric = 0; |
| 249 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 250 | if (IS_OSPF6_DEBUG_ZEBRA (RECV)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 251 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 252 | char prefixstr[128], nexthopstr[128]; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 253 | prefix2str ((struct prefix *)&p, prefixstr, sizeof (prefixstr)); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 254 | if (nexthop) |
| 255 | inet_ntop (AF_INET6, nexthop, nexthopstr, sizeof (nexthopstr)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 256 | else |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 257 | snprintf (nexthopstr, sizeof (nexthopstr), "::"); |
| 258 | |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 259 | zlog_debug ("Zebra Receive route %s: %s %s nexthop %s ifindex %ld", |
| 260 | (command == ZEBRA_IPV6_ROUTE_ADD ? "add" : "delete"), |
ajs | f52d13c | 2005-10-01 17:38:06 +0000 | [diff] [blame] | 261 | zebra_route_string(api.type), prefixstr, nexthopstr, ifindex); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | if (command == ZEBRA_IPV6_ROUTE_ADD) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 265 | ospf6_asbr_redistribute_add (api.type, ifindex, (struct prefix *) &p, |
| 266 | api.nexthop_num, nexthop); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 267 | else |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 268 | ospf6_asbr_redistribute_remove (api.type, ifindex, (struct prefix *) &p); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 269 | |
| 270 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP)) |
| 271 | free (nexthop); |
| 272 | |
| 273 | return 0; |
| 274 | } |
| 275 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 276 | |
| 277 | |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 278 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 279 | DEFUN (show_zebra, |
| 280 | show_zebra_cmd, |
| 281 | "show zebra", |
| 282 | SHOW_STR |
| 283 | "Zebra information\n") |
| 284 | { |
| 285 | int i; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 286 | if (zclient == NULL) |
| 287 | { |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 288 | vty_out (vty, "Not connected to zebra%s", VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 289 | return CMD_SUCCESS; |
| 290 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 291 | |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 292 | vty_out (vty, "Zebra Infomation%s", VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 293 | vty_out (vty, " enable: %d fail: %d%s", |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 294 | zclient->enable, zclient->fail, VNL); |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 295 | vty_out (vty, " redistribute default: %d%s", |
| 296 | vrf_bitmap_check (zclient->default_information, VRF_DEFAULT), |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 297 | VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 298 | vty_out (vty, " redistribute:"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 299 | for (i = 0; i < ZEBRA_ROUTE_MAX; i++) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 300 | { |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 301 | if (vrf_bitmap_check (zclient->redist[i], VRF_DEFAULT)) |
ajs | f52d13c | 2005-10-01 17:38:06 +0000 | [diff] [blame] | 302 | vty_out (vty, " %s", zebra_route_string(i)); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 303 | } |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 304 | vty_out (vty, "%s", VNL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 305 | return CMD_SUCCESS; |
| 306 | } |
| 307 | |
| 308 | DEFUN (router_zebra, |
| 309 | router_zebra_cmd, |
| 310 | "router zebra", |
| 311 | "Enable a routing process\n" |
| 312 | "Make connection to zebra daemon\n") |
| 313 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 314 | vty->node = ZEBRA_NODE; |
| 315 | zclient->enable = 1; |
| 316 | zclient_start (zclient); |
| 317 | return CMD_SUCCESS; |
| 318 | } |
| 319 | |
| 320 | DEFUN (no_router_zebra, |
| 321 | no_router_zebra_cmd, |
| 322 | "no router zebra", |
| 323 | NO_STR |
| 324 | "Configure routing process\n" |
| 325 | "Disable connection to zebra daemon\n") |
| 326 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 327 | zclient->enable = 0; |
| 328 | zclient_stop (zclient); |
| 329 | return CMD_SUCCESS; |
| 330 | } |
| 331 | |
| 332 | /* Zebra configuration write function. */ |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 333 | static int |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 334 | config_write_ospf6_zebra (struct vty *vty) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 335 | { |
| 336 | if (! zclient->enable) |
| 337 | { |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 338 | vty_out (vty, "no router zebra%s", VNL); |
| 339 | vty_out (vty, "!%s", VNL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 340 | } |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 341 | else if (! vrf_bitmap_check (zclient->redist[ZEBRA_ROUTE_OSPF6], VRF_DEFAULT)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 342 | { |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 343 | vty_out (vty, "router zebra%s", VNL); |
| 344 | vty_out (vty, " no redistribute ospf6%s", VNL); |
| 345 | vty_out (vty, "!%s", VNL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 346 | } |
| 347 | return 0; |
| 348 | } |
| 349 | |
| 350 | /* Zebra node structure. */ |
Stephen Hemminger | 7fc626d | 2008-12-01 11:10:34 -0800 | [diff] [blame] | 351 | static struct cmd_node zebra_node = |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 352 | { |
| 353 | ZEBRA_NODE, |
| 354 | "%s(config-zebra)# ", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 355 | }; |
| 356 | |
| 357 | #define ADD 0 |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 358 | #define REM 1 |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 359 | static void |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 360 | ospf6_zebra_route_update (int type, struct ospf6_route *request) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 361 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 362 | struct zapi_ipv6 api; |
ajs | d2fc889 | 2005-04-02 18:38:43 +0000 | [diff] [blame] | 363 | char buf[64]; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 364 | int nhcount; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 365 | struct in6_addr **nexthops; |
Paul Jakma | 9099f9b | 2016-01-18 10:12:10 +0000 | [diff] [blame] | 366 | ifindex_t *ifindexes; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 367 | int i, ret = 0; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 368 | struct prefix_ipv6 *dest; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 369 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 370 | if (IS_OSPF6_DEBUG_ZEBRA (SEND)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 371 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 372 | prefix2str (&request->prefix, buf, sizeof (buf)); |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 373 | zlog_debug ("Send %s route: %s", |
| 374 | (type == REM ? "remove" : "add"), buf); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | if (zclient->sock < 0) |
| 378 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 379 | if (IS_OSPF6_DEBUG_ZEBRA (SEND)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 380 | zlog_debug (" Not connected to Zebra"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 381 | return; |
| 382 | } |
| 383 | |
| 384 | if (request->path.origin.adv_router == ospf6->router_id && |
| 385 | (request->path.type == OSPF6_PATH_TYPE_EXTERNAL1 || |
| 386 | request->path.type == OSPF6_PATH_TYPE_EXTERNAL2)) |
| 387 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 388 | if (IS_OSPF6_DEBUG_ZEBRA (SEND)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 389 | zlog_debug (" Ignore self-originated external route"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 390 | return; |
| 391 | } |
| 392 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 393 | /* If removing is the best path and if there's another path, |
| 394 | treat this request as add the secondary path */ |
| 395 | if (type == REM && ospf6_route_is_best (request) && |
| 396 | request->next && ospf6_route_is_same (request, request->next)) |
| 397 | { |
| 398 | if (IS_OSPF6_DEBUG_ZEBRA (SEND)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 399 | zlog_debug (" Best-path removal resulted Sencondary addition"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 400 | type = ADD; |
| 401 | request = request->next; |
| 402 | } |
| 403 | |
| 404 | /* Only the best path will be sent to zebra. */ |
| 405 | if (! ospf6_route_is_best (request)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 406 | { |
| 407 | /* this is not preferred best route, ignore */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 408 | if (IS_OSPF6_DEBUG_ZEBRA (SEND)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 409 | zlog_debug (" Ignore non-best route"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 410 | return; |
| 411 | } |
| 412 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 413 | nhcount = 0; |
| 414 | for (i = 0; i < OSPF6_MULTI_PATH_LIMIT; i++) |
| 415 | if (ospf6_nexthop_is_set (&request->nexthop[i])) |
| 416 | nhcount++; |
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 (nhcount == 0) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 419 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 420 | if (IS_OSPF6_DEBUG_ZEBRA (SEND)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 421 | zlog_debug (" No nexthop, ignore"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 422 | return; |
| 423 | } |
| 424 | |
| 425 | /* allocate memory for nexthop_list */ |
| 426 | nexthops = XCALLOC (MTYPE_OSPF6_OTHER, |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 427 | nhcount * sizeof (struct in6_addr *)); |
| 428 | if (nexthops == NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 429 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 430 | zlog_warn ("Can't send route to zebra: malloc failed"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 431 | return; |
| 432 | } |
| 433 | |
| 434 | /* allocate memory for ifindex_list */ |
| 435 | ifindexes = XCALLOC (MTYPE_OSPF6_OTHER, |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 436 | nhcount * sizeof (unsigned int)); |
| 437 | if (ifindexes == NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 438 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 439 | zlog_warn ("Can't send route to zebra: malloc failed"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 440 | XFREE (MTYPE_OSPF6_OTHER, nexthops); |
| 441 | return; |
| 442 | } |
| 443 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 444 | for (i = 0; i < nhcount; i++) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 445 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 446 | if (IS_OSPF6_DEBUG_ZEBRA (SEND)) |
ajs | d2fc889 | 2005-04-02 18:38:43 +0000 | [diff] [blame] | 447 | { |
Feng Lu | 395828e | 2015-05-22 11:39:55 +0200 | [diff] [blame] | 448 | const char *ifname; |
ajs | d2fc889 | 2005-04-02 18:38:43 +0000 | [diff] [blame] | 449 | inet_ntop (AF_INET6, &request->nexthop[i].address, |
| 450 | buf, sizeof (buf)); |
Feng Lu | 395828e | 2015-05-22 11:39:55 +0200 | [diff] [blame] | 451 | ifname = ifindex2ifname (request->nexthop[i].ifindex); |
ajs | d2fc889 | 2005-04-02 18:38:43 +0000 | [diff] [blame] | 452 | zlog_debug (" nexthop: %s%%%.*s(%d)", buf, IFNAMSIZ, ifname, |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 453 | request->nexthop[i].ifindex); |
ajs | d2fc889 | 2005-04-02 18:38:43 +0000 | [diff] [blame] | 454 | } |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 455 | nexthops[i] = &request->nexthop[i].address; |
| 456 | ifindexes[i] = request->nexthop[i].ifindex; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 457 | } |
| 458 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 459 | api.vrf_id = VRF_DEFAULT; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 460 | api.type = ZEBRA_ROUTE_OSPF6; |
| 461 | api.flags = 0; |
| 462 | api.message = 0; |
Denis Ovsienko | b4e45f6 | 2011-12-05 16:35:14 +0400 | [diff] [blame] | 463 | api.safi = SAFI_UNICAST; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 464 | SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 465 | api.nexthop_num = nhcount; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 466 | api.nexthop = nexthops; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 467 | SET_FLAG (api.message, ZAPI_MESSAGE_IFINDEX); |
| 468 | api.ifindex_num = nhcount; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 469 | api.ifindex = ifindexes; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 470 | SET_FLAG (api.message, ZAPI_MESSAGE_METRIC); |
| 471 | api.metric = (request->path.metric_type == 2 ? |
| 472 | request->path.cost_e2 : request->path.cost); |
Roman Hoog Antink | d8f7f86 | 2014-03-05 09:13:43 +0100 | [diff] [blame] | 473 | SET_FLAG (api.message, ZAPI_MESSAGE_DISTANCE); |
| 474 | api.distance = ospf6_distance_apply (request, ospf6); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 475 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 476 | dest = (struct prefix_ipv6 *) &request->prefix; |
| 477 | if (type == REM) |
| 478 | ret = zapi_ipv6_route (ZEBRA_IPV6_ROUTE_DELETE, zclient, dest, &api); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 479 | else |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 480 | ret = zapi_ipv6_route (ZEBRA_IPV6_ROUTE_ADD, zclient, dest, &api); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 481 | |
| 482 | if (ret < 0) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 483 | zlog_err ("zapi_ipv6_route() %s failed: %s", |
ajs | 6099b3b | 2004-11-20 02:06:59 +0000 | [diff] [blame] | 484 | (type == REM ? "delete" : "add"), safe_strerror (errno)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 485 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 486 | XFREE (MTYPE_OSPF6_OTHER, nexthops); |
| 487 | XFREE (MTYPE_OSPF6_OTHER, ifindexes); |
| 488 | |
| 489 | return; |
| 490 | } |
| 491 | |
| 492 | void |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 493 | ospf6_zebra_route_update_add (struct ospf6_route *request) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 494 | { |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 495 | if (! vrf_bitmap_check (zclient->redist[ZEBRA_ROUTE_OSPF6], VRF_DEFAULT)) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 496 | { |
| 497 | ospf6->route_table->hook_add = NULL; |
| 498 | ospf6->route_table->hook_remove = NULL; |
| 499 | return; |
| 500 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 501 | ospf6_zebra_route_update (ADD, request); |
| 502 | } |
| 503 | |
| 504 | void |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 505 | ospf6_zebra_route_update_remove (struct ospf6_route *request) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 506 | { |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 507 | if (! vrf_bitmap_check (zclient->redist[ZEBRA_ROUTE_OSPF6], VRF_DEFAULT)) |
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->route_table->hook_add = NULL; |
| 510 | ospf6->route_table->hook_remove = NULL; |
| 511 | return; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 512 | } |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 513 | ospf6_zebra_route_update (REM, request); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 514 | } |
| 515 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 516 | DEFUN (redistribute_ospf6, |
| 517 | redistribute_ospf6_cmd, |
| 518 | "redistribute ospf6", |
| 519 | "Redistribute control\n" |
| 520 | "OSPF6 route\n") |
| 521 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 522 | struct ospf6_route *route; |
| 523 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 524 | if (vrf_bitmap_check (zclient->redist[ZEBRA_ROUTE_OSPF6], VRF_DEFAULT)) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 525 | return CMD_SUCCESS; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 526 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 527 | vrf_bitmap_set (zclient->redist[ZEBRA_ROUTE_OSPF6], VRF_DEFAULT); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 528 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 529 | if (ospf6 == NULL) |
| 530 | return CMD_SUCCESS; |
| 531 | |
| 532 | /* send ospf6 route to zebra route table */ |
| 533 | for (route = ospf6_route_head (ospf6->route_table); route; |
| 534 | route = ospf6_route_next (route)) |
| 535 | ospf6_zebra_route_update_add (route); |
| 536 | |
| 537 | ospf6->route_table->hook_add = ospf6_zebra_route_update_add; |
| 538 | ospf6->route_table->hook_remove = ospf6_zebra_route_update_remove; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 539 | |
| 540 | return CMD_SUCCESS; |
| 541 | } |
| 542 | |
| 543 | DEFUN (no_redistribute_ospf6, |
| 544 | no_redistribute_ospf6_cmd, |
| 545 | "no redistribute ospf6", |
| 546 | NO_STR |
| 547 | "Redistribute control\n" |
| 548 | "OSPF6 route\n") |
| 549 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 550 | struct ospf6_route *route; |
| 551 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 552 | if (! vrf_bitmap_check (zclient->redist[ZEBRA_ROUTE_OSPF6], VRF_DEFAULT)) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 553 | return CMD_SUCCESS; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 554 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 555 | vrf_bitmap_unset (zclient->redist[ZEBRA_ROUTE_OSPF6], VRF_DEFAULT); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 556 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 557 | if (ospf6 == NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 558 | return CMD_SUCCESS; |
| 559 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 560 | ospf6->route_table->hook_add = NULL; |
| 561 | ospf6->route_table->hook_remove = NULL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 562 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 563 | /* withdraw ospf6 route from zebra route table */ |
| 564 | for (route = ospf6_route_head (ospf6->route_table); route; |
| 565 | route = ospf6_route_next (route)) |
| 566 | ospf6_zebra_route_update_remove (route); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 567 | |
| 568 | return CMD_SUCCESS; |
| 569 | } |
| 570 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 571 | static void |
| 572 | ospf6_zebra_connected (struct zclient *zclient) |
| 573 | { |
| 574 | zclient_send_requests (zclient, VRF_DEFAULT); |
| 575 | } |
| 576 | |
Roman Hoog Antink | d8f7f86 | 2014-03-05 09:13:43 +0100 | [diff] [blame] | 577 | static struct ospf6_distance * |
| 578 | ospf6_distance_new (void) |
| 579 | { |
| 580 | return XCALLOC (MTYPE_OSPF6_DISTANCE, sizeof (struct ospf6_distance)); |
| 581 | } |
| 582 | |
| 583 | static void |
| 584 | ospf6_distance_free (struct ospf6_distance *odistance) |
| 585 | { |
| 586 | XFREE (MTYPE_OSPF6_DISTANCE, odistance); |
| 587 | } |
| 588 | |
| 589 | int |
| 590 | ospf6_distance_set (struct vty *vty, struct ospf6 *o, |
| 591 | const char *distance_str, |
| 592 | const char *ip_str, |
| 593 | const char *access_list_str) |
| 594 | { |
| 595 | int ret; |
| 596 | struct prefix_ipv6 p; |
| 597 | u_char distance; |
| 598 | struct route_node *rn; |
| 599 | struct ospf6_distance *odistance; |
| 600 | |
| 601 | ret = str2prefix_ipv6 (ip_str, &p); |
| 602 | if (ret == 0) |
| 603 | { |
| 604 | vty_out (vty, "Malformed prefix%s", VTY_NEWLINE); |
| 605 | return CMD_WARNING; |
| 606 | } |
| 607 | |
| 608 | distance = atoi (distance_str); |
| 609 | |
| 610 | /* Get OSPF6 distance node. */ |
| 611 | rn = route_node_get (o->distance_table, (struct prefix *) &p); |
| 612 | if (rn->info) |
| 613 | { |
| 614 | odistance = rn->info; |
| 615 | route_unlock_node (rn); |
| 616 | } |
| 617 | else |
| 618 | { |
| 619 | odistance = ospf6_distance_new (); |
| 620 | rn->info = odistance; |
| 621 | } |
| 622 | |
| 623 | /* Set distance value. */ |
| 624 | odistance->distance = distance; |
| 625 | |
| 626 | /*Reset access-list configuration. */ |
| 627 | if (odistance->access_list) |
| 628 | { |
| 629 | free (odistance->access_list); |
| 630 | odistance->access_list = NULL; |
| 631 | } |
| 632 | if (access_list_str) |
| 633 | odistance->access_list = strdup (access_list_str); |
| 634 | |
| 635 | return CMD_SUCCESS; |
| 636 | } |
| 637 | |
| 638 | int |
| 639 | ospf6_distance_unset (struct vty *vty, struct ospf6 *o, |
| 640 | const char *ip_str, |
| 641 | const char *access_list_str) |
| 642 | { |
| 643 | int ret; |
| 644 | struct prefix_ipv6 p; |
| 645 | struct route_node *rn; |
| 646 | struct ospf6_distance *odistance; |
| 647 | |
| 648 | ret = str2prefix_ipv6 (ip_str, &p); |
| 649 | if (ret == 0) |
| 650 | { |
| 651 | vty_out (vty, "Malformed prefix%s", VTY_NEWLINE); |
| 652 | return CMD_WARNING; |
| 653 | } |
| 654 | |
| 655 | rn = route_node_lookup (o->distance_table, (struct prefix *) &p); |
| 656 | if (!rn) |
| 657 | { |
| 658 | vty_out (vty, "Cant't find specified prefix%s", VTY_NEWLINE); |
| 659 | return CMD_WARNING; |
| 660 | } |
| 661 | |
| 662 | odistance = rn->info; |
| 663 | |
| 664 | if (odistance->access_list) |
| 665 | free (odistance->access_list); |
| 666 | ospf6_distance_free (odistance); |
| 667 | |
| 668 | rn->info = NULL; |
| 669 | route_unlock_node (rn); |
| 670 | route_unlock_node (rn); |
| 671 | |
| 672 | return CMD_SUCCESS; |
| 673 | } |
| 674 | |
| 675 | void |
| 676 | ospf6_distance_reset (struct ospf6 *o) |
| 677 | { |
| 678 | struct route_node *rn; |
| 679 | struct ospf6_distance *odistance; |
| 680 | |
| 681 | for (rn = route_top (o->distance_table); rn; rn = route_next (rn)) |
| 682 | if ((odistance = rn->info) != NULL) |
| 683 | { |
| 684 | if (odistance->access_list) |
| 685 | free (odistance->access_list); |
| 686 | ospf6_distance_free (odistance); |
| 687 | rn->info = NULL; |
| 688 | route_unlock_node (rn); |
| 689 | } |
| 690 | } |
| 691 | |
| 692 | u_char |
| 693 | ospf6_distance_apply (struct ospf6_route *or, struct ospf6 *o) |
| 694 | { |
| 695 | |
| 696 | if (o == NULL) |
| 697 | return 0; |
| 698 | |
| 699 | if (o->distance_intra) |
| 700 | if (or->path.type == OSPF6_PATH_TYPE_INTRA) |
| 701 | return o->distance_intra; |
| 702 | |
| 703 | if (o->distance_inter) |
| 704 | if (or->path.type == OSPF6_PATH_TYPE_INTER) |
| 705 | return o->distance_inter; |
| 706 | |
| 707 | if (o->distance_external) |
| 708 | if(or->path.type == OSPF6_PATH_TYPE_EXTERNAL1 |
| 709 | || or->path.type == OSPF6_PATH_TYPE_EXTERNAL2) |
| 710 | return o->distance_external; |
| 711 | |
| 712 | if (o->distance_all) |
| 713 | return o->distance_all; |
| 714 | |
| 715 | return 0; |
| 716 | } |
| 717 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 718 | void |
Donald Sharp | 7125293 | 2015-09-24 09:25:19 -0400 | [diff] [blame] | 719 | ospf6_zebra_init (struct thread_master *master) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 720 | { |
| 721 | /* Allocate zebra structure. */ |
Donald Sharp | 7125293 | 2015-09-24 09:25:19 -0400 | [diff] [blame] | 722 | zclient = zclient_new (master); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 723 | zclient_init (zclient, ZEBRA_ROUTE_OSPF6); |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 724 | zclient->zebra_connected = ospf6_zebra_connected; |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 725 | zclient->router_id_update = ospf6_router_id_update_zebra; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 726 | zclient->interface_add = ospf6_zebra_if_add; |
| 727 | zclient->interface_delete = ospf6_zebra_if_del; |
| 728 | zclient->interface_up = ospf6_zebra_if_state_update; |
| 729 | zclient->interface_down = ospf6_zebra_if_state_update; |
| 730 | zclient->interface_address_add = ospf6_zebra_if_address_update_add; |
| 731 | zclient->interface_address_delete = ospf6_zebra_if_address_update_delete; |
| 732 | zclient->ipv4_route_add = NULL; |
| 733 | zclient->ipv4_route_delete = NULL; |
| 734 | zclient->ipv6_route_add = ospf6_zebra_read_ipv6; |
| 735 | zclient->ipv6_route_delete = ospf6_zebra_read_ipv6; |
| 736 | |
| 737 | /* redistribute connected route by default */ |
| 738 | /* ospf6_zebra_redistribute (ZEBRA_ROUTE_CONNECT); */ |
| 739 | |
| 740 | /* Install zebra node. */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 741 | install_node (&zebra_node, config_write_ospf6_zebra); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 742 | |
| 743 | /* Install command element for zebra node. */ |
| 744 | install_element (VIEW_NODE, &show_zebra_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 745 | install_element (CONFIG_NODE, &router_zebra_cmd); |
| 746 | install_element (CONFIG_NODE, &no_router_zebra_cmd); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 747 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 748 | install_default (ZEBRA_NODE); |
| 749 | install_element (ZEBRA_NODE, &redistribute_ospf6_cmd); |
| 750 | install_element (ZEBRA_NODE, &no_redistribute_ospf6_cmd); |
| 751 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 752 | return; |
| 753 | } |
| 754 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 755 | /* Debug */ |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 756 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 757 | DEFUN (debug_ospf6_zebra_sendrecv, |
| 758 | debug_ospf6_zebra_sendrecv_cmd, |
| 759 | "debug ospf6 zebra (send|recv)", |
| 760 | DEBUG_STR |
| 761 | OSPF6_STR |
| 762 | "Debug connection between zebra\n" |
| 763 | "Debug Sending zebra\n" |
| 764 | "Debug Receiving zebra\n" |
| 765 | ) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 766 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 767 | unsigned char level = 0; |
| 768 | |
| 769 | if (argc) |
| 770 | { |
| 771 | if (! strncmp (argv[0], "s", 1)) |
| 772 | level = OSPF6_DEBUG_ZEBRA_SEND; |
| 773 | else if (! strncmp (argv[0], "r", 1)) |
| 774 | level = OSPF6_DEBUG_ZEBRA_RECV; |
| 775 | } |
| 776 | else |
| 777 | level = OSPF6_DEBUG_ZEBRA_SEND | OSPF6_DEBUG_ZEBRA_RECV; |
| 778 | |
| 779 | OSPF6_DEBUG_ZEBRA_ON (level); |
| 780 | return CMD_SUCCESS; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 781 | } |
| 782 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 783 | ALIAS (debug_ospf6_zebra_sendrecv, |
| 784 | debug_ospf6_zebra_cmd, |
| 785 | "debug ospf6 zebra", |
| 786 | DEBUG_STR |
| 787 | OSPF6_STR |
| 788 | "Debug connection between zebra\n" |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 789 | ) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 790 | |
| 791 | |
| 792 | DEFUN (no_debug_ospf6_zebra_sendrecv, |
| 793 | no_debug_ospf6_zebra_sendrecv_cmd, |
| 794 | "no debug ospf6 zebra (send|recv)", |
| 795 | NO_STR |
| 796 | DEBUG_STR |
| 797 | OSPF6_STR |
| 798 | "Debug connection between zebra\n" |
| 799 | "Debug Sending zebra\n" |
| 800 | "Debug Receiving zebra\n" |
| 801 | ) |
| 802 | { |
| 803 | unsigned char level = 0; |
| 804 | |
| 805 | if (argc) |
| 806 | { |
| 807 | if (! strncmp (argv[0], "s", 1)) |
| 808 | level = OSPF6_DEBUG_ZEBRA_SEND; |
| 809 | else if (! strncmp (argv[0], "r", 1)) |
| 810 | level = OSPF6_DEBUG_ZEBRA_RECV; |
| 811 | } |
| 812 | else |
| 813 | level = OSPF6_DEBUG_ZEBRA_SEND | OSPF6_DEBUG_ZEBRA_RECV; |
| 814 | |
| 815 | OSPF6_DEBUG_ZEBRA_OFF (level); |
| 816 | return CMD_SUCCESS; |
| 817 | } |
| 818 | |
| 819 | ALIAS (no_debug_ospf6_zebra_sendrecv, |
| 820 | no_debug_ospf6_zebra_cmd, |
| 821 | "no debug ospf6 zebra", |
| 822 | NO_STR |
| 823 | DEBUG_STR |
| 824 | OSPF6_STR |
| 825 | "Debug connection between zebra\n" |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 826 | ) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 827 | |
| 828 | int |
| 829 | config_write_ospf6_debug_zebra (struct vty *vty) |
| 830 | { |
| 831 | if (IS_OSPF6_DEBUG_ZEBRA (SEND) && IS_OSPF6_DEBUG_ZEBRA (RECV)) |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 832 | vty_out (vty, "debug ospf6 zebra%s", VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 833 | else |
| 834 | { |
| 835 | if (IS_OSPF6_DEBUG_ZEBRA (SEND)) |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 836 | vty_out (vty, "debug ospf6 zebra send%s", VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 837 | if (IS_OSPF6_DEBUG_ZEBRA (RECV)) |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 838 | vty_out (vty, "debug ospf6 zebra recv%s", VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 839 | } |
| 840 | return 0; |
| 841 | } |
| 842 | |
| 843 | void |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 844 | install_element_ospf6_debug_zebra (void) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 845 | { |
| 846 | install_element (ENABLE_NODE, &debug_ospf6_zebra_cmd); |
| 847 | install_element (ENABLE_NODE, &no_debug_ospf6_zebra_cmd); |
| 848 | install_element (ENABLE_NODE, &debug_ospf6_zebra_sendrecv_cmd); |
| 849 | install_element (ENABLE_NODE, &no_debug_ospf6_zebra_sendrecv_cmd); |
| 850 | install_element (CONFIG_NODE, &debug_ospf6_zebra_cmd); |
| 851 | install_element (CONFIG_NODE, &no_debug_ospf6_zebra_cmd); |
| 852 | install_element (CONFIG_NODE, &debug_ospf6_zebra_sendrecv_cmd); |
| 853 | install_element (CONFIG_NODE, &no_debug_ospf6_zebra_sendrecv_cmd); |
| 854 | } |
| 855 | |
| 856 | |