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