jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1 | /* |
| 2 | * IS-IS Rout(e)ing protocol - isis_spf.c |
| 3 | * The SPT algorithm |
| 4 | * |
| 5 | * Copyright (C) 2001,2002 Sampo Saaristo |
| 6 | * Tampere University of Technology |
| 7 | * Institute of Communications Engineering |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify it |
| 10 | * under the terms of the GNU General Public Licenseas published by the Free |
| 11 | * Software Foundation; either version 2 of the License, or (at your option) |
| 12 | * any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful,but WITHOUT |
| 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 17 | * more details. |
| 18 | |
| 19 | * You should have received a copy of the GNU General Public License along |
| 20 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 21 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 22 | */ |
| 23 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 24 | #include <zebra.h> |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 25 | |
| 26 | #include "thread.h" |
| 27 | #include "linklist.h" |
| 28 | #include "vty.h" |
| 29 | #include "log.h" |
| 30 | #include "command.h" |
| 31 | #include "memory.h" |
| 32 | #include "prefix.h" |
| 33 | #include "hash.h" |
| 34 | #include "if.h" |
| 35 | #include "table.h" |
| 36 | |
| 37 | #include "isis_constants.h" |
| 38 | #include "isis_common.h" |
| 39 | #include "dict.h" |
| 40 | #include "isisd.h" |
| 41 | #include "isis_misc.h" |
| 42 | #include "isis_adjacency.h" |
| 43 | #include "isis_circuit.h" |
| 44 | #include "isis_tlv.h" |
| 45 | #include "isis_pdu.h" |
| 46 | #include "isis_lsp.h" |
| 47 | #include "isis_dynhn.h" |
| 48 | #include "isis_spf.h" |
| 49 | #include "isis_route.h" |
| 50 | #include "isis_csm.h" |
| 51 | |
| 52 | extern struct isis *isis; |
| 53 | extern struct thread_master *master; |
| 54 | extern struct host host; |
| 55 | |
| 56 | int isis_run_spf_l1 (struct thread *thread); |
| 57 | int isis_run_spf_l2 (struct thread *thread); |
| 58 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 59 | /* 7.2.7 */ |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 60 | static void |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 61 | remove_excess_adjs (struct list *adjs) |
| 62 | { |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 63 | struct listnode *node, *excess = NULL; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 64 | struct isis_adjacency *adj, *candidate = NULL; |
| 65 | int comp; |
| 66 | |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 67 | for (ALL_LIST_ELEMENTS_RO (adjs, node, adj)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 68 | { |
| 69 | if (excess == NULL) |
| 70 | excess = node; |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 71 | candidate = listgetdata (excess); |
| 72 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 73 | if (candidate->sys_type < adj->sys_type) |
| 74 | { |
| 75 | excess = node; |
| 76 | candidate = adj; |
| 77 | continue; |
| 78 | } |
| 79 | if (candidate->sys_type > adj->sys_type) |
| 80 | continue; |
| 81 | |
| 82 | comp = memcmp (candidate->sysid, adj->sysid, ISIS_SYS_ID_LEN); |
| 83 | if (comp > 0) |
| 84 | { |
| 85 | excess = node; |
| 86 | candidate = adj; |
| 87 | continue; |
| 88 | } |
| 89 | if (comp < 0) |
| 90 | continue; |
| 91 | |
| 92 | if (candidate->circuit->circuit_id > adj->circuit->circuit_id) |
| 93 | { |
| 94 | excess = node; |
| 95 | candidate = adj; |
| 96 | continue; |
| 97 | } |
| 98 | |
| 99 | if (candidate->circuit->circuit_id < adj->circuit->circuit_id) |
| 100 | continue; |
| 101 | |
| 102 | comp = memcmp (candidate->snpa, adj->snpa, ETH_ALEN); |
| 103 | if (comp > 0) |
| 104 | { |
| 105 | excess = node; |
| 106 | candidate = adj; |
| 107 | continue; |
| 108 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 109 | } |
| 110 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 111 | list_delete_node (adjs, excess); |
| 112 | |
| 113 | return; |
| 114 | } |
| 115 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 116 | #ifdef EXTREME_DEBUG |
| 117 | static const char * |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 118 | vtype2string (enum vertextype vtype) |
| 119 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 120 | switch (vtype) |
| 121 | { |
| 122 | case VTYPE_PSEUDO_IS: |
| 123 | return "pseudo_IS"; |
| 124 | break; |
hasso | 82a8428 | 2005-09-26 18:15:36 +0000 | [diff] [blame] | 125 | case VTYPE_PSEUDO_TE_IS: |
| 126 | return "pseudo_TE-IS"; |
| 127 | break; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 128 | case VTYPE_NONPSEUDO_IS: |
| 129 | return "IS"; |
| 130 | break; |
hasso | 82a8428 | 2005-09-26 18:15:36 +0000 | [diff] [blame] | 131 | case VTYPE_NONPSEUDO_TE_IS: |
| 132 | return "TE-IS"; |
| 133 | break; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 134 | case VTYPE_ES: |
| 135 | return "ES"; |
| 136 | break; |
| 137 | case VTYPE_IPREACH_INTERNAL: |
| 138 | return "IP internal"; |
| 139 | break; |
| 140 | case VTYPE_IPREACH_EXTERNAL: |
| 141 | return "IP external"; |
| 142 | break; |
hasso | 82a8428 | 2005-09-26 18:15:36 +0000 | [diff] [blame] | 143 | case VTYPE_IPREACH_TE: |
| 144 | return "IP TE"; |
| 145 | break; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 146 | #ifdef HAVE_IPV6 |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 147 | case VTYPE_IP6REACH_INTERNAL: |
| 148 | return "IP6 internal"; |
| 149 | break; |
| 150 | case VTYPE_IP6REACH_EXTERNAL: |
| 151 | return "IP6 external"; |
| 152 | break; |
| 153 | #endif /* HAVE_IPV6 */ |
| 154 | default: |
| 155 | return "UNKNOWN"; |
| 156 | } |
| 157 | return NULL; /* Not reached */ |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 158 | } |
| 159 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 160 | static const char * |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 161 | vid2string (struct isis_vertex *vertex, u_char * buff) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 162 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 163 | switch (vertex->type) |
| 164 | { |
| 165 | case VTYPE_PSEUDO_IS: |
hasso | 82a8428 | 2005-09-26 18:15:36 +0000 | [diff] [blame] | 166 | case VTYPE_PSEUDO_TE_IS: |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 167 | return rawlspid_print (vertex->N.id); |
| 168 | break; |
| 169 | case VTYPE_NONPSEUDO_IS: |
hasso | 82a8428 | 2005-09-26 18:15:36 +0000 | [diff] [blame] | 170 | case VTYPE_NONPSEUDO_TE_IS: |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 171 | case VTYPE_ES: |
| 172 | return sysid_print (vertex->N.id); |
| 173 | break; |
| 174 | case VTYPE_IPREACH_INTERNAL: |
| 175 | case VTYPE_IPREACH_EXTERNAL: |
hasso | 82a8428 | 2005-09-26 18:15:36 +0000 | [diff] [blame] | 176 | case VTYPE_IPREACH_TE: |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 177 | #ifdef HAVE_IPV6 |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 178 | case VTYPE_IP6REACH_INTERNAL: |
| 179 | case VTYPE_IP6REACH_EXTERNAL: |
| 180 | #endif /* HAVE_IPV6 */ |
hasso | f7c43dc | 2004-09-26 16:24:14 +0000 | [diff] [blame] | 181 | prefix2str ((struct prefix *) &vertex->N.prefix, (char *) buff, BUFSIZ); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 182 | break; |
| 183 | default: |
| 184 | return "UNKNOWN"; |
| 185 | } |
| 186 | |
hasso | f7c43dc | 2004-09-26 16:24:14 +0000 | [diff] [blame] | 187 | return (char *) buff; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 188 | } |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 189 | #endif /* EXTREME_DEBUG */ |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 190 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 191 | static struct isis_spftree * |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 192 | isis_spftree_new () |
| 193 | { |
| 194 | struct isis_spftree *tree; |
| 195 | |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 196 | tree = XCALLOC (MTYPE_ISIS_SPFTREE, sizeof (struct isis_spftree)); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 197 | if (tree == NULL) |
| 198 | { |
| 199 | zlog_err ("ISIS-Spf: isis_spftree_new Out of memory!"); |
| 200 | return NULL; |
| 201 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 202 | |
| 203 | tree->tents = list_new (); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 204 | tree->paths = list_new (); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 205 | return tree; |
| 206 | } |
| 207 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 208 | static void |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 209 | isis_vertex_del (struct isis_vertex *vertex) |
| 210 | { |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 211 | list_delete (vertex->Adj_N); |
| 212 | |
| 213 | XFREE (MTYPE_ISIS_VERTEX, vertex); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 214 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 215 | return; |
| 216 | } |
| 217 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 218 | #if 0 /* HT: Not used yet. */ |
| 219 | static void |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 220 | isis_spftree_del (struct isis_spftree *spftree) |
| 221 | { |
hasso | f7c43dc | 2004-09-26 16:24:14 +0000 | [diff] [blame] | 222 | spftree->tents->del = (void (*)(void *)) isis_vertex_del; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 223 | list_delete (spftree->tents); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 224 | |
hasso | f7c43dc | 2004-09-26 16:24:14 +0000 | [diff] [blame] | 225 | spftree->paths->del = (void (*)(void *)) isis_vertex_del; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 226 | list_delete (spftree->paths); |
| 227 | |
| 228 | XFREE (MTYPE_ISIS_SPFTREE, spftree); |
| 229 | |
| 230 | return; |
| 231 | } |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 232 | #endif |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 233 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 234 | void |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 235 | spftree_area_init (struct isis_area *area) |
| 236 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 237 | if ((area->is_type & IS_LEVEL_1) && area->spftree[0] == NULL) |
| 238 | { |
| 239 | area->spftree[0] = isis_spftree_new (); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 240 | #ifdef HAVE_IPV6 |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 241 | area->spftree6[0] = isis_spftree_new (); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 242 | #endif |
| 243 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 244 | /* thread_add_timer (master, isis_run_spf_l1, area, |
| 245 | isis_jitter (PERIODIC_SPF_INTERVAL, 10)); */ |
| 246 | } |
| 247 | |
| 248 | if ((area->is_type & IS_LEVEL_2) && area->spftree[1] == NULL) |
| 249 | { |
| 250 | area->spftree[1] = isis_spftree_new (); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 251 | #ifdef HAVE_IPV6 |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 252 | area->spftree6[1] = isis_spftree_new (); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 253 | #endif |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 254 | /* thread_add_timer (master, isis_run_spf_l2, area, |
| 255 | isis_jitter (PERIODIC_SPF_INTERVAL, 10)); */ |
| 256 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 257 | |
| 258 | return; |
| 259 | } |
| 260 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 261 | static struct isis_vertex * |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 262 | isis_vertex_new (void *id, enum vertextype vtype) |
| 263 | { |
| 264 | struct isis_vertex *vertex; |
| 265 | |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 266 | vertex = XCALLOC (MTYPE_ISIS_VERTEX, sizeof (struct isis_vertex)); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 267 | if (vertex == NULL) |
| 268 | { |
| 269 | zlog_err ("isis_vertex_new Out of memory!"); |
| 270 | return NULL; |
| 271 | } |
| 272 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 273 | vertex->type = vtype; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 274 | switch (vtype) |
| 275 | { |
| 276 | case VTYPE_ES: |
| 277 | case VTYPE_NONPSEUDO_IS: |
hasso | 82a8428 | 2005-09-26 18:15:36 +0000 | [diff] [blame] | 278 | case VTYPE_NONPSEUDO_TE_IS: |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 279 | memcpy (vertex->N.id, (u_char *) id, ISIS_SYS_ID_LEN); |
| 280 | break; |
| 281 | case VTYPE_PSEUDO_IS: |
hasso | 82a8428 | 2005-09-26 18:15:36 +0000 | [diff] [blame] | 282 | case VTYPE_PSEUDO_TE_IS: |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 283 | memcpy (vertex->N.id, (u_char *) id, ISIS_SYS_ID_LEN + 1); |
| 284 | break; |
| 285 | case VTYPE_IPREACH_INTERNAL: |
| 286 | case VTYPE_IPREACH_EXTERNAL: |
hasso | 82a8428 | 2005-09-26 18:15:36 +0000 | [diff] [blame] | 287 | case VTYPE_IPREACH_TE: |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 288 | #ifdef HAVE_IPV6 |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 289 | case VTYPE_IP6REACH_INTERNAL: |
| 290 | case VTYPE_IP6REACH_EXTERNAL: |
| 291 | #endif /* HAVE_IPV6 */ |
| 292 | memcpy (&vertex->N.prefix, (struct prefix *) id, |
| 293 | sizeof (struct prefix)); |
| 294 | break; |
| 295 | default: |
| 296 | zlog_err ("WTF!"); |
| 297 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 298 | |
| 299 | vertex->Adj_N = list_new (); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 300 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 301 | return vertex; |
| 302 | } |
| 303 | |
| 304 | /* |
| 305 | * Add this IS to the root of SPT |
| 306 | */ |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 307 | static void |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 308 | isis_spf_add_self (struct isis_spftree *spftree, struct isis_area *area, |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 309 | int level) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 310 | { |
| 311 | struct isis_vertex *vertex; |
| 312 | struct isis_lsp *lsp; |
| 313 | u_char lspid[ISIS_SYS_ID_LEN + 2]; |
| 314 | #ifdef EXTREME_DEBUG |
| 315 | u_char buff[BUFSIZ]; |
| 316 | #endif /* EXTREME_DEBUG */ |
| 317 | memcpy (lspid, isis->sysid, ISIS_SYS_ID_LEN); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 318 | LSP_PSEUDO_ID (lspid) = 0; |
| 319 | LSP_FRAGMENT (lspid) = 0; |
| 320 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 321 | lsp = lsp_search (lspid, area->lspdb[level - 1]); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 322 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 323 | if (lsp == NULL) |
| 324 | zlog_warn ("ISIS-Spf: could not find own l%d LSP!", level); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 325 | |
hasso | 82a8428 | 2005-09-26 18:15:36 +0000 | [diff] [blame] | 326 | if (!area->oldmetric) |
| 327 | vertex = isis_vertex_new (isis->sysid, VTYPE_NONPSEUDO_TE_IS); |
| 328 | else |
| 329 | vertex = isis_vertex_new (isis->sysid, VTYPE_NONPSEUDO_IS); |
| 330 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 331 | vertex->lsp = lsp; |
| 332 | |
| 333 | listnode_add (spftree->paths, vertex); |
| 334 | |
| 335 | #ifdef EXTREME_DEBUG |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 336 | zlog_debug ("ISIS-Spf: added this IS %s %s depth %d dist %d to PATHS", |
| 337 | vtype2string (vertex->type), vid2string (vertex, buff), |
| 338 | vertex->depth, vertex->d_N); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 339 | #endif /* EXTREME_DEBUG */ |
| 340 | |
| 341 | return; |
| 342 | } |
| 343 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 344 | static struct isis_vertex * |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 345 | isis_find_vertex (struct list *list, void *id, enum vertextype vtype) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 346 | { |
| 347 | struct listnode *node; |
| 348 | struct isis_vertex *vertex; |
| 349 | struct prefix *p1, *p2; |
| 350 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 351 | for (ALL_LIST_ELEMENTS_RO (list, node, vertex)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 352 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 353 | if (vertex->type != vtype) |
| 354 | continue; |
| 355 | switch (vtype) |
| 356 | { |
| 357 | case VTYPE_ES: |
| 358 | case VTYPE_NONPSEUDO_IS: |
hasso | 82a8428 | 2005-09-26 18:15:36 +0000 | [diff] [blame] | 359 | case VTYPE_NONPSEUDO_TE_IS: |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 360 | if (memcmp ((u_char *) id, vertex->N.id, ISIS_SYS_ID_LEN) == 0) |
| 361 | return vertex; |
| 362 | break; |
| 363 | case VTYPE_PSEUDO_IS: |
hasso | 82a8428 | 2005-09-26 18:15:36 +0000 | [diff] [blame] | 364 | case VTYPE_PSEUDO_TE_IS: |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 365 | if (memcmp ((u_char *) id, vertex->N.id, ISIS_SYS_ID_LEN + 1) == 0) |
| 366 | return vertex; |
| 367 | break; |
| 368 | case VTYPE_IPREACH_INTERNAL: |
| 369 | case VTYPE_IPREACH_EXTERNAL: |
hasso | 82a8428 | 2005-09-26 18:15:36 +0000 | [diff] [blame] | 370 | case VTYPE_IPREACH_TE: |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 371 | #ifdef HAVE_IPV6 |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 372 | case VTYPE_IP6REACH_INTERNAL: |
| 373 | case VTYPE_IP6REACH_EXTERNAL: |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 374 | #endif /* HAVE_IPV6 */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 375 | p1 = (struct prefix *) id; |
| 376 | p2 = (struct prefix *) &vertex->N.id; |
| 377 | if (p1->family == p2->family && p1->prefixlen == p2->prefixlen && |
| 378 | memcmp (&p1->u.prefix, &p2->u.prefix, |
| 379 | PSIZE (p1->prefixlen)) == 0) |
| 380 | return vertex; |
| 381 | break; |
| 382 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 383 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 384 | |
| 385 | return NULL; |
| 386 | } |
| 387 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 388 | /* |
| 389 | * Add a vertex to TENT sorted by cost and by vertextype on tie break situation |
| 390 | */ |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 391 | static struct isis_vertex * |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 392 | isis_spf_add2tent (struct isis_spftree *spftree, enum vertextype vtype, |
hasso | fac1f7c | 2005-09-26 18:26:26 +0000 | [diff] [blame] | 393 | void *id, struct isis_adjacency *adj, u_int32_t cost, |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 394 | int depth, int family) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 395 | { |
| 396 | struct isis_vertex *vertex, *v; |
| 397 | struct listnode *node; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 398 | #ifdef EXTREME_DEBUG |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 399 | u_char buff[BUFSIZ]; |
| 400 | #endif |
| 401 | |
| 402 | vertex = isis_vertex_new (id, vtype); |
| 403 | vertex->d_N = cost; |
| 404 | vertex->depth = depth; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 405 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 406 | if (adj) |
| 407 | listnode_add (vertex->Adj_N, adj); |
Peter Szilagyi | d034aa0 | 2011-10-01 17:22:51 +0400 | [diff] [blame] | 408 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 409 | #ifdef EXTREME_DEBUG |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 410 | zlog_debug ("ISIS-Spf: add to TENT %s %s depth %d dist %d", |
| 411 | vtype2string (vertex->type), vid2string (vertex, buff), |
| 412 | vertex->depth, vertex->d_N); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 413 | #endif /* EXTREME_DEBUG */ |
Peter Szilagyi | d034aa0 | 2011-10-01 17:22:51 +0400 | [diff] [blame] | 414 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 415 | if (list_isempty (spftree->tents)) |
| 416 | { |
| 417 | listnode_add (spftree->tents, vertex); |
| 418 | return vertex; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 419 | } |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 420 | |
| 421 | /* XXX: This cant use the standard ALL_LIST_ELEMENT macro */ |
| 422 | for (node = listhead (spftree->tents); node; node = listnextnode (node)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 423 | { |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 424 | v = listgetdata (node); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 425 | if (v->d_N > vertex->d_N) |
| 426 | { |
| 427 | list_add_node_prev (spftree->tents, node, vertex); |
| 428 | break; |
| 429 | } |
| 430 | else if (v->d_N == vertex->d_N) |
| 431 | { |
| 432 | /* Tie break, add according to type */ |
| 433 | while (v && v->d_N == vertex->d_N && v->type > vertex->type) |
| 434 | { |
| 435 | if (v->type > vertex->type) |
| 436 | { |
| 437 | break; |
| 438 | } |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 439 | /* XXX: this seems dubious, node is the loop iterator */ |
| 440 | node = listnextnode (node); |
| 441 | (node) ? (v = listgetdata (node)) : (v = NULL); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 442 | } |
| 443 | list_add_node_prev (spftree->tents, node, vertex); |
| 444 | break; |
| 445 | } |
| 446 | else if (node->next == NULL) |
| 447 | { |
| 448 | list_add_node_next (spftree->tents, node, vertex); |
| 449 | break; |
| 450 | } |
| 451 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 452 | return vertex; |
| 453 | } |
| 454 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 455 | static struct isis_vertex * |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 456 | isis_spf_add_local (struct isis_spftree *spftree, enum vertextype vtype, |
hasso | fac1f7c | 2005-09-26 18:26:26 +0000 | [diff] [blame] | 457 | void *id, struct isis_adjacency *adj, u_int32_t cost, |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 458 | int family) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 459 | { |
| 460 | struct isis_vertex *vertex; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 461 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 462 | vertex = isis_find_vertex (spftree->tents, id, vtype); |
| 463 | |
| 464 | if (vertex) |
| 465 | { |
| 466 | /* C.2.5 c) */ |
| 467 | if (vertex->d_N == cost) |
| 468 | { |
| 469 | if (adj) |
| 470 | listnode_add (vertex->Adj_N, adj); |
| 471 | /* d) */ |
| 472 | if (listcount (vertex->Adj_N) > ISIS_MAX_PATH_SPLITS) |
| 473 | remove_excess_adjs (vertex->Adj_N); |
| 474 | } |
| 475 | /* f) */ |
| 476 | else if (vertex->d_N > cost) |
| 477 | { |
| 478 | listnode_delete (spftree->tents, vertex); |
| 479 | goto add2tent; |
| 480 | } |
| 481 | /* e) do nothing */ |
| 482 | return vertex; |
| 483 | } |
| 484 | |
| 485 | add2tent: |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 486 | return isis_spf_add2tent (spftree, vtype, id, adj, cost, 1, family); |
| 487 | } |
| 488 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 489 | static void |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 490 | process_N (struct isis_spftree *spftree, enum vertextype vtype, void *id, |
| 491 | u_int16_t dist, u_int16_t depth, struct isis_adjacency *adj, |
| 492 | int family) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 493 | { |
| 494 | struct isis_vertex *vertex; |
| 495 | #ifdef EXTREME_DEBUG |
| 496 | u_char buff[255]; |
| 497 | #endif |
| 498 | |
| 499 | /* C.2.6 b) */ |
| 500 | if (dist > MAX_PATH_METRIC) |
| 501 | return; |
| 502 | /* c) */ |
| 503 | vertex = isis_find_vertex (spftree->paths, id, vtype); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 504 | if (vertex) |
| 505 | { |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 506 | #ifdef EXTREME_DEBUG |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 507 | zlog_debug ("ISIS-Spf: process_N %s %s dist %d already found from PATH", |
| 508 | vtype2string (vtype), vid2string (vertex, buff), dist); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 509 | #endif /* EXTREME_DEBUG */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 510 | assert (dist >= vertex->d_N); |
| 511 | return; |
| 512 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 513 | |
| 514 | vertex = isis_find_vertex (spftree->tents, id, vtype); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 515 | /* d) */ |
| 516 | if (vertex) |
| 517 | { |
| 518 | /* 1) */ |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 519 | #ifdef EXTREME_DEBUG |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 520 | zlog_debug ("ISIS-Spf: process_N %s %s dist %d", |
| 521 | vtype2string (vtype), vid2string (vertex, buff), dist); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 522 | #endif /* EXTREME_DEBUG */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 523 | if (vertex->d_N == dist) |
| 524 | { |
| 525 | if (adj) |
| 526 | listnode_add (vertex->Adj_N, adj); |
| 527 | /* 2) */ |
| 528 | if (listcount (vertex->Adj_N) > ISIS_MAX_PATH_SPLITS) |
| 529 | remove_excess_adjs (vertex->Adj_N); |
| 530 | /* 3) */ |
| 531 | return; |
| 532 | } |
| 533 | else if (vertex->d_N < dist) |
| 534 | { |
| 535 | return; |
| 536 | /* 4) */ |
| 537 | } |
| 538 | else |
| 539 | { |
| 540 | listnode_delete (spftree->tents, vertex); |
| 541 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 542 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 543 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 544 | isis_spf_add2tent (spftree, vtype, id, adj, dist, depth, family); |
| 545 | return; |
| 546 | } |
| 547 | |
| 548 | /* |
| 549 | * C.2.6 Step 1 |
| 550 | */ |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 551 | static int |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 552 | isis_spf_process_lsp (struct isis_spftree *spftree, struct isis_lsp *lsp, |
Peter Szilagyi | d034aa0 | 2011-10-01 17:22:51 +0400 | [diff] [blame] | 553 | uint32_t cost, uint16_t depth, int family, |
| 554 | struct isis_adjacency *adj) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 555 | { |
| 556 | struct listnode *node, *fragnode = NULL; |
| 557 | u_int16_t dist; |
| 558 | struct is_neigh *is_neigh; |
hasso | 82a8428 | 2005-09-26 18:15:36 +0000 | [diff] [blame] | 559 | struct te_is_neigh *te_is_neigh; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 560 | struct ipv4_reachability *ipreach; |
hasso | 82a8428 | 2005-09-26 18:15:36 +0000 | [diff] [blame] | 561 | struct te_ipv4_reachability *te_ipv4_reach; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 562 | enum vertextype vtype; |
| 563 | struct prefix prefix; |
| 564 | #ifdef HAVE_IPV6 |
| 565 | struct ipv6_reachability *ip6reach; |
| 566 | #endif /* HAVE_IPV6 */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 567 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 568 | if (lsp->tlv_data.nlpids == NULL || !speaks (lsp->tlv_data.nlpids, family)) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 569 | return ISIS_OK; |
| 570 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 571 | lspfragloop: |
| 572 | if (lsp->lsp_header->seq_num == 0) |
| 573 | { |
| 574 | zlog_warn ("isis_spf_process_lsp(): lsp with 0 seq_num" |
| 575 | " - do not process"); |
| 576 | return ISIS_WARNING; |
| 577 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 578 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 579 | if (!ISIS_MASK_LSP_OL_BIT (lsp->lsp_header->lsp_bits)) |
| 580 | { |
| 581 | if (lsp->tlv_data.is_neighs) |
| 582 | { |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 583 | for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.is_neighs, node, is_neigh)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 584 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 585 | /* C.2.6 a) */ |
| 586 | /* Two way connectivity */ |
| 587 | if (!memcmp (is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN)) |
| 588 | continue; |
| 589 | dist = cost + is_neigh->metrics.metric_default; |
| 590 | vtype = LSP_PSEUDO_ID (is_neigh->neigh_id) ? VTYPE_PSEUDO_IS |
| 591 | : VTYPE_NONPSEUDO_IS; |
| 592 | process_N (spftree, vtype, (void *) is_neigh->neigh_id, dist, |
Peter Szilagyi | d034aa0 | 2011-10-01 17:22:51 +0400 | [diff] [blame] | 593 | depth + 1, adj, family); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 594 | } |
| 595 | } |
hasso | 82a8428 | 2005-09-26 18:15:36 +0000 | [diff] [blame] | 596 | if (lsp->tlv_data.te_is_neighs) |
| 597 | { |
| 598 | for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.te_is_neighs, node, |
| 599 | te_is_neigh)) |
| 600 | { |
| 601 | uint32_t metric; |
| 602 | if (!memcmp (te_is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN)) |
| 603 | continue; |
| 604 | memcpy (&metric, te_is_neigh->te_metric, 3); |
| 605 | dist = cost + ntohl (metric << 8); |
| 606 | vtype = LSP_PSEUDO_ID (te_is_neigh->neigh_id) ? VTYPE_PSEUDO_TE_IS |
| 607 | : VTYPE_NONPSEUDO_TE_IS; |
| 608 | process_N (spftree, vtype, (void *) te_is_neigh->neigh_id, dist, |
Peter Szilagyi | d034aa0 | 2011-10-01 17:22:51 +0400 | [diff] [blame] | 609 | depth + 1, adj, family); |
hasso | 82a8428 | 2005-09-26 18:15:36 +0000 | [diff] [blame] | 610 | } |
| 611 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 612 | if (family == AF_INET && lsp->tlv_data.ipv4_int_reachs) |
| 613 | { |
| 614 | prefix.family = AF_INET; |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 615 | for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.ipv4_int_reachs, |
| 616 | node, ipreach)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 617 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 618 | dist = cost + ipreach->metrics.metric_default; |
| 619 | vtype = VTYPE_IPREACH_INTERNAL; |
| 620 | prefix.u.prefix4 = ipreach->prefix; |
| 621 | prefix.prefixlen = ip_masklen (ipreach->mask); |
| 622 | process_N (spftree, vtype, (void *) &prefix, dist, depth + 1, |
Peter Szilagyi | d034aa0 | 2011-10-01 17:22:51 +0400 | [diff] [blame] | 623 | adj, family); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 624 | } |
| 625 | } |
| 626 | |
| 627 | if (family == AF_INET && lsp->tlv_data.ipv4_ext_reachs) |
| 628 | { |
| 629 | prefix.family = AF_INET; |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 630 | for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.ipv4_ext_reachs, |
| 631 | node, ipreach)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 632 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 633 | dist = cost + ipreach->metrics.metric_default; |
| 634 | vtype = VTYPE_IPREACH_EXTERNAL; |
| 635 | prefix.u.prefix4 = ipreach->prefix; |
| 636 | prefix.prefixlen = ip_masklen (ipreach->mask); |
| 637 | process_N (spftree, vtype, (void *) &prefix, dist, depth + 1, |
Peter Szilagyi | d034aa0 | 2011-10-01 17:22:51 +0400 | [diff] [blame] | 638 | adj, family); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 639 | } |
| 640 | } |
hasso | 82a8428 | 2005-09-26 18:15:36 +0000 | [diff] [blame] | 641 | if (family == AF_INET && lsp->tlv_data.te_ipv4_reachs) |
| 642 | { |
| 643 | prefix.family = AF_INET; |
| 644 | for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.te_ipv4_reachs, |
| 645 | node, te_ipv4_reach)) |
| 646 | { |
| 647 | dist = cost + ntohl (te_ipv4_reach->te_metric); |
| 648 | vtype = VTYPE_IPREACH_TE; |
| 649 | prefix.u.prefix4 = newprefix2inaddr (&te_ipv4_reach->prefix_start, |
| 650 | te_ipv4_reach->control); |
| 651 | prefix.prefixlen = (te_ipv4_reach->control & 0x3F); |
| 652 | process_N (spftree, vtype, (void *) &prefix, dist, depth + 1, |
Peter Szilagyi | d034aa0 | 2011-10-01 17:22:51 +0400 | [diff] [blame] | 653 | adj, family); |
hasso | 82a8428 | 2005-09-26 18:15:36 +0000 | [diff] [blame] | 654 | } |
| 655 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 656 | #ifdef HAVE_IPV6 |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 657 | if (family == AF_INET6 && lsp->tlv_data.ipv6_reachs) |
| 658 | { |
| 659 | prefix.family = AF_INET6; |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 660 | for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.ipv6_reachs, |
| 661 | node, ip6reach)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 662 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 663 | dist = cost + ip6reach->metric; |
| 664 | vtype = (ip6reach->control_info & CTRL_INFO_DISTRIBUTION) ? |
| 665 | VTYPE_IP6REACH_EXTERNAL : VTYPE_IP6REACH_INTERNAL; |
| 666 | prefix.prefixlen = ip6reach->prefix_len; |
| 667 | memcpy (&prefix.u.prefix6.s6_addr, ip6reach->prefix, |
| 668 | PSIZE (ip6reach->prefix_len)); |
| 669 | process_N (spftree, vtype, (void *) &prefix, dist, depth + 1, |
Peter Szilagyi | d034aa0 | 2011-10-01 17:22:51 +0400 | [diff] [blame] | 670 | adj, family); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 671 | } |
| 672 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 673 | #endif /* HAVE_IPV6 */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 674 | } |
| 675 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 676 | if (fragnode == NULL) |
| 677 | fragnode = listhead (lsp->lspu.frags); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 678 | else |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 679 | fragnode = listnextnode (fragnode); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 680 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 681 | if (fragnode) |
| 682 | { |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 683 | lsp = listgetdata (fragnode); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 684 | goto lspfragloop; |
| 685 | } |
| 686 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 687 | return ISIS_OK; |
| 688 | } |
| 689 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 690 | static int |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 691 | isis_spf_process_pseudo_lsp (struct isis_spftree *spftree, |
| 692 | struct isis_lsp *lsp, uint16_t cost, |
Peter Szilagyi | d034aa0 | 2011-10-01 17:22:51 +0400 | [diff] [blame] | 693 | uint16_t depth, int family, |
| 694 | struct isis_adjacency *adj) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 695 | { |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 696 | struct listnode *node, *fragnode = NULL; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 697 | struct is_neigh *is_neigh; |
hasso | 82a8428 | 2005-09-26 18:15:36 +0000 | [diff] [blame] | 698 | struct te_is_neigh *te_is_neigh; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 699 | enum vertextype vtype; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 700 | |
| 701 | pseudofragloop: |
| 702 | |
| 703 | if (lsp->lsp_header->seq_num == 0) |
| 704 | { |
| 705 | zlog_warn ("isis_spf_process_pseudo_lsp(): lsp with 0 seq_num" |
| 706 | " - do not process"); |
| 707 | return ISIS_WARNING; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 708 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 709 | |
hasso | 82a8428 | 2005-09-26 18:15:36 +0000 | [diff] [blame] | 710 | if (lsp->tlv_data.is_neighs) |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 711 | for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.is_neighs, node, is_neigh)) |
hasso | 82a8428 | 2005-09-26 18:15:36 +0000 | [diff] [blame] | 712 | { |
| 713 | vtype = LSP_PSEUDO_ID (is_neigh->neigh_id) ? VTYPE_PSEUDO_IS |
| 714 | : VTYPE_NONPSEUDO_IS; |
| 715 | /* Two way connectivity */ |
| 716 | if (!memcmp (is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN)) |
| 717 | continue; |
Peter Szilagyi | d034aa0 | 2011-10-01 17:22:51 +0400 | [diff] [blame] | 718 | if ((depth > 0 || isis_find_vertex |
| 719 | (spftree->tents, (void *) is_neigh->neigh_id, vtype) == NULL) |
hasso | 82a8428 | 2005-09-26 18:15:36 +0000 | [diff] [blame] | 720 | && isis_find_vertex (spftree->paths, (void *) is_neigh->neigh_id, |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 721 | vtype) == NULL) |
hasso | 82a8428 | 2005-09-26 18:15:36 +0000 | [diff] [blame] | 722 | { |
| 723 | /* C.2.5 i) */ |
Peter Szilagyi | d034aa0 | 2011-10-01 17:22:51 +0400 | [diff] [blame] | 724 | isis_spf_add2tent (spftree, vtype, is_neigh->neigh_id, adj, |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 725 | cost, depth, family); |
hasso | 82a8428 | 2005-09-26 18:15:36 +0000 | [diff] [blame] | 726 | } |
| 727 | } |
| 728 | if (lsp->tlv_data.te_is_neighs) |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 729 | for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.te_is_neighs, node, te_is_neigh)) |
hasso | 82a8428 | 2005-09-26 18:15:36 +0000 | [diff] [blame] | 730 | { |
| 731 | vtype = LSP_PSEUDO_ID (te_is_neigh->neigh_id) ? VTYPE_PSEUDO_TE_IS |
| 732 | : VTYPE_NONPSEUDO_TE_IS; |
| 733 | /* Two way connectivity */ |
| 734 | if (!memcmp (te_is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN)) |
| 735 | continue; |
Peter Szilagyi | d034aa0 | 2011-10-01 17:22:51 +0400 | [diff] [blame] | 736 | if ((depth > 0 || isis_find_vertex |
| 737 | (spftree->tents, (void *) te_is_neigh->neigh_id, vtype) == NULL) |
hasso | 82a8428 | 2005-09-26 18:15:36 +0000 | [diff] [blame] | 738 | && isis_find_vertex (spftree->paths, (void *) te_is_neigh->neigh_id, |
| 739 | vtype) == NULL) |
| 740 | { |
| 741 | /* C.2.5 i) */ |
Peter Szilagyi | d034aa0 | 2011-10-01 17:22:51 +0400 | [diff] [blame] | 742 | isis_spf_add2tent (spftree, vtype, te_is_neigh->neigh_id, adj, |
hasso | 82a8428 | 2005-09-26 18:15:36 +0000 | [diff] [blame] | 743 | cost, depth, family); |
| 744 | } |
| 745 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 746 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 747 | if (fragnode == NULL) |
| 748 | fragnode = listhead (lsp->lspu.frags); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 749 | else |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 750 | fragnode = listnextnode (fragnode); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 751 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 752 | if (fragnode) |
| 753 | { |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 754 | lsp = listgetdata (fragnode); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 755 | goto pseudofragloop; |
| 756 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 757 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 758 | return ISIS_OK; |
| 759 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 760 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 761 | static int |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 762 | isis_spf_preload_tent (struct isis_spftree *spftree, |
| 763 | struct isis_area *area, int level, int family) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 764 | { |
| 765 | struct isis_vertex *vertex; |
| 766 | struct isis_circuit *circuit; |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 767 | struct listnode *cnode, *anode, *ipnode; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 768 | struct isis_adjacency *adj; |
| 769 | struct isis_lsp *lsp; |
| 770 | struct list *adj_list; |
| 771 | struct list *adjdb; |
| 772 | struct prefix_ipv4 *ipv4; |
| 773 | struct prefix prefix; |
| 774 | int retval = ISIS_OK; |
| 775 | u_char lsp_id[ISIS_SYS_ID_LEN + 2]; |
| 776 | #ifdef HAVE_IPV6 |
| 777 | struct prefix_ipv6 *ipv6; |
| 778 | #endif /* HAVE_IPV6 */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 779 | |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 780 | for (ALL_LIST_ELEMENTS_RO (area->circuit_list, cnode, circuit)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 781 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 782 | if (circuit->state != C_STATE_UP) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 783 | continue; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 784 | if (!(circuit->circuit_is_type & level)) |
| 785 | continue; |
| 786 | if (family == AF_INET && !circuit->ip_router) |
| 787 | continue; |
| 788 | #ifdef HAVE_IPV6 |
| 789 | if (family == AF_INET6 && !circuit->ipv6_router) |
| 790 | continue; |
| 791 | #endif /* HAVE_IPV6 */ |
| 792 | /* |
| 793 | * Add IP(v6) addresses of this circuit |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 794 | */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 795 | if (family == AF_INET) |
| 796 | { |
| 797 | prefix.family = AF_INET; |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 798 | for (ALL_LIST_ELEMENTS_RO (circuit->ip_addrs, ipnode, ipv4)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 799 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 800 | prefix.u.prefix4 = ipv4->prefix; |
| 801 | prefix.prefixlen = ipv4->prefixlen; |
| 802 | isis_spf_add_local (spftree, VTYPE_IPREACH_INTERNAL, &prefix, |
| 803 | NULL, 0, family); |
| 804 | } |
| 805 | } |
| 806 | #ifdef HAVE_IPV6 |
| 807 | if (family == AF_INET6) |
| 808 | { |
| 809 | prefix.family = AF_INET6; |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 810 | for (ALL_LIST_ELEMENTS_RO (circuit->ipv6_non_link, ipnode, ipv6)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 811 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 812 | prefix.prefixlen = ipv6->prefixlen; |
| 813 | prefix.u.prefix6 = ipv6->prefix; |
| 814 | isis_spf_add_local (spftree, VTYPE_IP6REACH_INTERNAL, |
| 815 | &prefix, NULL, 0, family); |
| 816 | } |
| 817 | } |
| 818 | #endif /* HAVE_IPV6 */ |
| 819 | if (circuit->circ_type == CIRCUIT_T_BROADCAST) |
| 820 | { |
| 821 | /* |
| 822 | * Add the adjacencies |
| 823 | */ |
| 824 | adj_list = list_new (); |
| 825 | adjdb = circuit->u.bc.adjdb[level - 1]; |
| 826 | isis_adj_build_up_list (adjdb, adj_list); |
| 827 | if (listcount (adj_list) == 0) |
| 828 | { |
| 829 | list_delete (adj_list); |
hasso | c89c05d | 2005-09-04 21:36:36 +0000 | [diff] [blame] | 830 | if (isis->debugs & DEBUG_SPF_EVENTS) |
| 831 | zlog_debug ("ISIS-Spf: no L%d adjacencies on circuit %s", |
| 832 | level, circuit->interface->name); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 833 | continue; |
| 834 | } |
| 835 | anode = listhead (adj_list); |
| 836 | while (anode) |
| 837 | { |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 838 | adj = listgetdata (anode); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 839 | if (!speaks (&adj->nlpids, family)) |
| 840 | { |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 841 | anode = listnextnode (anode); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 842 | continue; |
| 843 | } |
| 844 | switch (adj->sys_type) |
| 845 | { |
| 846 | case ISIS_SYSTYPE_ES: |
| 847 | isis_spf_add_local (spftree, VTYPE_ES, adj->sysid, adj, |
hasso | 82a8428 | 2005-09-26 18:15:36 +0000 | [diff] [blame] | 848 | circuit->te_metric[level - 1], family); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 849 | break; |
| 850 | case ISIS_SYSTYPE_IS: |
| 851 | case ISIS_SYSTYPE_L1_IS: |
| 852 | case ISIS_SYSTYPE_L2_IS: |
| 853 | vertex = |
| 854 | isis_spf_add_local (spftree, VTYPE_NONPSEUDO_IS, |
| 855 | adj->sysid, adj, |
hasso | 82a8428 | 2005-09-26 18:15:36 +0000 | [diff] [blame] | 856 | circuit->te_metric[level - 1], family); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 857 | memcpy (lsp_id, adj->sysid, ISIS_SYS_ID_LEN); |
| 858 | LSP_PSEUDO_ID (lsp_id) = 0; |
| 859 | LSP_FRAGMENT (lsp_id) = 0; |
| 860 | lsp = lsp_search (lsp_id, area->lspdb[level - 1]); |
| 861 | if (!lsp) |
| 862 | zlog_warn ("No lsp found for IS adjacency"); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 863 | break; |
| 864 | case ISIS_SYSTYPE_UNKNOWN: |
| 865 | default: |
| 866 | zlog_warn ("isis_spf_preload_tent unknow adj type"); |
| 867 | } |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 868 | anode = listnextnode (anode); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 869 | } |
| 870 | list_delete (adj_list); |
| 871 | /* |
| 872 | * Add the pseudonode |
| 873 | */ |
| 874 | if (level == 1) |
| 875 | memcpy (lsp_id, circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1); |
| 876 | else |
| 877 | memcpy (lsp_id, circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1); |
| 878 | lsp = lsp_search (lsp_id, area->lspdb[level - 1]); |
| 879 | adj = isis_adj_lookup (lsp_id, adjdb); |
| 880 | /* if no adj, we are the dis or error */ |
| 881 | if (!adj && !circuit->u.bc.is_dr[level - 1]) |
| 882 | { |
| 883 | zlog_warn ("ISIS-Spf: No adjacency found for DR"); |
| 884 | } |
Peter Szilagyi | d034aa0 | 2011-10-01 17:22:51 +0400 | [diff] [blame] | 885 | else if (lsp == NULL || lsp->lsp_header->rem_lifetime == 0) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 886 | { |
| 887 | zlog_warn ("ISIS-Spf: No lsp found for DR"); |
| 888 | } |
| 889 | else |
| 890 | { |
hasso | 82a8428 | 2005-09-26 18:15:36 +0000 | [diff] [blame] | 891 | isis_spf_process_pseudo_lsp (spftree, lsp, |
Peter Szilagyi | d034aa0 | 2011-10-01 17:22:51 +0400 | [diff] [blame] | 892 | circuit->te_metric[level - 1], 0, family, adj); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 893 | |
| 894 | } |
| 895 | } |
| 896 | else if (circuit->circ_type == CIRCUIT_T_P2P) |
| 897 | { |
| 898 | adj = circuit->u.p2p.neighbor; |
| 899 | if (!adj) |
| 900 | continue; |
| 901 | switch (adj->sys_type) |
| 902 | { |
| 903 | case ISIS_SYSTYPE_ES: |
| 904 | isis_spf_add_local (spftree, VTYPE_ES, adj->sysid, adj, |
hasso | 82a8428 | 2005-09-26 18:15:36 +0000 | [diff] [blame] | 905 | circuit->te_metric[level - 1], family); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 906 | break; |
| 907 | case ISIS_SYSTYPE_IS: |
| 908 | case ISIS_SYSTYPE_L1_IS: |
| 909 | case ISIS_SYSTYPE_L2_IS: |
| 910 | if (speaks (&adj->nlpids, family)) |
| 911 | isis_spf_add_local (spftree, VTYPE_NONPSEUDO_IS, adj->sysid, |
hasso | 82a8428 | 2005-09-26 18:15:36 +0000 | [diff] [blame] | 912 | adj, circuit->te_metric[level - 1], |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 913 | family); |
| 914 | break; |
| 915 | case ISIS_SYSTYPE_UNKNOWN: |
| 916 | default: |
| 917 | zlog_warn ("isis_spf_preload_tent unknow adj type"); |
| 918 | break; |
| 919 | } |
| 920 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 921 | else |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 922 | { |
| 923 | zlog_warn ("isis_spf_preload_tent unsupported media"); |
| 924 | retval = ISIS_WARNING; |
| 925 | } |
| 926 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 927 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 928 | |
| 929 | return retval; |
| 930 | } |
| 931 | |
| 932 | /* |
| 933 | * The parent(s) for vertex is set when added to TENT list |
| 934 | * now we just put the child pointer(s) in place |
| 935 | */ |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 936 | static void |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 937 | add_to_paths (struct isis_spftree *spftree, struct isis_vertex *vertex, |
hasso | fac1f7c | 2005-09-26 18:26:26 +0000 | [diff] [blame] | 938 | struct isis_area *area, int level) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 939 | { |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 940 | #ifdef EXTREME_DEBUG |
| 941 | u_char buff[BUFSIZ]; |
| 942 | #endif /* EXTREME_DEBUG */ |
| 943 | listnode_add (spftree->paths, vertex); |
| 944 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 945 | #ifdef EXTREME_DEBUG |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 946 | zlog_debug ("ISIS-Spf: added %s %s depth %d dist %d to PATHS", |
| 947 | vtype2string (vertex->type), vid2string (vertex, buff), |
| 948 | vertex->depth, vertex->d_N); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 949 | #endif /* EXTREME_DEBUG */ |
| 950 | if (vertex->type > VTYPE_ES) |
| 951 | { |
| 952 | if (listcount (vertex->Adj_N) > 0) |
hasso | fac1f7c | 2005-09-26 18:26:26 +0000 | [diff] [blame] | 953 | isis_route_create ((struct prefix *) &vertex->N.prefix, vertex->d_N, |
| 954 | vertex->depth, vertex->Adj_N, area, level); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 955 | else if (isis->debugs & DEBUG_SPF_EVENTS) |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 956 | zlog_debug ("ISIS-Spf: no adjacencies do not install route"); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 957 | } |
| 958 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 959 | return; |
| 960 | } |
| 961 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 962 | static void |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 963 | init_spt (struct isis_spftree *spftree) |
| 964 | { |
hasso | f7c43dc | 2004-09-26 16:24:14 +0000 | [diff] [blame] | 965 | spftree->tents->del = spftree->paths->del = (void (*)(void *)) isis_vertex_del; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 966 | list_delete_all_node (spftree->tents); |
| 967 | list_delete_all_node (spftree->paths); |
| 968 | spftree->tents->del = spftree->paths->del = NULL; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 969 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 970 | return; |
| 971 | } |
| 972 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 973 | static int |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 974 | isis_run_spf (struct isis_area *area, int level, int family) |
| 975 | { |
| 976 | int retval = ISIS_OK; |
| 977 | struct listnode *node; |
| 978 | struct isis_vertex *vertex; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 979 | struct isis_spftree *spftree = NULL; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 980 | u_char lsp_id[ISIS_SYS_ID_LEN + 2]; |
| 981 | struct isis_lsp *lsp; |
Peter Szilagyi | d034aa0 | 2011-10-01 17:22:51 +0400 | [diff] [blame] | 982 | struct isis_adjacency *adj = NULL; |
hasso | fac1f7c | 2005-09-26 18:26:26 +0000 | [diff] [blame] | 983 | struct route_table *table = NULL; |
| 984 | struct route_node *rode; |
| 985 | struct isis_route_info *rinfo; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 986 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 987 | if (family == AF_INET) |
| 988 | spftree = area->spftree[level - 1]; |
| 989 | #ifdef HAVE_IPV6 |
| 990 | else if (family == AF_INET6) |
| 991 | spftree = area->spftree6[level - 1]; |
| 992 | #endif |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 993 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 994 | assert (spftree); |
| 995 | |
hasso | fac1f7c | 2005-09-26 18:26:26 +0000 | [diff] [blame] | 996 | /* Make all routes in current route table inactive. */ |
| 997 | if (family == AF_INET) |
| 998 | table = area->route_table[level - 1]; |
Paul Jakma | 41b36e9 | 2006-12-08 01:09:50 +0000 | [diff] [blame] | 999 | #ifdef HAVE_IPV6 |
hasso | fac1f7c | 2005-09-26 18:26:26 +0000 | [diff] [blame] | 1000 | else if (family == AF_INET6) |
| 1001 | table = area->route_table6[level - 1]; |
Paul Jakma | 41b36e9 | 2006-12-08 01:09:50 +0000 | [diff] [blame] | 1002 | #endif |
hasso | fac1f7c | 2005-09-26 18:26:26 +0000 | [diff] [blame] | 1003 | |
| 1004 | for (rode = route_top (table); rode; rode = route_next (rode)) |
| 1005 | { |
| 1006 | if (rode->info == NULL) |
| 1007 | continue; |
| 1008 | rinfo = rode->info; |
| 1009 | |
| 1010 | UNSET_FLAG (rinfo->flag, ISIS_ROUTE_FLAG_ACTIVE); |
| 1011 | } |
| 1012 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1013 | /* |
| 1014 | * C.2.5 Step 0 |
| 1015 | */ |
| 1016 | init_spt (spftree); |
| 1017 | /* a) */ |
| 1018 | isis_spf_add_self (spftree, area, level); |
| 1019 | /* b) */ |
| 1020 | retval = isis_spf_preload_tent (spftree, area, level, family); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1021 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1022 | /* |
| 1023 | * C.2.7 Step 2 |
| 1024 | */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1025 | if (listcount (spftree->tents) == 0) |
| 1026 | { |
| 1027 | zlog_warn ("ISIS-Spf: TENT is empty"); |
hasso | 13fb40a | 2005-10-01 06:03:04 +0000 | [diff] [blame] | 1028 | goto out; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1029 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1030 | |
| 1031 | while (listcount (spftree->tents) > 0) |
| 1032 | { |
Fritz Reichmann | c25eaff | 2011-10-01 17:43:12 +0400 | [diff] [blame] | 1033 | /* C.2.7 a) 1) */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1034 | node = listhead (spftree->tents); |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 1035 | vertex = listgetdata (node); |
Fritz Reichmann | c25eaff | 2011-10-01 17:43:12 +0400 | [diff] [blame] | 1036 | |
| 1037 | /* C.2.7 a) 2) */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1038 | list_delete_node (spftree->tents, node); |
Fritz Reichmann | c25eaff | 2011-10-01 17:43:12 +0400 | [diff] [blame] | 1039 | |
| 1040 | /* C.2.7 a) 3) */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1041 | if (isis_find_vertex (spftree->paths, vertex->N.id, vertex->type)) |
| 1042 | continue; |
hasso | fac1f7c | 2005-09-26 18:26:26 +0000 | [diff] [blame] | 1043 | add_to_paths (spftree, vertex, area, level); |
Fritz Reichmann | c25eaff | 2011-10-01 17:43:12 +0400 | [diff] [blame] | 1044 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1045 | if (vertex->type == VTYPE_PSEUDO_IS || |
Fritz Reichmann | c25eaff | 2011-10-01 17:43:12 +0400 | [diff] [blame] | 1046 | vertex->type == VTYPE_NONPSEUDO_IS || |
| 1047 | vertex->type == VTYPE_PSEUDO_TE_IS || |
| 1048 | vertex->type == VTYPE_NONPSEUDO_TE_IS ) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1049 | { |
Peter Szilagyi | d034aa0 | 2011-10-01 17:22:51 +0400 | [diff] [blame] | 1050 | if (listcount(vertex->Adj_N) == 0) { |
| 1051 | continue; |
| 1052 | } |
| 1053 | adj = listgetdata(vertex->Adj_N->head); |
| 1054 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1055 | memcpy (lsp_id, vertex->N.id, ISIS_SYS_ID_LEN + 1); |
| 1056 | LSP_FRAGMENT (lsp_id) = 0; |
| 1057 | lsp = lsp_search (lsp_id, area->lspdb[level - 1]); |
| 1058 | if (lsp) |
| 1059 | { |
| 1060 | if (LSP_PSEUDO_ID (lsp_id)) |
| 1061 | { |
| 1062 | isis_spf_process_pseudo_lsp (spftree, lsp, vertex->d_N, |
Peter Szilagyi | d034aa0 | 2011-10-01 17:22:51 +0400 | [diff] [blame] | 1063 | vertex->depth, family, adj); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1064 | } |
| 1065 | else |
| 1066 | { |
| 1067 | isis_spf_process_lsp (spftree, lsp, vertex->d_N, |
Peter Szilagyi | d034aa0 | 2011-10-01 17:22:51 +0400 | [diff] [blame] | 1068 | vertex->depth, family, adj); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1069 | } |
| 1070 | } |
| 1071 | else |
| 1072 | { |
| 1073 | zlog_warn ("ISIS-Spf: No LSP found for %s", |
| 1074 | rawlspid_print (lsp_id)); |
| 1075 | } |
| 1076 | } |
| 1077 | } |
| 1078 | |
hasso | 13fb40a | 2005-10-01 06:03:04 +0000 | [diff] [blame] | 1079 | out: |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1080 | thread_add_event (master, isis_route_validate, area, 0); |
| 1081 | spftree->lastrun = time (NULL); |
| 1082 | spftree->pending = 0; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1083 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1084 | return retval; |
| 1085 | } |
| 1086 | |
| 1087 | int |
| 1088 | isis_run_spf_l1 (struct thread *thread) |
| 1089 | { |
| 1090 | struct isis_area *area; |
| 1091 | int retval = ISIS_OK; |
| 1092 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1093 | area = THREAD_ARG (thread); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1094 | assert (area); |
| 1095 | |
hasso | 12a5cae | 2004-09-19 19:39:26 +0000 | [diff] [blame] | 1096 | area->spftree[0]->t_spf = NULL; |
| 1097 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1098 | if (!(area->is_type & IS_LEVEL_1)) |
| 1099 | { |
| 1100 | if (isis->debugs & DEBUG_SPF_EVENTS) |
hasso | 12a5cae | 2004-09-19 19:39:26 +0000 | [diff] [blame] | 1101 | zlog_warn ("ISIS-SPF (%s) area does not share level", |
| 1102 | area->area_tag); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1103 | return ISIS_WARNING; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1104 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1105 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1106 | if (isis->debugs & DEBUG_SPF_EVENTS) |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 1107 | zlog_debug ("ISIS-Spf (%s) L1 SPF needed, periodic SPF", area->area_tag); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1108 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1109 | if (area->ip_circuits) |
| 1110 | retval = isis_run_spf (area, 1, AF_INET); |
hasso | 12a5cae | 2004-09-19 19:39:26 +0000 | [diff] [blame] | 1111 | |
| 1112 | THREAD_TIMER_ON (master, area->spftree[0]->t_spf, isis_run_spf_l1, area, |
| 1113 | isis_jitter (PERIODIC_SPF_INTERVAL, 10)); |
| 1114 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1115 | return retval; |
| 1116 | } |
| 1117 | |
| 1118 | int |
| 1119 | isis_run_spf_l2 (struct thread *thread) |
| 1120 | { |
| 1121 | struct isis_area *area; |
| 1122 | int retval = ISIS_OK; |
| 1123 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1124 | area = THREAD_ARG (thread); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1125 | assert (area); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1126 | |
hasso | 12a5cae | 2004-09-19 19:39:26 +0000 | [diff] [blame] | 1127 | area->spftree[1]->t_spf = NULL; |
| 1128 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1129 | if (!(area->is_type & IS_LEVEL_2)) |
| 1130 | { |
| 1131 | if (isis->debugs & DEBUG_SPF_EVENTS) |
hasso | 12a5cae | 2004-09-19 19:39:26 +0000 | [diff] [blame] | 1132 | zlog_warn ("ISIS-SPF (%s) area does not share level", area->area_tag); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1133 | return ISIS_WARNING; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1134 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1135 | |
| 1136 | if (isis->debugs & DEBUG_SPF_EVENTS) |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 1137 | zlog_debug ("ISIS-Spf (%s) L2 SPF needed, periodic SPF", area->area_tag); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1138 | |
| 1139 | if (area->ip_circuits) |
| 1140 | retval = isis_run_spf (area, 2, AF_INET); |
hasso | 12a5cae | 2004-09-19 19:39:26 +0000 | [diff] [blame] | 1141 | |
| 1142 | THREAD_TIMER_ON (master, area->spftree[1]->t_spf, isis_run_spf_l2, area, |
| 1143 | isis_jitter (PERIODIC_SPF_INTERVAL, 10)); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1144 | |
| 1145 | return retval; |
| 1146 | } |
| 1147 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1148 | int |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1149 | isis_spf_schedule (struct isis_area *area, int level) |
| 1150 | { |
| 1151 | int retval = ISIS_OK; |
| 1152 | struct isis_spftree *spftree = area->spftree[level - 1]; |
| 1153 | time_t diff, now = time (NULL); |
| 1154 | |
| 1155 | if (spftree->pending) |
| 1156 | return retval; |
| 1157 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1158 | diff = now - spftree->lastrun; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1159 | |
| 1160 | /* FIXME: let's wait a minute before doing the SPF */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1161 | if (now - isis->uptime < 60 || isis->uptime == 0) |
| 1162 | { |
| 1163 | if (level == 1) |
hasso | 12a5cae | 2004-09-19 19:39:26 +0000 | [diff] [blame] | 1164 | THREAD_TIMER_ON (master, spftree->t_spf, isis_run_spf_l1, area, 60); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1165 | else |
hasso | 12a5cae | 2004-09-19 19:39:26 +0000 | [diff] [blame] | 1166 | THREAD_TIMER_ON (master, spftree->t_spf, isis_run_spf_l2, area, 60); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1167 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1168 | spftree->pending = 1; |
| 1169 | return retval; |
| 1170 | } |
hasso | 12a5cae | 2004-09-19 19:39:26 +0000 | [diff] [blame] | 1171 | |
| 1172 | THREAD_TIMER_OFF (spftree->t_spf); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1173 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1174 | if (diff < MINIMUM_SPF_INTERVAL) |
| 1175 | { |
| 1176 | if (level == 1) |
hasso | 12a5cae | 2004-09-19 19:39:26 +0000 | [diff] [blame] | 1177 | THREAD_TIMER_ON (master, spftree->t_spf, isis_run_spf_l1, area, |
| 1178 | MINIMUM_SPF_INTERVAL - diff); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1179 | else |
hasso | 12a5cae | 2004-09-19 19:39:26 +0000 | [diff] [blame] | 1180 | THREAD_TIMER_ON (master, spftree->t_spf, isis_run_spf_l2, area, |
| 1181 | MINIMUM_SPF_INTERVAL - diff); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1182 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1183 | spftree->pending = 1; |
| 1184 | } |
| 1185 | else |
| 1186 | { |
| 1187 | spftree->pending = 0; |
| 1188 | retval = isis_run_spf (area, level, AF_INET); |
hasso | 12a5cae | 2004-09-19 19:39:26 +0000 | [diff] [blame] | 1189 | if (level == 1) |
| 1190 | THREAD_TIMER_ON (master, spftree->t_spf, isis_run_spf_l1, area, |
| 1191 | isis_jitter (PERIODIC_SPF_INTERVAL, 10)); |
| 1192 | else |
| 1193 | THREAD_TIMER_ON (master, spftree->t_spf, isis_run_spf_l2, area, |
| 1194 | isis_jitter (PERIODIC_SPF_INTERVAL, 10)); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1195 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1196 | |
| 1197 | return retval; |
| 1198 | } |
| 1199 | |
| 1200 | #ifdef HAVE_IPV6 |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 1201 | static int |
hasso | 12a5cae | 2004-09-19 19:39:26 +0000 | [diff] [blame] | 1202 | isis_run_spf6_l1 (struct thread *thread) |
| 1203 | { |
| 1204 | struct isis_area *area; |
| 1205 | int retval = ISIS_OK; |
| 1206 | |
| 1207 | area = THREAD_ARG (thread); |
| 1208 | assert (area); |
| 1209 | |
| 1210 | area->spftree6[0]->t_spf = NULL; |
| 1211 | |
| 1212 | if (!(area->is_type & IS_LEVEL_1)) |
| 1213 | { |
| 1214 | if (isis->debugs & DEBUG_SPF_EVENTS) |
| 1215 | zlog_warn ("ISIS-SPF (%s) area does not share level", area->area_tag); |
| 1216 | return ISIS_WARNING; |
| 1217 | } |
| 1218 | |
| 1219 | if (isis->debugs & DEBUG_SPF_EVENTS) |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 1220 | zlog_debug ("ISIS-Spf (%s) L1 SPF needed, periodic SPF", area->area_tag); |
hasso | 12a5cae | 2004-09-19 19:39:26 +0000 | [diff] [blame] | 1221 | |
| 1222 | if (area->ipv6_circuits) |
| 1223 | retval = isis_run_spf (area, 1, AF_INET6); |
| 1224 | |
| 1225 | THREAD_TIMER_ON (master, area->spftree6[0]->t_spf, isis_run_spf6_l1, area, |
| 1226 | isis_jitter (PERIODIC_SPF_INTERVAL, 10)); |
| 1227 | |
| 1228 | return retval; |
| 1229 | } |
| 1230 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 1231 | static int |
hasso | 12a5cae | 2004-09-19 19:39:26 +0000 | [diff] [blame] | 1232 | isis_run_spf6_l2 (struct thread *thread) |
| 1233 | { |
| 1234 | struct isis_area *area; |
| 1235 | int retval = ISIS_OK; |
| 1236 | |
| 1237 | area = THREAD_ARG (thread); |
| 1238 | assert (area); |
| 1239 | |
| 1240 | area->spftree6[1]->t_spf = NULL; |
| 1241 | |
| 1242 | if (!(area->is_type & IS_LEVEL_2)) |
| 1243 | { |
| 1244 | if (isis->debugs & DEBUG_SPF_EVENTS) |
| 1245 | zlog_warn ("ISIS-SPF (%s) area does not share level", area->area_tag); |
| 1246 | return ISIS_WARNING; |
| 1247 | } |
| 1248 | |
| 1249 | if (isis->debugs & DEBUG_SPF_EVENTS) |
hasso | fac1f7c | 2005-09-26 18:26:26 +0000 | [diff] [blame] | 1250 | zlog_debug ("ISIS-Spf (%s) L2 SPF needed, periodic SPF.", area->area_tag); |
hasso | 12a5cae | 2004-09-19 19:39:26 +0000 | [diff] [blame] | 1251 | |
| 1252 | if (area->ipv6_circuits) |
| 1253 | retval = isis_run_spf (area, 2, AF_INET6); |
| 1254 | |
| 1255 | THREAD_TIMER_ON (master, area->spftree6[1]->t_spf, isis_run_spf6_l2, area, |
| 1256 | isis_jitter (PERIODIC_SPF_INTERVAL, 10)); |
| 1257 | |
| 1258 | return retval; |
| 1259 | } |
| 1260 | |
| 1261 | int |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1262 | isis_spf_schedule6 (struct isis_area *area, int level) |
| 1263 | { |
| 1264 | int retval = ISIS_OK; |
| 1265 | struct isis_spftree *spftree = area->spftree6[level - 1]; |
| 1266 | time_t diff, now = time (NULL); |
| 1267 | |
| 1268 | if (spftree->pending) |
| 1269 | return retval; |
| 1270 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1271 | diff = now - spftree->lastrun; |
| 1272 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1273 | /* FIXME: let's wait a minute before doing the SPF */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1274 | if (now - isis->uptime < 60 || isis->uptime == 0) |
| 1275 | { |
| 1276 | if (level == 1) |
hasso | 12a5cae | 2004-09-19 19:39:26 +0000 | [diff] [blame] | 1277 | THREAD_TIMER_ON (master, spftree->t_spf, isis_run_spf6_l1, area, 60); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1278 | else |
hasso | 12a5cae | 2004-09-19 19:39:26 +0000 | [diff] [blame] | 1279 | THREAD_TIMER_ON (master, spftree->t_spf, isis_run_spf6_l2, area, 60); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1280 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1281 | spftree->pending = 1; |
| 1282 | return retval; |
| 1283 | } |
hasso | 12a5cae | 2004-09-19 19:39:26 +0000 | [diff] [blame] | 1284 | |
| 1285 | THREAD_TIMER_OFF (spftree->t_spf); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1286 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1287 | if (diff < MINIMUM_SPF_INTERVAL) |
| 1288 | { |
| 1289 | if (level == 1) |
hasso | 12a5cae | 2004-09-19 19:39:26 +0000 | [diff] [blame] | 1290 | THREAD_TIMER_ON (master, spftree->t_spf, isis_run_spf6_l1, area, |
| 1291 | MINIMUM_SPF_INTERVAL - diff); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1292 | else |
hasso | 12a5cae | 2004-09-19 19:39:26 +0000 | [diff] [blame] | 1293 | THREAD_TIMER_ON (master, spftree->t_spf, isis_run_spf6_l2, area, |
| 1294 | MINIMUM_SPF_INTERVAL - diff); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1295 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1296 | spftree->pending = 1; |
| 1297 | } |
| 1298 | else |
| 1299 | { |
| 1300 | spftree->pending = 0; |
| 1301 | retval = isis_run_spf (area, level, AF_INET6); |
hasso | 12a5cae | 2004-09-19 19:39:26 +0000 | [diff] [blame] | 1302 | |
| 1303 | if (level == 1) |
| 1304 | THREAD_TIMER_ON (master, spftree->t_spf, isis_run_spf6_l1, area, |
| 1305 | isis_jitter (PERIODIC_SPF_INTERVAL, 10)); |
| 1306 | else |
| 1307 | THREAD_TIMER_ON (master, spftree->t_spf, isis_run_spf6_l2, area, |
| 1308 | isis_jitter (PERIODIC_SPF_INTERVAL, 10)); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1309 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1310 | |
| 1311 | return retval; |
| 1312 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1313 | #endif |
| 1314 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 1315 | static void |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1316 | isis_print_paths (struct vty *vty, struct list *paths) |
| 1317 | { |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 1318 | struct listnode *node; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1319 | struct isis_vertex *vertex; |
| 1320 | struct isis_dynhn *dyn, *nh_dyn = NULL; |
| 1321 | struct isis_adjacency *adj; |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 1322 | #if 0 |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1323 | u_char buff[255]; |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 1324 | #endif /* 0 */ |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1325 | |
| 1326 | vty_out (vty, "System Id Metric Next-Hop" |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1327 | " Interface SNPA%s", VTY_NEWLINE); |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 1328 | |
| 1329 | for (ALL_LIST_ELEMENTS_RO (paths, node, vertex)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1330 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1331 | if (vertex->type != VTYPE_NONPSEUDO_IS) |
| 1332 | continue; |
| 1333 | if (memcmp (vertex->N.id, isis->sysid, ISIS_SYS_ID_LEN) == 0) |
| 1334 | { |
hasso | c3d26c7 | 2005-03-07 08:54:41 +0000 | [diff] [blame] | 1335 | vty_out (vty, "%s --%s", host.name?host.name:"", |
| 1336 | VTY_NEWLINE); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1337 | } |
| 1338 | else |
| 1339 | { |
| 1340 | dyn = dynhn_find_by_id ((u_char *) vertex->N.id); |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 1341 | adj = listgetdata (listhead (vertex->Adj_N)); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1342 | if (adj) |
| 1343 | { |
| 1344 | nh_dyn = dynhn_find_by_id (adj->sysid); |
| 1345 | vty_out (vty, "%-20s %-10u %-20s %-11s %-5s%s", |
| 1346 | (dyn != NULL) ? dyn->name.name : |
Paul Jakma | 41b36e9 | 2006-12-08 01:09:50 +0000 | [diff] [blame] | 1347 | (const u_char *)rawlspid_print ((u_char *) vertex->N.id), |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1348 | vertex->d_N, (nh_dyn != NULL) ? nh_dyn->name.name : |
Paul Jakma | 41b36e9 | 2006-12-08 01:09:50 +0000 | [diff] [blame] | 1349 | (const u_char *)rawlspid_print (adj->sysid), |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1350 | adj->circuit->interface->name, |
| 1351 | snpa_print (adj->snpa), VTY_NEWLINE); |
| 1352 | } |
| 1353 | else |
| 1354 | { |
| 1355 | vty_out (vty, "%s %u %s", dyn ? dyn->name.name : |
Paul Jakma | 41b36e9 | 2006-12-08 01:09:50 +0000 | [diff] [blame] | 1356 | (const u_char *) rawlspid_print (vertex->N.id), |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1357 | vertex->d_N, VTY_NEWLINE); |
| 1358 | } |
| 1359 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1360 | #if 0 |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1361 | vty_out (vty, "%s %s %u %s", vtype2string (vertex->type), |
| 1362 | vid2string (vertex, buff), vertex->d_N, VTY_NEWLINE); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1363 | #endif |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1364 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1365 | } |
| 1366 | |
| 1367 | DEFUN (show_isis_topology, |
| 1368 | show_isis_topology_cmd, |
| 1369 | "show isis topology", |
| 1370 | SHOW_STR |
| 1371 | "IS-IS information\n" |
| 1372 | "IS-IS paths to Intermediate Systems\n") |
| 1373 | { |
| 1374 | struct listnode *node; |
| 1375 | struct isis_area *area; |
| 1376 | int level; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1377 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1378 | if (!isis->area_list || isis->area_list->count == 0) |
| 1379 | return CMD_SUCCESS; |
| 1380 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 1381 | for (ALL_LIST_ELEMENTS_RO (isis->area_list, node, area)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1382 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1383 | vty_out (vty, "Area %s:%s", area->area_tag ? area->area_tag : "null", |
| 1384 | VTY_NEWLINE); |
| 1385 | |
| 1386 | for (level = 0; level < ISIS_LEVELS; level++) |
| 1387 | { |
| 1388 | if (area->ip_circuits > 0 && area->spftree[level] |
| 1389 | && area->spftree[level]->paths->count > 0) |
| 1390 | { |
| 1391 | vty_out (vty, "IS-IS paths to level-%d routers that speak IP%s", |
| 1392 | level + 1, VTY_NEWLINE); |
| 1393 | isis_print_paths (vty, area->spftree[level]->paths); |
| 1394 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1395 | #ifdef HAVE_IPV6 |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1396 | if (area->ipv6_circuits > 0 && area->spftree6[level] |
| 1397 | && area->spftree6[level]->paths->count > 0) |
| 1398 | { |
| 1399 | vty_out (vty, |
| 1400 | "IS-IS paths to level-%d routers that speak IPv6%s", |
| 1401 | level + 1, VTY_NEWLINE); |
| 1402 | isis_print_paths (vty, area->spftree6[level]->paths); |
| 1403 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1404 | #endif /* HAVE_IPV6 */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1405 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1406 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1407 | |
| 1408 | return CMD_SUCCESS; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1409 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1410 | |
| 1411 | DEFUN (show_isis_topology_l1, |
| 1412 | show_isis_topology_l1_cmd, |
| 1413 | "show isis topology level-1", |
| 1414 | SHOW_STR |
| 1415 | "IS-IS information\n" |
| 1416 | "IS-IS paths to Intermediate Systems\n" |
| 1417 | "Paths to all level-1 routers in the area\n") |
| 1418 | { |
| 1419 | struct listnode *node; |
| 1420 | struct isis_area *area; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1421 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1422 | if (!isis->area_list || isis->area_list->count == 0) |
| 1423 | return CMD_SUCCESS; |
| 1424 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 1425 | for (ALL_LIST_ELEMENTS_RO (isis->area_list, node, area)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1426 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1427 | vty_out (vty, "Area %s:%s", area->area_tag ? area->area_tag : "null", |
| 1428 | VTY_NEWLINE); |
| 1429 | |
| 1430 | if (area->ip_circuits > 0 && area->spftree[0] |
| 1431 | && area->spftree[0]->paths->count > 0) |
| 1432 | { |
| 1433 | vty_out (vty, "IS-IS paths to level-1 routers that speak IP%s", |
| 1434 | VTY_NEWLINE); |
| 1435 | isis_print_paths (vty, area->spftree[0]->paths); |
| 1436 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1437 | #ifdef HAVE_IPV6 |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1438 | if (area->ipv6_circuits > 0 && area->spftree6[0] |
| 1439 | && area->spftree6[0]->paths->count > 0) |
| 1440 | { |
| 1441 | vty_out (vty, "IS-IS paths to level-1 routers that speak IPv6%s", |
| 1442 | VTY_NEWLINE); |
| 1443 | isis_print_paths (vty, area->spftree6[0]->paths); |
| 1444 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1445 | #endif /* HAVE_IPV6 */ |
| 1446 | } |
| 1447 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1448 | return CMD_SUCCESS; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1449 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1450 | |
| 1451 | DEFUN (show_isis_topology_l2, |
| 1452 | show_isis_topology_l2_cmd, |
| 1453 | "show isis topology level-2", |
| 1454 | SHOW_STR |
| 1455 | "IS-IS information\n" |
| 1456 | "IS-IS paths to Intermediate Systems\n" |
| 1457 | "Paths to all level-2 routers in the domain\n") |
| 1458 | { |
| 1459 | struct listnode *node; |
| 1460 | struct isis_area *area; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1461 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1462 | if (!isis->area_list || isis->area_list->count == 0) |
| 1463 | return CMD_SUCCESS; |
| 1464 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 1465 | for (ALL_LIST_ELEMENTS_RO (isis->area_list, node, area)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1466 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1467 | vty_out (vty, "Area %s:%s", area->area_tag ? area->area_tag : "null", |
| 1468 | VTY_NEWLINE); |
| 1469 | |
| 1470 | if (area->ip_circuits > 0 && area->spftree[1] |
| 1471 | && area->spftree[1]->paths->count > 0) |
| 1472 | { |
| 1473 | vty_out (vty, "IS-IS paths to level-2 routers that speak IP%s", |
| 1474 | VTY_NEWLINE); |
| 1475 | isis_print_paths (vty, area->spftree[1]->paths); |
| 1476 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1477 | #ifdef HAVE_IPV6 |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1478 | if (area->ipv6_circuits > 0 && area->spftree6[1] |
| 1479 | && area->spftree6[1]->paths->count > 0) |
| 1480 | { |
| 1481 | vty_out (vty, "IS-IS paths to level-2 routers that speak IPv6%s", |
| 1482 | VTY_NEWLINE); |
| 1483 | isis_print_paths (vty, area->spftree6[1]->paths); |
| 1484 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1485 | #endif /* HAVE_IPV6 */ |
| 1486 | } |
| 1487 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1488 | return CMD_SUCCESS; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1489 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1490 | |
| 1491 | void |
| 1492 | isis_spf_cmds_init () |
| 1493 | { |
| 1494 | install_element (VIEW_NODE, &show_isis_topology_cmd); |
| 1495 | install_element (VIEW_NODE, &show_isis_topology_l1_cmd); |
| 1496 | install_element (VIEW_NODE, &show_isis_topology_l2_cmd); |
| 1497 | |
| 1498 | install_element (ENABLE_NODE, &show_isis_topology_cmd); |
| 1499 | install_element (ENABLE_NODE, &show_isis_topology_l1_cmd); |
| 1500 | install_element (ENABLE_NODE, &show_isis_topology_l2_cmd); |
| 1501 | } |