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