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