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