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