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