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