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