paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1 | /* |
| 2 | * OSPF Interface functions. |
| 3 | * Copyright (C) 1999, 2000 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 |
| 8 | * it under the terms of the GNU General Public License as published |
| 9 | * by the Free Software Foundation; either version 2, or (at your |
| 10 | * option) any 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 "linklist.h" |
| 27 | #include "prefix.h" |
| 28 | #include "if.h" |
| 29 | #include "table.h" |
| 30 | #include "memory.h" |
| 31 | #include "command.h" |
| 32 | #include "stream.h" |
| 33 | #include "log.h" |
| 34 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 35 | #include "ospfd/ospfd.h" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 36 | #include "ospfd/ospf_spf.h" |
| 37 | #include "ospfd/ospf_interface.h" |
| 38 | #include "ospfd/ospf_ism.h" |
| 39 | #include "ospfd/ospf_asbr.h" |
| 40 | #include "ospfd/ospf_lsa.h" |
| 41 | #include "ospfd/ospf_lsdb.h" |
| 42 | #include "ospfd/ospf_neighbor.h" |
| 43 | #include "ospfd/ospf_nsm.h" |
| 44 | #include "ospfd/ospf_packet.h" |
| 45 | #include "ospfd/ospf_abr.h" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 46 | #include "ospfd/ospf_network.h" |
| 47 | #include "ospfd/ospf_dump.h" |
| 48 | #ifdef HAVE_SNMP |
| 49 | #include "ospfd/ospf_snmp.h" |
| 50 | #endif /* HAVE_SNMP */ |
| 51 | |
| 52 | |
| 53 | int |
| 54 | ospf_if_get_output_cost (struct ospf_interface *oi) |
| 55 | { |
| 56 | /* If all else fails, use default OSPF cost */ |
| 57 | u_int32_t cost; |
| 58 | u_int32_t bw, refbw; |
| 59 | |
| 60 | bw = oi->ifp->bandwidth ? oi->ifp->bandwidth : OSPF_DEFAULT_BANDWIDTH; |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 61 | refbw = oi->ospf->ref_bandwidth; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 62 | |
| 63 | /* A specifed ip ospf cost overrides a calculated one. */ |
| 64 | if (OSPF_IF_PARAM_CONFIGURED (IF_DEF_PARAMS (oi->ifp), output_cost_cmd) || |
| 65 | OSPF_IF_PARAM_CONFIGURED (oi->params, output_cost_cmd)) |
| 66 | cost = OSPF_IF_PARAM (oi, output_cost_cmd); |
| 67 | /* See if a cost can be calculated from the zebra processes |
| 68 | interface bandwidth field. */ |
| 69 | else |
| 70 | { |
| 71 | cost = (u_int32_t) ((double)refbw / (double)bw + (double)0.5); |
| 72 | if (cost < 1) |
| 73 | cost = 1; |
| 74 | else if (cost > 65535) |
| 75 | cost = 65535; |
| 76 | } |
| 77 | |
| 78 | return cost; |
| 79 | } |
| 80 | |
| 81 | void |
| 82 | ospf_if_recalculate_output_cost (struct interface *ifp) |
| 83 | { |
| 84 | u_int32_t newcost; |
| 85 | struct route_node *rn; |
| 86 | |
| 87 | for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn)) |
| 88 | { |
| 89 | struct ospf_interface *oi; |
| 90 | |
| 91 | if ( (oi = rn->info) == NULL) |
| 92 | continue; |
| 93 | |
| 94 | newcost = ospf_if_get_output_cost (oi); |
| 95 | |
| 96 | /* Is actual output cost changed? */ |
| 97 | if (oi->output_cost != newcost) |
| 98 | { |
| 99 | oi->output_cost = newcost; |
| 100 | ospf_router_lsa_timer_add (oi->area); |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | void |
| 106 | ospf_if_reset_variables (struct ospf_interface *oi) |
| 107 | { |
| 108 | /* Set default values. */ |
| 109 | /* don't clear this flag. oi->flag = OSPF_IF_DISABLE; */ |
| 110 | |
| 111 | if (oi->vl_data) |
| 112 | oi->type = OSPF_IFTYPE_VIRTUALLINK; |
| 113 | else |
| 114 | /* preserve network-type */ |
| 115 | if (oi->type != OSPF_IFTYPE_NBMA) |
| 116 | oi->type = OSPF_IFTYPE_BROADCAST; |
| 117 | |
| 118 | oi->state = ISM_Down; |
| 119 | |
| 120 | oi->crypt_seqnum = 0; |
| 121 | |
| 122 | /* This must be short, (less than RxmtInterval) |
| 123 | - RFC 2328 Section 13.5 para 3. Set to 1 second to avoid Acks being |
| 124 | held back for too long - MAG */ |
| 125 | oi->v_ls_ack = 1; |
| 126 | } |
| 127 | |
paul | 20916fb | 2003-10-15 21:14:20 +0000 | [diff] [blame] | 128 | /* lookup oi for specified prefix/ifp */ |
| 129 | struct ospf_interface * |
| 130 | ospf_if_table_lookup (struct interface *ifp, struct prefix *prefix) |
| 131 | { |
| 132 | struct prefix p; |
paul | affe1d9 | 2003-10-15 21:40:57 +0000 | [diff] [blame] | 133 | struct route_node *rn; |
paul | b5f2c12 | 2003-11-10 23:56:29 +0000 | [diff] [blame] | 134 | struct ospf_interface *rninfo; |
paul | 20916fb | 2003-10-15 21:14:20 +0000 | [diff] [blame] | 135 | |
| 136 | p = *prefix; |
| 137 | |
paul | affe1d9 | 2003-10-15 21:40:57 +0000 | [diff] [blame] | 138 | rn = route_node_get (IF_OIFS (ifp), &p); |
paul | 20916fb | 2003-10-15 21:14:20 +0000 | [diff] [blame] | 139 | /* route_node_get implicitely locks */ |
paul | b5f2c12 | 2003-11-10 23:56:29 +0000 | [diff] [blame] | 140 | rninfo = (struct ospf_interface *) rn->info; |
paul | affe1d9 | 2003-10-15 21:40:57 +0000 | [diff] [blame] | 141 | route_unlock_node (rn); |
paul | b5f2c12 | 2003-11-10 23:56:29 +0000 | [diff] [blame] | 142 | return rninfo; |
paul | 20916fb | 2003-10-15 21:14:20 +0000 | [diff] [blame] | 143 | } |
| 144 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 145 | void |
| 146 | ospf_add_to_if (struct interface *ifp, struct ospf_interface *oi) |
| 147 | { |
| 148 | struct route_node *rn; |
| 149 | struct prefix p; |
| 150 | |
| 151 | p = *oi->address; |
| 152 | p.prefixlen = IPV4_MAX_PREFIXLEN; |
| 153 | |
| 154 | rn = route_node_get (IF_OIFS (ifp), &p); |
paul | 8c80cb7 | 2003-02-18 23:25:44 +0000 | [diff] [blame] | 155 | /* rn->info should either be NULL or equal to this oi |
| 156 | * as route_node_get may return an existing node |
| 157 | */ |
paul | 20916fb | 2003-10-15 21:14:20 +0000 | [diff] [blame] | 158 | assert (!rn->info || rn->info == oi); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 159 | rn->info = oi; |
| 160 | } |
| 161 | |
| 162 | void |
| 163 | ospf_delete_from_if (struct interface *ifp, struct ospf_interface *oi) |
| 164 | { |
| 165 | struct route_node *rn; |
| 166 | struct prefix p; |
| 167 | |
| 168 | p = *oi->address; |
| 169 | p.prefixlen = IPV4_MAX_PREFIXLEN; |
| 170 | |
| 171 | rn = route_node_lookup (IF_OIFS (oi->ifp), &p); |
| 172 | assert (rn); |
| 173 | assert (rn->info); |
| 174 | rn->info = NULL; |
| 175 | route_unlock_node (rn); |
| 176 | route_unlock_node (rn); |
| 177 | } |
| 178 | |
| 179 | struct ospf_interface * |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 180 | ospf_if_new (struct ospf *ospf, struct interface *ifp, struct prefix *p) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 181 | { |
| 182 | struct ospf_interface *oi; |
| 183 | |
paul | 20916fb | 2003-10-15 21:14:20 +0000 | [diff] [blame] | 184 | if ((oi = ospf_if_table_lookup (ifp, p)) == NULL) |
| 185 | { |
| 186 | oi = XCALLOC (MTYPE_OSPF_IF, sizeof (struct ospf_interface)); |
| 187 | memset (oi, 0, sizeof (struct ospf_interface)); |
| 188 | } |
| 189 | else |
| 190 | return oi; |
| 191 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 192 | /* Set zebra interface pointer. */ |
| 193 | oi->ifp = ifp; |
| 194 | oi->address = p; |
| 195 | |
| 196 | ospf_add_to_if (ifp, oi); |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 197 | listnode_add (ospf->oiflist, oi); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 198 | |
| 199 | /* Clear self-originated network-LSA. */ |
| 200 | oi->network_lsa_self = NULL; |
| 201 | |
| 202 | /* Initialize neighbor list. */ |
| 203 | oi->nbrs = route_table_init (); |
| 204 | |
| 205 | /* Initialize static neighbor list. */ |
| 206 | oi->nbr_nbma = list_new (); |
| 207 | |
| 208 | /* Initialize Link State Acknowledgment list. */ |
| 209 | oi->ls_ack = list_new (); |
| 210 | oi->ls_ack_direct.ls_ack = list_new (); |
| 211 | |
| 212 | /* Set default values. */ |
| 213 | ospf_if_reset_variables (oi); |
| 214 | |
| 215 | /* Add pseudo neighbor. */ |
| 216 | oi->nbr_self = ospf_nbr_new (oi); |
| 217 | oi->nbr_self->state = NSM_TwoWay; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 218 | oi->nbr_self->priority = OSPF_IF_PARAM (oi, priority); |
| 219 | oi->nbr_self->options = OSPF_OPTION_E; |
| 220 | |
| 221 | oi->ls_upd_queue = route_table_init (); |
| 222 | oi->t_ls_upd_event = NULL; |
| 223 | oi->t_ls_ack_direct = NULL; |
| 224 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 225 | oi->crypt_seqnum = time (NULL); |
| 226 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 227 | #ifdef HAVE_OPAQUE_LSA |
| 228 | ospf_opaque_type9_lsa_init (oi); |
| 229 | #endif /* HAVE_OPAQUE_LSA */ |
| 230 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 231 | oi->ospf = ospf; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 232 | |
| 233 | return oi; |
| 234 | } |
| 235 | |
| 236 | /* Restore an interface to its pre UP state |
| 237 | Used from ism_interface_down only */ |
| 238 | void |
| 239 | ospf_if_cleanup (struct ospf_interface *oi) |
| 240 | { |
| 241 | struct route_node *rn; |
| 242 | listnode node; |
| 243 | struct ospf_neighbor *nbr; |
| 244 | |
| 245 | /* oi->nbrs and oi->nbr_nbma should be deletete on InterafceDown event */ |
| 246 | /* delete all static neighbors attached to this interface */ |
| 247 | for (node = listhead (oi->nbr_nbma); node; ) |
| 248 | { |
| 249 | struct ospf_nbr_nbma *nbr_nbma = getdata (node); |
| 250 | nextnode (node); |
| 251 | |
| 252 | OSPF_POLL_TIMER_OFF (nbr_nbma->t_poll); |
| 253 | |
| 254 | if (nbr_nbma->nbr) |
| 255 | { |
| 256 | nbr_nbma->nbr->nbr_nbma = NULL; |
| 257 | nbr_nbma->nbr = NULL; |
| 258 | } |
| 259 | |
| 260 | nbr_nbma->oi = NULL; |
| 261 | |
| 262 | listnode_delete (oi->nbr_nbma, nbr_nbma); |
| 263 | } |
| 264 | |
| 265 | /* send Neighbor event KillNbr to all associated neighbors. */ |
| 266 | for (rn = route_top (oi->nbrs); rn; rn = route_next (rn)) |
| 267 | if ((nbr = rn->info) != NULL) |
| 268 | if (nbr != oi->nbr_self) |
| 269 | OSPF_NSM_EVENT_EXECUTE (nbr, NSM_KillNbr); |
| 270 | |
| 271 | /* Cleanup Link State Acknowlegdment list. */ |
| 272 | for (node = listhead (oi->ls_ack); node; nextnode (node)) |
| 273 | ospf_lsa_unlock (node->data); |
| 274 | list_delete_all_node (oi->ls_ack); |
| 275 | |
| 276 | oi->crypt_seqnum = 0; |
| 277 | |
| 278 | /* Empty link state update queue */ |
| 279 | ospf_ls_upd_queue_empty (oi); |
| 280 | |
| 281 | /* Handle pseudo neighbor. */ |
| 282 | ospf_nbr_delete (oi->nbr_self); |
| 283 | oi->nbr_self = ospf_nbr_new (oi); |
| 284 | oi->nbr_self->state = NSM_TwoWay; |
| 285 | oi->nbr_self->priority = OSPF_IF_PARAM (oi, priority); |
paul | f2c8065 | 2002-12-13 21:44:27 +0000 | [diff] [blame] | 286 | |
| 287 | switch (oi->area->external_routing) |
| 288 | { |
| 289 | case OSPF_AREA_DEFAULT: |
| 290 | SET_FLAG (oi->nbr_self->options, OSPF_OPTION_E); |
| 291 | break; |
| 292 | case OSPF_AREA_STUB: |
| 293 | UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_E); |
| 294 | break; |
| 295 | #ifdef HAVE_NSSA |
| 296 | case OSPF_AREA_NSSA: |
| 297 | UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_E); |
| 298 | SET_FLAG (oi->nbr_self->options, OSPF_OPTION_NP); |
| 299 | break; |
| 300 | #endif /* HAVE_NSSA */ |
| 301 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 302 | |
| 303 | ospf_lsa_unlock (oi->network_lsa_self); |
| 304 | oi->network_lsa_self = NULL; |
| 305 | OSPF_TIMER_OFF (oi->t_network_lsa_self); |
| 306 | } |
| 307 | |
| 308 | void |
| 309 | ospf_if_free (struct ospf_interface *oi) |
| 310 | { |
| 311 | ospf_if_down (oi); |
| 312 | |
| 313 | assert (oi->state == ISM_Down); |
| 314 | |
| 315 | #ifdef HAVE_OPAQUE_LSA |
| 316 | ospf_opaque_type9_lsa_term (oi); |
| 317 | #endif /* HAVE_OPAQUE_LSA */ |
| 318 | |
| 319 | /* Free Pseudo Neighbour */ |
| 320 | ospf_nbr_delete (oi->nbr_self); |
| 321 | |
| 322 | route_table_finish (oi->nbrs); |
| 323 | route_table_finish (oi->ls_upd_queue); |
| 324 | |
| 325 | /* Free any lists that should be freed */ |
| 326 | list_free (oi->nbr_nbma); |
| 327 | |
| 328 | list_free (oi->ls_ack); |
| 329 | list_free (oi->ls_ack_direct.ls_ack); |
| 330 | |
| 331 | ospf_delete_from_if (oi->ifp, oi); |
| 332 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 333 | listnode_delete (oi->ospf->oiflist, oi); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 334 | listnode_delete (oi->area->oiflist, oi); |
| 335 | |
| 336 | memset (oi, 0, sizeof (*oi)); |
| 337 | XFREE (MTYPE_OSPF_IF, oi); |
| 338 | } |
| 339 | |
| 340 | |
| 341 | /* |
| 342 | * check if interface with given address is configured and |
| 343 | * return it if yes. |
| 344 | */ |
| 345 | struct ospf_interface * |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 346 | ospf_if_is_configured (struct ospf *ospf, struct in_addr *address) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 347 | { |
| 348 | listnode node; |
| 349 | struct ospf_interface *oi; |
| 350 | struct prefix *addr; |
| 351 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 352 | for (node = listhead (ospf->oiflist); node; nextnode (node)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 353 | if ((oi = getdata (node)) != NULL && oi->type != OSPF_IFTYPE_VIRTUALLINK) |
| 354 | { |
| 355 | if (oi->type == OSPF_IFTYPE_POINTOPOINT) |
| 356 | addr = oi->connected->destination; |
| 357 | else |
| 358 | addr = oi->address; |
| 359 | |
| 360 | if (IPV4_ADDR_SAME (address, &addr->u.prefix4)) |
| 361 | return oi; |
| 362 | } |
| 363 | |
| 364 | return NULL; |
| 365 | } |
| 366 | |
| 367 | int |
| 368 | ospf_if_is_up (struct ospf_interface *oi) |
| 369 | { |
| 370 | return if_is_up (oi->ifp); |
| 371 | } |
| 372 | |
| 373 | struct ospf_interface * |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 374 | ospf_if_lookup_by_local_addr (struct ospf *ospf, |
| 375 | struct interface *ifp, struct in_addr address) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 376 | { |
| 377 | listnode node; |
| 378 | struct ospf_interface *oi; |
| 379 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 380 | for (node = listhead (ospf->oiflist); node; nextnode (node)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 381 | if ((oi = getdata (node)) != NULL && oi->type != OSPF_IFTYPE_VIRTUALLINK) |
| 382 | { |
| 383 | if (ifp && oi->ifp != ifp) |
| 384 | continue; |
| 385 | |
| 386 | if (IPV4_ADDR_SAME (&address, &oi->address->u.prefix4)) |
| 387 | return oi; |
| 388 | } |
| 389 | |
| 390 | return NULL; |
| 391 | } |
| 392 | |
| 393 | struct ospf_interface * |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 394 | ospf_if_lookup_by_prefix (struct ospf *ospf, struct prefix_ipv4 *p) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 395 | { |
| 396 | listnode node; |
| 397 | struct ospf_interface *oi; |
| 398 | struct prefix ptmp; |
| 399 | |
| 400 | /* Check each Interface. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 401 | for (node = listhead (ospf->oiflist); node; nextnode (node)) |
| 402 | { |
| 403 | if ((oi = getdata (node)) != NULL && oi->type != OSPF_IFTYPE_VIRTUALLINK) |
| 404 | { |
| 405 | if (oi->type == OSPF_IFTYPE_POINTOPOINT) |
| 406 | { |
| 407 | prefix_copy (&ptmp, oi->connected->destination); |
| 408 | ptmp.prefixlen = IPV4_MAX_BITLEN; |
| 409 | } |
| 410 | else |
| 411 | prefix_copy (&ptmp, oi->address); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 412 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 413 | apply_mask (&ptmp); |
| 414 | if (prefix_same (&ptmp, (struct prefix *) p)) |
| 415 | return oi; |
| 416 | } |
| 417 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 418 | return NULL; |
| 419 | } |
| 420 | |
| 421 | /* determine receiving interface by source of packet */ |
| 422 | struct ospf_interface * |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 423 | ospf_if_lookup_recv_if (struct ospf *ospf, struct in_addr src) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 424 | { |
| 425 | listnode node; |
| 426 | struct prefix_ipv4 addr; |
| 427 | struct ospf_interface *oi, *match; |
| 428 | |
| 429 | addr.family = AF_INET; |
| 430 | addr.prefix = src; |
| 431 | addr.prefixlen = IPV4_MAX_BITLEN; |
| 432 | |
| 433 | match = NULL; |
| 434 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 435 | for (node = listhead (ospf->oiflist); node; nextnode (node)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 436 | { |
| 437 | oi = getdata (node); |
| 438 | |
| 439 | if (oi->type == OSPF_IFTYPE_VIRTUALLINK) |
| 440 | continue; |
| 441 | |
| 442 | if (oi->type == OSPF_IFTYPE_POINTOPOINT) |
| 443 | { |
| 444 | if (IPV4_ADDR_SAME (&oi->connected->destination->u.prefix4, &src)) |
| 445 | return oi; |
| 446 | } |
| 447 | else |
| 448 | { |
| 449 | if (prefix_match (oi->address, (struct prefix *) &addr)) |
paul | 0a825c7 | 2003-05-24 13:48:16 +0000 | [diff] [blame] | 450 | { |
paul | af8d033 | 2003-05-24 15:31:45 +0000 | [diff] [blame] | 451 | if ( (match == NULL) || |
| 452 | (match->address->prefixlen < oi->address->prefixlen) |
| 453 | ) |
paul | 0a825c7 | 2003-05-24 13:48:16 +0000 | [diff] [blame] | 454 | match = oi; |
| 455 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 456 | } |
| 457 | } |
| 458 | |
| 459 | return match; |
| 460 | } |
| 461 | |
| 462 | void |
| 463 | ospf_if_stream_set (struct ospf_interface *oi) |
| 464 | { |
| 465 | /* set output fifo queue. */ |
| 466 | if (oi->obuf == NULL) |
| 467 | oi->obuf = ospf_fifo_new (); |
| 468 | } |
| 469 | |
| 470 | void |
| 471 | ospf_if_stream_unset (struct ospf_interface *oi) |
| 472 | { |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 473 | struct ospf *ospf = oi->ospf; |
| 474 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 475 | if (oi->obuf) |
| 476 | { |
| 477 | ospf_fifo_free (oi->obuf); |
| 478 | oi->obuf = NULL; |
| 479 | |
| 480 | if (oi->on_write_q) |
| 481 | { |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 482 | listnode_delete (ospf->oi_write_q, oi); |
| 483 | if (list_isempty(ospf->oi_write_q)) |
| 484 | OSPF_TIMER_OFF (ospf->t_write); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 485 | oi->on_write_q = 0; |
| 486 | } |
| 487 | } |
| 488 | } |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 489 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 490 | |
| 491 | struct ospf_if_params * |
| 492 | ospf_new_if_params () |
| 493 | { |
| 494 | struct ospf_if_params *oip; |
| 495 | |
| 496 | oip = XMALLOC (MTYPE_OSPF_IF_PARAMS, sizeof (struct ospf_if_params)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 497 | |
| 498 | if (!oip) |
| 499 | return NULL; |
| 500 | |
paul | f645789 | 2003-04-17 16:11:30 +0000 | [diff] [blame] | 501 | memset (oip, 0, sizeof (struct ospf_if_params)); |
| 502 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 503 | UNSET_IF_PARAM (oip, output_cost_cmd); |
| 504 | UNSET_IF_PARAM (oip, transmit_delay); |
| 505 | UNSET_IF_PARAM (oip, retransmit_interval); |
| 506 | UNSET_IF_PARAM (oip, passive_interface); |
| 507 | UNSET_IF_PARAM (oip, v_hello); |
| 508 | UNSET_IF_PARAM (oip, v_wait); |
| 509 | UNSET_IF_PARAM (oip, priority); |
| 510 | UNSET_IF_PARAM (oip, type); |
| 511 | UNSET_IF_PARAM (oip, auth_simple); |
| 512 | UNSET_IF_PARAM (oip, auth_crypt); |
| 513 | UNSET_IF_PARAM (oip, auth_type); |
paul | ec1ca63 | 2003-06-04 02:23:15 +0000 | [diff] [blame] | 514 | |
| 515 | oip->auth_crypt = list_new (); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 516 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 517 | return oip; |
| 518 | } |
| 519 | |
| 520 | void |
| 521 | ospf_del_if_params (struct ospf_if_params *oip) |
| 522 | { |
| 523 | list_delete (oip->auth_crypt); |
| 524 | XFREE (MTYPE_OSPF_IF_PARAMS, oip); |
| 525 | } |
| 526 | |
| 527 | void |
| 528 | ospf_free_if_params (struct interface *ifp, struct in_addr addr) |
| 529 | { |
| 530 | struct ospf_if_params *oip; |
| 531 | struct prefix_ipv4 p; |
| 532 | struct route_node *rn; |
| 533 | p.prefixlen = IPV4_MAX_PREFIXLEN; |
| 534 | p.prefix = addr; |
| 535 | rn = route_node_lookup (IF_OIFS_PARAMS (ifp), (struct prefix*)&p); |
| 536 | if (!rn || !rn->info) |
| 537 | return; |
| 538 | |
| 539 | oip = rn->info; |
| 540 | route_unlock_node (rn); |
| 541 | |
| 542 | if (!OSPF_IF_PARAM_CONFIGURED (oip, output_cost_cmd) && |
| 543 | !OSPF_IF_PARAM_CONFIGURED (oip, transmit_delay) && |
| 544 | !OSPF_IF_PARAM_CONFIGURED (oip, retransmit_interval) && |
| 545 | !OSPF_IF_PARAM_CONFIGURED (oip, passive_interface) && |
| 546 | !OSPF_IF_PARAM_CONFIGURED (oip, v_hello) && |
| 547 | !OSPF_IF_PARAM_CONFIGURED (oip, v_wait) && |
| 548 | !OSPF_IF_PARAM_CONFIGURED (oip, priority) && |
| 549 | !OSPF_IF_PARAM_CONFIGURED (oip, type) && |
| 550 | !OSPF_IF_PARAM_CONFIGURED (oip, auth_simple) && |
| 551 | !OSPF_IF_PARAM_CONFIGURED (oip, auth_type) && |
| 552 | listcount (oip->auth_crypt) == 0) |
| 553 | { |
| 554 | ospf_del_if_params (oip); |
| 555 | rn->info = NULL; |
| 556 | route_unlock_node (rn); |
| 557 | } |
| 558 | } |
| 559 | |
| 560 | struct ospf_if_params * |
| 561 | ospf_lookup_if_params (struct interface *ifp, struct in_addr addr) |
| 562 | { |
| 563 | struct prefix_ipv4 p; |
| 564 | struct route_node *rn; |
| 565 | |
| 566 | p.prefixlen = IPV4_MAX_PREFIXLEN; |
| 567 | p.prefix = addr; |
| 568 | |
| 569 | rn = route_node_lookup (IF_OIFS_PARAMS (ifp), (struct prefix*)&p); |
| 570 | |
| 571 | if (rn) |
| 572 | { |
| 573 | route_unlock_node (rn); |
| 574 | return rn->info; |
| 575 | } |
| 576 | |
| 577 | return NULL; |
| 578 | } |
| 579 | |
| 580 | struct ospf_if_params * |
| 581 | ospf_get_if_params (struct interface *ifp, struct in_addr addr) |
| 582 | { |
| 583 | struct prefix_ipv4 p; |
| 584 | struct route_node *rn; |
| 585 | |
| 586 | p.family = AF_INET; |
| 587 | p.prefixlen = IPV4_MAX_PREFIXLEN; |
| 588 | p.prefix = addr; |
| 589 | |
| 590 | rn = route_node_get (IF_OIFS_PARAMS (ifp), (struct prefix*)&p); |
| 591 | |
| 592 | if (rn->info == NULL) |
| 593 | rn->info = ospf_new_if_params (); |
| 594 | else |
| 595 | route_unlock_node (rn); |
| 596 | |
| 597 | return rn->info; |
| 598 | } |
| 599 | |
| 600 | void |
| 601 | ospf_if_update_params (struct interface *ifp, struct in_addr addr) |
| 602 | { |
| 603 | struct route_node *rn; |
| 604 | struct ospf_interface *oi; |
| 605 | |
| 606 | for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn)) |
| 607 | { |
| 608 | if ((oi = rn->info) == NULL) |
| 609 | continue; |
| 610 | |
| 611 | if (IPV4_ADDR_SAME (&oi->address->u.prefix4, &addr)) |
| 612 | oi->params = ospf_lookup_if_params (ifp, oi->address->u.prefix4); |
| 613 | } |
| 614 | } |
| 615 | |
| 616 | int |
| 617 | ospf_if_new_hook (struct interface *ifp) |
| 618 | { |
| 619 | int rc = 0; |
| 620 | |
| 621 | ifp->info = XMALLOC (MTYPE_OSPF_IF_INFO, sizeof (struct ospf_if_info)); |
| 622 | memset (ifp->info, 0, sizeof (struct ospf_if_info)); |
| 623 | |
| 624 | IF_OIFS (ifp) = route_table_init (); |
| 625 | IF_OIFS_PARAMS (ifp) = route_table_init (); |
| 626 | |
| 627 | IF_DEF_PARAMS (ifp) = ospf_new_if_params (); |
| 628 | |
| 629 | SET_IF_PARAM (IF_DEF_PARAMS (ifp), transmit_delay); |
| 630 | IF_DEF_PARAMS (ifp)->transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT; |
| 631 | |
| 632 | SET_IF_PARAM (IF_DEF_PARAMS (ifp), retransmit_interval); |
| 633 | IF_DEF_PARAMS (ifp)->retransmit_interval = OSPF_RETRANSMIT_INTERVAL_DEFAULT; |
| 634 | |
| 635 | SET_IF_PARAM (IF_DEF_PARAMS (ifp), priority); |
| 636 | IF_DEF_PARAMS (ifp)->priority = OSPF_ROUTER_PRIORITY_DEFAULT; |
| 637 | |
| 638 | SET_IF_PARAM (IF_DEF_PARAMS (ifp), passive_interface); |
| 639 | IF_DEF_PARAMS (ifp)->passive_interface = OSPF_IF_ACTIVE; |
| 640 | |
| 641 | SET_IF_PARAM (IF_DEF_PARAMS (ifp), v_hello); |
| 642 | IF_DEF_PARAMS (ifp)->v_hello = OSPF_HELLO_INTERVAL_DEFAULT; |
| 643 | |
| 644 | SET_IF_PARAM (IF_DEF_PARAMS (ifp), v_wait); |
| 645 | IF_DEF_PARAMS (ifp)->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT; |
| 646 | |
| 647 | SET_IF_PARAM (IF_DEF_PARAMS (ifp), auth_simple); |
| 648 | memset (IF_DEF_PARAMS (ifp)->auth_simple, 0, OSPF_AUTH_SIMPLE_SIZE); |
| 649 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 650 | SET_IF_PARAM (IF_DEF_PARAMS (ifp), auth_type); |
| 651 | IF_DEF_PARAMS (ifp)->auth_type = OSPF_AUTH_NOTSET; |
| 652 | |
| 653 | #ifdef HAVE_OPAQUE_LSA |
| 654 | rc = ospf_opaque_new_if (ifp); |
| 655 | #endif /* HAVE_OPAQUE_LSA */ |
| 656 | return rc; |
| 657 | } |
| 658 | |
| 659 | int |
| 660 | ospf_if_delete_hook (struct interface *ifp) |
| 661 | { |
| 662 | int rc = 0; |
| 663 | #ifdef HAVE_OPAQUE_LSA |
| 664 | rc = ospf_opaque_del_if (ifp); |
| 665 | #endif /* HAVE_OPAQUE_LSA */ |
| 666 | route_table_finish (IF_OIFS (ifp)); |
| 667 | route_table_finish (IF_OIFS_PARAMS (ifp)); |
paul | cfc959b | 2003-06-04 02:28:45 +0000 | [diff] [blame] | 668 | ospf_del_if_params ((struct ospf_if_params *) IF_DEF_PARAMS (ifp)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 669 | XFREE (MTYPE_OSPF_IF_INFO, ifp->info); |
| 670 | ifp->info = NULL; |
| 671 | |
| 672 | return rc; |
| 673 | } |
| 674 | |
| 675 | int |
| 676 | ospf_if_is_enable (struct ospf_interface *oi) |
| 677 | { |
| 678 | if (!if_is_loopback (oi->ifp)) |
| 679 | if (if_is_up (oi->ifp)) |
| 680 | return 1; |
| 681 | |
| 682 | return 0; |
| 683 | } |
| 684 | |
| 685 | int |
| 686 | ospf_if_up (struct ospf_interface *oi) |
| 687 | { |
| 688 | if (oi == NULL) |
| 689 | return 0; |
| 690 | |
| 691 | if (oi->type == OSPF_IFTYPE_LOOPBACK) |
| 692 | OSPF_ISM_EVENT_SCHEDULE (oi, ISM_LoopInd); |
| 693 | else |
| 694 | { |
| 695 | if (oi->type != OSPF_IFTYPE_VIRTUALLINK) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 696 | ospf_if_add_allspfrouters (oi->ospf, oi->address, oi->ifp->ifindex); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 697 | ospf_if_stream_set (oi); |
| 698 | OSPF_ISM_EVENT_SCHEDULE (oi, ISM_InterfaceUp); |
| 699 | } |
| 700 | |
| 701 | return 1; |
| 702 | } |
| 703 | |
| 704 | int |
| 705 | ospf_if_down (struct ospf_interface *oi) |
| 706 | { |
| 707 | if (oi == NULL) |
| 708 | return 0; |
| 709 | |
| 710 | OSPF_ISM_EVENT_EXECUTE (oi, ISM_InterfaceDown); |
| 711 | /* Shutdown packet reception and sending */ |
| 712 | ospf_if_stream_unset (oi); |
| 713 | if (oi->type != OSPF_IFTYPE_VIRTUALLINK) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 714 | ospf_if_drop_allspfrouters (oi->ospf, oi->address, oi->ifp->ifindex); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 715 | |
| 716 | |
| 717 | return 1; |
| 718 | } |
| 719 | |
| 720 | |
| 721 | /* Virtual Link related functions. */ |
| 722 | |
| 723 | struct ospf_vl_data * |
| 724 | ospf_vl_data_new (struct ospf_area *area, struct in_addr vl_peer) |
| 725 | { |
| 726 | struct ospf_vl_data *vl_data; |
| 727 | |
| 728 | vl_data = XMALLOC (MTYPE_OSPF_VL_DATA, sizeof (struct ospf_vl_data)); |
| 729 | memset (vl_data, 0, sizeof (struct ospf_vl_data)); |
| 730 | |
| 731 | vl_data->vl_peer.s_addr = vl_peer.s_addr; |
| 732 | vl_data->vl_area_id = area->area_id; |
| 733 | vl_data->format = area->format; |
| 734 | |
| 735 | return vl_data; |
| 736 | } |
| 737 | |
| 738 | void |
| 739 | ospf_vl_data_free (struct ospf_vl_data *vl_data) |
| 740 | { |
| 741 | XFREE (MTYPE_OSPF_VL_DATA, vl_data); |
| 742 | } |
| 743 | |
| 744 | u_int vlink_count = 0; |
| 745 | |
| 746 | struct ospf_interface * |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 747 | ospf_vl_new (struct ospf *ospf, struct ospf_vl_data *vl_data) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 748 | { |
| 749 | struct ospf_interface * voi; |
| 750 | struct interface * vi; |
| 751 | char ifname[INTERFACE_NAMSIZ + 1]; |
| 752 | struct ospf_area *area; |
| 753 | struct in_addr area_id; |
| 754 | struct connected *co; |
| 755 | struct prefix_ipv4 *p; |
| 756 | |
| 757 | if (IS_DEBUG_OSPF_EVENT) |
| 758 | zlog_info ("ospf_vl_new(): Start"); |
| 759 | if (vlink_count == OSPF_VL_MAX_COUNT) |
| 760 | { |
| 761 | if (IS_DEBUG_OSPF_EVENT) |
| 762 | zlog_info ("ospf_vl_new(): Alarm: " |
| 763 | "cannot create more than OSPF_MAX_VL_COUNT virtual links"); |
| 764 | return NULL; |
| 765 | } |
| 766 | |
| 767 | if (IS_DEBUG_OSPF_EVENT) |
| 768 | zlog_info ("ospf_vl_new(): creating pseudo zebra interface"); |
| 769 | |
paul | 106d2fd | 2003-08-01 00:24:13 +0000 | [diff] [blame] | 770 | snprintf (ifname, INTERFACE_NAMSIZ + 1, "VLINK%d", vlink_count); |
| 771 | vi = if_create (ifname, INTERFACE_NAMSIZ); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 772 | co = connected_new (); |
| 773 | co->ifp = vi; |
| 774 | listnode_add (vi->connected, co); |
| 775 | |
| 776 | p = prefix_ipv4_new (); |
| 777 | p->family = AF_INET; |
| 778 | p->prefix.s_addr = 0; |
| 779 | p->prefixlen = 0; |
| 780 | |
| 781 | co->address = (struct prefix *)p; |
| 782 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 783 | voi = ospf_if_new (ospf, vi, co->address); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 784 | if (voi == NULL) |
| 785 | { |
| 786 | if (IS_DEBUG_OSPF_EVENT) |
| 787 | zlog_info ("ospf_vl_new(): Alarm: OSPF int structure is not created"); |
| 788 | return NULL; |
| 789 | } |
| 790 | voi->connected = co; |
| 791 | voi->vl_data = vl_data; |
| 792 | voi->ifp->mtu = OSPF_VL_MTU; |
| 793 | voi->type = OSPF_IFTYPE_VIRTUALLINK; |
| 794 | |
paul | 106d2fd | 2003-08-01 00:24:13 +0000 | [diff] [blame] | 795 | vlink_count++; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 796 | if (IS_DEBUG_OSPF_EVENT) |
| 797 | zlog_info ("ospf_vl_new(): Created name: %s", ifname); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 798 | if (IS_DEBUG_OSPF_EVENT) |
| 799 | zlog_info ("ospf_vl_new(): set if->name to %s", vi->name); |
| 800 | |
| 801 | area_id.s_addr = 0; |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 802 | area = ospf_area_get (ospf, area_id, OSPF_AREA_ID_FORMAT_ADDRESS); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 803 | voi->area = area; |
| 804 | |
| 805 | if (IS_DEBUG_OSPF_EVENT) |
| 806 | zlog_info ("ospf_vl_new(): set associated area to the backbone"); |
| 807 | |
| 808 | ospf_area_add_if (voi->area, voi); |
| 809 | |
| 810 | ospf_if_stream_set (voi); |
| 811 | |
| 812 | if (IS_DEBUG_OSPF_EVENT) |
| 813 | zlog_info ("ospf_vl_new(): Stop"); |
| 814 | return voi; |
| 815 | } |
| 816 | |
| 817 | void |
| 818 | ospf_vl_if_delete (struct ospf_vl_data *vl_data) |
| 819 | { |
| 820 | struct interface *ifp = vl_data->vl_oi->ifp; |
| 821 | vl_data->vl_oi->address->u.prefix4.s_addr = 0; |
| 822 | vl_data->vl_oi->address->prefixlen = 0; |
| 823 | ospf_if_free (vl_data->vl_oi); |
| 824 | if_delete (ifp); |
| 825 | vlink_count--; |
| 826 | } |
| 827 | |
| 828 | struct ospf_vl_data * |
| 829 | ospf_vl_lookup (struct ospf_area *area, struct in_addr vl_peer) |
| 830 | { |
| 831 | struct ospf_vl_data *vl_data; |
| 832 | listnode node; |
| 833 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 834 | for (node = listhead (area->ospf->vlinks); node; nextnode (node)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 835 | if ((vl_data = getdata (node)) != NULL) |
| 836 | if (vl_data->vl_peer.s_addr == vl_peer.s_addr && |
| 837 | IPV4_ADDR_SAME (&vl_data->vl_area_id, &area->area_id)) |
| 838 | return vl_data; |
| 839 | |
| 840 | return NULL; |
| 841 | } |
| 842 | |
| 843 | void |
| 844 | ospf_vl_shutdown (struct ospf_vl_data *vl_data) |
| 845 | { |
| 846 | struct ospf_interface *oi; |
| 847 | |
| 848 | if ((oi = vl_data->vl_oi) == NULL) |
| 849 | return; |
| 850 | |
| 851 | oi->address->u.prefix4.s_addr = 0; |
| 852 | oi->address->prefixlen = 0; |
| 853 | |
| 854 | UNSET_FLAG (oi->ifp->flags, IFF_UP); |
| 855 | /* OSPF_ISM_EVENT_SCHEDULE (oi, ISM_InterfaceDown); */ |
| 856 | OSPF_ISM_EVENT_EXECUTE (oi, ISM_InterfaceDown); |
| 857 | } |
| 858 | |
| 859 | void |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 860 | ospf_vl_add (struct ospf *ospf, struct ospf_vl_data *vl_data) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 861 | { |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 862 | listnode_add (ospf->vlinks, vl_data); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 863 | #ifdef HAVE_SNMP |
| 864 | ospf_snmp_vl_add (vl_data); |
| 865 | #endif /* HAVE_SNMP */ |
| 866 | } |
| 867 | |
| 868 | void |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 869 | ospf_vl_delete (struct ospf *ospf, struct ospf_vl_data *vl_data) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 870 | { |
| 871 | ospf_vl_shutdown (vl_data); |
| 872 | ospf_vl_if_delete (vl_data); |
| 873 | |
| 874 | #ifdef HAVE_SNMP |
| 875 | ospf_snmp_vl_delete (vl_data); |
| 876 | #endif /* HAVE_SNMP */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 877 | listnode_delete (ospf->vlinks, vl_data); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 878 | |
| 879 | ospf_vl_data_free (vl_data); |
| 880 | } |
| 881 | |
paul | 2e6b0bb | 2003-06-22 08:17:12 +0000 | [diff] [blame] | 882 | int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 883 | ospf_vl_set_params (struct ospf_vl_data *vl_data, struct vertex *v) |
| 884 | { |
| 885 | int changed = 0; |
| 886 | struct ospf_interface *voi; |
| 887 | listnode node; |
| 888 | struct vertex_nexthop *nh; |
| 889 | int i; |
| 890 | struct router_lsa *rl; |
| 891 | |
| 892 | voi = vl_data->vl_oi; |
| 893 | |
| 894 | if (voi->output_cost != v->distance) |
| 895 | { |
| 896 | voi->output_cost = v->distance; |
| 897 | changed = 1; |
| 898 | } |
| 899 | |
| 900 | for (node = listhead (v->nexthop); node; nextnode (node)) |
| 901 | if ((nh = getdata (node)) != NULL) |
| 902 | { |
| 903 | vl_data->out_oi = (struct ospf_interface *) nh->oi; |
| 904 | |
| 905 | voi->address->u.prefix4 = vl_data->out_oi->address->u.prefix4; |
| 906 | voi->address->prefixlen = vl_data->out_oi->address->prefixlen; |
| 907 | |
| 908 | break; /* We take the first interface. */ |
| 909 | } |
| 910 | |
| 911 | rl = (struct router_lsa *)v->lsa; |
| 912 | |
| 913 | for (i = 0; i < ntohs (rl->links); i++) |
| 914 | { |
| 915 | switch (rl->link[i].type) |
paul | 2e6b0bb | 2003-06-22 08:17:12 +0000 | [diff] [blame] | 916 | { |
| 917 | case LSA_LINK_TYPE_VIRTUALLINK: |
| 918 | if (IS_DEBUG_OSPF_EVENT) |
| 919 | zlog_info ("found back link through VL"); |
| 920 | case LSA_LINK_TYPE_TRANSIT: |
| 921 | case LSA_LINK_TYPE_POINTOPOINT: |
| 922 | vl_data->peer_addr = rl->link[i].link_data; |
| 923 | if (IS_DEBUG_OSPF_EVENT) |
| 924 | zlog_info ("%s peer address is %s\n", |
| 925 | vl_data->vl_oi->ifp->name, |
| 926 | inet_ntoa(vl_data->peer_addr)); |
| 927 | return changed; |
| 928 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 929 | } |
paul | 2e6b0bb | 2003-06-22 08:17:12 +0000 | [diff] [blame] | 930 | return changed; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 931 | } |
| 932 | |
| 933 | |
| 934 | void |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 935 | ospf_vl_up_check (struct ospf_area *area, struct in_addr rid, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 936 | struct vertex *v) |
| 937 | { |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 938 | struct ospf *ospf = area->ospf; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 939 | listnode node; |
| 940 | struct ospf_vl_data *vl_data; |
| 941 | struct ospf_interface *oi; |
| 942 | |
| 943 | if (IS_DEBUG_OSPF_EVENT) |
| 944 | { |
| 945 | zlog_info ("ospf_vl_up_check(): Start"); |
| 946 | zlog_info ("ospf_vl_up_check(): Router ID is %s", inet_ntoa (rid)); |
| 947 | zlog_info ("ospf_vl_up_check(): Area is %s", inet_ntoa (area->area_id)); |
| 948 | } |
| 949 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 950 | for (node = listhead (ospf->vlinks); node; nextnode (node)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 951 | { |
| 952 | if ((vl_data = getdata (node)) == NULL) |
| 953 | continue; |
| 954 | |
| 955 | if (IS_DEBUG_OSPF_EVENT) |
| 956 | { |
| 957 | zlog_info ("ospf_vl_up_check(): considering VL, name: %s", |
| 958 | vl_data->vl_oi->ifp->name); |
| 959 | zlog_info ("ospf_vl_up_check(): VL area: %s, peer ID: %s", |
| 960 | inet_ntoa (vl_data->vl_area_id), |
| 961 | inet_ntoa (vl_data->vl_peer)); |
| 962 | } |
| 963 | |
| 964 | if (IPV4_ADDR_SAME (&vl_data->vl_peer, &rid) && |
| 965 | IPV4_ADDR_SAME (&vl_data->vl_area_id, &area->area_id)) |
| 966 | { |
| 967 | oi = vl_data->vl_oi; |
| 968 | SET_FLAG (vl_data->flags, OSPF_VL_FLAG_APPROVED); |
| 969 | |
| 970 | if (IS_DEBUG_OSPF_EVENT) |
| 971 | zlog_info ("ospf_vl_up_check(): this VL matched"); |
| 972 | |
| 973 | if (oi->state == ISM_Down) |
| 974 | { |
| 975 | if (IS_DEBUG_OSPF_EVENT) |
| 976 | zlog_info ("ospf_vl_up_check(): VL is down, waking it up"); |
| 977 | SET_FLAG (oi->ifp->flags, IFF_UP); |
paul | 2e6b0bb | 2003-06-22 08:17:12 +0000 | [diff] [blame] | 978 | OSPF_ISM_EVENT_EXECUTE(oi,ISM_InterfaceUp); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 979 | } |
| 980 | |
paul | 2e6b0bb | 2003-06-22 08:17:12 +0000 | [diff] [blame] | 981 | if (ospf_vl_set_params (vl_data, v)) |
| 982 | { |
| 983 | if (IS_DEBUG_OSPF (ism, ISM_EVENTS)) |
| 984 | zlog_info ("ospf_vl_up_check: VL cost change, scheduling router lsa refresh"); |
| 985 | if(ospf->backbone) |
| 986 | ospf_router_lsa_timer_add(ospf->backbone); |
| 987 | else if (IS_DEBUG_OSPF (ism, ISM_EVENTS)) |
| 988 | zlog_info ("ospf_vl_up_check: VL cost change, no backbone!"); |
| 989 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 990 | } |
| 991 | } |
| 992 | } |
| 993 | |
| 994 | void |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 995 | ospf_vl_unapprove (struct ospf *ospf) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 996 | { |
| 997 | listnode node; |
| 998 | struct ospf_vl_data *vl_data; |
| 999 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1000 | for (node = listhead (ospf->vlinks); node; nextnode (node)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1001 | if ((vl_data = getdata (node)) != NULL) |
| 1002 | UNSET_FLAG (vl_data->flags, OSPF_VL_FLAG_APPROVED); |
| 1003 | } |
| 1004 | |
| 1005 | void |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1006 | ospf_vl_shut_unapproved (struct ospf *ospf) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1007 | { |
| 1008 | listnode node; |
| 1009 | struct ospf_vl_data *vl_data; |
| 1010 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1011 | for (node = listhead (ospf->vlinks); node; nextnode (node)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1012 | if ((vl_data = getdata (node)) != NULL) |
| 1013 | if (!CHECK_FLAG (vl_data->flags, OSPF_VL_FLAG_APPROVED)) |
| 1014 | ospf_vl_shutdown (vl_data); |
| 1015 | } |
| 1016 | |
| 1017 | int |
| 1018 | ospf_full_virtual_nbrs (struct ospf_area *area) |
| 1019 | { |
| 1020 | if (IS_DEBUG_OSPF_EVENT) |
| 1021 | { |
| 1022 | zlog_info ("counting fully adjacent virtual neighbors in area %s", |
| 1023 | inet_ntoa (area->area_id)); |
| 1024 | zlog_info ("there are %d of them", area->full_vls); |
| 1025 | } |
| 1026 | |
| 1027 | return area->full_vls; |
| 1028 | } |
| 1029 | |
| 1030 | int |
| 1031 | ospf_vls_in_area (struct ospf_area *area) |
| 1032 | { |
| 1033 | listnode node; |
| 1034 | struct ospf_vl_data *vl_data; |
| 1035 | int c = 0; |
| 1036 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1037 | for (node = listhead (area->ospf->vlinks); node; nextnode (node)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1038 | if ((vl_data = getdata (node)) != NULL) |
| 1039 | if (IPV4_ADDR_SAME (&vl_data->vl_area_id, &area->area_id)) |
| 1040 | c++; |
| 1041 | |
| 1042 | return c; |
| 1043 | } |
| 1044 | |
| 1045 | |
| 1046 | struct crypt_key * |
| 1047 | ospf_crypt_key_new () |
| 1048 | { |
| 1049 | struct crypt_key *ck; |
| 1050 | |
| 1051 | ck = XMALLOC (MTYPE_OSPF_CRYPT_KEY, sizeof (struct crypt_key)); |
| 1052 | memset (ck, 0, sizeof (struct crypt_key)); |
| 1053 | |
| 1054 | return ck; |
| 1055 | } |
| 1056 | |
| 1057 | void |
| 1058 | ospf_crypt_key_add (list crypt, struct crypt_key *ck) |
| 1059 | { |
| 1060 | listnode_add (crypt, ck); |
| 1061 | } |
| 1062 | |
| 1063 | struct crypt_key * |
| 1064 | ospf_crypt_key_lookup (list auth_crypt, u_char key_id) |
| 1065 | { |
| 1066 | listnode node; |
| 1067 | struct crypt_key *ck; |
| 1068 | |
| 1069 | for (node = listhead (auth_crypt); node; nextnode (node)) |
| 1070 | { |
| 1071 | ck = getdata (node); |
| 1072 | if (ck->key_id == key_id) |
| 1073 | return ck; |
| 1074 | } |
| 1075 | |
| 1076 | return NULL; |
| 1077 | } |
| 1078 | |
| 1079 | int |
| 1080 | ospf_crypt_key_delete (list auth_crypt, u_char key_id) |
| 1081 | { |
| 1082 | listnode node; |
| 1083 | struct crypt_key *ck; |
| 1084 | |
| 1085 | for (node = listhead (auth_crypt); node; nextnode (node)) |
| 1086 | { |
| 1087 | ck = getdata (node); |
| 1088 | if (ck->key_id == key_id) |
| 1089 | { |
| 1090 | listnode_delete (auth_crypt, ck); |
| 1091 | return 1; |
| 1092 | } |
| 1093 | } |
| 1094 | |
| 1095 | return 0; |
| 1096 | } |
| 1097 | |
| 1098 | void |
| 1099 | ospf_if_init () |
| 1100 | { |
| 1101 | /* Initialize Zebra interface data structure. */ |
| 1102 | if_init (); |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 1103 | om->iflist = iflist; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1104 | if_add_hook (IF_NEW_HOOK, ospf_if_new_hook); |
| 1105 | if_add_hook (IF_DELETE_HOOK, ospf_if_delete_hook); |
| 1106 | } |