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