paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Zebra connect library for OSPFd |
| 3 | * Copyright (C) 1997, 98, 99, 2000 Kunihiro Ishiguro, Toshiaki Takada |
| 4 | * |
| 5 | * This file is part of GNU Zebra. |
| 6 | * |
| 7 | * GNU Zebra is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of the GNU General Public License as published by the |
| 9 | * Free Software Foundation; either version 2, or (at your option) any |
| 10 | * later version. |
| 11 | * |
| 12 | * GNU Zebra is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with GNU Zebra; see the file COPYING. If not, write to the |
| 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 20 | * Boston, MA 02111-1307, USA. |
| 21 | */ |
| 22 | |
| 23 | #include <zebra.h> |
| 24 | |
| 25 | #include "thread.h" |
| 26 | #include "command.h" |
| 27 | #include "network.h" |
| 28 | #include "prefix.h" |
| 29 | #include "routemap.h" |
| 30 | #include "table.h" |
| 31 | #include "stream.h" |
| 32 | #include "memory.h" |
| 33 | #include "zclient.h" |
| 34 | #include "filter.h" |
hasso | dd669bb | 2004-05-10 07:43:59 +0000 | [diff] [blame] | 35 | #include "plist.h" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 36 | #include "log.h" |
| 37 | |
| 38 | #include "ospfd/ospfd.h" |
| 39 | #include "ospfd/ospf_interface.h" |
| 40 | #include "ospfd/ospf_ism.h" |
| 41 | #include "ospfd/ospf_asbr.h" |
| 42 | #include "ospfd/ospf_asbr.h" |
| 43 | #include "ospfd/ospf_abr.h" |
| 44 | #include "ospfd/ospf_lsa.h" |
| 45 | #include "ospfd/ospf_dump.h" |
| 46 | #include "ospfd/ospf_route.h" |
| 47 | #include "ospfd/ospf_zebra.h" |
| 48 | #ifdef HAVE_SNMP |
| 49 | #include "ospfd/ospf_snmp.h" |
| 50 | #endif /* HAVE_SNMP */ |
| 51 | |
| 52 | /* Zebra structure to hold current status. */ |
| 53 | struct zclient *zclient = NULL; |
| 54 | |
| 55 | /* For registering threads. */ |
| 56 | extern struct thread_master *master; |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 57 | struct in_addr router_id_zebra; |
| 58 | |
| 59 | /* Router-id update message from zebra. */ |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 60 | static int |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 61 | ospf_router_id_update_zebra (int command, struct zclient *zclient, |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 62 | zebra_size_t length, vrf_id_t vrf_id) |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 63 | { |
| 64 | struct ospf *ospf; |
| 65 | struct prefix router_id; |
| 66 | zebra_router_id_update_read(zclient->ibuf,&router_id); |
| 67 | |
Andrew J. Schorr | 7f643eb | 2006-11-30 16:17:02 +0000 | [diff] [blame] | 68 | if (IS_DEBUG_OSPF (zebra, ZEBRA_INTERFACE)) |
| 69 | { |
| 70 | char buf[128]; |
| 71 | prefix2str(&router_id, buf, sizeof(buf)); |
| 72 | zlog_debug("Zebra rcvd: router id update %s", buf); |
| 73 | } |
| 74 | |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 75 | router_id_zebra = router_id.u.prefix4; |
| 76 | |
| 77 | ospf = ospf_lookup (); |
paul | b29800a | 2005-11-20 14:50:45 +0000 | [diff] [blame] | 78 | |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 79 | if (ospf != NULL) |
paul | b29800a | 2005-11-20 14:50:45 +0000 | [diff] [blame] | 80 | ospf_router_id_update (ospf); |
| 81 | |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 82 | return 0; |
| 83 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 84 | |
| 85 | /* Inteface addition message from zebra. */ |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 86 | static int |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 87 | ospf_interface_add (int command, struct zclient *zclient, zebra_size_t length, |
| 88 | vrf_id_t vrf_id) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 89 | { |
| 90 | struct interface *ifp; |
| 91 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 92 | ifp = zebra_interface_add_read (zclient->ibuf, vrf_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 93 | |
| 94 | if (IS_DEBUG_OSPF (zebra, ZEBRA_INTERFACE)) |
Stephen Hemminger | 30d2059 | 2009-07-28 11:58:51 +0100 | [diff] [blame] | 95 | zlog_debug ("Zebra: interface add %s index %d flags %llx metric %d mtu %d", |
| 96 | ifp->name, ifp->ifindex, (unsigned long long)ifp->flags, |
| 97 | ifp->metric, ifp->mtu); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 98 | |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 99 | assert (ifp->info); |
paul | f2c8065 | 2002-12-13 21:44:27 +0000 | [diff] [blame] | 100 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 101 | if (!OSPF_IF_PARAM_CONFIGURED (IF_DEF_PARAMS (ifp), type)) |
| 102 | { |
| 103 | SET_IF_PARAM (IF_DEF_PARAMS (ifp), type); |
ajs | bc18d61 | 2004-12-15 15:07:19 +0000 | [diff] [blame] | 104 | IF_DEF_PARAMS (ifp)->type = ospf_default_iftype(ifp); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 105 | } |
| 106 | |
Joakim Tjernlund | a49eb30 | 2008-09-02 19:06:31 +0100 | [diff] [blame] | 107 | ospf_if_update (NULL, ifp); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 108 | |
| 109 | #ifdef HAVE_SNMP |
| 110 | ospf_snmp_if_update (ifp); |
| 111 | #endif /* HAVE_SNMP */ |
| 112 | |
| 113 | return 0; |
| 114 | } |
| 115 | |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 116 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 117 | ospf_interface_delete (int command, struct zclient *zclient, |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 118 | zebra_size_t length, vrf_id_t vrf_id) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 119 | { |
| 120 | struct interface *ifp; |
| 121 | struct stream *s; |
| 122 | struct route_node *rn; |
| 123 | |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 124 | s = zclient->ibuf; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 125 | /* zebra_interface_state_read() updates interface structure in iflist */ |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 126 | ifp = zebra_interface_state_read (s, vrf_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 127 | |
| 128 | if (ifp == NULL) |
| 129 | return 0; |
| 130 | |
| 131 | if (if_is_up (ifp)) |
| 132 | zlog_warn ("Zebra: got delete of %s, but interface is still up", |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 133 | ifp->name); |
| 134 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 135 | if (IS_DEBUG_OSPF (zebra, ZEBRA_INTERFACE)) |
ajs | 9b0e25c | 2004-12-08 19:06:51 +0000 | [diff] [blame] | 136 | zlog_debug |
Andrew Certain | 0798cee | 2012-12-04 13:43:42 -0800 | [diff] [blame] | 137 | ("Zebra: interface delete %s index %d flags %llx metric %d mtu %d", |
| 138 | ifp->name, ifp->ifindex, (unsigned long long)ifp->flags, ifp->metric, ifp->mtu); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 139 | |
| 140 | #ifdef HAVE_SNMP |
| 141 | ospf_snmp_if_delete (ifp); |
| 142 | #endif /* HAVE_SNMP */ |
| 143 | |
| 144 | for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn)) |
| 145 | if (rn->info) |
| 146 | ospf_if_free ((struct ospf_interface *) rn->info); |
| 147 | |
ajs | d2fc889 | 2005-04-02 18:38:43 +0000 | [diff] [blame] | 148 | ifp->ifindex = IFINDEX_INTERNAL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 149 | return 0; |
| 150 | } |
| 151 | |
ajs | d2fc889 | 2005-04-02 18:38:43 +0000 | [diff] [blame] | 152 | static struct interface * |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 153 | zebra_interface_if_lookup (struct stream *s, vrf_id_t vrf_id) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 154 | { |
ajs | 21fefa9 | 2005-04-02 23:16:41 +0000 | [diff] [blame] | 155 | char ifname_tmp[INTERFACE_NAMSIZ]; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 156 | |
| 157 | /* Read interface name. */ |
| 158 | stream_get (ifname_tmp, s, INTERFACE_NAMSIZ); |
| 159 | |
ajs | d2fc889 | 2005-04-02 18:38:43 +0000 | [diff] [blame] | 160 | /* And look it up. */ |
ajs | 21fefa9 | 2005-04-02 23:16:41 +0000 | [diff] [blame] | 161 | return if_lookup_by_name_len(ifname_tmp, |
| 162 | strnlen(ifname_tmp, INTERFACE_NAMSIZ)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 163 | } |
| 164 | |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 165 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 166 | ospf_interface_state_up (int command, struct zclient *zclient, |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 167 | zebra_size_t length, vrf_id_t vrf_id) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 168 | { |
| 169 | struct interface *ifp; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 170 | struct ospf_interface *oi; |
| 171 | struct route_node *rn; |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 172 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 173 | ifp = zebra_interface_if_lookup (zclient->ibuf, vrf_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 174 | |
| 175 | if (ifp == NULL) |
| 176 | return 0; |
| 177 | |
| 178 | /* Interface is already up. */ |
paul | 2e3b2e4 | 2002-12-13 21:03:13 +0000 | [diff] [blame] | 179 | if (if_is_operative (ifp)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 180 | { |
| 181 | /* Temporarily keep ifp values. */ |
ajs | a608bbf | 2005-03-29 17:03:49 +0000 | [diff] [blame] | 182 | struct interface if_tmp; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 183 | memcpy (&if_tmp, ifp, sizeof (struct interface)); |
| 184 | |
| 185 | zebra_interface_if_set_value (zclient->ibuf, ifp); |
| 186 | |
| 187 | if (IS_DEBUG_OSPF (zebra, ZEBRA_INTERFACE)) |
ajs | 9b0e25c | 2004-12-08 19:06:51 +0000 | [diff] [blame] | 188 | zlog_debug ("Zebra: Interface[%s] state update.", ifp->name); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 189 | |
| 190 | if (if_tmp.bandwidth != ifp->bandwidth) |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 191 | { |
| 192 | if (IS_DEBUG_OSPF (zebra, ZEBRA_INTERFACE)) |
ajs | 9b0e25c | 2004-12-08 19:06:51 +0000 | [diff] [blame] | 193 | zlog_debug ("Zebra: Interface[%s] bandwidth change %d -> %d.", |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 194 | ifp->name, if_tmp.bandwidth, ifp->bandwidth); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 195 | |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 196 | ospf_if_recalculate_output_cost (ifp); |
| 197 | } |
ajs | a608bbf | 2005-03-29 17:03:49 +0000 | [diff] [blame] | 198 | |
| 199 | if (if_tmp.mtu != ifp->mtu) |
| 200 | { |
| 201 | if (IS_DEBUG_OSPF (zebra, ZEBRA_INTERFACE)) |
| 202 | zlog_debug ("Zebra: Interface[%s] MTU change %u -> %u.", |
| 203 | ifp->name, if_tmp.mtu, ifp->mtu); |
| 204 | |
| 205 | /* Must reset the interface (simulate down/up) when MTU changes. */ |
| 206 | ospf_if_reset(ifp); |
| 207 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 208 | return 0; |
| 209 | } |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 210 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 211 | zebra_interface_if_set_value (zclient->ibuf, ifp); |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 212 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 213 | if (IS_DEBUG_OSPF (zebra, ZEBRA_INTERFACE)) |
ajs | 9b0e25c | 2004-12-08 19:06:51 +0000 | [diff] [blame] | 214 | zlog_debug ("Zebra: Interface[%s] state change to up.", ifp->name); |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 215 | |
| 216 | for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 217 | { |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 218 | if ((oi = rn->info) == NULL) |
| 219 | continue; |
| 220 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 221 | ospf_if_up (oi); |
| 222 | } |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 223 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 224 | return 0; |
| 225 | } |
| 226 | |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 227 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 228 | ospf_interface_state_down (int command, struct zclient *zclient, |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 229 | zebra_size_t length, vrf_id_t vrf_id) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 230 | { |
| 231 | struct interface *ifp; |
| 232 | struct ospf_interface *oi; |
| 233 | struct route_node *node; |
| 234 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 235 | ifp = zebra_interface_state_read (zclient->ibuf, vrf_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 236 | |
| 237 | if (ifp == NULL) |
| 238 | return 0; |
| 239 | |
| 240 | if (IS_DEBUG_OSPF (zebra, ZEBRA_INTERFACE)) |
ajs | 9b0e25c | 2004-12-08 19:06:51 +0000 | [diff] [blame] | 241 | zlog_debug ("Zebra: Interface[%s] state change to down.", ifp->name); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 242 | |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 243 | for (node = route_top (IF_OIFS (ifp)); node; node = route_next (node)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 244 | { |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 245 | if ((oi = node->info) == NULL) |
| 246 | continue; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 247 | ospf_if_down (oi); |
| 248 | } |
| 249 | |
| 250 | return 0; |
| 251 | } |
| 252 | |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 253 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 254 | ospf_interface_address_add (int command, struct zclient *zclient, |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 255 | zebra_size_t length, vrf_id_t vrf_id) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 256 | { |
| 257 | struct connected *c; |
| 258 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 259 | c = zebra_interface_address_read (command, zclient->ibuf, vrf_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 260 | |
| 261 | if (c == NULL) |
| 262 | return 0; |
| 263 | |
Andrew J. Schorr | 7f643eb | 2006-11-30 16:17:02 +0000 | [diff] [blame] | 264 | if (IS_DEBUG_OSPF (zebra, ZEBRA_INTERFACE)) |
| 265 | { |
| 266 | char buf[128]; |
| 267 | prefix2str(c->address, buf, sizeof(buf)); |
| 268 | zlog_debug("Zebra: interface %s address add %s", c->ifp->name, buf); |
| 269 | } |
| 270 | |
Joakim Tjernlund | a49eb30 | 2008-09-02 19:06:31 +0100 | [diff] [blame] | 271 | ospf_if_update (NULL, c->ifp); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 272 | |
| 273 | #ifdef HAVE_SNMP |
| 274 | ospf_snmp_if_update (c->ifp); |
| 275 | #endif /* HAVE_SNMP */ |
| 276 | |
| 277 | return 0; |
| 278 | } |
| 279 | |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 280 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 281 | ospf_interface_address_delete (int command, struct zclient *zclient, |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 282 | zebra_size_t length, vrf_id_t vrf_id) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 283 | { |
| 284 | struct connected *c; |
| 285 | struct interface *ifp; |
| 286 | struct ospf_interface *oi; |
| 287 | struct route_node *rn; |
| 288 | struct prefix p; |
| 289 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 290 | c = zebra_interface_address_read (command, zclient->ibuf, vrf_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 291 | |
| 292 | if (c == NULL) |
| 293 | return 0; |
| 294 | |
Andrew J. Schorr | 7f643eb | 2006-11-30 16:17:02 +0000 | [diff] [blame] | 295 | if (IS_DEBUG_OSPF (zebra, ZEBRA_INTERFACE)) |
| 296 | { |
| 297 | char buf[128]; |
| 298 | prefix2str(c->address, buf, sizeof(buf)); |
| 299 | zlog_debug("Zebra: interface %s address delete %s", c->ifp->name, buf); |
| 300 | } |
| 301 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 302 | ifp = c->ifp; |
| 303 | p = *c->address; |
| 304 | p.prefixlen = IPV4_MAX_PREFIXLEN; |
| 305 | |
| 306 | rn = route_node_lookup (IF_OIFS (ifp), &p); |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 307 | if (!rn) |
paul | 98429f6 | 2006-01-10 22:11:54 +0000 | [diff] [blame] | 308 | { |
| 309 | connected_free (c); |
| 310 | return 0; |
| 311 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 312 | |
| 313 | assert (rn->info); |
| 314 | oi = rn->info; |
Joakim Tjernlund | fbb6c86 | 2010-03-08 13:58:09 +0100 | [diff] [blame] | 315 | route_unlock_node (rn); |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 316 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 317 | /* Call interface hook functions to clean up */ |
| 318 | ospf_if_free (oi); |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 319 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 320 | #ifdef HAVE_SNMP |
| 321 | ospf_snmp_if_update (c->ifp); |
| 322 | #endif /* HAVE_SNMP */ |
| 323 | |
| 324 | connected_free (c); |
| 325 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 326 | return 0; |
| 327 | } |
paul | 72357f2 | 2003-06-19 02:11:23 +0000 | [diff] [blame] | 328 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 329 | void |
| 330 | ospf_zebra_add (struct prefix_ipv4 *p, struct ospf_route *or) |
| 331 | { |
| 332 | u_char message; |
| 333 | u_char distance; |
| 334 | u_char flags; |
| 335 | int psize; |
| 336 | struct stream *s; |
| 337 | struct ospf_path *path; |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 338 | struct listnode *node; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 339 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 340 | if (vrf_bitmap_check (zclient->redist[ZEBRA_ROUTE_OSPF], VRF_DEFAULT)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 341 | { |
| 342 | message = 0; |
| 343 | flags = 0; |
| 344 | |
| 345 | /* OSPF pass nexthop and metric */ |
| 346 | SET_FLAG (message, ZAPI_MESSAGE_NEXTHOP); |
| 347 | SET_FLAG (message, ZAPI_MESSAGE_METRIC); |
| 348 | |
| 349 | /* Distance value. */ |
| 350 | distance = ospf_distance_apply (p, or); |
| 351 | if (distance) |
paul | 72357f2 | 2003-06-19 02:11:23 +0000 | [diff] [blame] | 352 | SET_FLAG (message, ZAPI_MESSAGE_DISTANCE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 353 | |
| 354 | /* Make packet. */ |
| 355 | s = zclient->obuf; |
| 356 | stream_reset (s); |
| 357 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 358 | /* Put command, type, flags, message. */ |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 359 | zclient_create_header (s, ZEBRA_IPV4_ROUTE_ADD, VRF_DEFAULT); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 360 | stream_putc (s, ZEBRA_ROUTE_OSPF); |
| 361 | stream_putc (s, flags); |
| 362 | stream_putc (s, message); |
Denis Ovsienko | b4e45f6 | 2011-12-05 16:35:14 +0400 | [diff] [blame] | 363 | stream_putw (s, SAFI_UNICAST); |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 364 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 365 | /* Put prefix information. */ |
| 366 | psize = PSIZE (p->prefixlen); |
| 367 | stream_putc (s, p->prefixlen); |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 368 | stream_write (s, (u_char *) & p->prefix, psize); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 369 | |
| 370 | /* Nexthop count. */ |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 371 | stream_putc (s, or->paths->count); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 372 | |
| 373 | /* Nexthop, ifindex, distance and metric information. */ |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 374 | for (ALL_LIST_ELEMENTS_RO (or->paths, node, path)) |
paul | 72357f2 | 2003-06-19 02:11:23 +0000 | [diff] [blame] | 375 | { |
Joakim Tjernlund | ba281d3 | 2012-07-07 17:06:13 +0200 | [diff] [blame] | 376 | if (path->nexthop.s_addr != INADDR_ANY && |
| 377 | path->ifindex != 0) |
| 378 | { |
| 379 | stream_putc (s, ZEBRA_NEXTHOP_IPV4_IFINDEX); |
| 380 | stream_put_in_addr (s, &path->nexthop); |
| 381 | stream_putl (s, path->ifindex); |
| 382 | } |
| 383 | else if (path->nexthop.s_addr != INADDR_ANY) |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 384 | { |
| 385 | stream_putc (s, ZEBRA_NEXTHOP_IPV4); |
| 386 | stream_put_in_addr (s, &path->nexthop); |
| 387 | } |
| 388 | else |
| 389 | { |
| 390 | stream_putc (s, ZEBRA_NEXTHOP_IFINDEX); |
Joakim Tjernlund | a8ba847 | 2009-07-27 12:42:34 +0200 | [diff] [blame] | 391 | if (path->ifindex) |
| 392 | stream_putl (s, path->ifindex); |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 393 | else |
| 394 | stream_putl (s, 0); |
| 395 | } |
paul | 72357f2 | 2003-06-19 02:11:23 +0000 | [diff] [blame] | 396 | |
| 397 | if (IS_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE)) |
| 398 | { |
Andrew J. Schorr | 56b3ea0 | 2007-03-14 20:21:43 +0000 | [diff] [blame] | 399 | char buf[2][INET_ADDRSTRLEN]; |
| 400 | zlog_debug("Zebra: Route add %s/%d nexthop %s", |
| 401 | inet_ntop(AF_INET, &p->prefix, |
| 402 | buf[0], sizeof(buf[0])), |
| 403 | p->prefixlen, |
| 404 | inet_ntop(AF_INET, &path->nexthop, |
| 405 | buf[1], sizeof(buf[1]))); |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 406 | } |
| 407 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 408 | |
| 409 | if (CHECK_FLAG (message, ZAPI_MESSAGE_DISTANCE)) |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 410 | stream_putc (s, distance); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 411 | if (CHECK_FLAG (message, ZAPI_MESSAGE_METRIC)) |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 412 | { |
| 413 | if (or->path_type == OSPF_PATH_TYPE1_EXTERNAL) |
| 414 | stream_putl (s, or->cost + or->u.ext.type2_cost); |
| 415 | else if (or->path_type == OSPF_PATH_TYPE2_EXTERNAL) |
| 416 | stream_putl (s, or->u.ext.type2_cost); |
| 417 | else |
| 418 | stream_putl (s, or->cost); |
| 419 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 420 | |
| 421 | stream_putw_at (s, 0, stream_get_endp (s)); |
| 422 | |
ajs | 634f9ea | 2005-04-11 15:51:40 +0000 | [diff] [blame] | 423 | zclient_send_message(zclient); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 424 | } |
| 425 | } |
| 426 | |
| 427 | void |
| 428 | ospf_zebra_delete (struct prefix_ipv4 *p, struct ospf_route *or) |
| 429 | { |
Joakim Tjernlund | ba281d3 | 2012-07-07 17:06:13 +0200 | [diff] [blame] | 430 | u_char message; |
| 431 | u_char distance; |
| 432 | u_char flags; |
| 433 | int psize; |
| 434 | struct stream *s; |
paul | 72357f2 | 2003-06-19 02:11:23 +0000 | [diff] [blame] | 435 | struct ospf_path *path; |
Joakim Tjernlund | ba281d3 | 2012-07-07 17:06:13 +0200 | [diff] [blame] | 436 | struct listnode *node; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 437 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 438 | if (vrf_bitmap_check (zclient->redist[ZEBRA_ROUTE_OSPF], VRF_DEFAULT)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 439 | { |
Joakim Tjernlund | ba281d3 | 2012-07-07 17:06:13 +0200 | [diff] [blame] | 440 | message = 0; |
| 441 | flags = 0; |
| 442 | /* Distance value. */ |
| 443 | distance = ospf_distance_apply (p, or); |
| 444 | /* Make packet. */ |
| 445 | s = zclient->obuf; |
| 446 | stream_reset (s); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 447 | |
Joakim Tjernlund | ba281d3 | 2012-07-07 17:06:13 +0200 | [diff] [blame] | 448 | /* Put command, type, flags, message. */ |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 449 | zclient_create_header (s, ZEBRA_IPV4_ROUTE_DELETE, VRF_DEFAULT); |
Joakim Tjernlund | ba281d3 | 2012-07-07 17:06:13 +0200 | [diff] [blame] | 450 | stream_putc (s, ZEBRA_ROUTE_OSPF); |
| 451 | stream_putc (s, flags); |
| 452 | stream_putc (s, message); |
| 453 | stream_putw (s, SAFI_UNICAST); |
paul | 72357f2 | 2003-06-19 02:11:23 +0000 | [diff] [blame] | 454 | |
Joakim Tjernlund | ba281d3 | 2012-07-07 17:06:13 +0200 | [diff] [blame] | 455 | /* Put prefix information. */ |
| 456 | psize = PSIZE (p->prefixlen); |
| 457 | stream_putc (s, p->prefixlen); |
| 458 | stream_write (s, (u_char *) & p->prefix, psize); |
paul | 72357f2 | 2003-06-19 02:11:23 +0000 | [diff] [blame] | 459 | |
Joakim Tjernlund | ba281d3 | 2012-07-07 17:06:13 +0200 | [diff] [blame] | 460 | /* Nexthop count. */ |
| 461 | stream_putc (s, or->paths->count); |
| 462 | |
| 463 | /* Nexthop, ifindex, distance and metric information. */ |
| 464 | for (ALL_LIST_ELEMENTS_RO (or->paths, node, path)) |
| 465 | { |
| 466 | if (path->nexthop.s_addr != INADDR_ANY && |
| 467 | path->ifindex != 0) |
| 468 | { |
| 469 | stream_putc (s, ZEBRA_NEXTHOP_IPV4_IFINDEX); |
| 470 | stream_put_in_addr (s, &path->nexthop); |
| 471 | stream_putl (s, path->ifindex); |
| 472 | } |
| 473 | else if (path->nexthop.s_addr != INADDR_ANY) |
| 474 | { |
| 475 | stream_putc (s, ZEBRA_NEXTHOP_IPV4); |
| 476 | stream_put_in_addr (s, &path->nexthop); |
| 477 | } |
| 478 | else |
| 479 | { |
| 480 | stream_putc (s, ZEBRA_NEXTHOP_IFINDEX); |
| 481 | stream_putl (s, path->ifindex); |
| 482 | } |
| 483 | |
| 484 | if (IS_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE)) |
| 485 | { |
Andrew J. Schorr | 56b3ea0 | 2007-03-14 20:21:43 +0000 | [diff] [blame] | 486 | char buf[2][INET_ADDRSTRLEN]; |
Christian Franke | a25a126 | 2013-11-27 14:36:05 +0000 | [diff] [blame] | 487 | zlog_debug("Zebra: Route delete %s/%d nexthop %s", |
Joakim Tjernlund | ba281d3 | 2012-07-07 17:06:13 +0200 | [diff] [blame] | 488 | inet_ntop(AF_INET, &p->prefix, |
| 489 | buf[0], sizeof(buf[0])), |
Andrew J. Schorr | 56b3ea0 | 2007-03-14 20:21:43 +0000 | [diff] [blame] | 490 | p->prefixlen, |
Joakim Tjernlund | ba281d3 | 2012-07-07 17:06:13 +0200 | [diff] [blame] | 491 | inet_ntop(AF_INET, &path->nexthop, |
Andrew J. Schorr | 56b3ea0 | 2007-03-14 20:21:43 +0000 | [diff] [blame] | 492 | buf[1], sizeof(buf[1]))); |
Joakim Tjernlund | ba281d3 | 2012-07-07 17:06:13 +0200 | [diff] [blame] | 493 | } |
| 494 | } |
| 495 | |
| 496 | if (CHECK_FLAG (message, ZAPI_MESSAGE_DISTANCE)) |
| 497 | stream_putc (s, distance); |
| 498 | if (CHECK_FLAG (message, ZAPI_MESSAGE_METRIC)) |
| 499 | { |
| 500 | if (or->path_type == OSPF_PATH_TYPE1_EXTERNAL) |
| 501 | stream_putl (s, or->cost + or->u.ext.type2_cost); |
| 502 | else if (or->path_type == OSPF_PATH_TYPE2_EXTERNAL) |
| 503 | stream_putl (s, or->u.ext.type2_cost); |
| 504 | else |
| 505 | stream_putl (s, or->cost); |
| 506 | } |
| 507 | |
| 508 | stream_putw_at (s, 0, stream_get_endp (s)); |
| 509 | |
| 510 | zclient_send_message(zclient); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 511 | } |
| 512 | } |
| 513 | |
| 514 | void |
| 515 | ospf_zebra_add_discard (struct prefix_ipv4 *p) |
| 516 | { |
| 517 | struct zapi_ipv4 api; |
| 518 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 519 | if (vrf_bitmap_check (zclient->redist[ZEBRA_ROUTE_OSPF], VRF_DEFAULT)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 520 | { |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 521 | api.vrf_id = VRF_DEFAULT; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 522 | api.type = ZEBRA_ROUTE_OSPF; |
| 523 | api.flags = ZEBRA_FLAG_BLACKHOLE; |
| 524 | api.message = 0; |
Denis Ovsienko | b4e45f6 | 2011-12-05 16:35:14 +0400 | [diff] [blame] | 525 | api.safi = SAFI_UNICAST; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 526 | SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP); |
| 527 | api.nexthop_num = 0; |
| 528 | api.ifindex_num = 0; |
| 529 | |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 530 | zapi_ipv4_route (ZEBRA_IPV4_ROUTE_ADD, zclient, p, &api); |
Andrew J. Schorr | 7f643eb | 2006-11-30 16:17:02 +0000 | [diff] [blame] | 531 | |
| 532 | if (IS_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE)) |
| 533 | zlog_debug ("Zebra: Route add discard %s/%d", |
| 534 | inet_ntoa (p->prefix), p->prefixlen); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 535 | } |
| 536 | } |
| 537 | |
| 538 | void |
| 539 | ospf_zebra_delete_discard (struct prefix_ipv4 *p) |
| 540 | { |
| 541 | struct zapi_ipv4 api; |
| 542 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 543 | if (vrf_bitmap_check (zclient->redist[ZEBRA_ROUTE_OSPF], VRF_DEFAULT)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 544 | { |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 545 | api.vrf_id = VRF_DEFAULT; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 546 | api.type = ZEBRA_ROUTE_OSPF; |
| 547 | api.flags = ZEBRA_FLAG_BLACKHOLE; |
| 548 | api.message = 0; |
Denis Ovsienko | b4e45f6 | 2011-12-05 16:35:14 +0400 | [diff] [blame] | 549 | api.safi = SAFI_UNICAST; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 550 | SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP); |
| 551 | api.nexthop_num = 0; |
| 552 | api.ifindex_num = 0; |
| 553 | |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 554 | zapi_ipv4_route (ZEBRA_IPV4_ROUTE_DELETE, zclient, p, &api); |
paul | 72357f2 | 2003-06-19 02:11:23 +0000 | [diff] [blame] | 555 | |
| 556 | if (IS_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE)) |
ajs | 9b0e25c | 2004-12-08 19:06:51 +0000 | [diff] [blame] | 557 | zlog_debug ("Zebra: Route delete discard %s/%d", |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 558 | inet_ntoa (p->prefix), p->prefixlen); |
paul | 72357f2 | 2003-06-19 02:11:23 +0000 | [diff] [blame] | 559 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 560 | } |
| 561 | } |
| 562 | |
| 563 | int |
| 564 | ospf_is_type_redistributed (int type) |
| 565 | { |
| 566 | return (DEFAULT_ROUTE_TYPE (type)) ? |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 567 | vrf_bitmap_check (zclient->default_information, VRF_DEFAULT) : \ |
| 568 | vrf_bitmap_check (zclient->redist[type], VRF_DEFAULT); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 569 | } |
| 570 | |
| 571 | int |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 572 | ospf_redistribute_set (struct ospf *ospf, int type, int mtype, int mvalue) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 573 | { |
| 574 | int force = 0; |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 575 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 576 | if (ospf_is_type_redistributed (type)) |
| 577 | { |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 578 | if (mtype != ospf->dmetric[type].type) |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 579 | { |
| 580 | ospf->dmetric[type].type = mtype; |
| 581 | force = LSA_REFRESH_FORCE; |
| 582 | } |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 583 | if (mvalue != ospf->dmetric[type].value) |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 584 | { |
| 585 | ospf->dmetric[type].value = mvalue; |
| 586 | force = LSA_REFRESH_FORCE; |
| 587 | } |
| 588 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 589 | ospf_external_lsa_refresh_type (ospf, type, force); |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 590 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 591 | if (IS_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE)) |
ajs | 9b0e25c | 2004-12-08 19:06:51 +0000 | [diff] [blame] | 592 | zlog_debug ("Redistribute[%s]: Refresh Type[%d], Metric[%d]", |
ajs | f52d13c | 2005-10-01 17:38:06 +0000 | [diff] [blame] | 593 | ospf_redist_string(type), |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 594 | metric_type (ospf, type), metric_value (ospf, type)); |
| 595 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 596 | return CMD_SUCCESS; |
| 597 | } |
| 598 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 599 | ospf->dmetric[type].type = mtype; |
| 600 | ospf->dmetric[type].value = mvalue; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 601 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 602 | zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, type, VRF_DEFAULT); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 603 | |
| 604 | if (IS_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE)) |
ajs | 9b0e25c | 2004-12-08 19:06:51 +0000 | [diff] [blame] | 605 | zlog_debug ("Redistribute[%s]: Start Type[%d], Metric[%d]", |
ajs | f52d13c | 2005-10-01 17:38:06 +0000 | [diff] [blame] | 606 | ospf_redist_string(type), |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 607 | metric_type (ospf, type), metric_value (ospf, type)); |
| 608 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 609 | ospf_asbr_status_update (ospf, ++ospf->redistribute); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 610 | |
| 611 | return CMD_SUCCESS; |
| 612 | } |
| 613 | |
| 614 | int |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 615 | ospf_redistribute_unset (struct ospf *ospf, int type) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 616 | { |
| 617 | if (type == zclient->redist_default) |
| 618 | return CMD_SUCCESS; |
| 619 | |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 620 | if (!ospf_is_type_redistributed (type)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 621 | return CMD_SUCCESS; |
| 622 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 623 | zclient_redistribute (ZEBRA_REDISTRIBUTE_DELETE, zclient, type, VRF_DEFAULT); |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 624 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 625 | if (IS_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE)) |
ajs | 9b0e25c | 2004-12-08 19:06:51 +0000 | [diff] [blame] | 626 | zlog_debug ("Redistribute[%s]: Stop", |
ajs | f52d13c | 2005-10-01 17:38:06 +0000 | [diff] [blame] | 627 | ospf_redist_string(type)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 628 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 629 | ospf->dmetric[type].type = -1; |
| 630 | ospf->dmetric[type].value = -1; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 631 | |
| 632 | /* Remove the routes from OSPF table. */ |
Paul Jakma | 6db3a6f | 2006-05-12 23:02:46 +0000 | [diff] [blame] | 633 | ospf_redistribute_withdraw (ospf, type); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 634 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 635 | ospf_asbr_status_update (ospf, --ospf->redistribute); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 636 | |
| 637 | return CMD_SUCCESS; |
| 638 | } |
| 639 | |
| 640 | int |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 641 | ospf_redistribute_default_set (struct ospf *ospf, int originate, |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 642 | int mtype, int mvalue) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 643 | { |
Andrew J. Schorr | 8fb8a50 | 2006-10-24 19:04:26 +0000 | [diff] [blame] | 644 | ospf->default_originate = originate; |
| 645 | ospf->dmetric[DEFAULT_ROUTE].type = mtype; |
| 646 | ospf->dmetric[DEFAULT_ROUTE].value = mvalue; |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 647 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 648 | if (ospf_is_type_redistributed (DEFAULT_ROUTE)) |
| 649 | { |
Andrew J. Schorr | 8fb8a50 | 2006-10-24 19:04:26 +0000 | [diff] [blame] | 650 | /* if ospf->default_originate changes value, is calling |
| 651 | ospf_external_lsa_refresh_default sufficient to implement |
| 652 | the change? */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 653 | ospf_external_lsa_refresh_default (ospf); |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 654 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 655 | if (IS_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE)) |
ajs | 9b0e25c | 2004-12-08 19:06:51 +0000 | [diff] [blame] | 656 | zlog_debug ("Redistribute[%s]: Refresh Type[%d], Metric[%d]", |
ajs | f52d13c | 2005-10-01 17:38:06 +0000 | [diff] [blame] | 657 | ospf_redist_string(DEFAULT_ROUTE), |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 658 | metric_type (ospf, DEFAULT_ROUTE), |
| 659 | metric_value (ospf, DEFAULT_ROUTE)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 660 | return CMD_SUCCESS; |
| 661 | } |
| 662 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 663 | zclient_redistribute_default (ZEBRA_REDISTRIBUTE_DEFAULT_ADD, zclient, |
| 664 | VRF_DEFAULT); |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 665 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 666 | if (IS_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE)) |
ajs | 9b0e25c | 2004-12-08 19:06:51 +0000 | [diff] [blame] | 667 | zlog_debug ("Redistribute[DEFAULT]: Start Type[%d], Metric[%d]", |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 668 | metric_type (ospf, DEFAULT_ROUTE), |
| 669 | metric_value (ospf, DEFAULT_ROUTE)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 670 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 671 | if (ospf->router_id.s_addr == 0) |
| 672 | ospf->external_origin |= (1 << DEFAULT_ROUTE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 673 | else |
Paul Jakma | 4021b60 | 2006-05-12 22:55:41 +0000 | [diff] [blame] | 674 | thread_add_timer (master, ospf_default_originate_timer, ospf, 1); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 675 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 676 | ospf_asbr_status_update (ospf, ++ospf->redistribute); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 677 | |
| 678 | return CMD_SUCCESS; |
| 679 | } |
| 680 | |
| 681 | int |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 682 | ospf_redistribute_default_unset (struct ospf *ospf) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 683 | { |
| 684 | if (!ospf_is_type_redistributed (DEFAULT_ROUTE)) |
| 685 | return CMD_SUCCESS; |
| 686 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 687 | ospf->default_originate = DEFAULT_ORIGINATE_NONE; |
| 688 | ospf->dmetric[DEFAULT_ROUTE].type = -1; |
| 689 | ospf->dmetric[DEFAULT_ROUTE].value = -1; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 690 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 691 | zclient_redistribute_default (ZEBRA_REDISTRIBUTE_DEFAULT_DELETE, zclient, |
| 692 | VRF_DEFAULT); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 693 | |
| 694 | if (IS_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE)) |
ajs | 9b0e25c | 2004-12-08 19:06:51 +0000 | [diff] [blame] | 695 | zlog_debug ("Redistribute[DEFAULT]: Stop"); |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 696 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 697 | ospf_asbr_status_update (ospf, --ospf->redistribute); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 698 | |
| 699 | return CMD_SUCCESS; |
| 700 | } |
| 701 | |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 702 | static int |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 703 | ospf_external_lsa_originate_check (struct ospf *ospf, |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 704 | struct external_info *ei) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 705 | { |
| 706 | /* If prefix is multicast, then do not originate LSA. */ |
| 707 | if (IN_MULTICAST (htonl (ei->p.prefix.s_addr))) |
| 708 | { |
| 709 | zlog_info ("LSA[Type5:%s]: Not originate AS-external-LSA, " |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 710 | "Prefix belongs multicast", inet_ntoa (ei->p.prefix)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 711 | return 0; |
| 712 | } |
| 713 | |
| 714 | /* Take care of default-originate. */ |
| 715 | if (is_prefix_default (&ei->p)) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 716 | if (ospf->default_originate == DEFAULT_ORIGINATE_NONE) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 717 | { |
Denis Ovsienko | bcc6c59 | 2011-09-10 23:29:19 +0400 | [diff] [blame] | 718 | zlog_info ("LSA[Type5:0.0.0.0]: Not originate AS-external-LSA " |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 719 | "for default"); |
| 720 | return 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | return 1; |
| 724 | } |
| 725 | |
| 726 | /* If connected prefix is OSPF enable interface, then do not announce. */ |
| 727 | int |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 728 | ospf_distribute_check_connected (struct ospf *ospf, struct external_info *ei) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 729 | { |
Joakim Tjernlund | 5d8de93 | 2009-08-07 13:48:15 +0200 | [diff] [blame] | 730 | struct listnode *node; |
| 731 | struct ospf_interface *oi; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 732 | |
Joakim Tjernlund | 5d8de93 | 2009-08-07 13:48:15 +0200 | [diff] [blame] | 733 | |
| 734 | for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi)) |
| 735 | if (prefix_match (oi->address, (struct prefix *) &ei->p)) |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 736 | return 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 737 | return 1; |
| 738 | } |
| 739 | |
| 740 | /* return 1 if external LSA must be originated, 0 otherwise */ |
| 741 | int |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 742 | ospf_redistribute_check (struct ospf *ospf, |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 743 | struct external_info *ei, int *changed) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 744 | { |
| 745 | struct route_map_set_values save_values; |
| 746 | struct prefix_ipv4 *p = &ei->p; |
| 747 | u_char type = is_prefix_default (&ei->p) ? DEFAULT_ROUTE : ei->type; |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 748 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 749 | if (changed) |
| 750 | *changed = 0; |
| 751 | |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 752 | if (!ospf_external_lsa_originate_check (ospf, ei)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 753 | return 0; |
| 754 | |
| 755 | /* Take care connected route. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 756 | if (type == ZEBRA_ROUTE_CONNECT && |
| 757 | !ospf_distribute_check_connected (ospf, ei)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 758 | return 0; |
| 759 | |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 760 | if (!DEFAULT_ROUTE_TYPE (type) && DISTRIBUTE_NAME (ospf, type)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 761 | /* distirbute-list exists, but access-list may not? */ |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 762 | if (DISTRIBUTE_LIST (ospf, type)) |
| 763 | if (access_list_apply (DISTRIBUTE_LIST (ospf, type), p) == FILTER_DENY) |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 764 | { |
| 765 | if (IS_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE)) |
ajs | 9b0e25c | 2004-12-08 19:06:51 +0000 | [diff] [blame] | 766 | zlog_debug ("Redistribute[%s]: %s/%d filtered by ditribute-list.", |
ajs | f52d13c | 2005-10-01 17:38:06 +0000 | [diff] [blame] | 767 | ospf_redist_string(type), |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 768 | inet_ntoa (p->prefix), p->prefixlen); |
| 769 | return 0; |
| 770 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 771 | |
| 772 | save_values = ei->route_map_set; |
| 773 | ospf_reset_route_map_set_values (&ei->route_map_set); |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 774 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 775 | /* apply route-map if needed */ |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 776 | if (ROUTEMAP_NAME (ospf, type)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 777 | { |
| 778 | int ret; |
| 779 | |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 780 | ret = route_map_apply (ROUTEMAP (ospf, type), (struct prefix *) p, |
| 781 | RMAP_OSPF, ei); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 782 | |
| 783 | if (ret == RMAP_DENYMATCH) |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 784 | { |
| 785 | ei->route_map_set = save_values; |
| 786 | if (IS_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE)) |
ajs | 9b0e25c | 2004-12-08 19:06:51 +0000 | [diff] [blame] | 787 | zlog_debug ("Redistribute[%s]: %s/%d filtered by route-map.", |
ajs | f52d13c | 2005-10-01 17:38:06 +0000 | [diff] [blame] | 788 | ospf_redist_string(type), |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 789 | inet_ntoa (p->prefix), p->prefixlen); |
| 790 | return 0; |
| 791 | } |
| 792 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 793 | /* check if 'route-map set' changed something */ |
| 794 | if (changed) |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 795 | *changed = !ospf_route_map_set_compare (&ei->route_map_set, |
| 796 | &save_values); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 797 | } |
| 798 | |
| 799 | return 1; |
| 800 | } |
| 801 | |
| 802 | /* OSPF route-map set for redistribution */ |
| 803 | void |
paul | 6c83567 | 2004-10-11 11:00:30 +0000 | [diff] [blame] | 804 | ospf_routemap_set (struct ospf *ospf, int type, const char *name) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 805 | { |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 806 | if (ROUTEMAP_NAME (ospf, type)) |
| 807 | free (ROUTEMAP_NAME (ospf, type)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 808 | |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 809 | ROUTEMAP_NAME (ospf, type) = strdup (name); |
| 810 | ROUTEMAP (ospf, type) = route_map_lookup_by_name (name); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 811 | } |
| 812 | |
| 813 | void |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 814 | ospf_routemap_unset (struct ospf *ospf, int type) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 815 | { |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 816 | if (ROUTEMAP_NAME (ospf, type)) |
| 817 | free (ROUTEMAP_NAME (ospf, type)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 818 | |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 819 | ROUTEMAP_NAME (ospf, type) = NULL; |
| 820 | ROUTEMAP (ospf, type) = NULL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 821 | } |
| 822 | |
| 823 | /* Zebra route add and delete treatment. */ |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 824 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 825 | ospf_zebra_read_ipv4 (int command, struct zclient *zclient, |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 826 | zebra_size_t length, vrf_id_t vrf_id) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 827 | { |
| 828 | struct stream *s; |
| 829 | struct zapi_ipv4 api; |
| 830 | unsigned long ifindex; |
| 831 | struct in_addr nexthop; |
| 832 | struct prefix_ipv4 p; |
| 833 | struct external_info *ei; |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 834 | struct ospf *ospf; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 835 | |
| 836 | s = zclient->ibuf; |
| 837 | ifindex = 0; |
| 838 | nexthop.s_addr = 0; |
| 839 | |
| 840 | /* Type, flags, message. */ |
| 841 | api.type = stream_getc (s); |
| 842 | api.flags = stream_getc (s); |
| 843 | api.message = stream_getc (s); |
| 844 | |
| 845 | /* IPv4 prefix. */ |
| 846 | memset (&p, 0, sizeof (struct prefix_ipv4)); |
| 847 | p.family = AF_INET; |
Paul Jakma | bf83fa2 | 2016-02-09 15:23:03 +0000 | [diff] [blame] | 848 | p.prefixlen = MIN(IPV4_MAX_PREFIXLEN, stream_getc (s)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 849 | stream_get (&p.prefix, s, PSIZE (p.prefixlen)); |
| 850 | |
hasso | 8585d4e | 2004-04-20 17:25:12 +0000 | [diff] [blame] | 851 | if (IPV4_NET127(ntohl(p.prefix.s_addr))) |
| 852 | return 0; |
| 853 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 854 | /* Nexthop, ifindex, distance, metric. */ |
| 855 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP)) |
| 856 | { |
| 857 | api.nexthop_num = stream_getc (s); |
| 858 | nexthop.s_addr = stream_get_ipv4 (s); |
| 859 | } |
| 860 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_IFINDEX)) |
| 861 | { |
| 862 | api.ifindex_num = stream_getc (s); |
gdt | 6a8da85 | 2004-02-13 17:40:51 +0000 | [diff] [blame] | 863 | /* XXX assert(api.ifindex_num == 1); */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 864 | ifindex = stream_getl (s); |
| 865 | } |
| 866 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE)) |
| 867 | api.distance = stream_getc (s); |
| 868 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC)) |
| 869 | api.metric = stream_getl (s); |
| 870 | |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 871 | ospf = ospf_lookup (); |
| 872 | if (ospf == NULL) |
| 873 | return 0; |
| 874 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 875 | if (command == ZEBRA_IPV4_ROUTE_ADD) |
| 876 | { |
paul | 7021c42 | 2003-07-15 12:52:22 +0000 | [diff] [blame] | 877 | /* XXX|HACK|TODO|FIXME: |
hasso | a0a3976 | 2004-04-23 08:51:10 +0000 | [diff] [blame] | 878 | * Maybe we should ignore reject/blackhole routes? Testing shows that |
| 879 | * there is no problems though and this is only way to "summarize" |
| 880 | * routes in ASBR at the moment. Maybe we need just a better generalised |
| 881 | * solution for these types? |
| 882 | * |
| 883 | * if ( CHECK_FLAG (api.flags, ZEBRA_FLAG_BLACKHOLE) |
| 884 | * || CHECK_FLAG (api.flags, ZEBRA_FLAG_REJECT)) |
| 885 | * return 0; |
paul | 7021c42 | 2003-07-15 12:52:22 +0000 | [diff] [blame] | 886 | */ |
paul | 7021c42 | 2003-07-15 12:52:22 +0000 | [diff] [blame] | 887 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 888 | ei = ospf_external_info_add (api.type, p, ifindex, nexthop); |
| 889 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 890 | if (ospf->router_id.s_addr == 0) |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 891 | /* Set flags to generate AS-external-LSA originate event |
| 892 | for each redistributed protocols later. */ |
| 893 | ospf->external_origin |= (1 << api.type); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 894 | else |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 895 | { |
| 896 | if (ei) |
| 897 | { |
| 898 | if (is_prefix_default (&p)) |
| 899 | ospf_external_lsa_refresh_default (ospf); |
| 900 | else |
| 901 | { |
| 902 | struct ospf_lsa *current; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 903 | |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 904 | current = ospf_external_info_find_lsa (ospf, &ei->p); |
| 905 | if (!current) |
| 906 | ospf_external_lsa_originate (ospf, ei); |
| 907 | else if (IS_LSA_MAXAGE (current)) |
| 908 | ospf_external_lsa_refresh (ospf, current, |
| 909 | ei, LSA_REFRESH_FORCE); |
| 910 | else |
| 911 | zlog_warn ("ospf_zebra_read_ipv4() : %s already exists", |
| 912 | inet_ntoa (p.prefix)); |
| 913 | } |
| 914 | } |
| 915 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 916 | } |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 917 | else /* if (command == ZEBRA_IPV4_ROUTE_DELETE) */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 918 | { |
| 919 | ospf_external_info_delete (api.type, p); |
paul | 7021c42 | 2003-07-15 12:52:22 +0000 | [diff] [blame] | 920 | if (is_prefix_default (&p)) |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 921 | ospf_external_lsa_refresh_default (ospf); |
paul | 7021c42 | 2003-07-15 12:52:22 +0000 | [diff] [blame] | 922 | else |
ajs | 5339cfd | 2005-09-19 13:28:05 +0000 | [diff] [blame] | 923 | ospf_external_lsa_flush (ospf, api.type, &p, ifindex /*, nexthop */); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 924 | } |
| 925 | |
| 926 | return 0; |
| 927 | } |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 928 | |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 929 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 930 | int |
paul | 6c83567 | 2004-10-11 11:00:30 +0000 | [diff] [blame] | 931 | ospf_distribute_list_out_set (struct ospf *ospf, int type, const char *name) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 932 | { |
| 933 | /* Lookup access-list for distribute-list. */ |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 934 | DISTRIBUTE_LIST (ospf, type) = access_list_lookup (AFI_IP, name); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 935 | |
| 936 | /* Clear previous distribute-name. */ |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 937 | if (DISTRIBUTE_NAME (ospf, type)) |
| 938 | free (DISTRIBUTE_NAME (ospf, type)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 939 | |
| 940 | /* Set distribute-name. */ |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 941 | DISTRIBUTE_NAME (ospf, type) = strdup (name); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 942 | |
| 943 | /* If access-list have been set, schedule update timer. */ |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 944 | if (DISTRIBUTE_LIST (ospf, type)) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 945 | ospf_distribute_list_update (ospf, type); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 946 | |
| 947 | return CMD_SUCCESS; |
| 948 | } |
| 949 | |
| 950 | int |
paul | 6c83567 | 2004-10-11 11:00:30 +0000 | [diff] [blame] | 951 | ospf_distribute_list_out_unset (struct ospf *ospf, int type, const char *name) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 952 | { |
| 953 | /* Schedule update timer. */ |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 954 | if (DISTRIBUTE_LIST (ospf, type)) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 955 | ospf_distribute_list_update (ospf, type); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 956 | |
| 957 | /* Unset distribute-list. */ |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 958 | DISTRIBUTE_LIST (ospf, type) = NULL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 959 | |
| 960 | /* Clear distribute-name. */ |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 961 | if (DISTRIBUTE_NAME (ospf, type)) |
| 962 | free (DISTRIBUTE_NAME (ospf, type)); |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 963 | |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 964 | DISTRIBUTE_NAME (ospf, type) = NULL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 965 | |
| 966 | return CMD_SUCCESS; |
| 967 | } |
| 968 | |
| 969 | /* distribute-list update timer. */ |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 970 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 971 | ospf_distribute_list_update_timer (struct thread *thread) |
| 972 | { |
| 973 | struct route_node *rn; |
| 974 | struct external_info *ei; |
| 975 | struct route_table *rt; |
| 976 | struct ospf_lsa *lsa; |
Joakim Tjernlund | 46154fe | 2010-04-14 16:01:25 +0200 | [diff] [blame] | 977 | int type, default_refresh = 0; |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 978 | struct ospf *ospf; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 979 | |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 980 | ospf = ospf_lookup (); |
| 981 | if (ospf == NULL) |
| 982 | return 0; |
| 983 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 984 | ospf->t_distribute_update = NULL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 985 | |
| 986 | zlog_info ("Zebra[Redistribute]: distribute-list update timer fired!"); |
| 987 | |
| 988 | /* foreach all external info. */ |
Joakim Tjernlund | 274d3f0 | 2010-04-14 11:05:27 +0200 | [diff] [blame] | 989 | for (type = 0; type <= ZEBRA_ROUTE_MAX; type++) |
| 990 | { |
| 991 | rt = EXTERNAL_INFO (type); |
| 992 | if (!rt) |
| 993 | continue; |
| 994 | for (rn = route_top (rt); rn; rn = route_next (rn)) |
| 995 | if ((ei = rn->info) != NULL) |
| 996 | { |
| 997 | if (is_prefix_default (&ei->p)) |
Joakim Tjernlund | 46154fe | 2010-04-14 16:01:25 +0200 | [diff] [blame] | 998 | default_refresh = 1; |
Joakim Tjernlund | 274d3f0 | 2010-04-14 11:05:27 +0200 | [diff] [blame] | 999 | else if ((lsa = ospf_external_info_find_lsa (ospf, &ei->p))) |
| 1000 | ospf_external_lsa_refresh (ospf, lsa, ei, LSA_REFRESH_IF_CHANGED); |
| 1001 | else |
| 1002 | ospf_external_lsa_originate (ospf, ei); |
| 1003 | } |
| 1004 | } |
Joakim Tjernlund | 46154fe | 2010-04-14 16:01:25 +0200 | [diff] [blame] | 1005 | if (default_refresh) |
| 1006 | ospf_external_lsa_refresh_default (ospf); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1007 | return 0; |
| 1008 | } |
| 1009 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1010 | /* Update distribute-list and set timer to apply access-list. */ |
| 1011 | void |
Andrew Certain | 0798cee | 2012-12-04 13:43:42 -0800 | [diff] [blame] | 1012 | ospf_distribute_list_update (struct ospf *ospf, uintptr_t type) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1013 | { |
| 1014 | struct route_table *rt; |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 1015 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1016 | /* External info does not exist. */ |
| 1017 | if (!(rt = EXTERNAL_INFO (type))) |
| 1018 | return; |
| 1019 | |
Joakim Tjernlund | 45acaa0 | 2010-04-14 11:05:28 +0200 | [diff] [blame] | 1020 | /* If exists previously invoked thread, then let it continue. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1021 | if (ospf->t_distribute_update) |
Joakim Tjernlund | 45acaa0 | 2010-04-14 11:05:28 +0200 | [diff] [blame] | 1022 | return; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1023 | |
| 1024 | /* Set timer. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1025 | ospf->t_distribute_update = |
Michael Rossberg | 2ef762e | 2015-07-27 07:56:25 +0200 | [diff] [blame] | 1026 | thread_add_timer_msec (master, ospf_distribute_list_update_timer, |
| 1027 | (void *) type, ospf->min_ls_interval); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1028 | } |
| 1029 | |
| 1030 | /* If access-list is updated, apply some check. */ |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 1031 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1032 | ospf_filter_update (struct access_list *access) |
| 1033 | { |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 1034 | struct ospf *ospf; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1035 | int type; |
| 1036 | int abr_inv = 0; |
| 1037 | struct ospf_area *area; |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 1038 | struct listnode *node; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1039 | |
| 1040 | /* If OSPF instatnce does not exist, return right now. */ |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 1041 | ospf = ospf_lookup (); |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1042 | if (ospf == NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1043 | return; |
| 1044 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1045 | /* Update distribute-list, and apply filter. */ |
hasso | 01018ce | 2005-08-05 07:40:15 +0000 | [diff] [blame] | 1046 | for (type = 0; type <= ZEBRA_ROUTE_MAX; type++) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1047 | { |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 1048 | if (ROUTEMAP (ospf, type) != NULL) |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 1049 | { |
| 1050 | /* if route-map is not NULL it may be using this access list */ |
| 1051 | ospf_distribute_list_update (ospf, type); |
| 1052 | continue; |
| 1053 | } |
| 1054 | |
hasso | 01018ce | 2005-08-05 07:40:15 +0000 | [diff] [blame] | 1055 | /* There is place for route-map for default-information (ZEBRA_ROUTE_MAX), |
| 1056 | * but no distribute list. */ |
| 1057 | if (type == ZEBRA_ROUTE_MAX) |
| 1058 | break; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1059 | |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 1060 | if (DISTRIBUTE_NAME (ospf, type)) |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 1061 | { |
| 1062 | /* Keep old access-list for distribute-list. */ |
| 1063 | struct access_list *old = DISTRIBUTE_LIST (ospf, type); |
| 1064 | |
| 1065 | /* Update access-list for distribute-list. */ |
| 1066 | DISTRIBUTE_LIST (ospf, type) = |
| 1067 | access_list_lookup (AFI_IP, DISTRIBUTE_NAME (ospf, type)); |
| 1068 | |
| 1069 | /* No update for this distribute type. */ |
| 1070 | if (old == NULL && DISTRIBUTE_LIST (ospf, type) == NULL) |
| 1071 | continue; |
| 1072 | |
| 1073 | /* Schedule distribute-list update timer. */ |
| 1074 | if (DISTRIBUTE_LIST (ospf, type) == NULL || |
| 1075 | strcmp (DISTRIBUTE_NAME (ospf, type), access->name) == 0) |
| 1076 | ospf_distribute_list_update (ospf, type); |
| 1077 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1078 | } |
| 1079 | |
| 1080 | /* Update Area access-list. */ |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 1081 | for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area)) |
| 1082 | { |
| 1083 | if (EXPORT_NAME (area)) |
| 1084 | { |
| 1085 | EXPORT_LIST (area) = NULL; |
| 1086 | abr_inv++; |
| 1087 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1088 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 1089 | if (IMPORT_NAME (area)) |
| 1090 | { |
| 1091 | IMPORT_LIST (area) = NULL; |
| 1092 | abr_inv++; |
| 1093 | } |
| 1094 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1095 | |
| 1096 | /* Schedule ABR tasks -- this will be changed -- takada. */ |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 1097 | if (IS_OSPF_ABR (ospf) && abr_inv) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1098 | ospf_schedule_abr_task (ospf); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1099 | } |
hasso | dd669bb | 2004-05-10 07:43:59 +0000 | [diff] [blame] | 1100 | |
| 1101 | /* If prefix-list is updated, do some updates. */ |
| 1102 | void |
| 1103 | ospf_prefix_list_update (struct prefix_list *plist) |
| 1104 | { |
| 1105 | struct ospf *ospf; |
| 1106 | int type; |
| 1107 | int abr_inv = 0; |
| 1108 | struct ospf_area *area; |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 1109 | struct listnode *node; |
hasso | dd669bb | 2004-05-10 07:43:59 +0000 | [diff] [blame] | 1110 | |
| 1111 | /* If OSPF instatnce does not exist, return right now. */ |
| 1112 | ospf = ospf_lookup (); |
| 1113 | if (ospf == NULL) |
| 1114 | return; |
| 1115 | |
| 1116 | /* Update all route-maps which are used as redistribution filters. |
| 1117 | * They might use prefix-list. |
| 1118 | */ |
hasso | 01018ce | 2005-08-05 07:40:15 +0000 | [diff] [blame] | 1119 | for (type = 0; type <= ZEBRA_ROUTE_MAX; type++) |
hasso | dd669bb | 2004-05-10 07:43:59 +0000 | [diff] [blame] | 1120 | { |
| 1121 | if (ROUTEMAP (ospf, type) != NULL) |
| 1122 | { |
| 1123 | /* If route-map is not NULL it may be using this prefix list */ |
| 1124 | ospf_distribute_list_update (ospf, type); |
| 1125 | continue; |
| 1126 | } |
| 1127 | } |
| 1128 | |
| 1129 | /* Update area filter-lists. */ |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 1130 | for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area)) |
| 1131 | { |
| 1132 | /* Update filter-list in. */ |
| 1133 | if (PREFIX_NAME_IN (area)) |
David Lamparter | e66cbd1 | 2015-04-13 10:21:34 +0200 | [diff] [blame] | 1134 | if (strcmp (PREFIX_NAME_IN (area), prefix_list_name (plist)) == 0) |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 1135 | { |
| 1136 | PREFIX_LIST_IN (area) = |
| 1137 | prefix_list_lookup (AFI_IP, PREFIX_NAME_IN (area)); |
| 1138 | abr_inv++; |
| 1139 | } |
hasso | dd669bb | 2004-05-10 07:43:59 +0000 | [diff] [blame] | 1140 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 1141 | /* Update filter-list out. */ |
| 1142 | if (PREFIX_NAME_OUT (area)) |
David Lamparter | e66cbd1 | 2015-04-13 10:21:34 +0200 | [diff] [blame] | 1143 | if (strcmp (PREFIX_NAME_OUT (area), prefix_list_name (plist)) == 0) |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 1144 | { |
| 1145 | PREFIX_LIST_IN (area) = |
| 1146 | prefix_list_lookup (AFI_IP, PREFIX_NAME_OUT (area)); |
| 1147 | abr_inv++; |
| 1148 | } |
| 1149 | } |
hasso | dd669bb | 2004-05-10 07:43:59 +0000 | [diff] [blame] | 1150 | |
| 1151 | /* Schedule ABR task. */ |
| 1152 | if (IS_OSPF_ABR (ospf) && abr_inv) |
| 1153 | ospf_schedule_abr_task (ospf); |
| 1154 | } |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 1155 | |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 1156 | static struct ospf_distance * |
| 1157 | ospf_distance_new (void) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1158 | { |
Stephen Hemminger | 393deb9 | 2008-08-18 14:13:29 -0700 | [diff] [blame] | 1159 | return XCALLOC (MTYPE_OSPF_DISTANCE, sizeof (struct ospf_distance)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1160 | } |
| 1161 | |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 1162 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1163 | ospf_distance_free (struct ospf_distance *odistance) |
| 1164 | { |
| 1165 | XFREE (MTYPE_OSPF_DISTANCE, odistance); |
| 1166 | } |
| 1167 | |
| 1168 | int |
paul | 6c83567 | 2004-10-11 11:00:30 +0000 | [diff] [blame] | 1169 | ospf_distance_set (struct vty *vty, struct ospf *ospf, |
| 1170 | const char *distance_str, |
| 1171 | const char *ip_str, |
| 1172 | const char *access_list_str) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1173 | { |
| 1174 | int ret; |
| 1175 | struct prefix_ipv4 p; |
| 1176 | u_char distance; |
| 1177 | struct route_node *rn; |
| 1178 | struct ospf_distance *odistance; |
| 1179 | |
| 1180 | ret = str2prefix_ipv4 (ip_str, &p); |
| 1181 | if (ret == 0) |
| 1182 | { |
| 1183 | vty_out (vty, "Malformed prefix%s", VTY_NEWLINE); |
| 1184 | return CMD_WARNING; |
| 1185 | } |
| 1186 | |
| 1187 | distance = atoi (distance_str); |
| 1188 | |
| 1189 | /* Get OSPF distance node. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1190 | rn = route_node_get (ospf->distance_table, (struct prefix *) &p); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1191 | if (rn->info) |
| 1192 | { |
| 1193 | odistance = rn->info; |
| 1194 | route_unlock_node (rn); |
| 1195 | } |
| 1196 | else |
| 1197 | { |
| 1198 | odistance = ospf_distance_new (); |
| 1199 | rn->info = odistance; |
| 1200 | } |
| 1201 | |
| 1202 | /* Set distance value. */ |
| 1203 | odistance->distance = distance; |
| 1204 | |
| 1205 | /* Reset access-list configuration. */ |
| 1206 | if (odistance->access_list) |
| 1207 | { |
| 1208 | free (odistance->access_list); |
| 1209 | odistance->access_list = NULL; |
| 1210 | } |
| 1211 | if (access_list_str) |
| 1212 | odistance->access_list = strdup (access_list_str); |
| 1213 | |
| 1214 | return CMD_SUCCESS; |
| 1215 | } |
| 1216 | |
| 1217 | int |
paul | 6c83567 | 2004-10-11 11:00:30 +0000 | [diff] [blame] | 1218 | ospf_distance_unset (struct vty *vty, struct ospf *ospf, |
| 1219 | const char *distance_str, |
| 1220 | const char *ip_str, char |
| 1221 | const *access_list_str) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1222 | { |
| 1223 | int ret; |
| 1224 | struct prefix_ipv4 p; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1225 | struct route_node *rn; |
| 1226 | struct ospf_distance *odistance; |
| 1227 | |
| 1228 | ret = str2prefix_ipv4 (ip_str, &p); |
| 1229 | if (ret == 0) |
| 1230 | { |
| 1231 | vty_out (vty, "Malformed prefix%s", VTY_NEWLINE); |
| 1232 | return CMD_WARNING; |
| 1233 | } |
| 1234 | |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 1235 | rn = route_node_lookup (ospf->distance_table, (struct prefix *) &p); |
| 1236 | if (!rn) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1237 | { |
| 1238 | vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE); |
| 1239 | return CMD_WARNING; |
| 1240 | } |
| 1241 | |
| 1242 | odistance = rn->info; |
| 1243 | |
| 1244 | if (odistance->access_list) |
| 1245 | free (odistance->access_list); |
| 1246 | ospf_distance_free (odistance); |
| 1247 | |
| 1248 | rn->info = NULL; |
| 1249 | route_unlock_node (rn); |
| 1250 | route_unlock_node (rn); |
| 1251 | |
| 1252 | return CMD_SUCCESS; |
| 1253 | } |
| 1254 | |
| 1255 | void |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1256 | ospf_distance_reset (struct ospf *ospf) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1257 | { |
| 1258 | struct route_node *rn; |
| 1259 | struct ospf_distance *odistance; |
| 1260 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1261 | for (rn = route_top (ospf->distance_table); rn; rn = route_next (rn)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1262 | if ((odistance = rn->info) != NULL) |
| 1263 | { |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 1264 | if (odistance->access_list) |
| 1265 | free (odistance->access_list); |
| 1266 | ospf_distance_free (odistance); |
| 1267 | rn->info = NULL; |
| 1268 | route_unlock_node (rn); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1269 | } |
| 1270 | } |
| 1271 | |
| 1272 | u_char |
| 1273 | ospf_distance_apply (struct prefix_ipv4 *p, struct ospf_route *or) |
| 1274 | { |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 1275 | struct ospf *ospf; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1276 | |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 1277 | ospf = ospf_lookup (); |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1278 | if (ospf == NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1279 | return 0; |
| 1280 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1281 | if (ospf->distance_intra) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1282 | if (or->path_type == OSPF_PATH_INTRA_AREA) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1283 | return ospf->distance_intra; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1284 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1285 | if (ospf->distance_inter) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1286 | if (or->path_type == OSPF_PATH_INTER_AREA) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1287 | return ospf->distance_inter; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1288 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1289 | if (ospf->distance_external) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1290 | if (or->path_type == OSPF_PATH_TYPE1_EXTERNAL |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 1291 | || or->path_type == OSPF_PATH_TYPE2_EXTERNAL) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1292 | return ospf->distance_external; |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 1293 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1294 | if (ospf->distance_all) |
| 1295 | return ospf->distance_all; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1296 | |
| 1297 | return 0; |
| 1298 | } |
| 1299 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 1300 | static void |
| 1301 | ospf_zebra_connected (struct zclient *zclient) |
| 1302 | { |
| 1303 | zclient_send_requests (zclient, VRF_DEFAULT); |
| 1304 | } |
| 1305 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1306 | void |
Donald Sharp | 7125293 | 2015-09-24 09:25:19 -0400 | [diff] [blame] | 1307 | ospf_zebra_init (struct thread_master *master) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1308 | { |
| 1309 | /* Allocate zebra structure. */ |
Donald Sharp | 7125293 | 2015-09-24 09:25:19 -0400 | [diff] [blame] | 1310 | zclient = zclient_new (master); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1311 | zclient_init (zclient, ZEBRA_ROUTE_OSPF); |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 1312 | zclient->zebra_connected = ospf_zebra_connected; |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 1313 | zclient->router_id_update = ospf_router_id_update_zebra; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1314 | zclient->interface_add = ospf_interface_add; |
| 1315 | zclient->interface_delete = ospf_interface_delete; |
| 1316 | zclient->interface_up = ospf_interface_state_up; |
| 1317 | zclient->interface_down = ospf_interface_state_down; |
| 1318 | zclient->interface_address_add = ospf_interface_address_add; |
| 1319 | zclient->interface_address_delete = ospf_interface_address_delete; |
| 1320 | zclient->ipv4_route_add = ospf_zebra_read_ipv4; |
| 1321 | zclient->ipv4_route_delete = ospf_zebra_read_ipv4; |
| 1322 | |
| 1323 | access_list_add_hook (ospf_filter_update); |
| 1324 | access_list_delete_hook (ospf_filter_update); |
hasso | dd669bb | 2004-05-10 07:43:59 +0000 | [diff] [blame] | 1325 | prefix_list_add_hook (ospf_prefix_list_update); |
| 1326 | prefix_list_delete_hook (ospf_prefix_list_update); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1327 | } |