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