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; |
paul | f2c8065 | 2002-12-13 21:44:27 +0000 | [diff] [blame] | 295 | case OSPF_AREA_NSSA: |
| 296 | UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_E); |
| 297 | SET_FLAG (oi->nbr_self->options, OSPF_OPTION_NP); |
| 298 | break; |
paul | f2c8065 | 2002-12-13 21:44:27 +0000 | [diff] [blame] | 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 * |
hasso | 2db3d05 | 2004-02-11 21:52:13 +0000 | [diff] [blame] | 372 | ospf_if_exists (struct ospf_interface *oic) |
| 373 | { |
| 374 | listnode node; |
| 375 | struct ospf *ospf; |
| 376 | struct ospf_interface *oi; |
| 377 | |
| 378 | ospf = ospf_lookup (); |
| 379 | |
| 380 | for (node = listhead (ospf->oiflist); node; nextnode (node)) |
| 381 | { |
| 382 | if (((oi = getdata (node)) != NULL) && (oi == oic)) |
| 383 | return oi; |
| 384 | } |
| 385 | return NULL; |
| 386 | } |
| 387 | |
| 388 | struct ospf_interface * |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 389 | ospf_if_lookup_by_local_addr (struct ospf *ospf, |
| 390 | struct interface *ifp, struct in_addr address) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 391 | { |
| 392 | listnode node; |
| 393 | struct ospf_interface *oi; |
| 394 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 395 | for (node = listhead (ospf->oiflist); node; nextnode (node)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 396 | if ((oi = getdata (node)) != NULL && oi->type != OSPF_IFTYPE_VIRTUALLINK) |
| 397 | { |
| 398 | if (ifp && oi->ifp != ifp) |
| 399 | continue; |
| 400 | |
| 401 | if (IPV4_ADDR_SAME (&address, &oi->address->u.prefix4)) |
| 402 | return oi; |
| 403 | } |
| 404 | |
| 405 | return NULL; |
| 406 | } |
| 407 | |
| 408 | struct ospf_interface * |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 409 | ospf_if_lookup_by_prefix (struct ospf *ospf, struct prefix_ipv4 *p) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 410 | { |
| 411 | listnode node; |
| 412 | struct ospf_interface *oi; |
| 413 | struct prefix ptmp; |
| 414 | |
| 415 | /* Check each Interface. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 416 | for (node = listhead (ospf->oiflist); node; nextnode (node)) |
| 417 | { |
| 418 | if ((oi = getdata (node)) != NULL && oi->type != OSPF_IFTYPE_VIRTUALLINK) |
| 419 | { |
| 420 | if (oi->type == OSPF_IFTYPE_POINTOPOINT) |
| 421 | { |
| 422 | prefix_copy (&ptmp, oi->connected->destination); |
| 423 | ptmp.prefixlen = IPV4_MAX_BITLEN; |
| 424 | } |
| 425 | else |
| 426 | prefix_copy (&ptmp, oi->address); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 427 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 428 | apply_mask (&ptmp); |
| 429 | if (prefix_same (&ptmp, (struct prefix *) p)) |
| 430 | return oi; |
| 431 | } |
| 432 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 433 | return NULL; |
| 434 | } |
| 435 | |
| 436 | /* determine receiving interface by source of packet */ |
| 437 | struct ospf_interface * |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 438 | ospf_if_lookup_recv_if (struct ospf *ospf, struct in_addr src) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 439 | { |
| 440 | listnode node; |
| 441 | struct prefix_ipv4 addr; |
| 442 | struct ospf_interface *oi, *match; |
| 443 | |
| 444 | addr.family = AF_INET; |
| 445 | addr.prefix = src; |
| 446 | addr.prefixlen = IPV4_MAX_BITLEN; |
| 447 | |
| 448 | match = NULL; |
| 449 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 450 | for (node = listhead (ospf->oiflist); node; nextnode (node)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 451 | { |
| 452 | oi = getdata (node); |
| 453 | |
| 454 | if (oi->type == OSPF_IFTYPE_VIRTUALLINK) |
| 455 | continue; |
| 456 | |
| 457 | if (oi->type == OSPF_IFTYPE_POINTOPOINT) |
| 458 | { |
| 459 | if (IPV4_ADDR_SAME (&oi->connected->destination->u.prefix4, &src)) |
| 460 | return oi; |
| 461 | } |
| 462 | else |
| 463 | { |
| 464 | if (prefix_match (oi->address, (struct prefix *) &addr)) |
paul | 0a825c7 | 2003-05-24 13:48:16 +0000 | [diff] [blame] | 465 | { |
paul | af8d033 | 2003-05-24 15:31:45 +0000 | [diff] [blame] | 466 | if ( (match == NULL) || |
| 467 | (match->address->prefixlen < oi->address->prefixlen) |
| 468 | ) |
paul | 0a825c7 | 2003-05-24 13:48:16 +0000 | [diff] [blame] | 469 | match = oi; |
| 470 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 471 | } |
| 472 | } |
| 473 | |
| 474 | return match; |
| 475 | } |
| 476 | |
| 477 | void |
| 478 | ospf_if_stream_set (struct ospf_interface *oi) |
| 479 | { |
| 480 | /* set output fifo queue. */ |
| 481 | if (oi->obuf == NULL) |
| 482 | oi->obuf = ospf_fifo_new (); |
| 483 | } |
| 484 | |
| 485 | void |
| 486 | ospf_if_stream_unset (struct ospf_interface *oi) |
| 487 | { |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 488 | struct ospf *ospf = oi->ospf; |
| 489 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 490 | if (oi->obuf) |
| 491 | { |
| 492 | ospf_fifo_free (oi->obuf); |
| 493 | oi->obuf = NULL; |
| 494 | |
| 495 | if (oi->on_write_q) |
| 496 | { |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 497 | listnode_delete (ospf->oi_write_q, oi); |
| 498 | if (list_isempty(ospf->oi_write_q)) |
| 499 | OSPF_TIMER_OFF (ospf->t_write); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 500 | oi->on_write_q = 0; |
| 501 | } |
| 502 | } |
| 503 | } |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 504 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 505 | |
| 506 | struct ospf_if_params * |
| 507 | ospf_new_if_params () |
| 508 | { |
| 509 | struct ospf_if_params *oip; |
| 510 | |
| 511 | oip = XMALLOC (MTYPE_OSPF_IF_PARAMS, sizeof (struct ospf_if_params)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 512 | |
| 513 | if (!oip) |
| 514 | return NULL; |
| 515 | |
paul | f645789 | 2003-04-17 16:11:30 +0000 | [diff] [blame] | 516 | memset (oip, 0, sizeof (struct ospf_if_params)); |
| 517 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 518 | UNSET_IF_PARAM (oip, output_cost_cmd); |
| 519 | UNSET_IF_PARAM (oip, transmit_delay); |
| 520 | UNSET_IF_PARAM (oip, retransmit_interval); |
| 521 | UNSET_IF_PARAM (oip, passive_interface); |
| 522 | UNSET_IF_PARAM (oip, v_hello); |
| 523 | UNSET_IF_PARAM (oip, v_wait); |
| 524 | UNSET_IF_PARAM (oip, priority); |
| 525 | UNSET_IF_PARAM (oip, type); |
| 526 | UNSET_IF_PARAM (oip, auth_simple); |
| 527 | UNSET_IF_PARAM (oip, auth_crypt); |
| 528 | UNSET_IF_PARAM (oip, auth_type); |
paul | ec1ca63 | 2003-06-04 02:23:15 +0000 | [diff] [blame] | 529 | |
| 530 | oip->auth_crypt = list_new (); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 531 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 532 | return oip; |
| 533 | } |
| 534 | |
| 535 | void |
| 536 | ospf_del_if_params (struct ospf_if_params *oip) |
| 537 | { |
| 538 | list_delete (oip->auth_crypt); |
| 539 | XFREE (MTYPE_OSPF_IF_PARAMS, oip); |
| 540 | } |
| 541 | |
| 542 | void |
| 543 | ospf_free_if_params (struct interface *ifp, struct in_addr addr) |
| 544 | { |
| 545 | struct ospf_if_params *oip; |
| 546 | struct prefix_ipv4 p; |
| 547 | struct route_node *rn; |
| 548 | p.prefixlen = IPV4_MAX_PREFIXLEN; |
| 549 | p.prefix = addr; |
| 550 | rn = route_node_lookup (IF_OIFS_PARAMS (ifp), (struct prefix*)&p); |
| 551 | if (!rn || !rn->info) |
| 552 | return; |
| 553 | |
| 554 | oip = rn->info; |
| 555 | route_unlock_node (rn); |
| 556 | |
| 557 | if (!OSPF_IF_PARAM_CONFIGURED (oip, output_cost_cmd) && |
| 558 | !OSPF_IF_PARAM_CONFIGURED (oip, transmit_delay) && |
| 559 | !OSPF_IF_PARAM_CONFIGURED (oip, retransmit_interval) && |
| 560 | !OSPF_IF_PARAM_CONFIGURED (oip, passive_interface) && |
| 561 | !OSPF_IF_PARAM_CONFIGURED (oip, v_hello) && |
| 562 | !OSPF_IF_PARAM_CONFIGURED (oip, v_wait) && |
| 563 | !OSPF_IF_PARAM_CONFIGURED (oip, priority) && |
| 564 | !OSPF_IF_PARAM_CONFIGURED (oip, type) && |
| 565 | !OSPF_IF_PARAM_CONFIGURED (oip, auth_simple) && |
| 566 | !OSPF_IF_PARAM_CONFIGURED (oip, auth_type) && |
| 567 | listcount (oip->auth_crypt) == 0) |
| 568 | { |
| 569 | ospf_del_if_params (oip); |
| 570 | rn->info = NULL; |
| 571 | route_unlock_node (rn); |
| 572 | } |
| 573 | } |
| 574 | |
| 575 | struct ospf_if_params * |
| 576 | ospf_lookup_if_params (struct interface *ifp, struct in_addr addr) |
| 577 | { |
| 578 | struct prefix_ipv4 p; |
| 579 | struct route_node *rn; |
| 580 | |
| 581 | p.prefixlen = IPV4_MAX_PREFIXLEN; |
| 582 | p.prefix = addr; |
| 583 | |
| 584 | rn = route_node_lookup (IF_OIFS_PARAMS (ifp), (struct prefix*)&p); |
| 585 | |
| 586 | if (rn) |
| 587 | { |
| 588 | route_unlock_node (rn); |
| 589 | return rn->info; |
| 590 | } |
| 591 | |
| 592 | return NULL; |
| 593 | } |
| 594 | |
| 595 | struct ospf_if_params * |
| 596 | ospf_get_if_params (struct interface *ifp, struct in_addr addr) |
| 597 | { |
| 598 | struct prefix_ipv4 p; |
| 599 | struct route_node *rn; |
| 600 | |
| 601 | p.family = AF_INET; |
| 602 | p.prefixlen = IPV4_MAX_PREFIXLEN; |
| 603 | p.prefix = addr; |
| 604 | |
| 605 | rn = route_node_get (IF_OIFS_PARAMS (ifp), (struct prefix*)&p); |
| 606 | |
| 607 | if (rn->info == NULL) |
| 608 | rn->info = ospf_new_if_params (); |
| 609 | else |
| 610 | route_unlock_node (rn); |
| 611 | |
| 612 | return rn->info; |
| 613 | } |
| 614 | |
| 615 | void |
| 616 | ospf_if_update_params (struct interface *ifp, struct in_addr addr) |
| 617 | { |
| 618 | struct route_node *rn; |
| 619 | struct ospf_interface *oi; |
| 620 | |
| 621 | for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn)) |
| 622 | { |
| 623 | if ((oi = rn->info) == NULL) |
| 624 | continue; |
| 625 | |
| 626 | if (IPV4_ADDR_SAME (&oi->address->u.prefix4, &addr)) |
| 627 | oi->params = ospf_lookup_if_params (ifp, oi->address->u.prefix4); |
| 628 | } |
| 629 | } |
| 630 | |
| 631 | int |
| 632 | ospf_if_new_hook (struct interface *ifp) |
| 633 | { |
| 634 | int rc = 0; |
| 635 | |
| 636 | ifp->info = XMALLOC (MTYPE_OSPF_IF_INFO, sizeof (struct ospf_if_info)); |
| 637 | memset (ifp->info, 0, sizeof (struct ospf_if_info)); |
| 638 | |
| 639 | IF_OIFS (ifp) = route_table_init (); |
| 640 | IF_OIFS_PARAMS (ifp) = route_table_init (); |
| 641 | |
| 642 | IF_DEF_PARAMS (ifp) = ospf_new_if_params (); |
| 643 | |
| 644 | SET_IF_PARAM (IF_DEF_PARAMS (ifp), transmit_delay); |
| 645 | IF_DEF_PARAMS (ifp)->transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT; |
| 646 | |
| 647 | SET_IF_PARAM (IF_DEF_PARAMS (ifp), retransmit_interval); |
| 648 | IF_DEF_PARAMS (ifp)->retransmit_interval = OSPF_RETRANSMIT_INTERVAL_DEFAULT; |
| 649 | |
| 650 | SET_IF_PARAM (IF_DEF_PARAMS (ifp), priority); |
| 651 | IF_DEF_PARAMS (ifp)->priority = OSPF_ROUTER_PRIORITY_DEFAULT; |
| 652 | |
| 653 | SET_IF_PARAM (IF_DEF_PARAMS (ifp), passive_interface); |
| 654 | IF_DEF_PARAMS (ifp)->passive_interface = OSPF_IF_ACTIVE; |
| 655 | |
| 656 | SET_IF_PARAM (IF_DEF_PARAMS (ifp), v_hello); |
| 657 | IF_DEF_PARAMS (ifp)->v_hello = OSPF_HELLO_INTERVAL_DEFAULT; |
| 658 | |
| 659 | SET_IF_PARAM (IF_DEF_PARAMS (ifp), v_wait); |
| 660 | IF_DEF_PARAMS (ifp)->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT; |
| 661 | |
| 662 | SET_IF_PARAM (IF_DEF_PARAMS (ifp), auth_simple); |
| 663 | memset (IF_DEF_PARAMS (ifp)->auth_simple, 0, OSPF_AUTH_SIMPLE_SIZE); |
| 664 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 665 | SET_IF_PARAM (IF_DEF_PARAMS (ifp), auth_type); |
| 666 | IF_DEF_PARAMS (ifp)->auth_type = OSPF_AUTH_NOTSET; |
| 667 | |
| 668 | #ifdef HAVE_OPAQUE_LSA |
| 669 | rc = ospf_opaque_new_if (ifp); |
| 670 | #endif /* HAVE_OPAQUE_LSA */ |
| 671 | return rc; |
| 672 | } |
| 673 | |
| 674 | int |
| 675 | ospf_if_delete_hook (struct interface *ifp) |
| 676 | { |
| 677 | int rc = 0; |
paul | 940b01a | 2004-02-17 20:07:30 +0000 | [diff] [blame] | 678 | struct route_node *rn; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 679 | #ifdef HAVE_OPAQUE_LSA |
| 680 | rc = ospf_opaque_del_if (ifp); |
| 681 | #endif /* HAVE_OPAQUE_LSA */ |
paul | 940b01a | 2004-02-17 20:07:30 +0000 | [diff] [blame] | 682 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 683 | route_table_finish (IF_OIFS (ifp)); |
paul | 940b01a | 2004-02-17 20:07:30 +0000 | [diff] [blame] | 684 | |
| 685 | for (rn = route_top (IF_OIFS_PARAMS (ifp)); rn; rn = route_next (rn)) |
| 686 | if (rn->info) |
| 687 | ospf_del_if_params (rn->info); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 688 | route_table_finish (IF_OIFS_PARAMS (ifp)); |
paul | 940b01a | 2004-02-17 20:07:30 +0000 | [diff] [blame] | 689 | |
paul | cfc959b | 2003-06-04 02:28:45 +0000 | [diff] [blame] | 690 | ospf_del_if_params ((struct ospf_if_params *) IF_DEF_PARAMS (ifp)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 691 | XFREE (MTYPE_OSPF_IF_INFO, ifp->info); |
| 692 | ifp->info = NULL; |
| 693 | |
| 694 | return rc; |
| 695 | } |
| 696 | |
| 697 | int |
| 698 | ospf_if_is_enable (struct ospf_interface *oi) |
| 699 | { |
| 700 | if (!if_is_loopback (oi->ifp)) |
| 701 | if (if_is_up (oi->ifp)) |
| 702 | return 1; |
| 703 | |
| 704 | return 0; |
| 705 | } |
| 706 | |
| 707 | int |
| 708 | ospf_if_up (struct ospf_interface *oi) |
| 709 | { |
| 710 | if (oi == NULL) |
| 711 | return 0; |
| 712 | |
| 713 | if (oi->type == OSPF_IFTYPE_LOOPBACK) |
| 714 | OSPF_ISM_EVENT_SCHEDULE (oi, ISM_LoopInd); |
| 715 | else |
| 716 | { |
| 717 | if (oi->type != OSPF_IFTYPE_VIRTUALLINK) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 718 | ospf_if_add_allspfrouters (oi->ospf, oi->address, oi->ifp->ifindex); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 719 | ospf_if_stream_set (oi); |
| 720 | OSPF_ISM_EVENT_SCHEDULE (oi, ISM_InterfaceUp); |
| 721 | } |
| 722 | |
| 723 | return 1; |
| 724 | } |
| 725 | |
| 726 | int |
| 727 | ospf_if_down (struct ospf_interface *oi) |
| 728 | { |
| 729 | if (oi == NULL) |
| 730 | return 0; |
| 731 | |
| 732 | OSPF_ISM_EVENT_EXECUTE (oi, ISM_InterfaceDown); |
| 733 | /* Shutdown packet reception and sending */ |
| 734 | ospf_if_stream_unset (oi); |
| 735 | if (oi->type != OSPF_IFTYPE_VIRTUALLINK) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 736 | ospf_if_drop_allspfrouters (oi->ospf, oi->address, oi->ifp->ifindex); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 737 | |
| 738 | |
| 739 | return 1; |
| 740 | } |
| 741 | |
| 742 | |
| 743 | /* Virtual Link related functions. */ |
| 744 | |
| 745 | struct ospf_vl_data * |
| 746 | ospf_vl_data_new (struct ospf_area *area, struct in_addr vl_peer) |
| 747 | { |
| 748 | struct ospf_vl_data *vl_data; |
| 749 | |
| 750 | vl_data = XMALLOC (MTYPE_OSPF_VL_DATA, sizeof (struct ospf_vl_data)); |
| 751 | memset (vl_data, 0, sizeof (struct ospf_vl_data)); |
| 752 | |
| 753 | vl_data->vl_peer.s_addr = vl_peer.s_addr; |
| 754 | vl_data->vl_area_id = area->area_id; |
| 755 | vl_data->format = area->format; |
| 756 | |
| 757 | return vl_data; |
| 758 | } |
| 759 | |
| 760 | void |
| 761 | ospf_vl_data_free (struct ospf_vl_data *vl_data) |
| 762 | { |
| 763 | XFREE (MTYPE_OSPF_VL_DATA, vl_data); |
| 764 | } |
| 765 | |
| 766 | u_int vlink_count = 0; |
| 767 | |
| 768 | struct ospf_interface * |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 769 | ospf_vl_new (struct ospf *ospf, struct ospf_vl_data *vl_data) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 770 | { |
| 771 | struct ospf_interface * voi; |
| 772 | struct interface * vi; |
| 773 | char ifname[INTERFACE_NAMSIZ + 1]; |
| 774 | struct ospf_area *area; |
| 775 | struct in_addr area_id; |
| 776 | struct connected *co; |
| 777 | struct prefix_ipv4 *p; |
| 778 | |
| 779 | if (IS_DEBUG_OSPF_EVENT) |
| 780 | zlog_info ("ospf_vl_new(): Start"); |
| 781 | if (vlink_count == OSPF_VL_MAX_COUNT) |
| 782 | { |
| 783 | if (IS_DEBUG_OSPF_EVENT) |
| 784 | zlog_info ("ospf_vl_new(): Alarm: " |
| 785 | "cannot create more than OSPF_MAX_VL_COUNT virtual links"); |
| 786 | return NULL; |
| 787 | } |
| 788 | |
| 789 | if (IS_DEBUG_OSPF_EVENT) |
| 790 | zlog_info ("ospf_vl_new(): creating pseudo zebra interface"); |
| 791 | |
paul | 106d2fd | 2003-08-01 00:24:13 +0000 | [diff] [blame] | 792 | snprintf (ifname, INTERFACE_NAMSIZ + 1, "VLINK%d", vlink_count); |
| 793 | vi = if_create (ifname, INTERFACE_NAMSIZ); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 794 | co = connected_new (); |
| 795 | co->ifp = vi; |
| 796 | listnode_add (vi->connected, co); |
| 797 | |
| 798 | p = prefix_ipv4_new (); |
| 799 | p->family = AF_INET; |
| 800 | p->prefix.s_addr = 0; |
| 801 | p->prefixlen = 0; |
| 802 | |
| 803 | co->address = (struct prefix *)p; |
| 804 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 805 | voi = ospf_if_new (ospf, vi, co->address); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 806 | if (voi == NULL) |
| 807 | { |
| 808 | if (IS_DEBUG_OSPF_EVENT) |
| 809 | zlog_info ("ospf_vl_new(): Alarm: OSPF int structure is not created"); |
| 810 | return NULL; |
| 811 | } |
| 812 | voi->connected = co; |
| 813 | voi->vl_data = vl_data; |
| 814 | voi->ifp->mtu = OSPF_VL_MTU; |
| 815 | voi->type = OSPF_IFTYPE_VIRTUALLINK; |
| 816 | |
paul | 106d2fd | 2003-08-01 00:24:13 +0000 | [diff] [blame] | 817 | vlink_count++; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 818 | if (IS_DEBUG_OSPF_EVENT) |
| 819 | zlog_info ("ospf_vl_new(): Created name: %s", ifname); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 820 | if (IS_DEBUG_OSPF_EVENT) |
| 821 | zlog_info ("ospf_vl_new(): set if->name to %s", vi->name); |
| 822 | |
| 823 | area_id.s_addr = 0; |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 824 | area = ospf_area_get (ospf, area_id, OSPF_AREA_ID_FORMAT_ADDRESS); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 825 | voi->area = area; |
| 826 | |
| 827 | if (IS_DEBUG_OSPF_EVENT) |
| 828 | zlog_info ("ospf_vl_new(): set associated area to the backbone"); |
| 829 | |
| 830 | ospf_area_add_if (voi->area, voi); |
| 831 | |
| 832 | ospf_if_stream_set (voi); |
| 833 | |
| 834 | if (IS_DEBUG_OSPF_EVENT) |
| 835 | zlog_info ("ospf_vl_new(): Stop"); |
| 836 | return voi; |
| 837 | } |
| 838 | |
| 839 | void |
| 840 | ospf_vl_if_delete (struct ospf_vl_data *vl_data) |
| 841 | { |
| 842 | struct interface *ifp = vl_data->vl_oi->ifp; |
| 843 | vl_data->vl_oi->address->u.prefix4.s_addr = 0; |
| 844 | vl_data->vl_oi->address->prefixlen = 0; |
| 845 | ospf_if_free (vl_data->vl_oi); |
| 846 | if_delete (ifp); |
| 847 | vlink_count--; |
| 848 | } |
| 849 | |
| 850 | struct ospf_vl_data * |
| 851 | ospf_vl_lookup (struct ospf_area *area, struct in_addr vl_peer) |
| 852 | { |
| 853 | struct ospf_vl_data *vl_data; |
| 854 | listnode node; |
| 855 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 856 | for (node = listhead (area->ospf->vlinks); node; nextnode (node)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 857 | if ((vl_data = getdata (node)) != NULL) |
| 858 | if (vl_data->vl_peer.s_addr == vl_peer.s_addr && |
| 859 | IPV4_ADDR_SAME (&vl_data->vl_area_id, &area->area_id)) |
| 860 | return vl_data; |
| 861 | |
| 862 | return NULL; |
| 863 | } |
| 864 | |
| 865 | void |
| 866 | ospf_vl_shutdown (struct ospf_vl_data *vl_data) |
| 867 | { |
| 868 | struct ospf_interface *oi; |
| 869 | |
| 870 | if ((oi = vl_data->vl_oi) == NULL) |
| 871 | return; |
| 872 | |
| 873 | oi->address->u.prefix4.s_addr = 0; |
| 874 | oi->address->prefixlen = 0; |
| 875 | |
| 876 | UNSET_FLAG (oi->ifp->flags, IFF_UP); |
| 877 | /* OSPF_ISM_EVENT_SCHEDULE (oi, ISM_InterfaceDown); */ |
| 878 | OSPF_ISM_EVENT_EXECUTE (oi, ISM_InterfaceDown); |
| 879 | } |
| 880 | |
| 881 | void |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 882 | ospf_vl_add (struct ospf *ospf, struct ospf_vl_data *vl_data) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 883 | { |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 884 | listnode_add (ospf->vlinks, vl_data); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 885 | #ifdef HAVE_SNMP |
| 886 | ospf_snmp_vl_add (vl_data); |
| 887 | #endif /* HAVE_SNMP */ |
| 888 | } |
| 889 | |
| 890 | void |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 891 | ospf_vl_delete (struct ospf *ospf, struct ospf_vl_data *vl_data) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 892 | { |
| 893 | ospf_vl_shutdown (vl_data); |
| 894 | ospf_vl_if_delete (vl_data); |
| 895 | |
| 896 | #ifdef HAVE_SNMP |
| 897 | ospf_snmp_vl_delete (vl_data); |
| 898 | #endif /* HAVE_SNMP */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 899 | listnode_delete (ospf->vlinks, vl_data); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 900 | |
| 901 | ospf_vl_data_free (vl_data); |
| 902 | } |
| 903 | |
paul | 2e6b0bb | 2003-06-22 08:17:12 +0000 | [diff] [blame] | 904 | int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 905 | ospf_vl_set_params (struct ospf_vl_data *vl_data, struct vertex *v) |
| 906 | { |
| 907 | int changed = 0; |
| 908 | struct ospf_interface *voi; |
| 909 | listnode node; |
| 910 | struct vertex_nexthop *nh; |
| 911 | int i; |
| 912 | struct router_lsa *rl; |
| 913 | |
| 914 | voi = vl_data->vl_oi; |
| 915 | |
| 916 | if (voi->output_cost != v->distance) |
| 917 | { |
paul | cd59da6 | 2004-05-05 17:26:55 +0000 | [diff] [blame] | 918 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 919 | voi->output_cost = v->distance; |
| 920 | changed = 1; |
| 921 | } |
| 922 | |
| 923 | for (node = listhead (v->nexthop); node; nextnode (node)) |
| 924 | if ((nh = getdata (node)) != NULL) |
| 925 | { |
paul | cd59da6 | 2004-05-05 17:26:55 +0000 | [diff] [blame] | 926 | vl_data->out_oi = (struct ospf_interface *) nh->oi; |
| 927 | |
| 928 | if (!IPV4_ADDR_SAME(&voi->address->u.prefix4, |
| 929 | &vl_data->out_oi->address->u.prefix4)) |
| 930 | changed = 1; |
| 931 | |
| 932 | voi->address->u.prefix4 = vl_data->out_oi->address->u.prefix4; |
| 933 | voi->address->prefixlen = vl_data->out_oi->address->prefixlen; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 934 | |
paul | cd59da6 | 2004-05-05 17:26:55 +0000 | [diff] [blame] | 935 | break; /* We take the first interface. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 936 | } |
| 937 | |
| 938 | rl = (struct router_lsa *)v->lsa; |
paul | d355bfa | 2004-04-08 07:43:45 +0000 | [diff] [blame] | 939 | |
| 940 | /* use SPF determined backlink index in struct vertex |
| 941 | * for virtual link destination address |
| 942 | */ |
| 943 | if (v->backlink >= 0) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 944 | { |
paul | d355bfa | 2004-04-08 07:43:45 +0000 | [diff] [blame] | 945 | if (!IPV4_ADDR_SAME (&vl_data->peer_addr, |
| 946 | &rl->link[v->backlink].link_data)) |
| 947 | changed = 1; |
| 948 | vl_data->peer_addr = rl->link[v->backlink].link_data; |
| 949 | } |
| 950 | else |
| 951 | { |
| 952 | /* This is highly odd, there is no backlink index |
| 953 | * there should be due to the ospf_spf_has_link() check |
| 954 | * in SPF. Lets warn and try pick a link anyway. |
| 955 | */ |
| 956 | zlog_warn ("ospf_vl_set_params: No backlink for %s!", |
| 957 | vl_data->vl_oi->ifp->name); |
| 958 | for (i = 0; i < ntohs (rl->links); i++) |
paul | 2e6b0bb | 2003-06-22 08:17:12 +0000 | [diff] [blame] | 959 | { |
paul | d355bfa | 2004-04-08 07:43:45 +0000 | [diff] [blame] | 960 | switch (rl->link[i].type) |
| 961 | { |
| 962 | case LSA_LINK_TYPE_VIRTUALLINK: |
| 963 | if (IS_DEBUG_OSPF_EVENT) |
| 964 | zlog_info ("found back link through VL"); |
| 965 | case LSA_LINK_TYPE_TRANSIT: |
| 966 | case LSA_LINK_TYPE_POINTOPOINT: |
paul | cd59da6 | 2004-05-05 17:26:55 +0000 | [diff] [blame] | 967 | if (!IPV4_ADDR_SAME (&vl_data->peer_addr, |
| 968 | &rl->link[i].link_data)) |
| 969 | changed = 1; |
paul | d355bfa | 2004-04-08 07:43:45 +0000 | [diff] [blame] | 970 | vl_data->peer_addr = rl->link[i].link_data; |
| 971 | if (IS_DEBUG_OSPF_EVENT) |
paul | cd59da6 | 2004-05-05 17:26:55 +0000 | [diff] [blame] | 972 | zlog_info ("ospf_vl_set_params: %s peer address is %s\n", |
paul | d355bfa | 2004-04-08 07:43:45 +0000 | [diff] [blame] | 973 | vl_data->vl_oi->ifp->name, |
| 974 | inet_ntoa(vl_data->peer_addr)); |
| 975 | return changed; |
| 976 | } |
paul | 2e6b0bb | 2003-06-22 08:17:12 +0000 | [diff] [blame] | 977 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 978 | } |
paul | d355bfa | 2004-04-08 07:43:45 +0000 | [diff] [blame] | 979 | |
| 980 | if (IS_DEBUG_OSPF_EVENT) |
| 981 | zlog_info ("ospf_vl_set_params: %s peer address is %s\n", |
| 982 | vl_data->vl_oi->ifp->name, |
| 983 | inet_ntoa(vl_data->peer_addr)); |
| 984 | |
paul | 2e6b0bb | 2003-06-22 08:17:12 +0000 | [diff] [blame] | 985 | return changed; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 986 | } |
| 987 | |
| 988 | |
| 989 | void |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 990 | ospf_vl_up_check (struct ospf_area *area, struct in_addr rid, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 991 | struct vertex *v) |
| 992 | { |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 993 | struct ospf *ospf = area->ospf; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 994 | listnode node; |
| 995 | struct ospf_vl_data *vl_data; |
| 996 | struct ospf_interface *oi; |
| 997 | |
| 998 | if (IS_DEBUG_OSPF_EVENT) |
| 999 | { |
| 1000 | zlog_info ("ospf_vl_up_check(): Start"); |
| 1001 | zlog_info ("ospf_vl_up_check(): Router ID is %s", inet_ntoa (rid)); |
| 1002 | zlog_info ("ospf_vl_up_check(): Area is %s", inet_ntoa (area->area_id)); |
| 1003 | } |
| 1004 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1005 | for (node = listhead (ospf->vlinks); node; nextnode (node)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1006 | { |
| 1007 | if ((vl_data = getdata (node)) == NULL) |
| 1008 | continue; |
| 1009 | |
| 1010 | if (IS_DEBUG_OSPF_EVENT) |
| 1011 | { |
| 1012 | zlog_info ("ospf_vl_up_check(): considering VL, name: %s", |
| 1013 | vl_data->vl_oi->ifp->name); |
| 1014 | zlog_info ("ospf_vl_up_check(): VL area: %s, peer ID: %s", |
| 1015 | inet_ntoa (vl_data->vl_area_id), |
| 1016 | inet_ntoa (vl_data->vl_peer)); |
| 1017 | } |
| 1018 | |
| 1019 | if (IPV4_ADDR_SAME (&vl_data->vl_peer, &rid) && |
| 1020 | IPV4_ADDR_SAME (&vl_data->vl_area_id, &area->area_id)) |
| 1021 | { |
| 1022 | oi = vl_data->vl_oi; |
| 1023 | SET_FLAG (vl_data->flags, OSPF_VL_FLAG_APPROVED); |
| 1024 | |
| 1025 | if (IS_DEBUG_OSPF_EVENT) |
| 1026 | zlog_info ("ospf_vl_up_check(): this VL matched"); |
| 1027 | |
| 1028 | if (oi->state == ISM_Down) |
| 1029 | { |
| 1030 | if (IS_DEBUG_OSPF_EVENT) |
| 1031 | zlog_info ("ospf_vl_up_check(): VL is down, waking it up"); |
| 1032 | SET_FLAG (oi->ifp->flags, IFF_UP); |
paul | 2e6b0bb | 2003-06-22 08:17:12 +0000 | [diff] [blame] | 1033 | OSPF_ISM_EVENT_EXECUTE(oi,ISM_InterfaceUp); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1034 | } |
| 1035 | |
paul | 2e6b0bb | 2003-06-22 08:17:12 +0000 | [diff] [blame] | 1036 | if (ospf_vl_set_params (vl_data, v)) |
| 1037 | { |
| 1038 | if (IS_DEBUG_OSPF (ism, ISM_EVENTS)) |
paul | cd59da6 | 2004-05-05 17:26:55 +0000 | [diff] [blame] | 1039 | zlog_info ("ospf_vl_up_check: VL cost change," |
| 1040 | " scheduling router lsa refresh"); |
paul | 2e6b0bb | 2003-06-22 08:17:12 +0000 | [diff] [blame] | 1041 | if(ospf->backbone) |
paul | cd59da6 | 2004-05-05 17:26:55 +0000 | [diff] [blame] | 1042 | ospf_router_lsa_timer_add (ospf->backbone); |
paul | 2e6b0bb | 2003-06-22 08:17:12 +0000 | [diff] [blame] | 1043 | else if (IS_DEBUG_OSPF (ism, ISM_EVENTS)) |
| 1044 | zlog_info ("ospf_vl_up_check: VL cost change, no backbone!"); |
| 1045 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1046 | } |
| 1047 | } |
| 1048 | } |
| 1049 | |
| 1050 | void |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1051 | ospf_vl_unapprove (struct ospf *ospf) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1052 | { |
| 1053 | listnode node; |
| 1054 | struct ospf_vl_data *vl_data; |
| 1055 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1056 | for (node = listhead (ospf->vlinks); node; nextnode (node)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1057 | if ((vl_data = getdata (node)) != NULL) |
| 1058 | UNSET_FLAG (vl_data->flags, OSPF_VL_FLAG_APPROVED); |
| 1059 | } |
| 1060 | |
| 1061 | void |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1062 | ospf_vl_shut_unapproved (struct ospf *ospf) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1063 | { |
| 1064 | listnode node; |
| 1065 | struct ospf_vl_data *vl_data; |
| 1066 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1067 | for (node = listhead (ospf->vlinks); node; nextnode (node)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1068 | if ((vl_data = getdata (node)) != NULL) |
| 1069 | if (!CHECK_FLAG (vl_data->flags, OSPF_VL_FLAG_APPROVED)) |
| 1070 | ospf_vl_shutdown (vl_data); |
| 1071 | } |
| 1072 | |
| 1073 | int |
| 1074 | ospf_full_virtual_nbrs (struct ospf_area *area) |
| 1075 | { |
| 1076 | if (IS_DEBUG_OSPF_EVENT) |
| 1077 | { |
| 1078 | zlog_info ("counting fully adjacent virtual neighbors in area %s", |
| 1079 | inet_ntoa (area->area_id)); |
| 1080 | zlog_info ("there are %d of them", area->full_vls); |
| 1081 | } |
| 1082 | |
| 1083 | return area->full_vls; |
| 1084 | } |
| 1085 | |
| 1086 | int |
| 1087 | ospf_vls_in_area (struct ospf_area *area) |
| 1088 | { |
| 1089 | listnode node; |
| 1090 | struct ospf_vl_data *vl_data; |
| 1091 | int c = 0; |
| 1092 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1093 | for (node = listhead (area->ospf->vlinks); node; nextnode (node)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1094 | if ((vl_data = getdata (node)) != NULL) |
| 1095 | if (IPV4_ADDR_SAME (&vl_data->vl_area_id, &area->area_id)) |
| 1096 | c++; |
| 1097 | |
| 1098 | return c; |
| 1099 | } |
| 1100 | |
| 1101 | |
| 1102 | struct crypt_key * |
| 1103 | ospf_crypt_key_new () |
| 1104 | { |
| 1105 | struct crypt_key *ck; |
| 1106 | |
| 1107 | ck = XMALLOC (MTYPE_OSPF_CRYPT_KEY, sizeof (struct crypt_key)); |
| 1108 | memset (ck, 0, sizeof (struct crypt_key)); |
| 1109 | |
| 1110 | return ck; |
| 1111 | } |
| 1112 | |
| 1113 | void |
| 1114 | ospf_crypt_key_add (list crypt, struct crypt_key *ck) |
| 1115 | { |
| 1116 | listnode_add (crypt, ck); |
| 1117 | } |
| 1118 | |
| 1119 | struct crypt_key * |
| 1120 | ospf_crypt_key_lookup (list auth_crypt, u_char key_id) |
| 1121 | { |
| 1122 | listnode node; |
| 1123 | struct crypt_key *ck; |
| 1124 | |
| 1125 | for (node = listhead (auth_crypt); node; nextnode (node)) |
| 1126 | { |
| 1127 | ck = getdata (node); |
| 1128 | if (ck->key_id == key_id) |
| 1129 | return ck; |
| 1130 | } |
| 1131 | |
| 1132 | return NULL; |
| 1133 | } |
| 1134 | |
| 1135 | int |
| 1136 | ospf_crypt_key_delete (list auth_crypt, u_char key_id) |
| 1137 | { |
| 1138 | listnode node; |
| 1139 | struct crypt_key *ck; |
| 1140 | |
| 1141 | for (node = listhead (auth_crypt); node; nextnode (node)) |
| 1142 | { |
| 1143 | ck = getdata (node); |
| 1144 | if (ck->key_id == key_id) |
| 1145 | { |
| 1146 | listnode_delete (auth_crypt, ck); |
| 1147 | return 1; |
| 1148 | } |
| 1149 | } |
| 1150 | |
| 1151 | return 0; |
| 1152 | } |
| 1153 | |
| 1154 | void |
| 1155 | ospf_if_init () |
| 1156 | { |
| 1157 | /* Initialize Zebra interface data structure. */ |
| 1158 | if_init (); |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 1159 | om->iflist = iflist; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1160 | if_add_hook (IF_NEW_HOOK, ospf_if_new_hook); |
| 1161 | if_add_hook (IF_DELETE_HOOK, ospf_if_delete_hook); |
| 1162 | } |