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